From patchwork Wed Sep 9 17:56:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360874 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=l2kFQu/A; 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BmqVS6Mb3z9sTK for ; Thu, 10 Sep 2020 03:57:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 02B143C2C43 for ; Wed, 9 Sep 2020 19:57:28 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 6387F3C2C0E for ; Wed, 9 Sep 2020 19:57:17 +0200 (CEST) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 1602A60069A for ; Wed, 9 Sep 2020 19:57:17 +0200 (CEST) Received: by mail-wm1-x344.google.com with SMTP id a9so3289960wmm.2 for ; Wed, 09 Sep 2020 10:57:17 -0700 (PDT) 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; bh=hn6iynNog3DaPy2ZZP2uKebjDKV2A4Z7RruGPa2zsMk=; b=l2kFQu/AgDG/91SM12uCYPiXLr05NDHX+EdBRBsgJ1vOsctxl308YFt2l8AkqcDXb7 ue7UhSkXlKM1/NrrAC8vFd2hUfz3NhzTSPRxj3cZK0hJ0eq3YiomcTwsMgYn66T9H4p5 hofu9oI0U75Cqohdq6oUA0aZjjByCdDbzKjv2DVIss8kfj9BESex3amyipodH8k/3JUy Q4NRCeBNEIYXaW0QqQynvHLyuw41WlaafjhaCLawRUIvZzQ6BlqxN6aobrpb3rJMj3ku /ntxV+c1qsRN/PBL54yfSeGqJBVCC98SBJWjOmN5Y28Z8OUDP4q4mkuZp+bFBsJxlXrC d35Q== 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; bh=hn6iynNog3DaPy2ZZP2uKebjDKV2A4Z7RruGPa2zsMk=; b=AIaULm7lyPECDiHuT4P9F5jJ0ZLrKLVZy+wjwKuIuGVbtx5SciuUF1xMfn3zSOgrya 6IeR8oqHUSr0mLoXsxC1BPptmrGm7Q772A/Qq709FV9kMbaKA1kaUaan16yGMGxoizri mv781HXRMIOJvBymnkpRqVmsflbB5aMxc08/7bAykp+wEDDf2ikmVRXWRALSsTxtaRSO fZl1xblWO/+pSiDX5V1/fvcsAjpVYOrHtCd0ZvxChQFad4YIiwH2KyUkB+Wq4zIYkief aeLC/c3Ll26EUiRw59yA50kUAICi5ujQFgSLD+06G/Ap16fBaGAWJHTOnYzrxE4TKZiH Jc1Q== X-Gm-Message-State: AOAM532cX45rScvDYpo4oP4Jy4NdOEeuL4c9BpGs9vaB5GfLH6IvXyAt rt90hOO7T8/4n1gchpquiDI8wx35/Bk= X-Google-Smtp-Source: ABdhPJydigKpGztFJfX4kOQP39BZSYtiydWVRJgcNHyo5Dx+idIl2F69qF1KyefCmW/zhLp6lcs/iw== X-Received: by 2002:a7b:c84a:: with SMTP id c10mr4639792wml.139.1599674236679; Wed, 09 Sep 2020 10:57:16 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:16 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:56:58 +0300 Message-Id: <20200909175707.10670-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 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 01/10] syscalls/fanotify14: Test cases for FAN_REPORT_DFID_NAME 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check invalid combinations for the new flags. Signed-off-by: Amir Goldstein --- testcases/kernel/syscalls/fanotify/fanotify.h | 10 ++++++++++ testcases/kernel/syscalls/fanotify/fanotify14.c | 10 +++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index d271578e9..4a7959989 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -44,6 +44,13 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #ifndef FAN_REPORT_FID #define FAN_REPORT_FID 0x00000200 #endif +#ifndef FAN_REPORT_DIR_FID +#define FAN_REPORT_DIR_FID 0x00000400 +#endif +#ifndef FAN_REPORT_NAME +#define FAN_REPORT_NAME 0x00000800 +#define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) +#endif #ifndef FAN_MARK_INODE #define FAN_MARK_INODE 0 @@ -114,6 +121,9 @@ typedef struct { #ifndef FAN_EVENT_INFO_TYPE_DFID_NAME #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 #endif +#ifndef FAN_EVENT_INFO_TYPE_DFID +#define FAN_EVENT_INFO_TYPE_DFID 3 +#endif #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER struct fanotify_event_info_header { diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c index 3ca38d1e7..349177d9a 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify14.c +++ b/testcases/kernel/syscalls/fanotify/fanotify14.c @@ -52,7 +52,15 @@ static struct test_case_t { }, { FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS - } + }, + { + /* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */ + FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0 + }, + { + /* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */ + FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0 + }, }; static void do_test(unsigned int number) From patchwork Wed Sep 9 17:56:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360875 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=RpsfW+Dq; 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 4BmqVY3DdTz9sTK for ; Thu, 10 Sep 2020 03:57:41 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DA1AF3C2C31 for ; Wed, 9 Sep 2020 19:57:38 +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]) by picard.linux.it (Postfix) with ESMTP id F17033C2E8F for ; Wed, 9 Sep 2020 19:57:18 +0200 (CEST) Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (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 87AA9100079C for ; Wed, 9 Sep 2020 19:57:18 +0200 (CEST) Received: by mail-wm1-x341.google.com with SMTP id e17so3165655wme.0 for ; Wed, 09 Sep 2020 10:57:18 -0700 (PDT) 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; bh=3SxaYBZJpJ4Mso3aGJmfNLoc/++Q0UZHYubuwhSE0bk=; b=RpsfW+DqV47OdKLwjfxCiwPdHCbcfoMHrbgco4H+RsOQ8B5I0fWcifAQTa55DUi2Ve 6UEUYoLi7qnrSnkhH/kXZRiloCij0IhsmWs1jGOIawL14PNvTAVFJSEF76HEhNN7nkNP kF+yHVxK1go5cU2uduNc3StkrVS3Y72u+QNzvWfNfRpvXb8v8BJsCati/WzI/FqZqwdb LuzLh6Jaic4dTg0Xs9nucAVmTai0By1bKiDJmPdrJxy1ZzgpptTugdREBdyRMoorwRt4 EleMxAwH+N3uzJYdfDQRFdMI+P9B3trV5Mxb/EH73FY2S+2EZ+qasPxu3Lu249iXXk7g qYUw== 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; bh=3SxaYBZJpJ4Mso3aGJmfNLoc/++Q0UZHYubuwhSE0bk=; b=VkWPF01sKjlu0woZaNCMD0ZMJmYlgUPPL9QRl/nrju8p6xcNOPgZ4agOxezi0A/vzQ b/elNjbNmMo9QqyJZY7Yk9vwSUqvOc/WLZX0iTK78HT3y3TINHXH4COvp1y7tJkMro9G 9M5WvfDwr1xEMRpg3vDUTsg8LRw9Q4IGoDdvxX8wnDiDA4ls340HbThSGd65zCPawebX h3+2E0PMeWLBJ4fUJAWcMxuM+QApwotU54RZWZUBC/HWhUSObc2g7hQ8R0bhmoCE3zrA ZVXIHOMcbGa8W0EPf3e/tX87+6n3pUSuKnC6w8/jOR15zR8peRFcksmULnBfa7sq3mjY uTAA== X-Gm-Message-State: AOAM532PQH14rYeB5pEtayB2T9nBN8HhlZZ4DD29sKlQLmFAh9uxjSlQ q8r/Rin2rnkn+Hgw1Sj9e0M= X-Google-Smtp-Source: ABdhPJzuIRJAR7rAGwF1pfp0YtlcWlvSxW7xtqYjcAjsv9dWMdw6L9yxREJLcIe+H3VUHtr1jnNdiQ== X-Received: by 2002:a1c:4886:: with SMTP id v128mr4703613wma.139.1599674238058; Wed, 09 Sep 2020 10:57:18 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:17 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:56:59 +0300 Message-Id: <20200909175707.10670-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 02/10] syscalls/fanotify16: Adjust test to use FAN_REPORT_DFID_NAME 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The new FAN_DIR_MODIFY event was removed before final v5.7 release and will be replaced with a new group flag FAN_REPORT_DFID_NAME to report name info for FAN_CREATE, FAN_DELETE and FAN_MOVE events. Adjust the test to use this new API. Signed-off-by: Amir Goldstein --- testcases/kernel/syscalls/fanotify/fanotify.h | 11 ++- .../kernel/syscalls/fanotify/fanotify16.c | 69 ++++++++++--------- 2 files changed, 44 insertions(+), 36 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 4a7959989..91535718b 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -89,9 +89,6 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #ifndef FAN_OPEN_EXEC_PERM #define FAN_OPEN_EXEC_PERM 0x00040000 #endif -#ifndef FAN_DIR_MODIFY -#define FAN_DIR_MODIFY 0x00080000 -#endif /* * FAN_ALL_PERM_EVENTS has been deprecated, so any new permission events @@ -103,6 +100,11 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #define LTP_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_OPEN_EXEC_PERM | \ FAN_ACCESS_PERM) +struct fanotify_group_type { + unsigned int flag; + const char * name; +}; + struct fanotify_mark_type { unsigned int flag; const char * name; @@ -201,6 +203,9 @@ static inline void fanotify_save_fid(const char *path, } #endif /* HAVE_NAME_TO_HANDLE_AT */ +#define INIT_FANOTIFY_GROUP_TYPE(t) \ + { FAN_ ## t, "FAN_" #t } + #define INIT_FANOTIFY_MARK_TYPE(t) \ { FAN_MARK_ ## t, "FAN_MARK_" #t } diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index d366a455f..f3fbd3bc0 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -5,7 +5,8 @@ * Started by Amir Goldstein * * DESCRIPTION - * Check FAN_DIR_MODIFY events with name info + * Check fanotify directory entry modification events with group + * init flags FAN_REPORT_DFID_NAME (dir fid + name) */ #define _GNU_SOURCE #include "config.h" @@ -23,7 +24,6 @@ #if defined(HAVE_SYS_FANOTIFY_H) #include -#include #define EVENT_MAX 10 @@ -59,27 +59,30 @@ static char event_buf[EVENT_BUF_LEN]; static struct test_case_t { const char *tname; + struct fanotify_group_type group; struct fanotify_mark_type mark; unsigned long mask; struct fanotify_mark_type sub_mark; unsigned long sub_mask; } test_cases[] = { { - /* Filesystem watch for dir modify and delete self events */ - "FAN_REPORT_FID on filesystem with FAN_DIR_MODIFY", + /* Filesystem watch for directory entry modification events */ + "FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME), INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), - FAN_DIR_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, + FAN_CREATE | FAN_DELETE| FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR, {}, 0, }, { - /* Recursive watches for dir modify events */ - "FAN_REPORT_FID on directories with FAN_DIR_MODIFY", + /* Recursive watches for directory entry modification events */ + "FAN_REPORT_DFID_NAME monitor directories for create/delete/move", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME), INIT_FANOTIFY_MARK_TYPE(INODE), - FAN_DIR_MODIFY, - /* Watches for delete self event on subdir */ + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR, + /* Watches for directory entry modification events on subdir */ INIT_FANOTIFY_MARK_TYPE(INODE), - FAN_DIR_MODIFY | FAN_DELETE_SELF | FAN_ONDIR, + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR, }, }; @@ -87,20 +90,23 @@ static void do_test(unsigned int number) { int fd, len = 0, i = 0, test_num = 0, tst_count = 0; struct test_case_t *tc = &test_cases[number]; + struct fanotify_group_type *group = &tc->group; struct fanotify_mark_type *mark = &tc->mark; struct fanotify_mark_type *sub_mark = &tc->sub_mark; struct fanotify_fid_t root_fid, dir_fid, file_fid; tst_res(TINFO, "Test #%d: %s", number, tc->tname); - fd_notify = fanotify_init(FAN_REPORT_FID, 0); + fd_notify = fanotify_init(group->flag, 0); if (fd_notify == -1) { - if (errno == EINVAL) - tst_brk(TCONF, - "FAN_REPORT_FID not supported by kernel"); + if (errno == EINVAL) { + tst_res(TCONF, + "%s not supported by kernel", group->name); + return; + } tst_brk(TBROK | TERRNO, - "fanotify_init(FAN_REPORT_FID, 0) failed"); + "fanotify_init(%s, 0) failed", group->name); } /* @@ -108,10 +114,6 @@ static void do_test(unsigned int number) */ if (fanotify_mark(fd_notify, FAN_MARK_ADD | mark->flag, tc->mask, AT_FDCWD, MOUNT_PATH) < 0) { - if (errno == EINVAL) - tst_brk(TCONF, - "FAN_DIR_MODIFY not supported by kernel"); - tst_brk(TBROK | TERRNO, "fanotify_mark (%d, FAN_MARK_ADD | %s, 0x%lx, " "AT_FDCWD, '"MOUNT_PATH"') failed", @@ -138,7 +140,7 @@ static void do_test(unsigned int number) fd_notify, sub_mark->name, tc->sub_mask, dname1); } - event_set[tst_count].mask = FAN_DIR_MODIFY; + event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR; event_set[tst_count].fid = &root_fid; strcpy(event_set[tst_count].name, DIR_NAME1); tst_count++; @@ -160,22 +162,22 @@ static void do_test(unsigned int number) len += SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len); /* - * FAN_DIR_MODIFY events with the same name are merged. + * FAN_CREATE|FAN_DELETE|FAN_MOVE events with the same name are merged. */ - event_set[tst_count].mask = FAN_DIR_MODIFY; + event_set[tst_count].mask = FAN_CREATE | FAN_MOVED_FROM; event_set[tst_count].fid = &dir_fid; strcpy(event_set[tst_count].name, FILE_NAME1); tst_count++; - event_set[tst_count].mask = FAN_DIR_MODIFY; + event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO; event_set[tst_count].fid = &dir_fid; strcpy(event_set[tst_count].name, FILE_NAME2); tst_count++; - /* * Directory watch does not get self events on children. - * Filesystem watch gets self event w/o name info. + * Filesystem watch gets self event w/o name info if FAN_REPORT_FID + * is set. */ - if (mark->flag == FAN_MARK_FILESYSTEM) { + if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) { event_set[tst_count].mask = FAN_DELETE_SELF; event_set[tst_count].fid = &file_fid; strcpy(event_set[tst_count].name, ""); @@ -188,19 +190,20 @@ static void do_test(unsigned int number) /* Read more events on dirs */ len += SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len); - event_set[tst_count].mask = FAN_DIR_MODIFY; + event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR; event_set[tst_count].fid = &root_fid; strcpy(event_set[tst_count].name, DIR_NAME1); tst_count++; - event_set[tst_count].mask = FAN_DIR_MODIFY; + event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR; event_set[tst_count].fid = &root_fid; strcpy(event_set[tst_count].name, DIR_NAME2); tst_count++; /* - * Directory watch gets self event on itself w/o name info. + * Directory watch gets self event on itself and filesystem watch gets + * self event on all directories with name ".". */ event_set[tst_count].mask = FAN_DELETE_SELF | FAN_ONDIR; - strcpy(event_set[tst_count].name, ""); + strcpy(event_set[tst_count].name, "."); event_set[tst_count].fid = &dir_fid; tst_count++; @@ -224,8 +227,8 @@ static void do_test(unsigned int number) file_handle = (struct file_handle *)event_fid->handle; fhlen = file_handle->handle_bytes; filename = (char *)file_handle->f_handle + fhlen; - namelen = ((char *)event + event->event_len) - filename; - /* End of event could have name, zero padding, both or none */ + namelen = ((char *)event_fid + event_fid->hdr.len) - filename; + /* End of event_fid could have name, zero padding, both or none */ if (namelen > 0) { namelen = strlen(filename); } else { @@ -236,7 +239,7 @@ static void do_test(unsigned int number) if (expected->name[0]) { info_type = FAN_EVENT_INFO_TYPE_DFID_NAME; } else { - info_type = FAN_EVENT_INFO_TYPE_FID; + info_type = FAN_EVENT_INFO_TYPE_DFID; } if (test_num >= tst_count) { From patchwork Wed Sep 9 17:57:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360876 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=s6t3zAZ7; 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 4BmqVk4JyJz9sTK for ; Thu, 10 Sep 2020 03:57:50 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D64E23C5379 for ; Wed, 9 Sep 2020 19:57:47 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 8A2DA3C2C43 for ; Wed, 9 Sep 2020 19:57:20 +0200 (CEST) Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id 1987A1A00E3A for ; Wed, 9 Sep 2020 19:57:20 +0200 (CEST) Received: by mail-wr1-x444.google.com with SMTP id x14so3884595wrl.12 for ; Wed, 09 Sep 2020 10:57:20 -0700 (PDT) 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; bh=I2/TEQ3hdW1F8PkxGJQDHzwgXbLG3e9+AmpyMNd2k0w=; b=s6t3zAZ7FpyWvchq09EO3fUzz1/23e0KHQNgeNkqZR5B7lcDYiBIApo7f4YCHPCCcy CGaIM0eaCEkq9tCLx/zqgNG2l+lC13VbRAwMrN+gybCOi6ojxwiN1JQWwbNBgJQa0EBY xoaxeCiX5GOXDMTM17az/nq5A6bVn0DvWJa0wOjO8ScUZMpiqz7nYwGhTwWXcZmqfMnG cVZTXvVM0+NmoYQocioMGmr+oTL9UEniM9taZaJTlXCXzsY7JDzAg0E7IdulDea0bbAz sP/iUNA+LfCYLepVTZUNbMi2hx3C47AdSoyJ6tGPzxK1e53TkV1OJGXuU7kD41j9QOY+ z/Tw== 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; bh=I2/TEQ3hdW1F8PkxGJQDHzwgXbLG3e9+AmpyMNd2k0w=; b=lXwN1iF298ySjDPmbU/2VbABOLF63ygqwYIXHgCDWH7RWZai3WXbtEgXyFc0RtM8ie 4r8anl4tgWIrRIXD4Kk/p/G4pnVRYOUi1hoIsKYBaBFhRQKd1YPY5QdxSPiEom+hIwSd bh7Q5F+67MiD66oiy7ertVEzlRnfKnQt3HwtftfR59kIKSo40BPl32K43C4SHdyszUdB N/2vyapVrQfc7uEZGVdI3XMDFpieEseDWW0iFUiqEV+ocyN8Z76e9ZHYMaRsvdBNs22N iD/l0M+O4JHi1N1i3whhLNtVI8H1TvQGLN/u3XWmuBwTdJF2cPOIqZd6xg4ErnasnGmt UTaw== X-Gm-Message-State: AOAM531NqTq5fZyrmp/VFforkJhYl4Ie23YPhBwBegLOiwzMmiXZu3ap M92M3fQ7ulb+DXSXo6LSP7k= X-Google-Smtp-Source: ABdhPJzqiUlZ7BCc6qQTm2dvi2MzdIYTQXcDcg9PnH95T7ECYNc5Sv/+BQfohPzvDZxv3fm//cQRiA== X-Received: by 2002:adf:a35d:: with SMTP id d29mr4997933wrb.307.1599674239320; Wed, 09 Sep 2020 10:57:19 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:18 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:00 +0300 Message-Id: <20200909175707.10670-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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-3.smtp.seeweb.it Subject: [LTP] [PATCH 03/10] syscalls/fanotify16: Test more event types with name 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" - Test events "on child" reported with name - Test events on directory itself reported with name "." - Test move self event on directory and file Events open/close are not supported on filesystem mark, so they are set on either a subdir inode mark or mount mark. Events "on child" may or may not be merged with directory modification events with same file name, depending on group init flags, so relax the exact check to event mask and instead, just expect that all execpted event types will arrive. Signed-off-by: Amir Goldstein --- .../kernel/syscalls/fanotify/fanotify16.c | 102 +++++++++++++----- 1 file changed, 77 insertions(+), 25 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index f3fbd3bc0..76f053fd7 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -5,8 +5,8 @@ * Started by Amir Goldstein * * DESCRIPTION - * Check fanotify directory entry modification events with group - * init flags FAN_REPORT_DFID_NAME (dir fid + name) + * Check fanotify directory entry modification events, events on child and + * on self with group init flags FAN_REPORT_DFID_NAME (dir fid + name) */ #define _GNU_SOURCE #include "config.h" @@ -25,7 +25,7 @@ #if defined(HAVE_SYS_FANOTIFY_H) #include -#define EVENT_MAX 10 +#define EVENT_MAX 20 /* Size of the event structure, not including file handle */ #define EVENT_SIZE (sizeof(struct fanotify_event_metadata) + \ @@ -66,29 +66,29 @@ static struct test_case_t { unsigned long sub_mask; } test_cases[] = { { - /* Filesystem watch for directory entry modification events */ - "FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move", + "FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move/open/close", INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME), INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), - FAN_CREATE | FAN_DELETE| FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR, - {}, - 0, + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR, + /* Mount watch for events possible on children */ + INIT_FANOTIFY_MARK_TYPE(MOUNT), + FAN_OPEN | FAN_CLOSE | FAN_ONDIR, }, { - /* Recursive watches for directory entry modification events */ - "FAN_REPORT_DFID_NAME monitor directories for create/delete/move", + "FAN_REPORT_DFID_NAME monitor directories for create/delete/move/open/close", INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME), INIT_FANOTIFY_MARK_TYPE(INODE), FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR, - /* Watches for directory entry modification events on subdir */ + /* Watches for self events on subdir and events on subdir's children */ INIT_FANOTIFY_MARK_TYPE(INODE), - FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_ONDIR, + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR | + FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD, }, }; static void do_test(unsigned int number) { - int fd, len = 0, i = 0, test_num = 0, tst_count = 0; + int fd, dirfd, len = 0, i = 0, test_num = 0, tst_count = 0; struct test_case_t *tc = &test_cases[number]; struct fanotify_group_type *group = &tc->group; struct fanotify_mark_type *mark = &tc->mark; @@ -125,8 +125,10 @@ static void do_test(unsigned int number) /* * Create subdir and watch open events "on children" with name. + * Make it a mount root. */ SAFE_MKDIR(dname1, 0755); + SAFE_MOUNT(dname1, dname1, "none", MS_BIND, NULL); /* Save the subdir fid */ fanotify_save_fid(dname1, &dir_fid); @@ -153,6 +155,7 @@ static void do_test(unsigned int number) SAFE_WRITE(1, fd, "1", 1); SAFE_RENAME(fname1, fname2); + SAFE_CLOSE(fd); /* Generate delete events with fname2 */ @@ -168,6 +171,16 @@ static void do_test(unsigned int number) event_set[tst_count].fid = &dir_fid; strcpy(event_set[tst_count].name, FILE_NAME1); tst_count++; + /* + * Event on non-dir child with the same name may be merged with the + * directory entry modification events above, unless FAN_REPORT_FID is + * set and child fid is reported. + */ + event_set[tst_count].mask = FAN_OPEN; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, FILE_NAME1); + tst_count++; + event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO; event_set[tst_count].fid = &dir_fid; strcpy(event_set[tst_count].name, FILE_NAME2); @@ -178,11 +191,37 @@ static void do_test(unsigned int number) * is set. */ if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) { - event_set[tst_count].mask = FAN_DELETE_SELF; + event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF; event_set[tst_count].fid = &file_fid; strcpy(event_set[tst_count].name, ""); tst_count++; } + event_set[tst_count].mask = FAN_CLOSE_WRITE; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, FILE_NAME2); + tst_count++; + + dirfd = SAFE_OPEN(dname1, O_RDONLY | O_DIRECTORY); + SAFE_CLOSE(dirfd); + + SAFE_UMOUNT(dname1); + + /* + * Directory watch gets open/close events on itself and on its subdirs. + * Filesystem watch gets open/close event on all directories with name ".". + */ + event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, "."); + tst_count++; + /* + * Directory watch gets self event on itself and filesystem watch gets + * self event on all directories with name ".". + */ + event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, "."); + tst_count++; SAFE_RENAME(dname1, dname2); SAFE_RMDIR(dname2); @@ -198,14 +237,8 @@ static void do_test(unsigned int number) event_set[tst_count].fid = &root_fid; strcpy(event_set[tst_count].name, DIR_NAME2); tst_count++; - /* - * Directory watch gets self event on itself and filesystem watch gets - * self event on all directories with name ".". - */ - event_set[tst_count].mask = FAN_DELETE_SELF | FAN_ONDIR; - strcpy(event_set[tst_count].name, "."); - event_set[tst_count].fid = &dir_fid; - tst_count++; + /* Expect no more events */ + event_set[tst_count].mask = 0; /* * Cleanup the marks @@ -220,7 +253,7 @@ static void do_test(unsigned int number) struct file_handle *file_handle; unsigned int fhlen; const char *filename; - int namelen, info_type; + int namelen, info_type, mask_match; event = (struct fanotify_event_metadata *)&event_buf[i]; event_fid = (struct fanotify_event_info_fid *)(event + 1); @@ -242,6 +275,16 @@ static void do_test(unsigned int number) info_type = FAN_EVENT_INFO_TYPE_DFID; } + /* + * Event may contain more than the expected mask, but it must + * have all the bits in expected mask. + * Expected event on dir must not get event on non dir and the + * other way around. + */ + mask_match = ((event->mask & expected->mask) && + !(expected->mask & ~event->mask) && + !((event->mask ^ expected->mask) & FAN_ONDIR)); + if (test_num >= tst_count) { tst_res(TFAIL, "got unnecessary event: mask=%llx " @@ -259,7 +302,7 @@ static void do_test(unsigned int number) (unsigned)event->pid, event->fd, event->event_len, event_fid->hdr.info_type, event_fid->hdr.len, fhlen); - } else if (event->mask != expected->mask) { + } else if (!mask_match) { tst_res(TFAIL, "got event: mask=%llx (expected %llx) " "pid=%u fd=%d name='%s' " @@ -356,10 +399,19 @@ static void do_test(unsigned int number) event_fid->hdr.len, fhlen); } + if (test_num < tst_count) + test_num++; + + if (mask_match) { + /* In case of merged event match next expected mask */ + event->mask &= ~expected->mask | FAN_ONDIR; + if (event->mask & ~FAN_ONDIR) + continue; + } + i += event->event_len; if (event->fd > 0) SAFE_CLOSE(event->fd); - test_num++; } for (; test_num < tst_count; test_num++) { From patchwork Wed Sep 9 17:57:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360877 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=cWykvxYt; 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 4BmqVx4W3Lz9sTK for ; Thu, 10 Sep 2020 03:58:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CDF633C537E for ; Wed, 9 Sep 2020 19:57:58 +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 [IPv6:2001:4b78:1:20::6]) by picard.linux.it (Postfix) with ESMTP id 902933C2C93 for ; Wed, 9 Sep 2020 19:57:21 +0200 (CEST) Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) (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 065A01400437 for ; Wed, 9 Sep 2020 19:57:21 +0200 (CEST) Received: by mail-wr1-x441.google.com with SMTP id z4so3943088wrr.4 for ; Wed, 09 Sep 2020 10:57:21 -0700 (PDT) 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; bh=OnDb0Tq+FfdfCUteExEO5WzYp3RhLgmbZ/KhKNDo66g=; b=cWykvxYtoVQwosGQbBbkxXH193/7ozKpNUAomPN0hIetxwMQ8TVWuXPrr1GceQIJ4+ p5DRa48fJLA5oBzX3V8ijjN54UdMtc7Lxv3PNjFTe4IKStXRrFVLt85Ge1/taHTJMgC5 UImXmTWd30hm25Y/P3QbiMRPDJkHhnMul/P5XdMSJol/YQNNePPthVhJbEj8PZNgX2ox lxtpvOSLIrCq7eBO8kRYDxgi2YsKuILkuqpRMlzTPL912e7LL4pOFwQ3Y6BlJPmDhCZq JUbr2LiJ6VvHF9o5TO+dRB977haWk4jr35+xIgu9HsR+htERdIfTxjjoN6t07OOS6XhZ hcww== 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; bh=OnDb0Tq+FfdfCUteExEO5WzYp3RhLgmbZ/KhKNDo66g=; b=ommuTpkDK0LGkwIE2WPu7jtpfJuA5WKMgknsbYp0P70IYd85NGJrujp93e37dN+JSw ko8h7SgHhhmB0qYoeA06vBZ56MJZQfyiwA10qCDR3KFgDJQSxZBzvpG/5tlGHBvu+nzQ 3sZd/i2mC3ujIIWm2gia1TR9rKE7N99ukN3ukYbOjhEdQXubIXQmiJEt/rPv8+FJetBW wH0uAXr/msmBk2w0YdyoA9xTxxELBSSo1C5u2mlO3g4eFRcpe9akQp9UC1i87ZWg5rG8 7oTR3b3gKhEFca1Gw4QLFTEMunxT7In79ptLGXdEuc5hcFZAhEFV9PfD4ky65BiIL+nv FULQ== X-Gm-Message-State: AOAM533qUvv16Vq7WEEepUq5ABIOpIph+HXnelq17+T9cGnh/sOBxKfh Aw0wknhLbcsQ9QF7dJcQPWOYrPxfMM4= X-Google-Smtp-Source: ABdhPJy25j2+BOpYQtQVlQDz8/gKjHvB4dmLyg+pEflwfOBQiVS7wz6G5lJiEyXf6EDUnnAQVP+wMA== X-Received: by 2002:adf:9c93:: with SMTP id d19mr5090041wre.275.1599674240559; Wed, 09 Sep 2020 10:57:20 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:20 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:01 +0300 Message-Id: <20200909175707.10670-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 04/10] syscalls/fanotify16: Add test cases more init flag combinations 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Test more combination of flags FAN_REPORT_DIR_FID, FAN_REPORT_FID and FAN_REPORT_NAME. Reporting different information per event may result in different event merging. For example, with FAN_REPORT_DFID_NAME, create/open/moved_from of "file1" are merged and moved_to/delete/close of "file2" are merged. With FAN_REPORT_DIR_FID, open/close of the file are merged (dir fid + child fid info are the same) and create/move/delete of file are merged (dir fid info is the same). Signed-off-by: Amir Goldstein --- testcases/kernel/syscalls/fanotify/fanotify.h | 8 ++ .../kernel/syscalls/fanotify/fanotify16.c | 110 ++++++++++++++++-- 2 files changed, 108 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h index 91535718b..a9154f993 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify.h +++ b/testcases/kernel/syscalls/fanotify/fanotify.h @@ -52,6 +52,14 @@ static long fanotify_mark(int fd, unsigned int flags, uint64_t mask, #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) #endif +/* Non-uapi convenience macros */ +#ifndef FAN_REPORT_DFID_NAME_FID +#define FAN_REPORT_DFID_NAME_FID (FAN_REPORT_DFID_NAME | FAN_REPORT_FID) +#endif +#ifndef FAN_REPORT_DFID_FID +#define FAN_REPORT_DFID_FID (FAN_REPORT_DIR_FID | FAN_REPORT_FID) +#endif + #ifndef FAN_MARK_INODE #define FAN_MARK_INODE 0 #endif diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index 76f053fd7..c8c7a9ee8 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -6,7 +6,11 @@ * * DESCRIPTION * Check fanotify directory entry modification events, events on child and - * on self with group init flags FAN_REPORT_DFID_NAME (dir fid + name) + * on self with group init flags: + * - FAN_REPORT_DFID_NAME (dir fid + name) + * - FAN_REPORT_DIR_FID (dir fid) + * - FAN_REPORT_DIR_FID | FAN_REPORT_FID (dir fid + child fid) + * - FAN_REPORT_DFID_NAME | FAN_REPORT_FID (dir fid + name + child fid) */ #define _GNU_SOURCE #include "config.h" @@ -84,6 +88,63 @@ static struct test_case_t { FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR | FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD, }, + { + "FAN_REPORT_DIR_FID monitor filesystem for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DIR_FID), + INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR, + /* Mount watch for events possible on children */ + INIT_FANOTIFY_MARK_TYPE(MOUNT), + FAN_OPEN | FAN_CLOSE | FAN_ONDIR, + }, + { + "FAN_REPORT_DIR_FID monitor directories for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DIR_FID), + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR, + /* Watches for self events on subdir and events on subdir's children */ + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR | + FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD, + }, + { + "FAN_REPORT_DFID_FID monitor filesystem for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_FID), + INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR, + /* Mount watch for events possible on children */ + INIT_FANOTIFY_MARK_TYPE(MOUNT), + FAN_OPEN | FAN_CLOSE | FAN_ONDIR, + }, + { + "FAN_REPORT_DFID_FID monitor directories for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_FID), + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR, + /* Watches for self events on subdir and events on subdir's children */ + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR | + FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD, + }, + { + "FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID), + INIT_FANOTIFY_MARK_TYPE(FILESYSTEM), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR, + /* Mount watch for events possible on children */ + INIT_FANOTIFY_MARK_TYPE(MOUNT), + FAN_OPEN | FAN_CLOSE | FAN_ONDIR, + }, + { + "FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/open/close", + INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID), + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR, + /* Watches for self events on subdir and events on subdir's children */ + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR | + FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD, + }, }; static void do_test(unsigned int number) @@ -174,17 +235,31 @@ static void do_test(unsigned int number) /* * Event on non-dir child with the same name may be merged with the * directory entry modification events above, unless FAN_REPORT_FID is - * set and child fid is reported. + * set and child fid is reported. If FAN_REPORT_FID is set but + * FAN_REPORT_NAME is not set, then FAN_CREATE above is merged with + * FAN_DELETE below and FAN_OPEN will be merged with FAN_CLOSE. */ - event_set[tst_count].mask = FAN_OPEN; - event_set[tst_count].fid = &dir_fid; - strcpy(event_set[tst_count].name, FILE_NAME1); - tst_count++; + if (group->flag & FAN_REPORT_NAME) { + event_set[tst_count].mask = FAN_OPEN; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, FILE_NAME1); + tst_count++; + } event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO; event_set[tst_count].fid = &dir_fid; strcpy(event_set[tst_count].name, FILE_NAME2); tst_count++; + /* + * When not reporting name, open of FILE_NAME1 is merged + * with close of FILE_NAME2. + */ + if (!(group->flag & FAN_REPORT_NAME)) { + event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_WRITE; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, ""); + tst_count++; + } /* * Directory watch does not get self events on children. * Filesystem watch gets self event w/o name info if FAN_REPORT_FID @@ -196,10 +271,17 @@ static void do_test(unsigned int number) strcpy(event_set[tst_count].name, ""); tst_count++; } - event_set[tst_count].mask = FAN_CLOSE_WRITE; - event_set[tst_count].fid = &dir_fid; - strcpy(event_set[tst_count].name, FILE_NAME2); - tst_count++; + /* + * When reporting name, close of FILE_NAME2 is not merged with + * open of FILE_NAME1 and it is received after the merged self + * events. + */ + if (group->flag & FAN_REPORT_NAME) { + event_set[tst_count].mask = FAN_CLOSE_WRITE; + event_set[tst_count].fid = &dir_fid; + strcpy(event_set[tst_count].name, FILE_NAME2); + tst_count++; + } dirfd = SAFE_OPEN(dname1, O_RDONLY | O_DIRECTORY); SAFE_CLOSE(dirfd); @@ -269,8 +351,16 @@ static void do_test(unsigned int number) namelen = 0; } + if (!(group->flag & FAN_REPORT_NAME)) + expected->name[0] = 0; + if (expected->name[0]) { info_type = FAN_EVENT_INFO_TYPE_DFID_NAME; + } else if (expected->mask & FAN_ONDIR) { + info_type = FAN_EVENT_INFO_TYPE_DFID; + } else if (expected->mask & (FAN_DELETE_SELF | FAN_MOVE_SELF)) { + /* Self event on non-dir has only child fid */ + info_type = FAN_EVENT_INFO_TYPE_FID; } else { info_type = FAN_EVENT_INFO_TYPE_DFID; } From patchwork Wed Sep 9 17:57:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360878 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=cldnHE2w; 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 4BmqW81vtDz9sTK for ; Thu, 10 Sep 2020 03:58:12 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AB2113C2C98 for ; Wed, 9 Sep 2020 19:58:09 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id F23373C2E2B for ; Wed, 9 Sep 2020 19:57:22 +0200 (CEST) Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (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 8C6FF600683 for ; Wed, 9 Sep 2020 19:57:22 +0200 (CEST) Received: by mail-wr1-x442.google.com with SMTP id t10so3941890wrv.1 for ; Wed, 09 Sep 2020 10:57:22 -0700 (PDT) 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; bh=CSXFyv8DULSkRkigXjxPkfedFrVp+8UdgXFa2EuKTdw=; b=cldnHE2wELiJJp9qiqSCOiAqc7u3yceU41ScnqBsZTPGeycinLCW92Xx7Nx3vwhJL8 fyQZSs9njsg7Le30UuEuxa2c6/L4zUbRvTmFV38BS5HugAaM3pWzigqRwntLLq7IkXGs GY8LZ8X2aTK8B0E2c+4fnWHeMT5PI0FVNObfBkBWGnciWefcskhkevg9BuZqqKATqk4i I4Eh9SKQ87IIVXNnMhoh4ah1IuB0zOlRtaLOe6OaCEX7osvX1OT+tsfanY6ym13OS7yt Y5Cup9blDfpAga5PLvTFq+6OHRRfcbIzzESyTk7T0rhwi0n0SFsdkAMJy8QU+jX1rJyk BDFw== 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; bh=CSXFyv8DULSkRkigXjxPkfedFrVp+8UdgXFa2EuKTdw=; b=QGUXUosjoLt1VlRimEvrf12pf8mfMlMOv3NG5nvQKnMCG41QuQFFf4vQQpILA3ieaV 2rbgBAa3+qkc8nK4EtFuhnPBDhRIkq+JyP5zQyUb1HMpelXJzxz2eDxdwZkHfJFdd9xD 6SMdFtMHQUXAG3IpTV5DdkLrhLTszW3OfNd9/LIor7m0JguiDG9VPIbn2uQgGEH3LU1+ VRap+itc1Q2FHd004Dy6LqbMXDgYz+lNMvVr6hUFz7vBysUBYrXNNZ+DcgplR9u9+EPC HbSzRyMwKxUj+QndxM52IJ3cZjnT8wYARFXUm+WjtQNL++VaaOmNU7hZAY1aRq7CikFh aJCA== X-Gm-Message-State: AOAM530esqYOULiLq7jA5nLN/caaoTr0bwMTC6VVjmGi/Py53hXFgmFR BVAJb/4YlHr5WNJpV6HLqxI= X-Google-Smtp-Source: ABdhPJy5MPCX5XfE8ZXXmImvR6VkEeMreMYPHfffGphM+Qhfhn5b6S72so+iuwBLwCicRnGlcdHkLA== X-Received: by 2002:adf:ee01:: with SMTP id y1mr5411563wrn.2.1599674242090; Wed, 09 Sep 2020 10:57:22 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:21 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:02 +0300 Message-Id: <20200909175707.10670-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 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 05/10] syscalls/fanotify16: Verify child fid 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" If event reports both dir and child fid, also verify the expected child fid in the second info record. Signed-off-by: Amir Goldstein --- .../kernel/syscalls/fanotify/fanotify16.c | 73 ++++++++++++++++--- 1 file changed, 61 insertions(+), 12 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c index c8c7a9ee8..7995a1688 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify16.c +++ b/testcases/kernel/syscalls/fanotify/fanotify16.c @@ -44,6 +44,7 @@ struct event_t { unsigned long long mask; struct fanotify_fid_t *fid; + struct fanotify_fid_t *child_fid; char name[BUF_SIZE]; }; @@ -205,6 +206,7 @@ static void do_test(unsigned int number) event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR; event_set[tst_count].fid = &root_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, DIR_NAME1); tst_count++; @@ -230,6 +232,7 @@ static void do_test(unsigned int number) */ event_set[tst_count].mask = FAN_CREATE | FAN_MOVED_FROM; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, FILE_NAME1); tst_count++; /* @@ -242,12 +245,14 @@ static void do_test(unsigned int number) if (group->flag & FAN_REPORT_NAME) { event_set[tst_count].mask = FAN_OPEN; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = &file_fid; strcpy(event_set[tst_count].name, FILE_NAME1); tst_count++; } event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, FILE_NAME2); tst_count++; /* @@ -257,6 +262,7 @@ static void do_test(unsigned int number) if (!(group->flag & FAN_REPORT_NAME)) { event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_WRITE; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = &file_fid; strcpy(event_set[tst_count].name, ""); tst_count++; } @@ -268,6 +274,7 @@ static void do_test(unsigned int number) if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) { event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF; event_set[tst_count].fid = &file_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, ""); tst_count++; } @@ -279,6 +286,7 @@ static void do_test(unsigned int number) if (group->flag & FAN_REPORT_NAME) { event_set[tst_count].mask = FAN_CLOSE_WRITE; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = &file_fid; strcpy(event_set[tst_count].name, FILE_NAME2); tst_count++; } @@ -294,6 +302,7 @@ static void do_test(unsigned int number) */ event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_NOWRITE | FAN_ONDIR; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, "."); tst_count++; /* @@ -302,6 +311,7 @@ static void do_test(unsigned int number) */ event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR; event_set[tst_count].fid = &dir_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, "."); tst_count++; @@ -313,10 +323,12 @@ static void do_test(unsigned int number) event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR; event_set[tst_count].fid = &root_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, DIR_NAME1); tst_count++; event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR; event_set[tst_count].fid = &root_fid; + event_set[tst_count].child_fid = NULL; strcpy(event_set[tst_count].name, DIR_NAME2); tst_count++; /* Expect no more events */ @@ -332,17 +344,21 @@ static void do_test(unsigned int number) struct event_t *expected = &event_set[test_num]; struct fanotify_event_metadata *event; struct fanotify_event_info_fid *event_fid; + struct fanotify_event_info_fid *child_fid; + struct fanotify_fid_t *expected_fid = expected->fid; + struct fanotify_fid_t *expected_child_fid = expected->child_fid; struct file_handle *file_handle; unsigned int fhlen; const char *filename; - int namelen, info_type, mask_match; + int namelen, info_type, mask_match, info_id = 0; event = (struct fanotify_event_metadata *)&event_buf[i]; event_fid = (struct fanotify_event_info_fid *)(event + 1); file_handle = (struct file_handle *)event_fid->handle; fhlen = file_handle->handle_bytes; filename = (char *)file_handle->f_handle + fhlen; - namelen = ((char *)event_fid + event_fid->hdr.len) - filename; + child_fid = (void *)((char *)event_fid + event_fid->hdr.len); + namelen = (char *)child_fid - (char *)filename; /* End of event_fid could have name, zero padding, both or none */ if (namelen > 0) { namelen = strlen(filename); @@ -350,6 +366,12 @@ static void do_test(unsigned int number) filename = ""; namelen = 0; } + /* Is there a child fid after first fid record? */ + if (((char *)child_fid - (char *)event) >= event->event_len) + child_fid = NULL; + + if (!(group->flag & FAN_REPORT_FID)) + expected_child_fid = NULL; if (!(group->flag & FAN_REPORT_NAME)) expected->name[0] = 0; @@ -375,6 +397,7 @@ static void do_test(unsigned int number) !(expected->mask & ~event->mask) && !((event->mask ^ expected->mask) & FAN_ONDIR)); +check_match: if (test_num >= tst_count) { tst_res(TFAIL, "got unnecessary event: mask=%llx " @@ -409,7 +432,7 @@ static void do_test(unsigned int number) (unsigned)event->pid, event->fd, event->event_len, event_fid->hdr.info_type, info_type, event_fid->hdr.len, fhlen); - } else if (fhlen != expected->fid->handle.handle_bytes) { + } else if (fhlen != expected_fid->handle.handle_bytes) { tst_res(TFAIL, "got event: mask=%llx pid=%u fd=%d name='%s' " "len=%d info_type=%d info_len=%d fh_len=%d expected(%d)" @@ -418,10 +441,10 @@ static void do_test(unsigned int number) (unsigned)event->pid, event->fd, filename, event->event_len, info_type, event_fid->hdr.len, fhlen, - expected->fid->handle.handle_bytes, + expected_fid->handle.handle_bytes, file_handle->handle_type); } else if (file_handle->handle_type != - expected->fid->handle.handle_type) { + expected_fid->handle.handle_type) { tst_res(TFAIL, "got event: mask=%llx pid=%u fd=%d name='%s' " "len=%d info_type=%d info_len=%d fh_len=%d " @@ -431,9 +454,9 @@ static void do_test(unsigned int number) event->event_len, info_type, event_fid->hdr.len, fhlen, file_handle->handle_type, - expected->fid->handle.handle_type); + expected_fid->handle.handle_type); } else if (memcmp(file_handle->f_handle, - expected->fid->handle.f_handle, fhlen)) { + expected_fid->handle.f_handle, fhlen)) { tst_res(TFAIL, "got event: mask=%llx pid=%u fd=%d name='%s' " "len=%d info_type=%d info_len=%d fh_len=%d " @@ -444,7 +467,7 @@ static void do_test(unsigned int number) event_fid->hdr.len, fhlen, file_handle->handle_type, *(int *)(file_handle->f_handle)); - } else if (memcmp(&event_fid->fsid, &expected->fid->fsid, + } else if (memcmp(&event_fid->fsid, &expected_fid->fsid, sizeof(event_fid->fsid)) != 0) { tst_res(TFAIL, "got event: mask=%llx pid=%u fd=%d name='%s' " @@ -456,8 +479,8 @@ static void do_test(unsigned int number) event_fid->hdr.len, fhlen, FSID_VAL_MEMBER(event_fid->fsid, 0), FSID_VAL_MEMBER(event_fid->fsid, 1), - expected->fid->fsid.val[0], - expected->fid->fsid.val[1]); + expected_fid->fsid.val[0], + expected_fid->fsid.val[1]); } else if (strcmp(expected->name, filename)) { tst_res(TFAIL, "got event: mask=%llx " @@ -479,13 +502,39 @@ static void do_test(unsigned int number) event->fd, filename, event->event_len, event_fid->hdr.info_type, event_fid->hdr.len, fhlen); + } else if (!!child_fid != !!expected_child_fid) { + tst_res(TFAIL, + "got event: mask=%llx " + "pid=%u fd=%d name='%s' num_info=%d (expected %d) " + "len=%d info_type=%d info_len=%d fh_len=%d", + (unsigned long long)event->mask, + (unsigned)event->pid, event->fd, + filename, 1 + !!child_fid, 1 + !!expected_child_fid, + event->event_len, event_fid->hdr.info_type, + event_fid->hdr.len, fhlen); + } else if (child_fid) { + tst_res(TINFO, + "got event #%d: info #%d: info_type=%d info_len=%d fh_len=%d", + test_num, info_id, event_fid->hdr.info_type, + event_fid->hdr.len, fhlen); + + /* Recheck event_fid match with child_fid */ + event_fid = child_fid; + expected_fid = expected->child_fid; + info_id = 1; + info_type = FAN_EVENT_INFO_TYPE_FID; + file_handle = (struct file_handle *)event_fid->handle; + fhlen = file_handle->handle_bytes; + child_fid = NULL; + expected_child_fid = NULL; + goto check_match; } else { tst_res(TPASS, "got event #%d: mask=%llx pid=%u fd=%d name='%s' " - "len=%d info_type=%d info_len=%d fh_len=%d", + "len=%d; info #%d: info_type=%d info_len=%d fh_len=%d", test_num, (unsigned long long)event->mask, (unsigned)event->pid, event->fd, filename, - event->event_len, event_fid->hdr.info_type, + event->event_len, info_id, event_fid->hdr.info_type, event_fid->hdr.len, fhlen); } From patchwork Wed Sep 9 17:57:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360879 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=oAs1EJDQ; 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 4BmqWK1lR5z9sTK for ; Thu, 10 Sep 2020 03:58:21 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8C3C83C3228 for ; Wed, 9 Sep 2020 19:58:18 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 7261A3C267D for ; Wed, 9 Sep 2020 19:57:24 +0200 (CEST) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (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 29289600683 for ; Wed, 9 Sep 2020 19:57:24 +0200 (CEST) Received: by mail-wr1-x443.google.com with SMTP id z1so3928451wrt.3 for ; Wed, 09 Sep 2020 10:57:24 -0700 (PDT) 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; bh=eMpgBnxlHJPY8RJJAuKD1HXzm7RMV1POLeoNgrS7q/E=; b=oAs1EJDQl0R6uQhzNdpOfsExrYy29t4u5gvSFaViv3AkycMeAsbKqHKVZxKFXowcxo 1d9+piCkhC5zLCWu8w7bX/O4uOB0icB0DSpdwJqG7VXkBg3CjibbGYiF+xFcGI0I9RJ2 1JTIsUB4Ca5/2KzOFqJFkLtspB1EPmwUqyoSMC9X9uyvBHkA3XXvlxBtMbDAttASb5Ts b1GJMZ6a5nBA2lxd9q5FbpIKqNPYk54CKx2XwL6/oyZcDf9qiTSrizNAjcXQa+htSt1l M7w9Xu4cgC2sVxZf3LhyM7+lBYHmxLIpgjKiWosx3G/AVof3sn6sVyDMoAJ3WbjBDPlz jq7w== 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; bh=eMpgBnxlHJPY8RJJAuKD1HXzm7RMV1POLeoNgrS7q/E=; b=cusG0nuP3IcWE2r6mVrFGn0X1OKA8eshZuv2UYmOvVS5SF7gUIsD1oxKh3wLv7rHPw wk7lSdBNpzHepPgd4go8AKPZ1vlBpzfM4ffu2/E0ASHHi8Uv57iO74Q7q3GbrOTusM8m 2VjO8hX/b59OwMmn2O5YTjdujtXwIoNzvxNpZdnrAykG3azcgBNbDXS5BzhH9qTOFY78 16GQvSS0ywBd9ULzsBWLv6U99voYVQb9+RistWLNRbLvuAU3j2B9LV/95tnhzEg8LLbi mzADbk5g3xDFRxmPO7Hu+PfVgkXRH9bpHluKGTGEXWwOAn17TttPE19pC5phUPDRyPNB uxzw== X-Gm-Message-State: AOAM531OTaGgQE7vgOBzVSDMIkyOujiUfqq2xZXf98fkwq3pFTXsC/Hp GwlouS4uRJ1YlL2exuDzZ92041G6OFI= X-Google-Smtp-Source: ABdhPJx8tModr0h1iaKIu/kxBw7nW/+lo4YHwB7MYXWxBuK3WgbLqctouH8V/J5JntgBAQe92A+V4A== X-Received: by 2002:a5d:4d8f:: with SMTP id b15mr5080114wru.341.1599674243642; Wed, 09 Sep 2020 10:57:23 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:23 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:03 +0300 Message-Id: <20200909175707.10670-7-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 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 06/10] syscalls/fcntl: New test for F_NOTIFY (dnotify) 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check that signal is delivered for both watching parent and watching subdir when subdir metadata changes. Signed-off-by: Amir Goldstein --- runtest/syscalls | 2 + testcases/kernel/syscalls/fcntl/fcntl38.c | 96 +++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 testcases/kernel/syscalls/fcntl/fcntl38.c diff --git a/runtest/syscalls b/runtest/syscalls index dc0ca5626..376a2bc6b 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -316,6 +316,8 @@ fcntl36 fcntl36 fcntl36_64 fcntl36_64 fcntl37 fcntl37 fcntl37_64 fcntl37_64 +fcntl38 fcntl38 +fcntl38_64 fcntl38_64 fdatasync01 fdatasync01 fdatasync02 fdatasync02 diff --git a/testcases/kernel/syscalls/fcntl/fcntl38.c b/testcases/kernel/syscalls/fcntl/fcntl38.c new file mode 100644 index 000000000..6185d3209 --- /dev/null +++ b/testcases/kernel/syscalls/fcntl/fcntl38.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 CTERA Networks. All Rights Reserved. + * + * Started by Amir Goldstein + * + * DESCRIPTION + * Check that dnotify event is reported to both parent and subdir + */ + +#include +#include +#include +#include +#include "tst_test.h" +#include "lapi/fcntl.h" + +#define TEST_DIR "test_dir" + +#define TEST_SIG SIGRTMIN+1 + +static int parent_fd, subdir_fd; +static int got_parent_event, got_subdir_event; + +static void dnotify_handler(int sig, siginfo_t *si, void *data __attribute__((unused))) +{ + if (si->si_fd == parent_fd) + got_parent_event = 1; + else if (si->si_fd == subdir_fd) + got_subdir_event = 1; + else + tst_brk(TBROK, "Got unexpected signal %d with si_fd %d", sig, si->si_fd); +} + +static void setup_dnotify(int fd) +{ + struct sigaction act; + + act.sa_sigaction = dnotify_handler; + sigemptyset(&act.sa_mask); + act.sa_flags = SA_SIGINFO; + sigaction(TEST_SIG, &act, NULL); + + TEST(fcntl(fd, F_SETSIG, TEST_SIG)); + if (TST_RET != 0) { + tst_brk(TBROK, "F_SETSIG failed errno = %d : %s", + TST_ERR, strerror(TST_ERR)); + } + TEST(fcntl(fd, F_NOTIFY, DN_ATTRIB|DN_MULTISHOT)); + if (TST_RET != 0) { + tst_brk(TBROK, "F_NOTIFY failed errno = %d : %s", + TST_ERR, strerror(TST_ERR)); + } +} + +static void verify_dnotify(void) +{ + parent_fd = SAFE_OPEN(".", O_RDONLY); + subdir_fd = SAFE_OPEN(TEST_DIR, O_RDONLY); + /* Watch "." and its children for changes */ + setup_dnotify(parent_fd); + /* Also watch subdir itself for changes */ + setup_dnotify(subdir_fd); + /* Generate DN_ATTRIB event on subdir that should send a signal on both fds */ + SAFE_CHMOD(TEST_DIR, 0755); + if (got_parent_event) + tst_res(TPASS, "Got event on parent as expected"); + else + tst_res(TFAIL, "Missing event on parent"); + if (got_subdir_event) + tst_res(TPASS, "Got event on subdir as expected"); + else + tst_res(TFAIL, "Missing event on subdir"); + SAFE_CLOSE(parent_fd); + SAFE_CLOSE(subdir_fd); +} + +static void setup(void) +{ + SAFE_MKDIR(TEST_DIR, 00700); +} + +static void cleanup(void) +{ + if (parent_fd > 0) + SAFE_CLOSE(parent_fd); + if (subdir_fd > 0) + SAFE_CLOSE(subdir_fd); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_dnotify, +}; From patchwork Wed Sep 9 17:57:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360880 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=YDZDyOrj; 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 4BmqWW5JlZz9sTK for ; Thu, 10 Sep 2020 03:58:31 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 22C433C262C for ; Wed, 9 Sep 2020 19:58:29 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) by picard.linux.it (Postfix) with ESMTP id 4DAA23C3228 for ; Wed, 9 Sep 2020 19:57:26 +0200 (CEST) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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-3.smtp.seeweb.it (Postfix) with ESMTPS id F34871A00E5F for ; Wed, 9 Sep 2020 19:57:25 +0200 (CEST) Received: by mail-wm1-x344.google.com with SMTP id q9so3169038wmj.2 for ; Wed, 09 Sep 2020 10:57:25 -0700 (PDT) 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; bh=O3mF9HS/Umpd6BDIUTfY84J4Iag8BHPy8RyC+lI9oUk=; b=YDZDyOrj24Xn6gLYTURjBqlRwE18PUsmE+06wRRkSx/nrSO5vwQObhGEm6YgxlP6+X FpPFl8gxPvyz1FR4IiN3iLkPd8jnnqclh8bZPjp6ThZZyvtD5cHB/MeRHZk8gT9zJ0io XbtYxm/aBrQypBgwh2njhrBclGOLbukvc9exaySpSBvooYs1wYB5emKjRAYXNAKOR6Ap lzOGN07gkUlPwRvE7TM57iZBE/KbmSrwM0flPqvL8IYUjl7IjDYV+ykt6uPdAXXm5009 XojQqhzMUCFMfgnxtnxH6aIRPv+NrwPUID8Xnn9Pzt1gQQAR6daB861zusq8u9FXDdnD 1H5g== 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; bh=O3mF9HS/Umpd6BDIUTfY84J4Iag8BHPy8RyC+lI9oUk=; b=oVjwv66eZTT2KUyBSa/t6xuHfLRMmh1FFK0vGq3X83HUevlV4YpWI51JSqt35iGM2n NFGooBw0zQAdoAKvI61BRPf7T6jHSwSnYTxjpyBO+F9M3/iENA5Ic7YvvAUwi/ilrTmm OeWKEsyqRVN3ey9dNHzOS+eXqrAFZu5uo47NvuFqoiYf3rvip/7qUtcebIYv3C0SYpXw PcQ052wrVRolmLitqqu32nBYtAQlJRCVOleKKXfvl9pvYIUaADDfM9JX51+4whMKm3RU eiSkmM71/sN7EL4Oh2cgZn4WF2syQKnqW5LDGCRcRENqIJ23CdSnKDrstvA+MJz3eHH5 yUTQ== X-Gm-Message-State: AOAM530a8FePEcKhY7hLmN4Afj3ViH2+gAGmK4KHNf6uDbtX8wuWZHXn Oac0BMCY4s04rwOg/NvuS2w= X-Google-Smtp-Source: ABdhPJyL3sZJnLxD/3/aBvUA9WX8AzwMTJJSRR7QIanoPDRfiY1JOWP+PFQ/+hMvIp8KOtCabKhMFQ== X-Received: by 2002:a1c:81c6:: with SMTP id c189mr4607916wmd.124.1599674245478; Wed, 09 Sep 2020 10:57:25 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:25 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:04 +0300 Message-Id: <20200909175707.10670-8-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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-3.smtp.seeweb.it Subject: [LTP] [PATCH 07/10] syscalls/inotify: New test for watches on both parent and child 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Check that an inotify event is reported to both watching parent and watching child when the child metadata changes. Signed-off-by: Amir Goldstein --- runtest/syscalls | 1 + testcases/kernel/syscalls/inotify/.gitignore | 1 + testcases/kernel/syscalls/inotify/inotify10.c | 149 ++++++++++++++++++ 3 files changed, 151 insertions(+) create mode 100644 testcases/kernel/syscalls/inotify/inotify10.c diff --git a/runtest/syscalls b/runtest/syscalls index 376a2bc6b..b556fb85d 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -564,6 +564,7 @@ inotify06 inotify06 inotify07 inotify07 inotify08 inotify08 inotify09 inotify09 +inotify10 inotify10 fanotify01 fanotify01 fanotify02 fanotify02 diff --git a/testcases/kernel/syscalls/inotify/.gitignore b/testcases/kernel/syscalls/inotify/.gitignore index 32ccab5de..da9bfc767 100644 --- a/testcases/kernel/syscalls/inotify/.gitignore +++ b/testcases/kernel/syscalls/inotify/.gitignore @@ -7,3 +7,4 @@ /inotify07 /inotify08 /inotify09 +/inotify10 diff --git a/testcases/kernel/syscalls/inotify/inotify10.c b/testcases/kernel/syscalls/inotify/inotify10.c new file mode 100644 index 000000000..1c43915a8 --- /dev/null +++ b/testcases/kernel/syscalls/inotify/inotify10.c @@ -0,0 +1,149 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 CTERA Networks. All Rights Reserved. + * + * Started by Amir Goldstein + * + * DESCRIPTION + * Check that event is reported to both watching parent and watching child + */ + +#include "config.h" + +#if defined(HAVE_SYS_INOTIFY_H) +# include +#endif +#include +#include +#include "tst_test.h" +#include "inotify.h" + +#if defined(HAVE_SYS_INOTIFY_H) + +#define EVENT_MAX 10 +/* Size of the event structure, not including the name */ +#define EVENT_SIZE (sizeof(struct inotify_event)) +#define EVENT_BUF_LEN (EVENT_MAX * (EVENT_SIZE + 16)) + + +#define BUF_SIZE 256 + +struct event_t { + char name[BUF_SIZE]; + unsigned int mask; + int wd; +}; + +#define TEST_DIR "test_dir" +#define TEST_FILE "test_file" + +struct event_t event_set[EVENT_MAX]; + +char event_buf[EVENT_BUF_LEN]; + +int fd_notify; + +static void verify_inotify(void) +{ + int i = 0, test_num = 0, len; + int wd_parent, wd_dir, wd_file; + int test_cnt = 0; + + fd_notify = SAFE_MYINOTIFY_INIT(); + + /* Set watch on both parent dir and children */ + wd_parent = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, ".", IN_ATTRIB); + wd_dir = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, TEST_DIR, IN_ATTRIB); + wd_file = SAFE_MYINOTIFY_ADD_WATCH(fd_notify, TEST_FILE, IN_ATTRIB); + + /* + * Generate events on file and subdir that should be reported to parent + * dir with name and to children without name. + */ + SAFE_CHMOD(TEST_DIR, 0755); + SAFE_CHMOD(TEST_FILE, 0644); + + event_set[test_cnt].wd = wd_parent; + event_set[test_cnt].mask = IN_ATTRIB | IN_ISDIR; + strcpy(event_set[test_cnt].name, TEST_DIR); + test_cnt++; + event_set[test_cnt].wd = wd_dir; + event_set[test_cnt].mask = IN_ATTRIB | IN_ISDIR; + strcpy(event_set[test_cnt].name, ""); + test_cnt++; + event_set[test_cnt].wd = wd_parent; + event_set[test_cnt].mask = IN_ATTRIB; + strcpy(event_set[test_cnt].name, TEST_FILE); + test_cnt++; + event_set[test_cnt].wd = wd_file; + event_set[test_cnt].mask = IN_ATTRIB; + strcpy(event_set[test_cnt].name, ""); + test_cnt++; + + len = read(fd_notify, event_buf, EVENT_BUF_LEN); + if (len == -1) + tst_brk(TBROK | TERRNO, "read failed"); + + while (i < len) { + struct event_t *expected = &event_set[test_num]; + struct inotify_event *event; + event = (struct inotify_event *)&event_buf[i]; + if (test_num >= test_cnt) { + tst_res(TFAIL, + "got unnecessary event: " + "wd=%d mask=%04x len=%u " + "name=\"%.*s\"", event->wd, event->mask, + event->len, event->len, event->name); + + } else if (expected->wd == event->wd && + expected->mask == event->mask && + !strncmp(expected->name, event->name, event->len)) { + tst_res(TPASS, + "got event: wd=%d mask=%04x " + "cookie=%u len=%u name=\"%.*s\"", + event->wd, event->mask, event->cookie, + event->len, event->len, event->name); + + } else { + tst_res(TFAIL, "got event: wd=%d (expected %d) " + "mask=%04x (expected %x) len=%u " + "name=\"%.*s\" (expected \"%s\")", + event->wd, expected->wd, + event->mask, expected->mask, + event->len, event->len, + event->name, expected->name); + } + test_num++; + i += EVENT_SIZE + event->len; + } + + for (; test_num < test_cnt; test_num++) { + tst_res(TFAIL, "didn't get event: mask=%04x ", + event_set[test_num].mask); + } + + SAFE_CLOSE(fd_notify); +} + +static void setup(void) +{ + SAFE_MKDIR(TEST_DIR, 00700); + SAFE_FILE_PRINTF(TEST_FILE, "1"); +} + +static void cleanup(void) +{ + if (fd_notify > 0) + SAFE_CLOSE(fd_notify); +} + +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_inotify, +}; + +#else + TST_TEST_TCONF("system doesn't have required inotify support"); +#endif /* defined(HAVE_SYS_INOTIFY_H) */ From patchwork Wed Sep 9 17:57:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360881 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=WcBGDD8p; 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 4BmqWh48Yyz9sTK for ; Thu, 10 Sep 2020 03:58:40 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 133A13C2C74 for ; Wed, 9 Sep 2020 19:58:38 +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]) by picard.linux.it (Postfix) with ESMTP id BDE003C3228 for ; Wed, 9 Sep 2020 19:57:27 +0200 (CEST) Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) (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 6A537140074B for ; Wed, 9 Sep 2020 19:57:27 +0200 (CEST) Received: by mail-wm1-x344.google.com with SMTP id w2so3163028wmi.1 for ; Wed, 09 Sep 2020 10:57:27 -0700 (PDT) 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; bh=PzJEgBHJwFG7cam8Xnz7ZG0KIsjKVA8HlbRTsFKM5HI=; b=WcBGDD8p44TOAXzx7mtSdlNQSDz1TSAL9IEpk2Rdno6rB5U7K2nSlU52TFOqNmitli /tANCzoZ+7NzxL3PHkxxwtZbXdQFnbsY4mRFM8GQYNcP/5+aQhtFqAWFe5PGgpwhquAL tRpI2m3GNXdeESWS52O5Eg5HRcq5gMNWVAbqdfQitv2Qgy2rIfuCSwOGleXxvhaUQmsP 564t88KFntDXZEipnEFNl508X4swVFNolOBmmsOnZ1u6sgLT3rbfyEZeRPb3982Lah4c ybZHzQdp2wd1KjRlsvqENSlPJGO5+Im9ymwKVG8eOd7IAWTLGWfRPaUT9qtV2rvGiDNH o5Hw== 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; bh=PzJEgBHJwFG7cam8Xnz7ZG0KIsjKVA8HlbRTsFKM5HI=; b=hSs+rN9FnR6A10gDqHcm4x6ff6Eg2r9yv4U/MW+gZ1i2avmazCInd1o19LLYLlNIG+ f66y1Lumjsbh4sLGpl5ufEKaJY/wbgIeniJ2lmLvhRqrnU9TG7CAfYj4BTaZRx5Ifi/6 Oqm73ExqHZaIw9kldAyolT7mKBZE4LzsyqfEm/6EyU8p/vBh7/jvcyJnzmNkGD9XPVUa C7rECV6n1NTTt6bQGHwftfkQdggIzUsDkAi47Svl2MX/Hc02z/bUvYSTvIg8DmnuajZJ tT1WUZRJTu1f8gbxjbfj4FHw1/HT+bAWIda62Y+dxmicJX8quqKjMRdMzjc08sRrgzaT Ejaw== X-Gm-Message-State: AOAM531sHn5B7hXmDFf/EeDxGoHPgrn9/4MasS2DPBFS8ib38iKCwxFl 6mNKDF1CdsMTf3SDGoIfWfE= X-Google-Smtp-Source: ABdhPJwK02q/NwLB5HBM4GiyRVUeTTksuEwtPv4ivdC+9wyABYH3fomqIa5NCWPih+J2dKZZFfQNQg== X-Received: by 2002:a7b:c241:: with SMTP id b1mr4658439wmj.98.1599674246910; Wed, 09 Sep 2020 10:57:26 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:26 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:05 +0300 Message-Id: <20200909175707.10670-9-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 08/10] syscalls/fanotify09: Add test case with parent and subdir marks 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This test checks handling of events with both parent and mount marks. Generalize the test, and add test case of both parent and subdir marks. Verified that existing test cases still fail on old kernels without the relevant fix commits. Signed-off-by: Amir Goldstein --- .../kernel/syscalls/fanotify/fanotify09.c | 57 ++++++++++++------- 1 file changed, 35 insertions(+), 22 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c index 4336f498f..83210bc1c 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify09.c +++ b/testcases/kernel/syscalls/fanotify/fanotify09.c @@ -6,17 +6,17 @@ * * DESCRIPTION * Check that fanotify handles events on children correctly when - * both inode and mountpoint marks exist. + * both parent and subdir or mountpoint marks exist. * * This is a regression test for commit 54a307ba8d3c: * * fanotify: fix logic of events on child * - * Test case #2 is a regression test for commit b469e7e47c8a: + * Test case #1 is a regression test for commit b469e7e47c8a: * * fanotify: fix handling of events on child sub-directory * - * Test case #3 is a regression test for commit 55bf882c7f13: + * Test case #2 is a regression test for commit 55bf882c7f13: * * fanotify: fix merging marks masks with FAN_ONDIR */ @@ -60,33 +60,45 @@ static int mount_created; static struct tcase { const char *tname; + struct fanotify_mark_type mark; unsigned int ondir; const char *testdir; int nevents; } tcases[] = { { - "Events on children with both inode and mount marks", + "Events on non-dir child with both parent and mount marks", + INIT_FANOTIFY_MARK_TYPE(MOUNT), 0, DIR_NAME, 1, }, { - "Events on children and subdirs with both inode and mount marks", + "Events on non-dir child and subdir with both parent and mount marks", + INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, DIR_NAME, 2, }, { - "Events on files and dirs with both inode and mount marks", + "Events on non-dir child and parent with both parent and mount marks", + INIT_FANOTIFY_MARK_TYPE(MOUNT), FAN_ONDIR, ".", 2, }, + { + "Events on non-dir child and subdir with both parent and subdir marks", + INIT_FANOTIFY_MARK_TYPE(INODE), + FAN_ONDIR, + DIR_NAME, + 2, + }, }; -static void create_fanotify_groups(unsigned int ondir) +static void create_fanotify_groups(struct tcase *tc) { - unsigned int i, onchild; + struct fanotify_mark_type *mark = &tc->mark; + unsigned int i, onchild, ondir = tc->ondir; int ret; for (i = 0; i < NUM_GROUPS; i++) { @@ -94,22 +106,25 @@ static void create_fanotify_groups(unsigned int ondir) FAN_NONBLOCK, O_RDONLY); - /* Add mount mark for each group without MODIFY event */ + /* + * 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; ret = fanotify_mark(fd_notify[i], - FAN_MARK_ADD | FAN_MARK_MOUNT, + FAN_MARK_ADD | mark->flag, FAN_CLOSE_NOWRITE | onchild, - AT_FDCWD, "."); + AT_FDCWD, tc->testdir); if (ret < 0) { tst_brk(TBROK | TERRNO, - "fanotify_mark(%d, FAN_MARK_ADD | " - "FAN_MARK_MOUNT, FAN_MODIFY%s, AT_FDCWD," - " '.') failed", fd_notify[i], - ondir ? " | FAN_ONDIR" : ""); + "fanotify_mark(%d, FAN_MARK_ADD | %s, " + "%x, AT_FDCWD, '%s') failed", + fd_notify[i], mark->name, + FAN_CLOSE_NOWRITE | ondir, tc->testdir); } /* - * Add inode mark on parent for each group with MODIFY - * event, but only one group requests events on child. + * 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. @@ -120,10 +135,8 @@ static void create_fanotify_groups(unsigned int ondir) if (ret < 0) { tst_brk(TBROK | TERRNO, "fanotify_mark(%d, FAN_MARK_ADD, " - "FAN_MODIFY%s%s, AT_FDCWD, '.') failed", - fd_notify[i], - ondir ? " | FAN_ONDIR" : "", - onchild ? " | FAN_EVENT_ON_CHILD" : ""); + "%x, AT_FDCWD, '.') failed", + fd_notify[i], FAN_MODIFY | ondir | onchild); } } } @@ -179,7 +192,7 @@ static void test_fanotify(unsigned int n) tst_res(TINFO, "Test #%d: %s", n, tc->tname); - create_fanotify_groups(tc->ondir); + create_fanotify_groups(tc); /* * generate MODIFY event and no FAN_CLOSE_NOWRITE event. From patchwork Wed Sep 9 17:57:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360882 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=LnYzyhmI; 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 4BmqWv0kTPz9sTK for ; Thu, 10 Sep 2020 03:58:51 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 81CE43C537D for ; Wed, 9 Sep 2020 19:58:48 +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 [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 3443C3C2C31 for ; Wed, 9 Sep 2020 19:57:29 +0200 (CEST) Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) (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 B0A19600688 for ; Wed, 9 Sep 2020 19:57:28 +0200 (CEST) Received: by mail-wm1-x342.google.com with SMTP id a65so3146053wme.5 for ; Wed, 09 Sep 2020 10:57:28 -0700 (PDT) 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; bh=t2O37RCqEx+vn37GcxSotW78+DpeKvQ+YAeDwzG1GYc=; b=LnYzyhmIHsDZafd0UWfyAMg2TKDUpZAQVqJPf+EydhWG2LtvN1pF9UMsscG215nI+U 0WgGZAvXADndP7U3SKjS75dm3aO7kH1hJE6aSLdiST9sV+/5fQwb/qh0N4slBpI/4coy QMXKbTD215PIGCnDFOI9NohxyXwsrhSUesRRaHYMuj6BkNPisaEAiSJry+bOx3tH7uzS 6tmKFYyTt5QmEiuWpEhu61CuKtnXKXDpyYRUdF8H4yNRSvO5Qn+yLAZqBI3J6cs9v6eq wHd4W+VrUKy6p8tKPBXAd4btMMNQmbT5Nfwow87NQpb5XaJ6C/fyPfVG5FHpbFi1MEQM C7JQ== 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; bh=t2O37RCqEx+vn37GcxSotW78+DpeKvQ+YAeDwzG1GYc=; b=Tiad/HHBgb1xY7Mg0MlAsoXaz5VoFauCxUmK45ZTL5EgcMk8Mq61ZMFzk46WZs4ewr ObQISk4C2NxxJc6Q3yDcY1mQaEGbpzhHdrbKdnm20NP7c/0danvnn7bUiO/eAk4Rc6sX 6OTXHhN3gIOTtwySiiWJAph+A6o51d1ACCfNT/01ANyu3dOTXP4V5rsJUjDJmRGgDzMz Zco04vtftRYO2ULZdBNpSmFlV/R5wM6/L5QoafkZ0SlJPGQ2B1ILjLCTSNRfKBsQNpoL w1LoCkVNEHWAAXQPmG0VAA4m8FKKZfRZ+kxgYP3+lJ3f7605uzAsB0zMG2Z42GSgzcxA uCKw== X-Gm-Message-State: AOAM532MfdyUcNRJsNhwZ1FzvWpLlsrm87txQs6uf7N9H5v8XSpxMxw7 vv6Vr0M+Z/lN0LPKMIOtpwxKNn/52L4= X-Google-Smtp-Source: ABdhPJzpJ/knGa1ISiMHpqAtN2X9UtZC5WNcbnlHXteLnh8tgIOaJdXGL8fF+XB96TgBjx+WyvmX/g== X-Received: by 2002:a05:600c:2207:: with SMTP id z7mr4781005wml.42.1599674248197; Wed, 09 Sep 2020 10:57:28 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:27 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:06 +0300 Message-Id: <20200909175707.10670-10-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 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 09/10] syscalls/fanotify10: Test with group flag FAN_REPORT_NAME 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The group flag FAN_REPORT_NAME could change the behavior of merging inode mark mask with sb/mount marks. Add another group class with flag FAN_REPORT_NAME to see how it affects merging of events on kernels that support FAN_REPORT_NAME. On old kernels without FAN_REPORT_NAME support, the new group class is not tested. Signed-off-by: Amir Goldstein --- .../kernel/syscalls/fanotify/fanotify10.c | 72 +++++++++++-------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c index 3cdb25a73..9ebb6d68f 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify10.c +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c @@ -45,16 +45,18 @@ /* reasonable guess as to size of 1024 events */ #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE) -static unsigned int fanotify_prio[] = { +static unsigned int fanotify_class[] = { FAN_CLASS_PRE_CONTENT, FAN_CLASS_CONTENT, - FAN_CLASS_NOTIF + FAN_CLASS_NOTIF, + /* Reporting dfid+name+fid merges events similar to reporting fd */ + FAN_REPORT_DFID_NAME_FID, }; -#define FANOTIFY_PRIORITIES ARRAY_SIZE(fanotify_prio) +#define NUM_CLASSES ARRAY_SIZE(fanotify_class) #define GROUPS_PER_PRIO 3 -static int fd_notify[FANOTIFY_PRIORITIES][GROUPS_PER_PRIO]; +static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO]; static char event_buf[EVENT_BUF_LEN]; @@ -75,6 +77,7 @@ static char event_buf[EVENT_BUF_LEN]; static pid_t child_pid; static int bind_mount_created; +static unsigned int num_classes = NUM_CLASSES; enum { FANOTIFY_INODE, @@ -216,11 +219,23 @@ static int create_fanotify_groups(unsigned int n) mark = &fanotify_mark_types[tc->mark_type]; ignore_mark = &fanotify_mark_types[tc->ignore_mark_type]; - for (p = 0; p < FANOTIFY_PRIORITIES; p++) { + for (p = 0; p < num_classes; p++) { for (i = 0; i < GROUPS_PER_PRIO; i++) { - fd_notify[p][i] = SAFE_FANOTIFY_INIT(fanotify_prio[p] | - FAN_NONBLOCK, - O_RDONLY); + 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]); + } /* * Add mark for each group. @@ -281,7 +296,7 @@ static void cleanup_fanotify_groups(void) { unsigned int i, p; - for (p = 0; p < FANOTIFY_PRIORITIES; p++) { + for (p = 0; p < num_classes; p++) { for (i = 0; i < GROUPS_PER_PRIO; i++) { if (fd_notify[p][i] > 0) SAFE_CLOSE(fd_notify[p][i]); @@ -289,22 +304,23 @@ static void cleanup_fanotify_groups(void) } } -static void verify_event(int group, struct fanotify_event_metadata *event, +static void verify_event(int p, int group, struct fanotify_event_metadata *event, unsigned long long expected_mask) { if (event->mask != expected_mask) { - tst_res(TFAIL, "group %d got event: mask %llx (expected %llx) " - "pid=%u fd=%u", group, (unsigned long long)event->mask, + tst_res(TFAIL, "group %d (%x) got event: mask %llx (expected %llx) " + "pid=%u fd=%u", group, fanotify_class[p], + (unsigned long long) event->mask, (unsigned long long) expected_mask, (unsigned)event->pid, event->fd); } else if (event->pid != child_pid) { - tst_res(TFAIL, "group %d got event: mask %llx pid=%u " - "(expected %u) fd=%u", group, + tst_res(TFAIL, "group %d (%x) got event: mask %llx pid=%u " + "(expected %u) fd=%u", group, fanotify_class[p], (unsigned long long)event->mask, (unsigned)event->pid, (unsigned)getpid(), event->fd); } else { - tst_res(TPASS, "group %d got event: mask %llx pid=%u fd=%u", - group, (unsigned long long)event->mask, + tst_res(TPASS, "group %d (%x) got event: mask %llx pid=%u fd=%u", + group, fanotify_class[p], (unsigned long long)event->mask, (unsigned)event->pid, event->fd); } } @@ -357,7 +373,7 @@ static void test_fanotify(unsigned int n) tst_brk(TBROK, "Child process terminated incorrectly"); /* First verify all groups without matching ignore mask got the event */ - for (p = 0; p < FANOTIFY_PRIORITIES; p++) { + for (p = 0; p < num_classes; p++) { if (p > 0 && !tc->expected_mask_with_ignore) break; @@ -365,9 +381,10 @@ static void test_fanotify(unsigned int n) ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN); if (ret < 0) { if (errno == EAGAIN) { - tst_res(TFAIL, "group %d (prio %d) " + tst_res(TFAIL, "group %d (%x) " "with %s did not get event", - i, p, mark->name); + i, fanotify_class[p], mark->name); + continue; } tst_brk(TBROK | TERRNO, "reading fanotify events failed"); @@ -380,12 +397,12 @@ static void test_fanotify(unsigned int n) } event = (struct fanotify_event_metadata *)event_buf; if (ret > (int)event->event_len) { - tst_res(TFAIL, "group %d (prio %d) with %s " + tst_res(TFAIL, "group %d (%x) with %s " "got more than one event (%d > %d)", - i, p, mark->name, ret, + i, fanotify_class[p], mark->name, ret, event->event_len); } else { - verify_event(i, event, p == 0 ? + verify_event(p, i, event, p == 0 ? tc->expected_mask_without_ignore : tc->expected_mask_with_ignore); } @@ -394,8 +411,7 @@ static void test_fanotify(unsigned int n) } } /* Then verify all groups with matching ignore mask did got the event */ - for (p = 1; p < FANOTIFY_PRIORITIES && - !tc->expected_mask_with_ignore; p++) { + for (p = 1; p < num_classes && !tc->expected_mask_with_ignore; p++) { for (i = 0; i < GROUPS_PER_PRIO; i++) { ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN); if (ret == 0) { @@ -403,15 +419,15 @@ static void test_fanotify(unsigned int n) "zero length read from fanotify fd"); } if (ret > 0) { - tst_res(TFAIL, "group %d (prio %d) with %s and " + tst_res(TFAIL, "group %d (%x) with %s and " "%s ignore mask got event", - i, p, mark->name, ignore_mark->name); + i, fanotify_class[p], mark->name, ignore_mark->name); if (event->fd != FAN_NOFD) SAFE_CLOSE(event->fd); } else if (errno == EAGAIN) { - tst_res(TPASS, "group %d (prio %d) with %s and " + tst_res(TPASS, "group %d (%x) with %s and " "%s ignore mask got no event", - i, p, mark->name, ignore_mark->name); + i, fanotify_class[p], mark->name, ignore_mark->name); } else { tst_brk(TBROK | TERRNO, "reading fanotify events failed"); From patchwork Wed Sep 9 17:57:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 1360883 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=oOLOVlFc; 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 4BmqX55Qblz9sTd for ; Thu, 10 Sep 2020 03:59:01 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1B4DE3C5383 for ; Wed, 9 Sep 2020 19:58:59 +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]) by picard.linux.it (Postfix) with ESMTP id 7DCB93C2C76 for ; Wed, 9 Sep 2020 19:57:30 +0200 (CEST) Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) (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 155BA10007FB for ; Wed, 9 Sep 2020 19:57:30 +0200 (CEST) Received: by mail-wm1-x343.google.com with SMTP id x23so3154332wmi.3 for ; Wed, 09 Sep 2020 10:57:30 -0700 (PDT) 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; bh=21Zy1L9tHSGDp1oGrb0BsRsR967+gvxo/SCNq6Va0kM=; b=oOLOVlFc10WjNrhbR0FeFRA2AZ4yU+/kwMPjZs/tcQ7gTU8tdJ/OHOevoicYZGAfP1 0MYvnrxpxF3W/zM3se8/OYYWNMiW9kOQ24VTHdm0ipoaNy+n0Dg/Lh55FmWPBtUtwlco xcNGwWW0DCpOCJPxJGwV3MzyfloTPIxzWf4898kZW6s7grF+gh9vFd0avsLCDUfOXW2g PokW4ntUTW5xs7a5rBAFVj4OgFoU/Y8W7JlFj42NPLpnwPaBBze+7BKXt81VEBLhxpzA mWojASUoMJngFnwyydjz2ua9fBssrnASAOXcf7NGJN0g+1qsdeZb1Qgbf2MCEYz6KZjj YdUA== 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; bh=21Zy1L9tHSGDp1oGrb0BsRsR967+gvxo/SCNq6Va0kM=; b=qINx8BV0svVP3F35o+v2BkryFnq5F7dBJNBSdcHwG+O/D3CBJxdp1qjKE1jHv8TMju fI4Koj4PyRxS58MDxo7V6O7KBenUrKLGzjlhNsukno+7N6akxjLB0ZvNgfSv4phjhFW6 VQAB/gXyZ14YV2f/zqTd6kC3VEfQ0AP+e41rd/3Zs4NAZyX8a1DejhXp6c0m1sBbL/Vh VzZeXsU7fO13JbTuNHiCmx1a+IvnhTeeDIDw6Md3eFdjuSsh3mAXul9LmEdm/8/Iy5U5 INi+/YX78WZpQ3B77TAKZ228jcaeg7RMGS6Y7RP9YAA0531vk4s6KK07DRtI45rEre3W 6vsg== X-Gm-Message-State: AOAM530fzK6P6HLfafL0tt54eqddxiDV6sbHX82lUlN0O1wIt2JfPycV OYwgzeP46WRjmG261dv88ifJ/kgDjMs= X-Google-Smtp-Source: ABdhPJwLPF3u6uyXEzZcjNlbCrsFFoZVS776PFGaQU2bTogTB3n9yesfOZCRfoPF/BhgVJzbS/iiUQ== X-Received: by 2002:a7b:c056:: with SMTP id u22mr4680065wmc.188.1599674249610; Wed, 09 Sep 2020 10:57:29 -0700 (PDT) Received: from localhost.localdomain ([141.226.8.56]) by smtp.gmail.com with ESMTPSA id z83sm4979714wmb.4.2020.09.09.10.57.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 10:57:29 -0700 (PDT) From: Amir Goldstein To: Petr Vorel Date: Wed, 9 Sep 2020 20:57:07 +0300 Message-Id: <20200909175707.10670-11-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200909175707.10670-1-amir73il@gmail.com> References: <20200909175707.10670-1-amir73il@gmail.com> 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 10/10] syscalls/fanotify10: Add test cases for merge with ignored mask on directory 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 MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Pre kernel v5.9, a child mark with ignored mask would not prevent the delivery of events to a watching parent of that child. This was fixed by kernel commit eca4784cbb18 ("fsnotify: send event to parent and child with single callback"). We add test cases for combination of mark of a directory with ignored mask either watching children or not. Verified that existing test cases still fail on old kernels without the relevant fix commits. In current kernel, there is a limitation that requires setting the event also in the parent's mask for ignore mask to be correctly merged with other marks. This is a temporary workaround that could be removed in the future when the correct behavior could be tested. Signed-off-by: Amir Goldstein --- .../kernel/syscalls/fanotify/fanotify10.c | 109 ++++++++++++++++-- 1 file changed, 99 insertions(+), 10 deletions(-) diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c index 9ebb6d68f..17d2f7578 100644 --- a/testcases/kernel/syscalls/fanotify/fanotify10.c +++ b/testcases/kernel/syscalls/fanotify/fanotify10.c @@ -19,6 +19,10 @@ * Test case #16 is a regression test for commit: * * 2f02fd3fa13e fanotify: fix ignore mask logic for events on child... + * + * Test cases #17-#23 are regression tests for commit: + * + * eca4784cbb18 fsnotify: send event to parent and child with single... */ #define _GNU_SOURCE #include "config.h" @@ -97,6 +101,7 @@ static struct tcase { int mark_type; const char *ignore_path; int ignore_mark_type; + unsigned int ignored_onchild; const char *event_path; unsigned long long expected_mask_with_ignore; unsigned long long expected_mask_without_ignore; @@ -105,24 +110,28 @@ static struct tcase { "ignore mount events created on a specific file", MOUNT_PATH, FANOTIFY_MOUNT, FILE_MNT2, FANOTIFY_INODE, + 0, FILE_PATH, 0, FAN_OPEN }, { "ignore exec mount events created on a specific file", MOUNT_PATH, FANOTIFY_MOUNT, FILE_EXEC_PATH2, FANOTIFY_INODE, + 0, FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, { "don't ignore mount events created on another file", MOUNT_PATH, FANOTIFY_MOUNT, FILE_PATH, FANOTIFY_INODE, + 0, FILE2_PATH, FAN_OPEN, FAN_OPEN }, { "don't ignore exec mount events created on another file", MOUNT_PATH, FANOTIFY_MOUNT, FILE_EXEC_PATH, FANOTIFY_INODE, + 0, FILE2_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, @@ -130,24 +139,28 @@ static struct tcase { "ignore inode events created on a specific mount point", FILE_PATH, FANOTIFY_INODE, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_MNT2, 0, FAN_OPEN }, { "ignore exec inode events created on a specific mount point", FILE_EXEC_PATH, FANOTIFY_INODE, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_EXEC_PATH2, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, { "don't ignore inode events created on another mount point", FILE_MNT2, FANOTIFY_INODE, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_PATH, FAN_OPEN, FAN_OPEN }, { "don't ignore exec inode events created on another mount point", FILE_EXEC_PATH2, FANOTIFY_INODE, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, @@ -155,24 +168,28 @@ static struct tcase { "ignore fs events created on a specific file", MOUNT_PATH, FANOTIFY_FILESYSTEM, FILE_PATH, FANOTIFY_INODE, + 0, FILE_PATH, 0, FAN_OPEN }, { "ignore exec fs events created on a specific file", MOUNT_PATH, FANOTIFY_FILESYSTEM, FILE_EXEC_PATH, FANOTIFY_INODE, + 0, FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, { "don't ignore mount events created on another file", MOUNT_PATH, FANOTIFY_FILESYSTEM, FILE_PATH, FANOTIFY_INODE, + 0, FILE2_PATH, FAN_OPEN, FAN_OPEN }, { "don't ignore exec mount events created on another file", MOUNT_PATH, FANOTIFY_FILESYSTEM, FILE_EXEC_PATH, FANOTIFY_INODE, + 0, FILE2_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, @@ -180,24 +197,28 @@ static struct tcase { "ignore fs events created on a specific mount point", MOUNT_PATH, FANOTIFY_FILESYSTEM, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_MNT2, 0, FAN_OPEN }, { "ignore exec fs events created on a specific mount point", MOUNT_PATH, FANOTIFY_FILESYSTEM, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_EXEC_PATH2, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, { "don't ignore fs events created on another mount point", MOUNT_PATH, FANOTIFY_FILESYSTEM, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_PATH, FAN_OPEN, FAN_OPEN }, { "don't ignore exec fs events created on another mount point", MOUNT_PATH, FANOTIFY_FILESYSTEM, MNT2_PATH, FANOTIFY_MOUNT, + 0, FILE_EXEC_PATH, FAN_OPEN | FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, @@ -205,14 +226,65 @@ static struct tcase { "ignore child exec events created on a specific mount point", MOUNT_PATH, FANOTIFY_INODE, MOUNT_PATH, FANOTIFY_MOUNT, + 0, FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC }, + { + "ignore events on children of directory created on a specific file", + MNT2_PATH, FANOTIFY_INODE, + FILE_PATH, FANOTIFY_INODE, + FAN_EVENT_ON_CHILD, + FILE_PATH, 0, FAN_OPEN + }, + { + "ignore events on file created inside a parent watching children", + FILE_PATH, FANOTIFY_INODE, + MNT2_PATH, FANOTIFY_INODE, + FAN_EVENT_ON_CHILD, + FILE_PATH, 0, FAN_OPEN + }, + { + "don't ignore events on file created inside a parent not watching children", + FILE_PATH, FANOTIFY_INODE, + MNT2_PATH, FANOTIFY_INODE, + 0, + FILE_PATH, FAN_OPEN, FAN_OPEN + }, + { + "ignore mount events created inside a parent watching children", + FILE_PATH, FANOTIFY_MOUNT, + MNT2_PATH, FANOTIFY_INODE, + FAN_EVENT_ON_CHILD, + FILE_PATH, 0, FAN_OPEN + }, + { + "don't ignore mount events created inside a parent not watching children", + FILE_PATH, FANOTIFY_MOUNT, + MNT2_PATH, FANOTIFY_INODE, + 0, + FILE_PATH, FAN_OPEN, FAN_OPEN + }, + { + "ignore fs events created inside a parent watching children", + FILE_PATH, FANOTIFY_FILESYSTEM, + MNT2_PATH, FANOTIFY_INODE, + FAN_EVENT_ON_CHILD, + FILE_PATH, 0, FAN_OPEN + }, + { + "don't ignore fs events created inside a parent not watching children", + FILE_PATH, FANOTIFY_FILESYSTEM, + MNT2_PATH, FANOTIFY_INODE, + 0, + FILE_PATH, FAN_OPEN, FAN_OPEN + }, }; static int create_fanotify_groups(unsigned int n) { struct tcase *tc = &tcases[n]; struct fanotify_mark_type *mark, *ignore_mark; + unsigned int mark_ignored, mask; unsigned int p, i; int ret; @@ -272,20 +344,36 @@ static int create_fanotify_groups(unsigned int n) /* Add ignore mark for groups with higher priority */ if (p == 0) continue; + + mask = FAN_OPEN; + mark_ignored = FAN_MARK_IGNORED_MASK | + FAN_MARK_IGNORED_SURV_MODIFY; +add_mark: ret = fanotify_mark(fd_notify[p][i], - FAN_MARK_ADD | ignore_mark->flag | - FAN_MARK_IGNORED_MASK | - FAN_MARK_IGNORED_SURV_MODIFY, - FAN_OPEN, AT_FDCWD, - tc->ignore_path); + FAN_MARK_ADD | ignore_mark->flag | mark_ignored, + mask, AT_FDCWD, tc->ignore_path); if (ret < 0) { tst_brk(TBROK | TERRNO, - "fanotify_mark(%d, FAN_MARK_ADD | %s | " - "FAN_MARK_IGNORED_MASK | " - "FAN_MARK_IGNORED_SURV_MODIFY, " - "FAN_OPEN, AT_FDCWD, %s) failed", + "fanotify_mark(%d, FAN_MARK_ADD | %s | %s, " + "%x, AT_FDCWD, %s) failed", fd_notify[p][i], ignore_mark->name, - tc->ignore_path); + mark_ignored ? "FAN_MARK_IGNORED_MASK | " + "FAN_MARK_IGNORED_SURV_MODIFY" : "", + mask, tc->ignore_path); + } + + /* + * If ignored mask is on a parent watching children, + * also set the flag FAN_EVENT_ON_CHILD in mark mask. + * This is needed to indicate that parent ignored mask + * should be applied to events on children. + */ + if (tc->ignored_onchild && mark_ignored) { + mask = tc->ignored_onchild; + /* XXX: temporary hack may be removed in the future */ + mask |= FAN_OPEN; + mark_ignored = 0; + goto add_mark; } } } @@ -478,6 +566,7 @@ static struct tst_test test = { .tags = (const struct tst_tag[]) { {"linux-git", "9bdda4e9cf2d"}, {"linux-git", "2f02fd3fa13e"}, + {"linux-git", "eca4784cbb18"}, {} } };