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@gmail.com> --- 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@lists.xensource.com http://lists.xensource.com/xen-devel
On Wed, 2011-03-30 at 10:33 +0100, Frank Pan wrote:> 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.You can sort of get this from "xenstore-ls -p" but a stat option seems like a worthwhile addition.> Please tell me any suggestions.I think I''d suggest pulling the core of the new functionality out of perform() and into a new function do_stat().> + case MODE_stat: > + mstr = incl_mode ? "stat " : ""; > + errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr);Does it deal with multiple key names as a paramter? If not then I guess the [...] can be dropped, or else the necessary support added.> +static const char * > +perm_type_str(int perm_type) > +{Can you use xs_perm_to_string here instead?> @@ -459,6 +480,34 @@ perform(enum mode mode, int optind, int argc,[...]> + 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);Unused parameter? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
> You can sort of get this from "xenstore-ls -p" but a stat option seems > like a worthwhile addition.Didn''t know this before. :(> I think I''d suggest pulling the core of the new functionality out of > perform() and into a new function do_stat().Good idea.>> + case MODE_stat: >> + mstr = incl_mode ? "stat " : ""; >> + errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr); > > Does it deal with multiple key names as a paramter? If not then I guess > the [...] can be dropped, or else the necessary support added.Sure, xenstore-stat can accept multiple keys.>> +static const char * >> +perm_type_str(int perm_type) >> +{ > > Can you use xs_perm_to_string here instead?I''d like to make it more similar to unix permissions. ("-rwx") I think it''s more straightforward than "w/r/b/n". Is this a good idea?> Unused parameter?Yes. My compiler did not complain, weird. -- 潘震皓, Frank Pan Computer Science and Technology Tsinghua University _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
> Unused parameter?More horrible coding issues have been found. I''ll post another patch instead. -- 潘震皓, Frank Pan Computer Science and Technology Tsinghua University _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
(I saw the second posting but the same issues are present there so I reply here to keep the conversational context) On Wed, 2011-03-30 at 13:03 +0100, Frank Pan wrote:> >> + case MODE_stat: > >> + mstr = incl_mode ? "stat " : ""; > >> + errx(1, "Usage: %s %s[-h] [-s] key [...]", progname, mstr); > > > > Does it deal with multiple key names as a paramter? If not then I guess > > the [...] can be dropped, or else the necessary support added. > > Sure, xenstore-stat can accept multiple keys.But it doesn''t have a loop over optind or anything. It looks to me like it will just print the info for the first key.> >> +static const char * > >> +perm_type_str(int perm_type) > >> +{ > > > > Can you use xs_perm_to_string here instead? > > I''d like to make it more similar to unix permissions. ("-rwx") > I think it''s more straightforward than "w/r/b/n". > Is this a good idea?I''m not sure. The current xs way of doing things is odd compared with unix permissions but it''s what people are used to and what they need to type as n argument to xenstore-chmod. The last point is particularly compelling IMHO.> > > Unused parameter? > > Yes. My compiler did not complain, weird. >_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
> But it doesn''t have a loop over optind or anything. It looks to me like > it will just print the info for the first key.A big while sit inside perform(): while (optind < argc) { switch (mode) { blah blah... And also I just tested that. -- 潘震皓, Frank Pan Computer Science and Technology Tsinghua University _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
On Wed, 2011-03-30 at 14:13 +0100, Frank Pan wrote:> > But it doesn''t have a loop over optind or anything. It looks to me like > > it will just print the info for the first key. > > A big while sit inside perform(): > > while (optind < argc) { > switch (mode) { > blah blah...So there is, I even went and looked for it before commenting and missed it.> And also I just tested that.Thanks! _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Campbell writes ("Re: [Xen-devel] [PATCH] xenstore-stat"):> On Wed, 2011-03-30 at 13:03 +0100, Frank Pan wrote: > > I''d like to make it more similar to unix permissions. ("-rwx") > > I think it''s more straightforward than "w/r/b/n". > > Is this a good idea? > > I''m not sure. The current xs way of doing things is odd compared with > unix permissions but it''s what people are used to and what they need to > type as n argument to xenstore-chmod. The last point is particularly > compelling IMHO.I agree. I think we should use xs_perm_to_string exclusively and not introduce a new format. If we do introduce a new format it should be done as a separate task and should be done in xs_perm_to_string (perhaps optionally) so that all the tools benefit. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel