Skip to content

Commit

Permalink
fs: introduce a wrapper uuid_to_fsid()
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
amir73il authored and jankara committed Apr 19, 2021
1 parent 22d483b commit 9591c3a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
5 changes: 1 addition & 4 deletions fs/ext2/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,6 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
struct super_block *sb = dentry->d_sb;
struct ext2_sb_info *sbi = EXT2_SB(sb);
struct ext2_super_block *es = sbi->s_es;
u64 fsid;

spin_lock(&sbi->s_lock);

Expand Down Expand Up @@ -1453,9 +1452,7 @@ static int ext2_statfs (struct dentry * dentry, struct kstatfs * buf)
buf->f_ffree = ext2_count_free_inodes(sb);
es->s_free_inodes_count = cpu_to_le32(buf->f_ffree);
buf->f_namelen = EXT2_NAME_LEN;
fsid = le64_to_cpup((void *)es->s_uuid) ^
le64_to_cpup((void *)es->s_uuid + sizeof(u64));
buf->f_fsid = u64_to_fsid(fsid);
buf->f_fsid = uuid_to_fsid(es->s_uuid);
spin_unlock(&sbi->s_lock);
return 0;
}
Expand Down
5 changes: 1 addition & 4 deletions fs/ext4/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -6148,7 +6148,6 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)
struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext4_super_block *es = sbi->s_es;
ext4_fsblk_t overhead = 0, resv_blocks;
u64 fsid;
s64 bfree;
resv_blocks = EXT4_C2B(sbi, atomic64_read(&sbi->s_resv_clusters));

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

#ifdef CONFIG_QUOTA
if (ext4_test_inode_flag(dentry->d_inode, EXT4_INODE_PROJINHERIT) &&
Expand Down
5 changes: 1 addition & 4 deletions fs/zonefs/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,6 @@ static int zonefs_statfs(struct dentry *dentry, struct kstatfs *buf)
struct super_block *sb = dentry->d_sb;
struct zonefs_sb_info *sbi = ZONEFS_SB(sb);
enum zonefs_ztype t;
u64 fsid;

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

spin_unlock(&sbi->s_lock);

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

return 0;
}
Expand Down
8 changes: 8 additions & 0 deletions include/linux/statfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <linux/types.h>
#include <asm/statfs.h>
#include <asm/byteorder.h>

struct kstatfs {
long f_type;
Expand Down Expand Up @@ -50,4 +51,11 @@ static inline __kernel_fsid_t u64_to_fsid(u64 v)
return (__kernel_fsid_t){.val = {(u32)v, (u32)(v>>32)}};
}

/* Fold 16 bytes uuid to 64 bit fsid */
static inline __kernel_fsid_t uuid_to_fsid(__u8 *uuid)
{
return u64_to_fsid(le64_to_cpup((void *)uuid) ^
le64_to_cpup((void *)(uuid + sizeof(u64))));
}

#endif

0 comments on commit 9591c3a

Please sign in to comment.