
# HG changeset patch # User Eduardo Lima (Etrunko) <eblima@br.ibm.com> # Date 1308270993 14400 # Node ID 3a299dba1101ed6fc4c13fb90bdad7f24ed0d2ea # Parent a2f523cd39c29977ed07247a38316d44f5123874 Add read-only support. This patch enables a consumer of libvirt-cim to put it in read-only mode by adding the key-value pair 'readonly=true' to libvirt-cim.conf. Also clean-up some extra whitespace in touched files. Changes from #1: - Fix build error on RHEL 6 Changes from #2: - Small typo in libvirt-cim.conf Signed-off-by: Chip Vincent <cvincent@us.ibm.com> Signed-off-by: Eduardo Lima (Etrunko) <eblima@br.ibm.com> diff --git a/Makefile.am b/Makefile.am --- a/Makefile.am +++ b/Makefile.am @@ -172,6 +172,9 @@ pkgdata_SCRIPTS = provider-register.sh +libvirtcim_confdir = @sysconfdir@ +dist_libvirtcim_conf_DATA = @PACKAGE@.conf + EXTRA_DIST = schema $(MOFS) $(REGS) $(INTEROP_MOFS) $(INTEROP_REGS) \ $(pkgdata_SCRIPTS) libvirt-cim.spec.in libvirt-cim.spec \ doc/CodingStyle doc/SubmittingPatches \ diff --git a/acinclude.m4 b/acinclude.m4 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -270,6 +270,15 @@ LDFLAGS="$LDFLAGS $LIBUUID_LIBS" ]) +AC_DEFUN([CHECK_LIBCONFIG], + [ + PKG_CHECK_MODULES([LIBCONFIG], [libconfig]) + AC_SUBST([LIBCONFIG_CFLAGS]) + AC_SUBST([LIBCONFIG_LIBS]) + CPPFLAGS="$CPPFLAGS $LIBCONFIG_CFLAGS" + LDFLAGS="$LDFLAGS $LIBCONFIG_LIBS" + ]) + # A convenience macro that spits out a fail message for a particular test # # AC_CHECK_FAIL($LIBNAME,$PACKAGE_SUGGEST,$URL,$EXTRA) diff --git a/configure.ac b/configure.ac --- a/configure.ac +++ b/configure.ac @@ -166,6 +166,7 @@ CHECK_LIBXML2 CHECK_LIBCU CHECK_LIBUUID +CHECK_LIBCONFIG CFLAGS_STRICT="-Werror" diff --git a/libvirt-cim.conf b/libvirt-cim.conf new file mode 100644 --- /dev/null +++ b/libvirt-cim.conf @@ -0,0 +1,13 @@ +# +# libvirt-cim config file +# +# This config file is based on the libconfig format. For more information, +# please check http://www.hyperrealm.com/libconfig/ +# + +# readonly (boolean) +# Defines if connection to libvirt is read-only or not +# Possible values: {true,false} +# Default value: false +# +# readonly = false; diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -26,6 +26,7 @@ BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +BuildRequires: libconfig-devel BuildConflicts: sblim-cmpi-devel %description @@ -135,6 +136,7 @@ %{_datadir}/libvirt-cim/*.registration %{_datadir}/libvirt-cim/cim_schema_*-MOFs.zip %{_sysconfdir}/ld.so.conf.d/libvirt-cim.conf +%{_sysconfdir}/libvirt-cim.conf %changelog * Wed Oct 28 2009 Richard Maciel <rmaciel@linux.vnet.ibm.com> - 0.1-1 diff --git a/libxkutil/Makefile.am b/libxkutil/Makefile.am --- a/libxkutil/Makefile.am +++ b/libxkutil/Makefile.am @@ -1,7 +1,8 @@ # Copyright IBM Corp. 2007 SUBDIRS = tests -CFLAGS += $(CFLAGS_STRICT) +AM_CFLAGS = $(CFLAGS_STRICT) \ + -DLIBVIRTCIM_CONF=\"@sysconfdir@/@PACKAGE@.conf\" noinst_HEADERS = cs_util.h misc_util.h device_parsing.h xmlgen.h infostore.h \ pool_parsing.h acl_parsing.h diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -35,11 +35,12 @@ #include <libcmpiutil/libcmpiutil.h> #include <libcmpiutil/std_association.h> +#include <libconfig.h> #include "misc_util.h" #include "cs_util.h" -#include <config.h> +#include "config.h" #define URI_ENV "HYPURI" @@ -55,6 +56,37 @@ return NULL; } +static int is_read_only(void) +{ + config_t conf; + int ret, readonly = 0; + const char *readonly_str = "readonly"; + + config_init(&conf); + + ret = config_read_file(&conf, LIBVIRTCIM_CONF); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error reading config file at line %d: '%s'\n", + conf.error_line, conf.error_text); + goto out; + } + + ret = config_lookup_bool(&conf, readonly_str, &readonly); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Error: '%s' not found in config file\n", + readonly_str); + goto out; + } + + CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, + LIBVIRTCIM_CONF, readonly); +out: + config_destroy(&conf); + + /* Default value is 0 (false) */ + return readonly; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) @@ -66,7 +98,7 @@ uri = cn_to_uri(classname); if (!uri) { - cu_statusf(broker, s, + cu_statusf(broker, s, CMPI_RC_ERR_FAILED, "Unable to generate URI from classname"); return NULL; @@ -74,7 +106,11 @@ CU_DEBUG("Connecting to libvirt with uri `%s'", uri); - conn = virConnectOpen(uri); + if (is_read_only()) + conn = virConnectOpenReadOnly(uri); + else + conn = virConnectOpen(uri); + if (!conn) { CU_DEBUG("Unable to connect to `%s'", uri); return NULL; @@ -258,7 +294,7 @@ inst = CMNewInstance(broker, op, &s); if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - + CMSetProperty(inst, "CreationClassName", (CMPIValue *)new_cn, CMPI_chars); @@ -310,7 +346,7 @@ if (STREQC(pfx, "CIM")) { cu_statusf(broker, status, CMPI_RC_ERR_FAILED, - "Please exactly specify the class (check CIMOM behavior!): %s", + "Please exactly specify the class (check CIMOM behavior!): %s", CLASSNAME(reference)); rc = false; } @@ -347,7 +383,7 @@ free(pfx); } - + free(ref_pfx); return rc; } @@ -367,13 +403,13 @@ CLASSNAME(source_ref), assoc_classname, NAMESPACE(source_ref)); - + if (ref_inst != NULL) { CMPIObjectPath *target_ref; - + target_ref = CMGetObjectPath(target_inst, NULL); - set_reference(assoc, ref_inst, + set_reference(assoc, ref_inst, source_ref, target_ref); } diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c --- a/src/Virt_AllocationCapabilities.c +++ b/src/Virt_AllocationCapabilities.c @@ -47,6 +47,7 @@ CLASSNAME(ref), "AllocationCapabilities", NAMESPACE(ref)); + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (*alloc_cap == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -70,6 +71,7 @@ goto out; } out: + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -85,6 +87,7 @@ const char *inst_id; int i; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&device_pool_list); if (!provider_is_responsible(broker, ref, &s)) @@ -132,6 +135,7 @@ out: inst_list_free(&device_pool_list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -144,14 +148,20 @@ CMPIInstance *pool; CMPIStatus s; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); s = get_pool_by_name(broker, ref, poolid, &pool); - if ((pool == NULL) || (s.rc != CMPI_RC_OK)) + if ((pool == NULL) || (s.rc != CMPI_RC_OK)) { + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; + } s = ac_from_pool(broker, ref, pool, inst); - if (s.rc != CMPI_RC_OK) + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("%s(%d): return 2 ", __FUNCTION__, __LINE__); return s; + } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return cu_validate_ref(broker, ref, *inst); } @@ -165,6 +175,7 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; struct inst_list list; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); inst_list_init(&list); s = enum_alloc_cap_instances(broker, @@ -183,6 +194,7 @@ out: inst_list_free(&list); + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return s; } @@ -195,13 +207,16 @@ CMPIStatus s = {CMPI_RC_OK, NULL}; const char* id; + CU_DEBUG("%s(%d): Begin", __FUNCTION__, __LINE__); if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "No InstanceID specified"); + CU_DEBUG("%s(%d): return 1 ", __FUNCTION__, __LINE__); return s; } + CU_DEBUG("%s(%d): End", __FUNCTION__, __LINE__); return return_alloc_cap_instances(_BROKER, reference, results,