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
18 #ifndef AFS_PTHREAD_ENV
19 #define USUAL_PRIORITY (LWP_MAX_PRIORITY - 2)
22 * stack size increased from 8K because the HP machine seemed to have trouble
23 * with the smaller stack
25 #define USUAL_STACK_SIZE (24 * 1024)
26 #endif /* !AFS_PTHREAD_ENV */
30 File server synchronization with external volume utilities.
31 server-side implementation
34 /* This controls the size of an fd_set; it must be defined early before
35 * the system headers define that type and the macros that operate on it.
36 * Its value should be as large as the maximum file descriptor limit we
37 * are likely to run into on any platform. Right now, that is 65536
38 * which is the default hard fd limit on Solaris 9 */
40 #define FD_SETSIZE 65536
43 #include <afsconfig.h>
44 #include <afs/param.h>
47 #include <sys/types.h>
53 #include <sys/param.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
61 #ifdef AFS_PTHREAD_ENV
63 #else /* AFS_PTHREAD_ENV */
64 #include <afs/assert.h>
65 #endif /* AFS_PTHREAD_ENV */
70 #include <afs/afsint.h>
72 #include <afs/errors.h>
73 #include "daemon_com.h"
77 #include <afs/afssyscalls.h>
81 #include "volume_inline.h"
82 #include "partition.h"
86 #endif /* HAVE_POLL */
88 #ifdef USE_UNIX_SOCKETS
90 #include <afs/afsutil.h>
91 #endif /* USE_UNIX_SOCKETS */
93 #ifdef FSSYNC_BUILD_SERVER
95 /*@printflike@*/ extern void Log(const char *format, ...);
97 int (*V_BreakVolumeCallbacks) (VolumeId volume);
99 #define MAXHANDLERS 4 /* Up to 4 clients; must be at least 2, so that
100 * move = dump+restore can run on single server */
101 #define MAXOFFLINEVOLUMES 128 /* This needs to be as big as the maximum
102 * number that would be offline for 1 operation.
103 * Current winner is salvage, which needs all
104 * cloned read-only copies offline when salvaging
105 * a single read-write volume */
109 static struct offlineInfo OfflineVolumes[MAXHANDLERS][MAXOFFLINEVOLUMES];
112 * fssync server socket handle.
114 static SYNC_server_state_t fssync_server_state =
115 { -1, /* file descriptor */
116 FSSYNC_ENDPOINT_DECL, /* server endpoint */
117 FSYNC_PROTO_VERSION, /* protocol version */
118 5, /* bind() retry limit */
119 100, /* listen() queue depth */
120 "FSSYNC", /* protocol name string */
124 /* Forward declarations */
125 static void * FSYNC_sync(void *);
126 static void FSYNC_newconnection(osi_socket afd);
127 static void FSYNC_com(osi_socket fd);
128 static void FSYNC_Drop(osi_socket fd);
129 static void AcceptOn(void);
130 static void AcceptOff(void);
131 static void InitHandler(void);
132 static int AddHandler(osi_socket fd, void (*aproc)(osi_socket));
133 static int FindHandler(osi_socket afd);
134 static int FindHandler_r(osi_socket afd);
135 static int RemoveHandler(osi_socket afd);
136 #if defined(HAVE_POLL) && defined (AFS_PTHREAD_ENV)
137 static void CallHandler(struct pollfd *fds, int nfds, int mask);
138 static void GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds);
140 static void CallHandler(fd_set * fdsetp);
141 static void GetHandler(fd_set * fdsetp, int *maxfdp);
145 static afs_int32 FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res);
147 #ifdef AFS_DEMAND_ATTACH_FS
148 static afs_int32 FSYNC_com_VolError(FSSYNC_VolOp_command * com, SYNC_response * res);
150 static afs_int32 FSYNC_com_VolOn(FSSYNC_VolOp_command * com, SYNC_response * res);
151 static afs_int32 FSYNC_com_VolOff(FSSYNC_VolOp_command * com, SYNC_response * res);
152 static afs_int32 FSYNC_com_VolMove(FSSYNC_VolOp_command * com, SYNC_response * res);
153 static afs_int32 FSYNC_com_VolBreakCBKs(FSSYNC_VolOp_command * com, SYNC_response * res);
154 static afs_int32 FSYNC_com_VolDone(FSSYNC_VolOp_command * com, SYNC_response * res);
155 static afs_int32 FSYNC_com_VolQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
156 static afs_int32 FSYNC_com_VolHdrQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
157 #ifdef AFS_DEMAND_ATTACH_FS
158 static afs_int32 FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
159 #endif /* AFS_DEMAND_ATTACH_FS */
161 static afs_int32 FSYNC_com_VnQry(osi_socket fd, SYNC_command * com, SYNC_response * res);
163 static afs_int32 FSYNC_com_StatsOp(osi_socket fd, SYNC_command * com, SYNC_response * res);
165 static afs_int32 FSYNC_com_StatsOpGeneral(FSSYNC_StatsOp_command * scom, SYNC_response * res);
167 #ifdef AFS_DEMAND_ATTACH_FS
168 static afs_int32 FSYNC_com_StatsOpViceP(FSSYNC_StatsOp_command * scom, SYNC_response * res);
169 static afs_int32 FSYNC_com_StatsOpHash(FSSYNC_StatsOp_command * scom, SYNC_response * res);
170 static afs_int32 FSYNC_com_StatsOpHdr(FSSYNC_StatsOp_command * scom, SYNC_response * res);
171 static afs_int32 FSYNC_com_StatsOpVLRU(FSSYNC_StatsOp_command * scom, SYNC_response * res);
174 static void FSYNC_com_to_info(FSSYNC_VolOp_command * vcom, FSSYNC_VolOp_info * info);
176 static int FSYNC_partMatch(FSSYNC_VolOp_command * vcom, Volume * vp, int match_anon);
180 * This lock controls access to the handler array. The overhead
181 * is minimal in non-preemptive environments.
183 struct Lock FSYNC_handler_lock;
188 #ifdef AFS_PTHREAD_ENV
190 pthread_attr_t tattr;
191 #else /* AFS_PTHREAD_ENV */
193 #endif /* AFS_PTHREAD_ENV */
195 Lock_Init(&FSYNC_handler_lock);
197 #ifdef AFS_PTHREAD_ENV
198 assert(pthread_attr_init(&tattr) == 0);
199 assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
200 assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0);
201 #else /* AFS_PTHREAD_ENV */
202 assert(LWP_CreateProcess
203 (FSYNC_sync, USUAL_STACK_SIZE, USUAL_PRIORITY, (void *)0,
204 "FSYNC_sync", &pid) == LWP_SUCCESS);
205 #endif /* AFS_PTHREAD_ENV */
208 #if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
209 static struct pollfd FSYNC_readfds[MAXHANDLERS];
211 static fd_set FSYNC_readfds;
216 FSYNC_sync(void * args)
220 #ifdef AFS_PTHREAD_ENV
223 SYNC_server_state_t * state = &fssync_server_state;
224 #ifdef AFS_DEMAND_ATTACH_FS
225 VThreadOptions_t * thread_opts;
229 * For non-DAFS, only wait until we begin attaching volumes (instead
230 * of waiting until all volumes are attached), since it can take
231 * awhile until VInit == 2.
234 #endif /* AFS_DEMAND_ATTACH_FS */
236 SYNC_getAddr(&state->endpoint, &state->addr);
237 SYNC_cleanupSock(state);
240 (void)signal(SIGPIPE, SIG_IGN);
243 #ifdef AFS_PTHREAD_ENV
244 /* set our 'thread-id' so that the host hold table works */
245 MUTEX_ENTER(&rx_stats_mutex); /* protects rxi_pthread_hinum */
246 tid = ++rxi_pthread_hinum;
247 MUTEX_EXIT(&rx_stats_mutex);
248 pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)tid);
249 Log("Set thread id %d for FSYNC_sync\n", tid);
250 #endif /* AFS_PTHREAD_ENV */
252 while (VInit < min_vinit) {
253 /* Let somebody else run until all volumes have been preattached
254 * (DAFS), or we have started attaching volumes (non-DAFS). This
255 * doesn't mean that all volumes have been attached.
257 #ifdef AFS_PTHREAD_ENV
259 #else /* AFS_PTHREAD_ENV */
260 LWP_DispatchProcess();
261 #endif /* AFS_PTHREAD_ENV */
263 state->fd = SYNC_getSock(&state->endpoint);
264 code = SYNC_bindSock(state);
267 #ifdef AFS_DEMAND_ATTACH_FS
269 * make sure the volume package is incapable of recursively executing
270 * salvsync calls on this thread, since there is a possibility of
273 thread_opts = malloc(sizeof(VThreadOptions_t));
274 if (thread_opts == NULL) {
275 Log("failed to allocate memory for thread-specific volume package options structure\n");
278 memcpy(thread_opts, &VThread_defaults, sizeof(VThread_defaults));
279 thread_opts->disallow_salvsync = 1;
280 assert(pthread_setspecific(VThread_key, thread_opts) == 0);
287 #if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
289 GetHandler(FSYNC_readfds, MAXHANDLERS, POLLIN|POLLPRI, &nfds);
290 if (poll(FSYNC_readfds, nfds, -1) >=1)
291 CallHandler(FSYNC_readfds, nfds, POLLIN|POLLPRI);
294 GetHandler(&FSYNC_readfds, &maxfd);
295 /* Note: check for >= 1 below is essential since IOMGR_select
296 * doesn't have exactly same semantics as select.
298 #ifdef AFS_PTHREAD_ENV
299 if (select(maxfd + 1, &FSYNC_readfds, NULL, NULL, NULL) >= 1)
300 #else /* AFS_PTHREAD_ENV */
301 if (IOMGR_Select(maxfd + 1, &FSYNC_readfds, NULL, NULL, NULL) >= 1)
302 #endif /* AFS_PTHREAD_ENV */
303 CallHandler(&FSYNC_readfds);
306 return NULL; /* hush now, little gcc */
310 FSYNC_newconnection(osi_socket afd)
312 #ifdef USE_UNIX_SOCKETS
313 struct sockaddr_un other;
314 #else /* USE_UNIX_SOCKETS */
315 struct sockaddr_in other;
319 junk = sizeof(other);
320 fd = accept(afd, (struct sockaddr *)&other, &junk);
322 Log("FSYNC_newconnection: accept failed, errno==%d\n", errno);
324 } else if (!AddHandler(fd, FSYNC_com)) {
326 assert(AddHandler(fd, FSYNC_com));
330 /* this function processes commands from an fssync file descriptor (fd) */
331 afs_int32 FS_cnt = 0;
333 FSYNC_com(osi_socket fd)
337 SYNC_PROTO_BUF_DECL(com_buf);
338 SYNC_PROTO_BUF_DECL(res_buf);
340 memset(&res.hdr, 0, sizeof(res.hdr));
342 com.payload.buf = (void *)com_buf;
343 com.payload.len = SYNC_PROTO_MAX_LEN;
344 res.hdr.response_len = sizeof(res.hdr);
345 res.payload.len = SYNC_PROTO_MAX_LEN;
346 res.payload.buf = (void *)res_buf;
349 if (SYNC_getCom(&fssync_server_state, fd, &com)) {
350 Log("FSYNC_com: read failed; dropping connection (cnt=%d)\n", FS_cnt);
355 if (com.recv_len < sizeof(com.hdr)) {
356 Log("FSSYNC_com: invalid protocol message length (%u)\n", com.recv_len);
357 res.hdr.response = SYNC_COM_ERROR;
358 res.hdr.reason = SYNC_REASON_MALFORMED_PACKET;
359 res.hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
363 if (com.hdr.proto_version != FSYNC_PROTO_VERSION) {
364 Log("FSYNC_com: invalid protocol version (%u)\n", com.hdr.proto_version);
365 res.hdr.response = SYNC_COM_ERROR;
366 res.hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
370 if (com.hdr.command == SYNC_COM_CHANNEL_CLOSE) {
371 res.hdr.response = SYNC_OK;
372 res.hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
374 /* don't respond, just drop; senders of SYNC_COM_CHANNEL_CLOSE
375 * never wait for a response. */
379 res.hdr.com_seq = com.hdr.com_seq;
382 switch (com.hdr.command) {
384 case FSYNC_VOL_ATTACH:
385 case FSYNC_VOL_LEAVE_OFF:
387 case FSYNC_VOL_FORCE_ERROR:
388 case FSYNC_VOL_LISTVOLUMES:
389 case FSYNC_VOL_NEEDVOLUME:
391 case FSYNC_VOL_BREAKCBKS:
393 case FSYNC_VOL_QUERY:
394 case FSYNC_VOL_QUERY_HDR:
395 case FSYNC_VOL_QUERY_VOP:
396 res.hdr.response = FSYNC_com_VolOp(fd, &com, &res);
398 case FSYNC_VOL_STATS_GENERAL:
399 case FSYNC_VOL_STATS_VICEP:
400 case FSYNC_VOL_STATS_HASH:
401 case FSYNC_VOL_STATS_HDR:
402 case FSYNC_VOL_STATS_VLRU:
403 res.hdr.response = FSYNC_com_StatsOp(fd, &com, &res);
405 case FSYNC_VOL_QUERY_VNODE:
406 res.hdr.response = FSYNC_com_VnQry(fd, &com, &res);
409 res.hdr.response = SYNC_BAD_COMMAND;
415 SYNC_putRes(&fssync_server_state, fd, &res);
418 if (res.hdr.flags & SYNC_FLAG_CHANNEL_SHUTDOWN) {
424 FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res)
427 afs_int32 code = SYNC_OK;
428 FSSYNC_VolOp_command vcom;
430 if (com->recv_len != (sizeof(com->hdr) + sizeof(FSSYNC_VolOp_hdr))) {
431 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
432 res->hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
433 return SYNC_COM_ERROR;
436 vcom.hdr = &com->hdr;
437 vcom.vop = (FSSYNC_VolOp_hdr *) com->payload.buf;
440 vcom.volumes = OfflineVolumes[FindHandler(fd)];
441 for (vcom.v = NULL, i = 0; i < MAXOFFLINEVOLUMES; i++) {
442 if ((vcom.volumes[i].volumeID == vcom.vop->volume) &&
443 (strncmp(vcom.volumes[i].partName, vcom.vop->partName,
444 sizeof(vcom.volumes[i].partName)) == 0)) {
445 vcom.v = &vcom.volumes[i];
450 switch (com->hdr.command) {
452 case FSYNC_VOL_ATTACH:
453 case FSYNC_VOL_LEAVE_OFF:
454 code = FSYNC_com_VolOn(&vcom, res);
457 case FSYNC_VOL_NEEDVOLUME:
458 code = FSYNC_com_VolOff(&vcom, res);
460 case FSYNC_VOL_LISTVOLUMES:
464 code = FSYNC_com_VolMove(&vcom, res);
466 case FSYNC_VOL_BREAKCBKS:
467 code = FSYNC_com_VolBreakCBKs(&vcom, res);
470 code = FSYNC_com_VolDone(&vcom, res);
472 case FSYNC_VOL_QUERY:
473 code = FSYNC_com_VolQuery(&vcom, res);
475 case FSYNC_VOL_QUERY_HDR:
476 code = FSYNC_com_VolHdrQuery(&vcom, res);
478 #ifdef AFS_DEMAND_ATTACH_FS
479 case FSYNC_VOL_FORCE_ERROR:
480 code = FSYNC_com_VolError(&vcom, res);
482 case FSYNC_VOL_QUERY_VOP:
483 code = FSYNC_com_VolOpQuery(&vcom, res);
485 #endif /* AFS_DEMAND_ATTACH_FS */
487 code = SYNC_BAD_COMMAND;
494 * service an FSYNC request to bring a volume online.
496 * @param[in] vcom pointer command object
497 * @param[out] res object in which to store response packet
499 * @return operation status
500 * @retval SYNC_OK volume transitioned online
501 * @retval SYNC_FAILED invalid command protocol message
502 * @retval SYNC_DENIED operation could not be completed
504 * @note this is an FSYNC RPC server stub
506 * @note this procedure handles the following FSSYNC command codes:
509 * - FSYNC_VOL_LEAVE_OFF
511 * @note the supplementary reason code contains additional details.
512 * When SYNC_DENIED is returned, the specific reason is
513 * placed in the response packet reason field.
518 FSYNC_com_VolOn(FSSYNC_VolOp_command * vcom, SYNC_response * res)
520 afs_int32 code = SYNC_OK;
521 #ifndef AFS_DEMAND_ATTACH_FS
522 char tvolName[VMAXPATHLEN];
527 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
528 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
533 /* so, we need to attach the volume */
535 #ifdef AFS_DEMAND_ATTACH_FS
536 /* check DAFS permissions */
537 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
539 FSYNC_partMatch(vcom, vp, 1) &&
540 vp->pending_vol_op &&
541 (vcom->hdr->programType != vp->pending_vol_op->com.programType)) {
542 /* a different program has this volume checked out. deny. */
543 Log("FSYNC_VolOn: WARNING: program type %u has attempted to manipulate "
544 "state for volume %u using command code %u while the volume is "
545 "checked out by program type %u for command code %u.\n",
546 vcom->hdr->programType,
549 vp->pending_vol_op->com.programType,
550 vp->pending_vol_op->com.command);
552 res->hdr.reason = FSYNC_EXCLUSIVE;
558 vcom->v->volumeID = 0;
561 if (vcom->hdr->command == FSYNC_VOL_LEAVE_OFF) {
562 /* nothing much to do if we're leaving the volume offline */
563 #ifdef AFS_DEMAND_ATTACH_FS
565 if (FSYNC_partMatch(vcom, vp, 1)) {
566 if ((V_attachState(vp) == VOL_STATE_UNATTACHED) ||
567 (V_attachState(vp) == VOL_STATE_PREATTACHED)) {
568 VChangeState_r(vp, VOL_STATE_UNATTACHED);
569 VDeregisterVolOp_r(vp);
572 res->hdr.reason = FSYNC_BAD_STATE;
576 res->hdr.reason = FSYNC_WRONG_PART;
580 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
586 #ifdef AFS_DEMAND_ATTACH_FS
587 /* first, check to see whether we have such a volume defined */
588 vp = VPreAttachVolumeById_r(&error,
592 VDeregisterVolOp_r(vp);
594 #else /* !AFS_DEMAND_ATTACH_FS */
596 snprintf(&tvolName[1], sizeof(tvolName)-1, VFORMAT, afs_printable_uint32_lu(vcom->vop->volume));
597 tvolName[sizeof(tvolName)-1] = '\0';
599 vp = VAttachVolumeByName_r(&error, vcom->vop->partName, tvolName,
605 res->hdr.reason = error;
607 #endif /* !AFS_DEMAND_ATTACH_FS */
614 * service an FSYNC request to take a volume offline.
616 * @param[in] vcom pointer command object
617 * @param[out] res object in which to store response packet
619 * @return operation status
620 * @retval SYNC_OK volume transitioned offline
621 * @retval SYNC_FAILED invalid command protocol message
622 * @retval SYNC_DENIED operation could not be completed
624 * @note this is an FSYNC RPC server stub
626 * @note this procedure handles the following FSSYNC command codes:
628 * - FSYNC_VOL_NEEDVOLUME
630 * @note the supplementary reason code contains additional details.
631 * When SYNC_DENIED is returned, the specific reason is
632 * placed in the response packet reason field.
637 FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
639 FSSYNC_VolOp_info info;
640 afs_int32 code = SYNC_OK;
644 #ifdef AFS_DEMAND_ATTACH_FS
648 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
649 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
654 /* not already offline, we need to find a slot for newly offline volume */
655 if (vcom->hdr->programType == debugUtility) {
656 /* debug utilities do not have their operations tracked */
660 for (i = 0; i < MAXOFFLINEVOLUMES; i++) {
661 if (vcom->volumes[i].volumeID == 0) {
662 vcom->v = &vcom->volumes[i];
672 FSYNC_com_to_info(vcom, &info);
674 #ifdef AFS_DEMAND_ATTACH_FS
675 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
677 vp = VGetVolume_r(&error, vcom->vop->volume);
681 if (!FSYNC_partMatch(vcom, vp, 1)) {
682 /* volume on desired partition is not online, so we
683 * should treat this as an offline volume.
685 #ifndef AFS_DEMAND_ATTACH_FS
693 #ifdef AFS_DEMAND_ATTACH_FS
695 ProgramType type = (ProgramType) vcom->hdr->programType;
697 /* do initial filtering of requests */
699 /* enforce mutual exclusion for volume ops */
700 if (vp->pending_vol_op) {
701 if (vp->pending_vol_op->com.programType != type) {
702 Log("volume %u already checked out\n", vp->hashid);
704 Log("vp->vop = { com = { ver=%u, prog=%d, com=%d, reason=%d, len=%u, flags=0x%x }, vop = { vol=%u, part='%s' } }\n",
705 vp->pending_vol_op->com.proto_version,
706 vp->pending_vol_op->com.programType,
707 vp->pending_vol_op->com.command,
708 vp->pending_vol_op->com.reason,
709 vp->pending_vol_op->com.command_len,
710 vp->pending_vol_op->com.flags,
711 vp->pending_vol_op->vop.volume,
712 vp->pending_vol_op->vop.partName );
713 Log("vcom = { com = { ver=%u, prog=%d, com=%d, reason=%d, len=%u, flags=0x%x } , vop = { vol=%u, part='%s' } }\n",
714 vcom->hdr->proto_version,
715 vcom->hdr->programType,
718 vcom->hdr->command_len,
721 vcom->vop->partName);
722 res->hdr.reason = FSYNC_EXCLUSIVE;
725 Log("warning: volume %u recursively checked out by programType id %d\n",
726 vp->hashid, vcom->hdr->programType);
730 /* filter based upon requestor
732 * volume utilities are not allowed to check out volumes
733 * which are in an error state
735 * unknown utility programs will be denied on principal
739 /* it is possible for the salvageserver to checkout a
740 * volume for salvage before its scheduling request
741 * has been sent to the salvageserver */
742 if (vp->salvage.requested && !vp->salvage.scheduled) {
743 vp->salvage.scheduled = 1;
749 if (VIsErrorState(V_attachState(vp))) {
752 if (vp->salvage.requested) {
758 Log("bad program type passed to FSSYNC\n");
762 /* short circuit for offline volume states
763 * so we can avoid I/O penalty of attachment */
764 switch (V_attachState(vp)) {
765 case VOL_STATE_UNATTACHED:
766 case VOL_STATE_PREATTACHED:
767 case VOL_STATE_SALVAGING:
768 case VOL_STATE_ERROR:
769 /* register the volume operation metadata with the volume
771 * if the volume is currently pre-attached, attach2()
772 * will evaluate the vol op metadata to determine whether
773 * attaching the volume would be safe */
774 VRegisterVolOp_r(vp, &info);
775 vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningUnknown;
781 /* convert to heavyweight ref */
782 nvp = VGetVolumeByVp_r(&error, vp);
785 Log("FSYNC_com_VolOff: failed to get heavyweight reference to volume %u\n",
787 res->hdr.reason = FSYNC_VOL_PKG_ERROR;
789 } else if (nvp != vp) {
790 /* i don't think this should ever happen, but just in case... */
791 Log("FSYNC_com_VolOff: warning: potentially dangerous race detected\n");
795 /* register the volume operation metadata with the volume */
796 VRegisterVolOp_r(vp, &info);
799 #endif /* AFS_DEMAND_ATTACH_FS */
802 if (VVolOpLeaveOnline_r(vp, &info)) {
803 VUpdateVolume_r(&error, vp, VOL_UPDATE_WAIT); /* At least get volume stats right */
805 Log("FSYNC: Volume %u (%s) was left on line for an external %s request\n",
806 V_id(vp), V_name(vp),
807 vcom->hdr->reason == V_CLONE ? "clone" :
808 vcom->hdr->reason == V_READONLY ? "readonly" :
809 vcom->hdr->reason == V_DUMP ? "dump" :
812 #ifdef AFS_DEMAND_ATTACH_FS
813 vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOnline;
817 if (VVolOpSetVBusy_r(vp, &info)) {
818 vp->specialStatus = VBUSY;
821 /* remember what volume we got, so we can keep track of how
822 * many volumes the volserver or whatever is using. Note that
823 * vp is valid since leaveonline is only set when vp is valid.
826 vcom->v->volumeID = vcom->vop->volume;
827 strlcpy(vcom->v->partName, vp->partition->name, sizeof(vcom->v->partName));
830 #ifdef AFS_DEMAND_ATTACH_FS
831 VOfflineForVolOp_r(&error, vp, "A volume utility is running.");
833 assert(vp->nUsers==0);
834 vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOffline;
837 VDeregisterVolOp_r(vp);
841 VOffline_r(vp, "A volume utility is running.");
855 * service an FSYNC request to mark a volume as moved.
857 * @param[in] vcom pointer command object
858 * @param[out] res object in which to store response packet
860 * @return operation status
861 * @retval SYNC_OK volume marked as moved to a remote server
862 * @retval SYNC_FAILED invalid command protocol message
863 * @retval SYNC_DENIED current volume state does not permit this operation
865 * @note this is an FSYNC RPC server stub
867 * @note this operation also breaks all callbacks for the given volume
869 * @note this procedure handles the following FSSYNC command codes:
872 * @note the supplementary reason code contains additional details. For
873 * instance, SYNC_OK is still returned when the partition specified
874 * does not match the one registered in the volume object -- reason
875 * will be FSYNC_WRONG_PART in this case.
880 FSYNC_com_VolMove(FSSYNC_VolOp_command * vcom, SYNC_response * res)
882 afs_int32 code = SYNC_DENIED;
886 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
887 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
892 /* Yuch: the "reason" for the move is the site it got moved to... */
893 /* still set specialStatus so we stop sending back VBUSY.
894 * also should still break callbacks. Note that I don't know
895 * how to tell if we should break all or not, so we just do it
896 * since it doesn't matter much if we do an extra break
897 * volume callbacks on a volume move within the same server */
898 #ifdef AFS_DEMAND_ATTACH_FS
899 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
901 vp = VGetVolume_r(&error, vcom->vop->volume);
904 if (FSYNC_partMatch(vcom, vp, 1)) {
905 #ifdef AFS_DEMAND_ATTACH_FS
906 if ((V_attachState(vp) == VOL_STATE_UNATTACHED) ||
907 (V_attachState(vp) == VOL_STATE_PREATTACHED)) {
910 vp->specialStatus = VMOVED;
911 #ifdef AFS_DEMAND_ATTACH_FS
913 res->hdr.reason = FSYNC_BAD_STATE;
917 res->hdr.reason = FSYNC_WRONG_PART;
919 #ifndef AFS_DEMAND_ATTACH_FS
921 #endif /* !AFS_DEMAND_ATTACH_FS */
923 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
926 if ((code == SYNC_OK) && (V_BreakVolumeCallbacks != NULL)) {
927 Log("fssync: volume %u moved to %x; breaking all call backs\n",
928 vcom->vop->volume, vcom->hdr->reason);
930 (*V_BreakVolumeCallbacks) (vcom->vop->volume);
940 * service an FSYNC request to mark a volume as destroyed.
942 * @param[in] vcom pointer command object
943 * @param[out] res object in which to store response packet
945 * @return operation status
946 * @retval SYNC_OK volume marked as destroyed
947 * @retval SYNC_FAILED invalid command protocol message
948 * @retval SYNC_DENIED current volume state does not permit this operation
950 * @note this is an FSYNC RPC server stub
952 * @note this procedure handles the following FSSYNC command codes:
955 * @note the supplementary reason code contains additional details. For
956 * instance, SYNC_OK is still returned when the partition specified
957 * does not match the one registered in the volume object -- reason
958 * will be FSYNC_WRONG_PART in this case.
963 FSYNC_com_VolDone(FSSYNC_VolOp_command * vcom, SYNC_response * res)
965 afs_int32 code = SYNC_FAILED;
966 #ifdef AFS_DEMAND_ATTACH_FS
971 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
972 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
976 /* don't try to put online, this call is made only after deleting
977 * a volume, in which case we want to remove the vol # from the
978 * OfflineVolumes array only */
980 vcom->v->volumeID = 0;
982 #ifdef AFS_DEMAND_ATTACH_FS
983 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
985 if (FSYNC_partMatch(vcom, vp, 1)) {
986 if ((V_attachState(vp) == VOL_STATE_UNATTACHED) ||
987 (V_attachState(vp) == VOL_STATE_PREATTACHED)) {
988 VChangeState_r(vp, VOL_STATE_UNATTACHED);
989 VDeregisterVolOp_r(vp);
993 res->hdr.reason = FSYNC_BAD_STATE;
996 code = SYNC_OK; /* XXX is this really a good idea? */
997 res->hdr.reason = FSYNC_WRONG_PART;
1000 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1008 #ifdef AFS_DEMAND_ATTACH_FS
1010 * service an FSYNC request to transition a volume to the hard error state.
1012 * @param[in] vcom pointer command object
1013 * @param[out] res object in which to store response packet
1015 * @return operation status
1016 * @retval SYNC_OK volume transitioned to hard error state
1017 * @retval SYNC_FAILED invalid command protocol message
1018 * @retval SYNC_DENIED (see note)
1020 * @note this is an FSYNC RPC server stub
1022 * @note this procedure handles the following FSSYNC command codes:
1023 * - FSYNC_VOL_FORCE_ERROR
1025 * @note SYNC_DENIED is returned in the following cases:
1026 * - no partition name is specified (reason field set to
1027 * FSYNC_WRONG_PART).
1028 * - volume id not known to fileserver (reason field set
1029 * to FSYNC_UNKNOWN_VOLID).
1031 * @note demand attach fileserver only
1036 FSYNC_com_VolError(FSSYNC_VolOp_command * vcom, SYNC_response * res)
1040 afs_int32 code = SYNC_FAILED;
1042 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
1043 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1047 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
1049 if (FSYNC_partMatch(vcom, vp, 0)) {
1050 /* null out salvsync control state, as it's no longer relevant */
1051 memset(&vp->salvage, 0, sizeof(vp->salvage));
1052 VChangeState_r(vp, VOL_STATE_ERROR);
1055 res->hdr.reason = FSYNC_WRONG_PART;
1058 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1064 #endif /* AFS_DEMAND_ATTACH_FS */
1067 * service an FSYNC request to break all callbacks for this volume.
1069 * @param[in] vcom pointer command object
1070 * @param[out] res object in which to store response packet
1072 * @return operation status
1073 * @retval SYNC_OK callback breaks scheduled for volume
1075 * @note this is an FSYNC RPC server stub
1077 * @note this procedure handles the following FSSYNC command codes:
1078 * - FSYNC_VOL_BREAKCBKS
1080 * @note demand attach fileserver only
1082 * @todo should do partition matching
1087 FSYNC_com_VolBreakCBKs(FSSYNC_VolOp_command * vcom, SYNC_response * res)
1089 /* if the volume is being restored, break all callbacks on it */
1090 if (V_BreakVolumeCallbacks) {
1091 Log("fssync: breaking all call backs for volume %u\n",
1094 (*V_BreakVolumeCallbacks) (vcom->vop->volume);
1101 * service an FSYNC request to return the Volume object.
1103 * @param[in] vcom pointer command object
1104 * @param[out] res object in which to store response packet
1106 * @return operation status
1107 * @retval SYNC_OK volume object returned to caller
1108 * @retval SYNC_FAILED bad command packet, or failed to locate volume object
1110 * @note this is an FSYNC RPC server stub
1112 * @note this procedure handles the following FSSYNC command codes:
1118 FSYNC_com_VolQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
1120 afs_int32 code = SYNC_FAILED;
1124 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
1125 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1129 #ifdef AFS_DEMAND_ATTACH_FS
1130 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
1131 #else /* !AFS_DEMAND_ATTACH_FS */
1132 vp = VGetVolume_r(&error, vcom->vop->volume);
1133 #endif /* !AFS_DEMAND_ATTACH_FS */
1136 if (FSYNC_partMatch(vcom, vp, 1)) {
1137 if (res->payload.len >= sizeof(Volume)) {
1138 memcpy(res->payload.buf, vp, sizeof(Volume));
1139 res->hdr.response_len += sizeof(Volume);
1142 res->hdr.reason = SYNC_REASON_PAYLOAD_TOO_BIG;
1145 res->hdr.reason = FSYNC_WRONG_PART;
1147 #ifndef AFS_DEMAND_ATTACH_FS
1151 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1159 * service an FSYNC request to return the Volume header.
1161 * @param[in] vcom pointer command object
1162 * @param[out] res object in which to store response packet
1164 * @return operation status
1165 * @retval SYNC_OK volume header returned to caller
1166 * @retval SYNC_FAILED bad command packet, or failed to locate volume header
1168 * @note this is an FSYNC RPC server stub
1170 * @note this procedure handles the following FSSYNC command codes:
1171 * - FSYNC_VOL_QUERY_HDR
1176 FSYNC_com_VolHdrQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
1178 afs_int32 code = SYNC_FAILED;
1182 if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
1183 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1186 if (res->payload.len < sizeof(VolumeDiskData)) {
1187 res->hdr.reason = SYNC_REASON_PAYLOAD_TOO_BIG;
1191 #ifdef AFS_DEMAND_ATTACH_FS
1192 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
1193 #else /* !AFS_DEMAND_ATTACH_FS */
1194 vp = VGetVolume_r(&error, vcom->vop->volume);
1198 if (FSYNC_partMatch(vcom, vp, 1)) {
1199 #ifdef AFS_DEMAND_ATTACH_FS
1200 if ((vp->header == NULL) ||
1201 !(V_attachFlags(vp) & VOL_HDR_ATTACHED) ||
1202 !(V_attachFlags(vp) & VOL_HDR_LOADED)) {
1203 res->hdr.reason = FSYNC_HDR_NOT_ATTACHED;
1206 #else /* !AFS_DEMAND_ATTACH_FS */
1207 if (!vp || !vp->header) {
1208 res->hdr.reason = FSYNC_HDR_NOT_ATTACHED;
1211 #endif /* !AFS_DEMAND_ATTACH_FS */
1213 res->hdr.reason = FSYNC_WRONG_PART;
1217 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1221 memcpy(res->payload.buf, &V_disk(vp), sizeof(VolumeDiskData));
1222 res->hdr.response_len += sizeof(VolumeDiskData);
1226 #ifndef AFS_DEMAND_ATTACH_FS
1234 #ifdef AFS_DEMAND_ATTACH_FS
1236 FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
1238 afs_int32 code = SYNC_OK;
1242 vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
1244 if (vp && vp->pending_vol_op) {
1245 assert(sizeof(FSSYNC_VolOp_info) <= res->payload.len);
1246 memcpy(res->payload.buf, vp->pending_vol_op, sizeof(FSSYNC_VolOp_info));
1247 res->hdr.response_len += sizeof(FSSYNC_VolOp_info);
1250 res->hdr.reason = FSYNC_NO_PENDING_VOL_OP;
1252 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1258 #endif /* AFS_DEMAND_ATTACH_FS */
1261 FSYNC_com_VnQry(osi_socket fd, SYNC_command * com, SYNC_response * res)
1263 afs_int32 code = SYNC_OK;
1264 FSSYNC_VnQry_hdr * qry = com->payload.buf;
1269 if (com->recv_len != (sizeof(com->hdr) + sizeof(FSSYNC_VnQry_hdr))) {
1270 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1271 res->hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
1272 return SYNC_COM_ERROR;
1275 #ifdef AFS_DEMAND_ATTACH_FS
1276 vp = VLookupVolume_r(&error, qry->volume, NULL);
1277 #else /* !AFS_DEMAND_ATTACH_FS */
1278 vp = VGetVolume_r(&error, qry->volume);
1279 #endif /* !AFS_DEMAND_ATTACH_FS */
1282 res->hdr.reason = FSYNC_UNKNOWN_VOLID;
1287 vnp = VLookupVnode(vp, qry->vnode);
1289 res->hdr.reason = FSYNC_UNKNOWN_VNID;
1294 if (Vn_class(vnp)->residentSize > res->payload.len) {
1295 res->hdr.reason = SYNC_REASON_ENCODING_ERROR;
1300 memcpy(res->payload.buf, vnp, Vn_class(vnp)->residentSize);
1301 res->hdr.response_len += Vn_class(vnp)->residentSize;
1304 #ifndef AFS_DEMAND_ATTACH_FS
1313 FSYNC_com_StatsOp(osi_socket fd, SYNC_command * com, SYNC_response * res)
1315 afs_int32 code = SYNC_OK;
1316 FSSYNC_StatsOp_command scom;
1318 if (com->recv_len != (sizeof(com->hdr) + sizeof(FSSYNC_StatsOp_hdr))) {
1319 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1320 res->hdr.flags |= SYNC_FLAG_CHANNEL_SHUTDOWN;
1321 return SYNC_COM_ERROR;
1324 scom.hdr = &com->hdr;
1325 scom.sop = (FSSYNC_StatsOp_hdr *) com->payload.buf;
1328 switch (com->hdr.command) {
1329 case FSYNC_VOL_STATS_GENERAL:
1330 code = FSYNC_com_StatsOpGeneral(&scom, res);
1332 #ifdef AFS_DEMAND_ATTACH_FS
1333 /* statistics for the following subsystems are only tracked
1334 * for demand attach fileservers */
1335 case FSYNC_VOL_STATS_VICEP:
1336 code = FSYNC_com_StatsOpViceP(&scom, res);
1338 case FSYNC_VOL_STATS_HASH:
1339 code = FSYNC_com_StatsOpHash(&scom, res);
1341 case FSYNC_VOL_STATS_HDR:
1342 code = FSYNC_com_StatsOpHdr(&scom, res);
1344 case FSYNC_VOL_STATS_VLRU:
1345 code = FSYNC_com_StatsOpVLRU(&scom, res);
1347 #endif /* AFS_DEMAND_ATTACH_FS */
1349 code = SYNC_BAD_COMMAND;
1356 FSYNC_com_StatsOpGeneral(FSSYNC_StatsOp_command * scom, SYNC_response * res)
1358 afs_int32 code = SYNC_OK;
1360 memcpy(res->payload.buf, &VStats, sizeof(VStats));
1361 res->hdr.response_len += sizeof(VStats);
1366 #ifdef AFS_DEMAND_ATTACH_FS
1368 FSYNC_com_StatsOpViceP(FSSYNC_StatsOp_command * scom, SYNC_response * res)
1370 afs_int32 code = SYNC_OK;
1371 struct DiskPartition64 * dp;
1372 struct DiskPartitionStats64 * stats;
1374 if (SYNC_verifyProtocolString(scom->sop->args.partName, sizeof(scom->sop->args.partName))) {
1375 res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
1380 dp = VGetPartition_r(scom->sop->args.partName, 0);
1384 stats = (struct DiskPartitionStats64 *) res->payload.buf;
1385 stats->free = dp->free;
1386 stats->totalUsable = dp->totalUsable;
1387 stats->minFree = dp->minFree;
1388 stats->f_files = dp->f_files;
1389 stats->vol_list_len = dp->vol_list.len;
1391 res->hdr.response_len += sizeof(struct DiskPartitionStats64);
1399 FSYNC_com_StatsOpHash(FSSYNC_StatsOp_command * scom, SYNC_response * res)
1401 afs_int32 code = SYNC_OK;
1402 struct VolumeHashChainStats * stats;
1403 struct VolumeHashChainHead * head;
1405 if (scom->sop->args.hash_bucket >= VolumeHashTable.Size) {
1409 head = &VolumeHashTable.Table[scom->sop->args.hash_bucket];
1410 stats = (struct VolumeHashChainStats *) res->payload.buf;
1411 stats->table_size = VolumeHashTable.Size;
1412 stats->chain_len = head->len;
1413 stats->chain_cacheCheck = head->cacheCheck;
1414 stats->chain_busy = head->busy;
1415 AssignInt64(head->looks, &stats->chain_looks);
1416 AssignInt64(head->gets, &stats->chain_gets);
1417 AssignInt64(head->reorders, &stats->chain_reorders);
1419 res->hdr.response_len += sizeof(struct VolumeHashChainStats);
1425 FSYNC_com_StatsOpHdr(FSSYNC_StatsOp_command * scom, SYNC_response * res)
1427 afs_int32 code = SYNC_OK;
1429 memcpy(res->payload.buf, &volume_hdr_LRU.stats, sizeof(volume_hdr_LRU.stats));
1430 res->hdr.response_len += sizeof(volume_hdr_LRU.stats);
1436 FSYNC_com_StatsOpVLRU(FSSYNC_StatsOp_command * scom, SYNC_response * res)
1438 afs_int32 code = SYNC_OK;
1440 code = SYNC_BAD_COMMAND;
1444 #endif /* AFS_DEMAND_ATTACH_FS */
1447 * populate an FSSYNC_VolOp_info object from a command packet object.
1449 * @param[in] vcom pointer to command packet
1450 * @param[out] info pointer to info object which will be populated
1452 * @note FSSYNC_VolOp_info objects are attached to Volume objects when
1453 * a volume operation is commenced.
1458 FSYNC_com_to_info(FSSYNC_VolOp_command * vcom, FSSYNC_VolOp_info * info)
1460 memcpy(&info->com, vcom->hdr, sizeof(SYNC_command_hdr));
1461 memcpy(&info->vop, vcom->vop, sizeof(FSSYNC_VolOp_hdr));
1462 info->vol_op_state = FSSYNC_VolOpPending;
1466 * check whether command packet partition name matches volume
1467 * object's partition name.
1469 * @param[in] vcom pointer to command packet
1470 * @param[in] vp pointer to volume object
1471 * @param[in] match_anon anon matching control flag (see note below)
1473 * @return whether partitions match
1474 * @retval 0 partitions do NOT match
1475 * @retval 1 partitions match
1477 * @note if match_anon is non-zero, then this function will return a
1478 * positive match for a zero-length partition string in the
1484 FSYNC_partMatch(FSSYNC_VolOp_command * vcom, Volume * vp, int match_anon)
1486 return ((match_anon && vcom->vop->partName[0] == 0) ||
1487 (strncmp(vcom->vop->partName, V_partition(vp)->name,
1488 sizeof(vcom->vop->partName)) == 0));
1493 FSYNC_Drop(osi_socket fd)
1495 struct offlineInfo *p;
1498 char tvolName[VMAXPATHLEN];
1501 p = OfflineVolumes[FindHandler(fd)];
1502 for (i = 0; i < MAXOFFLINEVOLUMES; i++) {
1503 if (p[i].volumeID) {
1508 sprintf(&tvolName[1], VFORMAT, afs_printable_uint32_lu(p[i].volumeID));
1509 vp = VAttachVolumeByName_r(&error, p[i].partName, tvolName,
1526 static int AcceptHandler = -1; /* handler id for accept, if turned on */
1531 if (AcceptHandler == -1) {
1532 assert(AddHandler(fssync_server_state.fd, FSYNC_newconnection));
1533 AcceptHandler = FindHandler(fssync_server_state.fd);
1540 if (AcceptHandler != -1) {
1541 assert(RemoveHandler(fssync_server_state.fd));
1546 /* The multiple FD handling code. */
1548 static osi_socket HandlerFD[MAXHANDLERS];
1549 static void (*HandlerProc[MAXHANDLERS]) (osi_socket);
1555 ObtainWriteLock(&FSYNC_handler_lock);
1556 for (i = 0; i < MAXHANDLERS; i++) {
1560 ReleaseWriteLock(&FSYNC_handler_lock);
1563 #if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
1565 CallHandler(struct pollfd *fds, int nfds, int mask)
1569 ObtainReadLock(&FSYNC_handler_lock);
1570 for (i = 0; i < nfds; i++) {
1571 if (fds[i].revents & mask) {
1572 handler = FindHandler_r(fds[i].fd);
1573 ReleaseReadLock(&FSYNC_handler_lock);
1574 (*HandlerProc[handler]) (fds[i].fd);
1575 ObtainReadLock(&FSYNC_handler_lock);
1578 ReleaseReadLock(&FSYNC_handler_lock);
1582 CallHandler(fd_set * fdsetp)
1585 ObtainReadLock(&FSYNC_handler_lock);
1586 for (i = 0; i < MAXHANDLERS; i++) {
1587 if (HandlerFD[i] >= 0 && FD_ISSET(HandlerFD[i], fdsetp)) {
1588 ReleaseReadLock(&FSYNC_handler_lock);
1589 (*HandlerProc[i]) (HandlerFD[i]);
1590 ObtainReadLock(&FSYNC_handler_lock);
1593 ReleaseReadLock(&FSYNC_handler_lock);
1598 AddHandler(osi_socket afd, void (*aproc) (osi_socket))
1601 ObtainWriteLock(&FSYNC_handler_lock);
1602 for (i = 0; i < MAXHANDLERS; i++)
1603 if (HandlerFD[i] == -1)
1605 if (i >= MAXHANDLERS) {
1606 ReleaseWriteLock(&FSYNC_handler_lock);
1610 HandlerProc[i] = aproc;
1611 ReleaseWriteLock(&FSYNC_handler_lock);
1616 FindHandler(register osi_socket afd)
1619 ObtainReadLock(&FSYNC_handler_lock);
1620 for (i = 0; i < MAXHANDLERS; i++)
1621 if (HandlerFD[i] == afd) {
1622 ReleaseReadLock(&FSYNC_handler_lock);
1625 ReleaseReadLock(&FSYNC_handler_lock); /* just in case */
1627 return -1; /* satisfy compiler */
1631 FindHandler_r(register osi_socket afd)
1634 for (i = 0; i < MAXHANDLERS; i++)
1635 if (HandlerFD[i] == afd) {
1639 return -1; /* satisfy compiler */
1643 RemoveHandler(register osi_socket afd)
1645 ObtainWriteLock(&FSYNC_handler_lock);
1646 HandlerFD[FindHandler_r(afd)] = -1;
1647 ReleaseWriteLock(&FSYNC_handler_lock);
1651 #if defined(HAVE_POLL) && defined(AFS_PTHREAD_ENV)
1653 GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds)
1657 ObtainReadLock(&FSYNC_handler_lock);
1658 for (i = 0; i < MAXHANDLERS; i++)
1659 if (HandlerFD[i] != -1) {
1661 fds[fdi].fd = HandlerFD[i];
1662 fds[fdi].events = events;
1663 fds[fdi].revents = 0;
1667 ReleaseReadLock(&FSYNC_handler_lock);
1671 GetHandler(fd_set * fdsetp, int *maxfdp)
1674 register int maxfd = -1;
1676 ObtainReadLock(&FSYNC_handler_lock); /* just in case */
1677 for (i = 0; i < MAXHANDLERS; i++)
1678 if (HandlerFD[i] != -1) {
1679 FD_SET(HandlerFD[i], fdsetp);
1680 #ifndef AFS_NT40_ENV
1681 /* On Windows the nfds parameter to select() is ignored */
1682 if (maxfd < HandlerFD[i] || maxfd == (int)-1)
1683 maxfd = HandlerFD[i];
1684 #endif /* AFS_NT40_ENV */
1687 ReleaseReadLock(&FSYNC_handler_lock); /* just in case */
1689 #endif /* HAVE_POLL && AFS_PTHREAD_ENV */
1691 #endif /* FSSYNC_BUILD_SERVER */