From 4769f18c72a50642b0ccffda943149f9599435c5 Mon Sep 17 00:00:00 2001 From: David Lehman Date: Fri, 6 Mar 2015 12:34:00 -0600 Subject: [PATCH 10/19] Cancel scheduled actions on related disks when an outside change occurs. --- blivet/discoverer.py | 12 +++++++++++- blivet/handler.py | 28 ++++++++++++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/blivet/discoverer.py b/blivet/discoverer.py index 3df9951..5df7fb4 100644 --- a/blivet/discoverer.py +++ b/blivet/discoverer.py @@ -713,6 +713,13 @@ class DeviceDiscoverer(object): device.format = None + if device is None: + disk_names = self.getUdevDeviceDisks(info) + disks = [d for d in + [self.devicetree.getDeviceByName(n) for n in disk_names] + if d is not None] + self.devicetree.cancelDiskActions(disks) + # # The first step is to either look up or create the device # @@ -893,7 +900,7 @@ class DeviceDiscoverer(object): for lv_device in vg_device.lvs[:]: if lv_device.name not in lv_info: log.info("lv %s seems to have been removed", lv_device.name) - self.devicetree.recursiveRemove(lv_device, actions=False) + self.devicetree.cancelDiskActions(vg_device.disks) if not vg_device.complete: log.warning("Skipping LVs for incomplete VG %s", vg_name) @@ -1037,6 +1044,7 @@ class DeviceDiscoverer(object): lv_dev = self.devicetree.getDeviceByUuid(lv_uuid) if lv_dev is None: + self.devicetree.cancelDiskActions(vg_device.disks) lv_device = lv_class(lv_name, parents=lv_parents, uuid=lv_uuid, size=lv_size,segType=lv_type, exists=True, **lv_kwargs) @@ -1332,6 +1340,8 @@ class DeviceDiscoverer(object): log.debug("no type or existing type for %s, bailing", name) return + self.devicetree.cancelDiskActions(device.disks) + # set up the common arguments for the format constructor format_designator = format_type kwargs = {"uuid": uuid, diff --git a/blivet/handler.py b/blivet/handler.py index e26f62d..97146aa 100644 --- a/blivet/handler.py +++ b/blivet/handler.py @@ -301,10 +301,12 @@ class EventHandler(object): return int(start) if start is not None else start # remove any partitions we have that are no longer on disk + remove = [] for old in self.devicetree.getChildren(device): if not old.exists: log.warning("non-existent partition %s on changed " "disklabel", old.name) + remove.append(old) continue if old.isLogical: @@ -329,11 +331,20 @@ class EventHandler(object): if new is None: log.info("partition %s was removed", old.name) - self.devicetree.recursiveRemove(old, actions=False, - modparent=False) + remove.append(old) else: udev_devices.remove(new) + if remove or udev_devices: + self.devicetree.cancelDiskActions([device]) + + for old in remove: + if old not in self.devicetree.devices: + # may have been removed by action cancelation + continue + + self.devicetree.recursiveRemove(old, actions=False, modparent=False) + # any partitions left in the list have been added for new in udev_devices: log.info("partition %s was added", @@ -378,11 +389,17 @@ class EventHandler(object): old_container_uuid = device.format.containerUUID container_changed = (old_container_uuid != container_uuid) + if container_changed: + self.devicetree.cancelDiskActions(device.disks) + try: container = self.devicetree.getChildren(device)[0] except IndexError: container = None + if container and not container.exists: + self.devicetree.cancelDiskActions(device.disks) + if container_changed: if container: if len(container.parents) == 1: @@ -409,9 +426,8 @@ class EventHandler(object): device.format.vgName = new_vg_name device.format.peStart = udev.device_get_pv_pe_start(pv_info) if container: - # vg rename container.name = new_vg_name - self.devicetree.updateLVs(container) + self.devicetree.discoverer.updateLVs(container) # MD TODO: raid level, spares # BTRFS TODO: check for changes to subvol list IFF the volume is mounted @@ -480,6 +496,8 @@ class EventHandler(object): # handler for pv(s)) current_size = device.readCurrentSize() if expected or device.currentSize != current_size: + if not expected: + self.devicetree.cancelDiskActions(device.disks) device.updateSize(newsize=current_size) # This is also happening in ContainerDevice._postCreate. @@ -539,6 +557,8 @@ class EventHandler(object): device.format.label = label elif reformatted and not expected: log.info("%s was reformatted from outside of blivet", device.name) + self.devicetree.cancelDiskActions(device.disks) + # eg: wipefs on lvm pv w/ configured vg and lvs for child in self.devicetree.getChildren(device): self.devicetree.recursiveRemove(child, actions=False) -- 1.9.3