diff options
author | Volker Lendecke <vl@samba.org> | 2012-01-06 17:19:54 +0100 |
---|---|---|
committer | Volker Lendecke <vlendec@samba.org> | 2012-01-18 14:48:04 +0100 |
commit | 45e61fcf61ed9863fbe2b116fe0763fc139bbe0d (patch) | |
tree | 06ea9ead2285b4a671d102edb8824422f7325703 /source3/lib | |
parent | e75c436fe6a9ee44f6adc744b6269e99f4920431 (diff) | |
download | samba-45e61fcf61ed9863fbe2b116fe0763fc139bbe0d.tar.gz samba-45e61fcf61ed9863fbe2b116fe0763fc139bbe0d.tar.bz2 samba-45e61fcf61ed9863fbe2b116fe0763fc139bbe0d.zip |
s3: Add a "lock_order" argument to db_open
This will be used to enforce a lock hierarchy between the databases. We have
seen deadlocks between locking.tdb, brlock.tdb, serverid.tdb and notify*.tdb.
These should be fixed by refusing a dbwrap_fetch_locked that does not follow a
defined lock hierarchy.
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/conn_tdb.c | 3 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_open.c | 19 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_open.h | 8 | ||||
-rw-r--r-- | source3/lib/dbwrap/dbwrap_private.h | 2 | ||||
-rw-r--r-- | source3/lib/g_lock.c | 3 | ||||
-rw-r--r-- | source3/lib/serverid.c | 3 | ||||
-rw-r--r-- | source3/lib/sessionid_tdb.c | 3 | ||||
-rw-r--r-- | source3/lib/sharesec.c | 3 |
8 files changed, 36 insertions, 8 deletions
diff --git a/source3/lib/conn_tdb.c b/source3/lib/conn_tdb.c index f600871411..9b0a07a56c 100644 --- a/source3/lib/conn_tdb.c +++ b/source3/lib/conn_tdb.c @@ -36,7 +36,8 @@ static struct db_context *connections_db_ctx(bool rw) open_flags = rw ? (O_RDWR|O_CREAT) : O_RDONLY; db_ctx = db_open(NULL, lock_path("connections.tdb"), 0, - TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, open_flags, 0644); + TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH|TDB_DEFAULT, + open_flags, 0644, DBWRAP_LOCK_ORDER_1); return db_ctx; } diff --git a/source3/lib/dbwrap/dbwrap_open.c b/source3/lib/dbwrap/dbwrap_open.c index 6b8be2de16..23d299511b 100644 --- a/source3/lib/dbwrap/dbwrap_open.c +++ b/source3/lib/dbwrap/dbwrap_open.c @@ -62,11 +62,26 @@ bool db_is_local(const char *name) struct db_context *db_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode) + int open_flags, mode_t mode, + enum dbwrap_lock_order lock_order) { struct db_context *result = NULL; #ifdef CLUSTER_SUPPORT - const char *sockname = lp_ctdbd_socket(); + const char *sockname; +#endif + + if ((lock_order != DBWRAP_LOCK_ORDER_1) && + (lock_order != DBWRAP_LOCK_ORDER_2)) { + /* + * Only allow 2 levels. ctdb gives us 3, and we will + * have the watchers database soon. + */ + errno = EINVAL; + return NULL; + } + +#ifdef CLUSTER_SUPPORT + sockname = lp_ctdbd_socket(); if(!sockname || !*sockname) { sockname = CTDB_PATH; diff --git a/source3/lib/dbwrap/dbwrap_open.h b/source3/lib/dbwrap/dbwrap_open.h index 5a172a4a2a..2763ef2ade 100644 --- a/source3/lib/dbwrap/dbwrap_open.h +++ b/source3/lib/dbwrap/dbwrap_open.h @@ -29,6 +29,11 @@ struct db_context; */ bool db_is_local(const char *name); +enum dbwrap_lock_order { + DBWRAP_LOCK_ORDER_1 = 1, + DBWRAP_LOCK_ORDER_2 = 2 +}; + /** * Convenience function that will determine whether to * open a tdb database via the tdb backend or via the ctdb @@ -38,6 +43,7 @@ bool db_is_local(const char *name); struct db_context *db_open(TALLOC_CTX *mem_ctx, const char *name, int hash_size, int tdb_flags, - int open_flags, mode_t mode); + int open_flags, mode_t mode, + enum dbwrap_lock_order lock_order); #endif /* __DBWRAP_OPEN_H__ */ diff --git a/source3/lib/dbwrap/dbwrap_private.h b/source3/lib/dbwrap/dbwrap_private.h index 4806618543..d0b3279368 100644 --- a/source3/lib/dbwrap/dbwrap_private.h +++ b/source3/lib/dbwrap/dbwrap_private.h @@ -23,6 +23,8 @@ #ifndef __DBWRAP_PRIVATE_H__ #define __DBWRAP_PRIVATE_H__ +#include "dbwrap/dbwrap_open.h" + struct db_record { TDB_DATA key, value; NTSTATUS (*store)(struct db_record *rec, TDB_DATA data, int flag); diff --git a/source3/lib/g_lock.c b/source3/lib/g_lock.c index 561617023f..1fd8ae9f38 100644 --- a/source3/lib/g_lock.c +++ b/source3/lib/g_lock.c @@ -60,7 +60,8 @@ struct g_lock_ctx *g_lock_ctx_init(TALLOC_CTX *mem_ctx, result->db = db_open(result, lock_path("g_lock.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, - O_RDWR|O_CREAT, 0600); + O_RDWR|O_CREAT, 0600, + DBWRAP_LOCK_ORDER_2); if (result->db == NULL) { DEBUG(1, ("g_lock_init: Could not open g_lock.tdb\n")); TALLOC_FREE(result); diff --git a/source3/lib/serverid.c b/source3/lib/serverid.c index 6d8a3c004f..6a8083a7a2 100644 --- a/source3/lib/serverid.c +++ b/source3/lib/serverid.c @@ -76,7 +76,8 @@ static struct db_context *serverid_db(void) return db; } db = db_open(NULL, lock_path("serverid.tdb"), 0, - TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, O_RDWR|O_CREAT, 0644); + TDB_DEFAULT|TDB_CLEAR_IF_FIRST|TDB_INCOMPATIBLE_HASH, + O_RDWR|O_CREAT, 0644, DBWRAP_LOCK_ORDER_2); return db; } diff --git a/source3/lib/sessionid_tdb.c b/source3/lib/sessionid_tdb.c index 6fd3bbc487..5782c9a544 100644 --- a/source3/lib/sessionid_tdb.c +++ b/source3/lib/sessionid_tdb.c @@ -34,7 +34,8 @@ static struct db_context *session_db_ctx(void) session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT|TDB_INCOMPATIBLE_HASH, - O_RDWR | O_CREAT, 0644); + O_RDWR | O_CREAT, 0644, + DBWRAP_LOCK_ORDER_1); return session_db_ctx_ptr; } diff --git a/source3/lib/sharesec.c b/source3/lib/sharesec.c index 2c324cf971..cb8993cc8e 100644 --- a/source3/lib/sharesec.c +++ b/source3/lib/sharesec.c @@ -148,7 +148,8 @@ bool share_info_db_init(void) } share_db = db_open(NULL, state_path("share_info.tdb"), 0, - TDB_DEFAULT, O_RDWR|O_CREAT, 0600); + TDB_DEFAULT, O_RDWR|O_CREAT, 0600, + DBWRAP_LOCK_ORDER_1); if (share_db == NULL) { DEBUG(0,("Failed to open share info database %s (%s)\n", state_path("share_info.tdb"), strerror(errno) )); |