From: Qu Wenruo <wqu@suse.de>
To: Su Yue <Damenly_Su@gmx.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup()
Date: Thu, 27 Dec 2018 15:31:09 +0800 [thread overview]
Message-ID: <e47163cf-390f-d12a-35bc-7cc5d9900661@suse.de> (raw)
In-Reply-To: <2a24d1cf-41b4-b4db-7aae-33c836c9a6b0@gmx.com>
[-- Attachment #1.1: Type: text/plain, Size: 4120 bytes --]
On 2018/12/27 下午3:37, Su Yue wrote:
>
>
> On 12/27/18 3:13 PM, Qu Wenruo wrote:
>> Although we have btrfs_uuid_tree_lookup_any(), it's an online function
>> utilizing tree search ioctl, not an offline search function.
>>
>> This patch will port kernel btrfs_uuid_tree_lookup() into btrfs-progs
>> for later proper uuid tree initialization.
>>
>> Signed-off-by: Qu Wenruo <wqu@suse.com>
>
> One nitpick bellow.
>
> Reviewed-by: Su Yue <damenly_su@gmx.com>
>> ---
>> uuid-tree.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 69 insertions(+), 2 deletions(-)
>>
>> diff --git a/uuid-tree.c b/uuid-tree.c
>> index 320eb67e1404..b9190103c355 100644
>> --- a/uuid-tree.c
>> +++ b/uuid-tree.c
>> @@ -23,6 +23,7 @@
>> #include "transaction.h"
>> #include "disk-io.h"
>> #include "print-tree.h"
>> +#include "utils.h"
>> static void btrfs_uuid_to_key(const u8 *uuid, u64 *key_objectid,
>> @@ -32,8 +33,11 @@ static void btrfs_uuid_to_key(const u8 *uuid, u64
>> *key_objectid,
>> *key_offset = get_unaligned_le64(uuid + sizeof(u64));
>> }
>> -
>> -/* return -ENOENT for !found, < 0 for errors, or 0 if an item was
>> found */
>> +/*
>> + * Search uuid tree of a *MOUNTED* btrfs (online)
>> + *
>> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was found
>> + */
>> static int btrfs_uuid_tree_lookup_any(int fd, const u8 *uuid, u8 type,
>> u64 *subid)
>> {
>> @@ -103,3 +107,66 @@ int btrfs_lookup_uuid_received_subvol_item(int
>> fd, const u8 *uuid,
>> BTRFS_UUID_KEY_RECEIVED_SUBVOL,
>> subvol_id);
>> }
>> +
>> +/*
>> + * Search uuid tree of an *UNMOUNTED* btrfs (offline)
>
> For consistency of btrfs_uuid_tree_lookup_any(), I'd like to add
> "> + * return -ENOENT for !found, < 0 for errors, or 0 if an item was
> found"
> here too :).
Indeed, this return value isn't the normal >0 for !found and in fact the
comment is from kernel.
I'll update the github version without a resend.
Thanks,
Qu
>
>> + */
>> +static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, u8
>> *uuid,
>> + u8 type, u64 subid)
>> +{
>> + int ret;
>> + struct btrfs_path *path = NULL;
>> + struct extent_buffer *eb;
>> + int slot;
>> + u32 item_size;
>> + unsigned long offset;
>> + struct btrfs_key key;
>> +
>> + if (!uuid_root) {
>> + ret = -ENOENT;
>> + goto out;
>> + }
>> +
>> + path = btrfs_alloc_path();
>> + if (!path) {
>> + ret = -ENOMEM;
>> + goto out;
>> + }
>> +
>> + btrfs_uuid_to_key(uuid, &key.objectid, &key.offset);
>> + key.type = type;
>> + ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
>> + if (ret < 0) {
>> + goto out;
>> + } else if (ret > 0) {
>> + ret = -ENOENT;
>> + goto out;
>> + }
>> +
>> + eb = path->nodes[0];
>> + slot = path->slots[0];
>> + item_size = btrfs_item_size_nr(eb, slot);
>> + offset = btrfs_item_ptr_offset(eb, slot);
>> + ret = -ENOENT;
>> +
>> + if (!IS_ALIGNED(item_size, sizeof(u64))) {
>> + warning("uuid item with illegal size %lu!",
>> + (unsigned long)item_size);
>> + goto out;
>> + }
>> + while (item_size) {
>> + __le64 data;
>> +
>> + read_extent_buffer(eb, &data, offset, sizeof(data));
>> + if (le64_to_cpu(data) == subid) {
>> + ret = 0;
>> + break;
>> + }
>> + offset += sizeof(data);
>> + item_size -= sizeof(data);
>> + }
>> +
>> +out:
>> + btrfs_free_path(path);
>> + return ret;
>> +}
>>
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
next prev parent reply other threads:[~2018-12-27 7:31 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-27 7:13 [PATCH for-4.20 0/3] Fix incorrectly created uuid tree Qu Wenruo
2018-12-27 7:13 ` [PATCH 1/3] btrfs-progs: uuid: Port kernel btrfs_uuid_tree_lookup() Qu Wenruo
2018-12-27 7:37 ` Su Yue
2018-12-27 7:31 ` Qu Wenruo [this message]
2018-12-27 7:13 ` [PATCH 2/3] btrfs-progs: uuid: Port btrfs_uuid_tree_add() function Qu Wenruo
2018-12-27 7:54 ` Su Yue
2018-12-27 7:13 ` [PATCH 3/3] btrfs-progs: Create uuid tree with proper contents Qu Wenruo
2018-12-27 11:28 ` Su Yue
2018-12-27 11:32 ` Qu Wenruo
2019-01-02 16:31 ` David Sterba
2019-01-02 23:46 ` Su Yue
2019-01-02 9:13 ` Nikolay Borisov
2019-01-02 10:00 ` Qu Wenruo
2019-01-02 10:07 ` Nikolay Borisov
2019-01-02 10:11 ` Qu Wenruo
2019-01-03 4:50 ` Qu Wenruo
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=e47163cf-390f-d12a-35bc-7cc5d9900661@suse.de \
--to=wqu@suse.de \
--cc=Damenly_Su@gmx.com \
--cc=linux-btrfs@vger.kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).