Re: BTRFS file clone support for cp

2009-08-10 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Jim Meyering writes: > >> I am now convinced that cp's new behavior belongs on >> a separate option, --reflink (i.e., it should not be the default). >> Giuseppe, do you feel like adding that option and adjusting your >> test accordingly? > > I attached two separate pat

Re: BTRFS file clone support for cp

2009-08-07 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: > >>> + if (clone_file (dest_desc, source_desc)) >>> +{ >>> + error (0, errno, _("cannot fstat %s"), quote (dst_name)); >> >> I prefer this diagnostic ;-) >> >> error (0, errno, _("failed to clone %s"), quote (dst_n

Re: BTRFS file clone support for cp

2009-08-04 Thread Giuseppe Scrivano
Jim Meyering writes: >> + if (clone_file (dest_desc, source_desc)) >> +{ >> + error (0, errno, _("cannot fstat %s"), quote (dst_name)); > > I prefer this diagnostic ;-) > > error (0, errno, _("failed to clone %s"), quote (dst_name)); Too wild copy&paste :) I

Re: BTRFS file clone support for cp

2009-08-04 Thread Jim Meyering
Giuseppe Scrivano wrote: > I attached the cleaned patch, according to your advises. If there are > other things, I'll fix them. Thanks! ... > +...@item --reflink > +...@opindex --reflink > +Attempt a O(1) copy-on-write (COW) when the underlying file system > +supports this operation instead of r

Re: BTRFS file clone support for cp

2009-08-03 Thread Giuseppe Scrivano
Hi Jim, I attached the cleaned patch, according to your advises. If there are other things, I'll fix them. Regards, Giuseppe Jim Meyering writes: > How about this for NEWS: > > cp accepts a new option, --reflink: create a lightweight copy > using copy-on-write (COW). This is currently s

Re: BTRFS file clone support for cp

2009-08-02 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: > >> I am now convinced that cp's new behavior belongs on >> a separate option, --reflink (i.e., it should not be the default). >> Giuseppe, do you feel like adding that option and adjusting your >> test accordingly? > > I attached two separate patch

Re: BTRFS file clone support for cp

2009-08-01 Thread Giuseppe Scrivano
Jim Meyering writes: > I am now convinced that cp's new behavior belongs on > a separate option, --reflink (i.e., it should not be the default). > Giuseppe, do you feel like adding that option and adjusting your > test accordingly? I attached two separate patches, --reflink option and file-clone

Re: BTRFS file clone support for cp

2009-08-01 Thread Giuseppe Scrivano
Jim Meyering writes: > I am now convinced that cp's new behavior belongs on > a separate option, --reflink (i.e., it should not be the default). > Giuseppe, do you feel like adding that option and adjusting your > test accordingly? sure. > Things to adjust, other than copy.c and the test: >

Re: BTRFS file clone support for cp

2009-08-01 Thread Jim Meyering
Pádraig Brady wrote: > Giuseppe Scrivano wrote: >> Pádraig Brady writes: >> +#expensive_ >>> That comment is just for testing I presume? >>> Note you can run a single expensive test like: >>> (cd tests && make check TESTS=cp/file-clone VERBOSE=yes >>> RUN_EXPENSIVE_TESTS=yes) >> >> sorry, ye

Re: BTRFS file clone support for cp

2009-07-31 Thread Jim Meyering
Pádraig Brady wrote: > Giuseppe Scrivano wrote: >> Pádraig Brady writes: >> +#expensive_ >>> That comment is just for testing I presume? >>> Note you can run a single expensive test like: >>> (cd tests && make check TESTS=cp/file-clone VERBOSE=yes >>> RUN_EXPENSIVE_TESTS=yes) >> >> sorry, y

Re: BTRFS file clone support for cp

2009-07-31 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Pádraig Brady writes: > >>> +#expensive_ >> That comment is just for testing I presume? >> Note you can run a single expensive test like: >> (cd tests && make check TESTS=cp/file-clone VERBOSE=yes >> RUN_EXPENSIVE_TESTS=yes) > > sorry, yes I commented it out only for

Re: BTRFS file clone support for cp

2009-07-31 Thread Giuseppe Scrivano
Pádraig Brady writes: >> +#expensive_ > > That comment is just for testing I presume? > Note you can run a single expensive test like: > (cd tests && make check TESTS=cp/file-clone VERBOSE=yes > RUN_EXPENSIVE_TESTS=yes) sorry, yes I commented it out only for testing purpose. If you think the r

Re: BTRFS file clone support for cp

2009-07-30 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Hi Pádraig, > > thanks for the comments. > > Pádraig Brady writes: > >> # 300MB seems to be the minimum size for a btrfs with default >> parameters. > > Actually, it seems the minimum space required is 256MB. Using a 255MB > image I get: "device btrfs.img is too sma

Re: BTRFS file clone support for cp

2009-07-30 Thread Pádraig Brady
Joel Becker wrote: > In some sense, using btrfs, nilfs2i, ocfs2 with refcount trees > enabled, or any other CoW-ish filesystem is a tacit approval of the > delayed ENOSPC. The same can be said of "thin provisioning" LUNs. > However, the other concerns are still valid. A user invoking vanill

Re: BTRFS file clone support for cp

2009-07-30 Thread Joel Becker
On Thu, Jul 30, 2009 at 12:54:16PM +0200, Andi Kleen wrote: > > With classic cp, if I copy a 1GB non-sparse file and there's less > > space than that available, cp fails with ENOSPC. > > With this new feature, it succeeds even if there are > > just a few blocks available. > > > > Also, consider (b

Re: BTRFS file clone support for cp

2009-07-30 Thread Giuseppe Scrivano
Hi Pádraig, thanks for the comments. Pádraig Brady writes: > # 300MB seems to be the minimum size for a btrfs with default > parameters. Actually, it seems the minimum space required is 256MB. Using a 255MB image I get: "device btrfs.img is too small (must be at least 256 MB)" > # FIXME: us

Re: BTRFS file clone support for cp

2009-07-30 Thread Jim Meyering
Ric Wheeler wrote: > I think that doing reflink by default would be a horrible idea - one > good reason to copy a file is to increase your level of fault > tolerance and reflink magically avoids that :-) Good point. This would constitute another user-visible semantic change in cp: a disk fault tha

Re: BTRFS file clone support for cp

2009-07-30 Thread Ric Wheeler
On 07/30/2009 04:40 AM, Pádraig Brady wrote: Jim Meyering wrote: Joel Becker wrote: On Wed, Jul 29, 2009 at 07:14:37PM +0100, Pádraig Brady wrote: At the moment we have these linking options: cp -l, --link #for hardlinks cp -s, --symbolic-link #for symlinks So perhaps we s

Re: BTRFS file clone support for cp

2009-07-30 Thread Andi Kleen
> > With classic cp, if I copy a 1GB non-sparse file and there's less > space than that available, cp fails with ENOSPC. > With this new feature, it succeeds even if there are > just a few blocks available. > > Also, consider (buggy!) code that then depends on being able to modify > that file in-

Re: BTRFS file clone support for cp

2009-07-30 Thread Tomasz Chmielewski
Jim Meyering wrote: With classic cp, if I copy a 1GB non-sparse file and there's less space than that available, cp fails with ENOSPC. With this new feature, it succeeds even if there are just a few blocks available. Is it good or bad? Also, consider (buggy!) code that then depends on being

Re: BTRFS file clone support for cp

2009-07-30 Thread Andi Kleen
Jim Meyering writes: > > Thanks. I haven't looked, but after reading about the reflink syscall > [http://lwn.net/Articles/332802/] had come to the same conclusion: > this feature belongs with ln rather than with cp. cp already has -l so it would make sense to extend that too. > Besides, putting

Re: BTRFS file clone support for cp

2009-07-30 Thread Jim Meyering
Pádraig Brady wrote: > Jim Meyering wrote: >> diff --git a/tests/tail-2/pid b/tests/tail-2/pid >> >> +# Ensure that tail --pid=PID exits successfully when PID is dead. >> +# Use an unlikely-to-be-live PID: 2^31-1 >> +getlimits_ >> +tail --pid=$INT_MAX -f /dev/null || fail=1 > > Probably should use

Re: BTRFS file clone support for cp

2009-07-30 Thread Pádraig Brady
Jim Meyering wrote: > diff --git a/tests/tail-2/pid b/tests/tail-2/pid > > +# Ensure that tail --pid=PID exits successfully when PID is dead. > +# Use an unlikely-to-be-live PID: 2^31-1 > +getlimits_ > +tail --pid=$INT_MAX -f /dev/null || fail=1 Probably should use $PID_T_MAX You could speed up t

Re: BTRFS file clone support for cp

2009-07-30 Thread Jim Meyering
Andi Kleen wrote: > Jim Meyering writes: >> >> Thanks. I haven't looked, but after reading about the reflink syscall >> [http://lwn.net/Articles/332802/] had come to the same conclusion: >> this feature belongs with ln rather than with cp. > > cp already has -l so it would make sense to extend t

Re: BTRFS file clone support for cp

2009-07-30 Thread Pádraig Brady
Andi Kleen wrote: > Jim Meyering writes: >> Thanks. I haven't looked, but after reading about the reflink syscall >> [http://lwn.net/Articles/332802/] had come to the same conclusion: >> this feature belongs with ln rather than with cp. > > cp already has -l so it would make sense to extend that

Re: BTRFS file clone support for cp

2009-07-30 Thread Pádraig Brady
Jim Meyering wrote: > Joel Becker wrote: > >> On Wed, Jul 29, 2009 at 07:14:37PM +0100, Pádraig Brady wrote: >>> >>> At the moment we have these linking options: >>> >>> cp -l, --link #for hardlinks >>> cp -s, --symbolic-link #for symlinks >>> >>> So perhaps we should support: >>> >>> cp --link={s

Re: BTRFS file clone support for cp

2009-07-30 Thread Jim Meyering
Giuseppe Scrivano wrote: > Hi, > > I cleaned a bit the Pádraig's example in a new test case. > > The second patch fixes a problem that I introduced with the commit > e81c4d88c2fce526c02693d539e22c7468dc452b. Thanks for the test. We should be able to use it regardless of whether the feature is add

Re: BTRFS file clone support for cp

2009-07-30 Thread Joel Becker
On Thu, Jul 30, 2009 at 09:39:17AM +0200, Jim Meyering wrote: > Joel Becker wrote: > > I've cooked up 'ln -r' for reflinks, which works for ln(1) but > > not for cp(1). > > Thanks. I haven't looked, but after reading about the reflink syscall > [http://lwn.net/Articles/332802/] had come to th

Re: BTRFS file clone support for cp

2009-07-30 Thread Jim Meyering
Joel Becker wrote: > On Wed, Jul 29, 2009 at 07:14:37PM +0100, Pádraig Brady wrote: >> Chris Mason wrote: >> > On Wed, Jul 29, 2009 at 03:14:49PM +0100, Pádraig Brady wrote: >> >> >> >> We may need to play around with fallocate() >> >> if we want to get back to the original >> >> cp semantics of a

Re: BTRFS file clone support for cp

2009-07-29 Thread Joel Becker
On Wed, Jul 29, 2009 at 07:14:37PM +0100, Pádraig Brady wrote: > Chris Mason wrote: > > On Wed, Jul 29, 2009 at 03:14:49PM +0100, Pádraig Brady wrote: > >> > >> We may need to play around with fallocate() > >> if we want to get back to the original > >> cp semantics of actually allocating space > >

Re: BTRFS file clone support for cp

2009-07-29 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Hi, > > I cleaned a bit the Pádraig's example in a new test case. tests, great! comments below. > The second patch fixes a problem that I introduced with the commit > e81c4d88c2fce526c02693d539e22c7468dc452b. I would have posted that patch in the other "tail" thread.

Re: BTRFS file clone support for cp

2009-07-29 Thread Giuseppe Scrivano
Hi, I cleaned a bit the Pádraig's example in a new test case. The second patch fixes a problem that I introduced with the commit e81c4d88c2fce526c02693d539e22c7468dc452b. Any comment? Regards, Giuseppe >From 555192badb1a02dd730a3385e2540f48033b3de0 Mon Sep 17 00:00:00 2001 From: Giuseppe Scri

Re: BTRFS file clone support for cp

2009-07-29 Thread Chris Mason
On Wed, Jul 29, 2009 at 12:10:14PM -0400, Chris Mason wrote: > On Wed, Jul 29, 2009 at 03:14:49PM +0100, Pádraig Brady wrote: > > Chris Mason wrote: > > > On Tue, Jul 28, 2009 at 10:06:35PM +0200, Giuseppe Scrivano wrote: > > >> > > >> I can't replicate it now, all tests I am doing report that bloc

Re: BTRFS file clone support for cp

2009-07-29 Thread Chris Mason
On Wed, Jul 29, 2009 at 03:14:49PM +0100, Pádraig Brady wrote: > Chris Mason wrote: > > On Tue, Jul 28, 2009 at 10:06:35PM +0200, Giuseppe Scrivano wrote: > >> > >> I can't replicate it now, all tests I am doing report that blocks used > >> before and after the clone are the same. Probably yesterd

Re: BTRFS file clone support for cp

2009-07-29 Thread Chris Mason
On Tue, Jul 28, 2009 at 10:06:35PM +0200, Giuseppe Scrivano wrote: > Hi Pádraig, > > > Pádraig Brady writes: > > > How different exactly? > > OK I tried this myself on F11 with inconclusive results. > > I can't replicate it now, all tests I am doing report that blocks used > before and after t

Re: BTRFS file clone support for cp

2009-07-29 Thread Pádraig Brady
Chris Mason wrote: > On Wed, Jul 29, 2009 at 03:14:49PM +0100, Pádraig Brady wrote: >> >> We may need to play around with fallocate() >> if we want to get back to the original >> cp semantics of actually allocating space >> on the file system for the new file. > > Well, best to just use the origin

Re: BTRFS file clone support for cp

2009-07-29 Thread Pádraig Brady
Chris Mason wrote: > On Tue, Jul 28, 2009 at 10:06:35PM +0200, Giuseppe Scrivano wrote: >> >> I can't replicate it now, all tests I am doing report that blocks used >> before and after the clone are the same. Probably yesterday the >> difference I noticed was in reality the original file flushed t

Re: BTRFS file clone support for cp

2009-07-29 Thread Jim Meyering
Jim Meyering wrote: > Jim Meyering wrote: > >> Andreas Schwab wrote: >> >>> Jim Meyering writes: >>> +#ifdef __linux__ +# define BTRFS_IOC_CLONE 1074041865 >>> >>> This is wrong, the actual value is architecture dependent. You should >>> use the _IOW macro instead. >> >> Good point. T

Re: BTRFS file clone support for cp

2009-07-29 Thread Jim Meyering
Jim Meyering wrote: > Andreas Schwab wrote: > >> Jim Meyering writes: >> >>> +#ifdef __linux__ >>> +# define BTRFS_IOC_CLONE 1074041865 >> >> This is wrong, the actual value is architecture dependent. You should >> use the _IOW macro instead. > > Good point. Thanks! > I've adjusted it. > Here's

Re: BTRFS file clone support for cp

2009-07-28 Thread Giuseppe Scrivano
Hi Pádraig, Pádraig Brady writes: > How different exactly? > OK I tried this myself on F11 with inconclusive results. I can't replicate it now, all tests I am doing report that blocks used before and after the clone are the same. Probably yesterday the difference I noticed was in reality the

Re: BTRFS file clone support for cp

2009-07-28 Thread Jim Meyering
Andreas Schwab wrote: > Jim Meyering writes: > >> +#ifdef __linux__ >> +# define BTRFS_IOC_CLONE 1074041865 > > This is wrong, the actual value is architecture dependent. You should > use the _IOW macro instead. Good point. Thanks! I've adjusted it. Here's the patch I'm considering now: >From

Re: BTRFS file clone support for cp

2009-07-27 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Jim Meyering writes: > >>> Another possible issue with this I can think of is >>> depending on the modification pattern of the COW files, >>> the modification processes could fragment the file or >>> more seriously be given ENOSPC errors. >> I hope btrfs takes care of t

Re: BTRFS file clone support for cp

2009-07-27 Thread Giuseppe Scrivano
Jim Meyering writes: >> Another possible issue with this I can think of is >> depending on the modification pattern of the COW files, >> the modification processes could fragment the file or >> more seriously be given ENOSPC errors. > > I hope btrfs takes care of this behind the scene. > > How do

Re: BTRFS file clone support for cp

2009-07-27 Thread Andreas Schwab
Jim Meyering writes: > +#ifdef __linux__ > +# define BTRFS_IOC_CLONE 1074041865 This is wrong, the actual value is architecture dependent. You should use the _IOW macro instead. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8

Re: BTRFS file clone support for cp

2009-07-27 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: > Adding this optimization should not change the meaning of --sparse=always. >>> >>> So do you want to use it only when --sparse=auto is used? >> >> Precisely. > > I cleaned the patch a bit, the clone operation is done only when > --sparse=

Re: BTRFS file clone support for cp

2009-07-27 Thread Jim Meyering
Pádraig Brady wrote: > Giuseppe Scrivano wrote: >> Hello, >> >> the BTRFS file system, avaiable on Linux since its 2.6.29 version, >> supports file cloning. This simple patch adds the support for this >> feature to the cp utility. > > Right, so using the COW feature of BTRFS to speed up copies, >

Re: BTRFS file clone support for cp

2009-07-26 Thread Pádraig Brady
Giuseppe Scrivano wrote: > Hello, > > the BTRFS file system, avaiable on Linux since its 2.6.29 version, > supports file cloning. This simple patch adds the support for this > feature to the cp utility. Right, so using the COW feature of BTRFS to speed up copies, and reduce space by only writing

Re: BTRFS file clone support for cp

2009-07-26 Thread Giuseppe Scrivano
Jim Meyering writes: >>> Adding this optimization should not change the meaning of >>> --sparse=always. >> >> So do you want to use it only when --sparse=auto is used? > > Precisely. I cleaned the patch a bit, the clone operation is done only when --sparse=auto is used. Regards, Giuseppe >Fro

Re: BTRFS file clone support for cp

2009-07-26 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: >>> ..., a cloned partially-sparse file on btrfs takes less >>> space than a fully-sparse copied file. >> >> That is not true. A fully-sparse file takes less space >> than a partially-sparse one. > > Sorry I wasn't clear, I wanted to say that a clon

Re: BTRFS file clone support for cp

2009-07-26 Thread Giuseppe Scrivano
Jim Meyering writes: >> ..., a cloned partially-sparse file on btrfs takes less >> space than a fully-sparse copied file. > > That is not true. A fully-sparse file takes less space > than a partially-sparse one. Sorry I wasn't clear, I wanted to say that a cloned file in any case take less spac

Re: BTRFS file clone support for cp

2009-07-25 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: > >> However, but what about cp's --sparse option? >> btrfs supports sparse files, so this new code will have to >> honor that. The trouble is that there is currently no option >> to say "preserve precisely and only whatever holes are present >> in

Re: BTRFS file clone support for cp

2009-07-25 Thread Giuseppe Scrivano
Hi Jim, Jim Meyering writes: > However, but what about cp's --sparse option? > btrfs supports sparse files, so this new code will have to > honor that. The trouble is that there is currently no option > to say "preserve precisely and only whatever holes are present > in src", which is the behav

Re: BTRFS file clone support for cp

2009-07-25 Thread Jim Meyering
Giuseppe Scrivano wrote: > Jim Meyering writes: > >> Doesn't that constant, 1074041865, have a symbolic name? >> Maybe BTRFS_IOC_CLONE? > > Yes, it is exactly BTRFS_IOC_CLONE and it is defined in the > fs/btrfs/ioctl.h file. > > >>> Is there an easy and quick way to determine which file system is

Re: BTRFS file clone support for cp

2009-07-25 Thread Giuseppe Scrivano
Jim Meyering writes: > Doesn't that constant, 1074041865, have a symbolic name? > Maybe BTRFS_IOC_CLONE? Yes, it is exactly BTRFS_IOC_CLONE and it is defined in the fs/btrfs/ioctl.h file. >> Is there an easy and quick way to determine which file system is used by >> a file? Probably it would

Re: BTRFS file clone support for cp

2009-07-25 Thread Jim Meyering
Giuseppe Scrivano wrote: > Hello, > > the BTRFS file system, avaiable on Linux since its 2.6.29 version, > supports file cloning. This simple patch adds the support for this > feature to the cp utility. Thanks! I like it. A few comments: Doesn't that constant, 1074041865, have a symbolic name?