Martin Polednik has uploaded a new change for review. Change subject: supervdsm: generalize udevTrigger method ......................................................................
supervdsm: generalize udevTrigger method udevTrigger in it's current state is tied to storage code as it does property match against DM_NAME. USB devices require attribute match for devnum and busnum, and we should be somewhat able to do both these matches in a more generic function. This patch refactors udevTrigger to include attr_matches and property_matches. When dict is supplied to these, they're expanded to the command. Change-Id: I761305a54c14e8ac8ef9f4204ee5cc5d55cb31b7 Signed-off-by: Martin Polednik <[email protected]> --- M vdsm/storage/hsm.py M vdsm/supervdsmServer 2 files changed, 20 insertions(+), 21 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/67/44767/1 diff --git a/vdsm/storage/hsm.py b/vdsm/storage/hsm.py index 10409dd..db3b875 100644 --- a/vdsm/storage/hsm.py +++ b/vdsm/storage/hsm.py @@ -3151,7 +3151,8 @@ Warning: Internal use only. """ supervdsm.getProxy().appropriateDevice(guid, thiefId) - supervdsm.getProxy().udevTrigger(guid) + supervdsm.getProxy().udevTrigger(guid, + property_matches={'DM_NAME': guid}) devPath = os.path.join(devicemapper.DMPATH_PREFIX, guid) utils.retry(partial(fileUtils.validateQemuReadable, devPath), expectedException=OSError, diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer index 39e5f80..299e536 100755 --- a/vdsm/supervdsmServer +++ b/vdsm/supervdsmServer @@ -287,27 +287,25 @@ return setSafeNetworkConfig() @logDecorator - def udevTrigger(self, guid): - self.__udevReloadRules(guid) - cmd = [EXT_UDEVADM, 'trigger', '--verbose', '--action', 'change', - '--property-match=DM_NAME=%s' % guid] + def udevTrigger(self, device_name, property_matches=None, + attr_matches=None): + self.__udevReloadRules(device_name) + cmd = [EXT_UDEVADM, 'trigger', '--verbose', '--action', 'change'] + + if property_matches: + for property_name, property_value in property_matches.items(): + cmd.append('--property-match={}={}'.format(property_name, + property_value)) + + if attr_matches: + for attr_name, attr_value in attr_matches.items(): + cmd.append('--attr-match={}={}'.format(attr_name, attr_value)) + + self.log.debug("Calling trigger: %s", ' '.join(cmd)) rc, out, err = utils.execCmd(cmd) if rc: raise OSError(errno.EINVAL, "Could not trigger change for device \ - %s, out %s\nerr %s" % (guid, out, err)) - - @logDecorator - def udevTriggerUSB(self, bus, device): - self.__udevReloadRules('usb_' + '_'.join((bus, device))) - cmd = [EXT_UDEVADM, 'trigger', '--verbose', '--action', 'change', - '--attr-match=busnum={}'.format(bus), - '--attr-match=devnum={}'.format(device)] - rc, out, err = utils.execCmd(cmd) - if rc: - raise OSError(errno.EINVAL, - 'Could not trigger change for usb ' - 'device bus: %s, device: %s, out %s\nerr %s' % - (bus, device, out, err)) + %s, out %s\nerr %s" % (device_name, out, err)) @logDecorator def appropriateDevice(self, guid, thiefId): @@ -403,7 +401,7 @@ self.log.debug("Creating rule %s: %r", rule_file, rule) rf.write(rule) - self.udevTriggerUSB(bus, device) + self.udevTrigger('usb_' + '_'.join((bus, device))) @logDecorator def releaseAppropriateUSBDevice(self, bus, device): @@ -418,7 +416,7 @@ self.log.debug("Creating rule %s: %r", rule_file, rule) rf.write(rule) - self.udevTriggerUSB(bus, device) + self.udevTrigger('usb_' + '_'.join((bus, device))) @logDecorator def rmAppropriateUSBDevice(self, bus, device): -- To view, visit https://gerrit.ovirt.org/44767 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I761305a54c14e8ac8ef9f4204ee5cc5d55cb31b7 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Martin Polednik <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
