[Devel] [PATCH RHEL COMMIT] ovl: make uuid=off compatible with overlayfs created without it

Konstantin Khorenko khorenko at virtuozzo.com
Mon Oct 4 20:39:08 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 5664c3689ae258506f94bc32a658394860c4cc65
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Mon Oct 4 20:39:08 2021 +0300

    ovl: make uuid=off compatible with overlayfs created without it
    
    Patch makes mainstream "uuid=off" compatible with our reverted
    "index=nouuid" option.
    
    To make overlayfs mounts in containers be copyable by vzmlocal (which
    implies uuid change) we need to set "uuid=off" by default for all
    overlayfs mounts. So add CONFIG_OVERLAY_FS_UUID_OFF and uuid module
    param to configure defaults.
    
    To make overlayfs mounts created on older kernel without "uuid=off" also
    copyable by vzmlocal we also need to skip uuid checks. Mainstream
    version compares uuid with zero, but old overlayfs mount xattrs can
    store non-zero uuids as fhandles already.
    
    https://jira.sw.ru/browse/PSBM-123536
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    ====================
    Patchset descrition:
    
    ovl: replace "index=nouuid" with "uuid=off"
    
    Mainstream base is a bit different so we need some more ovl_fs
    propagation to functions. Also we still need some vz-specific hunks
    which were not allowed to mainstream overlay, so add them as a separate
    patch.
    
    https://jira.sw.ru/browse/PSBM-123536
    
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
    
    Pavel Tikhomirov (4):
      Revert "ovl: introduce new "index=nouuid" option for inodes index
        feature"
      ovl: propagate ovl_fs to ovl_decode_real_fh and ovl_encode_real_fh
      ovl: introduce new "uuid=off" option for inodes index feature
      ovl: make uuid=off compatible with overlayfs created without it
    
    Rebased to vz9:
     - dropped all patches already present in ms
    
    (cherry picked from vz8 commit 8d81d6d2563c029fdd8c26064ca0fdbc6666120b)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 fs/overlayfs/Kconfig                                  | 16 ++++++++++++++++
 fs/overlayfs/namei.c                                  | 19 ++++++++++++++++---
 fs/overlayfs/super.c                                  | 11 ++++++++---
 .../generic/CONFIG_OVERLAY_FS_UUID_OFF                |  1 +
 4 files changed, 41 insertions(+), 6 deletions(-)

diff --git a/fs/overlayfs/Kconfig b/fs/overlayfs/Kconfig
index 1ba9411d9a6a..ed4176101cff 100644
--- a/fs/overlayfs/Kconfig
+++ b/fs/overlayfs/Kconfig
@@ -61,6 +61,22 @@ config OVERLAY_FS_INDEX
 
 	  If unsure, say N.
 
+config OVERLAY_FS_UUID_OFF
+       bool "Overlayfs: skip uuid checks for fhandles"
+       depends on OVERLAY_FS
+       depends on OVERLAY_FS_INDEX
+       help
+         If this config option is enabled then overlay will skip uuid checks
+         for index lower to upper inode map, this only can be done if all
+         upper and lower directories are on the same filesystem where basic
+         fhandles are uniq.
+
+         It is needed to overcome possible change of uuid on superblock of the
+         backing filesystem, e.g. when you copied the virtual disk and mount
+         both the copy of the disk and the original one at the same time.
+
+         If unsure, say N.
+
 config OVERLAY_FS_NFS_EXPORT
 	bool "Overlayfs: turn on NFS export feature by default"
 	depends on OVERLAY_FS
diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index 210cd6f66e28..4aec6b29f717 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -164,8 +164,11 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
 	 * layer where file handle will be decoded.
 	 * In case of uuid=off option just make sure that stored uuid is null.
 	 */
-	if (ofs->config.uuid ? !uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid) :
-			      !uuid_is_null(&fh->fb.uuid))
+	/* Virtuozzo: Skip uuid is zero check when uuid=off is set for
+	 * compatibility with older containers which had overlayfs mounts
+	 * mounted without it and have non-zero uuid in fhandles.
+	 */
+	if (ofs->config.uuid && !uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid))
 		return NULL;
 
 	bytes = (fh->fb.len - offsetof(struct ovl_fb, fid));
@@ -432,8 +435,18 @@ static int ovl_verify_fh(struct ovl_fs *ofs, struct dentry *dentry,
 	if (IS_ERR(ofh))
 		return PTR_ERR(ofh);
 
-	if (fh->fb.len != ofh->fb.len || memcmp(&fh->fb, &ofh->fb, fh->fb.len))
+	if (fh->fb.len != ofh->fb.len) {
 		err = -ESTALE;
+	} else {
+		/*
+		 * Virtuozzo: Skip uuid comparison check when uuid=off is set
+		 * for compatibility.
+		 */
+		if (!ofs->config.uuid && !uuid_equal(&fh->fb.uuid, &ofh->fb.uuid))
+			ofh->fb.uuid = fh->fb.uuid;
+		if (memcmp(&fh->fb, &ofh->fb, fh->fb.len))
+			err = -ESTALE;
+	}
 
 	kfree(ofh);
 	return err;
diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c
index 2f497065f688..d85596325846 100644
--- a/fs/overlayfs/super.c
+++ b/fs/overlayfs/super.c
@@ -43,6 +43,11 @@ module_param_named(index, ovl_index_def, bool, 0644);
 MODULE_PARM_DESC(index,
 		 "Default to on or off for the inodes index feature");
 
+static bool ovl_uuid_def = !IS_ENABLED(CONFIG_OVERLAY_FS_UUID_OFF);
+module_param_named(uuid, ovl_uuid_def, bool, 0644);
+MODULE_PARM_DESC(uuid,
+		 "Default to on or off for the inodes uuid feature");
+
 static bool ovl_nfs_export_def = IS_ENABLED(CONFIG_OVERLAY_FS_NFS_EXPORT);
 module_param_named(nfs_export, ovl_nfs_export_def, bool, 0644);
 MODULE_PARM_DESC(nfs_export,
@@ -403,8 +408,8 @@ static int ovl_show_options(struct seq_file *m, struct dentry *dentry)
 		seq_printf(m, ",redirect_dir=%s", ofs->config.redirect_mode);
 	if (ofs->config.index != ovl_index_def)
 		seq_printf(m, ",index=%s", ofs->config.index ? "on" : "off");
-	if (!ofs->config.uuid)
-		seq_puts(m, ",uuid=off");
+	if (ofs->config.uuid != ovl_uuid_def)
+		seq_printf(m, ",uuid=%s", ofs->config.uuid ? "on" : "off");
 	if (ofs->config.nfs_export != ovl_nfs_export_def)
 		seq_printf(m, ",nfs_export=%s", ofs->config.nfs_export ?
 						"on" : "off");
@@ -2022,7 +2027,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
 	ofs->share_whiteout = true;
 
 	ofs->config.index = ovl_index_def;
-	ofs->config.uuid = true;
+	ofs->config.uuid = ovl_uuid_def;
 	ofs->config.nfs_export = ovl_nfs_export_def;
 	ofs->config.xino = ovl_xino_def();
 	ofs->config.metacopy = ovl_metacopy_def;
diff --git a/redhat/configs/custom-overrides/generic/CONFIG_OVERLAY_FS_UUID_OFF b/redhat/configs/custom-overrides/generic/CONFIG_OVERLAY_FS_UUID_OFF
new file mode 100644
index 000000000000..1529aadfedcb
--- /dev/null
+++ b/redhat/configs/custom-overrides/generic/CONFIG_OVERLAY_FS_UUID_OFF
@@ -0,0 +1 @@
+CONFIG_OVERLAY_FS_UUID_OFF=y


More information about the Devel mailing list