From patchwork Fri Dec 4 09:59:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1410932 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: 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=20161025 header.b=ufqteL/V; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CnSqW3YFHz9sWs for ; Fri, 4 Dec 2020 20:59:51 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9E3C33C6326 for ; Fri, 4 Dec 2020 10:59:46 +0100 (CET) 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 [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id D24C53C2B71 for ; Fri, 4 Dec 2020 10:59:35 +0100 (CET) Received: from mail-ej1-x641.google.com (mail-ej1-x641.google.com [IPv6:2a00:1450:4864:20::641]) (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 611AC14013AF for ; Fri, 4 Dec 2020 10:59:35 +0100 (CET) Received: by mail-ej1-x641.google.com with SMTP id x16so7807407ejj.7 for ; Fri, 04 Dec 2020 01:59:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QXZHyPaSlC+12ckoS2mFp61ukEvnW8eXh9ddEyd63lQ=; b=ufqteL/VgAFkGHPX+TU2iuDuyHuaVEVrC4WmrcO2B5MdEu9sLvBnTxNma6NMtliHdy 4GTMkD0l4Xr0n+O9NH2F1tqh+Dec/iWVtZpWy2XKUp0eGNXNCAsDjFUJ6kHDUz/vNeTe //mMOmIF/PFcuz48ndO/CdlFj6qS/WEXk/6uEOFVlbC8wCBs1737rWQlyakl9l2s8HN0 B2dHQIXCL0xZjYExvcZXUJH8uqgg9cjz4jaryFQSdE7ZW3O77gbNIQP0S8hd5o0FNTrw eDVdu9KyOvHMGTtHtUWuY/VEcJDTObDvxVJa17YHGz7oTBt05zORz8ia3ULBISo8/P9I wUMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QXZHyPaSlC+12ckoS2mFp61ukEvnW8eXh9ddEyd63lQ=; b=rRCSrso1ZaXobd7XnzaUGZXLH1JO2RgEHUYdEw1GGIUB9uuTGLkA1bxGIyhX9Gk0/F YZdxMYL6tZ1Yq/L9nlZXbUn+Rplre76H9rLoQa7EVyf6HQpNt/wokpiUEyayCMCARegU pnA3z6/GhiWqg0uaxPwP2i18yZFAE9VfECL0CLIjIpiNpnZZuZIQZzexbmcJ0ZEBlwjr +sfIY0oerPMimQir0Z5FdeI4fsy4JgTRVT9dzO7Wwn32TiWbbbUZZiqg9qvAsTYg5BYb +zglvQhrW0VoUsZuy6BKPr3zmBxoL4gvt1iC3b08MBzGIDrCddZvDNsaL2orBEa64IfW 4cTw== X-Gm-Message-State: AOAM531R3oFNEPHcYr1h/cwypqWtFJVw3Thn/E0OtrfoI1Qe3yHFQr18 T24xSlCYjfTckVdM/7PVjhJZTK5LqAQ= X-Google-Smtp-Source: ABdhPJwTzJAUUglhquFX7I8+a/hVIx8uS6FqpK/CzNgE1HgbJfh/kWSHx+Zzk8PPgBgxwNckC2plgA== X-Received: by 2002:a17:906:3187:: with SMTP id 7mr6368281ejy.225.1607075974987; Fri, 04 Dec 2020 01:59:34 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id qp16sm2701811ejb.74.2020.12.04.01.59.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 01:59:34 -0800 (PST) From: Amir Goldstein To: Petr Vorel Date: Fri, 4 Dec 2020 11:59:26 +0200 Message-Id: <20201204095930.866421-2-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204095930.866421-1-amir73il@gmail.com> References: <20201204095930.866421-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 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 1/5] syscalls/fanotify: Generalize check for FAN_REPORT_FID support 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: Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Generalize the helpers to be able to check any fanotify_init() flags and pass FAN_REPORT_FID as argument in call sites. Add helper fanotify_init_flags_supported_by_kernel() to check for kernel support for fanotify_init flags without checking fs support for those flags. Signed-off-by: Amir Goldstein Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- testcases/kernel/syscalls/fanotify/fanotify.h | 46 ++++++++++++------- .../kernel/syscalls/fanotify/fanotify01.c | 4 +- .../kernel/syscalls/fanotify/fanotify13.c | 2 +- .../kernel/syscalls/fanotify/fanotify15.c | 2 +- .../kernel/syscalls/fanotify/fanotify16.c | 2 +- 5 files changed, 34 insertions(+), 22 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 82e03db26..8907db052 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -286,15 +286,15 @@ static inline int fanotify_events_supported_by_kernel(uint64_t mask) /* * @return 0: fanotify supported both in kernel and on tested filesystem - * @return -1: FAN_REPORT_FID not supported in kernel - * @return -2: FAN_REPORT_FID not supported on tested filesystem + * @return -1: @flags not supported in kernel + * @return -2: @flags not supported on tested filesystem (tested if @fname is not NULL) */ -static inline int fanotify_fan_report_fid_supported_on_fs(const char *fname) +static inline int fanotify_init_flags_supported_on_fs(unsigned int flags, const char *fname) { int fd; int rval = 0; - fd = fanotify_init(FAN_CLASS_NOTIF | FAN_REPORT_FID, O_RDONLY); + fd = fanotify_init(flags, O_RDONLY); if (fd < 0) { if (errno == ENOSYS) @@ -306,7 +306,7 @@ static inline int fanotify_fan_report_fid_supported_on_fs(const char *fname) tst_brk(TBROK | TERRNO, "fanotify_init() failed"); } - if (fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) { + if (fname && fanotify_mark(fd, FAN_MARK_ADD, FAN_ACCESS, AT_FDCWD, fname) < 0) { if (errno == ENODEV || errno == EOPNOTSUPP || errno == EXDEV) { rval = -2; } else { @@ -321,20 +321,32 @@ static inline int fanotify_fan_report_fid_supported_on_fs(const char *fname) return rval; } -#define FANOTIFY_FAN_REPORT_FID_ERR_MSG_(res_func, fail) do { \ - if (fail == -1) \ - res_func(TCONF, "FAN_REPORT_FID not supported in kernel?"); \ - if (fail == -2) \ - res_func(TCONF, "FAN_REPORT_FID not supported on %s filesystem", \ - tst_device->fs_type); \ - } while (0) +static inline int fanotify_init_flags_supported_by_kernel(unsigned int flags) +{ + return fanotify_init_flags_supported_on_fs(flags, NULL); +} + +typedef void (*tst_res_func_t)(const char *file, const int lineno, + int ttype, const char *fmt, ...); + +static inline void fanotify_init_flags_err_msg(const char *flags_str, + const char *file, const int lineno, tst_res_func_t res_func, int fail) +{ + if (fail == -1) + res_func(file, lineno, TCONF, + "%s not supported in kernel?", flags_str); + if (fail == -2) + res_func(file, lineno, TCONF, + "%s not supported on %s filesystem", + flags_str, tst_device->fs_type); +} -#define FANOTIFY_FAN_REPORT_FID_ERR_MSG(fail) \ - FANOTIFY_FAN_REPORT_FID_ERR_MSG_(tst_res, (fail)) +#define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \ + fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_res_, (fail)) -#define REQUIRE_FANOTIFY_FAN_REPORT_FID_SUPPORTED_ON_FS(fname) do { \ - FANOTIFY_FAN_REPORT_FID_ERR_MSG_(tst_brk, \ - fanotify_fan_report_fid_supported_on_fs(fname)); \ +#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(flags, fname) do { \ + fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \ + fanotify_init_flags_supported_on_fs(flags, fname)); \ } while (0) static inline int fanotify_mark_supported_by_kernel(uint64_t flag) diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c index d6d72dad9..cdb01730f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify01.c +++ b/testcases/kernel/syscalls/fanotify/fanotify01.c @@ -90,7 +90,7 @@ static void test_fanotify(unsigned int n) tst_res(TINFO, "Test #%d: %s", n, tc->tname); if (fan_report_fid_unsupported && (tc->init_flags & FAN_REPORT_FID)) { - FANOTIFY_FAN_REPORT_FID_ERR_MSG(fan_report_fid_unsupported); + FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_FID, fan_report_fid_unsupported); return; } @@ -334,7 +334,7 @@ static void setup(void) sprintf(fname, MOUNT_PATH"/tfile_%d", getpid()); SAFE_FILE_PRINTF(fname, "1"); - fan_report_fid_unsupported = fanotify_fan_report_fid_supported_on_fs(fname); + fan_report_fid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_FID, fname); filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM); } diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c index a402cdb13..c9cf10555 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify13.c +++ b/testcases/kernel/syscalls/fanotify/fanotify13.c @@ -256,7 +256,7 @@ out: static void do_setup(void) { - REQUIRE_FANOTIFY_FAN_REPORT_FID_SUPPORTED_ON_FS(MOUNT_PATH); + REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, MOUNT_PATH); filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM); diff --git a/testcases/kernel/syscalls/fanotify/fanotify15.c b/testcases/kernel/syscalls/fanotify/fanotify15.c index 9e3748bc2..ba8259c7c 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify15.c +++ b/testcases/kernel/syscalls/fanotify/fanotify15.c @@ -270,7 +270,7 @@ static void do_test(unsigned int number) static void do_setup(void) { SAFE_MKDIR(TEST_DIR, 0755); - REQUIRE_FANOTIFY_FAN_REPORT_FID_SUPPORTED_ON_FS(TEST_DIR); + REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, TEST_DIR); fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_FID, O_RDONLY); } diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index a554c7d39..a4409df14 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -551,7 +551,7 @@ check_match: static void setup(void) { - REQUIRE_FANOTIFY_FAN_REPORT_FID_SUPPORTED_ON_FS(MOUNT_PATH); + REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, MOUNT_PATH); sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1); sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2); From patchwork Fri Dec 4 09:59:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1410933 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: 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=20161025 header.b=sN9rGRSC; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CnSqf49lGz9sWw for ; Fri, 4 Dec 2020 20:59:58 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EDFC93C4C06 for ; Fri, 4 Dec 2020 10:59:55 +0100 (CET) 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 [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 29D193C4C0E for ; Fri, 4 Dec 2020 10:59:37 +0100 (CET) Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) (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 BB23C1400744 for ; Fri, 4 Dec 2020 10:59:36 +0100 (CET) Received: by mail-ej1-x644.google.com with SMTP id d17so7794436ejy.9 for ; Fri, 04 Dec 2020 01:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z68jG772eca5ubxG6/Rd8Cmcjn6oSanfclulof/5ulI=; b=sN9rGRSCg7jaKrSAB4ulAw41DaC5Kekns3vVMwwuEMBAVo//AcAo9CgW32CFW5539L ZYN7DxqiinYpLHpJsODZXVgyT6QwwQYea1ZSuBcJoE+WeVkS9IVdGf88eT407G0TtXx/ DssQvQ8cm37Fsz3k6qKY9htjBDXAGb3I/uxZdQC9dlJkGeOuDWseT8KrcdHDnl4q6qDN FlaK37xRF3zQlqnvfsuWJIChfytC64En5wj7gyf8uPkxP+/31F8hSgJHG+2dVfz4TIcd 1YrI3xhIhKn0S/tbCkLnFXbgFuB5FAF5wJKHKXFoCROIXN6WOyAeWIC0V8MKt23bNust ZmgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z68jG772eca5ubxG6/Rd8Cmcjn6oSanfclulof/5ulI=; b=e7JpTozLmAlDsM7wpVR1xuM4a5ttfre7G+T4XvBJNQhihuC+C1aPsnxHqPOpzM9eVM doEcVEhmGy4LJM4cGIy6dZX8BQxcrnAxxXxXKo6d0TPqmk/tTlwyhZBQwSrNvfmP5DBH ikIFyPOPQJJCjmXJ5dOnp/VTAwnvXXfnn0SDnGAu7fMM4tqvL+fuzSKvNATYu7ptGhiP LADNB3W4UTXfSBEjFW4AbCzLWLIw3QFyd9b2JxdqdXUxOHaveGRoRyoEWKQhvEzmQLz8 x+LnXt7npdZHi6Ajqb26XKIYlKdcxi+zOqHz98qGIMGOiNgJ0V1gcFpYo+L7jh5tsC14 s2bQ== X-Gm-Message-State: AOAM532jFc4tTwr/rYMhDHkOFm58gANhI/L9di0VJbzsT+E8BJbBhzrp Jv4Lf0sYSDCO77IYWRXUnQ0MT/XqGTU= X-Google-Smtp-Source: ABdhPJz5xHjWqyVJy5KFvNgMp3smUWXHU6jdaedctwS939I7KN3EzwJ8N4XWvhJJRiuyJT4UBN8rGA== X-Received: by 2002:a17:906:b0d8:: with SMTP id bk24mr6261251ejb.113.1607075976351; Fri, 04 Dec 2020 01:59:36 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id qp16sm2701811ejb.74.2020.12.04.01.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 01:59:35 -0800 (PST) From: Amir Goldstein To: Petr Vorel Date: Fri, 4 Dec 2020 11:59:27 +0200 Message-Id: <20201204095930.866421-3-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204095930.866421-1-amir73il@gmail.com> References: <20201204095930.866421-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 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 2/5] syscalls/fanotify: Use generic checks for fanotify_init flags 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: Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Convert remaining tests to SAFE_FANOTIFY_INIT and use the generic helpers to check requires kernel/fs support for fanotify_init flags in advance. Signed-off-by: Amir Goldstein Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify10.c | 26 ++++++++----------- .../kernel/syscalls/fanotify/fanotify11.c | 21 ++++++--------- .../kernel/syscalls/fanotify/fanotify16.c | 14 ++-------- 3 files changed, 21 insertions(+), 40 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c index 404e57daa..cc164359f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify10.c +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c @@ -57,6 +57,7 @@ static unsigned int fanotify_class[] = { FAN_REPORT_DFID_NAME_FID, }; #define NUM_CLASSES ARRAY_SIZE(fanotify_class) +#define NUM_PRIORITIES 3 #define GROUPS_PER_PRIO 3 @@ -64,6 +65,7 @@ static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO]; static char event_buf[EVENT_BUF_LEN]; static int exec_events_unsupported; +static int fan_report_dfid_unsupported; static int filesystem_mark_unsupported; #define MOUNT_PATH "fs_mnt" @@ -294,21 +296,8 @@ static int create_fanotify_groups(unsigned int n) for (p = 0; p < num_classes; p++) { for (i = 0; i < GROUPS_PER_PRIO; i++) { - fd_notify[p][i] = fanotify_init(fanotify_class[p] | - FAN_NONBLOCK, O_RDONLY); - if (fd_notify[p][i] == -1) { - if (errno == EINVAL && - fanotify_class[p] & FAN_REPORT_NAME) { - tst_res(TCONF, - "FAN_REPORT_NAME not supported by kernel?"); - /* Do not try creating this group again */ - num_classes--; - return -1; - } - - tst_brk(TBROK | TERRNO, - "fanotify_init(%x, 0) failed", fanotify_class[p]); - } + fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_class[p] | + FAN_NONBLOCK, O_RDONLY); /* * Add mark for each group. @@ -518,6 +507,13 @@ static void setup(void) { exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC); filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM); + fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME, + MOUNT_PATH); + if (fan_report_dfid_unsupported) { + FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_DFID_NAME, fan_report_dfid_unsupported); + /* Limit tests to legacy priority classes */ + num_classes = NUM_PRIORITIES; + } /* Create another bind mount at another path for generating events */ SAFE_MKDIR(MNT2_PATH, 0755); diff --git a/testcases/kernel/syscalls/fanotify/fanotify11.c b/testcases/kernel/syscalls/fanotify/fanotify11.c index 785b5c5a5..f3b60cecb 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify11.c +++ b/testcases/kernel/syscalls/fanotify/fanotify11.c @@ -36,6 +36,8 @@ #define gettid() syscall(SYS_gettid) static int tid; +static int fan_report_tid_unsupported; + void *thread_create_file(void *arg LTP_ATTRIBUTE_UNUSED) { char tid_file[64] = {0}; @@ -63,17 +65,13 @@ void test01(unsigned int i) i, (tcases[i] & FAN_REPORT_TID) ? "with" : "without", tgid, tid, event.pid); - fd_notify = fanotify_init(tcases[i], 0); - if (fd_notify < 0) { - if (errno == EINVAL && (tcases[i] & FAN_REPORT_TID)) { - tst_res(TCONF, - "FAN_REPORT_TID not supported in kernel?"); - return; - } - tst_brk(TBROK | TERRNO, "fanotify_init(0x%x, 0) failed", - tcases[i]); + if (fan_report_tid_unsupported && (tcases[i] & FAN_REPORT_TID)) { + FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_TID, fan_report_tid_unsupported); + return; } + fd_notify = SAFE_FANOTIFY_INIT(tcases[i], 0); + SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD, FAN_ALL_EVENTS | FAN_EVENT_ON_CHILD, AT_FDCWD, "."); @@ -96,10 +94,7 @@ void test01(unsigned int i) static void setup(void) { - int fd; - - fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY); - SAFE_CLOSE(fd); + fan_report_tid_unsupported = fanotify_init_flags_supported_by_kernel(FAN_REPORT_TID); } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index a4409df14..5ffaec92f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -158,17 +158,7 @@ static void do_test(unsigned int number) tst_res(TINFO, "Test #%d: %s", number, tc->tname); - fd_notify = fanotify_init(group->flag, 0); - if (fd_notify == -1) { - if (errno == EINVAL) { - tst_res(TCONF, - "%s not supported by kernel", group->name); - return; - } - - tst_brk(TBROK | TERRNO, - "fanotify_init(%s, 0) failed", group->name); - } + fd_notify = SAFE_FANOTIFY_INIT(group->flag, 0); /* * Watch dir modify events with name in filesystem/dir @@ -551,7 +541,7 @@ check_match: static void setup(void) { - REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, MOUNT_PATH); + REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_DIR_FID, MOUNT_PATH); sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1); sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2); From patchwork Fri Dec 4 09:59:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1410934 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: 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=20161025 header.b=WCIW49Xj; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CnSqr2jqTz9sWq for ; Fri, 4 Dec 2020 21:00:08 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BFBC13C5367 for ; Fri, 4 Dec 2020 11:00:04 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id 735413C58E9 for ; Fri, 4 Dec 2020 10:59:38 +0100 (CET) Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id 1A2FD600708 for ; Fri, 4 Dec 2020 10:59:38 +0100 (CET) Received: by mail-ed1-x542.google.com with SMTP id b2so5203996edm.3 for ; Fri, 04 Dec 2020 01:59:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=txVBk56tO2gFllxzb8d5qhXnXnp0Q96rIqcLEaPRzUE=; b=WCIW49XjIHQxy5BFnxhDqgggbXFjm5mjJIkLd6YhETpuYkkVCx5N2EO2La+vfOjHHf ILBrMgeuJTCrNernHmlqslChk2CHVekBzroUaCQD/8KP1RZlvXyqz6XgoWjpfgSn1y2k i9xw2GH0EcN97K5UN6QQTx0X5lHTFiDX1dRQ9Aa2QvvaxHo4XhPNI6AtoAqtmo6Vj4GB iz4OEaLLVKABq07Dp9rfiDhchdgKOb0cCtBkC22afZ4vZ9AR1ajbJI52lnlObwwSTp30 eF4GXzSbIa0xRSPa2CCalIR+TYuXuHu0G7tw7vI1JrtSE7oZ3VieAHUM45YMESxOXORB smNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=txVBk56tO2gFllxzb8d5qhXnXnp0Q96rIqcLEaPRzUE=; b=cv7uWi03rjJcTjKAZFrpHlNM3uQu6sjmrwRF2HpxfUe9yAh6X+rSwHVOr+j654+J/o 5JWmsTtjfxJJTXS0tw9Yd//mg/t9XM9/xi3u1rmgaHUBEe/6cHZafdiV6z1K64IsV4a+ jM9A+iI3EZzoI3Ho1rlDzIMGwXt0u5Ai+DEMapSRSdJmVc0Pd9ML7Y223Qrds9SSM8VR 827w2M9pVzstoNJ0p/N8oeDlRN6IyL+FE+0WgnB1c8imEZLyA9F2HsV+svo6NIfx3MII bF3YkhbUhTmOMaGvu+EEQy1t7tgr4gJ+x+b4sgfNRal/SNxoGlfy2LuUXKkGHtJ8ZKvP ZoQw== X-Gm-Message-State: AOAM533ZCu+ZZFEgq2QRStBAZ9+F8igNAYatN5Tz14Y5cKmfLGv99Sod 21tFfE0iqASjlQY6KI2eQxU= X-Google-Smtp-Source: ABdhPJyL1rUYtOInN0sxnoZZKHHl4+8RjXoDp1ibePwgoN7ml+t+MySuQhfQZ4OVi7JbNwCE43Z6wA== X-Received: by 2002:aa7:cc8f:: with SMTP id p15mr6629835edt.240.1607075977709; Fri, 04 Dec 2020 01:59:37 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id qp16sm2701811ejb.74.2020.12.04.01.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 01:59:37 -0800 (PST) From: Amir Goldstein To: Petr Vorel Date: Fri, 4 Dec 2020 11:59:28 +0200 Message-Id: <20201204095930.866421-4-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204095930.866421-1-amir73il@gmail.com> References: <20201204095930.866421-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH 3/5] syscalls/fanotify09: Read variable length events 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: Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" In preparation of testing events with filename info, teach the how to read variable length events and parse the name info. Signed-off-by: Amir Goldstein Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 88 +++++++++++++------ 1 file changed, 60 insertions(+), 28 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index daeb712d2..7bb901cf3 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -138,42 +138,73 @@ static void cleanup_fanotify_groups(void) } static void event_res(int ttype, int group, - struct fanotify_event_metadata *event) + struct fanotify_event_metadata *event, + const char *filename) { - int len; - sprintf(symlnk, "/proc/self/fd/%d", event->fd); - len = readlink(symlnk, fdpath, sizeof(fdpath)); - if (len < 0) - len = 0; - fdpath[len] = 0; - tst_res(ttype, "group %d got event: mask %llx pid=%u fd=%d path=%s", + if (event->fd != FAN_NOFD) { + int len = 0; + sprintf(symlnk, "/proc/self/fd/%d", event->fd); + len = readlink(symlnk, fdpath, sizeof(fdpath)); + if (len < 0) + len = 0; + fdpath[len] = 0; + filename = fdpath; + } + tst_res(ttype, "group %d got event: mask %llx pid=%u fd=%d filename=%s", group, (unsigned long long)event->mask, - (unsigned)event->pid, event->fd, fdpath); + (unsigned)event->pid, event->fd, filename); +} + +static const char *event_filename(struct fanotify_event_metadata *event) +{ + struct fanotify_event_info_fid *event_fid; + struct file_handle *file_handle; + const char *filename, *end; + + if (event->event_len <= FAN_EVENT_METADATA_LEN) + return ""; + + event_fid = (struct fanotify_event_info_fid *)(event + 1); + file_handle = (struct file_handle *)event_fid->handle; + filename = (char *)file_handle->f_handle + file_handle->handle_bytes; + end = (char *)event_fid + event_fid->hdr.len; + + /* End of event_fid could have name, zero padding, both or none */ + return (filename == end) ? "" : filename; } static void verify_event(int group, struct fanotify_event_metadata *event, - uint32_t expect) + uint32_t expect, const char *expect_filename) { + const char *filename = event_filename(event); + if (event->mask != expect) { tst_res(TFAIL, "group %d got event: mask %llx (expected %llx) " - "pid=%u fd=%d", group, (unsigned long long)event->mask, + "pid=%u fd=%d filename=%s", group, (unsigned long long)event->mask, (unsigned long long)expect, - (unsigned)event->pid, event->fd); + (unsigned)event->pid, event->fd, filename); } else if (event->pid != getpid()) { tst_res(TFAIL, "group %d got event: mask %llx pid=%u " - "(expected %u) fd=%d", group, + "(expected %u) fd=%d filename=%s", group, (unsigned long long)event->mask, (unsigned)event->pid, - (unsigned)getpid(), event->fd); + (unsigned)getpid(), event->fd, filename); + } else if (strcmp(filename, expect_filename)) { + tst_res(TFAIL, "group %d got event: mask %llx pid=%u " + "fd=%d filename='%s' (expected '%s')", group, + (unsigned long long)event->mask, (unsigned)event->pid, + event->fd, filename, expect_filename); } else { - event_res(TPASS, group, event); + event_res(TPASS, group, event, filename); } + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); } static void test_fanotify(unsigned int n) { int ret, dirfd; unsigned int i; - struct fanotify_event_metadata *event, *ev; + struct fanotify_event_metadata *event; struct tcase *tc = &tcases[n]; tst_res(TINFO, "Test #%d: %s", n, tc->tname); @@ -210,20 +241,21 @@ static void test_fanotify(unsigned int n) ret, tc->nevents * (int)FAN_EVENT_METADATA_LEN); } event = (struct fanotify_event_metadata *)event_buf; - verify_event(0, event, FAN_MODIFY); - if (tc->ondir) - verify_event(0, event + 1, FAN_CLOSE_NOWRITE); - if (ret > tc->nevents * (int)FAN_EVENT_METADATA_LEN) { + verify_event(0, event, FAN_MODIFY, ""); + event = FAN_EVENT_NEXT(event, ret); + if (tc->ondir) { + verify_event(0, event, FAN_CLOSE_NOWRITE, ""); + event = FAN_EVENT_NEXT(event, ret); + } + if (ret > 0) { tst_res(TFAIL, - "first group got more than %d events (%d > %d)", - tc->nevents, ret, - tc->nevents * (int)FAN_EVENT_METADATA_LEN); + "first group got more than %d events (%d bytes)", + tc->nevents, ret); } /* Close all file descriptors of read events */ - for (ev = event; ret >= (int)FAN_EVENT_METADATA_LEN; ev++) { - if (ev->fd != FAN_NOFD) - SAFE_CLOSE(ev->fd); - ret -= (int)FAN_EVENT_METADATA_LEN; + for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) { + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); } /* @@ -233,7 +265,7 @@ static void test_fanotify(unsigned int n) for (i = 1; i < NUM_GROUPS; i++) { ret = read(fd_notify[i], event_buf, FAN_EVENT_METADATA_LEN); if (ret > 0) { - event_res(TFAIL, i, event); + event_res(TFAIL, i, event, ""); if (event->fd != FAN_NOFD) SAFE_CLOSE(event->fd); continue; From patchwork Fri Dec 4 09:59:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1410935 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: 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=20161025 header.b=n5Sqku2e; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CnSr335PTz9sWq for ; Fri, 4 Dec 2020 21:00:19 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 00A663C58EB for ; Fri, 4 Dec 2020 11:00:17 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id 4C4753C6329 for ; Fri, 4 Dec 2020 10:59:39 +0100 (CET) Received: from mail-ej1-x642.google.com (mail-ej1-x642.google.com [IPv6:2a00:1450:4864:20::642]) (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 704B210011A0 for ; Fri, 4 Dec 2020 10:59:39 +0100 (CET) Received: by mail-ej1-x642.google.com with SMTP id n26so7820233eju.6 for ; Fri, 04 Dec 2020 01:59:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6YM/jk+yHn1iKSieqhtotMht3S5NyPNM+ANvhTKQrMY=; b=n5Sqku2eVbHvjjw7TE5MO74Ch3h9KxImDFVfxDSFzcnH5g5WDLPC1Eg0yUhhyC6KVM u+lS2Mia7K3rAjEBl6Wq7W4Dytt+3Heu3BI5kNMBFpf1FOIr6K5WPUXH74zHbNUoKbFg rjv+jZu7oB5jDBOzpFAFM9KufRZGcT7lbjDAuetEHtRXKzVSaLetp3hCzYXKjOqWBFoI lcRRD42oYbf3Cs0Cl4Hjo8RocuOd3N3r6rD8+ybQkqxOLqJYNTOeY2HigpvvakMUsUdr O9ljqMrB6XG/uemK8mbPmhZ+uZDrvFUf6Szw/pX8/pOOJmqC5M1XSEywNvLvWfE1EbTP 95Ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6YM/jk+yHn1iKSieqhtotMht3S5NyPNM+ANvhTKQrMY=; b=mvK3fjNF550u1XL9JRScqIGoWWygo3QMfVNDK9uvMLUNJMyQgh/KtG5mHfl+V7h9+1 RFpP9crvK8i0Kycza7sESH0/jzucInIa8iJitPH7T7iinvSIoL07oVuRzlcSm8Uiytt1 OB4qF9szcYN+Ju/cXdDd+a4jj3B0PnkoyGmrZACmVooNqIFuGH8twBDMOJ+pWTSY+NBH RDsK5QVckihWsbEZJQSUHhF+s7HBBLOZtzUVk6B1tFpvoUM/QsnSASmYW50hScUEo0XZ y28Lfm+n3N15WMMRGw9tYg054yhk+WFN5TUpk441+1JLk4q4ysv1iR75Vn3UMYklTX0z SEwQ== X-Gm-Message-State: AOAM530g+PO9esnVXNbvVA3qiy4tj/R5VaqIIsXVPiGq4wHIURQjmaV7 kiDvHneMt6v5itZstcOsWcZaLzudo1A= X-Google-Smtp-Source: ABdhPJzbQ5qBu6hHmVOfMnRiVM2rIyhb1rCPU3X/wsRwuM5A44m34HN0haPY+VpKotPQgKy443XXgg== X-Received: by 2002:a17:907:3e17:: with SMTP id hp23mr6223965ejc.545.1607075979027; Fri, 04 Dec 2020 01:59:39 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id qp16sm2701811ejb.74.2020.12.04.01.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 01:59:38 -0800 (PST) From: Amir Goldstein To: Petr Vorel Date: Fri, 4 Dec 2020 11:59:29 +0200 Message-Id: <20201204095930.866421-5-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204095930.866421-1-amir73il@gmail.com> References: <20201204095930.866421-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 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/5] syscalls/fanotify09: Add test case with two non-dir children 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: Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The existing test cases generate FAN_MODIFY event on a non-dir child and FAN_CLOSE_NOWRITE event the parent or sibling subdir. Add a test case that generates FAN_CLOSE_NOWRITE on a sibling non-dir child. Signed-off-by: Amir Goldstein Reviewed-by: Petr Vorel Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index 7bb901cf3..0f1923981 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -55,13 +55,14 @@ static char event_buf[EVENT_BUF_LEN]; #define MOUNT_NAME "mntpoint" #define DIR_NAME "testdir" +#define FILE2_NAME "testfile" static int mount_created; static struct tcase { const char *tname; struct fanotify_mark_type mark; unsigned int ondir; - const char *testdir; + const char *close_nowrite; int nevents; } tcases[] = { { @@ -92,6 +93,13 @@ static struct tcase { DIR_NAME, 2, }, + { + "Events on non-dir children with both parent and mount marks", + INIT_FANOTIFY_MARK_TYPE(MOUNT), + 0, + FILE2_NAME, + 2, + }, }; static void create_fanotify_groups(struct tcase *tc) @@ -112,7 +120,7 @@ static void create_fanotify_groups(struct tcase *tc) SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD | mark->flag, FAN_CLOSE_NOWRITE | onchild, - AT_FDCWD, tc->testdir); + AT_FDCWD, tc->close_nowrite); /* * Add inode mark on parent for each group with MODIFY event, @@ -216,9 +224,9 @@ static void test_fanotify(unsigned int n) */ SAFE_FILE_PRINTF(fname, "1"); /* - * generate FAN_CLOSE_NOWRITE event on a testdir (subdir or ".") + * generate FAN_CLOSE_NOWRITE event on a child, subdir or "." */ - dirfd = SAFE_OPEN(tc->testdir, O_RDONLY); + dirfd = SAFE_OPEN(tc->close_nowrite, O_RDONLY); if (dirfd >= 0) SAFE_CLOSE(dirfd); @@ -243,7 +251,7 @@ static void test_fanotify(unsigned int n) event = (struct fanotify_event_metadata *)event_buf; verify_event(0, event, FAN_MODIFY, ""); event = FAN_EVENT_NEXT(event, ret); - if (tc->ondir) { + if (tc->nevents > 1) { verify_event(0, event, FAN_CLOSE_NOWRITE, ""); event = FAN_EVENT_NEXT(event, ret); } @@ -260,14 +268,23 @@ static void test_fanotify(unsigned int n) /* * Then verify the rest of the groups did not get the MODIFY event and - * did not get the FAN_CLOSE_NOWRITE event on testdir. + * got the FAN_CLOSE_NOWRITE event only on a non-directory. */ for (i = 1; i < NUM_GROUPS; i++) { - ret = read(fd_notify[i], event_buf, FAN_EVENT_METADATA_LEN); + ret = read(fd_notify[i], event_buf, EVENT_BUF_LEN); if (ret > 0) { - event_res(TFAIL, i, event, ""); - if (event->fd != FAN_NOFD) - SAFE_CLOSE(event->fd); + 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, ""); + + for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) { + if (event->fd != FAN_NOFD) + SAFE_CLOSE(event->fd); + } continue; } @@ -295,6 +312,7 @@ static void setup(void) sprintf(fname, "tfile_%d", getpid()); SAFE_FILE_PRINTF(fname, "1"); + SAFE_FILE_PRINTF(FILE2_NAME, "1"); } static void cleanup(void) From patchwork Fri Dec 4 09:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1410936 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: 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=20161025 header.b=GLM41Doh; 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 RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CnSrF0mTPz9sWq for ; Fri, 4 Dec 2020 21:00:28 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5C85A3C58F3 for ; Fri, 4 Dec 2020 11:00:26 +0100 (CET) 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]) by picard.linux.it (Postfix) with ESMTP id 245E53C58E9 for ; Fri, 4 Dec 2020 10:59:41 +0100 (CET) Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) (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-7.smtp.seeweb.it (Postfix) with ESMTPS id CD888200FD5 for ; Fri, 4 Dec 2020 10:59:40 +0100 (CET) Received: by mail-ej1-x643.google.com with SMTP id n26so7820340eju.6 for ; Fri, 04 Dec 2020 01:59:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=svSO34I/VfcgIbgCom3JarBphso/yZTKpYYNjygr4Gg=; b=GLM41DohrSX9aq6Ujysl0uOsDF9dRbKGsVYBwJwAlBUg4FBgtlB2NsQhsf9vuiDvSv dtxYJY5Y4q5okD4xKKqlsVwR2kgh6VE6A/VuOLNK04y7VrxJQB2jCI6qcNPMrJypEh4q pWzoPgs06pY3FhTbnkR6OG7RAYtO4bHM4XIuER6Wr23inPn9PtAlSkAaYJBGbX1hV5/3 1/9uZm1Hq5LduwBkkR+u8jR61hXHq7+QuizfA5KdX7fPHGXf078QoNZNPP/imGyUeiUo r8VAhAaAw8/Kn1zt5EpJDKvEH48boDmCmA5XKWZra9YjZhONrlngugcXl0gK6wO79Njp tvMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=svSO34I/VfcgIbgCom3JarBphso/yZTKpYYNjygr4Gg=; b=QlrCYhdQZk9XIfANolFadppJG+1k+4b4a8NEO4qzLRYXaQw9zP6SGz08x6GoG9l1VO kwOX8goau0YxSSh6jKWZAjzwjvOATpFnnJSn8hVWfQzLycwspPjqzOCnUdzRWYNv8OMK dalfjcwCUb9JioGNN6rI/0+K0CzrP5NlqH0KSCQPNA4tqRHkTT4YdOHpxL92ij/ssa6b vBvbnNH1VrDQ46LnleLlPWh5xuj/WeW7fWi2sVY2nt54Mfx29nMFw4qmglwxgPqQoM9I waXTA+awNFVAs9lvenIz6QKmqnlutLQN+qAKHA3B931MXpIUEELa7tygbtGBH9SB37dV r36Q== X-Gm-Message-State: AOAM533mm/UHFkFnDFReffE7FykRctc2JyKGEiSaepmCZTkOCso4gXmL 6WwvvQdZSrv0mhHPgsTVSebEeDKu0UM= X-Google-Smtp-Source: ABdhPJy58ermqKF20LBPLWRMA4vCNpYfb/GL3g8Y5DC9NXWIe5CHw1v5VY6sqPrxO1HKtuPM8qbu5Q== X-Received: by 2002:a17:906:17d1:: with SMTP id u17mr6199854eje.6.1607075980442; Fri, 04 Dec 2020 01:59:40 -0800 (PST) Received: from localhost.localdomain ([31.210.181.203]) by smtp.gmail.com with ESMTPSA id qp16sm2701811ejb.74.2020.12.04.01.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2020 01:59:39 -0800 (PST) From: Amir Goldstein To: Petr Vorel Date: Fri, 4 Dec 2020 11:59:30 +0200 Message-Id: <20201204095930.866421-6-amir73il@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201204095930.866421-1-amir73il@gmail.com> References: <20201204095930.866421-1-amir73il@gmail.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 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,FREEMAIL_FROM,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH 5/5] syscalls/fanotify09: Add test case for events with filename info 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: Jan Kara , ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Kernel v5.9 has a bug when there is a mark on filesystem or mount interested in events with filename AND there is an additional mark on a parent watching children. In some situations the event is reported to filesystem or mount mark without the filename info. This bug is fixed by kernel commit 7372e79c9eb9: fanotify: fix logic of reporting name info with watched parent The test case requires a blockdev filesystem. Signed-off-by: Amir Goldstein Reviewed-by: Jan Kara --- .../kernel/syscalls/fanotify/fanotify09.c | 49 ++++++++++++++++--- 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index 0f1923981..25b6b8be1 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -19,6 +19,10 @@ * Test case #2 is a regression test for commit 55bf882c7f13: * * fanotify: fix merging marks masks with FAN_ONDIR + * + * Test case #5 is a regression test for commit 7372e79c9eb9: + * + * fanotify: fix logic of reporting name info with watched parent */ #define _GNU_SOURCE #include "config.h" @@ -53,15 +57,19 @@ static int fd_notify[NUM_GROUPS]; static char event_buf[EVENT_BUF_LEN]; +#define MOUNT_PATH "fs_mnt" #define MOUNT_NAME "mntpoint" #define DIR_NAME "testdir" #define FILE2_NAME "testfile" static int mount_created; +static int fan_report_dfid_unsupported; + static struct tcase { const char *tname; struct fanotify_mark_type mark; unsigned int ondir; + unsigned int report_name; const char *close_nowrite; int nevents; } tcases[] = { @@ -69,6 +77,7 @@ static struct tcase { "Events on non-dir child with both parent and mount marks", INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, + 0, DIR_NAME, 1, }, @@ -76,6 +85,7 @@ static struct tcase { "Events on non-dir child and subdir with both parent and mount marks", INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, + 0, DIR_NAME, 2, }, @@ -83,6 +93,7 @@ static struct tcase { "Events on non-dir child and parent with both parent and mount marks", INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, + 0, ".", 2, }, @@ -90,6 +101,7 @@ static struct tcase { "Events on non-dir child and subdir with both parent and subdir marks", INIT_FANOTIFY_MARK_TYPE(INODE), FAN_ONDIR, + 0, DIR_NAME, 2, }, @@ -97,6 +109,15 @@ static struct tcase { "Events on non-dir children with both parent and mount marks", INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, + 0, + FILE2_NAME, + 2, + }, + { + "Events on non-dir child with both parent and mount marks and filename info", + INIT_FANOTIFY_MARK_TYPE(MOUNT), + 0, + FAN_REPORT_DFID_NAME, FILE2_NAME, 2, }, @@ -105,12 +126,15 @@ static struct tcase { static void create_fanotify_groups(struct tcase *tc) { struct fanotify_mark_type *mark = &tc->mark; - unsigned int i, onchild, ondir = tc->ondir; + unsigned int i, onchild, report_name, ondir = tc->ondir; for (i = 0; i < NUM_GROUPS; i++) { - fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | - FAN_NONBLOCK, - O_RDONLY); + /* + * The first group may request events with filename info. + */ + report_name = (i == 0) ? tc->report_name : 0; + fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | report_name | + FAN_NONBLOCK, O_RDONLY); /* * Add subdir or mount mark for each group with CLOSE event, @@ -217,6 +241,11 @@ static void test_fanotify(unsigned int n) tst_res(TINFO, "Test #%d: %s", n, tc->tname); + if (fan_report_dfid_unsupported && tc->report_name) { + FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_DFID_NAME, fan_report_dfid_unsupported); + return; + } + create_fanotify_groups(tc); /* @@ -249,10 +278,11 @@ static void test_fanotify(unsigned int n) ret, tc->nevents * (int)FAN_EVENT_METADATA_LEN); } event = (struct fanotify_event_metadata *)event_buf; - verify_event(0, event, FAN_MODIFY, ""); + verify_event(0, event, FAN_MODIFY, tc->report_name ? fname : ""); event = FAN_EVENT_NEXT(event, ret); if (tc->nevents > 1) { - verify_event(0, event, FAN_CLOSE_NOWRITE, ""); + verify_event(0, event, FAN_CLOSE_NOWRITE, + tc->report_name ? (tc->ondir ? "." : tc->close_nowrite) : ""); event = FAN_EVENT_NEXT(event, ret); } if (ret > 0) { @@ -304,8 +334,11 @@ static void test_fanotify(unsigned int n) static void setup(void) { + fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME, + MOUNT_PATH); + SAFE_MKDIR(MOUNT_NAME, 0755); - SAFE_MOUNT(MOUNT_NAME, MOUNT_NAME, "none", MS_BIND, NULL); + SAFE_MOUNT(MOUNT_PATH, MOUNT_NAME, "none", MS_BIND, NULL); mount_created = 1; SAFE_CHDIR(MOUNT_NAME); SAFE_MKDIR(DIR_NAME, 0755); @@ -330,6 +363,8 @@ static struct tst_test test = { .tcnt = ARRAY_SIZE(tcases), .setup = setup, .cleanup = cleanup, + .mount_device = 1, + .mntpoint = MOUNT_PATH, .needs_tmpdir = 1, .needs_root = 1, .tags = (const struct tst_tag[]) {