linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Li Zefan <lizf@cn.fujitsu.com>
To: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>
Cc: "Ian! D. Allen" <idallen@idallen.ca>
Subject: [PATCH 1/3] Btrfs: Really return keys within specified range
Date: Mon, 13 Dec 2010 17:47:53 +0800	[thread overview]
Message-ID: <4D05EBC9.6020908@cn.fujitsu.com> (raw)

The keys returned by tree search ioctl should be restricted to:

	key.objectid = [min_objectid, max_objectid] &&
	key.offset   = [min_offset, max_offset] &&
	key.type     = [min_type, max_type]

But actually it returns those keys:

	[(min_objectid, min_type, min_offset),
		(max_objectid, max_type, max_offset)].

And the bug can result in missing subvolumes in the output of
"btrfs subvolume list"

Reported-by: Ian! D. Allen <idallen@idallen.ca>
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
 fs/btrfs/ioctl.c |   20 ++++----------------
 1 files changed, 4 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index f1c9bb4..785f713 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1028,23 +1028,11 @@ out:
 static noinline int key_in_sk(struct btrfs_key *key,
 			      struct btrfs_ioctl_search_key *sk)
 {
-	struct btrfs_key test;
-	int ret;
-
-	test.objectid = sk->min_objectid;
-	test.type = sk->min_type;
-	test.offset = sk->min_offset;
-
-	ret = btrfs_comp_cpu_keys(key, &test);
-	if (ret < 0)
+	if (key->type < sk->min_type || key->type > sk->max_type)
 		return 0;
-
-	test.objectid = sk->max_objectid;
-	test.type = sk->max_type;
-	test.offset = sk->max_offset;
-
-	ret = btrfs_comp_cpu_keys(key, &test);
-	if (ret > 0)
+	if (key->offset < sk->min_offset || key->offset > sk->max_offset)
+		return 0;
+	if (key->objectid < sk->min_objectid || key->objectid > sk->max_objectid)
 		return 0;
 	return 1;
 }
-- 
1.6.3


             reply	other threads:[~2010-12-13  9:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-13  9:47 Li Zefan [this message]
2010-12-13  9:50 ` [PATCH 2/3] Btrfs: Don't return items more than user specified Li Zefan
2010-12-13  9:50 ` [PATCH 3/3] Btrfs: Clean up tree search ioctl code Li Zefan
2010-12-13 18:13 ` Bug in the design of the tree search ioctl API ? [was Re: [PATCH 1/3] Btrfs: Really return keys within specified range] Goffredo Baroncelli
2010-12-14  5:37   ` Li Zefan
2010-12-14 18:16     ` Goffredo Baroncelli
2010-12-15  3:33       ` Li Zefan
2010-12-15  6:53         ` Goffredo Baroncelli
2010-12-15  7:13           ` Li Zefan
2010-12-15 18:48             ` Goffredo Baroncelli
2010-12-16  1:03               ` Li Zefan
2010-12-15 16:14         ` Chris Mason
2010-12-15 18:42           ` Goffredo Baroncelli
2010-12-15 18:51             ` Chris Mason
2010-12-15 19:13               ` Goffredo Baroncelli

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=4D05EBC9.6020908@cn.fujitsu.com \
    --to=lizf@cn.fujitsu.com \
    --cc=idallen@idallen.ca \
    --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).