瀏覽代碼

Btrfs: remove unnecessary dget_parent/dput when creating the pending snapshot

Since we have grabbed the parent inode at the beginning of the
snapshot creation, and both sync and async snapshot creation
release it after the pending snapshots are actually created,
it is safe to access the parent inode directly during the snapshot
creation, we needn't use dget_parent/dput to fix the parent dentry
and get the dir inode.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Miao Xie 12 年之前
父節點
當前提交
e9662f701c
共有 3 個文件被更改,包括 8 次插入8 次删除
  1. 6 4
      fs/btrfs/ioctl.c
  2. 1 4
      fs/btrfs/transaction.c
  3. 1 0
      fs/btrfs/transaction.h

+ 6 - 4
fs/btrfs/ioctl.c

@@ -530,9 +530,10 @@ fail:
 	return ret;
 	return ret;
 }
 }
 
 
-static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
-			   char *name, int namelen, u64 *async_transid,
-			   bool readonly, struct btrfs_qgroup_inherit *inherit)
+static int create_snapshot(struct btrfs_root *root, struct inode *dir,
+			   struct dentry *dentry, char *name, int namelen,
+			   u64 *async_transid, bool readonly,
+			   struct btrfs_qgroup_inherit *inherit)
 {
 {
 	struct inode *inode;
 	struct inode *inode;
 	struct btrfs_pending_snapshot *pending_snapshot;
 	struct btrfs_pending_snapshot *pending_snapshot;
@@ -551,6 +552,7 @@ static int create_snapshot(struct btrfs_root *root, struct dentry *dentry,
 	pending_snapshot->dentry = dentry;
 	pending_snapshot->dentry = dentry;
 	pending_snapshot->root = root;
 	pending_snapshot->root = root;
 	pending_snapshot->readonly = readonly;
 	pending_snapshot->readonly = readonly;
+	pending_snapshot->dir = dir;
 	pending_snapshot->inherit = inherit;
 	pending_snapshot->inherit = inherit;
 
 
 	trans = btrfs_start_transaction(root->fs_info->extent_root, 6);
 	trans = btrfs_start_transaction(root->fs_info->extent_root, 6);
@@ -728,7 +730,7 @@ static noinline int btrfs_mksubvol(struct path *parent,
 		goto out_up_read;
 		goto out_up_read;
 
 
 	if (snap_src) {
 	if (snap_src) {
-		error = create_snapshot(snap_src, dentry, name, namelen,
+		error = create_snapshot(snap_src, dir, dentry, name, namelen,
 					async_transid, readonly, inherit);
 					async_transid, readonly, inherit);
 	} else {
 	} else {
 		error = create_subvol(BTRFS_I(dir)->root, dentry,
 		error = create_subvol(BTRFS_I(dir)->root, dentry,

+ 1 - 4
fs/btrfs/transaction.c

@@ -1068,7 +1068,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	struct inode *parent_inode;
 	struct inode *parent_inode;
 	struct btrfs_path *path;
 	struct btrfs_path *path;
 	struct btrfs_dir_item *dir_item;
 	struct btrfs_dir_item *dir_item;
-	struct dentry *parent;
 	struct dentry *dentry;
 	struct dentry *dentry;
 	struct extent_buffer *tmp;
 	struct extent_buffer *tmp;
 	struct extent_buffer *old;
 	struct extent_buffer *old;
@@ -1126,8 +1125,7 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	trans->bytes_reserved = trans->block_rsv->reserved;
 	trans->bytes_reserved = trans->block_rsv->reserved;
 
 
 	dentry = pending->dentry;
 	dentry = pending->dentry;
-	parent = dget_parent(dentry);
-	parent_inode = parent->d_inode;
+	parent_inode = pending->dir;
 	parent_root = BTRFS_I(parent_inode)->root;
 	parent_root = BTRFS_I(parent_inode)->root;
 	record_root_in_trans(trans, parent_root);
 	record_root_in_trans(trans, parent_root);
 
 
@@ -1275,7 +1273,6 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	if (ret)
 	if (ret)
 		btrfs_abort_transaction(trans, root, ret);
 		btrfs_abort_transaction(trans, root, ret);
 fail:
 fail:
-	dput(parent);
 	trans->block_rsv = rsv;
 	trans->block_rsv = rsv;
 	trans->bytes_reserved = 0;
 	trans->bytes_reserved = 0;
 no_free_objectid:
 no_free_objectid:

+ 1 - 0
fs/btrfs/transaction.h

@@ -84,6 +84,7 @@ struct btrfs_trans_handle {
 
 
 struct btrfs_pending_snapshot {
 struct btrfs_pending_snapshot {
 	struct dentry *dentry;
 	struct dentry *dentry;
+	struct inode *dir;
 	struct btrfs_root *root;
 	struct btrfs_root *root;
 	struct btrfs_root *snap;
 	struct btrfs_root *snap;
 	struct btrfs_qgroup_inherit *inherit;
 	struct btrfs_qgroup_inherit *inherit;