[OpenAFS-devel] Fwd: [PATCH] Add -xml commandline option to vos examine

Derrick Brashear shadow@gmail.com
Mon, 19 Apr 2010 09:12:36 -0400


---------- Forwarded message ----------
From: Mohammed Gamal <m.gamal005@gmail.com>
Date: Sun, Apr 18, 2010 at 6:03 PM
Subject: [PATCH] Add -xml commandline option to vos examine
To: shadow@gmail.com


This patch adds a -xml commandline switch to generate
a machine readable format from vos examine in XML.
It's pretty quick and dirty. So your feedback is greatly
appreciated.

Signed-off-by: Mohammed Gamal <m.gamal005@gmail.com>
---
=A0src/volser/vos.c | =A0120 ++++++++++++++++++++++++++++++++++++++++++++++=
++++++++
=A01 files changed, 120 insertions(+), 0 deletions(-)

diff --git a/src/volser/vos.c b/src/volser/vos.c
index 648606e..288b5f5 100644
--- a/src/volser/vos.c
+++ b/src/volser/vos.c
@@ -1149,6 +1149,121 @@ DisplayFormat2(long server, long partition,
volintInfo *pntr)
=A0}

=A0static void
+DisplayXML(long server, long partition, volintInfo *pntr)
+{
+ =A0 =A0static long server_cache =3D -1, partition_cache =3D -1;
+ =A0 =A0static char hostname[256], address[32], pname[16];
+ =A0 =A0time_t t;
+
+ =A0 =A0if (server !=3D server_cache) {
+ =A0 =A0 =A0 struct in_addr s;
+
+ =A0 =A0 =A0 s.s_addr =3D server;
+ =A0 =A0 =A0 strcpy(hostname, hostutil_GetNameByINet(server));
+ =A0 =A0 =A0 strcpy(address, inet_ntoa(s));
+ =A0 =A0 =A0 server_cache =3D server;
+ =A0 =A0}
+ =A0 =A0if (partition !=3D partition_cache) {
+ =A0 =A0 =A0 MapPartIdIntoName(partition, pname);
+ =A0 =A0 =A0 partition_cache =3D partition;
+ =A0 =A0}
+
+ =A0 =A0fprintf(STDOUT, "<?xml version=3D\"1.0\" encoding=3D\"ISO-8859-1\"=
?>\n");
+ =A0 =A0fprintf(STDOUT, "\t<info>\n"); /* Should we select some better nam=
e? */
+ =A0 =A0if (pntr->status =3D=3D VOK)
+ =A0 =A0 =A0 =A0fprintf(STDOUT, "\t\t<name>%s</name>\n", pntr->name);
+
+ =A0 =A0fprintf(STDOUT, "\t\t<id>%lu</id>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->volid));
+ =A0 =A0fprintf(STDOUT, "\t\t<serv>%s\t%s</serv>\n", address, hostname);
+ =A0 =A0fprintf(STDOUT, "\t\t<part>%s</part>\n", pname);
+ =A0 =A0fprintf(STDOUT, "\t\t<status>");
+ =A0 =A0switch (pntr->status) {
+ =A0 =A0case VOK:
+ =A0 =A0 =A0 fprintf(STDOUT, "OK");
+ =A0 =A0 =A0 break;
+ =A0 =A0case VBUSY:
+ =A0 =A0 =A0 fprintf(STDOUT, "BUSY");
+ =A0 =A0 =A0 return;
+ =A0 =A0default:
+ =A0 =A0 =A0 fprintf(STDOUT, "UNATTACHABLE");
+ =A0 =A0 =A0 return;
+ =A0 =A0}
+ =A0 =A0fprintf(STDOUT, "</status>\n");
+ =A0 =A0fprintf(STDOUT, "\t\t<backupID>%lu</backupID>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->backupID));
+ =A0 =A0fprintf(STDOUT, "\t\t<parentID>%lu</parentID>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->parentID));
+ =A0 =A0fprintf(STDOUT, "\t\t<cloneID>%lu</cloneID>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->cloneID));
+ =A0 =A0fprintf(STDOUT, "\t\t<inUse>%s</inUse>\n", pntr->inUse ? "Y" : "N"=
);
+ =A0 =A0fprintf(STDOUT, "\t\t<needsSalvaged>%s</needsSalvaged>\n",
pntr->needsSalvaged ? "Y" : "N");
+ =A0 =A0/* 0xD3 is from afs/volume.h since I had trouble including the fil=
e */
+ =A0 =A0fprintf(STDOUT, "\t\t<destroyMe>%s</destroyMe>\n",
pntr->destroyMe =3D=3D 0xD3 ? "Y" : "N");
+ =A0 =A0fprintf(STDOUT, "\t\t<type>");
+ =A0 =A0switch (pntr->type) {
+ =A0 =A0case 0:
+ =A0 =A0 =A0 fprintf(STDOUT, "RW");
+ =A0 =A0 =A0 break;
+ =A0 =A0case 1:
+ =A0 =A0 =A0 fprintf(STDOUT, "RO");
+ =A0 =A0 =A0 break;
+ =A0 =A0case 2:
+ =A0 =A0 =A0 fprintf(STDOUT, "BK");
+ =A0 =A0 =A0 break;
+ =A0 =A0default:
+ =A0 =A0 =A0 fprintf(STDOUT, "?");
+ =A0 =A0 =A0 break;
+ =A0 =A0}
+ =A0 =A0fprintf(STDOUT, "</type>\n");
+
+ =A0 =A0/* ctime() appends a newline character at the end of the date stri=
ng.
+ =A0 =A0 * Get around that by enclosing tags on different lines and adjust=
ing
+ =A0 =A0 * tab levels */
+ =A0 =A0t =3D pntr->creationDate;
+ =A0 =A0fprintf(STDOUT, "\t\t<creationDate>\n\t\t\t%-9lu\t%s\t\t</creation=
Date>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->creationDate),
+ =A0 =A0 =A0 =A0 =A0 ctime(&t));
+
+ =A0 =A0t =3D pntr->accessDate;
+ =A0 =A0fprintf(STDOUT, "\t\t<accessDate>\n\t\t\t%-9lu\t%s\t\t</accessDate=
>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->accessDate),
+ =A0 =A0 =A0 =A0 =A0 ctime(&t));
+
+ =A0 =A0t =3D pntr->updateDate;
+ =A0 =A0fprintf(STDOUT, "\t\t<updateDate>\n\t\t\t%-9lu\t%s\t\t</updateDate=
>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->updateDate),
+ =A0 =A0 =A0 =A0 =A0 ctime(&t));
+
+ =A0 =A0t =3D pntr->backupDate;
+ =A0 =A0fprintf(STDOUT, "\t\t<backupDate>\n\t\t\t%-9lu\t%s\t\t</backupDate=
>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->backupDate),
+ =A0 =A0 =A0 =A0 =A0 ctime(&t));
+
+ =A0 =A0t =3D pntr->copyDate;
+ =A0 =A0fprintf(STDOUT, "\t\t<copyDate>\n\t\t\t%-9lu\t%s\t\t</copyDate>\n"=
,
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->copyDate),
+ =A0 =A0 =A0 =A0 =A0 ctime(&t));
+
+ =A0 =A0fprintf(STDOUT, "\t\t<flags>%#lx</flags>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->flags));
+ =A0 =A0fprintf(STDOUT, "\t\t<diskused>%u</diskused>\n", pntr->size);
+ =A0 =A0fprintf(STDOUT, "\t\t<maxquota>%u</maxquota>\n", pntr->maxquota);
+ =A0 =A0fprintf(STDOUT, "\t\t<minquota>%lu</minquota>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->spare0));
+ =A0 =A0fprintf(STDOUT, "\t\t<filecount>%u</filecount>\n", pntr->filecount=
);
+ =A0 =A0fprintf(STDOUT, "\t\t<dayUse>%u</dayUse>\n", pntr->dayUse);
+ =A0 =A0fprintf(STDOUT, "\t\t<weekUse>%lu</weekUse>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->spare1));
+ =A0 =A0fprintf(STDOUT, "\t\t<spare2>%lu</spare2>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->spare2));
+ =A0 =A0fprintf(STDOUT, "\t\t<spare3>%lu</spare3>\n",
+ =A0 =A0 =A0 =A0 =A0 afs_printable_uint32_lu(pntr->spare3));
+ =A0 =A0fprintf(STDOUT, "\t</info>\n");
+ =A0 =A0return;
+}
+
+static void
=A0DisplayVolumes2(long server, long partition, volintInfo *pntr, long coun=
t)
=A0{
=A0 =A0 long i;
@@ -1643,6 +1758,9 @@ ExamineVolume(register struct cmd_syndesc *as,
void *arock)
=A0 =A0 =A0 =A0 =A0 =A0else if (as->parms[2].items) {
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DisplayFormat2(aserver, apart, pntr);
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0EnumerateEntry(&entry);
+ =A0 =A0 =A0 =A0 =A0 =A0} else if (as->parms[3].items) {
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0DisplayXML(aserver, apart, pntr);
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0EnumerateEntry(&entry);
=A0 =A0 =A0 =A0 =A0 =A0} else
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0VolumeStats_int(pntr, &entry, aserver, apart=
, voltype);

@@ -6101,6 +6219,8 @@ main(int argc, char **argv)
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"list extended volume fields");
=A0 =A0 cmd_AddParm(ts, "-format", CMD_FLAG, CMD_OPTIONAL,
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"machine readable format");
+ =A0 =A0cmd_AddParm(ts, "-xml", CMD_FLAG, CMD_OPTIONAL,
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"xml format");
=A0 =A0 COMMONPARMS;
=A0 =A0 cmd_CreateAlias(ts, "volinfo");

--
1.6.3.3




--=20
Derrick