From ydu at redhat.com Tue Oct 16 07:51:47 2012 From: ydu at redhat.com (Yanbing Du) Date: Tue, 16 Oct 2012 03:51:47 -0400 (EDT) Subject: [Libvirt-cim] Test result for libvirt-cim-0.6.1-4.el6 with cimtest suite In-Reply-To: <1012456217.1274320.1314254170249.JavaMail.root@zmail02.collab.prod.int.phx2.redhat.com> Message-ID: <1254183619.11455248.1350373907318.JavaMail.root@redhat.com> Hi Jiri, We just tested the libvirt-cim-0.6.1-4.el6 with cimtest suite, and pasted the summary as following, please check the full report in the attachment. BTW, the result is same with libvirt-cim-0.6.1-3.el6 we last tested. ================================================= Test Run Summary (Oct 16 2012): KVM on Red Hat Enterprise Linux Server release 6.3 (Santiago) with Pegasus ================================================= Distro: Red Hat Enterprise Linux Server release 6.3 (Santiago) Kernel: 2.6.32-323.el6.x86_64 libvirt: 0.10.2 Hypervisor: QEMU 0.12.1 CIMOM: Pegasus 2.11.0 Libvirt-cim revision: 1192 Libvirt-cim changeset: 0c468a8 Cimtest revision: Cimtest changeset: 93f0e6e Total test execution: Unknown ================================================= FAIL : 30 XFAIL : 2 SKIP : 14 PASS : 146 ----------------- Total : 192 ================================================= FAIL Test Summary: ElementAllocatedFromPool - 01_forward.py: FAIL ElementAllocatedFromPool - 02_reverse.py: FAIL ElementConforms - 01_forward.py: FAIL ElementConforms - 04_ectp_rev_errs.py: FAIL HostedResourcePool - 01_forward.py: FAIL HostSystem - 04_hs_to_EAPF.py: FAIL Profile - 02_profile_to_elec.py: FAIL Profile - 04_verify_libvirt_cim_slp_profiles.py: FAIL RASDIndications - 01_guest_states_rasd_ind.py: FAIL RASDIndications - 02_guest_add_mod_rem_rasd_ind.py: FAIL ResourceAllocationFromPool - 01_forward.py: FAIL ResourceAllocationFromPool - 02_reverse.py: FAIL SettingsDefineCapabilities - 01_forward.py: FAIL VirtualSystemManagementService - 06_addresource.py: FAIL VirtualSystemManagementService - 08_modifyresource.py: FAIL VirtualSystemManagementService - 09_procrasd_persist.py: FAIL VirtualSystemManagementService - 11_define_memrasdunits.py: FAIL VirtualSystemManagementService - 12_referenced_config.py: FAIL VirtualSystemManagementService - 13_refconfig_additional_devs.py: FAIL VirtualSystemManagementService - 14_define_sys_disk.py: FAIL VirtualSystemManagementService - 18_define_sys_bridge.py: FAIL VirtualSystemManagementService - 19_definenetwork_ers.py: FAIL VirtualSystemManagementService - 22_addmulti_brg_interface.py: FAIL VirtualSystemManagementService - 25_definesystem_floppy.py: FAIL VirtualSystemManagementService - 26_definesystem_nic_dev.py: FAIL VirtualSystemManagementService - 27_definesystem_macvtap_dev.py: FAIL VirtualSystemManagementService - 28_definesystem_with_vsi_profile.py: FAIL VirtualSystemManagementService - 29_cdrom_media_change.py: FAIL VirtualSystemSnapshotService - 03_create_snapshot.py: FAIL VSSD - 06_duplicate_uuid.py: FAIL ================================================= XFAIL Test Summary: SwitchService - 01_enum.py: XFAIL VirtualSystemManagementService - 30_dynamic_disk_mod.py: XFAIL ================================================= SKIP Test Summary: ComputerSystemMigrationJobIndication - 01_csmig_ind_for_offline_mig.py: SKIP ResourcePoolConfigurationService - 08_CreateDiskResourcePool.py: SKIP ResourcePoolConfigurationService - 10_create_storagevolume.py: SKIP ResourcePoolConfigurationService - 11_create_dir_storagevolume_errs.py: SKIP ResourcePoolConfigurationService - 13_delete_storagevolume.py: SKIP ResourcePoolConfigurationService - 14_delete_storagevolume_errs.py: SKIP ResourcePoolConfigurationService - 15_DiskPoolAutostart.py: SKIP VirtualSystemMigrationService - 01_migratable_host.py: SKIP VirtualSystemMigrationService - 02_host_migrate_type.py: SKIP VirtualSystemMigrationService - 05_migratable_host_errs.py: SKIP VirtualSystemMigrationService - 06_remote_live_migration.py: SKIP VirtualSystemMigrationService - 07_remote_offline_migration.py: SKIP VirtualSystemMigrationService - 08_remote_restart_resume_migration.py: SKIP VSSD - 02_bootldr.py: SKIP ================================================= Thanks & Best Regards Yanbing Du -------------- next part -------------- An embedded and charset-unspecified text was scrubbed... Name: run_report.txt URL: From xiawenc at linux.vnet.ibm.com Mon Oct 22 07:38:18 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 22 Oct 2012 15:38:18 +0800 Subject: [Libvirt-cim] [PATCH 2/4] CSI, add lock to protect shared data In-Reply-To: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1350891500-21520-2-git-send-email-xiawenc@linux.vnet.ibm.com> This patch added lock on shared data without which may trigger incorrect data operation. Global lock is used so speed may be slowed down, it can be improved in the future. Signed-off-by: Wenchao Xia --- src/Virt_ComputerSystemIndication.c | 39 ++++++++++++++++++++++++++++++++-- 1 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index b1b9fa0..3159ca0 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -174,9 +174,11 @@ static void csi_free_thread_data(void *data) if (data == NULL) return; + pthread_mutex_lock(&lifecycle_mutex); list_free(thread->dom_list); thread->dom_list = NULL; stdi_free_ind_args(&thread->args); + pthread_mutex_unlock(&lifecycle_mutex); } void set_source_inst_props(const CMPIBroker *broker, @@ -490,6 +492,8 @@ static int update_domain_list(virConnectPtr conn, csi_thread_data_t *thread) return s.rc; } +/* following function will protect global data with lifecycle_mutex. + TODO: improve it with seperate lock later. */ static void csi_domain_event_cb(virConnectPtr conn, virDomainPtr dom, int event, @@ -502,10 +506,13 @@ static void csi_domain_event_cb(virConnectPtr conn, char *prefix = class_prefix_name(thread->args->classname); CMPIStatus s = {CMPI_RC_OK, NULL}; + pthread_mutex_lock(&lifecycle_mutex); if (lifecycle_enabled == false || thread->active_filters <= 0) { CU_DEBUG("%s indications deactivated, return", prefix); + pthread_mutex_unlock(&lifecycle_mutex); return; } + pthread_mutex_unlock(&lifecycle_mutex); CU_DEBUG("Event: Domain %s(%d) event: %d detail: %d\n", virDomainGetName(dom), virDomainGetID(dom), event, detail); @@ -537,7 +544,9 @@ static void csi_domain_event_cb(virConnectPtr conn, if (cs_event != CS_CREATED) { char uuid[VIR_UUID_STRING_BUFLEN] = {0}; virDomainGetUUIDString(dom, &uuid[0]); + pthread_mutex_lock(&lifecycle_mutex); dom_xml = list_find(thread->dom_list, uuid); + pthread_mutex_unlock(&lifecycle_mutex); } if (dom_xml == NULL) { @@ -545,12 +554,16 @@ static void csi_domain_event_cb(virConnectPtr conn, goto end; } + pthread_mutex_lock(&lifecycle_mutex); async_ind(thread->args, cs_event, dom_xml, prefix); + pthread_mutex_unlock(&lifecycle_mutex); /* Update the domain list accordingly */ if (event == VIR_DOMAIN_EVENT_DEFINED) { if (detail == VIR_DOMAIN_EVENT_DEFINED_ADDED) { + pthread_mutex_lock(&lifecycle_mutex); csi_thread_dom_list_append(thread, dom_xml); + pthread_mutex_unlock(&lifecycle_mutex); } else if (detail == VIR_DOMAIN_EVENT_DEFINED_UPDATED) { free(dom_xml->name); free(dom_xml->xml); @@ -558,7 +571,9 @@ static void csi_domain_event_cb(virConnectPtr conn, } } else if (event == VIR_DOMAIN_EVENT_DEFINED && detail == VIR_DOMAIN_EVENT_UNDEFINED_REMOVED) { + pthread_mutex_lock(&lifecycle_mutex); list_remove(thread->dom_list, dom_xml); + pthread_mutex_unlock(&lifecycle_mutex); } end: @@ -579,10 +594,12 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) if (prefix == NULL) goto init_out; + pthread_mutex_lock(&lifecycle_mutex); conn = connect_by_classname(_BROKER, args->classname, &s); if (conn == NULL) { CU_DEBUG("Unable to start lifecycle thread: " "Failed to connect (cn: %s)", args->classname); + pthread_mutex_unlock(&lifecycle_mutex); goto conn_out; } @@ -594,33 +611,47 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) if (cb_id == -1) { CU_DEBUG("Failed to register domain event watch for '%s'", - args->classname) + args->classname); + pthread_mutex_unlock(&lifecycle_mutex); goto cb_out; } CBAttachThread(_BROKER, args->context); /* Get currently defined domains */ - if (update_domain_list(conn, thread) != CMPI_RC_OK) + if (update_domain_list(conn, thread) != CMPI_RC_OK) { + pthread_mutex_unlock(&lifecycle_mutex); goto end; + } + pthread_mutex_unlock(&lifecycle_mutex); CU_DEBUG("Entering CSI event loop (%s)", prefix); - while (thread->active_filters > 0) { + while (1) { + pthread_mutex_lock(&lifecycle_mutex); + if (thread->active_filters <= 0) { + pthread_mutex_unlock(&lifecycle_mutex); + break; + } + pthread_mutex_unlock(&lifecycle_mutex); if (virEventRunDefaultImpl() < 0) { virErrorPtr err = virGetLastError(); CU_DEBUG("Failed to run event loop: %s\n", err && err->message ? err->message : "Unknown error"); } + usleep(1); } CU_DEBUG("Exiting CSI event loop (%s)", prefix); + pthread_mutex_lock(&lifecycle_mutex); CBDetachThread(_BROKER, args->context); + pthread_mutex_unlock(&lifecycle_mutex); end: virConnectDomainEventDeregisterAny(conn, cb_id); cb_out: + pthread_mutex_lock(&lifecycle_mutex); thread->id = 0; thread->active_filters = 0; @@ -628,6 +659,8 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) if (thread->args != NULL) stdi_free_ind_args(&thread->args); + pthread_mutex_unlock(&lifecycle_mutex); + conn_out: virConnectClose(conn); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Oct 22 07:38:19 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 22 Oct 2012 15:38:19 +0800 Subject: [Libvirt-cim] [PATCH 3/4] DevicePool, fix debug print crash In-Reply-To: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1350891500-21520-3-git-send-email-xiawenc@linux.vnet.ibm.com> Dangerous bug, may trigger strange error, suggest apply it before investigate any strange bug shown. Signed-off-by: Wenchao Xia --- src/Virt_DevicePool.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 202e509..79dc108 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -710,7 +710,7 @@ static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) dom = virDomainLookupByID(conn, domain_ids[i]); if (dom == NULL) { - CU_DEBUG("Cannot connect to domain %n: excluding", + CU_DEBUG("Cannot connect to domain %d: excluding", domain_ids[i]); continue; } -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Oct 22 07:38:20 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 22 Oct 2012 15:38:20 +0800 Subject: [Libvirt-cim] [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1350891500-21520-4-git-send-email-xiawenc@linux.vnet.ibm.com> Oringinal implement have risk, this patch should fix it Signed-off-by: Wenchao Xia --- src/Virt_DevicePool.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 79dc108..0cb9124 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) return ret; } +/* This function returns the real number of pools, no negative value should be + returned, if error happens it returns zero. */ static int get_diskpool_config(virConnectPtr conn, struct tmp_disk_pool **_pools) { - int count = 0; + int count = 0, realcount = 0; int i; char ** names = NULL; struct tmp_disk_pool *pools = NULL; + int have_err = 0; count = virConnectNumOfStoragePools(conn); - if (count <= 0) + if (count <= 0) { + have_err = 1; goto out; + } names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); count = 0; + have_err = 1; goto out; } - if (virConnectListStoragePools(conn, names, count) == -1) { + realcount = virConnectListStoragePools(conn, names, count); + if (realcount == -1) { CU_DEBUG("Failed to get storage pools"); - count = 0; + realcount = 0; + have_err = 1; + goto out; + } + if (realcount == 0) { + CU_DEBUG("zero pools got, but prelist is %d.", count); goto out; } - pools = calloc(count, sizeof(*pools)); + pools = calloc(realcount, sizeof(*pools)); if (pools == NULL) { - CU_DEBUG("Failed to alloc space for %i pool structs", count); + CU_DEBUG("Failed to alloc space for %i pool structs", realcount); + realcount = 0; + have_err = 1; goto out; } - for (i = 0; i < count; i++) { + i = 0; + while (i < realcount) { pools[i].tag = strdup(names[i]); pools[i].primordial = false; + i++; } out: - for (i = 0; i < count; i++) - free(names[i]); - free(names); + if (count > 0) { + i = 0; + while (i < count) { + free(names[i]); + i++; + } + free(names); + } - get_disk_parent(&pools, &count); + if (have_err == 0) { + get_disk_parent(&pools, &realcount); + } *_pools = pools; - return count; + return realcount; } static bool diskpool_set_capacity(virConnectPtr conn, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Oct 22 07:38:17 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 22 Oct 2012 15:38:17 +0800 Subject: [Libvirt-cim] [PATCH 1/4] CSI, fix debug print crash Message-ID: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- src/Virt_ComputerSystemIndication.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 2d0a94e..b1b9fa0 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -503,7 +503,7 @@ static void csi_domain_event_cb(virConnectPtr conn, CMPIStatus s = {CMPI_RC_OK, NULL}; if (lifecycle_enabled == false || thread->active_filters <= 0) { - CU_DEBUG("%s indications deactivated, return"); + CU_DEBUG("%s indications deactivated, return", prefix); return; } -- 1.7.1 From snmishra at linux.vnet.ibm.com Mon Oct 22 18:01:27 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Mon, 22 Oct 2012 11:01:27 -0700 Subject: [Libvirt-cim] [PATCH 1/4] CSI, fix debug print crash In-Reply-To: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121022110127.Horde.NwYqbJir309QhYn3ximShIA@imap.linux.ibm.com> +1 -Sharad Mishra Quoting Wenchao Xia : > Signed-off-by: Wenchao Xia > --- > src/Virt_ComputerSystemIndication.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/Virt_ComputerSystemIndication.c > b/src/Virt_ComputerSystemIndication.c > index 2d0a94e..b1b9fa0 100644 > --- a/src/Virt_ComputerSystemIndication.c > +++ b/src/Virt_ComputerSystemIndication.c > @@ -503,7 +503,7 @@ static void csi_domain_event_cb(virConnectPtr conn, > CMPIStatus s = {CMPI_RC_OK, NULL}; > > if (lifecycle_enabled == false || thread->active_filters <= 0) { > - CU_DEBUG("%s indications deactivated, return"); > + CU_DEBUG("%s indications deactivated, return", prefix); > return; > } > > -- > 1.7.1 > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim From snmishra at linux.vnet.ibm.com Mon Oct 22 18:20:20 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Mon, 22 Oct 2012 11:20:20 -0700 Subject: [Libvirt-cim] [PATCH 3/4] DevicePool, fix debug print crash In-Reply-To: <1350891500-21520-3-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1350891500-21520-3-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121022112020.Horde.OYK1-pir309QhY5k6NWShEA@imap.linux.ibm.com> +1 -Sharad Mishra Quoting Wenchao Xia : > Dangerous bug, may trigger strange error, suggest apply it before investigate > any strange bug shown. > > Signed-off-by: Wenchao Xia > --- > src/Virt_DevicePool.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index 202e509..79dc108 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -710,7 +710,7 @@ static bool mempool_set_consumed(CMPIInstance > *inst, virConnectPtr conn) > > dom = virDomainLookupByID(conn, domain_ids[i]); > if (dom == NULL) { > - CU_DEBUG("Cannot connect to domain %n: excluding", > + CU_DEBUG("Cannot connect to domain %d: excluding", > domain_ids[i]); > continue; > } > -- > 1.7.1 > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim From snmishra at linux.vnet.ibm.com Mon Oct 22 18:22:50 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Mon, 22 Oct 2012 11:22:50 -0700 Subject: [Libvirt-cim] [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1350891500-21520-4-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1350891500-21520-4-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121022112250.Horde.Pq70y5ir309QhY76DiaG4XA@imap.linux.ibm.com> -1 This patch makes it impossible for called to know if "0" was returned as a result of a failure or no diskpools were found. I recommend returning "-1" in error and update the patch to make sure that calling functions are handling a return value of -1 properly. -Sharad Mishra Quoting Wenchao Xia : > Oringinal implement have risk, this patch should fix it > > Signed-off-by: Wenchao Xia > --- > src/Virt_DevicePool.c | 47 +++++++++++++++++++++++++++++++++++------------ > 1 files changed, 35 insertions(+), 12 deletions(-) > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index 79dc108..0cb9124 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, > struct virt_pool **pool) > return ret; > } > > +/* This function returns the real number of pools, no negative > value should be > + returned, if error happens it returns zero. */ > static int get_diskpool_config(virConnectPtr conn, > struct tmp_disk_pool **_pools) > { > - int count = 0; > + int count = 0, realcount = 0; > int i; > char ** names = NULL; > struct tmp_disk_pool *pools = NULL; > + int have_err = 0; > > count = virConnectNumOfStoragePools(conn); > - if (count <= 0) > + if (count <= 0) { > + have_err = 1; > goto out; > + } > > names = calloc(count, sizeof(char *)); > if (names == NULL) { > CU_DEBUG("Failed to alloc space for %i pool names", count); > count = 0; > + have_err = 1; > goto out; > } > > - if (virConnectListStoragePools(conn, names, count) == -1) { > + realcount = virConnectListStoragePools(conn, names, count); > + if (realcount == -1) { > CU_DEBUG("Failed to get storage pools"); > - count = 0; > + realcount = 0; > + have_err = 1; > + goto out; > + } > + if (realcount == 0) { > + CU_DEBUG("zero pools got, but prelist is %d.", count); > goto out; > } > > - pools = calloc(count, sizeof(*pools)); > + pools = calloc(realcount, sizeof(*pools)); > if (pools == NULL) { > - CU_DEBUG("Failed to alloc space for %i pool > structs", count); > + CU_DEBUG("Failed to alloc space for %i pool > structs", realcount); > + realcount = 0; > + have_err = 1; > goto out; > } > > - for (i = 0; i < count; i++) { > + i = 0; > + while (i < realcount) { > pools[i].tag = strdup(names[i]); > pools[i].primordial = false; > + i++; > } > > out: > - for (i = 0; i < count; i++) > - free(names[i]); > - free(names); > + if (count > 0) { > + i = 0; > + while (i < count) { > + free(names[i]); > + i++; > + } > + free(names); > + } > > - get_disk_parent(&pools, &count); > + if (have_err == 0) { > + get_disk_parent(&pools, &realcount); > + } > > *_pools = pools; > > - return count; > + return realcount; > } > > static bool diskpool_set_capacity(virConnectPtr conn, > -- > 1.7.1 > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim From eblima at gmail.com Tue Oct 23 16:28:40 2012 From: eblima at gmail.com (Eduardo Lima (Etrunko)) Date: Tue, 23 Oct 2012 14:28:40 -0200 Subject: [Libvirt-cim] [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1350891500-21520-4-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1350891500-21520-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1350891500-21520-4-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: On Mon, Oct 22, 2012 at 5:38 AM, Wenchao Xia wrote: > Oringinal implement have risk, this patch should fix it > > Signed-off-by: Wenchao Xia > --- > src/Virt_DevicePool.c | 47 +++++++++++++++++++++++++++++++++++------------ > 1 files changed, 35 insertions(+), 12 deletions(-) > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index 79dc108..0cb9124 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) > return ret; > } > > +/* This function returns the real number of pools, no negative value should be > + returned, if error happens it returns zero. */ > static int get_diskpool_config(virConnectPtr conn, > struct tmp_disk_pool **_pools) > { > - int count = 0; > + int count = 0, realcount = 0; > int i; > char ** names = NULL; > struct tmp_disk_pool *pools = NULL; > + int have_err = 0; > > count = virConnectNumOfStoragePools(conn); > - if (count <= 0) > + if (count <= 0) { > + have_err = 1; > goto out; > + } > > names = calloc(count, sizeof(char *)); > if (names == NULL) { > CU_DEBUG("Failed to alloc space for %i pool names", count); > count = 0; > + have_err = 1; > goto out; > } > > - if (virConnectListStoragePools(conn, names, count) == -1) { > + realcount = virConnectListStoragePools(conn, names, count); > + if (realcount == -1) { > CU_DEBUG("Failed to get storage pools"); > - count = 0; > + realcount = 0; > + have_err = 1; > + goto out; > + } > + if (realcount == 0) { > + CU_DEBUG("zero pools got, but prelist is %d.", count); > goto out; > } > > - pools = calloc(count, sizeof(*pools)); > + pools = calloc(realcount, sizeof(*pools)); > if (pools == NULL) { > - CU_DEBUG("Failed to alloc space for %i pool structs", count); > + CU_DEBUG("Failed to alloc space for %i pool structs", realcount); > + realcount = 0; > + have_err = 1; > goto out; > } > > - for (i = 0; i < count; i++) { > + i = 0; > + while (i < realcount) { > pools[i].tag = strdup(names[i]); > pools[i].primordial = false; > + i++; > } Any specific reason for changing the for() loop for a while() one?? > > out: > - for (i = 0; i < count; i++) > - free(names[i]); > - free(names); > + if (count > 0) { > + i = 0; > + while (i < count) { > + free(names[i]); > + i++; > + } > + free(names); > + } Same here. Best regards, -- Eduardo de Barros Lima ??? eblima at gmail.com From xiawenc at linux.vnet.ibm.com Wed Oct 24 05:52:11 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Wed, 24 Oct 2012 13:52:11 +0800 Subject: [Libvirt-cim] Fwd: Re: [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <50877FFA.4060802@linux.vnet.ibm.com> References: <50877FFA.4060802@linux.vnet.ibm.com> Message-ID: <5087820B.4020701@linux.vnet.ibm.com> > On Mon, Oct 22, 2012 at 5:38 AM, Wenchao Xia wrote: >> Oringinal implement have risk, this patch should fix it >> >> Signed-off-by: Wenchao Xia >> --- >> src/Virt_DevicePool.c | 47 +++++++++++++++++++++++++++++++++++------------ >> 1 files changed, 35 insertions(+), 12 deletions(-) >> >> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c >> index 79dc108..0cb9124 100644 >> --- a/src/Virt_DevicePool.c >> +++ b/src/Virt_DevicePool.c >> @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) >> return ret; >> } >> >> +/* This function returns the real number of pools, no negative value should be >> + returned, if error happens it returns zero. */ >> static int get_diskpool_config(virConnectPtr conn, >> struct tmp_disk_pool **_pools) >> { >> - int count = 0; >> + int count = 0, realcount = 0; >> int i; >> char ** names = NULL; >> struct tmp_disk_pool *pools = NULL; >> + int have_err = 0; >> >> count = virConnectNumOfStoragePools(conn); >> - if (count <= 0) >> + if (count <= 0) { >> + have_err = 1; >> goto out; >> + } >> >> names = calloc(count, sizeof(char *)); >> if (names == NULL) { >> CU_DEBUG("Failed to alloc space for %i pool names", count); >> count = 0; >> + have_err = 1; >> goto out; >> } >> >> - if (virConnectListStoragePools(conn, names, count) == -1) { >> + realcount = virConnectListStoragePools(conn, names, count); >> + if (realcount == -1) { >> CU_DEBUG("Failed to get storage pools"); >> - count = 0; >> + realcount = 0; >> + have_err = 1; >> + goto out; >> + } >> + if (realcount == 0) { >> + CU_DEBUG("zero pools got, but prelist is %d.", count); >> goto out; >> } >> >> - pools = calloc(count, sizeof(*pools)); >> + pools = calloc(realcount, sizeof(*pools)); >> if (pools == NULL) { >> - CU_DEBUG("Failed to alloc space for %i pool structs", count); >> + CU_DEBUG("Failed to alloc space for %i pool structs", realcount); >> + realcount = 0; >> + have_err = 1; >> goto out; >> } >> >> - for (i = 0; i < count; i++) { >> + i = 0; >> + while (i < realcount) { >> pools[i].tag = strdup(names[i]); >> pools[i].primordial = false; >> + i++; >> } > > Any specific reason for changing the for() loop for a while() one?? > >> >> out: >> - for (i = 0; i < count; i++) >> - free(names[i]); >> - free(names); >> + if (count > 0) { >> + i = 0; >> + while (i < count) { >> + free(names[i]); >> + i++; >> + } >> + free(names); >> + } > > Same here. > > Best regards, > Good to see you again, there is one for() before which may take one execution if count == 0,where it should not. For safe and code style unifying I switch it all to while. I am tring to fix some bugs after libvirt CSI patch applied, which make cimtest report strange error, A bit brute, could u help share some findings for those strange errors? (2 profile test case failing strangely, if CSI test case is executed with CSI patched libvirt-cim). -- Best Regards Wenchao Xia From eblima at gmail.com Wed Oct 24 12:58:16 2012 From: eblima at gmail.com (Eduardo Lima (Etrunko)) Date: Wed, 24 Oct 2012 10:58:16 -0200 Subject: [Libvirt-cim] [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <5087820B.4020701@linux.vnet.ibm.com> References: <50877FFA.4060802@linux.vnet.ibm.com> <5087820B.4020701@linux.vnet.ibm.com> Message-ID: On Wed, Oct 24, 2012 at 3:52 AM, Wenchao Xia wrote: > >> On Mon, Oct 22, 2012 at 5:38 AM, Wenchao Xia >> wrote: >>> >>> Oringinal implement have risk, this patch should fix it >>> >>> Signed-off-by: Wenchao Xia >>> --- >>> src/Virt_DevicePool.c | 47 >>> +++++++++++++++++++++++++++++++++++------------ >>> 1 files changed, 35 insertions(+), 12 deletions(-) >>> >>> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c >>> index 79dc108..0cb9124 100644 >>> --- a/src/Virt_DevicePool.c >>> +++ b/src/Virt_DevicePool.c >>> @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct >>> virt_pool **pool) >>> return ret; >>> } >>> >>> +/* This function returns the real number of pools, no negative value >>> should be >>> + returned, if error happens it returns zero. */ >>> static int get_diskpool_config(virConnectPtr conn, >>> struct tmp_disk_pool **_pools) >>> { >>> - int count = 0; >>> + int count = 0, realcount = 0; >>> int i; >>> char ** names = NULL; >>> struct tmp_disk_pool *pools = NULL; >>> + int have_err = 0; >>> >>> count = virConnectNumOfStoragePools(conn); >>> - if (count <= 0) >>> + if (count <= 0) { >>> + have_err = 1; >>> goto out; >>> + } >>> >>> names = calloc(count, sizeof(char *)); >>> if (names == NULL) { >>> CU_DEBUG("Failed to alloc space for %i pool names", >>> count); >>> count = 0; >>> + have_err = 1; >>> goto out; >>> } >>> >>> - if (virConnectListStoragePools(conn, names, count) == -1) { >>> + realcount = virConnectListStoragePools(conn, names, count); >>> + if (realcount == -1) { >>> CU_DEBUG("Failed to get storage pools"); >>> - count = 0; >>> + realcount = 0; >>> + have_err = 1; >>> + goto out; >>> + } >>> + if (realcount == 0) { >>> + CU_DEBUG("zero pools got, but prelist is %d.", count); >>> goto out; >>> } >>> >>> - pools = calloc(count, sizeof(*pools)); >>> + pools = calloc(realcount, sizeof(*pools)); >>> if (pools == NULL) { >>> - CU_DEBUG("Failed to alloc space for %i pool structs", >>> count); >>> + CU_DEBUG("Failed to alloc space for %i pool structs", >>> realcount); >>> + realcount = 0; >>> + have_err = 1; >>> goto out; >>> } >>> >>> - for (i = 0; i < count; i++) { >>> + i = 0; >>> + while (i < realcount) { >>> pools[i].tag = strdup(names[i]); >>> pools[i].primordial = false; >>> + i++; >>> } >> >> >> Any specific reason for changing the for() loop for a while() one?? >> >>> >>> out: >>> - for (i = 0; i < count; i++) >>> - free(names[i]); >>> - free(names); >>> + if (count > 0) { >>> + i = 0; >>> + while (i < count) { >>> + free(names[i]); >>> + i++; >>> + } >>> + free(names); >>> + } >> >> >> Same here. >> >> Best regards, >> > > Good to see you again, there is one for() before which may take > one execution if count == 0,where it should not. For safe and code > style unifying I switch it all to while. No, if count is 0 the for will never be executed, this is basic C. There is no need to test count before starting the loop. See test attached. As for coding style, when you know the number of iterations, the for loop it is much more readable and easier to maintain. > I am tring to fix some bugs after libvirt CSI patch applied, which > make cimtest report strange error, A bit brute, could u help share some > findings for those strange errors? (2 profile test case failing > strangely, if CSI test case is executed with CSI patched libvirt-cim). > Yes, I reported this a long time ago, the tests _only_ fail if you have SELinux enabled. Try disabling it and running again to check the results. Cheers, -- Eduardo de Barros Lima ??? eblima at gmail.com -------------- next part -------------- A non-text attachment was scrubbed... Name: test_for.c Type: text/x-csrc Size: 158 bytes Desc: not available URL: From xiawenc at linux.vnet.ibm.com Fri Oct 26 06:26:56 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 26 Oct 2012 14:26:56 +0800 Subject: [Libvirt-cim] [PATCH 4/4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: References: <50877FFA.4060802@linux.vnet.ibm.com> <5087820B.4020701@linux.vnet.ibm.com> Message-ID: <508A2D30.4030509@linux.vnet.ibm.com> ? 2012-10-24 20:58, Eduardo Lima (Etrunko) ??: > On Wed, Oct 24, 2012 at 3:52 AM, Wenchao Xia wrote: >> >>> On Mon, Oct 22, 2012 at 5:38 AM, Wenchao Xia >>> wrote: >>>> >>>> Oringinal implement have risk, this patch should fix it >>>> >>>> Signed-off-by: Wenchao Xia >>>> --- >>>> src/Virt_DevicePool.c | 47 >>>> +++++++++++++++++++++++++++++++++++------------ >>>> 1 files changed, 35 insertions(+), 12 deletions(-) >>>> >>>> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c >>>> index 79dc108..0cb9124 100644 >>>> --- a/src/Virt_DevicePool.c >>>> +++ b/src/Virt_DevicePool.c >>>> @@ -117,52 +117,75 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct >>>> virt_pool **pool) >>>> return ret; >>>> } >>>> >>>> +/* This function returns the real number of pools, no negative value >>>> should be >>>> + returned, if error happens it returns zero. */ >>>> static int get_diskpool_config(virConnectPtr conn, >>>> struct tmp_disk_pool **_pools) >>>> { >>>> - int count = 0; >>>> + int count = 0, realcount = 0; >>>> int i; >>>> char ** names = NULL; >>>> struct tmp_disk_pool *pools = NULL; >>>> + int have_err = 0; >>>> >>>> count = virConnectNumOfStoragePools(conn); >>>> - if (count <= 0) >>>> + if (count <= 0) { >>>> + have_err = 1; >>>> goto out; >>>> + } >>>> >>>> names = calloc(count, sizeof(char *)); >>>> if (names == NULL) { >>>> CU_DEBUG("Failed to alloc space for %i pool names", >>>> count); >>>> count = 0; >>>> + have_err = 1; >>>> goto out; >>>> } >>>> >>>> - if (virConnectListStoragePools(conn, names, count) == -1) { >>>> + realcount = virConnectListStoragePools(conn, names, count); >>>> + if (realcount == -1) { >>>> CU_DEBUG("Failed to get storage pools"); >>>> - count = 0; >>>> + realcount = 0; >>>> + have_err = 1; >>>> + goto out; >>>> + } >>>> + if (realcount == 0) { >>>> + CU_DEBUG("zero pools got, but prelist is %d.", count); >>>> goto out; >>>> } >>>> >>>> - pools = calloc(count, sizeof(*pools)); >>>> + pools = calloc(realcount, sizeof(*pools)); >>>> if (pools == NULL) { >>>> - CU_DEBUG("Failed to alloc space for %i pool structs", >>>> count); >>>> + CU_DEBUG("Failed to alloc space for %i pool structs", >>>> realcount); >>>> + realcount = 0; >>>> + have_err = 1; >>>> goto out; >>>> } >>>> >>>> - for (i = 0; i < count; i++) { >>>> + i = 0; >>>> + while (i < realcount) { >>>> pools[i].tag = strdup(names[i]); >>>> pools[i].primordial = false; >>>> + i++; >>>> } >>> >>> >>> Any specific reason for changing the for() loop for a while() one?? >>> >>>> >>>> out: >>>> - for (i = 0; i < count; i++) >>>> - free(names[i]); >>>> - free(names); >>>> + if (count > 0) { >>>> + i = 0; >>>> + while (i < count) { >>>> + free(names[i]); >>>> + i++; >>>> + } >>>> + free(names); >>>> + } >>> >>> >>> Same here. >>> >>> Best regards, >>> >> >> Good to see you again, there is one for() before which may take >> one execution if count == 0,where it should not. For safe and code >> style unifying I switch it all to while. > > No, if count is 0 the for will never be executed, this is basic C. > There is no need to test count before starting the loop. See test > attached. As for coding style, when you know the number of iterations, > the for loop it is much more readable and easier to maintain. > My mistake, I must have read it from some mis guiding books, for will look better. >> I am tring to fix some bugs after libvirt CSI patch applied, which >> make cimtest report strange error, A bit brute, could u help share some >> findings for those strange errors? (2 profile test case failing >> strangely, if CSI test case is executed with CSI patched libvirt-cim). >> > > Yes, I reported this a long time ago, the tests _only_ fail if you > have SELinux enabled. Try disabling it and running again to check the > results. > Perhaps SeLinux is another trigger of the cimtest error, Just found that there is some problem if libvirt-cim call libvirt event API, if I comment it out, test pass, otherwise fail, so will send a patch bring back libvirt-cim CSI, and leave libvirt event CSI as 2nd option. > Cheers, > -- Best Regards Wenchao Xia From xiaxia347work at 163.com Fri Oct 26 12:30:22 2012 From: xiaxia347work at 163.com (xiaxia347work) Date: Fri, 26 Oct 2012 20:30:22 +0800 Subject: [Libvirt-cim] [PATCH] libcmpiutil, fix potential debug print crash Message-ID: <1756278.84a3.13a9d0d3fbe.Coremail.xiaxia347work@163.com> It seems libcmpiutil still uses HG, sorry I forgot how to send patch with HG, so paste the patch directly here and attach the patch generated from "hg export" as attachement. exporting patch: # HG changeset patch # User Wenchao Xia # Date 1351243349 -28800 # Node ID 67a7b959ed47188efb8eb2f462bc7fc9ee145041 # Parent 2984ede9c082bab48b3494ef4b9f5561fadef2ad fix potential crash bug diff -r 2984ede9c082 -r 67a7b959ed47 std_indication.c --- a/std_indication.c Tue May 24 10:45:46 2011 -0400 +++ b/std_indication.c Fri Oct 26 17:22:29 2012 +0800 @@ -141,7 +141,12 @@ enabled = is_ind_enabled(ctx, ind_name, &s); if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem checking enabled: '%s'", CMGetCharPtr(s.msg)); + if (s.msg != NULL) { + CU_DEBUG("Problem checking enabled: '%s'", + CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Problem checking enabled, msg is NULL"); + } goto out; } @@ -176,7 +181,12 @@ enabled = is_ind_enabled(args->_ctx, ind_name, &s); if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem checking enabled: '%s'", CMGetCharPtr(s.msg)); + if (s.msg != NULL) { + CU_DEBUG("Problem checking enabled: '%s'", + CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Problem checking enabled, msg is NULL"); + } goto out; } -------------- next part -------------- A non-text attachment was scrubbed... Name: libcmpiutil_fix_crash.patch Type: application/octet-stream Size: 1476 bytes Desc: not available URL: From xiaxia347work at 163.com Fri Oct 26 12:32:36 2012 From: xiaxia347work at 163.com (xiaxia347work) Date: Fri, 26 Oct 2012 20:32:36 +0800 Subject: [Libvirt-cim] [PATCH] libcmpiutil, add time and thread info in CU_DEBUG Message-ID: <10836fdc.84c0.13a9d0f4fa1.Coremail.xiaxia347work@163.com> It seems libcmpiutil still uses HG, sorry I forgot how to send patch with HG, so paste the patch directly here and attach the patch generated from "hg export" as attachement. exporting patch: # HG changeset patch # User Wenchao Xia # Date 1351254054 -28800 # Node ID 4c82c8f418757be40bdd87575d309f17232545c0 # Parent 67a7b959ed47188efb8eb2f462bc7fc9ee145041 debug print, add time and thread info diff -r 67a7b959ed47 -r 4c82c8f41875 debug_util.c --- a/debug_util.c Fri Oct 26 17:22:29 2012 +0800 +++ b/debug_util.c Fri Oct 26 20:20:54 2012 +0800 @@ -23,7 +23,9 @@ #include #include #include - +#include +#include +#include #include "libcmpiutil.h" static int log_init = 0; @@ -32,6 +34,15 @@ void debug_print(char *fmt, ...) { char *log_file = NULL; + pthread_t id = pthread_self(); + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); + time_t timep; + struct tm *p; + time(&timep); + p=localtime(&timep); + va_list ap; va_start(ap, fmt); @@ -49,8 +60,10 @@ log_init = 1; } - if (log != NULL) + if (log != NULL) { + fprintf(log, "time[%d-%02d-%02d %02d:%02d:%02d.%06d] thread[%ld] ", (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, p->tm_hour, p->tm_min, p->tm_sec, (int)tv.tv_usec, id); vfprintf(log, fmt, ap); + } va_end(ap); } -------------- next part -------------- A non-text attachment was scrubbed... Name: libcmpiutil_debug_print.patch Type: application/octet-stream Size: 1354 bytes Desc: not available URL: From veillard at redhat.com Fri Oct 26 12:41:16 2012 From: veillard at redhat.com (Daniel Veillard) Date: Fri, 26 Oct 2012 20:41:16 +0800 Subject: [Libvirt-cim] [PATCH] libcmpiutil, fix potential debug print crash In-Reply-To: <1756278.84a3.13a9d0d3fbe.Coremail.xiaxia347work@163.com> References: <1756278.84a3.13a9d0d3fbe.Coremail.xiaxia347work@163.com> Message-ID: <20121026124116.GI4769@redhat.com> On Fri, Oct 26, 2012 at 08:30:22PM +0800, xiaxia347work wrote: > It seems libcmpiutil still uses HG, sorry I forgot how to send patch with HG, so Hum, no, it's converted to git too: http://libvirt.org/git/?p=libcmpiutil.git;a=summary Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard at redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/ From xiaxia347work at 163.com Fri Oct 26 13:40:34 2012 From: xiaxia347work at 163.com (xiaxia347work) Date: Fri, 26 Oct 2012 21:40:34 +0800 Subject: [Libvirt-cim] [PATCH] libcmpiutil, fix potential debug print crash In-Reply-To: <20121026124116.GI4769@redhat.com> References: <1756278.84a3.13a9d0d3fbe.Coremail.xiaxia347work@163.com><20121026124116.GI4769@redhat.com> Message-ID: <2ea48a69.8660.13a9d4d8c71.Coremail.xiaxia347work@163.com> Thank u for the tip, thus I will send them with git on Monday next week. Best Regards Wenchao Xia On Fri, Oct 26, 2012 at 08:30:22PM +0800, xiaxia347work wrote: > It seems libcmpiutil still uses HG, sorry I forgot how to send patch with HG, so Hum, no, it's converted to git too: http://libvirt.org/git/?p=libcmpiutil.git;a=summary Daniel -- Daniel Veillard | Open Source and Standards, Red Hat veillard at redhat.com | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ http://veillard.com/ | virtualization library http://libvirt.org/ From xiawenc at linux.vnet.ibm.com Tue Oct 30 08:09:57 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 16:09:57 +0800 Subject: [Libvirt-cim] [PATCH 11/15] RASDIndication, fix debug print crash Message-ID: <1351584597-23020-1-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- src/Virt_ResourceAllocationSettingDataIndication.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/src/Virt_ResourceAllocationSettingDataIndication.c b/src/Virt_ResourceAllocationSettingDataIndication.c index a386132..93fb563 100644 --- a/src/Virt_ResourceAllocationSettingDataIndication.c +++ b/src/Virt_ResourceAllocationSettingDataIndication.c @@ -122,7 +122,11 @@ static CMPIStatus raise_indication(const CMPIBroker *broker, if (s.rc == CMPI_RC_OK) { CU_DEBUG("Indication delivered"); } else { - CU_DEBUG("Not delivered: %s", CMGetCharPtr(s.msg)); + if (s.msg == NULL) { + CU_DEBUG("Not delivered: msg is NULL."); + } else { + CU_DEBUG("Not delivered: %s", CMGetCharPtr(s.msg)); + } } out: -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 08:10:24 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 16:10:24 +0800 Subject: [Libvirt-cim] [PATCH 12/15] device parsing, add debug print Message-ID: <1351584624-23101-1-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- libxkutil/device_parsing.c | 11 +++++++++-- 1 files changed, 9 insertions(+), 2 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index ceb4552..2841662 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -1251,12 +1251,19 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo) xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); - if (xml == NULL) + if (xml == NULL) { + CU_DEBUG("Failed to get dom xml with libvirt API."); return 0; + } ret = get_dominfo_from_xml(xml, dominfo); - if (virDomainGetAutostart(dom, &start) != 0) + if (ret != 1) { + CU_DEBUG("Failed to translate xml into struct domain"); + } + if (virDomainGetAutostart(dom, &start) != 0) { + CU_DEBUG("Failed to get dom autostart with libvirt API."); return 0; + } (*dominfo)->autostrt = start; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 08:10:47 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 16:10:47 +0800 Subject: [Libvirt-cim] [PATCH 13/15] CSI Discard libvirt event by default Message-ID: <1351584647-23175-1-git-send-email-xiawenc@linux.vnet.ibm.com> From cimtest, Calling to virEventRegisterDefaultImpl() of libvirt API, resulting random fail in cases, which seems most likely tog-pegasus's internal data is damaged. The root cause may be: 1 libvirt event API have a bug, we called it from thread A and then do other things in thread B, maybe it did not handle this well. 2 tog-pegasus have confilict with libvirt's event. 3 Potential requirement in libvirt event API or tog-pegasus's thread, which is not document so we used them in a wrong way. This patch bring back libvirt-cim's own old event implemention, which is by default used now. CSI from libvirt can still be activated with a macro. This patch also have changed some buglike code of old libvirt-cim's event implemention. Tested with cimtest on following Env, no more strange error found: RH6.3 libvirt-0.9.10-21.el6.x86_64 tog-pegasus-2.11.0-3.el6.x86_64 Signed-off-by: Wenchao Xia --- src/Virt_ComputerSystem.c | 46 +++- src/Virt_ComputerSystemIndication.c | 540 ++++++++++++++++++++++++++++- src/Virt_VirtualSystemManagementService.c | 36 ++- 3 files changed, 616 insertions(+), 6 deletions(-) diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index e6c7e55..adef85e 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -45,8 +45,45 @@ #include "Virt_HostSystem.h" #include "Virt_VirtualSystemSnapshotService.h" +#include "config.h" + const static CMPIBroker *_BROKER; +#ifndef USE_LIBVIRT_EVENT +static bool trigger_mod_indication(const CMPIContext *context, + CMPIInstance *prev_inst, + const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *ind_name = "ComputerSystemModifiedIndication"; + CMPIInstance *ind = NULL; + char *type = NULL; + + CU_DEBUG("Preparing ComputerSystem indication"); + + ind = get_typed_instance(_BROKER, + CLASSNAME(ref), + ind_name, + NAMESPACE(ref)); + if (ind == NULL) { + CU_DEBUG("Failed to create ind '%s'", ind_name); + goto out; + } + + CU_DEBUG("Setting PreviousInstance"); + CMSetProperty(ind, "PreviousInstance", + (CMPIValue *)&prev_inst, CMPI_instance); + + type = get_typed_class(CLASSNAME(ref), ind_name); + + s = stdi_raise_indication(_BROKER, context, type, NAMESPACE(ref), ind); + + out: + free(type); + return s.rc == CMPI_RC_OK; +} +#endif + /* Set the "Name" property of an instance from a domain */ static int set_name_from_dom(virDomainPtr dom, CMPIInstance *instance) { @@ -1256,8 +1293,15 @@ static CMPIStatus state_change(CMPIMethodMI *self, s = __state_change(name, state, reference); - if (s.rc == CMPI_RC_OK) + if (s.rc == CMPI_RC_OK) { +#ifndef USE_LIBVIRT_EVENT + bool ind_rc= trigger_mod_indication(context, prev_inst, + reference); + if (!ind_rc) + CU_DEBUG("Unable to trigger indication"); +#endif rc = 0; + } out: CMReturnData(results, &rc, CMPI_uint32); diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 3159ca0..d6f31cc 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -48,6 +48,8 @@ #include "Virt_ComputerSystemIndication.h" #include "Virt_HostSystem.h" +#define WAIT_TIME 60 +#define FAIL_WAIT_TIME 2 #define CSI_NUM_PLATFORMS 3 enum CSI_PLATFORMS { @@ -80,6 +82,7 @@ struct _csi_thread_data_t { }; static const CMPIBroker *_BROKER; +static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER; static pthread_mutex_t lifecycle_mutex = PTHREAD_MUTEX_INITIALIZER; static bool lifecycle_enabled = false; static csi_thread_data_t csi_thread_data[CSI_NUM_PLATFORMS] = {{0}, {0}, {0}}; @@ -580,6 +583,376 @@ static void csi_domain_event_cb(virConnectPtr conn, free(prefix); } +/* libvirt-cim's private CSI implement */ +struct dom_xml { + char uuid[VIR_UUID_STRING_BUFLEN]; + char *xml; + enum {DOM_OFFLINE, + DOM_ONLINE, + DOM_PAUSED, + DOM_CRASHED, + DOM_GONE, + } state; +}; + +static void free_dom_xml (struct dom_xml dom) +{ + free(dom.xml); + dom.xml = NULL; +} + +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 int dom_state(virDomainPtr dom) +{ + virDomainInfo info; + int ret; + + ret = virDomainGetInfo(dom, &info); + if (ret != 0) + return DOM_GONE; + + switch (info.state) { + case VIR_DOMAIN_NOSTATE: + case VIR_DOMAIN_RUNNING: + case VIR_DOMAIN_BLOCKED: + return DOM_ONLINE; + + case VIR_DOMAIN_PAUSED: + return DOM_PAUSED; + + case VIR_DOMAIN_SHUTOFF: + return DOM_OFFLINE; + + case VIR_DOMAIN_CRASHED: + return DOM_CRASHED; + + default: + return DOM_GONE; + }; +} + +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}; + + if (dom_ptr_count <= 0) { + *dom_xml_list = NULL; + return s; + } + *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], + VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); + if ((*dom_xml_list)[i].xml == NULL) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to get xml desc"); + break; + } + + (*dom_xml_list)[i].state = dom_state(dom_ptr_list[i]); + } + + 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) { + CU_DEBUG("Domain config changed"); + ret = true; + } + + if (prev_dom.state != cur_xml[i].state) { + CU_DEBUG("Domain state changed"); + ret = true; + } + + break; + } + + return ret; +} + +static bool wait_for_event(int wait_time) +{ + struct timespec timeout; + int ret; + + + clock_gettime(CLOCK_REALTIME, &timeout); + timeout.tv_sec += wait_time; + + ret = pthread_cond_timedwait(&lifecycle_cond, + &lifecycle_mutex, + &timeout); + + return true; +} + +static bool dom_in_list(char *uuid, int count, struct dom_xml *list) +{ + int i; + + for (i = 0; i < count; i++) { + if (STREQ(uuid, list[i].uuid)) + return true; + } + + return false; +} + +static bool async_ind_native(CMPIContext *context, + int ind_type, + struct dom_xml prev_dom, + char *prefix, + struct ind_args *args) +{ + bool rc = false; + char *name = NULL; + char *cn = NULL; + CMPIObjectPath *op; + CMPIInstance *prev_inst; + CMPIInstance *affected_inst; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + CU_DEBUG("Entering native indication diliv with type %d.", ind_type) + if (!lifecycle_enabled) { + CU_DEBUG("CSI not enabled, skipping indication delivery"); + return false; + } + + name = sys_name_from_xml(prev_dom.xml); + CU_DEBUG("Name for system: '%s'", name); + if (name == NULL) { + rc = false; + goto out; + } + + cn = get_typed_class(prefix, "ComputerSystem"); + + op = CMNewObjectPath(_BROKER, args->ns, cn, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) { + CU_DEBUG("op error"); + goto out; + } + + if (ind_type == CS_CREATED || ind_type == CS_MODIFIED) { + s = get_domain_by_name(_BROKER, op, name, &affected_inst); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("domain by name error"); + goto out; + } + } else if (ind_type == CS_DELETED) { + rc = create_deleted_guest_inst(prev_dom.xml, + args->ns, + prefix, + &affected_inst); + if (!rc) { + CU_DEBUG("Could not recreate guest instance"); + goto out; + } + } else { + CU_DEBUG("Unrecognized indication type"); + goto out; + } + + /* FIXME: We are unable to get the previous CS instance after it has + been modified. Consider keeping track of the previous + state in the place we keep track of the requested state */ + prev_inst = affected_inst; + + CMSetProperty(affected_inst, "Name", + (CMPIValue *)name, CMPI_chars); + CMSetProperty(affected_inst, "UUID", + (CMPIValue *)prev_dom.uuid, CMPI_chars); + + rc = _do_indication(_BROKER, context, prev_inst, affected_inst, + ind_type, prefix, args); + + out: + free(cn); + free(name); + return rc; +} + +static CMPI_THREAD_RETURN lifecycle_thread_native(void *params) +{ + CU_DEBUG("Entering libvirtc-cim native CSI thread."); + csi_thread_data_t *thread = (csi_thread_data_t *) params; + struct ind_args *args = thread->args; + CMPIContext *context = args->context; + char *prefix = class_prefix_name(args->classname); + virConnectPtr conn; + CMPIStatus s; + int retry_time = FAIL_WAIT_TIME; + + struct dom_xml *cur_xml = NULL; + struct dom_xml *prev_xml = NULL; + int prev_count = 0; + int cur_count = 0; + virDomainPtr *tmp_list = NULL; + int CBAttached = 0; + + if (prefix == NULL) + goto init_out; + + pthread_mutex_lock(&lifecycle_mutex); + conn = connect_by_classname(_BROKER, args->classname, &s); + if (conn == NULL) { + CU_DEBUG("Unable to start lifecycle thread: " + "Failed to connect (cn: %s)", args->classname); + pthread_mutex_unlock(&lifecycle_mutex); + goto conn_out; + } + + CBAttachThread(_BROKER, args->context); + CBAttached = 1; + prev_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&prev_xml, tmp_list, prev_count); + free_domain_list(tmp_list, prev_count); + free(tmp_list); + if (s.rc != CMPI_RC_OK) + CU_DEBUG("doms_to_xml failed. Attempting to continue."); + + CU_DEBUG("Entering libvirt-cim native CSI event loop (%s)", prefix); + + int i; + while (1) { + if (thread->active_filters <= 0) { + break; + } + + bool res; + bool failure = false; + + cur_count = get_domain_list(conn, &tmp_list); + s = doms_to_xml(&cur_xml, tmp_list, cur_count); + free_domain_list(tmp_list, cur_count); + free(tmp_list); + if (s.rc != CMPI_RC_OK) { + CU_DEBUG("doms_to_xml failed. retry in %d seconds", + retry_time); + failure = true; + goto fail; + } + + /* CU_DEBUG("cur_count %d, prev_count %d.", + cur_count, prev_count); */ + for (i = 0; i < cur_count; i++) { + res = dom_in_list(cur_xml[i].uuid, prev_count, prev_xml); + if (!res) { + async_ind_native(context, CS_CREATED, + cur_xml[i], prefix, args); + } + + } + + for (i = 0; i < prev_count; i++) { + res = dom_in_list(prev_xml[i].uuid, cur_count, cur_xml); + if (!res) { + async_ind_native(context, CS_DELETED, + prev_xml[i], prefix, args); + } + } + + for (i = 0; i < prev_count; i++) { + res = dom_changed(prev_xml[i], cur_xml, cur_count); + if (res) { + async_ind_native(context, CS_MODIFIED, + prev_xml[i], prefix, args); + } + free_dom_xml(prev_xml[i]); + } + + fail: + if (failure) { + wait_for_event(FAIL_WAIT_TIME); + } else { + free(prev_xml); + prev_xml = cur_xml; + cur_xml = NULL; + prev_count = cur_count; + cur_count = 0; + wait_for_event(WAIT_TIME); + } + } + + CU_DEBUG("Exiting libvirt-cim native CSI event loop (%s)", prefix); + + if (prev_xml != NULL) { + for (i = 0; i < prev_count; i++) { + free_dom_xml(prev_xml[i]); + } + free(prev_xml); + prev_xml = NULL; + } + + pthread_mutex_unlock(&lifecycle_mutex); + + virConnectClose(conn); + + conn_out: + free(prefix); + + init_out: + pthread_mutex_lock(&lifecycle_mutex); + thread->id = 0; + thread->active_filters = 0; + + /* it seems tog-pegasus try kill this thread after detached, use this + flag to delay detach as much as possible. */ + if (CBAttached > 0) { + CBDetachThread(_BROKER, args->context); + } + if (thread->args != NULL) + stdi_free_ind_args(&thread->args); + + pthread_mutex_unlock(&lifecycle_mutex); + + return (CMPI_THREAD_RETURN) 0; +} + static CMPI_THREAD_RETURN lifecycle_thread(void *params) { csi_thread_data_t *thread = (csi_thread_data_t *) params; @@ -696,13 +1069,24 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, csi_thread_data_t *thread = NULL; static int events_registered = 0; +#ifndef USE_LIBVIRT_EVENT + int use_libvirt_event = 0; +#else + int use_libvirt_event = 1; +#endif + CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); pthread_mutex_lock(&lifecycle_mutex); - if (events_registered == 0) { - events_registered = 1; - virEventRegisterDefaultImpl(); + if (use_libvirt_event == 1) { + if (events_registered == 0) { + events_registered = 1; + CU_DEBUG("Registering libvirt event."); + virEventRegisterDefaultImpl(); + } + } else { + CU_DEBUG("Using libvirt-cim's event implemention."); } _ctx = (struct std_indication_ctx *)mi->hdl; @@ -753,7 +1137,20 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, args->_ctx = _ctx; thread->args = args; - thread->id = _BROKER->xft->newThread(lifecycle_thread, thread, 0); + + if (use_libvirt_event == 0) { + thread->id = _BROKER->xft->newThread( + lifecycle_thread_native, + thread, 0); + } else { + thread->id = _BROKER->xft->newThread(lifecycle_thread, + thread, 0); + } + + if (thread->id <= 0) { + CU_DEBUG("Error, failed to create new thread."); + error = true; + } out: if (error == true) { @@ -791,6 +1188,10 @@ static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, csi_thread_data[platform].active_filters -= 1; pthread_mutex_unlock(&lifecycle_mutex); +#ifndef USE_LIBVIRT_EVENT + pthread_cond_signal(&lifecycle_cond); +#endif + out: return s; } @@ -817,6 +1218,7 @@ static _EI_RTYPE DisableIndications(CMPIIndicationMI* mi, _EI_RET(); } + DECLARE_FILTER(xen_created, "Xen_ComputerSystemCreatedIndication"); DECLARE_FILTER(xen_deleted, "Xen_ComputerSystemDeletedIndication"); DECLARE_FILTER(xen_modified, "Xen_ComputerSystemModifiedIndication"); @@ -840,7 +1242,137 @@ static struct std_ind_filter *filters[] = { NULL, }; +#ifndef USE_LIBVIRT_EVENT +static CMPIStatus trigger_indication(const CMPIContext *context) +{ + CU_DEBUG("triggered"); + pthread_cond_signal(&lifecycle_cond); + return(CMPIStatus){CMPI_RC_OK, NULL}; +} + +static CMPIInstance *get_prev_inst(const CMPIBroker *broker, + const CMPIInstance *ind, + CMPIStatus *s) +{ + CMPIData data; + CMPIInstance *prev_inst = NULL; + + data = CMGetProperty(ind, "PreviousInstance", s); + if (s->rc != CMPI_RC_OK || CMIsNullValue(data)) { + cu_statusf(broker, s, + CMPI_RC_ERR_NO_SUCH_PROPERTY, + "Unable to get PreviousInstance of the indication"); + goto out; + } + + if (data.type != CMPI_instance) { + cu_statusf(broker, s, + CMPI_RC_ERR_TYPE_MISMATCH, + "Indication SourceInstance is of unexpected type"); + goto out; + } + + prev_inst = data.value.inst; + + out: + return prev_inst; +} + +static CMPIStatus raise_indication(const CMPIBroker *broker, + const CMPIContext *ctx, + const CMPIObjectPath *ref, + const CMPIInstance *ind) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *prev_inst; + CMPIInstance *src_inst; + CMPIObjectPath *_ref = NULL; + struct std_indication_ctx *_ctx = NULL; + struct ind_args *args = NULL; + char *prefix = NULL; + bool rc; + + if (!lifecycle_enabled) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "CSI not enabled, skipping indication delivery"); + goto out; + } + + prev_inst = get_prev_inst(broker, ind, &s); + if (s.rc != CMPI_RC_OK || CMIsNullObject(prev_inst)) + goto out; + + _ref = CMGetObjectPath(prev_inst, &s); + if (s.rc != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to get a reference to the guest"); + goto out; + } + + /* FIXME: This is a Pegasus work around. Pegsus loses the namespace + when an ObjectPath is pulled from an instance */ + if (STREQ(NAMESPACE(_ref), "")) + CMSetNameSpace(_ref, "root/virt"); + + s = get_domain_by_ref(broker, _ref, &src_inst); + if (s.rc != CMPI_RC_OK || CMIsNullObject(src_inst)) + goto out; + + _ctx = malloc(sizeof(struct std_indication_ctx)); + if (_ctx == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to allocate indication context"); + goto out; + } + + _ctx->brkr = broker; + _ctx->handler = NULL; + _ctx->filters = filters; + _ctx->enabled = lifecycle_enabled; + + args = malloc(sizeof(struct ind_args)); + if (args == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + goto out; + } + + args->ns = strdup(NAMESPACE(_ref)); + args->classname = strdup(CLASSNAME(_ref)); + args->_ctx = _ctx; + + prefix = class_prefix_name(args->classname); + + rc = _do_indication(broker, ctx, prev_inst, src_inst, + CS_MODIFIED, prefix, args); + + if (!rc) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unable to generate indication"); + } + + out: + if (args != NULL) + stdi_free_ind_args(&args); + + if (_ctx != NULL) + free(_ctx); + + free(prefix); + return s; +} +#endif + static struct std_indication_handler csi = { +#ifndef USE_LIBVIRT_EVENT + .raise_fn = raise_indication, + .trigger_fn = trigger_indication, +#endif .activate_fn = ActivateFilter, .deactivate_fn = DeActivateFilter, .enable_fn = EnableIndications, diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index 10adf8b..059b852 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -107,6 +107,24 @@ enum ResourceAction { RESOURCE_MOD, }; +#ifndef USE_LIBVIRT_EVENT +static bool trigger_indication(const CMPIContext *context, + const char *base_type, + const CMPIObjectPath *ref) +{ + char *type; + CMPIStatus s; + + type = get_typed_class(CLASSNAME(ref), base_type); + + s = stdi_trigger_indication(_BROKER, context, type, NAMESPACE(ref)); + + free(type); + + return s.rc == CMPI_RC_OK; +} +#endif + #if LIBVIR_VERSION_NUMBER < 9000 /* Network QoS support */ static CMPIStatus add_qos_for_mac(const uint64_t qos, @@ -2166,6 +2184,11 @@ static CMPIStatus define_system(CMPIMethodMI *self, CMAddArg(argsout, "ResultingSystem", &result, CMPI_ref); } +#ifndef USE_LIBVIRT_EVENT + trigger_indication(context, + "ComputerSystemCreatedIndication", + reference); +#endif out: if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; @@ -2268,6 +2291,11 @@ error: NULL, reference, &list); +#ifndef USE_LIBVIRT_EVENT + trigger_indication(context, + "ComputerSystemDeletedIndication", + reference); +#endif } virDomainFree(dom); @@ -2349,8 +2377,14 @@ static CMPIStatus update_system_settings(const CMPIContext *context, connect_and_create(xml, ref, &s); } - if (s.rc == CMPI_RC_OK) + if (s.rc == CMPI_RC_OK) { set_autostart(vssd, ref, dom); +#ifndef USE_LIBVIRT_EVENT + trigger_indication(context, + "ComputerSystemModifiedIndication", + ref); +#endif + } out: free(xml); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 08:11:16 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 16:11:16 +0800 Subject: [Libvirt-cim] [PATCH 14/15] disable cgroup by default Message-ID: <1351584676-23251-1-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- libxkutil/device_parsing.c | 9 ++++++++- src/Virt_ComputerSystem.c | 7 ++++++- src/Virt_VirtualSystemManagementService.c | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index 2841662..83d4590 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -34,6 +34,8 @@ #include "xmlgen.h" #include "../src/svpc_types.h" +#include "config.h" + #define DISK_XPATH (xmlChar *)"/domain/devices/disk | "\ "/domain/devices/filesystem" #define VCPU_XPATH (xmlChar *)"/domain/vcpu" @@ -1407,7 +1409,9 @@ static int change_vcpus(virDomainPtr dom, struct virt_device *dev) strncpy(param.field, "cpu_shares", VIR_DOMAIN_SCHED_FIELD_LENGTH); param.type = VIR_DOMAIN_SCHED_FIELD_ULLONG; param.value.ul = dev->dev.vcpu.weight; - + + /* skip cgroup setting */ +#ifdef SUPPORT_CGROUP_CPU if (virDomainSetSchedulerParameters(dom, ¶m, 1) != 0) { CU_DEBUG("Failed to set scheduler params for domain"); return 0; @@ -1416,6 +1420,9 @@ static int change_vcpus(virDomainPtr dom, struct virt_device *dev) CU_DEBUG("Changed %s vcpu cgroup cpu_shares to %i", virDomainGetName(dom), dev->dev.vcpu.weight); +#else + CU_DEBUG("Skipped setting cpu cgroup."); +#endif } if (dev->dev.vcpu.quantity <= 0) { diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index adef85e..c422e3b 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -935,8 +935,13 @@ static void set_scheduler_params(virDomainPtr dom) goto out; } - if (count > 0) + if (count > 0) { +#ifdef SUPPORT_CGROUP_CPU virDomainSetSchedulerParameters(dom, params, count); +#else + CU_DEBUG("Skipped setting cpu cgroup."); +#endif + } else CU_DEBUG("No sched parameters to set"); out: diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index 059b852..9a9b635 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -1778,11 +1778,17 @@ static CMPIStatus update_dominfo(const struct domain *dominfo, params.type = VIR_DOMAIN_SCHED_FIELD_ULLONG; params.value.ul = dev->dev.vcpu.weight; +#ifdef SUPPORT_CGROUP_CPU CU_DEBUG("setting %s scheduler param cpu_shares=%d", dominfo->name, dev->dev.vcpu.weight); ret = virDomainSetSchedulerParametersFlags(dom, ¶ms, 1, VIR_DOMAIN_AFFECT_CONFIG); +#else + CU_DEBUG("Skipped cgroup cpu setting."); + ret = 0; +#endif + if (ret != 0) { CU_DEBUG("Failed to set config scheduler param"); cu_statusf(_BROKER, &s, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 08:11:46 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 16:11:46 +0800 Subject: [Libvirt-cim] [PATCH 15/15] VSSD, fix a error report issue in VSSD enum Message-ID: <1351584706-23300-1-git-send-email-xiawenc@linux.vnet.ibm.com> If user delete a VS and enum VSSD at the sametime, it may have chance to report error, but actually it succeed just with some VS not found. This Patch fixed it. It will continue if found one VS is missing in enum. Signed-off-by: Wenchao Xia --- src/Virt_VSSD.c | 72 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 59 insertions(+), 13 deletions(-) diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c index 499b157..1665ef5 100644 --- a/src/Virt_VSSD.c +++ b/src/Virt_VSSD.c @@ -36,6 +36,8 @@ #include "Virt_VSSD.h" +#define VSSD_ERROR_RECOVERABLE (2) + const static CMPIBroker *_BROKER; static CMPIStatus _set_fv_prop(const CMPIBroker *broker, @@ -181,8 +183,19 @@ static int instance_from_dom(const CMPIBroker *broker, struct domain *dominfo = NULL; ret = get_dominfo(dom, &dominfo); - if (!ret) + if (!ret) { + int active = virDomainIsActive(dom); + if (active < 0) { + /* ret > 1 indicate that it is recoverable */ + CU_DEBUG("Failed to get dominfo, " + "it may not present now."); + ret = VSSD_ERROR_RECOVERABLE; + } else { + CU_DEBUG("Failed to get dominfo, " + "libvirt level error."); + } goto out; + } op = CMGetObjectPath(inst, NULL); pfx = class_prefix_name(CLASSNAME(op)); @@ -246,6 +259,8 @@ static int instance_from_dom(const CMPIBroker *broker, s = _set_fv_prop(broker, dominfo, inst); if (s.rc != CMPI_RC_OK) { ret = 0; + CU_DEBUG("Failed to set full virtual prop for %d dom.", + dominfo->type); goto out; } } @@ -260,6 +275,7 @@ static int instance_from_dom(const CMPIBroker *broker, if (asprintf(&vsid, "%s:%s", pfx, dominfo->name) == -1) { ret = 0; + CU_DEBUG("Failed in asprintf vsid."); goto out; } @@ -278,7 +294,8 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, const CMPIObjectPath *reference, virConnectPtr conn, virDomainPtr dom, - CMPIStatus *s) + CMPIStatus *s, + int *error_below) { CMPIInstance *inst = NULL; @@ -294,10 +311,18 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, goto out; } - if (instance_from_dom(broker, dom, inst) != 1) { - cu_statusf(broker, s, - CMPI_RC_ERR_FAILED, - "Unable to get VSSD instance from Domain"); + *error_below = instance_from_dom(broker, dom, inst); + if (*error_below != 1) { + if (*error_below == VSSD_ERROR_RECOVERABLE) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to get VSSD instance from Domain, " + "Domain may not exist at this moment."); + } else { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to get VSSD instance from Domain"); + } } out: @@ -312,6 +337,7 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, virDomainPtr *list; int count; int i; + int error_below; CMPIStatus s = {CMPI_RC_OK, NULL}; conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); @@ -327,14 +353,33 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, } else if (count == 0) goto out; + int fail_count = 0; for (i = 0; i < count; i++) { CMPIInstance *inst = NULL; - - inst = _get_vssd(_BROKER, reference, conn, list[i], &s); - + + inst = _get_vssd(_BROKER, reference, conn, list[i], + &s, &error_below); + virDomainFree(list[i]); - if (inst == NULL) - continue; + + if ((inst == NULL) || (s.rc != CMPI_RC_OK)) { + fail_count++; + CU_DEBUG("VSSD got %d fail instance, total %d," + " error %d.", + fail_count, count, error_below); + if (error_below == VSSD_ERROR_RECOVERABLE) { + cu_statusf(_BROKER, &s, + CMPI_RC_OK, + "%d/%d VSSD not got," + " some VS may not exist now", + fail_count, count); + CU_DEBUG("Continue to next VSSD for enum."); + continue; + } else { + CU_DEBUG("Met unrecoverable error."); + break; + } + } if (names_only) cu_return_instance_name(results, inst); @@ -358,7 +403,8 @@ CMPIStatus get_vssd_by_name(const CMPIBroker *broker, virDomainPtr dom; CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst = NULL; - + int error_below; + conn = connect_by_classname(broker, CLASSNAME(reference), &s); if (conn == NULL) { cu_statusf(broker, &s, @@ -377,7 +423,7 @@ CMPIStatus get_vssd_by_name(const CMPIBroker *broker, goto out; } - inst = _get_vssd(broker, reference, conn, dom, &s); + inst = _get_vssd(broker, reference, conn, dom, &s, &error_below); virDomainFree(dom); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 10:24:40 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 18:24:40 +0800 Subject: [Libvirt-cim] [PATCH 1/2] libcmpiutil, add time and thread info in debug print Message-ID: <1351592681-12770-1-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- debug_util.c | 19 ++++++++++++++++++- 1 files changed, 18 insertions(+), 1 deletions(-) diff --git a/debug_util.c b/debug_util.c index 2912fb6..864a3f7 100644 --- a/debug_util.c +++ b/debug_util.c @@ -24,6 +24,9 @@ #include #include +#include +#include +#include #include "libcmpiutil.h" static int log_init = 0; @@ -32,6 +35,15 @@ static FILE *log = NULL; void debug_print(char *fmt, ...) { char *log_file = NULL; + pthread_t id = pthread_self(); + struct timeval tv; + struct timezone tz; + gettimeofday(&tv, &tz); + time_t timep; + struct tm *p; + time(&timep); + p=localtime(&timep); + va_list ap; va_start(ap, fmt); @@ -49,8 +61,13 @@ void debug_print(char *fmt, ...) log_init = 1; } - if (log != NULL) + if (log != NULL) { vfprintf(log, fmt, ap); + fprintf(log, "time[%d-%02d-%02d %02d:%02d:%02d.%06d] " + "thread[%ld] ", + (1900+p->tm_year), (1+p->tm_mon), p->tm_mday, + p->tm_hour, p->tm_min, p->tm_sec, (int)tv.tv_usec, id); + } va_end(ap); } -- 1.7.1 From xiawenc at linux.vnet.ibm.com Tue Oct 30 10:24:41 2012 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 30 Oct 2012 18:24:41 +0800 Subject: [Libvirt-cim] [PATCH 2/2] libcmpiutil, fix a potential debug print crash In-Reply-To: <1351592681-12770-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1351592681-12770-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1351592681-12770-2-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- std_indication.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/std_indication.c b/std_indication.c index f9dbea4..3585864 100644 --- a/std_indication.c +++ b/std_indication.c @@ -141,7 +141,12 @@ static CMPIStatus raise(struct std_indication_ctx *ctx, enabled = is_ind_enabled(ctx, ind_name, &s); if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem checking enabled: '%s'", CMGetCharPtr(s.msg)); + if (s.msg != NULL) { + CU_DEBUG("Problem checking enabled: '%s'", + CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Problem checking enabled, msg is NULL"); + } goto out; } @@ -176,7 +181,12 @@ CMPIStatus stdi_deliver(const CMPIBroker *broker, enabled = is_ind_enabled(args->_ctx, ind_name, &s); if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Problem checking enabled: '%s'", CMGetCharPtr(s.msg)); + if (s.msg != NULL) { + CU_DEBUG("Problem checking enabled: '%s'", + CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Problem checking enabled, msg is NULL."); + } goto out; } -- 1.7.1 From snmishra at linux.vnet.ibm.com Tue Oct 30 21:50:24 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Tue, 30 Oct 2012 14:50:24 -0700 Subject: [Libvirt-cim] [PATCH 2/2] libcmpiutil, fix a potential debug print crash In-Reply-To: <1351592681-12770-2-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1351592681-12770-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1351592681-12770-2-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121030145024.Horde.bhlWz5ir309QkEugKoLmJpA@imap.linux.ibm.com> +1 Sharad Mishra Quoting Wenchao Xia : > Signed-off-by: Wenchao Xia > --- > std_indication.c | 14 ++++++++++++-- > 1 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/std_indication.c b/std_indication.c > index f9dbea4..3585864 100644 > --- a/std_indication.c > +++ b/std_indication.c > @@ -141,7 +141,12 @@ static CMPIStatus raise(struct std_indication_ctx *ctx, > > enabled = is_ind_enabled(ctx, ind_name, &s); > if (s.rc != CMPI_RC_OK) { > - CU_DEBUG("Problem checking enabled: '%s'", > CMGetCharPtr(s.msg)); > + if (s.msg != NULL) { > + CU_DEBUG("Problem checking enabled: '%s'", > + CMGetCharPtr(s.msg)); > + } else { > + CU_DEBUG("Problem checking enabled, msg is NULL"); > + } > goto out; > } > > @@ -176,7 +181,12 @@ CMPIStatus stdi_deliver(const CMPIBroker *broker, > > enabled = is_ind_enabled(args->_ctx, ind_name, &s); > if (s.rc != CMPI_RC_OK) { > - CU_DEBUG("Problem checking enabled: '%s'", > CMGetCharPtr(s.msg)); > + if (s.msg != NULL) { > + CU_DEBUG("Problem checking enabled: '%s'", > + CMGetCharPtr(s.msg)); > + } else { > + CU_DEBUG("Problem checking enabled, msg is NULL."); > + } > goto out; > } > > -- > 1.7.1 From snmishra at linux.vnet.ibm.com Tue Oct 30 21:51:34 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Tue, 30 Oct 2012 14:51:34 -0700 Subject: [Libvirt-cim] [PATCH 12/15] device parsing, add debug print In-Reply-To: <1351584624-23101-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1351584624-23101-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121030145134.Horde.DKhoJZir309QkEvmB3KlUSA@imap.linux.ibm.com> +1 Sharad Mishra Quoting Wenchao Xia : > Signed-off-by: Wenchao Xia > --- > libxkutil/device_parsing.c | 11 +++++++++-- > 1 files changed, 9 insertions(+), 2 deletions(-) > > diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c > index ceb4552..2841662 100644 > --- a/libxkutil/device_parsing.c > +++ b/libxkutil/device_parsing.c > @@ -1251,12 +1251,19 @@ int get_dominfo(virDomainPtr dom, struct > domain **dominfo) > xml = virDomainGetXMLDesc(dom, > VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); > > - if (xml == NULL) > + if (xml == NULL) { > + CU_DEBUG("Failed to get dom xml with libvirt API."); > return 0; > + } > > ret = get_dominfo_from_xml(xml, dominfo); > - if (virDomainGetAutostart(dom, &start) != 0) > + if (ret != 1) { > + CU_DEBUG("Failed to translate xml into struct domain"); > + } > + if (virDomainGetAutostart(dom, &start) != 0) { > + CU_DEBUG("Failed to get dom autostart with libvirt API."); > return 0; > + } > > (*dominfo)->autostrt = start; > > -- > 1.7.1 From snmishra at linux.vnet.ibm.com Tue Oct 30 21:52:00 2012 From: snmishra at linux.vnet.ibm.com (snmishra at linux.vnet.ibm.com) Date: Tue, 30 Oct 2012 14:52:00 -0700 Subject: [Libvirt-cim] [PATCH 11/15] RASDIndication, fix debug print crash In-Reply-To: <1351584597-23020-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1351584597-23020-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <20121030145200.Horde.D6Bn_Jir309QkEwAFjGwJ8A@imap.linux.ibm.com> +1 Sharad Mishra Quoting Wenchao Xia : > Signed-off-by: Wenchao Xia > --- > src/Virt_ResourceAllocationSettingDataIndication.c | 6 +++++- > 1 files changed, 5 insertions(+), 1 deletions(-) > > diff --git a/src/Virt_ResourceAllocationSettingDataIndication.c > b/src/Virt_ResourceAllocationSettingDataIndication.c > index a386132..93fb563 100644 > --- a/src/Virt_ResourceAllocationSettingDataIndication.c > +++ b/src/Virt_ResourceAllocationSettingDataIndication.c > @@ -122,7 +122,11 @@ static CMPIStatus raise_indication(const > CMPIBroker *broker, > if (s.rc == CMPI_RC_OK) { > CU_DEBUG("Indication delivered"); > } else { > - CU_DEBUG("Not delivered: %s", CMGetCharPtr(s.msg)); > + if (s.msg == NULL) { > + CU_DEBUG("Not delivered: msg is NULL."); > + } else { > + CU_DEBUG("Not delivered: %s", CMGetCharPtr(s.msg)); > + } > } > > out: > -- > 1.7.1