Skip to content

Commit 9591c3a

Browse files
amir73iljankara
authored andcommitted
fs: introduce a wrapper uuid_to_fsid()
Some filesystem's use a digest of their uuid for f_fsid. Create a simple wrapper for this open coded folding. Filesystems that have a non null uuid but use the block device number for f_fsid may also consider using this helper. [JK: Added missing asm/byteorder.h include] Link: https://lore.kernel.org/r/[email protected] Acked-by: Damien Le Moal <[email protected]> Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Jan Kara <[email protected]>
1 parent 22d483b commit 9591c3a

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

fs/ext2/super.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,6 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
13991399
struct super_block *sb = dentry->d_sb;
14001400
struct ext2_sb_info *sbi = EXT2_SB(sb);
14011401
struct ext2_super_block *es = sbi->s_es;
1402-
u64 fsid;
14031402

14041403
spin_lock(&sbi->s_lock);
14051404

@@ -1453,9 +1452,7 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
14531452
buf->f_ffree = ext2_count_free_inodes(sb);
14541453
es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
14551454
buf->f_namelen = EXT2_NAME_LEN;
1456-
fsid = le64_to_cpup((void *)es->s_uuid) ^
1457-
le64_to_cpup((void *)es->s_uuid + sizeof(u64));
1458-
buf->f_fsid = u64_to_fsid(fsid);
1455+
buf->f_fsid = uuid_to_fsid(es->s_uuid);
14591456
spin_unlock(&sbi->s_lock);
14601457
return 0;
14611458
}

fs/ext4/super.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -6148,7 +6148,6 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
61486148
struct ext4_sb_info *sbi = EXT4_SB(sb);
61496149
struct ext4_super_block *es = sbi->s_es;
61506150
ext4_fsblk_t overhead = 0, resv_blocks;
6151-
u64 fsid;
61526151
s64 bfree;
61536152
resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters));
61546153

@@ -6169,9 +6168,7 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
61696168
buf->f_files = le32_to_cpu(es->s_inodes_count);
61706169
buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter);
61716170
buf->f_namelen = EXT4_NAME_LEN;
6172-
fsid = le64_to_cpup((void *)es->s_uuid) ^
6173-
le64_to_cpup((void *)es->s_uuid + sizeof(u64));
6174-
buf->f_fsid = u64_to_fsid(fsid);
6171+
buf->f_fsid = uuid_to_fsid(es->s_uuid);
61756172

61766173
#ifdef CONFIG_QUOTA
61776174
if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&

fs/zonefs/super.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,6 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
11041104
struct super_block *sb = dentry->d_sb;
11051105
struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
11061106
enum zonefs_ztype t;
1107-
u64 fsid;
11081107

11091108
buf->f_type = ZONEFS_MAGIC;
11101109
buf->f_bsize = sb->s_blocksize;
@@ -1127,9 +1126,7 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
11271126

11281127
spin_unlock(&sbi->s_lock);
11291128

1130-
fsid = le64_to_cpup((void *)sbi->s_uuid.b) ^
1131-
le64_to_cpup((void *)sbi->s_uuid.b + sizeof(u64));
1132-
buf->f_fsid = u64_to_fsid(fsid);
1129+
buf->f_fsid = uuid_to_fsid(sbi->s_uuid.b);
11331130

11341131
return 0;
11351132
}

include/linux/statfs.h

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <linux/types.h>
66
#include <asm/statfs.h>
7+
#include <asm/byteorder.h>
78

89
struct kstatfs {
910
long f_type;
@@ -50,4 +51,11 @@ static inline __kernel_fsid_t u64_to_fsid(u64 v)
5051
return (__kernel_fsid_t){.val = {(u32)v, (u32)(v>>32)}};
5152
}
5253

54+
/* Fold 16 bytes uuid to 64 bit fsid */
55+
static inline __kernel_fsid_t uuid_to_fsid(__u8 *uuid)
56+
{
57+
return u64_to_fsid(le64_to_cpup((void *)uuid) ^
58+
le64_to_cpup((void *)(uuid + sizeof(u64))));
59+
}
60+
5361
#endif

0 commit comments

Comments
 (0)