Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp1948628pxy; Mon, 2 Aug 2021 14:47:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqnputT/QZKjLLGgCW8/m69tsykiW0G+ZL6nx7TDsisVtGcuUE8I/ZjEA726vH0dfnJO7v X-Received: by 2002:a02:b798:: with SMTP id f24mr8032973jam.14.1627940841252; Mon, 02 Aug 2021 14:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627940841; cv=none; d=google.com; s=arc-20160816; b=zrbYuU37uqykpu/mELpkAbKL52tYWCR4e0viJPVPgQBWdTR+sgfgb5sh2FrWhNfnx+ 5AabWYToCgKC6IB8c6Os5t2kHUoYCReyXQpJYWvTX1XSWCr6gmfMcjTmH1VF+10DKH/u 0ngB9tNJwd/1E+EqtfD/5xG1Pko1NpTcaxSneP7aHfBMVlM5HNzsd8v4R2rLukmra+IL bMNRM+Av0zFC85adNvtiZSBWeMJ71zxtSCaERdUgnj1lh7NFOFNu1KqNYKZBIS3DaUUz JVuobWU508ekxXiO3zIGx4tNGZqrTyevDJrL+NvrG46lsqVLloZzfQAxHZoKHP83xffu 7lVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=67SqnJXa558bJJCBg3pqQ3YO+BYI2onK8n66wGY98iU=; b=gig4a2225wAxfgyeXScHRmACZJn2Dz8eu/UvbF1+nErmRfunWcOicG75wItaysBYZh 6AfHl9W3tKIm93w/IRIuarxcrcITTglD2r2zmjg9WAhAYEkRSZxhCfRyHP0xj+KaZAQp wAvw864YGlpQjy+X+Fm+h3sdebz92vQ0OP0B2qKGLg/n3iXD+iaLXqaQYgSiYHt6Pa+3 ba4as9EAIDFgISXnDhHPYxBs/vabdU5Hg3QvtmOyCWfxaj/za9pZlBnfHwn9d3MY9CVd Dz80T5+52u7QgCa45gLxkiQP9Aly1mt+jeumTw7d0LPeg1VgfLAFS5jYDbQRe5FDtjMU YiOQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a14si160140jat.106.2021.08.02.14.47.06; Mon, 02 Aug 2021 14:47:21 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231609AbhHBVrL (ORCPT + 99 others); Mon, 2 Aug 2021 17:47:11 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:38196 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbhHBVrK (ORCPT ); Mon, 2 Aug 2021 17:47:10 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id E018A1F42CC2 From: Gabriel Krisman Bertazi To: ltp@lists.linux.it, jack@suse.com, amir73il@gmail.com Cc: linux-ext4@vger.kernel.org, khazhy@google.com, kernel@collabora.com, Gabriel Krisman Bertazi Subject: [PATCH 1/7] syscalls/fanotify20: Introduce helpers for FAN_FS_ERROR test Date: Mon, 2 Aug 2021 17:46:39 -0400 Message-Id: <20210802214645.2633028-2-krisman@collabora.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210802214645.2633028-1-krisman@collabora.com> References: <20210802214645.2633028-1-krisman@collabora.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org 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(); + + 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); +} + +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, + .needs_root = 1, + .dev_fs_type = "ext4" + +}; + +#else + TST_TEST_TCONF("system doesn't have required fanotify support"); +#endif -- 2.32.0