2 * Copyright 2000, International Business Machines Corporation 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
9 * Portions Copyright (c) 2006,2008 Sine Nomine Associates
15 Institution: The Information Technology Center, Carnegie-Mellon University
19 #ifndef AFS_PTHREAD_ENV
20 #define USUAL_PRIORITY (LWP_MAX_PRIORITY - 2)
23 * stack size increased from 8K because the HP machine seemed to have trouble
24 * with the smaller stack
26 #define USUAL_STACK_SIZE (24 * 1024)
27 #endif /* !AFS_PTHREAD_ENV */
31 File server synchronization with external volume utilities.
32 client-side implementation
35 #include <afsconfig.h>
36 #include <afs/param.h>
39 #include <sys/types.h>
45 #include <sys/param.h>
46 #include <sys/socket.h>
47 #include <netinet/in.h>
52 #ifdef AFS_PTHREAD_ENV
54 #else /* AFS_PTHREAD_ENV */
55 #include <afs/assert.h>
56 #endif /* AFS_PTHREAD_ENV */
61 #include <afs/afsint.h>
63 #include <afs/errors.h>
64 #include "daemon_com.h"
68 #include <afs/afssyscalls.h>
72 #include "partition.h"
74 #ifdef FSSYNC_BUILD_CLIENT
76 /*@printflike@*/ extern void Log(const char *format, ...);
80 static SYNC_client_state fssync_state =
81 { -1, /* file descriptor */
82 FSSYNC_ENDPOINT_DECL, /* server endpoint */
83 FSYNC_PROTO_VERSION, /* protocol version */
84 5, /* connect retry limit */
85 120, /* hard timeout */
86 "FSSYNC", /* protocol name string */
89 #ifdef AFS_PTHREAD_ENV
90 static pthread_mutex_t vol_fsync_mutex;
91 static volatile int vol_fsync_mutex_init = 0;
93 assert(pthread_mutex_lock(&vol_fsync_mutex) == 0)
94 #define VFSYNC_UNLOCK \
95 assert(pthread_mutex_unlock(&vol_fsync_mutex) == 0)
102 FSYNC_clientInit(void)
104 #ifdef AFS_PTHREAD_ENV
105 /* this is safe since it gets called with VOL_LOCK held, or before we go multithreaded */
106 if (!vol_fsync_mutex_init) {
107 assert(pthread_mutex_init(&vol_fsync_mutex, NULL) == 0);
108 vol_fsync_mutex_init = 1;
111 return SYNC_connect(&fssync_state);
115 FSYNC_clientFinis(void)
117 SYNC_closeChannel(&fssync_state);
121 FSYNC_clientChildProcReconnect(void)
123 return SYNC_reconnect(&fssync_state);
126 /* fsync client interface */
128 FSYNC_askfs(SYNC_command * com, SYNC_response * res)
133 code = SYNC_ask(&fssync_state, com, res);
141 case SYNC_BAD_COMMAND:
142 Log("FSYNC_askfs: fatal FSSYNC protocol error; volume management functionality disabled until next fileserver restart\n");
145 Log("FSYNC_askfs: FSSYNC request denied for reason=%d\n", res->hdr.reason);
148 Log("FSYNC_askfs: unknown protocol response %d\n", code);
156 * FSSYNC volume operations client interface.
158 * @param[in] volume volume id
159 * @param[in] partName partition name string
160 * @param[in] com FSSYNC command code
161 * @param[in] reason FSSYNC reason sub-code
162 * @param[out] res response message
164 * @return operation status
165 * @retval SYNC_OK success
168 FSYNC_GenericOp(void * ext_hdr, size_t ext_len,
169 int command, int reason,
170 SYNC_response * res_in)
172 SYNC_response res_l, *res;
179 res_l.payload.buf = NULL;
180 res_l.payload.len = 0;
183 memset(&com, 0, sizeof(com));
185 com.hdr.programType = programType;
186 com.hdr.command = command;
187 com.hdr.reason = reason;
188 com.hdr.command_len = sizeof(com.hdr) + ext_len;
189 com.payload.buf = ext_hdr;
190 com.payload.len = ext_len;
192 return FSYNC_askfs(&com, res);
196 FSYNC_VolOp(VolumeId volume, char * partition,
197 int command, int reason,
200 FSSYNC_VolOp_hdr vcom;
202 memset(&vcom, 0, sizeof(vcom));
204 vcom.volume = volume;
206 strlcpy(vcom.partName, partition, sizeof(vcom.partName));
208 return FSYNC_GenericOp(&vcom, sizeof(vcom), command, reason, res);
212 FSYNC_StatsOp(FSSYNC_StatsOp_hdr * scom, int command, int reason,
215 return FSYNC_GenericOp(scom, sizeof(*scom), command, reason, res);
219 * query the volume group cache.
221 * @param[in] part vice partition path
222 * @param[in] volid volume id
223 * @param[out] qry query response object
224 * @param[out] res SYNC response message
226 * @return operation status
227 * @retval SYNC_OK success
230 FSYNC_VGCQuery(char * part,
232 FSSYNC_VGQry_response_t * qry,
241 res->hdr.response_len = sizeof(res->hdr);
242 res->payload.buf = qry;
243 res->payload.len = sizeof(*qry);
245 return FSYNC_VolOp(volid, part, FSYNC_VG_QUERY, 0, res);
249 * perform an update operation on the VGC.
251 * @param[in] parent rw volume
252 * @param[in] child volume id to add
253 * @param[in] partition name of vice partition on which this VG resides
254 * @param[in] opcode FSSYNC VG cache opcode
255 * @param[in] reason FSSYNC reason code
256 * @param[out] res SYNC response message
258 * @return operation status
259 * @retval SYNC_OK success
264 _FSYNC_VGCUpdate(char * partition,
271 FSSYNC_VGUpdate_command_t vcom;
273 memset(&vcom, 0, sizeof(vcom));
275 vcom.parent = parent;
278 strlcpy(vcom.partName, partition, sizeof(vcom.partName));
280 return FSYNC_GenericOp(&vcom, sizeof(vcom), opcode, reason, res);
284 * Add volume to volume group cache.
286 * @param[in] parent rw volume
287 * @param[in] child volume id to add
288 * @param[in] partition name of vice partition on which this VG resides
289 * @param[in] reason FSSYNC reason code
290 * @param[out] res SYNC response message
292 * @return operation status
293 * @retval SYNC_OK success
296 FSYNC_VGCAdd(char * partition,
302 return _FSYNC_VGCUpdate(partition, parent, child, FSYNC_VG_ADD, reason, res);
306 * Delete volume from volume group cache.
308 * @param[in] parent rw volume
309 * @param[in] child volume id to add
310 * @param[in] partition name of vice partition on which this VG resides
311 * @param[in] reason FSSYNC reason code
312 * @param[out] res SYNC response message
314 * @return operation status
315 * @retval SYNC_OK success
318 FSYNC_VGCDel(char * partition,
324 return _FSYNC_VGCUpdate(partition, parent, child, FSYNC_VG_DEL, reason, res);
328 * perform an asynchronous volume group scan.
330 * @param[in] partition vice partition string
331 * @param[in] reason FSSYNC reason code
333 * @note if partition is NULL, all vice partitions will be scanned.
335 * @return operation status
336 * @retval SYNC_OK success
339 FSYNC_VGCScan(char * partition, int reason)
343 if (partition == NULL) {
344 command = FSYNC_VG_SCAN_ALL;
347 command = FSYNC_VG_SCAN;
350 return FSYNC_VolOp(0, partition, command, reason, NULL);
353 #endif /* FSSYNC_BUILD_CLIENT */