ubik: Remove version_cond
[openafs.git] / src / ubik / remote.c
index d3d0f13..6874c6a 100644 (file)
@@ -396,45 +396,72 @@ SDISK_GetFile(struct rx_call *rxcall, afs_int32 file,
     char tbuffer[256];
     afs_int32 tlen;
     afs_int32 length;
+    struct rx_peer *tpeer;
+    struct rx_connection *tconn;
+    afs_uint32 otherHost = 0;
+    char hoststr[16];
 
     if ((code = ubik_CheckAuth(rxcall))) {
        return code;
     }
+
+    tconn = rx_ConnectionOf(rxcall);
+    tpeer = rx_PeerOf(tconn);
+    otherHost = ubikGetPrimaryInterfaceAddr(rx_HostOf(tpeer));
+    ViceLog(0, ("Ubik: Synchronize database: send (via GetFile) "
+               "to server %s begin\n",
+              afs_inet_ntoa_r(otherHost, hoststr)));
+
     dbase = ubik_dbase;
     DBHOLD(dbase);
     code = (*dbase->stat) (dbase, file, &ubikstat);
     if (code < 0) {
-       DBRELE(dbase);
-       return code;
+       ViceLog(0, ("database stat() error:%d\n", code));
+       goto failed;
     }
     length = ubikstat.size;
     tlen = htonl(length);
     code = rx_Write(rxcall, (char *)&tlen, sizeof(afs_int32));
     if (code != sizeof(afs_int32)) {
-       DBRELE(dbase);
-       ubik_dprint("Rx-write length error=%d\n", code);
-       return BULK_ERROR;
+       ViceLog(0, ("Rx-write length error=%d\n", code));
+       code = BULK_ERROR;
+       goto failed;
     }
     offset = 0;
     while (length > 0) {
        tlen = (length > sizeof(tbuffer) ? sizeof(tbuffer) : length);
        code = (*dbase->read) (dbase, file, tbuffer, offset, tlen);
        if (code != tlen) {
-           DBRELE(dbase);
-           ubik_dprint("read failed error=%d\n", code);
-           return UIOERROR;
+           ViceLog(0, ("read failed error=%d\n", code));
+           code = UIOERROR;
+           goto failed;
        }
        code = rx_Write(rxcall, tbuffer, tlen);
        if (code != tlen) {
-           DBRELE(dbase);
-           ubik_dprint("Rx-write length error=%d\n", code);
-           return BULK_ERROR;
+           ViceLog(0, ("Rx-write data error=%d\n", code));
+           code = BULK_ERROR;
+           goto failed;
        }
        length -= tlen;
        offset += tlen;
     }
     code = (*dbase->getlabel) (dbase, file, version);  /* return the dbase, too */
+    if (code)
+       ViceLog(0, ("getlabel error=%d\n", code));
+
+ failed:
     DBRELE(dbase);
+    if (code) {
+       ViceLog(0,
+           ("Ubik: Synchronize database: send (via GetFile) to "
+            "server %s failed (error = %d)\n",
+            afs_inet_ntoa_r(otherHost, hoststr), code));
+    } else {
+       ViceLog(0,
+           ("Ubik: Synchronize database: send (via GetFile) to "
+            "server %s complete, version: %d.%d\n",
+           afs_inet_ntoa_r(otherHost, hoststr), version->epoch, version->counter));
+    }
     return code;
 }
 
@@ -450,6 +477,7 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     int tlen;
     struct rx_peer *tpeer;
     struct rx_connection *tconn;
+    afs_uint32 syncHost = 0;
     afs_uint32 otherHost = 0;
     char hoststr[16];
     char pbuffer[1028];
@@ -463,8 +491,7 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     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
@@ -477,15 +504,18 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
      * screwup.  Thus, we only object if we're sure we know who the sync site
      * is, and it ain't the guy talking to us.
      */
-    offset = uvote_GetSyncSite();
+    syncHost = uvote_GetSyncSite();
     tconn = rx_ConnectionOf(rxcall);
     tpeer = rx_PeerOf(tconn);
     otherHost = ubikGetPrimaryInterfaceAddr(rx_HostOf(tpeer));
-    if (offset && offset != otherHost) {
+    if (syncHost && syncHost != otherHost) {
        /* we *know* this is the wrong guy */
-       code = USYNC;
-       DBHOLD(dbase);
-       goto failed;
+        char sync_hoststr[16];
+       ViceLog(0,
+           ("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(syncHost, sync_hoststr)));
+       return USYNC;
     }
 
     DBHOLD(dbase);
@@ -493,8 +523,8 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     /* abort any active trans that may scribble over the database */
     urecovery_AbortAll(dbase);
 
-    ubik_print("Ubik: Synchronize database with server %s\n",
-              afs_inet_ntoa_r(otherHost, hoststr));
+    ViceLog(0, ("Ubik: Synchronize database: receive (via SendFile) from server %s begin\n",
+              afs_inet_ntoa_r(otherHost, hoststr)));
 
     offset = 0;
     UBIK_VERSION_LOCK;
@@ -506,10 +536,12 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
     fd = open(pbuffer, O_CREAT | O_RDWR | O_TRUNC, 0600);
     if (fd < 0) {
        code = errno;
+       ViceLog(0, ("Open error=%d\n", code));
        goto failed_locked;
     }
     code = lseek(fd, HDRSIZE, 0);
     if (code != HDRSIZE) {
+       ViceLog(0, ("lseek error=%d\n", code));
        close(fd);
        goto failed_locked;
     }
@@ -524,7 +556,7 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
 #endif
        code = rx_Read(rxcall, tbuffer, tlen);
        if (code != tlen) {
-           ubik_dprint("Rx-read length error=%d\n", code);
+           ViceLog(0, ("Rx-read length error=%d\n", code));
            code = BULK_ERROR;
            close(fd);
            goto failed;
@@ -532,7 +564,7 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
        code = write(fd, tbuffer, tlen);
        pass++;
        if (code != tlen) {
-           ubik_dprint("write failed error=%d\n", code);
+           ViceLog(0, ("write failed tlen=%d, error=%d\n", tlen, code));
            code = UIOERROR;
            close(fd);
            goto failed;
@@ -541,8 +573,10 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
        length -= tlen;
     }
     code = close(fd);
-    if (code)
+    if (code) {
+       ViceLog(0, ("close failed error=%d\n", code));
        goto failed;
+    }
 
     /* sync data first, then write label and resync (resync done by setlabel call).
      * This way, good label is only on good database. */
@@ -571,11 +605,6 @@ SDISK_SendFile(struct rx_call *rxcall, afs_int32 file,
 #endif
     memcpy(&ubik_dbase->version, avers, sizeof(struct ubik_version));
     udisk_Invalidate(dbase, file);     /* new dbase, flush disk buffers */
-#ifdef AFS_PTHREAD_ENV
-    opr_Assert(pthread_cond_broadcast(&dbase->version_cond) == 0);
-#else
-    LWP_NoYieldSignal(&dbase->version);
-#endif
 
 failed_locked:
     UBIK_VERSION_UNLOCK;
@@ -592,12 +621,16 @@ failed:
            (*dbase->setlabel) (dbase, file, &tversion);
            UBIK_VERSION_UNLOCK;
        }
-       ubik_print
-           ("Ubik: Synchronize database with server %s failed (error = %d)\n",
-            afs_inet_ntoa_r(otherHost, hoststr), code);
+       ViceLog(0,
+           ("Ubik: Synchronize database: receive (via SendFile) from "
+            "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");
+       ViceLog(0,
+           ("Ubik: Synchronize database: receive (via SendFile) from "
+            "server %s complete, version: %d.%d\n",
+           afs_inet_ntoa_r(otherHost, hoststr), avers->epoch, avers->counter));
     }
     DBRELE(dbase);
     return code;
@@ -661,9 +694,9 @@ SDISK_UpdateInterfaceAddr(struct rx_call *rxcall,
     /* if (probableMatch) */
     /* inconsistent addresses in CellServDB */
     if (!probableMatch || found) {
-       ubik_print("Inconsistent Cell Info from server:\n");
+       ViceLog(0, ("Inconsistent Cell Info from server:\n"));
        for (i = 0; i < UBIK_MAX_INTERFACE_ADDR && inAddr->hostAddr[i]; i++)
-           ubik_print("... %s\n", afs_inet_ntoa_r(htonl(inAddr->hostAddr[i]), hoststr));
+           ViceLog(0, ("... %s\n", afs_inet_ntoa_r(htonl(inAddr->hostAddr[i]), hoststr)));
        fflush(stdout);
        fflush(stderr);
        printServerInfo();
@@ -675,9 +708,9 @@ 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:\n");
+    ViceLog(0, ("ubik: A Remote Server has addresses:\n"));
     for (i = 0; i < UBIK_MAX_INTERFACE_ADDR && ts->addr[i]; i++)
-       ubik_print("... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr));
+       ViceLog(0, ("... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr)));
 
     UBIK_ADDR_UNLOCK;
 
@@ -702,11 +735,11 @@ printServerInfo(void)
     int i, j = 1;
     char hoststr[16];
 
-    ubik_print("Local CellServDB:\n");
+    ViceLog(0, ("Local CellServDB:\n"));
     for (ts = ubik_servers; ts; ts = ts->next, j++) {
-       ubik_print("  Server %d:\n", j);
+       ViceLog(0, ("  Server %d:\n", j));
        for (i = 0; (i < UBIK_MAX_INTERFACE_ADDR) && ts->addr[i]; i++)
-           ubik_print("  ... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr));
+           ViceLog(0, ("  ... %s\n", afs_inet_ntoa_r(ts->addr[i], hoststr)));
     }
 }