Change in vdsm[master]: hostdev: fix creation and deletion of multiple udev rules

mpolednik at redhat.com mpolednik at redhat.com
Thu Feb 26 14:46:45 UTC 2015


Martin Polednik has uploaded a new change for review.

Change subject: hostdev: fix creation and deletion of multiple udev rules
......................................................................

hostdev: fix creation and deletion of multiple udev rules

When attaching multiple devices from the same group, each of the
devices needs to be detached and then later reattached to the host. To
this routine is hooked udev rule creation to give qemu access to
/dev/vfio endpoint. This patch corrects behaviour of udev if the file
already exists or does not exist due to creation or deletion of VM.

Change-Id: I83fffb2f6e42cc1746f30ca2b63c5d594de014e5
Signed-off-by: Martin Polednik <mpolednik at redhat.com>
---
M vdsm/supervdsmServer
1 file changed, 15 insertions(+), 4 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/08/38208/1

diff --git a/vdsm/supervdsmServer b/vdsm/supervdsmServer
index 59b29a9..92d2aa6 100755
--- a/vdsm/supervdsmServer
+++ b/vdsm/supervdsmServer
@@ -313,9 +313,14 @@
                 '/dev/vfio/{}"').format(iommu_group, EXT_CHOWN,
                                         QEMU_PROCESS_USER, QEMU_PROCESS_GROUP,
                                         iommu_group)
-        with open(ruleFile, "w") as rf:
-            self.log.debug("Creating rule %s: %r", ruleFile, rule)
-            rf.write(rule)
+
+        if not os.path.isfile(ruleFile):
+            # If the file exists, different device from the same group has
+            # already been detached and we therefore can skip overwriting the
+            # file.
+            with open(ruleFile, "w") as rf:
+                self.log.debug("Creating rule %s: %r", ruleFile, rule)
+                rf.write(rule)
 
     @logDecorator
     def rmAppropriateIommuGroup(self, iommu_group):
@@ -326,7 +331,13 @@
         rule = os.path.join(_UDEV_RULE_FILE_DIR, _UDEV_RULE_FILE_PREFIX +
                             "iommu_group_" + iommu_group + _UDEV_RULE_FILE_EXT)
         self.log.debug("Removing rule %s", rule)
-        os.remove(rule)
+        try:
+            os.remove(rule)
+        except OSError:
+            # OSError here means that the rule file does not exist - this is
+            # expected when multiple devices in one iommu group were passed
+            # through.
+            pass
 
     @logDecorator
     def ksmTune(self, tuningParams):


-- 
To view, visit https://gerrit.ovirt.org/38208
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I83fffb2f6e42cc1746f30ca2b63c5d594de014e5
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Martin Polednik <mpolednik at redhat.com>


More information about the vdsm-patches mailing list