From patchwork Mon Jun 20 13:27:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1645508 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=nhFwBxC+; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRVnr0Fpnz9sFx for ; Mon, 20 Jun 2022 23:27:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7FB2C3C93BA for ; Mon, 20 Jun 2022 15:27:57 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (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 7E25D3C9266 for ; Mon, 20 Jun 2022 15:27:44 +0200 (CEST) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 994CC6002C4 for ; Mon, 20 Jun 2022 15:27:44 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id o8so14704827wro.3 for ; Mon, 20 Jun 2022 06:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AMbHAsfg5InTeTYpQcp91/RcpYe8eE9b78r04KXwY1Q=; b=nhFwBxC+92Pyg/Oi41R+3cQfWZrm189VXKTQTvZR0+gBNrdhnnvS5mufoApv81EYb4 ywtLfv2NC50qF3v/qHQxZIEYwVqh0uxQjb0+Sy4Muieqad/5243aEK5Ht4Xe7wHrIS/2 j9NhBG8Fdwer66vEH/1579MW8f4TGwD/aGMJVvc/AWY8PzfQRPGvvQ5ss14lNYYxID8U JL8Uf8x58IVYnNLyxAzFYaEvheqO+N+K6pXqehezIJ/Pdic8yA5NdMJald3Apbjtd52E SmE52QiIPalRa0Vd73r+g7tAQ2MmwZVNK7p267BzogvSDCeyju46AlElwygvbypIT6JM lVPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=AMbHAsfg5InTeTYpQcp91/RcpYe8eE9b78r04KXwY1Q=; b=T7XAhIuY4bB0hTKAz70/9v1CDOfZ2YDRRYxI08/XN6kvxvU95aXUd6IvWJ1+FoSJzx kvQ2wQWoPh2UnV5675YQLPvU5HKA4OhZa/BAh5uPknEVN+IEYrCV5l9rkSgwbiGSU3DB Ne94a8a0la8bXAREVBV0XZzdPnuYXwZ8sw15zbBLn49hwJ3jdD8M81bIvSvRDmfDDaoN 9o8Q6FXcvh8Jh6T5joUUHNOoATpvYXXTAI2ea4jPhoNftr0A59XZTa3f9EEMt5PalWTF DAKpzkWcflOtzdVOZU3L9PTwq+sqq4XHV+FBODjNNktNhvM0rY9Tkt63KQvOVbJ98kS4 /Rhg== X-Gm-Message-State: AJIora+QLZsUbbYNOf1PWmJxbOIOtdsplkzVcXV2Uch+ZwJAwUEShBvz ldLJ1IZk1zTjaAZ787LxABvts4Fh+LKM1w== X-Google-Smtp-Source: AGRyM1tW4q5+mSIUXaHnVA5Diuh5aYtSN6AOhc+eemk4eu9UMBE9bR/uqt+RYv29v4WC/WUlOrO41w== X-Received: by 2002:a05:6000:1887:b0:218:5d15:9a95 with SMTP id a7-20020a056000188700b002185d159a95mr23046956wri.1.1655731664091; Mon, 20 Jun 2022 06:27:44 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id d5-20020a5d4f85000000b0021b862ad439sm9086556wru.9.2022.06.20.06.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 06:27:43 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Mon, 20 Jun 2022 16:27:34 +0300 Message-Id: <20220620132737.2015073-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620132737.2015073-1-amir73il@gmail.com> References: <20220620132737.2015073-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-5.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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH 1/4] syscalls/fanotify09: Cleanup open event fds on error 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: , Cc: Matthew Bobrowski , Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Avoid breaking out of test, without closing all fds of events in buffer to avoid failure to unmount fs on cleanup. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index fea374689..60ffcb81b 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -238,6 +238,15 @@ static void verify_event(int group, struct fanotify_event_metadata *event, SAFE_CLOSE(event->fd); } +static void close_event_fds(struct fanotify_event_metadata *event, int buflen) +{ + /* Close all file descriptors of read events */ + for (; FAN_EVENT_OK(event, buflen); FAN_EVENT_NEXT(event, buflen)) { + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); + } +} + static void test_fanotify(unsigned int n) { int ret, dirfd; @@ -262,8 +271,7 @@ static void test_fanotify(unsigned int n) * generate FAN_CLOSE_NOWRITE event on a child, subdir or "." */ dirfd = SAFE_OPEN(tc->close_nowrite, O_RDONLY); - if (dirfd >= 0) - SAFE_CLOSE(dirfd); + SAFE_CLOSE(dirfd); /* * First verify the first group got the file MODIFY event and got just @@ -278,15 +286,17 @@ static void test_fanotify(unsigned int n) "reading fanotify events failed"); } } + event = (struct fanotify_event_metadata *)event_buf; if (ret < tc->nevents * (int)FAN_EVENT_METADATA_LEN) { - tst_brk(TBROK, + tst_res(TFAIL, "short read when reading fanotify events (%d < %d)", ret, tc->nevents * (int)FAN_EVENT_METADATA_LEN); } - event = (struct fanotify_event_metadata *)event_buf; - verify_event(0, event, FAN_MODIFY, tc->report_name ? fname : ""); - event = FAN_EVENT_NEXT(event, ret); - if (tc->nevents > 1) { + if (FAN_EVENT_OK(event, ret)) { + verify_event(0, event, FAN_MODIFY, tc->report_name ? fname : ""); + event = FAN_EVENT_NEXT(event, ret); + } + if (tc->nevents > 1 && FAN_EVENT_OK(event, ret)) { verify_event(0, event, FAN_CLOSE_NOWRITE, tc->report_name ? (tc->ondir ? "." : tc->close_nowrite) : ""); event = FAN_EVENT_NEXT(event, ret); @@ -296,11 +306,7 @@ static void test_fanotify(unsigned int n) "first group got more than %d events (%d bytes)", tc->nevents, ret); } - /* Close all file descriptors of read events */ - for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) { - if (event->fd != FAN_NOFD) - SAFE_CLOSE(event->fd); - } + close_event_fds(event, ret); /* * Then verify the rest of the groups did not get the MODIFY event and @@ -318,15 +324,14 @@ static void test_fanotify(unsigned int n) verify_event(i, event, expect, ""); event = FAN_EVENT_NEXT(event, ret); - for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) { - if (event->fd != FAN_NOFD) - SAFE_CLOSE(event->fd); - } + close_event_fds(event, ret); continue; } - if (ret == 0) - tst_brk(TBROK, "zero length read from fanotify fd"); + if (ret == 0) { + tst_res(TFAIL, "group %d zero length read from fanotify fd", i); + continue; + } if (errno != EAGAIN) { tst_brk(TBROK | TERRNO, @@ -360,8 +365,8 @@ static void cleanup(void) SAFE_CHDIR("../"); - if (mount_created && tst_umount(MOUNT_NAME) < 0) - tst_brk(TBROK | TERRNO, "umount failed"); + if (mount_created) + SAFE_UMOUNT(MOUNT_NAME); } static struct tst_test test = { From patchwork Mon Jun 20 13:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1645509 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=VW07vHFf; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRVp22x4Gz9sFx for ; Mon, 20 Jun 2022 23:28:10 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 579BF3C925E for ; Mon, 20 Jun 2022 15:28:08 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C9ECF3C937A for ; Mon, 20 Jun 2022 15:27:46 +0200 (CEST) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 06544100023C for ; Mon, 20 Jun 2022 15:27:46 +0200 (CEST) Received: by mail-wm1-x332.google.com with SMTP id m32-20020a05600c3b2000b0039756bb41f2so5691831wms.3 for ; Mon, 20 Jun 2022 06:27:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OMQ2Cb6oDXEoth7Jvg2oYWhmkyQKrNLmMvoEhtoNIGA=; b=VW07vHFfLTtLFRPXmL5NCk41LD5snClDMFVdN6S4JWPcZRaGuTO/9d11SW7btsJ375 h1ZAsO4iVHI5+aqAc7tEkmGb9WrLFbC2m8FA1pmI1ivp6F7pRBOnSZ6bxka4inPiJdHv NgB6bwSAVN3o6E9RLuGzBwgXJZYJRFoe5il7Ab897Sj4LyUzPpCnOwUO75mKuG192Q0v BLJMQUg0n+PcHfjKYvbRogaDjMwVxxCEJuh1iqFgHBmJHHzgq/UWVp2YdJR4ru5MCbYq zV7oJrA3EajnRv6WfUw4quM2/HUwNaObQ4tdWl52yIH+JiL9+L4nXGCBbhuW70f23zy9 texg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=OMQ2Cb6oDXEoth7Jvg2oYWhmkyQKrNLmMvoEhtoNIGA=; b=L6sE5Ewjigoxk0yyemBbzoLjsNrQ80iLRu17cU+cdyKvaJ6FocOFXSAxPcdqMLwstr FbXnohiwv7rFXJH9H+mBP7jUIvNk8I56pLYvviAtHAKL8RlA94LKuhm4ALP3sS5h6zaU oOVVRiaYeVatHjuPyJwXPPfBeTarubZVTZBCqneNhCRWvNJRSc/R5jweDoAxZEQKR4st T6Ixxn81+RrOWpCoPGMa8CFdz08Kzcj7FhuY3ol97A6tx77Ng4Hcf096j10H2M/p7nfx YSr+hRcOWVB+Oin1ottcr//K0bPHmn0otH3uITtcAOIHtkw/NijDA4rRrwHpHWUlGx0X /UUQ== X-Gm-Message-State: AOAM5308TbLf/ahRs56EKUpowh6L15+revt8mleYjXpLfx4x3VehWtZ9 a2UMvYtfSveycj3b227DcbU= X-Google-Smtp-Source: ABdhPJzsD8Fd2DZ9MKcjevsynM7FyMl2PTrE44Yr1FvFf3N1DN1kRfUzHK+H8F0aim+MCxBbsLsVVg== X-Received: by 2002:a05:600c:4f15:b0:39c:7eaf:97e7 with SMTP id l21-20020a05600c4f1500b0039c7eaf97e7mr35195560wmq.199.1655731665471; Mon, 20 Jun 2022 06:27:45 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id d5-20020a5d4f85000000b0021b862ad439sm9086556wru.9.2022.06.20.06.27.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 06:27:44 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Mon, 20 Jun 2022 16:27:35 +0300 Message-Id: <20220620132737.2015073-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620132737.2015073-1-amir73il@gmail.com> References: <20220620132737.2015073-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 2/4] syscalls/fanotify09: Verify if no events are expected 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: , Cc: Matthew Bobrowski , Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Some test cases expect no events for non-first groups and some expect one event on non-dir child for non-first groups, but it is not verified that non-first groups get the desired amount of events, so add this information to the test case definition. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index 60ffcb81b..a8d56c10b 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -76,6 +76,7 @@ static struct tcase { unsigned int report_name; const char *close_nowrite; int nevents; + unsigned int nonfirst_event; } tcases[] = { { "Events on non-dir child with both parent and mount marks", @@ -83,7 +84,7 @@ static struct tcase { 0, 0, DIR_NAME, - 1, + 1, 0, }, { "Events on non-dir child and subdir with both parent and mount marks", @@ -91,7 +92,7 @@ static struct tcase { FAN_ONDIR, 0, DIR_NAME, - 2, + 2, 0, }, { "Events on non-dir child and parent with both parent and mount marks", @@ -99,7 +100,7 @@ static struct tcase { FAN_ONDIR, 0, ".", - 2, + 2, 0 }, { "Events on non-dir child and subdir with both parent and subdir marks", @@ -107,7 +108,7 @@ static struct tcase { FAN_ONDIR, 0, DIR_NAME, - 2, + 2, 0, }, { "Events on non-dir children with both parent and mount marks", @@ -115,7 +116,7 @@ static struct tcase { 0, 0, FILE2_NAME, - 2, + 2, FAN_CLOSE_NOWRITE, }, { "Events on non-dir child with both parent and mount marks and filename info", @@ -123,7 +124,7 @@ static struct tcase { 0, FAN_REPORT_DFID_NAME, FILE2_NAME, - 2, + 2, FAN_CLOSE_NOWRITE, }, }; @@ -315,13 +316,8 @@ static void test_fanotify(unsigned int n) for (i = 1; i < NUM_GROUPS; i++) { ret = read(fd_notify[i], event_buf, EVENT_BUF_LEN); if (ret > 0) { - uint32_t expect = 0; - - if (tc->nevents > 1 && !tc->ondir) - expect = FAN_CLOSE_NOWRITE; - event = (struct fanotify_event_metadata *)event_buf; - verify_event(i, event, expect, ""); + verify_event(i, event, tc->nonfirst_event, ""); event = FAN_EVENT_NEXT(event, ret); close_event_fds(event, ret); @@ -338,7 +334,10 @@ static void test_fanotify(unsigned int n) "reading fanotify events failed"); } - tst_res(TPASS, "group %d got no event", i); + if (tc->nonfirst_event) + tst_res(TFAIL, "group %d expected and got no event", i); + else + tst_res(TPASS, "group %d got no event as expected", i); } cleanup_fanotify_groups(); } From patchwork Mon Jun 20 13:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1645510 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=OIuUGxHY; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRVpH4rmTz9sFx for ; Mon, 20 Jun 2022 23:28:23 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 858A03C93BA for ; Mon, 20 Jun 2022 15:28:21 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (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 A5C363C93AF for ; Mon, 20 Jun 2022 15:27:47 +0200 (CEST) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 2DE671400188 for ; Mon, 20 Jun 2022 15:27:47 +0200 (CEST) Received: by mail-wr1-x42f.google.com with SMTP id m1so6930393wrb.2 for ; Mon, 20 Jun 2022 06:27:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rDaZNAqyjcycuwbwOMXHoa4OSlTBOGaRzBULsoapsK0=; b=OIuUGxHY4j8ExMnkXguBnMGnMc3bRNJVTTHxihLZ1U/KShF3TLAmmb3jM9Dusl86e5 M0pQ6+Sm6rXfNfkc01PmkXtfKVF2mlIhACtJEUs3eGotDNWinABIycJ/VN1XUhxlzLBv 2iI3zU19ZOkBQjCM1WwL/GRIHoDh1sW+gBcCQlscjDHRU2tWV8Xj1QE7bo3Pj7HIxUxQ a5Exxve6dtGAS+uG/BntfN1xdGJtrSHf+urX6A0dsU1ny4VTB58RyzQ41oADa2pHtaeI qszKjKYaw7804pldPtKC8PNhwGAVyIx/pEvgHc+m5IRjs5ubcCczhCoVJUgbLPaDEBai AsBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rDaZNAqyjcycuwbwOMXHoa4OSlTBOGaRzBULsoapsK0=; b=sHObRwCSKPZirVJcsfyAUosuOuv6aePHhuScutGayLCgrUFKsqR2TT9BU0vLYOWElI qNRvzJV+ph2NGJTCQjA+CWzoOpRHIT987MXPyuJl8AMI4Nz0PVcRuZhvupMHZ3iVxekl BcHFG8yAsGUSYVSuqfsjrkBk2H0eHyAtyO1W3SNBCh68sjPllk2iO4EnCpsCmJonUM3Y obRk7rE81I4VLb69v56xcHDeTy+A7/8lxSTjcVUp6lsD9UZaLDrkv7H10l/a9V/sn4/P 1GDuZQ3P410+Iw3hDYhpTumvoZciYG/kgr7qHTK+l76JfSeslvOOMIDyQMH99p9KXtqB i9kA== X-Gm-Message-State: AJIora9OXeOJMvnL5HjH21ao7Pj5hAiWxYjckJ7Izg04P9Ba20QtAIjq puTxwLISq6SSectwmnwKQTQ= X-Google-Smtp-Source: AGRyM1vL40kAaIfIeAiDIZM1xjoIsC5NkogoXUZQM8hN/L3IQaZxzbxBEDC/iQJEYoG27xhedQoBRA== X-Received: by 2002:a05:6000:186e:b0:218:5f5d:9c55 with SMTP id d14-20020a056000186e00b002185f5d9c55mr21879774wri.128.1655731666694; Mon, 20 Jun 2022 06:27:46 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id d5-20020a5d4f85000000b0021b862ad439sm9086556wru.9.2022.06.20.06.27.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 06:27:46 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Mon, 20 Jun 2022 16:27:36 +0300 Message-Id: <20220620132737.2015073-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620132737.2015073-1-amir73il@gmail.com> References: <20220620132737.2015073-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH 3/4] syscalls/fanotify09: Tidy up the test to make it more readable 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: , Cc: Matthew Bobrowski , Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Document and tidy up the code dealing with mask flags FAN_ONDIR and FAN_EVENT_ONCHILD. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index a8d56c10b..070ad9933 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -12,21 +12,21 @@ */ /* - * This is a regression test for commit 54a307ba8d3c: + * This is a regression test for commit: * - * fanotify: fix logic of events on child + * 54a307ba8d3c fanotify: fix logic of events on child * - * Test case #1 is a regression test for commit b469e7e47c8a: + * Test case #1 is a regression test for commit: * - * fanotify: fix handling of events on child sub-directory + * b469e7e47c8a fanotify: fix handling of events on child sub-directory * - * Test case #2 is a regression test for commit 55bf882c7f13: + * Test case #2 is a regression test for commit: * - * fanotify: fix merging marks masks with FAN_ONDIR + * 55bf882c7f13 fanotify: fix merging marks masks with FAN_ONDIR * - * Test case #5 is a regression test for commit 7372e79c9eb9: + * Test case #5 is a regression test for commit: * - * fanotify: fix logic of reporting name info with watched parent + * 7372e79c9eb9 fanotify: fix logic of reporting name info with watched parent */ #define _GNU_SOURCE @@ -131,13 +131,26 @@ static struct tcase { static void create_fanotify_groups(struct tcase *tc) { struct fanotify_mark_type *mark = &tc->mark; - unsigned int i, onchild, report_name, ondir = tc->ondir; + int i; for (i = 0; i < NUM_GROUPS; i++) { /* - * The first group may request events with filename info. + * The first group may request events with filename info and + * events on subdirs and always request events on children. */ - report_name = (i == 0) ? tc->report_name : 0; + unsigned int report_name = tc->report_name; + unsigned int mask_flags = tc->ondir | FAN_EVENT_ON_CHILD; + unsigned int parent_mask; + + /* + * The non-first groups do not request events on children and + * subdirs. + */ + if (i > 0) { + report_name = 0; + mask_flags = 0; + } + fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | report_name | FAN_NONBLOCK, O_RDONLY); @@ -145,21 +158,20 @@ static void create_fanotify_groups(struct tcase *tc) * Add subdir or mount mark for each group with CLOSE event, * but only the first group requests events on dir. */ - onchild = (i == 0) ? FAN_EVENT_ON_CHILD | ondir : 0; SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD | mark->flag, - FAN_CLOSE_NOWRITE | onchild, + FAN_CLOSE_NOWRITE | mask_flags, AT_FDCWD, tc->close_nowrite); /* * Add inode mark on parent for each group with MODIFY event, * but only the first group requests events on child. * The one mark with FAN_EVENT_ON_CHILD is needed for - * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry - * flag. + * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry flag. */ + parent_mask = FAN_MODIFY | tc->ondir | mask_flags; SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD, - FAN_MODIFY | ondir | onchild, + parent_mask, AT_FDCWD, "."); } } From patchwork Mon Jun 20 13:27:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1645511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=XdlCHmCh; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LRVpW0r7kz9sFx for ; Mon, 20 Jun 2022 23:28:34 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D8DF43C9223 for ; Mon, 20 Jun 2022 15:28:32 +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 [217.194.8.4]) (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 501723C927E for ; Mon, 20 Jun 2022 15:27:49 +0200 (CEST) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 3F9CB1000373 for ; Mon, 20 Jun 2022 15:27:48 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id v14so14698974wra.5 for ; Mon, 20 Jun 2022 06:27:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=38g23xwve3LJp2dx4uaaPIFPIJPvuVpMA5sZtWThGsk=; b=XdlCHmChNqJANehXrBAdBcn2h9BqFdCkKSe0nV+R6LMIYtf6bb3ugDPjRtqBp1EZGY dWBU9BzQP1QPJWSa/yAfff/Nabt8jJQ28WTbd0fvHfjqouwa4wlGftDwZd5JkxjqLPgg EZj5sw36LsOXhjFUf00KvokYOYHymoPZeK2vPY+KZYlTQrZ1rAuX85A+VfmSS7rrUocP jNC6hOif2O/Ojm8/tIOi/OIeZW3bTTc2p7rMrZCYJ823vedDcPJQ6gvzqyYeww4JAyfr H43f3bLP1msycW3QJjk5Kk375GZq5QDgBILEg3nLrJZqN8Mhdl4VF6IELhP1R7BUVZZg OZnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=38g23xwve3LJp2dx4uaaPIFPIJPvuVpMA5sZtWThGsk=; b=LxXFTRUf3qqxJ/Crmw7vMjIt5hY8XwpLJU2VP4OjLlTE4wNWKFcc8Y0CCxgL1ssmy6 /PhEmncniSdcVXTmFTZXKCQj3wW5vBxgAuOZbKb89VQVG11fZ8QSt/eokzxCEp1yr8ar Ew8FEfMuXBRoGE/J22qPm34y8jlD97DK6gc2kFXKwPqgJEbZn5giW5FcEuVaxDg/sLyJ b3cxgIhDXi0K7hjFAHi7Yb1/DMvCUPOmE9uX5GeUL7aXmy7dcRu6hvCdboCPrUrlqXR4 uxEbtUB46DFZJ9Cl3GHroVDQi4CtWcB6YcM48jHrFvI59djxSO/0qiidATFEV3anYeB1 LPEg== X-Gm-Message-State: AJIora+AHBD1HEzfcXvpV4MTxi65oqbBeAXLDzbYConK4af1qRnvOu9b 3a3Z+mHk+qDx11EkN5TOqWEWAXZCjhpkhg== X-Google-Smtp-Source: AGRyM1sHGF3k4mNNloR4K+PoDq1dGU2pjJRIldtOMbau0AkZNI2jD0vprbSMnhNRhVJRdZqxEZVAZg== X-Received: by 2002:a5d:5847:0:b0:218:5319:f4e3 with SMTP id i7-20020a5d5847000000b002185319f4e3mr23937844wrf.500.1655731667786; Mon, 20 Jun 2022 06:27:47 -0700 (PDT) Received: from amir-ThinkPad-T480.ctera.local (bzq-166-168-31-246.red.bezeqint.net. [31.168.166.246]) by smtp.gmail.com with ESMTPSA id d5-20020a5d4f85000000b0021b862ad439sm9086556wru.9.2022.06.20.06.27.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Jun 2022 06:27:47 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Mon, 20 Jun 2022 16:27:37 +0300 Message-Id: <20220620132737.2015073-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220620132737.2015073-1-amir73il@gmail.com> References: <20220620132737.2015073-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH 4/4] syscalls/fanotify09: Add test cases for merge of ignore mask 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: , Cc: Matthew Bobrowski , Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1. Verify that an ignore mask that does not survive modify event, does survive a modify event on child, if parent is not watching events on children. 2. Verify that an ignore mask on parent does not ignore close events sent to mount mark, if parent is not watching events on children. The behavior of these corner cases of ignore mask on parent dir have always been undefined, so do not run the test for kernel < v5.19. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 72 +++++++++++++++++-- 1 file changed, 68 insertions(+), 4 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index 070ad9933..0eb83e2f8 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -27,6 +27,11 @@ * Test case #5 is a regression test for commit: * * 7372e79c9eb9 fanotify: fix logic of reporting name info with watched parent + * + * Test cases #6-#7 are regression tests for commit: + * (from v5.19, unlikely to be backported thus not in .tags): + * + * e730558adffb fanotify: consistent behavior for parent not watching children */ #define _GNU_SOURCE @@ -73,6 +78,7 @@ static struct tcase { const char *tname; struct fanotify_mark_type mark; unsigned int ondir; + unsigned int ignore; unsigned int report_name; const char *close_nowrite; int nevents; @@ -83,6 +89,7 @@ static struct tcase { INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, 0, + 0, DIR_NAME, 1, 0, }, @@ -91,6 +98,7 @@ static struct tcase { INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, 0, + 0, DIR_NAME, 2, 0, }, @@ -99,6 +107,7 @@ static struct tcase { INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, 0, + 0, ".", 2, 0 }, @@ -107,6 +116,7 @@ static struct tcase { INIT_FANOTIFY_MARK_TYPE(INODE), FAN_ONDIR, 0, + 0, DIR_NAME, 2, 0, }, @@ -115,6 +125,7 @@ static struct tcase { INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, 0, + 0, FILE2_NAME, 2, FAN_CLOSE_NOWRITE, }, @@ -122,10 +133,29 @@ static struct tcase { "Events on non-dir child with both parent and mount marks and filename info", INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, + 0, FAN_REPORT_DFID_NAME, FILE2_NAME, 2, FAN_CLOSE_NOWRITE, }, + { + "Events on non-dir child with ignore mask on parent", + INIT_FANOTIFY_MARK_TYPE(MOUNT), + 0, + FAN_MARK_IGNORED_MASK, + 0, + DIR_NAME, + 1, 0, + }, + { + "Events on non-dir children with surviving ignore mask on parent", + INIT_FANOTIFY_MARK_TYPE(MOUNT), + 0, + FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY, + 0, + FILE2_NAME, + 2, FAN_CLOSE_NOWRITE, + }, }; static void create_fanotify_groups(struct tcase *tc) @@ -140,13 +170,14 @@ static void create_fanotify_groups(struct tcase *tc) */ unsigned int report_name = tc->report_name; unsigned int mask_flags = tc->ondir | FAN_EVENT_ON_CHILD; - unsigned int parent_mask; + unsigned int parent_mask, ignore = 0; /* * The non-first groups do not request events on children and - * subdirs. + * subdirs and may set an ignore mask on parent dir. */ if (i > 0) { + ignore = tc->ignore; report_name = 0; mask_flags = 0; } @@ -168,10 +199,15 @@ static void create_fanotify_groups(struct tcase *tc) * but only the first group requests events on child. * The one mark with FAN_EVENT_ON_CHILD is needed for * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry flag. + * + * The inode mark on non-first group is either with FAN_MODIFY + * in mask or FAN_CLOSE_NOWRITE in ignore mask. In either case, + * it is not expected to get the modify event on a child, nor + * the close event on dir. */ parent_mask = FAN_MODIFY | tc->ondir | mask_flags; - SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD, - parent_mask, + SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD | ignore, + ignore ? FAN_CLOSE_NOWRITE : parent_mask, AT_FDCWD, "."); } } @@ -186,6 +222,21 @@ static void cleanup_fanotify_groups(void) } } +static void check_ignore_mask(int fd) +{ + unsigned int ignored_mask, mflags; + char procfdinfo[100]; + + sprintf(procfdinfo, "/proc/%d/fdinfo/%d", (int)getpid(), fd); + if (FILE_LINES_SCANF(procfdinfo, "fanotify ino:%*x sdev:%*x mflags: %x mask:0 ignored_mask:%x", + &mflags, &ignored_mask) || !ignored_mask) { + tst_res(TFAIL, "The ignore mask did not survive"); + } else { + tst_res(TPASS, "Found mark with ignore mask (ignored_mask=%x, mflags=%x) in %s", + ignored_mask, mflags, procfdinfo); + } +} + static void event_res(int ttype, int group, struct fanotify_event_metadata *event, const char *filename) @@ -274,6 +325,12 @@ static void test_fanotify(unsigned int n) return; } + if (tc->ignore && tst_kvercmp(5, 19, 0) < 0) { + tst_res(TCONF, "ignored mask on parent dir has undefined " + "behavior on kernel < 5.19"); + return; + } + create_fanotify_groups(tc); /* @@ -326,6 +383,13 @@ static void test_fanotify(unsigned int n) * got the FAN_CLOSE_NOWRITE event only on a non-directory. */ for (i = 1; i < NUM_GROUPS; i++) { + /* + * Verify that ignore mask survived the modify event on child, + * which was not supposed to be sent to this group. + */ + if (tc->ignore) + check_ignore_mask(fd_notify[i]); + ret = read(fd_notify[i], event_buf, EVENT_BUF_LEN); if (ret > 0) { event = (struct fanotify_event_metadata *)event_buf;