add snapshot/subvol support for rename and rmdir
PATCH 2/4 add snapshot/subvol support for rename and rmdir
Links to snapshots/subvols are similar to normal directories. The main difference is snapshots/subvols use root back & forward references instead of inode back references. This patch adds code that handles back & forward references for rename and rmdir.
Signed-off-by Yan Zheng <[email protected]>
---
fs/btrfs/ctree.h +15 -4
@@ -2102,12 +2102,15 @@ int btrfs_drop_subtree(struct btrfs_tran struct extent_buffer *parent);/* root-item.c */ int btrfs_find_root_ref (struct btrfs_root *tree_root, -struct btrfs_path *path, -u64 root_id,u64 ref_id); +struct btrfs_path *path, +u64 root_id,u64 ref_id);int btrfs_add_root_ref (struct btrfs_trans_handle *trans,struct btrfs_root *tree_root, -u64 root_id,u8 type,u64 ref_id, -u64 dirid,u64 sequence, +u64 root_id,u64 ref_id,u64 dirid,u64 sequence, +const char *name,int name_len); +int btrfs_del_root_ref (struct btrfs_trans_handle *trans, +struct btrfs_root *tree_root, +u64 root_id,u64 ref_id,u64 dirid,u64 *sequence,const char *name,int name_len);int btrfs_del_root (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_key *key);
@@ -2140,6 +2143,10 @@ btrfs_lookup_dir_index_item(struct btrfs struct btrfs_path *path, u64 dir, u64 objectid, const char *name, int name_len, int mod); +struct btrfs_dir_item * +btrfs_search_dir_index_item (struct btrfs_root *root, +struct btrfs_path *path,u64 dirid, +const char *name,int name_len);struct btrfs_dir_item *btrfs_match_dir_item_name (struct btrfs_root *root,struct btrfs_path *path,const char *name,int name_len);
@@ -2234,6 +2241,10 @@ int btrfs_unlink_inode(struct btrfs_tranint btrfs_add_link (struct btrfs_trans_handle *trans,struct inode *parent_inode,struct inode *inode,const char *name,int name_len,int add_backref,u64 index); +int btrfs_unlink_subvol (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +struct inode *dir,struct inode *inode, +const char *name,int name_len); int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct inode *inode, u64 new_size,
fs/btrfs/dir-item.c +47 -0
53 lines not on this page · raw message
fs/btrfs/inode.c +133 -39
241 lines not on this page · raw message
fs/btrfs/ioctl.c +1 -11
@@ -323,18 +323,8 @@ static noinline int create_subvol(struct ret =btrfs_update_inode (trans, root, dir);BUG_ON (ret); -/* add the backref first */ ret =btrfs_add_root_ref (trans, root->fs_info->tree_root, - objectid,BTRFS_ROOT_BACKREF_KEY , - root->root_key.objectid, - dir->i_ino, index, name, namelen); - -BUG_ON (ret); - -/* now add the forward ref */ - ret =btrfs_add_root_ref (trans, root->fs_info->tree_root, - root->root_key.objectid,BTRFS_ROOT_REF_KEY , - objectid, + objectid, root->root_key.objectid, dir->i_ino, index, name, namelen);BUG_ON (ret);
fs/btrfs/root-tree.c +51 -18
116 lines not on this page · raw message
fs/btrfs/transaction.c +0 -10
@@ -779,24 +779,14 @@ static noinline int finish_pending_snaps ret =btrfs_update_inode (trans, parent_root, parent_inode);BUG_ON (ret); -/* add the backref first */ ret =btrfs_add_root_ref (trans, parent_root->fs_info->tree_root, pending->root_key.objectid, -BTRFS_ROOT_BACKREF_KEY , parent_root->root_key.objectid, parent_inode->i_ino, index, pending->name, namelen);BUG_ON (ret); -/* now add the forward ref */ - ret =btrfs_add_root_ref (trans, parent_root->fs_info->tree_root, - parent_root->root_key.objectid, -BTRFS_ROOT_REF_KEY , - pending->root_key.objectid, - parent_inode->i_ino, index, pending->name, - namelen); - inode =btrfs_lookup_dentry (parent_inode, pending->dentry);d_instantiate (pending->dentry, inode); fail:
fs/btrfs/tree-log.c +8 -0
@@ -2885,6 +2885,11 @@ int btrfs_log_inode_parent(struct btrfs_if (ret) goto end_no_trans; +if (root !=BTRFS_I (inode)->root) { + ret =0 ; + goto end_no_trans; + } +start_log_trans (trans, root); ret =btrfs_log_inode (trans, root, inode, inode_only);
@@ -2907,6 +2912,9 @@ int btrfs_log_inode_parent(struct btrfs_break ; inode = parent->d_inode; +if (root !=BTRFS_I (inode)->root) +break ; +if (BTRFS_I (inode)->generation > root->fs_info->last_trans_committed) { ret =btrfs_log_inode (trans, root, inode, inode_only);