From patchwork Thu Aug 16 08:45:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 958158 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=none (p=none dis=none) header.from=cn.fujitsu.com Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41rg0r39hcz9s3C for ; Thu, 16 Aug 2018 18:46:20 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B5CE93E6500 for ; Thu, 16 Aug 2018 10:46:17 +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 D76C83E64D0 for ; Thu, 16 Aug 2018 10:46:05 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id 229CB1A00F77 for ; Thu, 16 Aug 2018 10:46:04 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43532037" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Aug 2018 16:45:54 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 3564C4B6EC6B; Thu, 16 Aug 2018 16:45:52 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.399.0; Thu, 16 Aug 2018 16:45:56 +0800 From: Xiao Yang To: Date: Thu, 16 Aug 2018 16:45:45 +0800 Message-ID: <1534409147-29519-2-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1534409147-29519-1-git-send-email-yangx.jy@cn.fujitsu.com> References: <20180815114220.GA26923@rei> <1534409147-29519-1-git-send-email-yangx.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 3564C4B6EC6B.A999A X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=0.0 required=7.0 tests=none autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-3.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v2 2/4] lib/tst_test.c: add .needs_devfs flag 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" We add .needs_devfs flag to prepare a suitable filesystem to test device special files and use ext2 instead of tmpfs(because tmpfs doesn't support extended attributes) as default filesystem if .dev_fs_type is not specified. Signed-off-by: Xiao Yang --- include/tst_test.h | 1 + lib/tst_test.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/include/tst_test.h b/include/tst_test.h index f7d109a..4cc6202 100644 --- a/include/tst_test.h +++ b/include/tst_test.h @@ -129,6 +129,7 @@ struct tst_test { int mount_device:1; int needs_rofs:1; int child_needs_reinit:1; + int needs_devfs:1; /* * If set the test function will be executed for all available * filesystems and the current filesytem type would be set in the diff --git a/lib/tst_test.c b/lib/tst_test.c index 2f3d357..039c78f 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -724,6 +724,22 @@ static int prepare_and_mount_ro_fs(const char *dev, return 0; } +static void prepare_and_mount_dev_fs(const char *dev, + const char *mntpoint, + const char *fs_type) +{ + const char *flags[] = {"nodev", NULL}; + char abs_path[PATH_MAX]; + + sprintf(abs_path, "%s/%s", tst_get_tmpdir(), mntpoint); + + SAFE_MOUNT(dev, mntpoint, fs_type, MS_MGC_VAL, NULL); + mntpoint_mounted = 1; + + if (tst_path_has_mnt_flags(NULL, abs_path, flags)) + tst_brk(TBROK, "%s is mounted with nodev", fs_type); +} + static void prepare_device(void) { if (tst_test->format_device) { @@ -737,6 +753,12 @@ static void prepare_device(void) return; } + if (tst_test->needs_devfs) { + prepare_and_mount_dev_fs(tdev.dev, tst_test->mntpoint, + tdev.fs_type); + return; + } + if (tst_test->mount_device) { SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type, tst_test->mnt_flags, tst_test->mnt_data); @@ -778,6 +800,11 @@ static void do_setup(int argc, char *argv[]) if (tst_test->all_filesystems) tst_test->needs_device = 1; + if (tst_test->needs_devfs) { + tst_test->needs_device = 1; + tst_test->format_device = 1; + } + setup_ipc(); if (needs_tmpdir() && !tst_tmpdir_created()) @@ -786,8 +813,9 @@ static void do_setup(int argc, char *argv[]) if (tst_test->mntpoint) SAFE_MKDIR(tst_test->mntpoint, 0777); - if ((tst_test->needs_rofs || tst_test->mount_device || - tst_test->all_filesystems) && !tst_test->mntpoint) { + if ((tst_test->needs_devfs || tst_test->needs_rofs || + tst_test->mount_device || tst_test->all_filesystems) && + !tst_test->mntpoint) { tst_brk(TBROK, "tst_test->mntpoint must be set!"); }