Message ID | 60c0e07d871249ed86b53087c75a1013233da355.1734437595.git.fdmanana@suse.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | btrfs: use uuid_is_null() to verify if an uuid is empty | expand |
On 17.12.24 13:14, fdmanana@kernel.org wrote: > From: Filipe Manana <fdmanana@suse.com> > > At btrfs_is_empty_uuid() we have our custom code to check if an uuid is > empty, however there a kernel uuid library that has a function named > uuid_is_null() which does the same and probably more efficient. > > So change btrfs_is_empty_uuid() to use uuid_is_null(), which is almost > a directy replacement, it just wraps the necessary casting since our ^~ directly Other than that, Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
On Tue, Dec 17, 2024 at 1:27 PM Johannes Thumshirn <Johannes.Thumshirn@wdc.com> wrote: > > On 17.12.24 13:14, fdmanana@kernel.org wrote: > > From: Filipe Manana <fdmanana@suse.com> > > > > At btrfs_is_empty_uuid() we have our custom code to check if an uuid is > > empty, however there a kernel uuid library that has a function named > > uuid_is_null() which does the same and probably more efficient. > > > > So change btrfs_is_empty_uuid() to use uuid_is_null(), which is almost > > a directy replacement, it just wraps the necessary casting since our > ^~ directly Pushed to for-next with the typo fixed. Thanks. > > > Other than that, > Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
在 2024/12/17 22:44, fdmanana@kernel.org 写道: > From: Filipe Manana <fdmanana@suse.com> > > At btrfs_is_empty_uuid() we have our custom code to check if an uuid is > empty, however there a kernel uuid library that has a function named > uuid_is_null() which does the same and probably more efficient. > > So change btrfs_is_empty_uuid() to use uuid_is_null(), which is almost > a directy replacement, it just wraps the necessary casting since our > uuid types are u8 arrays while the uuid kernel library uses the uuid_t > type, which is just a typedef of an u8 array of 16 elements as well. > > Also since the function is now to trivial, make it a static inline > function in fs.h. > > Suggested-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> > Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Thanks, Qu > --- > fs/btrfs/fs.c | 9 --------- > fs/btrfs/fs.h | 5 ++++- > 2 files changed, 4 insertions(+), 10 deletions(-) > > diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c > index 06a863252a85..09cfb43580cb 100644 > --- a/fs/btrfs/fs.c > +++ b/fs/btrfs/fs.c > @@ -55,15 +55,6 @@ size_t __attribute_const__ btrfs_get_num_csums(void) > return ARRAY_SIZE(btrfs_csums); > } > > -bool __pure btrfs_is_empty_uuid(const u8 *uuid) > -{ > - for (int i = 0; i < BTRFS_UUID_SIZE; i++) { > - if (uuid[i] != 0) > - return false; > - } > - return true; > -} > - > /* > * Start exclusive operation @type, return true on success. > */ > diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h > index 1113646374f3..58e6b4b953f1 100644 > --- a/fs/btrfs/fs.h > +++ b/fs/btrfs/fs.h > @@ -996,7 +996,10 @@ const char *btrfs_super_csum_name(u16 csum_type); > const char *btrfs_super_csum_driver(u16 csum_type); > size_t __attribute_const__ btrfs_get_num_csums(void); > > -bool __pure btrfs_is_empty_uuid(const u8 *uuid); > +static inline bool btrfs_is_empty_uuid(const u8 *uuid) > +{ > + return uuid_is_null((const uuid_t *)uuid); > +} > > /* Compatibility and incompatibility defines */ > void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,
diff --git a/fs/btrfs/fs.c b/fs/btrfs/fs.c index 06a863252a85..09cfb43580cb 100644 --- a/fs/btrfs/fs.c +++ b/fs/btrfs/fs.c @@ -55,15 +55,6 @@ size_t __attribute_const__ btrfs_get_num_csums(void) return ARRAY_SIZE(btrfs_csums); } -bool __pure btrfs_is_empty_uuid(const u8 *uuid) -{ - for (int i = 0; i < BTRFS_UUID_SIZE; i++) { - if (uuid[i] != 0) - return false; - } - return true; -} - /* * Start exclusive operation @type, return true on success. */ diff --git a/fs/btrfs/fs.h b/fs/btrfs/fs.h index 1113646374f3..58e6b4b953f1 100644 --- a/fs/btrfs/fs.h +++ b/fs/btrfs/fs.h @@ -996,7 +996,10 @@ const char *btrfs_super_csum_name(u16 csum_type); const char *btrfs_super_csum_driver(u16 csum_type); size_t __attribute_const__ btrfs_get_num_csums(void); -bool __pure btrfs_is_empty_uuid(const u8 *uuid); +static inline bool btrfs_is_empty_uuid(const u8 *uuid) +{ + return uuid_is_null((const uuid_t *)uuid); +} /* Compatibility and incompatibility defines */ void __btrfs_set_fs_incompat(struct btrfs_fs_info *fs_info, u64 flag,