Skip to content

Commit

Permalink
Handle formatting after adding devices from format handlers.
Browse files Browse the repository at this point in the history
If we don't do it right away the device could be looked up successfully
and cause confusion due to inaccurate(missing) format data.

This is only needed in the places where we add a new device from a
format handler. The device additions from add*Device are not vulnerable
to this issue.

Related: rhbz#1192004
Related: rhbz#1197582
  • Loading branch information
dwlehman committed Jun 17, 2015
1 parent 6ca39b9 commit 1d3fc68
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions blivet/populator.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,16 @@ def addUdevLoopDevice(self, info):
self.devicetree._addDevice(device)
return device

def addUdevDevice(self, info):
def addUdevDevice(self, info, updateOrigFmt=False):
"""
:param :class:`pyudev.Device` info: udev info for the device
:keyword bool updateOrigFmt: update original format unconditionally
If a device is added to the tree based on info its original format
will be saved after the format has been detected. If the device
that corresponds to info is already in the tree, its original format
will not be updated unless updateOrigFmt is True.
"""
name = udev.device_get_name(info)
log_method_call(self, name=name, info=pprint.pformat(dict(info)))
uuid = udev.device_get_uuid(info)
Expand Down Expand Up @@ -744,7 +753,7 @@ def addUdevDevice(self, info):

# now handle the device's formatting
self.handleUdevDeviceFormat(info, device)
if device_added:
if device_added or updateOrigFmt:
device.originalFormat = copy.copy(device.format)
device.deviceLinks = udev.device_get_symlinks(info)

Expand Down Expand Up @@ -843,6 +852,12 @@ def handleUdevLUKSFormat(self, info, device):
else:
luks_device.updateSysfsPath()
self.devicetree._addDevice(luks_device)
luks_info = udev.get_device(luks_device.sysfsPath)
if not luks_info:
log.error("failed to get udev data for %s", luks_device.name)
return

self.addUdevDevice(luks_info, updateOrigFmt=True)
else:
log.warning("luks device %s already in the tree",
device.format.mapName)
Expand Down Expand Up @@ -1003,7 +1018,7 @@ def addLV(lv):
return

# do format handling now
self.addUdevDevice(lv_info)
self.addUdevDevice(lv_info, updateOrigFmt=True)

raid_items = dict((n.replace("[", "").replace("]", ""),
{"copies": 0, "log": Size(0), "meta": Size(0)})
Expand Down Expand Up @@ -1145,6 +1160,13 @@ def handleUdevMDMemberFormat(self, info, device):
md_array.updateSysfsPath()
md_array.parents.append(device)
self.devicetree._addDevice(md_array)
if md_array.status:
array_info = udev.get_device(md_array.sysfsPath)
if not array_info:
log.error("failed to get udev data for %s", md_array.name)
return

self.addUdevDevice(array_info, updateOrigFmt=True)

def handleUdevDMRaidMemberFormat(self, info, device):
# if dmraid usage is disabled skip any dmraid set activation
Expand Down Expand Up @@ -1451,7 +1473,7 @@ def setupDiskImages(self):
self.devicetree._addDevice(loopdev)
self.devicetree._addDevice(dmdev)
info = udev.get_device(dmdev.sysfsPath)
self.addUdevDevice(info)
self.addUdevDevice(info, updateOrigFmt=True)

def teardownDiskImages(self):
""" Tear down any disk image stacks. """
Expand Down

0 comments on commit 1d3fc68

Please sign in to comment.