direct-io.hg

changeset 7300:dfadbb90d092

Added xsls utility, which recursively lists the contents of the store.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Tue Oct 11 10:29:29 2005 +0100 (2005-10-11)
parents 4b93736d64f7
children 813bc65bde2a
files .hgignore tools/xenstore/Makefile tools/xenstore/xsls.c
line diff
     1.1 --- a/.hgignore	Tue Oct 11 10:03:54 2005 +0100
     1.2 +++ b/.hgignore	Tue Oct 11 10:29:29 2005 +0100
     1.3 @@ -161,6 +161,7 @@
     1.4  ^tools/xenstore/xs_tdb_dump$
     1.5  ^tools/xenstore/xs_test$
     1.6  ^tools/xenstore/xs_watch_stress$
     1.7 +^tools/xenstore/xsls$
     1.8  ^tools/xentrace/xenctx$
     1.9  ^tools/xentrace/xentrace$
    1.10  ^xen/BLOG$
     2.1 --- a/tools/xenstore/Makefile	Tue Oct 11 10:03:54 2005 +0100
     2.2 +++ b/tools/xenstore/Makefile	Tue Oct 11 10:29:29 2005 +0100
     2.3 @@ -27,7 +27,7 @@ CLIENTS := xenstore-exists xenstore-list
     2.4  CLIENTS += xenstore-write
     2.5  CLIENTS_OBJS := $(patsubst xenstore-%,xenstore_%.o,$(CLIENTS))
     2.6  
     2.7 -all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump
     2.8 +all: libxenstore.so xenstored $(CLIENTS) xs_tdb_dump xsls
     2.9  
    2.10  testcode: xs_test xenstored_test xs_random
    2.11  
    2.12 @@ -40,6 +40,9 @@ xenstored: xenstored_core.o xenstored_wa
    2.13  $(CLIENTS_OBJS): xenstore_%.o: xenstore_client.c
    2.14  	$(COMPILE.c) -DCLIENT_$(*F) -o $@ $<
    2.15  
    2.16 +xsls: xsls.o
    2.17 +	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -lxenctrl -L. -lxenstore -o $@
    2.18 +
    2.19  xenstored_test: xenstored_core_test.o xenstored_watch_test.o xenstored_domain_test.o xenstored_transaction_test.o xs_lib.o talloc_test.o fake_libxc.o utils.o tdb.o
    2.20  	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
    2.21  
    2.22 @@ -134,6 +137,7 @@ install: libxenstore.so xenstored $(CLIE
    2.23  	$(INSTALL_DIR) -p $(DESTDIR)/usr/include
    2.24  	$(INSTALL_PROG) xenstored $(DESTDIR)/usr/sbin
    2.25  	$(INSTALL_PROG) $(CLIENTS) $(DESTDIR)/usr/bin
    2.26 +	$(INSTALL_PROG) xsls $(DESTDIR)/usr/bin
    2.27  	$(INSTALL_DIR) -p $(DESTDIR)/usr/$(LIBDIR)
    2.28  	$(INSTALL_DATA) libxenstore.so $(DESTDIR)/usr/$(LIBDIR)
    2.29  	$(INSTALL_DATA) xs.h $(DESTDIR)/usr/include
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/xenstore/xsls.c	Tue Oct 11 10:29:29 2005 +0100
     3.3 @@ -0,0 +1,47 @@
     3.4 +#include <stdio.h>
     3.5 +#include <stdlib.h>
     3.6 +#include <string.h>
     3.7 +#include <err.h>
     3.8 +#include <xs.h>
     3.9 +
    3.10 +void print_dir(struct xs_handle *h, char *path, int cur_depth)
    3.11 +{
    3.12 +    char **e;
    3.13 +    char newpath[512], *val;
    3.14 +    int num, i, len;
    3.15 +
    3.16 +    e = xs_directory(h, NULL, path, &num);
    3.17 +    if (e == NULL)
    3.18 +        err(1, "xs_directory (%s)", path);
    3.19 +
    3.20 +    for (i = 0; i<num; i++) {
    3.21 +        int j;
    3.22 +        for (j=0; j<cur_depth; j++) printf(" ");
    3.23 +        printf("%s", e[i]);
    3.24 +        sprintf(newpath, "%s%s%s", path, 
    3.25 +                path[strlen(path)-1] == '/' ? "" : "/", 
    3.26 +                e[i]);
    3.27 +        val = xs_read(h, NULL, newpath, &len);
    3.28 +        if (val == NULL)
    3.29 +            printf(":\n");
    3.30 +        else if ((unsigned)len > (151 - strlen(e[i])))
    3.31 +            printf(" = \"%.*s...\"\n", 148 - strlen(e[i]), val);
    3.32 +        else
    3.33 +            printf(" = \"%s\"\n", val);
    3.34 +        free(val);
    3.35 +        print_dir(h, newpath, cur_depth+1); 
    3.36 +    }
    3.37 +    free(e);
    3.38 +}
    3.39 +
    3.40 +int main(int argc, char *argv[])
    3.41 +{
    3.42 +    struct xs_handle *xsh = xs_daemon_open();
    3.43 +
    3.44 +    if (xsh == NULL)
    3.45 +        err(1, "xs_daemon_open");
    3.46 +
    3.47 +    print_dir(xsh, argc == 1 ? "/" : argv[1], 0);
    3.48 +
    3.49 +    return 0;
    3.50 +}