From: Martin Schwenke Date: Tue, 8 Feb 2022 01:15:26 +0000 (+1100) Subject: ctdb-mutex: open() and fstat() when testing lock file X-Git-Tag: samba-4.17.0rc1~248 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=97a1714ee9427ca22201ebcc5201817d59f17764;p=thirdparty%2Fsamba.git ctdb-mutex: open() and fstat() when testing lock file This makes a file descriptor available for other I/O. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/server/ctdb_mutex_fcntl_helper.c b/ctdb/server/ctdb_mutex_fcntl_helper.c index 2f9e32580c2..07f111a0d6b 100644 --- a/ctdb/server/ctdb_mutex_fcntl_helper.c +++ b/ctdb/server/ctdb_mutex_fcntl_helper.c @@ -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) diff --git a/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh b/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh index 65d57c3f2b1..c21d1d38f33 100755 --- a/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh +++ b/ctdb/tests/UNIT/cunit/cluster_mutex_002.sh @@ -88,7 +88,7 @@ unit_test cluster_mutex_test lock-file-wait-recheck-unlock \ test_case "Recheck on, lock file removed" ok <