diff mbox series

[v2,1/8] btrfs-progs: Add btrfs_is_empty_uuid

Message ID 20210914090558.79411-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. 14, 2021, 9:05 a.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

Anand Jain Sept. 16, 2021, 7:26 a.m. UTC | #1
On 14/09/2021 17:05, 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)
> +{
> +	int i;
> +
> +	for (i = 0; i < BTRFS_UUID_SIZE; i++) {
> +		if (uuid[i])
> +			return 0;
> +	}
> +	return 1;
> +}
> 

   You could use uuid_is_null(). No?
David Sterba Sept. 20, 2021, 11:41 a.m. UTC | #2
On Thu, Sep 16, 2021 at 03:26:30PM +0800, Anand Jain wrote:
> On 14/09/2021 17:05, Nikolay Borisov wrote:
> > --- 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;
> > +}
> > 
> 
>    You could use uuid_is_null(). No?

Yeah, no need to duplicate that.
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;
+}