summaryrefslogtreecommitdiffstats
path: root/fs/overlayfs
diff options
context:
space:
mode:
authorAmir Goldstein <amir73il@gmail.com>2023-07-07 10:26:29 +0200
committerAmir Goldstein <amir73il@gmail.com>2023-08-12 18:02:50 +0200
commitcbb44f0935974bba997f8db0458fac5739ae0009 (patch)
treec32f08f3a699457bbcf17a0e6b6e180d50732233 /fs/overlayfs
parentovl: store persistent uuid/fsid with uuid=on (diff)
downloadlinux-cbb44f0935974bba997f8db0458fac5739ae0009.tar.xz
linux-cbb44f0935974bba997f8db0458fac5739ae0009.zip
ovl: auto generate uuid for new overlay filesystems
Add a new mount option uuid=auto, which is the default. If a persistent UUID xattr is found it is used. Otherwise, an existing ovelrayfs with copied up subdirs in upper dir that was never mounted with uuid=on retains the null UUID. A new overlayfs with no copied up subdirs, generates the persistent UUID on first mount. Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Diffstat (limited to 'fs/overlayfs')
-rw-r--r--fs/overlayfs/overlayfs.h4
-rw-r--r--fs/overlayfs/params.c3
-rw-r--r--fs/overlayfs/util.c22
3 files changed, 27 insertions, 2 deletions
diff --git a/fs/overlayfs/overlayfs.h b/fs/overlayfs/overlayfs.h
index 8b026d758eaf..72f57d919aa9 100644
--- a/fs/overlayfs/overlayfs.h
+++ b/fs/overlayfs/overlayfs.h
@@ -71,6 +71,7 @@ enum {
enum {
OVL_UUID_OFF,
OVL_UUID_NULL,
+ OVL_UUID_AUTO,
OVL_UUID_ON,
};
@@ -550,7 +551,8 @@ static inline bool ovl_origin_uuid(struct ovl_fs *ofs)
static inline bool ovl_has_fsid(struct ovl_fs *ofs)
{
- return ofs->config.uuid == OVL_UUID_ON;
+ return ofs->config.uuid == OVL_UUID_ON ||
+ ofs->config.uuid == OVL_UUID_AUTO;
}
/*
diff --git a/fs/overlayfs/params.c b/fs/overlayfs/params.c
index 5a59c87c1dfe..3fc01feb5f12 100644
--- a/fs/overlayfs/params.c
+++ b/fs/overlayfs/params.c
@@ -68,6 +68,7 @@ static const struct constant_table ovl_parameter_bool[] = {
static const struct constant_table ovl_parameter_uuid[] = {
{ "off", OVL_UUID_OFF },
{ "null", OVL_UUID_NULL },
+ { "auto", OVL_UUID_AUTO },
{ "on", OVL_UUID_ON },
{}
};
@@ -79,7 +80,7 @@ static const char *ovl_uuid_mode(struct ovl_config *config)
static int ovl_uuid_def(void)
{
- return OVL_UUID_NULL;
+ return OVL_UUID_AUTO;
}
static const struct constant_table ovl_parameter_xino[] = {
diff --git a/fs/overlayfs/util.c b/fs/overlayfs/util.c
index 8602982ae579..9ebb9598e7ec 100644
--- a/fs/overlayfs/util.c
+++ b/fs/overlayfs/util.c
@@ -695,6 +695,28 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
if (res != -ENODATA)
goto fail;
+ /*
+ * With uuid=auto, if uuid xattr is found, it will be used.
+ * If uuid xattrs is not found, generate a persistent uuid only on mount
+ * of new overlays where upper root dir is not yet marked as impure.
+ * An upper dir is marked as impure on copy up or lookup of its subdirs.
+ */
+ if (ofs->config.uuid == OVL_UUID_AUTO) {
+ res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_IMPURE, NULL,
+ 0);
+ if (res > 0) {
+ /* Any mount of old overlay - downgrade to uuid=null */
+ ofs->config.uuid = OVL_UUID_NULL;
+ return true;
+ } else if (res == -ENODATA) {
+ /* First mount of new overlay - upgrade to uuid=on */
+ ofs->config.uuid = OVL_UUID_ON;
+ } else if (res < 0) {
+ goto fail;
+ }
+
+ }
+
/* Generate overlay instance uuid */
uuid_gen(&sb->s_uuid);