Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: David Sterba <dave@jikos.cz>
To: Li Zefan <lizf@cn.fujitsu.com>
Cc: "linux-btrfs@vger.kernel.org" <linux-btrfs@vger.kernel.org>,
	Sage Weil <sage@newdream.net>
Subject: Re: [PATCH 1/2] Btrfs: don't make a file partly checksummed through file clone
Date: Thu, 15 Sep 2011 13:16:38 +0200	[thread overview]
Message-ID: <20110915111638.GD22205@twin.jikos.cz> (raw)
In-Reply-To: <4E703AC1.5060205@cn.fujitsu.com>

On Wed, Sep 14, 2011 at 01:25:21PM +0800, Li Zefan wrote:
> It's because part of the file is checksummed and the other part is not,
> and then btrfs will complain checksum is not found when we read the file.
> 
> Disallow file clone if src and dst file have different checksum flag,
> so we ensure a file is completely checksummed or unchecksummed.

Your fix prevents the bug, but I don't think it's good to let file clone
fail without any other message. ret is set to -EINVAL at the time of
'goto out_fput', which is fine, but the user has no clue what happened
or how to fix it.

The nodatasum status is recorded in inode flags and remains like that
regardless of the 'mount -o nodatasum', persistent and de facto
unchangable (unless the file is created again with the opposite nodatasum
mount). Even more, the user has no way to find out nodatasum flag of
any inode/file (the corresponding FS_NODATASUM_FL is not there).

My suggestion how to fix this:
1. add FS_NODATASUM_FL file flag and code to set/get via setflags ioctl
2. [this patch to skip cloning in case of nodatasum flag mismatch]
3. ... add a printk why it failed

The user then has at least option to drop/add the nodatasum flag for one of
the. Unfortunatelly this makes file cloning less straightforward.


david


> 
> Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
> ---
>  fs/btrfs/ioctl.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
> 
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index 970977a..dc82bbb 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -2177,6 +2177,11 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
>  	if (!(src_file->f_mode & FMODE_READ))
>  		goto out_fput;
>  
> +	/* don't make the dst file partly checksummed */
> +	if ((BTRFS_I(src)->flags & BTRFS_INODE_NODATASUM) !=
> +	    (BTRFS_I(inode)->flags & BTRFS_INODE_NODATASUM))
> +		goto out_fput;
> +
>  	ret = -EISDIR;
>  	if (S_ISDIR(src->i_mode) || S_ISDIR(inode->i_mode))
>  		goto out_fput;
> -- 1.7.3.1 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2011-09-15 11:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-14  5:25 [PATCH 1/2] Btrfs: don't make a file partly checksummed through file clone Li Zefan
2011-09-14  5:25 ` [PATCH 2/2] Btrfs: don't change inode flag of the dest clone file Li Zefan
2011-09-15 11:43   ` David Sterba
2011-09-14 12:17 ` [PATCH 1/2] Btrfs: don't make a file partly checksummed through file clone Sage Weil
2011-09-15 11:16 ` David Sterba [this message]
2011-09-16  3:01   ` Li Zefan

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=20110915111638.GD22205@twin.jikos.cz \
    --to=dave@jikos.cz \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=lizf@cn.fujitsu.com \
    --cc=sage@newdream.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox