Remove unused variable in vos.c
[openafs.git] / src / volser / vos.c
index 2df18df..648606e 100644 (file)
@@ -16,6 +16,9 @@
 
 #include <sys/types.h>
 #include <string.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif
 #ifdef AFS_NT40_ENV
 #include <fcntl.h>
 #include <io.h>
@@ -198,22 +201,35 @@ IsNumeric(char *name)
 
 
 /*
- * Parse a server name/address and return the address in HOST BYTE order
+ * Parse a server dotted address and return the address in network byte order
  */
 afs_int32
-GetServer(char *aname)
+GetServerNoresolve(char *aname)
 {
-    register struct hostent *th;
-    afs_int32 addr;
     int b1, b2, b3, b4;
-    register afs_int32 code;
-    char hostname[MAXHOSTCHARS];
+    afs_int32 addr;
+    afs_int32 code;
 
     code = sscanf(aname, "%d.%d.%d.%d", &b1, &b2, &b3, &b4);
     if (code == 4) {
        addr = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
-       addr = ntohl(addr);     /* convert to host order */
-    } else {
+       addr = htonl(addr);     /* convert to network byte order */
+       return addr;
+    } else
+       return 0;
+}
+/*
+ * Parse a server name/address and return the address in network byte order
+ */
+afs_int32
+GetServer(char *aname)
+{
+    register struct hostent *th;
+    afs_int32 addr; /* in network byte order */
+    register afs_int32 code;
+    char hostname[MAXHOSTCHARS];
+
+    if ((addr = GetServerNoresolve(aname)) == 0) {
        th = gethostbyname(aname);
        if (!th)
            return 0;
@@ -224,7 +240,7 @@ GetServer(char *aname)
        code = gethostname(hostname, MAXHOSTCHARS);
        if (code)
            return 0;
-       th = gethostbyname(hostname);   /* returns host byte order */
+       th = gethostbyname(hostname);
        if (!th)
            return 0;
        memcpy(&addr, th->h_addr, sizeof(addr));
@@ -292,7 +308,7 @@ SendFile(usd_handle_t ufd, register struct rx_call *call, long blksize)
        FD_SET((intptr_t)(ufd->handle), &in);
        /* don't timeout if read blocks */
 #if defined(AFS_PTHREAD_ENV)
-       select(((int)(ufd->handle)) + 1, &in, 0, 0, 0);
+       select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
 #else
        IOMGR_Select(((intptr_t)(ufd->handle)) + 1, &in, 0, 0, 0);
 #endif
@@ -407,7 +423,7 @@ ReceiveFile(usd_handle_t ufd, struct rx_call *call, long blksize)
            FD_SET((intptr_t)(ufd->handle), &out);
            /* don't timeout if write blocks */
 #if defined(AFS_PTHREAD_ENV)
-           select(((int)(ufd->handle)) + 1, &out, 0, 0, 0);
+           select(((intptr_t)(ufd->handle)) + 1, &out, 0, 0, 0);
 #else
            IOMGR_Select(((intptr_t)(ufd->handle)) + 1, 0, &out, 0, 0);
 #endif
@@ -522,7 +538,6 @@ DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
            t = pntr->creationDate;
            fprintf(STDOUT, "    Creation    %s",
                    ctime(&t));
-#ifdef FULL_LISTVOL_SWITCH
            t = pntr->copyDate;
            fprintf(STDOUT, "    Copy        %s",
                    ctime(&t));
@@ -538,7 +553,7 @@ DisplayFormat(volintInfo *pntr, afs_int32 server, afs_int32 part,
            if (t)
                fprintf(STDOUT, "    Last Access %s",
                        ctime(&t));
-#endif
+
            t = pntr->updateDate;
            if (!t)
                fprintf(STDOUT, "    Last Update Never\n");
@@ -677,7 +692,7 @@ XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
            t = a_xInfoP->creationDate;
            fprintf(STDOUT, "    Creation    %s",
                    ctime(&t));
-#ifdef FULL_LISTVOL_SWITCH
+
            t = a_xInfoP->copyDate;
            fprintf(STDOUT, "    Copy        %s",
                    ctime(&t));
@@ -693,7 +708,7 @@ XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
            if (t)
                fprintf(STDOUT, "    Last Access %s",
                        ctime(&t));
-#endif
+
            t = a_xInfoP->updateDate;
            if (!t)
                fprintf(STDOUT, "    Last Update Never\n");
@@ -832,7 +847,6 @@ XDisplayFormat(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
     }                          /*Default listing */
 }                              /*XDisplayFormat */
 
-#ifdef FULL_LISTVOL_SWITCH
 /*------------------------------------------------------------------------
  * PRIVATE XDisplayFormat2
  *
@@ -1029,9 +1043,7 @@ XDisplayFormat2(volintXInfo *a_xInfoP, afs_int32 a_servID, afs_int32 a_partID,
        }                       /*Screwed volume */
     }                          /*Default listing */
 }                              /*XDisplayFormat */
-#endif /*FULL_LISTVOL_SWITCH*/
 
-#ifdef FULL_LISTVOL_SWITCH
 static void
 DisplayFormat2(long server, long partition, volintInfo *pntr)
 {
@@ -1149,7 +1161,6 @@ DisplayVolumes2(long server, long partition, volintInfo *pntr, long count)
     }
     return;
 }
-#endif /* FULL_LISTVOL_SWITCH */
 
 static void
 DisplayVolumes(afs_int32 server, afs_int32 part, volintInfo *pntr,
@@ -1275,7 +1286,7 @@ XDisplayVolumes(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
     }
 
 }                              /*XDisplayVolumes */
-#ifdef FULL_LISTVOL_SWITCH
+
 /*------------------------------------------------------------------------
  * PRIVATE XDisplayVolumes2
  *
@@ -1361,7 +1372,6 @@ XDisplayVolumes2(afs_int32 a_servID, afs_int32 a_partID, volintXInfo *a_xInfoP,
     }
 
 }                              /*XDisplayVolumes2 */
-#endif /* FULL_LISTVOL_SWITCH */
 
 
 /* set <server> and <part> to the correct values depending on 
@@ -1630,13 +1640,10 @@ ExamineVolume(register struct cmd_syndesc *as, void *arock)
            foundserv = 1;
            if (wantExtendedInfo)
                XVolumeStats(xInfoP, &entry, aserver, apart, voltype);
-           else
-#ifdef FULL_LISTVOL_SWITCH
-           if (as->parms[2].items) {
+           else if (as->parms[2].items) {
                DisplayFormat2(aserver, apart, pntr);
                EnumerateEntry(&entry);
            } else
-#endif /* FULL_LISTVOL_SWITCH */
                VolumeStats_int(pntr, &entry, aserver, apart, voltype);
 
            if ((voltype == BACKVOL) && !(entry.flags & BACK_EXISTS)) {
@@ -3711,24 +3718,20 @@ ListVolumes(register struct cmd_syndesc *as, void *arock)
                        as->parms[0].items->data, pname,
                        (unsigned long)count);
            if (wantExtendedInfo) {
-#ifdef FULL_LISTVOL_SWITCH
                if (as->parms[6].items)
                    XDisplayVolumes2(aserver, dummyPartList.partId[i], origxInfoP,
                                count, int32list, fast, quiet);
                else
-#endif /* FULL_LISTVOL_SWITCH */
-               XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
+                   XDisplayVolumes(aserver, dummyPartList.partId[i], origxInfoP,
                                count, int32list, fast, quiet);
                if (xInfoP)
                    free(xInfoP);
                xInfoP = (volintXInfo *) 0;
            } else {
-#ifdef FULL_LISTVOL_SWITCH
                if (as->parms[6].items)
                    DisplayVolumes2(aserver, dummyPartList.partId[i], oldpntr,
                                    count);
                else
-#endif /* FULL_LISTVOL_SWITCH */
                    DisplayVolumes(aserver, dummyPartList.partId[i], oldpntr,
                                   count, int32list, fast, quiet);
                if (pntr)
@@ -5146,7 +5149,10 @@ ChangeAddr(register struct cmd_syndesc *as, void *arock)
     afs_int32 ip1, ip2, vcode;
     int remove = 0;
 
-    ip1 = GetServer(as->parms[0].items->data);
+    if (noresolve)
+       ip1 = GetServerNoresolve(as->parms[0].items->data);
+    else
+       ip1 = GetServer(as->parms[0].items->data);
     if (!ip1) {
        fprintf(STDERR, "vos: invalid host address\n");
        return (EINVAL);
@@ -5160,7 +5166,10 @@ ChangeAddr(register struct cmd_syndesc *as, void *arock)
     }
 
     if (as->parms[1].items) {
-       ip2 = GetServer(as->parms[1].items->data);
+       if (noresolve)
+           ip2 = GetServerNoresolve(as->parms[1].items->data);
+       else
+           ip2 = GetServer(as->parms[1].items->data);
        if (!ip2) {
            fprintf(STDERR, "vos: invalid host address\n");
            return (EINVAL);
@@ -5177,16 +5186,20 @@ ChangeAddr(register struct cmd_syndesc *as, void *arock)
 
     vcode = ubik_VL_ChangeAddr(cstruct, UBIK_CALL_NEW, ntohl(ip1), ntohl(ip2));
     if (vcode) {
+       char hoststr1[16], hoststr2[16];
        if (remove) {
+           afs_inet_ntoa_r(ip2, hoststr2);
            fprintf(STDERR, "Could not remove server %s from the VLDB\n",
-                   as->parms[0].items->data);
+                   hoststr2);
            if (vcode == VL_NOENT) {
                fprintf(STDERR,
                        "vlserver does not support the remove flag or ");
            }
        } else {
+           afs_inet_ntoa_r(ip1, hoststr1);
+           afs_inet_ntoa_r(ip2, hoststr2);
            fprintf(STDERR, "Could not change server %s to server %s\n",
-                   as->parms[0].items->data, as->parms[1].items->data);
+                   hoststr1, hoststr2);
        }
        PrintError("", vcode);
        return (vcode);
@@ -5392,6 +5405,71 @@ ListAddrs(register struct cmd_syndesc *as, void *arock)
     return 0;
 }
 
+
+static int
+SetAddrs(register struct cmd_syndesc *as, void *arock)
+{
+    afs_int32 vcode;
+    bulkaddrs m_addrs;
+    afsUUID askuuid;
+    afs_uint32 FS_HostAddrs_HBO[ADDRSPERSITE];
+
+    memset(&m_addrs, 0, sizeof(bulkaddrs));
+    memset(&askuuid, 0, sizeof(afsUUID));
+    if (as->parms[0].items) {
+       /* -uuid */
+        if (afsUUID_from_string(as->parms[0].items->data, &askuuid) < 0) {
+           fprintf(STDERR, "vos: invalid UUID '%s'\n",
+                   as->parms[0].items->data);
+           exit(-1);
+       }
+    }
+    if (as->parms[1].items) {
+       /* -host */
+       struct cmd_item *ti;
+       afs_int32 saddr;
+       int i = 0;
+
+       for (ti = as->parms[1].items; ti && i < ADDRSPERSITE; ti = ti->next) {
+
+           if (noresolve)
+               saddr = GetServerNoresolve(ti->data);
+           else
+               saddr = GetServer(ti->data);
+
+           if (!saddr) {
+               fprintf(STDERR, "vos: Can't get host info for '%s'\n",
+                       ti->data);
+               exit(-1);
+           }
+           /* Convert it to host byte order */
+           FS_HostAddrs_HBO[i] = ntohl(saddr);
+           i++;
+       }
+       m_addrs.bulkaddrs_len = i;
+       m_addrs.bulkaddrs_val = FS_HostAddrs_HBO;
+    }
+
+    vcode = ubik_VL_RegisterAddrs(cstruct, 0, &askuuid, 0, &m_addrs);
+
+    if (vcode) {
+       if (vcode == VL_MULTIPADDR) {
+           fprintf(STDERR, "vos: VL_RegisterAddrs rpc failed; The IP address exists on a different server; repair it\n");
+           PrintError("", vcode);
+           return vcode;
+       } else if (vcode == RXGEN_OPCODE) {
+           fprintf(STDERR, "vlserver doesn't support VL_RegisterAddrs rpc; ignored\n");
+           PrintError("", vcode);
+           return vcode;
+       }
+    }
+    if (verbose) {
+       fprintf(STDOUT, "vos: Changed UUID with addresses:\n");
+       print_addrs(&m_addrs, &askuuid, m_addrs.bulkaddrs_len, 1);
+    }
+    return 0;
+}
+
 static int
 LockEntry(register struct cmd_syndesc *as, void *arock)
 {
@@ -5997,10 +6075,8 @@ main(int argc, char **argv)
                "generate minimal information");
     cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
                "list extended volume fields");
-#ifdef FULL_LISTVOL_SWITCH
     cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
                "machine readable format");
-#endif /* FULL_LISTVOL_SWITCH */
     COMMONPARMS;
 
     ts = cmd_CreateSyntax("syncvldb", SyncVldb, NULL,
@@ -6023,10 +6099,8 @@ main(int argc, char **argv)
     cmd_AddParm(ts, "-id", CMD_SINGLE, 0, "volume name or ID");
     cmd_AddParm(ts, "-extended", CMD_FLAG, CMD_OPTIONAL,
                "list extended volume fields");
-#ifdef FULL_LISTVOL_SWITCH
     cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
                "machine readable format");
-#endif /* FULL_LISTVOL_SWITCH */
     COMMONPARMS;
     cmd_CreateAlias(ts, "volinfo");
 
@@ -6168,6 +6242,12 @@ main(int argc, char **argv)
                "transaction ID");
     COMMONPARMS;
 
+    ts = cmd_CreateSyntax("setaddrs", SetAddrs, NULL,
+                         "set the list of IP address for a given UUID in the VLDB");
+    cmd_AddParm(ts, "-uuid", CMD_SINGLE, 0, "uuid of server");
+    cmd_AddParm(ts, "-host", CMD_LIST, 0, "address of host");
+
+    COMMONPARMS;
     code = cmd_Dispatch(argc, argv);
     if (rxInitDone) {
        /* Shut down the ubik_client and rx connections */