mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
domain_driver.c: use g_auto* in virDomainDriverNodeDeviceDetachFlags()
Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
887dd0d331
commit
22a026fbcd
@ -465,57 +465,50 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
|||||||
virHostdevManagerPtr hostdevMgr,
|
virHostdevManagerPtr hostdevMgr,
|
||||||
const char *driverName)
|
const char *driverName)
|
||||||
{
|
{
|
||||||
virPCIDevicePtr pci = NULL;
|
g_autoptr(virPCIDevice) pci = NULL;
|
||||||
virPCIDeviceAddress devAddr;
|
virPCIDeviceAddress devAddr;
|
||||||
int ret = -1;
|
g_autoptr(virNodeDeviceDef) def = NULL;
|
||||||
virNodeDeviceDefPtr def = NULL;
|
|
||||||
g_autofree char *xml = NULL;
|
g_autofree char *xml = NULL;
|
||||||
virConnectPtr nodeconn = NULL;
|
g_autoptr(virConnect) nodeconn = NULL;
|
||||||
virNodeDevicePtr nodedev = NULL;
|
g_autoptr(virNodeDevice) nodedev = NULL;
|
||||||
|
|
||||||
if (!driverName)
|
if (!driverName)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(nodeconn = virGetConnectNodeDev()))
|
if (!(nodeconn = virGetConnectNodeDev()))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* 'dev' is associated with virConnectPtr, so for split
|
/* 'dev' is associated with virConnectPtr, so for split
|
||||||
* daemons, we need to get a copy that is associated with
|
* daemons, we need to get a copy that is associated with
|
||||||
* the virnodedevd daemon. */
|
* the virnodedevd daemon. */
|
||||||
if (!(nodedev = virNodeDeviceLookupByName(nodeconn,
|
if (!(nodedev = virNodeDeviceLookupByName(nodeconn,
|
||||||
virNodeDeviceGetName(dev))))
|
virNodeDeviceGetName(dev))))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
|
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
|
||||||
if (!xml)
|
if (!xml)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
|
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
|
||||||
if (!def)
|
if (!def)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
/* ACL check must happen against original 'dev',
|
/* ACL check must happen against original 'dev',
|
||||||
* not the new 'nodedev' we acquired */
|
* not the new 'nodedev' we acquired */
|
||||||
if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
|
if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
|
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
pci = virPCIDeviceNew(&devAddr);
|
pci = virPCIDeviceNew(&devAddr);
|
||||||
if (!pci)
|
if (!pci)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (STREQ(driverName, "vfio"))
|
if (STREQ(driverName, "vfio"))
|
||||||
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
|
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_VFIO);
|
||||||
else if (STREQ(driverName, "xen"))
|
else if (STREQ(driverName, "xen"))
|
||||||
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN);
|
virPCIDeviceSetStubDriver(pci, VIR_PCI_STUB_DRIVER_XEN);
|
||||||
|
|
||||||
ret = virHostdevPCINodeDeviceDetach(hostdevMgr, pci);
|
return virHostdevPCINodeDeviceDetach(hostdevMgr, pci);
|
||||||
cleanup:
|
|
||||||
virPCIDeviceFree(pci);
|
|
||||||
virNodeDeviceDefFree(def);
|
|
||||||
virObjectUnref(nodedev);
|
|
||||||
virObjectUnref(nodeconn);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user