From danms at us.ibm.com Wed Jan 2 15:01:08 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 02 Jan 2008 07:01:08 -0800 Subject: [Libvirt-cim] [PATCH] HRP accepts invalid references In-Reply-To: (Kaitlin Rupert's message of "Fri, 28 Dec 2007 14:28:53 -0800") References: Message-ID: <87hchwe0gb.fsf@theine.beaverton.ibm.com> KR> Add a get_host_cs() call to pool_to_sys() handler. The KR> get_host_cs() call will verify whether the reference passed in is KR> valid. Should this be "get_pool_inst()"? KR> Failing query: KR> wbemcli gi 'http://localhost/root/virt:Xen_MemoryPool.InstanceID="wrong"' Is "pool_to_sys()" really being run on a GetInstance call? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Wed Jan 2 15:11:50 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 02 Jan 2008 07:11:50 -0800 Subject: [Libvirt-cim] [PATCH] HRP accepts invalid references In-Reply-To: <87hchwe0gb.fsf@theine.beaverton.ibm.com> References: <87hchwe0gb.fsf@theine.beaverton.ibm.com> Message-ID: <477BA9B6.2060907@linux.vnet.ibm.com> Dan Smith wrote: > KR> Add a get_host_cs() call to pool_to_sys() handler. The > KR> get_host_cs() call will verify whether the reference passed in is > KR> valid. > > Should this be "get_pool_inst()"? > > KR> Failing query: > KR> wbemcli gi 'http://localhost/root/virt:Xen_MemoryPool.InstanceID="wrong"' > > Is "pool_to_sys()" really being run on a GetInstance call? > Wow - that was a spectacularly poor message on my part. I guess the end of the year holiday got the better of me. =) Is the patch alright otherwise? I can resend with an accurate message. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Wed Jan 2 17:18:31 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 02 Jan 2008 09:18:31 -0800 Subject: [Libvirt-cim] [PATCH] .#2 HRP accepts invalid references Message-ID: # HG changeset patch # User Kaitlin Rupert # Date 1199294302 28800 # Node ID b58d2ec7a275dce6fab21e1ae7f414b6159ce141 # Parent 3ea63b2076c1d02b7c3c48910809b9fb11ee290f .#2 HRP accepts invalid references. Updates: Fixed errors in commit message. Previous message didn't make any sense. Add a get_pool_inst() call to pool_to_sys() handler. The get_pool_inst() call will verify whether the reference passed in is valid. This patch is dependant on the "#2 EAFP and RAFP support invalid references" patchset. Failing query: wbemcli ain -ac Xen_HostedResourcePool http://localhost/root/virt:Xen_MemoryPool.InstanceID="wrong" Signed-off-by: Kaitlin Rupert diff -r 3ea63b2076c1 -r b58d2ec7a275 src/Virt_HostedResourcePool.c --- a/src/Virt_HostedResourcePool.c Fri Dec 21 10:58:37 2007 -0800 +++ b/src/Virt_HostedResourcePool.c Wed Jan 02 09:18:22 2008 -0800 @@ -43,8 +43,13 @@ static CMPIStatus pool_to_sys(const CMPI { CMPIInstance *host; CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = get_pool_inst(_BROKER, ref, &inst); + if ((s.rc != CMPI_RC_OK) || (inst == NULL)) return s; s = get_host_cs(_BROKER, ref, &host); From danms at us.ibm.com Wed Jan 2 17:18:59 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 02 Jan 2008 10:18:59 -0700 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API Message-ID: <7d60f44ffb2d1e4efccd.1199297939@theine> # HG changeset patch # User Dan Smith # Date 1199297921 28800 # Node ID 7d60f44ffb2d1e4efccd1b46bd184d2ca57063c0 # Parent 84b72fff34f65ad578d70fcc67b141510e34e24e Make NetworkPool use libvirt's virtual network API This means that you no longer see a NetworkPool for each bridge on the system, but rather one per configured virtual network in libvirt. The id is NetworkPool/NetName, and the Caption property of the instance includes the bridge name for reference. This change removes the need for the contents of hostres.{c,h}, so it is removed here. That makes the net change -85 lines of pure goodness. Signed-off-by: Dan Smith diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/Makefile.am --- a/libxkutil/Makefile.am Wed Jan 02 09:18:22 2008 -0800 +++ b/libxkutil/Makefile.am Wed Jan 02 10:18:41 2008 -0800 @@ -4,11 +4,11 @@ SUBDIRS = tests CFLAGS += $(CFLAGS_STRICT) -noinst_HEADERS = cs_util.h misc_util.h device_parsing.h hostres.h xmlgen.h +noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h lib_LTLIBRARIES = libxkutil.la AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ - xmlgen.c hostres.c + xmlgen.c diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/hostres.c --- a/libxkutil/hostres.c Wed Jan 02 09:18:22 2008 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright IBM Corp. 2007 - * - * Authors: - * Dan Smith - * - * 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 -#include -#include -#include - -#include -#include -#include - -#include "hostres.h" - -bool is_bridge(const char *name) -{ - char *path = NULL; - int ret; - struct stat s; - - ret = asprintf(&path, "/sys/class/net/%s/bridge", name); - if (ret == -1) - return false; - - if (stat(path, &s) != 0) - return false; - - if (S_ISDIR(s.st_mode)) - return true; - else - return false; -} - -char **list_bridges(void) -{ - char **list = NULL; - DIR *dir = NULL; - struct dirent *de; - int count = 0; - - dir = opendir("/sys/class/net"); - if (dir == NULL) - return NULL; - - while ((de = readdir(dir))) { - if (is_bridge(de->d_name)) { - list = realloc(list, ++count); - list[count-1] = strdup(de->d_name); - } - } - - /* Leave a NULL at the end, no matter what */ - list = realloc(list, count + 1); - list[count] = NULL; - - return list; -} - -/* - * Local Variables: - * mode: C - * c-set-style: "K&R" - * tab-width: 8 - * c-basic-offset: 8 - * indent-tabs-mode: nil - * End: - */ diff -r 84b72fff34f6 -r 7d60f44ffb2d libxkutil/hostres.h --- a/libxkutil/hostres.h Wed Jan 02 09:18:22 2008 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright IBM Corp. 2007 - * - * Authors: - * Dan Smith - * - * 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 __HOSTRES_H -#define __HOSTRES_H - -#include - -bool is_bridge(const char *name); - -/* Return a NULL-terminated array of bridge names on the system. - Result must be free()d, as well as each of the array members */ -char **list_bridges(void); - -#endif diff -r 84b72fff34f6 -r 7d60f44ffb2d src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Wed Jan 02 09:18:22 2008 -0800 +++ b/src/Virt_DevicePool.c Wed Jan 02 10:18:41 2008 -0800 @@ -35,7 +35,6 @@ #include "config.h" #include "misc_util.h" -#include "hostres.h" #include "device_parsing.h" #include @@ -416,31 +415,53 @@ static CMPIStatus procpool_instance(virC return s; } -static CMPIStatus _netpool_for_bridge(struct inst_list *list, - const char *ns, - const char *bridge, - const char *refcn, - const CMPIBroker *broker) -{ - char *id = NULL; +static CMPIStatus _netpool_for_network(struct inst_list *list, + const char *ns, + virConnectPtr conn, + const char *netname, + const char *refcn, + const CMPIBroker *broker) +{ + char *str = NULL; + char *bridge = NULL; uint16_t type = CIM_RASD_TYPE_NET; CMPIInstance *inst; + virNetworkPtr network = NULL; + + network = virNetworkLookupByName(conn, netname); + if (network == NULL) { + CMPIStatus s; + + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No such NetworkPool: %s", netname); + return s; + } inst = get_typed_instance(broker, refcn, "NetworkPool", ns); - if (asprintf(&id, "NetworkPool/%s", bridge) == -1) + if (asprintf(&str, "NetworkPool/%s", netname) == -1) return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; CMSetProperty(inst, "InstanceID", - (CMPIValue *)id, CMPI_chars); + (CMPIValue *)str, CMPI_chars); + free(str); + + bridge = virNetworkGetBridgeName(network); + if (asprintf(&str, "Bridge: %s", bridge) == -1) + return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; + + CMSetProperty(inst, "Caption", + (CMPIValue *)str, CMPI_chars); + free(str); + free(bridge); CMSetProperty(inst, "ResourceType", (CMPIValue *)&type, CMPI_uint16); - free(id); inst_list_add(list, inst); @@ -454,39 +475,49 @@ static CMPIStatus netpool_instance(virCo const CMPIBroker *broker) { CMPIStatus s = {CMPI_RC_OK, NULL}; - char **bridges; + char **netnames = NULL; int i; + int nets; if (id != NULL) { - if (!is_bridge(id)) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "No such network pool `%s'", id); - goto out; - } - return _netpool_for_bridge(list, - ns, - id, - pfx_from_conn(conn), - broker); - } - - bridges = list_bridges(); - if (bridges == NULL) - return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; - - for (i = 0; bridges[i]; i++) { - _netpool_for_bridge(list, - ns, - bridges[i], - pfx_from_conn(conn), - broker); - free(bridges[i]); - } - - free(bridges); - - out: + return _netpool_for_network(list, + ns, + conn, + id, + pfx_from_conn(conn), + broker); + } + + nets = virConnectNumOfNetworks(conn); + if (nets < 0) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to list networks"); + goto out; + } + + netnames = calloc(nets, sizeof(*netnames)); + if (netnames == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to allocate memory for %i net names", nets); + goto out; + } + + nets = virConnectListNetworks(conn, netnames, nets); + + for (i = 0; i < nets; i++) { + _netpool_for_network(list, + ns, + conn, + netnames[i], + pfx_from_conn(conn), + broker); + } + + out: + free(netnames); + return s; } From kaitlin at linux.vnet.ibm.com Thu Jan 3 03:41:48 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 02 Jan 2008 19:41:48 -0800 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API In-Reply-To: <7d60f44ffb2d1e4efccd.1199297939@theine> References: <7d60f44ffb2d1e4efccd.1199297939@theine> Message-ID: <477C597C.3070300@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199297921 28800 > # Node ID 7d60f44ffb2d1e4efccd1b46bd184d2ca57063c0 > # Parent 84b72fff34f65ad578d70fcc67b141510e34e24e > Make NetworkPool use libvirt's virtual network API > > This means that you no longer see a NetworkPool for each bridge on the > system, but rather one per configured virtual network in libvirt. The > id is NetworkPool/NetName, and the Caption property of the instance > includes the bridge name for reference. > > This change removes the need for the contents of hostres.{c,h}, so it is > removed here. That makes the net change -85 lines of pure goodness. > This patch tested out fine and looks good. One thing though, it causes EAFP and RAFP queries with a NetworkPort ref to fail. This is because netpool_member_of(), which eventually gets called by pool_member_of(), uses the bridge name to construct the InstanceID. Since the net_device struct doesn't have a virtual network element, I'm guessing this needs to be a separate patch. Failing query: wbemcli ain -ac Xen_ElementAllocatedFromPool 'http://localhost:5988/root/virt:Xen_NetworkPool.InstanceID="NetworkPool/default"' -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From grendel at linux.vnet.ibm.com Thu Jan 3 14:48:26 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 03 Jan 2008 09:48:26 -0500 Subject: [Libvirt-cim] [PATCH 2 of 5] GetInstance() in DevicePool returns an instance for invalid refs In-Reply-To: <40de750e13d37994bee0.1198263621@elm3b41.beaverton.ibm.com> References: <40de750e13d37994bee0.1198263621@elm3b41.beaverton.ibm.com> Message-ID: <477CF5BA.6040809@linux.vnet.ibm.com> Kaitlin Rupert wrote: > # HG changeset patch > # User Kaitlin Rupert > # Date 1198261308 28800 > # Node ID 40de750e13d37994bee0f7031e82f612d02ebe4d > # Parent 97c1cab36073319f7cf78cbec70eec9eaee01a4d > GetInstance() in DevicePool returns an instance for invalid refs. > > If a ref with a correct InstanceID but non-matching classname is passed, GetInstance() returns an instance that matches the InstanceID. This should return an error. > > Add cu_compare_ref() after retrieving the instance to make sure ref is valid. > > Failing query: > wbemcli gi 'http://localhost:5988/root/virt:Xen_ProcessorPool.InstanceID="MemoryPool/0"' > > Signed-off-by: Kaitlin Rupert > > > inst = get_pool_by_id(_BROKER, conn, id, NAMESPACE(reference)); > if (inst) { > + prop = cu_compare_ref(reference, inst); > + if (prop != NULL) { > + cu_statusf(broker, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "No such ResourcePool instance (%s)", prop); > + } > Just want to make sure I understand something correctly. You don't need to free prop here because cu_compare_ref gets it using CMGetCharPtr, right? That memory is managed by the CIMOM for you? -- -Jay From grendel at linux.vnet.ibm.com Thu Jan 3 15:09:16 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 03 Jan 2008 10:09:16 -0500 Subject: [Libvirt-cim] [PATCH 0 of 5] #2 EAFP and RAFP support invalid references. In-Reply-To: <476C10CD.8050908@linux.vnet.ibm.com> References: <476C10CD.8050908@linux.vnet.ibm.com> Message-ID: <477CFA9C.7060603@linux.vnet.ibm.com> Looks like a good set to me. The one patch is a little bit incongruous, but the total volume is quite manageable so it's not really an issue. Also, having a patch that may or may not fit into a set is far less of a concern to me than having changes that may or may not belong in a patch. Each individual patch is clear and consistent, so don't worry. Also, the (inst == NULL) check is a good catch. I wouldn't be surprised if we need that in a few more spots, especially since we've been a bit inconsistent when it comes to the "Is a NULL instance an error or just a NULL instance?" question. -- -Jay From danms at us.ibm.com Thu Jan 3 15:22:42 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 03 Jan 2008 07:22:42 -0800 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API In-Reply-To: <477C597C.3070300@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Wed, 02 Jan 2008 19:41:48 -0800") References: <7d60f44ffb2d1e4efccd.1199297939@theine> <477C597C.3070300@linux.vnet.ibm.com> Message-ID: <87wsqr6iil.fsf@theine.beaverton.ibm.com> KR> This patch tested out fine and looks good. One thing though, it KR> causes EAFP and RAFP queries with a NetworkPort ref to fail. This KR> is because netpool_member_of(), which eventually gets called by KR> pool_member_of(), uses the bridge name to construct the KR> InstanceID. Ah, right. I had looked over that stuff before I started making changes and convinced myself that it would all work in the end, but never tried it. I'll fix it up. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Thu Jan 3 15:26:12 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 07:26:12 -0800 Subject: [Libvirt-cim] [PATCH 2 of 5] GetInstance() in DevicePool returns an instance for invalid refs In-Reply-To: <477CF5BA.6040809@linux.vnet.ibm.com> References: <40de750e13d37994bee0.1198263621@elm3b41.beaverton.ibm.com> <477CF5BA.6040809@linux.vnet.ibm.com> Message-ID: <477CFE94.6090904@linux.vnet.ibm.com> Jay Gagnon wrote: > Kaitlin Rupert wrote: >> # HG changeset patch >> # User Kaitlin Rupert >> # Date 1198261308 28800 >> # Node ID 40de750e13d37994bee0f7031e82f612d02ebe4d >> # Parent 97c1cab36073319f7cf78cbec70eec9eaee01a4d >> GetInstance() in DevicePool returns an instance for invalid refs. >> >> If a ref with a correct InstanceID but non-matching classname is passed, GetInstance() returns an instance that matches the InstanceID. This should return an error. >> >> Add cu_compare_ref() after retrieving the instance to make sure ref is valid. >> >> Failing query: >> wbemcli gi 'http://localhost:5988/root/virt:Xen_ProcessorPool.InstanceID="MemoryPool/0"' >> >> Signed-off-by: Kaitlin Rupert >> >> >> inst = get_pool_by_id(_BROKER, conn, id, NAMESPACE(reference)); >> if (inst) { >> + prop = cu_compare_ref(reference, inst); >> + if (prop != NULL) { >> + cu_statusf(broker, &s, >> + CMPI_RC_ERR_NOT_FOUND, >> + "No such ResourcePool instance (%s)", prop); >> + } >> > Just want to make sure I understand something correctly. You don't need > to free prop here because cu_compare_ref gets it using CMGetCharPtr, > right? That memory is managed by the CIMOM for you? > Yes, that's correct. It's the same reason why you don't need to free an instance that's been created using CMNewInstance() (etc). -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Thu Jan 3 15:28:18 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 07:28:18 -0800 Subject: [Libvirt-cim] [PATCH 0 of 5] #2 EAFP and RAFP support invalid references. In-Reply-To: <477CFA9C.7060603@linux.vnet.ibm.com> References: <476C10CD.8050908@linux.vnet.ibm.com> <477CFA9C.7060603@linux.vnet.ibm.com> Message-ID: <477CFF12.5050200@linux.vnet.ibm.com> Jay Gagnon wrote: > Looks like a good set to me. The one patch is a little bit incongruous, > but the total volume is quite manageable so it's not really an issue. > Also, having a patch that may or may not fit into a set is far less of a > concern to me than having changes that may or may not belong in a > patch. Each individual patch is clear and consistent, so don't worry. Sounds good to me. Thanks =) -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Thu Jan 3 15:25:23 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 03 Jan 2008 08:25:23 -0700 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API Message-ID: <3a838dfd165b5f721687.1199377523@theine> # HG changeset patch # User Dan Smith # Date 1199377368 28800 # Node ID 3a838dfd165b5f721687a2bb0b2e03bb0c8192b7 # Parent 84b72fff34f65ad578d70fcc67b141510e34e24e Make NetworkPool use libvirt's virtual network API This means that you no longer see a NetworkPool for each bridge on the system, but rather one per configured virtual network in libvirt. The id is NetworkPool/NetName, and the Caption property of the instance includes the bridge name for reference. This change removes the need for the contents of hostres.{c,h}, so it is removed here. That makes the net change -85 lines of pure goodness. Changes since last version: - Fixed netpool_member_of() to do extra level of bridge->network mapping Signed-off-by: Dan Smith diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/Makefile.am --- a/libxkutil/Makefile.am Wed Jan 02 09:18:22 2008 -0800 +++ b/libxkutil/Makefile.am Thu Jan 03 08:22:48 2008 -0800 @@ -4,11 +4,11 @@ SUBDIRS = tests CFLAGS += $(CFLAGS_STRICT) -noinst_HEADERS = cs_util.h misc_util.h device_parsing.h hostres.h xmlgen.h +noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h lib_LTLIBRARIES = libxkutil.la AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ - xmlgen.c hostres.c + xmlgen.c diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/hostres.c --- a/libxkutil/hostres.c Wed Jan 02 09:18:22 2008 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,84 +0,0 @@ -/* - * Copyright IBM Corp. 2007 - * - * Authors: - * Dan Smith - * - * 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 -#include -#include -#include - -#include -#include -#include - -#include "hostres.h" - -bool is_bridge(const char *name) -{ - char *path = NULL; - int ret; - struct stat s; - - ret = asprintf(&path, "/sys/class/net/%s/bridge", name); - if (ret == -1) - return false; - - if (stat(path, &s) != 0) - return false; - - if (S_ISDIR(s.st_mode)) - return true; - else - return false; -} - -char **list_bridges(void) -{ - char **list = NULL; - DIR *dir = NULL; - struct dirent *de; - int count = 0; - - dir = opendir("/sys/class/net"); - if (dir == NULL) - return NULL; - - while ((de = readdir(dir))) { - if (is_bridge(de->d_name)) { - list = realloc(list, ++count); - list[count-1] = strdup(de->d_name); - } - } - - /* Leave a NULL at the end, no matter what */ - list = realloc(list, count + 1); - list[count] = NULL; - - return list; -} - -/* - * Local Variables: - * mode: C - * c-set-style: "K&R" - * tab-width: 8 - * c-basic-offset: 8 - * indent-tabs-mode: nil - * End: - */ diff -r 84b72fff34f6 -r 3a838dfd165b libxkutil/hostres.h --- a/libxkutil/hostres.h Wed Jan 02 09:18:22 2008 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -/* - * Copyright IBM Corp. 2007 - * - * Authors: - * Dan Smith - * - * 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 __HOSTRES_H -#define __HOSTRES_H - -#include - -bool is_bridge(const char *name); - -/* Return a NULL-terminated array of bridge names on the system. - Result must be free()d, as well as each of the array members */ -char **list_bridges(void); - -#endif diff -r 84b72fff34f6 -r 3a838dfd165b src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Wed Jan 02 09:18:22 2008 -0800 +++ b/src/Virt_DevicePool.c Thu Jan 03 08:22:48 2008 -0800 @@ -35,7 +35,6 @@ #include "config.h" #include "misc_util.h" -#include "hostres.h" #include "device_parsing.h" #include @@ -196,6 +195,74 @@ static char *diskpool_member_of(const CM return pool; } +static virNetworkPtr bridge_to_network(virConnectPtr conn, + const char *bridge) +{ + char **networks = NULL; + virNetworkPtr network = NULL; + int num; + int i; + + num = virConnectNumOfNetworks(conn); + if (num < 0) + return NULL; + + networks = calloc(num, sizeof(*networks)); + if (networks == NULL) + return NULL; + + num = virConnectListNetworks(conn, networks, num); + + for (i = 0; i < num; i++) { + char *_bridge; + + network = virNetworkLookupByName(conn, networks[i]); + if (network == NULL) + continue; + + _bridge = virNetworkGetBridgeName(network); + CU_DEBUG("Network `%s' has bridge `%s'", networks[i], _bridge); + if (STREQ(bridge, _bridge)) { + i = num; + } else { + virNetworkFree(network); + network = NULL; + } + + free(_bridge); + } + + free(networks); + + return network; +} + +static char *_netpool_member_of(virConnectPtr conn, + const char *bridge) +{ + virNetworkPtr net = NULL; + const char *netname; + char *pool = NULL; + + net = bridge_to_network(conn, bridge); + if (net == NULL) + goto out; + + netname = virNetworkGetName(net); + if (netname == NULL) + goto out; + + if (asprintf(&pool, "NetworkPool/%s", netname) == -1) + pool = NULL; + + CU_DEBUG("Determined pool: %s (%s, %s)", pool, bridge, netname); + + out: + virNetworkFree(net); + + return pool; +} + static char *netpool_member_of(const CMPIBroker *broker, const char *rasd_id, const char *refcn) @@ -227,11 +294,8 @@ static char *netpool_member_of(const CMP for (i = 0; i < count; i++) { if (STREQ((devs[i].id), dev)) { - ret = asprintf(&result, - "NetworkPool/%s", - devs[i].dev.net.bridge); - if (ret == -1) - result = NULL; + result = _netpool_member_of(conn, + devs[i].dev.net.bridge); break; } } @@ -416,31 +480,54 @@ static CMPIStatus procpool_instance(virC return s; } -static CMPIStatus _netpool_for_bridge(struct inst_list *list, - const char *ns, - const char *bridge, - const char *refcn, - const CMPIBroker *broker) -{ - char *id = NULL; +static CMPIStatus _netpool_for_network(struct inst_list *list, + const char *ns, + virConnectPtr conn, + const char *netname, + const char *refcn, + const CMPIBroker *broker) +{ + char *str = NULL; + char *bridge = NULL; uint16_t type = CIM_RASD_TYPE_NET; CMPIInstance *inst; + virNetworkPtr network = NULL; + + CU_DEBUG("Looking up network `%s'", netname); + network = virNetworkLookupByName(conn, netname); + if (network == NULL) { + CMPIStatus s; + + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No such NetworkPool: %s", netname); + return s; + } inst = get_typed_instance(broker, refcn, "NetworkPool", ns); - if (asprintf(&id, "NetworkPool/%s", bridge) == -1) + if (asprintf(&str, "NetworkPool/%s", netname) == -1) return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; CMSetProperty(inst, "InstanceID", - (CMPIValue *)id, CMPI_chars); + (CMPIValue *)str, CMPI_chars); + free(str); + + bridge = virNetworkGetBridgeName(network); + if (asprintf(&str, "Bridge: %s", bridge) == -1) + return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; + + CMSetProperty(inst, "Caption", + (CMPIValue *)str, CMPI_chars); + free(str); + free(bridge); CMSetProperty(inst, "ResourceType", (CMPIValue *)&type, CMPI_uint16); - free(id); inst_list_add(list, inst); @@ -454,39 +541,49 @@ static CMPIStatus netpool_instance(virCo const CMPIBroker *broker) { CMPIStatus s = {CMPI_RC_OK, NULL}; - char **bridges; + char **netnames = NULL; int i; + int nets; if (id != NULL) { - if (!is_bridge(id)) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "No such network pool `%s'", id); - goto out; - } - return _netpool_for_bridge(list, - ns, - id, - pfx_from_conn(conn), - broker); - } - - bridges = list_bridges(); - if (bridges == NULL) - return (CMPIStatus){CMPI_RC_ERR_FAILED, NULL}; - - for (i = 0; bridges[i]; i++) { - _netpool_for_bridge(list, - ns, - bridges[i], - pfx_from_conn(conn), - broker); - free(bridges[i]); - } - - free(bridges); - - out: + return _netpool_for_network(list, + ns, + conn, + id, + pfx_from_conn(conn), + broker); + } + + nets = virConnectNumOfNetworks(conn); + if (nets < 0) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to list networks"); + goto out; + } + + netnames = calloc(nets, sizeof(*netnames)); + if (netnames == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to allocate memory for %i net names", nets); + goto out; + } + + nets = virConnectListNetworks(conn, netnames, nets); + + for (i = 0; i < nets; i++) { + _netpool_for_network(list, + ns, + conn, + netnames[i], + pfx_from_conn(conn), + broker); + } + + out: + free(netnames); + return s; } From kaitlin at linux.vnet.ibm.com Thu Jan 3 20:47:26 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 12:47:26 -0800 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API In-Reply-To: <3a838dfd165b5f721687.1199377523@theine> References: <3a838dfd165b5f721687.1199377523@theine> Message-ID: <477D49DE.2070707@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199377368 28800 > # Node ID 3a838dfd165b5f721687a2bb0b2e03bb0c8192b7 > # Parent 84b72fff34f65ad578d70fcc67b141510e34e24e > Make NetworkPool use libvirt's virtual network API > I ran into one issue testing, but it seems like it might be a libvirt issue. I was testing with a defined guest and saw the following debug output: No bridge, taking default of `xenbr0' Virt_DevicePool.c(224): Network `default' has bridge `virbr0' libvir: Network error : invalid network pointer in virNetworkFree It looks like virNetworkFree() doesn't handle NULL pointers. I think most of the other libvirt functions do though. Otherwise, this patch looks good. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Thu Jan 3 20:29:41 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 03 Jan 2008 13:29:41 -0700 Subject: [Libvirt-cim] [PATCH 0 of 2] Full-virt XML parsing Message-ID: Preliminary XML parsing for full-virt domains From danms at us.ibm.com Thu Jan 3 20:29:43 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 03 Jan 2008 13:29:43 -0700 Subject: [Libvirt-cim] [PATCH 2 of 2] Add XML parsing tester for use when working on Xen PV and KVM support In-Reply-To: Message-ID: <003644d3e86528251c0c.1199395783@theine> # HG changeset patch # User Dan Smith # Date 1199395746 28800 # Node ID 003644d3e86528251c0c84b52af6a92a81253682 # Parent 65a07575d2cfc4dfd3c1d57e0a0828c88dacf540 Add XML parsing tester for use when working on Xen PV and KVM support This simply takes a domain argument, gets the XML from libvirt, parses it in the same way the providers will, and prints the domain information in a structured way. This can be used to test the previous patch, by validating the FV-specific data items, such as emulator and the HVM loader path. Signed-off-by: Dan Smith diff -r 65a07575d2cf -r 003644d3e865 libxkutil/Makefile.am --- a/libxkutil/Makefile.am Thu Jan 03 13:27:33 2008 -0800 +++ b/libxkutil/Makefile.am Thu Jan 03 13:29:06 2008 -0800 @@ -12,3 +12,9 @@ AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ xmlgen.c + +noinst_PROGRAMS = xml_parse_test + +xml_parse_test_SOURCES = xml_parse_test.c +#xml_parse_test_HEADERS = device_parsing.h +xml_parse_test_LDADD = -lvirt -lxkutil diff -r 65a07575d2cf -r 003644d3e865 libxkutil/xml_parse_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/xml_parse_test.c Thu Jan 03 13:29:06 2008 -0800 @@ -0,0 +1,172 @@ +#include + +#include + +#include "device_parsing.h" + +static void print_value(FILE *d, const char *name, const char *val) +{ + fprintf(d, "%-15s: %s\n", name, val); +} + +static void print_u64(FILE *d, const char *name, uint64_t val) +{ + fprintf(d, "%-15s: %lu\n", name, val); +} + +static void print_os(struct domain *dom, + FILE *d) +{ + + if (dom->type == DOMAIN_XENPV) { + print_value(d, "Domain Type", "Xen PV"); + print_value(d, "Type", dom->os_info.pv.type); + print_value(d, "Kernel", dom->os_info.pv.kernel); + print_value(d, "Ramdisk", dom->os_info.pv.initrd); + print_value(d, "Args", dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + print_value(d, "Domain Type", "Xen FV"); + print_value(d, "Type", dom->os_info.fv.type); + print_value(d, "Loader", dom->os_info.fv.loader); + print_value(d, "Boot", dom->os_info.fv.boot); + } else { + fprintf(d, "[ Unknown domain type %i ]\n", dom->type); + } +} + +static void print_dominfo(struct domain *dominfo, + FILE *d) +{ + print_value(d, "Name", dominfo->name); + print_value(d, "UUID", dominfo->uuid); + print_value(d, "Bootloader", dominfo->bootloader); + print_value(d, " args", dominfo->bootloader_args); + + fprintf(d, "Actions: : P:%i R:%i C:%i\n", + dominfo->on_poweroff, + dominfo->on_reboot, + dominfo->on_crash); + + print_os(dominfo, d); +} + +static void print_dev_mem(struct virt_device *dev, + FILE *d) +{ + print_u64(d, "Memory", dev->dev.mem.size); + print_u64(d, "Maximum", dev->dev.mem.maxsize); +} +static void print_dev_net(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.net.type); + print_value(d, "MAC", dev->dev.net.mac); +} + +static void print_dev_disk(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.disk.type); + print_value(d, "Device", dev->dev.disk.device); + print_value(d, "Driver", dev->dev.disk.driver); + print_value(d, "Source", dev->dev.disk.source); + print_value(d, "Virt Device", dev->dev.disk.virtual_dev); +} + +static void print_dev_vcpu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Virtual CPU", "Present"); +} + +static void print_dev_emu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Emulator", dev->dev.emu.path); +} + +static void print_dev_graphics(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Graphics Type", dev->dev.graphics.type); + print_value(d, "Graphics Port", dev->dev.graphics.port); +} + +static void print_devices(struct domain *dominfo, + FILE *d) +{ + int i; + + fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct); + for (i = 0; i < dominfo->dev_mem_ct; i++) + print_dev_mem(&dominfo->dev_mem[i], d); + + fprintf(d, "\n-- Network (%i) --\n", dominfo->dev_net_ct); + for (i = 0; i < dominfo->dev_net_ct; i++) + print_dev_net(&dominfo->dev_net[i], d); + + fprintf(d, "\n-- Disk (%i) --\n", dominfo->dev_disk_ct); + for (i = 0; i < dominfo->dev_disk_ct; i++) + print_dev_disk(&dominfo->dev_disk[i], d); + + fprintf(d, "\n-- VCPU (%i) -- \n", dominfo->dev_vcpu_ct); + for (i = 0; i < dominfo->dev_vcpu_ct; i++) + print_dev_vcpu(&dominfo->dev_vcpu[i], d); + + if (dominfo->type != DOMAIN_XENPV) { + fprintf(d, "\n-- Emulator --\n"); + print_dev_emu(dominfo->dev_emu, d); + } + + if (dominfo->dev_graphics) { + fprintf(d, "\n-- Graphics --\n"); + print_dev_graphics(dominfo->dev_graphics, d); + } +} + +int main(int argc, char **argv) +{ + virConnectPtr conn; + virDomainPtr dom; + struct domain *dominfo; + + if (argc != 2) { + printf("Usage: %s domain\n", argv[0]); + return 1; + } + + conn = virConnectOpen("xen:///"); + if (conn == NULL) { + printf("Unable to connect to libvirt\n"); + return 2; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + printf("Unable to lookup domain `%s'\n", argv[1]); + return 3; + } + + if (get_dominfo(dom, &dominfo) == 0) { + printf("Failed to parse domain info\n"); + return 4; + } + + printf("Parsed domain info\n"); + + print_dominfo(dominfo, stdout); + print_devices(dominfo, stdout); + + return 0; +} + + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From danms at us.ibm.com Thu Jan 3 20:29:42 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 03 Jan 2008 13:29:42 -0700 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: Message-ID: <65a07575d2cfc4dfd3c1.1199395782@theine> # HG changeset patch # User Dan Smith # Date 1199395653 28800 # Node ID 65a07575d2cfc4dfd3c1d57e0a0828c88dacf540 # Parent 3a838dfd165b5f721687a2bb0b2e03bb0c8192b7 Add preliminary XML-parsing support for Xen FV domains This adds a type switch for XenPV, XenFV, KVM to the struct domain. It also adds parsing of 'graphics' and 'emulator' devices. Finally, amidst the compulsory changes to xmlgen.c are modifications to generate a proper block for XenFV domains. More work will need to be done here, but this is an example of how the domain->type switch will be used to select different generation routines. Signed-off-by: Dan Smith diff -r 3a838dfd165b -r 65a07575d2cf libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Thu Jan 03 08:22:48 2008 -0800 +++ b/libxkutil/device_parsing.c Thu Jan 03 13:27:33 2008 -0800 @@ -36,6 +36,8 @@ #define DISK_XPATH (xmlChar *)"/domain/devices/disk" #define NET_XPATH (xmlChar *)"/domain/devices/interface" +#define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" @@ -195,6 +197,25 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_emu_device(xmlNode *node, struct virt_device *vdev) +{ + struct emu_device *edev = &(vdev->dev.emu); + + edev->path = get_node_content(node); + + return 1; +} + +static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) +{ + struct graphics_device *gdev = &(vdev->dev.graphics); + + gdev->type = get_attr_value(node, "type"); + gdev->port = get_attr_value(node, "port"); + + return 1; +} + static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int i = 0; @@ -209,6 +230,10 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_EMU) + do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_GRAPHICS) + do_real_parse = parse_graphics_device; else goto err; @@ -260,6 +285,10 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_EMU) + xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_GRAPHICS) + xpathstr = GRAPHICS_XPATH; else goto err1; @@ -324,6 +353,48 @@ struct virt_device *virt_device_dup(stru return dev; } +static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_EMU); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + +static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + int get_disk_devices(virDomainPtr dom, struct virt_device **list) { char *xml; @@ -474,14 +545,32 @@ static int parse_os(struct domain *domin for (child = os->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "type")) - STRPROP(dominfo, os_info.type, child); + STRPROP(dominfo, os_info.pv.type, child); else if (XSTREQ(child->name, "kernel")) - STRPROP(dominfo, os_info.kernel, child); + STRPROP(dominfo, os_info.pv.kernel, child); else if (XSTREQ(child->name, "initrd")) - STRPROP(dominfo, os_info.initrd, child); + STRPROP(dominfo, os_info.pv.initrd, child); else if (XSTREQ(child->name, "cmdline")) - STRPROP(dominfo, os_info.cmdline, child); - } + STRPROP(dominfo, os_info.pv.cmdline, child); + else if (XSTREQ(child->name, "loader")) + STRPROP(dominfo, os_info.fv.loader, child); + else if (XSTREQ(child->name, "boot")) + dominfo->os_info.fv.boot = get_attr_value(child, + "dev"); + } + + printf("Type string: %s\n", dominfo->typestr); + + if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "xen"))) + dominfo->type = DOMAIN_XENFV; + else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "kvm"))) + dominfo->type = DOMAIN_KVM; + else if (STREQC(dominfo->os_info.pv.type, "linux")) + dominfo->type = DOMAIN_XENPV; + else + dominfo->type = -1; return 1; } @@ -508,6 +597,8 @@ static int parse_domain(xmlNodeSet *nsv, xmlNode *child; memset(dominfo, 0, sizeof(*dominfo)); + + dominfo->typestr = get_attr_value(nodes[0], "type"); for (child = nodes[0]->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "name")) @@ -586,6 +677,9 @@ int get_dominfo(virDomainPtr dom, struct goto out; } + ret = get_emu_device(dom, &(*dominfo)->dev_emu); + ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); + (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); @@ -608,10 +702,18 @@ void cleanup_dominfo(struct domain **dom free(dom->uuid); free(dom->bootloader); free(dom->bootloader_args); - free(dom->os_info.type); - free(dom->os_info.kernel); - free(dom->os_info.initrd); - free(dom->os_info.cmdline); + + free(dom->os_info.pv.type); + if (dom->type == DOMAIN_XENPV) { + free(dom->os_info.pv.kernel); + free(dom->os_info.pv.initrd); + free(dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + free(dom->os_info.fv.loader); + free(dom->os_info.fv.boot); + } else { + CU_DEBUG("Unknown domain type %i", dom->type); + } cleanup_virt_devices(&dom->dev_mem, dom->dev_mem_ct); cleanup_virt_devices(&dom->dev_net, dom->dev_net_ct); diff -r 3a838dfd165b -r 65a07575d2cf libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Thu Jan 03 08:22:48 2008 -0800 +++ b/libxkutil/device_parsing.h Thu Jan 03 13:27:33 2008 -0800 @@ -48,38 +48,67 @@ struct mem_device { uint64_t maxsize; }; +struct emu_device { + char *path; +}; + +struct graphics_device { + char *type; + char *port; +}; + struct virt_device { enum {VIRT_DEV_UNKNOWN, VIRT_DEV_NET = CIM_RASD_TYPE_NET, VIRT_DEV_DISK = CIM_RASD_TYPE_DISK, VIRT_DEV_MEM = CIM_RASD_TYPE_MEM, VIRT_DEV_VCPU = CIM_RASD_TYPE_PROC, + VIRT_DEV_EMU, + VIRT_DEV_GRAPHICS, } type; union { struct disk_device disk; struct net_device net; struct mem_device mem; struct _virVcpuInfo vcpu; + struct emu_device emu; + struct graphics_device graphics; } dev; char *id; }; -struct os_info { +struct pv_os_info { char *type; char *kernel; char *initrd; char *cmdline; }; +struct fv_os_info { + char *type; /* Should always be 'hvm' */ + char *loader; + char *boot; +}; + struct domain { + enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM } type; char *name; + char *typestr; /*xen, kvm, etc */ char *uuid; char *bootloader; char *bootloader_args; - struct os_info os_info; + + union { + struct pv_os_info pv; + struct fv_os_info fv; + } os_info; + int on_poweroff; int on_reboot; int on_crash; + + struct virt_device *dev_graphics; + struct virt_device *dev_emu; struct virt_device *dev_mem; int dev_mem_ct; diff -r 3a838dfd165b -r 65a07575d2cf libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Thu Jan 03 08:22:48 2008 -0800 +++ b/libxkutil/xmlgen.c Thu Jan 03 13:27:33 2008 -0800 @@ -271,9 +271,9 @@ static char *system_xml(struct domain *d return xml; } -static char *os_xml(struct domain *domain) -{ - struct os_info *os = &domain->os_info; +static char *_xenpv_os_xml(struct domain *domain) +{ + struct pv_os_info *os = &domain->os_info.pv; int ret; char *xml; char *type = NULL; @@ -312,6 +312,60 @@ static char *os_xml(struct domain *domai free(cmdline); return xml; +} + +static char *_xenfv_os_xml(struct domain *domain) +{ + struct fv_os_info *os = &domain->os_info.fv; + int ret; + char *xml; + char *type; + char *loader; + char *boot; + struct kv bootattr = {"dev", NULL}; + + if (os->type == NULL) + os->type = strdup("hvm"); + + if (os->loader == NULL) + os->loader = strdup("/usr/lib/xen/boot/hvmloader"); + + if (os->boot == NULL) + os->boot = strdup("hd"); + + type = tagify("type", os->type, NULL, 0); + loader = tagify("loader", os->loader, NULL, 0); + + bootattr.val = os->boot; + boot = tagify("boot", NULL, &bootattr, 1); + + ret = asprintf(&xml, + "\n" + " %s\n" + " %s\n" + " %s\n" + "\n", + type, + loader, + boot); + if (ret == -1) + xml = NULL; + + free(type); + free(loader); + free(boot); + + return xml; +} + +static char *os_xml(struct domain *domain) +{ + if (domain->type == DOMAIN_XENPV) + return _xenpv_os_xml(domain); + else if (domain->type == DOMAIN_XENFV) + return _xenfv_os_xml(domain); + else + return strdup("\n"); } char *system_to_xml(struct domain *dominfo) From kaitlin at linux.vnet.ibm.com Thu Jan 3 23:38:32 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 15:38:32 -0800 Subject: [Libvirt-cim] [PATCH] VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref Message-ID: <652cc30234dacb2bca5c.1199403512@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199396274 28800 # Node ID 652cc30234dacb2bca5ca1b185dad32246aead48 # Parent 615554f6eca4cd21e5715a3af73a616637e54f96 VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref. Instead of return_vsm_cap(), call get_vsm_cap() and the compare the properties of the ref with the instance returned by get_vsm_cap(). Failing query: wbemcli gi 'http://localhost/root/virt:Xen_VirtualSystemManagementCapabilities.InstanceID="wrong"' Signed-off-by: Kaitlin Rupert diff -r 615554f6eca4 -r 652cc30234da src/Virt_VirtualSystemManagementCapabilities.c --- a/src/Virt_VirtualSystemManagementCapabilities.c Fri Dec 14 16:13:18 2007 -0800 +++ b/src/Virt_VirtualSystemManagementCapabilities.c Thu Jan 03 13:37:54 2008 -0800 @@ -172,7 +172,24 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - return return_vsm_cap(reference, results, 0); + CMPIInstance *inst; + CMPIStatus s; + const char *prop; + + s = get_vsm_cap(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(reference, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } else { + CMReturnInstance(results, inst); + } + + return s; } DEFAULT_CI(); From kaitlin at linux.vnet.ibm.com Fri Jan 4 00:26:38 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 16:26:38 -0800 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: <65a07575d2cfc4dfd3c1.1199395782@theine> References: <65a07575d2cfc4dfd3c1.1199395782@theine> Message-ID: <477D7D3E.50208@linux.vnet.ibm.com> Dan Smith wrote: > + > + printf("Type string: %s\n", dominfo->typestr); This should probably be a CU_DEBUG() statement. > + > + free(dom->os_info.pv.type); > + if (dom->type == DOMAIN_XENPV) { > + free(dom->os_info.pv.kernel); > + free(dom->os_info.pv.initrd); > + free(dom->os_info.pv.cmdline); > + } else if (dom->type == DOMAIN_XENFV) { > + free(dom->os_info.fv.loader); > + free(dom->os_info.fv.boot); > + } else { > + CU_DEBUG("Unknown domain type %i", dom->type); > + } Does os_info.fv.type need to be freed as well? -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Fri Jan 4 00:44:38 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 03 Jan 2008 16:44:38 -0800 Subject: [Libvirt-cim] [PATCH 2 of 2] Add XML parsing tester for use when working on Xen PV and KVM support In-Reply-To: <003644d3e86528251c0c.1199395783@theine> References: <003644d3e86528251c0c.1199395783@theine> Message-ID: <477D8176.2020709@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199395746 28800 > # Node ID 003644d3e86528251c0c84b52af6a92a81253682 > # Parent 65a07575d2cfc4dfd3c1d57e0a0828c88dacf540 > Add XML parsing tester for use when working on Xen PV and KVM support This is a neat test. It worked with my paravirt guest. I don't have a fullvirt guest to test with, but the code looks sane enough. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From grendel at linux.vnet.ibm.com Fri Jan 4 15:22:08 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Fri, 04 Jan 2008 10:22:08 -0500 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: <65a07575d2cfc4dfd3c1.1199395782@theine> References: <65a07575d2cfc4dfd3c1.1199395782@theine> Message-ID: <477E4F20.5010202@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199395653 28800 > # Node ID 65a07575d2cfc4dfd3c1d57e0a0828c88dacf540 > # Parent 3a838dfd165b5f721687a2bb0b2e03bb0c8192b7 > Add preliminary XML-parsing support for Xen FV domains > > This adds a type switch for XenPV, XenFV, KVM to the struct domain. > It also adds parsing of 'graphics' and 'emulator' devices. Finally, > amidst the compulsory changes to xmlgen.c are modifications to > generate a proper block for XenFV domains. More work will need > to be done here, but this is an example of how the domain->type switch > will be used to select different generation routines. > > Signed-off-by: Dan Smith > > + > +static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) > +{ > + char *xml; > + int ret; > + struct virt_device *list = NULL; > + > + xml = virDomainGetXMLDesc(dom, 0); > + if (!xml) > + return 0; > > I suppose this speaks well for the quality of the patch when this is all I can find to complain about, but isn't that a spot where we typically use "if (xml == NULL)" for the sake of clarity? Using "(!xml)" for the conditional tends to make me think of xml as an int. -- -Jay From grendel at linux.vnet.ibm.com Fri Jan 4 15:23:23 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Fri, 04 Jan 2008 10:23:23 -0500 Subject: [Libvirt-cim] [PATCH] VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref In-Reply-To: <652cc30234dacb2bca5c.1199403512@elm3b41.beaverton.ibm.com> References: <652cc30234dacb2bca5c.1199403512@elm3b41.beaverton.ibm.com> Message-ID: <477E4F6B.9020001@linux.vnet.ibm.com> Kaitlin Rupert wrote: > # HG changeset patch > # User Kaitlin Rupert > # Date 1199396274 28800 > # Node ID 652cc30234dacb2bca5ca1b185dad32246aead48 > # Parent 615554f6eca4cd21e5715a3af73a616637e54f96 > VirtualSystemManagementCapabilities GetInstance() returns inst for invalid ref. > > Instead of return_vsm_cap(), call get_vsm_cap() and the compare the properties of the ref with the instance returned by get_vsm_cap(). > > Failing query: > wbemcli gi 'http://localhost/root/virt:Xen_VirtualSystemManagementCapabilities.InstanceID="wrong"' > > Signed-off-by: Kaitlin Rupert > Looks good, +1. -- -Jay From danms at us.ibm.com Fri Jan 4 15:24:38 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 07:24:38 -0800 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: <477D7D3E.50208@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Thu, 03 Jan 2008 16:26:38 -0800") References: <65a07575d2cfc4dfd3c1.1199395782@theine> <477D7D3E.50208@linux.vnet.ibm.com> Message-ID: <87abnl7gw9.fsf@theine.beaverton.ibm.com> KR> This should probably be a CU_DEBUG() statement. Actually, it should be removed. That was left over from some debug. Thanks :) >> + >> + free(dom->os_info.pv.type); >> + if (dom->type == DOMAIN_XENPV) { >> + free(dom->os_info.pv.kernel); >> + free(dom->os_info.pv.initrd); >> + free(dom->os_info.pv.cmdline); >> + } else if (dom->type == DOMAIN_XENFV) { >> + free(dom->os_info.fv.loader); >> + free(dom->os_info.fv.boot); >> + } else { >> + CU_DEBUG("Unknown domain type %i", dom->type); >> + } KR> Does os_info.fv.type need to be freed as well? No, because os_info.pv.type and os_info.fv_type are the same value. However, this is ugly and left over from earlier bits in the implementation. I'll change it up to use the type switch to free the correct field in the body of the if. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 4 15:29:44 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 07:29:44 -0800 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: <477E4F20.5010202@linux.vnet.ibm.com> (Jay Gagnon's message of "Fri, 04 Jan 2008 10:22:08 -0500") References: <65a07575d2cfc4dfd3c1.1199395782@theine> <477E4F20.5010202@linux.vnet.ibm.com> Message-ID: <8763y97gnr.fsf@theine.beaverton.ibm.com> JG> isn't that a spot where we typically use "if (xml == NULL)" for JG> the sake of clarity? Using "(!xml)" for the conditional tends to JG> make me think of xml as an int. Yes, and it pained me to do it this way. However, I was keeping with the rest of Zhengang's style in that file. I think it would be good to leave it as-is for this patch and then work up a follow-on that corrects quite a few style issues in that particular file. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 4 14:34:43 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 07:34:43 -0700 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199460828 28800 # Node ID e5e8eb4659148bb5b77779b7fef17c1b284bb8db # Parent d6b90a71023048ba2bc601ea2180ff841ad44e5b Add preliminary XML-parsing support for Xen FV domains This adds a type switch for XenPV, XenFV, KVM to the struct domain. It also adds parsing of 'graphics' and 'emulator' devices. Finally, amidst the compulsory changes to xmlgen.c are modifications to generate a proper block for XenFV domains. More work will need to be done here, but this is an example of how the domain->type switch will be used to select different generation routines. Changes: - Removed stale debug statement - Cleaned up free() of type string in cleanup_dominfo() Signed-off-by: Dan Smith diff -r d6b90a710230 -r e5e8eb465914 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 07:33:48 2008 -0800 @@ -36,6 +36,8 @@ #define DISK_XPATH (xmlChar *)"/domain/devices/disk" #define NET_XPATH (xmlChar *)"/domain/devices/interface" +#define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" @@ -195,6 +197,25 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_emu_device(xmlNode *node, struct virt_device *vdev) +{ + struct emu_device *edev = &(vdev->dev.emu); + + edev->path = get_node_content(node); + + return 1; +} + +static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) +{ + struct graphics_device *gdev = &(vdev->dev.graphics); + + gdev->type = get_attr_value(node, "type"); + gdev->port = get_attr_value(node, "port"); + + return 1; +} + static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int i = 0; @@ -209,6 +230,10 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_EMU) + do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_GRAPHICS) + do_real_parse = parse_graphics_device; else goto err; @@ -260,6 +285,10 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_EMU) + xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_GRAPHICS) + xpathstr = GRAPHICS_XPATH; else goto err1; @@ -324,6 +353,48 @@ struct virt_device *virt_device_dup(stru return dev; } +static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_EMU); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + +static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + int get_disk_devices(virDomainPtr dom, struct virt_device **list) { char *xml; @@ -474,14 +545,30 @@ static int parse_os(struct domain *domin for (child = os->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "type")) - STRPROP(dominfo, os_info.type, child); + STRPROP(dominfo, os_info.pv.type, child); else if (XSTREQ(child->name, "kernel")) - STRPROP(dominfo, os_info.kernel, child); + STRPROP(dominfo, os_info.pv.kernel, child); else if (XSTREQ(child->name, "initrd")) - STRPROP(dominfo, os_info.initrd, child); + STRPROP(dominfo, os_info.pv.initrd, child); else if (XSTREQ(child->name, "cmdline")) - STRPROP(dominfo, os_info.cmdline, child); - } + STRPROP(dominfo, os_info.pv.cmdline, child); + else if (XSTREQ(child->name, "loader")) + STRPROP(dominfo, os_info.fv.loader, child); + else if (XSTREQ(child->name, "boot")) + dominfo->os_info.fv.boot = get_attr_value(child, + "dev"); + } + + if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "xen"))) + dominfo->type = DOMAIN_XENFV; + else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "kvm"))) + dominfo->type = DOMAIN_KVM; + else if (STREQC(dominfo->os_info.pv.type, "linux")) + dominfo->type = DOMAIN_XENPV; + else + dominfo->type = -1; return 1; } @@ -508,6 +595,8 @@ static int parse_domain(xmlNodeSet *nsv, xmlNode *child; memset(dominfo, 0, sizeof(*dominfo)); + + dominfo->typestr = get_attr_value(nodes[0], "type"); for (child = nodes[0]->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "name")) @@ -586,6 +675,9 @@ int get_dominfo(virDomainPtr dom, struct goto out; } + ret = get_emu_device(dom, &(*dominfo)->dev_emu); + ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); + (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); @@ -608,10 +700,19 @@ void cleanup_dominfo(struct domain **dom free(dom->uuid); free(dom->bootloader); free(dom->bootloader_args); - free(dom->os_info.type); - free(dom->os_info.kernel); - free(dom->os_info.initrd); - free(dom->os_info.cmdline); + + if (dom->type == DOMAIN_XENPV) { + free(dom->os_info.pv.type); + free(dom->os_info.pv.kernel); + free(dom->os_info.pv.initrd); + free(dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + free(dom->os_info.fv.type); + free(dom->os_info.fv.loader); + free(dom->os_info.fv.boot); + } else { + CU_DEBUG("Unknown domain type %i", dom->type); + } cleanup_virt_devices(&dom->dev_mem, dom->dev_mem_ct); cleanup_virt_devices(&dom->dev_net, dom->dev_net_ct); diff -r d6b90a710230 -r e5e8eb465914 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.h Fri Jan 04 07:33:48 2008 -0800 @@ -48,38 +48,67 @@ struct mem_device { uint64_t maxsize; }; +struct emu_device { + char *path; +}; + +struct graphics_device { + char *type; + char *port; +}; + struct virt_device { enum {VIRT_DEV_UNKNOWN, VIRT_DEV_NET = CIM_RASD_TYPE_NET, VIRT_DEV_DISK = CIM_RASD_TYPE_DISK, VIRT_DEV_MEM = CIM_RASD_TYPE_MEM, VIRT_DEV_VCPU = CIM_RASD_TYPE_PROC, + VIRT_DEV_EMU, + VIRT_DEV_GRAPHICS, } type; union { struct disk_device disk; struct net_device net; struct mem_device mem; struct _virVcpuInfo vcpu; + struct emu_device emu; + struct graphics_device graphics; } dev; char *id; }; -struct os_info { +struct pv_os_info { char *type; char *kernel; char *initrd; char *cmdline; }; +struct fv_os_info { + char *type; /* Should always be 'hvm' */ + char *loader; + char *boot; +}; + struct domain { + enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM } type; char *name; + char *typestr; /*xen, kvm, etc */ char *uuid; char *bootloader; char *bootloader_args; - struct os_info os_info; + + union { + struct pv_os_info pv; + struct fv_os_info fv; + } os_info; + int on_poweroff; int on_reboot; int on_crash; + + struct virt_device *dev_graphics; + struct virt_device *dev_emu; struct virt_device *dev_mem; int dev_mem_ct; diff -r d6b90a710230 -r e5e8eb465914 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/xmlgen.c Fri Jan 04 07:33:48 2008 -0800 @@ -271,9 +271,9 @@ static char *system_xml(struct domain *d return xml; } -static char *os_xml(struct domain *domain) -{ - struct os_info *os = &domain->os_info; +static char *_xenpv_os_xml(struct domain *domain) +{ + struct pv_os_info *os = &domain->os_info.pv; int ret; char *xml; char *type = NULL; @@ -312,6 +312,60 @@ static char *os_xml(struct domain *domai free(cmdline); return xml; +} + +static char *_xenfv_os_xml(struct domain *domain) +{ + struct fv_os_info *os = &domain->os_info.fv; + int ret; + char *xml; + char *type; + char *loader; + char *boot; + struct kv bootattr = {"dev", NULL}; + + if (os->type == NULL) + os->type = strdup("hvm"); + + if (os->loader == NULL) + os->loader = strdup("/usr/lib/xen/boot/hvmloader"); + + if (os->boot == NULL) + os->boot = strdup("hd"); + + type = tagify("type", os->type, NULL, 0); + loader = tagify("loader", os->loader, NULL, 0); + + bootattr.val = os->boot; + boot = tagify("boot", NULL, &bootattr, 1); + + ret = asprintf(&xml, + "\n" + " %s\n" + " %s\n" + " %s\n" + "\n", + type, + loader, + boot); + if (ret == -1) + xml = NULL; + + free(type); + free(loader); + free(boot); + + return xml; +} + +static char *os_xml(struct domain *domain) +{ + if (domain->type == DOMAIN_XENPV) + return _xenpv_os_xml(domain); + else if (domain->type == DOMAIN_XENFV) + return _xenfv_os_xml(domain); + else + return strdup("\n"); } char *system_to_xml(struct domain *dominfo) From danms at us.ibm.com Fri Jan 4 14:34:42 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 07:34:42 -0700 Subject: [Libvirt-cim] [PATCH 0 of 2] #2 Full-virt XML parsing Message-ID: Changes are as pointed out by Kaitlin to patch #1. #2 is unchanged. From danms at us.ibm.com Fri Jan 4 14:34:44 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 07:34:44 -0700 Subject: [Libvirt-cim] [PATCH 2 of 2] Add XML parsing tester for use when working on Xen PV and KVM support In-Reply-To: Message-ID: <0433f7d1e5fc0612e557.1199460884@theine> # HG changeset patch # User Dan Smith # Date 1199460875 28800 # Node ID 0433f7d1e5fc0612e557abfbc09830aa8d83753c # Parent e5e8eb4659148bb5b77779b7fef17c1b284bb8db Add XML parsing tester for use when working on Xen PV and KVM support This simply takes a domain argument, gets the XML from libvirt, parses it in the same way the providers will, and prints the domain information in a structured way. This can be used to test the previous patch, by validating the FV-specific data items, such as emulator and the HVM loader path. Signed-off-by: Dan Smith diff -r e5e8eb465914 -r 0433f7d1e5fc libxkutil/Makefile.am --- a/libxkutil/Makefile.am Fri Jan 04 07:33:48 2008 -0800 +++ b/libxkutil/Makefile.am Fri Jan 04 07:34:35 2008 -0800 @@ -12,3 +12,9 @@ AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ xmlgen.c + +noinst_PROGRAMS = xml_parse_test + +xml_parse_test_SOURCES = xml_parse_test.c +#xml_parse_test_HEADERS = device_parsing.h +xml_parse_test_LDADD = -lvirt -lxkutil diff -r e5e8eb465914 -r 0433f7d1e5fc libxkutil/xml_parse_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/xml_parse_test.c Fri Jan 04 07:34:35 2008 -0800 @@ -0,0 +1,172 @@ +#include + +#include + +#include "device_parsing.h" + +static void print_value(FILE *d, const char *name, const char *val) +{ + fprintf(d, "%-15s: %s\n", name, val); +} + +static void print_u64(FILE *d, const char *name, uint64_t val) +{ + fprintf(d, "%-15s: %lu\n", name, val); +} + +static void print_os(struct domain *dom, + FILE *d) +{ + + if (dom->type == DOMAIN_XENPV) { + print_value(d, "Domain Type", "Xen PV"); + print_value(d, "Type", dom->os_info.pv.type); + print_value(d, "Kernel", dom->os_info.pv.kernel); + print_value(d, "Ramdisk", dom->os_info.pv.initrd); + print_value(d, "Args", dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + print_value(d, "Domain Type", "Xen FV"); + print_value(d, "Type", dom->os_info.fv.type); + print_value(d, "Loader", dom->os_info.fv.loader); + print_value(d, "Boot", dom->os_info.fv.boot); + } else { + fprintf(d, "[ Unknown domain type %i ]\n", dom->type); + } +} + +static void print_dominfo(struct domain *dominfo, + FILE *d) +{ + print_value(d, "Name", dominfo->name); + print_value(d, "UUID", dominfo->uuid); + print_value(d, "Bootloader", dominfo->bootloader); + print_value(d, " args", dominfo->bootloader_args); + + fprintf(d, "Actions: : P:%i R:%i C:%i\n", + dominfo->on_poweroff, + dominfo->on_reboot, + dominfo->on_crash); + + print_os(dominfo, d); +} + +static void print_dev_mem(struct virt_device *dev, + FILE *d) +{ + print_u64(d, "Memory", dev->dev.mem.size); + print_u64(d, "Maximum", dev->dev.mem.maxsize); +} +static void print_dev_net(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.net.type); + print_value(d, "MAC", dev->dev.net.mac); +} + +static void print_dev_disk(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.disk.type); + print_value(d, "Device", dev->dev.disk.device); + print_value(d, "Driver", dev->dev.disk.driver); + print_value(d, "Source", dev->dev.disk.source); + print_value(d, "Virt Device", dev->dev.disk.virtual_dev); +} + +static void print_dev_vcpu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Virtual CPU", "Present"); +} + +static void print_dev_emu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Emulator", dev->dev.emu.path); +} + +static void print_dev_graphics(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Graphics Type", dev->dev.graphics.type); + print_value(d, "Graphics Port", dev->dev.graphics.port); +} + +static void print_devices(struct domain *dominfo, + FILE *d) +{ + int i; + + fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct); + for (i = 0; i < dominfo->dev_mem_ct; i++) + print_dev_mem(&dominfo->dev_mem[i], d); + + fprintf(d, "\n-- Network (%i) --\n", dominfo->dev_net_ct); + for (i = 0; i < dominfo->dev_net_ct; i++) + print_dev_net(&dominfo->dev_net[i], d); + + fprintf(d, "\n-- Disk (%i) --\n", dominfo->dev_disk_ct); + for (i = 0; i < dominfo->dev_disk_ct; i++) + print_dev_disk(&dominfo->dev_disk[i], d); + + fprintf(d, "\n-- VCPU (%i) -- \n", dominfo->dev_vcpu_ct); + for (i = 0; i < dominfo->dev_vcpu_ct; i++) + print_dev_vcpu(&dominfo->dev_vcpu[i], d); + + if (dominfo->type != DOMAIN_XENPV) { + fprintf(d, "\n-- Emulator --\n"); + print_dev_emu(dominfo->dev_emu, d); + } + + if (dominfo->dev_graphics) { + fprintf(d, "\n-- Graphics --\n"); + print_dev_graphics(dominfo->dev_graphics, d); + } +} + +int main(int argc, char **argv) +{ + virConnectPtr conn; + virDomainPtr dom; + struct domain *dominfo; + + if (argc != 2) { + printf("Usage: %s domain\n", argv[0]); + return 1; + } + + conn = virConnectOpen("xen:///"); + if (conn == NULL) { + printf("Unable to connect to libvirt\n"); + return 2; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + printf("Unable to lookup domain `%s'\n", argv[1]); + return 3; + } + + if (get_dominfo(dom, &dominfo) == 0) { + printf("Failed to parse domain info\n"); + return 4; + } + + printf("Parsed domain info\n"); + + print_dominfo(dominfo, stdout); + print_devices(dominfo, stdout); + + return 0; +} + + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From grendel at linux.vnet.ibm.com Fri Jan 4 15:44:13 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Fri, 04 Jan 2008 10:44:13 -0500 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: <8763y97gnr.fsf@theine.beaverton.ibm.com> References: <65a07575d2cfc4dfd3c1.1199395782@theine> <477E4F20.5010202@linux.vnet.ibm.com> <8763y97gnr.fsf@theine.beaverton.ibm.com> Message-ID: <477E544D.1070104@linux.vnet.ibm.com> Dan Smith wrote: > JG> isn't that a spot where we typically use "if (xml == NULL)" for > JG> the sake of clarity? Using "(!xml)" for the conditional tends to > JG> make me think of xml as an int. > > Yes, and it pained me to do it this way. However, I was keeping with > the rest of Zhengang's style in that file. > > I think it would be good to leave it as-is for this patch and then > work up a follow-on that corrects quite a few style issues in that > particular file. > > Okay, that works for me. -- -Jay From grendel at linux.vnet.ibm.com Fri Jan 4 16:06:52 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Fri, 04 Jan 2008 11:06:52 -0500 Subject: [Libvirt-cim] [PATCH 0 of 2] #2 Full-virt XML parsing In-Reply-To: References: Message-ID: <477E599C.1040304@linux.vnet.ibm.com> Dan Smith wrote: > Changes are as pointed out by Kaitlin to patch #1. #2 is unchanged. > > > Cool, greenlight from me now. -- -Jay From danms at us.ibm.com Fri Jan 4 16:40:00 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 08:40:00 -0800 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API In-Reply-To: <477D49DE.2070707@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Thu, 03 Jan 2008 12:47:26 -0800") References: <3a838dfd165b5f721687.1199377523@theine> <477D49DE.2070707@linux.vnet.ibm.com> Message-ID: <871w8x7den.fsf@theine.beaverton.ibm.com> KR> It looks like virNetworkFree() doesn't handle NULL pointers. I think KR> most of the other libvirt functions do though. Actually, it looks like it does, it just complains about it. For some reason, virConnectClose() quietly returns on a bad pointer, but virDomainFree() and virNetworkFree() both complain. I'm not sure it's a big deal, or worth making free conditional on network!=NULL. I imagine at some point we'll wrap the libvirt error handler, which would allow us to hide this warning. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 4 17:02:45 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 10:02:45 -0700 Subject: [Libvirt-cim] [PATCH 0 of 2] #3 Full-virt XML parsing Message-ID: Changes since last time: Added cleanup_{emu,graphics}_device() to the cleanup routines in patch 1 / From danms at us.ibm.com Fri Jan 4 17:02:47 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 10:02:47 -0700 Subject: [Libvirt-cim] [PATCH 2 of 2] Add XML parsing tester for use when working on Xen PV and KVM support In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199469758 28800 # Node ID c835f70d0865e04aff102b25286b9928691e39ab # Parent 56f9f42e5b66ec661f60dee4b4c8cc3424790ff9 Add XML parsing tester for use when working on Xen PV and KVM support This simply takes a domain argument, gets the XML from libvirt, parses it in the same way the providers will, and prints the domain information in a structured way. This can be used to test the previous patch, by validating the FV-specific data items, such as emulator and the HVM loader path. Signed-off-by: Dan Smith diff -r 56f9f42e5b66 -r c835f70d0865 libxkutil/Makefile.am --- a/libxkutil/Makefile.am Fri Jan 04 10:02:31 2008 -0800 +++ b/libxkutil/Makefile.am Fri Jan 04 10:02:38 2008 -0800 @@ -12,3 +12,9 @@ AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ xmlgen.c + +noinst_PROGRAMS = xml_parse_test + +xml_parse_test_SOURCES = xml_parse_test.c +#xml_parse_test_HEADERS = device_parsing.h +xml_parse_test_LDADD = -lvirt -lxkutil diff -r 56f9f42e5b66 -r c835f70d0865 libxkutil/xml_parse_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/xml_parse_test.c Fri Jan 04 10:02:38 2008 -0800 @@ -0,0 +1,172 @@ +#include + +#include + +#include "device_parsing.h" + +static void print_value(FILE *d, const char *name, const char *val) +{ + fprintf(d, "%-15s: %s\n", name, val); +} + +static void print_u64(FILE *d, const char *name, uint64_t val) +{ + fprintf(d, "%-15s: %lu\n", name, val); +} + +static void print_os(struct domain *dom, + FILE *d) +{ + + if (dom->type == DOMAIN_XENPV) { + print_value(d, "Domain Type", "Xen PV"); + print_value(d, "Type", dom->os_info.pv.type); + print_value(d, "Kernel", dom->os_info.pv.kernel); + print_value(d, "Ramdisk", dom->os_info.pv.initrd); + print_value(d, "Args", dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + print_value(d, "Domain Type", "Xen FV"); + print_value(d, "Type", dom->os_info.fv.type); + print_value(d, "Loader", dom->os_info.fv.loader); + print_value(d, "Boot", dom->os_info.fv.boot); + } else { + fprintf(d, "[ Unknown domain type %i ]\n", dom->type); + } +} + +static void print_dominfo(struct domain *dominfo, + FILE *d) +{ + print_value(d, "Name", dominfo->name); + print_value(d, "UUID", dominfo->uuid); + print_value(d, "Bootloader", dominfo->bootloader); + print_value(d, " args", dominfo->bootloader_args); + + fprintf(d, "Actions: : P:%i R:%i C:%i\n", + dominfo->on_poweroff, + dominfo->on_reboot, + dominfo->on_crash); + + print_os(dominfo, d); +} + +static void print_dev_mem(struct virt_device *dev, + FILE *d) +{ + print_u64(d, "Memory", dev->dev.mem.size); + print_u64(d, "Maximum", dev->dev.mem.maxsize); +} +static void print_dev_net(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.net.type); + print_value(d, "MAC", dev->dev.net.mac); +} + +static void print_dev_disk(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.disk.type); + print_value(d, "Device", dev->dev.disk.device); + print_value(d, "Driver", dev->dev.disk.driver); + print_value(d, "Source", dev->dev.disk.source); + print_value(d, "Virt Device", dev->dev.disk.virtual_dev); +} + +static void print_dev_vcpu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Virtual CPU", "Present"); +} + +static void print_dev_emu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Emulator", dev->dev.emu.path); +} + +static void print_dev_graphics(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Graphics Type", dev->dev.graphics.type); + print_value(d, "Graphics Port", dev->dev.graphics.port); +} + +static void print_devices(struct domain *dominfo, + FILE *d) +{ + int i; + + fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct); + for (i = 0; i < dominfo->dev_mem_ct; i++) + print_dev_mem(&dominfo->dev_mem[i], d); + + fprintf(d, "\n-- Network (%i) --\n", dominfo->dev_net_ct); + for (i = 0; i < dominfo->dev_net_ct; i++) + print_dev_net(&dominfo->dev_net[i], d); + + fprintf(d, "\n-- Disk (%i) --\n", dominfo->dev_disk_ct); + for (i = 0; i < dominfo->dev_disk_ct; i++) + print_dev_disk(&dominfo->dev_disk[i], d); + + fprintf(d, "\n-- VCPU (%i) -- \n", dominfo->dev_vcpu_ct); + for (i = 0; i < dominfo->dev_vcpu_ct; i++) + print_dev_vcpu(&dominfo->dev_vcpu[i], d); + + if (dominfo->type != DOMAIN_XENPV) { + fprintf(d, "\n-- Emulator --\n"); + print_dev_emu(dominfo->dev_emu, d); + } + + if (dominfo->dev_graphics) { + fprintf(d, "\n-- Graphics --\n"); + print_dev_graphics(dominfo->dev_graphics, d); + } +} + +int main(int argc, char **argv) +{ + virConnectPtr conn; + virDomainPtr dom; + struct domain *dominfo; + + if (argc != 2) { + printf("Usage: %s domain\n", argv[0]); + return 1; + } + + conn = virConnectOpen("xen:///"); + if (conn == NULL) { + printf("Unable to connect to libvirt\n"); + return 2; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + printf("Unable to lookup domain `%s'\n", argv[1]); + return 3; + } + + if (get_dominfo(dom, &dominfo) == 0) { + printf("Failed to parse domain info\n"); + return 4; + } + + printf("Parsed domain info\n"); + + print_dominfo(dominfo, stdout); + print_devices(dominfo, stdout); + + return 0; +} + + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From danms at us.ibm.com Fri Jan 4 17:02:46 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 10:02:46 -0700 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: Message-ID: <56f9f42e5b66ec661f60.1199469766@theine> # HG changeset patch # User Dan Smith # Date 1199469751 28800 # Node ID 56f9f42e5b66ec661f60dee4b4c8cc3424790ff9 # Parent d6b90a71023048ba2bc601ea2180ff841ad44e5b Add preliminary XML-parsing support for Xen FV domains This adds a type switch for XenPV, XenFV, KVM to the struct domain. It also adds parsing of 'graphics' and 'emulator' devices. Finally, amidst the compulsory changes to xmlgen.c are modifications to generate a proper block for XenFV domains. More work will need to be done here, but this is an example of how the domain->type switch will be used to select different generation routines. Changes: - Removed stale debug statement - Cleaned up free() of type string in cleanup_dominfo() Signed-off-by: Dan Smith diff -r d6b90a710230 -r 56f9f42e5b66 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 10:02:31 2008 -0800 @@ -36,6 +36,8 @@ #define DISK_XPATH (xmlChar *)"/domain/devices/disk" #define NET_XPATH (xmlChar *)"/domain/devices/interface" +#define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" @@ -55,6 +57,17 @@ static void cleanup_net_device(struct ne free(dev->bridge); } +static void cleanup_emu_device(struct emu_device *dev) +{ + free(dev->path); +} + +static void cleanup_graphics_device(struct graphics_device *dev) +{ + free(dev->type); + free(dev->port); +} + void cleanup_virt_device(struct virt_device *dev) { if (dev == NULL) @@ -64,6 +77,10 @@ void cleanup_virt_device(struct virt_dev cleanup_disk_device(&dev->dev.disk); else if (dev->type == VIRT_DEV_NET) cleanup_net_device(&dev->dev.net); + else if (dev->type == VIRT_DEV_EMU) + cleanup_emu_device(&dev->dev.emu); + else if (dev->type == VIRT_DEV_GRAPHICS) + cleanup_graphics_device(&dev->dev.graphics); free(dev->id); @@ -195,6 +212,25 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_emu_device(xmlNode *node, struct virt_device *vdev) +{ + struct emu_device *edev = &(vdev->dev.emu); + + edev->path = get_node_content(node); + + return 1; +} + +static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) +{ + struct graphics_device *gdev = &(vdev->dev.graphics); + + gdev->type = get_attr_value(node, "type"); + gdev->port = get_attr_value(node, "port"); + + return 1; +} + static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int i = 0; @@ -209,6 +245,10 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_EMU) + do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_GRAPHICS) + do_real_parse = parse_graphics_device; else goto err; @@ -260,6 +300,10 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_EMU) + xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_GRAPHICS) + xpathstr = GRAPHICS_XPATH; else goto err1; @@ -324,6 +368,48 @@ struct virt_device *virt_device_dup(stru return dev; } +static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_EMU); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + +static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + int get_disk_devices(virDomainPtr dom, struct virt_device **list) { char *xml; @@ -474,14 +560,30 @@ static int parse_os(struct domain *domin for (child = os->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "type")) - STRPROP(dominfo, os_info.type, child); + STRPROP(dominfo, os_info.pv.type, child); else if (XSTREQ(child->name, "kernel")) - STRPROP(dominfo, os_info.kernel, child); + STRPROP(dominfo, os_info.pv.kernel, child); else if (XSTREQ(child->name, "initrd")) - STRPROP(dominfo, os_info.initrd, child); + STRPROP(dominfo, os_info.pv.initrd, child); else if (XSTREQ(child->name, "cmdline")) - STRPROP(dominfo, os_info.cmdline, child); - } + STRPROP(dominfo, os_info.pv.cmdline, child); + else if (XSTREQ(child->name, "loader")) + STRPROP(dominfo, os_info.fv.loader, child); + else if (XSTREQ(child->name, "boot")) + dominfo->os_info.fv.boot = get_attr_value(child, + "dev"); + } + + if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "xen"))) + dominfo->type = DOMAIN_XENFV; + else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "kvm"))) + dominfo->type = DOMAIN_KVM; + else if (STREQC(dominfo->os_info.pv.type, "linux")) + dominfo->type = DOMAIN_XENPV; + else + dominfo->type = -1; return 1; } @@ -508,6 +610,8 @@ static int parse_domain(xmlNodeSet *nsv, xmlNode *child; memset(dominfo, 0, sizeof(*dominfo)); + + dominfo->typestr = get_attr_value(nodes[0], "type"); for (child = nodes[0]->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "name")) @@ -586,6 +690,9 @@ int get_dominfo(virDomainPtr dom, struct goto out; } + ret = get_emu_device(dom, &(*dominfo)->dev_emu); + ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); + (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); @@ -608,10 +715,19 @@ void cleanup_dominfo(struct domain **dom free(dom->uuid); free(dom->bootloader); free(dom->bootloader_args); - free(dom->os_info.type); - free(dom->os_info.kernel); - free(dom->os_info.initrd); - free(dom->os_info.cmdline); + + if (dom->type == DOMAIN_XENPV) { + free(dom->os_info.pv.type); + free(dom->os_info.pv.kernel); + free(dom->os_info.pv.initrd); + free(dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + free(dom->os_info.fv.type); + free(dom->os_info.fv.loader); + free(dom->os_info.fv.boot); + } else { + CU_DEBUG("Unknown domain type %i", dom->type); + } cleanup_virt_devices(&dom->dev_mem, dom->dev_mem_ct); cleanup_virt_devices(&dom->dev_net, dom->dev_net_ct); diff -r d6b90a710230 -r 56f9f42e5b66 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.h Fri Jan 04 10:02:31 2008 -0800 @@ -48,38 +48,67 @@ struct mem_device { uint64_t maxsize; }; +struct emu_device { + char *path; +}; + +struct graphics_device { + char *type; + char *port; +}; + struct virt_device { enum {VIRT_DEV_UNKNOWN, VIRT_DEV_NET = CIM_RASD_TYPE_NET, VIRT_DEV_DISK = CIM_RASD_TYPE_DISK, VIRT_DEV_MEM = CIM_RASD_TYPE_MEM, VIRT_DEV_VCPU = CIM_RASD_TYPE_PROC, + VIRT_DEV_EMU, + VIRT_DEV_GRAPHICS, } type; union { struct disk_device disk; struct net_device net; struct mem_device mem; struct _virVcpuInfo vcpu; + struct emu_device emu; + struct graphics_device graphics; } dev; char *id; }; -struct os_info { +struct pv_os_info { char *type; char *kernel; char *initrd; char *cmdline; }; +struct fv_os_info { + char *type; /* Should always be 'hvm' */ + char *loader; + char *boot; +}; + struct domain { + enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM } type; char *name; + char *typestr; /*xen, kvm, etc */ char *uuid; char *bootloader; char *bootloader_args; - struct os_info os_info; + + union { + struct pv_os_info pv; + struct fv_os_info fv; + } os_info; + int on_poweroff; int on_reboot; int on_crash; + + struct virt_device *dev_graphics; + struct virt_device *dev_emu; struct virt_device *dev_mem; int dev_mem_ct; diff -r d6b90a710230 -r 56f9f42e5b66 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/xmlgen.c Fri Jan 04 10:02:31 2008 -0800 @@ -271,9 +271,9 @@ static char *system_xml(struct domain *d return xml; } -static char *os_xml(struct domain *domain) -{ - struct os_info *os = &domain->os_info; +static char *_xenpv_os_xml(struct domain *domain) +{ + struct pv_os_info *os = &domain->os_info.pv; int ret; char *xml; char *type = NULL; @@ -312,6 +312,60 @@ static char *os_xml(struct domain *domai free(cmdline); return xml; +} + +static char *_xenfv_os_xml(struct domain *domain) +{ + struct fv_os_info *os = &domain->os_info.fv; + int ret; + char *xml; + char *type; + char *loader; + char *boot; + struct kv bootattr = {"dev", NULL}; + + if (os->type == NULL) + os->type = strdup("hvm"); + + if (os->loader == NULL) + os->loader = strdup("/usr/lib/xen/boot/hvmloader"); + + if (os->boot == NULL) + os->boot = strdup("hd"); + + type = tagify("type", os->type, NULL, 0); + loader = tagify("loader", os->loader, NULL, 0); + + bootattr.val = os->boot; + boot = tagify("boot", NULL, &bootattr, 1); + + ret = asprintf(&xml, + "\n" + " %s\n" + " %s\n" + " %s\n" + "\n", + type, + loader, + boot); + if (ret == -1) + xml = NULL; + + free(type); + free(loader); + free(boot); + + return xml; +} + +static char *os_xml(struct domain *domain) +{ + if (domain->type == DOMAIN_XENPV) + return _xenpv_os_xml(domain); + else if (domain->type == DOMAIN_XENFV) + return _xenfv_os_xml(domain); + else + return strdup("\n"); } char *system_to_xml(struct domain *dominfo) From kaitlin at linux.vnet.ibm.com Fri Jan 4 18:45:35 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 04 Jan 2008 10:45:35 -0800 Subject: [Libvirt-cim] [PATCH] Make NetworkPool use libvirt's virtual network API In-Reply-To: <871w8x7den.fsf@theine.beaverton.ibm.com> References: <3a838dfd165b5f721687.1199377523@theine> <477D49DE.2070707@linux.vnet.ibm.com> <871w8x7den.fsf@theine.beaverton.ibm.com> Message-ID: <477E7ECF.7030404@linux.vnet.ibm.com> Dan Smith wrote: > KR> It looks like virNetworkFree() doesn't handle NULL pointers. I think > KR> most of the other libvirt functions do though. > > Actually, it looks like it does, it just complains about it. For some > reason, virConnectClose() quietly returns on a bad pointer, but > virDomainFree() and virNetworkFree() both complain. I'm not sure it's > a big deal, or worth making free conditional on network!=NULL. I > imagine at some point we'll wrap the libvirt error handler, which > would allow us to hide this warning. > Oh, interesting. Thanks for taking a look. It's surprising, because it doesn't seem like any of the other Free() functions return this kind of warning. Either that, or I'm not paying enough attention. =) Thanks! From danms at us.ibm.com Fri Jan 4 19:30:18 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:30:18 -0700 Subject: [Libvirt-cim] [PATCH 0 of 2] #4 Full-virt XML parsing Message-ID: Okay, last time for this set, I promise. Changes only to the first patch From danms at us.ibm.com Fri Jan 4 19:30:19 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:30:19 -0700 Subject: [Libvirt-cim] [PATCH 1 of 2] Add preliminary XML-parsing support for Xen FV domains In-Reply-To: Message-ID: <4611462efdca4c1b6d45.1199478619@theine> # HG changeset patch # User Dan Smith # Date 1199478485 28800 # Node ID 4611462efdca4c1b6d45782d360d1ae6538fb407 # Parent d6b90a71023048ba2bc601ea2180ff841ad44e5b Add preliminary XML-parsing support for Xen FV domains This adds a type switch for XenPV, XenFV, KVM to the struct domain. It also adds parsing of 'graphics' and 'emulator' devices. Finally, amidst the compulsory changes to xmlgen.c are modifications to generate a proper block for XenFV domains. More work will need to be done here, but this is an example of how the domain->type switch will be used to select different generation routines. Changes: - Make VIRT_DEV_UNKNOWN start after CIM types, and with a constant so that automatic numbering starts again after the CIM range - Set the device types in the parse_*_device() functions for emu and graphics - Removed stale debug statement - Cleaned up free() of type string in cleanup_dominfo() Signed-off-by: Dan Smith diff -r d6b90a710230 -r 4611462efdca libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 12:28:05 2008 -0800 @@ -36,6 +36,8 @@ #define DISK_XPATH (xmlChar *)"/domain/devices/disk" #define NET_XPATH (xmlChar *)"/domain/devices/interface" +#define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" @@ -55,6 +57,17 @@ static void cleanup_net_device(struct ne free(dev->bridge); } +static void cleanup_emu_device(struct emu_device *dev) +{ + free(dev->path); +} + +static void cleanup_graphics_device(struct graphics_device *dev) +{ + free(dev->type); + free(dev->port); +} + void cleanup_virt_device(struct virt_device *dev) { if (dev == NULL) @@ -64,6 +77,10 @@ void cleanup_virt_device(struct virt_dev cleanup_disk_device(&dev->dev.disk); else if (dev->type == VIRT_DEV_NET) cleanup_net_device(&dev->dev.net); + else if (dev->type == VIRT_DEV_EMU) + cleanup_emu_device(&dev->dev.emu); + else if (dev->type == VIRT_DEV_GRAPHICS) + cleanup_graphics_device(&dev->dev.graphics); free(dev->id); @@ -195,6 +212,29 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_emu_device(xmlNode *node, struct virt_device *vdev) +{ + struct emu_device *edev = &(vdev->dev.emu); + + edev->path = get_node_content(node); + + vdev->type = VIRT_DEV_EMU; + + return 1; +} + +static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) +{ + struct graphics_device *gdev = &(vdev->dev.graphics); + + gdev->type = get_attr_value(node, "type"); + gdev->port = get_attr_value(node, "port"); + + vdev->type = VIRT_DEV_GRAPHICS; + + return 1; +} + static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int i = 0; @@ -209,6 +249,10 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_EMU) + do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_GRAPHICS) + do_real_parse = parse_graphics_device; else goto err; @@ -260,6 +304,10 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_EMU) + xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_GRAPHICS) + xpathstr = GRAPHICS_XPATH; else goto err1; @@ -324,6 +372,48 @@ struct virt_device *virt_device_dup(stru return dev; } +static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_EMU); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + +static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) +{ + char *xml; + int ret; + struct virt_device *list = NULL; + + xml = virDomainGetXMLDesc(dom, 0); + if (!xml) + return 0; + + ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); + if (ret == 1) + *dev = &list[0]; + else + *dev = NULL; + + free(xml); + + return ret; +} + int get_disk_devices(virDomainPtr dom, struct virt_device **list) { char *xml; @@ -474,14 +564,30 @@ static int parse_os(struct domain *domin for (child = os->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "type")) - STRPROP(dominfo, os_info.type, child); + STRPROP(dominfo, os_info.pv.type, child); else if (XSTREQ(child->name, "kernel")) - STRPROP(dominfo, os_info.kernel, child); + STRPROP(dominfo, os_info.pv.kernel, child); else if (XSTREQ(child->name, "initrd")) - STRPROP(dominfo, os_info.initrd, child); + STRPROP(dominfo, os_info.pv.initrd, child); else if (XSTREQ(child->name, "cmdline")) - STRPROP(dominfo, os_info.cmdline, child); - } + STRPROP(dominfo, os_info.pv.cmdline, child); + else if (XSTREQ(child->name, "loader")) + STRPROP(dominfo, os_info.fv.loader, child); + else if (XSTREQ(child->name, "boot")) + dominfo->os_info.fv.boot = get_attr_value(child, + "dev"); + } + + if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "xen"))) + dominfo->type = DOMAIN_XENFV; + else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && + (STREQC(dominfo->typestr, "kvm"))) + dominfo->type = DOMAIN_KVM; + else if (STREQC(dominfo->os_info.pv.type, "linux")) + dominfo->type = DOMAIN_XENPV; + else + dominfo->type = -1; return 1; } @@ -508,6 +614,8 @@ static int parse_domain(xmlNodeSet *nsv, xmlNode *child; memset(dominfo, 0, sizeof(*dominfo)); + + dominfo->typestr = get_attr_value(nodes[0], "type"); for (child = nodes[0]->children; child != NULL; child = child->next) { if (XSTREQ(child->name, "name")) @@ -586,6 +694,9 @@ int get_dominfo(virDomainPtr dom, struct goto out; } + ret = get_emu_device(dom, &(*dominfo)->dev_emu); + ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); + (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); @@ -608,10 +719,19 @@ void cleanup_dominfo(struct domain **dom free(dom->uuid); free(dom->bootloader); free(dom->bootloader_args); - free(dom->os_info.type); - free(dom->os_info.kernel); - free(dom->os_info.initrd); - free(dom->os_info.cmdline); + + if (dom->type == DOMAIN_XENPV) { + free(dom->os_info.pv.type); + free(dom->os_info.pv.kernel); + free(dom->os_info.pv.initrd); + free(dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + free(dom->os_info.fv.type); + free(dom->os_info.fv.loader); + free(dom->os_info.fv.boot); + } else { + CU_DEBUG("Unknown domain type %i", dom->type); + } cleanup_virt_devices(&dom->dev_mem, dom->dev_mem_ct); cleanup_virt_devices(&dom->dev_net, dom->dev_net_ct); diff -r d6b90a710230 -r 4611462efdca libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/device_parsing.h Fri Jan 04 12:28:05 2008 -0800 @@ -48,38 +48,68 @@ struct mem_device { uint64_t maxsize; }; +struct emu_device { + char *path; +}; + +struct graphics_device { + char *type; + char *port; +}; + struct virt_device { - enum {VIRT_DEV_UNKNOWN, + enum { VIRT_DEV_NET = CIM_RASD_TYPE_NET, VIRT_DEV_DISK = CIM_RASD_TYPE_DISK, VIRT_DEV_MEM = CIM_RASD_TYPE_MEM, VIRT_DEV_VCPU = CIM_RASD_TYPE_PROC, + VIRT_DEV_UNKNOWN = 1000, + VIRT_DEV_EMU, + VIRT_DEV_GRAPHICS, } type; union { struct disk_device disk; struct net_device net; struct mem_device mem; struct _virVcpuInfo vcpu; + struct emu_device emu; + struct graphics_device graphics; } dev; char *id; }; -struct os_info { +struct pv_os_info { char *type; char *kernel; char *initrd; char *cmdline; }; +struct fv_os_info { + char *type; /* Should always be 'hvm' */ + char *loader; + char *boot; +}; + struct domain { + enum { DOMAIN_XENPV, DOMAIN_XENFV, DOMAIN_KVM } type; char *name; + char *typestr; /*xen, kvm, etc */ char *uuid; char *bootloader; char *bootloader_args; - struct os_info os_info; + + union { + struct pv_os_info pv; + struct fv_os_info fv; + } os_info; + int on_poweroff; int on_reboot; int on_crash; + + struct virt_device *dev_graphics; + struct virt_device *dev_emu; struct virt_device *dev_mem; int dev_mem_ct; diff -r d6b90a710230 -r 4611462efdca libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jan 04 07:28:02 2008 -0800 +++ b/libxkutil/xmlgen.c Fri Jan 04 12:28:05 2008 -0800 @@ -271,9 +271,9 @@ static char *system_xml(struct domain *d return xml; } -static char *os_xml(struct domain *domain) -{ - struct os_info *os = &domain->os_info; +static char *_xenpv_os_xml(struct domain *domain) +{ + struct pv_os_info *os = &domain->os_info.pv; int ret; char *xml; char *type = NULL; @@ -312,6 +312,60 @@ static char *os_xml(struct domain *domai free(cmdline); return xml; +} + +static char *_xenfv_os_xml(struct domain *domain) +{ + struct fv_os_info *os = &domain->os_info.fv; + int ret; + char *xml; + char *type; + char *loader; + char *boot; + struct kv bootattr = {"dev", NULL}; + + if (os->type == NULL) + os->type = strdup("hvm"); + + if (os->loader == NULL) + os->loader = strdup("/usr/lib/xen/boot/hvmloader"); + + if (os->boot == NULL) + os->boot = strdup("hd"); + + type = tagify("type", os->type, NULL, 0); + loader = tagify("loader", os->loader, NULL, 0); + + bootattr.val = os->boot; + boot = tagify("boot", NULL, &bootattr, 1); + + ret = asprintf(&xml, + "\n" + " %s\n" + " %s\n" + " %s\n" + "\n", + type, + loader, + boot); + if (ret == -1) + xml = NULL; + + free(type); + free(loader); + free(boot); + + return xml; +} + +static char *os_xml(struct domain *domain) +{ + if (domain->type == DOMAIN_XENPV) + return _xenpv_os_xml(domain); + else if (domain->type == DOMAIN_XENFV) + return _xenfv_os_xml(domain); + else + return strdup("\n"); } char *system_to_xml(struct domain *dominfo) From danms at us.ibm.com Fri Jan 4 19:30:20 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:30:20 -0700 Subject: [Libvirt-cim] [PATCH 2 of 2] Add XML parsing tester for use when working on Xen PV and KVM support In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199478489 28800 # Node ID ff56b87755fa9608a7d046976ef011cf48ce92f1 # Parent 4611462efdca4c1b6d45782d360d1ae6538fb407 Add XML parsing tester for use when working on Xen PV and KVM support This simply takes a domain argument, gets the XML from libvirt, parses it in the same way the providers will, and prints the domain information in a structured way. This can be used to test the previous patch, by validating the FV-specific data items, such as emulator and the HVM loader path. Signed-off-by: Dan Smith diff -r 4611462efdca -r ff56b87755fa libxkutil/Makefile.am --- a/libxkutil/Makefile.am Fri Jan 04 12:28:05 2008 -0800 +++ b/libxkutil/Makefile.am Fri Jan 04 12:28:09 2008 -0800 @@ -12,3 +12,9 @@ AM_LDFLAGS = -lvirt -luuid libxkutil_la_SOURCES = cs_util_instance.c misc_util.c device_parsing.c \ xmlgen.c + +noinst_PROGRAMS = xml_parse_test + +xml_parse_test_SOURCES = xml_parse_test.c +#xml_parse_test_HEADERS = device_parsing.h +xml_parse_test_LDADD = -lvirt -lxkutil diff -r 4611462efdca -r ff56b87755fa libxkutil/xml_parse_test.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libxkutil/xml_parse_test.c Fri Jan 04 12:28:09 2008 -0800 @@ -0,0 +1,172 @@ +#include + +#include + +#include "device_parsing.h" + +static void print_value(FILE *d, const char *name, const char *val) +{ + fprintf(d, "%-15s: %s\n", name, val); +} + +static void print_u64(FILE *d, const char *name, uint64_t val) +{ + fprintf(d, "%-15s: %lu\n", name, val); +} + +static void print_os(struct domain *dom, + FILE *d) +{ + + if (dom->type == DOMAIN_XENPV) { + print_value(d, "Domain Type", "Xen PV"); + print_value(d, "Type", dom->os_info.pv.type); + print_value(d, "Kernel", dom->os_info.pv.kernel); + print_value(d, "Ramdisk", dom->os_info.pv.initrd); + print_value(d, "Args", dom->os_info.pv.cmdline); + } else if (dom->type == DOMAIN_XENFV) { + print_value(d, "Domain Type", "Xen FV"); + print_value(d, "Type", dom->os_info.fv.type); + print_value(d, "Loader", dom->os_info.fv.loader); + print_value(d, "Boot", dom->os_info.fv.boot); + } else { + fprintf(d, "[ Unknown domain type %i ]\n", dom->type); + } +} + +static void print_dominfo(struct domain *dominfo, + FILE *d) +{ + print_value(d, "Name", dominfo->name); + print_value(d, "UUID", dominfo->uuid); + print_value(d, "Bootloader", dominfo->bootloader); + print_value(d, " args", dominfo->bootloader_args); + + fprintf(d, "Actions: : P:%i R:%i C:%i\n", + dominfo->on_poweroff, + dominfo->on_reboot, + dominfo->on_crash); + + print_os(dominfo, d); +} + +static void print_dev_mem(struct virt_device *dev, + FILE *d) +{ + print_u64(d, "Memory", dev->dev.mem.size); + print_u64(d, "Maximum", dev->dev.mem.maxsize); +} +static void print_dev_net(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.net.type); + print_value(d, "MAC", dev->dev.net.mac); +} + +static void print_dev_disk(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Type", dev->dev.disk.type); + print_value(d, "Device", dev->dev.disk.device); + print_value(d, "Driver", dev->dev.disk.driver); + print_value(d, "Source", dev->dev.disk.source); + print_value(d, "Virt Device", dev->dev.disk.virtual_dev); +} + +static void print_dev_vcpu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Virtual CPU", "Present"); +} + +static void print_dev_emu(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Emulator", dev->dev.emu.path); +} + +static void print_dev_graphics(struct virt_device *dev, + FILE *d) +{ + print_value(d, "Graphics Type", dev->dev.graphics.type); + print_value(d, "Graphics Port", dev->dev.graphics.port); +} + +static void print_devices(struct domain *dominfo, + FILE *d) +{ + int i; + + fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct); + for (i = 0; i < dominfo->dev_mem_ct; i++) + print_dev_mem(&dominfo->dev_mem[i], d); + + fprintf(d, "\n-- Network (%i) --\n", dominfo->dev_net_ct); + for (i = 0; i < dominfo->dev_net_ct; i++) + print_dev_net(&dominfo->dev_net[i], d); + + fprintf(d, "\n-- Disk (%i) --\n", dominfo->dev_disk_ct); + for (i = 0; i < dominfo->dev_disk_ct; i++) + print_dev_disk(&dominfo->dev_disk[i], d); + + fprintf(d, "\n-- VCPU (%i) -- \n", dominfo->dev_vcpu_ct); + for (i = 0; i < dominfo->dev_vcpu_ct; i++) + print_dev_vcpu(&dominfo->dev_vcpu[i], d); + + if (dominfo->type != DOMAIN_XENPV) { + fprintf(d, "\n-- Emulator --\n"); + print_dev_emu(dominfo->dev_emu, d); + } + + if (dominfo->dev_graphics) { + fprintf(d, "\n-- Graphics --\n"); + print_dev_graphics(dominfo->dev_graphics, d); + } +} + +int main(int argc, char **argv) +{ + virConnectPtr conn; + virDomainPtr dom; + struct domain *dominfo; + + if (argc != 2) { + printf("Usage: %s domain\n", argv[0]); + return 1; + } + + conn = virConnectOpen("xen:///"); + if (conn == NULL) { + printf("Unable to connect to libvirt\n"); + return 2; + } + + dom = virDomainLookupByName(conn, argv[1]); + if (dom == NULL) { + printf("Unable to lookup domain `%s'\n", argv[1]); + return 3; + } + + if (get_dominfo(dom, &dominfo) == 0) { + printf("Failed to parse domain info\n"); + return 4; + } + + printf("Parsed domain info\n"); + + print_dominfo(dominfo, stdout); + print_devices(dominfo, stdout); + + return 0; +} + + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From kaitlin at linux.vnet.ibm.com Fri Jan 4 20:46:55 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 04 Jan 2008 12:46:55 -0800 Subject: [Libvirt-cim] [PATCH 0 of 2] #4 Full-virt XML parsing In-Reply-To: References: Message-ID: <477E9B3F.5000102@linux.vnet.ibm.com> Dan Smith wrote: > Okay, last time for this set, I promise. > > Changes only to the first patch > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim These changes look good to me. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Fri Jan 4 19:55:35 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:35 -0700 Subject: [Libvirt-cim] [PATCH 3 of 5] Make xml_parse_test capable of printing the generated XML for a domain In-Reply-To: Message-ID: <6cd4300ae6a3509caec3.1199480135@theine> # HG changeset patch # User Dan Smith # Date 1199480010 28800 # Node ID 6cd4300ae6a3509caec3a5076a6ccc498f06abcc # Parent c16905cea2137a9fb6275883550e08e1f83f2cc1 Make xml_parse_test capable of printing the generated XML for a domain Signed-off-by: Dan Smith diff -r c16905cea213 -r 6cd4300ae6a3 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/xml_parse_test.c Fri Jan 04 12:53:30 2008 -0800 @@ -3,6 +3,7 @@ #include #include "device_parsing.h" +#include "xmlgen.h" static void print_value(FILE *d, const char *name, const char *val) { @@ -130,6 +131,18 @@ static void print_devices(struct domain } } +static void print_domxml(struct domain *dominfo, + FILE *d) +{ + char *xml; + + xml = system_to_xml(dominfo); + if (xml == NULL) + printf("Failed to create system XML\n"); + else + printf("%s\n", xml); +} + int main(int argc, char **argv) { virConnectPtr conn; @@ -137,7 +150,7 @@ int main(int argc, char **argv) struct domain *dominfo; if (argc < 2) { - printf("Usage: %s domain\n", argv[0]); + printf("Usage: %s domain [URI] [xml]\n", argv[0]); return 1; } @@ -163,8 +176,12 @@ int main(int argc, char **argv) printf("Parsed domain info\n"); - print_dominfo(dominfo, stdout); - print_devices(dominfo, stdout); + if ((argc > 3) && (argv[3][0] == 'x')) + print_domxml(dominfo, stdout); + else { + print_dominfo(dominfo, stdout); + print_devices(dominfo, stdout); + } return 0; } From danms at us.ibm.com Fri Jan 4 19:55:37 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:37 -0700 Subject: [Libvirt-cim] [PATCH 5 of 5] Changes to xmlgen for KVM domains In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199480024 28800 # Node ID ea65740aa1ffe73b47a4a14c8a853dbb3f040016 # Parent 389b558dcf738da99f2c23f87d62ea5255defd56 Changes to xmlgen for KVM domains Includes support for graphics and emulator devices, which benefit XenFV and XenPV domains as well. Signed-off-by: Dan Smith diff -r 389b558dcf73 -r ea65740aa1ff libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/xmlgen.c Fri Jan 04 12:53:44 2008 -0800 @@ -186,6 +186,35 @@ static char *mem_to_xml(struct mem_devic return xml; } +static char *emu_to_xml(struct emu_device *emu) +{ + int ret; + char *xml; + + ret = asprintf(&xml, + "%s\n", + emu->path); + if (ret == -1) + xml = NULL; + + return xml; +} + +static char *graphics_to_xml(struct graphics_device *graphics) +{ + int ret; + char *xml; + + ret = asprintf(&xml, + "\n", + graphics->type, + graphics->port); + if (ret == -1) + xml = NULL; + + return xml; +} + char *device_to_xml(struct virt_device *dev) { switch (dev->type) { @@ -197,6 +226,10 @@ char *device_to_xml(struct virt_device * return mem_to_xml(&dev->dev.mem); case VIRT_DEV_VCPU: return proc_to_xml(&dev->dev.vcpu); + case VIRT_DEV_EMU: + return emu_to_xml(&dev->dev.emu); + case VIRT_DEV_GRAPHICS: + return graphics_to_xml(&dev->dev.graphics); default: return NULL; }; @@ -242,8 +275,16 @@ static char *system_xml(struct domain *d char *bl_args = NULL; char *xml; - bl = tagify("bootloader", domain->bootloader, NULL, 0); - bl_args = tagify("bootloader_args", domain->bootloader_args, NULL, 0); + if (domain->bootloader) + bl = tagify("bootloader", + domain->bootloader, + NULL, + 0); + if (domain->bootloader_args) + bl_args = tagify("bootloader_args", + domain->bootloader_args, + NULL, + 0); ret = asprintf(&xml, "%s\n" @@ -252,8 +293,8 @@ static char *system_xml(struct domain *d "%s\n" "%s\n", domain->name, - bl, - bl_args, + bl ? bl : "", + bl_args ? bl_args : "", vssd_recovery_action_str(domain->on_poweroff), vssd_recovery_action_str(domain->on_crash)); if (ret == -1) @@ -352,12 +393,39 @@ static char *_xenfv_os_xml(struct domain return xml; } +static char *_kvm_os_xml(struct domain *domain) +{ + struct fv_os_info *os = &domain->os_info.fv; + int ret; + char *xml; + char *type; + + if (os->type == NULL) + os->type = strdup("hvm"); + + type = tagify("type", os->type, NULL, 0); + + ret = asprintf(&xml, + "\n" + " %s\n" + "\n", + type); + if (ret == -1) + xml = NULL; + + free(type); + + return xml; +} + static char *os_xml(struct domain *domain) { if (domain->type == DOMAIN_XENPV) return _xenpv_os_xml(domain); else if (domain->type == DOMAIN_XENFV) return _xenfv_os_xml(domain); + else if (domain->type == DOMAIN_KVM) + return _kvm_os_xml(domain); else return strdup("\n"); } @@ -372,6 +440,14 @@ char *system_to_xml(struct domain *domin int ret; uint8_t uuid[16]; char uuidstr[37]; + const char *domtype; + + if ((dominfo->type == DOMAIN_XENPV) || (dominfo->type == DOMAIN_XENFV)) + domtype = "xen"; + else if (dominfo->type == DOMAIN_KVM) + domtype = "kvm"; + else + domtype = "unknown"; if (dominfo->uuid) { strcpy(uuidstr, dominfo->uuid); @@ -385,6 +461,12 @@ char *system_to_xml(struct domain *domin concat_devxml(&devxml, dominfo->dev_net, dominfo->dev_net_ct); concat_devxml(&devxml, dominfo->dev_disk, dominfo->dev_disk_ct); + if (dominfo->dev_emu) + concat_devxml(&devxml, dominfo->dev_emu, 1); + + if (dominfo->dev_graphics) + concat_devxml(&devxml, dominfo->dev_graphics, 1); + concat_devxml(&sysdevxml, dominfo->dev_mem, dominfo->dev_mem_ct); concat_devxml(&sysdevxml, dominfo->dev_vcpu, dominfo->dev_vcpu_ct); @@ -392,7 +474,7 @@ char *system_to_xml(struct domain *domin osxml = os_xml(dominfo); ret = asprintf(&xml, - "\n" + "\n" "%s\n" "%s" "%s" @@ -401,6 +483,7 @@ char *system_to_xml(struct domain *domin "%s" "\n" "\n", + domtype, uuidstr, sysxml, osxml, From danms at us.ibm.com Fri Jan 4 19:55:33 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:33 -0700 Subject: [Libvirt-cim] [PATCH 1 of 5] Extend xml_parse_test for KVM In-Reply-To: Message-ID: <2cdaa36e4a78c8013ca4.1199480133@theine> # HG changeset patch # User Dan Smith # Date 1199480010 28800 # Node ID 2cdaa36e4a78c8013ca4a8b58d4796d5e2012a68 # Parent ff56b87755fa9608a7d046976ef011cf48ce92f1 Extend xml_parse_test for KVM Also allow specification of a URI as the second argument on the command-line to allow connecting to libvirt for KVM. Signed-off-by: Dan Smith diff -r ff56b87755fa -r 2cdaa36e4a78 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Fri Jan 04 12:28:09 2008 -0800 +++ b/libxkutil/xml_parse_test.c Fri Jan 04 12:53:30 2008 -0800 @@ -26,6 +26,12 @@ static void print_os(struct domain *dom, print_value(d, "Args", dom->os_info.pv.cmdline); } else if (dom->type == DOMAIN_XENFV) { print_value(d, "Domain Type", "Xen FV"); + print_value(d, "Type", dom->os_info.fv.type); + print_value(d, "Loader", dom->os_info.fv.loader); + print_value(d, "Boot", dom->os_info.fv.boot); + + } else if (dom->type == DOMAIN_KVM) { + print_value(d, "Domain Type", "KVM/QEMU"); print_value(d, "Type", dom->os_info.fv.type); print_value(d, "Loader", dom->os_info.fv.loader); print_value(d, "Boot", dom->os_info.fv.boot); @@ -130,12 +136,15 @@ int main(int argc, char **argv) virDomainPtr dom; struct domain *dominfo; - if (argc != 2) { + if (argc < 2) { printf("Usage: %s domain\n", argv[0]); return 1; } - conn = virConnectOpen("xen:///"); + if (argc > 2) + conn = virConnectOpen(argv[2]); + else + conn = virConnectOpen("xen:///"); if (conn == NULL) { printf("Unable to connect to libvirt\n"); return 2; From danms at us.ibm.com Fri Jan 4 19:55:36 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:36 -0700 Subject: [Libvirt-cim] [PATCH 4 of 5] Make disk devices detect dev= or file= as a flag for which to use In-Reply-To: Message-ID: <389b558dcf738da99f2c.1199480136@theine> # HG changeset patch # User Dan Smith # Date 1199480010 28800 # Node ID 389b558dcf738da99f2c23f87d62ea5255defd56 # Parent 6cd4300ae6a3509caec3a5076a6ccc498f06abcc Make disk devices detect dev= or file= as a flag for which to use Also make VSMS set the flag properly based on the mode of the path we get in a RASD. Signed-off-by: Dan Smith diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 12:53:30 2008 -0800 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -149,11 +150,15 @@ static int parse_disk_device(xmlNode *dn goto err; } else if (STREQ((char*)child->name, "source")) { ddev->source = get_attr_value(child, "file"); - if (ddev->source) + if (ddev->source) { + ddev->disk_type = DISK_FILE; continue; + } ddev->source = get_attr_value(child, "dev"); - if (ddev->source) + if (ddev->source) { + ddev->disk_type = DISK_PHY; continue; + } goto err; } else if (STREQ((char*)child->name, "target")) { ddev->virtual_dev = get_attr_value(child, "dev"); @@ -825,6 +830,21 @@ int change_device(virDomainPtr dom, stru return 0; } +int disk_type_from_file(const char *path) +{ + struct stat s; + + if (stat(path, &s) < 0) + return DISK_UNKNOWN; + + if (S_ISBLK(s.st_mode)) + return DISK_PHY; + else if (S_ISREG(s.st_mode)) + return DISK_FILE; + else + return DISK_UNKNOWN; +} + /* * Local Variables: * mode: C diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/device_parsing.h Fri Jan 04 12:53:30 2008 -0800 @@ -35,6 +35,7 @@ struct disk_device { char *driver; char *source; char *virtual_dev; + enum {DISK_UNKNOWN, DISK_PHY, DISK_FILE} disk_type; }; struct net_device { @@ -126,6 +127,8 @@ struct domain { struct virt_device *virt_device_dup(struct virt_device *dev); +int disk_type_from_file(const char *path); + int get_dominfo(virDomainPtr dom, struct domain **dominfo); void cleanup_dominfo(struct domain **dominfo); diff -r 6cd4300ae6a3 -r 389b558dcf73 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/xmlgen.c Fri Jan 04 12:53:30 2008 -0800 @@ -22,7 +22,6 @@ #include #include #include -#include #include #include "xmlgen.h" @@ -101,7 +100,6 @@ static char *disk_block_xml(const char * ret = asprintf(&xml, "\n" - " \n" " \n" " \n" "\n", @@ -120,7 +118,6 @@ static char *disk_file_xml(const char *p ret = asprintf(&xml, "\n" - " \n" " \n" " \n" "\n", @@ -134,17 +131,14 @@ static char *disk_file_xml(const char *p static char *disk_to_xml(struct disk_device *disk) { - struct stat s; - - if (stat(disk->source, &s) < 0) - return NULL; - - if (S_ISBLK(s.st_mode)) + if (disk->disk_type == DISK_PHY) return disk_block_xml(disk->source, disk->virtual_dev); - else + else if (disk->disk_type == DISK_FILE) /* If it's not a block device, we assume a file, which should be a reasonable fail-safe */ return disk_file_xml(disk->source, disk->virtual_dev); + else + return strdup("\n"); } static char *net_to_xml(struct net_device *net) diff -r 6cd4300ae6a3 -r 389b558dcf73 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Fri Jan 04 12:53:30 2008 -0800 +++ b/src/Virt_VirtualSystemManagementService.c Fri Jan 04 12:53:30 2008 -0800 @@ -206,6 +206,7 @@ static int rasd_to_vdev(CMPIInstance *in free(dev->dev.disk.source); dev->dev.disk.source = strdup(val); + dev->dev.disk.disk_type = disk_type_from_file(val); } else if (type == VIRT_DEV_NET) { free(dev->dev.net.mac); dev->dev.net.mac = devid; From danms at us.ibm.com Fri Jan 4 19:55:32 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:32 -0700 Subject: [Libvirt-cim] [PATCH 0 of 5] KVM XML parsing and generation support Message-ID: This set adds most of the support we'll need for parsing and generating KVM domain XML. It updates the xml_parse_test app for KVM and allows testing of generated xml. I've tested with PV, FV, and KVM domains and it works for me. The next step after this will be making VSMS aware of how to create a KVM dominfo from RASDs, which will allow us to actually define a domain with DefineSystem for KVM. From danms at us.ibm.com Fri Jan 4 19:55:34 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 12:55:34 -0700 Subject: [Libvirt-cim] [PATCH 2 of 5] Make 'driver' not a required field, since it's not In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199480010 28800 # Node ID c16905cea2137a9fb6275883550e08e1f83f2cc1 # Parent 2cdaa36e4a78c8013ca4a8b58d4796d5e2012a68 Make 'driver' not a required field, since it's not Signed-off-by: Dan Smith diff -r 2cdaa36e4a78 -r c16905cea213 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:30 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 12:53:30 2008 -0800 @@ -161,7 +161,7 @@ static int parse_disk_device(xmlNode *dn goto err; } } - if (! (ddev->driver && ddev->source && ddev->virtual_dev)) + if (! (ddev->source && ddev->virtual_dev)) goto err; vdev->type = VIRT_DEV_DISK; vdev->id = strdup(ddev->virtual_dev); From danms at us.ibm.com Fri Jan 4 20:46:23 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 13:46:23 -0700 Subject: [Libvirt-cim] [PATCH] Fix up style issues in device_parsing.c Message-ID: <533fee39dd71883c5eff.1199483183@theine> # HG changeset patch # User Dan Smith # Date 1199483177 28800 # Node ID 533fee39dd71883c5effeed14a88a9146a15524d # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 Fix up style issues in device_parsing.c Lots of whitespace issues were corrected as well. Any lines that look untouched are trailing whitespace fixes. Changed non-error "err" labels to "out". Lots of other stuff. Signed-off-by: Dan Smith diff -r ea65740aa1ff -r 533fee39dd71 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:44 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 04 13:46:17 2008 -0800 @@ -42,6 +42,8 @@ #define DEFAULT_BRIDGE "xenbr0" +#define XSTREQ(x, y) (STREQ((char *)x, y)) + static void cleanup_disk_device(struct disk_device *dev) { free(dev->type); @@ -100,7 +102,7 @@ void cleanup_virt_devices(struct virt_de *_devs = NULL; } -static char * get_attr_value(xmlNode *node, char *attrname) +static char *get_attr_value(xmlNode *node, char *attrname) { char *buf = NULL; char *ret = NULL; @@ -110,6 +112,7 @@ static char * get_attr_value(xmlNode *no ret = strdup(buf); xmlFree(buf); } + return ret; } @@ -127,9 +130,13 @@ static char *get_node_content(xmlNode *n return buf; } -static int parse_disk_device(xmlNode *dnode, struct virt_device *vdev) +static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev) { struct disk_device *ddev = &(vdev->dev.disk); + xmlNode * child = NULL; + + memset(ddev, 0, sizeof(*ddev)); + ddev->type = get_attr_value(dnode, "type"); if (!ddev->type) goto err; @@ -137,18 +144,13 @@ static int parse_disk_device(xmlNode *dn ddev->device = get_attr_value(dnode, "device"); if (!ddev->device) goto err; - - xmlNode * child = NULL; - ddev->driver = NULL; - ddev->source = NULL; - ddev->virtual_dev = NULL; - for (child = dnode->children; child != NULL; - child = child->next) { - if (STREQ((char*)child->name, "driver")) { + + for (child = dnode->children; child != NULL; child = child->next) { + if (XSTREQ(child->name, "driver")) { ddev->driver = get_attr_value(child, "name"); if (!ddev->driver) goto err; - } else if (STREQ((char*)child->name, "source")) { + } else if (XSTREQ(child->name, "source")) { ddev->source = get_attr_value(child, "file"); if (ddev->source) { ddev->disk_type = DISK_FILE; @@ -160,131 +162,152 @@ static int parse_disk_device(xmlNode *dn continue; } goto err; - } else if (STREQ((char*)child->name, "target")) { + } else if (XSTREQ(child->name, "target")) { ddev->virtual_dev = get_attr_value(child, "dev"); if (!ddev->virtual_dev) goto err; } } - if (! (ddev->source && ddev->virtual_dev)) + if (! (ddev->source && ddev->virtual_dev)) goto err; + vdev->type = VIRT_DEV_DISK; vdev->id = strdup(ddev->virtual_dev); - return 1; + return true; err: cleanup_disk_device(ddev); - return 0; -} - -static int parse_net_device(xmlNode *inode, struct virt_device *vdev) + return false; +} + +static bool parse_net_device(xmlNode *inode, struct virt_device *vdev) { struct net_device *ndev = &(vdev->dev.net); + xmlNode *child = NULL; + + memset(ndev, 0, sizeof(*ndev)); + ndev->type = get_attr_value(inode, "type"); if (!ndev->type) goto err; - xmlNode *child = NULL; - ndev->mac = NULL; - ndev->bridge = NULL; - for (child = inode->children; child != NULL; - child = child->next) { - if (STREQ((char *)child->name, "mac")) { + for (child = inode->children; child != NULL; child = child->next) { + if (XSTREQ(child->name, "mac")) { ndev->mac = get_attr_value(child, "address"); if (!ndev->mac) goto err; - } else if (STREQ((char *)child->name, "source")) { + } else if (XSTREQ(child->name, "source")) { ndev->bridge = get_attr_value(child, "bridge"); if (!ndev->bridge) goto err; } } + if (!ndev->mac) goto err; + if (!ndev->bridge) { ndev->bridge = strdup(DEFAULT_BRIDGE); printf("No bridge, taking default of `%s'\n", ndev->bridge); } + vdev->type = VIRT_DEV_NET; vdev->id = strdup(ndev->mac); - return 1; + return true; err: cleanup_net_device(ndev); - - return 0; -} - -static int parse_emu_device(xmlNode *node, struct virt_device *vdev) + + return false; +} + +static bool parse_emu_device(xmlNode *node, struct virt_device *vdev) { struct emu_device *edev = &(vdev->dev.emu); edev->path = get_node_content(node); + if (edev->path != NULL) + goto err; vdev->type = VIRT_DEV_EMU; - return 1; -} - -static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) + return true; + err: + cleanup_emu_device(edev); + + return false; +} + +static bool parse_graphics_device(xmlNode *node, struct virt_device *vdev) { struct graphics_device *gdev = &(vdev->dev.graphics); gdev->type = get_attr_value(node, "type"); gdev->port = get_attr_value(node, "port"); + if ((gdev->type == NULL) || (gdev->port == NULL)) + goto err; + vdev->type = VIRT_DEV_GRAPHICS; - return 1; + return true; + err: + cleanup_graphics_device(gdev); + + return false; } static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { - int i = 0; - int j = 0; + int devidx; + int lstidx; int count = 0; struct virt_device *list = NULL; xmlNode **dev_nodes = NULL; - int (*do_real_parse)(xmlNode *, struct virt_device *) = NULL; - + bool (*do_real_parse)(xmlNode *, struct virt_device *) = NULL; + /* point to correct parser function according to type */ - if (type == VIRT_DEV_NET) - do_real_parse = &parse_net_device; - else if (type == VIRT_DEV_DISK) - do_real_parse = &parse_disk_device; + if (type == VIRT_DEV_NET) + do_real_parse = &parse_net_device; + else if (type == VIRT_DEV_DISK) + do_real_parse = &parse_disk_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; else if (type == VIRT_DEV_GRAPHICS) do_real_parse = parse_graphics_device; else - goto err; + goto out; if (!nsv) - goto err; + goto out; + dev_nodes = nsv->nodeTab; count = nsv ? nsv->nodeNr : 0; - - if (count > 0) { - list = (struct virt_device *)malloc( - count * sizeof(struct virt_device)); - if (!list) { - count = 0; - goto err; - } - /* walk thru the array, do real parsing on each node */ - while (i <= count-1) { - if (do_real_parse(dev_nodes[i], &list[j])) - j++; - i++; - } - if (j < i) { - list = realloc(list, j * sizeof(struct virt_device)); - count = j; - } - } - err: + + if (count <= 0) + goto out; + + list = (struct virt_device *)malloc(count * sizeof(struct virt_device)); + if (!list) { + count = 0; + goto out; + } + + /* walk thru the array, do real parsing on each node */ + lstidx = 0; + for (devidx = 0; devidx < count; devidx++) { + if (do_real_parse(dev_nodes[devidx], &list[lstidx])) + lstidx++; + } + + if (lstidx < devidx) { + list = realloc(list, lstidx * sizeof(struct virt_device)); + count = lstidx; + } + + out: *l = list; return count; } @@ -297,13 +320,13 @@ static void swallow_err_msg(void *ctx, c static int parse_devices(char *xml, struct virt_device **_list, int type) { - int i = 0; + int len = 0; int count = 0; xmlDoc *xmldoc; xmlXPathContext *xpathCtx; xmlXPathObject *xpathObj; - xmlChar *xpathstr; + xmlChar *xpathstr; if (type == VIRT_DEV_NET) xpathstr = NET_XPATH; @@ -315,22 +338,22 @@ static int parse_devices(char *xml, stru xpathstr = GRAPHICS_XPATH; else goto err1; - - i = strlen(xml) + 1; + + len = strlen(xml) + 1; xmlSetGenericErrorFunc(NULL, swallow_err_msg); - if ((xmldoc = xmlParseMemory(xml, i)) == NULL) + if ((xmldoc = xmlParseMemory(xml, len)) == NULL) goto err1; if ((xpathCtx = xmlXPathNewContext(xmldoc)) == NULL) goto err2; - + if ((xpathObj = xmlXPathEvalExpression(xpathstr, xpathCtx)) == NULL) goto err3; count = do_parse(xpathObj->nodesetval, type, _list); - + xmlSetGenericErrorFunc(NULL, NULL); xmlXPathFreeObject(xpathObj); err3: @@ -372,7 +395,7 @@ struct virt_device *virt_device_dup(stru dev->dev.vcpu.state = _dev->dev.vcpu.state; dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; - } + } return dev; } @@ -384,7 +407,7 @@ static int get_emu_device(virDomainPtr d struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, &list, VIRT_DEV_EMU); @@ -405,7 +428,7 @@ static int get_graphics_device(virDomain struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); @@ -425,7 +448,7 @@ int get_disk_devices(virDomainPtr dom, s int ret; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, list, VIRT_DEV_DISK); @@ -441,7 +464,7 @@ int get_net_devices(virDomainPtr dom, st int ret; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, list, VIRT_DEV_NET); @@ -459,25 +482,25 @@ int get_mem_devices(virDomainPtr dom, st struct virt_device *ret_list = NULL; rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1){ + if (rc == -1) { ret = -1; - goto err; + goto out; } mem_size = (uint64_t)dom_info.memory; mem_maxsize = (uint64_t)dom_info.maxMem; if (mem_size > mem_maxsize) { ret = -1; - goto err; - } - + goto out; + } + ret_list = malloc(sizeof(struct virt_device)); if (!ret_list) { ret = -1; free (ret_list); - goto err; - } - + goto out; + } + ret_list->type = VIRT_DEV_MEM; ret_list->dev.mem.size = mem_size; ret_list->dev.mem.maxsize = mem_maxsize; @@ -485,8 +508,7 @@ int get_mem_devices(virDomainPtr dom, st ret = 1; *list = ret_list; - - err: + out: return ret; } @@ -500,7 +522,7 @@ int get_vcpu_devices(virDomainPtr dom, s rc = virDomainGetInfo(dom, &dom_info); if (rc == -1) { ret = -1; - goto error1; + goto out1; } num_vcpus = dom_info.nrVirtCpu; @@ -508,7 +530,7 @@ int get_vcpu_devices(virDomainPtr dom, s num_filled = virDomainGetVcpus(dom, vcpu_info, num_vcpus, NULL, 0); if (num_vcpus != num_filled) { ret = -1; - goto error2; + goto out2; } ret_list = calloc(num_vcpus, sizeof(struct virt_device)); @@ -519,15 +541,15 @@ int get_vcpu_devices(virDomainPtr dom, s vcpu_info[i].number) == -1) { ret = -1; free(ret_list); - goto error2; + goto out2; } } ret = num_vcpus; *list = ret_list; - error2: + out2: free(vcpu_info); - error1: + out1: return ret; } @@ -537,7 +559,6 @@ char *get_fq_devid(char *host, char *_de if (asprintf(&devid, "%s/%s", host, _devid) == -1) return NULL; - else return devid; } @@ -560,7 +581,6 @@ int parse_fq_devid(const char *devid, ch return 1; } -#define XSTREQ(x, y) (STREQ((char *)x, y)) #define STRPROP(d, p, n) (d->p = get_node_content(n)) static int parse_os(struct domain *dominfo, xmlNode *os) From danms at us.ibm.com Fri Jan 4 21:48:59 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 04 Jan 2008 13:48:59 -0800 Subject: [Libvirt-cim] [PATCH] Fix up style issues in device_parsing.c In-Reply-To: <533fee39dd71883c5eff.1199483183@theine> (Dan Smith's message of "Fri, 04 Jan 2008 13:46:23 -0700") References: <533fee39dd71883c5eff.1199483183@theine> Message-ID: <87prwh5kj8.fsf@theine.beaverton.ibm.com> DS> # HG changeset patch DS> # User Dan Smith DS> # Date 1199483177 28800 DS> # Node ID 533fee39dd71883c5effeed14a88a9146a15524d DS> # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 DS> Fix up style issues in device_parsing.c Let me know if you can spot any others. DS> - if (!xml) DS> + if (xml == NULL) By the way, after looking again at the context, I think I originally committed this offense, so my apologies :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Sat Jan 5 00:49:33 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 04 Jan 2008 16:49:33 -0800 Subject: [Libvirt-cim] [PATCH 0 of 5] KVM XML parsing and generation support In-Reply-To: References: Message-ID: <477ED41D.2080301@linux.vnet.ibm.com> Dan Smith wrote: > This set adds most of the support we'll need for parsing and generating > KVM domain XML. It updates the xml_parse_test app for KVM and allows > testing of generated xml. I've tested with PV, FV, and KVM domains and > it works for me. > > The next step after this will be making VSMS aware of how to create a > KVM dominfo from RASDs, which will allow us to actually define a domain > with DefineSystem for KVM. No comments from me. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Sat Jan 5 01:05:18 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 04 Jan 2008 17:05:18 -0800 Subject: [Libvirt-cim] [PATCH] Fix up style issues in device_parsing.c In-Reply-To: <533fee39dd71883c5eff.1199483183@theine> References: <533fee39dd71883c5eff.1199483183@theine> Message-ID: <477ED7CE.9050104@linux.vnet.ibm.com> > if (!ddev->type) > if (!ddev->device) > if (!ddev->driver) > if (ddev->source) { > if (!ndev->mac) > goto err; > + > if (!ndev->bridge) { Since we have "if (edev->path != NULL)" below, should we change these as well? > edev->path = get_node_content(node); > + if (edev->path != NULL) > + goto err; > > if (!nsv) > - if (!list) { > + if (!list) { > if (!ret_list) { And these too? Although, I can't say as I mind either way. =) -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Sat Jan 5 15:43:48 2008 From: danms at us.ibm.com (Dan Smith) Date: Sat, 05 Jan 2008 07:43:48 -0800 Subject: [Libvirt-cim] [PATCH] Fix up style issues in device_parsing.c In-Reply-To: <477ED7CE.9050104@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Fri, 04 Jan 2008 17:05:18 -0800") References: <533fee39dd71883c5eff.1199483183@theine> <477ED7CE.9050104@linux.vnet.ibm.com> Message-ID: <87lk745lcb.fsf@theine.beaverton.ibm.com> KR> Since we have "if (edev->path != NULL)" below, should we change these KR> as well? Ah, I totally glazed over those. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From heidieck at linux.vnet.ibm.com Mon Jan 7 13:13:50 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Mon, 07 Jan 2008 14:13:50 +0100 Subject: [Libvirt-cim] class Virt_VirtualSystemMigrationCapabilities In-Reply-To: <87fxxwnm6j.fsf@theine.beaverton.ibm.com> References: <476ACEF7.2010505@linux.vnet.ibm.com> <87fxxwnm6j.fsf@theine.beaverton.ibm.com> Message-ID: <4782258E.6020909@linux.vnet.ibm.com> Dan Smith wrote: > HE> the subclass for VirtualSystemMigrationCapabilities in > HE> VSMigrationCapabilities.mof has "Virt" as prefix instead of > HE> "CIM". Does this has a certain background ? > > I think that I was running into an issue putting the superclass in the > MOF when I did that. I was seeing some weird behavior, and thought it > might have been related to putting a CIM_ class in the implementation > MOF. I'm sure it was unrelated, but I didn't change it back. > > If it works as CIM_, I'm fine with switching it. > I would not expect problems by changing the prefix to CIM_, buf if there are, please send me the message and I can have a look into it. The same seemed to happen in VSMigrationService.mof - there is a class called Virt_MigrationJob. But I'm not sure if this one should get the CIM or Xen/KVM prefix. What does the implementor say ;) ? -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Mon Jan 7 13:39:29 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Mon, 07 Jan 2008 14:39:29 +0100 Subject: [Libvirt-cim] [PATCH 0 of 5] KVM XML parsing and generation support In-Reply-To: References: Message-ID: <47822B91.3010909@linux.vnet.ibm.com> Dan Smith wrote: > This set adds most of the support we'll need for parsing and generating > KVM domain XML. It updates the xml_parse_test app for KVM and allows > testing of generated xml. I've tested with PV, FV, and KVM domains and > it works for me. > > The next step after this will be making VSMS aware of how to create a > KVM dominfo from RASDs, which will allow us to actually define a domain > with DefineSystem for KVM. > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cimD > When trying to compile I get the following error on my 32-bit machine: gcc -DHAVE_CONFIG_H -I. -I. -I.. -DCMPI_VERSION=100 -I/usr/local/include/cmpi -I/usr/local/include/libvirt -I/usr/include/libxml2 -I/usr/local/include/libcmpiutil -g -O2 -D_FORTIFY_SOURCE=2 -D_GNU_SOURCE -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wpointer-arith -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-format-y2k -Wcast-align -Wno-unused-value -Werror -c xml_parse_test.c cc1: warnings being treated as errors xml_parse_test.c: In function ?print_u64?: xml_parse_test.c:15: warning: format ?%lu? expects type ?long unsigned int?, but argument 5 has type ?uint64_t? make[3]: *** [xml_parse_test.o] Error 1 I haven't seen that the print_u64() function was touched by these patches, so I don't want to say that they cause this error. But maybe this can be fixed as part of this patch series. I I'm completely wrong with this scenario, then maybe my vacation was too long and I did a pretty ugly mistake when trying to compile ;). -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From danms at us.ibm.com Mon Jan 7 14:29:24 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 06:29:24 -0800 Subject: [Libvirt-cim] class Virt_VirtualSystemMigrationCapabilities In-Reply-To: <4782258E.6020909@linux.vnet.ibm.com> (Heidi Eckhart's message of "Mon, 07 Jan 2008 14:13:50 +0100") References: <476ACEF7.2010505@linux.vnet.ibm.com> <87fxxwnm6j.fsf@theine.beaverton.ibm.com> <4782258E.6020909@linux.vnet.ibm.com> Message-ID: <87hchp675n.fsf@theine.beaverton.ibm.com> HE> The same seemed to happen in VSMigrationService.mof - there is a HE> class called Virt_MigrationJob. But I'm not sure if this one HE> should get the CIM or Xen/KVM prefix. What does the implementor HE> say ;) ? For the other classes, I made Virt_ versions of their defined classes because I thought Pegasus was giving me trouble. However, I don't think there is a CIM_MigrationJob in the Migration profile, so I would tend to thing that keeping it as Virt_MigrationJob:CIM_ConcreteJob would be the right thing to do. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Mon Jan 7 14:30:16 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 06:30:16 -0800 Subject: [Libvirt-cim] [PATCH 0 of 5] KVM XML parsing and generation support In-Reply-To: <47822B91.3010909@linux.vnet.ibm.com> (Heidi Eckhart's message of "Mon, 07 Jan 2008 14:39:29 +0100") References: <47822B91.3010909@linux.vnet.ibm.com> Message-ID: <87d4sd6747.fsf@theine.beaverton.ibm.com> HE> I I'm completely wrong with this scenario, then maybe my vacation was HE> too long and I did a pretty ugly mistake when trying to compile ;). Nope, that's my problem. I should have used PRIu64 there. I'll cook up a patch. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Mon Jan 7 17:45:57 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 10:45:57 -0700 Subject: [Libvirt-cim] [PATCH] .#2 Fix up style issues in device_parsing.c Message-ID: <0306c8af0a5f5d585d22.1199731557@theine> # HG changeset patch # User Dan Smith # Date 1199731551 28800 # Node ID 0306c8af0a5f5d585d223fb1fde5dd04961bbce6 # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 .#2 Fix up style issues in device_parsing.c Lots of whitespace issues were corrected as well. Any lines that look untouched are trailing whitespace fixes. Changed non-error "err" labels to "out". Lots of other stuff. Changes: - Caught all 'if (!...' cases needing cleanup Signed-off-by: Dan Smith diff -r ea65740aa1ff -r 0306c8af0a5f libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:44 2008 -0800 +++ b/libxkutil/device_parsing.c Mon Jan 07 10:45:51 2008 -0800 @@ -42,6 +42,8 @@ #define DEFAULT_BRIDGE "xenbr0" +#define XSTREQ(x, y) (STREQ((char *)x, y)) + static void cleanup_disk_device(struct disk_device *dev) { free(dev->type); @@ -100,7 +102,7 @@ void cleanup_virt_devices(struct virt_de *_devs = NULL; } -static char * get_attr_value(xmlNode *node, char *attrname) +static char *get_attr_value(xmlNode *node, char *attrname) { char *buf = NULL; char *ret = NULL; @@ -110,6 +112,7 @@ static char * get_attr_value(xmlNode *no ret = strdup(buf); xmlFree(buf); } + return ret; } @@ -127,28 +130,27 @@ static char *get_node_content(xmlNode *n return buf; } -static int parse_disk_device(xmlNode *dnode, struct virt_device *vdev) +static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev) { struct disk_device *ddev = &(vdev->dev.disk); + xmlNode * child = NULL; + + memset(ddev, 0, sizeof(*ddev)); + ddev->type = get_attr_value(dnode, "type"); - if (!ddev->type) + if (ddev->type == NULL) goto err; ddev->device = get_attr_value(dnode, "device"); - if (!ddev->device) + if (ddev->device == NULL) goto err; - - xmlNode * child = NULL; - ddev->driver = NULL; - ddev->source = NULL; - ddev->virtual_dev = NULL; - for (child = dnode->children; child != NULL; - child = child->next) { - if (STREQ((char*)child->name, "driver")) { + + for (child = dnode->children; child != NULL; child = child->next) { + if (XSTREQ(child->name, "driver")) { ddev->driver = get_attr_value(child, "name"); - if (!ddev->driver) + if (ddev->driver == NULL) goto err; - } else if (STREQ((char*)child->name, "source")) { + } else if (XSTREQ(child->name, "source")) { ddev->source = get_attr_value(child, "file"); if (ddev->source) { ddev->disk_type = DISK_FILE; @@ -160,131 +162,152 @@ static int parse_disk_device(xmlNode *dn continue; } goto err; - } else if (STREQ((char*)child->name, "target")) { + } else if (XSTREQ(child->name, "target")) { ddev->virtual_dev = get_attr_value(child, "dev"); - if (!ddev->virtual_dev) + if (ddev->virtual_dev == NULL) goto err; } } - if (! (ddev->source && ddev->virtual_dev)) + if ((ddev->source == NULL) || (ddev->virtual_dev == NULL)) goto err; + vdev->type = VIRT_DEV_DISK; vdev->id = strdup(ddev->virtual_dev); - return 1; + return true; err: cleanup_disk_device(ddev); - return 0; -} - -static int parse_net_device(xmlNode *inode, struct virt_device *vdev) + return false; +} + +static bool parse_net_device(xmlNode *inode, struct virt_device *vdev) { struct net_device *ndev = &(vdev->dev.net); + xmlNode *child = NULL; + + memset(ndev, 0, sizeof(*ndev)); + ndev->type = get_attr_value(inode, "type"); - if (!ndev->type) + if (ndev->type == NULL) goto err; - xmlNode *child = NULL; - ndev->mac = NULL; - ndev->bridge = NULL; - for (child = inode->children; child != NULL; - child = child->next) { - if (STREQ((char *)child->name, "mac")) { + for (child = inode->children; child != NULL; child = child->next) { + if (XSTREQ(child->name, "mac")) { ndev->mac = get_attr_value(child, "address"); - if (!ndev->mac) + if (ndev->mac == NULL) goto err; - } else if (STREQ((char *)child->name, "source")) { + } else if (XSTREQ(child->name, "source")) { ndev->bridge = get_attr_value(child, "bridge"); - if (!ndev->bridge) + if (ndev->bridge == NULL) goto err; } } - if (!ndev->mac) + + if (ndev->mac == NULL) goto err; - if (!ndev->bridge) { + + if (ndev->bridge == NULL) { ndev->bridge = strdup(DEFAULT_BRIDGE); printf("No bridge, taking default of `%s'\n", ndev->bridge); } + vdev->type = VIRT_DEV_NET; vdev->id = strdup(ndev->mac); - return 1; + return true; err: cleanup_net_device(ndev); - - return 0; -} - -static int parse_emu_device(xmlNode *node, struct virt_device *vdev) + + return false; +} + +static bool parse_emu_device(xmlNode *node, struct virt_device *vdev) { struct emu_device *edev = &(vdev->dev.emu); edev->path = get_node_content(node); + if (edev->path != NULL) + goto err; vdev->type = VIRT_DEV_EMU; - return 1; -} - -static int parse_graphics_device(xmlNode *node, struct virt_device *vdev) + return true; + err: + cleanup_emu_device(edev); + + return false; +} + +static bool parse_graphics_device(xmlNode *node, struct virt_device *vdev) { struct graphics_device *gdev = &(vdev->dev.graphics); gdev->type = get_attr_value(node, "type"); gdev->port = get_attr_value(node, "port"); + if ((gdev->type == NULL) || (gdev->port == NULL)) + goto err; + vdev->type = VIRT_DEV_GRAPHICS; - return 1; + return true; + err: + cleanup_graphics_device(gdev); + + return false; } static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { - int i = 0; - int j = 0; + int devidx; + int lstidx; int count = 0; struct virt_device *list = NULL; xmlNode **dev_nodes = NULL; - int (*do_real_parse)(xmlNode *, struct virt_device *) = NULL; - + bool (*do_real_parse)(xmlNode *, struct virt_device *) = NULL; + /* point to correct parser function according to type */ - if (type == VIRT_DEV_NET) - do_real_parse = &parse_net_device; - else if (type == VIRT_DEV_DISK) - do_real_parse = &parse_disk_device; + if (type == VIRT_DEV_NET) + do_real_parse = &parse_net_device; + else if (type == VIRT_DEV_DISK) + do_real_parse = &parse_disk_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; else if (type == VIRT_DEV_GRAPHICS) do_real_parse = parse_graphics_device; else - goto err; - - if (!nsv) - goto err; + goto out; + + if (nsv == NULL) + goto out; + dev_nodes = nsv->nodeTab; count = nsv ? nsv->nodeNr : 0; - - if (count > 0) { - list = (struct virt_device *)malloc( - count * sizeof(struct virt_device)); - if (!list) { - count = 0; - goto err; - } - /* walk thru the array, do real parsing on each node */ - while (i <= count-1) { - if (do_real_parse(dev_nodes[i], &list[j])) - j++; - i++; - } - if (j < i) { - list = realloc(list, j * sizeof(struct virt_device)); - count = j; - } - } - err: + + if (count <= 0) + goto out; + + list = (struct virt_device *)malloc(count * sizeof(struct virt_device)); + if (list == NULL) { + count = 0; + goto out; + } + + /* walk thru the array, do real parsing on each node */ + lstidx = 0; + for (devidx = 0; devidx < count; devidx++) { + if (do_real_parse(dev_nodes[devidx], &list[lstidx])) + lstidx++; + } + + if (lstidx < devidx) { + list = realloc(list, lstidx * sizeof(struct virt_device)); + count = lstidx; + } + + out: *l = list; return count; } @@ -297,13 +320,13 @@ static void swallow_err_msg(void *ctx, c static int parse_devices(char *xml, struct virt_device **_list, int type) { - int i = 0; + int len = 0; int count = 0; xmlDoc *xmldoc; xmlXPathContext *xpathCtx; xmlXPathObject *xpathObj; - xmlChar *xpathstr; + xmlChar *xpathstr; if (type == VIRT_DEV_NET) xpathstr = NET_XPATH; @@ -315,22 +338,22 @@ static int parse_devices(char *xml, stru xpathstr = GRAPHICS_XPATH; else goto err1; - - i = strlen(xml) + 1; + + len = strlen(xml) + 1; xmlSetGenericErrorFunc(NULL, swallow_err_msg); - if ((xmldoc = xmlParseMemory(xml, i)) == NULL) + if ((xmldoc = xmlParseMemory(xml, len)) == NULL) goto err1; if ((xpathCtx = xmlXPathNewContext(xmldoc)) == NULL) goto err2; - + if ((xpathObj = xmlXPathEvalExpression(xpathstr, xpathCtx)) == NULL) goto err3; count = do_parse(xpathObj->nodesetval, type, _list); - + xmlSetGenericErrorFunc(NULL, NULL); xmlXPathFreeObject(xpathObj); err3: @@ -348,7 +371,7 @@ struct virt_device *virt_device_dup(stru struct virt_device *dev; dev = malloc(sizeof(*dev)); - if (!dev) + if (dev == NULL) return NULL; dev->type = _dev->type; @@ -372,7 +395,7 @@ struct virt_device *virt_device_dup(stru dev->dev.vcpu.state = _dev->dev.vcpu.state; dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; - } + } return dev; } @@ -384,7 +407,7 @@ static int get_emu_device(virDomainPtr d struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, &list, VIRT_DEV_EMU); @@ -405,7 +428,7 @@ static int get_graphics_device(virDomain struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); @@ -425,7 +448,7 @@ int get_disk_devices(virDomainPtr dom, s int ret; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, list, VIRT_DEV_DISK); @@ -441,7 +464,7 @@ int get_net_devices(virDomainPtr dom, st int ret; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) + if (xml == NULL) return 0; ret = parse_devices(xml, list, VIRT_DEV_NET); @@ -459,25 +482,25 @@ int get_mem_devices(virDomainPtr dom, st struct virt_device *ret_list = NULL; rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1){ + if (rc == -1) { ret = -1; - goto err; + goto out; } mem_size = (uint64_t)dom_info.memory; mem_maxsize = (uint64_t)dom_info.maxMem; if (mem_size > mem_maxsize) { ret = -1; - goto err; - } - + goto out; + } + ret_list = malloc(sizeof(struct virt_device)); - if (!ret_list) { + if (ret_list == NULL) { ret = -1; free (ret_list); - goto err; - } - + goto out; + } + ret_list->type = VIRT_DEV_MEM; ret_list->dev.mem.size = mem_size; ret_list->dev.mem.maxsize = mem_maxsize; @@ -485,8 +508,7 @@ int get_mem_devices(virDomainPtr dom, st ret = 1; *list = ret_list; - - err: + out: return ret; } @@ -500,7 +522,7 @@ int get_vcpu_devices(virDomainPtr dom, s rc = virDomainGetInfo(dom, &dom_info); if (rc == -1) { ret = -1; - goto error1; + goto out1; } num_vcpus = dom_info.nrVirtCpu; @@ -508,7 +530,7 @@ int get_vcpu_devices(virDomainPtr dom, s num_filled = virDomainGetVcpus(dom, vcpu_info, num_vcpus, NULL, 0); if (num_vcpus != num_filled) { ret = -1; - goto error2; + goto out2; } ret_list = calloc(num_vcpus, sizeof(struct virt_device)); @@ -519,15 +541,15 @@ int get_vcpu_devices(virDomainPtr dom, s vcpu_info[i].number) == -1) { ret = -1; free(ret_list); - goto error2; + goto out2; } } ret = num_vcpus; *list = ret_list; - error2: + out2: free(vcpu_info); - error1: + out1: return ret; } @@ -537,7 +559,6 @@ char *get_fq_devid(char *host, char *_de if (asprintf(&devid, "%s/%s", host, _devid) == -1) return NULL; - else return devid; } @@ -560,7 +581,6 @@ int parse_fq_devid(const char *devid, ch return 1; } -#define XSTREQ(x, y) (STREQ((char *)x, y)) #define STRPROP(d, p, n) (d->p = get_node_content(n)) static int parse_os(struct domain *dominfo, xmlNode *os) @@ -686,14 +706,14 @@ int get_dominfo(virDomainPtr dom, struct return 0; xml = virDomainGetXMLDesc(dom, 0); - if (!xml) { + if (xml == NULL) { free(*dominfo); *dominfo = NULL; return 0; } ret = _get_dominfo(xml, *dominfo); - if (!ret) { + if (ret == 0) { free(*dominfo); *dominfo = NULL; goto out; @@ -717,7 +737,7 @@ void cleanup_dominfo(struct domain **dom { struct domain *dom = *dominfo; - if (!dominfo || !(*dominfo)) + if ((dominfo == NULL) || (*dominfo == NULL)) return; free(dom->name); From danms at us.ibm.com Mon Jan 7 17:46:27 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 10:46:27 -0700 Subject: [Libvirt-cim] [PATCH] Fix libvirt version mentioned in README Message-ID: # HG changeset patch # User Dan Smith # Date 1199731573 28800 # Node ID b64e8fda92bffa03bde3dc8c05dc320e2a515de3 # Parent 0306c8af0a5f5d585d223fb1fde5dd04961bbce6 Fix libvirt version mentioned in README Signed-off-by: Dan Smith diff -r 0306c8af0a5f -r b64e8fda92bf README --- a/README Mon Jan 07 10:45:51 2008 -0800 +++ b/README Mon Jan 07 10:46:13 2008 -0800 @@ -21,7 +21,7 @@ Requirements: Requirements: - Pegasus or SFCB development headers - - libvirt 0.2.3 or greater + - libvirt 0.3.2 or greater - e2fsprogs-devel - libxml2 - libcmpiutil (http://libvirt.org/hg/libcmpiutil) From danms at us.ibm.com Mon Jan 7 17:50:27 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 10:50:27 -0700 Subject: [Libvirt-cim] [PATCH] Fix 32-bit compile issue in xml_parse_test Message-ID: # HG changeset patch # User Dan Smith # Date 1199731790 28800 # Node ID d5ac4e8e1c2b14c00a4edc96b9909471fef3b5b7 # Parent b64e8fda92bffa03bde3dc8c05dc320e2a515de3 Fix 32-bit compile issue in xml_parse_test Signed-off-by: Dan Smith diff -r b64e8fda92bf -r d5ac4e8e1c2b libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Mon Jan 07 10:46:13 2008 -0800 +++ b/libxkutil/xml_parse_test.c Mon Jan 07 10:49:50 2008 -0800 @@ -1,4 +1,5 @@ #include +#include #include @@ -12,7 +13,7 @@ static void print_value(FILE *d, const c static void print_u64(FILE *d, const char *name, uint64_t val) { - fprintf(d, "%-15s: %lu\n", name, val); + fprintf(d, "%-15s: %" PRIu64 "\n", name, val); } static void print_os(struct domain *dom, From kaitlin at linux.vnet.ibm.com Mon Jan 7 19:43:02 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 11:43:02 -0800 Subject: [Libvirt-cim] [PATCH] Fix get_graphics_device() - returns error if graphics tag is missing Message-ID: # HG changeset patch # User Kaitlin Rupert # Date 1199734960 28800 # Node ID abcb596636c9530009756b1aa1e8900a2f01d10e # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 Fix get_graphics_device() - returns error if graphics tag is missing. The graphics tag isn't mandatory, so we shouldn't return an error here. The same problem exists with get_emu_device(). Signed-off-by: Kaitlin Rupert diff -r ea65740aa1ff -r abcb596636c9 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:44 2008 -0800 +++ b/libxkutil/device_parsing.c Mon Jan 07 11:42:40 2008 -0800 @@ -395,7 +395,7 @@ static int get_emu_device(virDomainPtr d free(xml); - return ret; + return 1; } static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) @@ -416,7 +416,7 @@ static int get_graphics_device(virDomain free(xml); - return ret; + return 1; } int get_disk_devices(virDomainPtr dom, struct virt_device **list) From kaitlin at linux.vnet.ibm.com Mon Jan 7 19:49:05 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 11:49:05 -0800 Subject: [Libvirt-cim] [PATCH] .#2 Fix up style issues in device_parsing.c In-Reply-To: <0306c8af0a5f5d585d22.1199731557@theine> References: <0306c8af0a5f5d585d22.1199731557@theine> Message-ID: <47828231.70300@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199731551 28800 > # Node ID 0306c8af0a5f5d585d223fb1fde5dd04961bbce6 > # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 > .#2 Fix up style issues in device_parsing.c > Looks sound to me. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 7 19:52:44 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 11:52:44 -0800 Subject: [Libvirt-cim] [PATCH] Fix libvirt version mentioned in README In-Reply-To: References: Message-ID: <4782830C.1030501@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199731573 28800 > # Node ID b64e8fda92bffa03bde3dc8c05dc320e2a515de3 > # Parent 0306c8af0a5f5d585d223fb1fde5dd04961bbce6 > Fix libvirt version mentioned in README > > Signed-off-by: Dan Smith > > diff -r 0306c8af0a5f -r b64e8fda92bf README > --- a/README Mon Jan 07 10:45:51 2008 -0800 > +++ b/README Mon Jan 07 10:46:13 2008 -0800 > @@ -21,7 +21,7 @@ Requirements: > Requirements: > > - Pegasus or SFCB development headers > - - libvirt 0.2.3 or greater > + - libvirt 0.3.2 or greater Sounds sensible to have the correct version in the README =) Good find. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 7 19:54:25 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 11:54:25 -0800 Subject: [Libvirt-cim] [PATCH] Fix 32-bit compile issue in xml_parse_test In-Reply-To: References: Message-ID: <47828371.8040402@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199731790 28800 > # Node ID d5ac4e8e1c2b14c00a4edc96b9909471fef3b5b7 > # Parent b64e8fda92bffa03bde3dc8c05dc320e2a515de3 > Fix 32-bit compile issue in xml_parse_test > > Signed-off-by: Dan Smith > > diff -r b64e8fda92bf -r d5ac4e8e1c2b libxkutil/xml_parse_test.c > --- a/libxkutil/xml_parse_test.c Mon Jan 07 10:46:13 2008 -0800 > +++ b/libxkutil/xml_parse_test.c Mon Jan 07 10:49:50 2008 -0800 > @@ -1,4 +1,5 @@ > #include > +#include > > #include > > @@ -12,7 +13,7 @@ static void print_value(FILE *d, const c > > static void print_u64(FILE *d, const char *name, uint64_t val) > { > - fprintf(d, "%-15s: %lu\n", name, val); > + fprintf(d, "%-15s: %" PRIu64 "\n", name, val); > } Looks reasonable. =) +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:19:44 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:19:44 -0800 Subject: [Libvirt-cim] [PATCH 3 of 4] Replace printf() with CU_DEBUG in VSMgmtService In-Reply-To: Message-ID: # HG changeset patch # User Kaitlin Rupert # Date 1199740361 28800 # Node ID aecc7eb40e68ea06e9e5e3a5b80deac1c34af5eb # Parent 87362d52572b34fd880d28b76bdfb021a507cbd6 Replace printf() with CU_DEBUG in VSMgmtService. Signed-off-by: Kaitlin Rupert diff -r 87362d52572b -r aecc7eb40e68 src/Virt_VirtualSystemManagementService.c --- a/src/Virt_VirtualSystemManagementService.c Mon Jan 07 13:11:19 2008 -0800 +++ b/src/Virt_VirtualSystemManagementService.c Mon Jan 07 13:12:41 2008 -0800 @@ -513,7 +513,7 @@ static CMPIStatus update_system_settings xml = system_to_xml(dominfo); if (xml != NULL) { - printf("New XML is:\n%s\n", xml); + CU_DEBUG("New XML is:\n%s", xml); connect_and_create(xml, ref, &s); } @@ -848,7 +848,7 @@ static CMPIStatus _update_resources_for( xml = system_to_xml(dominfo); if (xml != NULL) { - printf("New XML:\n%s\n", xml); + CU_DEBUG("New XML:\n%s", xml); connect_and_create(xml, ref, &s); } else { cu_statusf(_BROKER, &s, From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:19:43 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:19:43 -0800 Subject: [Libvirt-cim] [PATCH 2 of 4] Replace printfs with CU_DEBUG in ComputerSystem In-Reply-To: Message-ID: <87362d52572b34fd880d.1199740783@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199740279 28800 # Node ID 87362d52572b34fd880d28b76bdfb021a507cbd6 # Parent 7281142059a1c419405addd2ba351c68fb719ff0 Replace printfs with CU_DEBUG in ComputerSystem. Signed-off-by: Kaitlin Rupert diff -r 7281142059a1 -r 87362d52572b src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Mon Jan 07 13:10:40 2008 -0800 +++ b/src/Virt_ComputerSystem.c Mon Jan 07 13:11:19 2008 -0800 @@ -482,15 +482,15 @@ static CMPIStatus state_change_enable(vi switch (info->state) { case VIR_DOMAIN_SHUTOFF: - printf("Start domain\n"); + CU_DEBUG("Start domain"); ret = virDomainCreate(dom); break; case VIR_DOMAIN_PAUSED: - printf("Unpause domain\n"); + CU_DEBUG("Unpause domain"); ret = virDomainResume(dom); break; default: - printf("Cannot go to enabled state from %i\n", info->state); + CU_DEBUG("Cannot go to enabled state from %i", info->state); cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Invalid state transition"); @@ -511,11 +511,11 @@ static CMPIStatus state_change_disable(v switch (info->state) { case VIR_DOMAIN_RUNNING: - printf("Stop domain\n"); + CU_DEBUG("Stop domain"); ret = virDomainShutdown(dom); break; default: - printf("Cannot go to disabled state from %i\n", info->state); + CU_DEBUG("Cannot go to disabled state from %i", info->state); cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Invalid state transition"); @@ -536,7 +536,7 @@ static CMPIStatus state_change_pause(vir switch (info->state) { case VIR_DOMAIN_RUNNING: - printf("Pause domain\n"); + CU_DEBUG("Pause domain"); ret = virDomainSuspend(dom); break; default: @@ -560,7 +560,7 @@ static CMPIStatus state_change_reboot(vi switch (info->state) { case VIR_DOMAIN_RUNNING: - printf("Reboot domain\n"); + CU_DEBUG("Reboot domain"); ret = virDomainReboot(dom, 0); break; default: @@ -584,7 +584,7 @@ static CMPIStatus state_change_reset(vir switch (info->state) { case VIR_DOMAIN_RUNNING: - printf("Reset domain\n"); + CU_DEBUG("Reset domain"); ret = domain_reset(dom); break; default: From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:19:42 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:19:42 -0800 Subject: [Libvirt-cim] [PATCH 1 of 4] Replace printf() with CU_DEBUG in EAFP In-Reply-To: Message-ID: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199740240 28800 # Node ID 7281142059a1c419405addd2ba351c68fb719ff0 # Parent abcb596636c9530009756b1aa1e8900a2f01d10e Replace printf() with CU_DEBUG in EAFP. Signed-off-by: Kaitlin Rupert diff -r abcb596636c9 -r 7281142059a1 src/Virt_ElementAllocatedFromPool.c --- a/src/Virt_ElementAllocatedFromPool.c Mon Jan 07 11:42:40 2008 -0800 +++ b/src/Virt_ElementAllocatedFromPool.c Mon Jan 07 13:10:40 2008 -0800 @@ -135,7 +135,7 @@ static int filter_by_pool(struct inst_li if ((dev_id == NULL) || (cn == NULL)) continue; - printf("Device %hhi:%s", type, dev_id); + CU_DEBUG("Device %hhi:%s", type, dev_id); poolid = pool_member_of(_BROKER, cn, type, dev_id); if (poolid && STREQ(poolid, _poolid)) @@ -162,11 +162,11 @@ static int devs_from_pool(uint16_t type, if (conn == NULL) return 0; - printf("Connected\n"); + CU_DEBUG("Connected"); count = get_domain_list(conn, &doms); - printf("Got %i domains\n", count); + CU_DEBUG("Got %i domains", count); for (i = 0; i < count; i++) { const char *name; @@ -179,11 +179,11 @@ static int devs_from_pool(uint16_t type, /* FIXME: Get VIRT_DEV_ type here */ dom_devices(_BROKER, doms[i], ns, type, &tmp); - printf("Got devices\n"); + CU_DEBUG("Got devices"); filter_by_pool(list, &tmp, type, poolid); - printf("Filtered\n"); + CU_DEBUG("Filtered"); inst_list_free(&tmp); virDomainFree(doms[i]); From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:19:41 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:19:41 -0800 Subject: [Libvirt-cim] [PATCH 0 of 4] Replace printfs with CU_DEBUG. Message-ID: This patchset cleans up some extraneous printfs. They are replaced with CU_DEBUG statements. From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:19:45 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:19:45 -0800 Subject: [Libvirt-cim] [PATCH 4 of 4] Replace printf() with CU_DEBUG in ComputerSystemIndication In-Reply-To: Message-ID: # HG changeset patch # User Kaitlin Rupert # Date 1199740491 28800 # Node ID d249e26d9d545455465e1f6fc2f03f160f3c8704 # Parent aecc7eb40e68ea06e9e5e3a5b80deac1c34af5eb Replace printf() with CU_DEBUG in ComputerSystemIndication. Signed-off-by: Kaitlin Rupert diff -r aecc7eb40e68 -r d249e26d9d54 src/Virt_ComputerSystemIndication.c --- a/src/Virt_ComputerSystemIndication.c Mon Jan 07 13:12:41 2008 -0800 +++ b/src/Virt_ComputerSystemIndication.c Mon Jan 07 13:14:51 2008 -0800 @@ -76,20 +76,20 @@ static bool _lifecycle_indication(const type, NAMESPACE(newsystem)); if (ind == NULL) { - printf("Failed to create ind\n"); + CU_DEBUG("Failed to create ind"); return false; } ind_op = CMGetObjectPath(ind, &s); if (s.rc != CMPI_RC_OK) { - printf("Failed to get ind_op\n"); + CU_DEBUG("Failed to get ind_op"); return false; } CMSetProperty(ind, "AffectedSystem", (CMPIValue *)&newsystem, CMPI_ref); - printf("Delivering Indication: %s\n", + CU_DEBUG("Delivering Indication: %s", CMGetCharPtr(CMObjectPathToString(ind_op, NULL))); CBDeliverIndication(_BROKER, @@ -160,7 +160,7 @@ static bool async_ind(CMPIContext *conte op = CMNewObjectPath(_BROKER, ns, type_cn, &s); } else { - printf("Unknown event type: %i\n", type); + CU_DEBUG("Unknown event type: %i", type); return false; } @@ -189,7 +189,7 @@ static CMPI_THREAD_RETURN lifecycle_thre conn = lv_connect(_BROKER, &s); if (conn == NULL) { - printf("Failed to connect: %s\n", CMGetCharPtr(s.msg)); + CU_DEBUG("Failed to connect: %s", CMGetCharPtr(s.msg)); return NULL; } @@ -271,7 +271,7 @@ static _EI_RTYPE EnableIndications(CMPII lifecycle_enabled = true; pthread_mutex_unlock(&lifecycle_mutex); - printf("ComputerSystemIndication enabled\n"); + CU_DEBUG("ComputerSystemIndication enabled"); _EI_RET(); } @@ -283,7 +283,7 @@ static _EI_RTYPE DisableIndications(CMPI lifecycle_enabled = false; pthread_mutex_unlock(&lifecycle_mutex); - printf("ComputerSystemIndication disabled\n"); + CU_DEBUG("ComputerSystemIndication disabled"); _EI_RET(); } From kaitlin at linux.vnet.ibm.com Mon Jan 7 21:23:05 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 07 Jan 2008 13:23:05 -0800 Subject: [Libvirt-cim] [PATCH] Remove TRACE #define from SystemDevice Message-ID: <27f3530502b64573ec30.1199740985@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199740963 28800 # Node ID 27f3530502b64573ec300807453851e2efa39b53 # Parent d249e26d9d545455465e1f6fc2f03f160f3c8704 Remove TRACE #define from SystemDevice. This doesn't appear to be used anymore. Signed-off-by: Kaitlin Rupert diff -r d249e26d9d54 -r 27f3530502b6 src/Virt_SystemDevice.c --- a/src/Virt_SystemDevice.c Mon Jan 07 13:14:51 2008 -0800 +++ b/src/Virt_SystemDevice.c Mon Jan 07 13:22:43 2008 -0800 @@ -55,8 +55,6 @@ const static int device_types[DEV_TYPE_C VIRT_DEV_MEM, VIRT_DEV_VCPU, }; - -#define TRACE(l, f, arg...) printf(f "\n", ##arg) static int get_dom_devices(const char *name, struct inst_list *list, From danms at us.ibm.com Mon Jan 7 23:55:52 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 15:55:52 -0800 Subject: [Libvirt-cim] [PATCH] Fix libvirt version mentioned in README In-Reply-To: <4782830C.1030501@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Mon, 07 Jan 2008 11:52:44 -0800") References: <4782830C.1030501@linux.vnet.ibm.com> Message-ID: <87r6gt2nsn.fsf@theine.beaverton.ibm.com> KR> Sounds sensible to have the correct version in the README =) Good KR> find. +1 I can't claim it, a Fedora reviewer complained about the mismatch between the readme and the spec :) -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Mon Jan 7 23:58:05 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 15:58:05 -0800 Subject: [Libvirt-cim] [PATCH 1 of 4] Replace printf() with CU_DEBUG in EAFP In-Reply-To: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> (Kaitlin Rupert's message of "Mon, 07 Jan 2008 13:19:42 -0800") References: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> Message-ID: <87myrh2noy.fsf@theine.beaverton.ibm.com> KR> # HG changeset patch KR> # User Kaitlin Rupert KR> # Date 1199740240 28800 KR> # Node ID 7281142059a1c419405addd2ba351c68fb719ff0 KR> # Parent abcb596636c9530009756b1aa1e8900a2f01d10e KR> Replace printf() with CU_DEBUG in EAFP. I'm all for cleanups of this fashion. However, KR> - printf("Device %hhi:%s", type, dev_id); KR> + CU_DEBUG("Device %hhi:%s", type, dev_id); This looks like crufty debug that uses a platform-dependent bit-width anyway. This and the rest in this file should probably be excised instead of formalized. What do you think? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Tue Jan 8 00:00:27 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 07 Jan 2008 16:00:27 -0800 Subject: [Libvirt-cim] [PATCH] Remove TRACE #define from SystemDevice In-Reply-To: <27f3530502b64573ec30.1199740985@elm3b41.beaverton.ibm.com> (Kaitlin Rupert's message of "Mon, 07 Jan 2008 13:23:05 -0800") References: <27f3530502b64573ec30.1199740985@elm3b41.beaverton.ibm.com> Message-ID: <87ir252nl0.fsf@theine.beaverton.ibm.com> KR> # HG changeset patch KR> # User Kaitlin Rupert KR> # Date 1199740963 28800 KR> # Node ID 27f3530502b64573ec300807453851e2efa39b53 KR> # Parent d249e26d9d545455465e1f6fc2f03f160f3c8704 KR> Remove TRACE #define from SystemDevice. KR> This doesn't appear to be used anymore. Yeah, that's really old. I put that in because SystemDevice was the most complicated provider we had at the time, and we hadn't worked out what to do for logging yet. Thanks for catching it! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From heidieck at linux.vnet.ibm.com Tue Jan 8 12:02:49 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 08 Jan 2008 13:02:49 +0100 Subject: [Libvirt-cim] [PATCH] Fix 32-bit compile issue in xml_parse_test In-Reply-To: References: Message-ID: <47836669.1030604@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199731790 28800 > # Node ID d5ac4e8e1c2b14c00a4edc96b9909471fef3b5b7 > # Parent b64e8fda92bffa03bde3dc8c05dc320e2a515de3 > Fix 32-bit compile issue in xml_parse_test > > Signed-off-by: Dan Smith > > Great - everything works fine now. Thanks :) -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 8 12:26:29 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 08 Jan 2008 13:26:29 +0100 Subject: [Libvirt-cim] [PATCH] Fix get_graphics_device() - returns error if graphics tag is missing In-Reply-To: References: Message-ID: <47836BF5.7050508@linux.vnet.ibm.com> Kaitlin Rupert wrote: > # HG changeset patch > # User Kaitlin Rupert > # Date 1199734960 28800 > # Node ID abcb596636c9530009756b1aa1e8900a2f01d10e > # Parent ea65740aa1ffe73b47a4a14c8a853dbb3f040016 > Fix get_graphics_device() - returns error if graphics tag is missing. > > The graphics tag isn't mandatory, so we shouldn't return an error here. > The same problem exists with get_emu_device(). > > Signed-off-by: Kaitlin Rupert > > diff -r ea65740aa1ff -r abcb596636c9 libxkutil/device_parsing.c > --- a/libxkutil/device_parsing.c Fri Jan 04 12:53:44 2008 -0800 > +++ b/libxkutil/device_parsing.c Mon Jan 07 11:42:40 2008 -0800 > @@ -395,7 +395,7 @@ static int get_emu_device(virDomainPtr d > > free(xml); > > - return ret; > + return 1; > } > > static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) > @@ -416,7 +416,7 @@ static int get_graphics_device(virDomain > > free(xml); > > - return ret; > + return 1; > } > > int get_disk_devices(virDomainPtr dom, struct virt_device **list) > > > If the return code of these two functions does not matter, couldn't we also make a void function out of them ? This could avoid the impression that the result of these functions matters for the return code of the calling function, like in get_dominfo(). -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 8 12:04:49 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 08 Jan 2008 14:04:49 +0200 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path Message-ID: <555126035e912e9202eb.1199797489@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1199797461 -3600 # Node ID 555126035e912e9202ebcc93483ee936be5ae998 # Parent 1bbea87ad37dcb95321f43aa5e17e6fa7ec1836d HS: returns results for wrong object path The client given reference was not checked for existance in both directions (from HostSystem to Service and reverse) and the call returned wrong results. Now NOT_FOUND is returned in case of a wrong object path. Examples: wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_ResourcePoolConfigurationService.CreationClassName="wrong",wrong="wrong"' wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="notthere"' Signed-off-by: Heidi Eckhart diff -r 1bbea87ad37d -r 555126035e91 src/Virt_HostedService.c --- a/src/Virt_HostedService.c Mon Jan 07 11:42:40 2008 -0800 +++ b/src/Virt_HostedService.c Tue Jan 08 14:04:21 2008 +0100 @@ -37,6 +37,57 @@ const static CMPIBroker *_BROKER; +static CMPIStatus check_host_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + + s = get_host_cs(_BROKER, ref, &inst); + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + return s; +} + +static CMPIStatus check_service_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + char* classname; + + classname = class_base_name(CLASSNAME(ref)); + + if (STREQC(classname, "VirtualSystemManagementService")) { + s = get_vsms(ref, &inst, _BROKER); + } + else if (STREQC(classname, "ResourcePoolConfigurationService")) { + s = rpcs_instance(ref, &inst, _BROKER); + } + else if (STREQC(classname, "VirtualSystemMigrationService")) { + s = get_migration_service(ref, &inst, _BROKER); + } + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + free(classname); + + return s; +} + static CMPIStatus service_to_host(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -47,6 +98,10 @@ static CMPIStatus service_to_host(const if (!match_hypervisor_prefix(ref, info)) return s; + s = check_service_ref(ref); + if (s.rc != CMPI_RC_OK) + return s; + s = get_host_cs(_BROKER, ref, &instance); if (s.rc == CMPI_RC_OK) inst_list_add(list, instance); @@ -62,6 +117,10 @@ static CMPIStatus host_to_service(const CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = check_host_ref(ref); + if (s.rc != CMPI_RC_OK) return s; s = rpcs_instance(ref, &inst, _BROKER); From heidieck at linux.vnet.ibm.com Tue Jan 8 13:07:41 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 08 Jan 2008 14:07:41 +0100 Subject: [Libvirt-cim] Xen_HostedService return expected queried result with non existing instance by two sides In-Reply-To: References: Message-ID: <4783759D.200@linux.vnet.ibm.com> Guo Lian Yun wrote: > > Hi, > > With a non existing instance, e.g. a wrong key name or value, > Xen_HostedService still return expected results below: > > wbemcli ain -ac Xen_HostedService > http://root:password at localhost/root/virt:Xen_ResourcePoolConfigurationService.wrong="wrong" > localhost:5988/root/virt:Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="zeit" > > wbemcli ain -ac Xen_HostedService > http://root:password at localhost/root/virt:Xen_HostSystem.CreationClassName="wrong",Wrong="zeit" > localhost:5988/root/virt:Xen_ResourcePoolConfigurationService.CreationClassName="Xen_ResourcePoolConfigurationService",Name="RPCS",SystemCreationClassName="Xen_HostSystem",SystemName="zei" > localhost:5988/root/virt:Xen_VirtualSystemManagementService.CreationClassName="Xen_VirtualSystemManagementService",Name="Management > Service",SystemCreationClassName="Xen_HostSystem",SystemName="zeit" > localhost:5988/root/virt:Xen_VirtualSystemMigrationService.CreationClassName="Xen_VirtualSystemMigrationService",Name="MigrationService",SystemCreationClassName="",SystemName="" > Daisy, thank you for reporting this bug. Very good finding :) ! The patch "HS: returns results for wrong object path" should fix this issue. Please can you verify it ? Thanks a lot. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From grendel at linux.vnet.ibm.com Tue Jan 8 14:07:04 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Tue, 08 Jan 2008 09:07:04 -0500 Subject: [Libvirt-cim] [PATCH 1 of 4] Replace printf() with CU_DEBUG in EAFP In-Reply-To: <87myrh2noy.fsf@theine.beaverton.ibm.com> References: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> <87myrh2noy.fsf@theine.beaverton.ibm.com> Message-ID: <47838388.1030204@linux.vnet.ibm.com> Dan Smith wrote: > KR> # HG changeset patch > KR> # User Kaitlin Rupert > KR> # Date 1199740240 28800 > KR> # Node ID 7281142059a1c419405addd2ba351c68fb719ff0 > KR> # Parent abcb596636c9530009756b1aa1e8900a2f01d10e > KR> Replace printf() with CU_DEBUG in EAFP. > > I'm all for cleanups of this fashion. However, > > KR> - printf("Device %hhi:%s", type, dev_id); > KR> + CU_DEBUG("Device %hhi:%s", type, dev_id); > > This looks like crufty debug that uses a platform-dependent bit-width > anyway. This and the rest in this file should probably be excised > instead of formalized. What do you think? > > I can't really comment on the necessity of these particular statements, but is there a way for use to print that value in a platform-independent way? -- -Jay From grendel at linux.vnet.ibm.com Tue Jan 8 14:12:26 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Tue, 08 Jan 2008 09:12:26 -0500 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path In-Reply-To: <555126035e912e9202eb.1199797489@localhost.localdomain> References: <555126035e912e9202eb.1199797489@localhost.localdomain> Message-ID: <478384CA.6090708@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1199797461 -3600 > # Node ID 555126035e912e9202ebcc93483ee936be5ae998 > # Parent 1bbea87ad37dcb95321f43aa5e17e6fa7ec1836d > HS: returns results for wrong object path > > The client given reference was not checked for existance in both > directions (from HostSystem to Service and reverse) and the call > returned wrong results. Now NOT_FOUND is returned in case of a > wrong object path. > > Examples: > wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_ResourcePoolConfigurationService.CreationClassName="wrong",wrong="wrong"' > wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="notthere"' > > Signed-off-by: Heidi Eckhart > > diff -r 1bbea87ad37d -r 555126035e91 src/Virt_HostedService.c > --- a/src/Virt_HostedService.c Mon Jan 07 11:42:40 2008 -0800 > +++ b/src/Virt_HostedService.c Tue Jan 08 14:04:21 2008 +0100 > @@ -37,6 +37,57 @@ > > + > +static CMPIStatus check_service_ref(const CMPIObjectPath *ref) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *inst; > + const char *prop; > + char* classname; > + > + classname = class_base_name(CLASSNAME(ref)); > + > + if (STREQC(classname, "VirtualSystemManagementService")) { > + s = get_vsms(ref, &inst, _BROKER); > + } > + else if (STREQC(classname, "ResourcePoolConfigurationService")) { > + s = rpcs_instance(ref, &inst, _BROKER); > + } > + else if (STREQC(classname, "VirtualSystemMigrationService")) { > + s = get_migration_service(ref, &inst, _BROKER); > + } > + if (s.rc != CMPI_RC_OK) > + return s; > Sorry for being so nitpicky, but for the sake of consistency I think this is a place where we use a "goto out;" type of statement as opposed to having multiple returns. > + > + prop = cu_compare_ref(ref, inst); > + if (prop != NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "No such instance (%s)", prop); > + } > + > Putting out right here should work fine. Actually, this is more than a nitpick I think, because if the above return happens we don't hit this free() and leak classname. > + free(classname); > + > + return s; > +} > -- -Jay From danms at us.ibm.com Tue Jan 8 14:56:18 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 06:56:18 -0800 Subject: [Libvirt-cim] [PATCH] Fix get_graphics_device() - returns error if graphics tag is missing In-Reply-To: (Kaitlin Rupert's message of "Mon, 07 Jan 2008 11:43:02 -0800") References: Message-ID: <87lk701i3x.fsf@theine.beaverton.ibm.com> KR> - return ret; KR> + return 1; This will cause the do_parse() function to keep an empty (and uninitialized) device struct on the list, because of this: > if (do_real_parse(dev_nodes[devidx], &list[lstidx])) > lstidx++; Which is bad. I think we need to keep the conditional return value From those individual functions. I think the problem lies just with this bit in get_dominfo(): > ret = get_emu_device(dom, &(*dominfo)->dev_emu); > ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); Which was me thinking that I'd capture the return value and maybe check it later, but ignore for now. The problem is that we return ret a few lines down, which makes the function fail if one of the two above calls fail. So, I think the solution here for now is to either do something meaningful with ret (not sure what that would be), or just remove 'ret =' from each call and truly ignore the status of those. Also, KR> - return ret; KR> + return 1; These functions now return a bool instead of an int. Maybe you need to update your tree? Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Tue Jan 8 15:04:56 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 07:04:56 -0800 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path In-Reply-To: <555126035e912e9202eb.1199797489@localhost.localdomain> (Heidi Eckhart's message of "Tue, 08 Jan 2008 14:04:49 +0200") References: <555126035e912e9202eb.1199797489@localhost.localdomain> Message-ID: <87hcho1hpj.fsf@theine.beaverton.ibm.com> HE> + if (STREQC(classname, "VirtualSystemManagementService")) { HE> + s = get_vsms(ref, &inst, _BROKER); HE> + } HE> + else if (STREQC(classname, "ResourcePoolConfigurationService")) { HE> + s = rpcs_instance(ref, &inst, _BROKER); HE> + } HE> + else if (STREQC(classname, "VirtualSystemMigrationService")) { HE> + s = get_migration_service(ref, &inst, _BROKER); HE> + } HE> + if (s.rc != CMPI_RC_OK) HE> + return s; This doesn't fit the style of the rest of the code. The "else if" statements should be on the same line as the closing brace, and there should be a blank line before the second and unrelated if. Otherwise, a good fix. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Tue Jan 8 15:07:21 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 07:07:21 -0800 Subject: [Libvirt-cim] [PATCH 1 of 4] Replace printf() with CU_DEBUG in EAFP In-Reply-To: <47838388.1030204@linux.vnet.ibm.com> (Jay Gagnon's message of "Tue, 08 Jan 2008 09:07:04 -0500") References: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> <87myrh2noy.fsf@theine.beaverton.ibm.com> <47838388.1030204@linux.vnet.ibm.com> Message-ID: <87d4sc1hli.fsf@theine.beaverton.ibm.com> JG> I can't really comment on the necessity of these particular JG> statements, but is there a way for use to print that value in a JG> platform-independent way? Yep, see inttypes.h. "%hhu" was intended to be a byte, so PRIu8 would be the appropriate selection here, used as follows: printf("Here is my byte: %" PRIu8 "\n", my_byte); -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Tue Jan 8 15:15:37 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 07:15:37 -0800 Subject: [Libvirt-cim] [PATCH] Fix get_graphics_device() - returns error if graphics tag is missing In-Reply-To: <87lk701i3x.fsf@theine.beaverton.ibm.com> References: <87lk701i3x.fsf@theine.beaverton.ibm.com> Message-ID: <47839399.1080906@linux.vnet.ibm.com> Dan Smith wrote: > KR> - return ret; > KR> + return 1; > > This will cause the do_parse() function to keep an empty (and > uninitialized) device struct on the list, because of this: > >> if (do_real_parse(dev_nodes[devidx], &list[lstidx])) >> lstidx++; Ah good point. Yep, I didn't notice this. > > Which is bad. I think we need to keep the conditional return value > From those individual functions. I think the problem lies just with > this bit in get_dominfo(): > >> ret = get_emu_device(dom, &(*dominfo)->dev_emu); >> ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); > > Which was me thinking that I'd capture the return value and maybe > check it later, but ignore for now. The problem is that we return ret > a few lines down, which makes the function fail if one of the two > above calls fail. > > So, I think the solution here for now is to either do something > meaningful with ret (not sure what that would be), or just remove > 'ret =' from each call and truly ignore the status of those. I'd vote for not capturing the return from the get_emu_device() and get_graphics_device() in get_dominfo(). Trying to handle the return in a meaningful way would probably not be obvious and would need a comment.. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Tue Jan 8 15:17:17 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 07:17:17 -0800 Subject: [Libvirt-cim] [PATCH 1 of 4] Replace printf() with CU_DEBUG in EAFP In-Reply-To: <87myrh2noy.fsf@theine.beaverton.ibm.com> References: <7281142059a1c419405a.1199740782@elm3b41.beaverton.ibm.com> <87myrh2noy.fsf@theine.beaverton.ibm.com> Message-ID: <478393FD.9080404@linux.vnet.ibm.com> Dan Smith wrote: > KR> # HG changeset patch > KR> # User Kaitlin Rupert > KR> # Date 1199740240 28800 > KR> # Node ID 7281142059a1c419405addd2ba351c68fb719ff0 > KR> # Parent abcb596636c9530009756b1aa1e8900a2f01d10e > KR> Replace printf() with CU_DEBUG in EAFP. > > I'm all for cleanups of this fashion. However, > > KR> - printf("Device %hhi:%s", type, dev_id); > KR> + CU_DEBUG("Device %hhi:%s", type, dev_id); > > This looks like crufty debug that uses a platform-dependent bit-width > anyway. This and the rest in this file should probably be excised > instead of formalized. What do you think? This is a good point. I'll generate a new patch. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Tue Jan 8 15:48:56 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 07:48:56 -0800 Subject: [Libvirt-cim] [PATCH] .#2 Fix get_graphics_device() - returns error if graphics tag is missing Message-ID: <021caa2990b499190a11.1199807336@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199807288 28800 # Node ID 021caa2990b499190a1123727ee52e2d6eaff209 # Parent a5fb6fa9273db7c073a42622ba14a7a0c25e4d01 .#2 Fix get_graphics_device() - returns error if graphics tag is missing. Update: Instead of returning a constant 1 from get_graphics_device() and get_emu_device(), keep the return value as is. Don't capture the return value of these functions in get_dominfo(). The graphics tag isn't mandatory, so we shouldn't capture an error in get_dominfo(). The same problem exists with get_emu_device(). Signed-off-by: Kaitlin Rupert diff -r a5fb6fa9273d -r 021caa2990b4 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Mon Jan 07 13:22:43 2008 -0800 +++ b/libxkutil/device_parsing.c Tue Jan 08 07:48:08 2008 -0800 @@ -719,8 +719,8 @@ int get_dominfo(virDomainPtr dom, struct goto out; } - ret = get_emu_device(dom, &(*dominfo)->dev_emu); - ret = get_graphics_device(dom, &(*dominfo)->dev_graphics); + get_emu_device(dom, &(*dominfo)->dev_emu); + get_graphics_device(dom, &(*dominfo)->dev_graphics); (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); From kaitlin at linux.vnet.ibm.com Tue Jan 8 15:58:57 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 07:58:57 -0800 Subject: [Libvirt-cim] [PATCH] .#2 Replace printf() with CU_DEBUG in EAFP Message-ID: <1bc8313927de11949fbc.1199807937@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199807895 28800 # Node ID 1bc8313927de11949fbc17b163bc838d754553b7 # Parent 021caa2990b499190a1123727ee52e2d6eaff209 .#2 Replace printf() with CU_DEBUG in EAFP. Update - removed platform-dependent bit-width values and an extraneous "\n". Signed-off-by: Kaitlin Rupert diff -r 021caa2990b4 -r 1bc8313927de src/Virt_ElementAllocatedFromPool.c --- a/src/Virt_ElementAllocatedFromPool.c Tue Jan 08 07:48:08 2008 -0800 +++ b/src/Virt_ElementAllocatedFromPool.c Tue Jan 08 07:58:15 2008 -0800 @@ -135,7 +135,7 @@ static int filter_by_pool(struct inst_li if ((dev_id == NULL) || (cn == NULL)) continue; - printf("Device %hhi:%s", type, dev_id); + CU_DEBUG("Got DeviceID: %s", dev_id); poolid = pool_member_of(_BROKER, cn, type, dev_id); if (poolid && STREQ(poolid, _poolid)) @@ -162,11 +162,11 @@ static int devs_from_pool(uint16_t type, if (conn == NULL) return 0; - printf("Connected\n"); + CU_DEBUG("Connected"); count = get_domain_list(conn, &doms); - printf("Got %i domains\n", count); + CU_DEBUG("Got %i domains", count); for (i = 0; i < count; i++) { const char *name; @@ -179,11 +179,11 @@ static int devs_from_pool(uint16_t type, /* FIXME: Get VIRT_DEV_ type here */ dom_devices(_BROKER, doms[i], ns, type, &tmp); - printf("Got devices\n"); + CU_DEBUG("Got devices"); filter_by_pool(list, &tmp, type, poolid); - printf("Filtered\n"); + CU_DEBUG("Filtered"); inst_list_free(&tmp); virDomainFree(doms[i]); @@ -214,7 +214,7 @@ static CMPIStatus pool_to_vdev(const CMP goto out; } - CU_DEBUG("Got %s\n", poolid); + CU_DEBUG("Got %s", poolid); type = device_type_from_poolid(poolid); if (type == VIRT_DEV_UNKNOWN) { From kaitlin at linux.vnet.ibm.com Tue Jan 8 16:19:14 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 08:19:14 -0800 Subject: [Libvirt-cim] [PATCH] .#3 Replace printf() with CU_DEBUG in EAFP Message-ID: <39bab8bae81e4bc10208.1199809154@elm3b41.beaverton.ibm.com> # HG changeset patch # User Kaitlin Rupert # Date 1199808925 28800 # Node ID 39bab8bae81e4bc102085144cea5f8c4016fde69 # Parent 021caa2990b499190a1123727ee52e2d6eaff209 .#3 Replace printf() with CU_DEBUG in EAFP. Update - removed unnecessary printfs. Signed-off-by: Kaitlin Rupert diff -r 021caa2990b4 -r 39bab8bae81e src/Virt_ElementAllocatedFromPool.c --- a/src/Virt_ElementAllocatedFromPool.c Tue Jan 08 07:48:08 2008 -0800 +++ b/src/Virt_ElementAllocatedFromPool.c Tue Jan 08 08:15:25 2008 -0800 @@ -135,8 +135,6 @@ static int filter_by_pool(struct inst_li if ((dev_id == NULL) || (cn == NULL)) continue; - printf("Device %hhi:%s", type, dev_id); - poolid = pool_member_of(_BROKER, cn, type, dev_id); if (poolid && STREQ(poolid, _poolid)) inst_list_add(dest, inst); @@ -162,12 +160,8 @@ static int devs_from_pool(uint16_t type, if (conn == NULL) return 0; - printf("Connected\n"); - count = get_domain_list(conn, &doms); - printf("Got %i domains\n", count); - for (i = 0; i < count; i++) { const char *name; struct inst_list tmp; @@ -179,11 +173,7 @@ static int devs_from_pool(uint16_t type, /* FIXME: Get VIRT_DEV_ type here */ dom_devices(_BROKER, doms[i], ns, type, &tmp); - printf("Got devices\n"); - filter_by_pool(list, &tmp, type, poolid); - - printf("Filtered\n"); inst_list_free(&tmp); virDomainFree(doms[i]); From danms at us.ibm.com Tue Jan 8 17:53:18 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 10:53:18 -0700 Subject: [Libvirt-cim] [PATCH] Fix virt_device_dup() for emu and graphics devices Message-ID: <10d141f683370b6f0463.1199818398@theine> # HG changeset patch # User Dan Smith # Date 1199818304 28800 # Node ID 10d141f683370b6f04637bb9ad059bbd92051ce0 # Parent 85213a968ca3b6e86b03287c3cf7355d54f62165 Fix virt_device_dup() for emu and graphics devices Signed-off-by: Dan Smith diff -r 85213a968ca3 -r 10d141f68337 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Tue Jan 08 08:15:25 2008 -0800 +++ b/libxkutil/device_parsing.c Tue Jan 08 10:51:44 2008 -0800 @@ -395,6 +395,11 @@ struct virt_device *virt_device_dup(stru dev->dev.vcpu.state = _dev->dev.vcpu.state; dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; + } else if (dev->type == VIRT_DEV_EMU) { + DUP_FIELD(dev, _dev, dev.emu.path); + } else if (dev->type == VIRT_DEV_GRAPHICS) { + DUP_FIELD(dev, _dev, dev.graphics.type); + DUP_FIELD(dev, _dev, dev.graphics.port); } return dev; From kaitlin at linux.vnet.ibm.com Tue Jan 8 20:50:08 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 12:50:08 -0800 Subject: [Libvirt-cim] [PATCH] Fix virt_device_dup() for emu and graphics devices In-Reply-To: <10d141f683370b6f0463.1199818398@theine> References: <10d141f683370b6f0463.1199818398@theine> Message-ID: <4783E200.6090305@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199818304 28800 > # Node ID 10d141f683370b6f04637bb9ad059bbd92051ce0 > # Parent 85213a968ca3b6e86b03287c3cf7355d54f62165 > Fix virt_device_dup() for emu and graphics devices > > Signed-off-by: Dan Smith > > diff -r 85213a968ca3 -r 10d141f68337 libxkutil/device_parsing.c > --- a/libxkutil/device_parsing.c Tue Jan 08 08:15:25 2008 -0800 > +++ b/libxkutil/device_parsing.c Tue Jan 08 10:51:44 2008 -0800 > @@ -395,6 +395,11 @@ struct virt_device *virt_device_dup(stru > dev->dev.vcpu.state = _dev->dev.vcpu.state; > dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; > dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; > + } else if (dev->type == VIRT_DEV_EMU) { > + DUP_FIELD(dev, _dev, dev.emu.path); > + } else if (dev->type == VIRT_DEV_GRAPHICS) { > + DUP_FIELD(dev, _dev, dev.graphics.type); > + DUP_FIELD(dev, _dev, dev.graphics.port); > } > > return dev; Good catch. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Tue Jan 8 20:24:05 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 13:24:05 -0700 Subject: [Libvirt-cim] [PATCH 3 of 3] Change behavior to get VCPU information from XML like other devices In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199827433 28800 # Node ID ebc8d09b3be6c1f1fe5b5a7ff865037298cd9f48 # Parent 3e5265023ddda5cfa24e7449c9f06bbd7dcaba5c Change behavior to get VCPU information from XML like other devices This is necessary for us to be able to show VCPU devices when a domain is offline. Signed-off-by: Dan Smith diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 @@ -36,6 +36,7 @@ #include "../src/svpc_types.h" #define DISK_XPATH (xmlChar *)"/domain/devices/disk" +#define VCPU_XPATH (xmlChar *)"/domain/vcpu" #define NET_XPATH (xmlChar *)"/domain/devices/interface" #define EMU_XPATH (xmlChar *)"/domain/devices/emulator" #define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" @@ -239,6 +240,45 @@ static int parse_net_device(xmlNode *ino return 0; } +static int parse_vcpu_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *list = NULL; + char *count_str; + int count; + int i; + + count_str = get_node_content(node); + if (count_str == NULL) + count = 1; /* Default to 1 VCPU if non specified */ + else if (sscanf(count_str, "%i", &count) != 1) + count = 1; /* Default to 1 VCPU if garbage */ + + free(count_str); + + list = calloc(count, sizeof(*list)); + if (list == NULL) + goto err; + + for (i = 0; i < count; i++) { + struct virt_device *vdev = &list[i]; + struct vcpu_device *cdev = &vdev->dev.vcpu; + + cdev->number = i; + + vdev->type = VIRT_DEV_VCPU; + if (asprintf(&vdev->id, "%i", i) == -1) + vdev->id = NULL; + } + + *vdevs = list; + + return count; + err: + free(list); + + return 0; +} + static int parse_emu_device(xmlNode *node, struct virt_device **vdevs) { struct virt_device *vdev = NULL; @@ -322,6 +362,8 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = &parse_net_device; else if (type == VIRT_DEV_DISK) do_real_parse = &parse_disk_device; + else if (type == VIRT_DEV_VCPU) + do_real_parse = parse_vcpu_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; else if (type == VIRT_DEV_GRAPHICS) @@ -386,6 +428,8 @@ static int parse_devices(char *xml, stru xpathstr = NET_XPATH; else if (type == VIRT_DEV_DISK) xpathstr = DISK_XPATH; + else if (type == VIRT_DEV_VCPU) + xpathstr = VCPU_XPATH; else if (type == VIRT_DEV_EMU) xpathstr = EMU_XPATH; else if (type == VIRT_DEV_GRAPHICS) @@ -446,9 +490,6 @@ struct virt_device *virt_device_dup(stru dev->dev.mem.maxsize = _dev->dev.mem.maxsize; } else if (dev->type == VIRT_DEV_VCPU) { dev->dev.vcpu.number = _dev->dev.vcpu.number; - dev->dev.vcpu.state = _dev->dev.vcpu.state; - dev->dev.vcpu.cpuTime = _dev->dev.vcpu.cpuTime; - dev->dev.vcpu.cpu = _dev->dev.vcpu.cpu; } else if (dev->type == VIRT_DEV_EMU) { DUP_FIELD(dev, _dev, dev.emu.path); } else if (dev->type == VIRT_DEV_GRAPHICS) { @@ -573,42 +614,17 @@ int get_mem_devices(virDomainPtr dom, st int get_vcpu_devices(virDomainPtr dom, struct virt_device **list) { - int i, rc, ret, num_filled, num_vcpus; - virDomainInfo dom_info; - virVcpuInfoPtr vcpu_info = NULL; - struct virt_device *ret_list = NULL; - - rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1) { - ret = -1; - goto out1; - } - - num_vcpus = dom_info.nrVirtCpu; - vcpu_info = calloc(num_vcpus, sizeof(virVcpuInfo)); - num_filled = virDomainGetVcpus(dom, vcpu_info, num_vcpus, NULL, 0); - if (num_vcpus != num_filled) { - ret = -1; - goto out2; - } - - ret_list = calloc(num_vcpus, sizeof(struct virt_device)); - for (i = 0; i < num_vcpus; i++) { - ret_list[i].type = VIRT_DEV_VCPU; - ret_list[i].dev.vcpu = vcpu_info[i]; - if (asprintf(&ret_list[i].id, "%d", - vcpu_info[i].number) == -1) { - ret = -1; - free(ret_list); - goto out2; - } - } - - ret = num_vcpus; - *list = ret_list; - out2: - free(vcpu_info); - out1: + char *xml; + int ret; + + xml = virDomainGetXMLDesc(dom, 0); + if (xml == NULL) + return 0; + + ret = parse_devices(xml, list, VIRT_DEV_VCPU); + + free(xml); + return ret; } diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/device_parsing.h Tue Jan 08 13:23:53 2008 -0800 @@ -49,6 +49,10 @@ struct mem_device { uint64_t maxsize; }; +struct vcpu_device { + uint32_t number; +}; + struct emu_device { char *path; }; @@ -72,7 +76,7 @@ struct virt_device { struct disk_device disk; struct net_device net; struct mem_device mem; - struct _virVcpuInfo vcpu; + struct vcpu_device vcpu; struct emu_device emu; struct graphics_device graphics; } dev; diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 @@ -14,6 +14,11 @@ static void print_u64(FILE *d, const cha static void print_u64(FILE *d, const char *name, uint64_t val) { fprintf(d, "%-15s: %" PRIu64 "\n", name, val); +} + +static void print_u32(FILE *d, const char *name, uint32_t val) +{ + fprintf(d, "%-15s: %" PRIu32 "\n", name, val); } static void print_os(struct domain *dom, @@ -84,7 +89,7 @@ static void print_dev_vcpu(struct virt_d static void print_dev_vcpu(struct virt_device *dev, FILE *d) { - print_value(d, "Virtual CPU", "Present"); + print_u32(d, "Virtual CPU", dev->dev.vcpu.number); } static void print_dev_emu(struct virt_device *dev, diff -r 3e5265023ddd -r ebc8d09b3be6 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/xmlgen.c Tue Jan 08 13:23:53 2008 -0800 @@ -163,7 +163,7 @@ static char *net_to_xml(struct net_devic return xml; } -static char *proc_to_xml(struct _virVcpuInfo *proc) +static char *proc_to_xml(struct vcpu_device *proc) { return strdup(""); } diff -r 3e5265023ddd -r ebc8d09b3be6 src/Virt_Device.c --- a/src/Virt_Device.c Tue Jan 08 13:23:53 2008 -0800 +++ b/src/Virt_Device.c Tue Jan 08 13:23:53 2008 -0800 @@ -187,7 +187,7 @@ static CMPIInstance *mem_instance(const } static CMPIInstance *vcpu_instance(const CMPIBroker *broker, - struct _virVcpuInfo *dev, + struct vcpu_device *dev, const virDomainPtr dom, const char *ns) { From danms at us.ibm.com Tue Jan 8 20:24:03 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 13:24:03 -0700 Subject: [Libvirt-cim] [PATCH 1 of 3] Fix xml_parse_test if no emulator is defined In-Reply-To: Message-ID: <7272934dc44185bef392.1199827443@theine> # HG changeset patch # User Dan Smith # Date 1199827433 28800 # Node ID 7272934dc44185bef3923c86fa19961d299518fd # Parent 10d141f683370b6f04637bb9ad059bbd92051ce0 Fix xml_parse_test if no emulator is defined Signed-off-by: Dan Smith diff -r 10d141f68337 -r 7272934dc441 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Tue Jan 08 10:51:44 2008 -0800 +++ b/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 @@ -121,7 +121,7 @@ static void print_devices(struct domain for (i = 0; i < dominfo->dev_vcpu_ct; i++) print_dev_vcpu(&dominfo->dev_vcpu[i], d); - if (dominfo->type != DOMAIN_XENPV) { + if ((dominfo->type != DOMAIN_XENPV) && (dominfo->dev_emu)) { fprintf(d, "\n-- Emulator --\n"); print_dev_emu(dominfo->dev_emu, d); } From danms at us.ibm.com Tue Jan 8 20:24:02 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 13:24:02 -0700 Subject: [Libvirt-cim] [PATCH 0 of 3] Fix offline VCPU representation Message-ID: Currently, we cannot present information and instances for VCPUs when a domain is powered off, because virDomainGetInfo() does not work unless a domain is running. This set ultimately changes the vcpu bits in device_parsing to, that's right, actually *parse* the VCPU information from the XML like all the other devices, which gives us VCPU information for offline domains. To get there, I had to make the core of device_parsing a little more dyanmic so that the parsing modules could return mulitple devices for a given XML cycle, which vcpu needs. From danms at us.ibm.com Tue Jan 8 20:24:04 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 08 Jan 2008 13:24:04 -0700 Subject: [Libvirt-cim] [PATCH 2 of 3] Allow device_parsing modules to return multiple devices per cycle In-Reply-To: Message-ID: <3e5265023ddda5cfa24e.1199827444@theine> # HG changeset patch # User Dan Smith # Date 1199827433 28800 # Node ID 3e5265023ddda5cfa24e7449c9f06bbd7dcaba5c # Parent 7272934dc44185bef3923c86fa19961d299518fd Allow device_parsing modules to return multiple devices per cycle Do this by growing the device list during the cycle instead of trying to predict it ahead of time based on the numbers of nodes in the XML tree. This could be a little nicer with a more integrated list structure or a linked-list of some kind, but this is the smallest change to accomplish the goal, which I think is a good idea for now. The need for this is apparent in the next patch for vcpu parsing. Signed-off-by: Dan Smith diff -r 7272934dc441 -r 3e5265023ddd libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 +++ b/libxkutil/device_parsing.c Tue Jan 08 13:23:53 2008 -0800 @@ -130,12 +130,17 @@ static char *get_node_content(xmlNode *n return buf; } -static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev) -{ - struct disk_device *ddev = &(vdev->dev.disk); +static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct disk_device *ddev = NULL; xmlNode * child = NULL; - memset(ddev, 0, sizeof(*ddev)); + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + ddev = &(vdev->dev.disk); ddev->type = get_attr_value(dnode, "type"); if (ddev->type == NULL) @@ -174,20 +179,28 @@ static bool parse_disk_device(xmlNode *d vdev->type = VIRT_DEV_DISK; vdev->id = strdup(ddev->virtual_dev); - return true; + *vdevs = vdev; + + return 1; err: cleanup_disk_device(ddev); - - return false; -} - -static bool parse_net_device(xmlNode *inode, struct virt_device *vdev) -{ - struct net_device *ndev = &(vdev->dev.net); + free(vdev); + + return 0; +} + +static int parse_net_device(xmlNode *inode, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct net_device *ndev = NULL; xmlNode *child = NULL; - memset(ndev, 0, sizeof(*ndev)); + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + ndev = &(vdev->dev.net); ndev->type = get_attr_value(inode, "type"); if (ndev->type == NULL) @@ -216,16 +229,26 @@ static bool parse_net_device(xmlNode *in vdev->type = VIRT_DEV_NET; vdev->id = strdup(ndev->mac); - return true; + *vdevs = vdev; + + return 1; err: cleanup_net_device(ndev); - - return false; -} - -static bool parse_emu_device(xmlNode *node, struct virt_device *vdev) -{ - struct emu_device *edev = &(vdev->dev.emu); + free(vdev); + + return 0; +} + +static int parse_emu_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct emu_device *edev = NULL; + + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + edev = &(vdev->dev.emu); edev->path = get_node_content(node); if (edev->path != NULL) @@ -233,16 +256,26 @@ static bool parse_emu_device(xmlNode *no vdev->type = VIRT_DEV_EMU; - return true; + *vdevs = vdev; + + return 1; err: cleanup_emu_device(edev); - - return false; -} - -static bool parse_graphics_device(xmlNode *node, struct virt_device *vdev) -{ - struct graphics_device *gdev = &(vdev->dev.graphics); + free(vdev); + + return 0; +} + +static int parse_graphics_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct graphics_device *gdev = NULL; + + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + gdev = &(vdev->dev.graphics); gdev->type = get_attr_value(node, "type"); gdev->port = get_attr_value(node, "port"); @@ -252,21 +285,37 @@ static bool parse_graphics_device(xmlNod vdev->type = VIRT_DEV_GRAPHICS; - return true; + *vdevs = vdev; + + return 1; err: cleanup_graphics_device(gdev); - - return false; + free(vdev); + + return 0; +} + +static bool resize_devlist(struct virt_device **list, int newsize) +{ + struct virt_device *_list; + + _list = realloc(*list, newsize * sizeof(struct virt_device)); + if (_list == NULL) + return false; + + *list = _list; + + return true; } static int do_parse(xmlNodeSet *nsv, int type, struct virt_device **l) { int devidx; - int lstidx; + int lstidx = 0; int count = 0; struct virt_device *list = NULL; xmlNode **dev_nodes = NULL; - bool (*do_real_parse)(xmlNode *, struct virt_device *) = NULL; + int (*do_real_parse)(xmlNode *, struct virt_device **) = NULL; /* point to correct parser function according to type */ if (type == VIRT_DEV_NET) @@ -289,27 +338,32 @@ static int do_parse(xmlNodeSet *nsv, int if (count <= 0) goto out; - list = (struct virt_device *)malloc(count * sizeof(struct virt_device)); - if (list == NULL) { - count = 0; - goto out; - } - /* walk thru the array, do real parsing on each node */ - lstidx = 0; for (devidx = 0; devidx < count; devidx++) { - if (do_real_parse(dev_nodes[devidx], &list[lstidx])) - lstidx++; - } - - if (lstidx < devidx) { - list = realloc(list, lstidx * sizeof(struct virt_device)); - count = lstidx; + struct virt_device *tmp_list = NULL; + int devices = 0; + + devices = do_real_parse(dev_nodes[devidx], &tmp_list); + if (devices <= 0) + continue; + + if (!resize_devlist(&list, lstidx + devices)) { + /* Skip these devices and try again for the + * next cycle, which will probably fail, but + * what else can you do? + */ + goto end; + } + + memcpy(&list[lstidx], tmp_list, devices * sizeof(*tmp_list)); + lstidx += devices; + end: + free(tmp_list); } out: *l = list; - return count; + return lstidx; } /* Dummy function to suppress error message from libxml2 */ From grendel at linux.vnet.ibm.com Tue Jan 8 21:46:36 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Tue, 08 Jan 2008 16:46:36 -0500 Subject: [Libvirt-cim] [PATCH 1 of 3] Fix xml_parse_test if no emulator is defined In-Reply-To: <7272934dc44185bef392.1199827443@theine> References: <7272934dc44185bef392.1199827443@theine> Message-ID: <4783EF3C.3050808@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1199827433 28800 > # Node ID 7272934dc44185bef3923c86fa19961d299518fd > # Parent 10d141f683370b6f04637bb9ad059bbd92051ce0 > Fix xml_parse_test if no emulator is defined > > Signed-off-by: Dan Smith > > diff -r 10d141f68337 -r 7272934dc441 libxkutil/xml_parse_test.c > --- a/libxkutil/xml_parse_test.c Tue Jan 08 10:51:44 2008 -0800 > +++ b/libxkutil/xml_parse_test.c Tue Jan 08 13:23:53 2008 -0800 > @@ -121,7 +121,7 @@ static void print_devices(struct domain > for (i = 0; i < dominfo->dev_vcpu_ct; i++) > print_dev_vcpu(&dominfo->dev_vcpu[i], d); > > - if (dominfo->type != DOMAIN_XENPV) { > + if ((dominfo->type != DOMAIN_XENPV) && (dominfo->dev_emu)) { > fprintf(d, "\n-- Emulator --\n"); > print_dev_emu(dominfo->dev_emu, d); > } > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > Well I gotta say, I'm a bit disappointed. All that lead up to the set, and the first patch doesn't even produce a vertical scrollbar in thunderbird. At the very least you could have done some pointer arithmetic. +1, I guess. -- -Jay From kaitlin at linux.vnet.ibm.com Tue Jan 8 23:24:07 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 15:24:07 -0800 Subject: [Libvirt-cim] [PATCH 2 of 3] Allow device_parsing modules to return multiple devices per cycle In-Reply-To: <3e5265023ddda5cfa24e.1199827444@theine> References: <3e5265023ddda5cfa24e.1199827444@theine> Message-ID: <47840617.5090503@linux.vnet.ibm.com> Dan Smith wrote: > > -static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev) > -{ > - struct disk_device *ddev = &(vdev->dev.disk); > +static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs) Why the move from int to bool and now back to int? > + > + devices = do_real_parse(dev_nodes[devidx], &tmp_list); > + if (devices <= 0) > + continue; Why is the check devices <= 0? The parse functions only return either 0 or 1. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Tue Jan 8 23:25:48 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 08 Jan 2008 15:25:48 -0800 Subject: [Libvirt-cim] [PATCH 2 of 3] Allow device_parsing modules to return multiple devices per cycle In-Reply-To: <47840617.5090503@linux.vnet.ibm.com> References: <3e5265023ddda5cfa24e.1199827444@theine> <47840617.5090503@linux.vnet.ibm.com> Message-ID: <4784067C.3010909@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Dan Smith wrote: > >> >> -static bool parse_disk_device(xmlNode *dnode, struct virt_device *vdev) >> -{ >> - struct disk_device *ddev = &(vdev->dev.disk); >> +static int parse_disk_device(xmlNode *dnode, struct virt_device **vdevs) > > Why the move from int to bool and now back to int? > > >> + >> + devices = do_real_parse(dev_nodes[devidx], &tmp_list); >> + if (devices <= 0) >> + continue; > > Why is the check devices <= 0? The parse functions only return either 0 > or 1. > Ah, I see - the vcpu parse function returns the count. I should read all the patches in a set before responding. =) -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From heidieck at linux.vnet.ibm.com Wed Jan 9 08:05:06 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:05:06 +0200 Subject: [Libvirt-cim] [PATCH 0 of 2] #2 - Validate client given object path in HostedService provider Message-ID: Diff to #1 (HS: returns results for wrong object path): - moved validate_host_ref() function to HostSystem provider for global availability - fixed style issues From heidieck at linux.vnet.ibm.com Wed Jan 9 08:05:07 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:05:07 +0200 Subject: [Libvirt-cim] [PATCH 1 of 2] Add function to validate the client given object path In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199869322 -3600 # Node ID ee811a7e50179f019cda5267e27f44faa4a1f353 # Parent 10d141f683370b6f04637bb9ad059bbd92051ce0 Add function to validate the client given object path Signed-off-by: Heidi Eckhart diff -r 10d141f68337 -r ee811a7e5017 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Tue Jan 08 10:51:44 2008 -0800 +++ b/src/Virt_HostSystem.c Wed Jan 09 10:02:02 2008 +0100 @@ -35,6 +35,25 @@ #include "Virt_HostSystem.h" const static CMPIBroker *_BROKER; + +CMPIStatus validate_host_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + + s = get_host_cs(broker, ref, &inst); + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + return s; +} static int set_host_system_properties(CMPIInstance *instance) { diff -r 10d141f68337 -r ee811a7e5017 src/Virt_HostSystem.h --- a/src/Virt_HostSystem.h Tue Jan 08 10:51:44 2008 -0800 +++ b/src/Virt_HostSystem.h Wed Jan 09 10:02:02 2008 +0100 @@ -29,4 +29,8 @@ CMPIStatus get_host_system_properties(co const char **ccname, const CMPIObjectPath *ref, const CMPIBroker *broker); + +CMPIStatus validate_host_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref); + #endif From heidieck at linux.vnet.ibm.com Wed Jan 9 08:05:08 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:05:08 +0200 Subject: [Libvirt-cim] [PATCH 2 of 2] HS: returns results for wrong object path In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199869324 -3600 # Node ID ad0ca904d4cb6184c5ae0002891fa22f336dcce0 # Parent ee811a7e50179f019cda5267e27f44faa4a1f353 HS: returns results for wrong object path The client given reference was not checked for existance in both directions (from HostSystem to Service and reverse) and the call returned wrong results. Now NOT_FOUND is returned in case of a wrong object path. Examples: wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_ResourcePoolConfigurationService.CreationClassName="wrong",wrong="wrong"' wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="notthere"' Diff to #1: - fixed style issues - validate_host_ref() now in HostSystem provider Signed-off-by: Heidi Eckhart diff -r ee811a7e5017 -r ad0ca904d4cb src/Makefile.am --- a/src/Makefile.am Wed Jan 09 10:02:02 2008 +0100 +++ b/src/Makefile.am Wed Jan 09 10:02:04 2008 +0100 @@ -135,9 +135,9 @@ libVirt_ElementAllocatedFromPool_la_SOUR libVirt_ElementAllocatedFromPool_la_SOURCES = Virt_ElementAllocatedFromPool.c libVirt_ElementAllocatedFromPool_la_LIBADD = -lVirt_DevicePool -lVirt_Device -libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la libVirt_VSMigrationService.la +libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la libVirt_VSMigrationService.la libVirt_HostSystem.la libVirt_HostedService_la_SOURCES = Virt_HostedService.c -libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService +libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService -lVirt_HostSystem libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c diff -r ee811a7e5017 -r ad0ca904d4cb src/Virt_HostedService.c --- a/src/Virt_HostedService.c Wed Jan 09 10:02:02 2008 +0100 +++ b/src/Virt_HostedService.c Wed Jan 09 10:02:04 2008 +0100 @@ -37,6 +37,39 @@ const static CMPIBroker *_BROKER; +static CMPIStatus validate_service_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + char* classname; + + classname = class_base_name(CLASSNAME(ref)); + + if (STREQC(classname, "VirtualSystemManagementService")) { + s = get_vsms(ref, &inst, _BROKER); + } else if (STREQC(classname, "ResourcePoolConfigurationService")) { + s = rpcs_instance(ref, &inst, _BROKER); + } else if (STREQC(classname, "VirtualSystemMigrationService")) { + s = get_migration_service(ref, &inst, _BROKER); + } + + if (s.rc != CMPI_RC_OK) + goto out; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + out: + free(classname); + + return s; +} + static CMPIStatus service_to_host(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -45,6 +78,10 @@ static CMPIStatus service_to_host(const CMPIInstance *instance; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = validate_service_ref(ref); + if (s.rc != CMPI_RC_OK) return s; s = get_host_cs(_BROKER, ref, &instance); @@ -62,6 +99,10 @@ static CMPIStatus host_to_service(const CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = validate_host_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) return s; s = rpcs_instance(ref, &inst, _BROKER); From heidieck at linux.vnet.ibm.com Wed Jan 9 09:14:01 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:14:01 +0100 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path In-Reply-To: <478384CA.6090708@linux.vnet.ibm.com> References: <555126035e912e9202eb.1199797489@localhost.localdomain> <478384CA.6090708@linux.vnet.ibm.com> Message-ID: <47849059.20500@linux.vnet.ibm.com> Jay Gagnon wrote: > Heidi Eckhart wrote: > >> + if (s.rc != CMPI_RC_OK) >> + return s; >> >> > Sorry for being so nitpicky, but for the sake of consistency I think > this is a place where we use a "goto out;" type of statement as opposed > to having multiple returns. > I wouldn't call it nitpicky. Its a very good finding :) ! Thanks. >> + >> + prop = cu_compare_ref(ref, inst); >> + if (prop != NULL) { >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_ERR_NOT_FOUND, >> + "No such instance (%s)", prop); >> + } >> + >> >> > Putting out right here should work fine. Agree and done so in the updated patch. > Actually, this is more than a > nitpick I think, because if the above return happens we don't hit this > free() and leak classname. > Mhh ... the above code does only set the status, but does not return right afterwards. So we wouldn't leak classname. Or did I miss something ? >> + free(classname); >> + >> + return s; >> +} >> >> -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Wed Jan 9 09:14:30 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:14:30 +0100 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path In-Reply-To: <87hcho1hpj.fsf@theine.beaverton.ibm.com> References: <555126035e912e9202eb.1199797489@localhost.localdomain> <87hcho1hpj.fsf@theine.beaverton.ibm.com> Message-ID: <47849076.4000305@linux.vnet.ibm.com> Dan Smith wrote: > HE> + if (STREQC(classname, "VirtualSystemManagementService")) { > HE> + s = get_vsms(ref, &inst, _BROKER); > HE> + } > HE> + else if (STREQC(classname, "ResourcePoolConfigurationService")) { > HE> + s = rpcs_instance(ref, &inst, _BROKER); > HE> + } > HE> + else if (STREQC(classname, "VirtualSystemMigrationService")) { > HE> + s = get_migration_service(ref, &inst, _BROKER); > HE> + } > HE> + if (s.rc != CMPI_RC_OK) > HE> + return s; > > This doesn't fit the style of the rest of the code. The "else if" > statements should be on the same line as the closing brace, and there > should be a blank line before the second and unrelated if. > > Fixed in the updated version. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Wed Jan 9 09:32:13 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 10:32:13 +0100 Subject: [Libvirt-cim] [PATCH 0 of 3] Fix offline VCPU representation In-Reply-To: References: Message-ID: <4784949D.5000802@linux.vnet.ibm.com> Dan Smith wrote: > Currently, we cannot present information and instances for VCPUs when a > domain is powered off, because virDomainGetInfo() does not work unless a > domain is running. > > This set ultimately changes the vcpu bits in device_parsing to, that's right, > actually *parse* the VCPU information from the XML like all the other devices, > which gives us VCPU information for offline domains. > > To get there, I had to make the core of device_parsing a little more dyanmic > so that the parsing modules could return mulitple devices for a given > XML cycle, which vcpu needs. > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > This is an excellent patch set ! I even wasn't able to see an instance of KVM_Processor with a running domain (because libvirt wasn't supporting it), but now I can ! This patch set gets a BIG +1 ! -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Wed Jan 9 11:00:40 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 12:00:40 +0100 Subject: [Libvirt-cim] Xen_ElementCapabilities return expected result from one side querying by non existing instance In-Reply-To: References: Message-ID: <4784A958.4010309@linux.vnet.ibm.com> Guo Lian Yun wrote: > > > Please who can have a look into them? Thanks a lot! > I will have a look into these issues. Thanks for reporting them :). These are all very good findings. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Wed Jan 9 11:09:13 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 13:09:13 +0200 Subject: [Libvirt-cim] [PATCH 1 of 4] RAFP: validation of client given object path is missing In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199880495 -3600 # Node ID ae476a5a5ab9891f4fbd3591e4175173f6b55c8b # Parent a6edc1c843ecbc619dbd40da2f4cedc58e45ba27 RAFP: validation of client given object path is missing The validation of the client's given object path for a ResourceAllocationSettingData instance is missing. The provider accepts InstanceIDs that do not exist, instead of returning NOT_FOUND. Example: wbemcli ain -ac KVM_ResourceAllocationFromPool http://localhost/root/virt:KVM_ProcResourceAllocationSettingData.InstanceID="NetworkPool/me" returns localhost:5988/root/virt:KVM_ProcessorPool.InstanceID="ProcessorPool/0" Also removed unused inst_list _list. Signed-off-by: Heidi Eckhart diff -r a6edc1c843ec -r ae476a5a5ab9 src/Virt_ResourceAllocationFromPool.c --- a/src/Virt_ResourceAllocationFromPool.c Tue Jan 08 13:23:53 2008 -0800 +++ b/src/Virt_ResourceAllocationFromPool.c Wed Jan 09 13:08:15 2008 +0100 @@ -37,6 +37,28 @@ const static CMPIBroker *_BROKER; +static CMPIStatus validate_rasd_ref(const CMPIContext *context, + const CMPIObjectPath *ref, + uint16_t type, + const char *id) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *rasd = NULL; + + rasd = get_rasd_instance(context, + ref, + _BROKER, + id, + type); + + if (CMIsNullObject(rasd)) + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", id); + + return s; +} + static CMPIStatus rasd_to_pool(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -46,14 +68,11 @@ static CMPIStatus rasd_to_pool(const CMP const char *id = NULL; char *poolid = NULL; virConnectPtr conn = NULL; - struct inst_list _list; CMPIInstance *pool = NULL; if (!match_hypervisor_prefix(ref, info)) return s; - inst_list_init(&_list); - if (rasd_type_from_classname(CLASSNAME(ref), &type) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -67,6 +86,13 @@ static CMPIStatus rasd_to_pool(const CMP "Missing InstanceID"); goto out; } + + s = validate_rasd_ref(info->context, + ref, + type, + id); + if (s.rc != CMPI_RC_OK) + goto out; poolid = pool_member_of(_BROKER, CLASSNAME(ref), type, id); if (poolid == NULL) { @@ -96,7 +122,6 @@ static CMPIStatus rasd_to_pool(const CMP out: free(poolid); virConnectClose(conn); - inst_list_free(&_list); return s; } From heidieck at linux.vnet.ibm.com Wed Jan 9 11:09:12 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 13:09:12 +0200 Subject: [Libvirt-cim] [PATCH 0 of 4] RAFP: Validation of client's given object path missing Message-ID: The starting point for this patch series was the missing validation of the client's given object path of ResourceAllocationSettingData in the RAFP provider. This is fixed by patch #1. Patch #2 switches the return code for getInstance from FAILED to NOT_FOUND for ResourceAllocationSettingData. Patch #3 registeres the RASD provider for KVM. Patch #4 switches the return code for getInstance from FAILED to NOT_FOUND for DevicePools. From heidieck at linux.vnet.ibm.com Wed Jan 9 11:09:14 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 13:09:14 +0200 Subject: [Libvirt-cim] [PATCH 2 of 4] getInstance of RASD returns FAILED in case of NOT_FOUND In-Reply-To: Message-ID: <35a3c6dc22e139c28360.1199880554@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1199880496 -3600 # Node ID 35a3c6dc22e139c28360611f4363a2c8ec9bab11 # Parent ae476a5a5ab9891f4fbd3591e4175173f6b55c8b getInstance of RASD returns FAILED in case of NOT_FOUND Signed-off-by: Heidi Eckhart diff -r ae476a5a5ab9 -r 35a3c6dc22e1 src/Virt_RASD.c --- a/src/Virt_RASD.c Wed Jan 09 13:08:15 2008 +0100 +++ b/src/Virt_RASD.c Wed Jan 09 13:08:16 2008 +0100 @@ -294,8 +294,8 @@ static CMPIStatus GetInstance(CMPIInstan CMReturnInstance(results, inst); else cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unknown instance"); + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", id); out: return s; } From heidieck at linux.vnet.ibm.com Wed Jan 9 11:09:15 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 13:09:15 +0200 Subject: [Libvirt-cim] [PATCH 3 of 4] Register RASD provider for KVM ResourceAllocationSettingData In-Reply-To: Message-ID: <5a1645d367b15bd3c6d1.1199880555@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1199880496 -3600 # Node ID 5a1645d367b15bd3c6d144f5098c5c2824875eb8 # Parent 35a3c6dc22e139c28360611f4363a2c8ec9bab11 Register RASD provider for KVM ResourceAllocationSettingData Signed-off-by: Heidi Eckhart diff -r 35a3c6dc22e1 -r 5a1645d367b1 schema/ResourceAllocationSettingData.registration --- a/schema/ResourceAllocationSettingData.registration Wed Jan 09 13:08:16 2008 +0100 +++ b/schema/ResourceAllocationSettingData.registration Wed Jan 09 13:08:16 2008 +0100 @@ -4,3 +4,7 @@ Xen_NetResourceAllocationSettingData roo Xen_NetResourceAllocationSettingData root/virt Virt_RASDP Virt_RASD instance Xen_ProcResourceAllocationSettingData root/virt Virt_RASD Virt_RASD instance Xen_MemResourceAllocationSettingData root/virt Virt_RASD Virt_RASD instance +KVM_DiskResourceAllocationSettingData root/virt Virt_RASD Virt_RASD instance +KVM_NetResourceAllocationSettingData root/virt Virt_RASDP Virt_RASD instance +KVM_ProcResourceAllocationSettingData root/virt Virt_RASD Virt_RASD instance +KVM_MemResourceAllocationSettingData root/virt Virt_RASD Virt_RASD instance From heidieck at linux.vnet.ibm.com Wed Jan 9 11:09:16 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Wed, 09 Jan 2008 13:09:16 +0200 Subject: [Libvirt-cim] [PATCH 4 of 4] getInstance of DevicePool returns FAILED in case of NOT_FOUND In-Reply-To: Message-ID: <102f4ccc2080dbaddb62.1199880556@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1199880497 -3600 # Node ID 102f4ccc2080dbaddb62b61eb9409ba09922cefd # Parent 5a1645d367b15bd3c6d144f5098c5c2824875eb8 getInstance of DevicePool returns FAILED in case of NOT_FOUND Signed-off-by: Heidi Eckhart diff -r 5a1645d367b1 -r 102f4ccc2080 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Wed Jan 09 13:08:16 2008 +0100 +++ b/src/Virt_DevicePool.c Wed Jan 09 13:08:17 2008 +0100 @@ -817,7 +817,6 @@ CMPIStatus get_pool_inst(const CMPIBroke CMPIInstance *inst = NULL; virConnectPtr conn = NULL; const char *id = NULL; - const char *prop; if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(broker, &s, @@ -831,19 +830,11 @@ CMPIStatus get_pool_inst(const CMPIBroke goto out; inst = get_pool_by_id(broker, conn, id, NAMESPACE(reference)); - if (inst) { - prop = cu_compare_ref(reference, inst); - if (prop != NULL) { - cu_statusf(broker, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such ResourcePool instance (%s)", prop); - } - } else { + if (inst == NULL) cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "No such instance `%s'", id); - } - + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", id); + out: virConnectClose(conn); *instance = inst; From kaitlin at linux.vnet.ibm.com Wed Jan 9 14:45:01 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 09 Jan 2008 06:45:01 -0800 Subject: [Libvirt-cim] [PATCH 0 of 3] Fix offline VCPU representation In-Reply-To: References: Message-ID: <4784DDED.6030806@linux.vnet.ibm.com> Dan Smith wrote: > Currently, we cannot present information and instances for VCPUs when a > domain is powered off, because virDomainGetInfo() does not work unless a > domain is running. > > This set ultimately changes the vcpu bits in device_parsing to, that's right, > actually *parse* the VCPU information from the XML like all the other devices, > which gives us VCPU information for offline domains. > > To get there, I had to make the core of device_parsing a little more dyanmic > so that the parsing modules could return mulitple devices for a given > XML cycle, which vcpu needs. This tested out fine on my system. No complaints. =) +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From grendel at linux.vnet.ibm.com Wed Jan 9 15:22:06 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Wed, 09 Jan 2008 10:22:06 -0500 Subject: [Libvirt-cim] [PATCH] HS: returns results for wrong object path In-Reply-To: <47849059.20500@linux.vnet.ibm.com> References: <555126035e912e9202eb.1199797489@localhost.localdomain> <478384CA.6090708@linux.vnet.ibm.com> <47849059.20500@linux.vnet.ibm.com> Message-ID: <4784E69E.3080800@linux.vnet.ibm.com> Heidi Eckhart wrote: > Jay Gagnon wrote: >> Heidi Eckhart wrote: >> >>> + if (s.rc != CMPI_RC_OK) >>> + return s; >>> >> Sorry for being so nitpicky, but for the sake of consistency I think >> this is a place where we use a "goto out;" type of statement as opposed >> to having multiple returns. >> > I wouldn't call it nitpicky. Its a very good finding :) ! Thanks. >>> + + prop = cu_compare_ref(ref, inst); >>> + if (prop != NULL) { >>> + cu_statusf(_BROKER, &s, >>> + CMPI_RC_ERR_NOT_FOUND, >>> + "No such instance (%s)", prop); >>> + } >>> + >> Putting out right here should work fine. > Agree and done so in the updated patch. >> Actually, this is more than a >> nitpick I think, because if the above return happens we don't hit this >> free() and leak classname. >> > Mhh ... the above code does only set the status, but does not return > right afterwards. So we wouldn't leak classname. Or did I miss > something ? Sorry, my "above" was a bit vague. I meant that if the "return s;" at the very top of this email happens, we leave the function before we get to "free(classname);" and so classname will be leaked. But no matter, the point will become moot when you switch the return to a goto; classname definitely won't leak that way. -- -Jay From kaitlin at linux.vnet.ibm.com Wed Jan 9 15:35:46 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 09 Jan 2008 07:35:46 -0800 Subject: [Libvirt-cim] [PATCH 0 of 2] #2 - Validate client given object path in HostedService provider In-Reply-To: References: Message-ID: <4784E9D2.4040207@linux.vnet.ibm.com> Heidi Eckhart wrote: > Diff to #1 (HS: returns results for wrong object path): > - moved validate_host_ref() function to HostSystem provider for global availability > - fixed style issues > This tested fine for me. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Wed Jan 9 16:32:00 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 09 Jan 2008 08:32:00 -0800 Subject: [Libvirt-cim] [PATCH 0 of 4] RAFP: Validation of client's given object path missing In-Reply-To: References: Message-ID: <4784F700.7090207@linux.vnet.ibm.com> Heidi Eckhart wrote: > The starting point for this patch series was the missing validation of the client's given object path of ResourceAllocationSettingData in the RAFP provider. This is fixed by patch #1. > Patch #2 switches the return code for getInstance from FAILED to NOT_FOUND for ResourceAllocationSettingData. > Patch #3 registeres the RASD provider for KVM. > Patch #4 switches the return code for getInstance from FAILED to NOT_FOUND for DevicePools. > This patch tested fine for me. Patch #4 confused me at first - wasn't sure why the cu_compare_ref() piece was being removed. But since DevicePools only have one key (which we use to grab the instance anyway), there's not need to revalidate the key again. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Wed Jan 9 19:46:25 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 12:46:25 -0700 Subject: [Libvirt-cim] [PATCH 2 of 3] Add get_dominfo_from_xml() function to device_parsing In-Reply-To: Message-ID: <1fe9e5492885e9af358f.1199911585@theine> # HG changeset patch # User Dan Smith # Date 1199911546 28800 # Node ID 1fe9e5492885e9af358f392c01ff6a88b613ab96 # Parent f04c92eecc4513ea251084e02e078bb22fa75daa Add get_dominfo_from_xml() function to device_parsing Signed-off-by: Dan Smith diff -r f04c92eecc45 -r 1fe9e5492885 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Wed Jan 09 12:45:45 2008 -0800 +++ b/libxkutil/device_parsing.c Wed Jan 09 12:45:46 2008 -0800 @@ -742,28 +742,17 @@ static int _get_dominfo(const char *xml, return ret; } -int get_dominfo(virDomainPtr dom, struct domain **dominfo) -{ - char *xml; +int get_dominfo_from_xml(const char *xml, struct domain **dominfo) +{ int ret; *dominfo = malloc(sizeof(**dominfo)); if (*dominfo == NULL) return 0; - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) { - free(*dominfo); - *dominfo = NULL; - return 0; - } - ret = _get_dominfo(xml, *dominfo); - if (ret == 0) { - free(*dominfo); - *dominfo = NULL; - goto out; - } + if (ret == 0) + goto err; parse_devices(xml, &(*dominfo)->dev_emu, VIRT_DEV_EMU); parse_devices(xml, &(*dominfo)->dev_graphics, VIRT_DEV_GRAPHICS); @@ -778,7 +767,27 @@ int get_dominfo(virDomainPtr dom, struct (*dominfo)->dev_vcpu_ct = parse_devices(xml, &(*dominfo)->dev_vcpu, VIRT_DEV_VCPU); -out: + + return ret; + + err: + free(*dominfo); + *dominfo = NULL; + + return 0; +} + +int get_dominfo(virDomainPtr dom, struct domain **dominfo) +{ + char *xml; + int ret; + + xml = virDomainGetXMLDesc(dom, 0); + if (xml == NULL) + return 0; + + ret = get_dominfo_from_xml(xml, dominfo); + free(xml); return ret; diff -r f04c92eecc45 -r 1fe9e5492885 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Wed Jan 09 12:45:45 2008 -0800 +++ b/libxkutil/device_parsing.h Wed Jan 09 12:45:46 2008 -0800 @@ -134,6 +134,7 @@ int disk_type_from_file(const char *path int disk_type_from_file(const char *path); int get_dominfo(virDomainPtr dom, struct domain **dominfo); +int get_dominfo_from_xml(const char *xml, struct domain **dominfo); void cleanup_dominfo(struct domain **dominfo); From danms at us.ibm.com Wed Jan 9 19:46:23 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 12:46:23 -0700 Subject: [Libvirt-cim] [PATCH 0 of 3] Memory devices from XML and raw XML parsing Message-ID: This patch set: - Moves memory device parsing to use XML like the rest - Restructures the entry points of device-only parsing to share more code - Adds a function to parse plain XML into a dominfo structure for times where we don't have a virDomainPtr - Updates the xml_parse_test program to allow testing of the aforementioned function, as well as clean up the option parsing to make way for more features later From danms at us.ibm.com Wed Jan 9 19:46:26 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 12:46:26 -0700 Subject: [Libvirt-cim] [PATCH 3 of 3] Signed-off-by: Dan Smith In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199911546 28800 # Node ID d981b576039570b106ecdb9a329b67d433ed4812 # Parent 1fe9e5492885e9af358f392c01ff6a88b613ab96 Signed-off-by: Dan Smith diff -r 1fe9e5492885 -r d981b5760395 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Wed Jan 09 12:45:46 2008 -0800 +++ b/libxkutil/xml_parse_test.c Wed Jan 09 12:45:46 2008 -0800 @@ -1,5 +1,7 @@ #include #include + +#include #include @@ -110,6 +112,7 @@ static void print_devices(struct domain { int i; + fprintf(d, "\n-- Memory (%i) --\n", dominfo->dev_mem_ct); for (i = 0; i < dominfo->dev_mem_ct; i++) print_dev_mem(&dominfo->dev_mem[i], d); @@ -149,40 +152,164 @@ static void print_domxml(struct domain * printf("%s\n", xml); } -int main(int argc, char **argv) -{ - virConnectPtr conn; - virDomainPtr dom; - struct domain *dominfo; - - if (argc < 2) { - printf("Usage: %s domain [URI] [xml]\n", argv[0]); - return 1; - } - - if (argc > 2) - conn = virConnectOpen(argv[2]); - else - conn = virConnectOpen("xen:///"); +static char *read_from_file(FILE *file) +{ + char *xml = NULL; + char buf[256]; + int size = 0; + + while (fgets(buf, sizeof(buf) - 1, file) != NULL) { + xml = realloc(xml, size + strlen(buf) + 1); + if (xml == NULL) { + printf("Out of memory\n"); + return NULL; + } + + strcat(xml, buf); + size += strlen(buf); + } + + return xml; +} + +static int dominfo_from_dom(const char *uri, + const char *domain, + struct domain **d) +{ + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + int ret = 0; + + conn = virConnectOpen(uri); if (conn == NULL) { printf("Unable to connect to libvirt\n"); + goto out; + } + + dom = virDomainLookupByName(conn, domain); + if (dom == NULL) { + printf("Unable to find domain `%s'\n", domain); + goto out; + } + + ret = get_dominfo(dom, d); + + out: + virDomainFree(dom); + virConnectClose(conn); + + return ret; +} + +static int dominfo_from_file(const char *fname, struct domain **d) +{ + char *xml; + FILE *file; + int ret; + + if (fname[0] == '-') + file = stdin; + else + file = fopen(fname, "r"); + + if (file == NULL) { + printf("Unable to open `%s'\n", fname); + return 0; + } + + xml = read_from_file(file); + if (xml == NULL) { + printf("Unable to read from `%s'\n", fname); + return 0; + } + + ret = get_dominfo_from_xml(xml, d); + + free(xml); + fclose(file); + + printf("XML:\n%s", xml); + + return ret; +} + +static void usage(void) +{ + printf("xml_parse_test -f [FILE | -] [--xml]\n" + "xml_parse_test -d domain [--uri URI] [--xml]\n" + "\n" + "-f,--file FILE Parse domain XML from file (or stdin if -)\n" + "-d,--domain DOM Display dominfo for a domain from libvirt\n" + "-u,--uri URI Connect to libvirt with URI\n" + "-x,--xml Dump generated XML instead of summary\n" + "-h,--help Display this help message\n"); +} + +int main(int argc, char **argv) +{ + int c; + char *domain = NULL; + char *uri = "xen"; + char *file = NULL; + bool xml = false; + struct domain *dominfo = NULL; + int ret; + + static struct option lopts[] = { + {"domain", 1, 0, 'd'}, + {"uri", 1, 0, 'u'}, + {"xml", 0, 0, 'x'}, + {"file", 1, 0, 'f'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0}}; + + while (1) { + int optidx = 0; + + c = getopt_long(argc, argv, "d:u:f:xh", lopts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'd': + domain = optarg; + break; + + case 'u': + uri = optarg; + break; + + case 'f': + file = optarg; + break; + + case 'x': + xml = true; + break; + + case '?': + case 'h': + usage(); + return c == '?'; + + }; + } + + if (file != NULL) + ret = dominfo_from_file(file, &dominfo); + else if (domain != NULL) + ret = dominfo_from_dom(uri, domain, &dominfo); + else { + printf("Need a data source (--domain or --file)\n"); + return 1; + } + + if (ret == 0) { + printf("Unable to get dominfo\n"); return 2; } - dom = virDomainLookupByName(conn, argv[1]); - if (dom == NULL) { - printf("Unable to lookup domain `%s'\n", argv[1]); - return 3; - } - - if (get_dominfo(dom, &dominfo) == 0) { - printf("Failed to parse domain info\n"); - return 4; - } - - printf("Parsed domain info\n"); - - if ((argc > 3) && (argv[3][0] == 'x')) + if (xml) print_domxml(dominfo, stdout); else { print_dominfo(dominfo, stdout); From danms at us.ibm.com Wed Jan 9 19:46:24 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 12:46:24 -0700 Subject: [Libvirt-cim] [PATCH 1 of 3] Make device_parsing get XML description for a domain once for all phases In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199911545 28800 # Node ID f04c92eecc4513ea251084e02e078bb22fa75daa # Parent c9eeda2625792e11f55ff74b71902591a49f041d Make device_parsing get XML description for a domain once for all phases Also, make memory devices parse the XML instead of ops on a domain. This gives us the ability to create a dominfo structure from XML-only. It would have been nice to put this into two separate patches, but I would have had to fake some memory stuff just to make the reorg work and then remove it in the next patch, so hopefully what I did is palatable to all :) Signed-off-by: Dan Smith diff -r c9eeda262579 -r f04c92eecc45 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Wed Jan 09 10:02:04 2008 +0100 +++ b/libxkutil/device_parsing.c Wed Jan 09 12:45:45 2008 -0800 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -39,11 +40,13 @@ #define VCPU_XPATH (xmlChar *)"/domain/vcpu" #define NET_XPATH (xmlChar *)"/domain/devices/interface" #define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define MEM_XPATH (xmlChar *)"/domain/memory | /domain/currentMemory" #define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" #define XSTREQ(x, y) (STREQ((char *)x, y)) +#define MAX(a,b) (((a)>(b))?(a):(b)) static void cleanup_disk_device(struct disk_device *dev) { @@ -306,6 +309,38 @@ static int parse_emu_device(xmlNode *nod return 0; } +static int parse_mem_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct mem_device *mdev = NULL; + char *content = NULL; + + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + mdev = &(vdev->dev.mem); + + content = get_node_content(node); + + if (XSTREQ(node->name, "memory")) + sscanf(content, "%" PRIu64, &mdev->size); + else if (XSTREQ(node->name, "currentMemory")) + sscanf(content, "%" PRIu64, &mdev->maxsize); + + free(content); + + *vdevs = vdev; + + return 1; + + err: + free(content); + free(vdev); + + return 0; +} + static int parse_graphics_device(xmlNode *node, struct virt_device **vdevs) { struct virt_device *vdev = NULL; @@ -366,6 +401,8 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = parse_vcpu_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_MEM) + do_real_parse = parse_mem_device; else if (type == VIRT_DEV_GRAPHICS) do_real_parse = parse_graphics_device; else @@ -414,7 +451,7 @@ static void swallow_err_msg(void *ctx, c /* do nothing, just swallow the message. */ } -static int parse_devices(char *xml, struct virt_device **_list, int type) +static int parse_devices(const char *xml, struct virt_device **_list, int type) { int len = 0; int count = 0; @@ -432,6 +469,8 @@ static int parse_devices(char *xml, stru xpathstr = VCPU_XPATH; else if (type == VIRT_DEV_EMU) xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_MEM) + xpathstr = MEM_XPATH; else if (type == VIRT_DEV_GRAPHICS) xpathstr = GRAPHICS_XPATH; else @@ -500,128 +539,60 @@ struct virt_device *virt_device_dup(stru return dev; } -static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +static int _get_mem_device(const char *xml, struct virt_device **list) +{ + struct virt_device *mdevs = NULL; + struct virt_device *mdev = NULL; + int ret; + + ret = parse_devices(xml, &mdevs, VIRT_DEV_MEM); + if (ret <= 0) + return ret; + + mdev = malloc(sizeof(*mdev)); + if (mdev == NULL) + return 0; + + memset(mdev, 0, sizeof(*mdev)); + + /* We could get one or two memory devices back, depending on + * if there is a currentMemory tag or not. Coalesce these + * into a single device to return + */ + + if (ret == 2) { + mdev->dev.mem.size = MAX(mdevs[0].dev.mem.size, + mdevs[1].dev.mem.size); + mdev->dev.mem.maxsize = MAX(mdevs[0].dev.mem.maxsize, + mdevs[1].dev.mem.maxsize); + } else { + mdev->dev.mem.size = MAX(mdevs[0].dev.mem.size, + mdevs[0].dev.mem.maxsize); + mdev->dev.mem.maxsize = mdev->dev.mem.size; + } + + mdev->type = VIRT_DEV_MEM; + mdev->id = strdup("mem"); + *list = mdev; + + cleanup_virt_devices(&mdevs, ret); + + return 1; +} + +int get_devices(virDomainPtr dom, struct virt_device **list, int type) { char *xml; int ret; - struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); if (xml == NULL) return 0; - ret = parse_devices(xml, &list, VIRT_DEV_EMU); - if (ret == 1) - *dev = &list[0]; + if (type == VIRT_DEV_MEM) + ret = _get_mem_device(xml, list); else - *dev = NULL; - - free(xml); - - return ret; -} - -static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) -{ - char *xml; - int ret; - struct virt_device *list = NULL; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); - if (ret == 1) - *dev = &list[0]; - else - *dev = NULL; - - free(xml); - - return ret; -} - -int get_disk_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_DISK); - - free(xml); - - return ret; -} - -int get_net_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_NET); - - free(xml); - - return ret; -} - -int get_mem_devices(virDomainPtr dom, struct virt_device **list) -{ - int rc, ret; - uint64_t mem_size, mem_maxsize; - virDomainInfo dom_info; - struct virt_device *ret_list = NULL; - - rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1) { - ret = -1; - goto out; - } - - mem_size = (uint64_t)dom_info.memory; - mem_maxsize = (uint64_t)dom_info.maxMem; - if (mem_size > mem_maxsize) { - ret = -1; - goto out; - } - - ret_list = malloc(sizeof(struct virt_device)); - if (ret_list == NULL) { - ret = -1; - free (ret_list); - goto out; - } - - ret_list->type = VIRT_DEV_MEM; - ret_list->dev.mem.size = mem_size; - ret_list->dev.mem.maxsize = mem_maxsize; - ret_list->id = strdup("mem"); - - ret = 1; - *list = ret_list; - out: - return ret; -} - -int get_vcpu_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_VCPU); + ret = parse_devices(xml, list, type); free(xml); @@ -794,14 +765,19 @@ int get_dominfo(virDomainPtr dom, struct goto out; } - get_emu_device(dom, &(*dominfo)->dev_emu); - get_graphics_device(dom, &(*dominfo)->dev_graphics); - - (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); - (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); - (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); - (*dominfo)->dev_vcpu_ct = get_vcpu_devices(dom, &(*dominfo)->dev_vcpu); - + parse_devices(xml, &(*dominfo)->dev_emu, VIRT_DEV_EMU); + parse_devices(xml, &(*dominfo)->dev_graphics, VIRT_DEV_GRAPHICS); + + (*dominfo)->dev_mem_ct = _get_mem_device(xml, &(*dominfo)->dev_mem); + (*dominfo)->dev_net_ct = parse_devices(xml, + &(*dominfo)->dev_net, + VIRT_DEV_NET); + (*dominfo)->dev_disk_ct = parse_devices(xml, + &(*dominfo)->dev_disk, + VIRT_DEV_DISK); + (*dominfo)->dev_vcpu_ct = parse_devices(xml, + &(*dominfo)->dev_vcpu, + VIRT_DEV_VCPU); out: free(xml); diff -r c9eeda262579 -r f04c92eecc45 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Wed Jan 09 10:02:04 2008 +0100 +++ b/libxkutil/device_parsing.h Wed Jan 09 12:45:45 2008 -0800 @@ -137,10 +137,7 @@ int get_dominfo(virDomainPtr dom, struct void cleanup_dominfo(struct domain **dominfo); -int get_disk_devices(virDomainPtr dom, struct virt_device **list); -int get_net_devices(virDomainPtr dom, struct virt_device **list); -int get_vcpu_devices(virDomainPtr dom, struct virt_device **list); -int get_mem_devices(virDomainPtr dom, struct virt_device **list); +int get_devices(virDomainPtr dom, struct virt_device **list, int type); void cleanup_virt_device(struct virt_device *dev); void cleanup_virt_devices(struct virt_device **devs, int count); diff -r c9eeda262579 -r f04c92eecc45 src/Virt_Device.c --- a/src/Virt_Device.c Wed Jan 09 10:02:04 2008 +0100 +++ b/src/Virt_Device.c Wed Jan 09 12:45:45 2008 -0800 @@ -283,22 +283,6 @@ int device_type_from_classname(const cha return VIRT_DEV_UNKNOWN; } -static int get_devices(virDomainPtr dom, - struct virt_device **devs, - int type) -{ - if (type == VIRT_DEV_NET) - return get_net_devices(dom, devs); - else if (type == VIRT_DEV_DISK) - return get_disk_devices(dom, devs); - else if (type == VIRT_DEV_MEM) - return get_mem_devices(dom, devs); - else if (type == VIRT_DEV_VCPU) - return get_vcpu_devices(dom, devs); - else - return -1; -} - int dom_devices(const CMPIBroker *broker, virDomainPtr dom, const char *ns, diff -r c9eeda262579 -r f04c92eecc45 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Wed Jan 09 10:02:04 2008 +0100 +++ b/src/Virt_DevicePool.c Wed Jan 09 12:45:45 2008 -0800 @@ -174,7 +174,7 @@ static char *diskpool_member_of(const CM if (dom == NULL) goto out; - count = get_disk_devices(dom, &devs); + count = get_devices(dom, &devs, VIRT_DEV_DISK); for (i = 0; i < count; i++) { if (STREQ((devs[i].dev.disk.virtual_dev), dev)) { @@ -290,7 +290,7 @@ static char *netpool_member_of(const CMP if (dom == NULL) goto out; - count = get_net_devices(dom, &devs); + count = get_devices(dom, &devs, VIRT_DEV_NET); for (i = 0; i < count; i++) { if (STREQ((devs[i].id), dev)) { diff -r c9eeda262579 -r f04c92eecc45 src/Virt_RASD.c --- a/src/Virt_RASD.c Wed Jan 09 10:02:04 2008 +0100 +++ b/src/Virt_RASD.c Wed Jan 09 12:45:45 2008 -0800 @@ -66,16 +66,7 @@ static int list_devs(virConnectPtr conn, if (dom == NULL) return 0; - if (type == CIM_RASD_TYPE_DISK) - return get_disk_devices(dom, list); - else if (type == CIM_RASD_TYPE_NET) - return get_net_devices(dom, list); - else if (type == CIM_RASD_TYPE_PROC) - return get_vcpu_devices(dom, list); - else if (type == CIM_RASD_TYPE_MEM) - return get_mem_devices(dom, list); - else - return 0; + return get_devices(dom, list, type); } static struct virt_device *find_dev(virConnectPtr conn, From danms at us.ibm.com Wed Jan 9 20:44:47 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 13:44:47 -0700 Subject: [Libvirt-cim] [PATCH 3 of 3] Make xml_parse_test capable of parsing an XML file In-Reply-To: Message-ID: <20c65a24edc83c444552.1199915087@theine> # HG changeset patch # User Dan Smith # Date 1199915038 28800 # Node ID 20c65a24edc83c4445527736476a2ad49f2c4066 # Parent a32cbc024d15b65dce1841025fafec5477614953 Make xml_parse_test capable of parsing an XML file to test the get_dominfo_from_xml() functionality. Changes: - Commit log - Removed an extraneous blank line addition Signed-off-by: Dan Smith diff -r a32cbc024d15 -r 20c65a24edc8 libxkutil/xml_parse_test.c --- a/libxkutil/xml_parse_test.c Wed Jan 09 12:53:15 2008 -0800 +++ b/libxkutil/xml_parse_test.c Wed Jan 09 13:43:58 2008 -0800 @@ -1,5 +1,7 @@ #include #include + +#include #include @@ -149,40 +151,164 @@ static void print_domxml(struct domain * printf("%s\n", xml); } -int main(int argc, char **argv) -{ - virConnectPtr conn; - virDomainPtr dom; - struct domain *dominfo; - - if (argc < 2) { - printf("Usage: %s domain [URI] [xml]\n", argv[0]); - return 1; - } - - if (argc > 2) - conn = virConnectOpen(argv[2]); - else - conn = virConnectOpen("xen:///"); +static char *read_from_file(FILE *file) +{ + char *xml = NULL; + char buf[256]; + int size = 0; + + while (fgets(buf, sizeof(buf) - 1, file) != NULL) { + xml = realloc(xml, size + strlen(buf) + 1); + if (xml == NULL) { + printf("Out of memory\n"); + return NULL; + } + + strcat(xml, buf); + size += strlen(buf); + } + + return xml; +} + +static int dominfo_from_dom(const char *uri, + const char *domain, + struct domain **d) +{ + virConnectPtr conn = NULL; + virDomainPtr dom = NULL; + int ret = 0; + + conn = virConnectOpen(uri); if (conn == NULL) { printf("Unable to connect to libvirt\n"); + goto out; + } + + dom = virDomainLookupByName(conn, domain); + if (dom == NULL) { + printf("Unable to find domain `%s'\n", domain); + goto out; + } + + ret = get_dominfo(dom, d); + + out: + virDomainFree(dom); + virConnectClose(conn); + + return ret; +} + +static int dominfo_from_file(const char *fname, struct domain **d) +{ + char *xml; + FILE *file; + int ret; + + if (fname[0] == '-') + file = stdin; + else + file = fopen(fname, "r"); + + if (file == NULL) { + printf("Unable to open `%s'\n", fname); + return 0; + } + + xml = read_from_file(file); + if (xml == NULL) { + printf("Unable to read from `%s'\n", fname); + return 0; + } + + ret = get_dominfo_from_xml(xml, d); + + free(xml); + fclose(file); + + printf("XML:\n%s", xml); + + return ret; +} + +static void usage(void) +{ + printf("xml_parse_test -f [FILE | -] [--xml]\n" + "xml_parse_test -d domain [--uri URI] [--xml]\n" + "\n" + "-f,--file FILE Parse domain XML from file (or stdin if -)\n" + "-d,--domain DOM Display dominfo for a domain from libvirt\n" + "-u,--uri URI Connect to libvirt with URI\n" + "-x,--xml Dump generated XML instead of summary\n" + "-h,--help Display this help message\n"); +} + +int main(int argc, char **argv) +{ + int c; + char *domain = NULL; + char *uri = "xen"; + char *file = NULL; + bool xml = false; + struct domain *dominfo = NULL; + int ret; + + static struct option lopts[] = { + {"domain", 1, 0, 'd'}, + {"uri", 1, 0, 'u'}, + {"xml", 0, 0, 'x'}, + {"file", 1, 0, 'f'}, + {"help", 0, 0, 'h'}, + {0, 0, 0, 0}}; + + while (1) { + int optidx = 0; + + c = getopt_long(argc, argv, "d:u:f:xh", lopts, &optidx); + if (c == -1) + break; + + switch (c) { + case 'd': + domain = optarg; + break; + + case 'u': + uri = optarg; + break; + + case 'f': + file = optarg; + break; + + case 'x': + xml = true; + break; + + case '?': + case 'h': + usage(); + return c == '?'; + + }; + } + + if (file != NULL) + ret = dominfo_from_file(file, &dominfo); + else if (domain != NULL) + ret = dominfo_from_dom(uri, domain, &dominfo); + else { + printf("Need a data source (--domain or --file)\n"); + return 1; + } + + if (ret == 0) { + printf("Unable to get dominfo\n"); return 2; } - dom = virDomainLookupByName(conn, argv[1]); - if (dom == NULL) { - printf("Unable to lookup domain `%s'\n", argv[1]); - return 3; - } - - if (get_dominfo(dom, &dominfo) == 0) { - printf("Failed to parse domain info\n"); - return 4; - } - - printf("Parsed domain info\n"); - - if ((argc > 3) && (argv[3][0] == 'x')) + if (xml) print_domxml(dominfo, stdout); else { print_dominfo(dominfo, stdout); From danms at us.ibm.com Wed Jan 9 20:44:45 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 13:44:45 -0700 Subject: [Libvirt-cim] [PATCH 1 of 3] Make device_parsing get XML description for a domain once for all phases In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199911995 28800 # Node ID a229f95979d52c955d46b93c589fd1cf4744ee27 # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 Make device_parsing get XML description for a domain once for all phases Also, make memory devices parse the XML instead of ops on a domain. This gives us the ability to create a dominfo structure from XML-only. It would have been nice to put this into two separate patches, but I would have had to fake some memory stuff just to make the reorg work and then remove it in the next patch, so hopefully what I did is palatable to all :) Signed-off-by: Dan Smith diff -r ca8dc23eacc4 -r a229f95979d5 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Wed Jan 09 13:08:17 2008 +0100 +++ b/libxkutil/device_parsing.c Wed Jan 09 12:53:15 2008 -0800 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -39,11 +40,13 @@ #define VCPU_XPATH (xmlChar *)"/domain/vcpu" #define NET_XPATH (xmlChar *)"/domain/devices/interface" #define EMU_XPATH (xmlChar *)"/domain/devices/emulator" +#define MEM_XPATH (xmlChar *)"/domain/memory | /domain/currentMemory" #define GRAPHICS_XPATH (xmlChar *)"/domain/devices/graphics" #define DEFAULT_BRIDGE "xenbr0" #define XSTREQ(x, y) (STREQ((char *)x, y)) +#define MAX(a,b) (((a)>(b))?(a):(b)) static void cleanup_disk_device(struct disk_device *dev) { @@ -306,6 +309,38 @@ static int parse_emu_device(xmlNode *nod return 0; } +static int parse_mem_device(xmlNode *node, struct virt_device **vdevs) +{ + struct virt_device *vdev = NULL; + struct mem_device *mdev = NULL; + char *content = NULL; + + vdev = calloc(1, sizeof(*vdev)); + if (vdev == NULL) + goto err; + + mdev = &(vdev->dev.mem); + + content = get_node_content(node); + + if (XSTREQ(node->name, "memory")) + sscanf(content, "%" PRIu64, &mdev->size); + else if (XSTREQ(node->name, "currentMemory")) + sscanf(content, "%" PRIu64, &mdev->maxsize); + + free(content); + + *vdevs = vdev; + + return 1; + + err: + free(content); + free(vdev); + + return 0; +} + static int parse_graphics_device(xmlNode *node, struct virt_device **vdevs) { struct virt_device *vdev = NULL; @@ -366,6 +401,8 @@ static int do_parse(xmlNodeSet *nsv, int do_real_parse = parse_vcpu_device; else if (type == VIRT_DEV_EMU) do_real_parse = parse_emu_device; + else if (type == VIRT_DEV_MEM) + do_real_parse = parse_mem_device; else if (type == VIRT_DEV_GRAPHICS) do_real_parse = parse_graphics_device; else @@ -414,7 +451,7 @@ static void swallow_err_msg(void *ctx, c /* do nothing, just swallow the message. */ } -static int parse_devices(char *xml, struct virt_device **_list, int type) +static int parse_devices(const char *xml, struct virt_device **_list, int type) { int len = 0; int count = 0; @@ -432,6 +469,8 @@ static int parse_devices(char *xml, stru xpathstr = VCPU_XPATH; else if (type == VIRT_DEV_EMU) xpathstr = EMU_XPATH; + else if (type == VIRT_DEV_MEM) + xpathstr = MEM_XPATH; else if (type == VIRT_DEV_GRAPHICS) xpathstr = GRAPHICS_XPATH; else @@ -500,128 +539,60 @@ struct virt_device *virt_device_dup(stru return dev; } -static int get_emu_device(virDomainPtr dom, struct virt_device **dev) +static int _get_mem_device(const char *xml, struct virt_device **list) +{ + struct virt_device *mdevs = NULL; + struct virt_device *mdev = NULL; + int ret; + + ret = parse_devices(xml, &mdevs, VIRT_DEV_MEM); + if (ret <= 0) + return ret; + + mdev = malloc(sizeof(*mdev)); + if (mdev == NULL) + return 0; + + memset(mdev, 0, sizeof(*mdev)); + + /* We could get one or two memory devices back, depending on + * if there is a currentMemory tag or not. Coalesce these + * into a single device to return + */ + + if (ret == 2) { + mdev->dev.mem.size = MAX(mdevs[0].dev.mem.size, + mdevs[1].dev.mem.size); + mdev->dev.mem.maxsize = MAX(mdevs[0].dev.mem.maxsize, + mdevs[1].dev.mem.maxsize); + } else { + mdev->dev.mem.size = MAX(mdevs[0].dev.mem.size, + mdevs[0].dev.mem.maxsize); + mdev->dev.mem.maxsize = mdev->dev.mem.size; + } + + mdev->type = VIRT_DEV_MEM; + mdev->id = strdup("mem"); + *list = mdev; + + cleanup_virt_devices(&mdevs, ret); + + return 1; +} + +int get_devices(virDomainPtr dom, struct virt_device **list, int type) { char *xml; int ret; - struct virt_device *list = NULL; xml = virDomainGetXMLDesc(dom, 0); if (xml == NULL) return 0; - ret = parse_devices(xml, &list, VIRT_DEV_EMU); - if (ret == 1) - *dev = &list[0]; + if (type == VIRT_DEV_MEM) + ret = _get_mem_device(xml, list); else - *dev = NULL; - - free(xml); - - return ret; -} - -static int get_graphics_device(virDomainPtr dom, struct virt_device **dev) -{ - char *xml; - int ret; - struct virt_device *list = NULL; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, &list, VIRT_DEV_GRAPHICS); - if (ret == 1) - *dev = &list[0]; - else - *dev = NULL; - - free(xml); - - return ret; -} - -int get_disk_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_DISK); - - free(xml); - - return ret; -} - -int get_net_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_NET); - - free(xml); - - return ret; -} - -int get_mem_devices(virDomainPtr dom, struct virt_device **list) -{ - int rc, ret; - uint64_t mem_size, mem_maxsize; - virDomainInfo dom_info; - struct virt_device *ret_list = NULL; - - rc = virDomainGetInfo(dom, &dom_info); - if (rc == -1) { - ret = -1; - goto out; - } - - mem_size = (uint64_t)dom_info.memory; - mem_maxsize = (uint64_t)dom_info.maxMem; - if (mem_size > mem_maxsize) { - ret = -1; - goto out; - } - - ret_list = malloc(sizeof(struct virt_device)); - if (ret_list == NULL) { - ret = -1; - free (ret_list); - goto out; - } - - ret_list->type = VIRT_DEV_MEM; - ret_list->dev.mem.size = mem_size; - ret_list->dev.mem.maxsize = mem_maxsize; - ret_list->id = strdup("mem"); - - ret = 1; - *list = ret_list; - out: - return ret; -} - -int get_vcpu_devices(virDomainPtr dom, struct virt_device **list) -{ - char *xml; - int ret; - - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) - return 0; - - ret = parse_devices(xml, list, VIRT_DEV_VCPU); + ret = parse_devices(xml, list, type); free(xml); @@ -794,14 +765,19 @@ int get_dominfo(virDomainPtr dom, struct goto out; } - get_emu_device(dom, &(*dominfo)->dev_emu); - get_graphics_device(dom, &(*dominfo)->dev_graphics); - - (*dominfo)->dev_mem_ct = get_mem_devices(dom, &(*dominfo)->dev_mem); - (*dominfo)->dev_net_ct = get_net_devices(dom, &(*dominfo)->dev_net); - (*dominfo)->dev_disk_ct = get_disk_devices(dom, &(*dominfo)->dev_disk); - (*dominfo)->dev_vcpu_ct = get_vcpu_devices(dom, &(*dominfo)->dev_vcpu); - + parse_devices(xml, &(*dominfo)->dev_emu, VIRT_DEV_EMU); + parse_devices(xml, &(*dominfo)->dev_graphics, VIRT_DEV_GRAPHICS); + + (*dominfo)->dev_mem_ct = _get_mem_device(xml, &(*dominfo)->dev_mem); + (*dominfo)->dev_net_ct = parse_devices(xml, + &(*dominfo)->dev_net, + VIRT_DEV_NET); + (*dominfo)->dev_disk_ct = parse_devices(xml, + &(*dominfo)->dev_disk, + VIRT_DEV_DISK); + (*dominfo)->dev_vcpu_ct = parse_devices(xml, + &(*dominfo)->dev_vcpu, + VIRT_DEV_VCPU); out: free(xml); diff -r ca8dc23eacc4 -r a229f95979d5 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Wed Jan 09 13:08:17 2008 +0100 +++ b/libxkutil/device_parsing.h Wed Jan 09 12:53:15 2008 -0800 @@ -137,10 +137,7 @@ int get_dominfo(virDomainPtr dom, struct void cleanup_dominfo(struct domain **dominfo); -int get_disk_devices(virDomainPtr dom, struct virt_device **list); -int get_net_devices(virDomainPtr dom, struct virt_device **list); -int get_vcpu_devices(virDomainPtr dom, struct virt_device **list); -int get_mem_devices(virDomainPtr dom, struct virt_device **list); +int get_devices(virDomainPtr dom, struct virt_device **list, int type); void cleanup_virt_device(struct virt_device *dev); void cleanup_virt_devices(struct virt_device **devs, int count); diff -r ca8dc23eacc4 -r a229f95979d5 src/Virt_Device.c --- a/src/Virt_Device.c Wed Jan 09 13:08:17 2008 +0100 +++ b/src/Virt_Device.c Wed Jan 09 12:53:15 2008 -0800 @@ -283,22 +283,6 @@ int device_type_from_classname(const cha return VIRT_DEV_UNKNOWN; } -static int get_devices(virDomainPtr dom, - struct virt_device **devs, - int type) -{ - if (type == VIRT_DEV_NET) - return get_net_devices(dom, devs); - else if (type == VIRT_DEV_DISK) - return get_disk_devices(dom, devs); - else if (type == VIRT_DEV_MEM) - return get_mem_devices(dom, devs); - else if (type == VIRT_DEV_VCPU) - return get_vcpu_devices(dom, devs); - else - return -1; -} - int dom_devices(const CMPIBroker *broker, virDomainPtr dom, const char *ns, diff -r ca8dc23eacc4 -r a229f95979d5 src/Virt_DevicePool.c --- a/src/Virt_DevicePool.c Wed Jan 09 13:08:17 2008 +0100 +++ b/src/Virt_DevicePool.c Wed Jan 09 12:53:15 2008 -0800 @@ -174,7 +174,7 @@ static char *diskpool_member_of(const CM if (dom == NULL) goto out; - count = get_disk_devices(dom, &devs); + count = get_devices(dom, &devs, VIRT_DEV_DISK); for (i = 0; i < count; i++) { if (STREQ((devs[i].dev.disk.virtual_dev), dev)) { @@ -290,7 +290,7 @@ static char *netpool_member_of(const CMP if (dom == NULL) goto out; - count = get_net_devices(dom, &devs); + count = get_devices(dom, &devs, VIRT_DEV_NET); for (i = 0; i < count; i++) { if (STREQ((devs[i].id), dev)) { diff -r ca8dc23eacc4 -r a229f95979d5 src/Virt_RASD.c --- a/src/Virt_RASD.c Wed Jan 09 13:08:17 2008 +0100 +++ b/src/Virt_RASD.c Wed Jan 09 12:53:15 2008 -0800 @@ -66,16 +66,7 @@ static int list_devs(virConnectPtr conn, if (dom == NULL) return 0; - if (type == CIM_RASD_TYPE_DISK) - return get_disk_devices(dom, list); - else if (type == CIM_RASD_TYPE_NET) - return get_net_devices(dom, list); - else if (type == CIM_RASD_TYPE_PROC) - return get_vcpu_devices(dom, list); - else if (type == CIM_RASD_TYPE_MEM) - return get_mem_devices(dom, list); - else - return 0; + return get_devices(dom, list, type); } static struct virt_device *find_dev(virConnectPtr conn, From danms at us.ibm.com Wed Jan 9 20:44:46 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 13:44:46 -0700 Subject: [Libvirt-cim] [PATCH 2 of 3] Add get_dominfo_from_xml() function to device_parsing In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1199911995 28800 # Node ID a32cbc024d15b65dce1841025fafec5477614953 # Parent a229f95979d52c955d46b93c589fd1cf4744ee27 Add get_dominfo_from_xml() function to device_parsing Signed-off-by: Dan Smith diff -r a229f95979d5 -r a32cbc024d15 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Wed Jan 09 12:53:15 2008 -0800 +++ b/libxkutil/device_parsing.c Wed Jan 09 12:53:15 2008 -0800 @@ -742,28 +742,17 @@ static int _get_dominfo(const char *xml, return ret; } -int get_dominfo(virDomainPtr dom, struct domain **dominfo) -{ - char *xml; +int get_dominfo_from_xml(const char *xml, struct domain **dominfo) +{ int ret; *dominfo = malloc(sizeof(**dominfo)); if (*dominfo == NULL) return 0; - xml = virDomainGetXMLDesc(dom, 0); - if (xml == NULL) { - free(*dominfo); - *dominfo = NULL; - return 0; - } - ret = _get_dominfo(xml, *dominfo); - if (ret == 0) { - free(*dominfo); - *dominfo = NULL; - goto out; - } + if (ret == 0) + goto err; parse_devices(xml, &(*dominfo)->dev_emu, VIRT_DEV_EMU); parse_devices(xml, &(*dominfo)->dev_graphics, VIRT_DEV_GRAPHICS); @@ -778,7 +767,27 @@ int get_dominfo(virDomainPtr dom, struct (*dominfo)->dev_vcpu_ct = parse_devices(xml, &(*dominfo)->dev_vcpu, VIRT_DEV_VCPU); -out: + + return ret; + + err: + free(*dominfo); + *dominfo = NULL; + + return 0; +} + +int get_dominfo(virDomainPtr dom, struct domain **dominfo) +{ + char *xml; + int ret; + + xml = virDomainGetXMLDesc(dom, 0); + if (xml == NULL) + return 0; + + ret = get_dominfo_from_xml(xml, dominfo); + free(xml); return ret; diff -r a229f95979d5 -r a32cbc024d15 libxkutil/device_parsing.h --- a/libxkutil/device_parsing.h Wed Jan 09 12:53:15 2008 -0800 +++ b/libxkutil/device_parsing.h Wed Jan 09 12:53:15 2008 -0800 @@ -134,6 +134,7 @@ int disk_type_from_file(const char *path int disk_type_from_file(const char *path); int get_dominfo(virDomainPtr dom, struct domain **dominfo); +int get_dominfo_from_xml(const char *xml, struct domain **dominfo); void cleanup_dominfo(struct domain **dominfo); From danms at us.ibm.com Wed Jan 9 20:44:44 2008 From: danms at us.ibm.com (Dan Smith) Date: Wed, 09 Jan 2008 13:44:44 -0700 Subject: [Libvirt-cim] [PATCH 0 of 3] .#2 Memory devices from XML and raw XML Message-ID: Changes to the third patch only. Sorry the first round didn't have a commit log :) From kaitlin at linux.vnet.ibm.com Wed Jan 9 22:06:08 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Wed, 09 Jan 2008 14:06:08 -0800 Subject: [Libvirt-cim] [PATCH 0 of 3] .#2 Memory devices from XML and raw XML In-Reply-To: References: Message-ID: <47854550.40703@linux.vnet.ibm.com> Dan Smith wrote: > Changes to the third patch only. Sorry the first round didn't have > a commit log :) > The consolidation of get_* functions into the get_devices() is nice. Makes the patch a bit tough to read, but the resulting device_parsing.c file is much easier to read. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From heidieck at linux.vnet.ibm.com Thu Jan 10 12:19:22 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Thu, 10 Jan 2008 14:19:22 +0200 Subject: [Libvirt-cim] [PATCH] HRP: Validation of client given object path Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199959479 -3600 # Node ID b69727ddc9a45a32c75547a90364759500280398 # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 HRP: Validation of client given object path Signed-off-by: Heidi Eckhart diff -r ca8dc23eacc4 -r b69727ddc9a4 src/Virt_HostedResourcePool.c --- a/src/Virt_HostedResourcePool.c Wed Jan 09 13:08:17 2008 +0100 +++ b/src/Virt_HostedResourcePool.c Thu Jan 10 11:04:39 2008 +0100 @@ -68,23 +68,13 @@ static CMPIStatus sys_to_pool(const CMPI CMPIStatus s = {CMPI_RC_OK, NULL}; int i; virConnectPtr conn; - CMPIInstance *host; - const char *prop; if (!match_hypervisor_prefix(ref, info)) return s; - s = get_host_cs(_BROKER, ref, &host); + s = validate_host_ref(_BROKER, ref); if (s.rc != CMPI_RC_OK) return s; - - prop = cu_compare_ref(ref, host); - if (prop != NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_NOT_FOUND, - "No such HostSystem instance (%s)", prop); - return s; - } conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); if (conn == NULL) From heidieck at linux.vnet.ibm.com Thu Jan 10 12:21:24 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Thu, 10 Jan 2008 14:21:24 +0200 Subject: [Libvirt-cim] [PATCH 0 of 3] Check client given object pathes in ElementCapabilities provider Message-ID: To enable the check for the client's given object path in ElementCapabilities, changes to the ComputerSystem and AllocationCapabilities provider have been necessary. From heidieck at linux.vnet.ibm.com Thu Jan 10 12:21:25 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Thu, 10 Jan 2008 14:21:25 +0200 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199971251 -3600 # Node ID a45042de9fd40ef1cb150c854f506baf03690ed5 # Parent b69727ddc9a45a32c75547a90364759500280398 Add function to validate the client given object path o ComputerSystem Signed-off-by: Heidi Eckhart diff -r b69727ddc9a4 -r a45042de9fd4 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Thu Jan 10 11:04:39 2008 +0100 +++ b/src/Virt_ComputerSystem.c Thu Jan 10 14:20:51 2008 +0100 @@ -285,7 +285,7 @@ CMPIInstance *instance_from_name(const C dom = virDomainLookupByName(conn, name); if (dom == NULL) - return 0; + return NULL; instance = get_typed_instance(broker, pfx_from_conn(conn), @@ -374,45 +374,62 @@ static CMPIStatus return_enum_domains(co return s; } -static CMPIStatus get_domain(const CMPIObjectPath *reference, - const CMPIResult *results, - const char *name) -{ - CMPIInstance *inst; - CMPIStatus s; +static CMPIStatus get_domain(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **inst) +{ + CMPIInstance *_inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn = NULL; - const char *prop = NULL; - - if (!provider_is_responsible(_BROKER, reference, &s)) { - CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND); + const char *name; + + if (!provider_is_responsible(broker, reference, &s)) return s; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No domain name specified"); + return s; + } + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) return s; - inst = instance_from_name(_BROKER, conn, name, reference); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to find `%s'", name); - goto out; - } - - prop = cu_compare_ref(reference, inst); + _inst = instance_from_name(broker, conn, name, reference); + if (_inst == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", name); + goto out; + } + + out: + virConnectClose(conn); + *inst = _inst; + + return s; +} + +CMPIStatus validate_domain_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + + s = get_domain(broker, ref, &inst); + if (s.rc != CMPI_RC_OK) + return s; + + prop = cu_compare_ref(ref, inst); if (prop != NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, "No such instance (%s)", prop); - goto out; - } - - CMReturnInstance(results, inst); - CMSetStatus(&s, CMPI_RC_OK); - out: - virConnectClose(conn); - + } + return s; } @@ -440,19 +457,25 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - const char *name; - - if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { - CMPIStatus s; - - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No domain name specified"); - + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop = NULL; + + s = get_domain(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) return s; - } - - return get_domain(reference, results, name); + + prop = cu_compare_ref(reference, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + return s; + } + + CMReturnInstance(results, inst); + + return s; } DEFAULT_CI(); diff -r b69727ddc9a4 -r a45042de9fd4 src/Virt_ComputerSystem.h --- a/src/Virt_ComputerSystem.h Thu Jan 10 11:04:39 2008 +0100 +++ b/src/Virt_ComputerSystem.h Thu Jan 10 14:20:51 2008 +0100 @@ -52,6 +52,16 @@ int enum_domains(const CMPIBroker *broke const char *ns, struct inst_list *instlist); +/** + * Validate the client given domain object path + * + * @param broker A pointer to the current broker + * @param ref The client given object path + * @returns CMPIStatus + */ +CMPIStatus validate_domain_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref); + #endif From heidieck at linux.vnet.ibm.com Thu Jan 10 12:21:26 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Thu, 10 Jan 2008 14:21:26 +0200 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199971252 -3600 # Node ID fd476f08b35e235ba7e50d326e5602018ebc3730 # Parent a45042de9fd40ef1cb150c854f506baf03690ed5 Make alloc_cap_instances() available for external use by EC The association provider ElementCapabilities needs the alloc_cap_instances() function to access to the list of available AllocationCapabilities. To return this instance to the association provider a CMPIInstance** is added to the parameter list. Signed-off-by: Heidi Eckhart diff -r a45042de9fd4 -r fd476f08b35e src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c Thu Jan 10 14:20:51 2008 +0100 +++ b/src/Virt_AllocationCapabilities.c Thu Jan 10 14:20:52 2008 +0100 @@ -31,6 +31,7 @@ #include "misc_util.h" +#include "Virt_AllocationCapabilities.h" #include "Virt_DevicePool.h" const static CMPIBroker *_BROKER; @@ -71,12 +72,13 @@ static CMPIStatus ac_from_pool(const CMP return s; } -static CMPIStatus alloc_cap_instances(const CMPIBroker *broker, - const CMPIObjectPath *ref, - const CMPIResult *results, - bool names_only, - const char **properties, - const char *id) +CMPIStatus alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only, + const char **properties, + const char *id, + CMPIInstance **inst) { int i; virConnectPtr conn = NULL; @@ -86,21 +88,19 @@ static CMPIStatus alloc_cap_instances(co CMPIStatus s = {CMPI_RC_OK, NULL}; const char *inst_id; - CU_DEBUG("In alloc_cap_instances()"); + if (!provider_is_responsible(broker, ref, &s)) + goto out; + + conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + if (conn == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Could not connect to hypervisor"); + goto out; + } inst_list_init(&device_pool_list); inst_list_init(&alloc_cap_list); - - if (!provider_is_responsible(broker, ref, &s)) - goto out; - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Could not connect to hypervisor"); - goto out; - } s = get_all_pools(broker, conn, NAMESPACE(ref), &device_pool_list); if (s.rc != CMPI_RC_OK) { @@ -138,19 +138,25 @@ static CMPIStatus alloc_cap_instances(co if (id && !inst_id) { cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, - "Requested Object could not be found."); + "No such instance (%s)", id); goto out; } - if (names_only) - cu_return_instance_names(results, &alloc_cap_list); - else - cu_return_instances(results, &alloc_cap_list); + if (results) { + if (names_only) + cu_return_instance_names(results, &alloc_cap_list); + else + cu_return_instances(results, &alloc_cap_list); + } else { + if (inst) + *inst = alloc_cap_list.list[0]; + } out: virConnectClose(conn); inst_list_free(&alloc_cap_list); inst_list_free(&device_pool_list); + return s; } @@ -175,7 +181,8 @@ static CMPIStatus GetInstance(CMPIInstan results, false, properties, - id); + id, + NULL); } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -188,6 +195,7 @@ static CMPIStatus EnumInstanceNames(CMPI results, true, NULL, + NULL, NULL); } @@ -202,6 +210,7 @@ static CMPIStatus EnumInstances(CMPIInst results, false, properties, + NULL, NULL); } diff -r a45042de9fd4 -r fd476f08b35e src/Virt_AllocationCapabilities.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_AllocationCapabilities.h Thu Jan 10 14:20:52 2008 +0100 @@ -0,0 +1,57 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Heidi Eckhart + * + * 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 __VIRT_ALLOCATIONCAPABILITIES_H +#define __VIRT_ALLOCATIONCAPABILITIES_H + +#include "misc_util.h" + +/** + * Return the instance of the AllocationCapabilities instance, + * defined by the id + * + * @param broker A pointer to the current broker + * @param ref The reference + * @param results The results pointer used to return results to the broker + * @param names_only True returns object pathes, false returns instances + * @param properties list of properties to set + * @param id The InstanceID of the AllocationCapabilities + * @param inst Contains the instance pointer in case of success + * @returns The status of this operation + */ +CMPIStatus alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only, + const char **properties, + const char *id, + CMPIInstance **inst); + +#endif + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From heidieck at linux.vnet.ibm.com Thu Jan 10 12:21:27 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Thu, 10 Jan 2008 14:21:27 +0200 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1199971253 -3600 # Node ID d4471d3ac4766af68f6bf151813f0ec246b0e409 # Parent fd476f08b35e235ba7e50d326e5602018ebc3730 EC: Validation of client given object path missing The validation of the client's given ResourcePool object path is missing. Instead the submitted InstanceID is taken as value for the AllocationCapabilities InstanceID. wbemain -ac CIM_ElementCapabilities 'http://localhost/root/virt:KVM_DiskPool.InstanceID="notthere"' returns localhost:5988/root/virt:KVM_AllocationCapabilities.InstanceID="notthere" Signed-off-by: Heidi Eckhart diff -r fd476f08b35e -r d4471d3ac476 src/Makefile.am --- a/src/Makefile.am Thu Jan 10 14:20:52 2008 +0100 +++ b/src/Makefile.am Thu Jan 10 14:20:53 2008 +0100 @@ -89,17 +89,18 @@ libVirt_ElementConformsToProfile_la_LIBA libVirt_EnabledLogicalElementCapabilities_la_SOURCES = Virt_EnabledLogicalElementCapabilities.c +libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la +libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c +libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + libVirt_ElementCapabilities_la_DEPENDENCIES = libVirt_VirtualSystemManagementCapabilities.la libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la libVirt_HostSystem.la libVirt_VSMigrationCapabilities.la libVirt_ElementCapabilities_la_SOURCES = Virt_ElementCapabilities.c libVirt_ElementCapabilities_la_LIBADD = -lVirt_VirtualSystemManagementCapabilities \ -lVirt_EnabledLogicalElementCapabilities \ -lVirt_ComputerSystem \ -lVirt_HostSystem \ - -lVirt_VSMigrationCapabilities - -libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la -libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c -libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + -lVirt_VSMigrationCapabilities \ + -lVirt_AllocationCapabilities libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c diff -r fd476f08b35e -r d4471d3ac476 src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Thu Jan 10 14:20:52 2008 +0100 +++ b/src/Virt_ElementCapabilities.c Thu Jan 10 14:20:53 2008 +0100 @@ -37,6 +37,7 @@ #include "Virt_ComputerSystem.h" #include "Virt_HostSystem.h" #include "Virt_VSMigrationCapabilities.h" +#include "Virt_AllocationCapabilities.h" /* Associate an XXX_Capabilities to the proper XXX_ManagedElement. * @@ -46,6 +47,37 @@ */ const static CMPIBroker *_BROKER; + +static CMPIStatus validate_host_caps_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + char* classname; + + classname = class_base_name(CLASSNAME(ref)); + + if (STREQC(classname, "VirtualSystemManagementCapabilities")) { + s = get_vsm_cap(_BROKER, ref, &inst); + } else if (STREQC(classname, "VirtualSystemMigrationCapabilities")) { + s = get_migration_caps(ref, &inst, _BROKER); + } + + if (s.rc != CMPI_RC_OK) + goto out; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + out: + free(classname); + + return s; +} static CMPIStatus sys_to_cap(const CMPIObjectPath *ref, struct std_assoc_info *info, @@ -53,22 +85,13 @@ static CMPIStatus sys_to_cap(const CMPIO { CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; - const char *prop; - - if (!match_hypervisor_prefix(ref, info)) - return s; - - s = get_host_cs(_BROKER, ref, &inst); - if (s.rc != CMPI_RC_OK) - goto out; - - prop = cu_compare_ref(ref, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such HostSystem (%s)", prop); - goto out; - } + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = validate_host_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_vsm_cap(_BROKER, ref, &inst); if (s.rc == CMPI_RC_OK) @@ -90,7 +113,11 @@ static CMPIStatus cap_to_sys(const CMPIO CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = validate_host_caps_ref(ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_host_cs(_BROKER, ref, &inst); if (s.rc != CMPI_RC_OK) @@ -111,7 +138,11 @@ static CMPIStatus cs_to_cap(const CMPIOb const char *sys_name = NULL; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = validate_domain_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &sys_name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -138,26 +169,30 @@ static CMPIStatus cap_to_cs(const CMPIOb CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Could not get InstanceID"); - goto error1; + goto out; } conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); if (s.rc != CMPI_RC_OK) - goto error1; + goto out; inst = instance_from_name(_BROKER, conn, inst_id, ref); if (inst) inst_list_add(list, inst); - + else + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", inst_id); + virConnectClose(conn); - error1: - + + out: return s; } @@ -173,14 +208,12 @@ static CMPIStatus pool_to_alloc(const CM struct std_assoc_info *info, struct inst_list *list) { - int ret; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; const char *inst_id; - uint16_t type; - CMPIInstance *inst = NULL; - CMPIStatus s = {CMPI_RC_OK}; - - if (!match_hypervisor_prefix(ref, info)) - return s; + + if (!match_hypervisor_prefix(ref, info)) + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -189,22 +222,16 @@ static CMPIStatus pool_to_alloc(const CM goto out; } - inst = get_typed_instance(_BROKER, - CLASSNAME(ref), - "AllocationCapabilities", - NAMESPACE(ref)); - CMSetProperty(inst, "InstanceID", inst_id, CMPI_chars); - - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (ret != 1) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Could not get ResourceType"); - goto out; - } - CMSetProperty(inst, "ResourceType", &type, CMPI_uint16); - - inst_list_add(list, inst); + s = alloc_cap_instances(_BROKER, + ref, + NULL, + false, + NULL, + inst_id, + &inst); + + if (inst) + inst_list_add(list, inst); out: return s; From grendel at linux.vnet.ibm.com Thu Jan 10 16:34:36 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 10 Jan 2008 11:34:36 -0500 Subject: [Libvirt-cim] [PATCH 0 of 2] [RFC] ComputerSystemModifiedIndication Message-ID: This is still pretty rough around the edges but it seems functional enough that it's worth showing, and I've got a few spots where I could use some input. Right now it does in fact notice a domain that changes and fires an indication. The "previous instance" embedded object has it's Name and UUID fields filled in; I couldn't find any other fields that seemed terribly relevant to fill in. The places where I could use some advice: In _lifecycle_indication, the get_typed_instance args are mostly hardcoded. This seems rather bad, but I'm not quite sure where I should get them. It's not like I have a reference being passed in to pull that out of. The entire sys_name_from_xml feels like an abomination, but sscanf falls short and full xml parsing seems way overkill. Any suggestions on how to make it safer/more sane are welcome. In async_ind, I once again use some hardcoded values because I'm not sure where to get them. In lifecycle_thread, I use lv_connect because I don't think I have the requisite info for the preferred method, but AFAIK lv_connect usage is frowned upon now. I also am not sure what to do here when I get errors. Should I terminate the event loop? Where would I even return an error message to the client? From grendel at linux.vnet.ibm.com Thu Jan 10 16:34:37 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 10 Jan 2008 11:34:37 -0500 Subject: [Libvirt-cim] [PATCH 1 of 2] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: Message-ID: <6f3a50557ab0648b1fa0.1199982877@wulfgar> # HG changeset patch # User Jay Gagnon # Date 1199982797 18000 # Node ID 6f3a50557ab0648b1fa0bde747914d6e58027eef # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests. Signed-off-by: Jay Gagnon diff -r ca8dc23eacc4 -r 6f3a50557ab0 src/Virt_ComputerSystemModifiedIndication.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ComputerSystemModifiedIndication.c Thu Jan 10 11:33:17 2008 -0500 @@ -0,0 +1,379 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Jay Gagnon + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "config.h" + +#include "Virt_ComputerSystem.h" +#include "Virt_ComputerSystemModifiedIndication.h" + +static const CMPIBroker *_BROKER; + +static CMPI_THREAD_TYPE lifecycle_thread_id = 0; + +enum CS_EVENTS { + CS_MODIFIED, +}; + +static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t lifecycle_mutex = PTHREAD_MUTEX_INITIALIZER; +static bool lifecycle_enabled = 0; + +#ifdef CMPI_EI_VOID +# define _EI_RTYPE void +# define _EI_RET() return +#else +# define _EI_RTYPE CMPIStatus +# define _EI_RET() return (CMPIStatus){CMPI_RC_OK, NULL} +#endif + +int free_dom_xml (struct dom_xml dom) +{ + free(dom.uuid); + free(dom.xml); + return 0; +} + +static bool _lifecycle_indication(const CMPIBroker *broker, + const CMPIContext *ctx, + CMPIInstance *mod_inst) +{ + CMPIObjectPath *ind_op; + CMPIInstance *ind; + CMPIStatus s; + + ind = get_typed_instance(broker, + "Xen", /* Temporary hack */ + "ComputerSystemModifiedIndication", + CIM_VIRT_NS); + if (ind == NULL) { + CU_DEBUG("Failed to create ind"); + return false; + } + + ind_op = CMGetObjectPath(ind, &s); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to get ind_op"); + return false; + } + + CMSetProperty(ind, "PreviousInstance", + (CMPIValue *)&mod_inst, CMPI_instance); + + printf("Delivering Indication: %s\n", + CMGetCharPtr(CMObjectPathToString(ind_op, NULL))); + + CBDeliverIndication(_BROKER, + ctx, + CIM_VIRT_NS, + ind); + + + return true; +} + +static bool wait_for_event(void) +{ + struct timespec timeout; + int ret; + + + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += 3; + + ret = pthread_cond_timedwait(&lifecycle_cond, + &lifecycle_mutex, + &timeout); + + return true; +} + +static char *sys_name_from_xml(char *xml) +{ + char *tmp; + char *start; + char *end; + char *name; + + /* Has to be a better way. */ + tmp = strdup(xml); + start = strstr(tmp, ""); + start += 6; + end = strstr(start, ""); + end[0] = '\0'; + + name = strdup(start); + free(tmp); + + return name; +} + +static bool async_ind(CMPIContext *context, + virConnectPtr conn, + struct dom_xml prev_dom) +{ + bool rc; + char *name = NULL; + CMPIInstance *mod_inst; + const char *ns = CIM_VIRT_NS; + + /* Where should we be getting the namespace and classname? */ + mod_inst = get_typed_instance(_BROKER, + "Xen", + "ComputerSystem", + ns); + + name = sys_name_from_xml(prev_dom.xml); + CU_DEBUG("Name for system: '%s'", name); + if (name == NULL) { + rc = false; + goto out; + } + + CMSetProperty(mod_inst, "Name", + (CMPIValue *)name, CMPI_chars); + CMSetProperty(mod_inst, "UUID", + (CMPIValue *)prev_dom.uuid, CMPI_chars); + + rc = _lifecycle_indication(_BROKER, context, mod_inst); + + out: + free(name); + return rc; +} + +static CMPIStatus doms_to_xml(struct dom_xml **dom_xml_list, + virDomainPtr *dom_ptr_list, + int dom_ptr_count) +{ + int i; + int rc; + char *xml = NULL; + char uuid[VIR_UUID_STRING_BUFLEN]; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + *dom_xml_list = malloc(dom_ptr_count * sizeof(struct dom_xml)); + for (i = 0; i < dom_ptr_count; i++) { + rc = virDomainGetUUIDString(dom_ptr_list[i], uuid); + if (rc == -1) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to get UUID"); + /* If any domain fails, we fail. */ + break; + } + + xml = virDomainGetXMLDesc(dom_ptr_list[i], 0); + if (xml == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to get xml desc"); + break; + } + + (*dom_xml_list)[i].xml = strdup(xml); + (*dom_xml_list)[i].uuid = strdup(uuid); + + free(xml); + } + + return s; +} + +static bool dom_changed(struct dom_xml prev_dom, + struct dom_xml *cur_xml, + int cur_count) +{ + int i; + bool ret = false; + + for (i = 0; i < cur_count; i++) { + if (strcmp(cur_xml[i].uuid, prev_dom.uuid) != 0) + continue; + + if (strcmp(cur_xml[i].xml, prev_dom.xml) != 0) + ret = true; + + break; + } + + return ret; +} + +static CMPI_THREAD_RETURN lifecycle_thread(void *params) +{ + int i; + int cur_count; + int prev_count; + virConnectPtr conn; + virDomainPtr *tmp_list; + struct dom_xml *cur_xml = NULL; + struct dom_xml *prev_xml = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIContext *context = (CMPIContext *)params; + + /* We can't use this anymore, can we? */ + conn = lv_connect(_BROKER, &s); + + pthread_mutex_lock(&lifecycle_mutex); + + CBAttachThread(_BROKER, context); + + prev_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&prev_xml, tmp_list, prev_count); + /* TODO: status check */ + for (i = 0; i < prev_count; i++) { + virDomainFree(tmp_list[i]); + } + + CU_DEBUG("entering event loop"); + while (lifecycle_enabled) { + bool modified; + + cur_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&cur_xml, tmp_list, cur_count); + /* TODO: status check */ + for (i = 0; i < cur_count; i++) { + virDomainFree(tmp_list[i]); + } + + for (i = 0; i < prev_count; i++) { + modified = dom_changed(prev_xml[i], cur_xml, cur_count); + if (modified) { + CU_DEBUG("Domain '%s' modified.", + prev_xml[i].uuid); + async_ind(context, conn, prev_xml[i]); + } + + free_dom_xml(prev_xml[i]); + } + + free(prev_xml); + prev_xml = cur_xml; + wait_for_event(); + } + CU_DEBUG("exiting event loop"); + + pthread_mutex_unlock(&lifecycle_mutex); + + return NULL; +} + +static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, + const CMPIContext* ctx, + const CMPISelectExp* se, + const char *ns, + const CMPIObjectPath* op, + CMPIBoolean first) +{ + CU_DEBUG("ActivateFilter"); + if (lifecycle_thread_id == 0) { + CMPIContext *thread_context; + + thread_context = CBPrepareAttachThread(_BROKER, ctx); + + lifecycle_thread_id = _BROKER->xft->newThread(lifecycle_thread, + thread_context, + 0); + } + + return (CMPIStatus){CMPI_RC_OK, NULL}; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, + const CMPIContext* ctx, + const CMPISelectExp* se, + const char *ns, + const CMPIObjectPath* op, + CMPIBoolean last) +{ + return (CMPIStatus){CMPI_RC_OK, NULL}; +} + +static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, + const CMPIContext *ctx) +{ + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = true; + pthread_mutex_unlock(&lifecycle_mutex); + + CU_DEBUG("ComputerSystemModifiedIndication enabled"); + + _EI_RET(); +} + +static _EI_RTYPE DisableIndications(CMPIIndicationMI* mi, + const CMPIContext *ctx) +{ + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = false; + pthread_mutex_unlock(&lifecycle_mutex); + + CU_DEBUG("ComputerSystemModifiedIndication disabled"); + + _EI_RET(); +} + +static CMPIStatus trigger_indication(const CMPIContext *context) +{ + pthread_cond_signal(&lifecycle_cond); + CU_DEBUG("CSMI triggered"); + return(CMPIStatus){CMPI_RC_OK, NULL}; +} + +static struct std_indication_handler csmi = { + .raise_fn = NULL, + .trigger_fn = trigger_indication, +}; + +DEFAULT_IND_CLEANUP(); +DEFAULT_AF(); +DEFAULT_MP(); + +STDI_IndicationMIStub(, Virt_ComputerSystemModifiedIndicationProvider, + _BROKER, libvirt_cim_init(), &csmi); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ diff -r ca8dc23eacc4 -r 6f3a50557ab0 src/Virt_ComputerSystemModifiedIndication.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ComputerSystemModifiedIndication.h Thu Jan 10 11:33:17 2008 -0500 @@ -0,0 +1,37 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Jay Gagnon + * + * 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 + */ + +struct dom_xml { + char *uuid; + char *xml; +}; + +int free_dom_xml(struct dom_xml dom); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From grendel at linux.vnet.ibm.com Thu Jan 10 16:34:38 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 10 Jan 2008 11:34:38 -0500 Subject: [Libvirt-cim] [PATCH 2 of 2] Makefile changes and schema file additions for ComputerSystemModifiedIndication In-Reply-To: Message-ID: # HG changeset patch # User Jay Gagnon # Date 1199982800 18000 # Node ID ddafd609bda2f33a7c4cb7943ee8e08e22a3f32f # Parent 6f3a50557ab0648b1fa0bde747914d6e58027eef Makefile changes and schema file additions for ComputerSystemModifiedIndication. Signed-off-by: Jay Gagnon diff -r 6f3a50557ab0 -r ddafd609bda2 Makefile.am --- a/Makefile.am Thu Jan 10 11:33:17 2008 -0500 +++ b/Makefile.am Thu Jan 10 11:33:20 2008 -0500 @@ -24,6 +24,7 @@ MOFS = \ schema/RegisteredProfile.mof \ schema/ElementConformsToProfile.mof \ schema/ComputerSystemIndication.mof \ + schema/ComputerSystemModifiedIndication.mof \ schema/ResourceAllocationSettingData.mof \ schema/ResourcePoolConfigurationService.mof \ schema/ResourcePoolConfigurationCapabilities.mof \ @@ -65,6 +66,7 @@ REGS = \ schema/DiskPool.registration \ schema/HostedResourcePool.registration \ schema/ComputerSystemIndication.registration \ + schema/ComputerSystemModifiedIndication.registration \ schema/ResourceAllocationSettingData.registration \ schema/ResourcePoolConfigurationService.registration \ schema/ResourcePoolConfigurationCapabilities.registration \ diff -r 6f3a50557ab0 -r ddafd609bda2 src/Makefile.am --- a/src/Makefile.am Thu Jan 10 11:33:17 2008 -0500 +++ b/src/Makefile.am Thu Jan 10 11:33:20 2008 -0500 @@ -30,6 +30,7 @@ provider_LTLIBRARIES = libVirt_ComputerS libVirt_Device.la \ libVirt_SystemDevice.la \ libVirt_ComputerSystemIndication.la \ + libVirt_ComputerSystemModifiedIndication.la \ libVirt_RASD.la \ libVirt_HostSystem.la \ libVirt_VirtualSystemManagementService.la \ @@ -61,6 +62,10 @@ libVirt_ComputerSystemIndication_la_DEPE libVirt_ComputerSystemIndication_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication_la_SOURCES = Virt_ComputerSystemIndication.c libVirt_ComputerSystemIndication_la_LIBADD = -lVirt_ComputerSystem -lpthread -lrt + +libVirt_ComputerSystemModifiedIndication_la_DEPENDENCIES = libVirt_ComputerSystem.la +libVirt_ComputerSystemModifiedIndication_la_SOURCES = Virt_ComputerSystemModifiedIndication.c +libVirt_ComputerSystemModifiedIndication_la_LIBADD = -lVirt_ComputerSystem -lpthread -lrt libVirt_VirtualSystemManagementService_la_DEPENDENCIES = libVirt_ComputerSystem.la libVirt_ComputerSystemIndication.la libVirt_RASD.la libVirt_HostSystem.la libVirt_VirtualSystemManagementService_la_SOURCES = Virt_VirtualSystemManagementService.c From kaitlin at linux.vnet.ibm.com Thu Jan 10 18:01:08 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 10 Jan 2008 10:01:08 -0800 Subject: [Libvirt-cim] [PATCH] HRP: Validation of client given object path In-Reply-To: References: Message-ID: <47865D64.5010300@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1199959479 -3600 > # Node ID b69727ddc9a45a32c75547a90364759500280398 > # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 > HRP: Validation of client given object path > Signed-off-by: Heidi Eckhart > Nice cleanup. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Thu Jan 10 18:14:10 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 10 Jan 2008 10:14:10 -0800 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem In-Reply-To: References: Message-ID: <47866072.6030405@linux.vnet.ibm.com> Heidi Eckhart wrote: I like the idea of a validate function. But the body of GetInstance() is almost identical to the body of validate_domain_ref() - the only exception is that one returns an instance and the other returns a status. Could these functions be consolidated? You could change get_domain() to something like _get_domain(). Then get_domain() could call _get_domain() and validate_domain_ref(). When you need the instance returned, you can use get_domain(), otherwise you can just call validate_domain_ref() directly to validate. > -static CMPIStatus get_domain(const CMPIObjectPath *reference, > - const CMPIResult *results, > - const char *name) > -{ > - CMPIInstance *inst; > - CMPIStatus s; > +static CMPIStatus get_domain(const CMPIBroker *broker, > + const CMPIObjectPath *reference, > + CMPIInstance **inst) > +{ > + CMPIInstance *_inst; > + CMPIStatus s = {CMPI_RC_OK, NULL}; > virConnectPtr conn = NULL; > - const char *prop = NULL; > - > - if (!provider_is_responsible(_BROKER, reference, &s)) { > - CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND); > + const char *name; > + > + if (!provider_is_responsible(broker, reference, &s)) > return s; > - } > - > - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); > + > + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > + cu_statusf(broker, &s, > + CMPI_RC_ERR_FAILED, > + "No domain name specified"); > + return s; > + } > + > + conn = connect_by_classname(broker, CLASSNAME(reference), &s); > if (conn == NULL) > return s; > > - inst = instance_from_name(_BROKER, conn, name, reference); > - if (inst == NULL) { > - cu_statusf(_BROKER, &s, > - CMPI_RC_ERR_FAILED, > - "Unable to find `%s'", name); > - goto out; > - } > - > - prop = cu_compare_ref(reference, inst); > + _inst = instance_from_name(broker, conn, name, reference); > + if (_inst == NULL) { > + cu_statusf(broker, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "No such instance (%s)", name); > + goto out; > + } > + > + out: > + virConnectClose(conn); > + *inst = _inst; > + > + return s; > +} > + > +CMPIStatus validate_domain_ref(const CMPIBroker *broker, > + const CMPIObjectPath *ref) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *inst; > + const char *prop; > + > + s = get_domain(broker, ref, &inst); > + if (s.rc != CMPI_RC_OK) > + return s; > + > + prop = cu_compare_ref(ref, inst); > if (prop != NULL) { > - cu_statusf(_BROKER, &s, > + cu_statusf(broker, &s, > CMPI_RC_ERR_NOT_FOUND, > "No such instance (%s)", prop); > - goto out; > - } > - > - CMReturnInstance(results, inst); > - CMSetStatus(&s, CMPI_RC_OK); > - out: > - virConnectClose(conn); > - > + } > + > return s; > } > > @@ -440,19 +457,25 @@ static CMPIStatus GetInstance(CMPIInstan > const CMPIObjectPath *reference, > const char **properties) > { > - const char *name; > - > - if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { > - CMPIStatus s; > - > - cu_statusf(_BROKER, &s, > - CMPI_RC_ERR_FAILED, > - "No domain name specified"); > - > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *inst; > + const char *prop = NULL; > + > + s = get_domain(_BROKER, reference, &inst); > + if (s.rc != CMPI_RC_OK) > return s; > - } > - > - return get_domain(reference, results, name); > + > + prop = cu_compare_ref(reference, inst); > + if (prop != NULL) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_NOT_FOUND, > + "No such instance (%s)", prop); > + return s; > + } > + > + CMReturnInstance(results, inst); > + > + return s; > } -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Thu Jan 10 18:24:29 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 10 Jan 2008 10:24:29 -0800 Subject: [Libvirt-cim] [PATCH 1 of 2] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: <6f3a50557ab0648b1fa0.1199982877@wulfgar> (Jay Gagnon's message of "Thu, 10 Jan 2008 11:34:37 -0500") References: <6f3a50557ab0648b1fa0.1199982877@wulfgar> Message-ID: <87ejcp7d42.fsf@theine.beaverton.ibm.com> JG> --- /dev/null Thu Jan 01 00:00:00 1970 +0000 JG> +++ b/src/Virt_ComputerSystemModifiedIndication.c Thu Jan 10 11:33:17 2008 -0500 I guess I had assumed that the modified indication would be integrated into the ComputerSystemIndication provider, instead of broken out alone (since the other handles Create and Destroy as well). Is there any reason that we shouldn't merge the two? JG> +int free_dom_xml (struct dom_xml dom) JG> +{ JG> + free(dom.uuid); JG> + free(dom.xml); JG> + return 0; JG> +} Looks like this could probably be a void function, which is what we do for the cleanup functions in device_parsing. JG> +static bool _lifecycle_indication(const CMPIBroker *broker, JG> + const CMPIContext *ctx, JG> + CMPIInstance *mod_inst) JG> +{ JG> + CMPIObjectPath *ind_op; JG> + CMPIInstance *ind; JG> + CMPIStatus s; JG> + JG> + ind = get_typed_instance(broker, JG> + "Xen", /* Temporary hack */ JG> + "ComputerSystemModifiedIndication", JG> + CIM_VIRT_NS); To determine the prefix, couldn't you get the prefix from mod_inst? I assume that mod_inst is a Xen_ComputerSystem (or similar), so you could grab the prefix from there. JG> + CBDeliverIndication(_BROKER, JG> + ctx, JG> + CIM_VIRT_NS, JG> + ind); JG> + JG> + JG> + return true; You've got an extra blank line in there :) JG> +static char *sys_name_from_xml(char *xml) JG> +{ JG> + char *tmp; JG> + char *start; JG> + char *end; JG> + char *name; JG> + JG> + /* Has to be a better way. */ JG> + tmp = strdup(xml); JG> + start = strstr(tmp, ""); JG> + start += 6; JG> + end = strstr(start, ""); JG> + end[0] = '\0'; Perhaps something like this: char *name = NULL; int ret; ret = sscanf(xml, "%a[^<]", &name); if (ret != 1) { /* Error */ } JG> +static bool async_ind(CMPIContext *context, JG> + virConnectPtr conn, JG> + struct dom_xml prev_dom) JG> +{ JG> + bool rc; JG> + char *name = NULL; JG> + CMPIInstance *mod_inst; JG> + const char *ns = CIM_VIRT_NS; JG> + JG> + /* Where should we be getting the namespace and classname? */ JG> + mod_inst = get_typed_instance(_BROKER, JG> + "Xen", JG> + "ComputerSystem", JG> + ns); I think using CIM_VIRT_NS is the right approach here. We use it in other places where we have to create an instance with no reference. Read on for a comment about the prefix. JG> +static CMPIStatus doms_to_xml(struct dom_xml **dom_xml_list, JG> + virDomainPtr *dom_ptr_list, JG> + int dom_ptr_count) JG> +{ JG> + int i; JG> + int rc; JG> + char *xml = NULL; JG> + char uuid[VIR_UUID_STRING_BUFLEN]; JG> + CMPIStatus s = {CMPI_RC_OK, NULL}; JG> + JG> + *dom_xml_list = malloc(dom_ptr_count * sizeof(struct dom_xml)); Using calloc() here would be more conventional. JG> + for (i = 0; i < dom_ptr_count; i++) { JG> + rc = virDomainGetUUIDString(dom_ptr_list[i], uuid); Why not just get the UUID directly to the dom_xml_list? rc = virDomainGetUUIDString(dom_ptr_list[i], (*dom_xml_list)[i].uuid); JG> + xml = virDomainGetXMLDesc(dom_ptr_list[i], 0); JG> + if (xml == NULL) { JG> + cu_statusf(broker, &s, JG> + CMPI_RC_ERR_FAILED, JG> + "Failed to get xml desc"); JG> + break; JG> + } JG> + JG> + (*dom_xml_list)[i].xml = strdup(xml); Do you need to strdup() the xml? It's just a malloc'd string anyway, right? JG> +static CMPI_THREAD_RETURN lifecycle_thread(void *params) JG> +{ JG> + int i; JG> + int cur_count; JG> + int prev_count; JG> + virConnectPtr conn; JG> + virDomainPtr *tmp_list; JG> + struct dom_xml *cur_xml = NULL; JG> + struct dom_xml *prev_xml = NULL; JG> + CMPIStatus s = {CMPI_RC_OK, NULL}; JG> + CMPIContext *context = (CMPIContext *)params; JG> + JG> + /* We can't use this anymore, can we? */ Correct :) JG> + conn = lv_connect(_BROKER, &s); This will only connect to Xen (if present) or KVM (if present), but not both. You need to get the prefix of yourself (i.e. if this is a KVM_ or Xen_ indication) and use that to connect_by_classname(). Thus, if a client subscribes to a Xen_ indication, and another subscribes to a KVM_ indication, then there will be two threads. I think that logic would be another good reason to merge this into the original ComputerSystemIndication provider, so you can share that logic (the other provider currently lacks it as well). JG> + for (i = 0; i < prev_count; i++) { JG> + virDomainFree(tmp_list[i]); JG> + } Perhaps we need a cleanup_domain_list() function? JG> + JG> + CU_DEBUG("entering event loop"); JG> + while (lifecycle_enabled) { JG> + bool modified; JG> + JG> + cur_count = get_domain_list(conn, &tmp_list); JG> + s = doms_to_xml(&cur_xml, tmp_list, cur_count); JG> + /* TODO: status check */ JG> + for (i = 0; i < cur_count; i++) { JG> + virDomainFree(tmp_list[i]); JG> + } JG> + JG> + for (i = 0; i < prev_count; i++) { JG> + modified = dom_changed(prev_xml[i], cur_xml, cur_count); JG> + if (modified) { JG> + CU_DEBUG("Domain '%s' modified.", JG> + prev_xml[i].uuid); JG> + async_ind(context, conn, prev_xml[i]); JG> + } JG> + JG> + free_dom_xml(prev_xml[i]); JG> + } JG> + JG> + free(prev_xml); JG> + prev_xml = cur_xml; JG> + wait_for_event(); JG> + } See, I think the above loop can detect additions, subtractions, and changes. This will avoid having multiple threads banging on libvirt every cycle. JG> --- /dev/null Thu Jan 01 00:00:00 1970 +0000 JG> +++ b/src/Virt_ComputerSystemModifiedIndication.h Thu Jan 10 11:33:17 2008 -0500 JG> @@ -0,0 +1,37 @@ JG> +struct dom_xml { JG> + char *uuid; JG> + char *xml; JG> +}; JG> + JG> +int free_dom_xml(struct dom_xml dom); I don't think these need to be known outside of the provider, do they? In that case, you can just do away with this whole header and define the struct in the .c file. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Thu Jan 10 18:35:48 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 10 Jan 2008 10:35:48 -0800 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: References: Message-ID: <47866584.9050208@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1199971253 -3600 > # Node ID d4471d3ac4766af68f6bf151813f0ec246b0e409 > # Parent fd476f08b35e235ba7e50d326e5602018ebc3730 > EC: Validation of client given object path missing > > conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); > if (s.rc != CMPI_RC_OK) > - goto error1; > + goto out; A question not directly related to this patch: Shouldn't we also check to see if conn is NULL here? If connect_by_classname() is unable to connect, an error value isn't assigned to the CMPIStatus variable. Or possibly a better approach would be to modify connect_by_classname() so that it sets an error. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Thu Jan 10 18:45:32 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 10 Jan 2008 10:45:32 -0800 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: <47866584.9050208@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Thu, 10 Jan 2008 10:35:48 -0800") References: <47866584.9050208@linux.vnet.ibm.com> Message-ID: <87sl155xkj.fsf@theine.beaverton.ibm.com> KR> Or possibly a better approach would be to modify KR> connect_by_classname() so that it sets an error. I'm pretty sure that connect_by_classname() used to set an error in the CMPIStatus if it was going to return NULL. I probably broke that when I fixed up (yes, ironic) the connect_by_classname() stuff a little while ago. Good catch! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Thu Jan 10 19:01:29 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 10 Jan 2008 11:01:29 -0800 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC References: Message-ID: <87hchl5wty.fsf@theine.beaverton.ibm.com> HE> + if (!provider_is_responsible(broker, ref, &s)) HE> + goto out; HE> + HE> + conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); HE> + if (conn == NULL) { HE> + cu_statusf(broker, &s, HE> + CMPI_RC_ERR_FAILED, HE> + "Could not connect to hypervisor"); HE> + goto out; HE> + } HE> inst_list_init(&device_pool_list); HE> inst_list_init(&alloc_cap_list); HE> - HE> - if (!provider_is_responsible(broker, ref, &s)) HE> - goto out; HE> - HE> - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); HE> - if (conn == NULL) { HE> - cu_statusf(broker, &s, HE> - CMPI_RC_ERR_FAILED, HE> - "Could not connect to hypervisor"); HE> - goto out; HE> - } Moving these functions above the inst_list_init() calls will cause a crash on error, because the out target tries to free them. As far as I can tell, these aren't related to the rest of the patch in any way. If there is something to fix here, perhaps we can call it out and make it a distinct patch? HE> @@ -138,19 +138,25 @@ static CMPIStatus alloc_cap_instances(co HE> if (id && !inst_id) { HE> cu_statusf(broker, &s, HE> CMPI_RC_ERR_NOT_FOUND, HE> - "Requested Object could not be found."); HE> + "No such instance (%s)", id); Also, this change doesn't seem to be necessary, and makes this one error message inconsistent with many others that we already have. If this is a personal preference change, then it should be a distinct patch that either changes (or plans to change) the other instances of these error messages. HE> - if (names_only) HE> - cu_return_instance_names(results, &alloc_cap_list); HE> - else HE> - cu_return_instances(results, &alloc_cap_list); HE> + if (results) { HE> + if (names_only) HE> + cu_return_instance_names(results, &alloc_cap_list); HE> + else HE> + cu_return_instances(results, &alloc_cap_list); HE> + } else { HE> + if (inst) HE> + *inst = alloc_cap_list.list[0]; HE> + } I'm not okay with this change. From what I can see, this function was modified to have a dual return path, where either results is passed in, and inst is NULL, or vice versa. If you want to have the opportunity to intercept the instances coming back, then the function should take in an inst_list, and populate it. The caller can then either return or inspect the result. Other places in the code, we have a function as described, and then a pass-through function called "return_foo()" that calls the function that returns the list, and then calls cm_return_instance...(). Such a function seems appropriate here. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From grendel at linux.vnet.ibm.com Thu Jan 10 19:48:07 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 10 Jan 2008 14:48:07 -0500 Subject: [Libvirt-cim] [PATCH 1 of 2] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: <87ejcp7d42.fsf@theine.beaverton.ibm.com> References: <6f3a50557ab0648b1fa0.1199982877@wulfgar> <87ejcp7d42.fsf@theine.beaverton.ibm.com> Message-ID: <47867677.6090403@linux.vnet.ibm.com> Dan Smith wrote: > JG> --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > JG> +++ b/src/Virt_ComputerSystemModifiedIndication.c Thu Jan 10 11:33:17 2008 -0500 > > I guess I had assumed that the modified indication would be integrated > into the ComputerSystemIndication provider, instead of broken out > alone (since the other handles Create and Destroy as well). Is there > any reason that we shouldn't merge the two? > Huh, I hadn't even thought of that. Yea, that could probably work. I don't think integrating should be too tough. Only issue might be that my async_ind() function is a bit different from the CSI one. > JG> +int free_dom_xml (struct dom_xml dom) > JG> +{ > JG> + free(dom.uuid); > JG> + free(dom.xml); > JG> + return 0; > JG> +} > > Looks like this could probably be a void function, which is what we do > for the cleanup functions in device_parsing. > Sure, no prob. > JG> +static bool _lifecycle_indication(const CMPIBroker *broker, > JG> + const CMPIContext *ctx, > JG> + CMPIInstance *mod_inst) > JG> +{ > JG> + CMPIObjectPath *ind_op; > JG> + CMPIInstance *ind; > JG> + CMPIStatus s; > JG> + > JG> + ind = get_typed_instance(broker, > JG> + "Xen", /* Temporary hack */ > JG> + "ComputerSystemModifiedIndication", > JG> + CIM_VIRT_NS); > > To determine the prefix, couldn't you get the prefix from mod_inst? I > assume that mod_inst is a Xen_ComputerSystem (or similar), so you > could grab the prefix from there. > I found the comment further down about prefix; I'll respond there. > JG> + CBDeliverIndication(_BROKER, > JG> + ctx, > JG> + CIM_VIRT_NS, > JG> + ind); > JG> + > JG> + > JG> + return true; > > You've got an extra blank line in there :) > Oops. :) > JG> +static char *sys_name_from_xml(char *xml) > JG> +{ > JG> + char *tmp; > JG> + char *start; > JG> + char *end; > JG> + char *name; > JG> + > JG> + /* Has to be a better way. */ > JG> + tmp = strdup(xml); > JG> + start = strstr(tmp, ""); > JG> + start += 6; > JG> + end = strstr(start, ""); > JG> + end[0] = '\0'; > > Perhaps something like this: > > char *name = NULL; > int ret; > > ret = sscanf(xml, "%a[^<]", &name); > if (ret != 1) { > /* Error */ > } > Ah, this explains my frustration with sscanf. I had been operating under the assumption that I need some sort of wildcarding before and after the relevant string, and was getting very upset with sscanf for not appearing to support wildcarding. Not sure why I had determined I needed it, but this can work. > JG> +static bool async_ind(CMPIContext *context, > JG> + virConnectPtr conn, > JG> + struct dom_xml prev_dom) > JG> +{ > JG> + bool rc; > JG> + char *name = NULL; > JG> + CMPIInstance *mod_inst; > JG> + const char *ns = CIM_VIRT_NS; > JG> + > JG> + /* Where should we be getting the namespace and classname? */ > JG> + mod_inst = get_typed_instance(_BROKER, > JG> + "Xen", > JG> + "ComputerSystem", > JG> + ns); > > I think using CIM_VIRT_NS is the right approach here. We use it > in other places where we have to create an instance with no > reference. > > Read on for a comment about the prefix. > > JG> +static CMPIStatus doms_to_xml(struct dom_xml **dom_xml_list, > JG> + virDomainPtr *dom_ptr_list, > JG> + int dom_ptr_count) > JG> +{ > JG> + int i; > JG> + int rc; > JG> + char *xml = NULL; > JG> + char uuid[VIR_UUID_STRING_BUFLEN]; > JG> + CMPIStatus s = {CMPI_RC_OK, NULL}; > JG> + > JG> + *dom_xml_list = malloc(dom_ptr_count * sizeof(struct dom_xml)); > > Using calloc() here would be more conventional. > Okay. > JG> + for (i = 0; i < dom_ptr_count; i++) { > JG> + rc = virDomainGetUUIDString(dom_ptr_list[i], uuid); > > Why not just get the UUID directly to the dom_xml_list? > Heh, good call. > rc = virDomainGetUUIDString(dom_ptr_list[i], (*dom_xml_list)[i].uuid); > > JG> + xml = virDomainGetXMLDesc(dom_ptr_list[i], 0); > JG> + if (xml == NULL) { > JG> + cu_statusf(broker, &s, > JG> + CMPI_RC_ERR_FAILED, > JG> + "Failed to get xml desc"); > JG> + break; > JG> + } > JG> + > JG> + (*dom_xml_list)[i].xml = strdup(xml); > > Do you need to strdup() the xml? It's just a malloc'd string anyway, > right? Heh, I think my not-C roots are showing there. I was paying too much attention to being safe with memory and totally didn't realize I was wasting work there. > > > JG> +static CMPI_THREAD_RETURN lifecycle_thread(void *params) > JG> +{ > JG> + int i; > JG> + int cur_count; > JG> + int prev_count; > JG> + virConnectPtr conn; > JG> + virDomainPtr *tmp_list; > JG> + struct dom_xml *cur_xml = NULL; > JG> + struct dom_xml *prev_xml = NULL; > JG> + CMPIStatus s = {CMPI_RC_OK, NULL}; > JG> + CMPIContext *context = (CMPIContext *)params; > JG> + > JG> + /* We can't use this anymore, can we? */ > > Correct :) > > JG> + conn = lv_connect(_BROKER, &s); > > This will only connect to Xen (if present) or KVM (if present), but > not both. > > You need to get the prefix of yourself (i.e. if this is a KVM_ or Xen_ > indication) and use that to connect_by_classname(). Thus, if a client > subscribes to a Xen_ indication, and another subscribes to a KVM_ > indication, then there will be two threads. > > I think that logic would be another good reason to merge this into the > original ComputerSystemIndication provider, so you can share that > logic (the other provider currently lacks it as well). > Okay, yea that sounds fine. As I said before, the actual process of firing the indication might be a little hairy to merge in, but I think I'll manage. > JG> + for (i = 0; i < prev_count; i++) { > JG> + virDomainFree(tmp_list[i]); > JG> + } > > Perhaps we need a cleanup_domain_list() function? > Yea, I do have that block twice in the same function, after all. I didn't make it separate earlier with some sort of "it's only three lines" rationalization, but it's definitely more in sync with how we do things. > JG> + > JG> + CU_DEBUG("entering event loop"); > JG> + while (lifecycle_enabled) { > JG> + bool modified; > JG> + > JG> + cur_count = get_domain_list(conn, &tmp_list); > JG> + s = doms_to_xml(&cur_xml, tmp_list, cur_count); > JG> + /* TODO: status check */ > JG> + for (i = 0; i < cur_count; i++) { > JG> + virDomainFree(tmp_list[i]); > JG> + } > JG> + > JG> + for (i = 0; i < prev_count; i++) { > JG> + modified = dom_changed(prev_xml[i], cur_xml, cur_count); > JG> + if (modified) { > JG> + CU_DEBUG("Domain '%s' modified.", > JG> + prev_xml[i].uuid); > JG> + async_ind(context, conn, prev_xml[i]); > JG> + } > JG> + > JG> + free_dom_xml(prev_xml[i]); > JG> + } > JG> + > JG> + free(prev_xml); > JG> + prev_xml = cur_xml; > JG> + wait_for_event(); > JG> + } > > See, I think the above loop can detect additions, subtractions, and > changes. This will avoid having multiple threads banging on libvirt > every cycle. > I can certainly give it a shot. I'm more comfortable with indications in general now, so modifying it won't seem so daunting. > JG> --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > JG> +++ b/src/Virt_ComputerSystemModifiedIndication.h Thu Jan 10 11:33:17 2008 -0500 > JG> @@ -0,0 +1,37 @@ > > > > JG> +struct dom_xml { > JG> + char *uuid; > JG> + char *xml; > JG> +}; > JG> + > JG> +int free_dom_xml(struct dom_xml dom); > > I don't think these need to be known outside of the provider, do they? > In that case, you can just do away with this whole header and define > the struct in the .c file. > > I had gone back in forth on that one, so whichever way you prefer is fine by me. Okay, so lots of stuff, which is good; definitely better than, "I dunno looks fine here," since I knew it was a bit shaky. I'll fix up the small stuff and then start trying to wedge it into the existing CSI. -- -Jay From grendel at linux.vnet.ibm.com Thu Jan 10 21:35:36 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Thu, 10 Jan 2008 16:35:36 -0500 Subject: [Libvirt-cim] [PATCH 0 of 2] [RFC] ComputerSystemModifiedIndication In-Reply-To: References: Message-ID: <47868FA8.9010601@linux.vnet.ibm.com> Jay Gagnon wrote: > This is still pretty rough around the edges but it seems functional enough that it's worth showing, and I've got a few spots where I could use some input. Right now it does in fact notice a domain that changes and fires an indication. The "previous instance" embedded object has it's Name and UUID fields filled in; I couldn't find any other fields that seemed terribly relevant to fill in. > > The places where I could use some advice: > > In _lifecycle_indication, the get_typed_instance args are mostly hardcoded. This seems rather bad, but I'm not quite sure where I should get them. It's not like I have a reference being passed in to pull that out of. > > The entire sys_name_from_xml feels like an abomination, but sscanf falls short and full xml parsing seems way overkill. Any suggestions on how to make it safer/more sane are welcome. > > In async_ind, I once again use some hardcoded values because I'm not sure where to get them. > > In lifecycle_thread, I use lv_connect because I don't think I have the requisite info for the preferred method, but AFAIK lv_connect usage is frowned upon now. I also am not sure what to do here when I get errors. Should I terminate the event loop? Where would I even return an error message to the client? > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > One thing I think I forgot to mention here (and any rate haven't seen any comments on) is what I should do when the indication event loop is doing its thing, it doesn't really know what to do with an error. Say for example, that it fails at getting the xml description for a domain. In most providers, I would use cu_statusf and bail, but here I've got nobody to give my status to and nowhere to bail to, other than what amounts to an untimely death. Is there a mechanism for indications reporting errors, beyond CU_DEBUG'ing "help" and hoping to recover? -- -Jay From danms at us.ibm.com Thu Jan 10 21:45:55 2008 From: danms at us.ibm.com (Dan Smith) Date: Thu, 10 Jan 2008 13:45:55 -0800 Subject: [Libvirt-cim] [PATCH 0 of 2] [RFC] ComputerSystemModifiedIndication In-Reply-To: <47868FA8.9010601@linux.vnet.ibm.com> (Jay Gagnon's message of "Thu, 10 Jan 2008 16:35:36 -0500") References: <47868FA8.9010601@linux.vnet.ibm.com> Message-ID: <87d4s95p7w.fsf@theine.beaverton.ibm.com> JG> Is there a mechanism for indications reporting errors, beyond JG> CU_DEBUG'ing "help" and hoping to recover? I would expect that the answer will be that there isn't much that can be done. A CU_DEBUG() indicating the issue is certainly required, but I'm not sure what else we have. I tend to think that indications are mostly for convenience and optimization, to avoid pinging the providers unnecessarily, in which case an error wouldn't be catastrophic. Multiple clients monitoring a single provider would use them to notice when the other makes a change. Maybe Heidi has a better answer for this? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Thu Jan 10 22:50:18 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Thu, 10 Jan 2008 14:50:18 -0800 Subject: [Libvirt-cim] [PATCH] Fix connect_by_classname() to set error status when connect fails Message-ID: # HG changeset patch # User Kaitlin Rupert # Date 1200005355 28800 # Node ID bb05fe5857468c3a524a29c06390d90ac84dde68 # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 Fix connect_by_classname() to set error status when connect fails. Signed-off-by: Kaitlin Rupert diff -r ca8dc23eacc4 -r bb05fe585746 libxkutil/misc_util.c --- a/libxkutil/misc_util.c Wed Jan 09 13:08:17 2008 +0100 +++ b/libxkutil/misc_util.c Thu Jan 10 14:49:15 2008 -0800 @@ -71,7 +71,9 @@ virConnectPtr connect_by_classname(const conn = virConnectOpen(uri); if (!conn) { - CU_DEBUG("Unable to connect to `%s'", uri); + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to connect to `%s'", uri); return NULL; } From lizg at cn.ibm.com Fri Jan 11 09:16:09 2008 From: lizg at cn.ibm.com (lizg at cn.ibm.com) Date: Fri, 11 Jan 2008 17:16:09 +0800 Subject: [Libvirt-cim] [PATCH] Fix array type missing in VSMigrationCapabilities properties Message-ID: # HG changeset patch # User Zhengang Li # Date 1200042953 -28800 # Node ID ebb30883a8e98732e2800193eacc11cbe00eb18c # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 Fix array type missing in VSMigrationCapabilities properties. sfcb doesn't seem to doing well on array without a type. It will report an 'invalid data type 8192 2000' upon generating the returned instances for EnumInstances request. Signed-off-by: Zhengang Li diff -r ca8dc23eacc4 -r ebb30883a8e9 src/Virt_VSMigrationCapabilities.c --- a/src/Virt_VSMigrationCapabilities.c Wed Jan 09 13:08:17 2008 +0100 +++ b/src/Virt_VSMigrationCapabilities.c Fri Jan 11 17:15:53 2008 +0800 @@ -46,7 +46,7 @@ static CMPIStatus set_method_properties( CMPIStatus s; uint16_t val; - array = CMNewArray(broker, 2, CMPI_INTEGER, &s); + array = CMNewArray(broker, 2, CMPI_uint16, &s); if (s.rc != CMPI_RC_OK) return s; @@ -57,10 +57,10 @@ static CMPIStatus set_method_properties( CMSetArrayElementAt(array, 1, (CMPIValue *)&val, CMPI_uint16); CMSetProperty(inst, "AsynchronousMethodsSupported", - (CMPIValue *)&array, CMPI_ARRAY); + (CMPIValue *)&array, CMPI_uint16A); - array = CMNewArray(broker, 2, CMPI_INTEGER, &s); + array = CMNewArray(broker, 2, CMPI_uint16, &s); if (s.rc != CMPI_RC_OK) return s; @@ -71,7 +71,7 @@ static CMPIStatus set_method_properties( CMSetArrayElementAt(array, 1, (CMPIValue *)&val, CMPI_uint16); CMSetProperty(inst, "SynchronousMethodsSupported", - (CMPIValue *)&array, CMPI_ARRAY); + (CMPIValue *)&array, CMPI_uint16A); CMSetStatus(&s, CMPI_RC_OK); From heidieck at linux.vnet.ibm.com Fri Jan 11 10:11:12 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 11:11:12 +0100 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem In-Reply-To: <47866072.6030405@linux.vnet.ibm.com> References: <47866072.6030405@linux.vnet.ibm.com> Message-ID: <478740C0.2000401@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Heidi Eckhart wrote: > > I like the idea of a validate function. But the body of GetInstance() > is almost identical to the body of validate_domain_ref() - the only > exception is that one returns an instance and the other returns a status. > > Could these functions be consolidated? > You could change get_domain() to something like _get_domain(). Then > get_domain() could call _get_domain() and validate_domain_ref(). When > you need the instance returned, you can use get_domain(), otherwise > you can just call validate_domain_ref() directly to validate. > In general a very good idea, but it causes a "hen and egg" situation. The intention of validate_domain_ref() is to be used by other providers to check if the client given object path is valid for this system. That means validate_domain_ref() can only get the object path as input parameter (besides the broker), because it should not be the calling function's responsibility to retrieve the domain instance before using validate_domain_ref(). This means validate_domain_ref() has to retrieve the real instance and compare this one against the client given object path. If the functions are reordered like above, this causes that get_domain() calls _get_domain() twice. First to retrieve the instance for a later returning - and second within validate_domain_ref() as it needs the instance for the comparison. So validate_domain_ref() can not be used internally. Its only an interface for external provider usage. But your comments made me rethink about the patch. So I've consolidated and reordered a bit. - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - that does the check between the system instance and the client given instance - get_domain() is now using the new libcmpiutil function - the parameter CMPIInstance **inst is now used to "configure" get_domain(); for internal usage the inst is returned and for external usage this can be ignored by setting it to NULL - validate_domain_ref() is now only an interface name for the client; this could also be removed and the provider has then to call get_domain(broker, ref, NULL) or simply ignores the returned instance; but what I do not really like is, that this can confuse the reader of the code; but I'm open for discussion and opinions Will send out the patch soon. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Fri Jan 11 09:12:14 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 11:12:14 +0200 Subject: [Libvirt-cim] [PATCH] [CU] Add function to validate a client given object path Message-ID: <393ba1344f5be2ea42b2.1200046334@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1200043988 -3600 # Node ID 393ba1344f5be2ea42b21adea0d377de440516dc # Parent 2a52fc3c4bbcc3efe93d2943928c8d3128dca03b [CU] Add function to validate a client given object path Signed-off-by: Heidi Eckhart diff -r 2a52fc3c4bbc -r 393ba1344f5b instance_util.c --- a/instance_util.c Thu Dec 13 11:10:59 2007 +0100 +++ b/instance_util.c Fri Jan 11 10:33:08 2008 +0100 @@ -154,6 +154,23 @@ const char *cu_compare_ref(const CMPIObj prop = NULL; out: return prop; +} + +CMPIStatus cu_validate_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIInstance *inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *prop; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + return s; } CMPIStatus cu_copy_prop(const CMPIBroker *broker, diff -r 2a52fc3c4bbc -r 393ba1344f5b libcmpiutil.h --- a/libcmpiutil.h Thu Dec 13 11:10:59 2007 +0100 +++ b/libcmpiutil.h Fri Jan 11 10:33:08 2008 +0100 @@ -377,6 +377,10 @@ int inst_list_add(struct inst_list *list * or NULL if all match */ const char *cu_compare_ref(const CMPIObjectPath *ref, + const CMPIInstance *inst); + +CMPIStatus cu_validate_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref, const CMPIInstance *inst); #define DEFAULT_EIN(pn) \ From heidieck at linux.vnet.ibm.com Fri Jan 11 11:06:30 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:06:30 +0100 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: <87hchl5wty.fsf@theine.beaverton.ibm.com> References: <87hchl5wty.fsf@theine.beaverton.ibm.com> Message-ID: <47874DB6.4080908@linux.vnet.ibm.com> Dan Smith wrote: > Moving these functions above the inst_list_init() calls will cause a > crash on error, because the out target tries to free them. > Mhh, as we have many free operations now that can handle NULL pointers, I suggest to also make inst_list_free() able to handle NULL pointers. > As far as I can tell, these aren't related to the rest of the patch in > any way. If there is something to fix here, perhaps we can call it > out and make it a distinct patch? > Agreed. I will cook up a patch for inst_list_free(). The intention to move the inst_list_init() functions below connect_by_classname() was to avoid some cycles, because the case where the provider exits right after provider_is_responsible() or connect_by_classname() can happen often. > HE> @@ -138,19 +138,25 @@ static CMPIStatus alloc_cap_instances(co > HE> if (id && !inst_id) { > HE> cu_statusf(broker, &s, > HE> CMPI_RC_ERR_NOT_FOUND, > HE> - "Requested Object could not be found."); > HE> + "No such instance (%s)", id); > > Also, this change doesn't seem to be necessary, and makes this one > error message inconsistent with many others that we already have. If > this is a personal preference change, then it should be a distinct > patch that either changes (or plans to change) the other instances of > these error messages. > Agreed. I saw that we already have a task for "Fix up all the error codes in returned status values (everything is currently CMPI_RC_ERR_FAILED)". So we should leave this discussion for there. I will remove this change. > HE> - if (names_only) > HE> - cu_return_instance_names(results, &alloc_cap_list); > HE> - else > HE> - cu_return_instances(results, &alloc_cap_list); > HE> + if (results) { > HE> + if (names_only) > HE> + cu_return_instance_names(results, &alloc_cap_list); > HE> + else > HE> + cu_return_instances(results, &alloc_cap_list); > HE> + } else { > HE> + if (inst) > HE> + *inst = alloc_cap_list.list[0]; > HE> + } > > I'm not okay with this change. From what I can see, this function was > modified to have a dual return path, where either results is passed > in, and inst is NULL, or vice versa. If you want to have the > opportunity to intercept the instances coming back, then the function > should take in an inst_list, and populate it. The caller can then > either return or inspect the result. > Very good catch. Sometimes the goal to make the best out of the existing code makes oneself blind for bigger changes. Thanks. > Other places in the code, we have a function as described, and then a > pass-through function called "return_foo()" that calls the function > that returns the list, and then calls cm_return_instance...(). Such a > function seems appropriate here. > > -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Fri Jan 11 11:17:07 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:17:07 +0100 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: <87sl155xkj.fsf@theine.beaverton.ibm.com> References: <47866584.9050208@linux.vnet.ibm.com> <87sl155xkj.fsf@theine.beaverton.ibm.com> Message-ID: <47875033.1020704@linux.vnet.ibm.com> Dan Smith wrote: > KR> Or possibly a better approach would be to modify > KR> connect_by_classname() so that it sets an error. > > I'm pretty sure that connect_by_classname() used to set an error in > the CMPIStatus if it was going to return NULL. Yes, it did. But for consistency with CIM this was removed. The reason is that a request against KVM on a Xen system can not return with an error, as this breaks the CIM model and operations. This happens if the client does e.g. an ein on CIM_ComputerSystem. We know that this one request gets split up into requests against Xen_ComputerSystem and KVM_ComputerSystem by the CIMOM. The CIMOM would then only return the error code of the KVM request and revoke the instances returned by the Xen request. This behavior would be wrong. > I probably broke that > when I fixed up (yes, ironic) the connect_by_classname() stuff a > little while ago. > > Good catch! > > -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Fri Jan 11 11:18:39 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:18:39 +0100 Subject: [Libvirt-cim] [PATCH] Fix connect_by_classname() to set error status when connect fails In-Reply-To: References: Message-ID: <4787508F.6040409@linux.vnet.ibm.com> Kaitlin Rupert wrote: > # HG changeset patch > # User Kaitlin Rupert > # Date 1200005355 28800 > # Node ID bb05fe5857468c3a524a29c06390d90ac84dde68 > # Parent ca8dc23eacc44970a2d79978bc9de65aaa600b92 > Fix connect_by_classname() to set error status when connect fails. > > Signed-off-by: Kaitlin Rupert > > diff -r ca8dc23eacc4 -r bb05fe585746 libxkutil/misc_util.c > --- a/libxkutil/misc_util.c Wed Jan 09 13:08:17 2008 +0100 > +++ b/libxkutil/misc_util.c Thu Jan 10 14:49:15 2008 -0800 > @@ -71,7 +71,9 @@ virConnectPtr connect_by_classname(const > > conn = virConnectOpen(uri); > if (!conn) { > - CU_DEBUG("Unable to connect to `%s'", uri); > + cu_statusf(broker, s, > + CMPI_RC_ERR_FAILED, > + "Unable to connect to `%s'", uri); > return NULL; > } > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > As already described in the comment for the other patch, this would break the CIM model and operations. Please do not apply. -1 -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Fri Jan 11 10:50:48 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:50:48 +0200 Subject: [Libvirt-cim] [PATCH 0 of 3] #2 - Check client given object pathes in ElementCapabilities provider Message-ID: To enable the check for the client's given object path in ElementCapabilities, changes to the ComputerSystem and AllocationCapabilities provider have been necessary. Diff to patch #1: - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - that does the check between the system instance and the client given instance - get_domain() is now using the new libcmpiutil function - the parameter CMPIInstance **inst is now used to "configure" get_domain(); for internal usage the inst is returned and for external usage this can be ignored by setting it to NULL - validate_domain_ref() is now only an interface name for the client - removed patch unrelated changes in patch 2 - reworked logic to return instance(s) From heidieck at linux.vnet.ibm.com Fri Jan 11 10:50:51 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:50:51 +0200 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: Message-ID: <90746174d66eb4d4ceb2.1200052251@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1200052160 -3600 # Node ID 90746174d66eb4d4ceb2b15633ff348a553ab908 # Parent 224b84cf00ac2e120d86e15d92ce50fddf6a0105 EC: Validation of client given object path missing The validation of the client's given ResourcePool object path is missing. Instead the submitted InstanceID is taken as value for the AllocationCapabilities InstanceID. wbemain -ac CIM_ElementCapabilities 'http://localhost/root/virt:KVM_DiskPool.InstanceID="notthere"' returns localhost:5988/root/virt:KVM_AllocationCapabilities.InstanceID="notthere" Signed-off-by: Heidi Eckhart diff -r 224b84cf00ac -r 90746174d66e src/Makefile.am --- a/src/Makefile.am Fri Jan 11 12:49:19 2008 +0100 +++ b/src/Makefile.am Fri Jan 11 12:49:20 2008 +0100 @@ -89,17 +89,18 @@ libVirt_ElementConformsToProfile_la_LIBA libVirt_EnabledLogicalElementCapabilities_la_SOURCES = Virt_EnabledLogicalElementCapabilities.c +libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la +libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c +libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + libVirt_ElementCapabilities_la_DEPENDENCIES = libVirt_VirtualSystemManagementCapabilities.la libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la libVirt_HostSystem.la libVirt_VSMigrationCapabilities.la libVirt_ElementCapabilities_la_SOURCES = Virt_ElementCapabilities.c libVirt_ElementCapabilities_la_LIBADD = -lVirt_VirtualSystemManagementCapabilities \ -lVirt_EnabledLogicalElementCapabilities \ -lVirt_ComputerSystem \ -lVirt_HostSystem \ - -lVirt_VSMigrationCapabilities - -libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la -libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c -libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + -lVirt_VSMigrationCapabilities \ + -lVirt_AllocationCapabilities libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c diff -r 224b84cf00ac -r 90746174d66e src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Fri Jan 11 12:49:19 2008 +0100 +++ b/src/Virt_ElementCapabilities.c Fri Jan 11 12:49:20 2008 +0100 @@ -37,6 +37,7 @@ #include "Virt_ComputerSystem.h" #include "Virt_HostSystem.h" #include "Virt_VSMigrationCapabilities.h" +#include "Virt_AllocationCapabilities.h" /* Associate an XXX_Capabilities to the proper XXX_ManagedElement. * @@ -46,6 +47,37 @@ */ const static CMPIBroker *_BROKER; + +static CMPIStatus validate_host_caps_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + char* classname; + + classname = class_base_name(CLASSNAME(ref)); + + if (STREQC(classname, "VirtualSystemManagementCapabilities")) { + s = get_vsm_cap(_BROKER, ref, &inst); + } else if (STREQC(classname, "VirtualSystemMigrationCapabilities")) { + s = get_migration_caps(ref, &inst, _BROKER); + } + + if (s.rc != CMPI_RC_OK) + goto out; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + out: + free(classname); + + return s; +} static CMPIStatus sys_to_cap(const CMPIObjectPath *ref, struct std_assoc_info *info, @@ -53,22 +85,13 @@ static CMPIStatus sys_to_cap(const CMPIO { CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; - const char *prop; - - if (!match_hypervisor_prefix(ref, info)) - return s; - - s = get_host_cs(_BROKER, ref, &inst); - if (s.rc != CMPI_RC_OK) - goto out; - - prop = cu_compare_ref(ref, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such HostSystem (%s)", prop); - goto out; - } + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = validate_host_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_vsm_cap(_BROKER, ref, &inst); if (s.rc == CMPI_RC_OK) @@ -90,7 +113,11 @@ static CMPIStatus cap_to_sys(const CMPIO CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = validate_host_caps_ref(ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_host_cs(_BROKER, ref, &inst); if (s.rc != CMPI_RC_OK) @@ -111,7 +138,11 @@ static CMPIStatus cs_to_cap(const CMPIOb const char *sys_name = NULL; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = validate_domain_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &sys_name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -138,26 +169,30 @@ static CMPIStatus cap_to_cs(const CMPIOb CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Could not get InstanceID"); - goto error1; + goto out; } conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); if (s.rc != CMPI_RC_OK) - goto error1; + goto out; inst = instance_from_name(_BROKER, conn, inst_id, ref); if (inst) inst_list_add(list, inst); - + else + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", inst_id); + virConnectClose(conn); - error1: - + + out: return s; } @@ -173,14 +208,11 @@ static CMPIStatus pool_to_alloc(const CM struct std_assoc_info *info, struct inst_list *list) { - int ret; + CMPIStatus s = {CMPI_RC_OK, NULL}; const char *inst_id; - uint16_t type; - CMPIInstance *inst = NULL; - CMPIStatus s = {CMPI_RC_OK}; - - if (!match_hypervisor_prefix(ref, info)) - return s; + + if (!match_hypervisor_prefix(ref, info)) + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -189,22 +221,11 @@ static CMPIStatus pool_to_alloc(const CM goto out; } - inst = get_typed_instance(_BROKER, - CLASSNAME(ref), - "AllocationCapabilities", - NAMESPACE(ref)); - CMSetProperty(inst, "InstanceID", inst_id, CMPI_chars); - - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (ret != 1) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Could not get ResourceType"); - goto out; - } - CMSetProperty(inst, "ResourceType", &type, CMPI_uint16); - - inst_list_add(list, inst); + s = enum_alloc_cap_instances(_BROKER, + ref, + NULL, + inst_id, + list); out: return s; From heidieck at linux.vnet.ibm.com Fri Jan 11 10:50:50 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:50:50 +0200 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: Message-ID: <224b84cf00ac2e120d86.1200052250@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1200052159 -3600 # Node ID 224b84cf00ac2e120d86e15d92ce50fddf6a0105 # Parent ec66d30629f4584ca30751ce3e079f5561f2985a Make alloc_cap_instances() available for external use by EC The association provider ElementCapabilities needs the enum_alloc_cap_instances() function to access to the list of available AllocationCapabilities. These are returned by the additional inst_list parameter. Signed-off-by: Heidi Eckhart diff -r ec66d30629f4 -r 224b84cf00ac src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c Fri Jan 11 12:49:18 2008 +0100 +++ b/src/Virt_AllocationCapabilities.c Fri Jan 11 12:49:19 2008 +0100 @@ -31,6 +31,7 @@ #include "misc_util.h" +#include "Virt_AllocationCapabilities.h" #include "Virt_DevicePool.h" const static CMPIBroker *_BROKER; @@ -71,30 +72,26 @@ static CMPIStatus ac_from_pool(const CMP return s; } -static CMPIStatus alloc_cap_instances(const CMPIBroker *broker, - const CMPIObjectPath *ref, - const CMPIResult *results, - bool names_only, - const char **properties, - const char *id) -{ +CMPIStatus enum_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char **properties, + const char *id, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *alloc_cap_inst; + virConnectPtr conn = NULL; + struct inst_list device_pool_list; + const char *inst_id; int i; - virConnectPtr conn = NULL; - CMPIInstance *alloc_cap_inst; - struct inst_list alloc_cap_list; - struct inst_list device_pool_list; - CMPIStatus s = {CMPI_RC_OK, NULL}; - const char *inst_id; - - CU_DEBUG("In alloc_cap_instances()"); - + + inst_list_init(list); inst_list_init(&device_pool_list); - inst_list_init(&alloc_cap_list); if (!provider_is_responsible(broker, ref, &s)) goto out; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + conn = connect_by_classname(broker, CLASSNAME(ref), &s); if (conn == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -129,7 +126,7 @@ static CMPIStatus alloc_cap_instances(co if (s.rc != CMPI_RC_OK) goto out; - inst_list_add(&alloc_cap_list, alloc_cap_inst); + inst_list_add(list, alloc_cap_inst); if (id && (STREQ(inst_id, id))) break; @@ -141,16 +138,40 @@ static CMPIStatus alloc_cap_instances(co "Requested Object could not be found."); goto out; } - - if (names_only) - cu_return_instance_names(results, &alloc_cap_list); - else - cu_return_instances(results, &alloc_cap_list); - + out: virConnectClose(conn); - inst_list_free(&alloc_cap_list); inst_list_free(&device_pool_list); + + return s; +} + +static CMPIStatus return_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only, + const char **properties, + const char *id) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct inst_list *list = NULL; + + s = enum_alloc_cap_instances(broker, + ref, + properties, + id, + list); + if (s.rc != CMPI_RC_OK) + goto out; + + if (names_only) + cu_return_instance_names(results, list); + else + cu_return_instances(results, list); + + out: + inst_list_free(list); + return s; } @@ -170,12 +191,12 @@ static CMPIStatus GetInstance(CMPIInstan return s; } - return alloc_cap_instances(_BROKER, - reference, - results, - false, - properties, - id); + return return_alloc_cap_instances(_BROKER, + reference, + results, + false, + properties, + id); } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -183,12 +204,12 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return alloc_cap_instances(_BROKER, - reference, - results, - true, - NULL, - NULL); + return return_alloc_cap_instances(_BROKER, + reference, + results, + true, + NULL, + NULL); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -197,12 +218,12 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - return alloc_cap_instances(_BROKER, - reference, - results, - false, - properties, - NULL); + return return_alloc_cap_instances(_BROKER, + reference, + results, + false, + properties, + NULL); } DEFAULT_CI(); diff -r ec66d30629f4 -r 224b84cf00ac src/Virt_AllocationCapabilities.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_AllocationCapabilities.h Fri Jan 11 12:49:19 2008 +0100 @@ -0,0 +1,53 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Heidi Eckhart + * + * 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 __VIRT_ALLOCATIONCAPABILITIES_H +#define __VIRT_ALLOCATIONCAPABILITIES_H + +#include "misc_util.h" + +/** + * Return the instance of the AllocationCapabilities instance, + * defined by the id + * + * @param broker A pointer to the current broker + * @param ref The reference + * @param properties list of properties to set + * @param id The InstanceID of the AllocationCapabilities + * @param inst The list of instance(s) in case of success + * @returns The status of this operation + */ +CMPIStatus enum_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char **properties, + const char *id, + struct inst_list *list); + +#endif + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From heidieck at linux.vnet.ibm.com Fri Jan 11 10:50:49 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:50:49 +0200 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path of a ComputerSystem In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1200052158 -3600 # Node ID ec66d30629f4584ca30751ce3e079f5561f2985a # Parent b69727ddc9a45a32c75547a90364759500280398 Add function to validate the client given object path of a ComputerSystem Signed-off-by: Heidi Eckhart diff -r b69727ddc9a4 -r ec66d30629f4 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Thu Jan 10 11:04:39 2008 +0100 +++ b/src/Virt_ComputerSystem.c Fri Jan 11 12:49:18 2008 +0100 @@ -285,7 +285,7 @@ CMPIInstance *instance_from_name(const C dom = virDomainLookupByName(conn, name); if (dom == NULL) - return 0; + return NULL; instance = get_typed_instance(broker, pfx_from_conn(conn), @@ -374,46 +374,66 @@ static CMPIStatus return_enum_domains(co return s; } -static CMPIStatus get_domain(const CMPIObjectPath *reference, - const CMPIResult *results, - const char *name) -{ - CMPIInstance *inst; - CMPIStatus s; +static CMPIStatus get_domain(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **inst) +{ + CMPIInstance *_inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn = NULL; - const char *prop = NULL; - - if (!provider_is_responsible(_BROKER, reference, &s)) { - CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND); + const char *name; + + if (!provider_is_responsible(broker, reference, &s)) return s; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No domain name specified"); + return s; + } + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) return s; - inst = instance_from_name(_BROKER, conn, name, reference); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to find `%s'", name); - goto out; - } - - prop = cu_compare_ref(reference, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, + _inst = instance_from_name(broker, conn, name, reference); + if (_inst == NULL) { + cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", prop); - goto out; - } - - CMReturnInstance(results, inst); - CMSetStatus(&s, CMPI_RC_OK); + "No such instance (%s)", name); + goto out; + } + + s = cu_validate_ref(broker, reference, _inst); + out: virConnectClose(conn); - - return s; + if (inst) + *inst = _inst; + + return s; +} + +static CMPIStatus return_domain(const CMPIObjectPath *reference, + const CMPIResult *results) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + + s = get_domain(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + return s; + + CMReturnInstance(results, inst); + + return s; +} + +CMPIStatus validate_domain_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref) +{ + return get_domain(broker, ref, NULL); } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -440,19 +460,7 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - const char *name; - - if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { - CMPIStatus s; - - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No domain name specified"); - - return s; - } - - return get_domain(reference, results, name); + return return_domain(reference, results); } DEFAULT_CI(); diff -r b69727ddc9a4 -r ec66d30629f4 src/Virt_ComputerSystem.h --- a/src/Virt_ComputerSystem.h Thu Jan 10 11:04:39 2008 +0100 +++ b/src/Virt_ComputerSystem.h Fri Jan 11 12:49:18 2008 +0100 @@ -52,6 +52,16 @@ int enum_domains(const CMPIBroker *broke const char *ns, struct inst_list *instlist); +/** + * Validate the client given domain object path + * + * @param broker A pointer to the current broker + * @param ref The client given object path + * @returns CMPIStatus + */ +CMPIStatus validate_domain_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref); + #endif From heidieck at linux.vnet.ibm.com Fri Jan 11 10:58:07 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:58:07 +0200 Subject: [Libvirt-cim] [PATCH] Make inst_list_free() handle NULL pointers Message-ID: <5278b5fa14a754ea8c6c.1200052687@localhost.localdomain> # HG changeset patch # User Heidi Eckhart # Date 1200052669 -3600 # Node ID 5278b5fa14a754ea8c6cfdd7870cdb7fc6c62fe7 # Parent 393ba1344f5be2ea42b21adea0d377de440516dc Make inst_list_free() handle NULL pointers Signed-off-by: Heidi Eckhart diff -r 393ba1344f5b -r 5278b5fa14a7 inst_list.c --- a/inst_list.c Fri Jan 11 10:33:08 2008 +0100 +++ b/inst_list.c Fri Jan 11 12:57:49 2008 +0100 @@ -50,6 +50,9 @@ void inst_list_init(struct inst_list *li void inst_list_free(struct inst_list *list) { + if (!list) + return; + free(list->list); inst_list_init(list); } From heidieck at linux.vnet.ibm.com Fri Jan 11 10:59:26 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 12:59:26 +0200 Subject: [Libvirt-cim] [PATCH] Add code style phrase to inst_list.c Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1200052746 -3600 # Node ID eec4b4e334563efaf7e3f64e1e4d0770969dc925 # Parent 5278b5fa14a754ea8c6cfdd7870cdb7fc6c62fe7 Add code style phrase to inst_list.c Signed-off-by: Heidi Eckhart diff -r 5278b5fa14a7 -r eec4b4e33456 inst_list.c --- a/inst_list.c Fri Jan 11 12:57:49 2008 +0100 +++ b/inst_list.c Fri Jan 11 12:59:06 2008 +0100 @@ -75,3 +75,12 @@ int inst_list_add(struct inst_list *list return 1; } +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From heidieck at linux.vnet.ibm.com Fri Jan 11 13:08:16 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Fri, 11 Jan 2008 14:08:16 +0100 Subject: [Libvirt-cim] [PATCH 0 of 3] .#2 Memory devices from XML and raw XML In-Reply-To: <47854550.40703@linux.vnet.ibm.com> References: <47854550.40703@linux.vnet.ibm.com> Message-ID: <47876A40.9050804@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Dan Smith wrote: >> Changes to the third patch only. Sorry the first round didn't have >> a commit log :) >> > > The consolidation of get_* functions into the get_devices() is nice. > Makes the patch a bit tough to read, but the resulting > device_parsing.c file is much easier to read. +1 I do not have that many experiences with the device-parsing stuff, but I agree, that the code is good to read. Testing is a bit difficult, as I get the following message when doing an ein on VSSD: misc_util.c(70): Connecting to libvirt with uri `qemu:///system' device_parsing.c(818): Unknown domain type -1 Seems like KVM is not supported at the moment. But the instance for VSSD is returned by ein and gi. So a +1 with the excuse for not testing it correct. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From danms at us.ibm.com Fri Jan 11 15:10:54 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 07:10:54 -0800 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: <47874DB6.4080908@linux.vnet.ibm.com> (Heidi Eckhart's message of "Fri, 11 Jan 2008 12:06:30 +0100") References: <87hchl5wty.fsf@theine.beaverton.ibm.com> <47874DB6.4080908@linux.vnet.ibm.com> Message-ID: <87ve604cu9.fsf@theine.beaverton.ibm.com> HE> Mhh, as we have many free operations now that can handle NULL HE> pointers, I suggest to also make inst_list_free() able to handle HE> NULL pointers. But they're not NULL pointers at that point, the list.list is a garbage pointer. Unless you define them as: struct inst_list list = {NULL, 0, 0}; Otherwise, the pointer will be garbage and a free() will smash the heap. The inst_list_init() call doesn't allocate any memory, it just initializes the contents of the struct, so why not always do that before proceeding? HE> Agreed. I will cook up a patch for inst_list_free(). The intention HE> to move the inst_list_init() functions below HE> connect_by_classname() was to avoid some cycles, because the case HE> where the provider exits right after provider_is_responsible() or HE> connect_by_classname() can happen often. I think this optimization is likely lost in the noise of the roaring CIMOM above us, so I'm not sure it's all that important. However, a macro could help make this cleaner I think. Something like what they do in the kernel might be helpful: #define DECLARE_INST_LIST(x) struct inst_list x = {NULL, 0, 0} so that we can just do this in a function to have pre-initialized lists and avoid the inst_list_init() calls: int function_foo(...) { int a; char b; DECLARE_INST_LIST(list_one); DECLARE_INST_LIST(list_two); ... } I still question the value of this optimization, as I think the compiler will inline the inst_list_init() function. At that point, this: struct inst_list foo = {NULL, 0, 0}; surely becomes the same code as this: struct inst_list foo; foo.list = NULL; foo.max = foo.cur = 0; Anyone else have thoughts on this? HE> Agreed. I saw that we already have a task for "Fix up all the HE> error codes in returned status values (everything is currently HE> CMPI_RC_ERR_FAILED)". So we should leave this discussion for HE> there. I will remove this change. Yes, we definitely have work to do on our return codes and error messages, but I'd rather address them as a group than sprinkle them in with other changes :) Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 11 15:21:24 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 07:21:24 -0800 Subject: [Libvirt-cim] [PATCH] Fix connect_by_classname() to set error status when connect fails In-Reply-To: <4787508F.6040409@linux.vnet.ibm.com> (Heidi Eckhart's message of "Fri, 11 Jan 2008 12:18:39 +0100") References: <4787508F.6040409@linux.vnet.ibm.com> Message-ID: <87r6go4ccr.fsf@theine.beaverton.ibm.com> HE> As already described in the comment for the other patch, this HE> would break the CIM model and operations. Please do not apply. -1 Thanks for catching this Heidi! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Fri Jan 11 15:23:59 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 11 Jan 2008 07:23:59 -0800 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: <47875033.1020704@linux.vnet.ibm.com> References: <47866584.9050208@linux.vnet.ibm.com> <87sl155xkj.fsf@theine.beaverton.ibm.com> <47875033.1020704@linux.vnet.ibm.com> Message-ID: <47878A0F.5040604@linux.vnet.ibm.com> Heidi Eckhart wrote: > Dan Smith wrote: >> KR> Or possibly a better approach would be to modify >> KR> connect_by_classname() so that it sets an error. >> >> I'm pretty sure that connect_by_classname() used to set an error in >> the CMPIStatus if it was going to return NULL. > Yes, it did. But for consistency with CIM this was removed. The reason > is that a request against KVM on a Xen system can not return with an > error, as this breaks the CIM model and operations. This happens if the > client does e.g. an ein on CIM_ComputerSystem. We know that this one > request gets split up into requests against Xen_ComputerSystem and > KVM_ComputerSystem by the CIMOM. The CIMOM would then only return the > error code of the KVM request and revoke the instances returned by the > Xen request. This behavior would be wrong. Excellent point. Thanks for catching this. =) -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Fri Jan 11 15:28:31 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 07:28:31 -0800 Subject: [Libvirt-cim] [PATCH] Make inst_list_free() handle NULL pointers In-Reply-To: <5278b5fa14a754ea8c6c.1200052687@localhost.localdomain> (Heidi Eckhart's message of "Fri, 11 Jan 2008 12:58:07 +0200") References: <5278b5fa14a754ea8c6c.1200052687@localhost.localdomain> Message-ID: <87myrc4c0w.fsf@theine.beaverton.ibm.com> HE> void inst_list_free(struct inst_list *list) HE> { HE> + if (!list) HE> + return; HE> + HE> free(list->list); HE> inst_list_init(list); HE> } I have no problem with this patch, although I'd like to reiterate that it won't solve the initialization problem. If you have this: struct inst_list foo; inst_list_free(&foo); You're passing in the address of a stack variable, which will never be NULL, so the additional check will fall through. The free() will then attempt to free a garbage pointer (list is valid, but list->list is not) and the heap is blown. I'd also point out that we overwhelmingly use inst_list variables on the stack, which means 99% of the time, this check won't help us, and will just consume "extra cycles". I'm sure that this would eclipse the overhead of a few unnecessary inst_list_init() calls :) I'm fine applying this to handle the case where we might have a dynamically-allocated list pointer. Any objections? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 11 15:44:23 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 07:44:23 -0800 Subject: [Libvirt-cim] [PATCH 0 of 3] .#2 Memory devices from XML and raw XML In-Reply-To: <47876A40.9050804@linux.vnet.ibm.com> (Heidi Eckhart's message of "Fri, 11 Jan 2008 14:08:16 +0100") References: <47854550.40703@linux.vnet.ibm.com> <47876A40.9050804@linux.vnet.ibm.com> Message-ID: <87fxx44bag.fsf@theine.beaverton.ibm.com> HE> Seems like KVM is not supported at the moment. But the instance for HE> VSSD is returned by ein and gi. So a +1 with the excuse for not HE> testing it correct. Hmm, it seems to work okay for me: % wbemcli ein http://root:password at localhost/root/virt:CIM_VirtualSystemSettingData localhost:5988/root/virt:KVM_VirtualSystemSettingData.InstanceID="KVM:kvm" -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 11 16:01:05 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 08:01:05 -0800 Subject: [Libvirt-cim] [PATCH 0 of 3] .#2 Memory devices from XML and raw XML References: <47854550.40703@linux.vnet.ibm.com> <47876A40.9050804@linux.vnet.ibm.com> Message-ID: <874pdk4aim.fsf@theine.beaverton.ibm.com> HE> misc_util.c(70): Connecting to libvirt with uri `qemu:///system' HE> device_parsing.c(818): Unknown domain type -1 Okay, I should start looking at the code before I speak :) It looks to me like you have a KVM domain with XML that doesn't fit with my type detection logic, hence the -1 domain type. Right now, if the block has a type of 'hvm', and the tag has a type of 'kvm', then we consider it to be a KVM domain. However, I'm assuming you're missing the type in your block, which really shouldn't be necessary (it's needed to determine between Xen PV and FV), so maybe removing that check would fix this problem. I'll submit a patch to do that; please report if it fixes your problem. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 11 15:01:39 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 08:01:39 -0700 Subject: [Libvirt-cim] [PATCH] Make cleanup_dominfo() handle KVM domains Message-ID: <4ae48640b6dfaf77c603.1200067299@theine> # HG changeset patch # User Dan Smith # Date 1200067187 28800 # Node ID 4ae48640b6dfaf77c60300aa2f41a3be9395bf83 # Parent e834b93342a431c9414fbb07c2aa34e28002744d Make cleanup_dominfo() handle KVM domains This avoids the following message in the CIMOM logs: device_parsing.c(818): Unknown domain type 2 Signed-off-by: Dan Smith diff -r e834b93342a4 -r 4ae48640b6df libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 11 07:40:28 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 11 07:59:47 2008 -0800 @@ -810,7 +810,8 @@ void cleanup_dominfo(struct domain **dom free(dom->os_info.pv.kernel); free(dom->os_info.pv.initrd); free(dom->os_info.pv.cmdline); - } else if (dom->type == DOMAIN_XENFV) { + } else if ((dom->type == DOMAIN_XENFV) || + (dom->type == DOMAIN_KVM)) { free(dom->os_info.fv.type); free(dom->os_info.fv.loader); free(dom->os_info.fv.boot); From danms at us.ibm.com Fri Jan 11 15:01:44 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 08:01:44 -0700 Subject: [Libvirt-cim] [PATCH] Relax the KVM type detection logic Message-ID: # HG changeset patch # User Dan Smith # Date 1200067225 28800 # Node ID a353b12b24858b16b3b6d77940178f5cd672bdce # Parent 4ae48640b6dfaf77c60300aa2f41a3be9395bf83 Relax the KVM type detection logic since it was too strict for no reason. Signed-off-by: Dan Smith diff -r 4ae48640b6df -r a353b12b2485 libxkutil/device_parsing.c --- a/libxkutil/device_parsing.c Fri Jan 11 07:59:47 2008 -0800 +++ b/libxkutil/device_parsing.c Fri Jan 11 08:00:25 2008 -0800 @@ -652,8 +652,7 @@ static int parse_os(struct domain *domin if ((STREQC(dominfo->os_info.fv.type, "hvm")) && (STREQC(dominfo->typestr, "xen"))) dominfo->type = DOMAIN_XENFV; - else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && - (STREQC(dominfo->typestr, "kvm"))) + else if (STREQC(dominfo->typestr, "kvm")) dominfo->type = DOMAIN_KVM; else if (STREQC(dominfo->os_info.pv.type, "linux")) dominfo->type = DOMAIN_XENPV; From danms at us.ibm.com Fri Jan 11 16:12:47 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 08:12:47 -0800 Subject: [Libvirt-cim] [PATCH] [CU] Add function to validate a client given object path In-Reply-To: <393ba1344f5be2ea42b2.1200046334@localhost.localdomain> (Heidi Eckhart's message of "Fri, 11 Jan 2008 11:12:14 +0200") References: <393ba1344f5be2ea42b2.1200046334@localhost.localdomain> Message-ID: <87zlvc2veo.fsf@theine.beaverton.ibm.com> HE> diff -r 2a52fc3c4bbc -r 393ba1344f5b libcmpiutil.h HE> --- a/libcmpiutil.h Thu Dec 13 11:10:59 2007 +0100 HE> +++ b/libcmpiutil.h Fri Jan 11 10:33:08 2008 +0100 HE> @@ -377,6 +377,10 @@ int inst_list_add(struct inst_list *list HE> * or NULL if all match HE> */ HE> const char *cu_compare_ref(const CMPIObjectPath *ref, HE> + const CMPIInstance *inst); HE> + HE> +CMPIStatus cu_validate_ref(const CMPIBroker *broker, HE> + const CMPIObjectPath *ref, HE> const CMPIInstance *inst); How about a comment before the function prototype explaining that it's just like cu_compare_ref() but returns a CMPIStatus? I was confused about how it's different when I first looked at it :) In general, I've tried to keep libcmpiutil.h pretty well documented, so I'd like to not depart from doing so. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From kaitlin at linux.vnet.ibm.com Fri Jan 11 16:30:06 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 11 Jan 2008 08:30:06 -0800 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: <90746174d66eb4d4ceb2.1200052251@localhost.localdomain> References: <90746174d66eb4d4ceb2.1200052251@localhost.localdomain> Message-ID: <4787998E.2070509@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1200052160 -3600 > # Node ID 90746174d66eb4d4ceb2b15633ff348a553ab908 > # Parent 224b84cf00ac2e120d86e15d92ce50fddf6a0105 > EC: Validation of client given object path missing > > > conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); > if (s.rc != CMPI_RC_OK) > - goto error1; > + goto out; Should this also check for to see if conn == NULL? -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Fri Jan 11 16:38:19 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 08:38:19 -0800 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC References: <224b84cf00ac2e120d86.1200052250@localhost.localdomain> Message-ID: <87hchk2u84.fsf@theine.beaverton.ibm.com> HE> + CMPIStatus s = {CMPI_RC_OK, NULL}; HE> + CMPIInstance *alloc_cap_inst; HE> + virConnectPtr conn = NULL; HE> + struct inst_list device_pool_list; HE> + const char *inst_id; HE> int i; HE> - virConnectPtr conn = NULL; HE> - CMPIInstance *alloc_cap_inst; HE> - struct inst_list alloc_cap_list; HE> - struct inst_list device_pool_list; HE> - CMPIStatus s = {CMPI_RC_OK, NULL}; HE> - const char *inst_id; Reordering this block for no reason makes it really difficult to tell what is changed. Can we please keep this kind of thing separate from the functional change to the code? HE> + inst_list_init(list); In other places, we initialize the list before we pass it into a function. I think it makes more sense that way, as the caller may want the results of this function appended to the list it passes in. HE> +static CMPIStatus return_alloc_cap_instances(const CMPIBroker *broker, HE> + const CMPIObjectPath *ref, HE> + const CMPIResult *results, HE> + bool names_only, HE> + const char **properties, HE> + const char *id) HE> +{ HE> + CMPIStatus s = {CMPI_RC_OK, NULL}; HE> + struct inst_list *list = NULL; HE> + HE> + s = enum_alloc_cap_instances(broker, HE> + ref, HE> + properties, HE> + id, HE> + list); HE> + if (s.rc != CMPI_RC_OK) HE> + goto out; HE> + HE> + if (names_only) HE> + cu_return_instance_names(results, list); HE> + else HE> + cu_return_instances(results, list); This doesn't work, does it? You pass a NULL list pointer in to the function, it allocates a list, but has no way to return it back. You're passing just a single pointer by value here. If you were modifying what the pointer pointed to, then you could get the result, but otherwise the list that the enum_alloc_cap_instances() function generates isn't visible to this caller. You should do the following: struct inst_list list; inst_list_init(&list); s = enum_alloc_cap_instances(broker, ref, properties, id, &list); Which addresses this issue as well as the previous one. Thanks! -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From grendel at linux.vnet.ibm.com Fri Jan 11 16:39:32 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Fri, 11 Jan 2008 11:39:32 -0500 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: <224b84cf00ac2e120d86.1200052250@localhost.localdomain> References: <224b84cf00ac2e120d86.1200052250@localhost.localdomain> Message-ID: <47879BC4.6060103@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1200052159 -3600 > # Node ID 224b84cf00ac2e120d86e15d92ce50fddf6a0105 > # Parent ec66d30629f4584ca30751ce3e079f5561f2985a > Make alloc_cap_instances() available for external use by EC > > The association provider ElementCapabilities needs the > enum_alloc_cap_instances() function to access to the list > of available AllocationCapabilities. These are returned > by the additional inst_list parameter. > > Signed-off-by: Heidi Eckhart > > diff -r ec66d30629f4 -r 224b84cf00ac src/Virt_AllocationCapabilities.c > --- a/src/Virt_AllocationCapabilities.c Fri Jan 11 12:49:18 2008 +0100 > +++ b/src/Virt_AllocationCapabilities.c Fri Jan 11 12:49:19 2008 +0100 > @@ -31,6 +31,7 @@ > > #include "misc_util.h" > > +#include "Virt_AllocationCapabilities.h" > #include "Virt_DevicePool.h" > > const static CMPIBroker *_BROKER; > @@ -71,30 +72,26 @@ static CMPIStatus ac_from_pool(const CMP > return s; > } > > -static CMPIStatus alloc_cap_instances(const CMPIBroker *broker, > - const CMPIObjectPath *ref, > - const CMPIResult *results, > - bool names_only, > - const char **properties, > - const char *id) > -{ > +CMPIStatus enum_alloc_cap_instances(const CMPIBroker *broker, > + const CMPIObjectPath *ref, > + const char **properties, > + const char *id, > + struct inst_list *list) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + CMPIInstance *alloc_cap_inst; > + virConnectPtr conn = NULL; > + struct inst_list device_pool_list; > + const char *inst_id; > int i; > - virConnectPtr conn = NULL; > - CMPIInstance *alloc_cap_inst; > - struct inst_list alloc_cap_list; > - struct inst_list device_pool_list; > - CMPIStatus s = {CMPI_RC_OK, NULL}; > - const char *inst_id; > - > - CU_DEBUG("In alloc_cap_instances()"); > - > + > + inst_list_init(list); > inst_list_init(&device_pool_list); > - inst_list_init(&alloc_cap_list); > Time for me to put on the PCO hat here. You've got some serious declaration reordering here, and it's really muddying up the change. I think you've got about three lines changed, but it's producing over 20 lines of diff. That can definitely be cleaned up. -- -Jay From kaitlin at linux.vnet.ibm.com Fri Jan 11 16:41:25 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 11 Jan 2008 08:41:25 -0800 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem In-Reply-To: <478740C0.2000401@linux.vnet.ibm.com> References: <47866072.6030405@linux.vnet.ibm.com> <478740C0.2000401@linux.vnet.ibm.com> Message-ID: <47879C35.4050300@linux.vnet.ibm.com> Heidi Eckhart wrote:. > > But your comments made me rethink about the patch. So I've consolidated > and reordered a bit. > - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - > that does the check between the system instance and the client given > instance I think this is a good idea. It seems like it'll be useful in other places as well. > - get_domain() is now using the new libcmpiutil function > - the parameter CMPIInstance **inst is now used to "configure" > get_domain(); for internal usage the inst is returned and for external > usage this can be ignored by setting it to NULL > - validate_domain_ref() is now only an interface name for the client; > this could also be removed and the provider has then to call > get_domain(broker, ref, NULL) or simply ignores the returned instance; > but what I do not really like is, that this can confuse the reader of > the code; but I'm open for discussion and opinions As far as readability, I'm fine with this method. As an alternative, you could have get_domain() return an instance and take a CMPIStatus variable as a parameter. The provider can then choose to ignore the returned instance. But that doesn't really fit with our existing code style. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Fri Jan 11 18:54:09 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Fri, 11 Jan 2008 10:54:09 -0800 Subject: [Libvirt-cim] [PATCH] Add code style phrase to inst_list.c In-Reply-To: References: Message-ID: <4787BB51.2060500@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1200052746 -3600 > # Node ID eec4b4e334563efaf7e3f64e1e4d0770969dc925 > # Parent 5278b5fa14a754ea8c6cfdd7870cdb7fc6c62fe7 > Add code style phrase to inst_list.c > Signed-off-by: Heidi Eckhart > > diff -r 5278b5fa14a7 -r eec4b4e33456 inst_list.c > --- a/inst_list.c Fri Jan 11 12:57:49 2008 +0100 > +++ b/inst_list.c Fri Jan 11 12:59:06 2008 +0100 > @@ -75,3 +75,12 @@ int inst_list_add(struct inst_list *list > return 1; > } > > +/* > + * Local Variables: > + * mode: C > + * c-set-style: "K&R" > + * tab-width: 8 > + * c-basic-offset: 8 > + * indent-tabs-mode: nil > + * End: > + */ This looks fine to me. I didn't see a requirement for this listed in doc/CodingStyle or doc/SubmittingPatches. Is this something that should be added? -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Fri Jan 11 19:00:29 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 11:00:29 -0800 Subject: [Libvirt-cim] [PATCH] Add code style phrase to inst_list.c In-Reply-To: <4787BB51.2060500@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Fri, 11 Jan 2008 10:54:09 -0800") References: <4787BB51.2060500@linux.vnet.ibm.com> Message-ID: <87odbs192q.fsf@theine.beaverton.ibm.com> KR> Is this something that should be added? I think it's in the SubmittingPatches thing, isn't it? But yes, it should be in CodingStyle as well. I think I have a couple other items for that file, so I'll try to slap them into a patch. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Fri Jan 11 20:06:41 2008 From: danms at us.ibm.com (Dan Smith) Date: Fri, 11 Jan 2008 13:06:41 -0700 Subject: [Libvirt-cim] [PATCH] CodingStyle updates based on experience gained in the past few months Message-ID: # HG changeset patch # User Dan Smith # Date 1200085592 28800 # Node ID a541f98f909ab469ebd1631899045cf81faf4657 # Parent a42d6f035ed6d5d519e2efd5aa2fd45d5a7a95be CodingStyle updates based on experience gained in the past few months. Comments and adjustments welcomed. Signed-off-by: Dan Smith diff -r a42d6f035ed6 -r a541f98f909a doc/CodingStyle --- a/doc/CodingStyle Fri Jan 11 17:15:53 2008 +0800 +++ b/doc/CodingStyle Fri Jan 11 13:06:32 2008 -0800 @@ -1,6 +1,64 @@ + +The CodingStyle for libvirt-cim (and libcmpiutil) is mostly kernel +style, but with the following "clarifications": + - Eight-space indents -- No single-line if statements + +- No single-line if statements. This means none of this: + + if (foo) bar; + - Keywords and parens separated by one space (i.e. "if (" not "if(") -- 80-char width limit -- Identifier style: use_underbars_and_lowercase -- Macro style: ALL_UPPERCASE + +- 80-char width limit. Break long function calls by putting *every* + parameter of the call on its own line. There are a few exceptions + to the "every parameter" rule, such as for cu_statusf() calls. + Unless you've seen another example in the code, put each parameter + on a line. + +- Identifiers should be named with underbars_and_lowercase. The + libvirt style is to use CamelCase, but try to limit that to + operations directly related to libvirt and don't spread it to the + rest of the code. + +- Macros should be ALL_UPPERCASE + +- Braces around blocks should look like this: + + if (foo) { + . . . + } else if (bar) { + . . . + } else { + . . . + } + +- Absolutely all files should contain the following block at the end: + + /* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ + + This ensures that emacs folks will have the style correct (they're + already halfway there by their choice in editor anyway). + +- Pointer and integer comparisons should be against something + concrete. The only time the following style should be used is if + foo is a bool: + + if (!foo) /* ONLY if foo is a bool */ + bar; + + For pointers and integers, do this: + + if (foo == NULL) /* if foo is a pointer */ + bar; + + if (foo == -1) /* if foo is an integer */ + bar; From yunguol at cn.ibm.com Mon Jan 14 03:05:18 2008 From: yunguol at cn.ibm.com (Guo Lian Yun) Date: Mon, 14 Jan 2008 11:05:18 +0800 Subject: [Libvirt-cim] Xen_HostedService return expected queried result with non existing instance by two sides In-Reply-To: <4783759D.200@linux.vnet.ibm.com> Message-ID: libvirt-cim-bounces at redhat.com wrote on 2008-01-08 21:07:41: > Guo Lian Yun wrote: > > > > Hi, > > > > With a non existing instance, e.g. a wrong key name or value, > > Xen_HostedService still return expected results below: > > > > wbemcli ain -ac Xen_HostedService > > http://root:password at localhost/root/virt: > Xen_ResourcePoolConfigurationService.wrong="wrong" > > localhost:5988/root/virt:Xen_HostSystem. > CreationClassName="Xen_HostSystem",Name="zeit" > > > > wbemcli ain -ac Xen_HostedService > > http://root:password at localhost/root/virt:Xen_HostSystem.CreationClassName= > "wrong",Wrong="zeit" > > localhost:5988/root/virt:Xen_ResourcePoolConfigurationService. > CreationClassName="Xen_ResourcePoolConfigurationService", > Name="RPCS",SystemCreationClassName="Xen_HostSystem",SystemName="zei" > > localhost:5988/root/virt:Xen_VirtualSystemManagementService. > CreationClassName="Xen_VirtualSystemManagementService",Name="Management > > Service",SystemCreationClassName="Xen_HostSystem",SystemName="zeit" > > localhost:5988/root/virt:Xen_VirtualSystemMigrationService. > CreationClassName="Xen_VirtualSystemMigrationService", > Name="MigrationService",SystemCreationClassName="",SystemName="" > > > Daisy, thank you for reporting this bug. Very good finding :) ! The > patch "HS: returns results for wrong object path" should fix this issue. > Please can you verify it ? Thanks a lot. > Sorry for delayed response. I've test again, the issue has been fixed with your good patch. Thanks! > -- > Regards > > Heidi Eckhart > Software Engineer > IBM Linux Technology Center - Open Hypervisor > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From yunguol at cn.ibm.com Mon Jan 14 06:54:53 2008 From: yunguol at cn.ibm.com (Guo Lian Yun) Date: Mon, 14 Jan 2008 14:54:53 +0800 Subject: [Libvirt-cim] Xen_ElementCapabilities return expected result from one side querying by non existing instance In-Reply-To: <4784A958.4010309@linux.vnet.ibm.com> Message-ID: libvirt-cim-bounces at redhat.com wrote on 2008-01-09 19:00:40: > Guo Lian Yun wrote: > > > > > > Please who can have a look into them? Thanks a lot! > > > I will have a look into these issues. Thanks for reporting them :). > These are all very good findings. I've test the other association providers again in FC8, which including Xen_HostedResourcePool, Xen_ResourceAllocationFromPool, Xen_HostedService and Xen_ElementCapabilities. Their issues have already been fixed except the last one, right? That is to say, Xen_ElementCapabilities still return expected results by wrong instance. Below is the test result. Could you please tell me once the bug has been fixed? Thanks! wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_VirtualSystemManagementCapabilities.InstanceID=" wrong" localhost:5988/root/virt:Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="wks230838wss.cn.ibm.com" > > -- > Regards > > Heidi Eckhart > Software Engineer > IBM Linux Technology Center - Open Hypervisor > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim -------------- next part -------------- An HTML attachment was scrubbed... URL: From kaitlin at linux.vnet.ibm.com Mon Jan 14 14:47:15 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 06:47:15 -0800 Subject: [Libvirt-cim] [PATCH] CodingStyle updates based on experience gained in the past few months In-Reply-To: References: Message-ID: <478B75F3.2050303@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200085592 28800 > # Node ID a541f98f909ab469ebd1631899045cf81faf4657 > # Parent a42d6f035ed6d5d519e2efd5aa2fd45d5a7a95be > CodingStyle updates based on experience gained in the past few months. > > Comments and adjustments welcomed. > No complaints from me - looks like a good update. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Mon Jan 14 14:20:16 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 07:20:16 -0700 Subject: [Libvirt-cim] [PATCH] Bump version to 0.2 Message-ID: <29c9bb8cb88428491764.1200324016@theine> # HG changeset patch # User Dan Smith # Date 1200323991 28800 # Node ID 29c9bb8cb88428491764aa58f9bb214c3d7f5f03 # Parent db25d5f62c9d662cd262ea82efb6d3fde2806b62 Bump version to 0.2 Signed-off-by: Dan Smith diff -r db25d5f62c9d -r 29c9bb8cb884 configure.ac --- a/configure.ac Mon Jan 14 07:19:12 2008 -0800 +++ b/configure.ac Mon Jan 14 07:19:51 2008 -0800 @@ -1,6 +1,6 @@ # (C) Copyright IBM Corp. 2005 -AC_INIT(libvirt CMPI provider, 0.1, danms at us.ibm.com, libvirt-cim) +AC_INIT(libvirt CMPI provider, 0.2, danms at us.ibm.com, libvirt-cim) AC_CONFIG_SRCDIR([src/Virt_ComputerSystem.c]) From danms at us.ibm.com Mon Jan 14 15:25:08 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 07:25:08 -0800 Subject: [Libvirt-cim] [PATCH] Bump version to 0.2 In-Reply-To: <29c9bb8cb88428491764.1200324016@theine> (Dan Smith's message of "Mon, 14 Jan 2008 07:20:16 -0700") References: <29c9bb8cb88428491764.1200324016@theine> Message-ID: <87ir1wzay3.fsf@theine.beaverton.ibm.com> DS> # HG changeset patch DS> # User Dan Smith DS> # Date 1200323991 28800 DS> # Node ID 29c9bb8cb88428491764aa58f9bb214c3d7f5f03 DS> # Parent db25d5f62c9d662cd262ea82efb6d3fde2806b62 DS> Bump version to 0.2 I tagged 0.1 in front of this set. Goals for version 0.2 will be: - More complete support for Xen FV and KVM - Domain lifecycle indications -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From danms at us.ibm.com Mon Jan 14 14:40:06 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 07:40:06 -0700 Subject: [Libvirt-cim] [PATCH] Add release information to the web content Message-ID: # HG changeset patch # User Dan Smith # Date 1200325203 28800 # Node ID ef7305a73d2920d12193ddf132cec079e7b56135 # Parent 206060cfee965f2939d8e7b3eb790724634017de Add release information to the web content Signed-off-by: Dan Smith diff -r 206060cfee96 -r ef7305a73d29 doc/libvirt-cim.html --- a/doc/libvirt-cim.html Mon Jan 14 07:20:44 2008 -0800 +++ b/doc/libvirt-cim.html Mon Jan 14 07:40:03 2008 -0800 @@ -22,7 +22,23 @@

Releases

-

There have been no releases to date

+

Here is the list of official releases. Developers and people +looking for the latest features should check +the downloads page for a snapshot of the +repository.

+ +

livirt-cim-0.1: Jan 14 2008

+ +
    +
  • Initial release
  • +
  • Focused on Xen paravirt guest support
  • +
+ +

libcmpiutil-0.1: Nov 30 2007

+ +
    +
  • Initial release
  • +

Introduction

@@ -42,6 +58,15 @@

Downloads

+

Official releases can be found on the +libvirt.org FTP server. +Alternatively, you can grab a +tarball or +zip +file snapshot of the development repository. These snapshots will +have the latest features (and bugs).

+ +

The libvirt-cim development tree can be found in the libvirt.org/hg repository.

@@ -53,11 +78,6 @@

$ hg clone http://libvirt.org/hg/libvirt-cim

-

Alternatively, you can grab a - tarball or - zip - file snapshot of the repository. -

Patches

From kaitlin at linux.vnet.ibm.com Mon Jan 14 17:02:43 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 09:02:43 -0800 Subject: [Libvirt-cim] [PATCH] Make cleanup_dominfo() handle KVM domains In-Reply-To: <4ae48640b6dfaf77c603.1200067299@theine> References: <4ae48640b6dfaf77c603.1200067299@theine> Message-ID: <478B95B3.10901@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200067187 28800 > # Node ID 4ae48640b6dfaf77c60300aa2f41a3be9395bf83 > # Parent e834b93342a431c9414fbb07c2aa34e28002744d > Make cleanup_dominfo() handle KVM domains > > This avoids the following message in the CIMOM logs: > > device_parsing.c(818): Unknown domain type 2 > > Signed-off-by: Dan Smith > > diff -r e834b93342a4 -r 4ae48640b6df libxkutil/device_parsing.c > --- a/libxkutil/device_parsing.c Fri Jan 11 07:40:28 2008 -0800 > +++ b/libxkutil/device_parsing.c Fri Jan 11 07:59:47 2008 -0800 > @@ -810,7 +810,8 @@ void cleanup_dominfo(struct domain **dom > free(dom->os_info.pv.kernel); > free(dom->os_info.pv.initrd); > free(dom->os_info.pv.cmdline); > - } else if (dom->type == DOMAIN_XENFV) { > + } else if ((dom->type == DOMAIN_XENFV) || > + (dom->type == DOMAIN_KVM)) { Good catch. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 14 17:16:05 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 09:16:05 -0800 Subject: [Libvirt-cim] [PATCH] Relax the KVM type detection logic In-Reply-To: References: Message-ID: <478B98D5.1070606@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200067225 28800 > # Node ID a353b12b24858b16b3b6d77940178f5cd672bdce > # Parent 4ae48640b6dfaf77c60300aa2f41a3be9395bf83 > Relax the KVM type detection logic > since it was too strict for no reason. > > Signed-off-by: Dan Smith > > diff -r 4ae48640b6df -r a353b12b2485 libxkutil/device_parsing.c > --- a/libxkutil/device_parsing.c Fri Jan 11 07:59:47 2008 -0800 > +++ b/libxkutil/device_parsing.c Fri Jan 11 08:00:25 2008 -0800 > @@ -652,8 +652,7 @@ static int parse_os(struct domain *domin > if ((STREQC(dominfo->os_info.fv.type, "hvm")) && > (STREQC(dominfo->typestr, "xen"))) > dominfo->type = DOMAIN_XENFV; > - else if ((STREQC(dominfo->os_info.fv.type, "hvm")) && > - (STREQC(dominfo->typestr, "kvm"))) > + else if (STREQC(dominfo->typestr, "kvm")) > dominfo->type = DOMAIN_KVM; Seems reasonable since we only care about the KVm typestr. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 14 17:17:29 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 09:17:29 -0800 Subject: [Libvirt-cim] [PATCH] Bump version to 0.2 In-Reply-To: <87ir1wzay3.fsf@theine.beaverton.ibm.com> References: <29c9bb8cb88428491764.1200324016@theine> <87ir1wzay3.fsf@theine.beaverton.ibm.com> Message-ID: <478B9929.6020509@linux.vnet.ibm.com> Dan Smith wrote: > DS> # HG changeset patch > DS> # User Dan Smith > DS> # Date 1200323991 28800 > DS> # Node ID 29c9bb8cb88428491764aa58f9bb214c3d7f5f03 > DS> # Parent db25d5f62c9d662cd262ea82efb6d3fde2806b62 > DS> Bump version to 0.2 > > I tagged 0.1 in front of this set. > > Goals for version 0.2 will be: > > - More complete support for Xen FV and KVM > - Domain lifecycle indications Sounds good. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Mon Jan 14 17:22:25 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 10:22:25 -0700 Subject: [Libvirt-cim] [PATCH] Add a README.DMTF to the base_schema Message-ID: <4909cfcdc6288cd20d8c.1200334945@theine> # HG changeset patch # User Dan Smith # Date 1200334917 28800 # Node ID 4909cfcdc6288cd20d8c06a54b1fd458d8d298f3 # Parent 6cf619d174232d9c4f2cfab1543ed863443a92d2 Add a README.DMTF to the base_schema Signed-off-by: Dan Smith diff -r 6cf619d17423 -r 4909cfcdc628 base_schema/Makefile.am --- a/base_schema/Makefile.am Mon Jan 14 09:33:40 2008 -0800 +++ b/base_schema/Makefile.am Mon Jan 14 10:21:57 2008 -0800 @@ -6,4 +6,6 @@ dist_pkgdata_SCRIPTS = install_base_sche dist_pkgdata_SCRIPTS = install_base_schema.sh $(CIM_SCHEMA_ZIP): - wget http://www.dmtf.org/standards/cim/cim_schema_v$(CIM_SCHEMA_VER)/$(CIM_SCHEMA_ZIP) \ No newline at end of file + wget http://www.dmtf.org/standards/cim/cim_schema_v$(CIM_SCHEMA_VER)/$(CIM_SCHEMA_ZIP) + +EXTRA_DIST = README.DMTF diff -r 6cf619d17423 -r 4909cfcdc628 base_schema/README.DMTF --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base_schema/README.DMTF Mon Jan 14 10:21:57 2008 -0800 @@ -0,0 +1,9 @@ +The DMTF CIM schema files included here are required for proper +initialization of the CIM server environment. They are permitted for +distribution per the guidelines at the top of the main MOF file: + +// DMTF is a not-for-profit association of industry members dedicated +// to promoting enterprise and systems management and interoperability. +// DMTF specifications and documents may be reproduced for uses +// consistent with this purpose by members and non-members, +// provided that correct attribution is given. From danms at us.ibm.com Mon Jan 14 17:22:42 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 10:22:42 -0700 Subject: [Libvirt-cim] [PATCH] Fix build of xml_parse_test Message-ID: <4b720e825e01217f4410.1200334962@theine> # HG changeset patch # User Dan Smith # Date 1200334940 28800 # Node ID 4b720e825e01217f441047b3eed0b25aa1c85c95 # Parent 4909cfcdc6288cd20d8c06a54b1fd458d8d298f3 Fix build of xml_parse_test to include the in-tree libxkutil, instead of the one installed on the system Signed-off-by: Dan Smith diff -r 4909cfcdc628 -r 4b720e825e01 libxkutil/Makefile.am --- a/libxkutil/Makefile.am Mon Jan 14 10:21:57 2008 -0800 +++ b/libxkutil/Makefile.am Mon Jan 14 10:22:20 2008 -0800 @@ -16,5 +16,6 @@ noinst_PROGRAMS = xml_parse_test noinst_PROGRAMS = xml_parse_test xml_parse_test_SOURCES = xml_parse_test.c -#xml_parse_test_HEADERS = device_parsing.h -xml_parse_test_LDADD = -lvirt -lxkutil +xml_parse_test_LDADD = -lvirt +xml_parse_test_LDFLAGS = libxkutil.la +xml_parse_test_DEPENDENCIES = libxkutil.la From kaitlin at linux.vnet.ibm.com Mon Jan 14 18:50:25 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 10:50:25 -0800 Subject: [Libvirt-cim] [PATCH] Add release information to the web content In-Reply-To: References: Message-ID: <478BAEF1.4090905@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200325203 28800 > # Node ID ef7305a73d2920d12193ddf132cec079e7b56135 > # Parent 206060cfee965f2939d8e7b3eb790724634017de > Add release information to the web content >

Releases

> > -

There have been no releases to date

> +

Here is the list of official releases. Developers and people > +looking for the latest features should check > +the downloads page for a snapshot of the > +repository.

> + > +

livirt-cim-0.1: Jan 14 2008

> + > +
    > +
  • Initial release
  • > +
  • Focused on Xen paravirt guest support
  • > +
> + > +

libcmpiutil-0.1: Nov 30 2007

> + > +
    > +
  • Initial release
  • > +
> Not sure where the right place is, but would it be a good idea to add some info on libcmpiutil (or at least a small note that indicates the dependency between the two packages)? -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 14 18:51:24 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 10:51:24 -0800 Subject: [Libvirt-cim] [PATCH] Add a README.DMTF to the base_schema In-Reply-To: <4909cfcdc6288cd20d8c.1200334945@theine> References: <4909cfcdc6288cd20d8c.1200334945@theine> Message-ID: <478BAF2C.2070803@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200334917 28800 > # Node ID 4909cfcdc6288cd20d8c06a54b1fd458d8d298f3 > # Parent 6cf619d174232d9c4f2cfab1543ed863443a92d2 > Add a README.DMTF to the base_schema > Looks like a good addition. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Mon Jan 14 18:52:11 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 10:52:11 -0800 Subject: [Libvirt-cim] [PATCH] Fix build of xml_parse_test In-Reply-To: <4b720e825e01217f4410.1200334962@theine> References: <4b720e825e01217f4410.1200334962@theine> Message-ID: <478BAF5B.2060208@linux.vnet.ibm.com> Dan Smith wrote: > # HG changeset patch > # User Dan Smith > # Date 1200334940 28800 > # Node ID 4b720e825e01217f441047b3eed0b25aa1c85c95 > # Parent 4909cfcdc6288cd20d8c06a54b1fd458d8d298f3 > Fix build of xml_parse_test > to include the in-tree libxkutil, instead of the one installed on the system > Excellent change. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Mon Jan 14 19:11:45 2008 From: danms at us.ibm.com (Dan Smith) Date: Mon, 14 Jan 2008 11:11:45 -0800 Subject: [Libvirt-cim] [PATCH] Add release information to the web content In-Reply-To: <478BAEF1.4090905@linux.vnet.ibm.com> (Kaitlin Rupert's message of "Mon, 14 Jan 2008 10:50:25 -0800") References: <478BAEF1.4090905@linux.vnet.ibm.com> Message-ID: <87ejckz0ge.fsf@theine.beaverton.ibm.com> KR> Not sure where the right place is, but would it be a good idea to KR> add some info on libcmpiutil (or at least a small note that KR> indicates the dependency between the two packages)? Yeah, which is why it's not in there anywhere. Perhaps on the "architecture" page that explains the components? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms at us.ibm.com -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 188 bytes Desc: not available URL: From grendel at linux.vnet.ibm.com Mon Jan 14 19:38:19 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Mon, 14 Jan 2008 14:38:19 -0500 Subject: [Libvirt-cim] [PATCH] (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests Message-ID: <83dd6d18f98c2f43b59c.1200339499@wulfgar> # HG changeset patch # User Jay Gagnon # Date 1200339496 18000 # Node ID 83dd6d18f98c2f43b59cbed5e025969f94a43f84 # Parent 51c57a6dabe9068f8638a6b923779085ff98b67e (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests. Changes since last time: change free_dom_xml from int to void return type use *far* better sys_name_from_xml logic use calloc instead of malloc for allocating array get UUID for domain directly into dom_xml structure changed struct dom_xml's uuid member to suit get xml for domain directly into dom_xml structure add cleanup_domain_list function use ObjectPath from CIMOM for prefix, classname, etc instead of literals Signed-off-by: Jay Gagnon diff -r 51c57a6dabe9 -r 83dd6d18f98c src/Virt_ComputerSystemModifiedIndication.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_ComputerSystemModifiedIndication.c Mon Jan 14 14:38:16 2008 -0500 @@ -0,0 +1,410 @@ +/* + * Copyright IBM Corp. 2007 + * + * Authors: + * Jay Gagnon + * + * 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 +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include +#include +#include +#include + +#include "config.h" + +#include "Virt_ComputerSystem.h" + +static const CMPIBroker *_BROKER; + +static CMPI_THREAD_TYPE lifecycle_thread_id = 0; + +enum CS_EVENTS { + CS_MODIFIED, +}; + +static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER; +static pthread_mutex_t lifecycle_mutex = PTHREAD_MUTEX_INITIALIZER; +static bool lifecycle_enabled = 0; + +#ifdef CMPI_EI_VOID +# define _EI_RTYPE void +# define _EI_RET() return +#else +# define _EI_RTYPE CMPIStatus +# define _EI_RET() return (CMPIStatus){CMPI_RC_OK, NULL} +#endif + +struct dom_xml { + char uuid[VIR_UUID_STRING_BUFLEN]; + char *xml; +}; + +struct ind_args { + CMPIContext *context; + const CMPIObjectPath *ref; +}; + +static void free_dom_xml (struct dom_xml dom) +{ + free(dom.xml); +} + +static void free_ind_args (struct ind_args args) +{ + /* Nothing to do right now, but if this ends up with + something that does need to be freed I want everything in place. */ +} + +static void cleanup_domain_list(virDomainPtr *list, int size) +{ + int i; + + for (i = 0; i < size; i++) { + virDomainFree(list[i]); + } +} + +static bool _lifecycle_indication(const CMPIBroker *broker, + const CMPIContext *ctx, + CMPIInstance *mod_inst, + char *prefix, + char *ns) +{ + CMPIObjectPath *ind_op; + CMPIInstance *ind; + CMPIStatus s; + + ind = get_typed_instance(broker, + prefix, + "ComputerSystemModifiedIndication", + ns); + if (ind == NULL) { + CU_DEBUG("Failed to create ind"); + return false; + } + + ind_op = CMGetObjectPath(ind, &s); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to get ind_op"); + return false; + } + + CMSetProperty(ind, "PreviousInstance", + (CMPIValue *)&mod_inst, CMPI_instance); + + printf("Delivering Indication: %s\n", + CMGetCharPtr(CMObjectPathToString(ind_op, NULL))); + + CBDeliverIndication(_BROKER, + ctx, + CIM_VIRT_NS, + ind); + + return true; +} + +static bool wait_for_event(void) +{ + struct timespec timeout; + int ret; + + + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += 3; + + ret = pthread_cond_timedwait(&lifecycle_cond, + &lifecycle_mutex, + &timeout); + + return true; +} + +static char *sys_name_from_xml(char *xml) +{ + char *tmp = NULL; + char *name = NULL; + int rc; + + tmp = strstr(xml, ""); + if (tmp == NULL) + goto out; + + rc = sscanf(tmp, "%a[^<]s", &name); + if (rc != 1) + name = NULL; + + out: + return name; +} + +static bool async_ind(CMPIContext *context, + virConnectPtr conn, + struct dom_xml prev_dom, + char *prefix, + char *ns) +{ + bool rc; + char *name = NULL; + CMPIInstance *mod_inst; + + /* Where should we be getting the namespace and classname? */ + mod_inst = get_typed_instance(_BROKER, + prefix, + "ComputerSystem", + ns); + + name = sys_name_from_xml(prev_dom.xml); + CU_DEBUG("Name for system: '%s'", name); + if (name == NULL) { + rc = false; + goto out; + } + + CMSetProperty(mod_inst, "Name", + (CMPIValue *)name, CMPI_chars); + CMSetProperty(mod_inst, "UUID", + (CMPIValue *)prev_dom.uuid, CMPI_chars); + + rc = _lifecycle_indication(_BROKER, context, mod_inst, prefix, ns); + + out: + free(name); + return rc; +} + +static CMPIStatus doms_to_xml(struct dom_xml **dom_xml_list, + virDomainPtr *dom_ptr_list, + int dom_ptr_count) +{ + int i; + int rc; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + *dom_xml_list = calloc(dom_ptr_count, sizeof(struct dom_xml)); + for (i = 0; i < dom_ptr_count; i++) { + rc = virDomainGetUUIDString(dom_ptr_list[i], + (*dom_xml_list)[i].uuid); + if (rc == -1) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to get UUID"); + /* If any domain fails, we fail. */ + break; + } + + (*dom_xml_list)[i].xml = virDomainGetXMLDesc(dom_ptr_list[i], + 0); + if ((*dom_xml_list)[i].xml == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to get xml desc"); + break; + } + } + + return s; +} + +static bool dom_changed(struct dom_xml prev_dom, + struct dom_xml *cur_xml, + int cur_count) +{ + int i; + bool ret = false; + + for (i = 0; i < cur_count; i++) { + if (strcmp(cur_xml[i].uuid, prev_dom.uuid) != 0) + continue; + + if (strcmp(cur_xml[i].xml, prev_dom.xml) != 0) + ret = true; + + break; + } + + return ret; +} + +static CMPI_THREAD_RETURN lifecycle_thread(void *params) +{ + int i; + int cur_count; + int prev_count; + char *ns = NULL; + virConnectPtr conn; + char *prefix = NULL; + virDomainPtr *tmp_list; + CMPIContext *context = NULL; + struct dom_xml *cur_xml = NULL; + struct dom_xml *prev_xml = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct ind_args *args = (struct ind_args *)params; + + context = args->context; + prefix = class_prefix_name(CLASSNAME(args->ref)); + ns = NAMESPACE(args->ref); + + conn = connect_by_classname(_BROKER, CLASSNAME(args->ref), &s); + + pthread_mutex_lock(&lifecycle_mutex); + + CBAttachThread(_BROKER, context); + + prev_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&prev_xml, tmp_list, prev_count); + /* TODO: status check */ + cleanup_domain_list(tmp_list, prev_count); + + CU_DEBUG("entering event loop"); + while (lifecycle_enabled) { + bool modified; + + cur_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&cur_xml, tmp_list, cur_count); + /* TODO: status check */ + cleanup_domain_list(tmp_list, cur_count); + + for (i = 0; i < prev_count; i++) { + modified = dom_changed(prev_xml[i], cur_xml, cur_count); + if (modified) { + CU_DEBUG("Domain '%s' modified.", prev_xml[i].uuid); + async_ind(context, conn, prev_xml[i], prefix, ns); + } + free_dom_xml(prev_xml[i]); + } + + free(prev_xml); + prev_xml = cur_xml; + wait_for_event(); + } + CU_DEBUG("exiting event loop"); + + pthread_mutex_unlock(&lifecycle_mutex); + free_ind_args(*args); + free(prefix); + /* Should I free args as well here, since it's malloced in activate? */ + + return NULL; +} + +static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, + const CMPIContext* ctx, + const CMPISelectExp* se, + const char *ns, + const CMPIObjectPath* op, + CMPIBoolean first) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct ind_args *args = malloc(sizeof(struct ind_args)); + + CU_DEBUG("ActivateFilter"); + + if (CMIsNullObject(op)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No ObjectPath given"); + goto out; + } + args->ref = op; + + if (lifecycle_thread_id == 0) { + args->context = CBPrepareAttachThread(_BROKER, ctx); + + lifecycle_thread_id = _BROKER->xft->newThread(lifecycle_thread, + args, + 0); + } + + out: + return s; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, + const CMPIContext* ctx, + const CMPISelectExp* se, + const char *ns, + const CMPIObjectPath* op, + CMPIBoolean last) +{ + return (CMPIStatus){CMPI_RC_OK, NULL}; +} + +static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, + const CMPIContext *ctx) +{ + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = true; + pthread_mutex_unlock(&lifecycle_mutex); + + CU_DEBUG("ComputerSystemModifiedIndication enabled"); + + _EI_RET(); +} + +static _EI_RTYPE DisableIndications(CMPIIndicationMI* mi, + const CMPIContext *ctx) +{ + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = false; + pthread_mutex_unlock(&lifecycle_mutex); + + CU_DEBUG("ComputerSystemModifiedIndication disabled"); + + _EI_RET(); +} + +static CMPIStatus trigger_indication(const CMPIContext *context) +{ + pthread_cond_signal(&lifecycle_cond); + CU_DEBUG("CSMI triggered"); + return(CMPIStatus){CMPI_RC_OK, NULL}; +} + +static struct std_indication_handler csmi = { + .raise_fn = NULL, + .trigger_fn = trigger_indication, +}; + +DEFAULT_IND_CLEANUP(); +DEFAULT_AF(); +DEFAULT_MP(); + +STDI_IndicationMIStub(, Virt_ComputerSystemModifiedIndicationProvider, + _BROKER, libvirt_cim_init(), &csmi); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From grendel at linux.vnet.ibm.com Mon Jan 14 19:50:53 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Mon, 14 Jan 2008 14:50:53 -0500 Subject: [Libvirt-cim] [PATCH] (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: <83dd6d18f98c2f43b59c.1200339499@wulfgar> References: <83dd6d18f98c2f43b59c.1200339499@wulfgar> Message-ID: <478BBD1D.4090102@linux.vnet.ibm.com> Jay Gagnon wrote: > # HG changeset patch > # User Jay Gagnon > # Date 1200339496 18000 > # Node ID 83dd6d18f98c2f43b59cbed5e025969f94a43f84 > # Parent 51c57a6dabe9068f8638a6b923779085ff98b67e > (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests. > > Changes since last time: > change free_dom_xml from int to void return type > use *far* better sys_name_from_xml logic > use calloc instead of malloc for allocating array > get UUID for domain directly into dom_xml structure > changed struct dom_xml's uuid member to suit > get xml for domain directly into dom_xml structure > add cleanup_domain_list function > use ObjectPath from CIMOM for prefix, classname, etc instead of literals > > Signed-off-by: Jay Gagnon > > If everyone is okay with things I will be integrating this into the existing CS indication provider (although codewise it might really be more like the other way around). If there is anything major here then I can do one more round of RFC before I integrate, but any minor things will be handled along with the integration. Oh, and just as a matter of taste, I prefer (#2) over .#2 as a method of comment protection in the commit message. Opinions? -- -Jay From kaitlin at linux.vnet.ibm.com Mon Jan 14 22:19:21 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Mon, 14 Jan 2008 14:19:21 -0800 Subject: [Libvirt-cim] [PATCH] (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: <83dd6d18f98c2f43b59c.1200339499@wulfgar> References: <83dd6d18f98c2f43b59c.1200339499@wulfgar> Message-ID: <478BDFE9.9080605@linux.vnet.ibm.com> Jay Gagnon wrote: > + > + printf("Delivering Indication: %s\n", > + CMGetCharPtr(CMObjectPathToString(ind_op, NULL))); Don't forget to change this to a CU_DEBUG(). > + > + conn = connect_by_classname(_BROKER, CLASSNAME(args->ref), &s); Don't forget to free the connection. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From grendel at linux.vnet.ibm.com Mon Jan 14 22:36:37 2008 From: grendel at linux.vnet.ibm.com (Jay Gagnon) Date: Mon, 14 Jan 2008 17:36:37 -0500 Subject: [Libvirt-cim] [PATCH] (#2) [RFC] Add Virt_ComputerSystemModifiedIndication, which watches for changes in our guests In-Reply-To: <478BDFE9.9080605@linux.vnet.ibm.com> References: <83dd6d18f98c2f43b59c.1200339499@wulfgar> <478BDFE9.9080605@linux.vnet.ibm.com> Message-ID: <478BE3F5.8090008@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Jay Gagnon wrote: >> + >> + printf("Delivering Indication: %s\n", >> + CMGetCharPtr(CMObjectPathToString(ind_op, NULL))); > > Don't forget to change this to a CU_DEBUG(). > >> + >> + conn = connect_by_classname(_BROKER, CLASSNAME(args->ref), &s); > > Don't forget to free the connection. > Eagle eyes, this one. :) -- -Jay From yunguol at cn.ibm.com Tue Jan 15 08:07:53 2008 From: yunguol at cn.ibm.com (Guo Lian Yun) Date: Tue, 15 Jan 2008 16:07:53 +0800 Subject: [Libvirt-cim] Xen_ElementCapabilities qurey error list Message-ID: Hi, Beside the former error report of query Xen_HostSystem from Xen_VirtualSystemManagementCapabilities according to Xen_ElementCapabilities association, that is to say, with a non exist VirtualSystemManagementCapabilities, we can still get excepted result as following. wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_VirtualSystemManagementCapabilities.InstanceID=" wrong" localhost:5988/root/virt:Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="wks230838wss.cn.ibm.com" Meanwhile, other associations have the same problems. With a non exist ComputerSystem instance, we can still get expected association. wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_ComputerSystem.CreationClassName="Xen_ComputerSystem",Name=" wrong" localhost:5988/root/virt:Xen_EnabledLogicalElementCapabilities.InstanceID="wrong" However, there is no error report when I do invalid reverse query of Xen_EnabledLogicalElementCapabilities. wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_EnabledLogicalElementCapabilities.InstanceID=" wrong" As we know, Xen_AllocationCapabilities associate with ResourcePool by Xen_ElementCapabilities. There are still errors from two sides querying. wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_AllocationCapabilities.InstanceID="ProcessorPool/0" * * wbemcli: Cim: (7) CIM_ERR_NOT_SUPPORTED: The requested operation is not supported * wbemcli ain -ac Xen_ElementCapabilities http://root:password at localhost/root/virt:Xen_MemoryPool.InstanceID="wrong" localhost:5988/root/virt:Xen_AllocationCapabilities.InstanceID="wrong" Please who can have a look into them? Thanks! Best, Regards Daisy Guo Lian Yun E-mail: yunguol at cn.ibm.com IBM China Development Lab, Shanghai, China TEL: (86)-21-61008057 -------------- next part -------------- An HTML attachment was scrubbed... URL: From heidieck at linux.vnet.ibm.com Tue Jan 15 11:56:16 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 12:56:16 +0100 Subject: [Libvirt-cim] [PATCH] [CU] Add function to validate a client given object path In-Reply-To: <87zlvc2veo.fsf@theine.beaverton.ibm.com> References: <393ba1344f5be2ea42b2.1200046334@localhost.localdomain> <87zlvc2veo.fsf@theine.beaverton.ibm.com> Message-ID: <478C9F60.7050107@linux.vnet.ibm.com> Dan Smith wrote: > How about a comment before the function prototype explaining that it's > just like cu_compare_ref() but returns a CMPIStatus? I was confused > about how it's different when I first looked at it :) > Sure. Good catch. I will send an updated patch. > In general, I've tried to keep libcmpiutil.h pretty well documented, > so I'd like to not depart from doing so. > > I can only agree :). -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 15 10:56:55 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 12:56:55 +0200 Subject: [Libvirt-cim] [PATCH] [CU] Add function to validate a client given object path Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1200398044 -3600 # Node ID feaf6295a3fbc749d5c57ee29f6391880e692493 # Parent 2a52fc3c4bbcc3efe93d2943928c8d3128dca03b [CU] Add function to validate a client given object path Signed-off-by: Heidi Eckhart diff -r 2a52fc3c4bbc -r feaf6295a3fb instance_util.c --- a/instance_util.c Thu Dec 13 11:10:59 2007 +0100 +++ b/instance_util.c Tue Jan 15 12:54:04 2008 +0100 @@ -154,6 +154,23 @@ const char *cu_compare_ref(const CMPIObj prop = NULL; out: return prop; +} + +CMPIStatus cu_validate_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIInstance *inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *prop; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + return s; } CMPIStatus cu_copy_prop(const CMPIBroker *broker, diff -r 2a52fc3c4bbc -r feaf6295a3fb libcmpiutil.h --- a/libcmpiutil.h Thu Dec 13 11:10:59 2007 +0100 +++ b/libcmpiutil.h Tue Jan 15 12:54:04 2008 +0100 @@ -377,6 +377,22 @@ int inst_list_add(struct inst_list *list * or NULL if all match */ const char *cu_compare_ref(const CMPIObjectPath *ref, + const CMPIInstance *inst); + +/** + * Validate a client given reference against the system instance. + * This is done by comparing the key values of the reference + * against the key properties found in the system instance. + * + * @param broker A pointer to the current broker + * @param ref The ObjectPath to examine + * @param inst The Instance to compare + * @returns The status of the comparision: + * CMPI_RC_OK in case of match + * CMPI_RC_ERR_NOT_FOUND in case of not matching + */ +CMPIStatus cu_validate_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref, const CMPIInstance *inst); #define DEFAULT_EIN(pn) \ From heidieck at linux.vnet.ibm.com Tue Jan 15 12:17:10 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 13:17:10 +0100 Subject: [Libvirt-cim] Xen_ElementCapabilities qurey error list In-Reply-To: References: Message-ID: <478CA446.9060803@linux.vnet.ibm.com> Guo Lian Yun wrote: > > Hi, > > Beside the former error report of query Xen_HostSystem from > Xen_VirtualSystemManagementCapabilities according to > Xen_ElementCapabilities association, > that is to say, with a non exist VirtualSystemManagementCapabilities, > we can still get excepted result as following. > wbemcli ain -ac Xen_ElementCapabilities > http://root:password at localhost/root/virt:Xen_VirtualSystemManagementCapabilities.InstanceID="wrong" > localhost:5988/root/virt:Xen_HostSystem.CreationClassName="Xen_HostSystem",Name="wks230838wss.cn.ibm.com" > > Meanwhile, other associations have the same problems. > With a non exist ComputerSystem instance, we can still get expected > association. > wbemcli ain -ac Xen_ElementCapabilities > http://root:password at localhost/root/virt:Xen_ComputerSystem.CreationClassName="Xen_ComputerSystem",Name="wrong" > localhost:5988/root/virt:Xen_EnabledLogicalElementCapabilities.InstanceID="wrong" > > However, there is no error report when I do invalid reverse query of > Xen_EnabledLogicalElementCapabilities. > wbemcli ain -ac Xen_ElementCapabilities > http://root:password at localhost/root/virt:Xen_EnabledLogicalElementCapabilities.InstanceID="wrong" > > As we know, Xen_AllocationCapabilities associate with ResourcePool by > Xen_ElementCapabilities. There are still errors from two sides querying. > > wbemcli ain -ac Xen_ElementCapabilities > http://root:password at localhost/root/virt:Xen_AllocationCapabilities.InstanceID="ProcessorPool/0" > * > * wbemcli: Cim: (7) CIM_ERR_NOT_SUPPORTED: The requested operation is > not supported > * > > wbemcli ain -ac Xen_ElementCapabilities > http://root:password at localhost/root/virt:Xen_MemoryPool.InstanceID="wrong" > localhost:5988/root/virt:Xen_AllocationCapabilities.InstanceID="wrong" > > Please who can have a look into them? Thanks! > > > Best, > Regards > > Daisy Guo Lian Yun > E-mail: yunguol at cn.ibm.com > IBM China Development Lab, Shanghai, China > TEL: (86)-21-61008057 > Hi Daisy, we are currently working on a patch set for all of the issues you mentioned. Once the patches are checked in, I will inform you. Thanks :) -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 15 12:56:10 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 13:56:10 +0100 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: <87hchk2u84.fsf@theine.beaverton.ibm.com> References: <224b84cf00ac2e120d86.1200052250@localhost.localdomain> <87hchk2u84.fsf@theine.beaverton.ibm.com> Message-ID: <478CAD6A.4000901@linux.vnet.ibm.com> Dan Smith wrote: > HE> + CMPIStatus s = {CMPI_RC_OK, NULL}; > HE> + CMPIInstance *alloc_cap_inst; > HE> + virConnectPtr conn = NULL; > HE> + struct inst_list device_pool_list; > HE> + const char *inst_id; > HE> int i; > HE> - virConnectPtr conn = NULL; > HE> - CMPIInstance *alloc_cap_inst; > HE> - struct inst_list alloc_cap_list; > HE> - struct inst_list device_pool_list; > HE> - CMPIStatus s = {CMPI_RC_OK, NULL}; > HE> - const char *inst_id; > > Reordering this block for no reason makes it really difficult to tell > what is changed. Can we please keep this kind of thing separate from > the functional change to the code? > Sorry, this happened as changes went forward. I will fix this. > HE> + inst_list_init(list); > > In other places, we initialize the list before we pass it into a > function. I think it makes more sense that way, as the caller may > want the results of this function appended to the list it passes in. > > HE> +static CMPIStatus return_alloc_cap_instances(const CMPIBroker *broker, > HE> + const CMPIObjectPath *ref, > HE> + const CMPIResult *results, > HE> + bool names_only, > HE> + const char **properties, > HE> + const char *id) > HE> +{ > HE> + CMPIStatus s = {CMPI_RC_OK, NULL}; > HE> + struct inst_list *list = NULL; > HE> + > HE> + s = enum_alloc_cap_instances(broker, > HE> + ref, > HE> + properties, > HE> + id, > HE> + list); > HE> + if (s.rc != CMPI_RC_OK) > HE> + goto out; > HE> + > HE> + if (names_only) > HE> + cu_return_instance_names(results, list); > HE> + else > HE> + cu_return_instances(results, list); > > This doesn't work, does it? You pass a NULL list pointer in to the > function, it allocates a list, but has no way to return it back. > You're passing just a single pointer by value here. If you were > modifying what the pointer pointed to, then you could get the result, > but otherwise the list that the enum_alloc_cap_instances() function > generates isn't visible to this caller. > > You should do the following: > > struct inst_list list; > > inst_list_init(&list); > > s = enum_alloc_cap_instances(broker, > ref, > properties, > id, > &list); > > Which addresses this issue as well as the previous one. > > Thanks! > > Oh, oh, what a bad day in my development time. You are absolutely right. This setup has no chance to return the result to the caller. And I haven't tested as extensively as I should have done. An excellent catch. Thank you. :) -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 15 12:58:30 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 13:58:30 +0100 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: <4787998E.2070509@linux.vnet.ibm.com> References: <90746174d66eb4d4ceb2.1200052251@localhost.localdomain> <4787998E.2070509@linux.vnet.ibm.com> Message-ID: <478CADF6.6040802@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Heidi Eckhart wrote: >> conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); >> if (s.rc != CMPI_RC_OK) >> - goto error1; >> + goto out; > > Should this also check for to see if conn == NULL? > Excellent catch - we always check for conn == NULL. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 15 14:11:54 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 15:11:54 +0100 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path o ComputerSystem In-Reply-To: <47879C35.4050300@linux.vnet.ibm.com> References: <47866072.6030405@linux.vnet.ibm.com> <478740C0.2000401@linux.vnet.ibm.com> <47879C35.4050300@linux.vnet.ibm.com> Message-ID: <478CBF2A.3060808@linux.vnet.ibm.com> Kaitlin Rupert wrote: > Heidi Eckhart wrote:. >> >> But your comments made me rethink about the patch. So I've >> consolidated and reordered a bit. >> - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - >> that does the check between the system instance and the client given >> instance > > I think this is a good idea. It seems like it'll be useful in other > places as well. > >> - get_domain() is now using the new libcmpiutil function >> - the parameter CMPIInstance **inst is now used to "configure" >> get_domain(); for internal usage the inst is returned and for >> external usage this can be ignored by setting it to NULL >> - validate_domain_ref() is now only an interface name for the client; >> this could also be removed and the provider has then to call >> get_domain(broker, ref, NULL) or simply ignores the returned >> instance; but what I do not really like is, that this can confuse the >> reader of the code; but I'm open for discussion and opinions > > As far as readability, I'm fine with this method. As an alternative, > you could have get_domain() return an instance and take a CMPIStatus > variable as a parameter. The provider can then choose to ignore the > returned instance. Ok, then it might not be that big issue to simply ignore the returned instance in case of success. > But that doesn't really fit with our existing code style. > If we leave get_domain() as it is now and only make it external, this would follow the coding style of e.g. DevicePool - get_pool_inst(...) - and EnabledLogicalElementCapabilities - get_ele_cap(...). So removing validate_domain_ref() and making get_domain() externally available is a good compromise. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor From heidieck at linux.vnet.ibm.com Tue Jan 15 13:23:17 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 15:23:17 +0200 Subject: [Libvirt-cim] [PATCH 0 of 3] #3 - Check client given object pathes in ElementCapabilities provider Message-ID: To enable the check for the client's given object path in ElementCapabilities, changes to the ComputerSystem and AllocationCapabilities provider have been necessary. Diff to patch #1: - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - that does the check between the system instance and the client given instance - get_domain() is now using the new libcmpiutil function - the parameter CMPIInstance **inst is now used to "configure" get_domain(); for internal usage the inst is returned and for external usage this can be ignored by setting it to NULL - validate_domain_ref() is now only an interface name for the client - removed patch unrelated changes in patch 2 - reworked logic to return instance(s) Diff to patch set #2: - removed validate_domain_ref() and made get_domain() external - fixed coding style in AllocationCapabilities - fixed inst_list to catch the returned instances - adopted changes to patch 1 and 2 to patch 3 - check for NULL connection in EC now From heidieck at linux.vnet.ibm.com Tue Jan 15 13:23:19 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 15:23:19 +0200 Subject: [Libvirt-cim] [PATCH 2 of 3] Make alloc_cap_instances() available for external use by EC In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1200405813 -3600 # Node ID e4d0cd30d6852f0e45d689086dccbe481c3c9fe9 # Parent a68e6445a09548ace93e2a191fead647e378d86c Make alloc_cap_instances() available for external use by EC The association provider ElementCapabilities needs the enum_alloc_cap_instances() function to access to the list of available AllocationCapabilities. These are returned by the additional inst_list parameter. Signed-off-by: Heidi Eckhart diff -r a68e6445a095 -r e4d0cd30d685 src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c Tue Jan 15 15:03:32 2008 +0100 +++ b/src/Virt_AllocationCapabilities.c Tue Jan 15 15:03:33 2008 +0100 @@ -31,6 +31,7 @@ #include "misc_util.h" +#include "Virt_AllocationCapabilities.h" #include "Virt_DevicePool.h" const static CMPIBroker *_BROKER; @@ -71,30 +72,25 @@ static CMPIStatus ac_from_pool(const CMP return s; } -static CMPIStatus alloc_cap_instances(const CMPIBroker *broker, - const CMPIObjectPath *ref, - const CMPIResult *results, - bool names_only, - const char **properties, - const char *id) -{ - int i; +CMPIStatus enum_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char **properties, + const char *id, + struct inst_list *list) +{ virConnectPtr conn = NULL; CMPIInstance *alloc_cap_inst; - struct inst_list alloc_cap_list; struct inst_list device_pool_list; CMPIStatus s = {CMPI_RC_OK, NULL}; const char *inst_id; - - CU_DEBUG("In alloc_cap_instances()"); + int i; inst_list_init(&device_pool_list); - inst_list_init(&alloc_cap_list); if (!provider_is_responsible(broker, ref, &s)) goto out; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + conn = connect_by_classname(broker, CLASSNAME(ref), &s); if (conn == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -129,7 +125,7 @@ static CMPIStatus alloc_cap_instances(co if (s.rc != CMPI_RC_OK) goto out; - inst_list_add(&alloc_cap_list, alloc_cap_inst); + inst_list_add(list, alloc_cap_inst); if (id && (STREQ(inst_id, id))) break; @@ -141,16 +137,42 @@ static CMPIStatus alloc_cap_instances(co "Requested Object could not be found."); goto out; } - - if (names_only) - cu_return_instance_names(results, &alloc_cap_list); - else - cu_return_instances(results, &alloc_cap_list); - + out: virConnectClose(conn); - inst_list_free(&alloc_cap_list); inst_list_free(&device_pool_list); + + return s; +} + +static CMPIStatus return_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only, + const char **properties, + const char *id) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct inst_list list; + + inst_list_init(&list); + + s = enum_alloc_cap_instances(broker, + ref, + properties, + id, + &list); + if (s.rc != CMPI_RC_OK) + goto out; + + if (names_only) + cu_return_instance_names(results, &list); + else + cu_return_instances(results, &list); + + out: + inst_list_free(&list); + return s; } @@ -170,12 +192,12 @@ static CMPIStatus GetInstance(CMPIInstan return s; } - return alloc_cap_instances(_BROKER, - reference, - results, - false, - properties, - id); + return return_alloc_cap_instances(_BROKER, + reference, + results, + false, + properties, + id); } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -183,12 +205,12 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return alloc_cap_instances(_BROKER, - reference, - results, - true, - NULL, - NULL); + return return_alloc_cap_instances(_BROKER, + reference, + results, + true, + NULL, + NULL); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -197,12 +219,12 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - return alloc_cap_instances(_BROKER, - reference, - results, - false, - properties, - NULL); + return return_alloc_cap_instances(_BROKER, + reference, + results, + false, + properties, + NULL); } DEFAULT_CI(); diff -r a68e6445a095 -r e4d0cd30d685 src/Virt_AllocationCapabilities.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_AllocationCapabilities.h Tue Jan 15 15:03:33 2008 +0100 @@ -0,0 +1,53 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Heidi Eckhart + * + * 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 __VIRT_ALLOCATIONCAPABILITIES_H +#define __VIRT_ALLOCATIONCAPABILITIES_H + +#include "misc_util.h" + +/** + * Return the instance of the AllocationCapabilities instance, + * defined by the id + * + * @param broker A pointer to the current broker + * @param ref The reference + * @param properties list of properties to set + * @param id The InstanceID of the AllocationCapabilities + * @param inst The list of instance(s) in case of success + * @returns The status of this operation + */ +CMPIStatus enum_alloc_cap_instances(const CMPIBroker *broker, + const CMPIObjectPath *ref, + const char **properties, + const char *id, + struct inst_list *list); + +#endif + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */ From heidieck at linux.vnet.ibm.com Tue Jan 15 13:23:18 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 15:23:18 +0200 Subject: [Libvirt-cim] [PATCH 1 of 3] Add function to validate the client given object path of a ComputerSystem In-Reply-To: Message-ID: # HG changeset patch # User Heidi Eckhart # Date 1200405812 -3600 # Node ID a68e6445a09548ace93e2a191fead647e378d86c # Parent b2a79064df2639a6b7ade2f2bbcb21af9c66a267 Add function to validate the client given object path of a ComputerSystem Signed-off-by: Heidi Eckhart diff -r b2a79064df26 -r a68e6445a095 src/Virt_ComputerSystem.c --- a/src/Virt_ComputerSystem.c Mon Jan 14 13:01:22 2008 -0800 +++ b/src/Virt_ComputerSystem.c Tue Jan 15 15:03:32 2008 +0100 @@ -285,7 +285,7 @@ CMPIInstance *instance_from_name(const C dom = virDomainLookupByName(conn, name); if (dom == NULL) - return 0; + return NULL; instance = get_typed_instance(broker, pfx_from_conn(conn), @@ -374,44 +374,57 @@ static CMPIStatus return_enum_domains(co return s; } -static CMPIStatus get_domain(const CMPIObjectPath *reference, - const CMPIResult *results, - const char *name) -{ - CMPIInstance *inst; - CMPIStatus s; +CMPIStatus get_domain(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **inst) +{ + CMPIInstance *_inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn = NULL; - const char *prop = NULL; - - if (!provider_is_responsible(_BROKER, reference, &s)) { - CMSetStatus(&s, CMPI_RC_ERR_NOT_FOUND); + const char *name; + + if (!provider_is_responsible(broker, reference, &s)) return s; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); + + if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No domain name specified"); + return s; + } + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) return s; - inst = instance_from_name(_BROKER, conn, name, reference); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to find `%s'", name); - goto out; - } - - prop = cu_compare_ref(reference, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, + _inst = instance_from_name(broker, conn, name, reference); + if (_inst == NULL) { + cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, - "No such instance (%s)", prop); - goto out; - } - - CMReturnInstance(results, inst); - CMSetStatus(&s, CMPI_RC_OK); + "No such instance (%s)", name); + goto out; + } + + s = cu_validate_ref(broker, reference, _inst); + out: virConnectClose(conn); + *inst = _inst; + + return s; +} + +static CMPIStatus return_domain(const CMPIObjectPath *reference, + const CMPIResult *results) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + + s = get_domain(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + return s; + + CMReturnInstance(results, inst); return s; } @@ -440,19 +453,7 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - const char *name; - - if (cu_get_str_path(reference, "Name", &name) != CMPI_RC_OK) { - CMPIStatus s; - - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No domain name specified"); - - return s; - } - - return get_domain(reference, results, name); + return return_domain(reference, results); } DEFAULT_CI(); diff -r b2a79064df26 -r a68e6445a095 src/Virt_ComputerSystem.h --- a/src/Virt_ComputerSystem.h Mon Jan 14 13:01:22 2008 -0800 +++ b/src/Virt_ComputerSystem.h Tue Jan 15 15:03:32 2008 +0100 @@ -52,6 +52,19 @@ int enum_domains(const CMPIBroker *broke const char *ns, struct inst_list *instlist); +/** + * Get domain instance specified by the client given domain + * object path + * + * @param broker A pointer to the current broker + * @param ref The client given object path + * @param inst In case of success the pointer to the instance + * @returns CMPIStatus + */ +CMPIStatus get_domain(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **inst); + #endif From heidieck at linux.vnet.ibm.com Tue Jan 15 13:23:20 2008 From: heidieck at linux.vnet.ibm.com (Heidi Eckhart) Date: Tue, 15 Jan 2008 15:23:20 +0200 Subject: [Libvirt-cim] [PATCH 3 of 3] EC: Validation of client given object path missing In-Reply-To: Message-ID: <67c18f86a60f0d2c13e8.1200407000@dyn-9-152-210-39.boeblingen.de.ibm.com> # HG changeset patch # User Heidi Eckhart # Date 1200405839 -3600 # Node ID 67c18f86a60f0d2c13e8106939efa99c21e33ea1 # Parent e4d0cd30d6852f0e45d689086dccbe481c3c9fe9 EC: Validation of client given object path missing The validation of the client's given ResourcePool object path is missing. Instead the submitted InstanceID is taken as value for the AllocationCapabilities InstanceID. wbemain -ac CIM_ElementCapabilities 'http://localhost/root/virt:KVM_DiskPool.InstanceID="notthere"' returns localhost:5988/root/virt:KVM_AllocationCapabilities.InstanceID="notthere" Signed-off-by: Heidi Eckhart diff -r e4d0cd30d685 -r 67c18f86a60f src/Makefile.am --- a/src/Makefile.am Tue Jan 15 15:03:33 2008 +0100 +++ b/src/Makefile.am Tue Jan 15 15:03:59 2008 +0100 @@ -89,17 +89,18 @@ libVirt_ElementConformsToProfile_la_LIBA libVirt_EnabledLogicalElementCapabilities_la_SOURCES = Virt_EnabledLogicalElementCapabilities.c +libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la +libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c +libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + libVirt_ElementCapabilities_la_DEPENDENCIES = libVirt_VirtualSystemManagementCapabilities.la libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la libVirt_HostSystem.la libVirt_VSMigrationCapabilities.la libVirt_ElementCapabilities_la_SOURCES = Virt_ElementCapabilities.c libVirt_ElementCapabilities_la_LIBADD = -lVirt_VirtualSystemManagementCapabilities \ -lVirt_EnabledLogicalElementCapabilities \ -lVirt_ComputerSystem \ -lVirt_HostSystem \ - -lVirt_VSMigrationCapabilities - -libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la -libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c -libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool + -lVirt_VSMigrationCapabilities \ + -lVirt_AllocationCapabilities libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la libVirt_DevicePool.la libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c diff -r e4d0cd30d685 -r 67c18f86a60f src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Tue Jan 15 15:03:33 2008 +0100 +++ b/src/Virt_ElementCapabilities.c Tue Jan 15 15:03:59 2008 +0100 @@ -37,6 +37,7 @@ #include "Virt_ComputerSystem.h" #include "Virt_HostSystem.h" #include "Virt_VSMigrationCapabilities.h" +#include "Virt_AllocationCapabilities.h" /* Associate an XXX_Capabilities to the proper XXX_ManagedElement. * @@ -46,6 +47,37 @@ */ const static CMPIBroker *_BROKER; + +static CMPIStatus validate_host_caps_ref(const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + char* classname; + + classname = class_base_name(CLASSNAME(ref)); + + if (STREQC(classname, "VirtualSystemManagementCapabilities")) { + s = get_vsm_cap(_BROKER, ref, &inst); + } else if (STREQC(classname, "VirtualSystemMigrationCapabilities")) { + s = get_migration_caps(ref, &inst, _BROKER); + } + + if (s.rc != CMPI_RC_OK) + goto out; + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + out: + free(classname); + + return s; +} static CMPIStatus sys_to_cap(const CMPIObjectPath *ref, struct std_assoc_info *info, @@ -53,22 +85,13 @@ static CMPIStatus sys_to_cap(const CMPIO { CMPIInstance *inst; CMPIStatus s = {CMPI_RC_OK, NULL}; - const char *prop; - - if (!match_hypervisor_prefix(ref, info)) - return s; - - s = get_host_cs(_BROKER, ref, &inst); - if (s.rc != CMPI_RC_OK) - goto out; - - prop = cu_compare_ref(ref, inst); - if (prop != NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such HostSystem (%s)", prop); - goto out; - } + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = validate_host_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_vsm_cap(_BROKER, ref, &inst); if (s.rc == CMPI_RC_OK) @@ -90,7 +113,11 @@ static CMPIStatus cap_to_sys(const CMPIO CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = validate_host_caps_ref(ref); + if (s.rc != CMPI_RC_OK) + goto out; s = get_host_cs(_BROKER, ref, &inst); if (s.rc != CMPI_RC_OK) @@ -111,7 +138,11 @@ static CMPIStatus cs_to_cap(const CMPIOb const char *sys_name = NULL; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; + + s = get_domain(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &sys_name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -138,26 +169,30 @@ static CMPIStatus cap_to_cs(const CMPIOb CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) - return s; + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Could not get InstanceID"); - goto error1; + goto out; } conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (s.rc != CMPI_RC_OK) - goto error1; + if (conn == NULL) + goto out; inst = instance_from_name(_BROKER, conn, inst_id, ref); if (inst) inst_list_add(list, inst); - + else + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", inst_id); + virConnectClose(conn); - error1: - + + out: return s; } @@ -173,14 +208,11 @@ static CMPIStatus pool_to_alloc(const CM struct std_assoc_info *info, struct inst_list *list) { - int ret; + CMPIStatus s = {CMPI_RC_OK, NULL}; const char *inst_id; - uint16_t type; - CMPIInstance *inst = NULL; - CMPIStatus s = {CMPI_RC_OK}; - - if (!match_hypervisor_prefix(ref, info)) - return s; + + if (!match_hypervisor_prefix(ref, info)) + goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -189,22 +221,11 @@ static CMPIStatus pool_to_alloc(const CM goto out; } - inst = get_typed_instance(_BROKER, - CLASSNAME(ref), - "AllocationCapabilities", - NAMESPACE(ref)); - CMSetProperty(inst, "InstanceID", inst_id, CMPI_chars); - - ret = cu_get_u16_path(ref, "ResourceType", &type); - if (ret != 1) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Could not get ResourceType"); - goto out; - } - CMSetProperty(inst, "ResourceType", &type, CMPI_uint16); - - inst_list_add(list, inst); + s = enum_alloc_cap_instances(_BROKER, + ref, + NULL, + inst_id, + list); out: return s; From kaitlin at linux.vnet.ibm.com Tue Jan 15 16:17:07 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 15 Jan 2008 08:17:07 -0800 Subject: [Libvirt-cim] [PATCH] [CU] Add function to validate a client given object path In-Reply-To: References: Message-ID: <478CDC83.5020102@linux.vnet.ibm.com> Heidi Eckhart wrote: > # HG changeset patch > # User Heidi Eckhart > # Date 1200398044 -3600 > # Node ID feaf6295a3fbc749d5c57ee29f6391880e692493 > # Parent 2a52fc3c4bbcc3efe93d2943928c8d3128dca03b > [CU] Add function to validate a client given object path > Signed-off-by: Heidi Eckhart > Looks good. +1 -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From kaitlin at linux.vnet.ibm.com Tue Jan 15 16:47:33 2008 From: kaitlin at linux.vnet.ibm.com (Kaitlin Rupert) Date: Tue, 15 Jan 2008 08:47:33 -0800 Subject: [Libvirt-cim] [PATCH 0 of 3] #3 - Check client given object pathes in ElementCapabilities provider In-Reply-To: References: Message-ID: <478CE3A5.2080301@linux.vnet.ibm.com> Heidi Eckhart wrote: > To enable the check for the client's given object path in ElementCapabilities, changes to the ComputerSystem and AllocationCapabilities provider have been necessary. > > Diff to patch #1: > - added a new function to libcmpiutil - cu_validate_ref(ref, inst) - that does the check between the system instance and the client given instance > - get_domain() is now using the new libcmpiutil function > - the parameter CMPIInstance **inst is now used to "configure" get_domain(); for internal usage the inst is returned and for external usage this can be ignored by setting it to NULL > - validate_domain_ref() is now only an interface name for the client > > - removed patch unrelated changes in patch 2 > - reworked logic to return instance(s) > > Diff to patch set #2: > - removed validate_domain_ref() and made get_domain() external > - fixed coding style in AllocationCapabilities > - fixed inst_list to catch the returned instances > - adopted changes to patch 1 and 2 to patch 3 > - check for NULL connection in EC now No complaints on this set. -- Kaitlin Rupert IBM Linux Technology Center karupert at us.ibm.com From danms at us.ibm.com Tue Jan 15 16:35:06 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 15 Jan 2008 09:35:06 -0700 Subject: [Libvirt-cim] [PATCH 0 of 2] VCPU xml generation Message-ID: We have, so far, been ignoring the vcpu bit of XML generation, mostly because we treat multiple vcpus as separate devices in the CIM world, but as a single integral value in the libvirt world. This set changes the way the xml generation code is structured to handle batches of devices, and then adds support for generating the VCPU node. It's a little strange, but I decided that allowing a given device class to modify and append the XML being generated for its class was the safest way to handle all the cases without separating things out too much. Comments on this approach are welcomed. I believe that this set will also make ModifyResource in VSMS work for VCPUs as well, since it should be able to generate updated XML with the new vcpu count after such an operation. More testing to determine if additional work will be required needs to be done. From danms at us.ibm.com Tue Jan 15 16:35:08 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 15 Jan 2008 09:35:08 -0700 Subject: [Libvirt-cim] [PATCH 2 of 2] Add VCPU XML generation In-Reply-To: Message-ID: <0339dbd4e4898d409cc4.1200418508@theine> # HG changeset patch # User Dan Smith # Date 1200415539 28800 # Node ID 0339dbd4e4898d409cc4a276a0197e71aec99937 # Parent f90450901ee0e616bda311a5da2e7d14c570f6fa Add VCPU XML generation Signed-off-by: Dan Smith diff -r f90450901ee0 -r 0339dbd4e489 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Tue Jan 15 08:33:39 2008 -0800 +++ b/libxkutil/xmlgen.c Tue Jan 15 08:45:39 2008 -0800 @@ -197,8 +197,21 @@ static bool net_to_xml(char **xml, struc static bool vcpu_to_xml(char **xml, struct virt_device *dev) { - astrcat(xml, "1\n"); - return true; + int count; + int ret; + + if (*xml == NULL) { + ret = asprintf(xml, "1"); + return ret != -1; + } + + if (sscanf(*xml, "%i\n", &count) != 1) + return false; + + free(*xml); + ret = asprintf(xml, "%i\n", count + 1); + + return ret != -1; } static bool mem_to_xml(char **xml, struct virt_device *dev) From danms at us.ibm.com Tue Jan 15 16:35:07 2008 From: danms at us.ibm.com (Dan Smith) Date: Tue, 15 Jan 2008 09:35:07 -0700 Subject: [Libvirt-cim] [PATCH 1 of 2] Change xmlgen core to handle batches of devices In-Reply-To: Message-ID: # HG changeset patch # User Dan Smith # Date 1200414819 28800 # Node ID f90450901ee0e616bda311a5da2e7d14c570f6fa # Parent b2a79064df2639a6b7ade2f2bbcb21af9c66a267 Change xmlgen core to handle batches of devices in preparation for the next patch to fix vcpu xml generation Signed-off-by: Dan Smith diff -r b2a79064df26 -r f90450901ee0 libxkutil/xmlgen.c --- a/libxkutil/xmlgen.c Mon Jan 14 13:01:22 2008 -0800 +++ b/libxkutil/xmlgen.c Tue Jan 15 08:33:39 2008 -0800 @@ -93,6 +93,26 @@ static char *tagify(char *tagname, char return result; } +static int astrcat(char **dest, char *source) +{ + char *tmp; + int ret; + + if (*dest) { + ret = asprintf(&tmp, "%s%s", *dest, source); + if (ret == -1) + return 0; + } else { + tmp = strdup(source); + } + + free(*dest); + + *dest = tmp; + + return 1; +} + static char *disk_block_xml(const char *path, const char *vdev) { char *xml; @@ -129,26 +149,34 @@ static char *disk_file_xml(const char *p return xml; } -static char *disk_to_xml(struct disk_device *disk) -{ +static bool disk_to_xml(char **xml, struct virt_device *dev) +{ + char *_xml = NULL; + struct disk_device *disk = &dev->dev.disk; + if (disk->disk_type == DISK_PHY) - return disk_block_xml(disk->source, disk->virtual_dev); + _xml = disk_block_xml(disk->source, disk->virtual_dev); else if (disk->disk_type == DISK_FILE) /* If it's not a block device, we assume a file, which should be a reasonable fail-safe */ - return disk_file_xml(disk->source, disk->virtual_dev); - else - return strdup("\n"); -} - -static char *net_to_xml(struct net_device *net) -{ - int ret; - char *xml; - + _xml = disk_file_xml(disk->source, disk->virtual_dev); + else + return false; + + astrcat(xml, _xml); + free(_xml); + + return true; +} + +static bool net_to_xml(char **xml, struct virt_device *dev) +{ + int ret; + char *_xml; char *script = "vif-bridge"; - - ret = asprintf(&xml, + struct net_device *net = &dev->dev.net; + + ret = asprintf(&_xml, "\n" " \n" "