All of lore.kernel.org
 help / color / mirror / Atom feed
From: Murphy Zhou <xzhou@redhat.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v4 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint
Date: Sat, 25 May 2019 19:51:11 +0800	[thread overview]
Message-ID: <20190525115112.15399-1-xzhou@redhat.com> (raw)
In-Reply-To: <20190524122357.GA28108@dell5510>

Define constraints of needed overlayfs dirs;
create_overlay_dirs() to create lower/upper/work dirs;
mount_overlay() to mount overlayfs;
SAFE_MOUNT_OVERLAY macro to mount overlayfs safely, tst_brk TCONF
if mount fail with errno ENODEV;
TST_MOUNT_OVERLAY  macro to mount overlayfs and return 0 if succeeds;

Suggested-by: Petr Vorel <pvorel@suse.cz>
Suggested-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Murphy Zhou <xzhou@redhat.com>
---
v4:
  Update ENODEV handle logic
  Define TST_MOUNT_OVERLAY and SAFE_MOUNT_OVERLAY macros
  Change helper names
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  |  4 ++++
 include/tst_fs.h            |  6 +++++
 include/tst_safe_file_ops.h |  6 +++++
 lib/tst_fs_setup.c          | 46 +++++++++++++++++++++++++++++++++++++
 4 files changed, 62 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..526454da7 100644
--- a/include/safe_file_ops_fn.h
+++ b/include/safe_file_ops_fn.h
@@ -76,4 +76,8 @@ 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 create_overlay_dirs(void);
+int mount_overlay(const char *file, const int lineno, int safe);
+
 #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..b62a7447f 100644
--- a/include/tst_safe_file_ops.h
+++ b/include/tst_safe_file_ops.h
@@ -59,4 +59,10 @@
 	safe_touch(__FILE__, __LINE__, NULL, \
 			(pathname), (mode), (times))
 
+#define SAFE_MOUNT_OVERLAY() \
+	((void) mount_overlay(__FILE__, __LINE__, 1))
+
+#define TST_MOUNT_OVERLAY() \
+	(mount_overlay(__FILE__, __LINE__, 0) == 0)
+
 #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..de09c7135
--- /dev/null
+++ b/lib/tst_fs_setup.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * DESCRIPTION
+ *	A place for setup filesystem helpers.
+ */
+
+#include <stdint.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/vfs.h>
+#include <sys/mount.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_fs.h"
+
+void create_overlay_dirs(void)
+{
+	SAFE_MKDIR(OVL_LOWER, 0755);
+	SAFE_MKDIR(OVL_UPPER, 0755);
+	SAFE_MKDIR(OVL_WORK, 0755);
+	SAFE_MKDIR(OVL_MNT, 0755);
+}
+
+int mount_overlay(const char *file, const int lineno, int safe)
+{
+	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) {
+			if (safe) {
+				tst_brk(TCONF, cfgmsg);
+			} else {
+				tst_res(TINFO, cfgmsg);
+				return 1;
+			}
+		} else {
+			tst_brk(TBROK | TERRNO, "overlayfs mount failed");
+		}
+	}
+	return 0;
+}
-- 
2.21.0


  parent reply	other threads:[~2019-05-25 11:51 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-30  4:39 [LTP] [PATCH] OVL_MNT: put overlayfs lower, upper, work, mnt dir in separated mountpoint Murphy Zhou
2019-04-30  8:18 ` Li Wang
2019-05-03 21:00 ` Petr Vorel
2019-05-15  9:21   ` [LTP] [PATCH v2 1/2] OVL_MNT: add setup_overlay helper Murphy Zhou
2019-05-15  9:21     ` [LTP] [PATCH v2 2/2] OVL_MNT: put overlayfs lower, upper, work, mnt dir in a separated mountpoint Murphy Zhou
2019-05-15 13:39       ` Petr Vorel
2019-05-16  9:14         ` Murphy Zhou
2019-05-15 13:31     ` [LTP] [PATCH v2 1/2] OVL_MNT: add setup_overlay helper Petr Vorel
2019-05-15 13:42       ` Petr Vorel
2019-05-15 14:30         ` Amir Goldstein
2019-05-15 18:20           ` Petr Vorel
2019-05-16  9:15             ` Murphy Zhou
2019-05-24  4:48         ` Murphy Zhou
2019-05-24  7:30           ` Petr Vorel
2019-05-24  9:04             ` [LTP] [PATCH v3 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint Murphy Zhou
2019-05-24  9:04               ` [LTP] [PATCH v3 2/2] OVL_MNT: setup overlayfs dirs and mount in a separated mountpoint Murphy Zhou
2019-05-24  4:32       ` [LTP] [PATCH v2 1/2] OVL_MNT: add setup_overlay helper Murphy Zhou
2019-05-24  8:54         ` Petr Vorel
2019-05-24 11:24           ` Amir Goldstein
2019-05-24 12:23             ` Petr Vorel
2019-05-24 13:44               ` Murphy Zhou
2019-05-25 11:51               ` Murphy Zhou [this message]
2019-05-25 11:51                 ` [LTP] [PATCH v4 2/2] OVL_MNT: setup overlayfs dirs and mount in a separated mountpoint Murphy Zhou
2019-05-27 12:09                 ` [LTP] [PATCH v4 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint Petr Vorel
2019-05-27 13:17                   ` Amir Goldstein
2019-05-27 15:27                     ` Petr Vorel
2019-05-27 13:38                   ` Murphy Zhou
2019-05-27 15:36                     ` Petr Vorel
2019-05-29  7:49                       ` Murphy Zhou
2019-05-29 10:18                       ` [LTP] [PATCH v5 " Murphy Zhou
2019-05-29 10:18                         ` [LTP] [PATCH v5 2/2] OVL_MNT: setup overlayfs dirs and mount in a separated mountpoint Murphy Zhou
2019-05-29 10:55                           ` Amir Goldstein
2019-05-29 10:59                         ` [LTP] [PATCH v5 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint Amir Goldstein
2019-05-30  2:41                           ` Murphy Zhou
2019-05-30  2:53                           ` [LTP] [PATCH v6 " Murphy Zhou
2019-05-30  2:53                             ` [LTP] [PATCH v6 2/2] OVL_MNT: setup overlayfs dirs and mount in a separated mountpoint Murphy Zhou
2019-06-03  7:12                               ` Petr Vorel
2019-06-03  5:06                             ` [LTP] [PATCH v6 1/2] OVL_MNT: add helpers to setup overlayfs mountpoint Petr Vorel
2019-05-24 13:36           ` [LTP] [PATCH v2 1/2] OVL_MNT: add setup_overlay helper Murphy Zhou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190525115112.15399-1-xzhou@redhat.com \
    --to=xzhou@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.