]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
hostdev: Create virHostdevIsPCINetDevice
authorHuanle Han <hanxueluo@gmail.com>
Wed, 22 Apr 2015 11:33:09 +0000 (07:33 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 24 Apr 2015 16:28:59 +0000 (12:28 -0400)
Refactor some code to create a static function virHostdevIsPCINetDevice
which will detect whether the hostdev is a pci net device or not.

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
src/util/virhostdev.c

index f583e545c04c4c54b5b9559fa4e89c1ae70cc75b..e1a5f0880fd6a9d77d47ce194822277132778a62 100644 (file)
@@ -351,6 +351,16 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev,
 }
 
 
+static int
+virHostdevIsPCINetDevice(virDomainHostdevDefPtr hostdev)
+{
+    return hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+        hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
+        hostdev->parent.type == VIR_DOMAIN_DEVICE_NET &&
+        hostdev->parent.data.net;
+}
+
+
 static int
 virHostdevNetConfigVirtPortProfile(const char *linkdev, int vf,
                                    virNetDevVPortProfilePtr virtPort,
@@ -481,10 +491,7 @@ virHostdevNetConfigRestore(virDomainHostdevDefPtr hostdev,
     /* This is only needed for PCI devices that have been defined
      * using <interface type='hostdev'>. For all others, it is a NOP.
      */
-    if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||
-        hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||
-        hostdev->parent.type != VIR_DOMAIN_DEVICE_NET ||
-        !hostdev->parent.data.net)
+    if (!virHostdevIsPCINetDevice(hostdev))
        return 0;
 
     isvf = virHostdevIsVirtualFunction(hostdev);
@@ -604,16 +611,11 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr hostdev_mgr,
      * the network device, set the netdev config */
     for (i = 0; i < nhostdevs; i++) {
          virDomainHostdevDefPtr hostdev = hostdevs[i];
-         if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
-             continue;
-         if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
+         if (!virHostdevIsPCINetDevice(hostdev))
              continue;
-         if (hostdev->parent.type == VIR_DOMAIN_DEVICE_NET &&
-             hostdev->parent.data.net) {
-             if (virHostdevNetConfigReplace(hostdev, uuid,
-                                            hostdev_mgr->stateDir) < 0) {
-                 goto resetvfnetconfig;
-             }
+         if (virHostdevNetConfigReplace(hostdev, uuid,
+                                        hostdev_mgr->stateDir) < 0) {
+             goto resetvfnetconfig;
          }
          last_processed_hostdev_vf = i;
     }