From patchwork Fri Aug 17 04:33:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiao Yang X-Patchwork-Id: 958644 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=213.254.12.146; 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 [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41s9MD062mz9s3Z for ; Fri, 17 Aug 2018 14:33:59 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1CBA83E6F0E for ; Fri, 17 Aug 2018 06:33:57 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) by picard.linux.it (Postfix) with ESMTP id 271603E68B4 for ; Fri, 17 Aug 2018 06:33:43 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-5.smtp.seeweb.it (Postfix) with ESMTP id 3D692600A42 for ; Fri, 17 Aug 2018 06:33:40 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.43,368,1503331200"; d="scan'208";a="43564155" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 17 Aug 2018 12:33:39 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 8C3BC4B6AE13; Fri, 17 Aug 2018 12:33:39 +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; Fri, 17 Aug 2018 12:33:40 +0800 From: Xiao Yang To: Date: Fri, 17 Aug 2018 12:33:35 +0800 Message-ID: <1534480415-18932-1-git-send-email-yangx.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20180816132815.GB30369@rei> References: <20180816132815.GB30369@rei> MIME-Version: 1.0 X-Originating-IP: [10.167.220.156] X-yoursite-MailScanner-ID: 8C3BC4B6AE13.AB943 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-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: ltp@lists.linux.it Subject: [LTP] [PATCH v3 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 tst_test->mntpoint is on a temporary directory that is mounted with nodev, we try to mount tmpfs without nodev over tst_test->mntpoint. 3) If tst_test->needs_devfs is set and tst_test->mntpoint is on a temporary directory that 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 | 23 +++++++++++++++++++++-- 2 files changed, 22 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..329bf8d 100644 --- a/lib/tst_test.c +++ b/lib/tst_test.c @@ -724,6 +724,21 @@ 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}; + char abs_path[PATH_MAX]; + + sprintf(abs_path, "%s/%s", tst_get_tmpdir(), mntpoint); + + if (tst_path_has_mnt_flags(NULL, abs_path, flags)) { + tst_res(TINFO, "%s isn't suitable for creating devices, " + "so mount tmpfs without nodev over it", abs_path); + SAFE_MOUNT(NULL, mntpoint, "tmpfs", 0, NULL); + mntpoint_mounted = 1; + } +} + static void prepare_device(void) { if (tst_test->format_device) { @@ -786,11 +801,15 @@ 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_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.