From patchwork Sat Sep 1 04:07:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 964288 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 421mzz6Z7tz9ryn for ; Fri, 31 Aug 2018 14:47:10 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 221643E73A9 for ; Fri, 31 Aug 2018 06:47:07 +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 [217.194.8.4]) by picard.linux.it (Postfix) with ESMTP id 1C2483E6071 for ; Fri, 31 Aug 2018 06:47:05 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-4.smtp.seeweb.it (Postfix) with ESMTP id 17632100060F for ; Fri, 31 Aug 2018 06:47:02 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="44233941" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 Aug 2018 12:47:01 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id B7AC84B6AE13; Fri, 31 Aug 2018 12:47:02 +0800 (CST) Received: from RHEL7U5Alpha_SERVER.g08.fujitsu.local (10.167.220.156) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 31 Aug 2018 12:47:01 +0800 From: Xiao Yang To: Date: Sat, 1 Sep 2018 12:07:41 +0800 Message-ID: <1535774861-27429-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20180830144943.GA20702@rei.lan> References: <20180830144943.GA20702@rei.lan> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: B7AC84B6AE13.ABB29 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: yangx.jy@cn.fujitsu.com X-Spam-Status: No, score=2.5 required=7.0 tests=DATE_IN_FUTURE_12_24 autolearn=disabled version=3.4.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Level: ** X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v4 2/2] 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 directory for creating devices. 1) If tst_test->needs_devfs is set, tst_test->mntpoint must be set as well. 2) If tst_test->needs_devfs is set and the temporary directory is mounted with nodev, we try to mount tmpfs without nodev on tst_test->mntpoint. 3) If tst_test->needs_devfs is set and the temporary directory is mounted without nodev, we just create devices on unmounted tst_test->mntpoint. Signed-off-by: Xiao Yang --- include/tst_test.h | 1 + lib/tst_test.c | 28 ++++++++++++++++++++++++++-- 2 files changed, 27 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..36eb8d5 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -724,6 +724,20 @@ static int prepare_and_mount_ro_fs(const char *dev, return 0; } +static void prepare_and_mount_dev_fs(const char *mntpoint) +{ + const char *flags[] = {"nodev", NULL}; + int mounted_nodev; + + mounted_nodev = tst_path_has_mnt_flags(NULL, NULL, flags); + if (mounted_nodev) { + tst_res(TINFO, "tmpdir isn't suitable for creating devices, " + "so mount tmpfs without nodev on %s", mntpoint); + SAFE_MOUNT(NULL, mntpoint, "tmpfs", 0, NULL); + mntpoint_mounted = 1; + } +} + static void prepare_device(void) { if (tst_test->format_device) { @@ -786,11 +800,21 @@ 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!"); } + if (!!tst_test->needs_rofs + !!tst_test->needs_devfs + + !!tst_test->needs_device > 1) { + tst_brk(TBROK, + "Two or more of needs_{rofs, devfs, device} are set"); + } + + if (tst_test->needs_devfs) + prepare_and_mount_dev_fs(tst_test->mntpoint); + if (tst_test->needs_rofs) { /* If we failed to mount read-only tmpfs. Fallback to * using a device with read-only filesystem.