Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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/20210322173944.449469-2-amir73il@gmail.com
Acked-by: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Jan Kara <jack@suse.cz>

authored by

Amir Goldstein and committed by
Jan Kara
9591c3a3 22d483b9

+11 -12
+1 -4
fs/ext2/super.c
··· 1399 1399 struct super_block *sb = dentry->d_sb; 1400 1400 struct ext2_sb_info *sbi = EXT2_SB(sb); 1401 1401 struct ext2_super_block *es = sbi->s_es; 1402 - u64 fsid; 1403 1402 1404 1403 spin_lock(&sbi->s_lock); 1405 1404 ··· 1452 1453 buf->f_ffree = ext2_count_free_inodes(sb); 1453 1454 es->s_free_inodes_count = cpu_to_le32(buf->f_ffree); 1454 1455 buf->f_namelen = EXT2_NAME_LEN; 1455 - fsid = le64_to_cpup((void *)es->s_uuid) ^ 1456 - le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 1457 - buf->f_fsid = u64_to_fsid(fsid); 1456 + buf->f_fsid = uuid_to_fsid(es->s_uuid); 1458 1457 spin_unlock(&sbi->s_lock); 1459 1458 return 0; 1460 1459 }
+1 -4
fs/ext4/super.c
··· 6148 6148 struct ext4_sb_info *sbi = EXT4_SB(sb); 6149 6149 struct ext4_super_block *es = sbi->s_es; 6150 6150 ext4_fsblk_t overhead = 0, resv_blocks; 6151 - u64 fsid; 6152 6151 s64 bfree; 6153 6152 resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters)); 6154 6153 ··· 6168 6169 buf->f_files = le32_to_cpu(es->s_inodes_count); 6169 6170 buf->f_ffree = percpu_counter_sum_positive(&sbi->s_freeinodes_counter); 6170 6171 buf->f_namelen = EXT4_NAME_LEN; 6171 - fsid = le64_to_cpup((void *)es->s_uuid) ^ 6172 - le64_to_cpup((void *)es->s_uuid + sizeof(u64)); 6173 - buf->f_fsid = u64_to_fsid(fsid); 6172 + buf->f_fsid = uuid_to_fsid(es->s_uuid); 6174 6173 6175 6174 #ifdef CONFIG_QUOTA 6176 6175 if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
+1 -4
fs/zonefs/super.c
··· 1104 1104 struct super_block *sb = dentry->d_sb; 1105 1105 struct zonefs_sb_info *sbi = ZONEFS_SB(sb); 1106 1106 enum zonefs_ztype t; 1107 - u64 fsid; 1108 1107 1109 1108 buf->f_type = ZONEFS_MAGIC; 1110 1109 buf->f_bsize = sb->s_blocksize; ··· 1126 1127 1127 1128 spin_unlock(&sbi->s_lock); 1128 1129 1129 - fsid = le64_to_cpup((void *)sbi->s_uuid.b) ^ 1130 - le64_to_cpup((void *)sbi->s_uuid.b + sizeof(u64)); 1131 - buf->f_fsid = u64_to_fsid(fsid); 1130 + buf->f_fsid = uuid_to_fsid(sbi->s_uuid.b); 1132 1131 1133 1132 return 0; 1134 1133 }
+8
include/linux/statfs.h
··· 4 4 5 5 #include <linux/types.h> 6 6 #include <asm/statfs.h> 7 + #include <asm/byteorder.h> 7 8 8 9 struct kstatfs { 9 10 long f_type; ··· 49 48 static inline __kernel_fsid_t u64_to_fsid(u64 v) 50 49 { 51 50 return (__kernel_fsid_t){.val = {(u32)v, (u32)(v>>32)}}; 51 + } 52 + 53 + /* Fold 16 bytes uuid to 64 bit fsid */ 54 + static inline __kernel_fsid_t uuid_to_fsid(__u8 *uuid) 55 + { 56 + return u64_to_fsid(le64_to_cpup((void *)uuid) ^ 57 + le64_to_cpup((void *)(uuid + sizeof(u64)))); 52 58 } 53 59 54 60 #endif