From: Martin Schwenke Date: Mon, 8 Jul 2019 10:51:11 +0000 (+1000) Subject: ctdb-tests: Add test to confirm need for cluster mutex lock file rechecking X-Git-Tag: tdb-1.4.2~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d716be19ea14f15984eab8ce3388eb90bbb49d0a;p=thirdparty%2Fsamba.git ctdb-tests: Add test to confirm need for cluster mutex lock file rechecking Remove the lock and a second locker can take the it. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/tests/cunit/cluster_mutex_002.sh b/ctdb/tests/cunit/cluster_mutex_002.sh index 8e0b4103fc6..fea6cfe2b93 100755 --- a/ctdb/tests/cunit/cluster_mutex_002.sh +++ b/ctdb/tests/cunit/cluster_mutex_002.sh @@ -58,3 +58,12 @@ LOCK UNLOCK EOF unit_test cluster_mutex_test lock-ppid-gone-lock-unlock "$helper" + +ok <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 \n", prog); + fprintf(stderr, "usage: %s [...]\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);