mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 04/13] fs: add cdev_umount_all()
Date: Mon, 31 Aug 2026 15:20:11 +0200	[thread overview]
Message-ID: <20260831-usb-device-lifetime-v1-4-6adf4054b909@pengutronix.de> (raw)
In-Reply-To: <20260831-usb-device-lifetime-v1-0-6adf4054b909@pengutronix.de>

umount_by_cdev() unmounts the filesystems mounted from one cdev. For a
partitioned device that is not enough: the filesystems are mounted from
the partitions, not from the disk itself, so unmounting the disk leaves
them behind.

Add a variant that walks the partitions as well. This is what a driver
needs when the medium it handed out is gone and the mounts on it have
become useless.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Assisted-by: Claude:claude-opus-5
---
 fs/fs.c      | 31 +++++++++++++++++++++++++++++++
 include/fs.h |  1 +
 2 files changed, 32 insertions(+)

diff --git a/fs/fs.c b/fs/fs.c
index ce41f23f88..f0d3d9fa0a 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -1033,6 +1033,37 @@ int umount_by_cdev(struct cdev *cdev)
 }
 EXPORT_SYMBOL(umount_by_cdev);
 
+/**
+ * cdev_umount_all - unmount everything mounted from a cdev
+ * @cdev: cdev to unmount
+ *
+ * Unmounts the filesystems mounted from @cdev and from its partitions.
+ * Useful for a medium that is gone, where the mounts cannot be used
+ * anymore anyway.
+ *
+ * Return: 0 on success or if nothing was mounted, the first error
+ *         otherwise
+ */
+int cdev_umount_all(struct cdev *cdev)
+{
+	struct cdev *partcdev;
+	int first_error = 0;
+	int ret;
+
+	for_each_cdev_partition(partcdev, cdev) {
+		ret = cdev_umount_all(partcdev);
+		if (ret && !first_error)
+			first_error = ret;
+	}
+
+	ret = umount_by_cdev(cdev);
+	if (ret && !first_error)
+		first_error = ret;
+
+	return first_error;
+}
+EXPORT_SYMBOL(cdev_umount_all);
+
 struct readdir_entry {
 	struct dirent d;
 	struct list_head list;
diff --git a/include/fs.h b/include/fs.h
index 9c3c8d9512..0cc58d73c2 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -112,6 +112,7 @@ static inline bool is_tftp_fs(const char *path)
 
 int flush(int fd);
 int umount_by_cdev(struct cdev *cdev);
+int cdev_umount_all(struct cdev *cdev);
 
 /* not-so-standard functions */
 #define ERASE_SIZE_ALL	((loff_t) - 1)

-- 
2.47.3




  parent reply	other threads:[~2026-08-31 13:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 13:20 [PATCH 00/13] USB: Make USB devices removable Sascha Hauer
2026-08-31 13:20 ` [PATCH 01/13] usb: don't report device removal after the device name is gone Sascha Hauer
2026-08-31 13:20 ` [PATCH 02/13] fs: devfs: count an open partition as an open device Sascha Hauer
2026-08-31 13:20 ` [PATCH 03/13] block: propagate errors from blockdevice_unregister() Sascha Hauer
2026-08-31 13:20 ` Sascha Hauer [this message]
2026-08-31 13:20 ` [PATCH 05/13] block: add blockdevice_unregister_removed() Sascha Hauer
2026-08-31 13:20 ` [PATCH 06/13] usb: storage: tear the disk down properly on disconnect Sascha Hauer
2026-08-31 13:20 ` [PATCH 07/13] usb: hub: cancel pending port scans of a removed device Sascha Hauer
2026-08-31 13:20 ` [PATCH 08/13] usb: reuse the addresses of removed devices Sascha Hauer
2026-08-31 13:20 ` [PATCH 09/13] usb: hub: detect disconnected devices Sascha Hauer
2026-08-31 13:20 ` [PATCH 10/13] usb: don't keep a dangling root device on enumeration failure Sascha Hauer
2026-08-31 13:20 ` [PATCH 11/13] usb: hub: limit the number of ports to USB_MAXCHILDREN Sascha Hauer
2026-08-31 13:20 ` [PATCH 12/13] usb: detect unplugged devices on transfer errors Sascha Hauer
2026-08-31 13:20 ` [PATCH 13/13] usb: storage: stop talking to a device that is gone Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260831-usb-device-lifetime-v1-4-6adf4054b909@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox