From: Andrew Tridgell Date: Sun, 22 Apr 2007 07:24:27 +0000 (+0200) Subject: added a useful tool for dumping a ctdb X-Git-Tag: tevent-0.9.20~348^2~2854 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2a08818e24906618ee8c237cdfe931382384fe02;p=thirdparty%2Fsamba.git added a useful tool for dumping a ctdb (This used to be ctdb commit 671ed94011e21396571a3f4a5191b9a83911c952) --- diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in index adc1f92d0a9..0653c727afb 100644 --- a/ctdb/Makefile.in +++ b/ctdb/Makefile.in @@ -30,7 +30,7 @@ CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TCP_OBJ) OBJS = @TDBOBJ@ @TALLOCOBJ@ @LIBREPLACEOBJ@ @INFINIBAND_WRAPPER_OBJ@ $(EXTRA_OBJ) $(EVENTS_OBJ) $(CTDB_OBJ) -BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_status @INFINIBAND_BINS@ +BINS = bin/ctdbd bin/ctdbd_test bin/ctdb_test bin/ctdb_bench bin/ctdb_messaging bin/ctdb_fetch bin/ctdb_fetch1 bin/lockwait bin/ctdb_status bin/ctdb_dump @INFINIBAND_BINS@ DIRS = lib bin @@ -61,6 +61,10 @@ bin/ctdb_status: $(OBJS) tools/ctdb_status.o @echo Linking $@ @$(CC) $(CFLAGS) -o $@ tools/ctdb_status.o $(OBJS) $(LIB_FLAGS) +bin/ctdb_dump: $(OBJS) tools/ctdb_dump.o + @echo Linking $@ + @$(CC) $(CFLAGS) -o $@ tools/ctdb_dump.o $(OBJS) $(LIB_FLAGS) + bin/ctdbd_test: $(OBJS) direct/ctdbd_test.o @echo Linking $@ @$(CC) $(CFLAGS) -o $@ direct/ctdbd_test.o diff --git a/ctdb/common/util.c b/ctdb/common/util.c index 4d0b25117a7..6ccecc80c4e 100644 --- a/ctdb/common/util.c +++ b/ctdb/common/util.c @@ -194,3 +194,16 @@ _PUBLIC_ char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *me return file_lines_parse(p, size, numlines, mem_ctx); } + +char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len) +{ + int i; + char *hex_buffer; + + hex_buffer = talloc_array(mem_ctx, char, (len*2)+1); + + for (i = 0; i < len; i++) + slprintf(&hex_buffer[i*2], 3, "%02X", buff_in[i]); + + return hex_buffer; +} diff --git a/ctdb/include/includes.h b/ctdb/include/includes.h index bffc66b358b..284710ae586 100644 --- a/ctdb/include/includes.h +++ b/ctdb/include/includes.h @@ -35,3 +35,5 @@ struct timeval timeval_until(const struct timeval *tv1, _PUBLIC_ struct timeval timeval_current_ofs(uint32_t secs, uint32_t usecs); double timeval_elapsed(struct timeval *tv); char **file_lines_load(const char *fname, int *numlines, TALLOC_CTX *mem_ctx); +char *hex_encode(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); + diff --git a/ctdb/tools/ctdb_dump.c b/ctdb/tools/ctdb_dump.c new file mode 100644 index 00000000000..419151c84d8 --- /dev/null +++ b/ctdb/tools/ctdb_dump.c @@ -0,0 +1,112 @@ +/* + ctdb status tool + + Copyright (C) Andrew Tridgell 2007 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#include "includes.h" +#include "lib/events/events.h" +#include "system/filesys.h" +#include "popt.h" +#include "cmdline.h" +#include "../include/ctdb_private.h" +#include "db_wrap.h" + + +/* + show usage message + */ +static void usage(void) +{ + printf("Usage: ctdb_dump \n"); + exit(1); +} + +static int traverse_fn(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *p) +{ + struct id { + dev_t dev; + ino_t inode; + } *id; + struct ctdb_ltdb_header *h = (struct ctdb_ltdb_header *)data.dptr; + char *keystr; + id = (struct id *)key.dptr; + if (key.dsize == sizeof(*id)) { + keystr = talloc_asprintf(NULL, "%llu:%llu", + (uint64_t)id->dev, (uint64_t)id->inode); + } else { + keystr = hex_encode(NULL, key.dptr, key.dsize); + } + printf(" rec %s dmaster=%u\n", keystr, h->dmaster); + talloc_free(keystr); + return 0; +} + +/* + main program +*/ +int main(int argc, const char *argv[]) +{ + struct poptOption popt_options[] = { + POPT_AUTOHELP + POPT_CTDB_CMDLINE + POPT_TABLEEND + }; + int opt; + const char **extra_argv; + int i, extra_argc = 0; + poptContext pc; + struct tdb_wrap *db; + + pc = poptGetContext(argv[0], argc, argv, popt_options, POPT_CONTEXT_KEEP_FIRST); + + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + default: + fprintf(stderr, "Invalid option %s: %s\n", + poptBadOption(pc, 0), poptStrerror(opt)); + exit(1); + } + } + + /* setup the remaining options for the main program to use */ + extra_argv = poptGetArgs(pc); + if (extra_argv) { + extra_argv++; + while (extra_argv[extra_argc]) extra_argc++; + } + + if (extra_argc < 1) { + usage(); + } + + for (i=0;itdb, traverse_fn, NULL); + + talloc_free(db); + } + + return 0; +}