Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx> --- src/test/test_driver.c | 160 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ef0ddab54d..6573ee3d61 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -182,6 +182,19 @@ struct _testDomainNamespaceDef { xmlNodePtr *snap_nodes; }; +typedef struct _testMonitorIOThreadInfo testMonitorIOThreadInfo; +struct _testMonitorIOThreadInfo { + unsigned int iothread_id; + int thread_id; + bool poll_valid; + unsigned long long poll_max_ns; + unsigned int poll_grow; + unsigned int poll_shrink; + bool set_poll_max_ns; + bool set_poll_grow; + bool set_poll_shrink; +}; + static void testDomainDefNamespaceFree(void *data) { @@ -9291,6 +9304,151 @@ testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, return ret; } +typedef enum { + VIR_DOMAIN_IOTHREAD_ACTION_ADD, + VIR_DOMAIN_IOTHREAD_ACTION_DEL, + VIR_DOMAIN_IOTHREAD_ACTION_MOD, +} virDomainIOThreadAction; + +static int +testDomainChgIOThread(virDomainObj *vm, + testMonitorIOThreadInfo iothread, + virDomainIOThreadAction action, + unsigned int flags) +{ + virDomainDef *def; + virDomainDef *persistentDef; + int ret = -1; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + return ret; + + if (def) { + switch (action) { + case VIR_DOMAIN_IOTHREAD_ACTION_ADD: + if (virDomainAddIOThreadCheck(def, iothread.iothread_id) < 0) + return ret; + + if (!virDomainIOThreadIDAdd(def, iothread.iothread_id)) + return ret; + + break; + + case VIR_DOMAIN_IOTHREAD_ACTION_DEL: + if (virDomainDelIOThreadCheck(def, iothread.iothread_id) < 0) + return ret; + + virDomainIOThreadIDDel(def, iothread.iothread_id); + + break; + + case VIR_DOMAIN_IOTHREAD_ACTION_MOD: + if (!(virDomainIOThreadIDFind(def, iothread.iothread_id))) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot find IOThread '%u' in iothreadids"), + iothread.iothread_id); + return ret; + } + + break; + } + } + + if (persistentDef) { + switch (action) { + case VIR_DOMAIN_IOTHREAD_ACTION_ADD: + if (virDomainAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0) + return ret; + + if (!virDomainIOThreadIDAdd(persistentDef, iothread.iothread_id)) + return ret; + + break; + + case VIR_DOMAIN_IOTHREAD_ACTION_DEL: + if (virDomainDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0) + return ret; + + virDomainIOThreadIDDel(persistentDef, iothread.iothread_id); + + break; + + case VIR_DOMAIN_IOTHREAD_ACTION_MOD: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("configuring persistent polling values is " + "not supported")); + return ret; + + break; + } + } + + ret = 0; + + return ret; +} + +static int +testDomainAddIOThread(virDomainPtr dom, + unsigned int iothread_id, + unsigned int flags) +{ + virDomainObj *vm = NULL; + testMonitorIOThreadInfo iothread = {0}; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (iothread_id == 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid value of 0 for iothread_id")); + return -1; + } + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + iothread.iothread_id = iothread_id; + ret = testDomainChgIOThread(vm, iothread, + VIR_DOMAIN_IOTHREAD_ACTION_ADD, flags); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static int +testDomainDelIOThread(virDomainPtr dom, + unsigned int iothread_id, + unsigned int flags) +{ + virDomainObj *vm = NULL; + testMonitorIOThreadInfo iothread = {0}; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (iothread_id == 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid value of 0 for iothread_id")); + return -1; + } + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + iothread.iothread_id = iothread_id; + ret = testDomainChgIOThread(vm, iothread, + VIR_DOMAIN_IOTHREAD_ACTION_DEL, flags); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + /* * Test driver */ @@ -9356,6 +9514,8 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */ .domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */ .domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */ + .domainAddIOThread = testDomainAddIOThread, /* 7.6.0 */ + .domainDelIOThread = testDomainDelIOThread, /* 7.6.0 */ .domainGetSecurityLabel = testDomainGetSecurityLabel, /* 7.5.0 */ .nodeGetSecurityModel = testNodeGetSecurityModel, /* 7.5.0 */ .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ -- 2.32.0