All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: Document some invariants of seed code
@ 2020-08-12 14:04 Nikolay Borisov
  2020-08-24 16:53 ` David Sterba
  2020-08-26  9:13 ` Anand Jain
  0 siblings, 2 replies; 3+ messages in thread
From: Nikolay Borisov @ 2020-08-12 14:04 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Nikolay Borisov

Without good understanding of how seed devices works it's hard to grok
some of what the code in open_seed_devices or btrfs_prepare_sprout does.

Add comments hopefully reducing some of the cognitive load.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 fs/btrfs/volumes.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 631cb03b3513..f7ee7837e6bc 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2361,10 +2361,20 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
 	if (!fs_devices->seeding)
 		return -EINVAL;
 
+	/*
+	 * Private copy of the seed devices, anchored at
+	 * fs_info->fs_devices->seed_list
+	 */
 	seed_devices = alloc_fs_devices(NULL, NULL);
 	if (IS_ERR(seed_devices))
 		return PTR_ERR(seed_devices);
 
+	/*
+	 * It's necessary to retain a copy of the original seed fs_devices in
+	 * fs_uuids so that filesystems which have been seeded can be
+	 * successfully reference the seed device from open_seed_devices. This
+	 * also supports multiple fs seed.
+	 */
 	old_devices = clone_fs_devices(fs_devices);
 	if (IS_ERR(old_devices)) {
 		kfree(seed_devices);
@@ -6713,6 +6723,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
 	lockdep_assert_held(&uuid_mutex);
 	ASSERT(fsid);
 
+	/* This will match only for multi-device seed fs */
 	list_for_each_entry(fs_devices, &fs_info->fs_devices->seed_list, seed_list)
 		if (!memcmp(fs_devices->fsid, fsid, BTRFS_FSID_SIZE))
 			return fs_devices;
@@ -6732,6 +6743,10 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
 		return fs_devices;
 	}
 
+	/*
+	 * Upon first call for a seed fs fsid just create a private copy of the
+	 * respective fs_devices and anchor it at fs_info->fs_devices->seed_list
+	 */
 	fs_devices = clone_fs_devices(fs_devices);
 	if (IS_ERR(fs_devices))
 		return fs_devices;
-- 
2.17.1


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

* Re: [PATCH] btrfs: Document some invariants of seed code
  2020-08-12 14:04 [PATCH] btrfs: Document some invariants of seed code Nikolay Borisov
@ 2020-08-24 16:53 ` David Sterba
  2020-08-26  9:13 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2020-08-24 16:53 UTC (permalink / raw)
  To: Nikolay Borisov; +Cc: linux-btrfs

On Wed, Aug 12, 2020 at 05:04:36PM +0300, Nikolay Borisov wrote:
> Without good understanding of how seed devices works it's hard to grok
> some of what the code in open_seed_devices or btrfs_prepare_sprout does.
> 
> Add comments hopefully reducing some of the cognitive load.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

I'll add this patch to the seed list api patchset.

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

* Re: [PATCH] btrfs: Document some invariants of seed code
  2020-08-12 14:04 [PATCH] btrfs: Document some invariants of seed code Nikolay Borisov
  2020-08-24 16:53 ` David Sterba
@ 2020-08-26  9:13 ` Anand Jain
  1 sibling, 0 replies; 3+ messages in thread
From: Anand Jain @ 2020-08-26  9:13 UTC (permalink / raw)
  To: Nikolay Borisov, linux-btrfs

On 12/8/20 10:04 pm, Nikolay Borisov wrote:
> Without good understanding of how seed devices works it's hard to grok
> some of what the code in open_seed_devices or btrfs_prepare_sprout does.
> 
> Add comments hopefully reducing some of the cognitive load.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>   fs/btrfs/volumes.c | 15 +++++++++++++++
>   1 file changed, 15 insertions(+)
> 
> diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
> index 631cb03b3513..f7ee7837e6bc 100644
> --- a/fs/btrfs/volumes.c
> +++ b/fs/btrfs/volumes.c
> @@ -2361,10 +2361,20 @@ static int btrfs_prepare_sprout(struct btrfs_fs_info *fs_info)
>   	if (!fs_devices->seeding)
>   		return -EINVAL;
>   
> +	/*
> +	 * Private copy of the seed devices, anchored at
> +	 * fs_info->fs_devices->seed_list
> +	 */
>   	seed_devices = alloc_fs_devices(NULL, NULL);
>   	if (IS_ERR(seed_devices))
>   		return PTR_ERR(seed_devices);
>   
> +	/*
> +	 * It's necessary to retain a copy of the original seed fs_devices in
> +	 * fs_uuids so that filesystems which have been seeded can be
> +	 * successfully reference the seed device from open_seed_devices. This
> +	 * also supports multiple fs seed.
> +	 */
 >
>   	old_devices = clone_fs_devices(fs_devices);
>   	if (IS_ERR(old_devices)) {
>   		kfree(seed_devices);
> @@ -6713,6 +6723,7 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
>   	lockdep_assert_held(&uuid_mutex);
>   	ASSERT(fsid);
>   
> +	/* This will match only for multi-device seed fs */
>   	list_for_each_entry(fs_devices, &fs_info->fs_devices->seed_list, seed_list)
>   		if (!memcmp(fs_devices->fsid, fsid, BTRFS_FSID_SIZE))
>   			return fs_devices;
> @@ -6732,6 +6743,10 @@ static struct btrfs_fs_devices *open_seed_devices(struct btrfs_fs_info *fs_info,
>   		return fs_devices;
>   	}
>   
> +	/*
> +	 * Upon first call for a seed fs fsid just create a private copy of the
> +	 * respective fs_devices and anchor it at fs_info->fs_devices->seed_list
> +	 */
>   	fs_devices = clone_fs_devices(fs_devices);
>   	if (IS_ERR(fs_devices))
>   		return fs_devices;
> 


Looks good. Thanks

Reviewed-by: Anand Jain <anand.jain@oracle.com>


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

end of thread, other threads:[~2020-08-26  9:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-12 14:04 [PATCH] btrfs: Document some invariants of seed code Nikolay Borisov
2020-08-24 16:53 ` David Sterba
2020-08-26  9:13 ` Anand Jain

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.