[OpenAFS-devel] numeric addresses in "vos" output (patch)
Ken Raeburn
raeburn@raeburn.org
Tue, 24 Sep 2002 18:17:39 -0400
--=-=-=
In trying to track down one problem I'm having, I've gotten rather
annoyed at another: Practically every "vos" command displays hostnames
and not addresses, with no option to change that. I've got a server
with multiple addresses, and the addresses are mapped to the same
hostname string, but I want to know which address is used.
I threw together this patch, which takes the "-noresolve" option of
"vos listaddrs", and applies it to everything in vos that prints
hostnames -- basically, tweaked some argument parsing, wrote a
function that may look up a hostname or may just format the numeric
address, and did a global replace of hostutil_GetNameByINet.
Having "-noresolve" might seem kind of bogus for some commands that
don't normally print hostnames, but many of them do if "-verbose" is
given also. (Personally, I would've used "-numeric", but "-noresolve"
was already there.)
Patch is relative to openafs-devel_1_3_3.
Ken
--=-=-=
Content-Disposition: attachment; filename=noresolve-diffs
Content-Description: vos -noresolve diffs
? noresolve-diffs
Index: vos.c
===================================================================
RCS file: /cvs/openafs/src/volser/vos.c,v
retrieving revision 1.17
diff -p -u -r1.17 vos.c
--- vos.c 2002/08/12 21:27:51 1.17
+++ vos.c 2002/09/24 22:01:10
@@ -70,10 +70,12 @@ cmd_AddParm(ts, "-noauth", CMD_FLAG, CMD
cmd_AddParm(ts, "-localauth",CMD_FLAG,CMD_OPTIONAL,"use server tickets");\
cmd_AddParm(ts, "-verbose", CMD_FLAG, CMD_OPTIONAL, "verbose");\
cmd_AddParm(ts, "-encrypt", CMD_FLAG, CMD_OPTIONAL, "encrypt commands");\
+cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses");\
#define ERROR_EXIT(code) {error=(code); goto error_exit;}
extern int verbose;
+extern int noresolve;
int rxInitDone = 0;
struct rx_connection *tconn;
afs_int32 tserver;
@@ -97,6 +99,7 @@ extern PrintError();
extern int MapPartIdIntoName();
extern int MapHostToNetwork();
extern int MapNetworkToHost();
+extern char *MapAddressToHostname();
extern void EnumerateEntry();
extern void SubEnumerateEntry();
@@ -482,7 +485,7 @@ int fast,longlist, disp;
if(pntr->needsSalvaged == 1) fprintf(STDOUT,"**needs salvage**");
fprintf(STDOUT,"\n");
MapPartIdIntoName(part,pname);
- fprintf(STDOUT," %s %s \n",hostutil_GetNameByINet(server),pname);
+ fprintf(STDOUT," %s %s \n",MapAddressToHostname(server),pname);
fprintf(STDOUT," RWrite %10u ROnly %10u Backup %10u \n", pntr->parentID,pntr->cloneID, pntr->backupID);
fprintf(STDOUT," MaxQuota %10d K \n",pntr->maxquota);
fprintf(STDOUT," Creation %s",
@@ -628,7 +631,7 @@ static void XDisplayFormat(a_xInfoP, a_s
fprintf(STDOUT, "\n");
MapPartIdIntoName(a_partID, pname);
fprintf(STDOUT, " %s %s \n",
- hostutil_GetNameByINet(a_servID),
+ MapAddressToHostname(a_servID),
pname);
fprintf(STDOUT, " RWrite %10u ROnly %10u Backup %10u \n",
a_xInfoP->parentID, a_xInfoP->cloneID, a_xInfoP->backupID);
@@ -807,7 +810,7 @@ static void DisplayFormat2(server, part
struct in_addr s;
s.s_addr = server;
- strcpy(hostname, hostutil_GetNameByINet(server));
+ strcpy(hostname, MapAddressToHostname(server));
strcpy(address, inet_ntoa(s));
server_cache = server;
}
@@ -1245,7 +1248,7 @@ register struct cmd_syndesc *as;
/* Get information about the volume from the server */
if (verbose) {
fprintf(STDOUT,"Getting volume listing from the server %s .. ",
- hostutil_GetNameByINet(aserver));
+ MapAddressToHostname(aserver));
fflush(STDOUT);
}
if (wantExtendedInfo)
@@ -1264,7 +1267,7 @@ register struct cmd_syndesc *as;
error = ENOENT;
} else {
fprintf(STDERR, "Volume does not exist on server %s as indicated by the VLDB\n",
- hostutil_GetNameByINet(aserver));
+ MapAddressToHostname(aserver));
}
} else {
PrintDiagnostics("examine", code);
@@ -1698,7 +1701,7 @@ static DeleteVolume(as)
MapPartIdIntoName(partition, pname);
fprintf(STDOUT,"Volume %u on partition %s server %s deleted\n",
- volid, pname, hostutil_GetNameByINet(server));
+ volid, pname, MapAddressToHostname(server));
return 0;
}
@@ -3822,7 +3825,7 @@ register struct cmd_syndesc *as;
}
static void
-print_addrs(const bulkaddrs *addrs, const afsUUID *m_uuid, int nentries, int print, int noresolve)
+print_addrs(const bulkaddrs *addrs, const afsUUID *m_uuid, int nentries, int print)
{
afs_int32 vcode;
afs_int32 i, j;
@@ -3868,13 +3871,8 @@ print_addrs(const bulkaddrs *addrs, cons
/* Print the list */
m_addrp = (afs_int32 *)m_addrs.bulkaddrs_val;
for (j=0; j<m_nentries; j++, m_addrp++) {
- *m_addrp = htonl(*m_addrp);
- if (noresolve) {
- char hoststr[16];
- printf("%s ", afs_inet_ntoa_r(*m_addrp,hoststr));
- } else {
- printf("%s ", hostutil_GetNameByINet(*m_addrp));
- }
+ *m_addrp = htonl(*m_addrp);
+ printf("%s ", MapAddressToHostname(*m_addrp));
}
if (j==0) {
printf("<unknown>\n");
@@ -3890,12 +3888,7 @@ print_addrs(const bulkaddrs *addrs, cons
* the IP address of the server - print it.
*/
*addrp = htonl(*addrp);
- if (noresolve) {
- char hoststr[16];
- printf("%s\n", afs_inet_ntoa_r(*addrp,hoststr));
- } else {
- printf("%s\n", hostutil_GetNameByINet(*addrp));
- }
+ printf("%s\n", MapAddressToHostname(*addrp));
}
if (print) {
@@ -3908,7 +3901,7 @@ static ListAddrs(as)
register struct cmd_syndesc *as;
{
afs_int32 vcode;
- afs_int32 i, j, noresolve=0, printuuid=0;
+ afs_int32 i, j, printuuid=0;
struct VLCallBack unused;
afs_int32 nentries, *addrp;
bulkaddrs addrs, m_addrs;
@@ -3944,9 +3937,6 @@ register struct cmd_syndesc *as;
m_attrs.ipaddr = ntohl(saddr);
}
if (as->parms[2].items) {
- noresolve=1;
- }
- if (as->parms[3].items) {
printuuid=1;
}
@@ -3986,7 +3976,7 @@ register struct cmd_syndesc *as;
return( vcode );
}
- print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid, noresolve);
+ print_addrs(&m_addrs, &m_uuid, m_nentries, printuuid);
i++;
if ((as->parms[1].items)||(as->parms[0].items)||(i>nentries))
@@ -4063,6 +4053,10 @@ char *arock; {
verbose = 1;
else
verbose = 0;
+ if(as->parms[17].items) /* -numeric flag set */
+ noresolve = 1;
+ else
+ noresolve = 0;
return 0;
}
@@ -4305,7 +4299,6 @@ char **argv; {
ts = cmd_CreateSyntax("listaddrs", ListAddrs, 0, "list the IP address of all file servers registered in the VLDB");
cmd_AddParm(ts, "-uuid", CMD_SINGLE, CMD_OPTIONAL, "uuid of server");
cmd_AddParm(ts, "-host", CMD_SINGLE, CMD_OPTIONAL, "address of host");
- cmd_AddParm(ts, "-noresolve", CMD_FLAG, CMD_OPTIONAL, "don't resolve addresses");
cmd_AddParm(ts, "-printuuid", CMD_FLAG, CMD_OPTIONAL, "print uuid of hosts");
COMMONPARMS;
Index: vsprocs.c
===================================================================
RCS file: /cvs/openafs/src/volser/vsprocs.c,v
retrieving revision 1.10
diff -p -u -r1.10 vsprocs.c
--- vsprocs.c 2001/10/08 22:55:41 1.10
+++ vsprocs.c 2002/09/24 22:01:11
@@ -56,6 +56,7 @@ afs_int32 VolumeExists(), CheckVldbRWBK(
struct ubik_client *cstruct;
int verbose = 0;
+int noresolve = 0;
extern struct rx_securityClass *rxnull_NewClientSecurityObject();
extern struct rx_connection *rx_NewConnection();
extern void AFSVolExecuteRequest();
@@ -73,6 +74,17 @@ struct release {
afs_int32 vldbEntryIndex;
};
+char *
+MapAddressToHostname(hostid)
+afs_int32 hostid;
+{
+ extern char *hostutil_GetNameByINet();
+
+ if (noresolve)
+ return afs_inet_ntoa(hostid);
+ return hostutil_GetNameByINet(hostid);
+}
+
/*map the partition <partId> into partition name <partName>*/
void
MapPartIdIntoName(partId, partName)
@@ -346,7 +358,8 @@ struct nvldbentry *entry;
for(i = 0; i < entry->nServers; i++) {
MapPartIdIntoName(entry->serverPartition[i],pname);
fprintf(STDOUT," server %s partition %s ",
- hostutil_GetNameByINet(entry->serverNumber[i]), pname);
+ MapAddressToHostname(entry->serverNumber[i]),
+ pname);
if(entry->serverFlags[i] & ITSRWVOL) fprintf(STDOUT,"RW Site ") ; else fprintf(STDOUT,"RO Site ");
if (isMixed) {
if (entry->serverFlags[i] & NEW_REPSITE)
@@ -942,7 +955,7 @@ UV_MoveVolume(afromvol, afromserver, afr
char pname[10];
MapPartIdIntoName(entry.serverPartition[i],pname);
fprintf(STDERR," server %s partition %s \n",
- hostutil_GetNameByINet(entry.serverNumber[i]), pname);
+ MapAddressToHostname(entry.serverNumber[i]), pname);
}
}
vcode = ubik_Call(VL_ReleaseLock, cstruct, 0, afromvol, -1,
@@ -1827,7 +1840,7 @@ static int GetTrans (vldbEntryPtr, index
if (verbose) {
fprintf(STDOUT,"Creating new volume %u on replication site %s: ",
- volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
+ volid, MapAddressToHostname(vldbEntryPtr->serverNumber[index]));
fflush(STDOUT);
}
@@ -1856,7 +1869,7 @@ static int GetTrans (vldbEntryPtr, index
else {
if (verbose) {
fprintf(STDOUT,"Updating existing ro volume %u on %s ...\n",
- volid, hostutil_GetNameByINet(vldbEntryPtr->serverNumber[index]));
+ volid, MapAddressToHostname(vldbEntryPtr->serverNumber[index]));
fflush(STDOUT);
}
@@ -2247,11 +2260,11 @@ UV_ReleaseVolume(afromvol, afromserver,
if (verbose) {
fprintf(STDOUT,"Starting ForwardMulti from %u to %u on %s",
cloneVolId, entry.volumeId[ROVOL],
- hostutil_GetNameByINet(entry.serverNumber[times[0].vldbEntryIndex]));
+ MapAddressToHostname(entry.serverNumber[times[0].vldbEntryIndex]));
for (s=1; s<volcount; s++) {
fprintf(STDOUT," and %s",
- hostutil_GetNameByINet(entry.serverNumber[times[s].vldbEntryIndex]));
+ MapAddressToHostname(entry.serverNumber[times[s].vldbEntryIndex]));
}
if (fromdate == 0)
@@ -2359,7 +2372,7 @@ UV_ReleaseVolume(afromvol, afromserver,
if (!(entry.serverFlags[i] & NEW_REPSITE)) {
MapPartIdIntoName(entry.serverPartition[i],pname);
fprintf(STDERR,"\t%35s %s\n",
- hostutil_GetNameByINet(entry.serverNumber[i]), pname);
+ MapAddressToHostname(entry.serverNumber[i]), pname);
}
}
@@ -2422,7 +2435,7 @@ UV_ReleaseVolume(afromvol, afromserver,
if (code) {
fprintf(STDERR,"Failed to end transaction on ro volume %u at server 0x%x\n",
entry.volumeId[ROVOL],
- hostutil_GetNameByINet(htonl(replicas[i].server.destHost)));
+ MapAddressToHostname(htonl(replicas[i].server.destHost)));
if (!error) error = code;
}
}
@@ -2621,7 +2634,7 @@ UV_RestoreVolume(toserver, topart, tovol
}
MapPartIdIntoName(topart, partName);
fprintf(STDOUT,"Restoring volume %s Id %u on server %s partition %s ..", tovolname,
- pvolid, hostutil_GetNameByINet(toserver), partName);
+ pvolid, MapAddressToHostname(toserver), partName);
fflush(STDOUT);
code = AFSVolCreateVolume(toconn, topart, tovolname, volsertype, 0,&pvolid, &totid);
if (code){
@@ -2827,7 +2840,7 @@ UV_RestoreVolume(toserver, topart, tovol
MapPartIdIntoName(entry.serverPartition[index], apartName);
fprintf(STDOUT,"Deleting the previous volume %u on server %s, partition %s ...",
pvolid,
- hostutil_GetNameByINet(entry.serverNumber[index]), apartName);
+ MapAddressToHostname(entry.serverNumber[index]), apartName);
fflush(STDOUT);
}
code = AFSVolTransCreate(tempconn, pvolid, entry.serverPartition[index], ITOffline, &temptid);
@@ -3642,11 +3655,11 @@ static afs_int32 CheckVolume(volumeinfo,
if (pass == 1) {
MapPartIdIntoName(apart, pname);
fprintf(STDERR,"*** Warning: Orphaned RW volume %u exists on %s %s\n",
- rwvolid, hostutil_GetNameByINet(aserver), pname);
+ rwvolid, MapAddressToHostname(aserver), pname);
MapPartIdIntoName(entry.serverPartition[idx], pname);
fprintf(STDERR," VLDB reports RW volume %u exists on %s %s\n",
rwvolid,
- hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
+ MapAddressToHostname(entry.serverNumber[idx]), pname);
}
} else {
/* The RW volume does not exist - have VLDB point to this one */
@@ -3658,10 +3671,10 @@ static afs_int32 CheckVolume(volumeinfo,
MapPartIdIntoName(entry.serverPartition[idx], pname);
fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
entry.volumeId[BACKVOL],
- hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
+ MapAddressToHostname(entry.serverNumber[idx]), pname);
MapPartIdIntoName(apart, pname);
fprintf(STDERR," VLDB reports its RW volume %u exists on %s %s\n",
- rwvolid, hostutil_GetNameByINet(aserver), pname);
+ rwvolid, MapAddressToHostname(aserver), pname);
}
}
}
@@ -3721,11 +3734,11 @@ static afs_int32 CheckVolume(volumeinfo,
if (pass == 1) {
MapPartIdIntoName(apart, pname);
fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
- volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
+ volumeinfo->volid, MapAddressToHostname(aserver), pname);
MapPartIdIntoName(entry.serverPartition[idx], pname);
fprintf(STDERR," VLDB reports its RW/BK volume %u exists on %s %s\n",
rwvolid,
- hostutil_GetNameByINet(entry.serverNumber[idx]), pname);
+ MapAddressToHostname(entry.serverNumber[idx]), pname);
}
} else {
if (volumeinfo->volid != entry.volumeId[BACKVOL]) {
@@ -3738,7 +3751,7 @@ static afs_int32 CheckVolume(volumeinfo,
if (pass == 1) {
MapPartIdIntoName(entry.serverPartition[idx], pname);
fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
- entry.volumeId[BACKVOL], hostutil_GetNameByINet(aserver), pname);
+ entry.volumeId[BACKVOL], MapAddressToHostname(aserver), pname);
fprintf(STDERR," VLDB reports its BK volume ID is %u\n",
volumeinfo->volid);
}
@@ -3746,7 +3759,7 @@ static afs_int32 CheckVolume(volumeinfo,
if (pass == 1) {
MapPartIdIntoName(entry.serverPartition[idx], pname);
fprintf(STDERR,"*** Warning: Orphaned BK volume %u exists on %s %s\n",
- volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
+ volumeinfo->volid, MapAddressToHostname(aserver), pname);
fprintf(STDERR," VLDB reports its BK volume ID is %u\n",
entry.volumeId[BACKVOL]);
}
@@ -3813,7 +3826,7 @@ static afs_int32 CheckVolume(volumeinfo,
MapPartIdIntoName(apart, entry.serverPartition[j]);
fprintf(STDERR,"*** Warning: Orphaned RO volume %u exists on %s %s\n",
entry.volumeId[ROVOL],
- hostutil_GetNameByINet(entry.serverNumber[j]), pname);
+ MapAddressToHostname(entry.serverNumber[j]), pname);
fprintf(STDERR," VLDB reports its RO volume ID is %u\n",
volumeinfo->volid);
}
@@ -3837,7 +3850,7 @@ static afs_int32 CheckVolume(volumeinfo,
if (pass == 1) {
MapPartIdIntoName(apart, pname);
fprintf(STDERR,"*** Warning: Orphaned RO volume %u exists on %s %s\n",
- volumeinfo->volid, hostutil_GetNameByINet(aserver), pname);
+ volumeinfo->volid, MapAddressToHostname(aserver), pname);
fprintf(STDERR," VLDB reports its RO volume ID is %u\n",
entry.volumeId[ROVOL]);
}
@@ -4210,7 +4223,7 @@ UV_SyncVldb(aserver, apart, flags, force
if (verbose) {
fprintf(STDOUT,"Processing volume entry %d: %s (%u) on server %s %s...\n",
j+1, vi->name, vi->volid,
- hostutil_GetNameByINet(aserver), pname);
+ MapAddressToHostname(aserver), pname);
fflush(STDOUT);
}
@@ -4235,7 +4248,7 @@ UV_SyncVldb(aserver, apart, flags, force
if (pfail) {
fprintf(STDERR,"Could not process entries on server %s partition %s\n",
- hostutil_GetNameByINet(aserver), pname);
+ MapAddressToHostname(aserver), pname);
}
if (volumeInfo.volEntries_val) {
free(volumeInfo.volEntries_val);
@@ -4348,7 +4361,7 @@ afs_int32 CheckVldbRWBK(entry, modified)
MapPartIdIntoName(entry->serverPartition[idx], pname);
fprintf(STDERR,"Transaction call failed for RW volume %u on server %s %s\n",
entry->volumeId[RWVOL],
- hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
+ MapAddressToHostname(entry->serverNumber[idx]), pname);
ERROR_EXIT(code);
}
}
@@ -4385,7 +4398,7 @@ afs_int32 CheckVldbRWBK(entry, modified)
MapPartIdIntoName(entry->serverPartition[idx], pname);
fprintf(STDERR,"Transaction call failed for BK volume %u on server %s %s\n",
entry->volumeId[BACKVOL],
- hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
+ MapAddressToHostname(entry->serverNumber[idx]), pname);
ERROR_EXIT(code);
}
}
@@ -4443,7 +4456,7 @@ CheckVldbRO(entry, modified)
MapPartIdIntoName(entry->serverPartition[idx], pname);
fprintf(STDERR,"Transaction call failed for RO %u on server %s %s\n",
entry->volumeId[ROVOL],
- hostutil_GetNameByINet(entry->serverNumber[idx]), pname);
+ MapAddressToHostname(entry->serverNumber[idx]), pname);
ERROR_EXIT(code);
}
}
@@ -4831,7 +4844,7 @@ char oldname[],newname[];
if(!code) {
if(verbose) fprintf(STDOUT,"Renamed RO volume %s on host %s\n",
nameBuffer,
- hostutil_GetNameByINet(entry->serverNumber[i]));
+ MapAddressToHostname(entry->serverNumber[i]));
code = AFSVolEndTrans(aconn, tid, &rcode);
tid = 0;
if (code) {
--=-=-=--