Skip to content

Commit

Permalink
discover/device-handler: Fallback to device if snapshot fails to mount
Browse files Browse the repository at this point in the history
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@mendozajonas.com>
  • Loading branch information
sammj committed Oct 11, 2017
1 parent eac7fc0 commit c62ae29
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions discover/device-handler.c
Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit c62ae29

Please sign in to comment.