[libvirt] [PATCH v3 0/3] add support for changing blkio parameters for inactive domains

This series enables user to change blkio parameters for inactive domains from virsh command line. CHANGES: v2-v3: - based on new macros VIR_DOMAIN_AFFECT_XXX Hu Tao (3): Add new parameters for blkiotune update qemuDomainGetBlkioParameters to use flags Update qemuDomainSetBlkioParameters to use flags src/qemu/qemu_driver.c | 250 ++++++++++++++++++++++++++++++++++-------------- tools/virsh.c | 26 +++++- tools/virsh.pod | 7 ++ 3 files changed, 206 insertions(+), 77 deletions(-) -- 1.7.3.1

Add --config, --live and --current for command blkiotune --- tools/virsh.c | 26 +++++++++++++++++++++++--- tools/virsh.pod | 7 +++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index d98be1c..d458b92 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3343,6 +3343,9 @@ static const vshCmdOptDef opts_blkiotune[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"weight", VSH_OT_INT, VSH_OFLAG_NONE, N_("IO Weight in range [100, 1000]")}, + {"config", VSH_OT_BOOL, 0, N_("affect next boot")}, + {"live", VSH_OT_BOOL, 0, N_("affect running domain")}, + {"current", VSH_OT_BOOL, 0, N_("affect current domain")}, {NULL, 0, 0, NULL} }; @@ -3355,6 +3358,23 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) unsigned int i = 0; virTypedParameterPtr params = NULL, temp = NULL; bool ret = false; + unsigned int flags = 0; + int current = vshCommandOptBool(cmd, "current"); + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + } if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -3379,7 +3399,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) if (nparams == 0) { /* get the number of blkio parameters */ - if (virDomainGetBlkioParameters(dom, NULL, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, NULL, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get number of blkio parameters")); goto cleanup; @@ -3393,7 +3413,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) /* now go get all the blkio parameters */ params = vshCalloc(ctl, nparams, sizeof(*params)); - if (virDomainGetBlkioParameters(dom, params, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, params, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get blkio parameters")); goto cleanup; } @@ -3445,7 +3465,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) weight = 0; } } - if (virDomainSetBlkioParameters(dom, params, nparams, 0) != 0) + if (virDomainSetBlkioParameters(dom, params, nparams, flags) != 0) vshError(ctl, "%s", _("Unable to change blkio parameters")); else ret = true; diff --git a/tools/virsh.pod b/tools/virsh.pod index 7ed3003..9c53203 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -697,6 +697,13 @@ value are kilobytes (i.e. blocks of 1024 bytes). Display or set the blkio parameters. QEMU/KVM supports I<--weight>. I<--weight> is in range [100, 1000]. +If I<--live> is specified, affect a running guest. +If I<--config> is specified, affect the next boot of a persistent guest. +If I<--current> is specified, affect the current guest state. +Both I<--live> and I<--current> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. + =item B<setvcpus> I<domain-id> I<count> optional I<--maximum> I<--config> I<--live> -- 1.7.3.1

On Tue, Jun 07, 2011 at 02:03:07PM +0800, Hu Tao wrote:
Add --config, --live and --current for command blkiotune --- tools/virsh.c | 26 +++++++++++++++++++++++--- tools/virsh.pod | 7 +++++++ 2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index d98be1c..d458b92 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3343,6 +3343,9 @@ static const vshCmdOptDef opts_blkiotune[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"weight", VSH_OT_INT, VSH_OFLAG_NONE, N_("IO Weight in range [100, 1000]")}, + {"config", VSH_OT_BOOL, 0, N_("affect next boot")}, + {"live", VSH_OT_BOOL, 0, N_("affect running domain")}, + {"current", VSH_OT_BOOL, 0, N_("affect current domain")}, {NULL, 0, 0, NULL} };
@@ -3355,6 +3358,23 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) unsigned int i = 0; virTypedParameterPtr params = NULL, temp = NULL; bool ret = false; + unsigned int flags = 0; + int current = vshCommandOptBool(cmd, "current"); + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + }
if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -3379,7 +3399,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
if (nparams == 0) { /* get the number of blkio parameters */ - if (virDomainGetBlkioParameters(dom, NULL, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, NULL, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get number of blkio parameters")); goto cleanup; @@ -3393,7 +3413,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
/* now go get all the blkio parameters */ params = vshCalloc(ctl, nparams, sizeof(*params)); - if (virDomainGetBlkioParameters(dom, params, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, params, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get blkio parameters")); goto cleanup; } @@ -3445,7 +3465,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) weight = 0; } } - if (virDomainSetBlkioParameters(dom, params, nparams, 0) != 0) + if (virDomainSetBlkioParameters(dom, params, nparams, flags) != 0) vshError(ctl, "%s", _("Unable to change blkio parameters")); else ret = true; diff --git a/tools/virsh.pod b/tools/virsh.pod index 7ed3003..9c53203 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -697,6 +697,13 @@ value are kilobytes (i.e. blocks of 1024 bytes). Display or set the blkio parameters. QEMU/KVM supports I<--weight>. I<--weight> is in range [100, 1000].
+If I<--live> is specified, affect a running guest. +If I<--config> is specified, affect the next boot of a persistent guest. +If I<--current> is specified, affect the current guest state. +Both I<--live> and I<--current> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. + =item B<setvcpus> I<domain-id> I<count> optional I<--maximum> I<--config> I<--live>
ACK, Wen could you push this ;-) ? Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

At 06/20/2011 02:22 PM, Daniel Veillard Write:
On Tue, Jun 07, 2011 at 02:03:07PM +0800, Hu Tao wrote:
Add --config, --live and --current for command blkiotune --- tools/virsh.c | 26 +++++++++++++++++++++++--- tools/virsh.pod | 7 +++++++ 2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/tools/virsh.c b/tools/virsh.c index d98be1c..d458b92 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -3343,6 +3343,9 @@ static const vshCmdOptDef opts_blkiotune[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"weight", VSH_OT_INT, VSH_OFLAG_NONE, N_("IO Weight in range [100, 1000]")}, + {"config", VSH_OT_BOOL, 0, N_("affect next boot")}, + {"live", VSH_OT_BOOL, 0, N_("affect running domain")}, + {"current", VSH_OT_BOOL, 0, N_("affect current domain")}, {NULL, 0, 0, NULL} };
@@ -3355,6 +3358,23 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) unsigned int i = 0; virTypedParameterPtr params = NULL, temp = NULL; bool ret = false; + unsigned int flags = 0; + int current = vshCommandOptBool(cmd, "current"); + int config = vshCommandOptBool(cmd, "config"); + int live = vshCommandOptBool(cmd, "live"); + + if (current) { + if (live || config) { + vshError(ctl, "%s", _("--current must be specified exclusively")); + return false; + } + flags = VIR_DOMAIN_AFFECT_CURRENT; + } else { + if (config) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; + }
if (!vshConnectionUsability(ctl, ctl->conn)) return false; @@ -3379,7 +3399,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
if (nparams == 0) { /* get the number of blkio parameters */ - if (virDomainGetBlkioParameters(dom, NULL, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, NULL, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get number of blkio parameters")); goto cleanup; @@ -3393,7 +3413,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
/* now go get all the blkio parameters */ params = vshCalloc(ctl, nparams, sizeof(*params)); - if (virDomainGetBlkioParameters(dom, params, &nparams, 0) != 0) { + if (virDomainGetBlkioParameters(dom, params, &nparams, flags) != 0) { vshError(ctl, "%s", _("Unable to get blkio parameters")); goto cleanup; } @@ -3445,7 +3465,7 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd) weight = 0; } } - if (virDomainSetBlkioParameters(dom, params, nparams, 0) != 0) + if (virDomainSetBlkioParameters(dom, params, nparams, flags) != 0) vshError(ctl, "%s", _("Unable to change blkio parameters")); else ret = true; diff --git a/tools/virsh.pod b/tools/virsh.pod index 7ed3003..9c53203 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -697,6 +697,13 @@ value are kilobytes (i.e. blocks of 1024 bytes). Display or set the blkio parameters. QEMU/KVM supports I<--weight>. I<--weight> is in range [100, 1000].
+If I<--live> is specified, affect a running guest. +If I<--config> is specified, affect the next boot of a persistent guest. +If I<--current> is specified, affect the current guest state. +Both I<--live> and I<--current> flags may be given, but I<--current> is +exclusive. If no flag is specified, behavior is different depending +on hypervisor. + =item B<setvcpus> I<domain-id> I<count> optional I<--maximum> I<--config> I<--live>
ACK,
Wen could you push this ;-) ?
I have pushed this series patch. Thanks. Wen Congyang
Daniel

--- src/qemu/qemu_driver.c | 124 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 86 insertions(+), 38 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2957467..8ebb7d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4824,18 +4824,16 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, int i; virCgroupPtr group = NULL; virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; unsigned int val; int ret = -1; int rc; + bool isActive; - virCheckFlags(0, -1); + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); qemuDriverLock(driver); - if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { - qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); - goto cleanup; - } - vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (vm == NULL) { @@ -4844,12 +4842,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (!virDomainObjIsActive(vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto cleanup; - } - if ((*nparams) == 0) { /* Current number of blkio parameters supported by cgroups */ *nparams = QEMU_NB_BLKIO_PARAM; @@ -4863,37 +4855,93 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find cgroup for domain %s"), vm->def->name); - goto cleanup; + isActive = virDomainObjIsActive(vm); + + if (flags == VIR_DOMAIN_AFFECT_CURRENT) { + if (isActive) + flags = VIR_DOMAIN_AFFECT_LIVE; + else + flags = VIR_DOMAIN_AFFECT_CONFIG; } - for (i = 0; i < *nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_TYPED_PARAM_UINT; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!isActive) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } - switch (i) { - case 0: /* fill blkio weight here */ - rc = virCgroupGetBlkioWeight(group, &val); - if (rc != 0) { - virReportSystemError(-rc, "%s", - _("unable to get blkio weight")); - goto cleanup; - } - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Field blkio weight too long for destination")); - goto cleanup; + if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { + qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); + goto cleanup; + } + + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find cgroup for domain %s"), vm->def->name); + goto cleanup; + } + } + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (!vm->persistent) { + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot change persistent config of a transient domain")); + goto cleanup; + } + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) + goto cleanup; + } + + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + for (i = 0; i < *nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_TYPED_PARAM_UINT; + + switch (i) { + case 0: /* fill blkio weight here */ + rc = virCgroupGetBlkioWeight(group, &val); + if (rc != 0) { + virReportSystemError(-rc, "%s", + _("unable to get blkio weight")); + goto cleanup; + } + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = val; + break; + + default: + break; + /* should not hit here */ } - param->value.ui = val; - break; + } + } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + for (i = 0; i < *nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_TYPED_PARAM_UINT; - default: - break; - /* should not hit here */ + switch (i) { + case 0: /* fill blkio weight here */ + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = persistentDef->blkio.weight; + break; + + default: + break; + /* should not hit here */ + } } } -- 1.7.3.1

On Tue, Jun 07, 2011 at 02:03:08PM +0800, Hu Tao wrote:
--- src/qemu/qemu_driver.c | 124 +++++++++++++++++++++++++++++++++--------------- 1 files changed, 86 insertions(+), 38 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 2957467..8ebb7d4 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4824,18 +4824,16 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, int i; virCgroupPtr group = NULL; virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; unsigned int val; int ret = -1; int rc; + bool isActive;
- virCheckFlags(0, -1); + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); qemuDriverLock(driver);
- if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { - qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); - goto cleanup; - } - vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (vm == NULL) { @@ -4844,12 +4842,6 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; }
- if (!virDomainObjIsActive(vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto cleanup; - } - if ((*nparams) == 0) { /* Current number of blkio parameters supported by cgroups */ *nparams = QEMU_NB_BLKIO_PARAM; @@ -4863,37 +4855,93 @@ static int qemuDomainGetBlkioParameters(virDomainPtr dom, goto cleanup; }
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find cgroup for domain %s"), vm->def->name); - goto cleanup; + isActive = virDomainObjIsActive(vm); + + if (flags == VIR_DOMAIN_AFFECT_CURRENT) { + if (isActive) + flags = VIR_DOMAIN_AFFECT_LIVE; + else + flags = VIR_DOMAIN_AFFECT_CONFIG; }
- for (i = 0; i < *nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; - val = 0; - param->value.ui = 0; - param->type = VIR_TYPED_PARAM_UINT; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!isActive) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + }
- switch (i) { - case 0: /* fill blkio weight here */ - rc = virCgroupGetBlkioWeight(group, &val); - if (rc != 0) { - virReportSystemError(-rc, "%s", - _("unable to get blkio weight")); - goto cleanup; - } - if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Field blkio weight too long for destination")); - goto cleanup; + if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { + qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); + goto cleanup; + } + + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find cgroup for domain %s"), vm->def->name); + goto cleanup; + } + } + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (!vm->persistent) { + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot change persistent config of a transient domain")); + goto cleanup; + } + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) + goto cleanup; + } + + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + for (i = 0; i < *nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_TYPED_PARAM_UINT; + + switch (i) { + case 0: /* fill blkio weight here */ + rc = virCgroupGetBlkioWeight(group, &val); + if (rc != 0) { + virReportSystemError(-rc, "%s", + _("unable to get blkio weight")); + goto cleanup; + } + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = val; + break; + + default: + break; + /* should not hit here */ } - param->value.ui = val; - break; + } + } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + for (i = 0; i < *nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; + val = 0; + param->value.ui = 0; + param->type = VIR_TYPED_PARAM_UINT;
- default: - break; - /* should not hit here */ + switch (i) { + case 0: /* fill blkio weight here */ + if (virStrcpyStatic(param->field, VIR_DOMAIN_BLKIO_WEIGHT) == NULL) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Field blkio weight too long for destination")); + goto cleanup; + } + param->value.ui = persistentDef->blkio.weight; + break; + + default: + break; + /* should not hit here */ + } } }
Okay, the for() loop with only 0 index being useful is a bit confusing but matches other similar parmeter filling pieces of code, ACK Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

--- src/qemu/qemu_driver.c | 126 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 90 insertions(+), 36 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8ebb7d4..fb2f63a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4745,14 +4745,13 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom, int i; virCgroupPtr group = NULL; virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; int ret = -1; + bool isActive; - virCheckFlags(0, -1); + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); qemuDriverLock(driver); - if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { - qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); - goto cleanup; - } vm = virDomainFindByUUID(&driver->domains, dom->uuid); @@ -4762,49 +4761,104 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom, goto cleanup; } - if (!virDomainObjIsActive(vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto cleanup; + isActive = virDomainObjIsActive(vm); + + if (flags == VIR_DOMAIN_AFFECT_CURRENT) { + if (isActive) + flags = VIR_DOMAIN_AFFECT_LIVE; + else + flags = VIR_DOMAIN_AFFECT_CONFIG; } - if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find cgroup for domain %s"), vm->def->name); - goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!isActive) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } + + if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { + qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); + goto cleanup; + } + + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find cgroup for domain %s"), vm->def->name); + goto cleanup; + } + } + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (!vm->persistent) { + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot change persistent config of a transient domain")); + goto cleanup; + } + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) + goto cleanup; } ret = 0; - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; - if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - int rc; - if (param->type != VIR_TYPED_PARAM_UINT) { - qemuReportError(VIR_ERR_INVALID_ARG, "%s", - _("invalid type for blkio weight tunable, expected a 'unsigned int'")); - ret = -1; - continue; - } + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + int rc; + if (param->type != VIR_TYPED_PARAM_UINT) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid type for blkio weight tunable, expected a 'unsigned int'")); + ret = -1; + continue; + } - if (params[i].value.ui > 1000 || params[i].value.ui < 100) { - qemuReportError(VIR_ERR_INVALID_ARG, "%s", - _("out of blkio weight range.")); + if (params[i].value.ui > 1000 || params[i].value.ui < 100) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("out of blkio weight range.")); + ret = -1; + continue; + } + + rc = virCgroupSetBlkioWeight(group, params[i].value.ui); + if (rc != 0) { + virReportSystemError(-rc, "%s", + _("unable to set blkio weight tunable")); + ret = -1; + } + } else { + qemuReportError(VIR_ERR_INVALID_ARG, + _("Parameter `%s' not supported"), param->field); ret = -1; - continue; } + } + } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i]; - rc = virCgroupSetBlkioWeight(group, params[i].value.ui); - if (rc != 0) { - virReportSystemError(-rc, "%s", - _("unable to set blkio weight tunable")); + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + if (param->type != VIR_TYPED_PARAM_UINT) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid type for blkio weight tunable, expected a 'unsigned int'")); + ret = -1; + continue; + } + + if (params[i].value.ui > 1000 || params[i].value.ui < 100) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("out of blkio weight range.")); + ret = -1; + continue; + } + + persistentDef->blkio.weight = params[i].value.ui; + } else { + qemuReportError(VIR_ERR_INVALID_ARG, + _("Parameter `%s' not supported"), param->field); ret = -1; } - } else { - qemuReportError(VIR_ERR_INVALID_ARG, - _("Parameter `%s' not supported"), param->field); - ret = -1; } + ret = virDomainSaveConfig(driver->configDir, persistentDef); } cleanup: -- 1.7.3.1

On Tue, Jun 07, 2011 at 02:03:09PM +0800, Hu Tao wrote:
--- src/qemu/qemu_driver.c | 126 ++++++++++++++++++++++++++++++++++-------------- 1 files changed, 90 insertions(+), 36 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 8ebb7d4..fb2f63a 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4745,14 +4745,13 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom, int i; virCgroupPtr group = NULL; virDomainObjPtr vm = NULL; + virDomainDefPtr persistentDef = NULL; int ret = -1; + bool isActive;
- virCheckFlags(0, -1); + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); qemuDriverLock(driver); - if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { - qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); - goto cleanup; - }
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
@@ -4762,49 +4761,104 @@ static int qemuDomainSetBlkioParameters(virDomainPtr dom, goto cleanup; }
- if (!virDomainObjIsActive(vm)) { - qemuReportError(VIR_ERR_OPERATION_INVALID, - "%s", _("domain is not running")); - goto cleanup; + isActive = virDomainObjIsActive(vm); + + if (flags == VIR_DOMAIN_AFFECT_CURRENT) { + if (isActive) + flags = VIR_DOMAIN_AFFECT_LIVE; + else + flags = VIR_DOMAIN_AFFECT_CONFIG; }
- if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { - qemuReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot find cgroup for domain %s"), vm->def->name); - goto cleanup; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + if (!isActive) { + qemuReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is not running")); + goto cleanup; + } + + if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) { + qemuReportError(VIR_ERR_NO_SUPPORT, _("blkio cgroup isn't mounted")); + goto cleanup; + } + + if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) { + qemuReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find cgroup for domain %s"), vm->def->name); + goto cleanup; + } + } + + if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + if (!vm->persistent) { + qemuReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot change persistent config of a transient domain")); + goto cleanup; + } + if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm))) + goto cleanup; }
ret = 0; - for (i = 0; i < nparams; i++) { - virTypedParameterPtr param = ¶ms[i]; + if (flags & VIR_DOMAIN_AFFECT_LIVE) { + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i];
- if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { - int rc; - if (param->type != VIR_TYPED_PARAM_UINT) { - qemuReportError(VIR_ERR_INVALID_ARG, "%s", - _("invalid type for blkio weight tunable, expected a 'unsigned int'")); - ret = -1; - continue; - } + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + int rc; + if (param->type != VIR_TYPED_PARAM_UINT) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid type for blkio weight tunable, expected a 'unsigned int'")); + ret = -1; + continue; + }
- if (params[i].value.ui > 1000 || params[i].value.ui < 100) { - qemuReportError(VIR_ERR_INVALID_ARG, "%s", - _("out of blkio weight range.")); + if (params[i].value.ui > 1000 || params[i].value.ui < 100) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("out of blkio weight range.")); + ret = -1; + continue; + } + + rc = virCgroupSetBlkioWeight(group, params[i].value.ui); + if (rc != 0) { + virReportSystemError(-rc, "%s", + _("unable to set blkio weight tunable")); + ret = -1; + } + } else { + qemuReportError(VIR_ERR_INVALID_ARG, + _("Parameter `%s' not supported"), param->field); ret = -1; - continue; } + } + } else if (flags & VIR_DOMAIN_AFFECT_CONFIG) { + for (i = 0; i < nparams; i++) { + virTypedParameterPtr param = ¶ms[i];
- rc = virCgroupSetBlkioWeight(group, params[i].value.ui); - if (rc != 0) { - virReportSystemError(-rc, "%s", - _("unable to set blkio weight tunable")); + if (STREQ(param->field, VIR_DOMAIN_BLKIO_WEIGHT)) { + if (param->type != VIR_TYPED_PARAM_UINT) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("invalid type for blkio weight tunable, expected a 'unsigned int'")); + ret = -1; + continue; + } + + if (params[i].value.ui > 1000 || params[i].value.ui < 100) { + qemuReportError(VIR_ERR_INVALID_ARG, "%s", + _("out of blkio weight range.")); + ret = -1; + continue; + } + + persistentDef->blkio.weight = params[i].value.ui; + } else { + qemuReportError(VIR_ERR_INVALID_ARG, + _("Parameter `%s' not supported"), param->field); ret = -1; } - } else { - qemuReportError(VIR_ERR_INVALID_ARG, - _("Parameter `%s' not supported"), param->field); - ret = -1; } + ret = virDomainSaveConfig(driver->configDir, persistentDef); }
cleanup:
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

ping On Tue, Jun 07, 2011 at 02:03:06PM +0800, Hu Tao wrote:
This series enables user to change blkio parameters for inactive domains from virsh command line.
CHANGES:
v2-v3: - based on new macros VIR_DOMAIN_AFFECT_XXX
Hu Tao (3): Add new parameters for blkiotune update qemuDomainGetBlkioParameters to use flags Update qemuDomainSetBlkioParameters to use flags
src/qemu/qemu_driver.c | 250 ++++++++++++++++++++++++++++++++++-------------- tools/virsh.c | 26 +++++- tools/virsh.pod | 7 ++ 3 files changed, 206 insertions(+), 77 deletions(-)
-- 1.7.3.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
participants (3)
-
Daniel Veillard
-
Hu Tao
-
Wen Congyang