fs: Fix default mount when device already mounted
PATCH 1/1 fs: Fix default mount when device already mounted
Let cdev_mount_default return an error in case the device is already mounted to a different location than the default mount point.
Otherwise the automount routine can get stuck in an infinite loop spamming:
mounted /dev/mmc0.0 on /mnt/mmc
mounted /dev/mmc0.0 on /mnt/mmc
mounted /dev/mmc0.0 on /mnt/mmc
--- fs/fs.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
fs/fs.c +19 -9
@@ -951,9 +951,10 @@ const char *cdev_get_mount_path(struct cdev *cdev)/* * cdev_mount_default - mount a cdev to the default path * -* If a cdev is already mounted return the path it's mounted on, otherwise -* mount it to /mnt/<cdevname> and return the path. Returns an error pointer -* on failure. +* If a cdev is already mounted to the default mount path return the path +* it's mounted on. If it is mounted to any other path return EBUSY. +* Otherwise mount it to /mnt/<cdevname> and return the path. Returns an +* error pointer on failure. */ const char *cdev_mount_default (struct cdev *cdev,const char *fsoptions) {
@@ -962,15 +963,24 @@ const char *cdev_mount_default(struct cdev *cdev, const char *fsoptions)int ret;/* -* If this cdev is already mounted somewhere use this path -* instead of mounting it again to avoid corruption on the -* filesystem. Note this ignores eventual fsoptions though. +* If this cdev is already mounted somewhere other than the +* default mount path return -EBUSY instead of mounting it +* again to avoid corruption on the filesystem. Note this +* ignores eventual fsoptions though. If the cdev is already +* mounted on the default path just return that path. */ path =cdev_get_mount_path (cdev); -if (path) -return path; - newpath =basprintf ("/mnt/%s" , cdev->name); + +if (path) { +if (strcmp (newpath, path)) { +free (newpath); +return ERR_PTR (-EBUSY ); + }else { +return path; + } + } +make_directory (newpath); devpath =basprintf ("/dev/%s" , cdev->name);
Signature · 7 lines
2.25.1 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
Hi Stefan,
Quoted 20 lines · Stefan Riedmueller
Let
cdev_mount_defaultreturn an error in case the device is already mounted to a different location than the default mount point.Otherwise the automount routine can get stuck in an infinite loop spamming:
mounted
/dev/mmc0.0on/mnt/mmc
mounted/dev/mmc0.0on/mnt/mmc
mounted/dev/mmc0.0on/mnt/mmcSigned-off-by Stefan Riedmueller <[email protected]>--- fs/fs.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)fs/fs.c +0
-0
fs/fs.c const char *cdev_get_mount_path(struct cdev *cdev) · line 957
Quoted 10 lines
fs/fs.c +4
-3@@ -951,9 +951,10 @@ const char *cdev_get_mount_path(struct cdev *cdev)/* * cdev_mount_default - mount a cdev to the default path * -* If a cdev is already mounted return the path it's mounted on, otherwise -* mount it to /mnt/<cdevname> and return the path. Returns an error pointer -* on failure. +* If a cdev is already mounted to the default mount path return the path +* it's mounted on. If it is mounted to any other path return EBUSY. +* Otherwise mount it to /mnt/<cdevname> and return the path. Returns an +* error pointer on failure.
blspec depends on the return-current-path-when-mounted part you are removing here. I added the following patch before applying this one.
Sascha
------------------------------8<-------------------------------
Quoted 1 line
From
7dc73d3618a15f0d858d5409574f38f9f83905efMon Sep 17 00:00:00 2001
From: Sascha Hauer <[email protected]>
Date: Wed, 17 Mar 2021 10:25:47 +0100
Subject: [PATCH] blspec: Check if already mounted before mounting
cdev_mount_default() either mounts a cdev and returns the path it's mounted to or directly returns the path when it already is mounted. This will change in the next patch: When the cdev is already mounted cdev_mount_default() will return -EBUSY instead. To let blspec work when a cdev is already mounted check for the actual mount path before trying to mount it.
--- common/blspec.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
common/blspec.c +3 -1
@@ -729,7 +729,9 @@ static int blspec_scan_cdev(struct bootentries *bootentries, struct cdev *cdev) found += ret; } - rootpath =cdev_mount_default (cdev,NULL ); + rootpath =cdev_get_mount_path (cdev); +if (!rootpath) + rootpath =cdev_mount_default (cdev,NULL );if (!IS_ERR (rootpath)) { ret =blspec_scan_directory (bootentries, rootpath);if (ret >0 )
Signature · 13 lines
2.29.2 -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 | _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox