Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 128765
b: refs/heads/master
c: 5d9cd9e
h: refs/heads/master
i:
  128763: 5d5d72e
v: v3
  • Loading branch information
Chris Mason committed Sep 25, 2008
1 parent 19c2c0c commit e5f7b5c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: b9d86667c94e5fe4bf9f6aa500e7ff1138e717ff
refs/heads/master: 5d9cd9ecbf40b8bd5045a3c2f1feb35db6a12266
79 changes: 47 additions & 32 deletions trunk/fs/btrfs/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -3101,27 +3101,30 @@ long btrfs_ioctl_add_dev(struct btrfs_root *root, void __user *arg)
return ret;
}

void dup_item_to_inode(struct btrfs_trans_handle *trans,
int dup_item_to_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
struct extent_buffer *leaf,
int slot,
struct btrfs_key *key,
u64 destino)
{
struct btrfs_path *cpath = btrfs_alloc_path();
char *dup;
int len = btrfs_item_size_nr(leaf, slot);
int dstoff;
struct btrfs_key ckey = *key;
int ret;
int ret = 0;

dup = kmalloc(len, GFP_NOFS);
if (!dup)
return -ENOMEM;

read_extent_buffer(leaf, dup, btrfs_item_ptr_offset(leaf, slot), len);
btrfs_release_path(root, path);

ckey.objectid = destino;
ret = btrfs_insert_empty_item(trans, root, cpath, &ckey, len);
dstoff = btrfs_item_ptr_offset(cpath->nodes[0], cpath->slots[0]);
copy_extent_buffer(cpath->nodes[0], leaf, dstoff,
btrfs_item_ptr_offset(leaf, slot),
len);
btrfs_release_path(root, cpath);
ret = btrfs_insert_item(trans, root, &ckey, dup, len);
kfree(dup);
return ret;
}

long btrfs_ioctl_clone(struct file *file, unsigned long src_fd)
Expand All @@ -3137,7 +3140,6 @@ long btrfs_ioctl_clone(struct file *file, unsigned long src_fd)
struct btrfs_key key;
struct extent_buffer *leaf;
u32 nritems;
int nextret;
int slot;

src_file = fget(src_fd);
Expand Down Expand Up @@ -3174,28 +3176,41 @@ long btrfs_ioctl_clone(struct file *file, unsigned long src_fd)
mutex_lock(&root->fs_info->fs_mutex);
trans = btrfs_start_transaction(root, 0);
path = btrfs_alloc_path();
if (!path) {
ret = -ENOMEM;
goto out;
}
key.offset = 0;
key.type = BTRFS_EXTENT_DATA_KEY;
key.objectid = src->i_ino;
pos = 0;
path->reada = 2;

while (1) {
ret = btrfs_lookup_file_extent(trans, root, path, src->i_ino,
pos, 0);
/*
* note the key will change type as we walk through the
* tree.
*/
ret = btrfs_search_slot(trans, root, &key, path, 0, 0);
if (ret < 0)
goto out;
if (ret > 0) {
if (path->slots[0] == 0) {
ret = 0;

if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
ret = btrfs_next_leaf(root, path);
if (ret < 0)
goto out;
}
path->slots[0]--;
if (ret > 0)
break;
}
next_slot:
leaf = path->nodes[0];
slot = path->slots[0];
btrfs_item_key_to_cpu(leaf, &key, slot);
nritems = btrfs_header_nritems(leaf);

if (btrfs_key_type(&key) > BTRFS_CSUM_ITEM_KEY ||
key.objectid != src->i_ino)
goto out;
break;

if (btrfs_key_type(&key) == BTRFS_EXTENT_DATA_KEY) {
struct btrfs_file_extent_item *extent;
int found_type;
Expand Down Expand Up @@ -3225,28 +3240,28 @@ long btrfs_ioctl_clone(struct file *file, unsigned long src_fd)
}
pos = key.offset + len;
} else if (found_type == BTRFS_FILE_EXTENT_INLINE) {
dup_item_to_inode(trans, root, path, leaf, slot,
&key, inode->i_ino);
ret = dup_item_to_inode(trans, root, path,
leaf, slot, &key,
inode->i_ino);
if (ret)
goto out;
pos = key.offset + btrfs_item_size_nr(leaf,
slot);
}
} else if (btrfs_key_type(&key) == BTRFS_CSUM_ITEM_KEY)
dup_item_to_inode(trans, root, path, leaf, slot, &key,
inode->i_ino);
} else if (btrfs_key_type(&key) == BTRFS_CSUM_ITEM_KEY) {
ret = dup_item_to_inode(trans, root, path, leaf,
slot, &key, inode->i_ino);

if (slot >= nritems - 1) {
nextret = btrfs_next_leaf(root, path);
if (nextret)
if (ret)
goto out;
} else {
path->slots[0]++;
}
goto next_slot;
key.offset++;
btrfs_release_path(root, path);
}

ret = 0;
out:
btrfs_free_path(path);
ret = 0;

inode->i_blocks = src->i_blocks;
i_size_write(inode, src->i_size);
Expand Down

0 comments on commit e5f7b5c

Please sign in to comment.