From patchwork Tue Dec 8 17:03:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sage Weil X-Patchwork-Id: 65715 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB8H3shA007985 for ; Tue, 8 Dec 2009 17:03:54 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935986AbZLHRDp (ORCPT ); Tue, 8 Dec 2009 12:03:45 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S935988AbZLHRDp (ORCPT ); Tue, 8 Dec 2009 12:03:45 -0500 Received: from cobra.newdream.net ([66.33.216.30]:38683 "EHLO cobra.newdream.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935983AbZLHRDn (ORCPT ); Tue, 8 Dec 2009 12:03:43 -0500 Received: by cobra.newdream.net (Postfix, from userid 1031) id 06A63BCC26; Tue, 8 Dec 2009 09:03:49 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by cobra.newdream.net (Postfix) with ESMTP id E6F40BCBB9; Tue, 8 Dec 2009 09:03:49 -0800 (PST) Date: Tue, 8 Dec 2009 09:03:49 -0800 (PST) From: Sage Weil To: Josef Bacik cc: linux-btrfs@vger.kernel.org Subject: Re: committing new snapshots In-Reply-To: <20091208160507.GA3374@localhost.localdomain> Message-ID: References: <20091208160507.GA3374@localhost.localdomain> MIME-Version: 1.0 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c index c207e8c..747d481 100644 --- a/fs/btrfs/transaction.c +++ b/fs/btrfs/transaction.c @@ -756,6 +756,9 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, struct extent_buffer *old; int ret; u64 objectid; + struct inode *parent_inode; + int namelen; + u64 index = 0; new_root_item = kmalloc(sizeof(*new_root_item), GFP_NOFS); if (!new_root_item) { @@ -775,6 +778,29 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, key.offset = trans->transid; btrfs_set_key_type(&key, BTRFS_ROOT_ITEM_KEY); + memcpy(&pending->root_key, &key, sizeof(key)); + pending->root_key.offset = (u64)-1; + + parent_inode = pending->dentry->d_parent->d_inode; + /* + * insert the directory item + */ + namelen = strlen(pending->name); + ret = btrfs_set_inode_index(parent_inode, &index); + ret = btrfs_insert_dir_item(trans, root, + pending->name, namelen, + parent_inode->i_ino, + &pending->root_key, BTRFS_FT_DIR, index); + + if (ret) + goto fail; + + btrfs_i_size_write(parent_inode, parent_inode->i_size + namelen * 2); + ret = btrfs_update_inode(trans, root, parent_inode); + BUG_ON(ret); + + + old = btrfs_lock_root_node(root); btrfs_cow_block(trans, root, old, NULL, 0, &old); btrfs_set_lock_blocking(old); @@ -791,8 +817,13 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans, if (ret) goto fail; - key.offset = (u64)-1; - memcpy(&pending->root_key, &key, sizeof(key)); + ret = btrfs_add_root_ref(trans, root->fs_info->tree_root, + pending->root_key.objectid, + root->root_key.objectid, + parent_inode->i_ino, index, pending->name, + namelen); + BUG_ON(ret); + fail: kfree(new_root_item); btrfs_unreserve_metadata_space(root, 6); @@ -802,48 +833,16 @@ fail: static noinline int finish_pending_snapshot(struct btrfs_fs_info *fs_info, struct btrfs_pending_snapshot *pending) { - int ret; - int namelen; - u64 index = 0; - struct btrfs_trans_handle *trans; struct inode *parent_inode; struct inode *inode; struct btrfs_root *parent_root; parent_inode = pending->dentry->d_parent->d_inode; parent_root = BTRFS_I(parent_inode)->root; - trans = btrfs_join_transaction(parent_root, 1); - - /* - * insert the directory item - */ - namelen = strlen(pending->name); - ret = btrfs_set_inode_index(parent_inode, &index); - ret = btrfs_insert_dir_item(trans, parent_root, - pending->name, namelen, - parent_inode->i_ino, - &pending->root_key, BTRFS_FT_DIR, index); - - if (ret) - goto fail; - - btrfs_i_size_write(parent_inode, parent_inode->i_size + namelen * 2); - ret = btrfs_update_inode(trans, parent_root, parent_inode); - BUG_ON(ret); - - ret = btrfs_add_root_ref(trans, parent_root->fs_info->tree_root, - pending->root_key.objectid, - parent_root->root_key.objectid, - parent_inode->i_ino, index, pending->name, - namelen); - - BUG_ON(ret); inode = btrfs_lookup_dentry(parent_inode, pending->dentry); d_instantiate(pending->dentry, inode); -fail: - btrfs_end_transaction(trans, fs_info->fs_root); - return ret; + return 0; } /*