Skip to content

Commit cbb44f0

Browse files
committed
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>
1 parent d9544c1 commit cbb44f0

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

Documentation/filesystems/overlayfs.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ UUID and fsid
664664
The UUID of overlayfs instance itself and the fsid reported by statfs(2) are
665665
controlled by the "uuid" mount option, which supports these values:
666666

667-
- "null": (default)
667+
- "null":
668668
UUID of overlayfs is null. fsid is taken from upper most filesystem.
669669
- "off":
670670
UUID of overlayfs is null. fsid is taken from upper most filesystem.
@@ -674,6 +674,12 @@ controlled by the "uuid" mount option, which supports these values:
674674
UUID is stored in xattr "trusted.overlay.uuid", making overlayfs fsid
675675
unique and persistent. This option requires an overlayfs with upper
676676
filesystem that supports xattrs.
677+
- "auto": (default)
678+
UUID is taken from xattr "trusted.overlay.uuid" if it exists.
679+
Upgrade to "uuid=on" on first time mount of new overlay filesystem that
680+
meets the prerequites.
681+
Downgrade to "uuid=null" for existing overlay filesystems that were never
682+
mounted with "uuid=on".
677683

678684

679685
Volatile mount

fs/overlayfs/overlayfs.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ enum {
7171
enum {
7272
OVL_UUID_OFF,
7373
OVL_UUID_NULL,
74+
OVL_UUID_AUTO,
7475
OVL_UUID_ON,
7576
};
7677

@@ -550,7 +551,8 @@ static inline bool ovl_origin_uuid(struct ovl_fs *ofs)
550551

551552
static inline bool ovl_has_fsid(struct ovl_fs *ofs)
552553
{
553-
return ofs->config.uuid == OVL_UUID_ON;
554+
return ofs->config.uuid == OVL_UUID_ON ||
555+
ofs->config.uuid == OVL_UUID_AUTO;
554556
}
555557

556558
/*

fs/overlayfs/params.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ static const struct constant_table ovl_parameter_bool[] = {
6868
static const struct constant_table ovl_parameter_uuid[] = {
6969
{ "off", OVL_UUID_OFF },
7070
{ "null", OVL_UUID_NULL },
71+
{ "auto", OVL_UUID_AUTO },
7172
{ "on", OVL_UUID_ON },
7273
{}
7374
};
@@ -79,7 +80,7 @@ static const char *ovl_uuid_mode(struct ovl_config *config)
7980

8081
static int ovl_uuid_def(void)
8182
{
82-
return OVL_UUID_NULL;
83+
return OVL_UUID_AUTO;
8384
}
8485

8586
static const struct constant_table ovl_parameter_xino[] = {

fs/overlayfs/util.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,28 @@ bool ovl_init_uuid_xattr(struct super_block *sb, struct ovl_fs *ofs,
695695
if (res != -ENODATA)
696696
goto fail;
697697

698+
/*
699+
* With uuid=auto, if uuid xattr is found, it will be used.
700+
* If uuid xattrs is not found, generate a persistent uuid only on mount
701+
* of new overlays where upper root dir is not yet marked as impure.
702+
* An upper dir is marked as impure on copy up or lookup of its subdirs.
703+
*/
704+
if (ofs->config.uuid == OVL_UUID_AUTO) {
705+
res = ovl_path_getxattr(ofs, upperpath, OVL_XATTR_IMPURE, NULL,
706+
0);
707+
if (res > 0) {
708+
/* Any mount of old overlay - downgrade to uuid=null */
709+
ofs->config.uuid = OVL_UUID_NULL;
710+
return true;
711+
} else if (res == -ENODATA) {
712+
/* First mount of new overlay - upgrade to uuid=on */
713+
ofs->config.uuid = OVL_UUID_ON;
714+
} else if (res < 0) {
715+
goto fail;
716+
}
717+
718+
}
719+
698720
/* Generate overlay instance uuid */
699721
uuid_gen(&sb->s_uuid);
700722

0 commit comments

Comments
 (0)