Skip to contentSkip to conversation

Create subvolume from a directory?

DISCUSSION Alex 8 participants 14 messages Mar 27, 2012 – May 14, 2012 Btrfs file system

lore
Share & tools
lore

Alex

author
#0 lore raw

Hi all,

Just a quick question but can't find an obvious answer.

Can I create/convert a existing (btrfs) directory into a subvolume?

It would be very helpful when transferring 'partitions' into btrfs. I found a similar question way back in google, but that site is down now generally.

Thanks in advance.

#1 lore raw
Quoted 4 lines · Alex

Hi all,

Just a quick question but can't find an obvious answer.

Quoted 9 lines

Can I create/convert a existing (btrfs) directory into a subvolume?

It would be very helpful when transferring 'partitions' into btrfs. I found a similar question way back in google, but that site is down now generally.

Thanks in advance.

I don't think this is possible. The closest thing I can think of is to take a snapshot of the volume, move the directory to the top of the subvolume, then delete all other content..

=2E.. That seems like an awful amount of work, but it'll preserve the contents of the directory without making duplicates.

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs=

" in

Quoted 2 lines

the body of a message to [email protected]
More majordomo info at =A0http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw
In reply to Alex

Hello Alex and all,

Quoted 8 lines · On 2012-03-27 T 17:19 +0000 Alex wrote:

Just a quick question but can't find an obvious answer. =20
Can I create/convert a existing (btrfs) directory into a subvolume?
=20
It would be very helpful when transferring 'partitions' into btrfs. I found a similar question way back in google, but that site is down now generally.

As far as I am aware, this is not possible directly. My approach to this would be using copy with reflinks:

------------------------------< snip >------------------------------

## migrate /var/lib/lxc/installserver=20
## from directory to btrfs subvolume

# du -ks /var/lib/lxc/installserver
500332  /var/lib/lxc/installserver
# mv /var/lib/lxc/installserver /var/lib/lxc/installserver_tmp
# btrfs subvol create /var/lib/lxc/installserver
Create subvolume '/var/lib/lxc/installserver'
# time cp -a --reflink /var/lib/lxc/installserver_tmp/rootfs /var/lib/l=
xc/installserver
real    0m1.367s
user    0m0.148s
sys     0m1.108s

## Now remove /var/lib/lxc/installserver_tmp (or not)

------------------------------< snap >------------------------------

Just to compare this with a "mv":

------------------------------< snip >------------------------------

## Go back to former state

# btrfs subvol delete /var/lib/lxc/installserver
Delete subvolume '/var/lib/lxc/installserver'
# btrfs subvol create /var/lib/lxc/installserver
Create subvolume '/var/lib/lxc/installserver'
# time mv /var/lib/lxc/installserver_tmp/rootfs /var/lib/lxc/installser=
ver/
real    0m12.917s
user    0m0.208s=20
sys     0m2.508s=20

------------------------------< snap >------------------------------

While the time measurement might be flawed due to the subvol actions inbetween, caching etc.: I tried several times, and "cp --reflinks" always is multiple times faster than "mv" in my environment.

Or did I misunderstand your question?

so long -
MgE

--=20
Matthias G. Eckermann Senior Product Manager SUSE=C2=AE Linux Ent=
erprise
SUSE LINUX Products GmbH Maxfeldstra=C3=9Fe 5 90409 N=C3=BCrn=
berg Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imend=C3=B6rffer, HRB 16746 (AG N=C3= =BCrnberg)
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#3 lore raw
Quoted 4 lines · Matthias G. Eckermann

While the time measurement might be flawed due to the subvol actions inbetween, caching etc.: I tried several times, and "cp --reflinks" always is multiple times faster than "mv" in my environment.

So this is cross-subvolume reflinks? I thought the code for that wasn't merged yet?

Signature · 1 line
Fajar
#5 lore raw
In reply to Matthias G. Eckermann
Quoted 24 lines · Matthias G. Eckermann

Hello Alex and all,

Quoted 8 lines · On 2012-03-27 T 17:19 +0000 Alex wrote:

Just a quick question but can't find an obvious answer.

Can I create/convert a existing (btrfs) directory into a subvolume?

It would be very helpful when transferring 'partitions' into btrfs. I found a similar question way back in google, but that site is down now generally.

As far as I am aware, this is not possible directly. My approach to this would be using copy with reflinks:

------------------------------< snip >------------------------------

## migrate /var/lib/lxc/installserver
## from directory to btrfs subvolume

# du -ks /var/lib/lxc/installserver
500332  /var/lib/lxc/installserver
Quoted 7 lines
# mv /var/lib/lxc/installserver /var/lib/lxc/installserver_tmp
# btrfs subvol create /var/lib/lxc/installserver
Create subvolume '/var/lib/lxc/installserver'
# time cp -a --reflink /var/lib/lxc/installserver_tmp/rootfs /var/lib/lxc/installserver

This is too much weird.

AFAIK, clone between different subvolumes should be forbidden.
So this would get a "Invalid cross-device link", because an individual subvolume can be mounted directly.

thanks,
liubo

Quoted 38 lines
real    0m1.367s
user    0m0.148s
sys     0m1.108s

## Now remove /var/lib/lxc/installserver_tmp (or not)

------------------------------< snap >------------------------------

Just to compare this with a "mv":

------------------------------< snip >------------------------------

## Go back to former state

# btrfs subvol delete /var/lib/lxc/installserver
Delete subvolume '/var/lib/lxc/installserver'
# btrfs subvol create /var/lib/lxc/installserver
Create subvolume '/var/lib/lxc/installserver'
# time mv /var/lib/lxc/installserver_tmp/rootfs /var/lib/lxc/installserver/
real    0m12.917s
user    0m0.208s 
sys     0m2.508s 

------------------------------< snap >------------------------------

While the time measurement might be flawed due to the subvol actions inbetween, caching etc.: I tried several times, and "cp --reflinks" always is multiple times faster than "mv" in my environment.

Or did I misunderstand your question?

so long -
MgE

#4 lore raw
In reply to Fajar A. Nugraha
Quoted 8 lines · Fajar A. Nugraha
Quoted 4 lines · Matthias G. Eckermann

While the time measurement might be flawed due to the subvol actions inbetween, caching etc.: I tried several times, and "cp --reflinks" always is multiple times faster than "mv" in my environment.

So this is cross-subvolume reflinks? I thought the code for that wasn't merged yet?

Matthias was using SLES kernel, the cross-subvolume reflink patch is present there, he was not aware it's not merged upstream.

david

#6 lore raw
In reply to Liu Bo

Hello Liu

Quoted 9 lines · Liu Bo
Quoted 2 lines · Matthias G. Eckermann
# time cp -a --reflink /var/lib/lxc/installserver_tmp/rootfs /var/lib/lxc/installserver

This is too much weird.

AFAIK, clone between different subvolumes should be forbidden.
So this would get a "Invalid cross-device link", because an individual subvolume can be mounted directly.

Could you elaborate which would be the issue ?
"cp --reflink"-ing a file is not different than snapshotting a file. In any case I could mount a snapshot and not the source subvolume.

Quoted 49 lines

thanks,
liubo

Quoted 33 lines
real    0m1.367s
user    0m0.148s
sys     0m1.108s

## Now remove /var/lib/lxc/installserver_tmp (or not)

------------------------------< snap>------------------------------

Just to compare this with a "mv":

------------------------------< snip>------------------------------

## Go back to former state

# btrfs subvol delete /var/lib/lxc/installserver
Delete subvolume '/var/lib/lxc/installserver'
# btrfs subvol create /var/lib/lxc/installserver
Create subvolume '/var/lib/lxc/installserver'
# time mv /var/lib/lxc/installserver_tmp/rootfs /var/lib/lxc/installserver/
real    0m12.917s
user    0m0.208s
sys     0m2.508s

------------------------------< snap>------------------------------

While the time measurement might be flawed due to the subvol actions inbetween, caching etc.: I tried several times, and "cp --reflinks" always is multiple times faster than "mv" in my environment.

Quoted 5 lines

Or did I misunderstand your question?

so long -
MgE

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
.

#7 lore raw
Quoted 8 lines · Goffredo Baroncelli
Quoted 1 line

Could you elaborate which would be the issue ?
"cp --reflink"-ing a file is not different than snapshotting a file. In any case I could mount a snapshot and not the source subvolume.

We already have a debate about this "cross-link device":
http://comments.gmane.org/gmane.comp.file-systems.btrfs/9864

"cp --reflink" will use clone feature, which can share data among files, but metadata is preserved individually.

My case is that I can mount both a subvolume and a snapshot via "-o subvol=xxx" or "-o subvolid=xxx".

thanks,
liubo

#8 lore raw
Quoted 3 lines · On Thursday 29 of March 2012 09:24:44 Liu Bo wrote:
Quoted 2 lines · Goffredo Baroncelli

Could you elaborate which would be the issue ?
"cp --reflink"-ing a file is not different than snapshotting a file=

=2E In

Quoted 6 lines
Quoted 1 line

any case I could mount a snapshot and not the source subvolume.

=20
We already have a debate about this "cross-link device":
http://comments.gmane.org/gmane.comp.file-systems.btrfs/9864
=20
"cp --reflink" will use clone feature, which can share data among fil=

es, but

Quoted 4 lines

metadata is preserved individually.
=20
My case is that I can mount both a subvolume and a snapshot via "-o subvol=3Dxxx" or "-o subvolid=3Dxxx".

And how is this different from regular snapshot of subvolume? In the en= d you=20
get two files pointing to same data on the disk while having different=20 metadata.

Let me rephrase it:

People don't want to be able to do:

mount /dev/lvm/btrfs /mnt/a -t btrfs -o subvol=3DvolA mount /dev/lvm/btrfs /mnt/b -t btrfs -o subvol=3DvolB cp --reflink=3Dalways /mnt/a/file /mnt/b

Just like you can't do hardlinks over mount --bind mountpoints, you=20 shouldn't be able to cp reflink over mountpoints. That's expected as th= is=20
*does* break VFS semantics.

*But* people want to be able to do this:=20

mount /dev/lvm/btrfs /mnt/ -t btrfs
btrfs subvol create /mnt/subvol
big-file-creator > /mnt/subvol/BIG-file
btrfs subvol snapshot /mnt/subvol /mnt/subvol-bak big-file-editor /mnt/subvol/BIG-file
rm /mnt/subvol-bak/BIG-file
cp --reflink=3Dalways /mnt/subvol/BIG-file /mnt/subvol-bak/BIG-file

This does not cross any VFS boundaries.

Regards,
--=20
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawer=F3w 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" = in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#9 lore raw
Quoted 11 lines · Hubert Kario

Let me rephrase it:

People don't want to be able to do:

mount /dev/lvm/btrfs /mnt/a -t btrfs -o subvol=volA mount /dev/lvm/btrfs /mnt/b -t btrfs -o subvol=volB cp --reflink=always /mnt/a/file /mnt/b

Just like you can't do hardlinks over mount --bind mountpoints, you shouldn't be able to cp reflink over mountpoints. That's expected as this *does* break VFS semantics.

Proposed fix (incremental on top of the cross-subvol):

fs/btrfs/ioctl.c +4 -0
@@ -2321,6 +2321,10 @@ static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd,
                goto out_drop_write;
        }
 
+       ret = -EXDEV;
+       if (src_file->f_path.mnt != file->f_path.mnt)
+               goto out_fput;
+
        src = src_file->f_dentry->d_inode;
 
        ret = -EINVAL;

david

#10 lore raw
Quoted 9 lines · On Wednesday 02 of May 2012 18:33:37 David Sterba wrote:
Quoted 8 lines · Hubert Kario

Let me rephrase it:

People don't want to be able to do:

mount /dev/lvm/btrfs /mnt/a -t btrfs -o subvol=volA mount /dev/lvm/btrfs /mnt/b -t btrfs -o subvol=volB cp --reflink=always /mnt/a/file /mnt/b

Quoted 5 lines
Quoted 3 lines

Just like you can't do hardlinks over mount --bind mountpoints, you shouldn't be able to cp reflink over mountpoints. That's expected as this *does* break VFS semantics.

Proposed fix (incremental on top of the cross-subvol):

I'm a noob as far as kernel development is concerned so take my comments for what they're worth.

fs/btrfs/ioctl.c static noinline long btrfs_ioctl_clone(struct file · line 2325

Quoted 8 lines
fs/btrfs/ioctl.c +2 -0
@@ -2321,6 +2321,10 @@ static noinline long btrfs_ioctl_clone(struct file
 *file, unsigned long srcfd, goto out_drop_write;
        }
 
+       ret = -EXDEV;
+       if (src_file->f_path.mnt != file->f_path.mnt)

I'm not sure about this comparision. Is the f_path struct member used just as reference to some general kernel structure?

fs/btrfs/ioctl.c static noinline long btrfs_ioctl_clone(struct file *file, unsigned long srcfd, · line 2330

Quoted 5 lines
fs/btrfs/ioctl.c +2 -0
+               goto out_fput;
+
        src = src_file->f_dentry->d_inode;
 
        ret = -EINVAL;

Other that that, looks OK.

Regards,

Signature · 5 lines
Hubert Kario
QBS - Quality Business Software
02-656 Warszawa, ul. Ksawerów 30/85
tel. +48 (22) 646-61-51, 646-74-24
www.qbs.com.pl
#11 lore raw
Quoted 11 lines · Hubert Kario

fs/btrfs/ioctl.c static noinline long btrfs_ioctl_clone(struct file · line 2325

Quoted 8 lines
fs/btrfs/ioctl.c +2 -0
@@ -2321,6 +2321,10 @@ static noinline long btrfs_ioctl_clone(struct file
 *file, unsigned long srcfd, goto out_drop_write;
        }
 
+       ret = -EXDEV;
+       if (src_file->f_path.mnt != file->f_path.mnt)

I'm not sure about this comparision. Is the f_path struct member used just as reference to some general kernel structure?

f_path is 'struct path' pointer obtained from a 'struct file' hence the 'f_' prefix, this is a naming scheme used in vfs.

Patch updated in my git repo (branch dev/cross-subvol-clone-v2).

david