From patchwork Mon Dec 13 09:50:38 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zefan X-Patchwork-Id: 405222 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBD9odbL017498 for ; Mon, 13 Dec 2010 09:50:39 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752883Ab0LMJug (ORCPT ); Mon, 13 Dec 2010 04:50:36 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:60796 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1752324Ab0LMJug (ORCPT ); Mon, 13 Dec 2010 04:50:36 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 419FE1709FD; Mon, 13 Dec 2010 17:50:34 +0800 (CST) Received: from mailserver.fnst.cn.fujitus.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id oBD9jliw027934; Mon, 13 Dec 2010 17:45:47 +0800 Received: from lizf.localdomain ([10.167.225.51]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010121317503477-220685 ; Mon, 13 Dec 2010 17:50:34 +0800 Message-ID: <4D05EC6E.2090408@cn.fujitsu.com> Date: Mon, 13 Dec 2010 17:50:38 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Thunderbird/3.0b2 MIME-Version: 1.0 To: "linux-btrfs@vger.kernel.org" CC: "Ian! D. Allen" Subject: [PATCH 3/3] Btrfs: Clean up tree search ioctl code References: <4D05EBC9.6020908@cn.fujitsu.com> In-Reply-To: <4D05EBC9.6020908@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-13 17:50:34, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-13 17:50:35, Serialize complete at 2010-12-13 17:50:35 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Mon, 13 Dec 2010 09:50:39 +0000 (UTC) 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: