[PATCH v2 0/3] Implement some blkio related APIs for test driver

v2: - Rebase to current master branch - Refine the tests Luke Yue (3): test_driver: Implement virDomainGetBlkioParameters test_driver: Implement virDomainSetBlkioParameters tests: Test BlkioParameters related functions for test driver examples/xml/test/testdomfv0.xml | 11 ++++ examples/xml/test/testnodeinline.xml | 11 ++++ src/test/meson.build | 1 + src/test/test_driver.c | 96 ++++++++++++++++++++++++++++ tests/virshtest.c | 55 ++++++++++++++++ 5 files changed, 174 insertions(+) -- 2.33.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b096d49ac6..23176000b6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3290,6 +3290,52 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return ret; } +static int +testDomainGetBlkioParameters(virDomainPtr dom, + virTypedParameterPtr params, + int *nparams, + unsigned int flags) +{ + virDomainObj *vm = NULL; + virDomainDef *def = NULL; + int maxparams = 6; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_TYPED_PARAM_STRING_OKAY, -1); + + if ((*nparams) == 0) { + *nparams = 6; + return 0; + } else if (*nparams < maxparams) { + maxparams = *nparams; + } + + *nparams = 0; + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (!(def = virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + if (virTypedParameterAssign(&(params[(*nparams)++]), + VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, + def->blkio.weight) < 0) + goto cleanup; + + if (virDomainGetBlkioParametersAssignFromDef(def, params, nparams, + maxparams) < 0) + goto cleanup; + + ret = 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} #define TEST_SET_PARAM(index, name, type, value) \ if (index < *nparams && \ @@ -9522,6 +9568,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ .domainSetBlockIoTune = testDomainSetBlockIoTune, /* 5.7.0 */ .domainGetBlockIoTune = testDomainGetBlockIoTune, /* 5.7.0 */ + .domainGetBlkioParameters = testDomainGetBlkioParameters, /* 7.7.0 */ .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ .domainCreate = testDomainCreate, /* 0.1.11 */ -- 2.33.0

On Thu, Aug 19, 2021 at 06:04:29PM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
--- src/test/test_driver.c | 47 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index b096d49ac6..23176000b6 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3290,6 +3290,52 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return ret; }
+static int +testDomainGetBlkioParameters(virDomainPtr dom, + virTypedParameterPtr params, + int *nparams, + unsigned int flags) +{ + virDomainObj *vm = NULL; + virDomainDef *def = NULL; + int maxparams = 6; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG | + VIR_TYPED_PARAM_STRING_OKAY, -1); + + if ((*nparams) == 0) { + *nparams = 6; + return 0; + } else if (*nparams < maxparams) { + maxparams = *nparams; + } + + *nparams = 0; + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (!(def = virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + if (virTypedParameterAssign(&(params[(*nparams)++]), + VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, + def->blkio.weight) < 0) + goto cleanup; + + if (virDomainGetBlkioParametersAssignFromDef(def, params, nparams, + maxparams) < 0) + goto cleanup; + + ret = 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +}
#define TEST_SET_PARAM(index, name, type, value) \ if (index < *nparams && \ @@ -9522,6 +9568,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ .domainSetBlockIoTune = testDomainSetBlockIoTune, /* 5.7.0 */ .domainGetBlockIoTune = testDomainGetBlockIoTune, /* 5.7.0 */ + .domainGetBlkioParameters = testDomainGetBlkioParameters, /* 7.7.0 */ .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ .domainCreate = testDomainCreate, /* 0.1.11 */ -- 2.33.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/meson.build | 1 + src/test/test_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/src/test/meson.build b/src/test/meson.build index f54585adfd..c0174ad856 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -17,6 +17,7 @@ if conf.has('WITH_TEST') ], include_directories: [ conf_inc_dir, + hypervisor_inc_dir, ], ) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 23176000b6..3aab8377c5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -40,6 +40,7 @@ #include "interface_conf.h" #include "checkpoint_conf.h" #include "domain_conf.h" +#include "domain_driver.h" #include "domain_event.h" #include "network_event.h" #include "snapshot_conf.h" @@ -3290,6 +3291,53 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return ret; } +static int +testDomainSetBlkioParameters(virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virDomainObj *vm = NULL; + virDomainDef *def; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (virTypedParamsValidate(params, nparams, + VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, + VIR_TYPED_PARAM_STRING, + NULL) < 0) + return -1; + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (!(def = virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + ret = 0; + + ret = virDomainDriverSetupPersistentDefBlkioParams(def, + params, + nparams); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainGetBlkioParameters(virDomainPtr dom, virTypedParameterPtr params, @@ -9568,6 +9616,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ .domainSetBlockIoTune = testDomainSetBlockIoTune, /* 5.7.0 */ .domainGetBlockIoTune = testDomainGetBlockIoTune, /* 5.7.0 */ + .domainSetBlkioParameters = testDomainSetBlkioParameters, /* 7.7.0 */ .domainGetBlkioParameters = testDomainGetBlkioParameters, /* 7.7.0 */ .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ -- 2.33.0

On Thu, Aug 19, 2021 at 06:04:30PM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/meson.build | 1 + src/test/test_driver.c | 49 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+)
diff --git a/src/test/meson.build b/src/test/meson.build index f54585adfd..c0174ad856 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -17,6 +17,7 @@ if conf.has('WITH_TEST') ], include_directories: [ conf_inc_dir, + hypervisor_inc_dir, ], )
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 23176000b6..3aab8377c5 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -40,6 +40,7 @@ #include "interface_conf.h" #include "checkpoint_conf.h" #include "domain_conf.h" +#include "domain_driver.h" #include "domain_event.h" #include "network_event.h" #include "snapshot_conf.h" @@ -3290,6 +3291,53 @@ static char *testDomainGetXMLDesc(virDomainPtr domain, unsigned int flags) return ret; }
+static int +testDomainSetBlkioParameters(virDomainPtr dom, + virTypedParameterPtr params, + int nparams, + unsigned int flags) +{ + virDomainObj *vm = NULL; + virDomainDef *def; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (virTypedParamsValidate(params, nparams, + VIR_DOMAIN_BLKIO_WEIGHT, + VIR_TYPED_PARAM_UINT, + VIR_DOMAIN_BLKIO_DEVICE_WEIGHT, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_READ_IOPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_IOPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_READ_BPS, + VIR_TYPED_PARAM_STRING, + VIR_DOMAIN_BLKIO_DEVICE_WRITE_BPS, + VIR_TYPED_PARAM_STRING, + NULL) < 0) + return -1; + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (!(def = virDomainObjGetOneDef(vm, flags))) + goto cleanup; + + ret = 0; +
Pointless line, but I can remove it before pushing. Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
+ ret = virDomainDriverSetupPersistentDefBlkioParams(def, + params, + nparams); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainGetBlkioParameters(virDomainPtr dom, virTypedParameterPtr params, @@ -9568,6 +9616,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetInterfaceParameters = testDomainGetInterfaceParameters, /* 5.6.0 */ .domainSetBlockIoTune = testDomainSetBlockIoTune, /* 5.7.0 */ .domainGetBlockIoTune = testDomainGetBlockIoTune, /* 5.7.0 */ + .domainSetBlkioParameters = testDomainSetBlkioParameters, /* 7.7.0 */ .domainGetBlkioParameters = testDomainGetBlkioParameters, /* 7.7.0 */ .connectListDefinedDomains = testConnectListDefinedDomains, /* 0.1.11 */ .connectNumOfDefinedDomains = testConnectNumOfDefinedDomains, /* 0.1.11 */ -- 2.33.0

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- examples/xml/test/testdomfv0.xml | 11 ++++++ examples/xml/test/testnodeinline.xml | 11 ++++++ tests/virshtest.c | 55 ++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/examples/xml/test/testdomfv0.xml b/examples/xml/test/testdomfv0.xml index fc209cce29..e60b5d69b7 100644 --- a/examples/xml/test/testdomfv0.xml +++ b/examples/xml/test/testdomfv0.xml @@ -38,4 +38,15 @@ </disk> <graphics type='vnc' port='5904'/> </devices> + <blkiotune> + <weight>800</weight> + <device> + <path>/dev/hda</path> + <weight>700</weight> + <read_bytes_sec>700</read_bytes_sec> + <write_bytes_sec>700</write_bytes_sec> + <read_iops_sec>700</read_iops_sec> + <write_iops_sec>700</write_iops_sec> + </device> + </blkiotune> </domain> diff --git a/examples/xml/test/testnodeinline.xml b/examples/xml/test/testnodeinline.xml index 60970145a0..9165d9302d 100644 --- a/examples/xml/test/testnodeinline.xml +++ b/examples/xml/test/testnodeinline.xml @@ -48,6 +48,17 @@ </disk> <graphics type="vnc" port="5904"/> </devices> + <blkiotune> + <weight>800</weight> + <device> + <path>/dev/hda</path> + <weight>700</weight> + <read_bytes_sec>700</read_bytes_sec> + <write_bytes_sec>700</write_bytes_sec> + <read_iops_sec>700</read_iops_sec> + <write_iops_sec>700</write_iops_sec> + </device> + </blkiotune> </domain> <domain type="test"> <name>fc4</name> diff --git a/tests/virshtest.c b/tests/virshtest.c index 751e8ffc49..87da1f5889 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -30,6 +30,8 @@ main(void) tainted: custom device tree blob used\n\ tainted: use of deprecated configuration settings\n\ deprecated configuration: CPU model Deprecated-Test" +# define GET_BLKIO_PARAMETER "/dev/hda,700" +# define SET_BLKIO_PARAMETER "/dev/hda,1000" static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -70,6 +72,25 @@ Security label: " SECURITY_LABEL "\n\ Messages: " FC5_MESSAGES "\n\ \n"; +static const char *get_blkio_parameters = "\ +weight : 800\n\ +device_weight : " GET_BLKIO_PARAMETER "\n\ +device_read_iops_sec: " GET_BLKIO_PARAMETER "\n\ +device_write_iops_sec: " GET_BLKIO_PARAMETER "\n\ +device_read_bytes_sec: " GET_BLKIO_PARAMETER "\n\ +device_write_bytes_sec: " GET_BLKIO_PARAMETER "\n\ +\n"; + +static const char *set_blkio_parameters = "\ +\n\ +weight : 500\n\ +device_weight : " SET_BLKIO_PARAMETER "\n\ +device_read_iops_sec: " SET_BLKIO_PARAMETER "\n\ +device_write_iops_sec: " SET_BLKIO_PARAMETER "\n\ +device_read_bytes_sec: " SET_BLKIO_PARAMETER "\n\ +device_write_bytes_sec: " SET_BLKIO_PARAMETER "\n\ +\n"; + static int testFilterLine(char *buffer, const char *toRemove) { @@ -291,6 +312,32 @@ static int testCompareDomControlInfoByName(const void *data G_GNUC_UNUSED) return testCompareOutputLit(exp, NULL, argv); } +static int testCompareGetBlkioParameters(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] = { VIRSH_CUSTOM, "blkiotune", "fv0", NULL }; + const char *exp = get_blkio_parameters; + return testCompareOutputLit(exp, NULL, argv); +} + +static int testCompareSetBlkioParameters(const void *data G_GNUC_UNUSED) +{ + const char *const argv[] = { VIRSH_CUSTOM, "blkiotune fv0\ + --weight 500\ + --device-weights\ + " SET_BLKIO_PARAMETER "\ + --device-read-iops-sec\ + " SET_BLKIO_PARAMETER "\ + --device-write-iops-sec\ + " SET_BLKIO_PARAMETER "\ + --device-read-bytes-sec\ + " SET_BLKIO_PARAMETER "\ + --device-write-bytes-sec\ + " SET_BLKIO_PARAMETER ";\ + blkiotune fv0", NULL }; + const char *exp = set_blkio_parameters; + return testCompareOutputLit(exp, NULL, argv); +} + struct testInfo { const char *const *argv; const char *result; @@ -383,6 +430,14 @@ mymain(void) testCompareDomControlInfoByName, NULL) != 0) ret = -1; + if (virTestRun("virsh blkiotune (get parameters)", + testCompareGetBlkioParameters, NULL) != 0) + ret = -1; + + if (virTestRun("virsh blkiotune (set parameters)", + testCompareSetBlkioParameters, NULL) != 0) + ret = -1; + /* It's a bit awkward listing result before argument, but that's a * limitation of C99 vararg macros. */ # define DO_TEST(i, result, ...) \ -- 2.33.0

On Thu, Aug 19, 2021 at 06:04:31PM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- examples/xml/test/testdomfv0.xml | 11 ++++++ examples/xml/test/testnodeinline.xml | 11 ++++++ tests/virshtest.c | 55 ++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
diff --git a/tests/virshtest.c b/tests/virshtest.c index 751e8ffc49..87da1f5889 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -30,6 +30,8 @@ main(void) tainted: custom device tree blob used\n\ tainted: use of deprecated configuration settings\n\ deprecated configuration: CPU model Deprecated-Test" +# define GET_BLKIO_PARAMETER "/dev/hda,700" +# define SET_BLKIO_PARAMETER "/dev/hda,1000"
static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -70,6 +72,25 @@ Security label: " SECURITY_LABEL "\n\ Messages: " FC5_MESSAGES "\n\ \n";
+static const char *get_blkio_parameters = "\ +weight : 800\n\ +device_weight : " GET_BLKIO_PARAMETER "\n\ +device_read_iops_sec: " GET_BLKIO_PARAMETER "\n\ +device_write_iops_sec: " GET_BLKIO_PARAMETER "\n\ +device_read_bytes_sec: " GET_BLKIO_PARAMETER "\n\ +device_write_bytes_sec: " GET_BLKIO_PARAMETER "\n\ +\n"; + +static const char *set_blkio_parameters = "\ +\n\ +weight : 500\n\ +device_weight : " SET_BLKIO_PARAMETER "\n\ +device_read_iops_sec: " SET_BLKIO_PARAMETER "\n\ +device_write_iops_sec: " SET_BLKIO_PARAMETER "\n\ +device_read_bytes_sec: " SET_BLKIO_PARAMETER "\n\ +device_write_bytes_sec: " SET_BLKIO_PARAMETER "\n\ +\n"; +
It could be a bit more thorough to set and test different values, but that can be done later, this is still a great improvement, thanks. Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
participants (2)
-
Luke Yue
-
Martin Kletzander