hostdev: Create virHostdevIsPCINetDevice

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>
This commit is contained in:
Huanle Han 2015-04-22 07:33:09 -04:00 committed by John Ferlan
parent 19425d110b
commit 7ec3f8051f

View 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)
if (!virHostdevIsPCINetDevice(hostdev))
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
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;
}