ctdb-locking: Talloc lock request from client specified context
authorAmitay Isaacs <amitay@gmail.com>
Mon, 11 Aug 2014 07:08:20 +0000 (17:08 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 5 Sep 2014 05:05:10 +0000 (07:05 +0200)
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 <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/include/ctdb_private.h
ctdb/server/ctdb_freeze.c
ctdb/server/ctdb_lock.c
ctdb/server/ctdb_ltdb_server.c

index 36ebe70ac0f06fa8241d3f8ff7ab128c275b1493..7de9afbf14f599171ca5a3d09f10a6b808d94097 100644 (file)
@@ -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);
index 42a12850ac3bea7bca8541d99cb6dff5d44b71ba..d68b0183ac41ca8f77ba2aaa085cbff62e465461 100644 (file)
@@ -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;
index 84c0de77eee1e68ebcb3574106169eca0b033c0d..4a641f19e265b42d08754a20bb8c07854f2feb89 100644 (file)
@@ -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,
index 55abf1f54400c74f849eedbd1fc5e121b8b9370d..4b41542b58d2d27f5da31f79942f3a485e8f0eb4 100644 (file)
@@ -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;
        }