All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: return error when we specify wrong start
@ 2013-04-16  8:40 Liu Bo
  2013-04-16  8:44 ` Jan Schmidt
  0 siblings, 1 reply; 3+ messages in thread
From: Liu Bo @ 2013-04-16  8:40 UTC (permalink / raw)
  To: linux-btrfs

We need such a sanity check for wrong start, otherwise, even with
a wrong start that's larger than file size, we can end up not only
changing inode's force compress flag but also FS's incompat flags.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/ioctl.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index 69cd80d..262d9db 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -1152,8 +1152,11 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 	u64 new_align = ~((u64)128 * 1024 - 1);
 	struct page **pages = NULL;
 
-	if (extent_thresh == 0)
-		extent_thresh = 256 * 1024;
+	if (isize == 0)
+		return 0;
+
+	if (range->start >= isize)
+		return -EINVAL;
 
 	if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) {
 		if (range->compress_type > BTRFS_COMPRESS_TYPES)
@@ -1162,8 +1165,8 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
 			compress_type = range->compress_type;
 	}
 
-	if (isize == 0)
-		return 0;
+	if (extent_thresh == 0)
+		extent_thresh = 256 * 1024;
 
 	/*
 	 * if we were not given a file, allocate a readahead
-- 
1.7.7


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Btrfs: return error when we specify wrong start
  2013-04-16  8:40 [PATCH] Btrfs: return error when we specify wrong start Liu Bo
@ 2013-04-16  8:44 ` Jan Schmidt
  2013-04-16  9:13   ` Liu Bo
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Schmidt @ 2013-04-16  8:44 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs

On Tue, April 16, 2013 at 10:40 (+0200), Liu Bo wrote:
> We need such a sanity check for wrong start, otherwise, even with
> a wrong start that's larger than file size, we can end up not only
> changing inode's force compress flag but also FS's incompat flags.

That reads out very cryptic. Can you please add something hinting at "defrag" to
the title or at least the description?

Thanks,
-Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Btrfs: return error when we specify wrong start
  2013-04-16  8:44 ` Jan Schmidt
@ 2013-04-16  9:13   ` Liu Bo
  0 siblings, 0 replies; 3+ messages in thread
From: Liu Bo @ 2013-04-16  9:13 UTC (permalink / raw)
  To: Jan Schmidt; +Cc: linux-btrfs

On Tue, Apr 16, 2013 at 10:44:33AM +0200, Jan Schmidt wrote:
> On Tue, April 16, 2013 at 10:40 (+0200), Liu Bo wrote:
> > We need such a sanity check for wrong start, otherwise, even with
> > a wrong start that's larger than file size, we can end up not only
> > changing inode's force compress flag but also FS's incompat flags.
> 
> That reads out very cryptic. Can you please add something hinting at "defrag" to
> the title or at least the description?

Oh yeah, my bad.

thanks,
liubo

> 
> Thanks,
> -Jan

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-16  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-16  8:40 [PATCH] Btrfs: return error when we specify wrong start Liu Bo
2013-04-16  8:44 ` Jan Schmidt
2013-04-16  9:13   ` Liu Bo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.