diff mbox series

[1/8] btrfs-progs: Add btrfs_is_empty_uuid

Message ID 20210913131729.37897-2-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series Implement progs support for removing received uuid on RW vols | expand

Commit Message

Nikolay Borisov Sept. 13, 2021, 1:17 p.m. UTC
This utility function is needed by the RO->RW snapshot detection code.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 kernel-shared/ctree.h     |  2 ++
 kernel-shared/uuid-tree.c | 11 +++++++++++
 2 files changed, 13 insertions(+)

Comments

Qu Wenruo Sept. 14, 2021, 12:58 a.m. UTC | #1
On 2021/9/13 下午9:17, Nikolay Borisov wrote:
> This utility function is needed by the RO->RW snapshot detection code.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>   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;
> +}
>
diff mbox series

Patch

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)
+{
+	int i;
+
+	for (i = 0; i < BTRFS_UUID_SIZE; i++) {
+		if (uuid[i])
+			return 0;
+	}
+	return 1;
+}