diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2005-09-23 14:25:01 +0100 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2005-09-23 14:25:01 +0100 |
commit | f11f68cd1157d84615621edcd7321a6d0a09b158 (patch) | |
tree | becbcc239c8b8c0f26e08428b4ac798fa5bdb4fc /tools/xenstore/xs_tdb_dump.c | |
parent | 7c7896249b7ffa3a0e6c1c749c8c3b08edf2ae70 (diff) | |
download | xen-f11f68cd1157d84615621edcd7321a6d0a09b158.tar.gz xen-f11f68cd1157d84615621edcd7321a6d0a09b158.tar.bz2 xen-f11f68cd1157d84615621edcd7321a6d0a09b158.zip |
Make xenstored use tdb, transactions can soft-fail (EAGAIN)
Transactions no longer take root dir, no longer lock & block: commit can fail spuriously with EAGAIN, not ETIMEDOUT.
Speeds up transactions by over 1000 times, should be NFS safe.
New program: xs_tdb_dump to dump raw TDB contents.
Don't do failure testing: we are no longer robust against all ENOMEM 8(
Introduce "struct node" which contains perms, children and data.
Make struct xs_permissions unpadded, so we can write to tdb w/o valgrind complaints.
Gently modify TDB to use talloc, not do alloc on tdb_delete.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'tools/xenstore/xs_tdb_dump.c')
-rw-r--r-- | tools/xenstore/xs_tdb_dump.c | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/tools/xenstore/xs_tdb_dump.c b/tools/xenstore/xs_tdb_dump.c new file mode 100644 index 0000000000..1cab37ed6d --- /dev/null +++ b/tools/xenstore/xs_tdb_dump.c @@ -0,0 +1,81 @@ +/* Simple program to dump out all records of TDB */ +#include <stdint.h> +#include <stdlib.h> +#include <fcntl.h> +#include <stdio.h> + +#include "xs_lib.h" +#include "tdb.h" +#include "talloc.h" +#include "utils.h" + +struct record_hdr { + u32 num_perms; + u32 datalen; + u32 childlen; + struct xs_permissions perms[0]; +}; + +static u32 total_size(struct record_hdr *hdr) +{ + return sizeof(*hdr) + hdr->num_perms * sizeof(struct xs_permissions) + + hdr->datalen + hdr->childlen; +} + +static char perm_to_char(enum xs_perm_type perm) +{ + return perm == XS_PERM_READ ? 'r' : + perm == XS_PERM_WRITE ? 'w' : + perm == XS_PERM_NONE ? '-' : + perm == (XS_PERM_READ|XS_PERM_WRITE) ? 'b' : + '?'; +} + +int main(int argc, char *argv[]) +{ + TDB_DATA key; + TDB_CONTEXT *tdb; + + if (argc != 2) + barf("Usage: xs_tdb_dump <tdbfile>"); + + tdb = tdb_open(talloc_strdup(NULL, argv[1]), 0, 0, O_RDONLY, 0); + if (!tdb) + barf_perror("Could not open %s", argv[1]); + + key = tdb_firstkey(tdb); + while (key.dptr) { + TDB_DATA data; + struct record_hdr *hdr; + + data = tdb_fetch(tdb, key); + hdr = (void *)data.dptr; + if (data.dsize < sizeof(*hdr)) + fprintf(stderr, "%.*s: BAD truncated\n", + key.dsize, key.dptr); + else if (data.dsize != total_size(hdr)) + fprintf(stderr, "%.*s: BAD length %i for %i/%i/%i (%i)\n", + key.dsize, key.dptr, data.dsize, + hdr->num_perms, hdr->datalen, + hdr->childlen, total_size(hdr)); + else { + unsigned int i; + char *p; + + printf("%.*s: ", key.dsize, key.dptr); + for (i = 0; i < hdr->num_perms; i++) + printf("%s%c%i", + i == 0 ? "" : ",", + perm_to_char(hdr->perms[i].perms), + hdr->perms[i].id); + p = (void *)&hdr->perms[hdr->num_perms]; + printf(" %.*s\n", hdr->datalen, p); + p += hdr->datalen; + for (i = 0; i < hdr->childlen; i += strlen(p+i)+1) + printf("\t-> %s\n", p+i); + } + key = tdb_nextkey(tdb, key); + } + return 0; +} + |