From 374cbc7b0ff68e04ee4e395935509c7df817b3c0 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Mon, 11 Aug 2014 17:08:20 +1000 Subject: [PATCH] ctdb-locking: Talloc lock request from client specified context This makes sure that when the client context is destroyed, the lock request goes away. If the lock requests is already scheduled, then the lock child process will be terminated. Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/include/ctdb_private.h | 12 ++++++++---- ctdb/server/ctdb_freeze.c | 4 ++-- ctdb/server/ctdb_lock.c | 34 +++++++++++++++++++++++----------- ctdb/server/ctdb_ltdb_server.c | 2 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 36ebe70ac0f..7de9afbf14f 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -1582,24 +1582,28 @@ int ctdb_lockall_unmark_prio(struct ctdb_context *ctdb, uint32_t priority); void ctdb_lock_free_request_context(struct lock_request *lock_req); -struct lock_request *ctdb_lock_record(struct ctdb_db_context *ctdb_db, +struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx, + struct ctdb_db_context *ctdb_db, TDB_DATA key, bool auto_mark, void (*callback)(void *, bool), void *private_data); -struct lock_request *ctdb_lock_db(struct ctdb_db_context *ctdb_db, +struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx, + struct ctdb_db_context *ctdb_db, bool auto_mark, void (*callback)(void *, bool), void *private_data); -struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb, +struct lock_request *ctdb_lock_alldb_prio(TALLOC_CTX *mem_ctx, + struct ctdb_context *ctdb, uint32_t priority, bool auto_mark, void (*callback)(void *, bool), void *private_data); -struct lock_request *ctdb_lock_alldb(struct ctdb_context *ctdb, +struct lock_request *ctdb_lock_alldb(TALLOC_CTX *mem_ctx, + struct ctdb_context *ctdb, bool auto_mark, void (*callback)(void *, bool), void *private_data); diff --git a/ctdb/server/ctdb_freeze.c b/ctdb/server/ctdb_freeze.c index 42a12850ac3..d68b0183ac4 100644 --- a/ctdb/server/ctdb_freeze.c +++ b/ctdb/server/ctdb_freeze.c @@ -75,7 +75,6 @@ static int ctdb_freeze_handle_destructor(struct ctdb_freeze_handle *h) ctdb->freeze_mode[h->priority] = CTDB_FREEZE_NONE; ctdb->freeze_handles[h->priority] = NULL; - ctdb_lock_free_request_context(h->lreq); return 0; } @@ -153,7 +152,8 @@ void ctdb_start_freeze(struct ctdb_context *ctdb, uint32_t priority) h->priority = priority; talloc_set_destructor(h, ctdb_freeze_handle_destructor); - h->lreq = ctdb_lock_alldb_prio(ctdb, priority, false, ctdb_freeze_lock_handler, h); + h->lreq = ctdb_lock_alldb_prio(h, ctdb, priority, false, + ctdb_freeze_lock_handler, h); CTDB_NO_MEMORY_FATAL(ctdb, h->lreq); ctdb->freeze_handles[priority] = h; ctdb->freeze_mode[priority] = CTDB_FREEZE_PENDING; diff --git a/ctdb/server/ctdb_lock.c b/ctdb/server/ctdb_lock.c index 84c0de77eee..4a641f19e26 100644 --- a/ctdb/server/ctdb_lock.c +++ b/ctdb/server/ctdb_lock.c @@ -272,6 +272,9 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb); */ static int ctdb_lock_context_destructor(struct lock_context *lock_ctx) { + if (lock_ctx->request) { + lock_ctx->request->lctx = NULL; + } if (lock_ctx->child > 0) { ctdb_kill(lock_ctx->ctdb, lock_ctx->child, SIGKILL); if (lock_ctx->type == LOCK_RECORD) { @@ -309,7 +312,7 @@ static int ctdb_lock_context_destructor(struct lock_context *lock_ctx) */ static int ctdb_lock_request_destructor(struct lock_request *lock_request) { - lock_request->lctx->request = NULL; + TALLOC_FREE(lock_request->lctx); return 0; } @@ -858,7 +861,8 @@ static void ctdb_lock_schedule(struct ctdb_context *ctdb) /* * Lock record / db depending on type */ -static struct lock_request *ctdb_lock_internal(struct ctdb_context *ctdb, +static struct lock_request *ctdb_lock_internal(TALLOC_CTX *mem_ctx, + struct ctdb_context *ctdb, struct ctdb_db_context *ctdb_db, TDB_DATA key, uint32_t priority, @@ -881,7 +885,7 @@ static struct lock_request *ctdb_lock_internal(struct ctdb_context *ctdb, return NULL; } - if ((request = talloc_zero(lock_ctx, struct lock_request)) == NULL) { + if ((request = talloc_zero(mem_ctx, struct lock_request)) == NULL) { talloc_free(lock_ctx); return NULL; } @@ -938,13 +942,15 @@ static struct lock_request *ctdb_lock_internal(struct ctdb_context *ctdb, /* * obtain a lock on a record in a database */ -struct lock_request *ctdb_lock_record(struct ctdb_db_context *ctdb_db, +struct lock_request *ctdb_lock_record(TALLOC_CTX *mem_ctx, + struct ctdb_db_context *ctdb_db, TDB_DATA key, bool auto_mark, void (*callback)(void *, bool), void *private_data) { - return ctdb_lock_internal(ctdb_db->ctdb, + return ctdb_lock_internal(mem_ctx, + ctdb_db->ctdb, ctdb_db, key, 0, @@ -958,12 +964,14 @@ struct lock_request *ctdb_lock_record(struct ctdb_db_context *ctdb_db, /* * obtain a lock on a database */ -struct lock_request *ctdb_lock_db(struct ctdb_db_context *ctdb_db, +struct lock_request *ctdb_lock_db(TALLOC_CTX *mem_ctx, + struct ctdb_db_context *ctdb_db, bool auto_mark, void (*callback)(void *, bool), void *private_data) { - return ctdb_lock_internal(ctdb_db->ctdb, + return ctdb_lock_internal(mem_ctx, + ctdb_db->ctdb, ctdb_db, tdb_null, 0, @@ -977,7 +985,8 @@ struct lock_request *ctdb_lock_db(struct ctdb_db_context *ctdb_db, /* * obtain locks on all databases of specified priority */ -struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb, +struct lock_request *ctdb_lock_alldb_prio(TALLOC_CTX *mem_ctx, + struct ctdb_context *ctdb, uint32_t priority, bool auto_mark, void (*callback)(void *, bool), @@ -988,7 +997,8 @@ struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb, return NULL; } - return ctdb_lock_internal(ctdb, + return ctdb_lock_internal(mem_ctx, + ctdb, NULL, tdb_null, priority, @@ -1002,12 +1012,14 @@ struct lock_request *ctdb_lock_alldb_prio(struct ctdb_context *ctdb, /* * obtain locks on all databases */ -struct lock_request *ctdb_lock_alldb(struct ctdb_context *ctdb, +struct lock_request *ctdb_lock_alldb(TALLOC_CTX *mem_ctx, + struct ctdb_context *ctdb, bool auto_mark, void (*callback)(void *, bool), void *private_data) { - return ctdb_lock_internal(ctdb, + return ctdb_lock_internal(mem_ctx, + ctdb, NULL, tdb_null, 0, diff --git a/ctdb/server/ctdb_ltdb_server.c b/ctdb/server/ctdb_ltdb_server.c index 55abf1f5440..4b41542b58d 100644 --- a/ctdb/server/ctdb_ltdb_server.c +++ b/ctdb/server/ctdb_ltdb_server.c @@ -328,7 +328,7 @@ int ctdb_ltdb_lock_requeue(struct ctdb_db_context *ctdb_db, state->ignore_generation = ignore_generation; /* now the contended path */ - lreq = ctdb_lock_record(ctdb_db, key, true, lock_fetch_callback, state); + lreq = ctdb_lock_record(state, ctdb_db, key, true, lock_fetch_callback, state); if (lreq == NULL) { return -1; } -- 2.34.1