Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Andrei Borzenkov <arvidjaar@gmail.com>
To: kreijack@inwind.it, linux-btrfs <linux-btrfs@vger.kernel.org>
Subject: Re: cp --reflink and NOCOW files
Date: Wed, 25 May 2022 08:11:07 +0300	[thread overview]
Message-ID: <30c67374-ba93-b613-147b-2fc855419d5e@gmail.com> (raw)
In-Reply-To: <c6f55508-a0df-aea3-279d-75648793dfb2@libero.it>

On 24.05.2022 22:02, Goffredo Baroncelli wrote:
> Hi All,
> 
> recently I discovered that BTRFS doesn't allow to reflink a file
> when the source is marked as NOCOW
> 
> $ lsattr
> ---------------C------ ./file-very-big-nocow
> $ cp --reflink file-very-big-nocow file2
> cp: failed to clone 'file2' from 'file-very-big-nocow': Invalid argument
> $ strace cp --reflink file-very-big-nocow file2 2>&1 | egrep ioctl
> ioctl(4, BTRFS_IOC_CLONE or FICLONE, 3) = -1 EINVAL (Invalid argument)
> 
> My first thought was that it would be sufficient to remove the "nocow" flag.
> But I was unable to do that.
> 
> $ chattr -C file-very-big-nocow
> 
> $ strace cp --reflink file-very-big-nocow file2 2>&1 | egrep ioctl
> ioctl(4, BTRFS_IOC_CLONE or FICLONE, 3) = -1 EINVAL (Invalid argument)
> 
> (I tried "chattr +C ..." too)
> 

E-h-h ... you tried to set this attribute expecting it to be unset as
result?

> Ok, now my question is: how we can remove the NOCOW flag from a file ?
> 

btrfs silently ignores changes to NOCOW for non-empty files.

NOCOW also implies no checksumming. Enabling COW will require rebuilding
all checksums for existing data. I do not say it is impossible, but this
is certainly much more involved than single bit flip.

And disabling COW will (potentially) invalidate all existing references
for which checksums are already stored, and those are likely read-only
and cannot be changed at all. So it is only possible if it is verified
that no other references exist.

> My use case is to move files between subvolumes some of which are marked as NOWCOW.
> The files are videos, so I want to avoid to copy the data.
> 
> 
> BR
> 


  parent reply	other threads:[~2022-05-25  5:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 19:02 cp --reflink and NOCOW files Goffredo Baroncelli
2022-05-25  2:19 ` Matthew Warren
2022-05-25  4:34   ` Forza
2022-05-25 16:15     ` Goffredo Baroncelli
2022-05-25  5:11 ` Andrei Borzenkov [this message]
2022-05-27 14:37 ` Forza

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=30c67374-ba93-b613-147b-2fc855419d5e@gmail.com \
    --to=arvidjaar@gmail.com \
    --cc=kreijack@inwind.it \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox