new-giveup-all-callbacks-rpc-20030303
[openafs.git] / src / viced / afsfileprocs.c
index 4ab945b..2aa0e35 100644 (file)
@@ -349,11 +349,13 @@ retry:
                afs_inet_ntoa_r(thost->host, hoststr)));
        if ( MultiProbeAlternateAddress_r (thost) ) {
            ViceLog(0, ("MultiProbe failed to find new address for host %s:%d\n",
-                       afs_inet_ntoa_r(thost->host, hoststr), thost->port));
+                       afs_inet_ntoa_r(thost->host, hoststr), 
+                       ntohs(thost->port)));
            code = -1;
        } else {
            ViceLog(0, ("MultiProbe found new address for host %s:%d\n",
-                       afs_inet_ntoa_r(thost->host, hoststr), thost->port));
+                       afs_inet_ntoa_r(thost->host, hoststr), 
+                       ntohs(thost->port)));
            if (BreakDelayedCallBacks_r(thost)) {
                ViceLog(0,("BreakDelayedCallbacks FAILED AGAIN for host %s which IS UP.  Possible network or routing failure.\n",
                        afs_inet_ntoa_r(thost->host, hoststr)));
@@ -462,13 +464,13 @@ CheckVnode(AFSFid *fid, Volume **volptr, Vnode **vptr, int lock)
            /* I'm not really worried about when we restarted, I'm   */
            /* just worried about when the first VBUSY was returned. */
            TM_GetTimeOfDay(&restartedat, 0);
-           return(VBUSY);
+           return(busyonrst?VBUSY:VRESTARTING);
          }
          else {
            struct timeval now;
            TM_GetTimeOfDay(&now, 0);
            if ((now.tv_sec - restartedat.tv_sec) < (11*60)) {
-             return(VBUSY);
+             return(busyonrst?VBUSY:VRESTARTING);
            }
            else {
              return (VRESTARTING);
@@ -1842,16 +1844,32 @@ RXGetVolumeStatus(AFSFetchVolumeStatus *status, char **name, char **offMsg,
     /* now allocate and copy these things; they're freed by the RXGEN stub */
     temp = strlen(V_name(volptr)) + 1;
     *name = malloc(temp);
+    if (!*name) {
+       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
+       assert(0);
+    }
     strcpy(*name, V_name(volptr));
     temp = strlen(V_offlineMessage(volptr)) + 1;
     *offMsg = malloc(temp);
+    if (!*offMsg) {
+       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
+       assert(0);
+    }
     strcpy(*offMsg, V_offlineMessage(volptr));
 #if TRANSARC_VOL_STATS
     *motd = malloc(1);
+    if (!*motd) {
+       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
+       assert(0);
+    }
     strcpy(*motd, nullString);
 #else
     temp = strlen(V_motd(volptr)) + 1;
     *motd = malloc(temp);
+    if (!*motd) {
+       ViceLog(0, ("Failed malloc in RXGetVolumeStatus\n"));
+       assert(0);
+    }
     strcpy(*motd, V_motd(volptr));
 #endif /* FS_STATS_DETAILED */
 
@@ -1940,8 +1958,15 @@ static char *AllocSendBuffer()
     FS_LOCK
     afs_buffersAlloced++;
     if (!freeBufferList) {
+       char *tmp;
        FS_UNLOCK
-       return malloc(sendBufSize);
+
+       tmp = malloc(sendBufSize);
+       if (!tmp) {
+           ViceLog(0, ("Failed malloc in AllocSendBuffer\n"));
+           assert(0);
+       }
+       return tmp;
     }
     tp = freeBufferList;
     freeBufferList = tp->next;
@@ -2330,6 +2355,10 @@ afs_int32 SRXAFS_FetchACL (struct rx_call *acall,
 
     AccessList->AFSOpaque_len = 0;
     AccessList->AFSOpaque_val = malloc(AFSOPAQUEMAX);
+    if (!AccessList->AFSOpaque_val) {
+       ViceLog(0, ("Failed malloc in SRXAFS_FetchACL\n"));
+       assert(0);
+    }
 
     /*
      * Get volume/vnode for the fetched file; caller's access rights to it
@@ -2507,9 +2536,17 @@ afs_int32 SRXAFS_BulkStatus(struct rx_call *acall,
     /* allocate space for return output parameters */
     OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
        malloc(nfiles * sizeof(struct AFSFetchStatus));
+    if (!OutStats->AFSBulkStats_val) {
+       ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
+       assert(0);
+    }
     OutStats->AFSBulkStats_len = nfiles;
     CallBacks->AFSCBs_val = (struct AFSCallBack *)
        malloc(nfiles * sizeof(struct AFSCallBack));
+    if (!CallBacks->AFSCBs_val) {
+       ViceLog(0, ("Failed malloc in SRXAFS_BulkStatus\n"));
+       assert(0);
+    }
     CallBacks->AFSCBs_len = nfiles;
 
     if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
@@ -2643,9 +2680,17 @@ afs_int32 SRXAFS_InlineBulkStatus(struct rx_call *acall,
     /* allocate space for return output parameters */
     OutStats->AFSBulkStats_val = (struct AFSFetchStatus *)
        malloc(nfiles * sizeof(struct AFSFetchStatus));
+    if (!OutStats->AFSBulkStats_val) {
+       ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
+       assert(0);
+    }
     OutStats->AFSBulkStats_len = nfiles;
     CallBacks->AFSCBs_val = (struct AFSCallBack *)
        malloc(nfiles * sizeof(struct AFSCallBack));
+    if (!CallBacks->AFSCBs_val) {
+       ViceLog(0, ("Failed malloc in SRXAFS_FetchStatus\n"));
+       assert(0);
+    }
     CallBacks->AFSCBs_len = nfiles;
 
     if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon))) {
@@ -5815,9 +5860,9 @@ afs_int32 SRXAFS_GetXStats(struct rx_call *a_call,
 } /*SRXAFS_GetXStats*/
 
 
-afs_int32 SRXAFS_GiveUpCallBacks (struct rx_call *acall,
-                                 struct AFSCBFids *FidArray,
-                                 struct AFSCBs *CallBackArray)
+static afs_int32 common_GiveUpCallBacks (struct rx_call *acall,
+                                        struct AFSCBFids *FidArray,
+                                        struct AFSCBs *CallBackArray)
 {
     afs_int32 errorCode;
     register int i;
@@ -5847,20 +5892,26 @@ afs_int32 SRXAFS_GiveUpCallBacks (struct rx_call *acall,
     if ((errorCode = CallPreamble(acall, ACTIVECALL, &tcon)))
        goto Bad_GiveUpCallBacks;
 
-    if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
-       ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n", 
-                  FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len, 
-                  (tcon->peer ? tcon->peer->host : 0)));
-       errorCode = EINVAL;
-       goto Bad_GiveUpCallBacks;
-    }
+    if (!FidArray && !CallBackArray) {
+       errorCode = GetClient(tcon, &client);
+        if (!errorCode) 
+           DeleteAllCallBacks_r(client->host, 1);
+    } else {
+       if (FidArray->AFSCBFids_len < CallBackArray->AFSCBs_len) {
+           ViceLog(0, ("GiveUpCallBacks: #Fids %d < #CallBacks %d, host=%x\n", 
+                       FidArray->AFSCBFids_len, CallBackArray->AFSCBs_len, 
+                       (tcon->peer ? tcon->peer->host : 0)));
+           errorCode = EINVAL;
+           goto Bad_GiveUpCallBacks;
+       }
 
-    errorCode = GetClient(tcon, &client);
-    if (!errorCode) {
-       for (i=0; i < FidArray->AFSCBFids_len; i++) {
-         register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
-         DeleteCallBack(client->host, fid);
-       }
+       errorCode = GetClient(tcon, &client);
+       if (!errorCode) {
+           for (i=0; i < FidArray->AFSCBFids_len; i++) {
+               register struct AFSFid *fid = &(FidArray->AFSCBFids_val[i]);
+               DeleteCallBack(client->host, fid);
+           }
+       }
     }
 
 Bad_GiveUpCallBacks:
@@ -5886,8 +5937,21 @@ Bad_GiveUpCallBacks:
 out:
     return errorCode;
 
+} /*common_GiveUpCallBacks*/
+
+
+afs_int32 SRXAFS_GiveUpCallBacks (struct rx_call *acall,
+                                 struct AFSCBFids *FidArray,
+                                 struct AFSCBs *CallBackArray)
+{
+    return common_GiveUpCallBacks(acall, FidArray, CallBackArray);
 } /*SRXAFS_GiveUpCallBacks*/
 
+afs_int32 SRXAFS_GiveUpAllCallBacks (struct rx_call *acall)
+{
+    return common_GiveUpCallBacks(acall, 0, 0);
+} /*SRXAFS_GiveUpAllCallBacks*/
+
 
 afs_int32 SRXAFS_NGetVolumeInfo (struct rx_call *acall,
                                 char *avolid,
@@ -5959,6 +6023,7 @@ afs_int32 SRXAFS_FlushCPS(struct rx_call *acall,
       if ((client->ViceId != ANONYMOUSID) && client->CPS.prlist_val) {
        free(client->CPS.prlist_val);
        client->CPS.prlist_val = NULL;
+       client->CPS.prlist_len = 0;
       }
       ReleaseWriteLock(&client->lock);
     }