diff mbox

Bug in btrfs_rename (kernel BUG at fs/btrfs/inode.c:5595!)

Message ID 20100114190004.GB2190@localhost.localdomain (mailing list archive)
State Accepted
Headers show

Commit Message

Josef Bacik Jan. 14, 2010, 7 p.m. UTC
None
diff mbox

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 5440bab..24cbf6b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -3305,24 +3305,7 @@  static int btrfs_setattr_size(struct inode *inode, struct iattr *attr)
 			send_sig(SIGXFSZ, current, 0);
 			return -EFBIG;
 		}
-	}
-
-	ret = btrfs_reserve_metadata_space(root, 1);
-	if (ret)
-		return ret;
-
-	trans = btrfs_start_transaction(root, 1);
-	btrfs_set_trans_block_group(trans, inode);
-
-	ret = btrfs_orphan_add(trans, inode);
-	BUG_ON(ret);
-
-	nr = trans->blocks_used;
-	btrfs_end_transaction(trans, root);
-	btrfs_unreserve_metadata_space(root, 1);
-	btrfs_btree_balance_dirty(root, nr);
 
-	if (attr->ia_size > inode->i_size) {
 		ret = btrfs_cont_expand(inode, attr->ia_size);
 		if (ret) {
 			btrfs_truncate(inode);
@@ -3337,14 +3320,26 @@  static int btrfs_setattr_size(struct inode *inode, struct iattr *attr)
 
 		ret = btrfs_update_inode(trans, root, inode);
 		BUG_ON(ret);
-		if (inode->i_nlink > 0) {
-			ret = btrfs_orphan_del(trans, inode);
-			BUG_ON(ret);
-		}
+
 		nr = trans->blocks_used;
 		btrfs_end_transaction(trans, root);
 		btrfs_btree_balance_dirty(root, nr);
 		return 0;
+	} else if (attr->ia_size < i_size_read(inode)) {
+		ret = btrfs_reserve_metadata_space(root, 1);
+		if (ret)
+			return ret;
+
+		trans = btrfs_start_transaction(root, 1);
+		btrfs_set_trans_block_group(trans, inode);
+
+		ret = btrfs_orphan_add(trans, inode);
+		BUG_ON(ret);
+
+		nr = trans->blocks_used;
+		btrfs_end_transaction(trans, root);
+		btrfs_unreserve_metadata_space(root, 1);
+		btrfs_btree_balance_dirty(root, nr);
 	}
 
 	/*
@@ -3355,10 +3350,6 @@  static int btrfs_setattr_size(struct inode *inode, struct iattr *attr)
 	if (attr->ia_size == 0)
 		BTRFS_I(inode)->ordered_data_close = 1;
 
-	/* we don't support swapfiles, so vmtruncate shouldn't fail */
-	ret = vmtruncate(inode, attr->ia_size);
-	BUG_ON(ret);
-
 	return 0;
 }
 
@@ -3376,7 +3367,6 @@  static int btrfs_setattr(struct dentry *dentry, struct iattr *attr)
 		if (err)
 			return err;
 	}
-	attr->ia_valid &= ~ATTR_SIZE;
 
 	if (attr->ia_valid)
 		err = inode_setattr(inode, attr);