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 3/3] Btrfs: Clean up tree search ioctl code
Date: Mon, 13 Dec 2010 17:50:38 +0800 [thread overview]
Message-ID: <4D05EC6E.2090408@cn.fujitsu.com> (raw)
In-Reply-To: <4D05EBC9.6020908@cn.fujitsu.com>
- Check if the key is within specified range before checking the
item length.
- Advance to the next key a bit more efficiently.
- Remove redundant code.
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
---
fs/btrfs/ioctl.c | 30 ++++++++++++------------------
1 files changed, 12 insertions(+), 18 deletions(-)
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 08174e2..477affb 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1059,28 +1059,24 @@ static noinline int copy_to_sk(struct btrfs_root *root,
slot = path->slots[0];
nritems = btrfs_header_nritems(leaf);
- if (btrfs_header_generation(leaf) > sk->max_transid) {
- i = nritems;
+ if (btrfs_header_generation(leaf) > sk->max_transid)
goto advance_key;
- }
found_transid = btrfs_header_generation(leaf);
for (i = slot; i < nritems; i++) {
item_off = btrfs_item_ptr_offset(leaf, i);
item_len = btrfs_item_size_nr(leaf, i);
+ btrfs_item_key_to_cpu(leaf, key, i);
+ if (!key_in_sk(key, sk))
+ continue;
+
if (item_len > BTRFS_SEARCH_ARGS_BUFSIZE)
item_len = 0;
if (sizeof(sh) + item_len + *sk_offset >
- BTRFS_SEARCH_ARGS_BUFSIZE) {
- ret = 1;
- goto overflow;
- }
-
- btrfs_item_key_to_cpu(leaf, key, i);
- if (!key_in_sk(key, sk))
- continue;
+ BTRFS_SEARCH_ARGS_BUFSIZE)
+ return 1;
sh.objectid = key->objectid;
sh.offset = key->offset;
@@ -1102,22 +1098,21 @@ static noinline int copy_to_sk(struct btrfs_root *root,
(*num_found)++;
if (*num_found >= sk->nr_items)
- break;
+ return 1;
}
advance_key:
ret = 0;
if (key->offset < (u64)-1 && key->offset < sk->max_offset)
key->offset++;
else if (key->type < (u8)-1 && key->type < sk->max_type) {
- key->offset = 0;
+ key->offset = sk->min_offset;
key->type++;
} else if (key->objectid < (u64)-1 && key->objectid < sk->max_objectid) {
- key->offset = 0;
- key->type = 0;
+ key->offset = sk->min_offset;
+ key->type = sk->min_type;
key->objectid++;
} else
ret = 1;
-overflow:
return ret;
}
@@ -1178,9 +1173,8 @@ static noinline int search_ioctl(struct inode *inode,
ret = copy_to_sk(root, path, &key, sk, args->buf,
&sk_offset, &num_found);
btrfs_release_path(root, path);
- if (ret || num_found >= sk->nr_items)
+ if (ret)
break;
-
}
ret = 0;
err:
--
1.6.3
next prev parent reply other threads:[~2010-12-13 9:50 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-13 9:47 [PATCH 1/3] Btrfs: Really return keys within specified range Li Zefan
2010-12-13 9:50 ` [PATCH 2/3] Btrfs: Don't return items more than user specified Li Zefan
2010-12-13 9:50 ` Li Zefan [this message]
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=4D05EC6E.2090408@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 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.