[PATCH 0 of 6] #2 Add scheduling parameter persistence

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248207 25200 # Node ID 3f95e5cf96d586b7315516421e7eac66ed0fef86 # Parent 3d2618df45908eecf363442d50e43297ebd77a62 Add persistent data location to configure.ac Changes: - Create the infostore directory on postinstall Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 3d2618df4590 -r 3f95e5cf96d5 Makefile.am --- a/Makefile.am Mon Jun 23 11:37:18 2008 -0700 +++ b/Makefile.am Mon Jun 23 12:10:07 2008 -0700 @@ -113,6 +113,7 @@ sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(REGS) -m $(MOFS) sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(INTEROP_REGS) -m $(INTEROP_MOFS) virsh -v | grep -q '^0.3' && cp examples/diskpool.conf $(DISK_POOL_CONFIG) || true + mkdir -p $(INFO_STORE) preuninstall: sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(REGS) -m $(MOFS) diff -r 3d2618df4590 -r 3f95e5cf96d5 acinclude.m4 --- a/acinclude.m4 Mon Jun 23 11:37:18 2008 -0700 +++ b/acinclude.m4 Mon Jun 23 12:10:07 2008 -0700 @@ -317,6 +317,17 @@ ] ) +# +# Define info store location. +# +AC_DEFUN([DEFINE_INFO_STORE], + [ + AC_DEFINE_UNQUOTED([INFO_STORE], "$1", [Info store location]) + INFO_STORE=$1 + AC_SUBST(INFO_STORE) + ] +) + AC_DEFUN([SET_CSET], [ if test -d .hg && test -x $(which hg); then diff -r 3d2618df4590 -r 3f95e5cf96d5 configure.ac --- a/configure.ac Mon Jun 23 11:37:18 2008 -0700 +++ b/configure.ac Mon Jun 23 12:10:07 2008 -0700 @@ -60,6 +60,13 @@ [DEFINE_DISK_CONFIG($with_diskconfig)], [DEFINE_DISK_CONFIG(/etc/libvirt/diskpool.conf)] ) + +AC_ARG_WITH([info_store], + [ --with-info-store=PATH Set information store location (default=/etc/libvirt/cim)], + [DEFINE_INFO_STORE($withval)], + [DEFINE_INFO_STORE(/etc/libvirt/cim)] +) + AC_ARG_WITH([maxmem], [ --with-maxmem=FOO Set max memory (KB) for a guest.], [DEFINE_MAXMEM($with_maxmem)],

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248231 25200 # Node ID cee13699488177020c8050cd9e4311d74d394b2c # Parent 3f95e5cf96d586b7315516421e7eac66ed0fef86 Add domain information store utilities This sets up a very simple XML file in /etc/libvirt/cim that can store some key=value attributes for a domain. The included test is a very simple example and exercise of the code, and should probably be improved a bit before moving on. Changes: - Fix inconsistent false return - Fix missing free of XML parsing context Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 3f95e5cf96d5 -r cee136994881 libxkutil/Makefile.am --- a/libxkutil/Makefile.am Mon Jun 23 12:10:07 2008 -0700 +++ b/libxkutil/Makefile.am Mon Jun 23 12:10:31 2008 -0700 @@ -4,14 +4,14 @@ CFLAGS += $(CFLAGS_STRICT) -noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h +noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h lib_LTLIBRARIES = libxkutil.la AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ - xmlgen.c + xmlgen.c infostore.c noinst_PROGRAMS = xml_parse_test diff -r 3f95e5cf96d5 -r cee136994881 libxkutil/infostore.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/infostore.c Mon Jun 23 12:10:31 2008 -0700 @@ -0,0 +1,374 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Dan Smith <danms@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <stdio.h> +#include <fcntl.h> +#include <unistd.h> +#include <inttypes.h> +#include <sys/file.h> + +#include <libvirt/libvirt.h> +#include <libxml/parser.h> +#include <libxml/tree.h> +#include <libxml/xpath.h> +#include <libxml/xmlsave.h> +#include <libxml/tree.h> + +#include <libcmpiutil/libcmpiutil.h> +#include <config.h> + +#include "infostore.h" + +struct infostore_ctx { + xmlDocPtr doc; + xmlNodePtr root; + xmlXPathContextPtr xpathctx; + int fd; +}; + +static void infostore_cleanup_ctx(struct infostore_ctx *ctx) +{ + xmlXPathFreeContext(ctx->xpathctx); + xmlFreeDoc(ctx->doc); + close(ctx->fd); + + free(ctx); +} + +static char *_make_filename(const char *type, const char *name) +{ + int ret; + char *path; + + ret = asprintf(&path, "%s/%s_%s", + INFO_STORE, + type, + name); + if (ret == -1) { + CU_DEBUG("Failed to asprintf() path to info store"); + path = NULL; + } + + return path; +} + +static char *make_filename(virDomainPtr dom) +{ + virConnectPtr conn; + char *path = NULL; + + conn = virDomainGetConnect(dom); + if (conn == NULL) { + CU_DEBUG("Domain has no libvirt connection"); + goto out; + } + + path = _make_filename(virConnectGetType(conn), + virDomainGetName(dom)); + + CU_DEBUG("Path is %s", path); + + out: + return path; +} + +static xmlDocPtr parse_xml(int fd) +{ + xmlParserCtxtPtr ctx = NULL; + xmlDocPtr doc = NULL; + + ctx = xmlNewParserCtxt(); + if (ctx == NULL) + goto err; + + doc = xmlCtxtReadFd(ctx, + fd, + "foo", + NULL, + XML_PARSE_NOWARNING | XML_PARSE_NONET); + if (doc == NULL) + goto err; + + xmlFreeParserCtxt(ctx); + + return doc; + err: + xmlFreeDoc(doc); + xmlFreeParserCtxt(ctx); + + return NULL; +} + +static xmlDocPtr new_xml(void) +{ + xmlDocPtr doc = NULL; + xmlNodePtr root = NULL; + + doc = xmlNewDoc(BAD_CAST "1.0"); + if (doc == NULL) { + CU_DEBUG("Failed to create new XML document"); + goto err; + } + + root = xmlNewNode(NULL, BAD_CAST "dominfo"); + if (root == NULL) { + CU_DEBUG("Failed top create new root node"); + goto err; + } + + xmlDocSetRootElement(doc, root); + + return doc; + err: + xmlFreeDoc(doc); + + return NULL; +} + +static bool save_xml(struct infostore_ctx *ctx) +{ + xmlSaveCtxtPtr save = NULL; + long size = 0; + + lseek(ctx->fd, 0, SEEK_SET); + + save = xmlSaveToFd(ctx->fd, NULL, 0); + if (save == NULL) { + CU_DEBUG("Failed to allocate save context"); + goto out; + } + + size = xmlSaveDoc(save, ctx->doc); + + xmlSaveClose(save); + + out: + return size >= 0; +} + +struct infostore_ctx *infostore_open(virDomainPtr dom) +{ + struct infostore_ctx *isc; + struct stat s; + char *filename = NULL; + + isc = calloc(1, sizeof(*isc)); + if (isc == NULL) { + CU_DEBUG("Unable to allocate domain_details struct"); + return NULL; + } + + filename = make_filename(dom); + if (filename == NULL) + goto err; + + isc->fd = open(filename, O_RDWR|O_CREAT, 0600); + if (isc->fd < 0) { + CU_DEBUG("Unable to open `%s': %m", filename); + goto err; + } + + if (flock(isc->fd, LOCK_EX) != 0) { + CU_DEBUG("Failed to lock infostore"); + goto err; + } + + fstat(isc->fd, &s); + if (s.st_size == 0) + isc->doc = new_xml(); + else + isc->doc = parse_xml(isc->fd); + + if (isc->doc == NULL) { + CU_DEBUG("Failed to parse XML"); + goto err; + } + + isc->root = xmlDocGetRootElement(isc->doc); + if (isc->root == NULL) { + CU_DEBUG("Failed to parse XML"); + goto err; + } + + if (!xmlStrEqual(isc->root->name, BAD_CAST "dominfo")) { + CU_DEBUG("XML does not start with <dominfo>"); + goto err; + } + + isc->xpathctx = xmlXPathNewContext(isc->doc); + if (isc->xpathctx == NULL) { + CU_DEBUG("Failed to allocate XPath context"); + goto err; + } + + free(filename); + + return isc; + + err: + infostore_cleanup_ctx(isc); + free(filename); + + return NULL; +} + +void infostore_close(struct infostore_ctx *ctx) +{ + if (ctx == NULL) + return; + + save_xml(ctx); + infostore_cleanup_ctx(ctx); +} + +void infostore_delete(const char *type, const char *name) +{ + char *path = NULL; + + path = _make_filename(type, name); + if (path == NULL) + return; + + unlink(path); + + free(path); +} + +static xmlXPathObjectPtr xpath_query(struct infostore_ctx *ctx, const char *key) +{ + char *path = NULL; + xmlXPathObjectPtr result = NULL; + + if (asprintf(&path, "/dominfo/%s[1]", key) == -1) { + CU_DEBUG("Failed to alloc path string"); + goto out; + } + + result = xmlXPathEval(BAD_CAST path, ctx->xpathctx); + if ((result->type != XPATH_NODESET) || + (xmlXPathNodeSetGetLength(result->nodesetval) < 1)) { + xmlXPathFreeObject(result); + result = NULL; + } + out: + free(path); + + return result; +} + +static char *xpath_query_string(struct infostore_ctx *ctx, const char *key) +{ + xmlXPathObjectPtr result; + char *val = NULL; + + result = xpath_query(ctx, key); + if (result != NULL) + val = (char *)xmlXPathCastToString(result); + + xmlXPathFreeObject(result); + + return val; +} + +static bool xpath_set_string(struct infostore_ctx *ctx, + const char *key, + const char *val) +{ + xmlXPathObjectPtr result = NULL; + xmlNodePtr node = NULL; + + result = xpath_query(ctx, key); + if (result == NULL) { + CU_DEBUG("Creating new node %s=%s", key, val); + node = xmlNewDocNode(ctx->doc, NULL, BAD_CAST key, NULL); + xmlAddChild(ctx->root, node); + } else { + node = result->nodesetval->nodeTab[0]; + } + + if (node == NULL) { + CU_DEBUG("Failed to update node for `%s'", key); + goto out; + } + + xmlNodeSetContent(node, BAD_CAST val); + out: + xmlXPathFreeObject(result); + + return node != NULL; +} + +uint64_t infostore_get_u64(struct infostore_ctx *ctx, const char *key) +{ + char *sval = NULL; + uint64_t val = 0; + + sval = xpath_query_string(ctx, key); + if (sval == NULL) + goto out; + + if (sscanf((const char *)sval, "%" SCNu64, &val) != 1) { + CU_DEBUG("Failed to parse u64 for %s (%s)", key, sval); + goto out; + } + out: + free(sval); + + return val; +} + +bool infostore_set_u64(struct infostore_ctx *ctx, const char *key, uint64_t val) +{ + char *sval = NULL; + + if (asprintf(&sval, "%" PRIu64, val) == -1) { + CU_DEBUG("Failed to format u64 string"); + sval = NULL; + goto out; + } + + xpath_set_string(ctx, key, sval); + out: + free(sval); + + return false; +} + +char *infostore_get_str(struct infostore_ctx *ctx, const char *key) +{ + return xpath_query_string(ctx, key); +} + +bool infostore_set_str(struct infostore_ctx *ctx, + const char *key, const char * val) +{ + return xpath_set_string(ctx, key, val); +} + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ diff -r 3f95e5cf96d5 -r cee136994881 libxkutil/infostore.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/infostore.h Mon Jun 23 12:10:31 2008 -0700 @@ -0,0 +1,54 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Dan Smith <danms@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef __INFOSTORE_H +#define __INFOSTORE_H + +#include <stdint.h> +#include <stdbool.h> +#include <libvirt/libvirt.h> + +struct infostore_ctx; + +struct infostore_ctx *infostore_open(virDomainPtr dom); +void infostore_close(struct infostore_ctx *ctx); +void infostore_delete(const char *type, const char *name); + +uint64_t infostore_get_u64(struct infostore_ctx *ctx, const char *key); +bool infostore_set_u64(struct infostore_ctx *ctx, + const char *key, uint64_t val); + +char *infostore_get_str(struct infostore_ctx *ctx, const char *key); +bool infostore_set_str(struct infostore_ctx *ctx, + const char *key, const char * val); + + +#endif + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ diff -r 3f95e5cf96d5 -r cee136994881 libxkutil/tests/Makefile.am --- a/libxkutil/tests/Makefile.am Mon Jun 23 12:10:07 2008 -0700 +++ b/libxkutil/tests/Makefile.am Mon Jun 23 12:10:31 2008 -0700 @@ -1,10 +1,10 @@ # Copyright IBM Corp. 2007 -TESTS = xml_tag.test xml_devices.test xmlgen.test xml_dominfo.test +TESTS = xml_tag.test xml_devices.test xmlgen.test xml_dominfo.test infostore.test CFLAGS += -g %.test: %.c - $(CC) -o $@ $^ $(CFLAGS) -lvirt `xml2-config --libs` + $(CC) -o $@ $^ $(CFLAGS) -lvirt `xml2-config --libs` -L../.libs -lxkutil clean-local: rm -f *.test diff -r 3f95e5cf96d5 -r cee136994881 libxkutil/tests/infostore.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/tests/infostore.c Mon Jun 23 12:10:31 2008 -0700 @@ -0,0 +1,80 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Dan Smith <danms@us.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include <stdio.h> +#include <inttypes.h> + +#include <libvirt/libvirt.h> + +#include "../infostore.h" + +int main(int argc, char **argv) +{ + struct infostore_ctx *ctx = NULL; + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + + if (argc != 2) { + printf("Usage: %s <domain>\n", argv[0]); + return 1; + } + + conn = virConnectOpen(NULL); + if (conn == NULL) { + printf("Unable to open connection\n"); + goto out; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + printf("Unable to lookup domain `%s'\n", argv[1]); + goto out; + } + + ctx = infostore_open(dom); + if (ctx == NULL) { + printf("Unable to open infostore for `%s'\n", argv[1]); + goto out; + } + + printf("Foo: %" PRIu64 "\n", infostore_get_u64(ctx, "foo")); + + infostore_set_u64(ctx, "foo", 321); + infostore_set_u64(ctx, "bar", 987); + printf("Should be (null): %s\n", infostore_get_str(ctx, "baz")); + + out: + infostore_close(ctx); + virDomainFree(dom); + virConnectClose(conn); + + return 0; +} + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

DS> +bool infostore_set_u64(struct infostore_ctx *ctx, const char *key, uint64_t val) DS> +{ DS> + char *sval = NULL; DS> + DS> + if (asprintf(&sval, "%" PRIu64, val) == -1) { DS> + CU_DEBUG("Failed to format u64 string"); DS> + sval = NULL; DS> + goto out; DS> + } DS> + DS> + xpath_set_string(ctx, key, sval); DS> + out: DS> + free(sval); DS> + DS> + return false; DS> +} Looks like I forgot to refresh the patch before sending it out. It's fixed locally, I promise :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
DS> +bool infostore_set_u64(struct infostore_ctx *ctx, const char *key, uint64_t val) DS> +{ DS> + char *sval = NULL; DS> + DS> + if (asprintf(&sval, "%" PRIu64, val) == -1) { DS> + CU_DEBUG("Failed to format u64 string"); DS> + sval = NULL; DS> + goto out; DS> + } DS> + DS> + xpath_set_string(ctx, key, sval); DS> + out: DS> + free(sval); DS> + DS> + return false; DS> +}
Looks like I forgot to refresh the patch before sending it out. It's fixed locally, I promise :)
Cool, then +1 for me. =) -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248235 25200 # Node ID f1e816b33b5e914523b064b19b27cb8fc61ebfcd # Parent cee13699488177020c8050cd9e4311d74d394b2c Make ProcRASD expose stored scheduler parameters When we're constructing a ProcRASD, open the infostore for the domain and read out the weight and limit attributes so they can be set in the RASD appropriately. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r cee136994881 -r f1e816b33b5e src/Virt_RASD.c --- a/src/Virt_RASD.c Mon Jun 23 12:10:31 2008 -0700 +++ b/src/Virt_RASD.c Mon Jun 23 12:10:35 2008 -0700 @@ -33,6 +33,7 @@ #include "misc_util.h" #include "cs_util.h" +#include "infostore.h" #include "Virt_RASD.h" #include "svpc_types.h" @@ -91,6 +92,54 @@ { /* FIXME: Remove this */ return NULL; +} + +static CMPIStatus set_proc_rasd_params(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char *domain, + CMPIInstance *inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + struct infostore_ctx *info; + uint32_t weight; + uint64_t limit; + + conn = connect_by_classname(broker, CLASSNAME(ref), &s); + if (conn == NULL) + return s; + + dom = virDomainLookupByName(conn, domain); + if (dom == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "Domain `%s' not found while getting info", domain); + goto out; + } + + info = infostore_open(dom); + if (info == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to open domain information store"); + goto out; + } + + weight = (uint32_t)infostore_get_u64(info, "weight"); + limit = infostore_get_u64(info, "limit"); + + CMSetProperty(inst, "Weight", + (CMPIValue *)&weight, CMPI_uint32); + CMSetProperty(inst, "Limit", + (CMPIValue *)&limit, CMPI_uint64); + + out: + virDomainFree(dom); + virConnectClose(conn); + infostore_close(info); + + return s; } static CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, @@ -174,6 +223,7 @@ } else if (dev->type == CIM_RES_TYPE_PROC) { CMSetProperty(inst, "VirtualQuantity", (CMPIValue *)&dev->dev.vcpu.quantity, CMPI_uint64); + set_proc_rasd_params(broker, ref, host, inst); } /* FIXME: Put the HostResource in place */

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248235 25200 # Node ID f9ee6cb959cf8c5c63b61219763d0d9f3c494f26 # Parent f1e816b33b5e914523b064b19b27cb8fc61ebfcd Add scheduling information to device_parsing structures Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r f1e816b33b5e -r f9ee6cb959cf libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Mon Jun 23 12:10:35 2008 -0700 +++ b/libxkutil/device_parsing.h Mon Jun 23 12:10:35 2008 -0700 @@ -51,6 +51,8 @@ struct vcpu_device { uint64_t quantity; + uint32_t weight; + uint64_t limit; }; struct emu_device {

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248235 25200 # Node ID 54d2e0f7e87e78a8a9e85765f0795300ec7190ce # Parent f9ee6cb959cf8c5c63b61219763d0d9f3c494f26 Make VSMS record scheduler parameters when changed This includes a new function to synchronize information to the infostore for use during a ModifyResource() or DefineSystem() call. Also, delete the infostore for a domain on DestroySystem() Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r f9ee6cb959cf -r 54d2e0f7e87e src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Jun 23 12:10:35 2008 -0700 +++ b/src/Virt_VirtualSystemManagementService.c Mon Jun 23 12:10:35 2008 -0700 @@ -42,6 +42,7 @@ #include <libcmpiutil/std_instance.h> #include "misc_util.h" +#include "infostore.h" #include "Virt_VirtualSystemManagementService.h" #include "Virt_ComputerSystem.h" @@ -471,6 +472,8 @@ struct virt_device *dev) { cu_get_u64_prop(inst, "VirtualQuantity", &dev->dev.vcpu.quantity); + cu_get_u64_prop(inst, "Limit", &dev->dev.vcpu.limit); + cu_get_u32_prop(inst, "Weight", &dev->dev.vcpu.weight); return NULL; } @@ -650,6 +653,54 @@ return inst; } +static CMPIStatus update_dominfo(const struct domain *dominfo, + const char *refcn) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct infostore_ctx *ctx = NULL; + struct virt_device *dev = dominfo->dev_vcpu; + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + + if (dominfo->dev_vcpu_ct != 1) { + /* Right now, we only have extra info for processors */ + CU_DEBUG("Domain has no vcpu devices!"); + return s; + } + + conn = connect_by_classname(_BROKER, refcn, &s); + if (conn == NULL) { + CU_DEBUG("Failed to connnect by %s", refcn); + return s; + } + + dom = virDomainLookupByName(conn, dominfo->name); + if (dom == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "Unable to lookup domain `%s'", dominfo->name); + goto out; + } + + ctx = infostore_open(dom); + if (ctx == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to open infostore"); + goto out; + } + + infostore_set_u64(ctx, "weight", dev->dev.vcpu.weight); + infostore_set_u64(ctx, "limit", dev->dev.vcpu.limit); + out: + infostore_close(ctx); + + virDomainFree(dom); + virConnectClose(conn); + + return s; +} + static CMPIInstance *create_system(CMPIInstance *vssd, CMPIArray *resources, const CMPIObjectPath *ref, @@ -690,6 +741,8 @@ CU_DEBUG("System XML:\n%s", xml); inst = connect_and_create(xml, ref, s); + if (inst != NULL) + update_dominfo(domain, CLASSNAME(ref)); out: cleanup_dominfo(&domain); @@ -780,6 +833,8 @@ rc = IM_RC_SYS_NOT_FOUND; goto error; } + + infostore_delete(virConnectGetType(conn), dom_name); virDomainDestroy(dom); /* Okay for this to fail */ if (virDomainUndefine(dom) == 0) { @@ -961,6 +1016,8 @@ "Virtual System `%s' not found", dominfo->name); goto out; } + + update_dominfo(dominfo, refcn); if (!domain_online(dom)) { CU_DEBUG("VS `%s' not online; skipping dynamic update",

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1214248235 25200 # Node ID d2ad8dd8ccbdf66c416deb765d8b738e15dabc2e # Parent 54d2e0f7e87e78a8a9e85765f0795300ec7190ce Make ComputerSystem::RequestStateChange() set scheduling parameters at start Currently, only do this for Xen domains. Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r 54d2e0f7e87e -r d2ad8dd8ccbd src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Mon Jun 23 12:10:35 2008 -0700 +++ b/src/Virt_ComputerSystem.c Mon Jun 23 12:10:35 2008 -0700 @@ -35,6 +35,7 @@ #include "cs_util.h" #include <libcmpiutil/libcmpiutil.h> #include "misc_util.h" +#include "infostore.h" #include "device_parsing.h" #include <libcmpiutil/std_invokemethod.h> #include <libcmpiutil/std_instance.h> @@ -620,6 +621,40 @@ DEFAULT_EQ(); DEFAULT_INST_CLEANUP(); +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 }, + }; + + 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; + } + + ctx = infostore_open(dom); + if (ctx == NULL) { + CU_DEBUG("Unable to open infostore for domain"); + return; + } + + params[0].value.ui = infostore_get_u64(ctx, "weight"); + params[1].value.ui = infostore_get_u64(ctx, "limit"); + + virDomainSetSchedulerParameters(dom, params, 2); + + infostore_close(ctx); +} + /* This composite operation may be supported as a flag to reboot */ static int domain_reset(virDomainPtr dom) { @@ -643,6 +678,7 @@ case VIR_DOMAIN_SHUTOFF: CU_DEBUG("Start domain"); ret = virDomainCreate(dom); + set_scheduler_params(dom); break; case VIR_DOMAIN_PAUSED: CU_DEBUG("Unpause domain");
participants (2)
-
Dan Smith
-
Kaitlin Rupert