]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
ctdb-mutex: open() and fstat() when testing lock file
authorMartin Schwenke <martin@meltin.net>
Tue, 8 Feb 2022 01:15:26 +0000 (12:15 +1100)
committerMartin Schwenke <martins@samba.org>
Thu, 28 Jul 2022 10:09:34 +0000 (10:09 +0000)
This makes a file descriptor available for other I/O.

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

index 2f9e32580c210e3f1658578238f4f9099b99fd49..07f111a0d6b692cef071b23b965860bcf30b5582 100644 (file)
@@ -225,6 +225,7 @@ static void lock_io_check_loop(struct tevent_req *subreq)
                req, struct lock_io_check_state);
        bool status;
        struct stat sb;
+       int fd = -1;
        int ret;
 
        status = tevent_wakeup_recv(subreq);
@@ -234,7 +235,18 @@ static void lock_io_check_loop(struct tevent_req *subreq)
                fprintf(stderr, "%s: tevent_wakeup_recv() failed\n", progname);
        }
 
-       ret = stat(state->lock_file, &sb);
+       fd = open(state->lock_file, O_RDWR);
+       if (fd == -1) {
+               fprintf(stderr,
+                       "%s: "
+                       "lock lost - lock file \"%s\" open failed (ret=%d)\n",
+                       progname,
+                       state->lock_file,
+                       errno);
+               goto done;
+       }
+
+       ret = fstat(fd, &sb);
        if (ret != 0) {
                fprintf(stderr,
                        "%s: "
@@ -242,8 +254,7 @@ static void lock_io_check_loop(struct tevent_req *subreq)
                        progname,
                        state->lock_file,
                        errno);
-               tevent_req_done(req);
-               return;
+               goto done;
        }
 
        if (sb.st_ino != state->inode) {
@@ -251,10 +262,11 @@ static void lock_io_check_loop(struct tevent_req *subreq)
                        "%s: lock lost - lock file \"%s\" inode changed\n",
                        progname,
                        state->lock_file);
-               tevent_req_done(req);
-               return;
+               goto done;
        }
 
+       close(fd);
+
        subreq = tevent_wakeup_send(
                        state,
                        state->ev,
@@ -263,6 +275,14 @@ static void lock_io_check_loop(struct tevent_req *subreq)
                return;
        }
        tevent_req_set_callback(subreq, lock_io_check_loop, req);
+
+       return;
+
+done:
+       if (fd != -1) {
+               close(fd);
+       }
+       tevent_req_done(req);
 }
 
 static bool lock_io_check_recv(struct tevent_req *req, int *perr)
index 65d57c3f2b1ebafc61aa25ce684ca917a6884632..c21d1d38f335c9b5b95d048edb10bb6f5441e464 100755 (executable)
@@ -88,7 +88,7 @@ unit_test cluster_mutex_test lock-file-wait-recheck-unlock \
 test_case "Recheck on, lock file removed"
 ok <<EOF
 LOCK
-ctdb_mutex_fcntl_helper: lock lost - lock file "${lockfile}" check failed (ret=2)
+ctdb_mutex_fcntl_helper: lock lost - lock file "${lockfile}" open failed (ret=2)
 LOST
 EOF
 unit_test cluster_mutex_test lock-file-removed "$helper 5" "$lockfile"