Linux-BTRFS Archive on lore.kernel.org
 help / Atom feed
* [PATCH v1] Btrfs: Switch to use new generic UUID API
@ 2019-01-10 18:16 Andy Shevchenko
  2019-01-11 13:48 ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2019-01-10 18:16 UTC (permalink / raw)
  To: Chris Mason, Josef Bacik, David Sterba, Lu Fengqi, linux-btrfs,
	Christoph Hellwig
  Cc: Andy Shevchenko

There are new types and helpers that are supposed to be used in new code.

As a preparation to get rid of legacy types and API functions do
the conversion here.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
- not tested on actual FS
 fs/btrfs/disk-io.c     |  6 +++---
 fs/btrfs/ioctl.c       | 12 ++----------
 fs/btrfs/root-tree.c   |  4 +---
 fs/btrfs/transaction.c |  7 +++----
 4 files changed, 9 insertions(+), 20 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index e0ad52804c26..f618661f5fa4 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1259,7 +1259,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 	struct btrfs_root *root;
 	struct btrfs_key key;
 	int ret = 0;
-	uuid_le uuid = NULL_UUID_LE;
 
 	root = btrfs_alloc_root(fs_info, GFP_KERNEL);
 	if (!root)
@@ -1293,8 +1292,9 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
 	btrfs_set_root_last_snapshot(&root->root_item, 0);
 	btrfs_set_root_dirid(&root->root_item, 0);
 	if (is_fstree(objectid))
-		uuid_le_gen(&uuid);
-	memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE);
+		guid_gen((guid_t *)&root->root_item.uuid);
+	else
+		guid_copy((guid_t *)&root->root_item.uuid, &guid_null);
 	root->root_item.drop_level = 0;
 
 	key.objectid = objectid;
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 9c8e1734429c..a40bf7ea9393 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -541,13 +541,7 @@ static noinline int btrfs_ioctl_fitrim(struct file *file, void __user *arg)
 
 int btrfs_is_empty_uuid(u8 *uuid)
 {
-	int i;
-
-	for (i = 0; i < BTRFS_UUID_SIZE; i++) {
-		if (uuid[i])
-			return 0;
-	}
-	return 1;
+	return guid_is_null((guid_t *)uuid);
 }
 
 static noinline int create_subvol(struct inode *dir,
@@ -572,7 +566,6 @@ static noinline int create_subvol(struct inode *dir,
 	u64 objectid;
 	u64 new_dirid = BTRFS_FIRST_FREE_OBJECTID;
 	u64 index = 0;
-	uuid_le new_uuid;
 
 	root_item = kzalloc(sizeof(*root_item), GFP_KERNEL);
 	if (!root_item)
@@ -642,8 +635,7 @@ static noinline int create_subvol(struct inode *dir,
 
 	btrfs_set_root_generation_v2(root_item,
 			btrfs_root_generation(root_item));
-	uuid_le_gen(&new_uuid);
-	memcpy(root_item->uuid, new_uuid.b, BTRFS_UUID_SIZE);
+	guid_gen((guid_t *)&root_item->uuid);
 	btrfs_set_stack_timespec_sec(&root_item->otime, cur_time.tv_sec);
 	btrfs_set_stack_timespec_nsec(&root_item->otime, cur_time.tv_nsec);
 	root_item->ctime = root_item->otime;
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index 65bda0682928..b797792d66bf 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -20,7 +20,6 @@
 static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 				struct btrfs_root_item *item)
 {
-	uuid_le uuid;
 	int len;
 	int need_reset = 0;
 
@@ -42,8 +41,7 @@ static void btrfs_read_root_item(struct extent_buffer *eb, int slot,
 			sizeof(*item) - offsetof(struct btrfs_root_item,
 					generation_v2));
 
-		uuid_le_gen(&uuid);
-		memcpy(item->uuid, uuid.b, BTRFS_UUID_SIZE);
+		guid_gen((guid_t *)&item->uuid);
 	}
 }
 
diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 127fa1535f58..394120c9c1f3 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1422,7 +1422,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	u64 index = 0;
 	u64 objectid;
 	u64 root_flags;
-	uuid_le new_uuid;
 
 	ASSERT(pending->path);
 	path = pending->path;
@@ -1515,8 +1514,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 
 	btrfs_set_root_generation_v2(new_root_item,
 			trans->transid);
-	uuid_le_gen(&new_uuid);
-	memcpy(new_root_item->uuid, new_uuid.b, BTRFS_UUID_SIZE);
+	guid_gen((guid_t *)&new_root_item->uuid);
 	memcpy(new_root_item->parent_uuid, root->root_item.uuid,
 			BTRFS_UUID_SIZE);
 	if (!(root_flags & BTRFS_ROOT_SUBVOL_RDONLY)) {
@@ -1627,7 +1625,8 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 		btrfs_abort_transaction(trans, ret);
 		goto fail;
 	}
-	ret = btrfs_uuid_tree_add(trans, new_uuid.b, BTRFS_UUID_KEY_SUBVOL,
+	ret = btrfs_uuid_tree_add(trans, new_root_item->uuid,
+				  BTRFS_UUID_KEY_SUBVOL,
 				  objectid);
 	if (ret) {
 		btrfs_abort_transaction(trans, ret);
-- 
2.20.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] Btrfs: Switch to use new generic UUID API
  2019-01-10 18:16 [PATCH v1] Btrfs: Switch to use new generic UUID API Andy Shevchenko
@ 2019-01-11 13:48 ` David Sterba
  2019-01-21  8:44   ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: David Sterba @ 2019-01-11 13:48 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Chris Mason, Josef Bacik, David Sterba, Lu Fengqi, linux-btrfs,
	Christoph Hellwig

On Thu, Jan 10, 2019 at 08:16:53PM +0200, Andy Shevchenko wrote:
> There are new types and helpers that are supposed to be used in new code.
> 
> As a preparation to get rid of legacy types and API functions do
> the conversion here.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
> - not tested on actual FS
>  fs/btrfs/disk-io.c     |  6 +++---
>  fs/btrfs/ioctl.c       | 12 ++----------
>  fs/btrfs/root-tree.c   |  4 +---
>  fs/btrfs/transaction.c |  7 +++----
>  4 files changed, 9 insertions(+), 20 deletions(-)
> 
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index e0ad52804c26..f618661f5fa4 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -1259,7 +1259,6 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
>  	struct btrfs_root *root;
>  	struct btrfs_key key;
>  	int ret = 0;
> -	uuid_le uuid = NULL_UUID_LE;
>  
>  	root = btrfs_alloc_root(fs_info, GFP_KERNEL);
>  	if (!root)
> @@ -1293,8 +1292,9 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
>  	btrfs_set_root_last_snapshot(&root->root_item, 0);
>  	btrfs_set_root_dirid(&root->root_item, 0);
>  	if (is_fstree(objectid))
> -		uuid_le_gen(&uuid);
> -	memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE);
> +		guid_gen((guid_t *)&root->root_item.uuid);
> +	else
> +		guid_copy((guid_t *)&root->root_item.uuid, &guid_null);

I don't like the type casts, a simple wrapper would be better I think.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] Btrfs: Switch to use new generic UUID API
  2019-01-11 13:48 ` David Sterba
@ 2019-01-21  8:44   ` Christoph Hellwig
  2019-01-21 18:18     ` David Sterba
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2019-01-21  8:44 UTC (permalink / raw)
  To: dsterba, Andy Shevchenko, Chris Mason, Josef Bacik, David Sterba,
	Lu Fengqi, linux-btrfs, Christoph Hellwig

On Fri, Jan 11, 2019 at 02:48:03PM +0100, David Sterba wrote:
> >  	if (is_fstree(objectid))
> > -		uuid_le_gen(&uuid);
> > -	memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE);
> > +		guid_gen((guid_t *)&root->root_item.uuid);
> > +	else
> > +		guid_copy((guid_t *)&root->root_item.uuid, &guid_null);
> 
> I don't like the type casts, a simple wrapper would be better I think.

It seems like we should use the guid_t type in the actual strutures
instead of doing this casting.  Andy, is there any reason I'm missing
why we can't do that in btrfs?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v1] Btrfs: Switch to use new generic UUID API
  2019-01-21  8:44   ` Christoph Hellwig
@ 2019-01-21 18:18     ` David Sterba
  0 siblings, 0 replies; 4+ messages in thread
From: David Sterba @ 2019-01-21 18:18 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: dsterba, Andy Shevchenko, Chris Mason, Josef Bacik, David Sterba,
	Lu Fengqi, linux-btrfs

On Mon, Jan 21, 2019 at 09:44:36AM +0100, Christoph Hellwig wrote:
> On Fri, Jan 11, 2019 at 02:48:03PM +0100, David Sterba wrote:
> > >  	if (is_fstree(objectid))
> > > -		uuid_le_gen(&uuid);
> > > -	memcpy(root->root_item.uuid, uuid.b, BTRFS_UUID_SIZE);
> > > +		guid_gen((guid_t *)&root->root_item.uuid);
> > > +	else
> > > +		guid_copy((guid_t *)&root->root_item.uuid, &guid_null);
> > 
> > I don't like the type casts, a simple wrapper would be better I think.
> 
> It seems like we should use the guid_t type in the actual strutures
> instead of doing this casting.

The uuid is part of several on-disk structures, so the definition with
u8[BTRFS_UUID_SIZE] makes the size and alignment clear, also the
constant is verified to be 16.  I find it quite useful that all the
on-disk definitions use only the basic types like u8 or u64.

I'd rather not touch the definitions but rather add a glue for the
guid_t API and the raw buffers.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-10 18:16 [PATCH v1] Btrfs: Switch to use new generic UUID API Andy Shevchenko
2019-01-11 13:48 ` David Sterba
2019-01-21  8:44   ` Christoph Hellwig
2019-01-21 18:18     ` David Sterba

Linux-BTRFS Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-btrfs/0 linux-btrfs/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-btrfs linux-btrfs/ https://lore.kernel.org/linux-btrfs \
		linux-btrfs@vger.kernel.org linux-btrfs@archiver.kernel.org
	public-inbox-index linux-btrfs


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-btrfs


AGPL code for this site: git clone https://public-inbox.org/ public-inbox