From patchwork Wed Dec 1 08:09:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 370441 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 oB188DZT022479 for ; Wed, 1 Dec 2010 08:08:13 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753730Ab0LAIH5 (ORCPT ); Wed, 1 Dec 2010 03:07:57 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:64295 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754035Ab0LAIH4 (ORCPT ); Wed, 1 Dec 2010 03:07:56 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id B12B71712FE for ; Wed, 1 Dec 2010 16:07:54 +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 oB183HEe016829 for ; Wed, 1 Dec 2010 16:03:17 +0800 Received: from [10.167.225.64] ([10.167.225.64]) by mailserver.fnst.cn.fujitus.com (Lotus Domino Release 8.5.1FP4) with ESMTP id 2010120116080520-135898 ; Wed, 1 Dec 2010 16:08:05 +0800 Message-ID: <4CF602B5.50404@cn.fujitsu.com> Date: Wed, 01 Dec 2010 16:09:25 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100413 Fedora/3.0.4-2.fc13 Thunderbird/3.0.4 MIME-Version: 1.0 To: Linux Btrfs Subject: [RFC PATCH 1/4] btrfs: introduce a function btrfs_insert_dir_index_item() X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-01 16:08:05, Serialize by Router on mailserver/fnst(Release 8.5.1FP4|July 25, 2010) at 2010-12-01 16:08:06, Serialize complete at 2010-12-01 16:08:06 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]); Wed, 01 Dec 2010 08:08:13 +0000 (UTC) diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index af52f6d..5c44cf4 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -2313,6 +2313,12 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root); int btrfs_set_root_node(struct btrfs_root_item *item, struct extent_buffer *node); /* dir-item.c */ +int btrfs_insert_dir_index_item(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_key *key, + struct btrfs_path *path, + struct btrfs_dir_item *dir_item, + int data_len); int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root *root, const char *name, int name_len, u64 dir, diff --git a/fs/btrfs/dir-item.c b/fs/btrfs/dir-item.c index f0cad5a..d2d23b6 100644 --- a/fs/btrfs/dir-item.c +++ b/fs/btrfs/dir-item.c @@ -117,6 +117,44 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans, } /* + * btrfs_insert_dir_index_item - insert a dir index item into the b-tree + * @trans: pointer of the transcation handle + * @root: pointer used to return the address of the btrfs root + * @rootid: id of the btrfs root that the dir index item is inserted to + * @key: key the dir index item + * @path: pointer of the b-tree path + * @dir_item: pointer of dir item + * @data_len: lenght of the data + * + * Return value: + * 0 - successed + * <0 - error happened + */ +int btrfs_insert_dir_index_item(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + struct btrfs_key *key, + struct btrfs_path *path, + struct btrfs_dir_item *dir_item, + int data_len) +{ + struct extent_buffer *leaf; + struct btrfs_dir_item *dir_item_ptr; + + dir_item_ptr = insert_with_overflow(trans, root, path, key, data_len, + (char *)(dir_item + 1), + le16_to_cpu(dir_item->name_len)); + if (IS_ERR(dir_item_ptr)) + return PTR_ERR(dir_item_ptr); + + leaf = path->nodes[0]; + write_extent_buffer(leaf, dir_item, (unsigned long)dir_item_ptr, + data_len); + btrfs_mark_buffer_dirty(leaf); + + return 0; +} + +/* * insert a directory item in the tree, doing all the magic for * both indexes. 'dir' indicates which objectid to insert it into, * 'location' is the key to stuff into the directory item, 'type' is the @@ -174,24 +212,25 @@ second_insert: } btrfs_release_path(root, path); - btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY); - key.offset = index; - dir_item = insert_with_overflow(trans, root, path, &key, data_size, - name, name_len); - if (IS_ERR(dir_item)) { - ret2 = PTR_ERR(dir_item); + dir_item = kmalloc(sizeof(*dir_item) + name_len, GFP_KERNEL | GFP_NOFS); + if (!dir_item) { + ret2 = -ENOMEM; goto out; } - leaf = path->nodes[0]; + + btrfs_set_key_type(&key, BTRFS_DIR_INDEX_KEY); + key.offset = index; + btrfs_cpu_key_to_disk(&disk_key, location); - btrfs_set_dir_item_key(leaf, dir_item, &disk_key); - btrfs_set_dir_type(leaf, dir_item, type); - btrfs_set_dir_data_len(leaf, dir_item, 0); - btrfs_set_dir_name_len(leaf, dir_item, name_len); - btrfs_set_dir_transid(leaf, dir_item, trans->transid); - name_ptr = (unsigned long)(dir_item + 1); - write_extent_buffer(leaf, name, name_ptr, name_len); - btrfs_mark_buffer_dirty(leaf); + dir_item->location = disk_key; + dir_item->transid = cpu_to_le64(trans->transid); + dir_item->data_len = 0; + dir_item->name_len = cpu_to_le16(name_len); + dir_item->type = type; + memcpy((char *)(dir_item + 1), name, name_len); + ret2 = btrfs_insert_dir_index_item(trans, root, &key, path, dir_item, + sizeof(*dir_item) + name_len); + kfree(dir_item); out: btrfs_free_path(path); if (ret)