Skip to contentSkip to conversation

erofs: derive fsid from on-disk UUID for .statfs() if possible

PATCH Superseded Hongzhen Luo 3 participants 4 messages Apr 9, 2024 EROFS file system

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 erofs: derive fsid from on-disk UUID for .statfs() if possible

Use the superblock's UUID to generate the fsid when it's non-null.

---
 fs/erofs/super.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
fs/erofs/super.c +5 -7
index c0eb139adb07..83bd8ee3b5ba 100644
@@ -923,22 +923,20 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct super_block *sb = dentry->d_sb;
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
-	u64 id = 0;
-
-	if (!erofs_is_fscache_mode(sb))
-		id = huge_encode_dev(sb->s_bdev->bd_dev);
 
 	buf->f_type = sb->s_magic;
 	buf->f_bsize = sb->s_blocksize;
 	buf->f_blocks = sbi->total_blocks;
 	buf->f_bfree = buf->f_bavail = 0;
-
 	buf->f_files = ULLONG_MAX;
 	buf->f_ffree = ULLONG_MAX - sbi->inos;
-
 	buf->f_namelen = EROFS_NAME_LEN;
 
-	buf->f_fsid    = u64_to_fsid(id);
+	if (uuid_is_null(&sb->s_uuid))
+		buf->f_fsid = u64_to_fsid(erofs_is_fscache_mode(sb) ? 0 :
+				huge_encode_dev(sb->s_bdev->bd_dev));
+	else
+		buf->f_fsid = uuid_to_fsid((__u8 *)&sb->s_uuid);
 	return 0;
 }
 
Signature · 1 line
2.37.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 3 lines · Hongzhen Luo

Use the superblock's UUID to generate the fsid when it's non-null.

Thanks,
Gao Xiang

Quoted 36 lines
---
  fs/erofs/super.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
fs/erofs/super.c +5 -7
index c0eb139adb07..83bd8ee3b5ba 100644
@@ -923,22 +923,20 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
  {
  	struct super_block *sb = dentry->d_sb;
  	struct erofs_sb_info *sbi = EROFS_SB(sb);
-	u64 id = 0;
-
-	if (!erofs_is_fscache_mode(sb))
-		id = huge_encode_dev(sb->s_bdev->bd_dev);
 
  	buf->f_type = sb->s_magic;
  	buf->f_bsize = sb->s_blocksize;
  	buf->f_blocks = sbi->total_blocks;
  	buf->f_bfree = buf->f_bavail = 0;
-
  	buf->f_files = ULLONG_MAX;
  	buf->f_ffree = ULLONG_MAX - sbi->inos;
-
  	buf->f_namelen = EROFS_NAME_LEN;
 
-	buf->f_fsid    = u64_to_fsid(id);
+	if (uuid_is_null(&sb->s_uuid))
+		buf->f_fsid = u64_to_fsid(erofs_is_fscache_mode(sb) ? 0 :
+				huge_encode_dev(sb->s_bdev->bd_dev));
+	else
+		buf->f_fsid = uuid_to_fsid((__u8 *)&sb->s_uuid);
  	return 0;
  }
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to Hongzhen Luo
Quoted 26 lines · Hongzhen Luo

Use the superblock's UUID to generate the fsid when it's non-null.

---
 fs/erofs/super.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
fs/erofs/super.c +0 -5
index c0eb139adb07..83bd8ee3b5ba 100644
@@ -923,22 +923,20 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
 {
 	struct super_block *sb = dentry->d_sb;
 	struct erofs_sb_info *sbi = EROFS_SB(sb);
-	u64 id = 0;
-
-	if (!erofs_is_fscache_mode(sb))
-		id = huge_encode_dev(sb->s_bdev->bd_dev);
 
 	buf->f_type = sb->s_magic;
 	buf->f_bsize = sb->s_blocksize;
 	buf->f_blocks = sbi->total_blocks;
 	buf->f_bfree = buf->f_bavail = 0;
-
 	buf->f_files = ULLONG_MAX;

fs/erofs/super.c static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 939

Quoted 10 lines
fs/erofs/super.c +5 -2
 	buf->f_ffree = ULLONG_MAX - sbi->inos;
-
 	buf->f_namelen = EROFS_NAME_LEN;
 
-	buf->f_fsid    = u64_to_fsid(id);
+	if (uuid_is_null(&sb->s_uuid))
+		buf->f_fsid = u64_to_fsid(erofs_is_fscache_mode(sb) ? 0 :
+				huge_encode_dev(sb->s_bdev->bd_dev));
+	else
+		buf->f_fsid = uuid_to_fsid((__u8 *)&sb->s_uuid);

How about

	buf->f_fsid = uuid_to_fsid(sb->s_uuid.b);

which looks cleaner.

Otherwise LGTM.

Signature · 2 lines
Thanks,
Jingbo
#3 lore raw
Quoted 40 lines · Jingbo Xu
Quoted 26 lines · Hongzhen Luo

Use the superblock's UUID to generate the fsid when it's non-null.

---
  fs/erofs/super.c | 12 +++++-------
  1 file changed, 5 insertions(+), 7 deletions(-)
fs/erofs/super.c +0 -5
index c0eb139adb07..83bd8ee3b5ba 100644
@@ -923,22 +923,20 @@ static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf)
  {
  	struct super_block *sb = dentry->d_sb;
  	struct erofs_sb_info *sbi = EROFS_SB(sb);
-	u64 id = 0;
-
-	if (!erofs_is_fscache_mode(sb))
-		id = huge_encode_dev(sb->s_bdev->bd_dev);
 
  	buf->f_type = sb->s_magic;
  	buf->f_bsize = sb->s_blocksize;
  	buf->f_blocks = sbi->total_blocks;
  	buf->f_bfree = buf->f_bavail = 0;
-
  	buf->f_files = ULLONG_MAX;

fs/erofs/super.c static int erofs_statfs(struct dentry *dentry, struct kstatfs *buf) · line 939

Quoted 10 lines
fs/erofs/super.c +5 -2
  	buf->f_ffree = ULLONG_MAX - sbi->inos;
-
  	buf->f_namelen = EROFS_NAME_LEN;
 
-	buf->f_fsid    = u64_to_fsid(id);
+	if (uuid_is_null(&sb->s_uuid))
+		buf->f_fsid = u64_to_fsid(erofs_is_fscache_mode(sb) ? 0 :
+				huge_encode_dev(sb->s_bdev->bd_dev));
+	else
+		buf->f_fsid = uuid_to_fsid((__u8 *)&sb->s_uuid);

How about

Quoted 9 lines
	buf->f_fsid = uuid_to_fsid(sb->s_uuid.b);

which looks cleaner.

Otherwise LGTM.

Thanks. I will send v2 later.

---

Hongzhen