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>
21 #include <sys/types.h>
27 #include <sys/param.h>
28 #include <sys/socket.h>
29 #include <netinet/in.h>
38 #include <afs/afsint.h>
40 #include <afs/errors.h>
44 #include <afs/afssyscalls.h>
48 #include "partition.h"
50 #include <rx/rx_queue.h>
52 #ifdef AFS_DEMAND_ATTACH_FS
54 * SALVSYNC is a feature specific to the demand attach fileserver
59 extern pthread_mutex_t vol_salvsync_mutex;
61 static SYNC_client_state salvsync_client_state =
62 { -1, /* file descriptor */
63 SALVSYNC_ENDPOINT_DECL, /* server endpoint */
64 SALVSYNC_PROTO_VERSION, /* protocol version */
65 5, /* connect retry limit */
66 120, /* hard timeout */
67 "SALVSYNC", /* protocol name string */
71 * client-side routines
75 SALVSYNC_clientInit(void)
77 return SYNC_connect(&salvsync_client_state);
81 SALVSYNC_clientFinis(void)
83 SYNC_closeChannel(&salvsync_client_state);
88 SALVSYNC_clientReconnect(void)
90 return SYNC_reconnect(&salvsync_client_state);
94 SALVSYNC_askSalv(SYNC_command * com, SYNC_response * res)
97 SALVSYNC_command_hdr * scom = com->payload.buf;
99 scom->hdr_version = SALVSYNC_PROTO_VERSION;
102 code = SYNC_ask(&salvsync_client_state, com, res);
110 case SYNC_BAD_COMMAND:
111 Log("SALVSYNC_askSalv: fatal SALVSYNC protocol error; online salvager functionality disabled until next fileserver restart\n");
114 Log("SALVSYNC_askSalv: SALVSYNC request denied for reason=%d\n", res->hdr.reason);
117 Log("SALVSYNC_askSalv: unknown protocol response %d\n", code);
125 SALVSYNC_SalvageVolume(VolumeId volume, char *partName, int command, int reason,
126 afs_uint32 prio, SYNC_response * res_in)
129 SYNC_response res_l, *res;
130 SALVSYNC_command_hdr scom;
131 SALVSYNC_response_hdr sres;
133 memset(&com, 0, sizeof(com));
134 memset(&scom, 0, sizeof(scom));
139 memset(&res_l, 0, sizeof(res_l));
140 memset(&sres, 0, sizeof(sres));
141 res_l.payload.buf = (void *) &sres;
142 res_l.payload.len = sizeof(sres);
146 com.payload.buf = (void *) &scom;
147 com.payload.len = sizeof(scom);
148 com.hdr.command = command;
149 com.hdr.reason = reason;
150 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
151 scom.volume = volume;
152 scom.parent = volume;
156 strlcpy(scom.partName, partName, sizeof(scom.partName));
158 scom.partName[0] = '\0';
161 return SALVSYNC_askSalv(&com, res);
165 SALVSYNC_LinkVolume(VolumeId parent,
168 SYNC_response * res_in)
171 SYNC_response res_l, *res;
172 SALVSYNC_command_hdr scom;
173 SALVSYNC_response_hdr sres;
175 memset(&com, 0, sizeof(com));
176 memset(&scom, 0, sizeof(scom));
181 memset(&res_l, 0, sizeof(res_l));
182 memset(&sres, 0, sizeof(sres));
183 res_l.payload.buf = (void *) &sres;
184 res_l.payload.len = sizeof(sres);
188 com.payload.buf = (void *) &scom;
189 com.payload.len = sizeof(scom);
190 com.hdr.command = SALVSYNC_OP_LINK;
191 com.hdr.reason = SALVSYNC_REASON_WHATEVER;
192 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
194 scom.parent = parent;
197 strlcpy(scom.partName, partName, sizeof(scom.partName));
199 scom.partName[0] = '\0';
202 return SALVSYNC_askSalv(&com, res);
205 #endif /* AFS_DEMAND_ATTACH_FS */