mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
qemu, libxl, hypervisor: use virDomainDriverNodeDeviceReset() helper
libxlNodeDeviceReset() and qemuNodeDeviceReset() are mostly equal, differing only how the virHostdevManager pointer is retrieved. Put the common code into virDomainDriverNodeDeviceReset() to reduce code duplication. Reviewed-by: Ján Tomko <jtomko@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
613e994af0
commit
42923b1356
@ -25,6 +25,10 @@
|
||||
#include "virstring.h"
|
||||
#include "vircrypto.h"
|
||||
#include "virutil.h"
|
||||
#include "virhostdev.h"
|
||||
#include "viraccessapicheck.h"
|
||||
#include "datatypes.h"
|
||||
#include "driver.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_DOMAIN
|
||||
|
||||
@ -365,3 +369,57 @@ virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
|
||||
virHostdevManagerPtr hostdevMgr)
|
||||
{
|
||||
virPCIDevicePtr pci;
|
||||
virPCIDeviceAddress devAddr;
|
||||
virNodeDeviceDefPtr def = NULL;
|
||||
g_autofree char *xml = NULL;
|
||||
virConnectPtr nodeconn = NULL;
|
||||
virNodeDevicePtr nodedev = NULL;
|
||||
int ret = -1;
|
||||
|
||||
if (!(nodeconn = virGetConnectNodeDev()))
|
||||
goto cleanup;
|
||||
|
||||
/* 'dev' is associated with virConnectPtr, so for split
|
||||
* daemons, we need to get a copy that is associated with
|
||||
* the virnodedevd daemon. */
|
||||
if (!(nodedev = virNodeDeviceLookupByName(
|
||||
nodeconn, virNodeDeviceGetName(dev))))
|
||||
goto cleanup;
|
||||
|
||||
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
|
||||
if (!xml)
|
||||
goto cleanup;
|
||||
|
||||
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
|
||||
if (!def)
|
||||
goto cleanup;
|
||||
|
||||
/* ACL check must happen against original 'dev',
|
||||
* not the new 'nodedev' we acquired */
|
||||
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(&devAddr);
|
||||
if (!pci)
|
||||
goto cleanup;
|
||||
|
||||
ret = virHostdevPCINodeDeviceReset(hostdevMgr, pci);
|
||||
|
||||
virPCIDeviceFree(pci);
|
||||
cleanup:
|
||||
virNodeDeviceDefFree(def);
|
||||
virObjectUnref(nodedev);
|
||||
virObjectUnref(nodeconn);
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include "domain_conf.h"
|
||||
#include "node_device_conf.h"
|
||||
#include "virhostdev.h"
|
||||
|
||||
char *
|
||||
virDomainDriverGenerateRootHash(const char *drivername,
|
||||
@ -49,3 +50,6 @@ int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
|
||||
|
||||
int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
virPCIDeviceAddressPtr devAddr);
|
||||
|
||||
int virDomainDriverNodeDeviceReset(virNodeDevicePtr dev,
|
||||
virHostdevManagerPtr hostdevMgr);
|
||||
|
@ -11,6 +11,7 @@ hypervisor_lib = static_library(
|
||||
hypervisor_sources,
|
||||
],
|
||||
dependencies: [
|
||||
access_dep,
|
||||
src_dep,
|
||||
],
|
||||
include_directories: [
|
||||
|
@ -1508,6 +1508,7 @@ virDomainDriverGenerateMachineName;
|
||||
virDomainDriverGenerateRootHash;
|
||||
virDomainDriverMergeBlkioDevice;
|
||||
virDomainDriverNodeDeviceGetPCIInfo;
|
||||
virDomainDriverNodeDeviceReset;
|
||||
virDomainDriverParseBlkioDeviceStr;
|
||||
virDomainDriverSetupPersistentDefBlkioParams;
|
||||
|
||||
|
@ -5901,58 +5901,12 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
|
||||
static int
|
||||
libxlNodeDeviceReset(virNodeDevicePtr dev)
|
||||
{
|
||||
virPCIDevicePtr pci = NULL;
|
||||
virPCIDeviceAddress devAddr;
|
||||
int ret = -1;
|
||||
virNodeDeviceDefPtr def = NULL;
|
||||
g_autofree char *xml = NULL;
|
||||
libxlDriverPrivatePtr driver = dev->conn->privateData;
|
||||
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||
virConnectPtr nodeconn = NULL;
|
||||
virNodeDevicePtr nodedev = NULL;
|
||||
|
||||
if (!(nodeconn = virGetConnectNodeDev()))
|
||||
goto cleanup;
|
||||
|
||||
/* 'dev' is associated with the QEMU virConnectPtr,
|
||||
* so for split daemons, we need to get a copy that
|
||||
* is associated with the virnodedevd daemon.
|
||||
*/
|
||||
if (!(nodedev = virNodeDeviceLookupByName(
|
||||
nodeconn, virNodeDeviceGetName(dev))))
|
||||
goto cleanup;
|
||||
|
||||
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
|
||||
if (!xml)
|
||||
goto cleanup;
|
||||
|
||||
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
|
||||
if (!def)
|
||||
goto cleanup;
|
||||
|
||||
/* ACL check must happen against original 'dev',
|
||||
* not the new 'nodedev' we acquired */
|
||||
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(&devAddr);
|
||||
if (!pci)
|
||||
goto cleanup;
|
||||
|
||||
if (virHostdevPCINodeDeviceReset(hostdev_mgr, pci) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
virPCIDeviceFree(pci);
|
||||
virNodeDeviceDefFree(def);
|
||||
virObjectUnref(nodedev);
|
||||
virObjectUnref(nodeconn);
|
||||
return ret;
|
||||
/* virNodeDeviceResetEnsureACL() is being called by
|
||||
* virDomainDriverNodeDeviceReset() */
|
||||
return virDomainDriverNodeDeviceReset(dev, hostdev_mgr);
|
||||
}
|
||||
|
||||
static char *
|
||||
|
@ -12136,54 +12136,11 @@ static int
|
||||
qemuNodeDeviceReset(virNodeDevicePtr dev)
|
||||
{
|
||||
virQEMUDriverPtr driver = dev->conn->privateData;
|
||||
virPCIDevicePtr pci;
|
||||
virPCIDeviceAddress devAddr;
|
||||
int ret = -1;
|
||||
virNodeDeviceDefPtr def = NULL;
|
||||
g_autofree char *xml = NULL;
|
||||
virHostdevManagerPtr hostdev_mgr = driver->hostdevMgr;
|
||||
virConnectPtr nodeconn = NULL;
|
||||
virNodeDevicePtr nodedev = NULL;
|
||||
|
||||
if (!(nodeconn = virGetConnectNodeDev()))
|
||||
goto cleanup;
|
||||
|
||||
/* 'dev' is associated with the QEMU virConnectPtr,
|
||||
* so for split daemons, we need to get a copy that
|
||||
* is associated with the virnodedevd daemon.
|
||||
*/
|
||||
if (!(nodedev = virNodeDeviceLookupByName(
|
||||
nodeconn, virNodeDeviceGetName(dev))))
|
||||
goto cleanup;
|
||||
|
||||
xml = virNodeDeviceGetXMLDesc(nodedev, 0);
|
||||
if (!xml)
|
||||
goto cleanup;
|
||||
|
||||
def = virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL);
|
||||
if (!def)
|
||||
goto cleanup;
|
||||
|
||||
/* ACL check must happen against original 'dev',
|
||||
* not the new 'nodedev' we acquired */
|
||||
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &devAddr) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(&devAddr);
|
||||
if (!pci)
|
||||
goto cleanup;
|
||||
|
||||
ret = virHostdevPCINodeDeviceReset(hostdev_mgr, pci);
|
||||
|
||||
virPCIDeviceFree(pci);
|
||||
cleanup:
|
||||
virNodeDeviceDefFree(def);
|
||||
virObjectUnref(nodedev);
|
||||
virObjectUnref(nodeconn);
|
||||
return ret;
|
||||
/* virNodeDeviceResetEnsureACL() is being called by
|
||||
* virDomainDriverNodeDeviceReset() */
|
||||
return virDomainDriverNodeDeviceReset(dev, hostdev_mgr);
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
x
Reference in New Issue
Block a user