All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libmount: run btrfs subvol checks for "auto" fs type
@ 2016-01-26 20:59 Stanislav Brabec
  2016-02-01 11:18 ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Brabec @ 2016-01-26 20:59 UTC (permalink / raw)
  To: util-linux

It is possible to mount btrfs using "auto" keyword in fstab. In such
case, btrfs specific checks are skipped. Run them for "auto" as well.

Looking at the code, it is a safe approach. In case of btrfs, it will do
what is needed, in case of no btrfs, btrfs_get_default_subvol_id() will
fail, and the rest of the code is skipped.

How to reproduce:
See reproducer in 2cd28fc and replace fstab line by
	echo "/dev/loop0 $PWD/btrfs_mnt btrfs auto 0 0" >>/etc/fstab

Current behavior of second "mount -a":
	mount: /dev/loop0 is already mounted or /root/btrfs_mnt busy
	       /dev/loop0 is already mounted on /root/btrfs_mnt

Testcases for btrfs and ext4:
	truncate -s1G btrfs_test.img
	truncate -s1G ext4_test.img
	mkdir -p btrfs_mnt
	mkdir -p ext4_mnt
	/sbin/mkfs.btrfs -f -d single -m single ./btrfs_test.img
	/sbin/mkfs.ext4 ./ext4_test.img
	losetup /dev/loop0 $PWD/btrfs_test.img
	losetup /dev/loop1 $PWD/ext4_test.img
	echo "/dev/loop0 $PWD/btrfs_mnt auto defaults 0 0" >>/etc/fstab
	echo "/dev/loop1 $PWD/ext4_mnt auto defaults 0 0" >>/etc/fstab
	./mount -a
	./mount -a
	umount btrfs_mnt
	umount ext4_mnt
	sed -i "/\/dev\/loop[01]/d" /etc/fstab
	losetup -d /dev/loop0
	losetup -d /dev/loop1
	rm btrfs_test.img
	rm ext4_test.img
	rmdir btrfs_mnt
	rmdir ext4_mnt

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
 libmount/src/tab.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libmount/src/tab.c b/libmount/src/tab.c
index 3099615..e8920cb 100644
--- a/libmount/src/tab.c
+++ b/libmount/src/tab.c
@@ -1319,7 +1319,7 @@ struct libmnt_fs *mnt_table_get_fs_root(struct libmnt_table *tb,
 	/*
 	 * btrfs-subvolume mount -- get subvolume name and use it as a root-fs path
 	 */
-	else if (fstype && !strcmp(fstype, "btrfs")) {
+	else if (fstype && (!strcmp(fstype, "btrfs") || !strcmp(fstype, "auto"))) {
 		char *vol = NULL, *p;
 		size_t sz, volsz = 0;
 
-- 
2.7.0

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

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

* Re: [PATCH] libmount: run btrfs subvol checks for "auto" fs type
  2016-01-26 20:59 [PATCH] libmount: run btrfs subvol checks for "auto" fs type Stanislav Brabec
@ 2016-02-01 11:18 ` Karel Zak
  2016-02-01 15:20   ` Stanislav Brabec
  0 siblings, 1 reply; 4+ messages in thread
From: Karel Zak @ 2016-02-01 11:18 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Tue, Jan 26, 2016 at 09:59:55PM +0100, Stanislav Brabec wrote:
> Looking at the code, it is a safe approach. In case of btrfs, it will do
> what is needed, in case of no btrfs, btrfs_get_default_subvol_id() will
> fail, and the rest of the code is skipped.

 It's safe, but "mount -a" is going to call the btrfs ioctl or each
 "auto" fstab entry :-)

 Anyway, applied. Thanks.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

* Re: [PATCH] libmount: run btrfs subvol checks for "auto" fs type
  2016-02-01 11:18 ` Karel Zak
@ 2016-02-01 15:20   ` Stanislav Brabec
  2016-02-02 10:00     ` Karel Zak
  0 siblings, 1 reply; 4+ messages in thread
From: Stanislav Brabec @ 2016-02-01 15:20 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

Karel Zak wrote:
>   It's safe, but "mount -a" is going to call the btrfs ioctl or each
>   "auto" fstab entry :-)
>
I am aware of it. Guessing what is more effective: search for all
candidates in mountinfo and checking whether it is btrfs, or blindly
issuing ioctl() that will:
- quickly fail with EINVAL for non-btrfs
- wil be needed for btrfs anyway

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

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

* Re: [PATCH] libmount: run btrfs subvol checks for "auto" fs type
  2016-02-01 15:20   ` Stanislav Brabec
@ 2016-02-02 10:00     ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2016-02-02 10:00 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Mon, Feb 01, 2016 at 04:20:30PM +0100, Stanislav Brabec wrote:
> Karel Zak wrote:
> >  It's safe, but "mount -a" is going to call the btrfs ioctl or each
> >  "auto" fstab entry :-)
> >
> I am aware of it. Guessing what is more effective: search for all
> candidates in mountinfo and checking whether it is btrfs, or blindly
> issuing ioctl() that will:
> - quickly fail with EINVAL for non-btrfs
> - wil be needed for btrfs anyway

I think the EINVAL based solution is good enough. It's one syscall, be
smart in mountinfo (and canonicalize paths, etc.) is more expensive in
some use-cases.

    Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

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

end of thread, other threads:[~2016-02-02 10:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-26 20:59 [PATCH] libmount: run btrfs subvol checks for "auto" fs type Stanislav Brabec
2016-02-01 11:18 ` Karel Zak
2016-02-01 15:20   ` Stanislav Brabec
2016-02-02 10:00     ` Karel Zak

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.