[PATCH] Add support for scheduler functions in remote

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a rather tedious patch, but I've tested it against the Xen driver and it works for getting and setting the various parameters and scheduler type.

Rich.

--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
Index: qemud/remote.c
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote.c,v
retrieving revision 1.1
diff -u -p -r1.1 remote.c
--- qemud/remote.c	11 Jun 2007 11:47:01 -0000	1.1
+++ qemud/remote.c	22 Jun 2007 11:28:32 -0000
@@ -516,6 +516,165 @@ remoteDispatchGetCapabilities (struct qe
 }
 
 static int
+remoteDispatchDomainGetSchedulerType (struct qemud_client *client,
+                                      remote_message_header *req,
+                                      remote_domain_get_scheduler_type_args *args,
+                                      remote_domain_get_scheduler_type_ret *ret)
+{
+    virDomainPtr dom;
+    char *type;
+    int nparams;
+    CHECK_CONN(client);
+
+    dom = get_nonnull_domain (client->conn, args->dom);
+    if (dom == NULL) {
+        remoteDispatchError (client, req, "domain not found");
+        return -2;
+    }
+
+    type = virDomainGetSchedulerType (dom, &nparams);
+    if (type == NULL) return -1;
+
+    ret->type = type;
+    ret->nparams = nparams;
+    return 0;
+}
+
+static int
+remoteDispatchDomainGetSchedulerParameters (struct qemud_client *client,
+                                            remote_message_header *req,
+                                            remote_domain_get_scheduler_parameters_args *args,
+                                            remote_domain_get_scheduler_parameters_ret *ret)
+{
+    virDomainPtr dom;
+    virSchedParameterPtr params;
+    int i, r, nparams;
+    CHECK_CONN(client);
+
+    nparams = args->nparams;
+
+    if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
+        remoteDispatchError (client, req, "nparams too large");
+        return -2;
+    }
+    params = malloc (sizeof (virSchedParameter) * nparams);
+    if (params == NULL) {
+        remoteDispatchError (client, req, "out of memory allocating array");
+        return -2;
+    }
+
+    dom = get_nonnull_domain (client->conn, args->dom);
+    if (dom == NULL) {
+        free (params);
+        remoteDispatchError (client, req, "domain not found");
+        return -2;
+    }
+
+    r = virDomainGetSchedulerParameters (dom, params, &nparams);
+    if (r == -1) {
+        free (params);
+        return -1;
+    }
+
+    /* Serialise the scheduler parameters. */
+    ret->params.params_len = nparams;
+    ret->params.params_val = malloc (sizeof (struct remote_sched_param)
+                                     * nparams);
+    if (ret->params.params_val == NULL) {
+        free (params);
+        remoteDispatchError (client, req,
+                             "out of memory allocating return array");
+        return -2;
+    }
+
+    for (i = 0; i < nparams; ++i) {
+        // remoteDispatchClientRequest will free this:
+        ret->params.params_val[i].field = strdup (params[i].field);
+        ret->params.params_val[i].value.type = params[i].type;
+        switch (params[i].type) {
+        case VIR_DOMAIN_SCHED_FIELD_INT:
+            ret->params.params_val[i].value.remote_sched_param_value_u.i = params[i].value.i; break;
+        case VIR_DOMAIN_SCHED_FIELD_UINT:
+            ret->params.params_val[i].value.remote_sched_param_value_u.ui = params[i].value.ui; break;
+        case VIR_DOMAIN_SCHED_FIELD_LLONG:
+            ret->params.params_val[i].value.remote_sched_param_value_u.l = params[i].value.l; break;
+        case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+            ret->params.params_val[i].value.remote_sched_param_value_u.ul = params[i].value.ul; break;
+        case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+            ret->params.params_val[i].value.remote_sched_param_value_u.d = params[i].value.d; break;
+        case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+            ret->params.params_val[i].value.remote_sched_param_value_u.b = params[i].value.b; break;
+        default:
+            free (params);
+            remoteDispatchError (client, req, "unknown type");
+            return -2;
+        }
+    }
+    free (params);
+
+    return 0;
+}
+
+static int
+remoteDispatchDomainSetSchedulerParameters (struct qemud_client *client,
+                                            remote_message_header *req,
+                                            remote_domain_set_scheduler_parameters_args *args,
+                                            void *ret ATTRIBUTE_UNUSED)
+{
+    virDomainPtr dom;
+    int i, r, nparams;
+    virSchedParameterPtr params;
+    CHECK_CONN(client);
+
+    nparams = args->params.params_len;
+
+    if (nparams > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX) {
+        remoteDispatchError (client, req, "nparams too large");
+        return -2;
+    }
+    params = malloc (sizeof (virSchedParameter) * nparams);
+    if (params == NULL) {
+        remoteDispatchError (client, req, "out of memory allocating array");
+        return -2;
+    }
+
+    /* Deserialise parameters. */
+    for (i = 0; i < nparams; ++i) {
+        strncpy (params[i].field, args->params.params_val[i].field,
+                 VIR_DOMAIN_SCHED_FIELD_LENGTH);
+        params[i].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
+        params[i].type = args->params.params_val[i].value.type;
+        switch (params[i].type) {
+        case VIR_DOMAIN_SCHED_FIELD_INT:
+            params[i].value.i = args->params.params_val[i].value.remote_sched_param_value_u.i; break;
+        case VIR_DOMAIN_SCHED_FIELD_UINT:
+            params[i].value.ui = args->params.params_val[i].value.remote_sched_param_value_u.ui; break;
+        case VIR_DOMAIN_SCHED_FIELD_LLONG:
+            params[i].value.l = args->params.params_val[i].value.remote_sched_param_value_u.l; break;
+        case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+            params[i].value.ul = args->params.params_val[i].value.remote_sched_param_value_u.ul; break;
+        case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+            params[i].value.d = args->params.params_val[i].value.remote_sched_param_value_u.d; break;
+        case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+            params[i].value.b = args->params.params_val[i].value.remote_sched_param_value_u.b; break;
+        }
+    }
+
+    dom = get_nonnull_domain (client->conn, args->dom);
+    if (dom == NULL) {
+        free (params);
+        remoteDispatchError (client, req, "domain not found");
+        return -2;
+    }
+
+    r = virDomainSetSchedulerParameters (dom, params, nparams);
+    free (params);
+    if (r == -1) return -1;
+
+    return 0;
+}
+
+static int
 remoteDispatchDomainAttachDevice (struct qemud_client *client,
                                   remote_message_header *req,
                                   remote_domain_attach_device_args *args,
Index: qemud/remote_protocol.x
===================================================================
RCS file: /data/cvs/libvirt/qemud/remote_protocol.x,v
retrieving revision 1.1
diff -u -p -r1.1 remote_protocol.x
--- qemud/remote_protocol.x	11 Jun 2007 11:36:17 -0000	1.1
+++ qemud/remote_protocol.x	22 Jun 2007 11:28:32 -0000
@@ -75,6 +75,9 @@ const REMOTE_CPUMAPS_MAX = 16384;
 /* Upper limit on lists of network names. */
 const REMOTE_NETWORK_NAME_LIST_MAX = 256;
 
+/* Upper limit on list of scheduler parameters. */
+const REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX = 16;
+
 /* UUID.  VIR_UUID_BUFLEN definition comes from libvirt.h */
 typedef opaque remote_uuid[VIR_UUID_BUFLEN];
 
@@ -125,6 +128,29 @@ struct remote_vcpu_info {
     int cpu;
 };
 
+/* Wire encoding of virDomainSchedParameter.
+ * Note the enum (type) which must remain binary compatible.
+ */
+union remote_sched_param_value switch (int type) {
+ case VIR_DOMAIN_SCHED_FIELD_INT:
+     int i;
+ case VIR_DOMAIN_SCHED_FIELD_UINT:
+     unsigned int ui;
+ case VIR_DOMAIN_SCHED_FIELD_LLONG:
+     hyper l;
+ case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+     unsigned hyper ul;
+ case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+     double d;
+ case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+     int b;
+};
+
+struct remote_sched_param {
+    remote_nonnull_string field;
+    remote_sched_param_value value;
+};
+
 /*----- Calls. -----*/
 
 /* For each call we may have a 'remote_CALL_args' and 'remote_CALL_ret'
@@ -178,6 +204,29 @@ struct remote_get_capabilities_ret {
     remote_nonnull_string capabilities;
 };
 
+struct remote_domain_get_scheduler_type_args {
+    remote_nonnull_domain dom;
+};
+
+struct remote_domain_get_scheduler_type_ret {
+    remote_nonnull_string type;
+    int nparams;
+};
+
+struct remote_domain_get_scheduler_parameters_args {
+    remote_nonnull_domain dom;
+    int nparams;
+};
+
+struct remote_domain_get_scheduler_parameters_ret {
+    remote_sched_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>;
+};
+
+struct remote_domain_set_scheduler_parameters_args {
+    remote_nonnull_domain dom;
+    remote_sched_param params<REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX>;
+};
+
 struct remote_list_domains_args {
     int maxids;
 };
@@ -553,7 +602,10 @@ enum remote_procedure {
     REMOTE_PROC_NUM_OF_NETWORKS = 52,
     REMOTE_PROC_DOMAIN_CORE_DUMP = 53,
     REMOTE_PROC_DOMAIN_RESTORE = 54,
-    REMOTE_PROC_DOMAIN_SAVE = 55
+    REMOTE_PROC_DOMAIN_SAVE = 55,
+    REMOTE_PROC_DOMAIN_GET_SCHEDULER_TYPE = 56,
+    REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS = 57,
+    REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS = 58
 };
 
 /* Custom RPC structure. */
Index: src/remote_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/remote_internal.c,v
retrieving revision 1.3
diff -u -p -r1.3 remote_internal.c
--- src/remote_internal.c	21 Jun 2007 15:49:09 -0000	1.3
+++ src/remote_internal.c	22 Jun 2007 11:28:34 -0000
@@ -1731,6 +1731,135 @@ remoteDomainSetAutostart (virDomainPtr d
     return 0;
 }
 
+static char *
+remoteDomainGetSchedulerType (virDomainPtr domain, int *nparams)
+{
+    remote_domain_get_scheduler_type_args args;
+    remote_domain_get_scheduler_type_ret ret;
+    GET_PRIVATE (domain->conn, NULL);
+
+    make_nonnull_domain (&args.dom, domain);
+
+    memset (&ret, 0, sizeof ret);
+    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SCHEDULER_TYPE,
+              (xdrproc_t) xdr_remote_domain_get_scheduler_type_args, (char *) &args,
+              (xdrproc_t) xdr_remote_domain_get_scheduler_type_ret, (char *) &ret) == -1)
+        return NULL;
+
+    if (nparams) *nparams = ret.nparams;
+
+    /* Caller frees this. */
+    return ret.type;
+}
+
+static int
+remoteDomainGetSchedulerParameters (virDomainPtr domain,
+                                    virSchedParameterPtr params, int *nparams)
+{
+    remote_domain_get_scheduler_parameters_args args;
+    remote_domain_get_scheduler_parameters_ret ret;
+    int i;
+    GET_PRIVATE (domain->conn, -1);
+
+    make_nonnull_domain (&args.dom, domain);
+    args.nparams = *nparams;
+
+    memset (&ret, 0, sizeof ret);
+    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_GET_SCHEDULER_PARAMETERS,
+              (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_args, (char *) &args,
+              (xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret) == -1)
+        return -1;
+
+    /* Check the length of the returned list carefully. */
+    if (ret.params.params_len > REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX ||
+        ret.params.params_len > *nparams) {
+        xdr_free ((xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret);
+        error (domain->conn, VIR_ERR_RPC, "remoteDomainGetSchedulerParameters: returned number of parameters exceeds limit");
+        return -1;
+    }
+    *nparams = ret.params.params_len;
+
+    /* Deserialise the result. */
+    for (i = 0; i < *nparams; ++i) {
+        strncpy (params[i].field, ret.params.params_val[i].field,
+                 VIR_DOMAIN_SCHED_FIELD_LENGTH);
+        params[i].field[VIR_DOMAIN_SCHED_FIELD_LENGTH-1] = '\0';
+        params[i].type = ret.params.params_val[i].value.type;
+        switch (params[i].type) {
+        case VIR_DOMAIN_SCHED_FIELD_INT:
+            params[i].value.i = ret.params.params_val[i].value.remote_sched_param_value_u.i; break;
+        case VIR_DOMAIN_SCHED_FIELD_UINT:
+            params[i].value.ui = ret.params.params_val[i].value.remote_sched_param_value_u.ui; break;
+        case VIR_DOMAIN_SCHED_FIELD_LLONG:
+            params[i].value.l = ret.params.params_val[i].value.remote_sched_param_value_u.l; break;
+        case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+            params[i].value.ul = ret.params.params_val[i].value.remote_sched_param_value_u.ul; break;
+        case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+            params[i].value.d = ret.params.params_val[i].value.remote_sched_param_value_u.d; break;
+        case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+            params[i].value.b = ret.params.params_val[i].value.remote_sched_param_value_u.b; break;
+        default:
+            xdr_free ((xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret);
+            error (domain->conn, VIR_ERR_RPC, "remoteDomainGetSchedulerParameters: unknown parameter type");
+            return -1;
+        }
+    }
+
+    xdr_free ((xdrproc_t) xdr_remote_domain_get_scheduler_parameters_ret, (char *) &ret);
+    return 0;
+}
+
+static int
+remoteDomainSetSchedulerParameters (virDomainPtr domain,
+                                    virSchedParameterPtr params, int nparams)
+{
+    remote_domain_set_scheduler_parameters_args args;
+    int i;
+    GET_PRIVATE (domain->conn, -1);
+
+    make_nonnull_domain (&args.dom, domain);
+
+    /* Serialise the scheduler parameters. */
+    args.params.params_len = nparams;
+    args.params.params_val = malloc (sizeof (struct remote_sched_param)
+                                     * nparams);
+    if (args.params.params_val == NULL) {
+        error (domain->conn, VIR_ERR_RPC, "out of memory allocating array");
+        return -1;
+    }
+
+    for (i = 0; i < nparams; ++i) {
+        // call() will free this:
+        args.params.params_val[i].field = strdup (params[i].field);
+        args.params.params_val[i].value.type = params[i].type;
+        switch (params[i].type) {
+        case VIR_DOMAIN_SCHED_FIELD_INT:
+            args.params.params_val[i].value.remote_sched_param_value_u.i = params[i].value.i; break;
+        case VIR_DOMAIN_SCHED_FIELD_UINT:
+            args.params.params_val[i].value.remote_sched_param_value_u.ui = params[i].value.ui; break;
+        case VIR_DOMAIN_SCHED_FIELD_LLONG:
+            args.params.params_val[i].value.remote_sched_param_value_u.l = params[i].value.l; break;
+        case VIR_DOMAIN_SCHED_FIELD_ULLONG:
+            args.params.params_val[i].value.remote_sched_param_value_u.ul = params[i].value.ul; break;
+        case VIR_DOMAIN_SCHED_FIELD_DOUBLE:
+            args.params.params_val[i].value.remote_sched_param_value_u.d = params[i].value.d; break;
+        case VIR_DOMAIN_SCHED_FIELD_BOOLEAN:
+            args.params.params_val[i].value.remote_sched_param_value_u.b = params[i].value.b; break;
+        default:
+            free (args.params.params_val);
+            error (domain->conn, VIR_ERR_RPC, "unknown parameter type");
+            return -1;
+        }
+    }
+
+    if (call (domain->conn, priv, 0, REMOTE_PROC_DOMAIN_SET_SCHEDULER_PARAMETERS,
+              (xdrproc_t) xdr_remote_domain_set_scheduler_parameters_args, (char *) &args,
+              (xdrproc_t) xdr_void, (char *) NULL) == -1)
+        return -1;
+
+    return 0;
+}
+
 /*----------------------------------------------------------------------*/
 
 static int
@@ -2499,6 +2628,9 @@ static virDriver driver = {
     .domainDetachDevice = remoteDomainDetachDevice,
     .domainGetAutostart = remoteDomainGetAutostart,
     .domainSetAutostart = remoteDomainSetAutostart,
+    .domainGetSchedulerType = remoteDomainGetSchedulerType,
+    .domainGetSchedulerParameters = remoteDomainGetSchedulerParameters,
+    .domainSetSchedulerParameters = remoteDomainSetSchedulerParameters,
 };
 
 static virNetworkDriver network_driver = {

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]