From: Alex Lyakas <alex.bolshoy.btrfs@gmail.com>
To: Jan Schmidt <list.btrfs@jan-o-sch.net>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: Newbie questions on some of btrfs code...
Date: Mon, 28 May 2012 21:45:44 +0300 [thread overview]
Message-ID: <CAHf9xvafYj-zuUhUUha6=Jm+aYaEz32dcpikS9xExt1VER18_w@mail.gmail.com> (raw)
In-Reply-To: <4FBC0E6A.3070101@jan-o-sch.net>
Hi Jan,
>> Let's say that slot[0] of the current leaf (A) has key=10. And let's
>> say that its parent node (N) has key=5 (and not 10). Let's say we have
>> a previous leaf (B), whose last slot has key=2.
>> If such tree is valid, then: btrfs_prev_leaf() will search for key==9.
>> Then btrfs_search_slot() would bring us node N and leaf A again,
>> wouldn't it? Because key(N)<=9. So we will receive leaf A back, and
>> will think that there is no previous leaf, while there is.
>> What am I missing here?
>
> It wouldn't. btrfs_search_slot always sets up the path such that it
> points to the position where such an key would be inserted. And we never
> insert at the beginning of a leaf. So in your example, this would be at
> the end of leaf B: your path object will have nodes[1] = N, nodes[0] = B
> and slots[0] = number_of_slots_used_in_B + 1.
I have re-looked at btrfs_search_slot, and don't see how it would end
up in leaf B. The bin_search() function will clearly return the slot
*after* the slot of N that has key==5 (which is the parent slot of A).
So then the following code:
if (level != 0) {
int dec = 0;
if (ret && slot > 0) {
dec = 1;
slot -= 1;
}
will bring us back into the slot of N with key=5. And we will go to
leaf A. While if key(N) of that slot was 10, we would never have ended
up in that slot, unless there is no lesser key in the tree. Actually,
it looks like "no lesser key" is the only case when we can get ret==1
and slot==0. Except perhaps an empty leaf, which I am not sure can
happen.
But I may be way off here, as my understanding is still pretty limited.
Thanks!
Alex.
next prev parent reply other threads:[~2012-05-28 18:45 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-18 11:21 Newbie questions on some of btrfs code Alex Lyakas
2012-05-18 11:50 ` Hugo Mills
2012-05-18 13:32 ` Alex Lyakas
2012-05-18 13:59 ` Hugo Mills
2012-05-20 7:40 ` Alex Lyakas
2012-05-21 1:59 ` Liu Bo
2012-05-21 8:20 ` Alex Lyakas
2012-05-21 9:33 ` Liu Bo
2012-05-21 10:05 ` Alex Lyakas
2012-05-22 1:42 ` Liu Bo
2012-05-22 7:48 ` Alex Lyakas
2012-05-21 10:44 ` Jan Schmidt
2012-05-22 8:07 ` Alex Lyakas
2012-05-22 22:08 ` Jan Schmidt
2012-05-28 18:45 ` Alex Lyakas [this message]
2012-05-29 9:13 ` Jan Schmidt
2012-05-29 11:27 ` Alex Lyakas
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='CAHf9xvafYj-zuUhUUha6=Jm+aYaEz32dcpikS9xExt1VER18_w@mail.gmail.com' \
--to=alex.bolshoy.btrfs@gmail.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=list.btrfs@jan-o-sch.net \
/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).