mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-28 11:31:16 +00:00
qemu, lxc: move NodeDeviceGetPCIInfo() function to domain_driver.c
libxlNodeDeviceGetPCIInfo() and qemuNodeDeviceGetPCIInfo() are equal. Let's move the logic to a new virDomainDriverNodeDeviceGetPCIInfo() info to be used by libxl_driver.c and qemu_driver.c. Reviewed-by: Laine Stump <laine@redhat.com> Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
parent
03f9c17805
commit
28657b8001
@ -336,3 +336,35 @@ virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
unsigned *domain,
|
||||
unsigned *bus,
|
||||
unsigned *slot,
|
||||
unsigned *function)
|
||||
{
|
||||
virNodeDevCapsDefPtr cap;
|
||||
|
||||
cap = def->caps;
|
||||
while (cap) {
|
||||
if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
|
||||
*domain = cap->data.pci_dev.domain;
|
||||
*bus = cap->data.pci_dev.bus;
|
||||
*slot = cap->data.pci_dev.slot;
|
||||
*function = cap->data.pci_dev.function;
|
||||
break;
|
||||
}
|
||||
|
||||
cap = cap->next;
|
||||
}
|
||||
|
||||
if (!cap) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("device %s is not a PCI device"), def->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -21,6 +21,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "domain_conf.h"
|
||||
#include "node_device_conf.h"
|
||||
|
||||
char *
|
||||
virDomainDriverGenerateRootHash(const char *drivername,
|
||||
@ -45,3 +46,9 @@ int virDomainDriverParseBlkioDeviceStr(char *blkioDeviceStr, const char *type,
|
||||
int virDomainDriverSetupPersistentDefBlkioParams(virDomainDefPtr persistentDef,
|
||||
virTypedParameterPtr params,
|
||||
int nparams);
|
||||
|
||||
int virDomainDriverNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
unsigned *domain,
|
||||
unsigned *bus,
|
||||
unsigned *slot,
|
||||
unsigned *function);
|
||||
|
@ -1503,6 +1503,7 @@ virDomainCgroupSetupMemtune;
|
||||
virDomainDriverGenerateMachineName;
|
||||
virDomainDriverGenerateRootHash;
|
||||
virDomainDriverMergeBlkioDevice;
|
||||
virDomainDriverNodeDeviceGetPCIInfo;
|
||||
virDomainDriverParseBlkioDeviceStr;
|
||||
virDomainDriverSetupPersistentDefBlkioParams;
|
||||
|
||||
|
@ -56,6 +56,7 @@
|
||||
#include "cpu/cpu.h"
|
||||
#include "virutil.h"
|
||||
#include "domain_validate.h"
|
||||
#include "domain_driver.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_LIBXL
|
||||
|
||||
@ -5773,37 +5774,6 @@ libxlConnectSupportsFeature(virConnectPtr conn, int feature)
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
libxlNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
unsigned *domain,
|
||||
unsigned *bus,
|
||||
unsigned *slot,
|
||||
unsigned *function)
|
||||
{
|
||||
virNodeDevCapsDefPtr cap;
|
||||
|
||||
cap = def->caps;
|
||||
while (cap) {
|
||||
if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
|
||||
*domain = cap->data.pci_dev.domain;
|
||||
*bus = cap->data.pci_dev.bus;
|
||||
*slot = cap->data.pci_dev.slot;
|
||||
*function = cap->data.pci_dev.function;
|
||||
break;
|
||||
}
|
||||
|
||||
cap = cap->next;
|
||||
}
|
||||
|
||||
if (!cap) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("device %s is not a PCI device"), def->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
const char *driverName,
|
||||
@ -5845,7 +5815,7 @@ libxlNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
@ -5916,7 +5886,7 @@ libxlNodeDeviceReAttach(virNodeDevicePtr dev)
|
||||
if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
@ -5974,7 +5944,7 @@ libxlNodeDeviceReset(virNodeDevicePtr dev)
|
||||
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (libxlNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
|
@ -11964,37 +11964,6 @@ qemuDomainMigrateConfirm3Params(virDomainPtr domain,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuNodeDeviceGetPCIInfo(virNodeDeviceDefPtr def,
|
||||
unsigned *domain,
|
||||
unsigned *bus,
|
||||
unsigned *slot,
|
||||
unsigned *function)
|
||||
{
|
||||
virNodeDevCapsDefPtr cap;
|
||||
|
||||
cap = def->caps;
|
||||
while (cap) {
|
||||
if (cap->data.type == VIR_NODE_DEV_CAP_PCI_DEV) {
|
||||
*domain = cap->data.pci_dev.domain;
|
||||
*bus = cap->data.pci_dev.bus;
|
||||
*slot = cap->data.pci_dev.slot;
|
||||
*function = cap->data.pci_dev.function;
|
||||
break;
|
||||
}
|
||||
|
||||
cap = cap->next;
|
||||
}
|
||||
|
||||
if (!cap) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("device %s is not a PCI device"), def->name);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
const char *driverName,
|
||||
@ -12037,7 +12006,7 @@ qemuNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
if (virNodeDeviceDetachFlagsEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
@ -12118,7 +12087,7 @@ qemuNodeDeviceReAttach(virNodeDevicePtr dev)
|
||||
if (virNodeDeviceReAttachEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
@ -12172,7 +12141,7 @@ qemuNodeDeviceReset(virNodeDevicePtr dev)
|
||||
if (virNodeDeviceResetEnsureACL(dev->conn, def) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (qemuNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
if (virDomainDriverNodeDeviceGetPCIInfo(def, &domain, &bus, &slot, &function) < 0)
|
||||
goto cleanup;
|
||||
|
||||
pci = virPCIDeviceNew(domain, bus, slot, function);
|
||||
|
Loading…
Reference in New Issue
Block a user