vol: Use OSI_NULLSOCKET and not -1 to indicate invalid fssync fd
[openafs.git] / src / vol / fssync-server.c
index 3f9578e..acd2e6c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
 #include <unistd.h>
 #endif
 #include <errno.h>
-#ifdef AFS_PTHREAD_ENV
-#include <assert.h>
-#else /* AFS_PTHREAD_ENV */
-#include <afs/assert.h>
-#endif /* AFS_PTHREAD_ENV */
+#include <afs/afs_assert.h>
 #include <signal.h>
 #include <string.h>
 
@@ -74,7 +70,9 @@
 #include "nfs.h"
 #include <afs/errors.h>
 #include "daemon_com.h"
+#include "daemon_com_inline.h"
 #include "fssync.h"
+#include "fssync_inline.h"
 #include "salvsync.h"
 #include "lwp.h"
 #include "lock.h"
@@ -85,6 +83,7 @@
 #include "volume_inline.h"
 #include "partition.h"
 #include "vg_cache.h"
+#include "common.h"
 
 #ifdef HAVE_POLL
 #include <sys/poll.h>
@@ -97,8 +96,6 @@
 
 #ifdef FSSYNC_BUILD_SERVER
 
-/*@printflike@*/ extern void Log(const char *format, ...);
-
 int (*V_BreakVolumeCallbacks) (VolumeId volume);
 
 #define MAXHANDLERS    4       /* Up to 4 clients; must be at least 2, so that
@@ -116,8 +113,8 @@ static struct offlineInfo OfflineVolumes[MAXHANDLERS][MAXOFFLINEVOLUMES];
 /**
  * fssync server socket handle.
  */
-static SYNC_server_state_t fssync_server_state = 
-    { -1,                       /* file descriptor */
+static SYNC_server_state_t fssync_server_state =
+    { OSI_NULLSOCKET,                       /* file descriptor */
       FSSYNC_ENDPOINT_DECL,     /* server endpoint */
       FSYNC_PROTO_VERSION,      /* protocol version */
       5,                        /* bind() retry limit */
@@ -177,9 +174,9 @@ static afs_int32 FSYNC_com_VolDone(FSSYNC_VolOp_command * com, SYNC_response * r
 static afs_int32 FSYNC_com_VolQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
 static afs_int32 FSYNC_com_VolHdrQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
 #ifdef AFS_DEMAND_ATTACH_FS
+static afs_int32 FSYNC_com_VGUpdate(osi_socket fd, SYNC_command * com, SYNC_response * res);
 static afs_int32 FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
 static afs_int32 FSYNC_com_VGQuery(FSSYNC_VolOp_command * com, SYNC_response * res);
-static afs_int32 FSYNC_com_VGUpdate(SYNC_command * com, SYNC_response * res);
 static afs_int32 FSYNC_com_VGScan(FSSYNC_VolOp_command * com, SYNC_response * res);
 static afs_int32 FSYNC_com_VGScanAll(FSSYNC_VolOp_command * com, SYNC_response * res);
 #endif /* AFS_DEMAND_ATTACH_FS */
@@ -221,19 +218,19 @@ FSYNC_fsInit(void)
     Lock_Init(&FSYNC_handler_lock);
 
 #ifdef AFS_PTHREAD_ENV
-    assert(pthread_attr_init(&tattr) == 0);
-    assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
-    assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0);
+    osi_Assert(pthread_attr_init(&tattr) == 0);
+    osi_Assert(pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED) == 0);
+    osi_Assert(pthread_create(&tid, &tattr, FSYNC_sync, NULL) == 0);
 #else /* AFS_PTHREAD_ENV */
-    assert(LWP_CreateProcess
+    osi_Assert(LWP_CreateProcess
           (FSYNC_sync, USUAL_STACK_SIZE, USUAL_PRIORITY, (void *)0,
            "FSYNC_sync", &pid) == LWP_SUCCESS);
 #endif /* AFS_PTHREAD_ENV */
 
 #ifdef AFS_DEMAND_ATTACH_FS
     queue_Init(&fsync_salv.head);
-    assert(pthread_cond_init(&fsync_salv.cv, NULL) == 0);
-    assert(pthread_create(&tid, &tattr, FSYNC_salvageThread, NULL) == 0);
+    CV_INIT(&fsync_salv.cv, "fsync salv", CV_DEFAULT, 0);
+    osi_Assert(pthread_create(&tid, &tattr, FSYNC_salvageThread, NULL) == 0);
 #endif /* AFS_DEMAND_ATTACH_FS */
 }
 
@@ -265,6 +262,10 @@ FSYNC_sync(void * args)
     int min_vinit = 1;
 #endif /* AFS_DEMAND_ATTACH_FS */
 
+    /* we must not be called before vol package initialization, since we use
+     * vol package mutexes and conds etc */
+    osi_Assert(VInit);
+
     SYNC_getAddr(&state->endpoint, &state->addr);
     SYNC_cleanupSock(state);
 
@@ -274,27 +275,30 @@ FSYNC_sync(void * args)
 
 #ifdef AFS_PTHREAD_ENV
     /* set our 'thread-id' so that the host hold table works */
-    MUTEX_ENTER(&rx_stats_mutex);      /* protects rxi_pthread_hinum */
-    tid = ++rxi_pthread_hinum;
-    MUTEX_EXIT(&rx_stats_mutex);
+    tid = rx_NewThreadId();
     pthread_setspecific(rx_thread_id_key, (void *)(intptr_t)tid);
     Log("Set thread id %d for FSYNC_sync\n", tid);
 #endif /* AFS_PTHREAD_ENV */
 
+    VOL_LOCK;
+
     while (VInit < min_vinit) {
        /* Let somebody else run until all volumes have been preattached
         * (DAFS), or we have started attaching volumes (non-DAFS). This
         * doesn't mean that all volumes have been attached.
         */
 #ifdef AFS_PTHREAD_ENV
-       pthread_yield();
+       VOL_CV_WAIT(&vol_vinit_cond);
 #else /* AFS_PTHREAD_ENV */
        LWP_DispatchProcess();
 #endif /* AFS_PTHREAD_ENV */
     }
+
+    VOL_UNLOCK;
+
     state->fd = SYNC_getSock(&state->endpoint);
     code = SYNC_bindSock(state);
-    assert(!code);
+    osi_Assert(!code);
 
 #ifdef AFS_DEMAND_ATTACH_FS
     /*
@@ -309,10 +313,10 @@ FSYNC_sync(void * args)
     }
     memcpy(thread_opts, &VThread_defaults, sizeof(VThread_defaults));
     thread_opts->disallow_salvsync = 1;
-    assert(pthread_setspecific(VThread_key, thread_opts) == 0);
+    osi_Assert(pthread_setspecific(VThread_key, thread_opts) == 0);
 
     code = VVGCache_PkgInit();
-    assert(code == 0);
+    osi_Assert(code == 0);
 #endif
 
     InitHandler();
@@ -422,7 +426,7 @@ FSYNC_backgroundSalvage(Volume *vp)
     }
 
     queue_Append(&fsync_salv.head, node);
-    assert(pthread_cond_broadcast(&fsync_salv.cv) == 0);
+    CV_BROADCAST(&fsync_salv.cv);
 }
 #endif /* AFS_DEMAND_ATTACH_FS */
 
@@ -438,12 +442,12 @@ FSYNC_newconnection(osi_socket afd)
     socklen_t junk;
     junk = sizeof(other);
     fd = accept(afd, (struct sockaddr *)&other, &junk);
-    if (fd == -1) {
+    if (fd == OSI_NULLSOCKET) {
        Log("FSYNC_newconnection:  accept failed, errno==%d\n", errno);
-       assert(1 == 2);
+       osi_Assert(1 == 2);
     } else if (!AddHandler(fd, FSYNC_com)) {
        AcceptOff();
-       assert(AddHandler(fd, FSYNC_com));
+       osi_Assert(AddHandler(fd, FSYNC_com));
     }
 }
 
@@ -496,6 +500,16 @@ FSYNC_com(osi_socket fd)
        goto done;
     }
 
+    ViceLog(125, ("FSYNC_com: from fd %d got command %ld (%s) reason %ld (%s) "
+                  "pt %ld (%s) pid %ld\n", (int)fd,
+                  afs_printable_int32_ld(com.hdr.command),
+                  FSYNC_com2string(com.hdr.command),
+                  afs_printable_int32_ld(com.hdr.reason),
+                  FSYNC_reason2string(com.hdr.reason),
+                  afs_printable_int32_ld(com.hdr.programType),
+                  VPTypeToString(com.hdr.programType),
+                  afs_printable_int32_ld(com.hdr.pid)));
+
     res.hdr.com_seq = com.hdr.com_seq;
 
     VOL_LOCK;
@@ -533,7 +547,7 @@ FSYNC_com(osi_socket fd)
 #ifdef AFS_DEMAND_ATTACH_FS
     case FSYNC_VG_ADD:
     case FSYNC_VG_DEL:
-       res.hdr.response = FSYNC_com_VGUpdate(&com, &res);
+       res.hdr.response = FSYNC_com_VGUpdate(fd, &com, &res);
        break;
 #endif
     default:
@@ -542,6 +556,13 @@ FSYNC_com(osi_socket fd)
     }
     VOL_UNLOCK;
 
+    ViceLog(125, ("FSYNC_com: fd %d responding with code %ld (%s) reason %ld "
+                  "(%s)\n", (int)fd,
+                  afs_printable_int32_ld(res.hdr.response),
+                  SYNC_res2string(res.hdr.response),
+                  afs_printable_int32_ld(res.hdr.reason),
+                  FSYNC_reason2string(res.hdr.reason)));
+
  respond:
     SYNC_putRes(&fssync_server_state, fd, &res);
 
@@ -578,6 +599,10 @@ FSYNC_com_VolOp(osi_socket fd, SYNC_command * com, SYNC_response * res)
        }
     }
 
+    ViceLog(125, ("FSYNC_com_VolOp: fd %d got command for vol %lu part %.16s\n",
+                  (int)fd, afs_printable_uint32_lu(vcom.vop->volume),
+                  vcom.vop->partName));
+
     switch (com->hdr.command) {
     case FSYNC_VOL_ON:
     case FSYNC_VOL_ATTACH:
@@ -677,11 +702,11 @@ FSYNC_com_VolOn(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
     if (vp &&
        FSYNC_partMatch(vcom, vp, 1) &&
-       vp->pending_vol_op && 
+       vp->pending_vol_op &&
        (vcom->hdr->programType != vp->pending_vol_op->com.programType)) {
        /* a different program has this volume checked out. deny. */
        Log("FSYNC_VolOn: WARNING: program type %u has attempted to manipulate "
-           "state for volume %u using command code %u while the volume is " 
+           "state for volume %u using command code %u while the volume is "
            "checked out by program type %u for command code %u.\n",
            vcom->hdr->programType,
            vcom->vop->volume,
@@ -764,7 +789,7 @@ FSYNC_com_VolOn(FSSYNC_VolOp_command * vcom, SYNC_response * res)
  * @note this is an FSYNC RPC server stub
  *
  * @note this procedure handles the following FSSYNC command codes:
- *       - FSYNC_VOL_OFF 
+ *       - FSYNC_VOL_OFF
  *       - FSYNC_VOL_NEEDVOLUME
  *
  * @note the supplementary reason code contains additional details.
@@ -851,7 +876,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
                Log("volume %u already checked out\n", vp->hashid);
                /* XXX debug */
                Log("vp->vop = { com = { ver=%u, prog=%d, com=%d, reason=%d, len=%u, flags=0x%x }, vop = { vol=%u, part='%s' } }\n",
-                   vp->pending_vol_op->com.proto_version, 
+                   vp->pending_vol_op->com.proto_version,
                    vp->pending_vol_op->com.programType,
                    vp->pending_vol_op->com.command,
                    vp->pending_vol_op->com.reason,
@@ -891,7 +916,7 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
         */
        switch (type) {
        case salvageServer:
-           /* it is possible for the salvageserver to checkout a 
+           /* it is possible for the salvageserver to checkout a
             * volume for salvage before its scheduling request
             * has been sent to the salvageserver */
            if (vp->salvage.requested && !vp->salvage.scheduled) {
@@ -947,9 +972,6 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
 
        /* convert to heavyweight ref */
        nvp = VGetVolumeByVp_r(&error, vp);
-       VCancelReservation_r(rvp);
-       rvp = NULL;
-
        if (!nvp) {
             /*
              * It's possible for VGetVolumeByVp_r to have dropped and
@@ -985,6 +1007,10 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
            vp = nvp;
        }
 
+       /* kill off lightweight ref to ensure we can't deadlock against ourselves later... */
+       VCancelReservation_r(rvp);
+       rvp = NULL;
+
        /* register the volume operation metadata with the volume */
        VRegisterVolOp_r(vp, &info);
 
@@ -995,11 +1021,11 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
        if (VVolOpLeaveOnline_r(vp, &info)) {
            VUpdateVolume_r(&error, vp, VOL_UPDATE_WAIT);       /* At least get volume stats right */
            if (LogLevel) {
-               Log("FSYNC: Volume %u (%s) was left on line for an external %s request\n", 
-                   V_id(vp), V_name(vp), 
-                   vcom->hdr->reason == V_CLONE ? "clone" : 
-                   vcom->hdr->reason == V_READONLY ? "readonly" : 
-                   vcom->hdr->reason == V_DUMP ? "dump" : 
+               Log("FSYNC: Volume %u (%s) was left on line for an external %s request\n",
+                   V_id(vp), V_name(vp),
+                   vcom->hdr->reason == V_CLONE ? "clone" :
+                   vcom->hdr->reason == V_READONLY ? "readonly" :
+                   vcom->hdr->reason == V_DUMP ? "dump" :
                    vcom->hdr->reason == FSYNC_SALVAGE ? "salvage" :
                    "UNKNOWN");
            }
@@ -1024,8 +1050,8 @@ FSYNC_com_VolOff(FSSYNC_VolOp_command * vcom, SYNC_response * res)
 #ifdef AFS_DEMAND_ATTACH_FS
             VOfflineForVolOp_r(&error, vp, "A volume utility is running.");
             if (error==0) {
-                assert(vp->nUsers==0);
-                vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOffline; 
+                osi_Assert(vp->nUsers==0);
+                vp->pending_vol_op->vol_op_state = FSSYNC_VolOpRunningOffline;
             }
             else {
                VDeregisterVolOp_r(vp);
@@ -1163,10 +1189,8 @@ static afs_int32
 FSYNC_com_VolDone(FSSYNC_VolOp_command * vcom, SYNC_response * res)
 {
     afs_int32 code = SYNC_FAILED;
-#ifdef AFS_DEMAND_ATTACH_FS
     Error error;
     Volume * vp;
-#endif
 
     if (SYNC_verifyProtocolString(vcom->vop->partName, sizeof(vcom->vop->partName))) {
        res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
@@ -1179,19 +1203,33 @@ FSYNC_com_VolDone(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     if (vcom->v)
        vcom->v->volumeID = 0;
 
-#ifdef AFS_DEMAND_ATTACH_FS
     vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
     if (vp) {
        if (FSYNC_partMatch(vcom, vp, 1)) {
+#ifdef AFS_DEMAND_ATTACH_FS
            if ((V_attachState(vp) == VOL_STATE_UNATTACHED) ||
                (V_attachState(vp) == VOL_STATE_PREATTACHED)) {
-               VChangeState_r(vp, VOL_STATE_UNATTACHED);
+
+               /* Change state to DELETED, not UNATTACHED, so clients get
+                * a VNOVOL error when they try to access from now on. */
+
+               VChangeState_r(vp, VOL_STATE_DELETED);
                VDeregisterVolOp_r(vp);
+
+               /* Someday we should free the vp, too, after about 2 hours,
+                * possibly by putting the vp back on the VLRU. */
+
                code = SYNC_OK;
            } else {
                code = SYNC_DENIED;
                res->hdr.reason = FSYNC_BAD_STATE;
            }
+#else /* AFS_DEMAND_ATTACH_FS */
+           if (!vp->specialStatus) {
+               vp->specialStatus = VNOVOL;
+           }
+           code = SYNC_OK;
+#endif /* !AFS_DEMAND_ATTACH_FS */
        } else {
            code = SYNC_OK; /* XXX is this really a good idea? */
            res->hdr.reason = FSYNC_WRONG_PART;
@@ -1199,7 +1237,6 @@ FSYNC_com_VolDone(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     } else {
        res->hdr.reason = FSYNC_UNKNOWN_VOLID;
     }
-#endif
 
  done:
     return code;
@@ -1245,6 +1282,22 @@ FSYNC_com_VolError(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     }
 
     vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
+
+    if (!vp && vcom->hdr->reason == FSYNC_SALVAGE) {
+       /* The requested volume doesn't seem to exist. However, it is possible
+        * that this is triggered by trying to create or clone a volume that
+        * was prevented from succeeding by a half-created volume in the way.
+        * (e.g. we tried to create volume X, but volume X exists except that
+        * its .vol header was deleted for some reason) So, still try to
+        * a salvage for that volume ID. */
+
+       Log("FSYNC_com_VolError: attempting to schedule salvage for unknown "
+           "volume %lu part %s\n", afs_printable_uint32_lu(vcom->vop->volume),
+           vcom->vop->partName);
+       vp = VPreAttachVolumeById_r(&error, vcom->vop->partName,
+                                   vcom->vop->volume);
+    }
+
     if (vp) {
        if (FSYNC_partMatch(vcom, vp, 0)) {
            /* null out salvsync control state, as it's no longer relevant */
@@ -1449,7 +1502,7 @@ FSYNC_com_VolOpQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
     vp = VLookupVolume_r(&error, vcom->vop->volume, NULL);
 
     if (vp && vp->pending_vol_op) {
-       assert(sizeof(FSSYNC_VolOp_info) <= res->payload.len);
+       osi_Assert(sizeof(FSSYNC_VolOp_info) <= res->payload.len);
        memcpy(res->payload.buf, vp->pending_vol_op, sizeof(FSSYNC_VolOp_info));
        res->hdr.response_len += sizeof(FSSYNC_VolOp_info);
     } else {
@@ -1481,7 +1534,7 @@ FSYNC_com_VGQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
        goto done;
     }
 
-    assert(sizeof(FSSYNC_VGQry_response_t) <= res->payload.len);
+    osi_Assert(sizeof(FSSYNC_VGQry_response_t) <= res->payload.len);
 
     rc = VVGCache_query_r(dp, vcom->vop->volume, res->payload.buf);
     switch (rc) {
@@ -1504,7 +1557,7 @@ FSYNC_com_VGQuery(FSSYNC_VolOp_command * vcom, SYNC_response * res)
 }
 
 static afs_int32
-FSYNC_com_VGUpdate(SYNC_command * com, SYNC_response * res)
+FSYNC_com_VGUpdate(osi_socket fd, SYNC_command * com, SYNC_response * res)
 {
     afs_int32 code = SYNC_FAILED;
     struct DiskPartition64 * dp;
@@ -1520,6 +1573,12 @@ FSYNC_com_VGUpdate(SYNC_command * com, SYNC_response * res)
 
     vgucom = com->payload.buf;
 
+    ViceLog(125, ("FSYNC_com_VGUpdate: fd %d got command for parent %lu child "
+                  "%lu partName %.16s\n", (int)fd,
+                  afs_printable_uint32_lu(vgucom->parent),
+                  afs_printable_uint32_lu(vgucom->child),
+                  vgucom->partName));
+
     if (SYNC_verifyProtocolString(vgucom->partName, sizeof(vgucom->partName))) {
        res->hdr.reason = SYNC_REASON_MALFORMED_PACKET;
        goto done;
@@ -1615,6 +1674,14 @@ FSYNC_com_VnQry(osi_socket fd, SYNC_command * com, SYNC_response * res)
        return SYNC_COM_ERROR;
     }
 
+    ViceLog(125, ("FSYNC_com_VnQry: fd %d got command for vol %lu vnode %lu "
+                  "uniq %lu spare %lu partName %.16s\n", (int)fd,
+                  afs_printable_uint32_lu(qry->volume),
+                  afs_printable_uint32_lu(qry->vnode),
+                  afs_printable_uint32_lu(qry->unique),
+                  afs_printable_uint32_lu(qry->spare),
+                  qry->partName));
+
 #ifdef AFS_DEMAND_ATTACH_FS
     vp = VLookupVolume_r(&error, qry->volume, NULL);
 #else /* !AFS_DEMAND_ATTACH_FS */
@@ -1668,6 +1735,13 @@ FSYNC_com_StatsOp(osi_socket fd, SYNC_command * com, SYNC_response * res)
     scom.sop = (FSSYNC_StatsOp_hdr *) com->payload.buf;
     scom.com = com;
 
+    ViceLog(125, ("FSYNC_com_StatsOp: fd %d got command for stats: "
+                  "{vlru_generation = %lu, hash_bucket = %lu, partName = "
+                  "%.16s}\n", (int)fd,
+                  afs_printable_uint32_lu(scom.sop->args.vlru_generation),
+                  afs_printable_uint32_lu(scom.sop->args.hash_bucket),
+                  scom.sop->args.partName));
+
     switch (com->hdr.command) {
     case FSYNC_VOL_STATS_GENERAL:
        code = FSYNC_com_StatsOpGeneral(&scom, res);
@@ -1730,7 +1804,7 @@ FSYNC_com_StatsOpViceP(FSSYNC_StatsOp_command * scom, SYNC_response * res)
        stats->minFree = dp->minFree;
        stats->f_files = dp->f_files;
        stats->vol_list_len = dp->vol_list.len;
-       
+
        res->hdr.response_len += sizeof(struct DiskPartitionStats64);
     }
 
@@ -1760,7 +1834,7 @@ FSYNC_com_StatsOpHash(FSSYNC_StatsOp_command * scom, SYNC_response * res)
     AssignInt64(head->reorders, &stats->chain_reorders);
 
     res->hdr.response_len += sizeof(struct VolumeHashChainStats);
-    
+
     return code;
 }
 
@@ -1806,7 +1880,7 @@ FSYNC_com_to_info(FSSYNC_VolOp_command * vcom, FSSYNC_VolOp_info * info)
 }
 
 /**
- * check whether command packet partition name matches volume 
+ * check whether command packet partition name matches volume
  * object's partition name.
  *
  * @param[in] vcom        pointer to command packet
@@ -1823,11 +1897,11 @@ FSYNC_com_to_info(FSSYNC_VolOp_command * vcom, FSSYNC_VolOp_info * info)
  *
  * @internal
  */
-static int 
+static int
 FSYNC_partMatch(FSSYNC_VolOp_command * vcom, Volume * vp, int match_anon)
 {
     return ((match_anon && vcom->vop->partName[0] == 0) ||
-           (strncmp(vcom->vop->partName, V_partition(vp)->name, 
+           (strncmp(vcom->vop->partName, V_partition(vp)->name,
                     sizeof(vcom->vop->partName)) == 0));
 }
 
@@ -1872,7 +1946,7 @@ static void
 AcceptOn(void)
 {
     if (AcceptHandler == -1) {
-       assert(AddHandler(fssync_server_state.fd, FSYNC_newconnection));
+       osi_Assert(AddHandler(fssync_server_state.fd, FSYNC_newconnection));
        AcceptHandler = FindHandler(fssync_server_state.fd);
     }
 }
@@ -1881,7 +1955,7 @@ static void
 AcceptOff(void)
 {
     if (AcceptHandler != -1) {
-       assert(RemoveHandler(fssync_server_state.fd));
+       osi_Assert(RemoveHandler(fssync_server_state.fd));
        AcceptHandler = -1;
     }
 }
@@ -1894,10 +1968,10 @@ static void (*HandlerProc[MAXHANDLERS]) (osi_socket);
 static void
 InitHandler(void)
 {
-    register int i;
+    int i;
     ObtainWriteLock(&FSYNC_handler_lock);
     for (i = 0; i < MAXHANDLERS; i++) {
-       HandlerFD[i] = -1;
+       HandlerFD[i] = OSI_NULLSOCKET;
        HandlerProc[i] = 0;
     }
     ReleaseWriteLock(&FSYNC_handler_lock);
@@ -1924,7 +1998,7 @@ CallHandler(struct pollfd *fds, int nfds, int mask)
 static void
 CallHandler(fd_set * fdsetp)
 {
-    register int i;
+    int i;
     ObtainReadLock(&FSYNC_handler_lock);
     for (i = 0; i < MAXHANDLERS; i++) {
        if (HandlerFD[i] >= 0 && FD_ISSET(HandlerFD[i], fdsetp)) {
@@ -1940,10 +2014,10 @@ CallHandler(fd_set * fdsetp)
 static int
 AddHandler(osi_socket afd, void (*aproc) (osi_socket))
 {
-    register int i;
+    int i;
     ObtainWriteLock(&FSYNC_handler_lock);
     for (i = 0; i < MAXHANDLERS; i++)
-       if (HandlerFD[i] == -1)
+       if (HandlerFD[i] == OSI_NULLSOCKET)
            break;
     if (i >= MAXHANDLERS) {
        ReleaseWriteLock(&FSYNC_handler_lock);
@@ -1956,9 +2030,9 @@ AddHandler(osi_socket afd, void (*aproc) (osi_socket))
 }
 
 static int
-FindHandler(register osi_socket afd)
+FindHandler(osi_socket afd)
 {
-    register int i;
+    int i;
     ObtainReadLock(&FSYNC_handler_lock);
     for (i = 0; i < MAXHANDLERS; i++)
        if (HandlerFD[i] == afd) {
@@ -1966,27 +2040,27 @@ FindHandler(register osi_socket afd)
            return i;
        }
     ReleaseReadLock(&FSYNC_handler_lock);      /* just in case */
-    assert(1 == 2);
+    osi_Assert(1 == 2);
     return -1;                 /* satisfy compiler */
 }
 
 static int
-FindHandler_r(register osi_socket afd)
+FindHandler_r(osi_socket afd)
 {
-    register int i;
+    int i;
     for (i = 0; i < MAXHANDLERS; i++)
        if (HandlerFD[i] == afd) {
            return i;
        }
-    assert(1 == 2);
+    osi_Assert(1 == 2);
     return -1;                 /* satisfy compiler */
 }
 
 static int
-RemoveHandler(register osi_socket afd)
+RemoveHandler(osi_socket afd)
 {
     ObtainWriteLock(&FSYNC_handler_lock);
-    HandlerFD[FindHandler_r(afd)] = -1;
+    HandlerFD[FindHandler_r(afd)] = OSI_NULLSOCKET;
     ReleaseWriteLock(&FSYNC_handler_lock);
     return 1;
 }
@@ -1999,8 +2073,8 @@ GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds)
     int fdi = 0;
     ObtainReadLock(&FSYNC_handler_lock);
     for (i = 0; i < MAXHANDLERS; i++)
-       if (HandlerFD[i] != -1) {
-           assert(fdi<maxfds);
+       if (HandlerFD[i] != OSI_NULLSOCKET) {
+           osi_Assert(fdi<maxfds);
            fds[fdi].fd = HandlerFD[i];
            fds[fdi].events = events;
            fds[fdi].revents = 0;
@@ -2013,12 +2087,12 @@ GetHandler(struct pollfd *fds, int maxfds, int events, int *nfds)
 static void
 GetHandler(fd_set * fdsetp, int *maxfdp)
 {
-    register int i;
-    register int maxfd = -1;
+    int i;
+    int maxfd = -1;
     FD_ZERO(fdsetp);
     ObtainReadLock(&FSYNC_handler_lock);       /* just in case */
     for (i = 0; i < MAXHANDLERS; i++)
-       if (HandlerFD[i] != -1) {
+       if (HandlerFD[i] != OSI_NULLSOCKET) {
            FD_SET(HandlerFD[i], fdsetp);
 #ifndef AFS_NT40_ENV
             /* On Windows the nfds parameter to select() is ignored */