All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sage Weil <sage@newdream.net>
To: Li Dongyang <jerry87905@gmail.com>
Cc: linux-btrfs@vger.kernel.org
Subject: Re: cp --reflink with Btrfs
Date: Wed, 16 Dec 2009 09:55:43 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.64.0912160943280.2801@cobra.newdream.net> (raw)
In-Reply-To: <4b287dd5.5744f10a.3536.2011@mx.google.com>

On Wed, 16 Dec 2009, Li Dongyang wrote:

> Have a look at line 998, ioctl.c, inside btrfs_ioctl_clone(),
> the src->i_size(the size of the testfile created by touch) is just 0, and this 
> will cause btrfs_ioctl_clone just return -EINVAL.
> I'm not sure if it makes sense to clone a file which actually doesn't have any 
> data extents.

Probably not, but it seems more consistent to return success instead than 
-EINVAL.  Requiring the caller to check and special case empty files isn't 
very friendly...

sage

---
Subject: [PATCH] Btrfs: return success when cloning 0 byte range at eof

We currently return -EINVAL when cloning a zero byte range at EOF (most 
commonly when cloning a 0 byte file).  Return success instead, even though 
this is a no-op.

Signed-off-by: Sage Weil <sage@newdream.net>
---
 fs/btrfs/ioctl.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index cdbb054..1a964a4 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -994,8 +994,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
 	}
 
 	/* determine range to clone */
+	ret = 0;
+	if (off == src->i_size && len == 0)
+		goto out_unlock;
 	ret = -EINVAL;
-	if (off >= src->i_size || off + len > src->i_size)
+	if (off > src->i_size || off + len > src->i_size)
 		goto out_unlock;
 	if (len == 0)
 		olen = len = src->i_size - off;
-- 
1.6.5


  reply	other threads:[~2009-12-16 17:55 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-13  0:29 cp --reflink with Btrfs Jason White
2009-12-14 16:23 ` Josef Bacik
2009-12-15 23:37   ` Jason White
2009-12-16  6:27     ` Li Dongyang
2009-12-16 17:55       ` Sage Weil [this message]
2010-01-27 10:53 Andreas Barth
2010-01-28 21:09 ` Chris Mason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.64.0912160943280.2801@cobra.newdream.net \
    --to=sage@newdream.net \
    --cc=jerry87905@gmail.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.