From c62ae29ecbc248527a03578fa18e1b6b93506965 Mon Sep 17 00:00:00 2001 From: Samuel Mendoza-Jonas Date: Tue, 10 Oct 2017 13:24:48 +1100 Subject: discover/device-handler: Fallback to device if snapshot fails to mount 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 --- discover/device-handler.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'discover/device-handler.c') 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); -- cgit v1.2.1