[PATCH] discover/device-handler: Fallback to device if snapshot fails to mount

Samuel Mendoza-Jonas sam at mendozajonas.com
Tue Oct 10 14:54:36 AEDT 2017


In the event that a snapshot fails to mount, destroy it and fall back to
the actual source device. While this loses the protection afforded by a
snapshot it avoids users being greeted with an empty boot menu and
unable to continue booting.

Signed-off-by: Samuel Mendoza-Jonas <sam at mendozajonas.com>
---
 discover/device-handler.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/discover/device-handler.c b/discover/device-handler.c
index 4e1b3ca..8ad885f 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -1792,6 +1792,20 @@ static int mount_device(struct discover_device *dev)
 	rc = try_mount(device_path, dev->mount_path, fstype,
 		       MS_RDONLY | MS_SILENT, dev->ramdisk);
 
+	/* If mount fails clean up any snapshot and try again */
+	if (rc && dev->ramdisk) {
+		pb_log("couldn't mount snapshot for %s: mount failed: %s\n",
+				device_path, strerror(errno));
+		pb_log("falling back to actual device\n");
+
+		devmapper_destroy_snapshot(dev);
+
+		device_path = get_device_path(dev);
+		pb_log("mounting device %s read-only\n", dev->device_path);
+		rc = try_mount(device_path, dev->mount_path, fstype,
+			       MS_RDONLY | MS_SILENT, dev->ramdisk);
+	}
+
 	if (!rc) {
 		dev->mounted = true;
 		dev->mounted_rw = false;
@@ -1803,9 +1817,6 @@ static int mount_device(struct discover_device *dev)
 	pb_log("couldn't mount device %s: mount failed: %s\n",
 			device_path, strerror(errno));
 
-	/* If mount fails clean up any snapshot */
-	devmapper_destroy_snapshot(dev);
-
 	pb_rmdir_recursive(mount_base(), dev->mount_path);
 err_free:
 	talloc_free(dev->mount_path);
-- 
2.14.2



More information about the Petitboot mailing list