From acf26089f18c163290a0540ece1209aea26834d5 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 15 Aug 2014 15:46:33 +1000 Subject: ctdb-util: Rename db_wrap to tdb_wrap and make it a build subsystem This makes it consistent with Samba, to ease transition. Update unit test code to link to with tdb_wrap instead of including db_wrap.c. There are some potential whitespace fixes in this commit that have been ignored. CTDB's lib/tdb_wrap will be deleted after the transition to Samba's lib/tdb_wrap, so there's no point polishing it too much. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- ctdb/client/ctdb_client.c | 2 +- ctdb/common/ctdb_ltdb.c | 2 +- ctdb/lib/tdb_wrap/tdb_wrap.c | 103 +++++++++++++++++++++++++ ctdb/lib/tdb_wrap/tdb_wrap.h | 36 +++++++++ ctdb/lib/tdb_wrap/wscript_build | 7 ++ ctdb/lib/util/db_wrap.c | 103 ------------------------- ctdb/lib/util/db_wrap.h | 36 --------- ctdb/lib/util/wscript_build | 2 +- ctdb/server/ctdb_control.c | 2 +- ctdb/server/ctdb_daemon.c | 2 +- ctdb/server/ctdb_freeze.c | 2 +- ctdb/server/ctdb_lock.c | 2 +- ctdb/server/ctdb_ltdb_server.c | 2 +- ctdb/server/ctdb_persistent.c | 2 +- ctdb/server/ctdb_recover.c | 2 +- ctdb/server/ctdb_recoverd.c | 2 +- ctdb/server/ctdb_traverse.c | 2 +- ctdb/server/ctdb_update_record.c | 2 +- ctdb/server/ctdb_vacuum.c | 2 +- ctdb/tests/src/ctdb_test.c | 1 - ctdb/tests/src/ctdb_trackingdb_test.c | 2 +- ctdb/tests/src/ctdb_update_record_persistent.c | 2 +- ctdb/tests/src/ctdbd_test.c | 1 - ctdb/tools/ctdb.c | 2 +- ctdb/tools/ctdb_vacuum.c | 2 +- ctdb/wscript | 13 +++- 26 files changed, 173 insertions(+), 163 deletions(-) create mode 100644 ctdb/lib/tdb_wrap/tdb_wrap.c create mode 100644 ctdb/lib/tdb_wrap/tdb_wrap.h create mode 100755 ctdb/lib/tdb_wrap/wscript_build delete mode 100644 ctdb/lib/util/db_wrap.c delete mode 100644 ctdb/lib/util/db_wrap.h diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 3e19d10b95..7d629dbde1 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -19,7 +19,7 @@ */ #include "includes.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "lib/util/dlinklist.h" #include "system/network.h" diff --git a/ctdb/common/ctdb_ltdb.c b/ctdb/common/ctdb_ltdb.c index 103d89bf2b..f4d571ec96 100644 --- a/ctdb/common/ctdb_ltdb.c +++ b/ctdb/common/ctdb_ltdb.c @@ -23,7 +23,7 @@ #include "system/network.h" #include "system/filesys.h" #include "../include/ctdb_private.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" /* diff --git a/ctdb/lib/tdb_wrap/tdb_wrap.c b/ctdb/lib/tdb_wrap/tdb_wrap.c new file mode 100644 index 0000000000..2a6dbe5e82 --- /dev/null +++ b/ctdb/lib/tdb_wrap/tdb_wrap.c @@ -0,0 +1,103 @@ +/* + Unix SMB/CIFS implementation. + + database wrap functions + + Copyright (C) Andrew Tridgell 2004 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +/* + the stupidity of the unix fcntl locking design forces us to never + allow a database file to be opened twice in the same process. These + wrappers provide convenient access to a tdb or ldb, taking advantage + of talloc destructors to ensure that only a single open is done +*/ + +#include "includes.h" +#include "lib/util/dlinklist.h" +#include "tdb.h" +#include "tdb_wrap.h" + +static struct tdb_wrap *tdb_list; + + + +/* destroy the last connection to a tdb */ +static int tdb_wrap_destructor(struct tdb_wrap *w) +{ + tdb_close(w->tdb); + DLIST_REMOVE(tdb_list, w); + return 0; +} + +static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) +{ + if (level <= TDB_DEBUG_ERROR) { + va_list ap; + char newfmt[strlen(tdb_name(tdb)) + 1 + strlen(fmt) + 1]; + this_log_level = level; + sprintf(newfmt, "%s:%s", tdb_name(tdb), fmt); + va_start(ap, fmt); + do_debug_v(newfmt, ap); + va_end(ap); + } +} + + +/* + wrapped connection to a tdb database + to close just talloc_free() the tdb_wrap pointer + */ +struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, + const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode) +{ + struct tdb_wrap *w; + struct tdb_logging_context log_ctx; + + log_ctx.log_fn = log_fn; + log_ctx.log_private = NULL; + + for (w=tdb_list;w;w=w->next) { + if (strcmp(name, w->name) == 0) { + return talloc_reference(mem_ctx, w); + } + } + + w = talloc(mem_ctx, struct tdb_wrap); + if (w == NULL) { + return NULL; + } + + w->name = talloc_strdup(w, name); + if (w->name == NULL) { + talloc_free(w); + return NULL; + } + + w->tdb = tdb_open_ex(name, hash_size, tdb_flags, + open_flags, mode, &log_ctx, NULL); + if (w->tdb == NULL) { + talloc_free(w); + return NULL; + } + + talloc_set_destructor(w, tdb_wrap_destructor); + + DLIST_ADD(tdb_list, w); + + return w; +} diff --git a/ctdb/lib/tdb_wrap/tdb_wrap.h b/ctdb/lib/tdb_wrap/tdb_wrap.h new file mode 100644 index 0000000000..b11d9585e3 --- /dev/null +++ b/ctdb/lib/tdb_wrap/tdb_wrap.h @@ -0,0 +1,36 @@ +/* + Unix SMB/CIFS implementation. + + database wrap headers + + Copyright (C) Andrew Tridgell 2004 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program 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 General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see . +*/ + +#ifndef _DB_WRAP_H +#define _DB_WRAP_H + +struct tdb_wrap { + struct tdb_context *tdb; + + const char *name; + struct tdb_wrap *next, *prev; +}; + +struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, + const char *name, int hash_size, int tdb_flags, + int open_flags, mode_t mode); + +#endif /* _DB_WRAP_H */ diff --git a/ctdb/lib/tdb_wrap/wscript_build b/ctdb/lib/tdb_wrap/wscript_build new file mode 100755 index 0000000000..39a128aeab --- /dev/null +++ b/ctdb/lib/tdb_wrap/wscript_build @@ -0,0 +1,7 @@ +#!/usr/bin/python + +bld.SAMBA_SUBSYSTEM('tdb-wrap', + source='tdb_wrap.c', + deps='tdb talloc', + local_include=False + ) diff --git a/ctdb/lib/util/db_wrap.c b/ctdb/lib/util/db_wrap.c deleted file mode 100644 index bc174a42a8..0000000000 --- a/ctdb/lib/util/db_wrap.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - database wrap functions - - Copyright (C) Andrew Tridgell 2004 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . -*/ - -/* - the stupidity of the unix fcntl locking design forces us to never - allow a database file to be opened twice in the same process. These - wrappers provide convenient access to a tdb or ldb, taking advantage - of talloc destructors to ensure that only a single open is done -*/ - -#include "includes.h" -#include "lib/util/dlinklist.h" -#include "tdb.h" -#include "db_wrap.h" - -static struct tdb_wrap *tdb_list; - - - -/* destroy the last connection to a tdb */ -static int tdb_wrap_destructor(struct tdb_wrap *w) -{ - tdb_close(w->tdb); - DLIST_REMOVE(tdb_list, w); - return 0; -} - -static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...) -{ - if (level <= TDB_DEBUG_ERROR) { - va_list ap; - char newfmt[strlen(tdb_name(tdb)) + 1 + strlen(fmt) + 1]; - this_log_level = level; - sprintf(newfmt, "%s:%s", tdb_name(tdb), fmt); - va_start(ap, fmt); - do_debug_v(newfmt, ap); - va_end(ap); - } -} - - -/* - wrapped connection to a tdb database - to close just talloc_free() the tdb_wrap pointer - */ -struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) -{ - struct tdb_wrap *w; - struct tdb_logging_context log_ctx; - - log_ctx.log_fn = log_fn; - log_ctx.log_private = NULL; - - for (w=tdb_list;w;w=w->next) { - if (strcmp(name, w->name) == 0) { - return talloc_reference(mem_ctx, w); - } - } - - w = talloc(mem_ctx, struct tdb_wrap); - if (w == NULL) { - return NULL; - } - - w->name = talloc_strdup(w, name); - if (w->name == NULL) { - talloc_free(w); - return NULL; - } - - w->tdb = tdb_open_ex(name, hash_size, tdb_flags, - open_flags, mode, &log_ctx, NULL); - if (w->tdb == NULL) { - talloc_free(w); - return NULL; - } - - talloc_set_destructor(w, tdb_wrap_destructor); - - DLIST_ADD(tdb_list, w); - - return w; -} diff --git a/ctdb/lib/util/db_wrap.h b/ctdb/lib/util/db_wrap.h deleted file mode 100644 index 5ae5fd10ae..0000000000 --- a/ctdb/lib/util/db_wrap.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - database wrap headers - - Copyright (C) Andrew Tridgell 2004 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3 of the License, or - (at your option) any later version. - - This program 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 General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see . -*/ - -#ifndef _DB_WRAP_H -#define _DB_WRAP_H - -struct tdb_wrap { - struct tdb_context *tdb; - - const char *name; - struct tdb_wrap *next, *prev; -}; - -struct tdb_wrap *tdb_wrap_open(TALLOC_CTX *mem_ctx, - const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); - -#endif /* _DB_WRAP_H */ diff --git a/ctdb/lib/util/wscript_build b/ctdb/lib/util/wscript_build index 243566860a..89e69588b0 100755 --- a/ctdb/lib/util/wscript_build +++ b/ctdb/lib/util/wscript_build @@ -1,7 +1,7 @@ #!/usr/bin/env python bld.SAMBA_SUBSYSTEM('ctdb-util', - source='''util.c util_file.c util_time.c db_wrap.c + source='''util.c util_file.c util_time.c debug.c fault.c idtree.c signal.c substitute.c''', deps='tdb talloc', diff --git a/ctdb/server/ctdb_control.c b/ctdb/server/ctdb_control.c index 1f9e4bc5a0..c350cde286 100644 --- a/ctdb/server/ctdb_control.c +++ b/ctdb/server/ctdb_control.c @@ -23,7 +23,7 @@ #include "system/wait.h" #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" struct ctdb_control_state { diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index bf8b82dd70..fd5413b75f 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -18,7 +18,7 @@ */ #include "includes.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "lib/util/dlinklist.h" #include "system/network.h" diff --git a/ctdb/server/ctdb_freeze.c b/ctdb/server/ctdb_freeze.c index d68b0183ac..ced2cca518 100644 --- a/ctdb/server/ctdb_freeze.c +++ b/ctdb/server/ctdb_freeze.c @@ -23,7 +23,7 @@ #include "system/wait.h" #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "../common/rb_tree.h" /* diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index 5ad2500be6..e1a9fed772 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -22,7 +22,7 @@ #include "include/ctdb_protocol.h" #include "tevent.h" #include "tdb.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "system/filesys.h" #include "lib/util/dlinklist.h" diff --git a/ctdb/server/ctdb_ltdb_server.c b/ctdb/server/ctdb_ltdb_server.c index fb4bb0ab5e..8fb2bc7ce9 100644 --- a/ctdb/server/ctdb_ltdb_server.c +++ b/ctdb/server/ctdb_ltdb_server.c @@ -25,7 +25,7 @@ #include "system/time.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" #include diff --git a/ctdb/server/ctdb_persistent.c b/ctdb/server/ctdb_persistent.c index cfbea63cc5..e28622f20e 100644 --- a/ctdb/server/ctdb_persistent.c +++ b/ctdb/server/ctdb_persistent.c @@ -21,7 +21,7 @@ #include "includes.h" #include "system/filesys.h" #include "system/wait.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "../include/ctdb_private.h" diff --git a/ctdb/server/ctdb_recover.c b/ctdb/server/ctdb_recover.c index d033b2126e..c26a048c8b 100644 --- a/ctdb/server/ctdb_recover.c +++ b/ctdb/server/ctdb_recover.c @@ -25,7 +25,7 @@ #include "system/wait.h" #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" int diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 57d278d028..14e6ea85ad 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -26,7 +26,7 @@ #include "cmdline.h" #include "../include/ctdb_client.h" #include "../include/ctdb_private.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" diff --git a/ctdb/server/ctdb_traverse.c b/ctdb/server/ctdb_traverse.c index 64f25306b5..d19305af07 100644 --- a/ctdb/server/ctdb_traverse.c +++ b/ctdb/server/ctdb_traverse.c @@ -20,7 +20,7 @@ #include "includes.h" #include "system/filesys.h" #include "system/wait.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" diff --git a/ctdb/server/ctdb_update_record.c b/ctdb/server/ctdb_update_record.c index 81e36253c7..418bbb10e1 100644 --- a/ctdb/server/ctdb_update_record.c +++ b/ctdb/server/ctdb_update_record.c @@ -19,7 +19,7 @@ */ #include "includes.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "tdb.h" #include "ctdb_private.h" diff --git a/ctdb/server/ctdb_vacuum.c b/ctdb/server/ctdb_vacuum.c index 5013339c23..35f1fe1bfb 100644 --- a/ctdb/server/ctdb_vacuum.c +++ b/ctdb/server/ctdb_vacuum.c @@ -25,7 +25,7 @@ #include "system/filesys.h" #include "system/dir.h" #include "../include/ctdb_private.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" diff --git a/ctdb/tests/src/ctdb_test.c b/ctdb/tests/src/ctdb_test.c index f4dccbaa34..fbbe63d569 100644 --- a/ctdb/tests/src/ctdb_test.c +++ b/ctdb/tests/src/ctdb_test.c @@ -112,7 +112,6 @@ bool ctdb_sys_have_ip(ctdb_sock_addr *addr); /* UTIL_OBJ */ #include "lib/util/idtree.c" -#include "lib/util/db_wrap.c" #include "lib/util/util.c" #include "lib/util/util_time.c" #include "lib/util/util_file.c" diff --git a/ctdb/tests/src/ctdb_trackingdb_test.c b/ctdb/tests/src/ctdb_trackingdb_test.c index 760d314079..18bc174382 100644 --- a/ctdb/tests/src/ctdb_trackingdb_test.c +++ b/ctdb/tests/src/ctdb_trackingdb_test.c @@ -28,7 +28,7 @@ #include "popt.h" #include "cmdline.h" #include "ctdb_private.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #define MAXINDEX 64 char indices[MAXINDEX]; diff --git a/ctdb/tests/src/ctdb_update_record_persistent.c b/ctdb/tests/src/ctdb_update_record_persistent.c index a0bb383ed5..d73636ea1c 100644 --- a/ctdb/tests/src/ctdb_update_record_persistent.c +++ b/ctdb/tests/src/ctdb_update_record_persistent.c @@ -19,7 +19,7 @@ */ #include "includes.h" -#include "lib/util/db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "system/filesys.h" #include "popt.h" #include "cmdline.h" diff --git a/ctdb/tests/src/ctdbd_test.c b/ctdb/tests/src/ctdbd_test.c index 8e193f78a9..a360ddfc9c 100644 --- a/ctdb/tests/src/ctdbd_test.c +++ b/ctdb/tests/src/ctdbd_test.c @@ -33,7 +33,6 @@ bool fast_start; /* UTIL_OBJ */ #include "lib/util/idtree.c" -#include "lib/util/db_wrap.c" #include "lib/util/util.c" #include "lib/util/util_time.c" #include "lib/util/util_file.c" diff --git a/ctdb/tools/ctdb.c b/ctdb/tools/ctdb.c index cc8e37c410..82783d8dfa 100644 --- a/ctdb/tools/ctdb.c +++ b/ctdb/tools/ctdb.c @@ -29,7 +29,7 @@ #include "../include/ctdb_client.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" #include "lib/util/dlinklist.h" #define ERR_TIMEOUT 20 /* timed out trying to reach node */ diff --git a/ctdb/tools/ctdb_vacuum.c b/ctdb/tools/ctdb_vacuum.c index 808b15ca4b..ae93682430 100644 --- a/ctdb/tools/ctdb_vacuum.c +++ b/ctdb/tools/ctdb_vacuum.c @@ -23,7 +23,7 @@ #include "../include/ctdb_client.h" #include "../include/ctdb_private.h" #include "../common/rb_tree.h" -#include "db_wrap.h" +#include "lib/tdb_wrap/tdb_wrap.h" /* should be tunable */ #define TIMELIMIT() timeval_current_ofs(10, 0) diff --git a/ctdb/wscript b/ctdb/wscript index 0d56065138..3570b009ab 100755 --- a/ctdb/wscript +++ b/ctdb/wscript @@ -173,6 +173,7 @@ def build(bld): if bld.CHECK_FOR_THIRD_PARTY(): bld.RECURSE('third_party/popt') + bld.RECURSE('lib/tdb_wrap') bld.RECURSE('lib/util') bld.RECURSE('lib/talloc') @@ -238,7 +239,8 @@ def build(bld): source=bld.SUBDIR('client', 'ctdb_client.c'), includes='include include/internal lib/util', public_headers='include/ctdb_client.h', - deps='replace popt talloc tevent tdb ctdb-util') + deps='''replace popt talloc tevent tdb + ctdb-util tdb-wrap''') bld.SAMBA_SUBSYSTEM('ctdb-server', source='server/ctdbd.c ' + @@ -451,20 +453,23 @@ def build(bld): bld.SAMBA_BINARY('ctdb_takeover_tests', source='tests/src/ctdb_takeover_tests.c', - deps='replace popt tdb tevent talloc ctdb-system' + + deps='''replace popt tdb tevent talloc ctdb-system + tdb-wrap''' + ib_deps, includes='include include/internal lib/util', install_path='${CTDB_TEST_LIBDIR}') bld.SAMBA_BINARY('ctdb_functest', source='tests/src/ctdb_functest.c', - deps='replace tdb tevent talloc popt ctdb-system', + deps='''replace tdb tevent talloc popt ctdb-system + tdb-wrap''', includes='include include/internal lib/util', install_path='${CTDB_TEST_LIBDIR}') bld.SAMBA_BINARY('ctdb_stubtest', source='tests/src/ctdb_test.c', - deps='replace tdb tevent talloc popt ctdb-system', + deps='''replace tdb tevent talloc popt ctdb-system + tdb-wrap''', includes='include include/internal lib/util', install_path='${CTDB_TEST_LIBDIR}') -- cgit