From: Alexander Aring <aahringo@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 5/5] fcntl44: test for kill child while others waiting
Date: Tue, 30 May 2023 16:37:07 -0400 [thread overview]
Message-ID: <20230530203707.2965684-6-aahringo@redhat.com> (raw)
In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com>
This patch adds fcntl44 to kill a forked child blocking for get a lock
granted and another child waiting for the same lock context. This test
checks on cleanup issues when the forked child gets killed.
Signed-off-by: Alexander Aring <aahringo@redhat.com>
---
testcases/kernel/syscalls/fcntl/.gitignore | 2 +
testcases/kernel/syscalls/fcntl/fcntl44.c | 128 +++++++++++++++++++++
2 files changed, 130 insertions(+)
create mode 100644 testcases/kernel/syscalls/fcntl/fcntl44.c
diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
index 6622aedbc..0ee00ce1f 100644
--- a/testcases/kernel/syscalls/fcntl/.gitignore
+++ b/testcases/kernel/syscalls/fcntl/.gitignore
@@ -82,3 +82,5 @@
/fcntl42_64
/fcntl43
/fcntl43_64
+/fcntl44_64
+/fcntl44
diff --git a/testcases/kernel/syscalls/fcntl/fcntl44.c b/testcases/kernel/syscalls/fcntl/fcntl44.c
new file mode 100644
index 000000000..364916634
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl44.c
@@ -0,0 +1,128 @@
+/*
+ * [Description]
+ * Tests killing a child while several other processes using different OFD
+ * lock contexts are blocking. When the child is killed there is a cleanup
+ * routine going on. The parent will check if there were any unexpected
+ * side-effects, e.g. unlock all previous acquired locks, happened.
+ *
+ * It is recommended to run watch -n 0.1 "dlm_tool plocks $LS"
+ * aside to monitor dlm plock handling.
+ *
+ * [How to use it]
+ * Call it with TMPDIR=/mnt ./fcntl44 where TMPDIR is a gfs2 mountpoint.
+ * Try it on other filesystems to compare results.
+ *
+ * [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/dlm/plock.c?h=v6.3#n432
+ */
+
+#include <sys/wait.h>
+
+#include "tst_test.h"
+
+static int fd, fd2;
+
+void do_child1(void)
+{
+ const struct flock fl = {
+ .l_type = F_WRLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 0L,
+ .l_len = 1L,
+ };
+
+ SAFE_FCNTL(fd2, F_OFD_SETLKW, &fl);
+ tst_res(TINFO, "child1 lock region 0-0 acquired");
+
+ TST_CHECKPOINT_WAIT(1);
+
+ tst_res(TPASS, "Child1 passed!");
+}
+
+void do_child2(void)
+{
+ const struct flock fl = {
+ .l_type = F_WRLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 1L,
+ .l_len = 1L,
+ };
+
+ SAFE_FCNTL(fd2, F_OFD_SETLKW, &fl);
+}
+
+static void fcntl40_test(void)
+{
+ struct flock fl = {
+ .l_type = F_WRLCK,
+ .l_whence = SEEK_SET,
+ .l_start = 0L,
+ .l_len = 2L,
+ };
+ pid_t pid, pid2;
+ int rv;
+
+ SAFE_FCNTL(fd, F_SETLK, &fl);
+ tst_res(TINFO, "parent lock 0-1");
+
+ pid = SAFE_FORK();
+ if (pid == 0) {
+ do_child1();
+ return;
+ }
+
+ pid2 = SAFE_FORK();
+ if (pid2 == 0) {
+ do_child2();
+ return;
+ }
+
+ /* wait until childs wait to acquire */
+ sleep(2);
+
+ kill(pid2, SIGKILL);
+ /* wait until linux killed the process */
+ sleep(3);
+ tst_res(TPASS, "Child2 killed!");
+
+ fl.l_type = F_UNLCK;
+ SAFE_FCNTL(fd, F_SETLK, &fl);
+
+ /* let child1 acquire 0-0 */
+ sleep(2);
+
+ fl.l_type = F_WRLCK;
+ fl.l_start = 0;
+ fl.l_len = 1;
+ rv = fcntl(fd, F_OFD_SETLK, &fl);
+ if (rv == -1 && errno == EAGAIN)
+ tst_res(TPASS, "region 1-1 was locked");
+ else
+ tst_res(TFAIL, "region 1-1 was unlocked");
+
+ TST_CHECKPOINT_WAKE(1);
+
+ /* due bug child1 does not return because child2 killing removed waiters */
+ wait(NULL);
+
+ tst_res(TPASS, "Parent passed!");
+}
+
+static void setup(void)
+{
+ fd = SAFE_OPEN("filename", O_RDWR | O_CREAT, 0700);
+ fd2 = SAFE_OPEN("filename", O_RDWR | O_CREAT, 0700);
+}
+
+static void cleanup(void)
+{
+ if (fd > -1)
+ SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+ .forks_child = 1,
+ .needs_checkpoints = 1,
+ .test_all = fcntl40_test,
+ .setup = setup,
+ .cleanup = cleanup,
+};
--
2.31.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
prev parent reply other threads:[~2023-05-30 20:38 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-30 20:37 [LTP] [PATCH 0/5] fcntl: add more testcases Alexander Aring
2023-05-30 20:37 ` [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock Alexander Aring
2023-06-21 9:03 ` Petr Vorel
2023-06-30 19:59 ` Alexander Aring
2023-07-02 19:18 ` Petr Vorel
2023-07-05 13:23 ` Alexander Aring
2023-07-07 8:14 ` Petr Vorel
2023-07-07 12:50 ` Alexander Aring
2023-07-07 13:17 ` Petr Vorel
2023-07-02 19:19 ` Petr Vorel
2023-05-30 20:37 ` [LTP] [PATCH 2/5] fcntl41: test for owner values on OFD posix locks Alexander Aring
2023-06-21 9:38 ` Petr Vorel
2023-06-30 20:00 ` Alexander Aring
2023-05-30 20:37 ` [LTP] [PATCH 3/5] fcntl42: test for F_SETLKW interruption case Alexander Aring
2023-05-30 20:37 ` [LTP] [PATCH 4/5] fcntl43: test for identical F_SETLKW lock requests Alexander Aring
2023-05-30 20:37 ` Alexander Aring [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230530203707.2965684-6-aahringo@redhat.com \
--to=aahringo@redhat.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox