[PATCH 0 of 3] #2 Added HostedAccessPoint association (ComputerSystem <-> KVMRedirectionSAP)

It was necessary to change the return_console_sap function to make it return a inst_list type. Also, the static keyword was removed to make it accessible from the association source file

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227890924 7200 # Node ID 74137e041664ce92f28d41ea12358c4508949cde # Parent f21e9ebf0ad0573bf55be7c16a9d32a07d9ac899 * Created a new function in the Virt_KVMRedirectionSAP.c called enum_console_saps() that is responsible for returning a CMPIResult type containing the redirection saps * Function return_console_sap in Virt_KVMRedirectionSAP.c now only takes three arguments: the reference to the broker, the reference and a return argument that represent the list of redirection saps Signed-off by: Richard Maciel <richardm@br.ibm.com> diff -r f21e9ebf0ad0 -r 74137e041664 src/Virt_KVMRedirectionSAP.c --- a/src/Virt_KVMRedirectionSAP.c Mon Nov 24 13:06:18 2008 -0800 +++ b/src/Virt_KVMRedirectionSAP.c Fri Nov 28 14:48:44 2008 -0200 @@ -241,26 +241,46 @@ return true; } -static CMPIStatus return_console_sap(const CMPIObjectPath *ref, - const CMPIResult *results, - bool names_only) +static CMPIStatus enum_console_saps(const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct inst_list list; + + inst_list_init(&list); + + s = return_console_sap(_BROKER, ref, &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; +} + +CMPIStatus return_console_sap(const CMPIBroker *broker, + const CMPIObjectPath *ref, + struct inst_list *list) { CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn; virDomainPtr *domain_list; struct domain *dominfo = NULL; - struct inst_list list; struct vnc_ports port_list; int count; int lport; int ret; int i; - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); + conn = connect_by_classname(broker, CLASSNAME(ref), &s); if (conn == NULL) return s; - - inst_list_init(&list); port_list.list = NULL; port_list.max = 0; @@ -268,7 +288,7 @@ count = get_domain_list(conn, &domain_list); if (count < 0) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Failed to enumerate domains"); goto out; @@ -277,7 +297,7 @@ port_list.list = malloc(count * sizeof(struct vnc_port *)); if (port_list.list == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate guest port list"); goto out; @@ -286,7 +306,7 @@ for (i = 0; i < count; i++) { port_list.list[i] = malloc(sizeof(struct vnc_port)); if (port_list.list[i] == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate guest port list"); goto out; @@ -305,7 +325,7 @@ "%d", &lport); if (ret != 1) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to guest's console port"); goto out; @@ -313,7 +333,7 @@ port_list.list[port_list.cur]->name = strdup(dominfo->name); if (port_list.list[port_list.cur]->name == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, "Unable to allocate string"); goto out; @@ -330,18 +350,12 @@ port_list.max = port_list.cur; port_list.cur = 0; - s = get_vnc_sessions(ref, conn, port_list, &list); + s = get_vnc_sessions(ref, conn, port_list, 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: free(domain_list); - inst_list_free(&list); for (i = 0; i < count; i++) { free(port_list.list[i]->name); @@ -478,7 +492,7 @@ const CMPIResult *results, const CMPIObjectPath *reference) { - return return_console_sap(reference, results, true); + return enum_console_saps(reference, results, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -488,7 +502,7 @@ const char **properties) { - return return_console_sap(reference, results, false); + return enum_console_saps(reference, results, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, diff -r f21e9ebf0ad0 -r 74137e041664 src/Virt_KVMRedirectionSAP.h --- a/src/Virt_KVMRedirectionSAP.h Mon Nov 24 13:06:18 2008 -0800 +++ b/src/Virt_KVMRedirectionSAP.h Fri Nov 28 14:48:44 2008 -0200 @@ -28,6 +28,10 @@ const CMPIObjectPath *reference, CMPIInstance **_inst); +CMPIStatus return_console_sap(const CMPIBroker *broker, + const CMPIObjectPath *ref, + struct inst_list *list); + /* * Local Variables: * mode: C

RM> -static CMPIStatus return_console_sap(const CMPIObjectPath *ref, RM> - const CMPIResult *results, RM> - bool names_only) RM> +static CMPIStatus enum_console_saps(const CMPIObjectPath *ref, RM> + const CMPIResult *results, RM> + bool names_only) RM> +{ RM> + CMPIStatus s = {CMPI_RC_OK, NULL}; RM> + struct inst_list list; RM> + RM> + inst_list_init(&list); RM> + RM> + s = return_console_sap(_BROKER, ref, &list); RM> + if (s.rc != CMPI_RC_OK) RM> + goto out; RM> + RM> + if (names_only) RM> + cu_return_instance_names(results, &list); RM> + else RM> + cu_return_instances(results, &list); RM> + RM> + out: RM> + inst_list_free(&list); RM> + return s; RM> +} I didn't catch this before, but your terminology is a bit reversed in this patch. In all of our other instance providers that behave like this, the enum function is the one that populates an inst_list. The return_foo() function calls the enum function and does the actual return action to the results object. Also, the return function should be below the enum function in the file. I think it's worth getting it straight before we put this in, for the sake of consistency. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227890946 7200 # Node ID b00134f8377db3a83498d4829358df8a8ef16d6a # Parent 74137e041664ce92f28d41ea12358c4508949cde * Added schema/HostedAccessPoint.mof (and .registration) to create and register the new associations * Changed Makefile.am to regiser HostedAccessPoint association Signed-off by: Richard Maciel <richardm@br.ibm.com> diff -r 74137e041664 -r b00134f8377d Makefile.am --- a/Makefile.am Fri Nov 28 14:48:44 2008 -0200 +++ b/Makefile.am Fri Nov 28 14:49:06 2008 -0200 @@ -51,7 +51,8 @@ schema/DisplayController.mof \ schema/PointingDevice.mof \ schema/GraphicsPool.mof \ - schema/InputPool.mof + schema/InputPool.mof \ + schema/HostedAccessPoint.mof INTEROP_MOFS = \ schema/ComputerSystem.mof \ @@ -117,7 +118,8 @@ schema/DisplayController.registration \ schema/PointingDevice.registration \ schema/GraphicsPool.registration \ - schema/InputPool.registration + schema/InputPool.registration \ + schema/HostedAccessPoint.registration INTEROP_REGS = \ schema/RegisteredProfile.registration \ diff -r 74137e041664 -r b00134f8377d schema/HostedAccessPoint.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.mof Fri Nov 28 14:49:06 2008 -0200 @@ -0,0 +1,22 @@ +// Copyright IBM Corp. 2007 + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class Xen_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class KVM_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; + +[Association, + Provider("cmpi::Virt_HostedAccessPoint") +] +class LXC_HostedAccessPoint : CIM_HostedAccessPoint +{ +}; diff -r 74137e041664 -r b00134f8377d schema/HostedAccessPoint.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.registration Fri Nov 28 14:49:06 2008 -0200 @@ -0,0 +1,5 @@ +# Copyright IBM Corp. 2007 +# Classname Namespace ProviderName ProviderModule ProviderTypes +Xen_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association +KVM_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association +LXC_HostedAccessPoint root/virt Virt_HostedAccessPoint Virt_HostedAccessPoint association

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227890990 7200 # Node ID 1970936f76cda86986275f60d2b8ad7d880247aa # Parent b00134f8377db3a83498d4829358df8a8ef16d6a * Created Virt_HostedAccessPoint.c file * Changed src/Makefile.am file, so the libvirt build creates the libHostedAccessPoint.la library changes for submission #2: * Added support for SBLIM host references This patch implements the HostedAccessPoint association using the standard procedure. Signed-off by: Richard Maciel <richardm@br.ibm.com> diff -r b00134f8377d -r 1970936f76cd src/Makefile.am --- a/src/Makefile.am Fri Nov 28 14:49:06 2008 -0200 +++ b/src/Makefile.am Fri Nov 28 14:49:50 2008 -0200 @@ -72,7 +72,8 @@ libVirt_HostedService.la \ libVirt_ElementSettingData.la \ libVirt_ConcreteComponent.la \ - libVirt_ServiceAffectsElement.la + libVirt_ServiceAffectsElement.la \ + libVirt_HostedAccessPoint.la libVirt_ComputerSystem_la_SOURCES = Virt_ComputerSystem.c libVirt_ComputerSystem_la_DEPENDENCIES = libVirt_VirtualSystemSnapshotService.la @@ -216,3 +217,7 @@ libVirt_KVMRedirectionSAP_la_SOURCES = Virt_KVMRedirectionSAP.c +libVirt_HostedAccessPoint_la_DEPENDENCIES = libVirt_HostSystem.la libVirt_KVMRedirectionSAP.la +libVirt_HostedAccessPoint_la_SOURCES = Virt_HostedAccessPoint.c +libVirt_HostedAccessPoint_la_LIBADD = -lVirt_HostSystem -lVirt_KVMRedirectionSAP + diff -r b00134f8377d -r 1970936f76cd src/Virt_HostedAccessPoint.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_HostedAccessPoint.c Fri Nov 28 14:49:50 2008 -0200 @@ -0,0 +1,161 @@ +/* + * Copyright IBM Corp. 2008 + * + * Authors: + * Richard Maciel <richardm@br.ibm.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include <string.h> +#include <stdlib.h> +#include <stdio.h> +#include <stdbool.h> + +#include "cmpidt.h" +#include "cmpift.h" +#include "cmpimacs.h" + +#include <libcmpiutil/libcmpiutil.h> +#include <libcmpiutil/std_association.h> +#include "misc_util.h" + +#include "Virt_HostSystem.h" +#include "Virt_KVMRedirectionSAP.h" + +static const CMPIBroker *_BROKER; + +static CMPIStatus rsap_to_host(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + + if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = get_console_sap_by_ref(_BROKER, ref, &instance); + if (s.rc != CMPI_RC_OK) + goto out; + + s = get_host(_BROKER, info->context, ref, &instance, false); + if (s.rc == CMPI_RC_OK) + inst_list_add(list, instance); + + out: + return s; +} + + +static CMPIStatus host_to_rsap(const CMPIObjectPath *ref, + struct std_assoc_info *info, + struct inst_list *list) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *instance = NULL; + CMPIObjectPath *vref = NULL; + + if (!STARTS_WITH(CLASSNAME(ref), "Linux_") && + !match_hypervisor_prefix(ref, info)) + goto out; + + s = get_host(_BROKER, info->context, ref, &instance, true); + if (s.rc != CMPI_RC_OK) + goto out; + + vref = convert_sblim_hostsystem(_BROKER, ref, info); + if (vref == NULL) + goto out; + + s = return_console_sap(_BROKER, vref, list); + + if (s.rc != CMPI_RC_OK) + goto out; + + out: + return s; +} + +LIBVIRT_CIM_DEFAULT_MAKEREF() + +static char* antecedent[] = { + "Xen_HostSystem", + "KVM_HostSystem", + "LXC_HostSystem", + "Linux_ComputerSystem", + NULL +}; + +static char* dependent[] = { + "Xen_KVMRedirectionSAP", + "KVM_KVMRedirectionSAP", + "LXC_KVMRedirectionSAP", + NULL +}; + +static char* assoc_classname[] = { + "Xen_HostedAccessPoint", + "KVM_HostedAccessPoint", + "LXC_HostedAccessPoint", + NULL +}; + +static struct std_assoc _host_to_rsap = { + .source_class = (char **)&antecedent, + .source_prop = "Antecedent", + + .target_class = (char **)&dependent, + .target_prop = "Dependent", + + .assoc_class = (char **)&assoc_classname, + + .handler = host_to_rsap, + .make_ref = make_ref +}; + +static struct std_assoc _rsap_to_host = { + .source_class = (char **)&dependent, + .source_prop = "Dependent", + + .target_class = (char **)&antecedent, + .target_prop = "Antecedent", + + .assoc_class = (char **)&assoc_classname, + + .handler = rsap_to_host, + .make_ref = make_ref +}; + +static struct std_assoc *handlers[] = { + &_host_to_rsap, + &_rsap_to_host, + NULL +}; + +STDA_AssocMIStub(, + Virt_HostedAccessPoint, + _BROKER, + libvirt_cim_init(), + handlers); + +/* + * Local Variables: + * mode: C + * c-set-style: "K&R" + * tab-width: 8 + * c-basic-offset: 8 + * indent-tabs-mode: nil + * End: + */

Richard Maciel wrote:
# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1227890990 7200 # Node ID 1970936f76cda86986275f60d2b8ad7d880247aa # Parent b00134f8377db3a83498d4829358df8a8ef16d6a * Created Virt_HostedAccessPoint.c file * Changed src/Makefile.am file, so the libvirt build creates the libHostedAccessPoint.la library
changes for submission #2: * Added support for SBLIM host references
If you pass in a SBLIM ref, you get the following error: wbemcli ain -ac KVM_HostedAccessPoint 'http://localhost/root/cimv2:Linux_ComputerSystem.CreationClassName="Linux_ComputerSystem",Name="elm3b41"' * * wbemcli: Cim: (4) CIM_ERR_INVALID_PARAMETER: KVM_HostedAccessPoint * You'll need to make sure the proper classes are registered in the cimv2 namespace. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Dan Smith
-
Kaitlin Rupert
-
Richard Maciel