Skip to content

Commit 0ba83f0

Browse files
committed
Merge tag 'ovl-update-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs
Pull overlayfs update from Amir Goldstein: "Relax the semantics of uuid=off to cater to a use case of overlayfs lower layers on btrfs clones, whose UUID are ephemeral and an upper layer on a different filesystem" * tag 'ovl-update-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/overlayfs/vfs: ovl: relax requirement for uuid=off,index=on
2 parents 1d22968 + 869056d commit 0ba83f0

4 files changed

Lines changed: 24 additions & 20 deletions

File tree

Documentation/filesystems/overlayfs.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,9 +753,9 @@ Note: the mount options index=off,nfs_export=on are conflicting for a
753753
read-write mount and will result in an error.
754754

755755
Note: the mount option uuid=off can be used to replace UUID of the underlying
756-
filesystem in file handles with null, and effectively disable UUID checks. This
756+
filesystem in file handles with null, in order to relax the UUID checks. This
757757
can be useful in case the underlying disk is copied and the UUID of this copy
758-
is changed. This is only applicable if all lower/upper/work directories are on
758+
is changed. This is only applicable if all lower directories are on
759759
the same filesystem, otherwise it will fallback to normal behaviour.
760760

761761

@@ -769,7 +769,7 @@ controlled by the "uuid" mount option, which supports these values:
769769
UUID of overlayfs is null. fsid is taken from upper most filesystem.
770770
- "off":
771771
UUID of overlayfs is null. fsid is taken from upper most filesystem.
772-
UUID of underlying layers is ignored.
772+
UUID of underlying layers is ignored and null used instead.
773773
- "on":
774774
UUID of overlayfs is generated and used to report a unique fsid.
775775
UUID is stored in xattr "trusted.overlay.uuid", making overlayfs fsid

fs/overlayfs/namei.c

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,18 @@ static struct ovl_fh *ovl_get_fh(struct ovl_fs *ofs, struct dentry *upperdentry,
159159
goto out;
160160
}
161161

162+
bool ovl_uuid_match(struct ovl_fs *ofs, const struct super_block *sb,
163+
const uuid_t *uuid)
164+
{
165+
/*
166+
* Make sure that the stored uuid matches the uuid of the lower
167+
* layer where file handle will be decoded.
168+
* In case of uuid=off option just make sure that stored uuid is null.
169+
*/
170+
return ovl_origin_uuid(ofs) ? uuid_equal(uuid, &sb->s_uuid) :
171+
uuid_is_null(uuid);
172+
}
173+
162174
struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
163175
struct vfsmount *mnt, bool connected)
164176
{
@@ -168,14 +180,7 @@ struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
168180
if (!capable(CAP_DAC_READ_SEARCH))
169181
return NULL;
170182

171-
/*
172-
* Make sure that the stored uuid matches the uuid of the lower
173-
* layer where file handle will be decoded.
174-
* In case of uuid=off option just make sure that stored uuid is null.
175-
*/
176-
if (ovl_origin_uuid(ofs) ?
177-
!uuid_equal(&fh->fb.uuid, &mnt->mnt_sb->s_uuid) :
178-
!uuid_is_null(&fh->fb.uuid))
183+
if (!ovl_uuid_match(ofs, mnt->mnt_sb, &fh->fb.uuid))
179184
return NULL;
180185

181186
bytes = (fh->fb.len - offsetof(struct ovl_fb, fid));

fs/overlayfs/overlayfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,8 @@ static inline int ovl_check_fh_len(struct ovl_fh *fh, int fh_len)
710710
return ovl_check_fb_len(&fh->fb, fh_len - OVL_FH_WIRE_OFFSET);
711711
}
712712

713+
bool ovl_uuid_match(struct ovl_fs *ofs, const struct super_block *sb,
714+
const uuid_t *uuid);
713715
struct dentry *ovl_decode_real_fh(struct ovl_fs *ofs, struct ovl_fh *fh,
714716
struct vfsmount *mnt, bool connected);
715717
int ovl_check_origin_fh(struct ovl_fs *ofs, struct ovl_fh *fh, bool connected,

fs/overlayfs/super.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ static bool ovl_lower_uuid_ok(struct ovl_fs *ofs, const uuid_t *uuid)
940940
* disable lower file handle decoding on all of them.
941941
*/
942942
if (ofs->fs[i].is_lower &&
943-
uuid_equal(&ofs->fs[i].sb->s_uuid, uuid)) {
943+
ovl_uuid_match(ofs, ofs->fs[i].sb, uuid)) {
944944
ofs->fs[i].bad_uuid = true;
945945
return false;
946946
}
@@ -952,6 +952,7 @@ static bool ovl_lower_uuid_ok(struct ovl_fs *ofs, const uuid_t *uuid)
952952
static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
953953
{
954954
struct super_block *sb = path->mnt->mnt_sb;
955+
const uuid_t *uuid = ovl_origin_uuid(ofs) ? &sb->s_uuid : &uuid_null;
955956
unsigned int i;
956957
dev_t dev;
957958
int err;
@@ -963,7 +964,7 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
963964
return i;
964965
}
965966

966-
if (!ovl_lower_uuid_ok(ofs, &sb->s_uuid)) {
967+
if (!ovl_lower_uuid_ok(ofs, uuid)) {
967968
bad_uuid = true;
968969
if (ofs->config.xino == OVL_XINO_AUTO) {
969970
ofs->config.xino = OVL_XINO_OFF;
@@ -975,9 +976,8 @@ static int ovl_get_fsid(struct ovl_fs *ofs, const struct path *path)
975976
warn = true;
976977
}
977978
if (warn) {
978-
pr_warn("%s uuid detected in lower fs '%pd2', falling back to xino=%s,index=off,nfs_export=off.\n",
979-
uuid_is_null(&sb->s_uuid) ? "null" :
980-
"conflicting",
979+
pr_warn("%s uuid in non-single lower fs '%pd2', falling back to xino=%s,index=off,nfs_export=off.\n",
980+
uuid_is_null(uuid) ? "null" : "conflicting",
981981
path->dentry, ovl_xino_mode(&ofs->config));
982982
}
983983
}
@@ -1469,10 +1469,7 @@ static int ovl_fill_super_creds(struct fs_context *fc, struct super_block *sb)
14691469
if (!ovl_upper_mnt(ofs))
14701470
sb->s_flags |= SB_RDONLY;
14711471

1472-
if (!ovl_origin_uuid(ofs) && ofs->numfs > 1) {
1473-
pr_warn("The uuid=off requires a single fs for lower and upper, falling back to uuid=null.\n");
1474-
ofs->config.uuid = OVL_UUID_NULL;
1475-
} else if (ovl_has_fsid(ofs) && ovl_upper_mnt(ofs)) {
1472+
if (ovl_has_fsid(ofs) && ovl_upper_mnt(ofs)) {
14761473
/* Use per instance persistent uuid/fsid */
14771474
ovl_init_uuid_xattr(sb, ofs, &ctx->upper);
14781475
}

0 commit comments

Comments
 (0)