btrfs: allow cross-subvolume BTRFS_IOC_CLONE
cover btrfs: allow cross-subvolume BTRFS_IOC_CLONE
This is a simple patch to allow reflinks to be made crossing subvolume boundaries. The only complication I found in implementing this is that btrfs_ioctl_clone reuses a btrfs_path. This is a slight problem because once we allow the source and destination inodes to come from different btrfs_roots, we need to know what root to pass into the various calls to btrfs_release_path, and keeping track of this would further complicate the control flow of btrfs_ioctl_clone. Fortunately btrfs_release_path does not use it's first argument, patch number 1 removes it.
Patch number 2 is then just a simple matter of distinguishing between the source and destination btrfs_roots in btrfs_ioctl_clone.
If removing the first argument from btrfs_release_path is undesirable, then btrfs_ioctl_clone could simply pass NULL. There are a few other places in btrfs that already do this.
I have tested this by cp -a --reflink=always all the files found in the UML slackware root_fs, and also by cloning a test file with hundreds of random extents and holes.
Larry D'Anna (2):
btrfs: remove unused argument 'root' from btrfs_release_path
btrfs: allow cross-subvolume BTRFS_IOC_CLONE
fs/btrfs/ctree.c | 28 ++++++------ fs/btrfs/ctree.h | 2 +- fs/btrfs/dir-item.c | 2 +- fs/btrfs/extent-tree.c | 74 ++++++++++++++++---------------- fs/btrfs/file-item.c | 12 +++--- fs/btrfs/file.c | 12 +++--- fs/btrfs/free-space-cache.c | 14 +++--- fs/btrfs/inode.c | 42 +++++++++--------- fs/btrfs/ioctl.c | 22 +++++---- fs/btrfs/relocation.c | 30 +++++++------- fs/btrfs/root-tree.c | 10 ++-- fs/btrfs/tree-defrag.c | 2 +- fs/btrfs/tree-log.c | 98 +++++++++++++++++++++--------------------- fs/btrfs/volumes.c | 16 ++++---- fs/btrfs/xattr.c | 4 +- 15 files changed, 185 insertions(+), 183 deletions(-)
PATCH 1/2 btrfs: remove unused argument 'root' from btrfs_release_path
--- fs/btrfs/ctree.c | 28 ++++++------ fs/btrfs/ctree.h | 2 +- fs/btrfs/dir-item.c | 2 +- fs/btrfs/extent-tree.c | 74 ++++++++++++++++---------------- fs/btrfs/file-item.c | 12 +++--- fs/btrfs/file.c | 12 +++--- fs/btrfs/free-space-cache.c | 14 +++--- fs/btrfs/inode.c | 42 +++++++++--------- fs/btrfs/ioctl.c | 12 +++--- fs/btrfs/relocation.c | 30 +++++++------- fs/btrfs/root-tree.c | 10 ++-- fs/btrfs/tree-defrag.c | 2 +- fs/btrfs/tree-log.c | 98 +++++++++++++++++++++--------------------- fs/btrfs/volumes.c | 16 ++++---- fs/btrfs/xattr.c | 4 +- 15 files changed, 179 insertions(+), 179 deletions(-)
fs/btrfs/ctree.c +14 -14
@@ -107,7 +107,7 @@ void btrfs_free_path(struct btrfs_path *p) {if (!p)return ; -btrfs_release_path (NULL , p); +btrfs_release_path (p);kmem_cache_free (btrfs_path_cachep, p); }
@@ -117,7 +117,7 @@ void btrfs_free_path(struct btrfs_path *p)* * It is safe to call this on paths that no locks or extent buffers held. */ -noinline void btrfs_release_path(struct btrfs_root *root, struct btrfs_path *p) +noinline void btrfs_release_path(struct btrfs_path *p) {int i;
@@ -1328,7 +1328,7 @@ static noinline int reada_for_balance(struct btrfs_root *root, ret = -EAGAIN ;/* release the whole path */ -btrfs_release_path (root, path); +btrfs_release_path (path);/* read the blocks */ if (block1)
@@ -1475,7 +1475,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,return 0 ; }free_extent_buffer (tmp); -btrfs_release_path (NULL , p); +btrfs_release_path (p);return -EIO ; } }
@@ -1494,7 +1494,7 @@ read_block_for_search(struct btrfs_trans_handle *trans,if (p->reada)reada_for_search (root, p, level, slot, key->objectid); -btrfs_release_path (NULL , p); +btrfs_release_path (p); ret = -EAGAIN ; tmp =read_tree_block (root, blocknr, blocksize,0 );
@@ -1563,7 +1563,7 @@ setup_nodes_for_search(struct btrfs_trans_handle *trans, } b = p->nodes[level];if (!b) { -btrfs_release_path (NULL , p); +btrfs_release_path (p); goto again; }BUG_ON (btrfs_header_nritems (b) ==1 );
@@ -1753,7 +1753,7 @@ done:if (!p->leave_spinning)btrfs_set_path_blocking (p);if (ret <0 ) -btrfs_release_path (root, p); +btrfs_release_path (p);return ret; }
@@ -3026,7 +3026,7 @@ static noinline int setup_leaf_for_split(struct btrfs_trans_handle *trans, struct btrfs_file_extent_item); extent_len =btrfs_file_extent_num_bytes (leaf, fi); } -btrfs_release_path (root, path); +btrfs_release_path (path); path->keep_locks =1 ; path->search_for_split =1 ;
@@ -3949,7 +3949,7 @@ int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path)else return 1 ; -btrfs_release_path (root, path); +btrfs_release_path (path); ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 );if (ret <0 )return ret;
@@ -4073,7 +4073,7 @@ find_next_key: sret =btrfs_find_next_key (root, path, min_key, level, cache_only, min_trans);if (sret ==0 ) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; }else { goto out;
@@ -4152,7 +4152,7 @@ next:btrfs_node_key_to_cpu (c, &cur_key, slot); orig_lowest = path->lowest_level; -btrfs_release_path (root, path); +btrfs_release_path (path); path->lowest_level = level; ret =btrfs_search_slot (NULL , root, &cur_key, path,0 ,0 );
@@ -4229,7 +4229,7 @@ int btrfs_next_leaf(struct btrfs_root *root, struct btrfs_path *path) again: level =1 ; next =NULL ; -btrfs_release_path (root, path); +btrfs_release_path (path); path->keep_locks =1 ;
@@ -4285,7 +4285,7 @@ again: goto again;if (ret <0 ) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto done; }
@@ -4324,7 +4324,7 @@ again: goto again;if (ret <0 ) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto done; }
fs/btrfs/ctree.h +1 -1
@@ -2286,7 +2286,7 @@ int btrfs_realloc_node(struct btrfs_trans_handle *trans, struct btrfs_root *root, struct extent_buffer *parent, int start_slot, int cache_only, u64 *last_ret, struct btrfs_key *progress); -void btrfs_release_path (struct btrfs_root *root,struct btrfs_path *p); +void btrfs_release_path (struct btrfs_path *p);struct btrfs_path *btrfs_alloc_path (void );void btrfs_free_path (struct btrfs_path *p);void btrfs_set_path_blocking (struct btrfs_path *p);
fs/btrfs/dir-item.c +1 -1
@@ -172,7 +172,7 @@ second_insert: ret =0 ; goto out_free; } -btrfs_release_path (root, path); +btrfs_release_path (path);btrfs_set_key_type (&key,BTRFS_DIR_INDEX_KEY ); key.offset = index;
fs/btrfs/extent-tree.c +37 -37
294 lines not on this page · raw message
fs/btrfs/file-item.c +6 -6
@@ -193,7 +193,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,u32 item_size;if (item) -btrfs_release_path (root, path); +btrfs_release_path (path); item =btrfs_lookup_csum (NULL , root->fs_info->csum_root, path, disk_bytenr,0 );if (IS_ERR (item)) {
@@ -213,7 +213,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, (unsigned long long)offset); } item =NULL ; -btrfs_release_path (root, path); +btrfs_release_path (path); goto found; } btrfs_item_key_to_cpu(path->nodes[0], &found_key,
@@ -631,7 +631,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,if (key.offset < bytenr)break ; } -btrfs_release_path (root, path); +btrfs_release_path (path); } out:btrfs_free_path (path);
@@ -722,7 +722,7 @@ again:* at this point, we know the tree has an item, but it isn't big * enough yet to put our csum in. Grow it */ -btrfs_release_path (root, path); +btrfs_release_path (path); ret =btrfs_search_slot (trans, root, &file_key, path, csum_size,1 );if (ret <0 )
@@ -766,7 +766,7 @@ again: } insert: -btrfs_release_path (root, path); +btrfs_release_path (path); csum_offset =0 ;if (found_next) {u64 tmp = total_bytes + root->sectorsize;
@@ -850,7 +850,7 @@ next_sector: }btrfs_mark_buffer_dirty (path->nodes[0 ]);if (total_bytes < sums->len) { -btrfs_release_path (root, path); +btrfs_release_path (path);cond_resched (); goto again; }
fs/btrfs/file.c +6 -6
@@ -379,7 +379,7 @@ next_slot: search_start =max (key.offset, start);if (recow) { -btrfs_release_path (root, path); +btrfs_release_path (path);continue ; }
@@ -396,7 +396,7 @@ next_slot: ret =btrfs_duplicate_item (trans, root, path, &new_key);if (ret == -EAGAIN ) { -btrfs_release_path (root, path); +btrfs_release_path (path);continue ; }if (ret <0 )
@@ -519,7 +519,7 @@ next_slot: del_nr =0 ; del_slot =0 ; -btrfs_release_path (root, path); +btrfs_release_path (path);continue ; }
@@ -684,7 +684,7 @@ again: new_key.offset = split; ret =btrfs_duplicate_item (trans, root, path, &new_key);if (ret == -EAGAIN ) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; }BUG_ON (ret <0 );
@@ -724,7 +724,7 @@ again: inode->i_ino, bytenr, orig_offset, &other_start, &other_end)) {if (recow) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; } extent_end = other_end;
@@ -741,7 +741,7 @@ again: inode->i_ino, bytenr, orig_offset, &other_start, &other_end)) {if (recow) { -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; } key.offset = other_start;
fs/btrfs/free-space-cache.c +7 -7
@@ -60,7 +60,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root,if (ret <0 )return ERR_PTR (ret);if (ret >0 ) { -btrfs_release_path (root, path); +btrfs_release_path (path);return ERR_PTR (-ENOENT ); }
@@ -69,7 +69,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root, struct btrfs_free_space_header);btrfs_free_space_key (leaf, header, &disk_key);btrfs_disk_key_to_cpu (&location, &disk_key); -btrfs_release_path (root, path); +btrfs_release_path (path); inode =btrfs_iget (root->fs_info->sb, &location, root,NULL );if (!inode)
@@ -131,7 +131,7 @@ int create_free_space_inode(struct btrfs_root *root,btrfs_set_inode_block_group (leaf, inode_item, block_group->key.objectid);btrfs_mark_buffer_dirty (leaf); -btrfs_release_path (root, path); +btrfs_release_path (path); key.objectid =BTRFS_FREE_SPACE_OBJECTID ; key.offset = block_group->key.objectid;
@@ -140,7 +140,7 @@ int create_free_space_inode(struct btrfs_root *root, ret =btrfs_insert_empty_item (trans, root, path, &key,sizeof (struct btrfs_free_space_header ));if (ret <0 ) { -btrfs_release_path (root, path); +btrfs_release_path (path);return ret; } leaf = path->nodes[0 ];
@@ -149,7 +149,7 @@ int create_free_space_inode(struct btrfs_root *root,memset_extent_buffer (leaf,0 , (unsigned long )header,sizeof (*header));btrfs_set_free_space_key (leaf, header, &disk_key);btrfs_mark_buffer_dirty (leaf); -btrfs_release_path (root, path); +btrfs_release_path (path);return 0 ; }
@@ -754,7 +754,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,EXTENT_DIRTY |EXTENT_DELALLOC |EXTENT_DO_ACCOUNTING ,0 ,0 ,NULL , GFP_NOFS); -btrfs_release_path (root, path); +btrfs_release_path (path); goto out_free; } }
@@ -764,7 +764,7 @@ int btrfs_write_out_cache(struct btrfs_root *root,btrfs_set_free_space_bitmaps (leaf, header, bitmaps);btrfs_set_free_space_generation (leaf, header, trans->transid);btrfs_mark_buffer_dirty (leaf); -btrfs_release_path (root, path); +btrfs_release_path (path); ret =1 ;
fs/btrfs/inode.c +21 -21
168 lines not on this page · raw message
fs/btrfs/ioctl.c +6 -6
@@ -1392,7 +1392,7 @@ static noinline int search_ioctl(struct inode *inode, } ret =copy_to_sk (root, path, &key, sk, args->buf, &sk_offset, &num_found); -btrfs_release_path (root, path); +btrfs_release_path (path);if (ret || num_found >= sk->nr_items)break ;
@@ -1499,7 +1499,7 @@ static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info,if (key.offset ==BTRFS_FIRST_FREE_OBJECTID )break ; -btrfs_release_path (root, path); +btrfs_release_path (path); key.objectid = key.offset; key.offset = (u64)-1 ; dirid = key.objectid;
@@ -1978,7 +1978,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, datal =btrfs_file_extent_ram_bytes (leaf, extent); } -btrfs_release_path (root, path); +btrfs_release_path (path);if (key.offset + datal <= off || key.offset >= off+len)
@@ -2088,7 +2088,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, }btrfs_mark_buffer_dirty (leaf); -btrfs_release_path (root, path); +btrfs_release_path (path); inode->i_mtime = inode->i_ctime =CURRENT_TIME ;
@@ -2109,12 +2109,12 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,btrfs_end_transaction (trans, root); } next: -btrfs_release_path (root, path); +btrfs_release_path (path); key.offset++; } ret =0 ; out: -btrfs_release_path (root, path); +btrfs_release_path (path);unlock_extent (&BTRFS_I (src)->io_tree, off, off+len,GFP_NOFS ); out_unlock:mutex_unlock (&src->i_mutex);
fs/btrfs/relocation.c +15 -15
@@ -961,7 +961,7 @@ again: lower = upper; upper =NULL ; } -btrfs_release_path (root, path2); +btrfs_release_path (path2); next:if (ptr < end) { ptr +=btrfs_extent_inline_ref_size (key.type);
@@ -974,7 +974,7 @@ next:if (ptr >= end) path1->slots[0 ]++; } -btrfs_release_path (rc->extent_root, path1); +btrfs_release_path (path1); cur->checked =1 ;WARN_ON (exist);
@@ -1749,7 +1749,7 @@ again:btrfs_node_key_to_cpu (path->nodes[level], &key, path->slots[level]); -btrfs_release_path (src, path); +btrfs_release_path (path); path->lowest_level = level; ret =btrfs_search_slot (trans, src, &key, path,0 ,1 );
@@ -2496,7 +2496,7 @@ static int do_relocation(struct btrfs_trans_handle *trans, path->locks[upper->level] =0 ; slot = path->slots[upper->level]; -btrfs_release_path (NULL , path); +btrfs_release_path (path); }else { ret =btrfs_bin_search (upper->eb, key, upper->level, &slot);
@@ -2737,7 +2737,7 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans, }else { path->lowest_level = node->level; ret =btrfs_search_slot (trans, root, key, path,0 ,1 ); -btrfs_release_path (root, path); +btrfs_release_path (path);if (ret >0 ) ret =0 ; }
@@ -3119,7 +3119,7 @@ static int add_tree_block(struct reloc_control *rc,#endif } -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path);BUG_ON (level ==-1 );
@@ -3505,7 +3505,7 @@ int add_data_references(struct reloc_control *rc, } path->slots[0 ]++; } -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path);if (err)free_block_list (blocks);return err;
@@ -3568,7 +3568,7 @@ next: EXTENT_DIRTY);if (ret ==0 && start <= key.objectid) { -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path); rc->search_start = end +1 ; }else { rc->search_start = key.objectid + key.offset;
@@ -3576,7 +3576,7 @@ next:return 0 ; } } -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path);return ret; }
@@ -3713,7 +3713,7 @@ restart: flags =BTRFS_EXTENT_FLAG_DATA ;if (path_change) { -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path); path->search_commit_root =1 ; path->skip_locking =1 ;
@@ -3736,7 +3736,7 @@ restart: (flags & BTRFS_EXTENT_FLAG_DATA)) { ret = add_data_references(rc, &key, path, &blocks); } else { -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path); ret =0 ; }if (ret <0 ) {
@@ -3799,7 +3799,7 @@ restart: } } -btrfs_release_path (rc->extent_root, path); +btrfs_release_path (path);clear_extent_bits (&rc->processed_blocks,0 , (u64)-1 ,EXTENT_DIRTY ,GFP_NOFS );
@@ -3867,7 +3867,7 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,btrfs_set_inode_flags (leaf, item,BTRFS_INODE_NOCOMPRESS |BTRFS_INODE_PREALLOC );btrfs_mark_buffer_dirty (leaf); -btrfs_release_path (root, path); +btrfs_release_path (path); out:btrfs_free_path (path);return ret;
@@ -4109,7 +4109,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) } leaf = path->nodes[0 ];btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]); -btrfs_release_path (root->fs_info->tree_root, path); +btrfs_release_path (path);if (key.objectid !=BTRFS_TREE_RELOC_OBJECTID || key.type !=BTRFS_ROOT_ITEM_KEY )
@@ -4141,7 +4141,7 @@ int btrfs_recover_relocation(struct btrfs_root *root) key.offset--; } -btrfs_release_path (root->fs_info->tree_root, path); +btrfs_release_path (path);if (list_empty (&reloc_roots)) goto out;
fs/btrfs/root-tree.c +5 -5
@@ -57,7 +57,7 @@ again:btrfs_item_key_to_cpu (path->nodes[0 ], &search_key, path->slots[0 ]);if (search_key.type !=BTRFS_ROOT_ITEM_KEY ) { search_key.offset++; -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; } ret =0 ;
@@ -230,7 +230,7 @@ again:memcpy (&found_key, &key,sizeof (key)); key.offset++; -btrfs_release_path (root, path); +btrfs_release_path (path); dead_root =btrfs_read_fs_root_no_radix (root->fs_info->tree_root, &found_key);
@@ -292,7 +292,7 @@ int btrfs_find_orphan_roots(struct btrfs_root *tree_root) }btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]); -btrfs_release_path (tree_root, path); +btrfs_release_path (path);if (key.objectid !=BTRFS_ORPHAN_OBJECTID || key.type !=BTRFS_ORPHAN_ITEM_KEY )
@@ -390,7 +390,7 @@ again: err = -ENOENT ;if (key.type ==BTRFS_ROOT_BACKREF_KEY ) { -btrfs_release_path (tree_root, path); +btrfs_release_path (path); key.objectid = ref_id; key.type =BTRFS_ROOT_REF_KEY ; key.offset = root_id;
@@ -463,7 +463,7 @@ again:btrfs_mark_buffer_dirty (leaf);if (key.type ==BTRFS_ROOT_BACKREF_KEY ) { -btrfs_release_path (tree_root, path); +btrfs_release_path (path); key.objectid = ref_id; key.type =BTRFS_ROOT_REF_KEY ; key.offset = root_id;
fs/btrfs/tree-defrag.c +1 -1
@@ -97,7 +97,7 @@ int btrfs_defrag_leaves(struct btrfs_trans_handle *trans, ret =0 ; goto out; } -btrfs_release_path (root, path); +btrfs_release_path (path); wret =btrfs_search_slot (trans, root, &key, path,0 ,1 );if (wret <0 ) {
fs/btrfs/tree-log.c +49 -49
345 lines not on this page · raw message
fs/btrfs/volumes.c +8 -8
@@ -1465,7 +1465,7 @@ next_slot: goto error; leaf = path->nodes[0 ];btrfs_item_key_to_cpu (leaf, &key, path->slots[0 ]); -btrfs_release_path (root, path); +btrfs_release_path (path);continue ; }
@@ -1937,7 +1937,7 @@ again: chunk =btrfs_item_ptr (leaf, path->slots[0 ], struct btrfs_chunk); chunk_type =btrfs_chunk_type (leaf, chunk); -btrfs_release_path (chunk_root, path); +btrfs_release_path (path);if (chunk_type &BTRFS_BLOCK_GROUP_SYSTEM ) { ret = btrfs_relocate_chunk(chunk_root, chunk_tree,
@@ -2055,7 +2055,7 @@ int btrfs_balance(struct btrfs_root *dev_root)if (found_key.offset ==0 )break ; -btrfs_release_path (chunk_root, path); +btrfs_release_path (path); ret = btrfs_relocate_chunk(chunk_root, chunk_root->root_key.objectid, found_key.objectid,
@@ -2127,7 +2127,7 @@ again: goto done;if (ret) { ret =0 ; -btrfs_release_path (root, path); +btrfs_release_path (path);break ; }
@@ -2136,7 +2136,7 @@ again:btrfs_item_key_to_cpu (l, &key, path->slots[0 ]);if (key.objectid != device->devid) { -btrfs_release_path (root, path); +btrfs_release_path (path);break ; }
@@ -2144,14 +2144,14 @@ again: length =btrfs_dev_extent_length (l, dev_extent);if (key.offset + length <= new_size) { -btrfs_release_path (root, path); +btrfs_release_path (path);break ; } chunk_tree =btrfs_dev_extent_chunk_tree (l, dev_extent); chunk_objectid =btrfs_dev_extent_chunk_objectid (l, dev_extent); chunk_offset =btrfs_dev_extent_chunk_offset (l, dev_extent); -btrfs_release_path (root, path); +btrfs_release_path (path); ret =btrfs_relocate_chunk (root, chunk_tree, chunk_objectid, chunk_offset);
@@ -3803,7 +3803,7 @@ again: }if (key.objectid ==BTRFS_DEV_ITEMS_OBJECTID ) { key.objectid =0 ; -btrfs_release_path (root, path); +btrfs_release_path (path); goto again; } ret =0 ;
fs/btrfs/xattr.c +2 -2
@@ -120,13 +120,13 @@ static int do_setxattr(struct btrfs_trans_handle *trans, ret =btrfs_delete_one_dir_name (trans, root, path, di);BUG_ON (ret); -btrfs_release_path (root, path); +btrfs_release_path (path);/* if we don't have a value then we are removing the xattr */ if (!value) goto out; }else { -btrfs_release_path (root, path); +btrfs_release_path (path);if (flags &XATTR_REPLACE ) {/* we couldn't find the attr to replace */
Signature · 1 line
1.7.0.rc2.40.g7d8aa
PATCH 2/2 btrfs: allow cross-subvolume BTRFS_IOC_CLONE
In reply to Larry D'Anna--- fs/btrfs/ioctl.c | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-)
fs/btrfs/ioctl.c +6 -4
@@ -1804,6 +1804,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, {struct inode *inode =fdentry (file)->d_inode;struct btrfs_root *root =BTRFS_I (inode)->root; +struct btrfs_root *srcroot;struct file *src_file;struct inode *src;struct btrfs_trans_handle *trans;
@@ -1846,6 +1847,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, } src = src_file->f_dentry->d_inode; + srcroot =BTRFS_I (src)->root; ret = -EINVAL ;if (src == inode)
@@ -1860,11 +1862,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, goto out_fput; ret = -EXDEV ; -if (src->i_sb != inode->i_sb ||BTRFS_I (src)->root != root) +if (src->i_sb != inode->i_sb) goto out_fput; ret = -ENOMEM ; - buf =vmalloc (btrfs_level_size (root,0 )); + buf =vmalloc (btrfs_level_size (srcroot,0 ));if (!buf) goto out_fput;
@@ -1924,13 +1926,13 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,* note the key will change type as we walk through the * tree. */ - ret =btrfs_search_slot (NULL , root, &key, path,0 ,0 ); + ret =btrfs_search_slot (NULL , srcroot, &key, path,0 ,0 );if (ret <0 ) goto out; nritems =btrfs_header_nritems (path->nodes[0 ]);if (path->slots[0 ] >= nritems) { - ret =btrfs_next_leaf (root, path); + ret =btrfs_next_leaf (srcroot, path);if (ret <0 ) goto out;if (ret >0 )
Signature · 1 line
1.7.0.rc2.40.g7d8aa
Quoted 2 lines · Larry D'Anna
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
Quoted 6 lines · Christoph Hellwig
Quoted 2 lines · Larry D'Anna
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
In what way would this interfere? the reflinked file gets its own inum in its own mountpoint. The two files only internally share some disk space.
Quoted 5 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Excerpts from Christoph Hellwig's message of 2011-03-31 02:36:36 -0400:
Quoted 7 lines · Larry D'Anna
Quoted 2 lines
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
Sorry, I disagree here. reflinks were always intended to be able to span subvolumes. There's no conflict at all because they span different inodes.
-chris
Quoted 5 lines · Chris Mason
Excerpts from Christoph Hellwig's message of 2011-03-31 02:36:36 -0400:
Quoted 4 lines · Larry D'Anna
Quoted 2 lines
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
Quoted 7 lines
Quoted 3 lines
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
Sorry, I disagree here. reflinks were always intended to be able to span subvolumes. There's no conflict at all because they span different inodes.
I don't think it's a good idea to introduce any user visible operations over subvolume boundaries. Currently we don't have any operations over mount boundaries, which is pretty fumdamental to the unix filesystem semantics. If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
Excerpts from Christoph Hellwig's message of 2011-04-01 09:34:05 -0400:
Quoted 14 lines · Chris Mason
Quoted 5 lines
Excerpts from Christoph Hellwig's message of 2011-03-31 02:36:36 -0400:
Quoted 4 lines · Larry D'Anna
Quoted 2 lines
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
Quoted 7 lines
Quoted 3 lines
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
Sorry, I disagree here. reflinks were always intended to be able to span subvolumes. There's no conflict at all because they span different inodes.
Quoted 8 lines
I don't think it's a good idea to introduce any user visible operations over subvolume boundaries. Currently we don't have any operations over mount boundaries, which is pretty fumdamental to the unix filesystem semantics. If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
The subvolume is just a directory tree that can be snapshotted, and has it's own private inode number space.
reflink across subvolumes is no different from copying a file from one subvolume to another at the VFS level. The src and destination are different files and different inodes, they just happen to share data extents.
-chris
On Fri, Apr 1, 2011 at 8:40 PM, Chris Mason <[email protected]> wr= ote:
Quoted 1 line
Excerpts from Christoph Hellwig's message of 2011-04-01 09:34:05 -040=
0:
Quoted 1 line
Quoted 1 line
I don't think it's a good idea to introduce any user visible operati=
ons
Quoted 1 line
Quoted 1 line
over subvolume boundaries. =A0Currently we don't have any operations=
over
Quoted 8 lines
Quoted 6 lines
mount boundaries, which is pretty fumdamental to the unix filesystem semantics. =A0If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. =A0That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
The subvolume is just a directory tree that can be snapshotted, and h=
as
Quoted 3 lines
it's own private inode number space.
reflink across subvolumes is no different from copying a file from on=
e
Quoted 3 lines
subvolume to another at the VFS level. =A0The src and destination are different files and different inodes, they just happen to share data extents.
=2E.. and currently copying file from one subvolume to another requires copying the data as well. It'd be great if you could only copy the metadata.
A good possible use that comes to mind is to quickly merge several subvolumes into a new one.
--=20
=46ajar
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Christoph,
Quoted 1 line · Chris Mason
Excerpts from Christoph Hellwig's message of 2011-04-01 09:34:05
-0400:
Quoted 10 lines
Quoted 9 lines
I don't think it's a good idea to introduce any user visible operations over subvolume boundaries. Currently we don't have any operations over mount boundaries, which is pretty fumdamental to the unix filesystem semantics. If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
Quoted 7 lines
The subvolume is just a directory tree that can be snapshotted, and has it's own private inode number space.
reflink across subvolumes is no different from copying a file from one subvolume to another at the VFS level. The src and destination are different files and different inodes, they just happen to share data extents.
Were Chris Mason's points above enough to sway your opposition to this functionality/patch?
There is demand for the ability to move data between subvolumes without needing to copy the extents themselves, it's cropped up again on the list in recent days.
It seems a little hard (and counterintuitive) to enforce a wasteful use of resources to copy data between different parts of the same filesystem which happen to be a on a different subvolume when it's permitted & functional to the same filesystem on the same subvolume.
I don't dispute the comment about documentation on subvolumes though, there is a short discussion of them on the btrfs wiki in the sysadmins guide, but not really a lot of detail. :-)
All the best,
Chris
Signature · 4 lines
Chris Samuel : http://www.csamuel.org/ : Melbourne, VIC This email may come with a PGP signature as a file. Do not panic. For more info see: http://en.wikipedia.org/wiki/OpenPGP
Quoted 19 lines · Chris Samuel
Christoph,
Quoted 1 line · Chris Mason
Excerpts from Christoph Hellwig's message of 2011-04-01 09:34:05
-0400:
Quoted 13 lines
Quoted 9 lines
I don't think it's a good idea to introduce any user visible operations over subvolume boundaries. Currently we don't have any operations over mount boundaries, which is pretty fumdamental to the unix filesystem semantics. If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
The subvolume is just a directory tree that can be snapshotted, and has it's own private inode number space.
Quoted 6 lines
Quoted 4 lines
reflink across subvolumes is no different from copying a file from one subvolume to another at the VFS level. The src and destination are different files and different inodes, they just happen to share data extents.
Were Chris Mason's points above enough to sway your opposition to thi=
s
Quoted 6 lines
functionality/patch?
There is demand for the ability to move data between subvolumes without needing to copy the extents themselves, it's cropped up again on the list in recent days.
Quoted 7 lines
It seems a little hard (and counterintuitive) to enforce a wasteful use of resources to copy data between different parts of the same filesystem which happen to be a on a different subvolume when it's permitted& functional to the same filesystem on the same subvolume.
I don't dispute the comment about documentation on subvolumes though, there is a short discussion of them on the btrfs wiki in the sysadmin=
s
Quoted 4 lines
guide, but not really a lot of detail. :-)
All the best,
Chris
Me too wants cp --reflink across subvolumes. Please make this feature=20 available to us, as its a "poor man's dedupe" and would give big space=20 savings for many use cases.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Konstantinos Skarlatos
Me too wants cp --reflink across subvolumes. Please make this feature available to us, as its a "poor man's dedupe" and would give big space savings for many use cases.
The simple case of 'cp --reflink' works fine, the only remaining case is the unimplemented clone of part of a compressed inline extent. And it has to be:
* at least 2 blocks uncompressed
* the cloned range does not span the whole extent
The ioctl needs ranges and length aligned up to blocksize, ie. 4096, cloning of short inline extents work.
The missing case can be reproduced with this:
---
#!/bin/sh
# assume, that fs is mounted with compression on src=test-clone-compressed-inline
dd if=/dev/zero of="$src" bs=1K count=3 oflag=sync sync
filefrag -vbs "$src"clone_range "$src" 4096 4096 subvol2/"$src"-dest0 0 clone_range "$src" 4096 4096 subvol2/"$src"-dest4096 4096 clone_range "$src" 4096 4096 subvol2/"$src"-dest8192 8192
---
$ ./test-clone-range-inline 3+0 records in 3+0 records out 3072 bytes (3.1 kB) copied, 0.0487466 s, 63.0 kB/s Filesystem type is: 9123683e File size of test-clone-compressed-inline is 3072 (3 blocks, blocksize 1024) ext logical physical expected length flags 0 0 0 4096 not_aligned,inline,eof test-clone-compressed-inline: 1 extent found clone_range test-clone-compressed-inline 3 4096~4096 to subvol2/test-clone-compressed-inline-dest0 4 0 = -1 Invalid argument clone_range test-clone-compressed-inline 3 4096~4096 to subvol2/test-clone-compressed-inline-dest4096 4 4096 = -1 Invalid argument clone_range test-clone-compressed-inline 3 4096~4096 to subvol2/test-clone-compressed-inline-dest8192 4 8192 = -1 Invalid argument
---
This does not work on a single subvolume, so extending clone to span subvolumes should not break anything that hasn't been broken already.
david
Quoted 6 lines · David Sterba
Quoted 3 lines · Konstantinos Skarlatos
Me too wants cp --reflink across subvolumes. Please make this feature available to us, as its a "poor man's dedupe" and would give big space savings for many use cases.
The simple case of 'cp --reflink' works fine [...]
It doesn't work here:
cp: failed to clone `/tmp/test': Invalid cross-device link
That's with 3.1 + for-linus.
Quoted 7 lines · Marios Titas
Quoted 1 line
The simple case of 'cp --reflink' works fine [...]
It doesn't work here:
cp: failed to clone `/tmp/test': Invalid cross-device link
That's with 3.1 + for-linus.
This is the problem, it doesn't work because you have to apply the patch at http://permalink.gmane.org/gmane.comp.file-systems.btrfs/9865
which is not mainlined yet. This patch dates back from March 31st, I have been using it since it was released.
Is there any reason why this can't be applied in for-linus? Does it need more testing? Still no corruption here after copying the whole root FS in subvolume after btrfs-convert, this FS is used everyday with big image files, clients backups of Windows directories (small files) and 3 snapshots a day, using cp --reflink for whole image copy to test recovery and more.
BTRFS is the only module I need to recompile on this machine after each upgrading the kernel to apply this patch.
Quoted 1 line · On Mon, Jan 9, 2012 at 8:31 AM, J=C3=A9r=C3=B4me Poulin <jeromepoulin@g=…
On Mon, Jan 9, 2012 at 1:58 AM, Marios Titas <[email protected]> w=
rote:
Quoted 10 lines
Quoted 7 lines
Quoted 1 line
The simple case of 'cp --reflink' works fine [...]
It doesn't work here:
cp: failed to clone `/tmp/test': Invalid cross-device link
That's with 3.1 + for-linus.
This is the problem, it doesn't work because you have to apply the patch at http://permalink.gmane.org/gmane.comp.file-systems.btrfs/986=
5
Quoted 2 lines
which is not mainlined yet. This patch dates back from March 31st, I have been using it since it was released.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 14 lines · Christoph Hellwig
Quoted 5 lines · Chris Mason
Excerpts from Christoph Hellwig's message of 2011-03-31 02:36:36 -0400:
Quoted 4 lines · Larry D'Anna
Quoted 2 lines
This is a simple patch to allow reflinks to be made crossing subvolume boundaries.
Quoted 7 lines
Quoted 3 lines
NAK. subvolumes will have to become vfsmounts sooner or later, and we really must not support any operations spanning mountpoints.
Sorry, I disagree here. reflinks were always intended to be able to span subvolumes. There's no conflict at all because they span different inodes.
Quoted 8 lines
I don't think it's a good idea to introduce any user visible operations over subvolume boundaries. Currently we don't have any operations over mount boundaries, which is pretty fumdamental to the unix filesystem semantics. If you want to change this please come up with a clear description of the semantics and post it to linux-fsdevel for discussion. That of course requires a clear description of the btrfs subvolumes, which is still completely missing.
I don't really understand the details here, but doesn't the creation of a snapshot already lead to data extents being shared between sub-volumes? From a simple user perspective this sounds like a very useful capability.
Quoted 4 lines · * Ken Drummond ([email protected]) [110402 11:51]:
I don't really understand the details here, but doesn't the creation of a snapshot already lead to data extents being shared between sub-volumes? From a simple user perspective this sounds like a very useful capability.
I was surprised and frustrated to find it missing. I had just copied a large quantity of data into btrfs, realized i need to make a subvolume to try out snapshotting, and then found out i had to copy all the data *again* to get it into a subvolume. There are tons of scenarios where users will want and expect to be able to do this.
I am very happy to see this patch. It was one of the first thing I tried after making a subvolume, cp --reflink, and it failed. I'll have to try this out.
J=E9r=F4me Poulin
Quoted 2 lines · Larry D'Anna
Quoted 1 line · * Ken Drummond ([email protected]) [110402 11:51]:
I don't really understand the details here, but doesn't the creation=
of
Quoted 5 lines
Quoted 3 lines
a snapshot already lead to data extents being shared between sub-volumes? From a simple user perspective this sounds like a very useful capability.
I was surprised and frustrated to find it missing. I had just copied=
a large
Quoted 1 line
quantity of data into btrfs, realized i need to make a subvolume to t=
ry out
Quoted 1 line
snapshotting, and then found out i had to copy all the data *again* t=
o get it
Quoted 1 line
into a subvolume. There are tons of scenarios where users will want =
and expect
Quoted 3 lines
to be able to do this.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=
" in
Quoted 2 lines
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html