From patchwork Tue May 30 20:37:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 1787966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=CYt6SbEo; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW43d6srRz20PW for ; Wed, 31 May 2023 06:38:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1E2613CE715 for ; Tue, 30 May 2023 22:38:19 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id D92F53CCFA1 for ; Tue, 30 May 2023 22:37:23 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 7A3A11000BD9 for ; Tue, 30 May 2023 22:37:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685479040; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DjN6dg59V0TBoYTUAid/o9q8l4IMeFbDiTYtOBeabOM=; b=CYt6SbEo7n0yQcY6Ruj+bNZiiqQYlc61TfJwk42YfXAIDfgnqfvmFKYiVFk5DLRJtDuxnQ zQ0Mmvvy/xT0LX3BRm65lsjP8ohrCAmMo13mLyVQlG3IjMklLyc2UaGSLGtD5Z7VpXmSF4 NDid5y5DYgDjMGIRK2TwfETrL9H9n2w= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-46-S2jGaPTTNbC4ekTG1wJi8g-1; Tue, 30 May 2023 16:37:19 -0400 X-MC-Unique: S2jGaPTTNbC4ekTG1wJi8g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B95A8007D9 for ; Tue, 30 May 2023 20:37:19 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 22A8020296C6; Tue, 30 May 2023 20:37:19 +0000 (UTC) From: Alexander Aring To: ltp@lists.linux.it Date: Tue, 30 May 2023 16:37:03 -0400 Message-Id: <20230530203707.2965684-2-aahringo@redhat.com> In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com> References: <20230530203707.2965684-1-aahringo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.1 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 1/5] fcntl40: test for owner values on classic posix lock X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Signed-off-by: Alexander Aring --- 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 diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore index 10cb0995f..e558cfe83 100644 --- a/testcases/kernel/syscalls/fcntl/.gitignore +++ b/testcases/kernel/syscalls/fcntl/.gitignore @@ -74,3 +74,5 @@ /fcntl38_64 /fcntl39 /fcntl39_64 +/fcntl40 +/fcntl40_64 diff --git a/testcases/kernel/syscalls/fcntl/Makefile b/testcases/kernel/syscalls/fcntl/Makefile index df663a50a..c3196a527 100644 --- a/testcases/kernel/syscalls/fcntl/Makefile +++ b/testcases/kernel/syscalls/fcntl/Makefile @@ -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 diff --git a/testcases/kernel/syscalls/fcntl/fcntl40.c b/testcases/kernel/syscalls/fcntl/fcntl40.c new file mode 100644 index 000000000..829685436 --- /dev/null +++ b/testcases/kernel/syscalls/fcntl/fcntl40.c @@ -0,0 +1,188 @@ +/* + * [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. + * Try it on other filesystems to compare results. + * + * [What's it doing] + * + * The test shows that we currently have problems with the operation lookup + * functionality [0] when we using threads. The owner value is the same for two + * locks being in WAITING state. dlm_controld "dlm_tool plocks $LS" will show + * it correctly that the specific lock is not in waiting anymore. The issue + * begins matching the right iter->done in the kernel at dev_write() see [0]. + * + * What this test does is (using dlm_controld interval range interpretation): + * + * parent: + * + * 1. lock[0-1] + * + * child: + * + * thread1: + * + * 2. lockw[1-1] - important 1-1 at first because the order of WAITING state + * locks matters + * + * thread2: + * + * 3. lockw[0-0] + * + * parent: + * + * 4. unlock[1-1] - will give a iter->done = 1 in [0] for lock at 3. and the + * application results in a deadlock + * 5. unlock[0-0] + * + * We have this issue also with SETLK, GETLK - it's easier to reproduce + * with SETLKW because dev_write() is more controlable by doing unlocks. + * + * OFD (open filedescriptor locks) are also affected and should be able + * to reproduce with fork() only and not threads. The owner value of [0] + * depends on "struct file *" pointer in this case. + * + * [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/dlm/plock.c?h=v6.3#n432 + */ + +#include +#include + +#include "tst_safe_pthread.h" +#include "tst_test.h" + +static int fd; + +static void *do_thread1(void *arg) +{ + const struct flock fl_0_0 = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 0L, + .l_len = 1L, + }; + (void)arg; + + 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(fd, F_SETLKW, &fl_0_0); + tst_res(TINFO, "lock region 0-0 acquired"); + + return NULL; +} + +static void *do_thread2(void *arg) +{ + const struct flock fl_1_1 = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 1L, + .l_len = 1L, + }; + (void)arg; + + tst_res(TINFO, "thread1 lock region 1-1 - It should block"); + SAFE_FCNTL(fd, F_SETLKW, &fl_1_1); + tst_res(TINFO, "lock region 1-1 acquired"); + + TST_CHECKPOINT_WAKE(2); + + return NULL; +} + +void do_child(void) +{ + 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) +{ + 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); + /* 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(); + return; + } + + do_parent(); + wait(NULL); + + tst_res(TPASS, "Parent passed!"); +} + +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, +}; From patchwork Tue May 30 20:37:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 1787964 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=X2khfxdb; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW43D65bqz20PW for ; Wed, 31 May 2023 06:38:00 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 45AFA3CB939 for ; Tue, 30 May 2023 22:37:58 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 766CC3CCFAE for ; Tue, 30 May 2023 22:37:23 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 91D47600D93 for ; Tue, 30 May 2023 22:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685479041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UclEeytSxBtMCAJA0FHvD2BTmOAl4543G4hHGOceilM=; b=X2khfxdb5yJ2+ZZPtiPMX0ukg7A3PpbCYWYKhQxWwF5Lw9eeJtIGuZN5yYM8K/MlpHr4JB SuXs9H3cjAaX46EfALmeNLuBZjtZsqJAIZkyFSupBqEM3jY6CYFrr6ddK68ch+gnQxzPAW 9XLXkllzzu9CupmpArCUwm78nis4UBI= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-505-5wZKzjcBPyyCU5Itl0XYtw-1; Tue, 30 May 2023 16:37:19 -0400 X-MC-Unique: 5wZKzjcBPyyCU5Itl0XYtw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A4BF85A5BA for ; Tue, 30 May 2023 20:37:19 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4332420296C6; Tue, 30 May 2023 20:37:19 +0000 (UTC) From: Alexander Aring To: ltp@lists.linux.it Date: Tue, 30 May 2023 16:37:04 -0400 Message-Id: <20230530203707.2965684-3-aahringo@redhat.com> In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com> References: <20230530203707.2965684-1-aahringo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.1 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 2/5] fcntl41: test for owner values on OFD posix locks X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Signed-off-by: Alexander Aring --- 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 diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore index e558cfe83..4bdae1a22 100644 --- a/testcases/kernel/syscalls/fcntl/.gitignore +++ b/testcases/kernel/syscalls/fcntl/.gitignore @@ -76,3 +76,5 @@ /fcntl39_64 /fcntl40 /fcntl40_64 +/fcntl41 +/fcntl41_64 diff --git a/testcases/kernel/syscalls/fcntl/fcntl41.c b/testcases/kernel/syscalls/fcntl/fcntl41.c new file mode 100644 index 000000000..40d14ff02 --- /dev/null +++ b/testcases/kernel/syscalls/fcntl/fcntl41.c @@ -0,0 +1,178 @@ +/* + * [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 ./fcntl41 where TMPDIR is a gfs2 mountpoint. + * Try it on other filesystems to compare results. + * + * [What's it doing] + * + * The test shows that we currently have problems with the operation lookup + * functionality [0] when we using threads. The owner value is the same for two + * locks being in WAITING state. dlm_controld "dlm_tool plocks $LS" will show + * it correctly that the specific lock is not in waiting anymore. The issue + * begins matching the right iter->done in the kernel at dev_write() see [0]. + * + * What this test does is (using dlm_controld interval range interpretation): + * + * parent: + * + * 1. lock[0-1] + * + * child: + * + * thread1: + * + * 2. lockw[1-1] - important 1-1 at first because the order of WAITING state + * locks matters + * + * thread2: + * + * 3. lockw[0-0] + * + * parent: + * + * 4. unlock[1-1] - will give a iter->done = 1 in [0] for lock at 3. and the + * application results in a deadlock + * 5. unlock[0-0] + * + * We have this issue also with SETLK, GETLK - it's easier to reproduce + * with SETLKW because dev_write() is more controlable by doing unlocks. + * + * OFD (open filedescriptor locks) are also affected and should be able + * to reproduce with fork() only and not threads. The owner value of [0] + * depends on "struct file *" pointer in this case. + * + * [0] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/dlm/plock.c?h=v6.3#n432 + */ + +#include + +#include "tst_test.h" + +static int fd, fd2; + +void do_child1(void) +{ + const struct flock fl_0_0 = { + .l_type = F_WRLCK, + .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); + tst_res(TINFO, "lock region 0-0 acquired"); + + tst_res(TPASS, "Child1 passed!"); +} + +void do_child2(void) +{ + const struct flock fl_1_1 = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 1L, + .l_len = 1L, + }; + + tst_res(TINFO, "thread1 lock region 1-1 - It should block"); + SAFE_FCNTL(fd2, F_OFD_SETLKW, &fl_1_1); + tst_res(TINFO, "lock region 1-1 acquired"); + + TST_CHECKPOINT_WAKE(2); + tst_res(TPASS, "Child2 passed!"); +} + +void do_parent(void) +{ + 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); + /* 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_OFD_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_OFD_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_OFD_SETLK, &fl); + tst_res(TINFO, "parent region 0-1 locked"); + + pid = SAFE_FORK(); + if (pid == 0) { + do_child1(); + return; + } + + pid = SAFE_FORK(); + if (pid == 0) { + do_child2(); + return; + } + + do_parent(); + wait(NULL); + 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, +}; From patchwork Tue May 30 20:37:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 1787963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=ZRVmz/Ch; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW4316WL9z20PW for ; Wed, 31 May 2023 06:37:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 00F463CCFAE for ; Tue, 30 May 2023 22:37:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6FC173CCFAA for ; Tue, 30 May 2023 22:37:23 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 8B64D600878 for ; Tue, 30 May 2023 22:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685479041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=foAiNe7XydzU2kWqvjALQh0K4VYmVs3JeIGk4008Mls=; b=ZRVmz/ChzsLSOlaQlPez6UREiFQXuEBuviQ1L6SBMGS+wBKyzmnrvnRLcgdI8eLtuQISrA /rmiJAbE0U2u/ajcNyuPLRfquVM4gDA7wgfVGGbdYkq2oU5hjPYzBEq+JWGiESAuohySe4 PXrejusilcpTgsc4NXOzre3LClRO/2o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-427--akcnarkP_yhAL0l7kdpMQ-1; Tue, 30 May 2023 16:37:19 -0400 X-MC-Unique: -akcnarkP_yhAL0l7kdpMQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7984C811E7C for ; Tue, 30 May 2023 20:37:19 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62634202696C; Tue, 30 May 2023 20:37:19 +0000 (UTC) From: Alexander Aring To: ltp@lists.linux.it Date: Tue, 30 May 2023 16:37:05 -0400 Message-Id: <20230530203707.2965684-4-aahringo@redhat.com> In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com> References: <20230530203707.2965684-1-aahringo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.1 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 3/5] fcntl42: test for F_SETLKW interruption case X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Signed-off-by: Alexander Aring --- 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 diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore index 4bdae1a22..abffa2967 100644 --- a/testcases/kernel/syscalls/fcntl/.gitignore +++ b/testcases/kernel/syscalls/fcntl/.gitignore @@ -78,3 +78,5 @@ /fcntl40_64 /fcntl41 /fcntl41_64 +/fcntl42 +/fcntl42_64 diff --git a/testcases/kernel/syscalls/fcntl/fcntl42.c b/testcases/kernel/syscalls/fcntl/fcntl42.c new file mode 100644 index 000000000..4d66568fd --- /dev/null +++ b/testcases/kernel/syscalls/fcntl/fcntl42.c @@ -0,0 +1,153 @@ +/* + * [Description] + * This test confirms that DLM posix locking has problems when a posix lock + * got interrupted every lock gets unlocked. + * + * man fcntl: + * + * F_SETLKW (struct flock *) + * As for F_SETLK, but if a conflicting lock is held on the file, + * then wait for that lock to be released. If a signal is caught + * while waiting, then the call is interrupted and (after the signal + * handler has returned) returns immediately (with return value -1 and + * errno set to EINTR; see signal(7)). + * + * The above quote of the man page of fcntl() is what this testcase tests. + * particulary if it has side-effects of previously acquired locks. + * + * [How to use it] + * Call it with TMPDIR=/mnt ./fcntl42 where TMPDIR is a gfs2 mountpoint. + * Try it on other filesystems to compare results. + * + * [What's it doing] + * + * What this test does is (using dlm_controld interval range interpretation): + * + * parent: + * + * 1. lock[0-0] + * + * child: + * + * 2. lock[1-1] + * 3. lockw[0-0] - should block (see 1. parent), but we get interrupted by SIGALRM + * + * parent: + * + * 4. trylock[1-1] - should return -1 and errno -EAGAIN because the child + * should still have lock[1-1] acuired and this is what + * the child thinks to have. If it's successful the child + * wrongly assumes it has the lock[1-1] still acquired and + * the child process is still alive. + * + */ + +#include + +#include "tst_test.h" + +static int fd; + +static void catch_alarm(int num) +{ + (void)num; + + tst_res(TINFO, "catch alarm"); +} + +void do_child1(void) +{ + struct flock fl = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 1L, + .l_len = 1L, + }; + struct sigaction act; + int rv; + + SAFE_FCNTL(fd, F_SETLK, &fl); + tst_res(TINFO, "child locked lock 1-1"); + + fl.l_type = F_WRLCK; + fl.l_start = 0; + fl.l_len = 1; + + memset(&act, 0, sizeof(act)); + act.sa_handler = catch_alarm; + sigemptyset(&act.sa_mask); + sigaddset(&act.sa_mask, SIGALRM); + sigaction(SIGALRM, &act, NULL); + + /* interrupt SETLKW by signal in 3 secs */ + alarm(3); + rv = fcntl(fd, F_SETLKW, &fl); + if (rv == -1 && errno == EINTR) + tst_res(TPASS, "Child1 interrupted 0-0"); + + TST_CHECKPOINT_WAKE(1); + /* keep child alive until parent check region */ + TST_CHECKPOINT_WAIT(2); +} + +static void fcntl40_test(void) +{ + struct flock fl = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 0L, + .l_len = 1L, + }; + pid_t pid; + int rv; + + SAFE_FCNTL(fd, F_SETLK, &fl); + tst_res(TINFO, "parent lock 0-0"); + + pid = SAFE_FORK(); + if (pid == 0) { + do_child1(); + tst_res(TINFO, "childs exits"); + return; + } + + TST_CHECKPOINT_WAIT(1); + + fl.l_type = F_WRLCK; + fl.l_start = 1; + fl.l_len = 1; + rv = fcntl(fd, F_SETLK, &fl); + /* parent testing childs region, the child will think + * it has region 1-1 locked because it was interrupted + * by region 0-0. Due bugs the interruption also unlocked + * region 1-1. + */ + if (rv == -1 && errno == EAGAIN) + tst_res(TPASS, "region 1-1 locked"); + else + tst_res(TFAIL, "region 1-1 unlocked"); + + TST_CHECKPOINT_WAKE(2); + + wait(NULL); + tst_res(TINFO, "parent exits"); +} + +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, +}; From patchwork Tue May 30 20:37:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 1787962 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=KBsSlsGm; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW42q6jGgz20PW for ; Wed, 31 May 2023 06:37:39 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B17B93CCFBA for ; Tue, 30 May 2023 22:37:36 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 611183CCFA1 for ; Tue, 30 May 2023 22:37:23 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 789E0200BB8 for ; Tue, 30 May 2023 22:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685479041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OZS0eCB9R6/tJQfBcZJnUjXwLzZRrY8gN2CVq/Q5kXs=; b=KBsSlsGmnv/7mDHP7325LV38Z9LIuTtJd1XgkAovqcUydpDf4DRvYeF3+O0g2hY845U9lW 6JKQ4V21CxJ2JkjbVA3ZeQ6uh8uVc8CrmOiuVT2uWDhpS/GsmZOf3vJn9yE2uqyPl5kB+w FEuWOLhzqLrFtZvfelWFuMf91CEZEZs= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-22-XPRMW97uMxC9I4__iuXf0Q-1; Tue, 30 May 2023 16:37:19 -0400 X-MC-Unique: XPRMW97uMxC9I4__iuXf0Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9A0F1811E85 for ; Tue, 30 May 2023 20:37:19 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id 81D4D200AE6F; Tue, 30 May 2023 20:37:19 +0000 (UTC) From: Alexander Aring To: ltp@lists.linux.it Date: Tue, 30 May 2023 16:37:06 -0400 Message-Id: <20230530203707.2965684-5-aahringo@redhat.com> In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com> References: <20230530203707.2965684-1-aahringo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.1 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 4/5] fcntl43: test for identical F_SETLKW lock requests X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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. Signed-off-by: Alexander Aring --- 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 diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore index abffa2967..6622aedbc 100644 --- a/testcases/kernel/syscalls/fcntl/.gitignore +++ b/testcases/kernel/syscalls/fcntl/.gitignore @@ -80,3 +80,5 @@ /fcntl41_64 /fcntl42 /fcntl42_64 +/fcntl43 +/fcntl43_64 diff --git a/testcases/kernel/syscalls/fcntl/Makefile b/testcases/kernel/syscalls/fcntl/Makefile index c3196a527..7478b87ec 100644 --- a/testcases/kernel/syscalls/fcntl/Makefile +++ b/testcases/kernel/syscalls/fcntl/Makefile @@ -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 diff --git a/testcases/kernel/syscalls/fcntl/fcntl43.c b/testcases/kernel/syscalls/fcntl/fcntl43.c new file mode 100644 index 000000000..0a69396a4 --- /dev/null +++ b/testcases/kernel/syscalls/fcntl/fcntl43.c @@ -0,0 +1,140 @@ +/* + * [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. + * + * This testcase creates two lock requests which looks identical and should + * be granted at the same time. + * + * [How to use it] + * Call it with TMPDIR=/mnt ./fcntl43 where TMPDIR is a gfs2 mountpoint. + * Try it on other filesystems to compare results. + */ + +#include +#include + +#include "tst_safe_pthread.h" +#include "tst_test.h" + +static int fd; + +static void *do_thread1(void *arg) +{ + const struct flock fl = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 0L, + .l_len = 1L, + }; + (void)arg; + + tst_res(TINFO, "thread1 waits for thread2 to lock 0-0"); + TST_CHECKPOINT_WAIT(1); + + tst_res(TINFO, "thread1 lock region 0-0 - It should block"); + SAFE_FCNTL(fd, F_SETLKW, &fl); + tst_res(TINFO, "lock region 0-0 acquired"); + + return NULL; +} + +static void *do_thread2(void *arg) +{ + const struct flock fl = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 0L, + .l_len = 1L, + }; + (void)arg; + + tst_res(TINFO, "thread1 lock region 0-0 - It should block"); + SAFE_FCNTL(fd, F_SETLKW, &fl); + tst_res(TINFO, "lock region 0-0 acquired"); + + return NULL; +} + +void do_child(void) +{ + 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) +{ + struct flock fl = { + .l_whence = SEEK_SET, + }; + + /* wait for 1 seconds so thread2 lock 0-0 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); + /* 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-0, should be successful */ + fl.l_type = F_UNLCK; + fl.l_start = 0; + fl.l_len = 1; + 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(); + return; + } + + do_parent(); + wait(NULL); + + tst_res(TPASS, "Parent passed!"); +} + +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, +}; From patchwork Tue May 30 20:37:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Aring X-Patchwork-Id: 1787965 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=g7fEAujB; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QW43R41vvz20QD for ; Wed, 31 May 2023 06:38:11 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CC1A93CE723 for ; Tue, 30 May 2023 22:38:08 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id BDBC03CB939 for ; Tue, 30 May 2023 22:37:23 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id E9D26200BCD for ; Tue, 30 May 2023 22:37:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685479041; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OJFtseW1TKoHdAEDJ73boji0oZHmTNEr1dRP6ec14QQ=; b=g7fEAujBvlaz2zZLK5wGsV7JHiS7VyRmvflOpVKFgjqBmwncMWBdgHJ7EQHIzlT96Sz8Ev 9dpAJsnKJOz5TyTQu01pwSe0MqD1uoLOKKk/z8H7Ck9x9McPDZIQx8Tkwm07W9uS7aVpFv euvLbZfm5DlJXJavzgEKdRz5B19a0dc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-461-M_4D8P5WNcuONl1DdMGRDQ-1; Tue, 30 May 2023 16:37:20 -0400 X-MC-Unique: M_4D8P5WNcuONl1DdMGRDQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B97821C01505 for ; Tue, 30 May 2023 20:37:19 +0000 (UTC) Received: from fs-i40c-03.fs.lab.eng.bos.redhat.com (fs-i40c-03.fs.lab.eng.bos.redhat.com [10.16.224.23]) by smtp.corp.redhat.com (Postfix) with ESMTP id A1F3720296C6; Tue, 30 May 2023 20:37:19 +0000 (UTC) From: Alexander Aring To: ltp@lists.linux.it Date: Tue, 30 May 2023 16:37:07 -0400 Message-Id: <20230530203707.2965684-6-aahringo@redhat.com> In-Reply-To: <20230530203707.2965684-1-aahringo@redhat.com> References: <20230530203707.2965684-1-aahringo@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Virus-Scanned: clamav-milter 1.0.1 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 5/5] fcntl44: test for kill child while others waiting X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 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 --- 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 + +#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, +};