Skip to contentSkip to conversation

VFS API for getting filesystem's UUID

PATCH In review Amir Goldstein 5 participants 12 messages Apr 27, 2017 – Apr 30, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover VFS API for getting filesystem's UUID

Miklos,

As you observed, the sb->s_uuid field is not always filled by filesystems.

Consumers, like overlayfs, that wish to use this field can check if is zeroed out as an indication for valid value.

Christoph suggested to make the test more explicit and require the filesystems that fill the s_uuid field to set a super block flag.

Do you agree with the proposed API?

The first patch in the series defines the flag.
If you push this patch through your tree to Al or Linus, then filesystem maintainers could later pick the individual patches to their trees.

The xfs patch is based on a patch I already sent to Darrick for filling out the s_uuid field.

Thanks,
Amir.

Amir Goldstein (5):
vfs: define a flag to indicate sb->s_uuid is available
ext4: set the super block SB_I_HAVE_UUID flag
f2fs: set the super block SB_I_HAVE_UUID flag
ocfs2: set the super block SB_I_HAVE_UUID flag
xfs: set the super block SB_I_HAVE_UUID flag

 fs/ext4/super.c    | 1 +
 fs/f2fs/super.c    | 1 +
 fs/ocfs2/super.c   | 1 +
 fs/xfs/xfs_mount.c | 1 +
 include/linux/fs.h | 3 +++
 5 files changed, 7 insertions(+)
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/5 vfs: define a flag to indicate sb->s_uuid is available

Overlayfs would like to make use of underlying filesystem's sb->s_uuid, but not all filesytems fill this field.

Define a flag to be set by filesystems that do fill the s_uuid field, so let consumers like overlayfs know that the content of this field is valid.

---
 include/linux/fs.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/fs.h +3 -0
index 80daadf..de913b4 100644
@@ -1272,6 +1272,9 @@ struct mm_struct;
 /* sb->s_iflags to limit user namespace mounts */
 #define SB_I_USERNS_VISIBLE		0x00000010 /* fstype already mounted */
 
+/* sb->s_iflags for optional information available in super_block struct */
+#define SB_I_HAVE_UUID			0x00000100 /* s_uuid */
+
 /* Possible states of 'frozen' field */
 enum {
 	SB_UNFROZEN = 0,		/* FS is unfrozen */
Signature · 1 line
2.7.4
#3 lore raw

PATCH 2/5 ext4: set the super block SB_I_HAVE_UUID flag

In reply to Amir Goldstein

Let consumers (i.e. overlayfs) know that the content of the field sb->s_uuid is valid.

---
 fs/ext4/super.c | 1 +
 1 file changed, 1 insertion(+)
fs/ext4/super.c +1 -0
index 2e03a0a..98e8fb0 100644
@@ -3925,6 +3925,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP | QTYPE_MASK_PRJ;
 #endif
 	memcpy(sb->s_uuid, es->s_uuid, sizeof(es->s_uuid));
+	sb->s_iflags |= SB_I_HAVE_UUID;
 
 	INIT_LIST_HEAD(&sbi->s_orphan); /* unlinked but open files */
 	mutex_init(&sbi->s_orphan_lock);
Signature · 1 line
2.7.4
#4 lore raw

PATCH 3/5 f2fs: set the super block SB_I_HAVE_UUID flag

In reply to Amir Goldstein

Let consumers (i.e. overlayfs) know that the content of the field sb->s_uuid is valid.

---
 fs/f2fs/super.c | 1 +
 1 file changed, 1 insertion(+)
fs/f2fs/super.c +1 -0
index 96fe8ed..9dca352 100644
@@ -1911,6 +1911,7 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent)
 	sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
 		(test_opt(sbi, POSIX_ACL) ? MS_POSIXACL : 0);
 	memcpy(sb->s_uuid, raw_super->uuid, sizeof(raw_super->uuid));
+	sb->s_iflags |= SB_I_HAVE_UUID;
 
 	/* init f2fs-specific super block info */
 	sbi->valid_super_block = valid_super_block;
Signature · 1 line
2.7.4
#6 lore raw

PATCH 5/5 xfs: set the super block SB_I_HAVE_UUID flag

In reply to Amir Goldstein

Let consumers (i.e. overlayfs) know that the content of the field sb->s_uuid is valid.

---
 fs/xfs/xfs_mount.c | 1 +
 1 file changed, 1 insertion(+)
fs/xfs/xfs_mount.c +1 -0
index 29e45a0..bb1d325 100644
@@ -103,6 +103,7 @@ xfs_uuid_mount(
 	/* Publish UUID in struct super_block */
 	BUILD_BUG_ON(sizeof(mp->m_super->s_uuid) != sizeof(uuid_t));
 	memcpy(&mp->m_super->s_uuid, uuid, sizeof(uuid_t));
+	mp->m_super->s_iflags |= SB_I_HAVE_UUID;
 	return 0;
 
  out_duplicate:
Signature · 1 line
2.7.4
#5 lore raw

PATCH 4/5 ocfs2: set the super block SB_I_HAVE_UUID flag

In reply to Amir Goldstein

Let consumers (i.e. overlayfs) know that the content of the field sb->s_uuid is valid.

---
 fs/ocfs2/super.c | 1 +
 1 file changed, 1 insertion(+)
fs/ocfs2/super.c +1 -0
index ca1646f..9c5e701 100644
@@ -2064,6 +2064,7 @@ static int ocfs2_initialize_super(struct super_block *sb,
 	sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
 	memcpy(sb->s_uuid, di->id2.i_super.s_uuid,
 	       sizeof(di->id2.i_super.s_uuid));
+	sb->s_iflags |= SB_I_HAVE_UUID;
 
 	osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
 
Signature · 1 line
2.7.4
#7 lore raw
In reply to Amir Goldstein
Quoted 11 lines · Amir Goldstein

Miklos,

As you observed, the sb->s_uuid field is not always filled by filesystems.

Consumers, like overlayfs, that wish to use this field can check if is zeroed out as an indication for valid value.

Christoph suggested to make the test more explicit and require the filesystems that fill the s_uuid field to set a super block flag.

Do you agree with the proposed API?

Sure.

Thanks,
Miklos

Reviewed-by on v1 1/5
#2 lore raw

Re: [PATCH 1/5] vfs: define a flag to indicate sb->s_uuid is available

In reply to Amir Goldstein
Quoted 17 lines · Amir Goldstein

Overlayfs would like to make use of underlying filesystem's sb->s_uuid, but not all filesytems fill this field.

Define a flag to be set by filesystems that do fill the s_uuid field, so let consumers like overlayfs know that the content of this field is valid.

---
 include/linux/fs.h | 3 +++
 1 file changed, 3 insertions(+)
include/linux/fs.h +0 -0
index 80daadf..de913b4 100644

include/linux/fs.h struct mm_struct; · line 1276

Quoted 5 lines
include/linux/fs.h +2 -0
@@ -1272,6 +1272,9 @@ struct mm_struct;
 /* sb->s_iflags to limit user namespace mounts */
 #define SB_I_USERNS_VISIBLE		0x00000010 /* fstype already mounted */
 
+/* sb->s_iflags for optional information available in super_block struct */
+#define SB_I_HAVE_UUID			0x00000100 /* s_uuid */

SB_I_CAN_HAZ_UUID, heh. :)

There seems to be demand for a "Yes I really filled this out" flag, so for the vfs and xfs parts,

(I wonder why we can't just leave s_uuid as nil and to heck with anyone who deliberately sets their fs to have a nil uuid (like we do now), but whatever... :))

--D

Quoted 11 lines
include/linux/fs.h +1 -0
+
 /* Possible states of 'frozen' field */
 enum {
 	SB_UNFROZEN = 0,		/* FS is unfrozen */
Signature · 6 lines
2.7.4

--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#8 lore raw
In reply to Amir Goldstein
Quoted 29 lines · Amir Goldstein

Miklos,

As you observed, the sb->s_uuid field is not always filled by filesystems.

Consumers, like overlayfs, that wish to use this field can check if is zeroed out as an indication for valid value.

Christoph suggested to make the test more explicit and require the filesystems that fill the s_uuid field to set a super block flag.

Do you agree with the proposed API?

The first patch in the series defines the flag.
If you push this patch through your tree to Al or Linus, then filesystem maintainers could later pick the individual patches to their trees.

The xfs patch is based on a patch I already sent to Darrick for filling out the s_uuid field.

Thanks,
Amir.

Amir Goldstein (5):
vfs: define a flag to indicate sb->s_uuid is available
ext4: set the super block SB_I_HAVE_UUID flag
f2fs: set the super block SB_I_HAVE_UUID flag
ocfs2: set the super block SB_I_HAVE_UUID flag
xfs: set the super block SB_I_HAVE_UUID flag

Quoted 6 lines
 fs/ext4/super.c    | 1 +
 fs/f2fs/super.c    | 1 +
 fs/ocfs2/super.c   | 1 +
 fs/xfs/xfs_mount.c | 1 +
 include/linux/fs.h | 3 +++
 5 files changed, 7 insertions(+)

Doesn't this make the struct export_opierations .get_uuid method somewhat redundant? Shouldn't that now be replaced with generic functions that looks at SB_I_HAVE_UUID before allowing PNFS export is allowed and then just use s_uuid directly in the PNFS code?

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
maintainer
#9 lore raw
Quoted 4 lines · Dave Chinner

Doesn't this make the struct export_opierations .get_uuid method somewhat redundant? Shouldn't that now be replaced with generic functions that looks at SB_I_HAVE_UUID before allowing PNFS export is allowed and then just use s_uuid directly in the PNFS code?

Do we even need a flag? Checking if 16 bytes are not all zeroes isn't hard, after all...

#11 lore raw
In reply to Dave Chinner
Quoted 37 lines · Dave Chinner
Quoted 29 lines · Amir Goldstein

Miklos,

As you observed, the sb->s_uuid field is not always filled by filesystems.

Consumers, like overlayfs, that wish to use this field can check if is zeroed out as an indication for valid value.

Christoph suggested to make the test more explicit and require the filesystems that fill the s_uuid field to set a super block flag.

Do you agree with the proposed API?

The first patch in the series defines the flag.
If you push this patch through your tree to Al or Linus, then filesystem maintainers could later pick the individual patches to their trees.

The xfs patch is based on a patch I already sent to Darrick for filling out the s_uuid field.

Thanks,
Amir.

Amir Goldstein (5):
vfs: define a flag to indicate sb->s_uuid is available
ext4: set the super block SB_I_HAVE_UUID flag
f2fs: set the super block SB_I_HAVE_UUID flag
ocfs2: set the super block SB_I_HAVE_UUID flag
xfs: set the super block SB_I_HAVE_UUID flag

Quoted 6 lines
 fs/ext4/super.c    | 1 +
 fs/f2fs/super.c    | 1 +
 fs/ocfs2/super.c   | 1 +
 fs/xfs/xfs_mount.c | 1 +
 include/linux/fs.h | 3 +++
 5 files changed, 7 insertions(+)
Quoted 5 lines

Doesn't this make the struct export_opierations .get_uuid method somewhat redundant? Shouldn't that now be replaced with generic functions that looks at SB_I_HAVE_UUID before allowing PNFS export is allowed and then just use s_uuid directly in the PNFS code?

There's the tiny issue that get_uuid also returns the offset of the uuid on disk. Not sure how much that really matters for PNFS?

Amir.

#10 lore raw
In reply to Al Viro
Quoted 9 lines · Al Viro
Quoted 4 lines · Dave Chinner

Doesn't this make the struct export_opierations .get_uuid method somewhat redundant? Shouldn't that now be replaced with generic functions that looks at SB_I_HAVE_UUID before allowing PNFS export is allowed and then just use s_uuid directly in the PNFS code?

Do we even need a flag? Checking if 16 bytes are not all zeroes isn't hard, after all...

Nope, it's not hard and that is what we do now.
I posted the flag per Christoph's suggestion to see what others have to say.

Amir.