All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Nikolay Borisov <nborisov@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove
Date: Tue, 14 Sep 2021 09:07:20 +0800	[thread overview]
Message-ID: <f84fe95a-1469-9e39-2813-4111fe258390@gmx.com> (raw)
In-Reply-To: <20210913131729.37897-6-nborisov@suse.com>



On 2021/9/13 下午9:17, Nikolay Borisov wrote:
> It will be used to clear received data on RW snapshots that were
> received.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>   kernel-shared/ctree.h     |  3 ++
>   kernel-shared/uuid-tree.c | 82 +++++++++++++++++++++++++++++++++++++++
>   2 files changed, 85 insertions(+)
>
> diff --git a/kernel-shared/ctree.h b/kernel-shared/ctree.h
> index 91a85796a678..158281a9fd67 100644
> --- a/kernel-shared/ctree.h
> +++ b/kernel-shared/ctree.h
> @@ -2860,6 +2860,9 @@ 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);
> +int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
> +               u64 subid);
> +

I have checked the callers in the incoming check patches, they are all
starting a new trans on uuid tree, thus there is no need to start a
trans out of this function.

Let's just pass the subvolume root into the function, and start a new
trans in side the function.

So that we only need one parameter @root, everything else can be fetched
from @root, and we can also modify the root item and uuid tree just in
one go.

Thanks,
Qu
>
>   static inline int is_fstree(u64 rootid)
>   {
> diff --git a/kernel-shared/uuid-tree.c b/kernel-shared/uuid-tree.c
> index 51a7b5d9ff5d..0f0fbf667dda 100644
> --- a/kernel-shared/uuid-tree.c
> +++ b/kernel-shared/uuid-tree.c
> @@ -120,3 +120,85 @@ int btrfs_is_empty_uuid(u8 *uuid)
>   	}
>   	return 1;
>   }
> +
> +int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, u8 *uuid, u8 type,
> +		u64 subid)
> +{
> +	struct btrfs_fs_info *fs_info = trans->fs_info;
> +	struct btrfs_root *uuid_root = fs_info->uuid_root;
> +	int ret;
> +	struct btrfs_path *path = NULL;
> +	struct btrfs_key key;
> +	struct extent_buffer *eb;
> +	int slot;
> +	unsigned long offset;
> +	u32 item_size;
> +	unsigned long move_dst;
> +	unsigned long move_src;
> +	unsigned long move_len;
> +
> +	if (!uuid_root) {
> +		ret = -EINVAL;
> +		goto out;
> +	}
> +
> +	btrfs_uuid_to_key(uuid, &key);
> +	key.type = type;
> +
> +	path = btrfs_alloc_path();
> +	if (!path) {
> +		ret = -ENOMEM;
> +		goto out;
> +	}
> +
> +	ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1);
> +	if (ret < 0) {
> +		warning("error %d while searching for uuid item!", ret);
> +		goto out;
> +	}
> +	if (ret > 0) {
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +
> +
> +	eb = path->nodes[0];
> +	slot = path->slots[0];
> +	offset = btrfs_item_ptr_offset(eb, slot);
> +	item_size = btrfs_item_size_nr(eb, slot);
> +	if (!IS_ALIGNED(item_size, sizeof(u64))) {
> +		warning("uuid item with illegal size %lu!",	(unsigned long)item_size);
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +	while (item_size) {
> +		__le64 read_subid;
> +
> +		read_extent_buffer(eb, &read_subid, offset, sizeof(read_subid));
> +		if (le64_to_cpu(read_subid) == subid)
> +			break;
> +		offset += sizeof(read_subid);
> +		item_size -= sizeof(read_subid);
> +	}
> +
> +	if (!item_size) {
> +		ret = -ENOENT;
> +		goto out;
> +	}
> +
> +	item_size = btrfs_item_size_nr(eb, slot);
> +	if (item_size == sizeof(subid)) {
> +		ret = btrfs_del_item(trans, uuid_root, path);
> +		goto out;
> +	}
> +
> +	move_dst = offset;
> +	move_src = offset + sizeof(subid);
> +	move_len = item_size - (move_src - btrfs_item_ptr_offset(eb, slot));
> +	memmove_extent_buffer(eb, move_dst, move_src, move_len);
> +	btrfs_truncate_item(path, item_size - sizeof(subid), 1);
> +
> +out:
> +	btrfs_free_path(path);
> +	return ret;
> +}
>

  reply	other threads:[~2021-09-14  1:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-13 13:17 [PATCH 0/8] Implement progs support for removing received uuid on RW vols Nikolay Borisov
2021-09-13 13:17 ` [PATCH 1/8] btrfs-progs: Add btrfs_is_empty_uuid Nikolay Borisov
2021-09-14  0:58   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 2/8] btrfs-progs: Remove root argument from btrfs_fixup_low_keys Nikolay Borisov
2021-09-14  1:01   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 3/8] btrfs-progs: Remove fs_info argument from leaf_data_end Nikolay Borisov
2021-09-14  1:02   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 4/8] btrfs-progs: Remove root argument from btrfs_truncate_item Nikolay Borisov
2021-09-14  1:02   ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 5/8] btrfs-progs: Add btrfs_uuid_tree_remove Nikolay Borisov
2021-09-14  1:07   ` Qu Wenruo [this message]
2021-09-14  4:49     ` Nikolay Borisov
2021-09-14  4:57       ` Qu Wenruo
2021-09-13 13:17 ` [PATCH 6/8] btrfs-progs: check/original: Implement removing received data for RW subvols Nikolay Borisov
2021-09-13 13:17 ` [PATCH 7/8] btrfs-progs: check/lowmem: Implement received info clearing for RW volumes Nikolay Borisov
2021-09-13 13:17 ` [PATCH 8/8] btrfs-progs: tests: Add test for received information removal Nikolay Borisov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f84fe95a-1469-9e39-2813-4111fe258390@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=nborisov@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.