mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
blkiotune: add interface for blkiotune.device_weight
This adds per-device weights to <blkiotune>. Note that the
cgroups implementation only supports weights per block device,
and not per-file within the device; hence this option must be
global to the domain definition rather than tied to individual
<devices>/<disk> entries:
<domain ...>
<blkiotune>
<device>
<path>/path/to/block</path>
<weight>1000</weight>
</device>
</blkiotune>
..
This patch also adds a parameter --device-weights to virsh command
blkiotune for setting/getting blkiotune.weight_device for any
hypervisor that supports it. All <device> entries under
<blkiotune> are concatenated into a single string attribute under
virDomain{Get,Set}BlkioParameters, named "device_weight".
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
@@ -4653,6 +4653,8 @@ 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]")},
|
||||
{"device-weights", VSH_OT_STRING, VSH_OFLAG_NONE,
|
||||
N_("per-device IO Weights, in the form of /path/to/device,weight,...")},
|
||||
{"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")},
|
||||
@@ -4663,6 +4665,7 @@ static bool
|
||||
cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
|
||||
{
|
||||
virDomainPtr dom;
|
||||
const char *device_weight = NULL;
|
||||
int weight = 0;
|
||||
int nparams = 0;
|
||||
int rv = 0;
|
||||
@@ -4707,6 +4710,16 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
|
||||
}
|
||||
}
|
||||
|
||||
rv = vshCommandOptString(cmd, "device-weights", &device_weight);
|
||||
if (rv < 0) {
|
||||
vshError(ctl, "%s",
|
||||
_("Unable to parse string parameter"));
|
||||
goto cleanup;
|
||||
}
|
||||
if (rv > 0) {
|
||||
nparams++;
|
||||
}
|
||||
|
||||
if (nparams == 0) {
|
||||
/* get the number of blkio parameters */
|
||||
if (virDomainGetBlkioParameters(dom, NULL, &nparams, flags) != 0) {
|
||||
@@ -4754,12 +4767,14 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
|
||||
vshPrint(ctl, "%-15s: %d\n", params[i].field,
|
||||
params[i].value.b);
|
||||
break;
|
||||
case VIR_TYPED_PARAM_STRING:
|
||||
vshPrint(ctl, "%-15s: %s\n", params[i].field,
|
||||
params[i].value.s);
|
||||
break;
|
||||
default:
|
||||
vshPrint(ctl, "unimplemented blkio parameter type\n");
|
||||
}
|
||||
}
|
||||
|
||||
ret = true;
|
||||
} else {
|
||||
/* set the blkio parameters */
|
||||
params = vshCalloc(ctl, nparams, sizeof(*params));
|
||||
@@ -4770,18 +4785,30 @@ cmdBlkiotune(vshControl * ctl, const vshCmd * cmd)
|
||||
|
||||
if (weight) {
|
||||
temp->value.ui = weight;
|
||||
strncpy(temp->field, VIR_DOMAIN_BLKIO_WEIGHT,
|
||||
sizeof(temp->field));
|
||||
weight = 0;
|
||||
if (!virStrcpy(temp->field, VIR_DOMAIN_BLKIO_WEIGHT,
|
||||
sizeof(temp->field)))
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (device_weight) {
|
||||
temp->value.s = vshStrdup(ctl, device_weight);
|
||||
temp->type = VIR_TYPED_PARAM_STRING;
|
||||
if (!virStrcpy(temp->field, VIR_DOMAIN_BLKIO_DEVICE_WEIGHT,
|
||||
sizeof(temp->field)))
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (virDomainSetBlkioParameters(dom, params, nparams, flags) != 0)
|
||||
|
||||
if (virDomainSetBlkioParameters(dom, params, nparams, flags) < 0) {
|
||||
vshError(ctl, "%s", _("Unable to change blkio parameters"));
|
||||
else
|
||||
ret = true;
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
ret = true;
|
||||
|
||||
cleanup:
|
||||
virTypedParameterArrayClear(params, nparams);
|
||||
VIR_FREE(params);
|
||||
virDomainFree(dom);
|
||||
return ret;
|
||||
|
||||
@@ -1045,12 +1045,18 @@ value are kilobytes (i.e. blocks of 1024 bytes).
|
||||
|
||||
Specifying -1 as a value for these limits is interpreted as unlimited.
|
||||
|
||||
=item B<blkiotune> I<domain-id> [I<--weight> B<weight>] [[I<--config>]
|
||||
=item B<blkiotune> I<domain-id> [I<--weight> B<weight>]
|
||||
[I<--device-weights> B<device-weights>] [[I<--config>]
|
||||
[I<--live>] | [I<--current>]]
|
||||
|
||||
Display or set the blkio parameters. QEMU/KVM supports I<--weight>.
|
||||
I<--weight> is in range [100, 1000].
|
||||
|
||||
B<device-weights> is a single string listing one or more device/weight
|
||||
pairs, in the format of /path/to/device,weight,/path/to/device,weight.
|
||||
Each weight is in the range [100, 1000], or the value 0 to remove that
|
||||
device from per-device listings.
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user