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

Changes in the Virt_KVMRedirectionSAP.c were needed to provide access to the KVMRedirectionSAP for the association

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1228338795 7200 # Node ID 0424a762d6f8b1ba9c36ab18aeafcf20c27350fa # Parent ae687011f6def5df176e5b9b553b93e9f907b7d6 Added association HostedAccessPoint (HostSystem <-> KVMRedirectionSAP) * CHanged function return_console_sap in the Virt_KVMRedirectionSAP.c so it is responsible for returning a CMPIResult type containing the redirection saps * Created new function enum_console_sap in Virt_KVMRedirectionSAP.c to return a list containg the redirection saps. This new function 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 ae687011f6de -r 0424a762d6f8 src/Virt_KVMRedirectionSAP.c --- a/src/Virt_KVMRedirectionSAP.c Wed Dec 03 16:21:29 2008 -0200 +++ b/src/Virt_KVMRedirectionSAP.c Wed Dec 03 19:13:15 2008 -0200 @@ -246,21 +246,41 @@ bool names_only) { CMPIStatus s = {CMPI_RC_OK, NULL}; + struct inst_list list; + + inst_list_init(&list); + + s = enum_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 enum_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); diff -r ae687011f6de -r 0424a762d6f8 src/Virt_KVMRedirectionSAP.h --- a/src/Virt_KVMRedirectionSAP.h Wed Dec 03 16:21:29 2008 -0200 +++ b/src/Virt_KVMRedirectionSAP.h Wed Dec 03 19:13:15 2008 -0200 @@ -28,6 +28,10 @@ const CMPIObjectPath *reference, CMPIInstance **_inst); +CMPIStatus enum_console_sap(const CMPIBroker *broker, + const CMPIObjectPath *ref, + struct inst_list *list); + /* * Local Variables: * mode: C

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1228338856 7200 # Node ID c24663c358a1174cd66d9d2ced35f7aa8977dcc8 # Parent 0424a762d6f8b1ba9c36ab18aeafcf20c27350fa Added association HostedAccessPoint (HostSystem <-> KVMRedirectionSAP) * 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 0424a762d6f8 -r c24663c358a1 Makefile.am --- a/Makefile.am Wed Dec 03 19:13:15 2008 -0200 +++ b/Makefile.am Wed Dec 03 19:14:16 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 \ @@ -120,7 +121,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 0424a762d6f8 -r c24663c358a1 schema/HostedAccessPoint.mof --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.mof Wed Dec 03 19:14:16 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 0424a762d6f8 -r c24663c358a1 schema/HostedAccessPoint.registration --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/schema/HostedAccessPoint.registration Wed Dec 03 19:14:16 2008 -0200 @@ -0,0 +1,8 @@ +# 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 +Xen_HostedAccessPoint root/cimv2 Virt_HostedAccessPoint Virt_HostedAccessPoint association +KVM_HostedAccessPoint root/cimv2 Virt_HostedAccessPoint Virt_HostedAccessPoint association +LXC_HostedAccessPoint root/cimv2 Virt_HostedAccessPoint Virt_HostedAccessPoint association

# HG changeset patch # User Richard Maciel <richardm@br.ibm.com> # Date 1228338856 7200 # Node ID 9983fc910b2e6ec4b43193b54a9a1baf2e7d340e # Parent c24663c358a1174cd66d9d2ced35f7aa8977dcc8 Added association HostedAccessPoint (HostSystem <-> KVMRedirectionSAP) * 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 changes for submission #3: * Association now uses the enum_console_sap function (simple rename) which was renamed from the return_console_sap This patch implements the HostedAccessPoint association using the standard procedure. Signed-off by: Richard Maciel <richardm@br.ibm.com> diff -r c24663c358a1 -r 9983fc910b2e src/Makefile.am --- a/src/Makefile.am Wed Dec 03 19:14:16 2008 -0200 +++ b/src/Makefile.am Wed Dec 03 19:14:16 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 c24663c358a1 -r 9983fc910b2e src/Virt_HostedAccessPoint.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Virt_HostedAccessPoint.c Wed Dec 03 19:14:16 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 = enum_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: + */
participants (1)
-
Richard Maciel