2013-09-24 18:36:59

by Thomas Meyer

[permalink] [raw]
Subject: Copy on write hard links?

Hi,

Is there such a thing?

With kind regards
Thomas


2013-09-25 01:40:46

by Adam Borowski

[permalink] [raw]
Subject: Re: Copy on write hard links?

On Tue, Sep 24, 2013 at 08:36:56PM +0200, Thomas Meyer wrote:
> Is there such a thing?

In mainline, AFAIK no. The vserver patchset, on the other hand, adds a new
xattr, iunlink, that copies the whole file when needed. That works on most
filesystems.

That's quite a hack, though, and I think you'd be better off using btrfs
which does cow transparently at a lower level than hardlinks.

--
ᛊᚨᚾᛁᛏᚣ᛫ᛁᛊ᛫ᚠᛟᚱ᛫ᚦᛖ᛫ᚹᛖᚨᚲ

2013-09-25 13:59:36

by Rob Landley

[permalink] [raw]
Subject: Re: Copy on write hard links?

On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
> Hi,
>
> Is there such a thing?

In the kernel's vfs layer? No, although some filesystems (ala btrfs) do
things like that with snapshots.

In userspace? Breaking hardlinks when updating a file is fairly normal,
that's why they distinguish between "truncate and rewrite" (preserve
hardlinks) and "write new file and rename over old file" (break
hardlinks, avoiding the more obvious race conditions).

Rob-

2013-09-25 14:29:09

by Thomas Meyer

[permalink] [raw]
Subject: Re: Copy on write hard links?

Am Mittwoch, den 25.09.2013, 08:59 -0500 schrieb Rob Landley:
> On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
> > Hi,
> >
> > Is there such a thing?
>
> In the kernel's vfs layer?

Yes, that would be a nice feature!

> No, although some filesystems (ala btrfs) do
> things like that with snapshots.
>
> In userspace? Breaking hardlinks when updating a file is fairly normal,
> that's why they distinguish between "truncate and rewrite" (preserve
> hardlinks) and "write new file and rename over old file" (break
> hardlinks, avoiding the more obvious race conditions).

so every user space application needs to implement that for itself?
I wonder how hard it would be to implement this on vfs layer? linkat()
with a new flag as api or something like that.

>
> Rob

2013-09-25 14:37:25

by Richard Weinberger

[permalink] [raw]
Subject: Re: Copy on write hard links?

On Wed, Sep 25, 2013 at 4:28 PM, Thomas Meyer <[email protected]> wrote:
> Am Mittwoch, den 25.09.2013, 08:59 -0500 schrieb Rob Landley:
>> On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
>> > Hi,
>> >
>> > Is there such a thing?
>>
>> In the kernel's vfs layer?
>
> Yes, that would be a nice feature!

You mean reflinks?
Currently only OCFS2 and btrfs support them.
Both using a fs specific ioctl().
IIRC GNU cp uses the btrfs specific one if the --reflink parameter is used.

--
Thanks,
//richard

2013-09-29 05:34:14

by Pádraig Brady

[permalink] [raw]
Subject: Re: Copy on write hard links?

On 09/25/2013 03:37 PM, richard -rw- weinberger wrote:
> On Wed, Sep 25, 2013 at 4:28 PM, Thomas Meyer <[email protected]> wrote:
>> Am Mittwoch, den 25.09.2013, 08:59 -0500 schrieb Rob Landley:
>>> On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
>>>> Hi,
>>>>
>>>> Is there such a thing?
>>>
>>> In the kernel's vfs layer?
>>
>> Yes, that would be a nice feature!
>
> You mean reflinks?
> Currently only OCFS2 and btrfs support them.
> Both using a fs specific ioctl().
> IIRC GNU cp uses the btrfs specific one if the --reflink parameter is used.

coreutils is waiting for a reflink syscall to materialize
rather than adding new per filesystem support
http://lwn.net/Articles/335380/

thanks,
P?draig.

2013-09-29 07:14:28

by Richard Weinberger

[permalink] [raw]
Subject: Re: Copy on write hard links?

On Sun, Sep 29, 2013 at 7:22 AM, P?draig Brady <[email protected]> wrote:
> On 09/25/2013 03:37 PM, richard -rw- weinberger wrote:
>> On Wed, Sep 25, 2013 at 4:28 PM, Thomas Meyer <[email protected]> wrote:
>>> Am Mittwoch, den 25.09.2013, 08:59 -0500 schrieb Rob Landley:
>>>> On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
>>>>> Hi,
>>>>>
>>>>> Is there such a thing?
>>>>
>>>> In the kernel's vfs layer?
>>>
>>> Yes, that would be a nice feature!
>>
>> You mean reflinks?
>> Currently only OCFS2 and btrfs support them.
>> Both using a fs specific ioctl().
>> IIRC GNU cp uses the btrfs specific one if the --reflink parameter is used.
>
> coreutils is waiting for a reflink syscall to materialize
> rather than adding new per filesystem support
> http://lwn.net/Articles/335380/

Is this the correct link? It's a proposal for a reflink() syscall.
But corrently both OCFS2 and btrfs are using ioctl().

Digging into GNU coreutils shows that their cp's
clone_file() only supports the btrfs ioctl().
I don't know what the GNU folks big plan is, maybe you know more. :-)

--
Thanks,
//richard

2013-09-29 17:19:15

by Pádraig Brady

[permalink] [raw]
Subject: Re: Copy on write hard links?

On 09/29/2013 08:14 AM, Richard Weinberger wrote:
> On Sun, Sep 29, 2013 at 7:22 AM, P?draig Brady <[email protected]> wrote:
>> On 09/25/2013 03:37 PM, richard -rw- weinberger wrote:
>>> On Wed, Sep 25, 2013 at 4:28 PM, Thomas Meyer <[email protected]> wrote:
>>>> Am Mittwoch, den 25.09.2013, 08:59 -0500 schrieb Rob Landley:
>>>>> On 09/24/2013 01:36:56 PM, Thomas Meyer wrote:
>>>>>> Hi,
>>>>>>
>>>>>> Is there such a thing?
>>>>>
>>>>> In the kernel's vfs layer?
>>>>
>>>> Yes, that would be a nice feature!
>>>
>>> You mean reflinks?
>>> Currently only OCFS2 and btrfs support them.
>>> Both using a fs specific ioctl().
>>> IIRC GNU cp uses the btrfs specific one if the --reflink parameter is used.
>>
>> coreutils is waiting for a reflink syscall to materialize
>> rather than adding new per filesystem support
>> http://lwn.net/Articles/335380/
>
> Is this the correct link? It's a proposal for a reflink() syscall.
> But corrently both OCFS2 and btrfs are using ioctl().
>
> Digging into GNU coreutils shows that their cp's
> clone_file() only supports the btrfs ioctl().
> I don't know what the GNU folks big plan is, maybe you know more. :-)

The current coreutils plan is to not to call any more file system specific ioctls,
rather waiting until a more general syscall is available.

thanks,
P?draig.