# HG changeset patch
# User Dan Smith <danms(a)us.ibm.com>
# Date 1223921465 25200
# Node ID 56b5db360cb4e78cec960c6b31e4f6159edb8c46
# Parent 31edd656481f4a328f16102ab9f7b9e24643d687
Make ComputerSystem enforce LXC scheduling parameters on domain start
Signed-off-by: Dan Smith <danms(a)us.ibm.com>
diff -r 31edd656481f -r 56b5db360cb4 src/Virt_ComputerSystem.c
--- a/src/Virt_ComputerSystem.c Mon Oct 13 11:02:40 2008 -0700
+++ b/src/Virt_ComputerSystem.c Mon Oct 13 11:11:05 2008 -0700
@@ -667,23 +667,70 @@
DEFAULT_EQ();
DEFAULT_INST_CLEANUP();
+static int xen_scheduler_params(struct infostore_ctx *ctx,
+ virSchedParameter **params)
+{
+ unsigned long long weight;
+ unsigned long long cap;
+
+ *params = calloc(2, sizeof(virSchedParameter));
+ if (*params == NULL)
+ return -1;
+
+ weight = infostore_get_u64(ctx, "weight");
+ cap = infostore_get_u64(ctx, "limit");
+
+ if (weight != 0) {
+ strncpy((*params)[0].field,
+ "weight",
+ sizeof((*params)[0].field));
+ (*params)[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
+ (*params)[0].value.ui = weight;
+ }
+
+ if (cap != 0) {
+ strncpy((*params)[0].field,
+ "cap",
+ sizeof((*params)[0].field));
+ (*params)[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
+ (*params)[0].value.ui = cap;
+ }
+
+ return 2;
+}
+
+static int lxc_scheduler_params(struct infostore_ctx *ctx,
+ virSchedParameter **params)
+{
+ unsigned long long value;
+
+ *params = calloc(1, sizeof(virSchedParameter));
+ if (*params == NULL)
+ return -1;
+
+ value = infostore_get_u64(ctx, "weight");
+
+ if (value != 0) {
+ strncpy((*params)[0].field,
+ "cpu_shares",
+ sizeof((*params)[0].field));
+ (*params)[0].type = VIR_DOMAIN_SCHED_FIELD_UINT;
+ (*params)[0].value.ui = value;
+ }
+
+ return 1;
+}
+
static void set_scheduler_params(virDomainPtr dom)
{
struct infostore_ctx *ctx;
virConnectPtr conn = NULL;
- virSchedParameter params[] =
- {{ "weight", VIR_DOMAIN_SCHED_FIELD_UINT },
- { "cap", VIR_DOMAIN_SCHED_FIELD_UINT },
- };
+ virSchedParameter *params = NULL;
+ int count;
conn = virDomainGetConnect(dom);
if (conn == NULL) {
CU_DEBUG("Unable to get connection from domain");
- return;
- }
-
- if (!STREQC(virConnectGetType(conn), "xen")) {
- CU_DEBUG("Not setting sched params for this domain type");
return;
}
@@ -693,13 +740,27 @@
return;
}
- params[0].value.ui = infostore_get_u64(ctx, "weight");
- params[1].value.ui = infostore_get_u64(ctx, "limit");
+ if (STREQC(virConnectGetType(conn), "xen"))
+ count = xen_scheduler_params(ctx, ¶ms);
+ else if (STREQC(virConnectGetType(conn), "lxc"))
+ count = lxc_scheduler_params(ctx, ¶ms);
+ else {
+ CU_DEBUG("Not setting sched params for type %s",
+ virConnectGetType(conn));
+ goto out;
+ }
- virDomainSetSchedulerParameters(dom, params, 2);
+ if (count < 0) {
+ CU_DEBUG("Unable to set scheduler parameters");
+ goto out;
+ }
+ virDomainSetSchedulerParameters(dom, params, count);
+ out:
infostore_close(ctx);
+ free(params);
}
+
/* This composite operation may be supported as a flag to reboot */
static int domain_reset(virDomainPtr dom)