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>
39 #include <afs/afsint.h>
41 #include <afs/errors.h>
45 #include <afs/afssyscalls.h>
49 #include "partition.h"
50 #include <rx/rx_queue.h>
52 /*@printflike@*/ extern void Log(const char *format, ...);
54 #ifdef AFS_DEMAND_ATTACH_FS
56 * SALVSYNC is a feature specific to the demand attach fileserver
61 extern pthread_mutex_t vol_salvsync_mutex;
63 static SYNC_client_state salvsync_client_state =
64 { -1, /* file descriptor */
65 SALVSYNC_ENDPOINT_DECL, /* server endpoint */
66 SALVSYNC_PROTO_VERSION, /* protocol version */
67 5, /* connect retry limit */
68 120, /* hard timeout */
69 "SALVSYNC", /* protocol name string */
73 * client-side routines
77 SALVSYNC_clientInit(void)
79 return SYNC_connect(&salvsync_client_state);
83 SALVSYNC_clientFinis(void)
85 SYNC_closeChannel(&salvsync_client_state);
90 SALVSYNC_clientReconnect(void)
92 return SYNC_reconnect(&salvsync_client_state);
96 SALVSYNC_askSalv(SYNC_command * com, SYNC_response * res)
99 SALVSYNC_command_hdr * scom = com->payload.buf;
101 scom->hdr_version = SALVSYNC_PROTO_VERSION;
104 code = SYNC_ask(&salvsync_client_state, com, res);
112 case SYNC_BAD_COMMAND:
113 Log("SALVSYNC_askSalv: fatal SALVSYNC protocol error; online salvager functionality disabled until next fileserver restart\n");
116 Log("SALVSYNC_askSalv: SALVSYNC request denied for reason=%d\n", res->hdr.reason);
119 Log("SALVSYNC_askSalv: unknown protocol response %d\n", code);
127 SALVSYNC_SalvageVolume(VolumeId volume, char *partName, int command, int reason,
128 afs_uint32 prio, SYNC_response * res_in)
131 SYNC_response res_l, *res;
132 SALVSYNC_command_hdr scom;
133 SALVSYNC_response_hdr sres;
136 memset(&com, 0, sizeof(com));
137 memset(&scom, 0, sizeof(scom));
142 memset(&res_l, 0, sizeof(res_l));
143 memset(&sres, 0, sizeof(sres));
144 res_l.payload.buf = (void *) &sres;
145 res_l.payload.len = sizeof(sres);
149 com.payload.buf = (void *) &scom;
150 com.payload.len = sizeof(scom);
151 com.hdr.command = command;
152 com.hdr.reason = reason;
153 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
154 scom.volume = volume;
155 scom.parent = volume;
159 strlcpy(scom.partName, partName, sizeof(scom.partName));
161 scom.partName[0] = '\0';
164 return SALVSYNC_askSalv(&com, res);
168 SALVSYNC_LinkVolume(VolumeId parent,
171 SYNC_response * res_in)
174 SYNC_response res_l, *res;
175 SALVSYNC_command_hdr scom;
176 SALVSYNC_response_hdr sres;
179 memset(&com, 0, sizeof(com));
180 memset(&scom, 0, sizeof(scom));
185 memset(&res_l, 0, sizeof(res_l));
186 memset(&sres, 0, sizeof(sres));
187 res_l.payload.buf = (void *) &sres;
188 res_l.payload.len = sizeof(sres);
192 com.payload.buf = (void *) &scom;
193 com.payload.len = sizeof(scom);
194 com.hdr.command = SALVSYNC_OP_LINK;
195 com.hdr.reason = SALVSYNC_REASON_WHATEVER;
196 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
198 scom.parent = parent;
201 strlcpy(scom.partName, partName, sizeof(scom.partName));
203 scom.partName[0] = '\0';
206 return SALVSYNC_askSalv(&com, res);
209 #endif /* AFS_DEMAND_ATTACH_FS */