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);
155 FSYNC_GenericOp(void * ext_hdr, size_t ext_len,
156 int command, int reason,
157 SYNC_response * res_in)
159 SYNC_response res_l, *res;
166 res_l.payload.buf = NULL;
167 res_l.payload.len = 0;
170 memset(&com, 0, sizeof(com));
172 com.hdr.programType = programType;
173 com.hdr.command = command;
174 com.hdr.reason = reason;
175 com.hdr.command_len = sizeof(com.hdr) + ext_len;
176 com.payload.buf = ext_hdr;
177 com.payload.len = ext_len;
179 return FSYNC_askfs(&com, res);
183 FSYNC_VolOp(VolumeId volume, char * partition,
184 int command, int reason,
187 FSSYNC_VolOp_hdr vcom;
189 memset(&vcom, 0, sizeof(vcom));
191 vcom.volume = volume;
193 strlcpy(vcom.partName, partition, sizeof(vcom.partName));
195 return FSYNC_GenericOp(&vcom, sizeof(vcom), command, reason, res);
199 FSYNC_StatsOp(FSSYNC_StatsOp_hdr * scom, int command, int reason,
202 return FSYNC_GenericOp(scom, sizeof(*scom), command, reason, res);
206 #endif /* FSSYNC_BUILD_CLIENT */