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>
22 #include <sys/types.h>
28 #include <sys/param.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
39 #include <afs/afsint.h>
41 #include <afs/errors.h>
45 #include <afs/afssyscalls.h>
49 #include "partition.h"
51 #include <rx/rx_queue.h>
53 #ifdef AFS_DEMAND_ATTACH_FS
55 * SALVSYNC is a feature specific to the demand attach fileserver
60 extern pthread_mutex_t vol_salvsync_mutex;
62 static SYNC_client_state salvsync_client_state =
63 { -1, /* file descriptor */
64 SALVSYNC_ENDPOINT_DECL, /* server endpoint */
65 SALVSYNC_PROTO_VERSION, /* protocol version */
66 5, /* connect retry limit */
67 120, /* hard timeout */
68 "SALVSYNC", /* protocol name string */
72 * client-side routines
76 SALVSYNC_clientInit(void)
78 return SYNC_connect(&salvsync_client_state);
82 SALVSYNC_clientFinis(void)
84 SYNC_closeChannel(&salvsync_client_state);
89 SALVSYNC_clientReconnect(void)
91 return SYNC_reconnect(&salvsync_client_state);
95 SALVSYNC_askSalv(SYNC_command * com, SYNC_response * res)
98 SALVSYNC_command_hdr * scom = com->payload.buf;
100 scom->hdr_version = SALVSYNC_PROTO_VERSION;
103 code = SYNC_ask(&salvsync_client_state, com, res);
111 case SYNC_BAD_COMMAND:
112 Log("SALVSYNC_askSalv: fatal SALVSYNC protocol error; online salvager functionality disabled until next fileserver restart\n");
115 Log("SALVSYNC_askSalv: SALVSYNC request denied for reason=%d\n", res->hdr.reason);
118 Log("SALVSYNC_askSalv: unknown protocol response %d\n", code);
126 SALVSYNC_SalvageVolume(VolumeId volume, char *partName, int command, int reason,
127 afs_uint32 prio, SYNC_response * res_in)
130 SYNC_response res_l, *res;
131 SALVSYNC_command_hdr scom;
132 SALVSYNC_response_hdr sres;
134 memset(&com, 0, sizeof(com));
135 memset(&scom, 0, sizeof(scom));
140 memset(&res_l, 0, sizeof(res_l));
141 memset(&sres, 0, sizeof(sres));
142 res_l.payload.buf = (void *) &sres;
143 res_l.payload.len = sizeof(sres);
147 com.payload.buf = (void *) &scom;
148 com.payload.len = sizeof(scom);
149 com.hdr.command = command;
150 com.hdr.reason = reason;
151 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
152 scom.volume = volume;
153 scom.parent = volume;
157 strlcpy(scom.partName, partName, sizeof(scom.partName));
159 scom.partName[0] = '\0';
162 return SALVSYNC_askSalv(&com, res);
166 SALVSYNC_LinkVolume(VolumeId parent,
169 SYNC_response * res_in)
172 SYNC_response res_l, *res;
173 SALVSYNC_command_hdr scom;
174 SALVSYNC_response_hdr sres;
176 memset(&com, 0, sizeof(com));
177 memset(&scom, 0, sizeof(scom));
182 memset(&res_l, 0, sizeof(res_l));
183 memset(&sres, 0, sizeof(sres));
184 res_l.payload.buf = (void *) &sres;
185 res_l.payload.len = sizeof(sres);
189 com.payload.buf = (void *) &scom;
190 com.payload.len = sizeof(scom);
191 com.hdr.command = SALVSYNC_OP_LINK;
192 com.hdr.reason = SALVSYNC_REASON_WHATEVER;
193 com.hdr.command_len = sizeof(com.hdr) + sizeof(scom);
195 scom.parent = parent;
198 strlcpy(scom.partName, partName, sizeof(scom.partName));
200 scom.partName[0] = '\0';
203 return SALVSYNC_askSalv(&com, res);
206 #endif /* AFS_DEMAND_ATTACH_FS */