2 Unix SMB/CIFS implementation.
3 Database interface wrapper
5 Copyright (C) Volker Lendecke 2005-2007
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "dbwrap/dbwrap.h"
23 #include "dbwrap/dbwrap_private.h"
24 #include "dbwrap/dbwrap_open.h"
25 #include "dbwrap/dbwrap_tdb.h"
26 #include "dbwrap/dbwrap_ctdb.h"
28 #ifdef CLUSTER_SUPPORT
29 #include "ctdb_private.h"
32 bool db_is_local(const char *name)
34 #ifdef CLUSTER_SUPPORT
35 const char *sockname = lp_ctdbd_socket();
37 if(!sockname || !*sockname) {
41 if (lp_clustering() && socket_exist(sockname)) {
43 /* ctdb only wants the file part of the name */
44 partname = strrchr(name, '/');
50 /* allow ctdb for individual databases to be disabled */
51 if (lp_parm_bool(-1, "ctdb", partname, True)) {
62 struct db_context *db_open(TALLOC_CTX *mem_ctx,
64 int hash_size, int tdb_flags,
65 int open_flags, mode_t mode)
67 struct db_context *result = NULL;
68 #ifdef CLUSTER_SUPPORT
69 const char *sockname = lp_ctdbd_socket();
71 if(!sockname || !*sockname) {
75 if (lp_clustering()) {
78 if (!socket_exist(sockname)) {
79 DEBUG(1, ("ctdb socket does not exist - is ctdb not "
84 /* ctdb only wants the file part of the name */
85 partname = strrchr(name, '/');
91 /* allow ctdb for individual databases to be disabled */
92 if (lp_parm_bool(-1, "ctdb", partname, True)) {
93 result = db_open_ctdb(mem_ctx, partname, hash_size,
94 tdb_flags, open_flags, mode);
96 DEBUG(0,("failed to attach to ctdb %s\n",
108 if (result == NULL) {
109 result = db_open_tdb(mem_ctx, name, hash_size,
110 tdb_flags, open_flags, mode);
113 if ((result != NULL) && (result->wipe == NULL)) {
114 result->wipe = dbwrap_fallback_wipe;