mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-12 07:42:56 +00:00
domain_driver.c: Introduce and use virDomainDriverAddIOThreadCheck()
The test driver can share the same code with qemu driver when implement testDomainAddIOThreadCheck and testDomainDelIOThreadCheck, so extract them for test driver to use. Signed-off-by: Luke Yue <lukedyue@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
c4f3c955d5
commit
cb3033776f
src
@ -512,3 +512,67 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
|
||||
return virHostdevPCINodeDeviceDetach(hostdevMgr, pci);
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainDriverAddIOThreadCheck:
|
||||
* @def: domain definition
|
||||
* @iothread_id: iothread id
|
||||
*
|
||||
* Returns -1 if an IOThread is already using the given iothread id
|
||||
*/
|
||||
int
|
||||
virDomainDriverAddIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id)
|
||||
{
|
||||
if (virDomainIOThreadIDFind(def, iothread_id)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("an IOThread is already using iothread_id '%u'"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainDriverDelIOThreadCheck:
|
||||
* @def: domain definition
|
||||
* @iothread_id: iothread id
|
||||
*
|
||||
* Returns -1 if there is no IOThread using the given iothread id
|
||||
*/
|
||||
int
|
||||
virDomainDriverDelIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!virDomainIOThreadIDFind(def, iothread_id)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot find IOThread '%u' in iothreadids list"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (def->disks[i]->iothread == iothread_id) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot remove IOThread %u since it "
|
||||
"is being used by disk '%s'"),
|
||||
iothread_id, def->disks[i]->dst);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < def->ncontrollers; i++) {
|
||||
if (def->controllers[i]->iothread == iothread_id) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot remove IOThread '%u' since it "
|
||||
"is being used by controller"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -60,3 +60,9 @@ int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev,
|
||||
int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
|
||||
virHostdevManager *hostdevMgr,
|
||||
const char *driverName);
|
||||
|
||||
int virDomainDriverAddIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id);
|
||||
|
||||
int virDomainDriverDelIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id);
|
||||
|
@ -1537,6 +1537,8 @@ virDomainCgroupSetupMemtune;
|
||||
|
||||
|
||||
# hypervisor/domain_driver.h
|
||||
virDomainDriverAddIOThreadCheck;
|
||||
virDomainDriverDelIOThreadCheck;
|
||||
virDomainDriverGenerateMachineName;
|
||||
virDomainDriverGenerateRootHash;
|
||||
virDomainDriverMergeBlkioDevice;
|
||||
|
@ -5438,58 +5438,6 @@ qemuDomainHotplugDelIOThread(virQEMUDriver *driver,
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainAddIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id)
|
||||
{
|
||||
if (virDomainIOThreadIDFind(def, iothread_id)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("an IOThread is already using iothread_id '%u'"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
qemuDomainDelIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
if (!virDomainIOThreadIDFind(def, iothread_id)) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot find IOThread '%u' in iothreadids list"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < def->ndisks; i++) {
|
||||
if (def->disks[i]->iothread == iothread_id) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot remove IOThread %u since it "
|
||||
"is being used by disk '%s'"),
|
||||
iothread_id, def->disks[i]->dst);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < def->ncontrollers; i++) {
|
||||
if (def->controllers[i]->iothread == iothread_id) {
|
||||
virReportError(VIR_ERR_INVALID_ARG,
|
||||
_("cannot remove IOThread '%u' since it "
|
||||
"is being used by controller"),
|
||||
iothread_id);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @params: Pointer to params list
|
||||
* @nparams: Number of params to be parsed
|
||||
@ -5623,7 +5571,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
|
||||
|
||||
switch (action) {
|
||||
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
|
||||
if (qemuDomainAddIOThreadCheck(def, iothread.iothread_id) < 0)
|
||||
if (virDomainDriverAddIOThreadCheck(def, iothread.iothread_id) < 0)
|
||||
goto endjob;
|
||||
|
||||
if (qemuDomainHotplugAddIOThread(driver, vm, iothread.iothread_id) < 0)
|
||||
@ -5632,7 +5580,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
|
||||
if (qemuDomainDelIOThreadCheck(def, iothread.iothread_id) < 0)
|
||||
if (virDomainDriverDelIOThreadCheck(def, iothread.iothread_id) < 0)
|
||||
goto endjob;
|
||||
|
||||
if (qemuDomainHotplugDelIOThread(driver, vm, iothread.iothread_id) < 0)
|
||||
@ -5661,7 +5609,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
|
||||
if (persistentDef) {
|
||||
switch (action) {
|
||||
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
|
||||
if (qemuDomainAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
|
||||
if (virDomainDriverAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
|
||||
goto endjob;
|
||||
|
||||
if (!virDomainIOThreadIDAdd(persistentDef, iothread.iothread_id))
|
||||
@ -5670,7 +5618,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
|
||||
break;
|
||||
|
||||
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
|
||||
if (qemuDomainDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
|
||||
if (virDomainDriverDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
|
||||
goto endjob;
|
||||
|
||||
virDomainIOThreadIDDel(persistentDef, iothread.iothread_id);
|
||||
|
Loading…
x
Reference in New Issue
Block a user