Re: [PATCH 1/8] btrfs-progs: Add btrfs_is_empty_uuid
From: Qu Wenruo <hidden>
Date: 2021-09-14 00:59:02
On 2021/9/13 下午9:17, Nikolay Borisov wrote:
quoted hunk ↗ jump to hunk
This utility function is needed by the RO->RW snapshot detection code. Signed-off-by: Nikolay Borisov <redacted> --- kernel-shared/ctree.h | 2 ++ kernel-shared/uuid-tree.c | 11 +++++++++++ 2 files changed, 13 insertions(+)diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h index 3cca60323e3d..f53436a7f38b 100644 --- a/kernel-shared/ctree.h +++ b/kernel-shared/ctree.h@@ -2860,6 +2860,8 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid, int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, u8 *uuid, u8 type, u64 subvol_id_cpu); +int btrfs_is_empty_uuid(u8 *uuid); + static inline int is_fstree(u64 rootid) { if (rootid == BTRFS_FS_TREE_OBJECTID ||diff --git a/kernel-shared/uuid-tree.c b/kernel-shared/uuid-tree.c index 21115a4d2d09..51a7b5d9ff5d 100644 --- a/kernel-shared/uuid-tree.c +++ b/kernel-shared/uuid-tree.c@@ -109,3 +109,14 @@ int btrfs_lookup_uuid_received_subvol_item(int fd, const u8 *uuid, BTRFS_UUID_KEY_RECEIVED_SUBVOL, subvol_id); } + +int btrfs_is_empty_uuid(u8 *uuid) +{
I did the same work in my previous warning try, but it can be even easier: u8 empty_uuid[BTRFS_UUID_SIZE] = 0; return !memcmpy(uuid, empty_uuid, BTRFS_UUID_SIZE); So simple that I didn't even create a helper for it... Thanks, Qu
+ int i;
+
+ for (i = 0; i < BTRFS_UUID_SIZE; i++) {
+ if (uuid[i])
+ return 0;
+ }
+ return 1;
+}