2 * Copyright 2006-2008, Sine Nomine Associates and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
13 * OpenAFS demand attach fileserver
14 * Salvage server synchronization with fileserver.
17 #include <afsconfig.h>
18 #include <afs/param.h>
23 #include <sys/types.h>
29 #include <sys/param.h>
30 #include <sys/socket.h>
31 #include <netinet/in.h>
41 #include <afs/afsint.h>
43 #include <afs/errors.h>
47 #include <afs/afssyscalls.h>
51 #include "partition.h"
52 #include <rx/rx_queue.h>
54 /*@printflike@*/ extern void Log(const char *format, ...);
56 #ifdef AFS_DEMAND_ATTACH_FS
58 * SALVSYNC is a feature specific to the demand attach fileserver
63 extern pthread_mutex_t vol_salvsync_mutex;
65 static SYNC_client_state salvsync_client_state =
66 { -1, /* file descriptor */
67 SALVSYNC_ENDPOINT_DECL, /* server endpoint */
68 SALVSYNC_PROTO_VERSION, /* protocol version */
69 5, /* connect retry limit */
70 120, /* hard timeout */
71 "SALVSYNC", /* protocol name string */
75 * client-side routines
79 SALVSYNC_clientInit(void)
81 return SYNC_connect(&salvsync_client_state);
85 SALVSYNC_clientFinis(void)
87 SYNC_closeChannel(&salvsync_client_state);
92 SALVSYNC_clientReconnect(void)
94 return SYNC_reconnect(&salvsync_client_state);
98 SALVSYNC_askSalv(SYNC_command * com, SYNC_response * res)
101 SALVSYNC_command_hdr * scom = com->payload.buf;
103 scom->hdr_version = SALVSYNC_PROTO_VERSION;
106 code = SYNC_ask(&salvsync_client_state, com, res);
114 case SYNC_BAD_COMMAND:
115 Log("SALVSYNC_askSalv: fatal SALVSYNC protocol error; online salvager functionality disabled until next fileserver restart\n");
118 Log("SALVSYNC_askSalv: SALVSYNC request denied for reason=%d\n", res->hdr.reason);
121 Log("SALVSYNC_askSalv: unknown protocol response %d\n", code);
129 SALVSYNC_SalvageVolume(VolumeId volume, char *partName, int command, int reason,
130 afs_uint32 prio, SYNC_response * res_in)
133 SYNC_response res_l, *res;
134 SALVSYNC_command_hdr scom;
135 SALVSYNC_response_hdr sres;
138 memset(&com, 0, sizeof(com));
139 memset(&scom, 0, sizeof(scom));
144 memset(&res_l, 0, sizeof(res_l));
145 memset(&sres, 0, sizeof(sres));
146 res_l.payload.buf = (void *) &sres;
147 res_l.payload.len = sizeof(sres);
151 com.payload.buf = (void *) &scom;
152 com.payload.len = sizeof(scom);
153 com.hdr.command = command;
154 com.hdr.reason = reason;
155 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
156 scom.volume = volume;
157 scom.parent = volume;
161 strlcpy(scom.partName, partName, sizeof(scom.partName));
163 scom.partName[0] = '\0';
166 return SALVSYNC_askSalv(&com, res);
170 SALVSYNC_LinkVolume(VolumeId parent,
173 SYNC_response * res_in)
176 SYNC_response res_l, *res;
177 SALVSYNC_command_hdr scom;
178 SALVSYNC_response_hdr sres;
181 memset(&com, 0, sizeof(com));
182 memset(&scom, 0, sizeof(scom));
187 memset(&res_l, 0, sizeof(res_l));
188 memset(&sres, 0, sizeof(sres));
189 res_l.payload.buf = (void *) &sres;
190 res_l.payload.len = sizeof(sres);
194 com.payload.buf = (void *) &scom;
195 com.payload.len = sizeof(scom);
196 com.hdr.command = SALVSYNC_OP_LINK;
197 com.hdr.reason = SALVSYNC_REASON_WHATEVER;
198 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
200 scom.parent = parent;
203 strlcpy(scom.partName, partName, sizeof(scom.partName));
205 scom.partName[0] = '\0';
208 return SALVSYNC_askSalv(&com, res);
211 #endif /* AFS_DEMAND_ATTACH_FS */