summaryrefslogtreecommitdiff
path: root/ctdb/libctdb
diff options
context:
space:
mode:
authorRusty Russell <rusty@rustcorp.com.au>2010-06-18 15:35:52 +0930
committerRusty Russell <rusty@rustcorp.com.au>2010-06-18 15:35:52 +0930
commitb93e65eaf74ff637bc960356a418ab55f4ca9330 (patch)
tree2d08722c2b2e7e55b84d5a4405b3d881c80e11e0 /ctdb/libctdb
parent3d126e8c1453f29f21ac918b5167753372282aa2 (diff)
downloadsamba-b93e65eaf74ff637bc960356a418ab55f4ca9330.tar.gz
libctdb: implement ctdb_disconnect and ctdb_detachdb
These are important for testing, since we can easily tell if we leak memory if there are outstanding allocations after calling these. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au> (This used to be ctdb commit 18a212aa40d0ff9ff59775c6fcf9dc973e991460)
Diffstat (limited to 'ctdb/libctdb')
-rw-r--r--ctdb/libctdb/ctdb.c67
-rw-r--r--ctdb/libctdb/messages.c12
-rw-r--r--ctdb/libctdb/messages.h1
3 files changed, 70 insertions, 10 deletions
diff --git a/ctdb/libctdb/ctdb.c b/ctdb/libctdb/ctdb.c
index 1c16d36a7c1..096a9264f0a 100644
--- a/ctdb/libctdb/ctdb.c
+++ b/ctdb/libctdb/ctdb.c
@@ -50,6 +50,17 @@ struct ctdb_lock {
ctdb_rrl_callback_t callback;
};
+struct ctdb_db {
+ struct ctdb_connection *ctdb;
+ bool persistent;
+ uint32_t tdb_flags;
+ uint32_t id;
+ struct tdb_context *tdb;
+
+ ctdb_callback_t callback;
+ void *private_data;
+};
+
static void remove_lock(struct ctdb_connection *ctdb, struct ctdb_lock *lock)
{
DLIST_REMOVE(ctdb->locks, lock);
@@ -67,6 +78,19 @@ static void add_lock(struct ctdb_connection *ctdb, struct ctdb_lock *lock)
DLIST_ADD(ctdb->locks, lock);
}
+static void cleanup_locks(struct ctdb_connection *ctdb, struct ctdb_db *db)
+{
+ struct ctdb_lock *i, *next;
+
+ for (i = ctdb->locks; i; i = next) {
+ /* Grab next pointer, as release_lock will free i */
+ next = i->next;
+ if (i->ctdb_db == db) {
+ ctdb_release_lock(db, i);
+ }
+ }
+}
+
/* FIXME: Could be in shared util code with rest of ctdb */
static void close_noerr(int fd)
{
@@ -165,6 +189,33 @@ fail:
return NULL;
}
+void ctdb_disconnect(struct ctdb_connection *ctdb)
+{
+ struct ctdb_request *i;
+
+ DEBUG(ctdb, LOG_DEBUG, "ctdb_disconnect");
+
+ while ((i = ctdb->outq) != NULL) {
+ DLIST_REMOVE(ctdb->outq, i);
+ ctdb_request_free(ctdb, i);
+ }
+
+ while ((i = ctdb->doneq) != NULL) {
+ DLIST_REMOVE(ctdb->doneq, i);
+ ctdb_request_free(ctdb, i);
+ }
+
+ if (ctdb->in)
+ free_io_elem(ctdb->in);
+
+ remove_message_handlers(ctdb);
+
+ close(ctdb->fd);
+ /* Just in case they try to reuse */
+ ctdb->fd = -1;
+ free(ctdb);
+}
+
int ctdb_get_fd(struct ctdb_connection *ctdb)
{
return ctdb->fd;
@@ -478,16 +529,12 @@ void ctdb_cancel(struct ctdb_connection *ctdb, struct ctdb_request *req)
req->callback = ctdb_cancel_callback;
}
-struct ctdb_db {
- struct ctdb_connection *ctdb;
- bool persistent;
- uint32_t tdb_flags;
- uint32_t id;
- struct tdb_context *tdb;
-
- ctdb_callback_t callback;
- void *private_data;
-};
+void ctdb_detachdb(struct ctdb_connection *ctdb, struct ctdb_db *db)
+{
+ cleanup_locks(ctdb, db);
+ tdb_close(db->tdb);
+ free(db);
+}
static void attachdb_getdbpath_done(struct ctdb_connection *ctdb,
struct ctdb_request *req,
diff --git a/ctdb/libctdb/messages.c b/ctdb/libctdb/messages.c
index bab0e8c4cbd..7ad48d5dc83 100644
--- a/ctdb/libctdb/messages.c
+++ b/ctdb/libctdb/messages.c
@@ -43,6 +43,18 @@ void deliver_message(struct ctdb_connection *ctdb, struct ctdb_req_header *hdr)
}
}
+void remove_message_handlers(struct ctdb_connection *ctdb)
+{
+ struct message_handler_info *i;
+
+ /* ctdbd should unregister automatically when we close fd, so we don't
+ need to do that here. */
+ while ((i = ctdb->message_handlers) != NULL) {
+ DLIST_REMOVE(ctdb->message_handlers, i);
+ free(i);
+ }
+}
+
bool ctdb_set_message_handler_recv(struct ctdb_connection *ctdb,
struct ctdb_request *req)
{
diff --git a/ctdb/libctdb/messages.h b/ctdb/libctdb/messages.h
index dcf19c8b6ca..89a04608eca 100644
--- a/ctdb/libctdb/messages.h
+++ b/ctdb/libctdb/messages.h
@@ -5,4 +5,5 @@ struct ctdb_connection;
struct ctdb_req_header;
void deliver_message(struct ctdb_connection *ctdb, struct ctdb_req_header *hdr);
+void remove_message_handlers(struct ctdb_connection *ctdb);
#endif /* _LIBCTDB_MESSAGE_H */