Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2256936pxy; Tue, 3 Aug 2021 01:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy/jK5MuvIC2tEbfvJRw5Guv7OFeITPmY4lZ3O4/w/wDArNF6A7kM5+ZabveM7a29ev/AOf X-Received: by 2002:a17:906:38ce:: with SMTP id r14mr19094104ejd.268.1627979513603; Tue, 03 Aug 2021 01:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627979513; cv=none; d=google.com; s=arc-20160816; b=IF+ey1vFftntqZR5wfdw77QOf1U0rCCzRbX4+zlvq/iRh3UxTeAc/T4JHRHIiztl74 U59N6eoByYMIkUNoubu8xOZwxzAopWiF/H80fF2LVQXMnuNJDPQwozEFAxeQJZbwsa5x VAbFEHRppGf2BEAwsbAo8Hy6DWNllkqU9d9hT/FgboMjKYE5WsLPzVsi7doushUFRbxn lNaAl4u7FLY1mCxzyPyNUOV2XHT5ZMTSc3Qjf9Zx5CDa5yim9RN4UNzzAx8qxeRvDn89 cVQpHY7olMGe5x2ksGqld35Guwt923Y56ay59hW0FF6jTv8T3O5tlcah/dnUPN9GP/wW tRsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uCcXlwSAKTIF37G9Oo5Jh0ZARuxw2IkE3sJLiIMH2tw=; b=R047cQHap9yxzjub0x2xhGp9ByGGjb6lSQ/Mo/WwSacV5Bwtd7ID/aL+L3cFfGPHOW vNicCd9jWOBhiMHO5FeVW6sWk2VIEQMxTkx+/MGYrbRGdK9tUlQBgGpRpQjJYCRnSf14 LurilmlRb3zy6RjWUeeV+BxbPevKKcidmOBV+2Okh6JRT6UkhhjlONFHseXYdhDbks6p 9OkdaXOrKOzMDHddwd7j1k7HRjjW8q+UrffjB8W6w3/5qmK3aMiXsIan77aQ9Z7KQxre d5MhLhjUHsQDcZapCq1E0AyKFFugosw65fpHe9AbuuJMmJ+SqIxBjsCG35Oct0tXz2mA xsSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i075z81c; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dz19si8843508edb.116.2021.08.03.01.31.21; Tue, 03 Aug 2021 01:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=i075z81c; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234541AbhHCIbB (ORCPT + 99 others); Tue, 3 Aug 2021 04:31:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234469AbhHCIbB (ORCPT ); Tue, 3 Aug 2021 04:31:01 -0400 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EFBE4C061764 for ; Tue, 3 Aug 2021 01:30:50 -0700 (PDT) Received: by mail-il1-x12c.google.com with SMTP id j18so15819344ile.8 for ; Tue, 03 Aug 2021 01:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uCcXlwSAKTIF37G9Oo5Jh0ZARuxw2IkE3sJLiIMH2tw=; b=i075z81cME7P4lYR3hb/d99BmR/hPnypw9laAJw02LW/p+NlpiSyc0xxRRh/bl2c+i CpxrWHOMCEuSTSo7UHB4Y8ejtYlsZ7OAvKJvW46KXq3bAFvXTw5eyvkStGeQYuEU15M+ qH0pnVz4/KECR1JZpe6tQ5o/YqCAn7Juo6Dj4kc3NKgx8F7qqrDzf/CtjZPQYjaLDI82 qoDOcddYcsY+ZaFUx2nioejc3aF5BuR1TJzg9GTNTu7CkdRdbGoe3quovx3FaJzghR41 Jvnr+l2YifYVn2LUes+E4hcXjUFIdPuQRQArIKI4eb29d2zCNAHr9B7B+zbVTZGcJGhp C1AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=uCcXlwSAKTIF37G9Oo5Jh0ZARuxw2IkE3sJLiIMH2tw=; b=laXQS5zQphM3xyU1F+RlQ/AewO5MLfcKYXZejKpr7zc30kpOc8YOV1iUR6/YYJBidD 1Y8YaJ0uZgKGLUtr8k7mgyCtV3tGKyTwtD111ZIFTxaZz99+hB/X2we3YTWswsKGwenO RhjII7aNC70aX6nmzMB6JRsiWoKliq1vapVpnegxpnSVLql1oA0xTvUKclXYRsU6zFOF j4DkJ2KWDmhC5VYojUMuFbhw6xu36wpO8u4bv3OzBmoAMSKEASrArcEllzwbR0TR6mO0 2qigcMtbgmV4dFgOXUCNKGdp5Vxqxarm5GgzU3IupCFVTXXKRq0zDZDCboj9nUbvLO6Q tb8g== X-Gm-Message-State: AOAM530t6wQgxQGC5XZoyeWvrvYBASHa2Z32fmfalx1Gktnw8Ay01XWi G7PTkDuuL7WI5cZUFu1a6UD9Tjk0cRVLLvNZqMk= X-Received: by 2002:a05:6e02:1c02:: with SMTP id l2mr275707ilh.9.1627979450356; Tue, 03 Aug 2021 01:30:50 -0700 (PDT) MIME-Version: 1.0 References: <20210802214645.2633028-1-krisman@collabora.com> <20210802214645.2633028-2-krisman@collabora.com> In-Reply-To: <20210802214645.2633028-2-krisman@collabora.com> From: Amir Goldstein Date: Tue, 3 Aug 2021 11:30:39 +0300 Message-ID: Subject: Re: [PATCH 1/7] syscalls/fanotify20: Introduce helpers for FAN_FS_ERROR test To: Gabriel Krisman Bertazi Cc: LTP List , Jan Kara , Ext4 , Khazhismel Kumykov , kernel@collabora.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Tue, Aug 3, 2021 at 12:47 AM Gabriel Krisman Bertazi wrote: > > fanotify20 is a new test validating the FAN_FS_ERROR file system error > event. This adds some basic structure for the next patches. > > The strategy for error reporting testing in fanotify20 goes like this: > > - Generate a broken filesystem > - Start FAN_FS_ERROR monitoring group > - Make the file system notice the error through ordinary operations > - Observe the event generated > > Signed-off-by: Gabriel Krisman Bertazi > --- > testcases/kernel/syscalls/fanotify/.gitignore | 1 + > .../kernel/syscalls/fanotify/fanotify20.c | 135 ++++++++++++++++++ > 2 files changed, 136 insertions(+) > create mode 100644 testcases/kernel/syscalls/fanotify/fanotify20.c > > diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore > index 9554b16b196e..c99e6fff76d6 100644 > --- a/testcases/kernel/syscalls/fanotify/.gitignore > +++ b/testcases/kernel/syscalls/fanotify/.gitignore > @@ -17,4 +17,5 @@ > /fanotify17 > /fanotify18 > /fanotify19 > +/fanotify20 > /fanotify_child > diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c > new file mode 100644 > index 000000000000..50531bd99cc9 > --- /dev/null > +++ b/testcases/kernel/syscalls/fanotify/fanotify20.c > @@ -0,0 +1,135 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > +/* > + * Copyright (c) 2021 Collabora Ltd. > + * > + * Author: Gabriel Krisman Bertazi > + * Based on previous work by Amir Goldstein > + */ > + > +/*\ > + * [Description] > + * Check fanotify FAN_ERROR_FS events triggered by intentionally > + * corrupted filesystems: > + * > + * - Generate a broken filesystem > + * - Start FAN_FS_ERROR monitoring group > + * - Make the file system notice the error through ordinary operations > + * - Observe the event generated > + */ > + > +#define _GNU_SOURCE > +#include "config.h" > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include "tst_test.h" > +#include > +#include > +#include > + > +#ifdef HAVE_SYS_FANOTIFY_H > +#include "fanotify.h" > + > +#ifndef FAN_FS_ERROR > +#define FAN_FS_ERROR 0x00008000 > +#endif > + > +#define BUF_SIZE 256 > +static char event_buf[BUF_SIZE]; > +int fd_notify; > + > +#define MOUNT_PATH "test_mnt" > + > +static const struct test_case { > + char *name; > + void (*trigger_error)(void); > + void (*prepare_fs)(void); > +} testcases[] = { > +}; > + > +int check_error_event_metadata(struct fanotify_event_metadata *event) > +{ > + int fail = 0; > + > + if (event->mask != FAN_FS_ERROR) { > + fail++; > + tst_res(TFAIL, "got unexpected event %llx", > + (unsigned long long)event->mask); > + } > + > + if (event->fd != FAN_NOFD) { > + fail++; > + tst_res(TFAIL, "Weird FAN_FD %llx", > + (unsigned long long)event->mask); > + } > + return fail; > +} > + > +void check_event(char *buf, size_t len, const struct test_case *ex) > +{ > + struct fanotify_event_metadata *event = > + (struct fanotify_event_metadata *) buf; > + > + if (len < FAN_EVENT_METADATA_LEN) > + tst_res(TFAIL, "No event metadata found"); > + > + if (check_error_event_metadata(event)) > + return; > + > + tst_res(TPASS, "Successfully received: %s", ex->name); > +} > + > +static void do_test(unsigned int i) > +{ > + const struct test_case *tcase = &testcases[i]; > + size_t read_len; > + > + tcase->trigger_error(); > + > + read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE); > + > + check_event(event_buf, read_len, tcase); > +} > + > +static void setup(void) > +{ > + unsigned long i; > + > + for (i = 0; i < ARRAY_SIZE(testcases); i++) > + if (testcases[i].prepare_fs) > + testcases[i].prepare_fs(); > + Why is prepare_fs called up front and not on every test case? > + fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF|FAN_REPORT_FID, > + O_RDONLY); > + > + SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD|FAN_MARK_FILESYSTEM, > + FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH); This will cause test to fail on old kernels. You need to start this test with fanotify_events_supported_by_kernel(FAN_FS_ERROR) but you cannot use it as is. Create a macro like REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS which calls fanotify_init_flags_err_msg(...fanotify_events_supported_by_kernel()) and pass init flags as argument to fanotify_events_supported_by_kernel() instead of using hardcoded flags FAN_CLASS_CONTENT. > +} > + > +static void cleanup(void) > +{ > + if (fd_notify > 0) > + SAFE_CLOSE(fd_notify); > +} > + > +static struct tst_test test = { > + .test = do_test, > + .tcnt = ARRAY_SIZE(testcases), > + .setup = setup, > + .cleanup = cleanup, > + .mount_device = 1, > + .mntpoint = MOUNT_PATH, > + .all_filesystems = 0, This is 0 by default Thanks, Amir.