ubik: Log sync site for SDISK_SendFile USYNC error
[openafs.git] / src / ubik / remote.c
index 05611e9..2fca3b1 100644 (file)
 #include <assert.h>
 
 #include <afs/opr.h>
+#ifdef AFS_PTHREAD_ENV
+# include <opr/lock.h>
+#else
+# include <opr/lockstub.h>
+#endif
+
 #include <lock.h>
 #include <rx/xdr.h>
 #include <rx/rx.h>
@@ -49,6 +55,10 @@ SDISK_Begin(struct rx_call *rxcall, struct ubik_tid *atid)
        return code;
     }
     DBHOLD(ubik_dbase);
+    if (urecovery_AllBetter(ubik_dbase, 0) == 0) {
+       code = UNOQUORUM;
+       goto out;
+    }
     urecovery_CheckTid(atid, 1);
     code = udisk_begin(ubik_dbase, UBIK_WRITETRANS, &ubik_currentTrans);
     if (!code && ubik_currentTrans) {
@@ -56,6 +66,7 @@ SDISK_Begin(struct rx_call *rxcall, struct ubik_tid *atid)
        ubik_currentTrans->tid.epoch = atid->epoch;
        ubik_currentTrans->tid.counter = atid->counter;
     }
+  out:
     DBRELE(ubik_dbase);
     return code;
 }
@@ -449,10 +460,10 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     /* send the file back to the requester */
 
     dbase = ubik_dbase;
+    pbuffer[0] = '\0';
 
     if ((code = ubik_CheckAuth(rxcall))) {
-       DBHOLD(dbase);
-       goto failed;
+       return code;
     }
 
     /* next, we do a sanity check to see if the guy sending us the database is
@@ -471,9 +482,12 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     otherHost = ubikGetPrimaryInterfaceAddr(rx_HostOf(tpeer));
     if (offset && offset != otherHost) {
        /* we *know* this is the wrong guy */
-       code = USYNC;
-       DBHOLD(dbase);
-       goto failed;
+        char sync_hoststr[16];
+       ubik_print
+           ("Ubik: Refusing synchronization with server %s since it is not the sync-site (%s).\n",
+            afs_inet_ntoa_r(otherHost, hoststr),
+            afs_inet_ntoa_r(offset, sync_hoststr));
+       return USYNC;
     }
 
     DBHOLD(dbase);
@@ -570,7 +584,9 @@ failed_locked:
 
 failed:
     if (code) {
-       unlink(pbuffer);
+       if (pbuffer[0] != '\0')
+           unlink(pbuffer);
+
        /* Failed to sync. Allow reads again for now. */
        if (dbase != NULL) {
            UBIK_VERSION_LOCK;
@@ -582,6 +598,7 @@ failed:
            ("Ubik: Synchronize database with server %s failed (error = %d)\n",
             afs_inet_ntoa_r(otherHost, hoststr), code);
     } else {
+       uvote_set_dbVersion(*avers);
        ubik_print("Ubik: Synchronize database completed\n");
     }
     DBRELE(dbase);
@@ -646,10 +663,9 @@ SDISK_UpdateInterfaceAddr(struct rx_call *rxcall,
     /* if (probableMatch) */
     /* inconsistent addresses in CellServDB */
     if (!probableMatch || found) {
-       ubik_print("Inconsistent Cell Info from server: ");
+       ubik_print("Inconsistent Cell Info from server:\n");
        for (i = 0; i < UBIK_MAX_INTERFACE_ADDR && inAddr->hostAddr[i]; i++)
-           ubik_print("%s ", afs_inet_ntoa_r(htonl(inAddr->hostAddr[i]), hoststr));
-       ubik_print("\n");
+           ubik_print("... %s\n", afs_inet_ntoa_r(htonl(inAddr->hostAddr[i]), hoststr));
        fflush(stdout);
        fflush(stderr);
        printServerInfo();
@@ -661,12 +677,23 @@ SDISK_UpdateInterfaceAddr(struct rx_call *rxcall,
     for (i = 1; i < UBIK_MAX_INTERFACE_ADDR; i++)
        ts->addr[i] = htonl(inAddr->hostAddr[i]);
 
-    ubik_print("ubik: A Remote Server has addresses: ");
+    ubik_print("ubik: A Remote Server has addresses:\n");
     for (i = 0; i < UBIK_MAX_INTERFACE_ADDR && ts->addr[i]; i++)
-       ubik_print("%s ", afs_inet_ntoa_r(ts->addr[i], hoststr));
-    ubik_print("\n");
+       ubik_print("... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr));
 
     UBIK_ADDR_UNLOCK;
+
+    /*
+     * The most likely cause of a DISK_UpdateInterfaceAddr RPC
+     * is because the server was restarted.  Reset its state
+     * so that no DISK_Begin RPCs will be issued until the
+     * known database version is current.
+     */
+    UBIK_BEACON_LOCK;
+    ts->beaconSinceDown = 0;
+    ts->currentDB = 0;
+    urecovery_LostServer(ts);
+    UBIK_BEACON_UNLOCK;
     return 0;
 }
 
@@ -677,13 +704,12 @@ printServerInfo(void)
     int i, j = 1;
     char hoststr[16];
 
-    ubik_print("Local CellServDB:");
+    ubik_print("Local CellServDB:\n");
     for (ts = ubik_servers; ts; ts = ts->next, j++) {
-       ubik_print("Server %d: ", j);
+       ubik_print("  Server %d:\n", j);
        for (i = 0; (i < UBIK_MAX_INTERFACE_ADDR) && ts->addr[i]; i++)
-           ubik_print("%s ", afs_inet_ntoa_r(ts->addr[i], hoststr));
+           ubik_print("  ... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr));
     }
-    ubik_print("\n");
 }
 
 afs_int32
@@ -719,8 +745,14 @@ SDISK_SetVersion(struct rx_call *rxcall, struct ubik_tid *atid,
        goto done;
     }
 
-    /* Set the label if its version matches the sync-site's */
-    if (uvote_eq_dbVersion(*oldversionp)) {
+    /* Set the label if our version matches the sync-site's. Also set the label
+     * if our on-disk version matches the old version, and our view of the
+     * sync-site's version matches the new version. This suggests that
+     * ubik_dbVersion was updated while the sync-site was setting the new
+     * version, and it already told us via VOTE_Beacon. */
+    if (uvote_eq_dbVersion(*oldversionp)
+       || (uvote_eq_dbVersion(*newversionp)
+           && vcmp(ubik_dbase->version, *oldversionp) == 0)) {
        UBIK_VERSION_LOCK;
        code = (*ubik_dbase->setlabel) (ubik_dbase, 0, newversionp);
        if (!code) {