Skip to contentSkip to conversation

Is it safe to mount subvolumes of already-mounted volumes (even with different options)?

DISCUSSION Sebastian Ochmann 6 participants 7 messages Jul 16, 2014 – Jul 17, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Hello,

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive. The root of the drive is mounted at /mnt/tray and the home directory for machine {hostname} is under /mnt/tray/Homes/{hostname}. Up until now, I have mounted /mnt/tray like a normal volume and then did an additional bind-mount of /mnt/tray/Homes/{hostname} to /home.

Now I have a new drive and wanted to do things a bit more advanced by creating subvolumes for each of the machines' home directories so that I can also do independent snapshotting. I guess I could use the bind-mount method like before but my question is if it is considered safe to do an additional, "regular" mount of one of the subvolumes to /home instead, like

mount /dev/sdxN /mnt/tray
mount -o subvol=/Homes/{hostname} /dev/sdxN /home

When I experimented with such additional mounts of subvolumes of already-mounted volumes, I noticed that the mount options of the additional subvolume mount might differ from the "original" mount. For instance, the root volume might be mounted with "noatime" while the subvolume mount may have "relatime".

So my questions are: Is mounting a subvolume of an already mounted volume considered safe and are there any combinations of possibly conflicting mount options one should be aware of (compression, autodefrag, cache clearing)? Is it advisable to use the same mount options for all mounts pointing to the same physical device?

Best regards,
Sebastian

#1 lore raw
Quoted 3 lines · Sebastian Ochmann

Hello,

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive.

2+ computers writing to the same block device? I don't see how this is safe. Seems possibly a bug that the 1st mount event isn't setting some metadata so that another kernel instance knows not to allow another mount.

Chris Murphy

#4 lore raw
In reply to Sebastian Ochmann

Hi Sebastian,

I posted a similar question and got many helpful answers:
https://www.mail-archive.com/[email protected]/msg35047.html

Basically, you cannot guarantee that the computing mounting /dev/sdx doesn't write to arbitrary addresses of /dev/sdxN as unallocated blocks and thus corrupting the file system on it (I assume sdxN in your example is a sub volume of sdx).

Quoted 36 lines · Sebastian Ochmann

Hello,

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive. The root of the drive is mounted at /mnt/tray and the home directory for machine {hostname} is under /mnt/tray/Homes/{hostname}. Up until now, I have mounted /mnt/tray like a normal volume and then did an additional bind-mount of /mnt/tray/Homes/{hostname} to /home.

Now I have a new drive and wanted to do things a bit more advanced by creating subvolumes for each of the machines' home directories so that I can also do independent snapshotting. I guess I could use the bind-mount method like before but my question is if it is considered safe to do an additional, "regular" mount of one of the subvolumes to /home instead, like

mount /dev/sdxN /mnt/tray
mount -o subvol=/Homes/{hostname} /dev/sdxN /home

When I experimented with such additional mounts of subvolumes of already-mounted volumes, I noticed that the mount options of the additional subvolume mount might differ from the "original" mount. For instance, the root volume might be mounted with "noatime" while the subvolume mount may have "relatime".

So my questions are: Is mounting a subvolume of an already mounted volume considered safe and are there any combinations of possibly conflicting mount options one should be aware of (compression, autodefrag, cache clearing)? Is it advisable to use the same mount options for all mounts pointing to the same physical device?

Best regards,
Sebastian
--
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 Chris Murphy

Hello,

I need to clarify, I'm _not_ sharing a drive between multiple computers at the _same_ time. It's a portable device which I use at different locations with different computers. I just wanted to give a rationale for mounting the whole drive to some mountpoint and then also part of that drive (a subvolume) to the respective computer's /home mountpoint. So it's controlled by the same kernel in the same computer, it's just that part of the filesystem is mounted at multiple mountpoints, much like a bind-mount, but I'm interested in mounting a subvolume of the already-mounted volume to some other mountpoint. Sorry for the confusion.

Best regards
Sebastian

Quoted 12 lines · Chris Murphy
Quoted 3 lines · Sebastian Ochmann

Hello,

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive.

2+ computers writing to the same block device? I don't see how this is safe. Seems possibly a bug that the 1st mount event isn't setting some metadata so that another kernel instance knows not to allow another mount.

Chris Murphy

#5 lore raw
In reply to Sebastian Ochmann
Quoted 6 lines · Sebastian Ochmann

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive. The root of the drive is mounted at /mnt/tray and the home directory for machine {hostname} is under /mnt/tray/Homes/{hostname}. Up until now, I have mounted /mnt/tray like a normal volume and then did an additional bind-mount of /mnt/tray/Homes/{hostname} to /home.

You've said you're not sharing it concurrently, which is good -- as
long as you've only got one machine accessing it at the same time, you're fine there.

Quoted 9 lines

Now I have a new drive and wanted to do things a bit more advanced by creating subvolumes for each of the machines' home directories so that I can also do independent snapshotting. I guess I could use the bind-mount method like before but my question is if it is considered safe to do an additional, "regular" mount of one of the subvolumes to /home instead, like

mount /dev/sdxN /mnt/tray
mount -o subvol=/Homes/{hostname} /dev/sdxN /home

Quoted 8 lines

When I experimented with such additional mounts of subvolumes of already-mounted volumes, I noticed that the mount options of the additional subvolume mount might differ from the "original" mount. For instance, the root volume might be mounted with "noatime" while the subvolume mount may have "relatime".

So my questions are: Is mounting a subvolume of an already mounted volume considered safe

Yes, absolutely:

hrm@amelia:~$ mount | grep btrfs
/dev/sda2 on /boot type btrfs (rw,noatime,space_cache)
/dev/sda2 on /home type btrfs (rw,noatime,space_cache)
/dev/sda2 on /media/video type btrfs (rw,noatime,space_cache)
/dev/sda2 on /media/pipeline type btrfs (rw,noatime,space_cache)
/dev/sda2 on /media/snarf type btrfs (rw,noatime,space_cache)
/dev/sda2 on /media/audio type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/home type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/video type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/testing type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/pipeline type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/audio type btrfs (rw,noatime,space_cache)
/dev/sda2 on /srv/nfs/nadja type btrfs (rw,noatime,space_cache)
Quoted 4 lines

and are there any combinations of possibly conflicting mount options one should be aware of (compression, autodefrag, cache clearing)? Is it advisable to use the same mount options for all mounts pointing to the same physical device?

If you assume that the first mount options are the ones used for
everything, regardless of any different options provided in subsequent mounts, then you probably won't go far wrong. It's not quite true:
some options do work on a per-mount basis, but most are per-filesystem. I'm sure there was a list of them on the wiki at some point, but I can't seem to track it down right now.

Hugo.

Signature · 3 lines
=== Hugo Mills: hugo@... carfax.org.uk | darksatanic.net | lug.org.uk ===
  PGP key: 65E74AC0 from wwwkeys.eu.pgp.net or http://www.carfax.org.uk
      --- Try everything once,  except incest and folk-dancing. ---      
#3 lore raw
In reply to Sebastian Ochmann

-------- Original Message --------
Subject: Re: Is it safe to mount subvolumes of already-mounted volumes (even with different options)?
From: Sebastian Ochmann <[email protected]>
To: Chris Murphy <[email protected]>, [email protected]
Date: 2014年07月17日 15:58

Quoted 6 lines

Hello,

I need to clarify, I'm _not_ sharing a drive between multiple computers at the _same_ time. It's a portable device which I use at different locations with different computers. I just wanted to give a rationale for mounting the whole drive to some mountpoint and then also part of that drive (a subvolume) to the respective computer's /home mountpoint. So it's controlled by the same kernel in the same computer, it's just that part of the filesystem is mounted at multiple mountpoints, much like a bind-mount, but I'm interested in mounting a subvolume of the already-mounted volume to some other mountpoint. Sorry for the confusion.

Best regards
Sebastian

If you mean something like the following use case:

# mount /dev/sdb1 -o subvolid=257 /home
# mount /dev/sdb1 -o subvolid=5 /some/other/place

That is completly OK.

But when it comes to different mount option, especially different ro/rw mount option,
although it is working for 3.16-rc*, the ro/rw mount option is still under disscussion and the current rc implement will cause a kernel warning mounting a subvolume rw when it's first mounted as ro.

So in short:
1) mount subvolumes when the btrfs fs is already mounted. Completly OK.

2) different mount option for different subvolume in one btrfs fs. For most mount option including ro/rw, No.

Thanks,
Qu

Quoted 19 lines · Chris Murphy
Quoted 12 lines · Sebastian Ochmann
Quoted 4 lines

Hello,

I'm sharing a btrfs-formatted drive between multiple computers and each of the machines has a separate home directory on that drive.

2+ computers writing to the same block device? I don't see how this is safe. Seems possibly a bug that the 1st mount event isn't setting some metadata so that another kernel instance knows not to allow another mount.

Chris Murphy

Signature · 3 lines
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
#6 lore raw
In reply to Hugo Mills

Hugo Mills posted on Thu, 17 Jul 2014 09:41:53 +0100 as excerpted:

Quoted 11 lines
Quoted 4 lines

and are there any combinations of possibly conflicting mount options one should be aware of (compression, autodefrag, cache clearing)? Is it advisable to use the same mount options for all mounts pointing to the same physical device?

If you assume that the first mount options are the ones used for
everything, regardless of any different options provided in subsequent mounts, then you probably won't go far wrong. It's not quite true: some options do work on a per-mount basis, but most are per-filesystem. I'm sure there was a list of them on the wiki at some point, but I can't seem to track it down right now.

IIRC/AFAIK, the btrfs-specific mount options should be per filesystem, while stuff like relatime vs noatime is VFS level and should work per subvolume.

There's actually a current discussion about ro vs rw. Consider the case of a parent subvolume (perhaps but not necessarily the root subvolume, id=5), being mounted writable in one location, with a child mounted elsewhere read-only. Because it's possible to browse in the parent's subvolume down into the child subvolume as well, and someone could write a file there, that write would then show up in the elsewhere mounted read- only child subvolume as well.

That's unexpected behavior to say the least! Normally, read-only means it cannot and will not change, but in this case it wouldn't mean that at all!

My idea is that the same rules should apply to ro/rw as apply to btrfs snapshots -- they stop at subvolume borders. Any write into a child subvolume would thus throw an error, regardless of how the parent subvolume was mounted. The only way to write into a subvolume would be to mount it read-write on its own. That would solve the ambiguity, but it would also be quite a change from existing behavior, where a read- write mount of the root subvolume can write into any subvolume.

Someone else suggested that we separate filesystem read-write from subvolume read-write. There's already the concept of read-only snapshots, used in btrfs-send, for one thing. The idea here would be that a read-only filesystem/root mount means the entire filesystem is read-only, but provided the filesystem/root was mounted read-write, individual subvolumes could be mounted read-only using a different option, subv=ro, or similar, which would be hooked into the existing read- only subvolume mechanism. In that case, if the filesystem/root was read- write, then the subvolume specific rw/ro mount option would take precedence and would trigger an error on write to that subvolume even if written from the read-write parent mount.

But while btrfs is the first filesystem to do this sort of thing and thus to deal with the problem, it might not be the last, so policy coordination with the VFS layer should be considered and a generic kernel policy for any filesystem dealing with subvolumes should be established. IOW, it's bigger than simply btrfs.

So anyway, while there was a patch applied earlier that did allow different read-only/read-write subvolume mounts, I believe that's reverted for 3.16, while this discussion continues and until it gets resolved one way or another, possibly at a kernel conference or the like.

But I believe generic VFS stuff like noatime/relatime/atime and dev/nodev/ suid/nosuid/exec/noexec is fine per-subvolume, because that's enforced at the VFS layer and there's no internal or expectation inconsistency to worry about if you can access for example the same device-file as a device via one mountpoint and not by another.

Signature · 3 lines
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman