summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2022-02-08 12:15:26 +1100
committerMartin Schwenke <martins@samba.org>2022-07-28 10:09:34 +0000
commit97a1714ee9427ca22201ebcc5201817d59f17764 (patch)
tree26ada73985b676cdaa90d340e0769e42aa89e73e /ctdb
parentc07e81abf04c20fb591376efcaa9b738a60c1a58 (diff)
downloadsamba-97a1714ee9427ca22201ebcc5201817d59f17764.tar.gz
ctdb-mutex: open() and fstat() when testing lock file
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>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/server/ctdb_mutex_fcntl_helper.c30
-rwxr-xr-xctdb/tests/UNIT/cunit/cluster_mutex_002.sh2
2 files changed, 26 insertions, 6 deletions
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 <<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"