]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-tests: Add test to confirm need for cluster mutex lock file rechecking
authorMartin Schwenke <martin@meltin.net>
Mon, 8 Jul 2019 10:51:11 +0000 (20:51 +1000)
committerMartin Schwenke <martins@samba.org>
Fri, 26 Jul 2019 03:34:17 +0000 (03:34 +0000)
Remove the lock and a second locker can take the it.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/tests/cunit/cluster_mutex_002.sh
ctdb/tests/src/cluster_mutex_test.c

index 8e0b4103fc6a98832d430e1e0b6b2221ea9b87a1..fea6cfe2b93b2d5e13bfe79f83399408728f70a6 100755 (executable)
@@ -58,3 +58,12 @@ LOCK
 UNLOCK
 EOF
 unit_test cluster_mutex_test lock-ppid-gone-lock-unlock "$helper"
+
+ok <<EOF
+LOCK
+LOCK
+UNLOCK
+UNLOCK
+EOF
+unit_test cluster_mutex_test lock-file-removed-no-recheck \
+         "$helper" "$lockfile"
index 21a6d2e7690400cc200600025a22b0fdc212c7f9..fa7e1e034152a4881918723978adb3a578d4604a 100644 (file)
@@ -475,6 +475,43 @@ static void test_lock_ppid_gone_lock_unlock(TALLOC_CTX *mem_ctx,
        assert(dl->mh == NULL);
 }
 
+static void test_lock_file_removed_no_recheck(TALLOC_CTX *mem_ctx,
+                                             struct ctdb_context *ctdb,
+                                             const char *mutex_string,
+                                             const char *lock_file)
+{
+       struct do_lock_context *dl1;
+       struct do_lock_context *dl2;
+       int ret;
+
+       dl1 = talloc_zero(mem_ctx, struct do_lock_context);
+       assert(dl1 != NULL);
+       dl1->ctdb = ctdb;
+
+       dl2 = talloc_zero(mem_ctx, struct do_lock_context);
+       assert(dl2 != NULL);
+       dl2->ctdb = ctdb;
+
+       /* LOCK */
+       do_lock(dl1, mutex_string);
+       assert(dl1->mh != NULL);
+
+       ret = unlink(lock_file);
+       assert(ret == 0);
+
+       /* LOCK */
+       do_lock(dl2, mutex_string);
+       assert(dl2->mh != NULL);
+
+       /* UNLOCK */
+       do_unlock(dl2);
+       assert(dl2->mh == NULL);
+
+       /* UNLOCK */
+       do_unlock(dl1);
+       assert(dl1->mh == NULL);
+}
+
 /*
  * Main
  */
@@ -483,7 +520,7 @@ static const char *prog;
 
 static void usage(void)
 {
-       fprintf(stderr, "usage: %s <test> <mutex-string>\n", prog);
+       fprintf(stderr, "usage: %s <test> <mutex-string> [<arg>...]\n", prog);
        exit(1);
 }
 
@@ -500,10 +537,11 @@ int main(int argc, const char *argv[])
        const char *test;
        struct sigaction sa = { .sa_handler = NULL, };
        int ret;
+       const char *lock_file;
 
        prog = argv[0];
 
-       if (argc != 3) {
+       if (argc < 3) {
                usage();
        }
 
@@ -540,6 +578,17 @@ int main(int argc, const char *argv[])
                test_lock_wait_unlock(mem_ctx, ctdb, mutex_string);
        } else if (strcmp(test, "lock-ppid-gone-lock-unlock") == 0) {
                test_lock_ppid_gone_lock_unlock(mem_ctx, ctdb, mutex_string);
+       } else if (strcmp(test, "lock-file-removed-no-recheck") == 0) {
+               if (argc != 4) {
+                       usage();
+               }
+
+               lock_file = argv[3];
+
+               test_lock_file_removed_no_recheck(mem_ctx,
+                                                 ctdb,
+                                                 mutex_string,
+                                                 lock_file);
        } else {
                fprintf(stderr, "Unknown test\n");
                exit(1);