All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jan Schmidt <list.btrfs@jan-o-sch.net>
To: Alex Lyakas <alex.bolshoy.btrfs@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: Newbie questions on some of btrfs code...
Date: Mon, 21 May 2012 12:44:11 +0200	[thread overview]
Message-ID: <4FBA1C7B.8000308@jan-o-sch.net> (raw)
In-Reply-To: <CAHf9xvbp=FQwY1Pn9FDaMPdGqe-G4aSMeBK8kUAq-5Kry0YaTA@mail.gmail.com>

Hi Alex,

On Fri, May 18, 2012 at 13:21 (+0200), Alex Lyakas wrote:
> Some general questions on the ctree code.
> 
> # I saw that slot==0 is special. My understanding is that btrfs
> maintains the property that the parent of each node/leaf has a key
> pointing to that node/leaf, which must be equal to the key in the
> slot==0 of this node/leaf. That's what fixup_low_keys() tries to
> maintain. Is this correct?

Yes. I'm not 100% sure if the key in the parent node must match exactly
the first key of the child node. It is probably allowed that it's less
or equal than the first key. It is guaranteed to be larger than the
largest of the previous (left) node, though.

And yes, that's what fixup_low_keys is correcting.

> # If my understanding in the previous bullet is correct: Is that the
> reason that in btrfs_prev_leaf() it is assumed that if there is a
> lesser key, btrfs_search_slot() will never bring us to the slot==0 of
> the current leaf?

It's quite straight: We look for a key smaller than the first (slot 0)
of the current leaf. If we find the current leaf again (because
btrfs_search_slot returns the place where such a key would have be
inserted), then there's no previous leaf. No preconditions or
assumptions on nodes in levels needed.

> # btrfs_search_slot(): how can it happen that b becomes NULL, and we
> exit the while loop? (and set ret=1)

Good question, probably a leftover. b can't be NULL in the beginning,
because there's always a root node and a commit_root. b
setup_nodes_for_search only sets b NULL when it returns EAGAIN. And the
regular loop exit is in the "if (level == 0)" path.

> # btrfs_insert_empty_items(): if nr>1, then an array of keys is
> expected to be passed. But btrfs_search_slot() is searching only for
> the first key. What happens if the first key does not exist (as
> expected), but the next key in the array exists?

The reason here is that key ordering == insertion order. That function
only has two callers: once from log replay (where either all the items
from the log will exist in the leaf or none) and once from inode.c,
inserting INODE_ITEM and INODE_REF, which never come without the other.
But you are right, there seems to be no safety net in this function, a
comment might be useful.

-Jan

  parent reply	other threads:[~2012-05-21 10:44 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 [this message]
2012-05-22  8:07   ` Alex Lyakas
2012-05-22 22:08     ` Jan Schmidt
2012-05-28 18:45       ` Alex Lyakas
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=4FBA1C7B.8000308@jan-o-sch.net \
    --to=list.btrfs@jan-o-sch.net \
    --cc=alex.bolshoy.btrfs@gmail.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 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.