WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] xenstore-stat

To: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] xenstore-stat
From: Frank Pan <frankpzh@xxxxxxxxx>
Date: Wed, 30 Mar 2011 17:33:20 +0800
Cc:
Delivery-date: Wed, 30 Mar 2011 02:34:27 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=4aYrcLaONdieScJL3npXE9NmpE5YuXoLOejmw+gKxr0=; b=lt3lhcN1IvgQrLkGWVRYeId1YWgxGDL7fB2/KRFRhtmQ0O6D4ZYXsmOflWlqfK6EB1 NcIzDIoE5GtNGNnSkAd9/aIhIVKLqYSo8BNGEEM+tabhxR83oB0JLpjkz8Ea0V9FY4Vd lOkP2hwU/4PXub7FbBb5BjjGnR2w8DKZ/nXI0=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type :content-transfer-encoding; b=nC3BTcs20DoXi7aX+i1gKge9MuMNoJ0klzAe+LNsmrzR8dR/EL8htpWpwXPbZjbZ+G k9mYmjt5fAAWV8HKHQBTlDShNZv17yNrRcEvsQPK8LQ3k4CbP8BE8voou3mlUouL+LnP fvxrkQvX5PSDkORwYS1Pay7wn6HsKfZ+GdBWk=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
The entries in xenstore have permission attributes. The
attributes can be easily altered by xenstore-chmod, however,
I cannot find an easy way to view them.

I've modified xenstore_client.c to raise a new utility.
The utility checks the permission and makes an easy-to-look output.

Please tell me any suggestions.
Thanks.

Signed-off-by: Frank Pan <frankpzh@xxxxxxxxx>
---
 tools/xenstore/Makefile          |    2 +-
 tools/xenstore/xenstore_client.c |   51 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+), 1 deletions(-)

diff --git a/tools/xenstore/Makefile b/tools/xenstore/Makefile
index 35e68d0..ca57e9c 100644
--- a/tools/xenstore/Makefile
+++ b/tools/xenstore/Makefile
@@ -9,7 +9,7 @@ CFLAGS += -I.
 CFLAGS += $(CFLAGS_libxenctrl)

 CLIENTS := xenstore-exists xenstore-list xenstore-read xenstore-rm
xenstore-chmod
-CLIENTS += xenstore-write xenstore-ls xenstore-watch
+CLIENTS += xenstore-write xenstore-ls xenstore-watch xenstore-stat

 XENSTORED_OBJS = xenstored_core.o xenstored_watch.o
xenstored_domain.o xenstored_transaction.o xs_lib.o talloc.o utils.o
tdb.o hashtable.o

diff --git a/tools/xenstore/xenstore_client.c b/tools/xenstore/xenstore_client.c
index 94b82b9..3a537ce 100644
--- a/tools/xenstore/xenstore_client.c
+++ b/tools/xenstore/xenstore_client.c
@@ -37,6 +37,7 @@ enum mode {
     MODE_rm,
     MODE_write,
     MODE_watch,
+    MODE_stat,
 };

 static char *output_buf = NULL;
@@ -99,6 +100,9 @@ usage(enum mode mode, int incl_mode, const char *progname)
     case MODE_watch:
        mstr = incl_mode ? "watch " : "";
        errx(1, "Usage: %s %s[-h] [-n NR] key", progname, mstr);
+    case MODE_stat:
+        mstr = incl_mode ? "stat " : "";
+        errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr);
     }
 }

@@ -286,6 +290,23 @@ do_watch(struct xs_handle *xsh, int max_events)
     }
 }

+static const char *
+perm_type_str(int perm_type)
+{
+    switch (perm_type) {
+    case XS_PERM_WRITE:
+        return "-w";
+    case XS_PERM_READ:
+        return "r-";
+    case XS_PERM_READ|XS_PERM_WRITE:
+        return "rw";
+    case XS_PERM_NONE:
+        return "--";
+    default:
+        return "uu";
+    }
+}
+
 static int
 perform(enum mode mode, int optind, int argc, char **argv, struct
xs_handle *xsh,
         xs_transaction_t xth, int prefix, int tidy, int upto, int
recurse, int nr_watches)
@@ -459,6 +480,34 @@ perform(enum mode mode, int optind, int argc,
char **argv, struct xs_handle *xsh
                     errx(1, "Unable to add watch on %s\n", w);
             }
             do_watch(xsh, nr_watches);
+            break;
+        }
+        case MODE_stat: {
+            unsigned int i, nperms;
+            struct xs_permissions *perms;
+
+            perms = xs_get_permissions(xsh, xth, argv[optind], &nperms);
+            if (!perms)
+                errx(1, "Unable to get permission on %s\n", argv[optind]);
+
+            if (!nperms) {
+                free(perms);
+                errx(1, "Cannot determine owner of %s\n", argv[optind]);
+            }
+
+            output("Owner:\t\t\t%d\n", perms[0].id);
+            output("Default permission:\t%s\n", perm_type_str(perms[0].perms));
+            output("Permissions:\t\t", perms[0].id);
+            for (i = 1; i < nperms; i++) {
+                output("%d: %s", perms[0].id,
+                       perm_type_str(perms[0].perms));
+                if (i < nperms - 1)
+                    output(" ");
+            }
+            output("\n");
+            free(perms);
+            optind++;
+            break;
         }
         }
     }
@@ -486,6 +535,8 @@ static enum mode lookup_mode(const char *m)
        return MODE_read;
     else if (strcmp(m, "watch") == 0)
        return MODE_watch;
+    else if (strcmp(m, "stat") == 0)
+       return MODE_stat;

     errx(1, "unknown mode %s\n", m);
     return 0;
-- 
1.7.1


-- 
潘震皓, Frank Pan

Computer Science and Technology
Tsinghua University

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel