X-Git-Url: http://git.ozlabs.org/?p=petitboot;a=blobdiff_plain;f=discover%2Fdevice-handler.c;h=69665fa00dbf5caaac309c2c17ce5f62e495968d;hp=cd16399c4bd175d5a2f63c920772b00fafcfe940;hb=203ad2cb596a4b8df13df4afdc8d7e0d999a5fd5;hpb=d2f71341c8077c649c00f75c1f6c3f590c1b2576 diff --git a/discover/device-handler.c b/discover/device-handler.c index cd16399..69665fa 100644 --- a/discover/device-handler.c +++ b/discover/device-handler.c @@ -26,6 +26,7 @@ #include "device-handler.h" #include "discover-server.h" +#include "devmapper.h" #include "user-event.h" #include "platform.h" #include "event.h" @@ -456,6 +457,7 @@ struct { } device_type_map[] = { { IPMI_BOOTDEV_NETWORK, DEVICE_TYPE_NETWORK }, { IPMI_BOOTDEV_DISK, DEVICE_TYPE_DISK }, + { IPMI_BOOTDEV_DISK, DEVICE_TYPE_USB }, { IPMI_BOOTDEV_CDROM, DEVICE_TYPE_OPTICAL }, }; @@ -860,7 +862,7 @@ int device_handler_discover(struct device_handler *handler, status = talloc_zero(handler, struct boot_status); status->type = BOOT_STATUS_INFO; - status->message = talloc_asprintf(status, "Processing %s device %s", + status->message = talloc_asprintf(status, _("Processing %s device %s"), device_type_display_name(dev->device->type), dev->device->id); boot_status(handler, status); @@ -885,7 +887,7 @@ int device_handler_discover(struct device_handler *handler, device_handler_discover_context_commit(handler, ctx); out: - status->message = talloc_asprintf(status,"Processing %s complete\n", + status->message = talloc_asprintf(status,_("Processing %s complete\n"), dev->device->id); boot_status(handler, status); @@ -904,7 +906,7 @@ int device_handler_dhcp(struct device_handler *handler, status = talloc_zero(handler, struct boot_status); status->type = BOOT_STATUS_INFO; - status->message = talloc_asprintf(status, "Processing dhcp event on %s", + status->message = talloc_asprintf(status, _("Processing dhcp event on %s"), dev->device->id); boot_status(handler, status); @@ -916,7 +918,7 @@ int device_handler_dhcp(struct device_handler *handler, device_handler_discover_context_commit(handler, ctx); - status->message = talloc_asprintf(status,"Processing %s complete\n", + status->message = talloc_asprintf(status,_("Processing %s complete\n"), dev->device->id); boot_status(handler, status); @@ -935,7 +937,7 @@ int device_handler_conf(struct device_handler *handler, status = talloc_zero(handler, struct boot_status); status->type = BOOT_STATUS_INFO; - status->message = talloc_asprintf(status, "Processing user config"); + status->message = talloc_asprintf(status, _("Processing user config")); boot_status(handler, status); /* create our context */ @@ -947,7 +949,7 @@ int device_handler_conf(struct device_handler *handler, device_handler_discover_context_commit(handler, ctx); status->message = talloc_asprintf(status, - "Processing user config complete"); + _("Processing user config complete")); boot_status(handler, status); talloc_free(status); @@ -1223,28 +1225,46 @@ static void device_handler_reinit_sources(struct device_handler *handler) handler->dry_run); } -static const char *fs_parameters(unsigned int rw_flags, const char *fstype) +static const char *fs_parameters(struct discover_device *dev, + unsigned int rw_flags) { + const char *fstype = discover_device_get_param(dev, "ID_FS_TYPE"); + + /* XFS journals are not cross-endian compatible; don't try recovery + * even if we have a snapshot */ + if (!strncmp(fstype, "xfs", strlen("xfs"))) + return "norecovery"; + + /* If we have a snapshot available allow touching the filesystem */ + if (dev->ramdisk) + return ""; + if ((rw_flags | MS_RDONLY) != MS_RDONLY) return ""; - /* Avoid writing back to the disk on journaled filesystems */ + /* Avoid writes due to journal replay if we don't have a snapshot */ if (!strncmp(fstype, "ext4", strlen("ext4"))) return "norecovery"; - if (!strncmp(fstype, "xfs", strlen("xfs"))) - return "norecovery"; return ""; } +static inline const char *get_device_path(struct discover_device *dev) +{ + return dev->ramdisk ? dev->ramdisk->snapshot : dev->device_path; +} + static bool check_existing_mount(struct discover_device *dev) { struct stat devstat, mntstat; + const char *device_path; struct mntent *mnt; FILE *fp; int rc; - rc = stat(dev->device_path, &devstat); + device_path = get_device_path(dev); + + rc = stat(device_path, &devstat); if (rc) { pb_debug("%s: stat failed: %s\n", __func__, strerror(errno)); return false; @@ -1294,7 +1314,7 @@ static bool check_existing_mount(struct discover_device *dev) static int mount_device(struct discover_device *dev) { - const char *fstype; + const char *fstype, *device_path; int rc; if (!dev->device_path) @@ -1326,11 +1346,13 @@ static int mount_device(struct discover_device *dev) goto err_free; } + device_path = get_device_path(dev); + pb_log("mounting device %s read-only\n", dev->device_path); errno = 0; - rc = mount(dev->device_path, dev->mount_path, fstype, + rc = mount(device_path, dev->mount_path, fstype, MS_RDONLY | MS_SILENT, - fs_parameters(MS_RDONLY, fstype)); + fs_parameters(dev, MS_RDONLY)); if (!rc) { dev->mounted = true; dev->mounted_rw = false; @@ -1339,7 +1361,10 @@ static int mount_device(struct discover_device *dev) } pb_log("couldn't mount device %s: mount failed: %s\n", - dev->device_path, strerror(errno)); + 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: @@ -1350,17 +1375,21 @@ err_free: static int umount_device(struct discover_device *dev) { + const char *device_path; int rc; if (!dev->mounted || !dev->unmount) return 0; - pb_log("unmounting device %s\n", dev->device_path); + device_path = get_device_path(dev); + + pb_log("unmounting device %s\n", device_path); rc = umount(dev->mount_path); if (rc) return -1; dev->mounted = false; + devmapper_destroy_snapshot(dev); pb_rmdir_recursive(mount_base(), dev->mount_path); @@ -1372,11 +1401,16 @@ static int umount_device(struct discover_device *dev) int device_request_write(struct discover_device *dev, bool *release) { - const char *fstype; + const char *fstype, *device_path; + const struct config *config; int rc; *release = false; + config = config_get(); + if (!config->allow_writes) + return -1; + if (!dev->mounted) return -1; @@ -1385,16 +1419,20 @@ int device_request_write(struct discover_device *dev, bool *release) fstype = discover_device_get_param(dev, "ID_FS_TYPE"); - pb_log("remounting device %s read-write\n", dev->device_path); + device_path = get_device_path(dev); + + pb_log("remounting device %s read-write\n", device_path); rc = umount(dev->mount_path); if (rc) { - pb_log("Failed to unmount %s\n", dev->mount_path); + pb_log("Failed to unmount %s: %s\n", + dev->mount_path, strerror(errno)); return -1; } - rc = mount(dev->device_path, dev->mount_path, fstype, + + rc = mount(device_path, dev->mount_path, fstype, MS_SILENT, - fs_parameters(MS_REMOUNT, fstype)); + fs_parameters(dev, MS_REMOUNT)); if (rc) goto mount_ro; @@ -1403,29 +1441,50 @@ int device_request_write(struct discover_device *dev, bool *release) return 0; mount_ro: - pb_log("Unable to remount device %s read-write\n", dev->device_path); - rc = mount(dev->device_path, dev->mount_path, fstype, + pb_log("Unable to remount device %s read-write: %s\n", + device_path, strerror(errno)); + if (mount(device_path, dev->mount_path, fstype, MS_RDONLY | MS_SILENT, - fs_parameters(MS_RDONLY, fstype)); - if (rc) - pb_log("Unable to recover mount for %s\n", dev->device_path); + fs_parameters(dev, MS_RDONLY))) + pb_log("Unable to recover mount for %s: %s\n", + device_path, strerror(errno)); return -1; } void device_release_write(struct discover_device *dev, bool release) { - const char *fstype; + const char *fstype, *device_path; + int rc = 0; if (!release) return; + device_path = get_device_path(dev); + fstype = discover_device_get_param(dev, "ID_FS_TYPE"); - pb_log("remounting device %s read-only\n", dev->device_path); - mount(dev->device_path, dev->mount_path, "", - MS_REMOUNT | MS_RDONLY | MS_SILENT, - fs_parameters(MS_RDONLY, fstype)); - dev->mounted_rw = false; + pb_log("remounting device %s read-only\n", device_path); + + if (umount(dev->mount_path)) { + pb_log("Failed to unmount %s\n", dev->mount_path); + return; + } + dev->mounted_rw = dev->mounted = false; + + if (dev->ramdisk) { + devmapper_merge_snapshot(dev); + /* device_path becomes stale after merge */ + device_path = get_device_path(dev); + } + + mount(device_path, dev->mount_path, fstype, + MS_RDONLY | MS_SILENT, + fs_parameters(dev, MS_RDONLY)); + if (rc) + pb_log("Failed to remount %s read-only: %s\n", + device_path, strerror(errno)); + else + dev->mounted = true; } #else