All of lore.kernel.org
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Vivek Goyal <vgoyal@redhat.com>
Cc: Giuseppe Scrivano <gscrivan@redhat.com>,
	Miklos Szeredi <miklos@szeredi.hu>,
	linux-unionfs@vger.kernel.org
Subject: [PATCH 1/2] Stop using bind mounts for --samefs
Date: Wed, 15 Apr 2020 15:01:33 +0300	[thread overview]
Message-ID: <20200415120134.28154-2-amir73il@gmail.com> (raw)
In-Reply-To: <20200415120134.28154-1-amir73il@gmail.com>

The implementation of --samefs uses bind mount to mount
/base/lower at /lower and /base/upper at /upper.

Re-assign the value of cfg.{lower,upper}_mntroot to the path
under base dir instead of using bind mounts.

Also stop the habit of remounting lowerdir ro in set_up(), just to
remount it again rw in mount_union() in case of --samefs.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 mount_union.py   |  8 ++---
 set_up.py        | 84 +++++++++++++++++++++++++++---------------------
 settings.py      | 18 +++++++++++
 unmount_union.py | 19 ++++++-----
 4 files changed, 78 insertions(+), 51 deletions(-)

diff --git a/mount_union.py b/mount_union.py
index 55515af..0b3316a 100644
--- a/mount_union.py
+++ b/mount_union.py
@@ -6,7 +6,6 @@ def mount_union(ctx):
     testdir = cfg.testdir()
     if cfg.testing_none():
         lower_mntroot = cfg.lower_mntroot()
-        system("mount -o remount,rw " + lower_mntroot)
         system("mount -o bind " + lower_mntroot + " " + union_mntroot)
         ctx.note_upper_fs(lower_mntroot, testdir, testdir)
 
@@ -14,14 +13,11 @@ def mount_union(ctx):
         lower_mntroot = cfg.lower_mntroot()
         upper_mntroot = cfg.upper_mntroot()
         if cfg.is_samefs():
-            base_mntroot = cfg.base_mntroot()
-            system("mount -o remount,rw " + base_mntroot)
             try:
-                os.mkdir(base_mntroot + upper_mntroot)
+                os.mkdir(upper_mntroot)
             except OSError:
                 pass
-            system("mount -o bind " + base_mntroot + upper_mntroot + " " + upper_mntroot)
-        else:
+        elif cfg.should_mount_upper():
             system("mount " + upper_mntroot + " 2>/dev/null"
                     " || mount -t tmpfs upper_layer " + upper_mntroot)
         layer_mntroot = upper_mntroot + "/" + ctx.curr_layer()
diff --git a/set_up.py b/set_up.py
index c3fad21..afdf5ba 100644
--- a/set_up.py
+++ b/set_up.py
@@ -12,9 +12,7 @@ def create_file(name, content):
 def set_up(ctx):
     cfg = ctx.config()
     lower_mntroot = cfg.lower_mntroot()
-    lowerdir = cfg.lowerdir()
-    lowerimg = cfg.lowerimg()
-    testdir = cfg.testdir()
+    upper_mntroot = cfg.upper_mntroot()
 
     os.sync()
 
@@ -26,12 +24,13 @@ def set_up(ctx):
         except RuntimeError:
             pass
 
-        try:
-            while system("grep -q 'lower_layer " + lower_mntroot + "' /proc/mounts" +
-                         " && umount " + lower_mntroot):
+        if cfg.should_mount_lower():
+            try:
+                while system("grep -q 'lower_layer " + lower_mntroot + "' /proc/mounts" +
+                             " && umount " + lower_mntroot):
+                    pass
+            except RuntimeError:
                 pass
-        except RuntimeError:
-            pass
 
     if cfg.testing_overlayfs():
         try:
@@ -41,59 +40,70 @@ def set_up(ctx):
         except RuntimeError:
             pass
 
-        try:
-            while system("grep -q 'lower_layer " + cfg.base_mntroot() + "' /proc/mounts" +
-                         " && umount " + cfg.base_mntroot()):
+        if cfg.should_mount_base():
+            try:
+                while system("grep -q 'lower_layer " + cfg.base_mntroot() + "' /proc/mounts" +
+                             " && umount " + cfg.base_mntroot()):
+                    pass
+            except RuntimeError:
                 pass
-        except RuntimeError:
-            pass
 
-        try:
-            while system("grep -q 'lower_layer " + lower_mntroot + "' /proc/mounts" +
-                         " && umount " + lower_mntroot):
+        if cfg.should_mount_lower():
+            try:
+                while system("grep -q 'lower_layer " + lower_mntroot + "' /proc/mounts" +
+                             " && umount " + lower_mntroot):
+                    pass
+            except RuntimeError:
                 pass
-        except RuntimeError:
-            pass
+
+        # Adjust lower/upper path in case of --samefs
+        if cfg.is_samefs():
+            base_mntroot = cfg.base_mntroot()
+            lower_mntroot = base_mntroot + "/lower"
+            cfg.set_lower_mntroot(lower_mntroot)
+            upper_mntroot = base_mntroot + "/upper"
+            cfg.set_upper_mntroot(upper_mntroot)
 
         try:
-            # grep filter to catch <lower|upper|N>_layer, in case upper and lower are on same fs
+            # grep filter to catch <lower|upper|N>_layer, in case of --ovov --samefs
             # and in case different layers are on different fs
-            while system("grep -q '_layer " + cfg.upper_mntroot() + "/' /proc/mounts" +
-                         " && umount " + cfg.upper_mntroot() + "/* 2>/dev/null"):
+            while system("grep -q '_layer " + upper_mntroot + "/' /proc/mounts" +
+                         " && umount " + upper_mntroot + "/* 2>/dev/null"):
                 pass
         except RuntimeError:
             pass
 
-        try:
-            # grep filter to catch <low|upp>er_layer, in case upper and lower are on same fs
-            while system("grep -q 'er_layer " + cfg.upper_mntroot() + "' /proc/mounts" +
-                         " && umount " + cfg.upper_mntroot()):
+        if cfg.should_mount_upper():
+            try:
+                while system("grep -q 'upper_layer " + cfg.upper_mntroot() + "' /proc/mounts" +
+                             " && umount " + cfg.upper_mntroot()):
+                    pass
+            except RuntimeError:
                 pass
-        except RuntimeError:
-            pass
 
-    if cfg.is_samefs() and cfg.testing_overlayfs():
+    if cfg.should_mount_base():
         # Create base fs for both lower and upper
-        base_mntroot = cfg.base_mntroot()
         system("mount " + base_mntroot + " 2>/dev/null"
                 " || mount -t tmpfs lower_layer " + base_mntroot)
         system("mount --make-private " + base_mntroot)
+
+    if cfg.is_samefs():
         try:
-            os.mkdir(base_mntroot + lower_mntroot)
+            os.mkdir(lower_mntroot)
         except OSError:
             pass
-        system("mount -o bind " + base_mntroot + lower_mntroot + " " + lower_mntroot)
-    else:
+    elif cfg.should_mount_lower():
         # Create a lower layer to union over
         system("mount " + lower_mntroot + " 2>/dev/null"
                 " || mount -t tmpfs lower_layer " + lower_mntroot)
-
-    # Systemd has weird ideas about things
-    system("mount --make-private " + lower_mntroot)
+        system("mount --make-private " + lower_mntroot)
 
     #
     # Create a few test files we can use in the lower layer
     #
+    lowerdir = cfg.lowerdir()
+    lowerimg = cfg.lowerimg()
+    testdir = cfg.testdir()
     try:
         os.mkdir(lowerdir)
     except OSError:
@@ -176,7 +186,7 @@ def set_up(ctx):
         system("mksquashfs " + lowerdir + " " + lowerimg + " -keep-as-directory > /dev/null");
         system("mount -o loop,ro " + lowerimg + " " + lower_mntroot)
         system("mount --make-private " + lower_mntroot)
-    else:
-        # The mount has to be read-only for us to make use of it
+    elif cfg.should_mount_lower_ro():
+        # Make overlay lower layer read-only
         system("mount -o remount,ro " + lower_mntroot)
     ctx.note_lower_fs(lowerdir)
diff --git a/settings.py b/settings.py
index 12015c8..ced9cae 100644
--- a/settings.py
+++ b/settings.py
@@ -61,10 +61,28 @@ class config:
         self.__union_mntroot = "/mnt"
         self.__testing_overlayfs = True
 
+    # base dir is mounted only for --ov --samefs
+    def should_mount_base(self):
+        return self.testing_overlayfs() and self.is_samefs()
     def base_mntroot(self):
         return self.__base_mntroot
+    # lower dir is mounted ro for --ov (without --samefs) ...
+    def should_mount_lower_ro(self):
+        return self.testing_overlayfs() and not self.is_samefs()
+    # ... and mounted rw for --no
+    def should_mount_lower_rw(self):
+        return self.testing_none()
+    def should_mount_lower(self):
+        return self.should_mount_lower_ro() or self.should_mount_lower_rw()
+    def set_lower_mntroot(self, path):
+        self.__lower_mntroot = path
     def lower_mntroot(self):
         return self.__lower_mntroot
+    # upper dir is mounted for --ov (without --samefs)
+    def should_mount_upper(self):
+        return self.testing_overlayfs() and not self.is_samefs()
+    def set_upper_mntroot(self, path):
+        self.__upper_mntroot = path
     def upper_mntroot(self):
         return self.__upper_mntroot
     def union_mntroot(self):
diff --git a/unmount_union.py b/unmount_union.py
index a83d457..f8f38af 100644
--- a/unmount_union.py
+++ b/unmount_union.py
@@ -6,18 +6,21 @@ def unmount_union(ctx):
     check_not_tainted()
 
     if cfg.testing_overlayfs():
-        if cfg.is_samefs():
-            system("umount " + cfg.base_mntroot())
-            check_not_tainted()
         # unmount individual layers with maxfs > 0
         if cfg.maxfs() > 0 or cfg.is_nested:
             try:
                 system("umount " + cfg.upper_mntroot() + "/* 2>/dev/null")
             except RuntimeError:
                 pass
-        check_not_tainted()
-        system("umount " + cfg.upper_mntroot())
-        check_not_tainted()
+            check_not_tainted()
 
-    system("umount " + cfg.lower_mntroot())
-    check_not_tainted()
+        if cfg.should_mount_base():
+            system("umount " + cfg.base_mntroot())
+            check_not_tainted()
+        elif cfg.should_mount_upper():
+            system("umount " + cfg.upper_mntroot())
+            check_not_tainted()
+
+    if cfg.should_mount_lower():
+        system("umount " + cfg.lower_mntroot())
+        check_not_tainted()
-- 
2.17.1


  reply	other threads:[~2020-04-15 12:04 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-15 12:01 [PATCH 0/2] Prepare for running unionmount testssuite from Amir Goldstein
2020-04-15 12:01 ` Amir Goldstein [this message]
2020-04-15 12:01 ` [PATCH 2/2] Configure custom layers via environment variables Amir Goldstein
2020-04-15 15:30   ` Vivek Goyal
2020-04-15 16:27     ` Amir Goldstein
2020-04-15 19:42       ` Vivek Goyal
2020-04-16  7:10         ` Amir Goldstein
2020-04-16 12:58           ` Vivek Goyal
2020-04-16 13:49             ` Amir Goldstein
2020-04-18  9:57               ` Amir Goldstein
2020-04-20 19:14                 ` Vivek Goyal
2020-04-21  5:57                   ` Amir Goldstein
2020-05-17  8:45                     ` Amir Goldstein
2020-05-22 14:36                       ` Vivek Goyal
2020-05-22 17:19                         ` Amir Goldstein
2020-05-24 10:28                           ` Amir Goldstein
2020-05-26 12:54                             ` Vivek Goyal

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=20200415120134.28154-2-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=gscrivan@redhat.com \
    --cc=linux-unionfs@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=vgoyal@redhat.com \
    /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.