public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] proposal for a btrfs filesystem layout
@ 2009-11-20 18:50 Goffredo Baroncelli
  2009-11-20 19:24 ` David Nicol
  2009-11-20 19:54 ` Chris Mason
  0 siblings, 2 replies; 9+ messages in thread
From: Goffredo Baroncelli @ 2009-11-20 18:50 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Chris Ball

Hi all,

after the Chirs (Ball) email, I thought about a possible btrfs file-system 
layout, which may permit to snapshot the root and mount (if required) an old 
snapshot of the root.

A btrfs file-system has the capability to be partitioned in subvolumes. Every 
subvolume has a name. The root of the btrfs file-system is itself a volume, 
called "." (dot).
At the mount time using the option subvol= it is possible to mount a specific 
subvolume. If nothing is specified the subvol "." (dot) is mounted.

My idea is that the root of the file-system has to be a subvolume of a btrfs 
file-system. Then the subvolume "." is mounted under a subdirectory and is 
used only for managing the snapshot of the root file-system.

In order to be more clear I will use the following nomenclature:

- root of the file-system (or fs root):
	the root of system. This directory contains /bin, /sbin, /usr...

- root of a btrfs files-system (or btrfs root):
	the root of a btrfs file-system which contains the subvolumes. This is
	still a subvolume called "." (dot)

Under the btrfs root a subvolume named "rootfs" is created, this will contain 
the fs root. Also the fs root snapshots are created under the btrfs root.
In order to access the btrfs root and handle the fs root subvolume and its 
snapshots, the btrfs root is mounted under /var/run/btrfs.

To mount the fs root, the option "subvol=rootfs" has to be used used (for 
example in the initramfs). 
# mount -t btrfs -o subvol=rootfs /dev/sdxx /

To mount the btrfs root, the option "subvol=." has to be used . 
# mount -t btrfs -o subvol=. /dev/sdxx /var/run/btrfs

Note 1) the "rootfs" volume is a portion of the real btrfs.
Note 2) if only the "rootfs" volume is mounted is impossible to access to all 
data contained in the btrfs file-system. In order to access to the btrfs root, 
this has to be mounted under a sub-directory of the "rootfs" volume
Note 3) the files contained in the "rootfs" volume appear two times:
 - under / (where the "rootfs" volume is mounted)
 - under /var/run/btrfs/rootfs (if the "." volume is mounted under
    /var/run/btrfs)
Note 4) snapshotting a volume doesn't affect the other volumes, even though 
these volumes are mounted or located under the volume snapshotted.

This is a time for the ascii art:

*Real* btrfs filesystem layout (or the volume called ".")

/  \                  <--- "." volume 
   rootfs \           <--- "rootfs" volume
           !- bin 
           !- sbin
           !- etc
           !- usr
           !- [...]
   snap1  \          <---- 1st snapshot of the rootfs volume
           !- bin
           !- sbin
           !- etc
           !- usr
           !- [...]
   snap1  \          <---- 2st snapshot of the rootfs volume
           !- bin
           !- sbin
           !- etc
           !- usr
           !- [...]


*Effective* file-system layout:

/  \                                              <--- "rootfs" volume
    !- bin 
    !- sbin
    !- etc
    !- usr
    [...]
    !- var \
            !- run \
                   ! - btrfs \                  <--- "." volume
                              ! -  rootfs \     <--- "rootfs" volume(2nd time)
                                          !- bin 
                                          !- sbin
                                          [...]
                              ! -  snap1 \     <--- 1st snapshot
                                          [...]
                              ! -  snap2 \     <--- 1st snapshot
                                          [...]




Below I will show some use cases:
1) system install
2) fs root snapshotting
3) exchange the root with a old snapshot (a reboot is required)



** 1) System install

root@host:/> mkfs.btrfs /dev/sdxx
root@host:/> mount -t btrfs /dev/sdxx /media/btrfs-test
root@host:/ cd /media/btrfs-test
root@host:/media/btrfs-test> btrfsctl -S rootfs .
root@host:/media/btrfs-test> ls -l
drwx------ 1 root root 160 2009-11-20 17:22 rootfs
root@host:/media/btrfs-test> cd rootfs
root@host:/media/btrfs-test/rootfs> debootstrap sid .  # install packages
						       # under the rootfs volume
[... config the system ...]

root@host:/media/btrfs-test/rootfs> ls
bin   dev  home  lib64       media  opt   root  selinux  sys  usr
boot  etc  lib   lost+found  mnt    proc  sbin  srv      tmp  var

root@host:/media/btrfs-test/rootfs> mkdir /var/run/btrfs
root@host:/media/btrfs-test/rootfs> cd /
root@host:/> umount /media/btrfs.test
root@host:/> mount -t btrfs -o subvol=rootfs /dev/sdxx /media/btrfs-test
root@host:/> chroot /media/btrfs-test

root@guest:/> ls /
bin   dev  home  lib64       media  opt   root  selinux  sys  usr
boot  etc  lib   lost+found  mnt    proc  sbin  srv      tmp  var

root@guest:/> mount -t btrfs -o subvol=. /dev/sdxx /var/run/btrfs
root@guest:/> ls /var/run/btrfs
rootfs

root@guest:/> # to mount automatically the btrfs root under /var/run/btrfs
root@guest:/> echo "/dev/sdxx /var/run/btrfs btrfs subvol=. 0 0" >>/etc/fstab 


** 2) system snapshot

root@guest:/> cd /var/run/btrfs
root@guest:/var/run/btrfs> ls
rootfs

root@guest:/var/run/btrfs> btrfsctl -s snap-of-root /.
root@guest:/var/run/btrfs> ls
rootfs snap-of-root
root@guest:/var/run/btrfs> ls snap-of-root
bin   dev  home  lib64       media  opt   root  selinux  sys  usr
boot  etc  lib   lost+found  mnt    proc  sbin  srv      tmp  var

root@guest:/var/run/btrfs> touch /root/old-root-witness
root@guest:/var/run/btrfs> ls rootfs/root
old-root-witness
root@guest:/var/run/btrfs> ls snap-of-root/root
root@guest:/var/run/btrfs>

** 3) exchange the fs root with an its (older) snapshot
root@guest:/var/run/btrfs> ls /root
old-root-witness
root@guest:/var/run/btrfs> ls
rootfs snap-of-root
root@guest:/var/run/btrfs> mv rootfs rootfs-old
root@guest:/var/run/btrfs> mv snap-of-root rootfs
root@guest:/var/run/btrfs> ls
rootfs rootfs-old
root@guest:/var/run/btrfs> reboot
[...]
root@guest:/> ls root
root@guest:/> ls /var/run/btrfs
rootfs rootfs-old


Any comments ? 
BR
G.Baroncelli
-- 
gpg key@ keyserver.linux.it: Goffredo Baroncelli (ghigo) <kreijackATinwind.it>
Key fingerprint = 4769 7E51 5293 D36C 814E  C054 BF04 F161 3DC5 0512

^ permalink raw reply	[flat|nested] 9+ messages in thread
* Re: [RFC] proposal for a btrfs filesystem layout
@ 2009-11-24 18:27 Goffredo Baroncelli
  0 siblings, 0 replies; 9+ messages in thread
From: Goffredo Baroncelli @ 2009-11-24 18:27 UTC (permalink / raw)
  To: chris.mason; +Cc: kreijack, linux-btrfs

Chris Mason wrote:
> On Sat, Nov 21, 2009 at 12:31:06AM +0100, Goffredo Baroncelli wrote:
[...]
> > My concern is about the btrfs user interface.
> > The biggest difficult that I had to learn the btrfs capabilities is its "user-
> > interface". I have to admit to be not the smartest person, but I spent a lot 
> > of time in order to understand which was the difference between a btrfs 
> > subvolume creation and a "mkfs + mount".
> > Finally I concluded that there no is difference (except the COW behaviour and 
> > other implementation detail). My impression was that in some area too often 
> > the VFS and btrfs do the same things. [*]
> > The point is that if btrfs do the same things of VFS, this may be called as 
> > "flexibility". 
> > But the history has highlight that from a long term point of view is the 
> > orthogonality of the subsystems that leads to the flexibility of the system..
> 
> Well, btrfs is using the VFS to expose the subvolumes.  Basically a
> subvolume is a special directory.

Let me explain better: what I would say was to expose the sub-volume content *only* with a command like "mount -o subvol=<name>".
To day when I create a snapshot, automatically it is placed in the btrfs filesystem with the snapshot name. IIRC when I move (rename) the directory I change the subvolume/snapshot name also.
Yes, I can remount the sub-volume with the mount command anywhere and with an arbitrary name. In fact the thing that seems strange to me is that when I create a snapshot, immediately it is mounted: it is not a real problem, it is only a strange behaviour. The "standard" behaviour is to create the file-system and then mount it: two separate actions.

> -chris
Goffredo



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-11-24 18:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-20 18:50 [RFC] proposal for a btrfs filesystem layout Goffredo Baroncelli
2009-11-20 19:24 ` David Nicol
2009-11-20 19:50   ` Chris Mason
2009-11-20 20:05     ` David Nicol
2009-11-24  1:26       ` Chris Mason
2009-11-20 19:54 ` Chris Mason
2009-11-20 23:31   ` Goffredo Baroncelli
2009-11-24  1:27     ` Chris Mason
  -- strict thread matches above, loose matches on Subject: below --
2009-11-24 18:27 Goffredo Baroncelli

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox