---------- Forwarded message ----------
From: Mohammed Gamal <[email protected]>
Date: Sun, Apr 18, 2010 at 6:03 PM
Subject: [PATCH] Add -xml commandline option to vos examine
To: [email protected]


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 <[email protected]>
---
 src/volser/vos.c |  120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 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)
 }

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

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

--
1.6.3.3




-- 
Derrick
_______________________________________________
OpenAFS-devel mailing list
[email protected]
https://lists.openafs.org/mailman/listinfo/openafs-devel

Reply via email to