committing new snapshots
diff mbox

Message ID Pine.LNX.4.64.0912080856370.1307@cobra.newdream.net
State New, archived
Headers show

Commit Message

Sage Weil Dec. 8, 2009, 5:03 p.m. UTC
None

Patch
diff mbox

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;
 }
 
 /*