From patchwork Fri May 24 09:04:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murphy Zhou X-Patchwork-Id: 1104728 X-Patchwork-Delegate: petr.vorel@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=redhat.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 459L6d0Y5nz9s3l for ; Fri, 24 May 2019 19:04:57 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 600F13EA637 for ; Fri, 24 May 2019 11:04:54 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) by picard.linux.it (Postfix) with ESMTP id A0E673EA2D1 for ; Fri, 24 May 2019 11:04:52 +0200 (CEST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 9CBDC60162F for ; Fri, 24 May 2019 11:04:51 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6275AC0733C9; Fri, 24 May 2019 09:04:49 +0000 (UTC) Received: from localhost (dhcp-12-130.nay.redhat.com [10.66.12.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1133110027B9; Fri, 24 May 2019 09:04:47 +0000 (UTC) From: Murphy Zhou To: pvorel@suse.cz Date: Fri, 24 May 2019 17:04:40 +0800 Message-Id: <20190524090441.21586-1-xzhou@redhat.com> In-Reply-To: <20190524073045.GA29592@dell5510> References: <20190524073045.GA29592@dell5510> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 24 May 2019 09:04:49 +0000 (UTC) X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: liwan@redhat.com, ltp@lists.linux.it Subject: [LTP] [PATCH v3 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Also defined constraints of needed overlayfs dirs. setup_overlayfs_files() to create lower/upper/work dirs. safe_mount_overlayfs() to mount overlayfs. Signed-off-by: Murphy Zhou --- v3: Split setup to 2 parts: creating files and mounting. Use macro SAFE_MOUNT_OVERLAYFS. Handle ENODEV differently for 4 testcases we have modified. v2: define constraints in header file. add a setup helper to create dirs and mount. include/safe_file_ops_fn.h | 5 ++++ include/tst_fs.h | 6 ++++ include/tst_safe_file_ops.h | 3 ++ lib/tst_fs_setup.c | 56 +++++++++++++++++++++++++++++++++++++ 4 files changed, 70 insertions(+) create mode 100644 lib/tst_fs_setup.c diff --git a/include/safe_file_ops_fn.h b/include/safe_file_ops_fn.h index 35ec4fb1f..2491fa40c 100644 --- a/include/safe_file_ops_fn.h +++ b/include/safe_file_ops_fn.h @@ -76,4 +76,9 @@ void safe_touch(const char *file, const int lineno, const char *pathname, mode_t mode, const struct timespec times[2]); +/* helper functions to setup overlayfs mountpoint */ +void setup_overlayfs_files(void); + +int safe_mount_overlayfs(const char *file, const int lineno, + void (cleanup_fn)(void), int infoflag); #endif /* SAFE_FILE_OPS_FN */ diff --git a/include/tst_fs.h b/include/tst_fs.h index 423ca82ec..ce110b723 100644 --- a/include/tst_fs.h +++ b/include/tst_fs.h @@ -50,6 +50,12 @@ enum { TST_GB = 1073741824, }; +#define OVL_BASE_MNTPOINT "mntpoint" +#define OVL_LOWER OVL_BASE_MNTPOINT"/lower" +#define OVL_UPPER OVL_BASE_MNTPOINT"/upper" +#define OVL_WORK OVL_BASE_MNTPOINT"/work" +#define OVL_MNT OVL_BASE_MNTPOINT"/ovl" + /* * @path: path is the pathname of any file within the mounted file system * @mult: mult should be TST_KB, TST_MB or TST_GB diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h index 5c3fea4e2..d211b40ff 100644 --- a/include/tst_safe_file_ops.h +++ b/include/tst_safe_file_ops.h @@ -59,4 +59,7 @@ safe_touch(__FILE__, __LINE__, NULL, \ (pathname), (mode), (times)) +#define SAFE_MOUNT_OVERLAYFS(flag) \ + safe_mount_overlayfs(__FILE__, __LINE__, NULL, (flag)) + #endif /* TST_SAFE_FILE_OPS */ diff --git a/lib/tst_fs_setup.c b/lib/tst_fs_setup.c new file mode 100644 index 000000000..0f28beb61 --- /dev/null +++ b/lib/tst_fs_setup.c @@ -0,0 +1,56 @@ +/* + * DESCRIPTION + * A place for setup filesystem helpers. + */ + +#include +#include +#include +#include +#include +#include + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_fs.h" + +void setup_overlayfs_files(void) +{ + SAFE_MKDIR(OVL_LOWER, 0755); + SAFE_MKDIR(OVL_UPPER, 0755); + SAFE_MKDIR(OVL_WORK, 0755); + SAFE_MKDIR(OVL_MNT, 0755); +} + +int safe_mount_overlayfs(const char *file, const int lineno, + void (cleanup_fn)(void), int infoflag) +{ + int ret = 0; + char *cfgmsg = "overlayfs is not configured in this kernel."; + + ret = mount("overlay", OVL_MNT, "overlay", 0, "lowerdir="OVL_LOWER + ",upperdir="OVL_UPPER",workdir="OVL_WORK); + if (ret < 0) { + if (errno == ENODEV) { + /* To keep the original test logic of testcases, use + infoflag to handle ENODEV differently. Like + execveat03 inotify0{7,8} readahead02. */ + switch (infoflag) { + case 1: + tst_res(TINFO, cfgmsg); + return 1; + case 2: + tst_brk(TCONF, cfgmsg); + break; + case 3: + tst_brk(TCONF, cfgmsg); + default: + tst_brk(TBROK | TERRNO, "overlayfs mount failed"); + break; + } + } else { + tst_brk(TBROK | TERRNO, "overlayfs mount failed"); + } + } + return 0; +}