Skip to contentSkip to conversation

fcntl: add more testcases

PATCH In review Alexander Aring 2 participants 16 messages May 30, 2023 – Jul 7, 2023

lore
Share & tools
lore
#0 lore raw

cover fcntl: add more testcases

Hi,

this patch series introduces more fcntl testcases which was found by testing fcntl on a Linux gfs2 filesystem. They can also be run on different filesystems. It was mostly compared with the default Linux behaviour e.g. tmpfs and gfs2, it's getting usual interessting when a filesystem implements it's own posix lock behaviour like it's the case for gfs2.

First ltp contribution, would like to get some review.

Alexander Aring (5):
fcntl40: test for owner values on classic posix lock
fcntl41: test for owner values on OFD posix locks
fcntl42: test for F_SETLKW interruption case
fcntl43: test for identical F_SETLKW lock requests
fcntl44: test for kill child while others waiting

 testcases/kernel/syscalls/fcntl/.gitignore |  10 ++
 testcases/kernel/syscalls/fcntl/Makefile   |   6 +
 testcases/kernel/syscalls/fcntl/fcntl40.c  | 188 +++++++++++++++++++++
 testcases/kernel/syscalls/fcntl/fcntl41.c  | 178 +++++++++++++++++++
 testcases/kernel/syscalls/fcntl/fcntl42.c  | 153 +++++++++++++++++
 testcases/kernel/syscalls/fcntl/fcntl43.c  | 140 +++++++++++++++
 testcases/kernel/syscalls/fcntl/fcntl44.c  | 128 ++++++++++++++
 7 files changed, 803 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl40.c
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl41.c
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl42.c
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl43.c
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl44.c
Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

PATCH 1/5 fcntl40: test for owner values on classic posix lock

This patch adds fcntl40 to test similar owner values for classical owner locks. There was an issue been found in the gfs2 filesystem because there can be collisions with identical owner values.

---
 testcases/kernel/syscalls/fcntl/.gitignore |   2 +
 testcases/kernel/syscalls/fcntl/Makefile   |   3 +
 testcases/kernel/syscalls/fcntl/fcntl40.c  | 188 +++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl40.c
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
index 10cb0995f..e558cfe83 100644
@@ -74,3 +74,5 @@
 /fcntl38_64
 /fcntl39
 /fcntl39_64
+/fcntl40
+/fcntl40_64
testcases/kernel/syscalls/fcntl/Makefile +3 -0
index df663a50a..c3196a527 100644
@@ -12,6 +12,9 @@ fcntl34_64: LDLIBS += -lpthread
 fcntl36: LDLIBS += -lpthread
 fcntl36_64: LDLIBS += -lpthread
 
+fcntl40: LDLIBS += -lpthread
+fcntl40_64: LDLIBS += -lpthread
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../utils/newer_64.mk
 
testcases/kernel/syscalls/fcntl/fcntl40.c new file +188 -0

188 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Hi Alexander,

Quoted 3 lines

This patch adds fcntl40 to test similar owner values for classical owner locks. There was an issue been found in the gfs2 filesystem because there can be collisions with identical owner values.

Thanks for your work!

...

Review

Quoted 2 lines

+++ b/testcases/kernel/syscalls/fcntl/fcntl40.c

(quoted diff) +0 -0
@@ -0,0 +1,188 @@

There is no SPDX and copyright, see other files:

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2023 ...
*/

testcases/kernel/syscalls/fcntl/fcntl40.c line 1

Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1 -0
+/*

NOTE: this should be /*\
to be able to get the description in our automatically generated documentation

https://github.com/linux-test-project/ltp/releases/download/20230516/metadata.20230516.html

testcases/kernel/syscalls/fcntl/fcntl40.c line 8

Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7 -0
+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

testcases/kernel/syscalls/fcntl/fcntl40.c line 11

Quoted 3 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +3 -0
+ * Try it on other filesystems to compare results.
+ *
+ * [What's it doing]

nit: I'd replace this with [Algorithm].

...

testcases/kernel/syscalls/fcntl/fcntl40.c line 99

Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1 -0
+void do_child(void)

This should be static (in all files).

make check (or make check-fcntl40) is your friend.

testcases/kernel/syscalls/fcntl/fcntl40.c line 112

Quoted 13 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +13 -0
+{
+	pthread_t t1, t2;
+
+	SAFE_PTHREAD_CREATE(&t1, NULL, do_thread1, NULL);
+	SAFE_PTHREAD_CREATE(&t2, NULL, do_thread2, NULL);
+
+	SAFE_PTHREAD_JOIN(t1, NULL);
+	SAFE_PTHREAD_JOIN(t2, NULL);
+
+	tst_res(TPASS, "Child passed!");
+}
+
+void do_parent(void)

This should also be static.

testcases/kernel/syscalls/fcntl/fcntl40.c line 122

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +10 -0
+{
+	struct flock fl = {
+		.l_whence = SEEK_SET,
+	};
+
+	/* wait for 1 seconds so thread2 lock 1-1 tries to acquires at first
+	 * than thread1 lock 0-0 tries to acquired to have a specific waiting
+	 * order in dlm posix handling.
+	 */
+	sleep(1);

I wonder if there could be some proactive check instead of sleep. FYI we have undocumented TST_RETRY_FUNC() in C API.

Quoted 34 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +34 -0
+	/* tell thread2 to call SETLKW for lock 0-0 */
+	TST_CHECKPOINT_WAKE(1);
+	/* wait 3 seconds for thread 1 and 2 being in waiting state */
+	sleep(3);
+
+	/* unlock 0-1, should be successful */
+	fl.l_type = F_UNLCK;
+	fl.l_start = 1;
+	fl.l_len = 1;
+	tst_res(TINFO, "unlock region 1-1 thread2");
+	SAFE_FCNTL(fd, F_SETLK, &fl);
+
+	/* wait until thread 2 got acquired and leave waiting */
+	TST_CHECKPOINT_WAIT(2);
+
+	fl.l_start = 0;
+	fl.l_len = 1;
+	fl.l_type = F_UNLCK;
+	tst_res(TINFO, "unlock region 0-0 thread2");
+	SAFE_FCNTL(fd, F_SETLK, &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;
+
+	tst_res(TINFO, "parent lock region 0-1 - should be successful");
+	SAFE_FCNTL(fd, F_SETLK, &fl);

testcases/kernel/syscalls/fcntl/fcntl40.c line 166

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +10 -0
+	tst_res(TINFO, "parent region 0-1 locked");
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		do_child();
+		return;
+	}
+
+	do_parent();
+	wait(NULL);

waitpid() should be replaced by tst_reap_children(), see
https://github.com/linux-test-project/ltp/wiki/C-Test-API#18-doing-the-test-in-the-child-process

Review line 81

Quoted 2 lines
(quoted diff) +2 -0
+
+	tst_res(TPASS, "Parent passed!");

There is TPASS in child, does it really need to be in the parent as well?

Quoted 20 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +20 -0
+}
+
+static void setup(void)
+{
+	fd = 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,
+};
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#3 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Hi,

Quoted 19 lines · Petr Vorel

Hi Alexander,

Quoted 3 lines

This patch adds fcntl40 to test similar owner values for classical owner locks. There was an issue been found in the gfs2 filesystem because there can be collisions with identical owner values.

Thanks for your work!

...

Review

Quoted 2 lines

+++ b/testcases/kernel/syscalls/fcntl/fcntl40.c

(quoted diff) +0 -0
@@ -0,0 +1,188 @@

There is no SPDX and copyright, see other files:

// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2023 ...
*/

Quoted 6 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 1

Quoted 1 line
testcases/kernel/syscalls/fcntl/fcntl40.c new file +1 -0
+/*

NOTE: this should be /*\
to be able to get the description in our automatically generated documentation

https://github.com/linux-test-project/ltp/releases/download/20230516/metadata.20230516.html

ok

Quoted 7 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 8

Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7 -0
+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.
Quoted 6 lines

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

Quoted 5 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 11

Quoted 3 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +3 -0
+ * Try it on other filesystems to compare results.
+ *
+ * [What's it doing]

nit: I'd replace this with [Algorithm].

ok.

Quoted 6 lines

...

Quoted 1 line

+void do_child(void)

This should be static (in all files).

make check (or make check-fcntl40) is your friend.

ok. Thanks for telling me about make check.

Quoted 6 lines
Quoted 6 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +6 -0
+{
+     pthread_t t1, t2;
+
+     SAFE_PTHREAD_CREATE(&t1, NULL, do_thread1, NULL);
+     SAFE_PTHREAD_CREATE(&t2, NULL, do_thread2, NULL);
+
Quoted 9 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 112

Quoted 7 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +7 -0
+     SAFE_PTHREAD_JOIN(t1, NULL);
+     SAFE_PTHREAD_JOIN(t2, NULL);
+
+     tst_res(TPASS, "Child passed!");
+}
+
+void do_parent(void)

This should also be static.

ok.

Quoted 5 lines
Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5 -0
+{
+     struct flock fl = {
+             .l_whence = SEEK_SET,
+     };
+
Quoted 9 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 122

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5 -0
+     /* wait for 1 seconds so thread2 lock 1-1 tries to acquires at first
+      * than thread1 lock 0-0 tries to acquired to have a specific waiting
+      * order in dlm posix handling.
+      */
+     sleep(1);

I wonder if there could be some proactive check instead of sleep. FYI we have undocumented TST_RETRY_FUNC() in C API.

I try to look into it.

Quoted 39 lines
Quoted 39 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +39 -0
+     /* tell thread2 to call SETLKW for lock 0-0 */
+     TST_CHECKPOINT_WAKE(1);
+     /* wait 3 seconds for thread 1 and 2 being in waiting state */
+     sleep(3);
+
+     /* unlock 0-1, should be successful */
+     fl.l_type = F_UNLCK;
+     fl.l_start = 1;
+     fl.l_len = 1;
+     tst_res(TINFO, "unlock region 1-1 thread2");
+     SAFE_FCNTL(fd, F_SETLK, &fl);
+
+     /* wait until thread 2 got acquired and leave waiting */
+     TST_CHECKPOINT_WAIT(2);
+
+     fl.l_start = 0;
+     fl.l_len = 1;
+     fl.l_type = F_UNLCK;
+     tst_res(TINFO, "unlock region 0-0 thread2");
+     SAFE_FCNTL(fd, F_SETLK, &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;
+
+     tst_res(TINFO, "parent lock region 0-1 - should be successful");
+     SAFE_FCNTL(fd, F_SETLK, &fl);
+     tst_res(TINFO, "parent region 0-1 locked");
+
+     pid = SAFE_FORK();
+     if (pid == 0) {
+             do_child();
Quoted 9 lines

testcases/kernel/syscalls/fcntl/fcntl40.c line 166

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl40.c new file +5 -0
+             return;
+     }
+
+     do_parent();
+     wait(NULL);

waitpid() should be replaced by tst_reap_children(), see
https://github.com/linux-test-project/ltp/wiki/C-Test-API#18-doing-the-test-in-the-child-process

ok. Thanks.

Quoted 3 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+     tst_res(TPASS, "Parent passed!");

There is TPASS in child, does it really need to be in the parent as well?

no.

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#4 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Hi Alex,

...

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

Quoted 7 lines
Quoted 1 line

ATM we don't have any helper in struct tst_test, which would do it.

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

I see .lock is implemented in 9p, afs, ceph, cifs, ocfs2, orangefs, even NFS. "file system core": do you mean VFS? Because that would be more usable than the filesystems above (which are quite exotic).

...

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#5 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Hi,

Quoted 18 lines · Petr Vorel

Hi Alex,

...

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

Quoted 9 lines
Quoted 4 lines

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

I see .lock is implemented in 9p, afs, ceph, cifs, ocfs2, orangefs, even NFS. "file system core": do you mean VFS? Because that would be more usable than the filesystems above (which are quite exotic).

It depends here what they are doing in .lock() - If they just call locks_lock_file_wait() or similar helpers depending on the call, then they don't do much different than what vfs is doing.
In case of gfs2/ocfs it is very special, it redirects their calls to DLM and DLM has its own whole posix implementation behind it. We only call locks_lock_file_wait() to keep the Linux bookkeeping in /proc/locks.

What I am doing here is mostly trusting the Linux implementation and comparing results from e.g. tmpfs with GFS2 and I found issues.

For now I trust the Linux implementation and check if we have a different result here. I need to be very careful here because GFS2/OCFS2 are cluster filesystems and the fcntl() interface was never made for cluster filesystems. However I currently only test "one node" locking and this should deliver the same results as tmpfs, etc.

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#6 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Quoted 39 lines

Hi,

Quoted 17 lines · Petr Vorel

Hi Alex,

...

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

Quoted 8 lines
Quoted 4 lines

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

I see .lock is implemented in 9p, afs, ceph, cifs, ocfs2, orangefs, even NFS. "file system core": do you mean VFS? Because that would be more usable than the filesystems above (which are quite exotic).

It depends here what they are doing in .lock() - If they just call locks_lock_file_wait() or similar helpers depending on the call, then they don't do much different than what vfs is doing.
In case of gfs2/ocfs it is very special, it redirects their calls to DLM and DLM has its own whole posix implementation behind it. We only call locks_lock_file_wait() to keep the Linux bookkeeping in /proc/locks.

Quoted 8 lines

What I am doing here is mostly trusting the Linux implementation and comparing results from e.g. tmpfs with GFS2 and I found issues.

For now I trust the Linux implementation and check if we have a different result here. I need to be very careful here because GFS2/OCFS2 are cluster filesystems and the fcntl() interface was never made for cluster filesystems. However I currently only test "one node" locking and this should deliver the same results as tmpfs, etc.

Thanks for info. I'm still not sure if this is useful only for gfs2/ocfs and we should prepare block device with gfs2 or ocfs and test filesystem on it. Or if it would be useful to test other filesystem implementation. In this latter case we usually use .all_filesystems (we don't have proper docs for .all_filesystems, the closest is [1]) and test is then run on various common filesystems (see fs_type_whitelist[] in lib/tst_supported_fs_types.c), but in that case gfs2 would be skipped (it's not a common filesystem).

In case preparing block device with gfs2 something like this might work:

static struct tst_test test = {
	...
	.dev_fs_type = "gfs2",
	.format_device = 1,
	.dev_fs_opts = (const char *const []){ "-t", "mycluster:mygfs2", "-p", "lock_dlm", "-j" , "2" , NULL},

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/wiki/C-Test-API#113-filesystem-type-detection-and-skiplist

Quoted 1 line

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#7 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Hi,

Quoted 57 lines · Petr Vorel
Quoted 40 lines

Hi,

Quoted 17 lines · Petr Vorel

Hi Alex,

...

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

Quoted 8 lines
Quoted 4 lines

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

I see .lock is implemented in 9p, afs, ceph, cifs, ocfs2, orangefs, even NFS. "file system core": do you mean VFS? Because that would be more usable than the filesystems above (which are quite exotic).

It depends here what they are doing in .lock() - If they just call locks_lock_file_wait() or similar helpers depending on the call, then they don't do much different than what vfs is doing.
In case of gfs2/ocfs it is very special, it redirects their calls to DLM and DLM has its own whole posix implementation behind it. We only call locks_lock_file_wait() to keep the Linux bookkeeping in /proc/locks.

Quoted 8 lines

What I am doing here is mostly trusting the Linux implementation and comparing results from e.g. tmpfs with GFS2 and I found issues.

For now I trust the Linux implementation and check if we have a different result here. I need to be very careful here because GFS2/OCFS2 are cluster filesystems and the fcntl() interface was never made for cluster filesystems. However I currently only test "one node" locking and this should deliver the same results as tmpfs, etc.

Thanks for info. I'm still not sure if this is useful only for gfs2/ocfs and we should prepare block device with gfs2 or ocfs and test filesystem on it. Or if it would be useful to test other filesystem implementation. In this latter case we usually use .all_filesystems (we don't have proper docs for .all_filesystems, the closest is [1]) and test is then run on various common filesystems (see fs_type_whitelist[] in lib/tst_supported_fs_types.c), but in that case gfs2 would be skipped (it's not a common filesystem).

Quoted 8 lines

In case preparing block device with gfs2 something like this might work:

static struct tst_test test = {
        ...
        .dev_fs_type = "gfs2",
        .format_device = 1,
        .dev_fs_opts = (const char *const []){ "-t", "mycluster:mygfs2", "-p", "lock_dlm", "-j" , "2" , NULL},

Can I override this setting by some ENV because I actually want to run it on a different filesystem which is using VFS posix lock implementation, because as I said I want to compare the results.

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#8 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

Quoted 69 lines

Hi,

Quoted 56 lines · Petr Vorel
Quoted 39 lines

Hi,

Quoted 17 lines · Petr Vorel

Hi Alex,

...

Quoted 12 lines
Quoted 12 lines
Quoted 7 lines

+ * [Description]
+ * Tests gfs2 dlm posix op queue handling in the kernel.
+ * 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 ./fcntl40 where TMPDIR is a gfs2 mountpoint.

I wonder if we could check for GFS2_MAGIC (we'd need to add it to include/tst_fs.h => 0x01161970) and quit the test with tst_brk(TCONF) if TMPDIR is not on gfs2.

ATM we don't have any helper in struct tst_test, which would do it.

Quoted 8 lines
Quoted 4 lines

I will mention that gfs2 is only an example here. It becomes interesting when a file system implements its own .lock() callback OR if somebody wants to test file system core, when a filesystem does not implement its own .lock().

I see .lock is implemented in 9p, afs, ceph, cifs, ocfs2, orangefs, even NFS. "file system core": do you mean VFS? Because that would be more usable than the filesystems above (which are quite exotic).

It depends here what they are doing in .lock() - If they just call locks_lock_file_wait() or similar helpers depending on the call, then they don't do much different than what vfs is doing.
In case of gfs2/ocfs it is very special, it redirects their calls to DLM and DLM has its own whole posix implementation behind it. We only call locks_lock_file_wait() to keep the Linux bookkeeping in /proc/locks.

Quoted 8 lines

What I am doing here is mostly trusting the Linux implementation and comparing results from e.g. tmpfs with GFS2 and I found issues.

For now I trust the Linux implementation and check if we have a different result here. I need to be very careful here because GFS2/OCFS2 are cluster filesystems and the fcntl() interface was never made for cluster filesystems. However I currently only test "one node" locking and this should deliver the same results as tmpfs, etc.

Thanks for info. I'm still not sure if this is useful only for gfs2/ocfs and we should prepare block device with gfs2 or ocfs and test filesystem on it. Or if it would be useful to test other filesystem implementation. In this latter case we usually use .all_filesystems (we don't have proper docs for .all_filesystems, the closest is [1]) and test is then run on various common filesystems (see fs_type_whitelist[] in lib/tst_supported_fs_types.c), but in that case gfs2 would be skipped (it's not a common filesystem).

Quoted 7 lines

In case preparing block device with gfs2 something like this might work:

static struct tst_test test = {
        ...
        .dev_fs_type = "gfs2",
        .format_device = 1,
        .dev_fs_opts = (const char *const []){ "-t", "mycluster:mygfs2", "-p", "lock_dlm", "-j" , "2" , NULL},
Quoted 3 lines

Can I override this setting by some ENV because I actually want to run it on a different filesystem which is using VFS posix lock implementation, because as I said I want to compare the results.

Sure, there is LTP_DEV_FS_TYPE. But the point is to write test which will be useful for the default scenario.

Kind regards,
Petr

Quoted 1 line

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#9 lore raw

Re: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock

In reply to Alexander Aring

Hi Alex,

...

Quoted 4 lines
Quoted 2 lines
Quoted 1 line

+ tst_res(TPASS, "Parent passed!");

There is TPASS in child, does it really need to be in the parent as well?

no.

Thanks for info, let's skip it then in the parent.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#10 lore raw

PATCH 2/5 fcntl41: test for owner values on OFD posix locks

In reply to Alexander Aring

This patch adds fcntl41 to test similar owner values for OFD locks. There was an issue been found in the gfs2 filesystem because there can be collisions with identical owner values.

---
 testcases/kernel/syscalls/fcntl/.gitignore |   2 +
 testcases/kernel/syscalls/fcntl/fcntl41.c  | 178 +++++++++++++++++++++
 2 files changed, 180 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl41.c
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
index e558cfe83..4bdae1a22 100644
@@ -76,3 +76,5 @@
 /fcntl39_64
 /fcntl40
 /fcntl40_64
+/fcntl41
+/fcntl41_64
testcases/kernel/syscalls/fcntl/fcntl41.c new file +178 -0

178 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#11 lore raw

Re: [LTP] [PATCH 2/5] fcntl41: test for owner values on OFD posix locks

Hi Alexander,

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +0 -0
new file mode 100644
index 000000000..40d14ff02

...

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +10 -0
+#include <sys/wait.h>
+
+#include "tst_test.h"
+
+static int fd, fd2;
+
+void do_child1(void)
+{
+	const struct flock fl_0_0 = {
+		.l_type = F_WRLCK,

testcases/kernel/syscalls/fcntl/fcntl41.c line 71

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +10 -0
+		.l_whence = SEEK_SET,
+		.l_start = 0L,
+		.l_len = 1L,
+	};
+
+	tst_res(TINFO, "thread1 waits for thread2 to lock 1-1");
+	TST_CHECKPOINT_WAIT(1);
+
+	tst_res(TINFO, "thread1 lock region 0-0 - It should block");
+	SAFE_FCNTL(fd2, F_OFD_SETLKW, &fl_0_0);

F_OFD_SETLKW is undefined on old Cent0S 7, we still support:
https://github.com/pevik/ltp/actions/runs/5331934790/jobs/9660442246

You need to use our fallback to avoid this.

#include "lapi/fcntl.h"

We also have fcntl_common.h, which is used for F_OFD_* (fcntl_compat(), you may need to use it. It also includes lapi/fcntl.h.

Kind regards,
Petr

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#12 lore raw

Re: [LTP] [PATCH 2/5] fcntl41: test for owner values on OFD posix locks

Hi,

Quoted 32 lines · Petr Vorel

Hi Alexander,

Quoted 5 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +0 -0
new file mode 100644
index 000000000..40d14ff02

...

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +10 -0
+#include <sys/wait.h>
+
+#include "tst_test.h"
+
+static int fd, fd2;
+
+void do_child1(void)
+{
+     const struct flock fl_0_0 = {
+             .l_type = F_WRLCK,

testcases/kernel/syscalls/fcntl/fcntl41.c line 71

Quoted 10 lines
testcases/kernel/syscalls/fcntl/fcntl41.c new file +10 -0
+             .l_whence = SEEK_SET,
+             .l_start = 0L,
+             .l_len = 1L,
+     };
+
+     tst_res(TINFO, "thread1 waits for thread2 to lock 1-1");
+     TST_CHECKPOINT_WAIT(1);
+
+     tst_res(TINFO, "thread1 lock region 0-0 - It should block");
+     SAFE_FCNTL(fd2, F_OFD_SETLKW, &fl_0_0);

F_OFD_SETLKW is undefined on old Cent0S 7, we still support:
https://github.com/pevik/ltp/actions/runs/5331934790/jobs/9660442246

Quoted 7 lines

You need to use our fallback to avoid this.

#include "lapi/fcntl.h"

We also have fcntl_common.h, which is used for F_OFD_* (fcntl_compat(), you may need to use it. It also includes lapi/fcntl.h.

ok.

- Alex

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#13 lore raw

PATCH 3/5 fcntl42: test for F_SETLKW interruption case

In reply to Alexander Aring

This patch adds fcntl42 testcase to test on side effects, e.g. unlock all acquired locks, when a lock request was interrupted by a signal.

---
 testcases/kernel/syscalls/fcntl/.gitignore |   2 +
 testcases/kernel/syscalls/fcntl/fcntl42.c  | 153 +++++++++++++++++++++
 2 files changed, 155 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl42.c
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
index 4bdae1a22..abffa2967 100644
@@ -78,3 +78,5 @@
 /fcntl40_64
 /fcntl41
 /fcntl41_64
+/fcntl42
+/fcntl42_64
testcases/kernel/syscalls/fcntl/fcntl42.c new file +153 -0

153 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#14 lore raw

PATCH 4/5 fcntl43: test for identical F_SETLKW lock requests

In reply to Alexander Aring

This patch adds fcntl43 to test two identical lock requests at the same time. They are identical as they will be granted at the same time.

---
 testcases/kernel/syscalls/fcntl/.gitignore |   2 +
 testcases/kernel/syscalls/fcntl/Makefile   |   3 +
 testcases/kernel/syscalls/fcntl/fcntl43.c  | 140 +++++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 testcases/kernel/syscalls/fcntl/fcntl43.c
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
index abffa2967..6622aedbc 100644
@@ -80,3 +80,5 @@
 /fcntl41_64
 /fcntl42
 /fcntl42_64
+/fcntl43
+/fcntl43_64
testcases/kernel/syscalls/fcntl/Makefile +3 -0
index c3196a527..7478b87ec 100644
@@ -15,6 +15,9 @@ fcntl36_64: LDLIBS += -lpthread
 fcntl40: LDLIBS += -lpthread
 fcntl40_64: LDLIBS += -lpthread
 
+fcntl43: LDLIBS += -lpthread
+fcntl43_64: LDLIBS += -lpthread
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../utils/newer_64.mk
 
testcases/kernel/syscalls/fcntl/fcntl43.c new file +140 -0

140 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#15 lore raw

PATCH 5/5 fcntl44: test for kill child while others waiting

In reply to Alexander Aring

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.

---
 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
testcases/kernel/syscalls/fcntl/.gitignore +2 -0
index 6622aedbc..0ee00ce1f 100644
@@ -82,3 +82,5 @@
 /fcntl42_64
 /fcntl43
 /fcntl43_64
+/fcntl44_64
+/fcntl44
testcases/kernel/syscalls/fcntl/fcntl44.c new file +128 -0

128 lines not on this page · raw message

Signature · 5 lines
2.31.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp