libafs: update the volume setup time when the vldb is rechecked
[openafs.git] / src / afs / afs_analyze.c
index dfa61fe..c0233ef 100644 (file)
 #endif /* vlserver error base define */
 
 
-int afs_BusyWaitPeriod = 15;   /* poll every 15 seconds */
+int afs_BusyWaitPeriod = 15;   /**< poll period, in seconds */
 
-afs_int32 hm_retry_RO = 0;     /* don't wait */
-afs_int32 hm_retry_RW = 0;     /* don't wait */
-afs_int32 hm_retry_int = 0;    /* don't wait */
+afs_int32 hm_retry_RO = 0;     /**< enable read-only hard-mount retry */
+afs_int32 hm_retry_RW = 0;     /**< enable read-write hard-mount retry */
+afs_int32 hm_retry_int = 0;    /**< hard-mount retry interval, in seconds */
 
 #define        VSleep(at)      afs_osi_Wait((at)*1000, 0, 0)
 
 
 int lastcode;
-/* returns:
- * 0   if the vldb record for a specific volume is different from what
- *     we have cached -- perhaps the volume has moved.
- * 1   if the vldb record is the same
- * 2   if we can't tell if it's the same or not.
- *
- * If 0, the caller will probably start over at the beginning of our
- * list of servers for this volume and try to find one that is up.  If
- * not 0, we will probably just keep plugging with what we have
- * cached.   If we fail to contact the VL server, we  should just keep
- * trying with the information we have, rather than failing. */
 #define DIFFERENT 0
 #define SAME 1
 #define DUNNO 2
+/*!
+ * \brief
+ *     Request vldb record to determined if it has changed.
+ *
+ * \retval 0 if the vldb record for a specific volume is different from what
+ *           we have cached -- perhaps the volume has moved.
+ * \retval 1 if the vldb record is the same
+ * \retval 2 if we can't tell if it's the same or not.
+ *
+ * \note
+ *     If 0 returned, the caller will probably start over at the beginning of our
+ *     list of servers for this volume and try to find one that is up.  If
+ *     not 0, we will probably just keep plugging with what we have
+ *     cached.   If we fail to contact the VL server, we  should just keep
+ *     trying with the information we have, rather than failing.
+ */
 static int
 VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
 {
-    struct vrequest treq;
+    struct vrequest *treq = NULL;
     struct afs_conn *tconn;
     int i, type = 0;
     union {
@@ -105,7 +110,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
     AFS_STATCNT(CheckVLDB);
     afs_FinalizeReq(areq);
 
-    if ((i = afs_InitReq(&treq, afs_osi_credp)))
+    if ((i = afs_CreateReq(&treq, afs_osi_credp)))
        return DUNNO;
     v = afs_osi_Alloc(sizeof(*v));
     osi_Assert(v != NULL);
@@ -115,7 +120,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
        VSleep(2);              /* Better safe than sorry. */
        tconn =
            afs_ConnByMHosts(tcell->cellHosts, tcell->vlport, tcell->cellNum,
-                            &treq, SHARED_LOCK, 0, &rxconn);
+                            treq, SHARED_LOCK, 0, &rxconn);
        if (tconn) {
            if ( tconn->parent->srvr->server->flags & SNO_LHOSTS) {
                type = 0;
@@ -153,7 +158,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
            }
        } else
            i = -1;
-    } while (afs_Analyze(tconn, rxconn, i, NULL, &treq, -1,    /* no op code for this */
+    } while (afs_Analyze(tconn, rxconn, i, NULL, treq, -1,     /* no op code for this */
                         SHARED_LOCK, tcell));
 
     afs_PutCell(tcell, READ_LOCK);
@@ -161,6 +166,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
               ICL_TYPE_INT32, i);
 
     if (i) {
+       afs_DestroyReq(treq);
        afs_osi_Free(v, sizeof(*v));
        return DUNNO;
     }
@@ -175,7 +181,7 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
        ReleaseWriteLock(&tvp->lock);
 
        if (type == 2) {
-           LockAndInstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, &treq);
+           LockAndInstallUVolumeEntry(tvp, &v->utve, afid->Cell, tcell, treq);
        } else if (type == 1) {
            LockAndInstallNVolumeEntry(tvp, &v->ntve, afid->Cell);
        } else {
@@ -191,52 +197,52 @@ VLDB_Same(struct VenusFid *afid, struct vrequest *areq)
            }
        }
 
+       tvp->states &= ~VRecheck;     /* Just checked it. */
+       tvp->setupTime = osi_Time();  /* Time the vldb was checked. */
+
        ReleaseWriteLock(&tvp->lock);
        afs_PutVolume(tvp, WRITE_LOCK);
     } else {                   /* can't find volume */
-       tvp = afs_GetVolume(afid, &treq, WRITE_LOCK);
+       tvp = afs_GetVolume(afid, treq, WRITE_LOCK);
        if (tvp) {
            afs_PutVolume(tvp, WRITE_LOCK);
+           afs_DestroyReq(treq);
            afs_osi_Free(v, sizeof(*v));
            return DIFFERENT;
        } else {
+           afs_DestroyReq(treq);
            afs_osi_Free(v, sizeof(*v));
            return DUNNO;
        }
     }
 
+    afs_DestroyReq(treq);
     afs_osi_Free(v, sizeof(*v));
     return (changed ? DIFFERENT : SAME);
 }                              /*VLDB_Same */
 
-/*------------------------------------------------------------------------
- * afs_BlackListOnce
- *
- * Description:
+/*!
+ * \brief
  *     Mark a server as invalid for further attempts of this request only.
  *
- * Arguments:
- *     areq  : The request record associated with this operation.
- *     afid  : The FID of the file involved in the action.  This argument
- *             may be null if none was involved.
- *      tsp   : pointer to a server struct for the server we wish to
- *              blacklist.
+ * \param[in,out] areq  The request record associated with this operation.
+ * \param[in]     afid  The FID of the file involved in the action.  This argument
+ *                      may be null if none was involved.
+ * \param[in,out] tsp   pointer to a server struct for the server we wish to
+ *                      blacklist.
  *
- * Returns:
+ * \returns
  *     Non-zero value if further servers are available to try,
  *     zero otherwise.
  *
- * Environment:
+ * \note
  *     This routine is typically called in situations where we believe
- *      one server out of a pool may have an error condition.
+ *     one server out of a pool may have an error condition.
  *
- * Side Effects:
- *     As advertised.
- *
- * NOTE:
+ * \note
  *     The afs_Conn* routines use the list of invalidated servers to
  *      avoid reusing a server marked as invalid for this request.
- *------------------------------------------------------------------------*/
+ */
 static afs_int32
 afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
                  struct server *tsp)
@@ -271,28 +277,25 @@ afs_BlackListOnce(struct vrequest *areq, struct VenusFid *afid,
     return serversleft;
 }
 
-/*------------------------------------------------------------------------
- * afs_ClearStatus
+/*!
+ * \brief
+ *     Clear any cached status for the target FID of a failed fileserver
+ *     write RPC.
  *
- * Description:
- *     Analyze the outcome of an RPC operation, taking whatever support
- *     actions are necessary.
+ * \param[in]     afid   The FID of the file involved in the action.  This argument
+ *                       may be null if none was involved.
+ * \param[in]     op     which RPC we are analyzing.
+ * \param[in,out] avp    A pointer to the struct volume, if we already have one.
  *
- * Arguments:
- *     afid  : The FID of the file involved in the action.  This argument
- *             may be null if none was involved.
- *      op    : which RPC we are analyzing.
- *      avp   : A pointer to the struct volume, if we already have one.
- *
- * Returns:
+ * \returns
  *     Non-zero value if the related RPC operation can be retried,
  *     zero otherwise.
  *
- * Environment:
+ * \note
  *     This routine is called when we got a network error,
  *      and discards state if the operation was a data-mutating
  *      operation.
- *------------------------------------------------------------------------*/
+ */
 static int
 afs_ClearStatus(struct VenusFid *afid, int op, struct volume *avp)
 {
@@ -330,38 +333,82 @@ afs_ClearStatus(struct VenusFid *afid, int op, struct volume *avp)
     return 0;
 }
 
-/*------------------------------------------------------------------------
- * EXPORTED afs_Analyze
+/*!
+ * \brief
+ *      Print the last errors from the servers for the volume on
+ *      this request.
  *
- * Description:
+ * \param[in] areq   The request record associated with this operation.
+ * \param[in] afid   The FID of the file involved in the action.  This argument
+ *                  may be null if none was involved.
+ *
+ * \return
+ *      None
+ *
+ * \note
+ *      This routine is called before a hard-mount retry, to display
+ *      the servers by primary address and the errors encountered.
+ */
+static void
+afs_PrintServerErrors(struct vrequest *areq, struct VenusFid *afid)
+{
+    int i;
+    struct volume *tvp;
+    struct srvAddr *sa;
+    afs_uint32 address;
+    char *sep = " (";
+    char *term = "";
+
+    if (afid) {
+       tvp = afs_FindVolume(afid, READ_LOCK);
+       if (tvp) {
+           for (i = 0; i < AFS_MAXHOSTS; i++) {
+               if (areq->lasterror[i] && tvp->serverHost[i]) {
+                   sa = tvp->serverHost[i]->addr;
+                   if (sa) {
+                       address = ntohl(sa->sa_ip);
+                       afs_warnuser("%s%d.%d.%d.%d code=%d", sep,
+                                    (address >> 24), (address >> 16) & 0xff,
+                                    (address >> 8) & 0xff, (address) & 0xff,
+                                    areq->lasterror[i]);
+                       sep = ", ";
+                       term = ")";
+                   }
+               }
+           }
+           afs_PutVolume(tvp, READ_LOCK);
+       }
+    }
+    afs_warnuser("%s\n", term);
+}
+
+/*!
+ * \brief
  *     Analyze the outcome of an RPC operation, taking whatever support
  *     actions are necessary.
  *
- * Arguments:
- *     aconn : Ptr to the relevant connection on which the call was made.
- *     acode : The return code experienced by the RPC.
- *     afid  : The FID of the file involved in the action.  This argument
- *             may be null if none was involved.
- *     areq  : The request record associated with this operation.
- *      op    : which RPC we are analyzing.
- *      cellp : pointer to a cell struct.  Must provide either fid or cell.
+ * \param[in]     aconn  Ptr to the relevant connection on which the call was made.
+ * \param[in]     rxconn Ptr to the rx_connection.
+ * \param[in]     acode  The return code experienced by the RPC.
+ * \param[in]     fid    The FID of the file involved in the action.  This argument
+ *                       may be null if none was involved.
+ * \param[in,out] areq   The request record associated with this operation.
+ * \param[in]     op     which RPC we are analyzing.
+ * \param[in]     cellp  pointer to a cell struct.  Must provide either fid or cell.
  *
- * Returns:
+ * \returns
  *     Non-zero value if the related RPC operation should be retried,
  *     zero otherwise.
  *
- * Environment:
+ * \note
  *     This routine is typically called in a do-while loop, causing the
  *     embedded RPC operation to be called repeatedly if appropriate
  *     until whatever error condition (if any) is intolerable.
  *
- * Side Effects:
- *     As advertised.
- *
- * NOTE:
+ * \note
  *     The retry return value is used by afs_StoreAllSegments to determine
  *     if this is a temporary or permanent error.
- *------------------------------------------------------------------------*/
+ */
 int
 afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
             afs_int32 acode, struct VenusFid *afid, struct vrequest *areq,
@@ -497,8 +544,9 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
                    if (shouldRetry) {
                        if (warn) {
                            afs_warnuser
-                               ("afs: hard-mount waiting for volume %u\n",
+                               ("afs: hard-mount waiting for volume %u",
                                 afid->Fid.Volume);
+                           afs_PrintServerErrors(areq, afid);
                        }
 
                        VSleep(hm_retry_int);
@@ -529,6 +577,8 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
                }
            }
        }
+       if (aconn) /* simply lacking aconn->server doesn't absolve this */
+           afs_PutConn(aconn, rxconn, locktype);
        return shouldRetry;
     }
 
@@ -560,45 +610,56 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
        return 0;
     }
 
-    /* If network troubles, mark server as having bogued out again. */
-    /* VRESTARTING is < 0 because of backward compatibility issues
-     * with 3.4 file servers and older cache managers */
+    /* Save the last code of this server on this request. */
+    tvp = afs_FindVolume(afid, READ_LOCK);
+    if (tvp) {
+       for (i = 0; i < AFS_MAXHOSTS; i++) {
+           if (tvp->serverHost[i] == tsp) {
+               areq->lasterror[i] = acode;
+           }
+       }
+       afs_PutVolume(tvp, READ_LOCK);
+    }
+
 #ifdef AFS_64BIT_CLIENT
     if (acode == -455)
        acode = 455;
 #endif /* AFS_64BIT_CLIENT */
-    if ((acode < 0) && (acode != VRESTARTING)) {
-       if (acode == RX_MSGSIZE || acode == RX_CALL_BUSY) {
+    if (acode == RX_MSGSIZE) {
+       shouldRetry = 1;
+       goto out;
+    }
+    if (acode == RX_CALL_TIMEOUT || acode == VNOSERVICE) {
+       serversleft = afs_BlackListOnce(areq, afid, tsp);
+       if (afid)
+           tvp = afs_FindVolume(afid, READ_LOCK);
+       if ((serversleft == 0) && tvp &&
+           ((tvp->states & VRO) || (tvp->states & VBackup))) {
+           shouldRetry = 0;
+       } else {
            shouldRetry = 1;
-           goto out;
        }
-       if (acode == RX_CALL_TIMEOUT || acode == RX_CALL_IDLE) {
-           serversleft = afs_BlackListOnce(areq, afid, tsp);
-           if (afid)
-               tvp = afs_FindVolume(afid, READ_LOCK);
-           if ((serversleft == 0) && tvp &&
-               ((tvp->states & VRO) || (tvp->states & VBackup))) {
-               shouldRetry = 0;
-           } else {
-               shouldRetry = 1;
-           }
-           if (!afid || !tvp || (tvp->states & VRO))
-               areq->idleError++;
-           else if (afs_ClearStatus(afid, op, tvp) == 0)
-               shouldRetry = 0;
+       if (!afid || !tvp || (tvp->states & VRO))
+           areq->idleError++;
+       else if (afs_ClearStatus(afid, op, tvp) == 0)
+           shouldRetry = 0;
 
-           if (tvp)
-               afs_PutVolume(tvp, READ_LOCK);
-           /* By doing this, we avoid ever marking a server down
-            * in an idle timeout case. That's because the server is
-            * still responding and may only be letting a single vnode
-            * time out. We otherwise risk having the server continually
-            * be marked down, then up, then down again...
-            */
-           goto out;
-       }
-       afs_ServerDown(sa, acode);
-       ForceNewConnections(sa); /**multi homed clients lock:afs_xsrvAddr? */
+       if (tvp)
+           afs_PutVolume(tvp, READ_LOCK);
+       /* By doing this, we avoid ever marking a server down
+        * in an idle timeout case. That's because the server is
+        * still responding and may only be letting a single vnode
+        * time out. We otherwise risk having the server continually
+        * be marked down, then up, then down again...
+        */
+       goto out;
+    }
+    /* If network troubles, mark server as having bogued out again. */
+    /* VRESTARTING is < 0 because of backward compatibility issues
+     * with 3.4 file servers and older cache managers */
+    if ((acode < 0) && (acode != VRESTARTING)) {
+       afs_ServerDown(sa, acode, rxconn);
+       ForceNewConnections(sa); /* multi homed clients lock:afs_xsrvAddr? */
        if (aerrP)
            (aerrP->err_Server)++;
     }
@@ -717,7 +778,7 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
     }
     /* check for ubik errors; treat them like crashed servers */
     else if (acode >= ERROR_TABLE_BASE_U && acode < ERROR_TABLE_BASE_U + 255) {
-       afs_ServerDown(sa, acode);
+       afs_ServerDown(sa, acode, rxconn);
        if (aerrP)
            (aerrP->err_Server)++;
        shouldRetry = 1;        /* retryable (maybe one is working) */
@@ -725,7 +786,7 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
     }
     /* Check for bad volume data base / missing volume. */
     else if (acode == VSALVAGE || acode == VOFFLINE || acode == VNOVOL
-            || acode == VNOSERVICE || acode == VMOVED) {
+            || acode == VMOVED) {
        struct cell *tcell;
        int same;
 
@@ -777,7 +838,7 @@ afs_Analyze(struct afs_conn *aconn, struct rx_connection *rxconn,
         * retry in case there is another server.  However, if we find
         * no connection (aconn == 0) we set the networkError flag.
         */
-       afs_ServerDown(sa, acode);
+       afs_ServerDown(sa, acode, rxconn);
        if (aerrP)
            (aerrP->err_Server)++;
        VSleep(1);              /* Just a hack for desperate times. */