qemu: Alter qemuDomainChgIOThread to take enum instead of bool

We're about to add a new state "modify" and thus the function
goes from just Add/Del. Use an enum to manage.

Extracted from code originally posted by Pavel Hrdina
<phrdina@redhat.com>, but placed into a separate patch.

Signed-off-by: John Ferlan <jferlan@redhat.com>
ACKed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
John Ferlan 2018-10-03 18:46:05 -04:00
parent 3083bf18da
commit 315e1105b6
1 changed files with 25 additions and 7 deletions

View File

@ -6016,11 +6016,16 @@ qemuDomainDelIOThreadCheck(virDomainDefPtr def,
return 0;
}
typedef enum {
VIR_DOMAIN_IOTHREAD_ACTION_ADD,
VIR_DOMAIN_IOTHREAD_ACTION_DEL,
} virDomainIOThreadAction;
static int
qemuDomainChgIOThread(virQEMUDriverPtr driver,
virDomainObjPtr vm,
unsigned int iothread_id,
bool add,
virDomainIOThreadAction action,
unsigned int flags)
{
virQEMUDriverConfigPtr cfg = NULL;
@ -6046,18 +6051,24 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
goto endjob;
}
if (add) {
switch (action) {
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
if (qemuDomainAddIOThreadCheck(def, iothread_id) < 0)
goto endjob;
if (qemuDomainHotplugAddIOThread(driver, vm, iothread_id) < 0)
goto endjob;
} else {
break;
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
if (qemuDomainDelIOThreadCheck(def, iothread_id) < 0)
goto endjob;
if (qemuDomainHotplugDelIOThread(driver, vm, iothread_id) < 0)
goto endjob;
break;
}
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
@ -6065,18 +6076,23 @@ qemuDomainChgIOThread(virQEMUDriverPtr driver,
}
if (persistentDef) {
if (add) {
switch (action) {
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
if (qemuDomainAddIOThreadCheck(persistentDef, iothread_id) < 0)
goto endjob;
if (!virDomainIOThreadIDAdd(persistentDef, iothread_id))
goto endjob;
} else {
break;
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
if (qemuDomainDelIOThreadCheck(persistentDef, iothread_id) < 0)
goto endjob;
virDomainIOThreadIDDel(persistentDef, iothread_id);
break;
}
if (virDomainSaveConfig(cfg->configDir, driver->caps,
@ -6118,7 +6134,8 @@ qemuDomainAddIOThread(virDomainPtr dom,
if (virDomainAddIOThreadEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
ret = qemuDomainChgIOThread(driver, vm, iothread_id, true, flags);
ret = qemuDomainChgIOThread(driver, vm, iothread_id,
VIR_DOMAIN_IOTHREAD_ACTION_ADD, flags);
cleanup:
virDomainObjEndAPI(&vm);
@ -6150,7 +6167,8 @@ qemuDomainDelIOThread(virDomainPtr dom,
if (virDomainDelIOThreadEnsureACL(dom->conn, vm->def, flags) < 0)
goto cleanup;
ret = qemuDomainChgIOThread(driver, vm, iothread_id, false, flags);
ret = qemuDomainChgIOThread(driver, vm, iothread_id,
VIR_DOMAIN_IOTHREAD_ACTION_DEL, flags);
cleanup:
virDomainObjEndAPI(&vm);