aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorLiu Bo <bo.li.liu@oracle.com>2012-09-18 05:52:23 -0400
committerChris Mason <chris.mason@fusionio.com>2012-10-08 20:07:32 -0400
commitaa42ffd918c420d5625b25b7a0bc2bbde4c9f890 (patch)
tree3833ab0e8a2932c58e227947e7f216da64a1da49 /fs
parent7e97b8daf63487c20f78487bd4045f39b0d97cf4 (diff)
Btrfs: fix off-by-one in file clone
Btrfs uses inclusive range end for lock_extent(), unlock_extent() and related functions, so we made off-by-one errors in file clone. This fixes it and also fixes some style problems. Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/ioctl.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 4d7f4bbf4c96..d6836af6d60f 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -2481,13 +2481,13 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2481 another, and lock file content */ 2481 another, and lock file content */
2482 while (1) { 2482 while (1) {
2483 struct btrfs_ordered_extent *ordered; 2483 struct btrfs_ordered_extent *ordered;
2484 lock_extent(&BTRFS_I(src)->io_tree, off, off+len); 2484 lock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
2485 ordered = btrfs_lookup_first_ordered_extent(src, off+len); 2485 ordered = btrfs_lookup_first_ordered_extent(src, off + len - 1);
2486 if (!ordered && 2486 if (!ordered &&
2487 !test_range_bit(&BTRFS_I(src)->io_tree, off, off+len, 2487 !test_range_bit(&BTRFS_I(src)->io_tree, off, off + len - 1,
2488 EXTENT_DELALLOC, 0, NULL)) 2488 EXTENT_DELALLOC, 0, NULL))
2489 break; 2489 break;
2490 unlock_extent(&BTRFS_I(src)->io_tree, off, off+len); 2490 unlock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
2491 if (ordered) 2491 if (ordered)
2492 btrfs_put_ordered_extent(ordered); 2492 btrfs_put_ordered_extent(ordered);
2493 btrfs_wait_ordered_range(src, off, len); 2493 btrfs_wait_ordered_range(src, off, len);
@@ -2561,7 +2561,7 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2561 btrfs_release_path(path); 2561 btrfs_release_path(path);
2562 2562
2563 if (key.offset + datal <= off || 2563 if (key.offset + datal <= off ||
2564 key.offset >= off+len) 2564 key.offset >= off + len - 1)
2565 goto next; 2565 goto next;
2566 2566
2567 memcpy(&new_key, &key, sizeof(new_key)); 2567 memcpy(&new_key, &key, sizeof(new_key));
@@ -2662,8 +2662,8 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
2662 new_key.offset += skip; 2662 new_key.offset += skip;
2663 } 2663 }
2664 2664
2665 if (key.offset + datal > off+len) 2665 if (key.offset + datal > off + len)
2666 trim = key.offset + datal - (off+len); 2666 trim = key.offset + datal - (off + len);
2667 2667
2668 if (comp && (skip || trim)) { 2668 if (comp && (skip || trim)) {
2669 ret = -EINVAL; 2669 ret = -EINVAL;
@@ -2740,7 +2740,7 @@ next:
2740 ret = 0; 2740 ret = 0;
2741out: 2741out:
2742 btrfs_release_path(path); 2742 btrfs_release_path(path);
2743 unlock_extent(&BTRFS_I(src)->io_tree, off, off+len); 2743 unlock_extent(&BTRFS_I(src)->io_tree, off, off + len - 1);
2744out_unlock: 2744out_unlock:
2745 mutex_unlock(&src->i_mutex); 2745 mutex_unlock(&src->i_mutex);
2746 mutex_unlock(&inode->i_mutex); 2746 mutex_unlock(&inode->i_mutex);