From jferlan at redhat.com Mon Mar 4 23:49:46 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 04 Mar 2013 18:49:46 -0500 Subject: [Libvirt-cim] [RFC] Patches need no testcase In-Reply-To: <50F63EA9.6060804@linux.vnet.ibm.com> References: <50F63EA9.6060804@linux.vnet.ibm.com> Message-ID: <5135331A.1020704@redhat.com> On 01/16/2013 12:46 AM, Wenchao Xia wrote: > Hi, Danial > Happy new year! > Could u have a look v3 serial of libcmpituil patches? It is simple > and need no test case, hope it can be merged if no problem found. > First off - let me introduce myself... I'm (relatively) new to Red Hat having joined in Dec 2012 from HP where I worked on Virtualization products at HP. Primarily I was responsible for the API/CLI space of the HPVM product. I also was part of a project that created what HP calls VirtProvider which was a DSP2013 CIM Provider. Since I knew how to spell CIM and had some history, I was asked to take a look at failures that Yanbing Du posted questions about back in October: https://www.redhat.com/archives/libvirt-cim/2012-October/msg00000.html Sorry in advance for the length of the rest of this... While this won't be a full time endeavour, putting some cycles on libvirt-cim has been added to my list of things to do. I still need a bit of help - I'm not quite sure of the "proper procedure" to use when testing a local libvirt-cim build. The only way I was able to make things work was remove the libvirt-cim package (rpm -e) and then reinstall (yum localinstall from build rpm in a 'make rpm'). I tried the install/postinstall process with stopping/starting tog-pegasus, but couldn't quite get things to work. Getting "up to speed" was a bit of a challenge as the libvirt CIM web pages seem to be a bit out of date and perhaps assume a few things along the way. I've taken some notes, but was eventually able to get things installed. I'm still working through some of the "kinks". Setting up a CIMserver with tog_pegasus was not something I did at HP, so it was a bit of an adventure. Eventually I worked my way through things with lots of trial and error. Following the README instructions I ran into two issues during the post installation phase, which I'm somewhat curious if long time users would also hit (not that many are active any more): #1: The commit id '22022870d' to Makefile.am which essentially added "$(top_srcdir)/" in front of the "schema" directory path caused the 'make postinstall' to fail (at least on my fedora18 system). The problem is that the path ends up as ".//usr/..." the "./" being the problem with respect to the ability to "find" the files. Stripping that off allows finding files to be found again. The fix is to modify the various "$(subst schema" and replace them with "$(subst $(top_srcdir)/schema" - this allowed me to continue. #2: After that was solved, as things were scrolling past I noted that there was some sort of issue with "schema/SwitchService.registration". In looking at the file, it seems the blank line at the end of the file caused some sort of "issue", so I removed it and the registration was happier. After those changes I was able to run through the 'cimtest' using the most recent libvirt (what is looking to be 1.0.3). I didn't see all the same errors, but did trip across a few. Figuring that perhaps some of those were fixed by patches that I knew were out there, I went back to start looking, applying, and running cimtest again for tests that failed for me. I downloaded and applied the Dec 2012 patches for libvirt-cim (v3 01 -> 11 and v4 DevicePool) and libcmpiutil (v3 1&2) as well as the Nov 2012 patch submitted by Jirka. I believe that gets me "up to date". Although it was a bit confusing as what I should have done for the v4 patches on 12/25/12 was to "replace" the 12/18/12 patches 6 and 10. Luckily it was a quick retrace of my steps. Unfortunately it didn't seem I was "using" the changes when I ran "make", "make preinstall", "make install", & "make postinstall". So, I figured I'd try to make a new distribution to see if that would work. I got a bit further; however, the 'make distcheck' failed for me much in the same way the 'make postinstall' did above. So I adjusted commit id '9f5e204f' to rather than "$(subst ./schema," use "$(subst $(top_srcdir)/schema" which resolve the issue I was running into. Once I did the 'rpm -e libvirt-cim', I was able to install the rpm I build and test the changes. The (partial) good news is between the fixes provided in the December patches and some of my own I can get a majority of cimtest to succeed. I've had to make other adjustments, but I figured that'd be par for the course anyway. So some comments about your changes. Now that I have a little more experience I'll look at the other changes more in depth, but these two popped out due to me running into "issues" with them. Patch 01/11: * The change for 'bridge' networks and not allowing scripts is only for qemu domains. Apparently Xen domains would still support the script. So while your change does effectively remove it for Qemu, doing so for Xen could be a regression (I have no way to test). See the following for my logic: http://www.redhat.com/archives/libvir-list/2012-January/msg00240.html Before I had applied your patches I had made a similar change except that I passed along the dominfo->type to the bridge_net_to_xml() function and then test in there whether or not the "script" should be added based on type of DOMAIN_XENPV or DOMAIN_XENFV. Patch 09/11 * This change caused the 'make distcheck" to fail. The 'wait_for_event()' routine has a "ret" variable that is unused. Some changes I've made to 'cimtest' in order to get things to work * The test makes use of setting a MAC in quite a few places, unfortunately the MAC chosen for most (99:aa:bb:cc:ee:ff) is a Multicast Address. We know this because the low bit of the first byte (e.g. "99") is set (in hex 0x10011001). Changing those references to "88" works. * ComputerSystemIndication and RASDIndications fail for me. After a long pause, I got a Python stack trace where it looks like it's trying to print testsuite results. What that turns out to be is the 'os_status' being passed along is the errno value for 'ETIMEDOUT' (eg. 110). Using 110 to index into the rc[] record in Reporter.py causes a KeyError exception. I "fixed" that by checking if os_status was outside of the valid range and if so, set it to FAIL, but log that I did so. * Profile/04_verify_libvirt_cim_slp_profiles.py has a bug. It only checks for "slp" when it should check "slp=true". * Looking for the NFS Server at /sbin/init.d/nfs doesn't work any more with the usage of systemd in order to start/stop daemons. I adjusted the code accordingly * The ResourcePoolConfigurationService tests 08, 09, & 15 try to create a pool pointing at /var/lib/libvirt/images which causes a failure because cimtest-diskpool already exists and uses it. Not sure if this is a new check or not (remember I haven't been here that long). My current results have 173 of 192 tests passing. There are 4 FAIL, 4 XFAIL, and 11 SKIP (mostly migration which I haven't figured out yet). 2 of the SKIP's are because I already had a domains and storage pools defined on my system. John From xiawenc at linux.vnet.ibm.com Tue Mar 5 03:22:24 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 05 Mar 2013 11:22:24 +0800 Subject: [Libvirt-cim] [RFC] Patches need no testcase In-Reply-To: <5135331A.1020704@redhat.com> References: <50F63EA9.6060804@linux.vnet.ibm.com> <5135331A.1020704@redhat.com> Message-ID: <513564F0.2030502@linux.vnet.ibm.com> ? 2013-3-5 7:49, John Ferlan ??: > On 01/16/2013 12:46 AM, Wenchao Xia wrote: >> Hi, Danial >> Happy new year! >> Could u have a look v3 serial of libcmpituil patches? It is simple >> and need no test case, hope it can be merged if no problem found. >> > > First off - let me introduce myself... I'm (relatively) new to Red Hat > having joined in Dec 2012 from HP where I worked on Virtualization > products at HP. Primarily I was responsible for the API/CLI space of > the HPVM product. I also was part of a project that created what HP > calls VirtProvider which was a DSP2013 CIM Provider. Since I knew how > to spell CIM and had some history, I was asked to take a look at > failures that Yanbing Du posted questions about back in October: > > https://www.redhat.com/archives/libvirt-cim/2012-October/msg00000.html > > Sorry in advance for the length of the rest of this... > It is very nice to hear new people comes to libvirt-cim, although the developement slows down but user are still there, it need to be taken care of. Welcome the libvirt-cim project. :). > While this won't be a full time endeavour, putting some cycles on > libvirt-cim has been added to my list of things to do. I still need a > bit of help - I'm not quite sure of the "proper procedure" to use when > testing a local libvirt-cim build. The only way I was able to make > things work was remove the libvirt-cim package (rpm -e) and then > reinstall (yum localinstall from build rpm in a 'make rpm'). I tried the > install/postinstall process with stopping/starting tog-pegasus, but > couldn't quite get things to work. > Using "rpm -e [old rpm]" and "rpm -ivh [new rpm]" should be enough to test new libvirt-cim. I am not sure how you install/postinstall it, in common case of test, these steps are not needed. > Getting "up to speed" was a bit of a challenge as the libvirt CIM web > pages seem to be a bit out of date and perhaps assume a few things along > the way. I've taken some notes, but was eventually able to get things > installed. I'm still working through some of the "kinks". > > Setting up a CIMserver with tog_pegasus was not something I did at HP, > so it was a bit of an adventure. Eventually I worked my way through > things with lots of trial and error. Following the README instructions I > ran into two issues during the post installation phase, which I'm > somewhat curious if long time users would also hit (not that many are > active any more): > I haven't installed it either, always used the rpm. Can't you use "rpm -ivh" to install/replace tog_pegasus? > #1: The commit id '22022870d' to Makefile.am which essentially added > "$(top_srcdir)/" in front of the "schema" directory path caused the > 'make postinstall' to fail (at least on my fedora18 system). The > problem is that the path ends up as ".//usr/..." the "./" being the > problem with respect to the ability to "find" the files. Stripping that > off allows finding files to be found again. The fix is to modify the > various "$(subst schema" and replace them with "$(subst > $(top_srcdir)/schema" - this allowed me to continue. > > #2: After that was solved, as things were scrolling past I noted that > there was some sort of issue with "schema/SwitchService.registration". > In looking at the file, it seems the blank line at the end of the file > caused some sort of "issue", so I removed it and the registration was > happier. > > After those changes I was able to run through the 'cimtest' using the > most recent libvirt (what is looking to be 1.0.3). I didn't see all the > same errors, but did trip across a few. > > Figuring that perhaps some of those were fixed by patches that I knew > were out there, I went back to start looking, applying, and running > cimtest again for tests that failed for me. > > I downloaded and applied the Dec 2012 patches for libvirt-cim (v3 01 -> > 11 and v4 DevicePool) and libcmpiutil (v3 1&2) as well as the Nov 2012 > patch submitted by Jirka. I believe that gets me "up to date". Although > it was a bit confusing as what I should have done for the v4 patches on > 12/25/12 was to "replace" the 12/18/12 patches 6 and 10. Luckily it was > a quick retrace of my steps. > Sorry for the trouble of different versions, glad you replaced the correct patches. :) > Unfortunately it didn't seem I was "using" the changes when I ran > "make", "make preinstall", "make install", & "make postinstall". So, I > figured I'd try to make a new distribution to see if that would work. I > got a bit further; however, the 'make distcheck' failed for me much in > the same way the 'make postinstall' did above. So I adjusted commit id > '9f5e204f' to rather than "$(subst ./schema," use "$(subst > $(top_srcdir)/schema" which resolve the issue I was running into. Once I > did the 'rpm -e libvirt-cim', I was able to install the rpm I build and > test the changes. > I haven't try it on Fedora, but usually on RH I use "make rpm" from source code to build a rpm, then replace the rpm and test. "make install" seems have problem before and I am not sure if it works now, so please use rpm replacing if it work on Fedora. > The (partial) good news is between the fixes provided in the December > patches and some of my own I can get a majority of cimtest to succeed. > I've had to make other adjustments, but I figured that'd be par for the > course anyway. > > So some comments about your changes. Now that I have a little more > experience I'll look at the other changes more in depth, but these two > popped out due to me running into "issues" with them. > > Patch 01/11: > * The change for 'bridge' networks and not allowing scripts is only for > qemu domains. Apparently Xen domains would still support the script. > So while your change does effectively remove it for Qemu, doing so for > Xen could be a regression (I have no way to test). > > See the following for my logic: > > http://www.redhat.com/archives/libvir-list/2012-January/msg00240.html > > Before I had applied your patches I had made a similar change except > that I passed along the dominfo->type to the bridge_net_to_xml() > function and then test in there whether or not the "script" should be > added based on type of DOMAIN_XENPV or DOMAIN_XENFV. This seems a safer way, since we both lack a ENV to test for Xen, If you wish you could form a patch for it, replace mine in the serial. > > > Patch 09/11 > * This change caused the 'make distcheck" to fail. The > 'wait_for_event()' routine has a "ret" variable that is unused. > My bad, this check is not done before. > > Some changes I've made to 'cimtest' in order to get things to work > > * The test makes use of setting a MAC in quite a few places, > unfortunately the MAC chosen for most (99:aa:bb:cc:ee:ff) is a Multicast > Address. We know this because the low bit of the first byte (e.g. "99") > is set (in hex 0x10011001). Changing those references to "88" works. > > * ComputerSystemIndication and RASDIndications fail for me. After a > long pause, I got a Python stack trace where it looks like it's trying > to print testsuite results. What that turns out to be is the > 'os_status' being passed along is the errno value for 'ETIMEDOUT' (eg. > 110). Using 110 to index into the rc[] record in Reporter.py causes a > KeyError exception. I "fixed" that by checking if os_status was outside > of the valid range and if so, set it to FAIL, but log that I did so. > > * Profile/04_verify_libvirt_cim_slp_profiles.py has a bug. It only > checks for "slp" when it should check "slp=true". > Yes, this test case seems need slp server configured correctly and it never passed on my machine, but user of libvirt-cim with slp=true works fine, suggest ignore this case. > * Looking for the NFS Server at /sbin/init.d/nfs doesn't work any more > with the usage of systemd in order to start/stop daemons. I adjusted the > code accordingly > > * The ResourcePoolConfigurationService tests 08, 09, & 15 try to create > a pool pointing at /var/lib/libvirt/images which causes a failure > because cimtest-diskpool already exists and uses it. Not sure if this > is a new check or not (remember I haven't been here that long). Fails also in mine machine, seems a error in cimtest code. > > My current results have 173 of 192 tests passing. There are 4 FAIL, 4 > XFAIL, and 11 SKIP (mostly migration which I haven't figured out yet). > 2 of the SKIP's are because I already had a domains and storage pools > defined on my system. > This is really nice, I have 8 FAIL. Before I ignored them because in error message it shows as testcase issue not libvirt-cim's problem. If you can form patches for cimtest and verify it on RH, pls post them on maillist, they will be very helpful, fixing the problems remains in cimtest for a long time. I am working on qemu dev now but will still pay time for libvirt-cim for bug/patches. If you like you can post your patches and let me review. We really need new libvirt-cim 0.6.2 release fast to eliminate bug reports for old 0.6.1. > > John > > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From jferlan at redhat.com Mon Mar 11 13:34:43 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 09:34:43 -0400 Subject: [Libvirt-cim] [PATCH V3 01/11] remove script for bridge network Message-ID: <513DDD73.9080908@redhat.com> Since I don't have the original email to reply-to for a code review, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00030.html NACK As previously noted, a script is supported (and perhaps required) in the Xen guest. Consider the following, which adds a parameter to the call in order to allow for Xen: -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, + int domtype) { const char *script = "vif-bridge"; xmlNodePtr tmp; const char *msg = NULL; - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); - if (tmp == NULL) - return XML_ERROR; - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + /* Scripts only supported on Xen guests see 'libvirt' + * commit id 1734cdb99 (since 0.9.10) */ + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); + if (tmp == NULL) + return XML_ERROR; + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + } msg = set_net_source(nic, dev, "bridge"); @@ -375,13 +380,13 @@ static const char *net_xml(xmlNodePtr root, struct domain } #endif - if (STREQ(dev->dev.net.type, "network")) + if (STREQ(dev->dev.net.type, "network")) { msg = set_net_source(nic, net, "network"); - else if (STREQ(dev->dev.net.type, "bridge")) - msg = bridge_net_to_xml(nic, net); - else if (STREQ(dev->dev.net.type, "user")) + } else if (STREQ(dev->dev.net.type, "bridge")) { + msg = bridge_net_to_xml(nic, net, dominfo->type); + } else if (STREQ(dev->dev.net.type, "user")) { continue; - else if (STREQ(dev->dev.net.type, "direct")) { + } else if (STREQ(dev->dev.net.type, "direct")) { msg = set_net_source(nic, net, "direct"); if (net->vsi.vsi_type != NULL) { struct vsi_device *vsi = &dev->dev.net.vsi; From jferlan at redhat.com Mon Mar 11 13:40:36 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 09:40:36 -0400 Subject: [Libvirt-cim] [PATCH V3 02/11] do not deregister virt classes in yum upgrade Message-ID: <513DDED4.2020002@redhat.com> Since I don't have the email to reply-to for a review, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00021.html I'm not sure what "$1" is in this context, let's consider setting "$1" to some variable that is more understandable in the context. Furthermore, is "0" a special number/string? How would anyone know reading the code without having knowledge of the code. John From jferlan at redhat.com Mon Mar 11 13:43:20 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 09:43:20 -0400 Subject: [Libvirt-cim] [PATCH V3 03/11] CSI, fix debug print crash Message-ID: <513DDF78.6020704@redhat.com> Since I don't have the email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00028.html ACK From mihajlov at linux.vnet.ibm.com Mon Mar 11 14:30:59 2013 From: mihajlov at linux.vnet.ibm.com (Viktor Mihajlovski) Date: Mon, 11 Mar 2013 15:30:59 +0100 Subject: [Libvirt-cim] [PATCH V3 02/11] do not deregister virt classes in yum upgrade In-Reply-To: <513DDED4.2020002@redhat.com> References: <513DDED4.2020002@redhat.com> Message-ID: <513DEAA3.8020109@linux.vnet.ibm.com> On 03/11/2013 02:40 PM, John Ferlan wrote: > > > I'm not sure what "$1" is in this context, let's consider setting "$1" > to some variable that is more understandable in the context. > Furthermore, is "0" a special number/string? How would anyone know > reading the code without having knowledge of the code. > Hi John, actually this is standard way a %post or %pre scripts are handled by RPM: the single parameter tells the scripts whether they are called during a clean install/uninstall or an update. See http://www.rpm.org/max-rpm/s1-rpm-inside-scripts.html for reference. -- Mit freundlichen Gr??en/Kind Regards Viktor Mihajlovski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martin Jetter Gesch?ftsf?hrung: Dirk Wittkopp Sitz der Gesellschaft: B?blingen Registergericht: Amtsgericht Stuttgart, HRB 243294 From jferlan at redhat.com Mon Mar 11 14:41:27 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 10:41:27 -0400 Subject: [Libvirt-cim] [PATCH V3 04/11] CSI, add lock to protect shared data Message-ID: <513DED17.4010407@redhat.com> Since I don't have the email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00026.html Why was the decision to reuse the lifecycle_mutex rather than generating a data specific mutex? Seems like that mutex is used for other operations to protect filters and indications. Thus unless the two are somehow tied, I really think it'd be better to create/use a data specific mutex. Furthermore, there's a few mutex adds around thread mgmt that probably should be a separate patch. That is - the non "dom_list" protection additions appear to be different. John From jferlan at redhat.com Mon Mar 11 14:42:43 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 10:42:43 -0400 Subject: [Libvirt-cim] [PATCH V3 05/11] DevicePool, fix debug print crash Message-ID: <513DED63.8070004@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00024.html ACK From jferlan at redhat.com Mon Mar 11 14:46:51 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 10:46:51 -0400 Subject: [Libvirt-cim] [PATCH V3 06/11] DevicePool, reimplement get_diskpool_config with libvirt Message-ID: <513DEE5B.2030009@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00023.html NACK this since it's replaced by: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00039.html I will review that one separately. John From jferlan at redhat.com Mon Mar 11 15:06:31 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 11:06:31 -0400 Subject: [Libvirt-cim] [PATCH V3 07/11] RASDIndication, fix debug print crash Message-ID: <513DF2F7.4040402@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00027.html ACK Although the 3 of these could be "one patch" realistically since they fix the same problem. I know there are a lot of calls to CU_DEBUG, perhaps it'd be best to go through all of them to make sure there are no other similar issues lurking. John From jferlan at redhat.com Mon Mar 11 15:24:58 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 11:24:58 -0400 Subject: [Libvirt-cim] [PATCH V3 08/11] device parsing, add debug print Message-ID: <513DF74A.5090207@redhat.com> Since I didn't have the original email to reply-to, here is the link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00029.html Should the following return 0 as well?: + if (ret != 1) { + CU_DEBUG("Failed to translate xml into struct domain"); + } Especially since get_dominfo_from_xml() will free and initialize dominfo to NULL. You'll also need a "free(xml);" if you return. That's a memory leak. What probably should be done is (btw: 8 space tabs are hard to do!) ret = get_dominfo_from_xml(xml, dominfo); if (ret == 0) { CU_DEBUG("Failed to translate xml into struct domain"); goto out; } ret = virDomainGetAutostart(dom, &start); if (ret != 0) { CU_DEBUG("Failed to get dom autostart with libvirt API."); goto out; } (*dominfo)->autostrt = start; out: free(xml); return ret; John From jferlan at redhat.com Mon Mar 11 17:22:51 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 13:22:51 -0400 Subject: [Libvirt-cim] [PATCH V3 09/11] CSI Discard libvirt event by default Message-ID: <513E12EB.9030401@redhat.com> Since I don't have the original email to reply-to, here is the link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00032.html Seems this was "pulled back" from some other commit - might be nice to reference the commit id where it was removed and now replaced - at least for historical purposes. src/Virt_ComputerSystem.c In trigger_mod_indication() * The "goto out" if/when "(ind == NULL)" will perhaps trigger a false positive this succeeded since "s" is initialized to CMPI_RC_OK. src/Virt_ComputerSystemIndication.c In doms_to_xml(), * the calloc() has no check for successful return of memory leading to possible NULL pointer deref of *dom_xml_list. In async_ind_native(): * The CU_DEBUG() message "...indication diliv..." should be "...indication delivery..." * The CU_DEBUG("Unrecognized indication type"); should report what 'ind_type' is (btw: it's unrecognised) In lifecycle_thread_native(): * Seems inefficient to traverse lists so many times. In the for loop running through prev_xml, it would seem that if 'dom_in_list()' returns 1, then we could call 'dom_changed()' and possibly 'async_ind_native()' if it has changed. * Since this routine keeps lifecycle_mutex for the duration - I believe it makes it even more important to separate it from 'dom_list' in your previous change... NOTE: the get_domain_list() call could be made better by getting all "Active and Defined" domains in one virConnectListAllDomains() call, but that's mostly unrelated to this code. Getting the list of All domains at one time is "preferred" since you won't run into odd timing issues by making two calls. In raise_indication() * The returns for the strdup()'s are not checked. John From jferlan at redhat.com Mon Mar 11 17:24:13 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 13:24:13 -0400 Subject: [Libvirt-cim] [PATCH V3 10/11] VSSD, fix a error report issue in VSSD enum Message-ID: <513E133D.9040706@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00031.html NACK since this has been replaced by: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00038.html Which I will review separately. John From jferlan at redhat.com Mon Mar 11 19:18:58 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 15:18:58 -0400 Subject: [Libvirt-cim] [PATCH V3 11/11] allow ssh based migration with non root's key file Message-ID: <513E2E22.3040001@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00033.html libvirt-cim.conf Consider changing the following: +# Defines a temp key file which would be used as ssh key in ssh migration, +# Only valid when SSH_Key is set in migration call. +# If SSH_Key is not in a directory owned by root, set this value to a path +# owned by root, tells libvirt-cim copy it there before use it. The directory +# in the path must exist and totally owned by root. +# If SSH_Key is already in a valid place, don't set it to to tell libvirt-cim +# use SSH_Key directly. # Only valid when SSH_Key is set for the migration call. # # In order to allow using a non-root owned SSH Key during migration, set this variable # to a location to copy the SSH_Key from the SSH_Key path and file not owned by root # to a directory path and file owned by root. The target path must exist and it must # be owned by root. If it is not, the migration will fail. # # If the SSH_Key is already in a directory owned by root there is no need to set, thus # allowing libvirt-cim to use the SSH_Key directly. libxkutil/misc_util.c In libvirt_cim_config_get() * The 'default:' case should probably also which prop->name was being used for the prop->value_type In is_read_only() & get_mig_ssh_tmp_key() * Probably should initialize prop.value_string = NULL just to be clear * Call to libvirt_cim_config_get() does not check return status - perhaps make setting prop.have_read conditional on return value... src/Virt_VSMigrationService.c In ssh_key_cp(): * Do you need a path to 'cp' (eg /sbin/cp)? * Is it worth a stat() afterwards to ensure the copy occurred since your fgets() isn't returning anything? * Other thoughts - should there be a "stat" and "rm" before? Perhaps another safety ensure we copy something? In get_msd_values() * Since you already print the source ssh_key file, change the the copy src to dest message to just indicate the destination (e.g. "Copying ssh key to '%s'.", tmp_keyfile) So let's say this is successful, now we leave the 'migrate_ssh_temp_key' around? Is that a good idea? Shouldn't there be a corresponding 'unlink()' after we're done? We're really not a "temporary" file if we keep it around. In fact, after the connection is made, shouldn't we be able to safely delete the file? John Finally, this one seems to require/need an update to documentation "somewhere" to describe that new conf variable... That is how does one know how to use this unless they read the conf file? From jferlan at redhat.com Mon Mar 11 20:24:01 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 16:24:01 -0400 Subject: [Libvirt-cim] [PATCH V4] DevicePool, reimplement get_diskpool_config with libvirt Message-ID: <513E3D61.9020801@redhat.com> Since I don't have an email to reply-to, here is the link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00039.html In get_diskpool_config(): * Rather than use the "racy" NumOfStoragePools and ListStoragePools, why not use virConnectListAllStoragePools() passing the "Active" flag for all active pools only? * You may even want to consider keeping the returned virStoragePoolPtr structures around.. I also imagine the other objects (networks and domains) could use the similar calls. I guess the answer somewhat depends on what is the minimum version of libvirt that needs to be supported. But if you "have" to stay with the current model... * The return 'names[i]' is something you'd have to free() anyway, so rather than strdup(names[i]), just take it when setting pools[i].tag and set names[i] = NULL; That avoids an error path. John From jferlan at redhat.com Mon Mar 11 20:54:58 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 16:54:58 -0400 Subject: [Libvirt-cim] [PATCH V4] VSSD, fix a error report issue in VSSD enum Message-ID: <513E44A2.1030601@redhat.com> Since I don't have the original email to reply-to, here is a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00038.html In instance_from_dom(): * virDomainIsActive returns: Returns 1 if running, 0 if inactive, -1 on error. You are testing for < 0 (error condition) and an else with no determination about whether it's really active or not. Your comments in the code and the CU_DEBUG statements don't seem to sync. How is VSSD_RECOVERABLE true when active = -1? NOTE: In looking at get_dominfo() again - and thinking about this as a caller - why does it matter if autostart is set or not? I really think the "get_domain_list()" should change to use virConnectListAllDomains() - it may solve more timing issues. John From jferlan at redhat.com Mon Mar 11 21:02:42 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 17:02:42 -0400 Subject: [Libvirt-cim] [PATCH V3 00/11] bug fix and enhancement patch rebase for 6.2 Message-ID: <513E4672.90103@redhat.com> Now that I've gone through the series - hopefully that gives you enough to put out another series. Once we get through it, then we can work with DV in order to go through the next steps. I'll look at the libcmpiutil changes next. John From jferlan at redhat.com Mon Mar 11 21:03:54 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 17:03:54 -0400 Subject: [Libvirt-cim] [PATCH V3 1/2] libcmpiutil: fix potential debug print crash Message-ID: <513E46BA.8020506@redhat.com> Since I don't have the original email to reply-to, here's a link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00019.html ACK John From jferlan at redhat.com Mon Mar 11 21:14:23 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 11 Mar 2013 17:14:23 -0400 Subject: [Libvirt-cim] [PATCH V3 2/2] libcmpiutil: add time and thread info in debug log Message-ID: <513E492F.4050202@redhat.com> Since I don't have the original email to reply-to, here's the link: https://www.redhat.com/archives/libvirt-cim/2012-December/msg00020.html ACK From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:08:18 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:08:18 +0800 Subject: [Libvirt-cim] [PATCH V3 01/11] remove script for bridge network In-Reply-To: <513DDD73.9080908@redhat.com> References: <513DDD73.9080908@redhat.com> Message-ID: <513EB842.9010500@linux.vnet.ibm.com> ? 2013-3-11 21:34, John Ferlan ??: > > Since I don't have the original email to reply-to for a code review, here is a link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00030.html > > NACK > > As previously noted, a script is supported (and perhaps required) in the Xen guest. > > Consider the following, which adds a parameter to the call in order to allow for Xen: > Agree with your approach, please "git send-email" your patch. > > -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) > +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, > + int domtype) > { > const char *script = "vif-bridge"; > xmlNodePtr tmp; > const char *msg = NULL; > > - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); > - if (tmp == NULL) > - return XML_ERROR; > - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); > + /* Scripts only supported on Xen guests see 'libvirt' > + * commit id 1734cdb99 (since 0.9.10) */ > + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { > + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); > + if (tmp == NULL) > + return XML_ERROR; > + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); > + } > > msg = set_net_source(nic, dev, "bridge"); > > @@ -375,13 +380,13 @@ static const char *net_xml(xmlNodePtr root, struct domain > } > #endif > > - if (STREQ(dev->dev.net.type, "network")) > + if (STREQ(dev->dev.net.type, "network")) { > msg = set_net_source(nic, net, "network"); > - else if (STREQ(dev->dev.net.type, "bridge")) > - msg = bridge_net_to_xml(nic, net); > - else if (STREQ(dev->dev.net.type, "user")) > + } else if (STREQ(dev->dev.net.type, "bridge")) { > + msg = bridge_net_to_xml(nic, net, dominfo->type); > + } else if (STREQ(dev->dev.net.type, "user")) { > continue; > - else if (STREQ(dev->dev.net.type, "direct")) { > + } else if (STREQ(dev->dev.net.type, "direct")) { > msg = set_net_source(nic, net, "direct"); > if (net->vsi.vsi_type != NULL) { > struct vsi_device *vsi = &dev->dev.net.vsi; > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:10:36 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:10:36 +0800 Subject: [Libvirt-cim] [PATCH V3 04/11] CSI, add lock to protect shared data In-Reply-To: <513DED17.4010407@redhat.com> References: <513DED17.4010407@redhat.com> Message-ID: <513EB8CC.4090103@linux.vnet.ibm.com> ? 2013-3-11 22:41, John Ferlan ??: > > Since I don't have the email to reply-to, here is a link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00026.html > > > Why was the decision to reuse the lifecycle_mutex rather than generating > a data specific mutex? Seems like that mutex is used for other > operations to protect filters and indications. Thus unless the two are > somehow tied, I really think it'd be better to create/use a data > specific mutex. > > Furthermore, there's a few mutex adds around thread mgmt that probably > should be a separate patch. That is - the non "dom_list" protection > additions appear to be different. > > John > It is just the quickest way to fix bug, it should be a separate lock just as mentioned in the commit message for performance, you can form a patch to fix it above or replace this patch. > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:14:16 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:14:16 +0800 Subject: [Libvirt-cim] [PATCH V3 08/11] device parsing, add debug print In-Reply-To: <513DF74A.5090207@redhat.com> References: <513DF74A.5090207@redhat.com> Message-ID: <513EB9A8.5090002@linux.vnet.ibm.com> ? 2013-3-11 23:24, John Ferlan ??: > > Since I didn't have the original email to reply-to, here is the link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00029.html > > Should the following return 0 as well?: > > + if (ret != 1) { > + CU_DEBUG("Failed to translate xml into struct domain"); > + } > > Especially since get_dominfo_from_xml() will free and initialize dominfo to NULL. > > You'll also need a "free(xml);" if you return. That's a memory leak. > > What probably should be done is (btw: 8 space tabs are hard to do!) > > > ret = get_dominfo_from_xml(xml, dominfo); > if (ret == 0) { > CU_DEBUG("Failed to translate xml into struct domain"); > goto out; > } > ret = virDomainGetAutostart(dom, &start); > if (ret != 0) { > CU_DEBUG("Failed to get dom autostart with libvirt API."); > goto out; > } > (*dominfo)->autostrt = start; > > out: > free(xml); > > return ret; > > > > > > John > Yes, this seems fine. > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:30:22 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:30:22 +0800 Subject: [Libvirt-cim] [PATCH V3 09/11] CSI Discard libvirt event by default In-Reply-To: <513E12EB.9030401@redhat.com> References: <513E12EB.9030401@redhat.com> Message-ID: <513EBD6E.2050508@linux.vnet.ibm.com> ? 2013-3-12 1:22, John Ferlan ??: > > Since I don't have the original email to reply-to, here is the link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00032.html > > Seems this was "pulled back" from some other commit - might be nice to > reference the commit id where it was removed and now replaced - at least > for historical purposes. > > > src/Virt_ComputerSystem.c > > In trigger_mod_indication() > * The "goto out" if/when "(ind == NULL)" will perhaps trigger a false > positive this succeeded since "s" is initialized to CMPI_RC_OK. > This is a problem, sorry haven't check it out since the code is copied from old version. > > > src/Virt_ComputerSystemIndication.c > > In doms_to_xml(), > > * the calloc() has no check for successful return of memory leading to > possible NULL pointer deref of *dom_xml_list. > > > In async_ind_native(): > * The CU_DEBUG() message "...indication diliv..." should be > "...indication delivery..." > * The CU_DEBUG("Unrecognized indication type"); should report what > 'ind_type' is (btw: it's unrecognised) > > In lifecycle_thread_native(): > * Seems inefficient to traverse lists so many times. In the for loop > running through prev_xml, it would seem that if 'dom_in_list()' returns > 1, then we could call 'dom_changed()' and possibly 'async_ind_native()' > if it has changed. The logic is from old version;s code, I must admit there are space to optimize for performance. > * Since this routine keeps lifecycle_mutex for the duration - I believe > it makes it even more important to separate it from 'dom_list' in your > previous change... > This is not needed, the CSI from libvirt-cim/libvirt can be activated only one at one time. Actually this patch disabled previous libvirt CSI event feature, with a macro it can be activated again when we found the real problem below later. > NOTE: the get_domain_list() call could be made better by getting all > "Active and Defined" domains in one virConnectListAllDomains() call, but > that's mostly unrelated to this code. Getting the list of All domains > at one time is "preferred" since you won't run into odd timing issues by > making two calls. > > In raise_indication() > * The returns for the strdup()'s are not checked. > > John > Please form a patch based on mine if you wish, to fix these problems, I am a bit too busy to rewrite the code.... > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:53:19 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:53:19 +0800 Subject: [Libvirt-cim] [PATCH V3 11/11] allow ssh based migration with non root's key file In-Reply-To: <513E2E22.3040001@redhat.com> References: <513E2E22.3040001@redhat.com> Message-ID: <513EC2CF.4010308@linux.vnet.ibm.com> ? 2013-3-12 3:18, John Ferlan ??: > > Since I don't have the original email to reply-to, here is a link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00033.html > > > libvirt-cim.conf > > Consider changing the following: > > +# Defines a temp key file which would be used as ssh key in ssh migration, > +# Only valid when SSH_Key is set in migration call. > +# If SSH_Key is not in a directory owned by root, set this value to a path > +# owned by root, tells libvirt-cim copy it there before use it. The directory > +# in the path must exist and totally owned by root. > +# If SSH_Key is already in a valid place, don't set it to to tell libvirt-cim > +# use SSH_Key directly. > > > # Only valid when SSH_Key is set for the migration call. > # > # In order to allow using a non-root owned SSH Key during migration, set this variable > # to a location to copy the SSH_Key from the SSH_Key path and file not owned by root > # to a directory path and file owned by root. The target path must exist and it must > # be owned by root. If it is not, the migration will fail. > # > # If the SSH_Key is already in a directory owned by root there is no need to set, thus > # allowing libvirt-cim to use the SSH_Key directly. > > > > > > libxkutil/misc_util.c > > In libvirt_cim_config_get() > * The 'default:' case should probably also which prop->name was being used for the prop->value_type > do you mean check prop->name == NULL? > In is_read_only() & get_mig_ssh_tmp_key() > * Probably should initialize prop.value_string = NULL just to be clear OK to add but not necessary, since they are declared as static and will be initialized by default. But a comment in API libvirt_cim_config_get() as "*prop must be initialized with valid default value" seems good to tip caller. > * Call to libvirt_cim_config_get() does not check return status - perhaps make setting prop.have_read conditional on return value... > This will make the process continue reading config when a property do not exist, reduce performance. Instead of that, I think it is right to read only once when boot up. If user modify the config, he can reboot the process. > > src/Virt_VSMigrationService.c > In ssh_key_cp(): > * Do you need a path to 'cp' (eg /sbin/cp)? Possible ,maybe a config as "CP=/sbin/cp"? > * Is it worth a stat() afterwards to ensure the copy occurred since your fgets() isn't returning anything? good idea. > * Other thoughts - should there be a "stat" and "rm" before? Perhaps another safety ensure we copy something? good idea to avoid reimplement "popen". > > In get_msd_values() > * Since you already print the source ssh_key file, change the the copy src to dest message to just indicate the destination (e.g. "Copying ssh key to '%s'.", tmp_keyfile) > It is OK to do so. > > So let's say this is successful, now we leave the 'migrate_ssh_temp_key' around? Is that a good idea? Shouldn't there be a corresponding 'unlink()' after we're done? We're really not a "temporary" file if we keep it around. In fact, after the connection is made, shouldn't we be able to safely delete the file? > I don't think delete is needed, since the model of provider to run. In actually case the user may start dozens of threads with one key, delete in one thread while other thread is still using it,may cause exception. This is the user's responsibility to clean it since he knows where it would be copied to in config file, we just need to document it. > > John > > > Finally, this one seems to require/need an update to documentation "somewhere" to describe that new conf variable... That is how does one know how to use this unless they read the conf file? > In normal case yes a page will be good, but now we have only config file as documents. I think config file can play the role well now. > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 05:57:44 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 13:57:44 +0800 Subject: [Libvirt-cim] [PATCH V4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <513E3D61.9020801@redhat.com> References: <513E3D61.9020801@redhat.com> Message-ID: <513EC3D8.7060200@linux.vnet.ibm.com> ? 2013-3-12 4:24, John Ferlan ??: > > Since I don't have an email to reply-to, here is the link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00039.html > > > > In get_diskpool_config(): > > * Rather than use the "racy" NumOfStoragePools and ListStoragePools, why > not use virConnectListAllStoragePools() passing the "Active" flag for > all active pools only? > Let me check if the version of minium libvirt requirement in configure, to see if the API exist. > * You may even want to consider keeping the returned virStoragePoolPtr > structures around.. > > > > I also imagine the other objects (networks and domains) could use the > similar calls. I guess the answer somewhat depends on what is the > minimum version of libvirt that needs to be supported. > Yep, that is the problem. To limit the work, I guess other change for networks and domains should be separate patches, if we decide they are worthy. > But if you "have" to stay with the current model... > > * The return 'names[i]' is something you'd have to free() anyway, so > rather than strdup(names[i]), just take it when setting pools[i].tag and > set names[i] = NULL; That avoids an error path. > let me check. > > > John > > > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 06:05:51 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 14:05:51 +0800 Subject: [Libvirt-cim] [PATCH V4] VSSD, fix a error report issue in VSSD enum In-Reply-To: <513E44A2.1030601@redhat.com> References: <513E44A2.1030601@redhat.com> Message-ID: <513EC5BF.5040405@linux.vnet.ibm.com> ? 2013-3-12 4:54, John Ferlan ??: > > Since I don't have the original email to reply-to, here is a link: > > https://www.redhat.com/archives/libvirt-cim/2012-December/msg00038.html > > > > In instance_from_dom(): > * virDomainIsActive returns: Returns 1 if running, 0 if inactive, -1 on > error. You are testing for < 0 (error condition) and an else with no > determination about whether it's really active or not. Your comments in > the code and the CU_DEBUG statements don't seem to sync. How is > VSSD_RECOVERABLE true when active = -1? > logic is: ret = get_dominfo(dom, &dominfo); if (!ret) { int active = virDomainIsActive(dom); if (active < 0) { /* ret > 1 indicate that it is recoverable */ CU_DEBUG("Failed to get dominfo, " "domain may not be active anymore."); ret = VSSD_ERROR_RECOVERABLE; } else { CU_DEBUG("Failed to get dominfo."); } goto out; } if it get_dominfo() fail, then check the reason. if virDomainIsActive() returns negative also, that means domain may not exist. if it succeed, but get_dominfo() fail, that means somethings bad happen below. I know this seems inreasonable, but I did observe the case for one VM, while it shows active but get xml fail, for underlining storage issue, in stress test. This is not perfect, let me check virConnectListAllDomains() case. > NOTE: In looking at get_dominfo() again - and thinking about this as a > caller - why does it matter if autostart is set or not? > > I really think the "get_domain_list()" should change to use > virConnectListAllDomains() - it may solve more timing issues. > Yep, let me check the API version of libvirt. > > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 12 06:09:28 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 12 Mar 2013 14:09:28 +0800 Subject: [Libvirt-cim] [PATCH V3 00/11] bug fix and enhancement patch rebase for 6.2 In-Reply-To: <513E4672.90103@redhat.com> References: <513E4672.90103@redhat.com> Message-ID: <513EC698.5010609@linux.vnet.ibm.com> ? 2013-3-12 5:02, John Ferlan ??: > > Now that I've gone through the series - hopefully that gives you enough > to put out another series. Once we get through it, then we can work with > DV in order to go through the next steps. > > I'll look at the libcmpiutil changes next. > Great thanks to your review, I am busy in another work now and will start coding it next week. You can "git send-email" the patches with your name if you like, such as "remove bridge script", and I will review and include it in "V5". > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Wed Mar 13 02:19:31 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Wed, 13 Mar 2013 10:19:31 +0800 Subject: [Libvirt-cim] [PATCH V3 11/11] allow ssh based migration with non root's key file In-Reply-To: <513EC2CF.4010308@linux.vnet.ibm.com> References: <513E2E22.3040001@redhat.com> <513EC2CF.4010308@linux.vnet.ibm.com> Message-ID: <513FE233.50002@linux.vnet.ibm.com> ? 2013-3-12 13:53, Wenchao Xia ??: > ? 2013-3-12 3:18, John Ferlan ??: >> >> Since I don't have the original email to reply-to, here is a link: >> >> https://www.redhat.com/archives/libvirt-cim/2012-December/msg00033.html >> >> >> libvirt-cim.conf >> >> Consider changing the following: >> >> +# Defines a temp key file which would be used as ssh key in ssh >> migration, >> +# Only valid when SSH_Key is set in migration call. >> +# If SSH_Key is not in a directory owned by root, set this value to >> a path >> +# owned by root, tells libvirt-cim copy it there before use it. The >> directory >> +# in the path must exist and totally owned by root. >> +# If SSH_Key is already in a valid place, don't set it to to tell >> libvirt-cim >> +# use SSH_Key directly. >> >> >> # Only valid when SSH_Key is set for the migration call. >> # >> # In order to allow using a non-root owned SSH Key during migration, >> set this variable >> # to a location to copy the SSH_Key from the SSH_Key path and file not >> owned by root >> # to a directory path and file owned by root. The target path must >> exist and it must >> # be owned by root. If it is not, the migration will fail. >> # >> # If the SSH_Key is already in a directory owned by root there is no >> need to set, thus >> # allowing libvirt-cim to use the SSH_Key directly. >> >> >> >> >> >> libxkutil/misc_util.c >> >> In libvirt_cim_config_get() >> * The 'default:' case should probably also which prop->name was >> being used for the prop->value_type >> > do you mean check prop->name == NULL? > >> In is_read_only() & get_mig_ssh_tmp_key() >> * Probably should initialize prop.value_string = NULL just to be clear > OK to add but not necessary, since they are declared as static and > will be initialized by default. But a comment in API > libvirt_cim_config_get() as "*prop must be initialized with valid > default value" seems good to tip caller. > >> * Call to libvirt_cim_config_get() does not check return status - >> perhaps make setting prop.have_read conditional on return value... >> > This will make the process continue reading config when a property > do not exist, reduce performance. Instead of that, I think it is right > to read only once when boot up. If user modify the config, he > can reboot the process. > >> >> src/Virt_VSMigrationService.c >> In ssh_key_cp(): >> * Do you need a path to 'cp' (eg /sbin/cp)? > Possible ,maybe a config as "CP=/sbin/cp"? > >> * Is it worth a stat() afterwards to ensure the copy occurred since >> your fgets() isn't returning anything? > good idea. > >> * Other thoughts - should there be a "stat" and "rm" before? Perhaps >> another safety ensure we copy something? > good idea to avoid reimplement "popen". > After recheck, I think "rm" can't be used here, it have a risk to break other thread. I guess better to provide a new method in the class: copy_ssh_key(char *path_src); delete_ssh_key(); Let the user call it manually. >> >> In get_msd_values() >> * Since you already print the source ssh_key file, change the the >> copy src to dest message to just indicate the destination (e.g. >> "Copying ssh key to '%s'.", tmp_keyfile) >> > It is OK to do so. > >> >> So let's say this is successful, now we leave the >> 'migrate_ssh_temp_key' around? Is that a good idea? Shouldn't there >> be a corresponding 'unlink()' after we're done? We're really not a >> "temporary" file if we keep it around. In fact, after the connection >> is made, shouldn't we be able to safely delete the file? >> > I don't think delete is needed, since the model of provider to run. > In actually case the user may start dozens of threads with one key, > delete in one thread while other thread is still using it,may > cause exception. This is the user's responsibility to clean > it since he knows where it would be copied to in config file, > we just need to document it. > >> >> John >> >> >> Finally, this one seems to require/need an update to documentation >> "somewhere" to describe that new conf variable... That is how does >> one know how to use this unless they read the conf file? >> > In normal case yes a page will be good, but now we have only config > file as documents. I think config file can play the role well now. > >> >> _______________________________________________ >> Libvirt-cim mailing list >> Libvirt-cim at redhat.com >> https://www.redhat.com/mailman/listinfo/libvirt-cim >> > > -- Best Regards Wenchao Xia From jferlan at redhat.com Thu Mar 14 22:55:53 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:53 -0400 Subject: [Libvirt-cim] [PATCH 01/10] Remove empty newline at bottom In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-2-git-send-email-jferlan@redhat.com> --- schema/SwitchService.registration | 1 - 1 file changed, 1 deletion(-) diff --git a/schema/SwitchService.registration b/schema/SwitchService.registration index b8e4f23..82a5c04 100644 --- a/schema/SwitchService.registration +++ b/schema/SwitchService.registration @@ -3,4 +3,3 @@ Xen_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance KVM_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance LXC_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance - -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:52 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:52 -0400 Subject: [Libvirt-cim] [PATCH 00/10] Adjustments based on recent review Message-ID: <1363301762-31091-1-git-send-email-jferlan@redhat.com> As requested here is a series of patches to address a couple of issues I discovered during my initial foray into using libvirt-cim as well as from my code review. These are all *based on* the code I reviewed. Feel free to pick, choose, and apply. I have run them on my f18 system and things seem to work, but it's possible I've made a configuration error. I also will have a series of cimtest fixes, but I need to tidy them up a bit before sending. I did figure out that rather than uninstalling and reinstalling the package, I can use make preuninstall, make preinstall, restart the CIMOM, make install, and make postinsall which seems to replace the mofs "mostly correctly". There is an error in the postinstall phase which I haven't had the cycles to chase yet. John Ferlan (10): Remove empty newline at bottom Makefile.am: Remove the $(top_srcdir) from subst command xmlgen: Only support script on bridge for xen domains CSI: Fix bug found during 'make distcheck' Makefile.am: Use the top_srcdir rather than direct path in subst libxkutil: Use virConnectListAllDomains() to fetch domains libvirt-cim.spec: Use systemctl for tog-pegasus restart libxkutil: Adjust get_dominfo() logic DevicePool: Use the virConnectListAll interfaces register: Adjust the chatter output Makefile.am | 18 +++--- libvirt-cim.spec.in | 10 ++- libxkutil/cs_util_instance.c | 23 +++++++ libxkutil/device_parsing.c | 10 +-- libxkutil/xmlgen.c | 25 +++++--- provider-register.sh | 9 +-- schema/SwitchService.registration | 1 - src/Virt_ComputerSystemIndication.c | 4 ++ src/Virt_DevicePool.c | 121 +++++++++++++++++++++++++++++++++++- 9 files changed, 190 insertions(+), 31 deletions(-) -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:56 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:56 -0400 Subject: [Libvirt-cim] [PATCH 04/10] CSI: Fix bug found during 'make distcheck' In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-5-git-send-email-jferlan@redhat.com> The 'ret' variable was set, but never checked. Caller never checks returned status anyway. --- src/Virt_ComputerSystemIndication.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 6b5cdd4..4c087c4 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -726,6 +726,10 @@ static bool wait_for_event(int wait_time) ret = pthread_cond_timedwait(&lifecycle_cond, &lifecycle_mutex, &timeout); + if (ret != 0) { + CU_DEBUG("timed wait failed with ret = %d", ret); + return false; + } return true; } -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:55 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:55 -0400 Subject: [Libvirt-cim] [PATCH 03/10] xmlgen: Only support script on bridge for xen domains In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-4-git-send-email-jferlan@redhat.com> A change was made in 0.9.10 to disallow a script on a bridge device for qemu guests, see 'libvirt' commit id '1734cdb99'. --- libxkutil/xmlgen.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c index 2dcd0d2..099fdd2 100644 --- a/libxkutil/xmlgen.c +++ b/libxkutil/xmlgen.c @@ -270,16 +270,21 @@ static const char *set_net_source(xmlNodePtr nic, } -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, + int domtype) { const char *script = "vif-bridge"; xmlNodePtr tmp; const char *msg = NULL; - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); - if (tmp == NULL) - return XML_ERROR; - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + /* Scripts only supported on Xen guests see 'libvirt' + * commit id 1734cdb99 (since 0.9.10) */ + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); + if (tmp == NULL) + return XML_ERROR; + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + } msg = set_net_source(nic, dev, "bridge"); @@ -375,13 +380,13 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo) } #endif - if (STREQ(dev->dev.net.type, "network")) + if (STREQ(dev->dev.net.type, "network")) { msg = set_net_source(nic, net, "network"); - else if (STREQ(dev->dev.net.type, "bridge")) - msg = bridge_net_to_xml(nic, net); - else if (STREQ(dev->dev.net.type, "user")) + } else if (STREQ(dev->dev.net.type, "bridge")) { + msg = bridge_net_to_xml(nic, net, dominfo->type); + } else if (STREQ(dev->dev.net.type, "user")) { continue; - else if (STREQ(dev->dev.net.type, "direct")) { + } else if (STREQ(dev->dev.net.type, "direct")) { msg = set_net_source(nic, net, "direct"); if (net->vsi.vsi_type != NULL) { struct vsi_device *vsi = &dev->dev.net.vsi; -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:54 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:54 -0400 Subject: [Libvirt-cim] [PATCH 02/10] Makefile.am: Remove the $(top_srcdir) from subst command In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-3-git-send-email-jferlan@redhat.com> During the postinstall and preuninstall phases various variables are modified to build up the list of mofs to be installed. The generated output had ".//usr/local/share/libvirt-cim/*" which caused issues finding files. This is a followup to commit '22022870' which changed the paths using to schema for each of the variables. --- Makefile.am | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0fdd8bb..b7ee230 100644 --- a/Makefile.am +++ b/Makefile.am @@ -206,21 +206,21 @@ preinstall: # Un/Register the providers and class definitions from/to the current CIMOM. # @CIMSERVER@ is set by the configure script postinstall: - sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi virsh -v | grep -q '^0.3' && cp examples/diskpool.conf $(DISK_POOL_CONFIG) || true mkdir -p $(INFO_STORE) preuninstall: - sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi rpm: clean -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:56:00 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:56:00 -0400 Subject: [Libvirt-cim] [PATCH 08/10] libxkutil: Adjust get_dominfo() logic In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-9-git-send-email-jferlan@redhat.com> Need to really handle the error on the get_dominfo_from_xml() call Need to be sure to free(xml) before returning --- libxkutil/device_parsing.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index 2841662..264d4cc 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -1246,7 +1246,7 @@ int get_dominfo_from_xml(const char *xml, struct domain **dominfo) int get_dominfo(virDomainPtr dom, struct domain **dominfo) { char *xml; - int ret; + int ret = 0; int start; xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); @@ -1256,17 +1256,19 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo) return 0; } - ret = get_dominfo_from_xml(xml, dominfo); - if (ret != 1) { + if (get_dominfo_from_xml(xml, dominfo) == 0) { CU_DEBUG("Failed to translate xml into struct domain"); + goto out; } if (virDomainGetAutostart(dom, &start) != 0) { CU_DEBUG("Failed to get dom autostart with libvirt API."); - return 0; + goto out; } (*dominfo)->autostrt = start; + ret = 1; + out: free(xml); return ret; -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:59 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:59 -0400 Subject: [Libvirt-cim] [PATCH 07/10] libvirt-cim.spec: Use systemctl for tog-pegasus restart In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-8-git-send-email-jferlan@redhat.com> For Fedora 17 and RHEL7 use systemd, so change the pegasus startup to use that and make a dependency upon it. --- libvirt-cim.spec.in | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in index 7652dee..0679d7f 100644 --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -27,6 +27,9 @@ BuildRequires: libconfig-devel BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 +BuildRequires: systemd-units +%endif BuildConflicts: sblim-cmpi-devel %description @@ -85,7 +88,12 @@ rm -fr $RPM_BUILD_ROOT %{_datadir}/%{name}/install_base_schema.sh %{_datadir}/%{name} -/etc/init.d/tog-pegasus condrestart +# Fedora 17 / RHEL-7 are first where we use systemd. +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 + systemctl restart tog-pegasus +%else + /etc/init.d/tog-pegasus condrestart +%endif %{_datadir}/%{name}/provider-register.sh -t pegasus \ -n @CIM_VIRT_NS@ \ -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:57 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:57 -0400 Subject: [Libvirt-cim] [PATCH 05/10] Makefile.am: Use the top_srcdir rather than direct path in subst In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-6-git-send-email-jferlan@redhat.com> This is a followup to '9f5e204f' which directly added the './' to the schema path. Use of top_srcdir instead just symbolizes things. --- Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile.am b/Makefile.am index b7ee230..63ed3c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,7 +189,7 @@ install-data-local: $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_MOFS) $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_REGS) if [[ @CIMSERVER@ != pegasus ]]; then \ - sed -i '/^# --/,/^# --!/d' $(subst ./schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ + sed -i '/^# --/,/^# --!/d' $(subst $(top_srcdir)/schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ fi uninstall-local: -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:55:58 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:55:58 -0400 Subject: [Libvirt-cim] [PATCH 06/10] libxkutil: Use virConnectListAllDomains() to fetch domains In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-7-git-send-email-jferlan@redhat.com> This is an optimization over using the multistep approach to get a count, get some memory, and get the list of domains (active and defined). Followed other examples to ensure only building the code if the libvirt version is correct. The API was added in 0.9.13. --- libxkutil/cs_util_instance.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/libxkutil/cs_util_instance.c b/libxkutil/cs_util_instance.c index a383147..e34c05d 100644 --- a/libxkutil/cs_util_instance.c +++ b/libxkutil/cs_util_instance.c @@ -34,6 +34,28 @@ #include int get_domain_list(virConnectPtr conn, virDomainPtr **_list) +#if LIBVIR_VERSION_NUMBER >= 9013 +{ + virDomainPtr *nameList = NULL; + int n_names; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names > 0) { + *_list = nameList; + } else if (n_names == 0) { + /* Since there are no elements, no domain ptrs to free + * but still must free the nameList returned + */ + free(nameList); + } + + return n_names; +} +#else { char **names = NULL; int n_names; @@ -113,6 +135,7 @@ int get_domain_list(virConnectPtr conn, virDomainPtr **_list) return idx; } +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ void set_instance_class_name(CMPIInstance *instance, char *name) { -- 1.8.1.4 From jferlan at redhat.com Thu Mar 14 22:56:02 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 14 Mar 2013 18:56:02 -0400 Subject: [Libvirt-cim] [PATCH 10/10] register: Adjust the chatter output In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-11-git-send-email-jferlan@redhat.com> Caused error during make postinstall. Rather than print the $PROVIDERMODULES it attempted to execute the second one in the list. Added extra output just prior to CIMMOF commands to show which namespace is being modified from which directory. There appears to be some sort of issue registering some mofs as the following message is generated numerous times: Warning: the instance already exists. In this implementation, that means it cannot be changed. --- provider-register.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/provider-register.sh b/provider-register.sh index 0616a14..b907df1 100755 --- a/provider-register.sh +++ b/provider-register.sh @@ -90,10 +90,10 @@ pegasus_transform() chatter "cimserver version is " $version if compare_version "$version" "2.11.0" then - chatter "Processing provider modules (w/o ModuleGroupName):" \ - $PROVIDERMODULES + chatter "Processing provider modules (w/o ModuleGroupName):" for pm in $PROVIDERMODULES do + chatter "...processing " $pm cat >> $OUTFILE <> $OUTFILE < References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <1363301762-31091-10-git-send-email-jferlan@redhat.com> Rather than the somewhat unreliable get a count and get a list of active names, use the newer virConnectListAll* interfaces in order to retrieve both a count and list in one call. --- src/Virt_DevicePool.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 2 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index bf3dd3b..bffa0cf 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -146,13 +146,24 @@ static int get_diskpool_config(virConnectPtr conn, struct tmp_disk_pool **_pools, int *_count) { +#if LIBVIR_VERSION_NUMBER >= 100002 + int i, realcount = 0, count = 0; + virStoragePoolPtr *nameList = NULL; + int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; +#else int count = 0, realcount = 0; int i; char ** names = NULL; +#endif struct tmp_disk_pool *pools = NULL; int ret = 0; bool bret; +#if LIBVIR_VERSION_NUMBER >= 100002 + realcount = virConnectListAllStoragePools(conn, + &nameList, + flags); +#else count = virConnectNumOfStoragePools(conn); if (count < 0) { ret = count; @@ -169,6 +180,7 @@ static int get_diskpool_config(virConnectPtr conn, } realcount = virConnectListStoragePools(conn, names, count); +#endif if (realcount < 0) { CU_DEBUG("Failed to get storage pools, return %d.", realcount); ret = realcount; @@ -187,7 +199,13 @@ static int get_diskpool_config(virConnectPtr conn, } for (i = 0; i < realcount; i++) { - pools[i].tag = strdup(names[i]); +#if LIBVIR_VERSION_NUMBER >= 100002 + pools[i].tag = strdup(getVirStoragePoolName(nameList[i])); +#else + /* Just take names[i], since we're free()'ing later */ + pools[i].tag = names[i]; + names[i] = NULL; +#endif if (pools[i].tag == NULL) { CU_DEBUG("Failed in strdup for name '%s'.", names[i]); ret = -3; @@ -213,10 +231,18 @@ static int get_diskpool_config(virConnectPtr conn, free_diskpool(pools, realcount); free_names: +#if LIBVIR_VERSION_NUMBER >= 100002 + if (nameList != NULL) { + for (i = 0; i < realcount; i++) + virStoragePoolFree(nameList[i]); + free(nameList); + } +#else for (i = 0; i < count; i++) { free(names[i]); } free(names); +#endif out: return ret; @@ -529,6 +555,40 @@ static char *diskpool_member_of(const CMPIBroker *broker, static virNetworkPtr bridge_to_network(virConnectPtr conn, const char *bridge) { +#if LIBVIR_VERSION_NUMBER >= 100002 + int num; + virNetworkPtr **nameList = NULL; + virNetworkPtr network = NULL; + flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; + + num = virConnectListAllNetworks(conn, + &nameList, + flags); + if (num < 0) { + CU_DEBUG("Failed to get network pools."); + return NULL; + } + + for (i = 0; i < num; i++) { + char *_netname; + char *_bridge; + + _netname = virNetworkGetName(nameList[i]); + _bridge = virNetworkGetBridgeName(network); + CU_DEBUG("Network `%s' has bridge `%s'", _netname, _bridge); + if (STREQ(bridge, _bridge)) { + network = nameList[i]; + nameList[i] = NULL; + i = num; /* Loop breaker */ + } + free(_bridge); + } + + for (i = 0; i < num; i++) { + virNetworkFree(nameList[i]); + } + free(nameList); +#else char **networks = NULL; virNetworkPtr network = NULL; int num; @@ -566,7 +626,7 @@ static virNetworkPtr bridge_to_network(virConnectPtr conn, for (i = 0; i < num; i++) free(networks[i]); free(networks); - +#endif return network; } @@ -748,6 +808,29 @@ static bool mempool_set_total(CMPIInstance *inst, virConnectPtr conn) static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) { uint64_t memory = 0; +#if LIBVIR_VERSION_NUMBER >= 9013 + virDomainPtr *nameList = NULL; + int n_names, i; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names < 0) { + CU_DEBUG("Failed to get a list of all domains"); + goto out; + } + + for (i = 0; i < n_names; i++) { + virDomainInfo dom_info; + if (virDomainGetInfo(nameList[i], &dom_info) == 0) + memory += dom_info.memory; + virDomainFree(nameList[i]); + } + free(nameList); + + out: +#else int *domain_ids = NULL; int count, i = 0; @@ -781,6 +864,7 @@ static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) out: free(domain_ids); +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ CMSetProperty(inst, "Reserved", (CMPIValue *)&memory, CMPI_uint64); @@ -1034,6 +1118,10 @@ static CMPIStatus netpool_instance(virConnectPtr conn, char **netnames = NULL; int i; int nets = 0; +#if LIBVIR_VERSION_NUMBER >= 100002 + virNetworkPtr **nameList = NULL; + flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; +#endif if (id != NULL) { return _netpool_for_network(list, @@ -1044,7 +1132,16 @@ static CMPIStatus netpool_instance(virConnectPtr conn, broker); } +#if LIBVIR_VERSION_NUMBER >= 100002 + nets = virConnectListAllNetworks(conn, + &nameList, + flags); + /* Avoids the need to realloc since we have a true number */ + if (nets >= 0) + nets++; +#else nets = virConnectNumOfNetworks(conn); +#endif if (nets < 0) { virt_set_status(broker, &s, CMPI_RC_ERR_FAILED, @@ -1062,6 +1159,18 @@ static CMPIStatus netpool_instance(virConnectPtr conn, goto out; } +#if LIBVIR_VERSION_NUMBER >= 100002 + for (i = 0; i < nets - 1; i++) { + netnames[i] = strdup(virNetworkGetName(nameList[i])); + if (netnames[i] == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to strdup memory for %i net names", + nets); + goto out; + } + } +#else nets = virConnectListNetworks(conn, netnames, nets); nets++; @@ -1072,6 +1181,7 @@ static CMPIStatus netpool_instance(virConnectPtr conn, "Failed to allocate memory for %i net names", nets); goto out; } +#endif netnames[nets - 1] = strdup("0"); @@ -1085,6 +1195,13 @@ static CMPIStatus netpool_instance(virConnectPtr conn, } out: +#if LIBVIR_VERSION_NUMBER >= 100002 + if (nameList != NULL) { + for (i = 0; i < nets - 1; i++) + virNetworkFree(nameList[i]); + free(nameList); + } +#endif if (netnames != NULL) { for (i = 0; i < nets; i++) free(netnames[i]); -- 1.8.1.4 From tyreld at us.ibm.com Fri Mar 15 02:04:07 2013 From: tyreld at us.ibm.com (Tyrel Datwyler) Date: Thu, 14 Mar 2013 20:04:07 -0600 Subject: [Libvirt-cim] Tyrel Datwyler is out of the office. Message-ID: I will be out of the office starting 03/13/2013 and will not return until 03/18/2013. During this time I will not have access to email. In the case of any urgent issues please contact my back up David Heller. -------------- next part -------------- An HTML attachment was scrubbed... URL: From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:03:38 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:03:38 +0800 Subject: [Libvirt-cim] [PATCH 01/10] Remove empty newline at bottom In-Reply-To: <1363301762-31091-2-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-2-git-send-email-jferlan@redhat.com> Message-ID: <5142D5DA.5060202@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > --- > schema/SwitchService.registration | 1 - > 1 file changed, 1 deletion(-) > > diff --git a/schema/SwitchService.registration b/schema/SwitchService.registration > index b8e4f23..82a5c04 100644 > --- a/schema/SwitchService.registration > +++ b/schema/SwitchService.registration > @@ -3,4 +3,3 @@ > Xen_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance > KVM_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance > LXC_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance > - > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:06:59 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:06:59 +0800 Subject: [Libvirt-cim] [PATCH 03/10] xmlgen: Only support script on bridge for xen domains In-Reply-To: <1363301762-31091-4-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-4-git-send-email-jferlan@redhat.com> Message-ID: <5142D6A3.9000606@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > A change was made in 0.9.10 to disallow a script on a bridge device for > qemu guests, see 'libvirt' commit id '1734cdb99'. > --- > libxkutil/xmlgen.c | 25 +++++++++++++++---------- > 1 file changed, 15 insertions(+), 10 deletions(-) > > diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c > index 2dcd0d2..099fdd2 100644 > --- a/libxkutil/xmlgen.c > +++ b/libxkutil/xmlgen.c > @@ -270,16 +270,21 @@ static const char *set_net_source(xmlNodePtr nic, > } > > > -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) > +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, > + int domtype) > { > const char *script = "vif-bridge"; > xmlNodePtr tmp; > const char *msg = NULL; > > - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); > - if (tmp == NULL) > - return XML_ERROR; > - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); > + /* Scripts only supported on Xen guests see 'libvirt' > + * commit id 1734cdb99 (since 0.9.10) */ > + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { > + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); > + if (tmp == NULL) > + return XML_ERROR; > + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); > + } > > msg = set_net_source(nic, dev, "bridge"); > > @@ -375,13 +380,13 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo) > } > #endif > > - if (STREQ(dev->dev.net.type, "network")) > + if (STREQ(dev->dev.net.type, "network")) { > msg = set_net_source(nic, net, "network"); > - else if (STREQ(dev->dev.net.type, "bridge")) > - msg = bridge_net_to_xml(nic, net); > - else if (STREQ(dev->dev.net.type, "user")) > + } else if (STREQ(dev->dev.net.type, "bridge")) { > + msg = bridge_net_to_xml(nic, net, dominfo->type); > + } else if (STREQ(dev->dev.net.type, "user")) { > continue; > - else if (STREQ(dev->dev.net.type, "direct")) { > + } else if (STREQ(dev->dev.net.type, "direct")) { > msg = set_net_source(nic, net, "direct"); > if (net->vsi.vsi_type != NULL) { > struct vsi_device *vsi = &dev->dev.net.vsi; > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:07:25 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:07:25 +0800 Subject: [Libvirt-cim] [PATCH 04/10] CSI: Fix bug found during 'make distcheck' In-Reply-To: <1363301762-31091-5-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-5-git-send-email-jferlan@redhat.com> Message-ID: <5142D6BD.70606@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > The 'ret' variable was set, but never checked. Caller never checks > returned status anyway. > --- > src/Virt_ComputerSystemIndication.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c > index 6b5cdd4..4c087c4 100644 > --- a/src/Virt_ComputerSystemIndication.c > +++ b/src/Virt_ComputerSystemIndication.c > @@ -726,6 +726,10 @@ static bool wait_for_event(int wait_time) > ret = pthread_cond_timedwait(&lifecycle_cond, > &lifecycle_mutex, > &timeout); > + if (ret != 0) { > + CU_DEBUG("timed wait failed with ret = %d", ret); > + return false; > + } > > return true; > } > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:07:44 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:07:44 +0800 Subject: [Libvirt-cim] [PATCH 04/10] CSI: Fix bug found during 'make distcheck' In-Reply-To: <1363301762-31091-5-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-5-git-send-email-jferlan@redhat.com> Message-ID: <5142D6D0.9070907@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > The 'ret' variable was set, but never checked. Caller never checks > returned status anyway. > --- > src/Virt_ComputerSystemIndication.c | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c > index 6b5cdd4..4c087c4 100644 > --- a/src/Virt_ComputerSystemIndication.c > +++ b/src/Virt_ComputerSystemIndication.c > @@ -726,6 +726,10 @@ static bool wait_for_event(int wait_time) > ret = pthread_cond_timedwait(&lifecycle_cond, > &lifecycle_mutex, > &timeout); > + if (ret != 0) { > + CU_DEBUG("timed wait failed with ret = %d", ret); > + return false; > + } > > return true; > } > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:20:45 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:20:45 +0800 Subject: [Libvirt-cim] [PATCH 06/10] libxkutil: Use virConnectListAllDomains() to fetch domains In-Reply-To: <1363301762-31091-7-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-7-git-send-email-jferlan@redhat.com> Message-ID: <5142D9DD.8000806@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > This is an optimization over using the multistep approach to get a count, > get some memory, and get the list of domains (active and defined). Followed > other examples to ensure only building the code if the libvirt version is > correct. The API was added in 0.9.13. > --- > libxkutil/cs_util_instance.c | 23 +++++++++++++++++++++++ > 1 file changed, 23 insertions(+) > > diff --git a/libxkutil/cs_util_instance.c b/libxkutil/cs_util_instance.c > index a383147..e34c05d 100644 > --- a/libxkutil/cs_util_instance.c > +++ b/libxkutil/cs_util_instance.c > @@ -34,6 +34,28 @@ > #include > > int get_domain_list(virConnectPtr conn, virDomainPtr **_list) > +#if LIBVIR_VERSION_NUMBER >= 9013 > +{ > + virDomainPtr *nameList = NULL; > + int n_names; > + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE | > + VIR_CONNECT_LIST_DOMAINS_INACTIVE; > + > + n_names = virConnectListAllDomains(conn, > + &nameList, > + flags); > + if (n_names > 0) { > + *_list = nameList; > + } else if (n_names == 0) { > + /* Since there are no elements, no domain ptrs to free > + * but still must free the nameList returned > + */ > + free(nameList); > + } > + > + return n_names; > +} > +#else > { > char **names = NULL; > int n_names; > @@ -113,6 +135,7 @@ int get_domain_list(virConnectPtr conn, virDomainPtr **_list) > > return idx; > } > +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ > > void set_instance_class_name(CMPIInstance *instance, char *name) > { > Code seems good, +1. Please reduce version condition macro in function as much as possible, if there are more functions in same file, I think two mirrored functions in two condition will make code easier to read in future: #if LIBVIRT_VERSION_NUMER >= XXX void function1(void) { } void function2(void) { } #else void function1(void) { } void function2(void) { } #endif -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:21:46 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:21:46 +0800 Subject: [Libvirt-cim] [PATCH 07/10] libvirt-cim.spec: Use systemctl for tog-pegasus restart In-Reply-To: <1363301762-31091-8-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-8-git-send-email-jferlan@redhat.com> Message-ID: <5142DA1A.5040005@linux.vnet.ibm.com> ? 2013-3-15 6:55, John Ferlan ??: > For Fedora 17 and RHEL7 use systemd, so change the pegasus startup to use > that and make a dependency upon it. > --- > libvirt-cim.spec.in | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in > index 7652dee..0679d7f 100644 > --- a/libvirt-cim.spec.in > +++ b/libvirt-cim.spec.in > @@ -27,6 +27,9 @@ BuildRequires: libconfig-devel > > BuildRequires: libxml2-devel > BuildRequires: libcmpiutil-devel > +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 > +BuildRequires: systemd-units > +%endif > BuildConflicts: sblim-cmpi-devel > > %description > @@ -85,7 +88,12 @@ rm -fr $RPM_BUILD_ROOT > > %{_datadir}/%{name}/install_base_schema.sh %{_datadir}/%{name} > > -/etc/init.d/tog-pegasus condrestart > +# Fedora 17 / RHEL-7 are first where we use systemd. > +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 > + systemctl restart tog-pegasus > +%else > + /etc/init.d/tog-pegasus condrestart > +%endif > > %{_datadir}/%{name}/provider-register.sh -t pegasus \ > -n @CIM_VIRT_NS@ \ > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:25:47 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:25:47 +0800 Subject: [Libvirt-cim] [PATCH 08/10] libxkutil: Adjust get_dominfo() logic In-Reply-To: <1363301762-31091-9-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-9-git-send-email-jferlan@redhat.com> Message-ID: <5142DB0B.5070603@linux.vnet.ibm.com> ? 2013-3-15 6:56, John Ferlan ??: > Need to really handle the error on the get_dominfo_from_xml() call > > Need to be sure to free(xml) before returning > --- > libxkutil/device_parsing.c | 10 ++++++---- > 1 file changed, 6 insertions(+), 4 deletions(-) > > diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c > index 2841662..264d4cc 100644 > --- a/libxkutil/device_parsing.c > +++ b/libxkutil/device_parsing.c > @@ -1246,7 +1246,7 @@ int get_dominfo_from_xml(const char *xml, struct domain **dominfo) > int get_dominfo(virDomainPtr dom, struct domain **dominfo) > { > char *xml; > - int ret; > + int ret = 0; > int start; > xml = virDomainGetXMLDesc(dom, > VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); > @@ -1256,17 +1256,19 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo) > return 0; > } > > - ret = get_dominfo_from_xml(xml, dominfo); > - if (ret != 1) { > + if (get_dominfo_from_xml(xml, dominfo) == 0) { > CU_DEBUG("Failed to translate xml into struct domain"); > + goto out; > } > if (virDomainGetAutostart(dom, &start) != 0) { > CU_DEBUG("Failed to get dom autostart with libvirt API."); > - return 0; > + goto out; > } > > (*dominfo)->autostrt = start; > + ret = 1; > > + out: > free(xml); > > return ret; > Fixed a leak, +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:27:59 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:27:59 +0800 Subject: [Libvirt-cim] [PATCH 09/10] DevicePool: Use the virConnectListAll interfaces In-Reply-To: <1363301762-31091-10-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-10-git-send-email-jferlan@redhat.com> Message-ID: <5142DB8F.7070402@linux.vnet.ibm.com> ? 2013-3-15 6:56, John Ferlan ??: > Rather than the somewhat unreliable get a count and get a list of active > names, use the newer virConnectListAll* interfaces in order to retrieve both > a count and list in one call. > --- > src/Virt_DevicePool.c | 121 +++++++++++++++++++++++++++++++++++++++++++++++++- > 1 file changed, 119 insertions(+), 2 deletions(-) > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index bf3dd3b..bffa0cf 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -146,13 +146,24 @@ static int get_diskpool_config(virConnectPtr conn, > struct tmp_disk_pool **_pools, > int *_count) > { > +#if LIBVIR_VERSION_NUMBER >= 100002 > + int i, realcount = 0, count = 0; > + virStoragePoolPtr *nameList = NULL; > + int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; > +#else > int count = 0, realcount = 0; > int i; > char ** names = NULL; > +#endif > struct tmp_disk_pool *pools = NULL; > int ret = 0; > bool bret; > > +#if LIBVIR_VERSION_NUMBER >= 100002 > + realcount = virConnectListAllStoragePools(conn, > + &nameList, > + flags); > +#else > count = virConnectNumOfStoragePools(conn); > if (count < 0) { > ret = count; > @@ -169,6 +180,7 @@ static int get_diskpool_config(virConnectPtr conn, > } > > realcount = virConnectListStoragePools(conn, names, count); > +#endif > if (realcount < 0) { > CU_DEBUG("Failed to get storage pools, return %d.", realcount); > ret = realcount; > @@ -187,7 +199,13 @@ static int get_diskpool_config(virConnectPtr conn, > } > > for (i = 0; i < realcount; i++) { > - pools[i].tag = strdup(names[i]); > +#if LIBVIR_VERSION_NUMBER >= 100002 > + pools[i].tag = strdup(getVirStoragePoolName(nameList[i])); > +#else > + /* Just take names[i], since we're free()'ing later */ > + pools[i].tag = names[i]; > + names[i] = NULL; > +#endif > if (pools[i].tag == NULL) { > CU_DEBUG("Failed in strdup for name '%s'.", names[i]); > ret = -3; > @@ -213,10 +231,18 @@ static int get_diskpool_config(virConnectPtr conn, > free_diskpool(pools, realcount); > > free_names: > +#if LIBVIR_VERSION_NUMBER >= 100002 > + if (nameList != NULL) { > + for (i = 0; i < realcount; i++) > + virStoragePoolFree(nameList[i]); > + free(nameList); > + } > +#else > for (i = 0; i < count; i++) { > free(names[i]); > } > free(names); > +#endif > > out: > return ret; > @@ -529,6 +555,40 @@ static char *diskpool_member_of(const CMPIBroker *broker, > static virNetworkPtr bridge_to_network(virConnectPtr conn, > const char *bridge) > { > +#if LIBVIR_VERSION_NUMBER >= 100002 > + int num; > + virNetworkPtr **nameList = NULL; > + virNetworkPtr network = NULL; > + flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; > + > + num = virConnectListAllNetworks(conn, > + &nameList, > + flags); > + if (num < 0) { > + CU_DEBUG("Failed to get network pools."); > + return NULL; > + } > + > + for (i = 0; i < num; i++) { > + char *_netname; > + char *_bridge; > + > + _netname = virNetworkGetName(nameList[i]); > + _bridge = virNetworkGetBridgeName(network); > + CU_DEBUG("Network `%s' has bridge `%s'", _netname, _bridge); > + if (STREQ(bridge, _bridge)) { > + network = nameList[i]; > + nameList[i] = NULL; > + i = num; /* Loop breaker */ > + } > + free(_bridge); > + } > + > + for (i = 0; i < num; i++) { > + virNetworkFree(nameList[i]); > + } > + free(nameList); > +#else > char **networks = NULL; > virNetworkPtr network = NULL; > int num; > @@ -566,7 +626,7 @@ static virNetworkPtr bridge_to_network(virConnectPtr conn, > for (i = 0; i < num; i++) > free(networks[i]); > free(networks); > - > +#endif > return network; > } > > @@ -748,6 +808,29 @@ static bool mempool_set_total(CMPIInstance *inst, virConnectPtr conn) > static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) > { > uint64_t memory = 0; > +#if LIBVIR_VERSION_NUMBER >= 9013 > + virDomainPtr *nameList = NULL; > + int n_names, i; > + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; > + > + n_names = virConnectListAllDomains(conn, > + &nameList, > + flags); > + if (n_names < 0) { > + CU_DEBUG("Failed to get a list of all domains"); > + goto out; > + } > + > + for (i = 0; i < n_names; i++) { > + virDomainInfo dom_info; > + if (virDomainGetInfo(nameList[i], &dom_info) == 0) > + memory += dom_info.memory; > + virDomainFree(nameList[i]); > + } > + free(nameList); > + > + out: > +#else > int *domain_ids = NULL; > int count, i = 0; > > @@ -781,6 +864,7 @@ static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) > > out: > free(domain_ids); > +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ > > CMSetProperty(inst, "Reserved", > (CMPIValue *)&memory, CMPI_uint64); > @@ -1034,6 +1118,10 @@ static CMPIStatus netpool_instance(virConnectPtr conn, > char **netnames = NULL; > int i; > int nets = 0; > +#if LIBVIR_VERSION_NUMBER >= 100002 > + virNetworkPtr **nameList = NULL; > + flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; > +#endif > > if (id != NULL) { > return _netpool_for_network(list, > @@ -1044,7 +1132,16 @@ static CMPIStatus netpool_instance(virConnectPtr conn, > broker); > } > > +#if LIBVIR_VERSION_NUMBER >= 100002 > + nets = virConnectListAllNetworks(conn, > + &nameList, > + flags); > + /* Avoids the need to realloc since we have a true number */ > + if (nets >= 0) > + nets++; > +#else > nets = virConnectNumOfNetworks(conn); > +#endif > if (nets < 0) { > virt_set_status(broker, &s, > CMPI_RC_ERR_FAILED, > @@ -1062,6 +1159,18 @@ static CMPIStatus netpool_instance(virConnectPtr conn, > goto out; > } > > +#if LIBVIR_VERSION_NUMBER >= 100002 > + for (i = 0; i < nets - 1; i++) { > + netnames[i] = strdup(virNetworkGetName(nameList[i])); > + if (netnames[i] == NULL) { > + cu_statusf(broker, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to strdup memory for %i net names", > + nets); > + goto out; > + } > + } > +#else > nets = virConnectListNetworks(conn, netnames, nets); > > nets++; > @@ -1072,6 +1181,7 @@ static CMPIStatus netpool_instance(virConnectPtr conn, > "Failed to allocate memory for %i net names", nets); > goto out; > } > +#endif > > netnames[nets - 1] = strdup("0"); > > @@ -1085,6 +1195,13 @@ static CMPIStatus netpool_instance(virConnectPtr conn, > } > > out: > +#if LIBVIR_VERSION_NUMBER >= 100002 > + if (nameList != NULL) { > + for (i = 0; i < nets - 1; i++) > + virNetworkFree(nameList[i]); > + free(nameList); > + } > +#endif > if (netnames != NULL) { > for (i = 0; i < nets; i++) > free(netnames[i]); > -1, too much inline macros, which will make the file very hard to read later, please use mirrored function pairs. -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:32:20 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:32:20 +0800 Subject: [Libvirt-cim] [PATCH 10/10] register: Adjust the chatter output In-Reply-To: <1363301762-31091-11-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-11-git-send-email-jferlan@redhat.com> Message-ID: <5142DC94.5010200@linux.vnet.ibm.com> ? 2013-3-15 6:56, John Ferlan ??: > Caused error during make postinstall. Rather than print the $PROVIDERMODULES > it attempted to execute the second one in the list. > > Added extra output just prior to CIMMOF commands to show which namespace > is being modified from which directory. There appears to be some sort of > issue registering some mofs as the following message is generated numerous > times: > > Warning: the instance already exists. > In this implementation, that means it cannot be changed. > --- > provider-register.sh | 9 +++++---- > 1 file changed, 5 insertions(+), 4 deletions(-) > > diff --git a/provider-register.sh b/provider-register.sh > index 0616a14..b907df1 100755 > --- a/provider-register.sh > +++ b/provider-register.sh > @@ -90,10 +90,10 @@ pegasus_transform() > chatter "cimserver version is " $version > if compare_version "$version" "2.11.0" > then > - chatter "Processing provider modules (w/o ModuleGroupName):" \ > - $PROVIDERMODULES > + chatter "Processing provider modules (w/o ModuleGroupName):" > for pm in $PROVIDERMODULES > do > + chatter "...processing " $pm > cat >> $OUTFILE < instance of PG_ProviderModule > { > @@ -109,10 +109,10 @@ EOFPM > done > > else > - chatter "Processing provider modules (w/ ModuleGroupName):" \ > - $PROVIDERMODULES > + chatter "Processing provider modules (w/ ModuleGroupName):" > for pm in $PROVIDERMODULES > do > + chatter "...processing " $pm > cat >> $OUTFILE < instance of PG_ProviderModule > { > @@ -272,6 +272,7 @@ pegasus_install() > if pegasus_transform $_REGFILENAME $namespace $myregs > then > chatter Registering providers with $state cimserver '('$version')' > + chatter Installing mofs into namespace $namespace from path $mofpath > $CIMMOF -uc -I $mofpath -n $namespace $mymofs && > $CIMMOF -uc -n root/PG_Interop $_REGFILENAME > else > +1 -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Fri Mar 15 08:37:20 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 15 Mar 2013 16:37:20 +0800 Subject: [Libvirt-cim] [PATCH 00/10] Adjustments based on recent review In-Reply-To: <1363301762-31091-1-git-send-email-jferlan@redhat.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> Message-ID: <5142DDC0.6010300@linux.vnet.ibm.com> Thanks for your patches, most seems good, some I can't confirm in a short time. Since I am not the maintainer, I'll include those got +1 in my serial with Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia And then let Danial V decide whether to pull. > As requested here is a series of patches to address a couple of issues > I discovered during my initial foray into using libvirt-cim as well as > from my code review. These are all *based on* the code I reviewed. > > Feel free to pick, choose, and apply. I have run them on my f18 system > and things seem to work, but it's possible I've made a configuration error. > I also will have a series of cimtest fixes, but I need to tidy them up > a bit before sending. > > I did figure out that rather than uninstalling and reinstalling the > package, I can use make preuninstall, make preinstall, restart the > CIMOM, make install, and make postinsall which seems to replace the > mofs "mostly correctly". There is an error in the postinstall phase > which I haven't had the cycles to chase yet. > > John Ferlan (10): > Remove empty newline at bottom > Makefile.am: Remove the $(top_srcdir) from subst command > xmlgen: Only support script on bridge for xen domains > CSI: Fix bug found during 'make distcheck' > Makefile.am: Use the top_srcdir rather than direct path in subst > libxkutil: Use virConnectListAllDomains() to fetch domains > libvirt-cim.spec: Use systemctl for tog-pegasus restart > libxkutil: Adjust get_dominfo() logic > DevicePool: Use the virConnectListAll interfaces > register: Adjust the chatter output > > Makefile.am | 18 +++--- > libvirt-cim.spec.in | 10 ++- > libxkutil/cs_util_instance.c | 23 +++++++ > libxkutil/device_parsing.c | 10 +-- > libxkutil/xmlgen.c | 25 +++++--- > provider-register.sh | 9 +-- > schema/SwitchService.registration | 1 - > src/Virt_ComputerSystemIndication.c | 4 ++ > src/Virt_DevicePool.c | 121 +++++++++++++++++++++++++++++++++++- > 9 files changed, 190 insertions(+), 31 deletions(-) > -- Best Regards Wenchao Xia From jferlan at redhat.com Fri Mar 15 10:53:40 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 06:53:40 -0400 Subject: [Libvirt-cim] [PATCH 06/10] libxkutil: Use virConnectListAllDomains() to fetch domains In-Reply-To: <5142D9DD.8000806@linux.vnet.ibm.com> References: <1363301762-31091-1-git-send-email-jferlan@redhat.com> <1363301762-31091-7-git-send-email-jferlan@redhat.com> <5142D9DD.8000806@linux.vnet.ibm.com> Message-ID: <5142FDB4.7080105@redhat.com> On 03/15/2013 04:20 AM, Wenchao Xia wrote: > ? 2013-3-15 6:55, John Ferlan ??: >> > > Code seems good, +1. Please reduce version condition macro in function > as much as possible, if there are more functions in same file, I think > two mirrored functions in two condition will make code easier to read > in future: > Readability +1, maintainability -1 - that's the reason I went with interlaced. I also looked at a few other examples in the code that have used the LIBVIR_VERSION_NUMBER mechanism and they interlace the code. For me it's good coding practice. Another option would be to modify the libvirt.spec.in file and change the following from: Requires: libvirt >= 0.9.0 to Requires: libvirt >= 0.10.2 And the aclocal.m4 file to change the following from: _pkg_min_version=m4_default([$1], [0.9.0]) to _pkg_min_version=m4_default([$1], [0.10.2]) Then just remove all the "#else" conditions... Since we're at 0.9.0 already, I'm not sure why the code has the lesser checks. However, I don't have the "history" to say for 100% the right path to take on this... John From jferlan at redhat.com Fri Mar 15 22:55:09 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:09 -0400 Subject: [Libvirt-cim] [PATCH 0/9] cimtest changes Message-ID: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Here's my set of cimtest changes. Quite a few of the changes deal with the illegal MAC address that starts with 99-* - this is a multicast MAC which is not allowed. There are changes to handle systemd/nfs, a couple dealing with fedora vs. rhel default network device name, and a couple of fixes that I just dug into to resolve on my f18 box. I get the following results: ================================================= FAIL : 4 XFAIL : 3 SKIP : 11 PASS : 174 ----------------- Total : 192 ================================================= FAIL Test Summary: ComputerSystemIndication - 01_created_indication.py: FAIL RASDIndications - 01_guest_states_rasd_ind.py: FAIL RASDIndications - 02_guest_add_mod_rem_rasd_ind.py: FAIL VirtualSystemManagementService - 22_addmulti_brg_interface.py: FAIL ================================================= XFAIL Test Summary: SwitchService - 01_enum.py: XFAIL VirtualSystemManagementService - 28_definesystem_with_vsi_profile.py: XFAIL VirtualSystemManagementService - 30_dynamic_disk_mod.py: XFAIL ================================================= SKIP Test Summary: ComputerSystem - 02_nosystems.py: SKIP ComputerSystemMigrationJobIndication - 01_csmig_ind_for_offline_mig.py: SKIP LogicalDisk - 02_nodevs.py: SKIP Profile - 04_verify_libvirt_cim_slp_profiles.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 John Ferlan (9): Need to check "slp=true", not just "slp" since "slp=false" is possible Change the MAC from "99:" to "88:" Create a temporary directory for disk pool tests Use symbols as named in libvirt-cim for easier reference Fix nfs-server lookup code Fix os_status passing to reporter functions Resolve issues found in test. On Fedora systems default to using 'em1' instead of 'eth1' 19 - resolve issues found in test .../Profile/04_verify_libvirt_cim_slp_profiles.py | 2 +- .../08_CreateDiskResourcePool.py | 26 ++++++-- .../09_DeleteDiskPool.py | 19 ++++-- .../15_DiskPoolAutostart.py | 11 +++- .../libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py | 2 +- .../06_addresource.py | 2 +- .../08_modifyresource.py | 4 +- .../13_refconfig_additional_devs.py | 4 +- .../15_mod_system_settings.py | 11 ++-- .../18_define_sys_bridge.py | 2 +- .../19_definenetwork_ers.py | 17 +++-- .../22_addmulti_brg_interface.py | 2 +- .../27_definesystem_macvtap_dev.py | 19 +++++- .../28_definesystem_with_vsi_profile.py | 15 +++++ suites/libvirt-cim/lib/XenKvmLib/common_util.py | 77 +++++++++++++++++----- suites/libvirt-cim/lib/XenKvmLib/const.py | 6 +- suites/libvirt-cim/lib/XenKvmLib/test_xml.py | 2 +- suites/libvirt-cim/main.py | 15 +++++ 18 files changed, 183 insertions(+), 53 deletions(-) -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:10 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:10 -0400 Subject: [Libvirt-cim] [PATCH 1/9] Need to check "slp=true", not just "slp" since "slp=false" is possible In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-2-git-send-email-jferlan@redhat.com> --- .../libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py b/suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py index f6cf5b1..f08d157 100644 --- a/suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py +++ b/suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py @@ -64,7 +64,7 @@ def get_slp_info(server): logger.info("Test not supported for sfcb yet ... hence skipping") return SKIP - cmd = "cimconfig -l -p | grep slp" + cmd = "cimconfig -l -p | grep slp=true" rc, out = run_remote(server, cmd) if rc != 0: logger.error("SLP is not enabled for the cimserver on '%s'", server) -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:11 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:11 -0400 Subject: [Libvirt-cim] [PATCH 2/9] Change the MAC from "99:" to "88:" In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-3-git-send-email-jferlan@redhat.com> Using a MAC starting with "99:" is not legal. That ends up being a Multicast Address since the low order bit of the first byte of the address (in hex) is one. That is "99" is 0x10011001" in hex, where the least significant bit is a "1" (one) indicating a multicast. --- suites/libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py | 2 +- .../cimtest/VirtualSystemManagementService/06_addresource.py | 2 +- .../cimtest/VirtualSystemManagementService/08_modifyresource.py | 4 ++-- .../VirtualSystemManagementService/13_refconfig_additional_devs.py | 4 ++-- .../cimtest/VirtualSystemManagementService/18_define_sys_bridge.py | 2 +- .../VirtualSystemManagementService/22_addmulti_brg_interface.py | 2 +- suites/libvirt-cim/lib/XenKvmLib/const.py | 6 +++--- suites/libvirt-cim/lib/XenKvmLib/test_xml.py | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/suites/libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py b/suites/libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py index c5d8a22..be82335 100644 --- a/suites/libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py +++ b/suites/libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py @@ -40,7 +40,7 @@ from XenKvmLib.const import get_provider_version sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] default_dom = 'uuid_domain' test_dom = 'test_domain' -nmac = '99:aa:bb:cc:ee:ff' +nmac = '88:aa:bb:cc:ee:ff' duplicate_uuid_support = 915 def get_vssd(ip, virt, dom): diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/06_addresource.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/06_addresource.py index fdcb84a..ac18c69 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/06_addresource.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/06_addresource.py @@ -38,7 +38,7 @@ from XenKvmLib.common_util import create_netpool_conf, destroy_netpool sup_types = ['Xen', 'KVM', 'XenFV'] default_dom = 'rstest_domain' -nmac = '99:aa:bb:cc:ee:ff' +nmac = '88:aa:bb:cc:ee:ff' ntype = 'network' npool_name = default_network_name + str(random.randint(1, 100)) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/08_modifyresource.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/08_modifyresource.py index df58d1f..a7c3871 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/08_modifyresource.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/08_modifyresource.py @@ -43,9 +43,9 @@ cpu = 2 ncpu = 1 nmem = 131072 new_int = randint(10, 99) -new_mac1 = "11:%s:22:%s:33:%s" % (new_int, new_int, new_int) +new_mac1 = "88:%s:22:%s:33:%s" % (new_int, new_int, new_int) new_int += 1 -new_mac2 = "11:%s:22:%s:33:%s" % (new_int, new_int, new_int) +new_mac2 = "88:%s:22:%s:33:%s" % (new_int, new_int, new_int) def cleanup_env(ip, cxml): cxml.destroy(ip) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/13_refconfig_additional_devs.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/13_refconfig_additional_devs.py index 6274527..a47db8f 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/13_refconfig_additional_devs.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/13_refconfig_additional_devs.py @@ -38,8 +38,8 @@ from XenKvmLib.vxml import get_class sup_types = ['Xen', 'XenFV', 'KVM'] test_dom = 'rstest_domain' test_dom2 = 'rstest_domain2' -mac1 = '99:aa:bb:cc:ee:ff' -mac2 = '99:aa:bb:cc:ee:aa' +mac1 = '88:aa:bb:cc:ee:ff' +mac2 = '88:aa:bb:cc:ee:aa' REQUESTED_STATE = 2 TIME = "00000000000000.000000:000" diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/18_define_sys_bridge.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/18_define_sys_bridge.py index e02de29..66b3e45 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/18_define_sys_bridge.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/18_define_sys_bridge.py @@ -32,7 +32,7 @@ from XenKvmLib.common_util import create_netpool_conf, destroy_netpool sup_types = ['Xen', 'KVM', 'XenFV'] default_dom = 'brgtest_domain' -nmac = '99:aa:bb:cc:ee:ff' +nmac = '88:aa:bb:cc:ee:ff' npool_name = default_network_name + str(random.randint(1, 100)) brg_name = "br" + str(random.randint(1, 100)) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/22_addmulti_brg_interface.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/22_addmulti_brg_interface.py index 9abb21b..36d1873 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/22_addmulti_brg_interface.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/22_addmulti_brg_interface.py @@ -36,7 +36,7 @@ sup_types = ['Xen', 'KVM', 'XenFV'] test_dom = "my_domain1" default_net = "my_network0" test_net = "my_network1" -test_mac = '99:aa:bb:cc:ee:ff' +test_mac = '88:aa:bb:cc:ee:ff' default_mac = "00:11:33:33:44:55" ntype = 'bridge' default_brg = 'mybr0' diff --git a/suites/libvirt-cim/lib/XenKvmLib/const.py b/suites/libvirt-cim/lib/XenKvmLib/const.py index 6dea644..6701d36 100755 --- a/suites/libvirt-cim/lib/XenKvmLib/const.py +++ b/suites/libvirt-cim/lib/XenKvmLib/const.py @@ -80,7 +80,7 @@ Xen_init_path = os.path.join(_image_dir, 'default-xen-initrd') Xen_disk_path = os.path.join(_image_dir, 'default-xen-dimage') Xen_secondary_disk_path = os.path.join(_image_dir, 'default-xen-dimage.2ND') Xen_default_disk_dev = 'xvda' -Xen_default_mac = '11:22:33:aa:bb:cc' +Xen_default_mac = '88:22:33:aa:bb:cc' # vxml.KVMXML KVM_default_emulator = '/usr/bin/qemu-system-x86_64' @@ -88,7 +88,7 @@ KVM_disk_path = os.path.join(_image_dir, 'default-kvm-dimage') KVM_secondary_disk_path = os.path.join(_image_dir, 'default-kvm-dimage.2ND') KVM_default_disk_dev = 'hda' KVM_default_cdrom_dev = 'hdc' -KVM_default_mac = '11:22:33:aa:bb:cc' +KVM_default_mac = '88:22:33:aa:bb:cc' # vxml.XenFVXML s, o = platform.architecture() @@ -109,7 +109,7 @@ LXC_default_emulator = '/usr/libexec/libvirt_lxc' LXC_default_tty = '/dev/ptmx' LXC_default_mp = '/tmp' LXC_default_source = '/var/lib/libvirt/images/lxc_files' -LXC_default_mac = '11:22:33:aa:bb:cc' +LXC_default_mac = '88:22:33:aa:bb:cc' LXC_netns_support = False parser = OptionParser() diff --git a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py index b32ae4c..914dbb0 100755 --- a/suites/libvirt-cim/lib/XenKvmLib/test_xml.py +++ b/suites/libvirt-cim/lib/XenKvmLib/test_xml.py @@ -42,7 +42,7 @@ kernel_path = os.path.join(image_dir, 'default-xen-kernel') init_path = os.path.join(image_dir, 'default-xen-initrd') disk_path = os.path.join(image_dir, 'default-xen-dimage') -default_mac = '11:22:33:aa:bb:cc' +default_mac = '88:22:33:aa:bb:cc' def testxml(test_dom="domU1", mem = 128, vcpus = 1, mac = default_mac, disk_file_path = disk_path, disk = "xvda"): -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:13 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:13 -0400 Subject: [Libvirt-cim] [PATCH 4/9] Use symbols as named in libvirt-cim for easier reference In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-5-git-send-email-jferlan@redhat.com> --- .../VirtualSystemManagementService/15_mod_system_settings.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py index e576fca..0be3ae0 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/15_mod_system_settings.py @@ -37,7 +37,10 @@ from XenKvmLib.xm_virt_util import domain_list, active_domain_list, \ sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] default_dom = 'rstest_domain' cpu = 2 -RECOVERY_VAL = 3 +# AutomaticRecoveryAction +NONE_VAL = 2 +RESTART_VAL = 3 + DEFINED_STATE = 3 bug = "00008" f9_bug = "00010" @@ -113,7 +116,7 @@ def main(): raise Expcetion("Failed to get the VSSD instance for %s" % \ default_dom) - val = pywbem.cim_types.Uint16(RECOVERY_VAL) + val = pywbem.cim_types.Uint16(RESTART_VAL) inst['AutomaticRecoveryAction'] = val vssd = inst_to_mof(inst) @@ -135,9 +138,9 @@ def main(): raise Exception("Failed to get the VSSD instance for %s" % \ default_dom) - if inst.AutomaticRecoveryAction != RECOVERY_VAL: + if inst.AutomaticRecoveryAction != RESTART_VAL: logger.error("Exp AutomaticRecoveryAction=%d, got %d", - RECOVERY_VAL, inst.AutomaticRecoveryAction) + RESTART_VAL, inst.AutomaticRecoveryAction) raise Exception("%s not updated properly" % default_dom) status = PASS -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:12 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:12 -0400 Subject: [Libvirt-cim] [PATCH 3/9] Create a temporary directory for disk pool tests In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-4-git-send-email-jferlan@redhat.com> We cannot have two storage pools referencing the same path. Since the cimtest-diskpool is already created at /var/lib/libvirt/images, we'll use that (e.g. _image_dir symbol) to create a subdirectory for the test. We'll also delete that directory when we're done. --- .../08_CreateDiskResourcePool.py | 26 +++++++++++++++++----- .../09_DeleteDiskPool.py | 19 +++++++++++----- .../15_DiskPoolAutostart.py | 11 ++++++++- 3 files changed, 43 insertions(+), 13 deletions(-) diff --git a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py index c82b5b0..636f59c 100644 --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/08_CreateDiskResourcePool.py @@ -48,6 +48,7 @@ # -Date: 26.05.2009 import sys +import os from CimTest.Globals import logger from XenKvmLib.xm_virt_util import virsh_version from CimTest.ReturnCodes import FAIL, PASS, SKIP @@ -55,8 +56,9 @@ from XenKvmLib.const import do_main, platform_sup from XenKvmLib.classes import get_typed_class from XenKvmLib.common_util import destroy_diskpool, nfs_netfs_setup, \ netfs_cleanup -from XenKvmLib.pool import create_pool, verify_pool, undefine_diskpool -from XenKvmLib.const import get_provider_version +from XenKvmLib.pool import create_pool, verify_pool, undefine_diskpool, \ + DIR_POOL, NETFS_POOL +from XenKvmLib.const import get_provider_version, _image_dir libvirt_disk_pool_support=837 libvirt_netfs_pool_support=869 @@ -94,19 +96,20 @@ def main(): curr_cim_rev, changeset = get_provider_version(virt, server) if curr_cim_rev >= libvirt_disk_pool_support: - dp_types["DISK_POOL_DIR"] = 1 + dp_types["DISK_POOL_DIR"] = DIR_POOL if curr_cim_rev >= libvirt_netfs_pool_support: - dp_types["DISK_POOL_NETFS"] = 3 + dp_types["DISK_POOL_NETFS"] = NETFS_POOL if len(dp_types) == 0 : - logger.info("No disk pool types in list , hence skipping the test...") + logger.info("No disk pool types in list, hence skipping the test...") return SKIP status = FAIL pool_attr = None # For now the test case support only the creation of # dir type disk pool, netfs later change to fs and disk pooltypes etc - for key, value in dp_types.iteritems(): + for key, value in dp_types.iteritems(): + del_path = False try: logger.info("Verifying '%s'.....", key) test_pool = key @@ -115,6 +118,15 @@ def main(): if status != PASS: return FAIL + # Cannot have two pools that use the same location/path, so + # since cimtest-diskpool already exists + if key == 'DISK_POOL_DIR': + path = os.path.join(_image_dir, 'temppool') + if not os.path.exists(path): + os.mkdir(path) + del_path = True + pool_attr["Path"] = path + status = create_pool(server, virt, test_pool, pool_attr, mode_type=value, pool_type= "DiskPool") @@ -152,6 +164,8 @@ def main(): if key == 'DISK_POOL_NETFS': netfs_cleanup(server, pool_attr) + if del_path: + os.rmdir(path) return status if __name__ == "__main__": diff --git a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/09_DeleteDiskPool.py b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/09_DeleteDiskPool.py index 31e3f22..8bd15e2 100644 --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/09_DeleteDiskPool.py +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/09_DeleteDiskPool.py @@ -44,6 +44,7 @@ # -Date: 26.05.2009 import sys +import os import pywbem from XenKvmLib import rpcs_service from CimTest.Globals import logger @@ -88,13 +89,17 @@ def main(): elif curr_cim_rev >= libvirt_cim_child_pool_rev: + del_path = False try: - pool_attr = { "Path" : _image_dir } + path = os.path.join(_image_dir, 'deltest') + if not os.path.exists(path): + os.mkdir(path) + del_path = True + pool_attr = { "Path" : path } status = create_pool(server, virt, test_pool, pool_attr, pool_type="DiskPool", mode_type=TYPE) if status != PASS: - logger.error("Failed to create diskpool '%s'", test_pool) - return status + raise Exception("Failed to create diskpool '%s'" % test_pool) status = verify_pool(server, virt, test_pool, pool_attr, pool_type="DiskPool") @@ -112,8 +117,8 @@ def main(): break if pool_settings == None: - logger.error("Failed to get poolsettings for '%s'", test_pool) - return FAIL + raise Exception("Failed to get poolsettings for '%s'" \ + % test_pool) rpcs_conn.DeleteResourcePool(Pool = pool_settings) pool = EnumInstances(server, dp) @@ -127,8 +132,10 @@ def main(): logger.error("Exception details: %s", details) destroy_diskpool(server, virt, test_pool) undefine_diskpool(server, virt, test_pool) - return FAIL + status = FAIL + if del_path: + os.rmdir(path) return status if __name__ == "__main__": diff --git a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/15_DiskPoolAutostart.py b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/15_DiskPoolAutostart.py index b6b758c..b7e72a8 100644 --- a/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/15_DiskPoolAutostart.py +++ b/suites/libvirt-cim/cimtest/ResourcePoolConfigurationService/15_DiskPoolAutostart.py @@ -23,6 +23,7 @@ # -Date: 04.14.2011 import sys +import os from pywbem import cim_types from CimTest.Globals import logger from XenKvmLib.xm_virt_util import virsh_version @@ -77,12 +78,17 @@ def main(): pool_attr = None key = 'DISK_POOL_DIR' value = 1 + del_path = False try: logger.info("Verifying '%s'.....", key) test_pool = key - pool_attr = { "Path" : "/var/lib/libvirt/images", + pool_attr = { "Path" : "/var/lib/libvirt/images/autotest", "Autostart" : cim_types.Uint16(1) } + if not os.path.exists(pool_attr["Path"]): + os.mkdir(pool_attr["Path"]) + del_path = True + status = create_pool(server, virt, test_pool, pool_attr, mode_type=value, pool_type= "DiskPool") @@ -112,6 +118,9 @@ def main(): status = FAIL logger.error("Exception details: %s", details) + if del_path: + os.rmdir(pool_attr["Path"]) + return status if __name__ == "__main__": -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:15 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:15 -0400 Subject: [Libvirt-cim] [PATCH 6/9] Fix os_status passing to reporter functions In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-7-git-send-email-jferlan@redhat.com> If the status returned is an errno value, then os_status will be set outside of the bounds of the 'rc' array in Reporter.py which will cause a KeyError exception. Find, message, and adjust - we're failing anyway. --- suites/libvirt-cim/main.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/suites/libvirt-cim/main.py b/suites/libvirt-cim/main.py index a4e33e6..e5f3526 100644 --- a/suites/libvirt-cim/main.py +++ b/suites/libvirt-cim/main.py @@ -23,12 +23,14 @@ # from time import time +from time import sleep from optparse import OptionParser import os import sys sys.path.append('../../lib') import TestSuite from CimTest.Globals import logger, log_param +from CimTest.ReturnCodes import PASS, FAIL, XFAIL, SKIP import commands from VirtLib import groups import ConfigParser @@ -274,6 +276,14 @@ def main(options, args): os_status = os.WEXITSTATUS(status) + # status should be from our test; however, if there's an OS level + # failure, it could be set to errno. But that's included in our + # output, so just set it to FAIL; otherwise, we get a KeyError + # in Reporter.py when trying to index it's 'rc' record + if os_status not in (PASS, FAIL, XFAIL, SKIP): + logger.error("Changing os_status from %d to FAIL", os_status) + os_status = FAIL + testsuite.print_results(test['group'], test['test'], os_status, output) exec_time = end_time - start_time @@ -282,6 +292,11 @@ def main(options, args): if options.print_exec_time: print_exec_time(testsuite, exec_time, " Test execution time:") + # Give ourselves a 3 second pause before running the next + # test to help ensure we have cleaned things up properly just + # in case the cimserver is a little slow to respond + sleep(3) + testsuite.debug("%s\n" % div) if options.print_exec_time: -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:14 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:14 -0400 Subject: [Libvirt-cim] [PATCH 5/9] Fix nfs-server lookup code In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-6-git-send-email-jferlan@redhat.com> The 'get_nfs_bin()', 'nfs_config()', and 'nfs_netfs_setup()' API's needed adjustment to handle using systemd rather than looking for /etc/init.d/nfs --- suites/libvirt-cim/lib/XenKvmLib/common_util.py | 77 ++++++++++++++++++++----- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/suites/libvirt-cim/lib/XenKvmLib/common_util.py b/suites/libvirt-cim/lib/XenKvmLib/common_util.py index f145811..43e5e2c 100644 --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py @@ -493,27 +493,65 @@ def parse_instance_id(instid): def get_nfs_bin(server): cmd = 'cat /etc/issue | grep -v ^$ | egrep "Red Hat|Fedora"' rc, out = utils.run_remote(server, cmd) + is_systemd = 0 if rc != 0: #SLES nfs_server_bin = "/etc/init.d/nfsserver" else: + # Default, but allow it to be changed nfs_server_bin = "/etc/init.d/nfs" - return nfs_server_bin - -def nfs_config(server, nfs_server_bin): - cmd = "ps aux | grep -v -e nfsiod -e grep | grep nfsd" + # Check for 'systemd' being used + # Fedora 15 seems to have been the first place this was the default + # RHEL 7 and beyond will also use the mechanism. + # Since 'out' returns the fetched string, let's parse it a bit more + # looking for the number after the string 'release' which happens to + # be the version. On Fedora systems it's + # "Fedora release 18 (Spherical Cow)" while on RHEL systems it's: + # "Red Hat Enterprise Linux Server release 6.4 (Santiago)" + # + elems = out.split() + if elems[0] == 'Fedora' or (elems[0] == 'Red' and elems[1] == 'Hat'): + for i in range(1, len(elems)): + if elems[i] == 'release': + if (elems[0] == 'Fedora' and int(elems[i+1]) >= 15) or \ + (elems[0] == 'Red' and int(elems[i+1]) >= 7): + # Handle this differently - the command would be + # "systemctl {start|restart|status} nfs" + nfs_server_bin = "systemctl %s nfs" + is_systemd = 1 + break + + return nfs_server_bin, is_systemd + +def nfs_config(server, nfs_server_bin, is_systemd): + if is_systemd == 0: + cmd = "ps aux | grep -v -e nfsiod -e grep | grep nfsd" + else: + cmd = "systemctl | grep nfs-server" rc, out = utils.run_remote(server, cmd) # if NFS services is not found on the machine, start it.. if rc != PASS : # Check if NFS server is installed ... - if not os.path.exists(nfs_server_bin): - logger.error("NFS server '%s' does not seem to be installed "\ - "on '%s'", nfs_server_bin, server) - return SKIP + if is_systemd == 0: + if not os.path.exists(nfs_server_bin): + logger.error("NFS server '%s' does not seem to be installed "\ + "on '%s'", nfs_server_bin, server) + return SKIP + else: + # Works on Fedora and RHEL6 + cmd = "rpm -q nfs-utils" + rc, out = utils.run_remote(server, cmd) + if rc != PASS : + logger.error("NFS server package nfs-utils does not seem "\ + "to be installed on '%s'", server) + return SKIP # Start the nfs server ... - nfs_server_cmd = "%s start" % nfs_server_bin + if is_systemd == 0: + nfs_server_cmd = "%s start" % nfs_server_bin + else: + nfs_server_cmd = nfs_server_bin % "start" rc, out = utils.run_remote(server, nfs_server_cmd) if rc != PASS: logger.error("Could not start the nfsserver on '%s'", server) @@ -573,13 +611,16 @@ def netfs_cleanup(server, pool_attr): move_file(back_exports_file, exports_file) # restart the nfs server - nfs_server_bin = get_nfs_bin(server) - nfs_server_cmd = "%s restart" % nfs_server_bin + nfs_server_bin, is_systemd = get_nfs_bin(server) + if is_systemd == 0: + nfs_server_cmd = "%s restart" % nfs_server_bin + else: + nfs_server_cmd = nfs_server_bin % "restart" rc, out = utils.run_remote(server, nfs_server_cmd) if rc != PASS: logger.error("Could not restart NFS server on '%s'" % server) -def netfs_config(server, nfs_server_bin, dest_dir_to_mnt): +def netfs_config(server, nfs_server_bin, dest_dir_to_mnt, is_systemd): src_dir_for_mnt = mkdtemp() try: @@ -601,7 +642,10 @@ def netfs_config(server, nfs_server_bin, dest_dir_to_mnt): % (src_dir_for_mnt, dest_dir_to_mnt)) # Restart the nfs server.... - nfs_server_cmd = "%s restart" % nfs_server_bin + if is_systemd == 0: + nfs_server_cmd = "%s restart" % nfs_server_bin + else: + nfs_server_cmd = nfs_server_bin % "restart" rc, out = utils.run_remote(server, nfs_server_cmd) if rc != PASS: raise Exception("Could not restart NFS server on '%s'" % server) @@ -615,12 +659,12 @@ def netfs_config(server, nfs_server_bin, dest_dir_to_mnt): return PASS, src_dir_for_mnt def nfs_netfs_setup(server): - nfs_server_bin = get_nfs_bin(server) + nfs_server_bin, is_systemd = get_nfs_bin(server) dest_dir = mkdtemp() # Before going ahead verify that nfs server is available on machine.. - ret = nfs_config(server, nfs_server_bin) + ret = nfs_config(server, nfs_server_bin, is_systemd) if ret != PASS: logger.error("Failed to configure NFS on '%s'", server) logger.info("Trying to look for nfs mounted dir on '%s'...", server) @@ -631,7 +675,8 @@ def nfs_netfs_setup(server): else: return PASS, server, src_dir, dest_dir else: - ret, src_dir = netfs_config(server, nfs_server_bin, dest_dir) + ret, src_dir = netfs_config(server, nfs_server_bin, \ + dest_dir, is_systemd) if ret != PASS: logger.error("Failed to configure netfs on '%s'", server) return ret, None, None, None -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:16 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:16 -0400 Subject: [Libvirt-cim] [PATCH 7/9] Resolve issues found in test. In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-8-git-send-email-jferlan@redhat.com> 1. Use a MAC that isn't a multicast MAC. 2. Error messages changed in libvirt "0.9.8", so we need to account for that --- .../19_definenetwork_ers.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py index ad7c1ce..4cda327 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py @@ -37,7 +37,7 @@ from XenKvmLib.xm_virt_util import virsh_version sup_types = ['Xen', 'KVM', 'XenFV'] default_dom = 'brgtest_domain' -nmac = '99:aa:bb:cc:ee:ff' +nmac = '88:aa:bb:cc:ee:ff' npool_name = default_network_name + str(random.randint(1, 100)) brg_name = "br" + str(random.randint(1, 100)) @@ -89,11 +89,16 @@ def main(): expected_values['invalid']['bridge'] = inv_br_str else: + logger.error('DEBUG libvirt_version=%s', libvirt_version) if libvirt_version >= "0.7.0": expected_values['empty']['network'] = inv_empty_network expected_values['invalid']['network'] = inv_empty_network - expected_values['invalid']['bridge'] = " Failed to add tap "\ - "interface to bridge" + if libvirt_version >= "0.9.8": + expected_values['invalid']['bridge'] = "Cannot get interface "\ + "MTU on 'invalid'" + else: + expected_values['invalid']['bridge'] = " Failed to add tap "\ + "interface to bridge" tc_scen = { @@ -114,7 +119,8 @@ def main(): status = PASS for nettype in nettypes: for tc, field in tc_scen.iteritems(): - logger.error("DEBUG nettype is %s, field is %s, tc is %s", nettype, field, tc) + logger.error("DEBUG nettype is %s, field is %s, tc is %s", + nettype, field, tc) cxml = vxml.get_class(options.virt)(default_dom, mac=nmac, ntype=nettype, net_name=field) @@ -122,7 +128,7 @@ def main(): try: ret = cxml.cim_define(options.ip) - if not ret: + if not ret: status = verify_error(exp_rc, exp_desc, cxml) if status != PASS: # There are few libvirt version between 0.7.0 @@ -138,7 +144,7 @@ def main(): cxml.err_rc, cxml.err_desc)) continue ret = cxml.cim_start(options.ip) - if ret: + if ret: status = verify_error(exp_rc, exp_desc, cxml) cxml.undefine(options.ip) if status != PASS: -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:18 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:18 -0400 Subject: [Libvirt-cim] [PATCH 9/9] 19 - resolve issues found in test In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-10-git-send-email-jferlan@redhat.com> --- .../cimtest/VirtualSystemManagementService/19_definenetwork_ers.py | 1 - 1 file changed, 1 deletion(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py index 4cda327..cf461d1 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/19_definenetwork_ers.py @@ -89,7 +89,6 @@ def main(): expected_values['invalid']['bridge'] = inv_br_str else: - logger.error('DEBUG libvirt_version=%s', libvirt_version) if libvirt_version >= "0.7.0": expected_values['empty']['network'] = inv_empty_network expected_values['invalid']['network'] = inv_empty_network -- 1.8.1.4 From jferlan at redhat.com Fri Mar 15 22:55:17 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 15 Mar 2013 18:55:17 -0400 Subject: [Libvirt-cim] [PATCH 8/9] On Fedora systems default to using 'em1' instead of 'eth1' In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <1363388118-17604-9-git-send-email-jferlan@redhat.com> Fedora changed the default device naming scheme, see http://fedoraproject.org/wiki/Features/ConsistentNetworkDeviceNaming So if we're running on Fedora, let's "default" to "em1" although that doesn't guarantee that we will find what we're looking for. This code probably needs some mechanism to detect with interfaces are available, then query those interfaces to find one that supports the feature we want. --- .../27_definesystem_macvtap_dev.py | 19 ++++++++++++++++++- .../28_definesystem_with_vsi_profile.py | 15 +++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py index 8c20781..36bf52f 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py @@ -32,6 +32,7 @@ import sys from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS, SKIP +from VirtLib import utils from XenKvmLib.classes import get_typed_class, inst_to_mof from XenKvmLib.rasd import get_default_rasds from XenKvmLib.const import do_main, get_provider_version @@ -101,6 +102,7 @@ def verify_net_rasd(ip, virt, target_dev, source_dev, guest_name): @do_main(sup_types) def main(): options = main.options + server = options.ip status = FAIL @@ -113,7 +115,22 @@ def main(): cxml = get_class(options.virt)(test_dom) target_dev = "vepa" - source_dev = "eth1" + + # Fedora changed the default device naming scheme, see + # http://fedoraproject.org/wiki/Features/ConsistentNetworkDeviceNaming + # + # So if we're running on Fedora, let's "default" to "em1" although that + # doesn't guarantee that we will find what we're looking for. This code + # probably needs some mechanism to detect with interfaces are available, + # then query those interfaces to find one that supports the feature we + # want. If not are found and XFAIL could be generated indicating so. + # + cmd = 'cat /etc/issue | grep -v ^$ | egrep "Fedora"' + rc, out = utils.run_remote(server, cmd) + if rc == 0: + source_dev = "em1" + else: + source_dev = "eth1" guest_defined = False diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py index d14dda3..2b108f9 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py @@ -35,6 +35,7 @@ import sys from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS, SKIP, XFAIL_RC, XFAIL +from VirtLib import utils from XenKvmLib.classes import get_typed_class, inst_to_mof from XenKvmLib.rasd import get_default_rasds from XenKvmLib.const import do_main, get_provider_version @@ -173,6 +174,20 @@ def main(): 'VSITypeIDVersion' : "1" } + # Fedora changed the default device naming scheme, see + # http://fedoraproject.org/wiki/Features/ConsistentNetworkDeviceNaming + # + # So if we're running on Fedora, let's "default" to "em1" although that + # doesn't guarantee that we will find what we're looking for. This code + # probably needs some mechanism to detect with interfaces are available, + # then query those interfaces to find one that supports the feature we + # want. If not are found and XFAIL could be generated indicating so. + # + cmd = 'cat /etc/issue | grep -v ^$ | egrep "Fedora"' + rc, out = utils.run_remote(server, cmd) + if rc == 0: + vsi_defaults['SourceDevice'] = "em1" + nrasd_cn = get_typed_class(virt, 'NetResourceAllocationSettingData') status = FAIL cxml = None -- 1.8.1.4 From xiawenc at linux.vnet.ibm.com Mon Mar 18 09:55:18 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 18 Mar 2013 17:55:18 +0800 Subject: [Libvirt-cim] [PATCH 0/9] cimtest changes In-Reply-To: <1363388118-17604-1-git-send-email-jferlan@redhat.com> References: <1363388118-17604-1-git-send-email-jferlan@redhat.com> Message-ID: <5146E486.3000508@linux.vnet.ibm.com> Hi, John Thank u for the fix about cimtest. Currently I can't pay much time review this but later one colleague of mine will come to see the cimtest later. Since there are about 20+ patches for libvirt-cim hangs out there, and the queue is very long and make it hard to rebase, I think we need a way to sync our work, let's arrange out patches as following: 1-10: my patch V5. 11-later: your patches. I'll send V5 in a few days, could u rebase your work based on that? I'll provide a private git tree to easying down loading code. > Here's my set of cimtest changes. Quite a few of the changes deal with the > illegal MAC address that starts with 99-* - this is a multicast MAC which > is not allowed. There are changes to handle systemd/nfs, a couple dealing > with fedora vs. rhel default network device name, and a couple of fixes that > I just dug into to resolve on my f18 box. > > > I get the following results: > > ================================================= > FAIL : 4 > XFAIL : 3 > SKIP : 11 > PASS : 174 > ----------------- > Total : 192 > ================================================= > FAIL Test Summary: > ComputerSystemIndication - 01_created_indication.py: FAIL > RASDIndications - 01_guest_states_rasd_ind.py: FAIL > RASDIndications - 02_guest_add_mod_rem_rasd_ind.py: FAIL > VirtualSystemManagementService - 22_addmulti_brg_interface.py: FAIL > > ================================================= > XFAIL Test Summary: > SwitchService - 01_enum.py: XFAIL > VirtualSystemManagementService - 28_definesystem_with_vsi_profile.py: XFAIL > VirtualSystemManagementService - 30_dynamic_disk_mod.py: XFAIL > > ================================================= > SKIP Test Summary: > ComputerSystem - 02_nosystems.py: SKIP > ComputerSystemMigrationJobIndication - 01_csmig_ind_for_offline_mig.py: SKIP > LogicalDisk - 02_nodevs.py: SKIP > Profile - 04_verify_libvirt_cim_slp_profiles.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 > > > John Ferlan (9): > Need to check "slp=true", not just "slp" since "slp=false" is possible > Change the MAC from "99:" to "88:" > Create a temporary directory for disk pool tests > Use symbols as named in libvirt-cim for easier reference > Fix nfs-server lookup code > Fix os_status passing to reporter functions > Resolve issues found in test. > On Fedora systems default to using 'em1' instead of 'eth1' > 19 - resolve issues found in test > > .../Profile/04_verify_libvirt_cim_slp_profiles.py | 2 +- > .../08_CreateDiskResourcePool.py | 26 ++++++-- > .../09_DeleteDiskPool.py | 19 ++++-- > .../15_DiskPoolAutostart.py | 11 +++- > .../libvirt-cim/cimtest/VSSD/06_duplicate_uuid.py | 2 +- > .../06_addresource.py | 2 +- > .../08_modifyresource.py | 4 +- > .../13_refconfig_additional_devs.py | 4 +- > .../15_mod_system_settings.py | 11 ++-- > .../18_define_sys_bridge.py | 2 +- > .../19_definenetwork_ers.py | 17 +++-- > .../22_addmulti_brg_interface.py | 2 +- > .../27_definesystem_macvtap_dev.py | 19 +++++- > .../28_definesystem_with_vsi_profile.py | 15 +++++ > suites/libvirt-cim/lib/XenKvmLib/common_util.py | 77 +++++++++++++++++----- > suites/libvirt-cim/lib/XenKvmLib/const.py | 6 +- > suites/libvirt-cim/lib/XenKvmLib/test_xml.py | 2 +- > suites/libvirt-cim/main.py | 15 +++++ > 18 files changed, 183 insertions(+), 53 deletions(-) > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 19 06:40:58 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 19 Mar 2013 14:40:58 +0800 Subject: [Libvirt-cim] [PATCH V3 04/11] CSI, add lock to protect shared data In-Reply-To: <513EB8CC.4090103@linux.vnet.ibm.com> References: <513DED17.4010407@redhat.com> <513EB8CC.4090103@linux.vnet.ibm.com> Message-ID: <5148087A.6060804@linux.vnet.ibm.com> ? 2013-3-12 13:10, Wenchao Xia ??: > ? 2013-3-11 22:41, John Ferlan ??: >> >> Since I don't have the email to reply-to, here is a link: >> >> https://www.redhat.com/archives/libvirt-cim/2012-December/msg00026.html >> >> >> Why was the decision to reuse the lifecycle_mutex rather than generating >> a data specific mutex? Seems like that mutex is used for other >> operations to protect filters and indications. Thus unless the two are >> somehow tied, I really think it'd be better to create/use a data >> specific mutex. >> >> Furthermore, there's a few mutex adds around thread mgmt that probably >> should be a separate patch. That is - the non "dom_list" protection >> additions appear to be different. >> >> John >> > It is just the quickest way to fix bug, it should be a separate lock > just as mentioned in the commit message for performance, you can form a > patch to fix it above or replace this patch. > > >> _______________________________________________ >> Libvirt-cim mailing list >> Libvirt-cim at redhat.com >> https://www.redhat.com/mailman/listinfo/libvirt-cim >> > > Rechecked the code, the lifecycle_mutex is original meant to protect global variables, actually it should be declared as: struct CSI_gloable_data { pthread_mutex_t lifecycle_mutex, bool lifecycle_enabled, csi_thread_data_t csi_thread_data[CSI_NUM_PLATFORMS], }; Since above is a pure code structure improve and need quite a change, I hope to leave it untouched with a commit message, and rebase become easier. So this patch will only fix lock missing problem, if worthy, later we can send a patch fix the code struture problem as "CSI: folder global lock and structure ", and a patch improves lock as "CSI: use smaller lock". -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Tue Mar 19 07:06:31 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Tue, 19 Mar 2013 15:06:31 +0800 Subject: [Libvirt-cim] [PATCH V4] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <513EC3D8.7060200@linux.vnet.ibm.com> References: <513E3D61.9020801@redhat.com> <513EC3D8.7060200@linux.vnet.ibm.com> Message-ID: <51480E77.80608@linux.vnet.ibm.com> ? 2013-3-12 13:57, Wenchao Xia ??: > ? 2013-3-12 4:24, John Ferlan ??: >> >> Since I don't have an email to reply-to, here is the link: >> >> https://www.redhat.com/archives/libvirt-cim/2012-December/msg00039.html >> >> >> >> In get_diskpool_config(): >> >> * Rather than use the "racy" NumOfStoragePools and ListStoragePools, why >> not use virConnectListAllStoragePools() passing the "Active" flag for >> all active pools only? >> > Let me check if the version of minium libvirt requirement in configure, > to see if the API exist. > >> * You may even want to consider keeping the returned virStoragePoolPtr >> structures around.. >> >> >> >> I also imagine the other objects (networks and domains) could use the >> similar calls. I guess the answer somewhat depends on what is the >> minimum version of libvirt that needs to be supported. >> > Yep, that is the problem. To limit the work, I guess other change > for networks and domains should be separate patches, if we decide > they are worthy. > >> But if you "have" to stay with the current model... Checked with the new API, it is too new. I hope to stick to API requirement around libvirt 0.9.0 to avoid trouble when user want to just upgrade libvirt-cim as fix, so if this function can ensure no more risk with old libvirt API, I prefer the old way. >> >> * The return 'names[i]' is something you'd have to free() anyway, so >> rather than strdup(names[i]), just take it when setting pools[i].tag and >> set names[i] = NULL; That avoids an error path. >> > let me check. > This seems workable, thanks. >> >> >> John >> >> >> >> _______________________________________________ >> Libvirt-cim mailing list >> Libvirt-cim at redhat.com >> https://www.redhat.com/mailman/listinfo/libvirt-cim >> > > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:07 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:07 +0800 Subject: [Libvirt-cim] [PATCH V5 04/15] do not deregister virt classes in yum upgrade In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-5-git-send-email-xiawenc@linux.vnet.ibm.com> Now yum upgrade will deregister the virt classes, make libvirt-cim not workable. This patch fixed it from now on. Signed-off-by: Wenchao Xia --- libvirt-cim.spec.in | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in index d78eee7..3def978 100644 --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -104,18 +104,22 @@ rm -fr $RPM_BUILD_ROOT -r %{CIMV2_REG} -m %{CIMV2_MOF} -v >/dev/null 2>&1 || true %preun -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ +#Deregister only in uninstall, do nothing in upgrade. +if [ "$1" = "0" ]; then + echo "Deleting registered classes in libvirt-cim..." + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n @CIM_VIRT_NS@ \ -r %{REGISTRATION} -m %{SCHEMA} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/interop \ -r %{INTEROP_REG} -m %{INTEROP_MOF} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/PG_InterOp \ -r %{PGINTEROP_REG} -m %{PGINTEROP_MOF} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/cimv2 \ -r %{CIMV2_REG} -m %{CIMV2_MOF} >/dev/null 2>&1 || true +fi %postun -p /sbin/ldconfig -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:08 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:08 +0800 Subject: [Libvirt-cim] [PATCH V5 05/15] CSI, fix debug print crash In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-6-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan Reviewed-by: Sharad Mishra --- 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 3096683..8250850 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -504,7 +504,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 xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:04 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:04 +0800 Subject: [Libvirt-cim] [PATCH V5 01/15] Remove property CreationClassName in some instance In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-2-git-send-email-xiawenc@linux.vnet.ibm.com> There are some instances which did not register this property, so this patch added a parameter in get_typed_instance(). The caller must set it clearly whether to set the property. When tog-pegasus > 2.12 and its log >= WARNING, tog-pegasus will report this problem in log. Signed-off-by: Wenchao Xia --- libxkutil/misc_util.c | 12 ++++++++---- libxkutil/misc_util.h | 3 ++- src/Virt_AllocationCapabilities.c | 3 ++- src/Virt_ComputerSystem.c | 6 ++++-- src/Virt_ComputerSystemIndication.c | 3 ++- src/Virt_ConsoleRedirectionService.c | 3 ++- src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 ++- src/Virt_Device.c | 18 ++++++++++++------ src/Virt_DevicePool.c | 20 +++++++++++++------- src/Virt_EnabledLogicalElementCapabilities.c | 3 ++- src/Virt_FilterEntry.c | 3 ++- src/Virt_FilterList.c | 3 ++- src/Virt_HostSystem.c | 3 ++- src/Virt_KVMRedirectionSAP.c | 3 ++- src/Virt_RASD.c | 3 ++- src/Virt_ReferencedProfile.c | 3 ++- src/Virt_RegisteredProfile.c | 3 ++- src/Virt_ResourcePoolConfigurationCapabilities.c | 3 ++- src/Virt_ResourcePoolConfigurationService.c | 8 ++++++-- src/Virt_SettingsDefineCapabilities.c | 6 ++++-- src/Virt_SwitchService.c | 3 ++- src/Virt_VSMigrationCapabilities.c | 3 ++- src/Virt_VSMigrationService.c | 6 ++++-- src/Virt_VSMigrationSettingData.c | 3 ++- src/Virt_VSSD.c | 3 ++- src/Virt_VirtualSystemManagementCapabilities.c | 3 ++- src/Virt_VirtualSystemManagementService.c | 6 ++++-- src/Virt_VirtualSystemSnapshotService.c | 3 ++- ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 ++- 29 files changed, 97 insertions(+), 48 deletions(-) diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index 2d149ae..f1b93e4 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -341,7 +341,8 @@ char *get_typed_class(const char *refcn, const char *new_base) CMPIInstance *get_typed_instance(const CMPIBroker *broker, const char *refcn, const char *base, - const char *namespace) + const char *namespace, + bool ccn_flag) { char *new_cn; CMPIObjectPath *op; @@ -360,8 +361,10 @@ CMPIInstance *get_typed_instance(const CMPIBroker *broker, if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - CMSetProperty(inst, "CreationClassName", - (CMPIValue *)new_cn, CMPI_chars); + if (ccn_flag) { + CMSetProperty(inst, "CreationClassName", + (CMPIValue *)new_cn, CMPI_chars); + } out: free(new_cn); @@ -467,7 +470,8 @@ CMPIInstance *make_reference(const CMPIBroker *broker, ref_inst = get_typed_instance(broker, CLASSNAME(source_ref), assoc_classname, - NAMESPACE(source_ref)); + NAMESPACE(source_ref), + false); if (ref_inst != NULL) { CMPIObjectPath *target_ref; diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h index c7a2122..90fb2da 100644 --- a/libxkutil/misc_util.h +++ b/libxkutil/misc_util.h @@ -85,7 +85,8 @@ char *get_typed_class(const char *refcn, const char *new_base); CMPIInstance *get_typed_instance(const CMPIBroker *broker, const char *refcn, const char *base, - const char *namespace); + const char *namespace, + bool ccn_flag); /* Parse an OrgID:LocID string into its constituent parts */ int parse_instance_id(char *iid, char **orgid, char **locid); diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c index 970abeb..b358fac 100644 --- a/src/Virt_AllocationCapabilities.c +++ b/src/Virt_AllocationCapabilities.c @@ -46,7 +46,8 @@ static CMPIStatus ac_from_pool(const CMPIBroker *broker, *alloc_cap = get_typed_instance(broker, CLASSNAME(ref), "AllocationCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (*alloc_cap == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index e6c7e55..4a9b26d 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -440,7 +440,8 @@ CMPIStatus instance_from_dominfo(const CMPIBroker *broker, inst = get_typed_instance(broker, prefix, "ComputerSystem", - namespace); + namespace, + true); if (inst == NULL) { CU_DEBUG("Could not init CS instance. " @@ -560,7 +561,8 @@ static CMPIStatus instance_from_dom(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "ComputerSystem", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 2d0a94e..3096683 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -239,7 +239,8 @@ static bool _do_indication(const CMPIBroker *broker, ind = get_typed_instance(broker, prefix, ind_type_name, - args->ns); + args->ns, + false); /* Generally report errors and hope to continue, since we have no one to actually return status to. */ diff --git a/src/Virt_ConsoleRedirectionService.c b/src/Virt_ConsoleRedirectionService.c index 7b20c0d..16cade8 100644 --- a/src/Virt_ConsoleRedirectionService.c +++ b/src/Virt_ConsoleRedirectionService.c @@ -129,7 +129,8 @@ CMPIStatus get_console_rs(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "ConsoleRedirectionService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_ConsoleRedirectionServiceCapabilities.c b/src/Virt_ConsoleRedirectionServiceCapabilities.c index 11f2986..88fb3a4 100644 --- a/src/Virt_ConsoleRedirectionServiceCapabilities.c +++ b/src/Virt_ConsoleRedirectionServiceCapabilities.c @@ -91,7 +91,8 @@ CMPIStatus get_console_rs_caps(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "ConsoleRedirectionServiceCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_Device.c b/src/Virt_Device.c index e047a94..c7dcbc3 100644 --- a/src/Virt_Device.c +++ b/src/Virt_Device.c @@ -100,7 +100,8 @@ static CMPIInstance *net_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "NetworkPort", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for NetworkPort"); @@ -138,7 +139,8 @@ static CMPIInstance *disk_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "LogicalDisk", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for LogicalDisk"); @@ -185,7 +187,8 @@ static CMPIInstance *mem_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "Memory", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for Memory"); @@ -234,7 +237,8 @@ static CMPIInstance *graphics_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "DisplayController", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for DisplayController"); @@ -320,7 +324,8 @@ static CMPIInstance *input_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "PointingDevice", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance of %s_PointingDevice", pfx_from_conn(conn)); @@ -407,7 +412,8 @@ static bool vcpu_inst(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "Processor", - ns); + ns, + true); if (inst == NULL) return false; diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 202e509..56c9715 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -803,7 +803,8 @@ static CMPIStatus mempool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "MemoryPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, @@ -842,7 +843,8 @@ static CMPIStatus procpool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "ProcessorPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, @@ -872,7 +874,8 @@ static CMPIStatus _netpool_for_parent(struct inst_list *list, inst = get_typed_instance(broker, refcn, "NetworkPool", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", ns, refcn); @@ -928,7 +931,8 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, inst = get_typed_instance(broker, refcn, "NetworkPool", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", ns, refcn); @@ -1046,7 +1050,7 @@ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, CMPIInstance *inst; char *poolid = NULL; - inst = get_typed_instance(broker, refcn, "DiskPool", ns); + inst = get_typed_instance(broker, refcn, "DiskPool", ns, false); if (inst == NULL) { cu_statusf(broker, &s, @@ -1136,7 +1140,8 @@ static CMPIStatus graphicspool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "GraphicsPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -1172,7 +1177,8 @@ static CMPIStatus inputpool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "InputPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_EnabledLogicalElementCapabilities.c b/src/Virt_EnabledLogicalElementCapabilities.c index 7ba5eae..2fcdef1 100644 --- a/src/Virt_EnabledLogicalElementCapabilities.c +++ b/src/Virt_EnabledLogicalElementCapabilities.c @@ -61,7 +61,8 @@ static CMPIInstance *_get_elec(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "EnabledLogicalElementCapabilities", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(broker, s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c index 126615b..3c4a3e6 100644 --- a/src/Virt_FilterEntry.c +++ b/src/Virt_FilterEntry.c @@ -546,7 +546,8 @@ static CMPIInstance *convert_rule_to_instance( inst = get_typed_instance(broker, CLASSNAME(reference), basename, - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c index 9b5dbae..79776cd 100644 --- a/src/Virt_FilterList.c +++ b/src/Virt_FilterList.c @@ -50,7 +50,8 @@ static CMPIInstance *convert_filter_to_instance( inst = get_typed_instance(broker, CLASSNAME(reference), "FilterList", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_HostSystem.c b/src/Virt_HostSystem.c index 724a5ea..c31d6cf 100644 --- a/src/Virt_HostSystem.c +++ b/src/Virt_HostSystem.c @@ -135,7 +135,8 @@ static CMPIStatus fake_host(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "HostSystem", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, diff --git a/src/Virt_KVMRedirectionSAP.c b/src/Virt_KVMRedirectionSAP.c index db34d57..38ad468 100644 --- a/src/Virt_KVMRedirectionSAP.c +++ b/src/Virt_KVMRedirectionSAP.c @@ -125,7 +125,8 @@ static CMPIInstance *get_console_sap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "KVMRedirectionSAP", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c index 9493077..6e8a244 100644 --- a/src/Virt_RASD.c +++ b/src/Virt_RASD.c @@ -716,7 +716,8 @@ CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, inst = get_typed_instance(broker, CLASSNAME(ref), base, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) return inst; diff --git a/src/Virt_ReferencedProfile.c b/src/Virt_ReferencedProfile.c index 150be1f..e78a8d3 100644 --- a/src/Virt_ReferencedProfile.c +++ b/src/Virt_ReferencedProfile.c @@ -242,7 +242,8 @@ static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, ref_inst = get_typed_instance(_BROKER, CLASSNAME(source_ref), assoc_classname, - NAMESPACE(source_ref)); + NAMESPACE(source_ref), + false); source = get_reg_prof_by_ref(source_ref); if (source->scoping_profile != NULL) diff --git a/src/Virt_RegisteredProfile.c b/src/Virt_RegisteredProfile.c index 389a179..e644708 100644 --- a/src/Virt_RegisteredProfile.c +++ b/src/Virt_RegisteredProfile.c @@ -54,7 +54,8 @@ CMPIStatus get_profile(const CMPIBroker *broker, instance = get_typed_instance(broker, pfx, "RegisteredProfile", - CIM_INTEROP_NS); + CIM_INTEROP_NS, + false); if (instance == NULL) { cu_statusf(broker, &s, diff --git a/src/Virt_ResourcePoolConfigurationCapabilities.c b/src/Virt_ResourcePoolConfigurationCapabilities.c index 32274ed..2dcbbcf 100644 --- a/src/Virt_ResourcePoolConfigurationCapabilities.c +++ b/src/Virt_ResourcePoolConfigurationCapabilities.c @@ -69,7 +69,8 @@ static CMPIStatus get_rpc_cap(const CMPIObjectPath *reference, inst = get_typed_instance(_BROKER, pfx_from_conn(conn), "ResourcePoolConfigurationCapabilities", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c index 751d016..0c0cc06 100644 --- a/src/Virt_ResourcePoolConfigurationService.c +++ b/src/Virt_ResourcePoolConfigurationService.c @@ -781,6 +781,8 @@ static const char *rasd_to_res(CMPIInstance *inst, return msg; } +/* Warning: returned instance is not freed manually in caller, need confirm + if server will auto free it. */ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, const CMPIObjectPath *ref, CMPIStatus *s) @@ -798,7 +800,8 @@ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, inst = get_typed_instance(_BROKER, CLASSNAME(ref), "StorageVolumeResourceAllocationSettingData", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, @@ -1279,7 +1282,8 @@ CMPIStatus get_rpcs(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "ResourcePoolConfigurationService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index 9eb9e57..5091205 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -113,7 +113,8 @@ static CMPIInstance *default_vssd_instance(const char *prefix, inst = get_typed_instance(_BROKER, prefix, "VirtualSystemSettingData", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Failed to create default VSSD instance"); goto out; @@ -303,7 +304,8 @@ static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, inst = get_typed_instance(_BROKER, CLASSNAME(ref), base, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(_BROKER, s, diff --git a/src/Virt_SwitchService.c b/src/Virt_SwitchService.c index 7e59d38..8991426 100644 --- a/src/Virt_SwitchService.c +++ b/src/Virt_SwitchService.c @@ -229,7 +229,8 @@ static CMPIStatus get_switchservice(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "SwitchService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_VSMigrationCapabilities.c b/src/Virt_VSMigrationCapabilities.c index 4f0e434..3e53f68 100644 --- a/src/Virt_VSMigrationCapabilities.c +++ b/src/Virt_VSMigrationCapabilities.c @@ -134,7 +134,8 @@ CMPIStatus get_migration_caps(const CMPIObjectPath *ref, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemMigrationCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c index 76e3d25..1f6659d 100644 --- a/src/Virt_VSMigrationService.c +++ b/src/Virt_VSMigrationService.c @@ -831,7 +831,8 @@ static CMPIInstance *prepare_indication(const CMPIBroker *broker, ind = get_typed_instance(broker, pfx, ind_name, - job->ref_ns); + job->ref_ns, + false); if (ind == NULL) { CU_DEBUG("Failed to create ind, type '%s:%s_%s'", job->ref_ns, pfx, ind_name); @@ -1686,7 +1687,8 @@ CMPIStatus get_migration_service(const CMPIObjectPath *ref, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemMigrationService", - NAMESPACE(ref)); + NAMESPACE(ref), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSMigrationSettingData.c b/src/Virt_VSMigrationSettingData.c index a6707bd..eb545f1 100644 --- a/src/Virt_VSMigrationSettingData.c +++ b/src/Virt_VSMigrationSettingData.c @@ -79,7 +79,8 @@ CMPIStatus get_migration_sd(const CMPIObjectPath *ref, inst = get_typed_instance(broker, CLASSNAME(ref), "VirtualSystemMigrationSettingData", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c index 499b157..975623b 100644 --- a/src/Virt_VSSD.c +++ b/src/Virt_VSSD.c @@ -285,7 +285,8 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSettingData", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_VirtualSystemManagementCapabilities.c b/src/Virt_VirtualSystemManagementCapabilities.c index 020ce8a..51738ee 100644 --- a/src/Virt_VirtualSystemManagementCapabilities.c +++ b/src/Virt_VirtualSystemManagementCapabilities.c @@ -129,7 +129,8 @@ CMPIStatus get_vsm_cap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemManagementCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index 10adf8b..96c8a03 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -1928,7 +1928,8 @@ static CMPIStatus raise_rasd_indication(const CMPIContext *context, ind = get_typed_instance(_BROKER, CLASSNAME(ref), base_type, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (ind == NULL) { CU_DEBUG("Failed to get indication instance"); s.rc = CMPI_RC_ERR_FAILED; @@ -3293,7 +3294,8 @@ CMPIStatus get_vsms(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemManagementService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_VirtualSystemSnapshotService.c b/src/Virt_VirtualSystemSnapshotService.c index aae628f..8c0889d 100644 --- a/src/Virt_VirtualSystemSnapshotService.c +++ b/src/Virt_VirtualSystemSnapshotService.c @@ -681,7 +681,8 @@ CMPIStatus get_vsss(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSnapshotService", - NAMESPACE(ref)); + NAMESPACE(ref), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c index 69c8e97..04a9c7a 100644 --- a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c +++ b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c @@ -117,7 +117,8 @@ CMPIStatus get_vss_cap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSnapshotServiceCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:06 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:06 +0800 Subject: [Libvirt-cim] [PATCH V5 03/15] SDC: use property BootDevices instead of BootDevice In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-4-git-send-email-xiawenc@linux.vnet.ibm.com> The property registerted is BootDevices, so correct it. Signed-off-by: Wenchao Xia --- src/Virt_SettingsDefineCapabilities.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index 5091205..1e7a778 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -172,7 +172,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, if (inst == NULL) goto error; - CMSetProperty(inst, "BootDevice", + CMSetProperty(inst, "BootDevices", (CMPIValue *)"hda", CMPI_chars); CMSetProperty(inst, "isFullVirt", @@ -211,7 +211,7 @@ static CMPIStatus _kvm_vsmc_to_vssd(virConnectPtr conn, CMSetProperty(inst, "VirtualSystemIdentifier", (CMPIValue *)"KVM_guest", CMPI_chars); - CMSetProperty(inst, "BootDevice", + CMSetProperty(inst, "BootDevices", (CMPIValue *)"hda", CMPI_chars); inst_list_add(list, inst); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:03 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:03 +0800 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 Message-ID: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> This serial fix a serial of issues. V5: General change: Remove script change patch, need John Ferlan's patch in following. 1/15-3/15: new patch make libvirt-cim conform to DSP more. 6/15: better commit message. 8/15: remove a strdup() to reduce a error path. 10/15: free *xml after a fail. 11/15: return fail when ind == NULL in trigger_mod_indiction(), check return value for calloc() in doms_to_xml(), better debug message, check strdup() return on raise_indication, better traverse in dom list. Reduce condition macros. 12/15: new patch to move CSI-libvirt/CSI-libvirt-cim together. 13/15: remove defensive code, only fix the problem of report fail when some VSSD succeed. 14/15: new separate patch from 15/15, to enhance config reading. 15/15: changed the interface, new method to copy/delete the key, rm the key before copy and check the key's status after copy. Wenchao Xia (15): 1 Remove property CreationClassName in some instance 2 VSSD: add missing property IsFullVirt in schema 3 SDC: use property BootDevices instead of BootDevice 4 do not deregister virt classes in yum upgrade 5 CSI, fix debug print crash 6 CSI, add lock to protect shared data in lifecycle_thread 7 DevicePool, fix debug print crash 8 DevicePool, reimplement get_diskpool_config with libvirt 9 RASDIndication, fix debug print crash 10 device parsing, add debug print 11 CSI Discard libvirt event by default 12 CSI: Move native CSI code together 13 VSSD: report success if not all VS fail in enum 14 misc_util: better way to read config 15 migration: allow ssh based migration with non root's key file libvirt-cim.conf | 19 + libvirt-cim.spec.in | 12 +- libxkutil/device_parsing.c | 16 +- libxkutil/misc_util.c | 135 +++- libxkutil/misc_util.h | 6 +- schema/Virt_VSSD.mof | 3 + src/Virt_AllocationCapabilities.c | 3 +- src/Virt_ComputerSystem.c | 66 ++- src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- src/Virt_ConsoleRedirectionService.c | 3 +- src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- src/Virt_Device.c | 18 +- src/Virt_DevicePool.c | 198 +++-- src/Virt_EnabledLogicalElementCapabilities.c | 3 +- src/Virt_FilterEntry.c | 3 +- src/Virt_FilterList.c | 3 +- src/Virt_HostSystem.c | 3 +- src/Virt_KVMRedirectionSAP.c | 3 +- src/Virt_RASD.c | 3 +- src/Virt_ReferencedProfile.c | 3 +- src/Virt_RegisteredProfile.c | 3 +- src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- src/Virt_ResourcePoolConfigurationService.c | 8 +- src/Virt_SettingsDefineCapabilities.c | 10 +- src/Virt_SwitchService.c | 3 +- src/Virt_VSMigrationCapabilities.c | 3 +- src/Virt_VSMigrationService.c | 269 +++++- src/Virt_VSMigrationSettingData.c | 3 +- src/Virt_VSSD.c | 46 +- src/Virt_VirtualSystemManagementCapabilities.c | 3 +- src/Virt_VirtualSystemManagementService.c | 63 ++- src/Virt_VirtualSystemSnapshotService.c | 3 +- ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- 34 files changed, 1652 insertions(+), 295 deletions(-) From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:12 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:12 +0800 Subject: [Libvirt-cim] [PATCH V5 09/15] RASDIndication, fix debug print crash In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-10-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan Reviewed-by: Sharad Mishra --- 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 Thu Mar 21 03:39:10 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:10 +0800 Subject: [Libvirt-cim] [PATCH V5 07/15] DevicePool, fix debug print crash In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-8-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- 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 56c9715..08677e2 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 Thu Mar 21 03:39:16 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:16 +0800 Subject: [Libvirt-cim] [PATCH V5 13/15] VSSD: report success if not all VS fail in enum In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-14-git-send-email-xiawenc@linux.vnet.ibm.com> Original code 'continue' in the 'for' in return_enum_vssd() when one VSDS fail in retrieving, but forgot to set s to normal. This patch fix this case. Also many debug message is added to log the error if met. Signed-off-by: Wenchao Xia --- src/Virt_VSSD.c | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c index 975623b..3d2de26 100644 --- a/src/Virt_VSSD.c +++ b/src/Virt_VSSD.c @@ -181,8 +181,10 @@ static int instance_from_dom(const CMPIBroker *broker, struct domain *dominfo = NULL; ret = get_dominfo(dom, &dominfo); - if (!ret) + if (!ret) { + CU_DEBUG("Failed in get_dominfo()."); goto out; + } op = CMGetObjectPath(inst, NULL); pfx = class_prefix_name(CLASSNAME(op)); @@ -245,6 +247,7 @@ static int instance_from_dom(const CMPIBroker *broker, (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU)) { s = _set_fv_prop(broker, dominfo, inst); if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to set full virtual props."); ret = 0; goto out; } @@ -259,6 +262,7 @@ static int instance_from_dom(const CMPIBroker *broker, dominfo->type); if (asprintf(&vsid, "%s:%s", pfx, dominfo->name) == -1) { + CU_DEBUG("Failed in asprintf()."); ret = 0; goto out; } @@ -328,14 +332,34 @@ 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); virDomainFree(list[i]); - if (inst == NULL) + if (inst == NULL) { + /* log the error */ + const char *dom_name = virDomainGetName(list[i]); + if (s.msg) { + CU_DEBUG("Failed to get VSSD instance from " + "domain [%s], status msg [%s].", + dom_name, CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Failed to get VSSD instance from " + "domain [%s].", + dom_name); + } + /* restore s until last one */ + if (i < count - 1) { + cu_statusf(_BROKER, &s, + CMPI_RC_OK, + "NULL"); + } + fail_count++; continue; + } if (names_only) cu_return_instance_name(results, inst); @@ -343,6 +367,21 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, CMReturnInstance(results, inst); } + /* check if some VS fail */ + if (fail_count > 0) { + CU_DEBUG("Failed to get %d VSSD in enum, total is %d.", + fail_count, count); + if (fail_count < count) { + /* consider it succeed, some VSSD will be returned */ + cu_statusf(_BROKER, &s, + CMPI_RC_OK, + "Got %d/%d VSSD, " + "some VS may changed during enum", + count - fail_count, count); + } + } + + out: free(list); virConnectClose(conn); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:05 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:05 +0800 Subject: [Libvirt-cim] [PATCH V5 02/15] VSSD: add missing property IsFullVirt in schema In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> This property is used but not defined, so add it. Signed-off-by: Wenchao Xia --- schema/Virt_VSSD.mof | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/schema/Virt_VSSD.mof b/schema/Virt_VSSD.mof index baf4ac2..b960450 100644 --- a/schema/Virt_VSSD.mof +++ b/schema/Virt_VSSD.mof @@ -27,4 +27,7 @@ class Virt_VirtualSystemSettingData : CIM_VirtualSystemSettingData [Description ("Flag to determine whether this guest has to be autostarted on reboot")] uint16 AutoStart; + [Description ("Flag to determine whether this guest is a full virtualization")] + boolean IsFullVirt; + }; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:15 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:15 +0800 Subject: [Libvirt-cim] [PATCH V5 12/15] CSI: Move native CSI code together In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-13-git-send-email-xiawenc@linux.vnet.ibm.com> This is a pure code move patch. Now codes using libvirt event or native event, are moved into one macro protection, which make code easy to read, and in futher they can be moved into new file as CSI-libvirt.c. This patch also fix code style problem in moved code. Signed-off-by: Wenchao Xia --- src/Virt_ComputerSystemIndication.c | 851 ++++++++++++++++++----------------- 1 files changed, 429 insertions(+), 422 deletions(-) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index ef449ff..247143c 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -83,106 +83,6 @@ 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}}; -#ifndef USE_LIBVIRT_EVENT -#else -/* - * Domain manipulation - */ -static void csi_dom_xml_free(void *data) -{ - csi_dom_xml_t *dom = (csi_dom_xml_t *) data; - free(dom->xml); - free(dom->name); - free(dom); -} - -static int csi_dom_xml_cmp(void *data, void *cmp_cb_data) -{ - csi_dom_xml_t *dom = (csi_dom_xml_t *) data; - const char *uuid = (const char *) cmp_cb_data; - - return strcmp(dom->uuid, uuid); -} - -static int csi_dom_xml_set(csi_dom_xml_t *dom, virDomainPtr dom_ptr, CMPIStatus *s) -{ - const char *name; - - name = virDomainGetName(dom_ptr); - if (name == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get domain name"); - return -1; - } - - dom->name = strdup(name); - - /* xml */ - dom->xml = virDomainGetXMLDesc(dom_ptr, - VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); - if (dom->xml == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get xml desc"); - return -1; - } - - return 0; -} - -static csi_dom_xml_t *csi_dom_xml_new(virDomainPtr dom_ptr, CMPIStatus *s) -{ - int rc; - csi_dom_xml_t *dom; - - dom = calloc(1, sizeof(*dom)); - if (dom == NULL) - return NULL; - - /* uuid */ - rc = virDomainGetUUIDString(dom_ptr, dom->uuid); - if (rc == -1) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get domain UUID"); - goto error; - } - - if (csi_dom_xml_set(dom, dom_ptr, s) == -1) - goto error; - - return dom; - - error: - csi_dom_xml_free(dom); - return NULL; -} - -static void csi_thread_dom_list_append(csi_thread_data_t *thread, - csi_dom_xml_t *dom) -{ - if (thread->dom_list == NULL) - thread->dom_list = list_new(csi_dom_xml_free, csi_dom_xml_cmp); - - list_append(thread->dom_list, dom); -} - -static void csi_free_thread_data(void *data) -{ - csi_thread_data_t *thread = (csi_thread_data_t *) 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); -} -#endif - void set_source_inst_props(const CMPIBroker *broker, const CMPIContext *context, const CMPIObjectPath *ref, @@ -388,6 +288,64 @@ static bool create_deleted_guest_inst(const char *xml, return rc; } +static int platform_from_class(const char *cn) +{ + if (STARTS_WITH(cn, "Xen")) { + return CSI_XEN; + } else if (STARTS_WITH(cn, "KVM")) { + return CSI_KVM; + } else if (STARTS_WITH(cn, "LXC")) { + return CSI_LXC; + } else { + return -1; + } +} + +static _EI_RTYPE EnableIndications(CMPIIndicationMI *mi, + const CMPIContext *ctx) +{ + CU_DEBUG("EnableIndications"); + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = true; + pthread_mutex_unlock(&lifecycle_mutex); + + _EI_RET(); +} + +static _EI_RTYPE DisableIndications(CMPIIndicationMI *mi, + const CMPIContext *ctx) +{ + CU_DEBUG("DisableIndications"); + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = false; + pthread_mutex_unlock(&lifecycle_mutex); + + _EI_RET(); +} + +DECLARE_FILTER(xen_created, "Xen_ComputerSystemCreatedIndication"); +DECLARE_FILTER(xen_deleted, "Xen_ComputerSystemDeletedIndication"); +DECLARE_FILTER(xen_modified, "Xen_ComputerSystemModifiedIndication"); +DECLARE_FILTER(kvm_created, "KVM_ComputerSystemCreatedIndication"); +DECLARE_FILTER(kvm_deleted, "KVM_ComputerSystemDeletedIndication"); +DECLARE_FILTER(kvm_modified, "KVM_ComputerSystemModifiedIndication"); +DECLARE_FILTER(lxc_created, "LXC_ComputerSystemCreatedIndication"); +DECLARE_FILTER(lxc_deleted, "LXC_ComputerSystemDeletedIndication"); +DECLARE_FILTER(lxc_modified, "LXC_ComputerSystemModifiedIndication"); + +static struct std_ind_filter *filters[] = { + &xen_created, + &xen_deleted, + &xen_modified, + &kvm_created, + &kvm_deleted, + &kvm_modified, + &lxc_created, + &lxc_deleted, + &lxc_modified, + NULL, +}; + #ifndef USE_LIBVIRT_EVENT /* libvirt-cim's private CSI implement */ @@ -775,7 +733,377 @@ static CMPI_THREAD_RETURN lifecycle_thread_native(void *params) return (CMPI_THREAD_RETURN) 0; } + +static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean first) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct std_indication_ctx *_ctx; + struct ind_args *args = NULL; + int platform; + bool error = false; + csi_thread_data_t *thread = NULL; + + CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); + + pthread_mutex_lock(&lifecycle_mutex); + + CU_DEBUG("Using libvirt-cim's event implemention."); + + _ctx = (struct std_indication_ctx *)mi->hdl; + + if (CMIsNullObject(op)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No ObjectPath given"); + goto out; + } + + /* FIXME: op is stale the second time around, for some reason */ + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + thread = &csi_thread_data[platform]; + thread->active_filters += 1; + + /* Check if thread is already running */ + if (thread->id > 0) { + goto out; + } + + args = malloc(sizeof(*args)); + if (args == NULL) { + CU_DEBUG("Failed to allocate ind_args"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + error = true; + goto out; + } + + args->context = CBPrepareAttachThread(_BROKER, ctx); + if (args->context == NULL) { + CU_DEBUG("Failed to create thread context"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to create thread context"); + error = true; + goto out; + } + + args->ns = strdup(NAMESPACE(op)); + args->classname = strdup(CLASSNAME(op)); + args->_ctx = _ctx; + + thread->args = args; + + thread->id = _BROKER->xft->newThread(lifecycle_thread_native, + thread, 0); + + if (thread->id <= 0) { + CU_DEBUG("Error, failed to create new thread."); + error = true; + } + + out: + if (error == true) { + thread->active_filters -= 1; + free(args); + } + + pthread_mutex_unlock(&lifecycle_mutex); + + return s; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean last) +{ + int platform; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); + + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + + pthread_mutex_lock(&lifecycle_mutex); + csi_thread_data[platform].active_filters -= 1; + pthread_mutex_unlock(&lifecycle_mutex); + + pthread_cond_signal(&lifecycle_cond); + + out: + return s; +} + +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)); + if (!args->classname || !args->ns) { + CU_DEBUG("Failed in strdup"); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed in strdup in indication raising"); + goto out; + } + 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; +} + +static struct std_indication_handler csi = { + .raise_fn = raise_indication, + .trigger_fn = trigger_indication, + .activate_fn = ActivateFilter, + .deactivate_fn = DeActivateFilter, + .enable_fn = EnableIndications, + .disable_fn = DisableIndications, +}; #else +/* Using libvirt's event to implement CSI */ + +/* + * Domain manipulation + */ +static void csi_dom_xml_free(void *data) +{ + csi_dom_xml_t *dom = (csi_dom_xml_t *) data; + free(dom->xml); + free(dom->name); + free(dom); +} + +static int csi_dom_xml_cmp(void *data, void *cmp_cb_data) +{ + csi_dom_xml_t *dom = (csi_dom_xml_t *) data; + const char *uuid = (const char *) cmp_cb_data; + + return strcmp(dom->uuid, uuid); +} + +static int csi_dom_xml_set(csi_dom_xml_t *dom, + virDomainPtr dom_ptr, + CMPIStatus *s) +{ + const char *name; + + name = virDomainGetName(dom_ptr); + if (name == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get domain name"); + return -1; + } + + dom->name = strdup(name); + + /* xml */ + dom->xml = virDomainGetXMLDesc(dom_ptr, + VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); + if (dom->xml == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get xml desc"); + return -1; + } + + return 0; +} + +static csi_dom_xml_t *csi_dom_xml_new(virDomainPtr dom_ptr, CMPIStatus *s) +{ + int rc; + csi_dom_xml_t *dom; + + dom = calloc(1, sizeof(*dom)); + if (dom == NULL) { + return NULL; + } + + /* uuid */ + rc = virDomainGetUUIDString(dom_ptr, dom->uuid); + if (rc == -1) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get domain UUID"); + goto error; + } + + if (csi_dom_xml_set(dom, dom_ptr, s) == -1) { + goto error; + } + + return dom; + + error: + csi_dom_xml_free(dom); + return NULL; +} + +static void csi_thread_dom_list_append(csi_thread_data_t *thread, + csi_dom_xml_t *dom) +{ + if (thread->dom_list == NULL) { + thread->dom_list = list_new(csi_dom_xml_free, csi_dom_xml_cmp); + } + + list_append(thread->dom_list, dom); +} + +static void csi_free_thread_data(void *data) +{ + csi_thread_data_t *thread = (csi_thread_data_t *) 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); +} + static bool async_ind(struct ind_args *args, int ind_type, csi_dom_xml_t *dom, @@ -1059,176 +1387,7 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) free(prefix); return (CMPI_THREAD_RETURN) 0; } -#endif - -static int platform_from_class(const char *cn) -{ - if (STARTS_WITH(cn, "Xen")) - return CSI_XEN; - else if (STARTS_WITH(cn, "KVM")) - return CSI_KVM; - else if (STARTS_WITH(cn, "LXC")) - return CSI_LXC; - else - return -1; -} - -#ifndef USE_LIBVIRT_EVENT -static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, - const CMPIContext *ctx, - const CMPISelectExp *se, - const char *ns, - const CMPIObjectPath *op, - CMPIBoolean first) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - struct std_indication_ctx *_ctx; - struct ind_args *args = NULL; - int platform; - bool error = false; - csi_thread_data_t *thread = NULL; - - CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); - - pthread_mutex_lock(&lifecycle_mutex); - - CU_DEBUG("Using libvirt-cim's event implemention."); - - _ctx = (struct std_indication_ctx *)mi->hdl; - - if (CMIsNullObject(op)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No ObjectPath given"); - goto out; - } - - /* FIXME: op is stale the second time around, for some reason */ - platform = platform_from_class(CLASSNAME(op)); - if (platform < 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unknown platform"); - goto out; - } - - thread = &csi_thread_data[platform]; - thread->active_filters += 1; - - /* Check if thread is already running */ - if (thread->id > 0) { - goto out; - } - - args = malloc(sizeof(*args)); - if (args == NULL) { - CU_DEBUG("Failed to allocate ind_args"); - cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Unable to allocate ind_args"); - error = true; - goto out; - } - - args->context = CBPrepareAttachThread(_BROKER, ctx); - if (args->context == NULL) { - CU_DEBUG("Failed to create thread context"); - cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Unable to create thread context"); - error = true; - goto out; - } - - args->ns = strdup(NAMESPACE(op)); - args->classname = strdup(CLASSNAME(op)); - args->_ctx = _ctx; - - thread->args = args; - - thread->id = _BROKER->xft->newThread(lifecycle_thread_native, - thread, 0); - - if (thread->id <= 0) { - CU_DEBUG("Error, failed to create new thread."); - error = true; - } - - out: - if (error == true) { - thread->active_filters -= 1; - free(args); - } - - pthread_mutex_unlock(&lifecycle_mutex); - - return s; -} - -static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, - const CMPIContext *ctx, - const CMPISelectExp *se, - const char *ns, - const CMPIObjectPath *op, - CMPIBoolean last) -{ - int platform; - CMPIStatus s = {CMPI_RC_OK, NULL}; - - CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); - platform = platform_from_class(CLASSNAME(op)); - if (platform < 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unknown platform"); - goto out; - } - - - pthread_mutex_lock(&lifecycle_mutex); - csi_thread_data[platform].active_filters -= 1; - pthread_mutex_unlock(&lifecycle_mutex); - - pthread_cond_signal(&lifecycle_cond); - - out: - return s; -} - -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; -} -#else static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, const CMPIContext* ctx, const CMPISelectExp* se, @@ -1348,166 +1507,14 @@ static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, out: return s; } -#endif - -static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, - const CMPIContext *ctx) -{ - CU_DEBUG("EnableIndications"); - pthread_mutex_lock(&lifecycle_mutex); - lifecycle_enabled = true; - pthread_mutex_unlock(&lifecycle_mutex); - - _EI_RET(); -} - -static _EI_RTYPE DisableIndications(CMPIIndicationMI* mi, - const CMPIContext *ctx) -{ - CU_DEBUG("DisableIndications"); - pthread_mutex_lock(&lifecycle_mutex); - lifecycle_enabled = false; - pthread_mutex_unlock(&lifecycle_mutex); - - _EI_RET(); -} - -DECLARE_FILTER(xen_created, "Xen_ComputerSystemCreatedIndication"); -DECLARE_FILTER(xen_deleted, "Xen_ComputerSystemDeletedIndication"); -DECLARE_FILTER(xen_modified, "Xen_ComputerSystemModifiedIndication"); -DECLARE_FILTER(kvm_created, "KVM_ComputerSystemCreatedIndication"); -DECLARE_FILTER(kvm_deleted, "KVM_ComputerSystemDeletedIndication"); -DECLARE_FILTER(kvm_modified, "KVM_ComputerSystemModifiedIndication"); -DECLARE_FILTER(lxc_created, "LXC_ComputerSystemCreatedIndication"); -DECLARE_FILTER(lxc_deleted, "LXC_ComputerSystemDeletedIndication"); -DECLARE_FILTER(lxc_modified, "LXC_ComputerSystemModifiedIndication"); - -static struct std_ind_filter *filters[] = { - &xen_created, - &xen_deleted, - &xen_modified, - &kvm_created, - &kvm_deleted, - &kvm_modified, - &lxc_created, - &lxc_deleted, - &lxc_modified, - NULL, -}; - -#ifndef USE_LIBVIRT_EVENT -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)); - if (!args->classname || !args->ns) { - CU_DEBUG("Failed in strdup"); - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Failed in strdup in indication raising"); - goto out; - } - 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, .disable_fn = DisableIndications, }; +#endif DEFAULT_IND_CLEANUP(); DEFAULT_AF(); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:14 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:14 +0800 Subject: [Libvirt-cim] [PATCH V5 11/15] CSI Discard libvirt event by default In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-12-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. Most possible is that tog-pegasus tries to manage all threads resulting the error. 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 Note that to make review easy, this patch try move the code as little as possible, a following "clean up" patch will move the code together. Signed-off-by: Wenchao Xia --- src/Virt_ComputerSystem.c | 60 +++- src/Virt_ComputerSystemIndication.c | 663 ++++++++++++++++++++++++++++- src/Virt_VirtualSystemManagementService.c | 57 +++- 3 files changed, 777 insertions(+), 3 deletions(-) diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index 4a9b26d..d37159f 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -45,8 +45,58 @@ #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 CMPIBroker *broker, + 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 libvirt-cim native ComputerSystem indication"); + + ind = get_typed_instance(broker, + CLASSNAME(ref), + ind_name, + NAMESPACE(ref), + false); + if (ind == NULL) { + CU_DEBUG("Failed to create ind '%s'", ind_name); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "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; +} +#else +static bool trigger_mod_indication(const CMPIBroker *broker, + const CMPIContext *context, + CMPIInstance *prev_inst, + const CMPIObjectPath *ref) +{ + return true; +} +#endif + /* Set the "Name" property of an instance from a domain */ static int set_name_from_dom(virDomainPtr dom, CMPIInstance *instance) { @@ -1258,8 +1308,16 @@ static CMPIStatus state_change(CMPIMethodMI *self, s = __state_change(name, state, reference); - if (s.rc == CMPI_RC_OK) + if (s.rc == CMPI_RC_OK) { rc = 0; + /* try trigger indication */ + bool ind_rc = trigger_mod_indication(_BROKER, context, + prev_inst, reference); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "state change, dom is '%s'", name); + } + } out: CMReturnData(results, &rc, CMPI_uint32); diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 3df47fa..ef449ff 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -48,7 +48,6 @@ #include "Virt_ComputerSystemIndication.h" #include "Virt_HostSystem.h" - #define CSI_NUM_PLATFORMS 3 enum CSI_PLATFORMS { CSI_XEN, @@ -84,6 +83,8 @@ 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}}; +#ifndef USE_LIBVIRT_EVENT +#else /* * Domain manipulation */ @@ -180,6 +181,7 @@ static void csi_free_thread_data(void *data) stdi_free_ind_args(&thread->args); pthread_mutex_unlock(&lifecycle_mutex); } +#endif void set_source_inst_props(const CMPIBroker *broker, const CMPIContext *context, @@ -386,6 +388,394 @@ static bool create_deleted_guest_inst(const char *xml, return rc; } +#ifndef USE_LIBVIRT_EVENT +/* libvirt-cim's private CSI implement */ + +#define WAIT_TIME 60 +#define FAIL_WAIT_TIME 2 + +static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER; + +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)); + if (!dom_xml_list) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed calloc %d dom_xml.", dom_ptr_count); + return s; + } + 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 !ret; +} + +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 dilivery 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 %d", ind_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); + } else if (dom_changed(prev_xml[i], + cur_xml, cur_count)) { + 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; +} +#else static bool async_ind(struct ind_args *args, int ind_type, csi_dom_xml_t *dom, @@ -669,6 +1059,7 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) free(prefix); return (CMPI_THREAD_RETURN) 0; } +#endif static int platform_from_class(const char *cn) { @@ -682,6 +1073,162 @@ static int platform_from_class(const char *cn) return -1; } +#ifndef USE_LIBVIRT_EVENT +static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean first) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct std_indication_ctx *_ctx; + struct ind_args *args = NULL; + int platform; + bool error = false; + csi_thread_data_t *thread = NULL; + + CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); + + pthread_mutex_lock(&lifecycle_mutex); + + CU_DEBUG("Using libvirt-cim's event implemention."); + + _ctx = (struct std_indication_ctx *)mi->hdl; + + if (CMIsNullObject(op)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No ObjectPath given"); + goto out; + } + + /* FIXME: op is stale the second time around, for some reason */ + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + thread = &csi_thread_data[platform]; + thread->active_filters += 1; + + /* Check if thread is already running */ + if (thread->id > 0) { + goto out; + } + + args = malloc(sizeof(*args)); + if (args == NULL) { + CU_DEBUG("Failed to allocate ind_args"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + error = true; + goto out; + } + + args->context = CBPrepareAttachThread(_BROKER, ctx); + if (args->context == NULL) { + CU_DEBUG("Failed to create thread context"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to create thread context"); + error = true; + goto out; + } + + args->ns = strdup(NAMESPACE(op)); + args->classname = strdup(CLASSNAME(op)); + args->_ctx = _ctx; + + thread->args = args; + + thread->id = _BROKER->xft->newThread(lifecycle_thread_native, + thread, 0); + + if (thread->id <= 0) { + CU_DEBUG("Error, failed to create new thread."); + error = true; + } + + out: + if (error == true) { + thread->active_filters -= 1; + free(args); + } + + pthread_mutex_unlock(&lifecycle_mutex); + + return s; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean last) +{ + int platform; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); + + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + + pthread_mutex_lock(&lifecycle_mutex); + csi_thread_data[platform].active_filters -= 1; + pthread_mutex_unlock(&lifecycle_mutex); + + pthread_cond_signal(&lifecycle_cond); + + out: + return s; +} + +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; +} +#else static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, const CMPIContext* ctx, const CMPISelectExp* se, @@ -703,6 +1250,7 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, if (events_registered == 0) { events_registered = 1; + CU_DEBUG("Registering libvirt event."); virEventRegisterDefaultImpl(); } @@ -756,6 +1304,11 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, thread->args = args; 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) { thread->active_filters -= 1; @@ -795,6 +1348,7 @@ static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, out: return s; } +#endif static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, const CMPIContext *ctx) @@ -841,7 +1395,114 @@ static struct std_ind_filter *filters[] = { NULL, }; +#ifndef USE_LIBVIRT_EVENT +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)); + if (!args->classname || !args->ns) { + CU_DEBUG("Failed in strdup"); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed in strdup in indication raising"); + goto out; + } + 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 96c8a03..4da92e3 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -107,6 +107,33 @@ enum ResourceAction { RESOURCE_MOD, }; +#ifndef USE_LIBVIRT_EVENT +static bool trigger_indication(const CMPIBroker *broker, + 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; +} +#else +static bool trigger_indication(const CMPIBroker *broker; + const CMPIContext *context, + const char *base_type, + const CMPIObjectPath *ref) +{ + return true; +} +#endif + #if LIBVIR_VERSION_NUMBER < 9000 /* Network QoS support */ static CMPIStatus add_qos_for_mac(const uint64_t qos, @@ -2167,6 +2194,16 @@ static CMPIStatus define_system(CMPIMethodMI *self, CMAddArg(argsout, "ResultingSystem", &result, CMPI_ref); } + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemCreatedIndication", reference); + if (!ind_rc) { + const char *dom_name = NULL; + cu_get_str_prop(vssd, "VirtualSystemIdentifier", &dom_name); + CU_DEBUG("Unable to trigger indication for " + "system create, dom is '%s'", dom_name); + } + out: if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; @@ -2269,6 +2306,15 @@ error: NULL, reference, &list); + + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemDeletedIndication", reference); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "system delete, dom is '%s'", dom_name); + } + } virDomainFree(dom); @@ -2350,8 +2396,17 @@ 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); + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemModifiedIndication", ref); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "system modify, dom is '%s'", name); + } + + } out: free(xml); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:09 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:09 +0800 Subject: [Libvirt-cim] [PATCH V5 06/15] CSI, add lock to protect shared data in lifecycle_thread In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-7-git-send-email-xiawenc@linux.vnet.ibm.com> This patch use lock 'lifecycle_mutex' to protect gloable shared data in lifecycle_thread(). This lock exist in Activate/Deactivate Enable/Disable method, which is meant to protect the gloable shared data, but forgot to be added in new libvirt based CSI thread. This patch can avoid following risk at least: Original code have a small chance to free thread->args in child thread just after main thread malloc it, for that thread->id is set to zero allowing main thread to enter that code. This patch focus on adding missing lock, the CSI can be still improved as: smaller lock, folder lock into a structure with data to tip better what it is doing. 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 8250850..3df47fa 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, @@ -491,6 +493,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, @@ -503,10 +507,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); @@ -538,7 +545,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) { @@ -546,12 +555,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); @@ -559,7 +572,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: @@ -580,10 +595,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; } @@ -595,33 +612,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; @@ -629,6 +660,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 Thu Mar 21 03:39:11 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:11 +0800 Subject: [Libvirt-cim] [PATCH V5 08/15] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-9-git-send-email-xiawenc@linux.vnet.ibm.com> Original implemetion may return pools with NULL name if some pool disappear between two libvirt pool API call. And originally it return the number of pools and negative value when error happens, but caller of this function consider number = 0 as error. As a fix, this patch changed the function prototype, it do not return the pool number anymore, it returns 0 on success and negative on fail now. Code for checking the risk of returning pools with NULL name is also added. Another small fix is, return false in get_disk_parent() when strdup fail. Signed-off-by: Wenchao Xia --- src/Virt_DevicePool.c | 176 +++++++++++++++++++++++++++++++++---------------- 1 files changed, 120 insertions(+), 56 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 08677e2..185e3cc 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -51,6 +51,22 @@ struct tmp_disk_pool { bool primordial; }; +static void free_diskpool(struct tmp_disk_pool *pools, int count) +{ + int i; + + if (pools == NULL) { + return; + } + + for (i = 0; i < count; i++) { + free(pools[i].tag); + free(pools[i].path); + } + + free(pools); +} + /* * Right now, detect support and use it, if available. * Later, this can be a configure option if needed @@ -78,6 +94,10 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, } pools[count].tag = strdup("0"); + if (pools[count].tag == NULL) { + count++; + goto free; + } pools[count].path = NULL; pools[count].primordial = true; count++; @@ -85,12 +105,17 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, *_count = count; *_pools = pools; ret = true; + goto out; + free: + free_diskpool(pools, count); + /* old pool is invalid, update it */ + *_count = 0; + *_pools = NULL; out: return ret; } - #if VIR_USE_LIBVIRT_STORAGE int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) { @@ -117,52 +142,82 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) return ret; } +/* This function returns 0 on sucess, negative on fail. */ static int get_diskpool_config(virConnectPtr conn, - struct tmp_disk_pool **_pools) + struct tmp_disk_pool **_pools, + int *_count) { - int count = 0; + int count = 0, realcount = 0; int i; char ** names = NULL; struct tmp_disk_pool *pools = NULL; + int ret = 0; + bool bret; count = virConnectNumOfStoragePools(conn); - if (count <= 0) + if (count < 0) { + ret = count; goto out; + } else if (count == 0) { + goto set_parent; + } names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); - count = 0; + ret = -1; goto out; } - if (virConnectListStoragePools(conn, names, count) == -1) { - CU_DEBUG("Failed to get storage pools"); - count = 0; - goto out; + realcount = virConnectListStoragePools(conn, names, count); + if (realcount < 0) { + CU_DEBUG("Failed to get storage pools, return %d.", realcount); + ret = realcount; + goto free_names; + } + if (realcount == 0) { + CU_DEBUG("Zero pools got, but prelist is %d.", count); + goto set_parent; } - pools = calloc(count, sizeof(*pools)); + pools = calloc(realcount, sizeof(*pools)); if (pools == NULL) { - CU_DEBUG("Failed to alloc space for %i pool structs", count); - goto out; + CU_DEBUG("Failed to alloc space for %i pool structs", + realcount); + ret = -2; + goto free_names; } - for (i = 0; i < count; i++) { - pools[i].tag = strdup(names[i]); + for (i = 0; i < realcount; i++) { + pools[i].tag = names[i]; + names[i] = NULL; pools[i].primordial = false; } - out: - for (i = 0; i < count; i++) - free(names[i]); - free(names); - - get_disk_parent(&pools, &count); + set_parent: + bret = get_disk_parent(&pools, &realcount); + if (bret != true) { + CU_DEBUG("Failed in adding parentpool."); + ret = -4; + goto free_pools; + } + /* succeed */ *_pools = pools; + *_count = realcount; + goto free_names; + + free_pools: + free_diskpool(pools, realcount); - return count; + free_names: + for (i = 0; i < count; i++) { + free(names[i]); + } + free(names); + + out: + return ret; } static bool diskpool_set_capacity(virConnectPtr conn, @@ -294,42 +349,59 @@ static int parse_diskpool_line(struct tmp_disk_pool *pool, return (ret == 2); } +/* return 0 on sucess, negative on fail. */ static int get_diskpool_config(virConnectPtr conn, - struct tmp_disk_pool **_pools) + struct tmp_disk_pool **_pools, + int *_count) { const char *path = DISK_POOL_CONFIG; FILE *config; char *line = NULL; size_t len = 0; - int count = 0; - struct tmp_disk_pool *pools = NULL; + int count = 0, ret = 0; + struct tmp_disk_pool *pools = NULL, *new_pools = NULL; + bool bret; config = fopen(path, "r"); if (config == NULL) { CU_DEBUG("Failed to open %s: %m", path); - return 0; + ret = -1; + goto out; } while (getline(&line, &len, config) > 0) { - pools = realloc(pools, - (count + 1) * (sizeof(*pools))); - if (pools == NULL) { + new_pools = realloc(pools, + (count + 1) * (sizeof(*pools))); + if (new_pools == NULL) { CU_DEBUG("Failed to alloc new pool"); - goto out; + ret = -2; + goto free_pools; } + pools = new_pools; if (parse_diskpool_line(&pools[count], line)) count++; } + bret = get_disk_parent(&pools, &count); + if (bret != true) { + CU_DEBUG("Failed in adding parentpool."); + ret = -3; + goto free_pools; + } - get_disk_parent(&pools, &count); - out: - free(line); + /* succeed */ *_pools = pools; - fclose(config); + *_count = count; + goto clean; - return count; + free_pools: + free_diskpool(pools, count); + clean: + free(line); + fclose(config); + out: + return ret; } static bool diskpool_set_capacity(virConnectPtr conn, @@ -367,39 +439,23 @@ static bool diskpool_set_capacity(virConnectPtr conn, } static bool _diskpool_is_member(virConnectPtr conn, - const struct disk_pool *pool, + const struct tmp_disk_pool *pool, const char *file) { return STARTS_WITH(file, pool->path); } #endif -static void free_diskpool(struct tmp_disk_pool *pools, int count) -{ - int i; - - if (pools == NULL) - return; - - for (i = 0; i < count; i++) { - free(pools[i].tag); - free(pools[i].path); - } - - free(pools); -} - static char *_diskpool_member_of(virConnectPtr conn, const char *file) { struct tmp_disk_pool *pools = NULL; int count; - int i; + int i, ret; char *pool = NULL; - count = get_diskpool_config(conn, &pools); - if (count == 0) { - free(pools); + ret = get_diskpool_config(conn, &pools, &count); + if (ret < 0) { return NULL; } @@ -1088,9 +1144,17 @@ static CMPIStatus diskpool_instance(virConnectPtr conn, CMPIStatus s = {CMPI_RC_OK, NULL}; struct tmp_disk_pool *pools = NULL; int count = 0; - int i; + int i, ret; - count = get_diskpool_config(conn, &pools); + ret = get_diskpool_config(conn, &pools, &count); + if (ret < 0) { + CU_DEBUG("Failed to get diskpool config, return is %d.", ret); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to get diskpool config, return is %d.", + ret); + return s; + } if ((id == NULL) && (count == 0)) { CU_DEBUG("No defined DiskPools"); free(pools); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:13 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:13 +0800 Subject: [Libvirt-cim] [PATCH V5 10/15] device parsing, add debug print In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-11-git-send-email-xiawenc@linux.vnet.ibm.com> Sometimes libvirt will fail in these APIs if there is low level error, what we saw is libvirt can't got xml for some domain. This patch adds debug log when met this error, so in future we can know what is wrong. Signed-off-by: Wenchao Xia --- libxkutil/device_parsing.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index ceb4552..845a953 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -1251,15 +1251,25 @@ 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) - return 0; + if (ret != 1) { + CU_DEBUG("Failed to translate xml into struct domain"); + goto out; + } + if (virDomainGetAutostart(dom, &start) != 0) { + CU_DEBUG("Failed to get dom autostart with libvirt API."); + ret = 0; + goto out; + } (*dominfo)->autostrt = start; + out: free(xml); return ret; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:18 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:18 +0800 Subject: [Libvirt-cim] [PATCH V5 15/15] migration: allow ssh based migration with non root's key file In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> This patch allow libvirt-cim to use non-root's ssh key in migration to avoid exposing root's ssh login on server. In some case server are forbidden to expose or provide any root ssh login, and still use ssh encryption between two migration nodes with key of special account created for virtual machine management. When it is enabled in config file: 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key to be copied. It will be copied to [migrate_ssh_temp_key]. 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, use bool property [MigrationWithoutRootKey], to tell whether to use the key as [migrate_ssh_temp_key]. 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be deleted. Details: libvirt-cim would run shell command "cp -f [SSH_Key_Src] [migrate_ssh_temp_key]", then use [migrate_ssh_temp_key] to generate uri suffix for remote connection to migration destination. Signed-off-by: Wenchao Xia --- libvirt-cim.conf | 19 +++ libxkutil/misc_util.c | 9 ++ libxkutil/misc_util.h | 3 + src/Virt_VSMigrationService.c | 263 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 289 insertions(+), 5 deletions(-) diff --git a/libvirt-cim.conf b/libvirt-cim.conf index d3cb2c3..37d7b0f 100644 --- a/libvirt-cim.conf +++ b/libvirt-cim.conf @@ -11,3 +11,22 @@ # Default value: false # # readonly = false; + +# migrate_ssh_temp_key (string) +# Defines a temp key file which would be used as ssh key in ssh migration, +# Only when it is set, following methods in VirtualSystemMigrationService +# could be used: +# 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key +# to be copied. It will be copied to [migrate_ssh_temp_key]. +# 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, +# use bool property [MigrationWithoutRootKey], to tell whether to use the key +# as [migrate_ssh_temp_key]. +# 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be +# deleted. +# Note: migrate_ssh_temp_key must be set in a directory completely owned by +# root from bottom to top, such as /root/A, or /tmp/A. +# +# Possible values: {any path plus filename on host} +# Default value: NULL, that is not set. +# +# migrate_ssh_temp_key = "/root/vm_migrate_tmp_id_rsa"; diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index 820b42d..00eb4b1 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -227,6 +227,15 @@ static int is_read_only(void) return prop.value_bool; } +const char *get_mig_ssh_tmp_key(void) +{ + static LibvirtcimConfigProperty prop = { + "migrate_ssh_temp_key", CONFIG_STRING, {0}, 0}; + + libvirt_cim_config_get(&prop); + return prop.value_string; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h index 90fb2da..0f52290 100644 --- a/libxkutil/misc_util.h +++ b/libxkutil/misc_util.h @@ -152,6 +152,9 @@ int virt_set_status(const CMPIBroker *broker, #define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL)) +/* get libvirt-cim config */ +const char *get_mig_ssh_tmp_key(void); + /* * Local Variables: * mode: C diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c index 1f6659d..d03e1a0 100644 --- a/src/Virt_VSMigrationService.c +++ b/src/Virt_VSMigrationService.c @@ -150,6 +150,7 @@ static CMPIStatus get_migration_uri(CMPIInstance *msd, static char *dest_uri(const char *cn, const char *dest, + const char *dest_params, uint16_t transport) { const char *prefix; @@ -157,6 +158,7 @@ static char *dest_uri(const char *cn, const char *param = ""; char *uri = NULL; int rc; + int param_labeled = 0; if (STARTS_WITH(cn, "Xen")) prefix = "xen"; @@ -197,16 +199,54 @@ static char *dest_uri(const char *cn, goto out; } - if (!STREQC(param, "")) + if (!STREQC(param, "")) { rc = asprintf(&uri, "%s/%s", uri, param); + param_labeled = 1; + } - if (rc == -1) + if (rc == -1) { uri = NULL; + goto out; + } + if (dest_params) { + if (param_labeled == 0) { + rc = asprintf(&uri, "%s?%s", uri, dest_params); + } else { + /* ? is already added */ + rc = asprintf(&uri, "%s%s", uri, dest_params); + } + if (rc == -1) { + uri = NULL; + goto out; + } + } out: return uri; } +/* Todo: move it to libcmpiutil */ +static CMPIrc cu_get_bool_arg_my(const CMPIArgs *args, + const char *name, + bool *target) +{ + CMPIData argdata; + CMPIStatus s; + + argdata = CMGetArg(args, name, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) { + return CMPI_RC_ERR_INVALID_PARAMETER; + } + + if (argdata.type != CMPI_boolean) { + return CMPI_RC_ERR_TYPE_MISMATCH; + } + + *target = (bool)argdata.value.boolean; + + return CMPI_RC_OK; +} + static CMPIStatus get_msd_values(const CMPIObjectPath *ref, const char *destination, const CMPIArgs *argsin, @@ -217,6 +257,13 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, CMPIInstance *msd; uint16_t uri_type; char *uri = NULL; + bool no_root_ssh_key = false; + char *dest_params = NULL; + int ret; + + cu_get_bool_arg_my(argsin, + "MigrationWithoutRootKey", + &no_root_ssh_key); s = get_msd(ref, argsin, &msd); if (s.rc != CMPI_RC_OK) @@ -230,7 +277,27 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, if (s.rc != CMPI_RC_OK) goto out; - uri = dest_uri(CLASSNAME(ref), destination, uri_type); + if (no_root_ssh_key) { + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + CU_DEBUG("Trying migrate with specified ssh key file [%s].", + tmp_keyfile); + ret = asprintf(&dest_params, "keyfile=%s", tmp_keyfile); + if (ret < 0) { + CU_DEBUG("Failed in generating param string."); + goto out; + } + } + + uri = dest_uri(CLASSNAME(ref), destination, dest_params, uri_type); if (uri == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -238,6 +305,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, goto out; } + CU_DEBUG("Migrate tring to connect remote host with uri %s.", uri); *conn = virConnectOpen(uri); if (*conn == NULL) { CU_DEBUG("Failed to connect to remote host (%s)", uri); @@ -249,7 +317,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, out: free(uri); - + free(dest_params); return s; } @@ -1538,7 +1606,7 @@ static CMPIStatus migrate_vs_host(CMPIMethodMI *self, const char *dhost = NULL; CMPIObjectPath *system; const char *name = NULL; - + cu_get_str_arg(argsin, "DestinationHost", &dhost); cu_get_ref_arg(argsin, "ComputerSystem", &system); @@ -1604,11 +1672,178 @@ static CMPIStatus migrate_vs_system(CMPIMethodMI *self, return migrate_do(ref, ctx, name, dname, argsin, results, argsout); } +/* return 0 on success */ +static int pipe_exec(const char *cmd) +{ + FILE *stream = NULL; + int ret = 0; + char buf[256]; + + CU_DEBUG("executing system cmd [%s].", cmd); + /* Todo: We need a better popen, currently stdout have been closed + and SIGCHILD is handled by tog-pegasus, so fgets always got NULL + making error detection not possible. */ + stream = popen(cmd, "r"); + if (stream == NULL) { + CU_DEBUG("Failed to open pipe to run the command."); + ret = -1; + goto out; + } + usleep(10000); + + buf[255] = 0; + while (fgets(buf, sizeof(buf), stream) != NULL) { + CU_DEBUG("Exception got: [%s].", buf); + ret = -2; + goto out; + } + + out: + if (stream != NULL) { + pclose(stream); + } + return ret; +} + +/* + * libvirt require private key specified to be placed in a directory owned by + * root, because libvirt-cim now runs as root. So here the key would be copied. + * In this way libvirt-cim could borrow a non-root ssh private key, instead of + * using root's private key, avoid security risk. + */ +static int ssh_key_copy(const char *src, const char *dest) +{ + char *cmd = NULL; + int ret = 0; + struct stat sb; + + /* try delete it */ + unlink(dest); + ret = stat(dest, &sb); + if (ret == 0) { + CU_DEBUG("Can not delete [%s] before copy, " + "maybe someone is using it.", + dest); + /* not a fatal fault */ + } + + ret = asprintf(&cmd, "cp -f %s %s", src, dest); + if (ret < 0) { + CU_DEBUG("Failed in combination for shell command."); + goto out; + } + + ret = pipe_exec(cmd); + if (ret < 0) { + CU_DEBUG("Error in executing command [%s]"); + goto out; + } + + ret = stat(dest, &sb); + if (ret < 0) { + CU_DEBUG("Can not find file [%s] after copy.", dest); + } + out: + free(cmd); + return ret; +} + +static CMPIStatus migrate_sshkey_copy(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *ssh_key_src = NULL; + int ret; + + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + + cu_get_str_arg(argsin, "SSH_Key_Src", &ssh_key_src); + if (!ssh_key_src) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Failed to get property 'SSH_Key_Src'."); + CU_DEBUG("Failed to get property 'SSH_Key_Src'."); + goto out; + } + + ret = ssh_key_copy(ssh_key_src, tmp_keyfile); + if (ret < 0) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Got error in copying ssh key from [%s] to [%s].", + ssh_key_src, tmp_keyfile); + CU_DEBUG("Got error in copying ssh key from [%s] to [%s].", + ssh_key_src, tmp_keyfile); + } + + out: + METHOD_RETURN(results, s.rc); + return s; +} + +static CMPIStatus migrate_sshkey_delete(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + int ret; + struct stat sb; + + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + + ret = stat(tmp_keyfile, &sb); + if (ret == 0) { + /* need delete */ + ret = unlink(tmp_keyfile); + if (ret < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to delete [%s].", + tmp_keyfile); + CU_DEBUG("Failed to delete [%s].", tmp_keyfile); + } + } else { + /* not exist */ + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Can not find file [%s] before delete.", + tmp_keyfile); + CU_DEBUG("Can not find file [%s] before delete.", tmp_keyfile); + } + + out: + METHOD_RETURN(results, s.rc); + return s; +}; + static struct method_handler vsimth = { .name = "CheckVirtualSystemIsMigratableToHost", .handler = vs_migratable_host, .args = {{"ComputerSystem", CMPI_ref, false}, {"DestinationHost", CMPI_string, false}, + {"MigrationWithoutRootKey", CMPI_boolean, true}, {"MigrationSettingData", CMPI_instance, true}, {"NewSystemSettingData", CMPI_instance, true}, {"NewResourceSettingData", CMPI_instanceA, true}, @@ -1633,6 +1868,7 @@ static struct method_handler mvsth = { .handler = migrate_vs_host, .args = {{"ComputerSystem", CMPI_ref, false}, {"DestinationHost", CMPI_string, false}, + {"MigrationWithoutRootKey", CMPI_boolean, true}, {"MigrationSettingData", CMPI_instance, true}, {"NewSystemSettingData", CMPI_instance, true}, {"NewResourceSettingData", CMPI_instanceA, true}, @@ -1652,11 +1888,28 @@ static struct method_handler mvsts = { } }; +static struct method_handler msshkc = { + .name = "MigrateSSHKeyCopy", + .handler = migrate_sshkey_copy, + .args = {{"SSH_Key_Src", CMPI_string, true}, + ARG_END + } +}; + +static struct method_handler msshkd = { + .name = "MigrateSSHKeyDelete", + .handler = migrate_sshkey_delete, + .args = {ARG_END + } +}; + static struct method_handler *my_handlers[] = { &vsimth, &vsimts, &mvsth, &mvsts, + &msshkc, + &msshkd, NULL }; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:39:17 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:39:17 +0800 Subject: [Libvirt-cim] [PATCH V5 14/15] misc_util: better way to read config In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1363837158-11509-15-git-send-email-xiawenc@linux.vnet.ibm.com> This patch adds an common internal function to get property from libvirt-cim config, so it is easy to add properties later. Signed-off-by: Wenchao Xia --- libxkutil/misc_util.c | 114 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 100 insertions(+), 14 deletions(-) diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index f1b93e4..820b42d 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -106,14 +106,40 @@ static const char *cn_to_uri(const char *classname) return NULL; } -static int is_read_only(void) -{ - int readonly = 0; +/* config support */ +typedef enum LibvirtcimConfigType { + CONFIG_BOOL, + CONFIG_STRING, +} LibvirtcimConfigType; + +typedef struct LibvirtcimConfigProperty { + const char *name; + LibvirtcimConfigType value_type; + union { + int value_bool; + char *value_string; + }; + int have_read; +} LibvirtcimConfigProperty; #ifdef HAVE_LIBCONFIG +/* + * @prop must be initialized with zeros, except default value, return 0 means + * OK. prop->value_string will be automatically freed if not NULL, caller must + * never set it to const char*. + */ +static int libvirt_cim_config_get(LibvirtcimConfigProperty *prop) +{ + int error = 0; config_t conf; - int ret; - const char *readonly_str = "readonly"; + int ret = 0; + const char *value_string = NULL; + + /* try only once */ + if (prop->have_read == 1) { + return 0; + } + prop->have_read = 1; config_init(&conf); @@ -121,24 +147,84 @@ static int is_read_only(void) if (ret == CONFIG_FALSE) { CU_DEBUG("Error reading config file at line %d: '%s'\n", conf.error_line, conf.error_text); + error = -1; goto out; } - ret = config_lookup_bool(&conf, readonly_str, &readonly); - if (ret == CONFIG_FALSE) { - CU_DEBUG("'%s' not found in config file, assuming false\n", - readonly_str); - goto out; + switch (prop->value_type) { + case CONFIG_BOOL: + ret = config_lookup_bool(&conf, + prop->name, &prop->value_bool); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Bool property '%s' in config file '%s' " + "not found.", + prop->name, LIBVIRTCIM_CONF); + error = -1; + goto out; + } + + CU_DEBUG("Bool property '%s' in config file '%s' is '%d'.", + prop->name, LIBVIRTCIM_CONF, prop->value_bool); + break; + case CONFIG_STRING: + ret = config_lookup_string(&conf, + prop->name, &value_string); + if (ret == CONFIG_FALSE) { + CU_DEBUG("String property '%s' in config file '%s' " + "not found.", + prop->name, LIBVIRTCIM_CONF); + error = -1; + goto out; + } + + CU_DEBUG("String property '%s' in config file '%s' is '%s'.", + prop->name, LIBVIRTCIM_CONF, value_string); + + if (prop->value_string) { + CU_DEBUG("String property '%s' have value '%s', will " + "be overwritten.", + prop->name, prop->value_string); + free(prop->value_string); + } + prop->value_string = strdup(value_string); + if (!prop->value_string) { + CU_DEBUG("Failed in duplicate value '%s'", + value_string); + error = -1; + goto out; + } + break; + default: + CU_DEBUG("Got invalid property type request %d.", + prop->value_type); + error = -1; + break; } - CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, - LIBVIRTCIM_CONF, readonly); out: config_destroy(&conf); + return error; +} +#else +static int libvirt_cim_config_get(LibvirtcimConfigProperty *prop) +{ + /* try only once */ + if (prop->have_read == 1) { + return 0; + } + prop->have_read = 1; + + CU_DEBUG("Built without libconfig, can't read '%s'.", prop->name); + return -2; +} #endif - /* Default value is 0 (false) */ - return readonly; +static int is_read_only(void) +{ + static LibvirtcimConfigProperty prop = { + "readonly", CONFIG_BOOL, {0}, 0}; + libvirt_cim_config_get(&prop); + return prop.value_bool; } virConnectPtr connect_by_classname(const CMPIBroker *broker, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Thu Mar 21 03:46:55 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Thu, 21 Mar 2013 11:46:55 +0800 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514A82AF.5040404@linux.vnet.ibm.com> Hi, John These were recoded patches, removing script for bridge patch is removed, please add yours after it. After reconsideration, I think we should stick to libvirt 0.9.0 for libvirt-cim0.6.2, which makes 0.6.2 as steady version and allow user to update to it without any trouble. After it we can raise the libvirt version requirement in config file. Also please add signed-off in your patches. Many thanks. > This serial fix a serial of issues. > > V5: > General change: > Remove script change patch, need John Ferlan's patch in following. > 1/15-3/15: new patch make libvirt-cim conform to DSP more. > 6/15: better commit message. > 8/15: remove a strdup() to reduce a error path. > 10/15: free *xml after a fail. > 11/15: return fail when ind == NULL in trigger_mod_indiction(), > check return value for calloc() in doms_to_xml(), better debug message, > check strdup() return on raise_indication, better traverse in dom list. > Reduce condition macros. > 12/15: new patch to move CSI-libvirt/CSI-libvirt-cim together. > 13/15: remove defensive code, only fix the problem of report fail when > some VSSD succeed. > 14/15: new separate patch from 15/15, to enhance config reading. > 15/15: changed the interface, new method to copy/delete the key, > rm the key before copy and check the key's status after copy. > > Wenchao Xia (15): > 1 Remove property CreationClassName in some instance > 2 VSSD: add missing property IsFullVirt in schema > 3 SDC: use property BootDevices instead of BootDevice > 4 do not deregister virt classes in yum upgrade > 5 CSI, fix debug print crash > 6 CSI, add lock to protect shared data in lifecycle_thread > 7 DevicePool, fix debug print crash > 8 DevicePool, reimplement get_diskpool_config with libvirt > 9 RASDIndication, fix debug print crash > 10 device parsing, add debug print > 11 CSI Discard libvirt event by default > 12 CSI: Move native CSI code together > 13 VSSD: report success if not all VS fail in enum > 14 misc_util: better way to read config > 15 migration: allow ssh based migration with non root's key file > > libvirt-cim.conf | 19 + > libvirt-cim.spec.in | 12 +- > libxkutil/device_parsing.c | 16 +- > libxkutil/misc_util.c | 135 +++- > libxkutil/misc_util.h | 6 +- > schema/Virt_VSSD.mof | 3 + > src/Virt_AllocationCapabilities.c | 3 +- > src/Virt_ComputerSystem.c | 66 ++- > src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- > src/Virt_ConsoleRedirectionService.c | 3 +- > src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- > src/Virt_Device.c | 18 +- > src/Virt_DevicePool.c | 198 +++-- > src/Virt_EnabledLogicalElementCapabilities.c | 3 +- > src/Virt_FilterEntry.c | 3 +- > src/Virt_FilterList.c | 3 +- > src/Virt_HostSystem.c | 3 +- > src/Virt_KVMRedirectionSAP.c | 3 +- > src/Virt_RASD.c | 3 +- > src/Virt_ReferencedProfile.c | 3 +- > src/Virt_RegisteredProfile.c | 3 +- > src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- > src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- > src/Virt_ResourcePoolConfigurationService.c | 8 +- > src/Virt_SettingsDefineCapabilities.c | 10 +- > src/Virt_SwitchService.c | 3 +- > src/Virt_VSMigrationCapabilities.c | 3 +- > src/Virt_VSMigrationService.c | 269 +++++- > src/Virt_VSMigrationSettingData.c | 3 +- > src/Virt_VSSD.c | 46 +- > src/Virt_VirtualSystemManagementCapabilities.c | 3 +- > src/Virt_VirtualSystemManagementService.c | 63 ++- > src/Virt_VirtualSystemSnapshotService.c | 3 +- > ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- > 34 files changed, 1652 insertions(+), 295 deletions(-) > > -- Best Regards Wenchao Xia From jferlan at redhat.com Thu Mar 21 16:51:24 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 12:51:24 -0400 Subject: [Libvirt-cim] [PATCH V5 02/15] VSSD: add missing property IsFullVirt in schema In-Reply-To: <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3A8C.2010307@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This property is used but not defined, so add it. > > Signed-off-by: Wenchao Xia > --- > schema/Virt_VSSD.mof | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/schema/Virt_VSSD.mof b/schema/Virt_VSSD.mof > index baf4ac2..b960450 100644 > --- a/schema/Virt_VSSD.mof > +++ b/schema/Virt_VSSD.mof > @@ -27,4 +27,7 @@ class Virt_VirtualSystemSettingData : CIM_VirtualSystemSettingData > [Description ("Flag to determine whether this guest has to be autostarted on reboot")] > uint16 AutoStart; > > + [Description ("Flag to determine whether this guest is a full virtualization")] > + boolean IsFullVirt; > + > }; > This property is found in 'VSSD.mof': class Xen_VirtualSystemSettingData : Virt_VirtualSystemSettingData { [Description ("Flag to determine whether this guest is fully-virtualized")] boolean IsFullVirt; ... Since that is a child of the one you are placing the the property into, shouldn't it be removed from the child? Also I think the Description in VSSD.mof is better than the one in Virt_VSSD.mof. John From jferlan at redhat.com Thu Mar 21 16:56:29 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 12:56:29 -0400 Subject: [Libvirt-cim] [PATCH V5 02/15] VSSD: add missing property IsFullVirt in schema In-Reply-To: <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3BBD.3030102@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This property is used but not defined, so add it. > > Signed-off-by: Wenchao Xia > --- > schema/Virt_VSSD.mof | 3 +++ > 1 files changed, 3 insertions(+), 0 deletions(-) > > diff --git a/schema/Virt_VSSD.mof b/schema/Virt_VSSD.mof > index baf4ac2..b960450 100644 > --- a/schema/Virt_VSSD.mof > +++ b/schema/Virt_VSSD.mof > @@ -27,4 +27,7 @@ class Virt_VirtualSystemSettingData : CIM_VirtualSystemSettingData > [Description ("Flag to determine whether this guest has to be autostarted on reboot")] > uint16 AutoStart; > > + [Description ("Flag to determine whether this guest is a full virtualization")] > + boolean IsFullVirt; > + > }; > Follow up note... Is this "isFullVirt" or "IsFullVirt" - I see it used both ways, so I'm confused. John From jferlan at redhat.com Thu Mar 21 17:00:33 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 13:00:33 -0400 Subject: [Libvirt-cim] [PATCH V5 03/15] SDC: use property BootDevices instead of BootDevice In-Reply-To: <1363837158-11509-4-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-4-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3CB1.9060209@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > The property registerted is BootDevices, so correct it. > > Signed-off-by: Wenchao Xia > --- > src/Virt_SettingsDefineCapabilities.c | 4 ++-- > 1 files changed, 2 insertions(+), 2 deletions(-) > > diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c > index 5091205..1e7a778 100644 > --- a/src/Virt_SettingsDefineCapabilities.c > +++ b/src/Virt_SettingsDefineCapabilities.c > @@ -172,7 +172,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, > if (inst == NULL) > goto error; > > - CMSetProperty(inst, "BootDevice", > + CMSetProperty(inst, "BootDevices", > (CMPIValue *)"hda", CMPI_chars); > > CMSetProperty(inst, "isFullVirt", > @@ -211,7 +211,7 @@ static CMPIStatus _kvm_vsmc_to_vssd(virConnectPtr conn, > CMSetProperty(inst, "VirtualSystemIdentifier", > (CMPIValue *)"KVM_guest", CMPI_chars); > > - CMSetProperty(inst, "BootDevice", > + CMSetProperty(inst, "BootDevices", > (CMPIValue *)"hda", CMPI_chars); > > inst_list_add(list, inst); > ACK Note: In this module, the "isFullVirt" is used - hence my follow-up question to patch 2/15. I also found two instances where "BootDevice" is used in CU_DEBUG messages (not that it matters, but it's a consistency thing for me). John From jferlan at redhat.com Thu Mar 21 17:01:50 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 13:01:50 -0400 Subject: [Libvirt-cim] [PATCH V5 04/15] do not deregister virt classes in yum upgrade In-Reply-To: <1363837158-11509-5-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-5-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3CFE.9020900@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Now yum upgrade will deregister the virt classes, make > libvirt-cim not workable. This patch fixed it from now on. > > Signed-off-by: Wenchao Xia > --- > libvirt-cim.spec.in | 12 ++++++++---- > 1 files changed, 8 insertions(+), 4 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 17:03:12 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 13:03:12 -0400 Subject: [Libvirt-cim] [PATCH V5 05/15] CSI, fix debug print crash In-Reply-To: <1363837158-11509-6-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-6-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3D50.1070400@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Signed-off-by: Wenchao Xia > Reviewed-by: John Ferlan > Reviewed-by: Sharad Mishra > --- > src/Virt_ComputerSystemIndication.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 17:16:25 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 13:16:25 -0400 Subject: [Libvirt-cim] [PATCH V5 06/15] CSI, add lock to protect shared data in lifecycle_thread In-Reply-To: <1363837158-11509-7-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-7-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B4069.3040209@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This patch use lock 'lifecycle_mutex' to protect gloable shared > data in lifecycle_thread(). This lock exist in Activate/Deactivate > Enable/Disable method, which is meant to protect the gloable s/gloable/global > shared data, but forgot to be added in new libvirt based CSI > thread. > This patch can avoid following risk at least: Original code have > a small chance to free thread->args in child thread just after main > thread malloc it, for that thread->id is set to zero allowing main > thread to enter that code. > This patch focus on adding missing lock, the CSI can be still > improved as: smaller lock, folder lock into a structure with data > to tip better what it is doing. > > Signed-off-by: Wenchao Xia > --- > src/Virt_ComputerSystemIndication.c | 39 ++++++++++++++++++++++++++++++++-- > 1 files changed, 36 insertions(+), 3 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 17:18:52 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 13:18:52 -0400 Subject: [Libvirt-cim] [PATCH V5 07/15] DevicePool, fix debug print crash In-Reply-To: <1363837158-11509-8-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-8-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B40FC.8040906@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Signed-off-by: Wenchao Xia > Reviewed-by: John Ferlan > --- > src/Virt_DevicePool.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > ACK Although "theoretically speaking" this could/should be combined with 5/15 and 9/15 since they are similar (eg, via git rebase -i and squash 3 into 1 patch). John From jferlan at redhat.com Thu Mar 21 16:36:37 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 12:36:37 -0400 Subject: [Libvirt-cim] [PATCH V5 01/15] Remove property CreationClassName in some instance In-Reply-To: <1363837158-11509-2-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-2-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B3715.2010803@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > There are some instances which did not register this property, so this > patch added a parameter in get_typed_instance(). The caller must set it > clearly whether to set the property. > When tog-pegasus > 2.12 and its log >= WARNING, tog-pegasus will > report this problem in log. > > Signed-off-by: Wenchao Xia > --- > libxkutil/misc_util.c | 12 ++++++++---- > libxkutil/misc_util.h | 3 ++- > src/Virt_AllocationCapabilities.c | 3 ++- > src/Virt_ComputerSystem.c | 6 ++++-- > src/Virt_ComputerSystemIndication.c | 3 ++- > src/Virt_ConsoleRedirectionService.c | 3 ++- > src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 ++- > src/Virt_Device.c | 18 ++++++++++++------ > src/Virt_DevicePool.c | 20 +++++++++++++------- > src/Virt_EnabledLogicalElementCapabilities.c | 3 ++- > src/Virt_FilterEntry.c | 3 ++- > src/Virt_FilterList.c | 3 ++- > src/Virt_HostSystem.c | 3 ++- > src/Virt_KVMRedirectionSAP.c | 3 ++- > src/Virt_RASD.c | 3 ++- > src/Virt_ReferencedProfile.c | 3 ++- > src/Virt_RegisteredProfile.c | 3 ++- > src/Virt_ResourcePoolConfigurationCapabilities.c | 3 ++- > src/Virt_ResourcePoolConfigurationService.c | 8 ++++++-- > src/Virt_SettingsDefineCapabilities.c | 6 ++++-- > src/Virt_SwitchService.c | 3 ++- > src/Virt_VSMigrationCapabilities.c | 3 ++- > src/Virt_VSMigrationService.c | 6 ++++-- > src/Virt_VSMigrationSettingData.c | 3 ++- > src/Virt_VSSD.c | 3 ++- > src/Virt_VirtualSystemManagementCapabilities.c | 3 ++- > src/Virt_VirtualSystemManagementService.c | 6 ++++-- > src/Virt_VirtualSystemSnapshotService.c | 3 ++- > ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 ++- > 29 files changed, 97 insertions(+), 48 deletions(-) > > diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c > index 2d149ae..f1b93e4 100644 > --- a/libxkutil/misc_util.c > +++ b/libxkutil/misc_util.c > @@ -341,7 +341,8 @@ char *get_typed_class(const char *refcn, const char *new_base) > CMPIInstance *get_typed_instance(const CMPIBroker *broker, > const char *refcn, > const char *base, > - const char *namespace) > + const char *namespace, > + bool ccn_flag) While it may seem obvious to you why one would want to provide 'true' or 'false' here, could the function header elaborate a bit so that in the future when someone "adds" a call to this function they will know whether they should pass true or false. IOW which type of instances need this and which do not. If the answer is "as according to the DSP" - I think that's fine. I don't know where to find the DSP (yet) or at least where/how to make the determination that the caller would (or not) need the property. >From my scan of these - it sems *Capabilities, *Indications, *Filter, *Profiles, & *RASDs type classes don't need the property, while specific element classes (ComputerSystem, HostSystem, LogicalDisk, NetworkPort, etc) and *Service classes need the property. Is that a "fair" summary? ACK with description the remainder looks fine. John > { > char *new_cn; > CMPIObjectPath *op; > @@ -360,8 +361,10 @@ CMPIInstance *get_typed_instance(const CMPIBroker *broker, > if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) > goto out; > > - CMSetProperty(inst, "CreationClassName", > - (CMPIValue *)new_cn, CMPI_chars); > + if (ccn_flag) { > + CMSetProperty(inst, "CreationClassName", > + (CMPIValue *)new_cn, CMPI_chars); > + } > > out: > free(new_cn); > @@ -467,7 +470,8 @@ CMPIInstance *make_reference(const CMPIBroker *broker, > ref_inst = get_typed_instance(broker, > CLASSNAME(source_ref), > assoc_classname, > - NAMESPACE(source_ref)); > + NAMESPACE(source_ref), > + false); > > if (ref_inst != NULL) { > CMPIObjectPath *target_ref; > diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h > index c7a2122..90fb2da 100644 > --- a/libxkutil/misc_util.h > +++ b/libxkutil/misc_util.h > @@ -85,7 +85,8 @@ char *get_typed_class(const char *refcn, const char *new_base); > CMPIInstance *get_typed_instance(const CMPIBroker *broker, > const char *refcn, > const char *base, > - const char *namespace); > + const char *namespace, > + bool ccn_flag); > > /* Parse an OrgID:LocID string into its constituent parts */ > int parse_instance_id(char *iid, char **orgid, char **locid); > diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c > index 970abeb..b358fac 100644 > --- a/src/Virt_AllocationCapabilities.c > +++ b/src/Virt_AllocationCapabilities.c > @@ -46,7 +46,8 @@ static CMPIStatus ac_from_pool(const CMPIBroker *broker, > *alloc_cap = get_typed_instance(broker, > CLASSNAME(ref), > "AllocationCapabilities", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (*alloc_cap == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c > index e6c7e55..4a9b26d 100644 > --- a/src/Virt_ComputerSystem.c > +++ b/src/Virt_ComputerSystem.c > @@ -440,7 +440,8 @@ CMPIStatus instance_from_dominfo(const CMPIBroker *broker, > inst = get_typed_instance(broker, > prefix, > "ComputerSystem", > - namespace); > + namespace, > + true); > > if (inst == NULL) { > CU_DEBUG("Could not init CS instance. " > @@ -560,7 +561,8 @@ static CMPIStatus instance_from_dom(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "ComputerSystem", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c > index 2d0a94e..3096683 100644 > --- a/src/Virt_ComputerSystemIndication.c > +++ b/src/Virt_ComputerSystemIndication.c > @@ -239,7 +239,8 @@ static bool _do_indication(const CMPIBroker *broker, > ind = get_typed_instance(broker, > prefix, > ind_type_name, > - args->ns); > + args->ns, > + false); > > /* Generally report errors and hope to continue, since we have no one > to actually return status to. */ > diff --git a/src/Virt_ConsoleRedirectionService.c b/src/Virt_ConsoleRedirectionService.c > index 7b20c0d..16cade8 100644 > --- a/src/Virt_ConsoleRedirectionService.c > +++ b/src/Virt_ConsoleRedirectionService.c > @@ -129,7 +129,8 @@ CMPIStatus get_console_rs(const CMPIObjectPath *reference, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "ConsoleRedirectionService", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get typed instance"); > diff --git a/src/Virt_ConsoleRedirectionServiceCapabilities.c b/src/Virt_ConsoleRedirectionServiceCapabilities.c > index 11f2986..88fb3a4 100644 > --- a/src/Virt_ConsoleRedirectionServiceCapabilities.c > +++ b/src/Virt_ConsoleRedirectionServiceCapabilities.c > @@ -91,7 +91,8 @@ CMPIStatus get_console_rs_caps(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "ConsoleRedirectionServiceCapabilities", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_Device.c b/src/Virt_Device.c > index e047a94..c7dcbc3 100644 > --- a/src/Virt_Device.c > +++ b/src/Virt_Device.c > @@ -100,7 +100,8 @@ static CMPIInstance *net_instance(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "NetworkPort", > - ns); > + ns, > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get instance for NetworkPort"); > @@ -138,7 +139,8 @@ static CMPIInstance *disk_instance(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "LogicalDisk", > - ns); > + ns, > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get instance for LogicalDisk"); > @@ -185,7 +187,8 @@ static CMPIInstance *mem_instance(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "Memory", > - ns); > + ns, > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get instance for Memory"); > @@ -234,7 +237,8 @@ static CMPIInstance *graphics_instance(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "DisplayController", > - ns); > + ns, > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get instance for DisplayController"); > @@ -320,7 +324,8 @@ static CMPIInstance *input_instance(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "PointingDevice", > - ns); > + ns, > + true); > if (inst == NULL) { > CU_DEBUG("Failed to get instance of %s_PointingDevice", > pfx_from_conn(conn)); > @@ -407,7 +412,8 @@ static bool vcpu_inst(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "Processor", > - ns); > + ns, > + true); > if (inst == NULL) > return false; > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index 202e509..56c9715 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -803,7 +803,8 @@ static CMPIStatus mempool_instance(virConnectPtr conn, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "MemoryPool", > - ns); > + ns, > + false); > > if (inst == NULL) { > cu_statusf(broker, &s, > @@ -842,7 +843,8 @@ static CMPIStatus procpool_instance(virConnectPtr conn, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "ProcessorPool", > - ns); > + ns, > + false); > > if (inst == NULL) { > cu_statusf(broker, &s, > @@ -872,7 +874,8 @@ static CMPIStatus _netpool_for_parent(struct inst_list *list, > inst = get_typed_instance(broker, > refcn, > "NetworkPool", > - ns); > + ns, > + false); > if (inst == NULL) { > CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", > ns, refcn); > @@ -928,7 +931,8 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, > inst = get_typed_instance(broker, > refcn, > "NetworkPool", > - ns); > + ns, > + false); > if (inst == NULL) { > CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", > ns, refcn); > @@ -1046,7 +1050,7 @@ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, > CMPIInstance *inst; > char *poolid = NULL; > > - inst = get_typed_instance(broker, refcn, "DiskPool", ns); > + inst = get_typed_instance(broker, refcn, "DiskPool", ns, false); > > if (inst == NULL) { > cu_statusf(broker, &s, > @@ -1136,7 +1140,8 @@ static CMPIStatus graphicspool_instance(virConnectPtr conn, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "GraphicsPool", > - ns); > + ns, > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > @@ -1172,7 +1177,8 @@ static CMPIStatus inputpool_instance(virConnectPtr conn, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "InputPool", > - ns); > + ns, > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_EnabledLogicalElementCapabilities.c b/src/Virt_EnabledLogicalElementCapabilities.c > index 7ba5eae..2fcdef1 100644 > --- a/src/Virt_EnabledLogicalElementCapabilities.c > +++ b/src/Virt_EnabledLogicalElementCapabilities.c > @@ -61,7 +61,8 @@ static CMPIInstance *_get_elec(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "EnabledLogicalElementCapabilities", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + false); > if (inst == NULL) { > cu_statusf(broker, s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c > index 126615b..3c4a3e6 100644 > --- a/src/Virt_FilterEntry.c > +++ b/src/Virt_FilterEntry.c > @@ -546,7 +546,8 @@ static CMPIInstance *convert_rule_to_instance( > inst = get_typed_instance(broker, > CLASSNAME(reference), > basename, > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > cu_statusf(broker, s, > diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c > index 9b5dbae..79776cd 100644 > --- a/src/Virt_FilterList.c > +++ b/src/Virt_FilterList.c > @@ -50,7 +50,8 @@ static CMPIInstance *convert_filter_to_instance( > inst = get_typed_instance(broker, > CLASSNAME(reference), > "FilterList", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > if (inst == NULL) { > cu_statusf(broker, s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_HostSystem.c b/src/Virt_HostSystem.c > index 724a5ea..c31d6cf 100644 > --- a/src/Virt_HostSystem.c > +++ b/src/Virt_HostSystem.c > @@ -135,7 +135,8 @@ static CMPIStatus fake_host(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "HostSystem", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > cu_statusf(broker, &s, > diff --git a/src/Virt_KVMRedirectionSAP.c b/src/Virt_KVMRedirectionSAP.c > index db34d57..38ad468 100644 > --- a/src/Virt_KVMRedirectionSAP.c > +++ b/src/Virt_KVMRedirectionSAP.c > @@ -125,7 +125,8 @@ static CMPIInstance *get_console_sap(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "KVMRedirectionSAP", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > cu_statusf(broker, s, > diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c > index 9493077..6e8a244 100644 > --- a/src/Virt_RASD.c > +++ b/src/Virt_RASD.c > @@ -716,7 +716,8 @@ CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, > inst = get_typed_instance(broker, > CLASSNAME(ref), > base, > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) > return inst; > > diff --git a/src/Virt_ReferencedProfile.c b/src/Virt_ReferencedProfile.c > index 150be1f..e78a8d3 100644 > --- a/src/Virt_ReferencedProfile.c > +++ b/src/Virt_ReferencedProfile.c > @@ -242,7 +242,8 @@ static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, > ref_inst = get_typed_instance(_BROKER, > CLASSNAME(source_ref), > assoc_classname, > - NAMESPACE(source_ref)); > + NAMESPACE(source_ref), > + false); > > source = get_reg_prof_by_ref(source_ref); > if (source->scoping_profile != NULL) > diff --git a/src/Virt_RegisteredProfile.c b/src/Virt_RegisteredProfile.c > index 389a179..e644708 100644 > --- a/src/Virt_RegisteredProfile.c > +++ b/src/Virt_RegisteredProfile.c > @@ -54,7 +54,8 @@ CMPIStatus get_profile(const CMPIBroker *broker, > instance = get_typed_instance(broker, > pfx, > "RegisteredProfile", > - CIM_INTEROP_NS); > + CIM_INTEROP_NS, > + false); > > if (instance == NULL) { > cu_statusf(broker, &s, > diff --git a/src/Virt_ResourcePoolConfigurationCapabilities.c b/src/Virt_ResourcePoolConfigurationCapabilities.c > index 32274ed..2dcbbcf 100644 > --- a/src/Virt_ResourcePoolConfigurationCapabilities.c > +++ b/src/Virt_ResourcePoolConfigurationCapabilities.c > @@ -69,7 +69,8 @@ static CMPIStatus get_rpc_cap(const CMPIObjectPath *reference, > inst = get_typed_instance(_BROKER, > pfx_from_conn(conn), > "ResourcePoolConfigurationCapabilities", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + false); > if (inst == NULL) { > cu_statusf(_BROKER, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c > index 751d016..0c0cc06 100644 > --- a/src/Virt_ResourcePoolConfigurationService.c > +++ b/src/Virt_ResourcePoolConfigurationService.c > @@ -781,6 +781,8 @@ static const char *rasd_to_res(CMPIInstance *inst, > return msg; > } > > +/* Warning: returned instance is not freed manually in caller, need confirm > + if server will auto free it. */ > static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, > const CMPIObjectPath *ref, > CMPIStatus *s) > @@ -798,7 +800,8 @@ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, > inst = get_typed_instance(_BROKER, > CLASSNAME(ref), > "StorageVolumeResourceAllocationSettingData", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(_BROKER, s, > CMPI_RC_ERR_FAILED, > @@ -1279,7 +1282,8 @@ CMPIStatus get_rpcs(const CMPIObjectPath *reference, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "ResourcePoolConfigurationService", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c > index 9eb9e57..5091205 100644 > --- a/src/Virt_SettingsDefineCapabilities.c > +++ b/src/Virt_SettingsDefineCapabilities.c > @@ -113,7 +113,8 @@ static CMPIInstance *default_vssd_instance(const char *prefix, > inst = get_typed_instance(_BROKER, > prefix, > "VirtualSystemSettingData", > - ns); > + ns, > + false); > if (inst == NULL) { > CU_DEBUG("Failed to create default VSSD instance"); > goto out; > @@ -303,7 +304,8 @@ static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, > inst = get_typed_instance(_BROKER, > CLASSNAME(ref), > base, > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > > if (inst == NULL) { > cu_statusf(_BROKER, s, > diff --git a/src/Virt_SwitchService.c b/src/Virt_SwitchService.c > index 7e59d38..8991426 100644 > --- a/src/Virt_SwitchService.c > +++ b/src/Virt_SwitchService.c > @@ -229,7 +229,8 @@ static CMPIStatus get_switchservice(const CMPIObjectPath *reference, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "SwitchService", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get typed instance"); > diff --git a/src/Virt_VSMigrationCapabilities.c b/src/Virt_VSMigrationCapabilities.c > index 4f0e434..3e53f68 100644 > --- a/src/Virt_VSMigrationCapabilities.c > +++ b/src/Virt_VSMigrationCapabilities.c > @@ -134,7 +134,8 @@ CMPIStatus get_migration_caps(const CMPIObjectPath *ref, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemMigrationCapabilities", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c > index 76e3d25..1f6659d 100644 > --- a/src/Virt_VSMigrationService.c > +++ b/src/Virt_VSMigrationService.c > @@ -831,7 +831,8 @@ static CMPIInstance *prepare_indication(const CMPIBroker *broker, > ind = get_typed_instance(broker, > pfx, > ind_name, > - job->ref_ns); > + job->ref_ns, > + false); > if (ind == NULL) { > CU_DEBUG("Failed to create ind, type '%s:%s_%s'", > job->ref_ns, pfx, ind_name); > @@ -1686,7 +1687,8 @@ CMPIStatus get_migration_service(const CMPIObjectPath *ref, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemMigrationService", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + true); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_VSMigrationSettingData.c b/src/Virt_VSMigrationSettingData.c > index a6707bd..eb545f1 100644 > --- a/src/Virt_VSMigrationSettingData.c > +++ b/src/Virt_VSMigrationSettingData.c > @@ -79,7 +79,8 @@ CMPIStatus get_migration_sd(const CMPIObjectPath *ref, > inst = get_typed_instance(broker, > CLASSNAME(ref), > "VirtualSystemMigrationSettingData", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c > index 499b157..975623b 100644 > --- a/src/Virt_VSSD.c > +++ b/src/Virt_VSSD.c > @@ -285,7 +285,8 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemSettingData", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + false); > > if (inst == NULL) { > cu_statusf(broker, s, > diff --git a/src/Virt_VirtualSystemManagementCapabilities.c b/src/Virt_VirtualSystemManagementCapabilities.c > index 020ce8a..51738ee 100644 > --- a/src/Virt_VirtualSystemManagementCapabilities.c > +++ b/src/Virt_VirtualSystemManagementCapabilities.c > @@ -129,7 +129,8 @@ CMPIStatus get_vsm_cap(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemManagementCapabilities", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c > index 10adf8b..96c8a03 100644 > --- a/src/Virt_VirtualSystemManagementService.c > +++ b/src/Virt_VirtualSystemManagementService.c > @@ -1928,7 +1928,8 @@ static CMPIStatus raise_rasd_indication(const CMPIContext *context, > ind = get_typed_instance(_BROKER, > CLASSNAME(ref), > base_type, > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (ind == NULL) { > CU_DEBUG("Failed to get indication instance"); > s.rc = CMPI_RC_ERR_FAILED; > @@ -3293,7 +3294,8 @@ CMPIStatus get_vsms(const CMPIObjectPath *reference, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemManagementService", > - NAMESPACE(reference)); > + NAMESPACE(reference), > + true); > > if (inst == NULL) { > CU_DEBUG("Failed to get typed instance"); > diff --git a/src/Virt_VirtualSystemSnapshotService.c b/src/Virt_VirtualSystemSnapshotService.c > index aae628f..8c0889d 100644 > --- a/src/Virt_VirtualSystemSnapshotService.c > +++ b/src/Virt_VirtualSystemSnapshotService.c > @@ -681,7 +681,8 @@ CMPIStatus get_vsss(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemSnapshotService", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + true); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > diff --git a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c > index 69c8e97..04a9c7a 100644 > --- a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c > +++ b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c > @@ -117,7 +117,8 @@ CMPIStatus get_vss_cap(const CMPIBroker *broker, > inst = get_typed_instance(broker, > pfx_from_conn(conn), > "VirtualSystemSnapshotServiceCapabilities", > - NAMESPACE(ref)); > + NAMESPACE(ref), > + false); > if (inst == NULL) { > cu_statusf(broker, &s, > CMPI_RC_ERR_FAILED, > From jferlan at redhat.com Thu Mar 21 18:03:15 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:03:15 -0400 Subject: [Libvirt-cim] [PATCH V5 08/15] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1363837158-11509-9-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-9-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B4B63.8090207@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Original implemetion may return pools with NULL name if > some pool disappear between two libvirt pool API call. And > originally it return the number of pools and negative value > when error happens, but caller of this function consider > number = 0 as error. > As a fix, this patch changed the function prototype, it do > not return the pool number anymore, it returns 0 on success > and negative on fail now. Code for checking the risk of returning > pools with NULL name is also added. > Another small fix is, return false in get_disk_parent() when > strdup fail. > > Signed-off-by: Wenchao Xia > --- > src/Virt_DevicePool.c | 176 +++++++++++++++++++++++++++++++++---------------- > 1 files changed, 120 insertions(+), 56 deletions(-) > > diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c > index 08677e2..185e3cc 100644 > --- a/src/Virt_DevicePool.c > +++ b/src/Virt_DevicePool.c > @@ -51,6 +51,22 @@ struct tmp_disk_pool { > bool primordial; > }; > > +static void free_diskpool(struct tmp_disk_pool *pools, int count) > +{ > + int i; > + > + if (pools == NULL) { > + return; > + } > + > + for (i = 0; i < count; i++) { > + free(pools[i].tag); > + free(pools[i].path); > + } > + > + free(pools); > +} > + > /* > * Right now, detect support and use it, if available. > * Later, this can be a configure option if needed > @@ -78,6 +94,10 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, > } > > pools[count].tag = strdup("0"); > + if (pools[count].tag == NULL) { > + count++; > + goto free; > + } > pools[count].path = NULL; > pools[count].primordial = true; > count++; > @@ -85,12 +105,17 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, > *_count = count; > *_pools = pools; > ret = true; > + goto out; > > + free: > + free_diskpool(pools, count); > + /* old pool is invalid, update it */ > + *_count = 0; > + *_pools = NULL; > out: > return ret; > } > > - > #if VIR_USE_LIBVIRT_STORAGE > int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) > { > @@ -117,52 +142,82 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) > return ret; > } > > +/* This function returns 0 on sucess, negative on fail. */ > static int get_diskpool_config(virConnectPtr conn, > - struct tmp_disk_pool **_pools) > + struct tmp_disk_pool **_pools, > + int *_count) > { > - int count = 0; > + int count = 0, realcount = 0; > int i; > char ** names = NULL; > struct tmp_disk_pool *pools = NULL; > + int ret = 0; > + bool bret; > > count = virConnectNumOfStoragePools(conn); > - if (count <= 0) > + if (count < 0) { > + ret = count; > goto out; > + } else if (count == 0) { > + goto set_parent; > + } > > names = calloc(count, sizeof(char *)); > if (names == NULL) { > CU_DEBUG("Failed to alloc space for %i pool names", count); > - count = 0; > + ret = -1; > goto out; > } > > - if (virConnectListStoragePools(conn, names, count) == -1) { > - CU_DEBUG("Failed to get storage pools"); > - count = 0; > - goto out; > + realcount = virConnectListStoragePools(conn, names, count); > + if (realcount < 0) { > + CU_DEBUG("Failed to get storage pools, return %d.", realcount); > + ret = realcount; > + goto free_names; > + } > + if (realcount == 0) { > + CU_DEBUG("Zero pools got, but prelist is %d.", count); > + goto set_parent; > } > > - pools = calloc(count, sizeof(*pools)); > + pools = calloc(realcount, sizeof(*pools)); > if (pools == NULL) { > - CU_DEBUG("Failed to alloc space for %i pool structs", count); > - goto out; > + CU_DEBUG("Failed to alloc space for %i pool structs", > + realcount); > + ret = -2; > + goto free_names; > } > > - for (i = 0; i < count; i++) { > - pools[i].tag = strdup(names[i]); > + for (i = 0; i < realcount; i++) { > + pools[i].tag = names[i]; > + names[i] = NULL; > pools[i].primordial = false; > } > > - out: > - for (i = 0; i < count; i++) > - free(names[i]); > - free(names); > - > - get_disk_parent(&pools, &count); > + set_parent: > + bret = get_disk_parent(&pools, &realcount); > + if (bret != true) { > + CU_DEBUG("Failed in adding parentpool."); > + ret = -4; > + goto free_pools; If here, we will have already called free_diskpools() which is probably a good thing since at this point pools and realcount will be inaccurate. So just jump to free_names instead (also leave a reason why!!!) > + } > > + /* succeed */ > *_pools = pools; > + *_count = realcount; > + goto free_names; > + > + free_pools: > + free_diskpool(pools, realcount); > > - return count; > + free_names: > + for (i = 0; i < count; i++) { > + free(names[i]); > + } > + free(names); > + > + out: > + return ret; > } > > static bool diskpool_set_capacity(virConnectPtr conn, > @@ -294,42 +349,59 @@ static int parse_diskpool_line(struct tmp_disk_pool *pool, > return (ret == 2); > } > > +/* return 0 on sucess, negative on fail. */ > static int get_diskpool_config(virConnectPtr conn, > - struct tmp_disk_pool **_pools) > + struct tmp_disk_pool **_pools, > + int *_count) > { > const char *path = DISK_POOL_CONFIG; > FILE *config; > char *line = NULL; > size_t len = 0; > - int count = 0; > - struct tmp_disk_pool *pools = NULL; > + int count = 0, ret = 0; > + struct tmp_disk_pool *pools = NULL, *new_pools = NULL; > + bool bret; > > config = fopen(path, "r"); > if (config == NULL) { > CU_DEBUG("Failed to open %s: %m", path); > - return 0; > + ret = -1; > + goto out; > } > > while (getline(&line, &len, config) > 0) { > - pools = realloc(pools, > - (count + 1) * (sizeof(*pools))); > - if (pools == NULL) { > + new_pools = realloc(pools, > + (count + 1) * (sizeof(*pools))); > + if (new_pools == NULL) { > CU_DEBUG("Failed to alloc new pool"); > - goto out; > + ret = -2; > + goto free_pools; > } > + pools = new_pools; Once the realloc is successful, then pools will have count+1 elems. If for some reason the next line files, then I don't think we need to realloc again in this loop. Makes the logic a bit more messy though. > > if (parse_diskpool_line(&pools[count], line)) > count++; Since you have a free(line) below, won't you need a free(line) and line = NULL each time through this loop (the line = NULL is so that the free(line) below doesn't double deallocate). > } > > + bret = get_disk_parent(&pools, &count); > + if (bret != true) { > + CU_DEBUG("Failed in adding parentpool."); > + ret = -3; > + goto free_pools; If here, we will have already called free_diskpools() which is probably a good thing since at this point pools and count will be inaccurate. So just jump to clean instead (also leave a reason why!!!) > + } > > - get_disk_parent(&pools, &count); > - out: > - free(line); > + /* succeed */ > *_pools = pools; > - fclose(config); > + *_count = count; > + goto clean; > > - return count; > + free_pools: > + free_diskpool(pools, count); > + clean: > + free(line); Seeing this free(line) made me realize the issue above... The rest is fine. John > + fclose(config); > + out: > + return ret; > } > > static bool diskpool_set_capacity(virConnectPtr conn, > @@ -367,39 +439,23 @@ static bool diskpool_set_capacity(virConnectPtr conn, > } > > static bool _diskpool_is_member(virConnectPtr conn, > - const struct disk_pool *pool, > + const struct tmp_disk_pool *pool, > const char *file) > { > return STARTS_WITH(file, pool->path); > } > #endif > > -static void free_diskpool(struct tmp_disk_pool *pools, int count) > -{ > - int i; > - > - if (pools == NULL) > - return; > - > - for (i = 0; i < count; i++) { > - free(pools[i].tag); > - free(pools[i].path); > - } > - > - free(pools); > -} > - > static char *_diskpool_member_of(virConnectPtr conn, > const char *file) > { > struct tmp_disk_pool *pools = NULL; > int count; > - int i; > + int i, ret; > char *pool = NULL; > > - count = get_diskpool_config(conn, &pools); > - if (count == 0) { > - free(pools); > + ret = get_diskpool_config(conn, &pools, &count); > + if (ret < 0) { > return NULL; > } > > @@ -1088,9 +1144,17 @@ static CMPIStatus diskpool_instance(virConnectPtr conn, > CMPIStatus s = {CMPI_RC_OK, NULL}; > struct tmp_disk_pool *pools = NULL; > int count = 0; > - int i; > + int i, ret; > > - count = get_diskpool_config(conn, &pools); > + ret = get_diskpool_config(conn, &pools, &count); > + if (ret < 0) { > + CU_DEBUG("Failed to get diskpool config, return is %d.", ret); > + cu_statusf(broker, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to get diskpool config, return is %d.", > + ret); > + return s; > + } > if ((id == NULL) && (count == 0)) { > CU_DEBUG("No defined DiskPools"); > free(pools); > From jferlan at redhat.com Thu Mar 21 18:04:10 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:04:10 -0400 Subject: [Libvirt-cim] [PATCH V5 09/15] RASDIndication, fix debug print crash In-Reply-To: <1363837158-11509-10-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-10-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B4B9A.8010402@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Signed-off-by: Wenchao Xia > Reviewed-by: John Ferlan > Reviewed-by: Sharad Mishra > --- > src/Virt_ResourceAllocationSettingDataIndication.c | 6 +++++- > 1 files changed, 5 insertions(+), 1 deletions(-) > ACK Again with the comment that you could git rebase -i to include this and 7/15 with 5/15 John From jferlan at redhat.com Thu Mar 21 18:06:13 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:06:13 -0400 Subject: [Libvirt-cim] [PATCH V5 10/15] device parsing, add debug print In-Reply-To: <1363837158-11509-11-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-11-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B4C15.2060708@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Sometimes libvirt will fail in these APIs if there is low level error, > what we saw is libvirt can't got xml for some domain. This patch adds > debug log when met this error, so in future we can know what is wrong. > > Signed-off-by: Wenchao Xia > --- > libxkutil/device_parsing.c | 16 +++++++++++++--- > 1 files changed, 13 insertions(+), 3 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 18:28:20 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:28:20 -0400 Subject: [Libvirt-cim] [PATCH V5 11/15] CSI Discard libvirt event by default In-Reply-To: <1363837158-11509-12-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-12-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B5144.2000306@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > 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. > > Most possible is that tog-pegasus tries to manage all threads > resulting the error. > > 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 > > Note that to make review easy, this patch try move the code > as little as possible, a following "clean up" patch will > move the code together. > > Signed-off-by: Wenchao Xia > --- > src/Virt_ComputerSystem.c | 60 +++- > src/Virt_ComputerSystemIndication.c | 663 ++++++++++++++++++++++++++++- > src/Virt_VirtualSystemManagementService.c | 57 +++- > 3 files changed, 777 insertions(+), 3 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 18:33:16 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:33:16 -0400 Subject: [Libvirt-cim] [PATCH V5 12/15] CSI: Move native CSI code together In-Reply-To: <1363837158-11509-13-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-13-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B526C.8020309@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This is a pure code move patch. Now codes using libvirt event > or native event, are moved into one macro protection, which make > code easy to read, and in futher they can be moved into new file > as CSI-libvirt.c. > This patch also fix code style problem in moved code. > > Signed-off-by: Wenchao Xia > --- > src/Virt_ComputerSystemIndication.c | 851 ++++++++++++++++++----------------- > 1 files changed, 429 insertions(+), 422 deletions(-) > ACK - lots of trust here as it's not fun looking around for code movement :-) Personally, I prefer interlaced code as it's somewhat easier to maintain long term. Now there's lots duplicated (eg, cut-n-paste) code that's can be the source of future "issues" when one stream is changed but not the other. John From jferlan at redhat.com Thu Mar 21 18:43:43 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:43:43 -0400 Subject: [Libvirt-cim] [PATCH V5 13/15] VSSD: report success if not all VS fail in enum In-Reply-To: <1363837158-11509-14-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-14-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B54DF.4020001@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > Original code 'continue' in the 'for' in return_enum_vssd() when > one VSDS fail in retrieving, but forgot to set s to normal. This patch > fix this case. > Also many debug message is added to log the error if met. > > Signed-off-by: Wenchao Xia > --- > src/Virt_VSSD.c | 43 +++++++++++++++++++++++++++++++++++++++++-- > 1 files changed, 41 insertions(+), 2 deletions(-) > > diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c > index 975623b..3d2de26 100644 > --- a/src/Virt_VSSD.c > +++ b/src/Virt_VSSD.c > @@ -181,8 +181,10 @@ static int instance_from_dom(const CMPIBroker *broker, > struct domain *dominfo = NULL; > > ret = get_dominfo(dom, &dominfo); > - if (!ret) > + if (!ret) { > + CU_DEBUG("Failed in get_dominfo()."); > goto out; > + } > > op = CMGetObjectPath(inst, NULL); > pfx = class_prefix_name(CLASSNAME(op)); > @@ -245,6 +247,7 @@ static int instance_from_dom(const CMPIBroker *broker, > (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU)) { > s = _set_fv_prop(broker, dominfo, inst); > if (s.rc != CMPI_RC_OK) { > + CU_DEBUG("Failed to set full virtual props."); > ret = 0; > goto out; > } > @@ -259,6 +262,7 @@ static int instance_from_dom(const CMPIBroker *broker, > dominfo->type); > > if (asprintf(&vsid, "%s:%s", pfx, dominfo->name) == -1) { > + CU_DEBUG("Failed in asprintf()."); > ret = 0; > goto out; > } > @@ -328,14 +332,34 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, > } else if (count == 0) > goto out; > > + int fail_count = 0; Put this with the other decls. > for (i = 0; i < count; i++) { > CMPIInstance *inst = NULL; > > inst = _get_vssd(_BROKER, reference, conn, list[i], &s); > > virDomainFree(list[i]); > - if (inst == NULL) > + if (inst == NULL) { > + /* log the error */ > + const char *dom_name = virDomainGetName(list[i]); You'll need to do this before you virDomainFree(list[i]) or reformat the code a bit to do the virDomainFree() twice. Once before the continue below and once if inst != NULL Or do the virDomainFree() below in a for loop before free(list). The rest seems fine. John > + if (s.msg) { > + CU_DEBUG("Failed to get VSSD instance from " > + "domain [%s], status msg [%s].", > + dom_name, CMGetCharPtr(s.msg)); > + } else { > + CU_DEBUG("Failed to get VSSD instance from " > + "domain [%s].", > + dom_name); > + } > + /* restore s until last one */ > + if (i < count - 1) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_OK, > + "NULL"); > + } > + fail_count++; > continue; > + } > > if (names_only) > cu_return_instance_name(results, inst); > @@ -343,6 +367,21 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, > CMReturnInstance(results, inst); > } > > + /* check if some VS fail */ > + if (fail_count > 0) { > + CU_DEBUG("Failed to get %d VSSD in enum, total is %d.", > + fail_count, count); > + if (fail_count < count) { > + /* consider it succeed, some VSSD will be returned */ > + cu_statusf(_BROKER, &s, > + CMPI_RC_OK, > + "Got %d/%d VSSD, " > + "some VS may changed during enum", > + count - fail_count, count); > + } > + } > + > + > out: > free(list); > virConnectClose(conn); > From jferlan at redhat.com Thu Mar 21 18:58:34 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 14:58:34 -0400 Subject: [Libvirt-cim] [PATCH V5 14/15] misc_util: better way to read config In-Reply-To: <1363837158-11509-15-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-15-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B585A.1050702@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This patch adds an common internal function to get property > from libvirt-cim config, so it is easy to add properties > later. > > Signed-off-by: Wenchao Xia > --- > libxkutil/misc_util.c | 114 +++++++++++++++++++++++++++++++++++++++++++------ > 1 files changed, 100 insertions(+), 14 deletions(-) > ACK John From jferlan at redhat.com Thu Mar 21 23:07:48 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 19:07:48 -0400 Subject: [Libvirt-cim] [PATCH V5 15/15] migration: allow ssh based migration with non root's key file In-Reply-To: <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514B92C4.1050202@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This patch allow libvirt-cim to use non-root's ssh key in migration > to avoid exposing root's ssh login on server. In some case server are > forbidden to expose or provide any root ssh login, and still use ssh > encryption between two migration nodes with key of special account > created for virtual machine management. > > When it is enabled in config file: > 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key > to be copied. It will be copied to [migrate_ssh_temp_key]. > 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, > use bool property [MigrationWithoutRootKey], to tell whether to use the key > as [migrate_ssh_temp_key]. > 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be > deleted. > > Details: > libvirt-cim would run shell command "cp -f [SSH_Key_Src] > [migrate_ssh_temp_key]", then use [migrate_ssh_temp_key] to generate uri > suffix for remote connection to migration destination. > > Signed-off-by: Wenchao Xia > --- > libvirt-cim.conf | 19 +++ > libxkutil/misc_util.c | 9 ++ > libxkutil/misc_util.h | 3 + > src/Virt_VSMigrationService.c | 263 ++++++++++++++++++++++++++++++++++++++++- > 4 files changed, 289 insertions(+), 5 deletions(-) > Need some more time to look at this - first pass seems OK, but it's late and I'll pick it up again tomorrow. John From jferlan at redhat.com Thu Mar 21 23:16:08 2013 From: jferlan at redhat.com (John Ferlan) Date: Thu, 21 Mar 2013 19:16:08 -0400 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <514A82AF.5040404@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <514A82AF.5040404@linux.vnet.ibm.com> Message-ID: <514B94B8.7070601@redhat.com> On 03/20/2013 11:46 PM, Wenchao Xia wrote: > Hi, John > These were recoded patches, removing script for bridge patch > is removed, please add yours after it. > After reconsideration, I think we should stick to libvirt 0.9.0 > for libvirt-cim0.6.2, which makes 0.6.2 as steady version and allow > user to update to it without any trouble. After it we can raise > the libvirt version requirement in config file. > Also please add signed-off in your patches. > > Many thanks. > I'll repost the bridge patch tomorrow at some point. As for 0.9.0 vs. later - I understand your position, maybe there's some other mechanism that would allow the "choice" for someone to build using a later version that would allow the use of those All API's. What I don't know/understand is when libvirt-cim is built, is a 0.9.0 environment used? Not that it should matter, but I guess I'm just curious. For those patches I had questions/issues with - just post an update and let's take it from there. I don't think you have to repost the whole series unless that's what DV would prefer. I'm not sure what you mean by "add signed-off in your patches". I'm still a bit of a novice w/ git and the process. John From jferlan at redhat.com Fri Mar 22 13:22:42 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 09:22:42 -0400 Subject: [Libvirt-cim] [PATCH V5 15/15] migration: allow ssh based migration with non root's key file In-Reply-To: <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <514C5B22.9020401@redhat.com> On 03/20/2013 11:39 PM, Wenchao Xia wrote: > This patch allow libvirt-cim to use non-root's ssh key in migration > to avoid exposing root's ssh login on server. In some case server are > forbidden to expose or provide any root ssh login, and still use ssh > encryption between two migration nodes with key of special account > created for virtual machine management. > > When it is enabled in config file: > 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key > to be copied. It will be copied to [migrate_ssh_temp_key]. > 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, > use bool property [MigrationWithoutRootKey], to tell whether to use the key > as [migrate_ssh_temp_key]. > 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be > deleted. > > Details: > libvirt-cim would run shell command "cp -f [SSH_Key_Src] > [migrate_ssh_temp_key]", then use [migrate_ssh_temp_key] to generate uri > suffix for remote connection to migration destination. > > Signed-off-by: Wenchao Xia > --- > libvirt-cim.conf | 19 +++ > libxkutil/misc_util.c | 9 ++ > libxkutil/misc_util.h | 3 + > src/Virt_VSMigrationService.c | 263 ++++++++++++++++++++++++++++++++++++++++- > 4 files changed, 289 insertions(+), 5 deletions(-) > > diff --git a/libvirt-cim.conf b/libvirt-cim.conf > index d3cb2c3..37d7b0f 100644 > --- a/libvirt-cim.conf > +++ b/libvirt-cim.conf > @@ -11,3 +11,22 @@ > # Default value: false > # > # readonly = false; > + > +# migrate_ssh_temp_key (string) > +# Defines a temp key file which would be used as ssh key in ssh migration, > +# Only when it is set, following methods in VirtualSystemMigrationService > +# could be used: > +# 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key > +# to be copied. It will be copied to [migrate_ssh_temp_key]. > +# 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, > +# use bool property [MigrationWithoutRootKey], to tell whether to use the key > +# as [migrate_ssh_temp_key]. > +# 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be > +# deleted. > +# Note: migrate_ssh_temp_key must be set in a directory completely owned by > +# root from bottom to top, such as /root/A, or /tmp/A. > +# > +# Possible values: {any path plus filename on host} > +# Default value: NULL, that is not set. > +# > +# migrate_ssh_temp_key = "/root/vm_migrate_tmp_id_rsa"; > diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c > index 820b42d..00eb4b1 100644 > --- a/libxkutil/misc_util.c > +++ b/libxkutil/misc_util.c > @@ -227,6 +227,15 @@ static int is_read_only(void) > return prop.value_bool; > } > > +const char *get_mig_ssh_tmp_key(void) > +{ > + static LibvirtcimConfigProperty prop = { > + "migrate_ssh_temp_key", CONFIG_STRING, {0}, 0}; > + > + libvirt_cim_config_get(&prop); > + return prop.value_string; > +} > + > virConnectPtr connect_by_classname(const CMPIBroker *broker, > const char *classname, > CMPIStatus *s) > diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h > index 90fb2da..0f52290 100644 > --- a/libxkutil/misc_util.h > +++ b/libxkutil/misc_util.h > @@ -152,6 +152,9 @@ int virt_set_status(const CMPIBroker *broker, > > #define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL)) > > +/* get libvirt-cim config */ > +const char *get_mig_ssh_tmp_key(void); > + > /* > * Local Variables: > * mode: C > diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c > index 1f6659d..d03e1a0 100644 > --- a/src/Virt_VSMigrationService.c > +++ b/src/Virt_VSMigrationService.c > @@ -150,6 +150,7 @@ static CMPIStatus get_migration_uri(CMPIInstance *msd, > > static char *dest_uri(const char *cn, > const char *dest, > + const char *dest_params, > uint16_t transport) > { > const char *prefix; > @@ -157,6 +158,7 @@ static char *dest_uri(const char *cn, > const char *param = ""; > char *uri = NULL; > int rc; > + int param_labeled = 0; > > if (STARTS_WITH(cn, "Xen")) > prefix = "xen"; > @@ -197,16 +199,54 @@ static char *dest_uri(const char *cn, > goto out; > } > > - if (!STREQC(param, "")) > + if (!STREQC(param, "")) { > rc = asprintf(&uri, "%s/%s", uri, param); > + param_labeled = 1; > + } > > - if (rc == -1) > + if (rc == -1) { > uri = NULL; > + goto out; > + } > > + if (dest_params) { > + if (param_labeled == 0) { > + rc = asprintf(&uri, "%s?%s", uri, dest_params); > + } else { > + /* ? is already added */ > + rc = asprintf(&uri, "%s%s", uri, dest_params); > + } > + if (rc == -1) { > + uri = NULL; > + goto out; > + } > + } > out: > return uri; > } > > +/* Todo: move it to libcmpiutil */ > +static CMPIrc cu_get_bool_arg_my(const CMPIArgs *args, > + const char *name, > + bool *target) > +{ > + CMPIData argdata; > + CMPIStatus s; > + > + argdata = CMGetArg(args, name, &s); > + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) { > + return CMPI_RC_ERR_INVALID_PARAMETER; > + } > + > + if (argdata.type != CMPI_boolean) { > + return CMPI_RC_ERR_TYPE_MISMATCH; > + } > + > + *target = (bool)argdata.value.boolean; > + > + return CMPI_RC_OK; > +} > + I don't believe the above function is necessary - there is already a cu_get_bool_prop(). > static CMPIStatus get_msd_values(const CMPIObjectPath *ref, > const char *destination, > const CMPIArgs *argsin, > @@ -217,6 +257,13 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, > CMPIInstance *msd; > uint16_t uri_type; > char *uri = NULL; > + bool no_root_ssh_key = false; s/no_root_ssh_key/use_non_root_ssh_key/ Just a consideration, not a requirement. When I first saw the variable in use I had to think about it. "no_root_ssh_key" just had a different meaning in my mind. > + char *dest_params = NULL; > + int ret; > + > + cu_get_bool_arg_my(argsin, > + "MigrationWithoutRootKey", > + &no_root_ssh_key); Why not use the existing cu_get_bool_prop(). You don't even check the return value here, so what's the use of your local routine? > > s = get_msd(ref, argsin, &msd); > if (s.rc != CMPI_RC_OK) > @@ -230,7 +277,27 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, > if (s.rc != CMPI_RC_OK) > goto out; > > - uri = dest_uri(CLASSNAME(ref), destination, uri_type); > + if (no_root_ssh_key) { > + const char *tmp_keyfile = get_mig_ssh_tmp_key(); > + if (!tmp_keyfile) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Migration with special ssh key " > + "is not enabled in config file."); > + CU_DEBUG("Migration with special ssh key " > + "is not enabled in config file."); > + goto out; > + } > + CU_DEBUG("Trying migrate with specified ssh key file [%s].", > + tmp_keyfile); > + ret = asprintf(&dest_params, "keyfile=%s", tmp_keyfile); > + if (ret < 0) { > + CU_DEBUG("Failed in generating param string."); > + goto out; > + } > + } > + > + uri = dest_uri(CLASSNAME(ref), destination, dest_params, uri_type); > if (uri == NULL) { > cu_statusf(_BROKER, &s, > CMPI_RC_ERR_FAILED, > @@ -238,6 +305,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, > goto out; > } > > + CU_DEBUG("Migrate tring to connect remote host with uri %s.", uri); > *conn = virConnectOpen(uri); > if (*conn == NULL) { > CU_DEBUG("Failed to connect to remote host (%s)", uri); > @@ -249,7 +317,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, > > out: > free(uri); > - > + free(dest_params); > return s; > } > > @@ -1538,7 +1606,7 @@ static CMPIStatus migrate_vs_host(CMPIMethodMI *self, > const char *dhost = NULL; > CMPIObjectPath *system; > const char *name = NULL; > - > + > cu_get_str_arg(argsin, "DestinationHost", &dhost); > cu_get_ref_arg(argsin, "ComputerSystem", &system); > > @@ -1604,11 +1672,178 @@ static CMPIStatus migrate_vs_system(CMPIMethodMI *self, > return migrate_do(ref, ctx, name, dname, argsin, results, argsout); > } > > +/* return 0 on success */ > +static int pipe_exec(const char *cmd) > +{ > + FILE *stream = NULL; > + int ret = 0; > + char buf[256]; > + > + CU_DEBUG("executing system cmd [%s].", cmd); > + /* Todo: We need a better popen, currently stdout have been closed > + and SIGCHILD is handled by tog-pegasus, so fgets always got NULL > + making error detection not possible. */ > + stream = popen(cmd, "r"); > + if (stream == NULL) { > + CU_DEBUG("Failed to open pipe to run the command."); > + ret = -1; > + goto out; > + } > + usleep(10000); > + > + buf[255] = 0; > + while (fgets(buf, sizeof(buf), stream) != NULL) { > + CU_DEBUG("Exception got: [%s].", buf); > + ret = -2; > + goto out; > + } > + > + out: > + if (stream != NULL) { > + pclose(stream); > + } > + return ret; > +} > + > +/* > + * libvirt require private key specified to be placed in a directory owned by > + * root, because libvirt-cim now runs as root. So here the key would be copied. > + * In this way libvirt-cim could borrow a non-root ssh private key, instead of > + * using root's private key, avoid security risk. > + */ > +static int ssh_key_copy(const char *src, const char *dest) > +{ > + char *cmd = NULL; > + int ret = 0; > + struct stat sb; > + > + /* try delete it */ > + unlink(dest); > + ret = stat(dest, &sb); > + if (ret == 0) { > + CU_DEBUG("Can not delete [%s] before copy, " > + "maybe someone is using it.", > + dest); > + /* not a fatal fault */ Maybe not fatal, but what makes you believe a subsequent copy will succeed? Is there a way to keep track of this being "in use" by some other thread that could delete it? It's almost like there needs to be a reference count. Is it possible for two threads to be using it at the same time? Just thinking out loud and trying to consider the negative consequences. In a former job we allowed 1 migration at a time and I'm not aware of the libvirt "restrictions" (yet). IOW, Before we unlink it, if it's already there what does that mean? > + } > + > + ret = asprintf(&cmd, "cp -f %s %s", src, dest); > + if (ret < 0) { > + CU_DEBUG("Failed in combination for shell command."); > + goto out; > + } > + > + ret = pipe_exec(cmd); > + if (ret < 0) { > + CU_DEBUG("Error in executing command [%s]"); > + goto out; > + } > + > + ret = stat(dest, &sb); > + if (ret < 0) { > + CU_DEBUG("Can not find file [%s] after copy.", dest); > + } > + out: > + free(cmd); > + return ret; > +} > + > +static CMPIStatus migrate_sshkey_copy(CMPIMethodMI *self, > + const CMPIContext *ctx, > + const CMPIResult *results, > + const CMPIObjectPath *ref, > + const CMPIArgs *argsin, > + CMPIArgs *argsout) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + const char *ssh_key_src = NULL; > + int ret; > + > + const char *tmp_keyfile = get_mig_ssh_tmp_key(); > + if (!tmp_keyfile) { > + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, > + "Migration with special ssh key " > + "is not enabled in config file."); > + CU_DEBUG("Migration with special ssh key " > + "is not enabled in config file."); > + goto out; > + } > + > + cu_get_str_arg(argsin, "SSH_Key_Src", &ssh_key_src); > + if (!ssh_key_src) { > + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, > + "Failed to get property 'SSH_Key_Src'."); > + CU_DEBUG("Failed to get property 'SSH_Key_Src'."); > + goto out; > + } > + > + ret = ssh_key_copy(ssh_key_src, tmp_keyfile); > + if (ret < 0) { > + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, > + "Got error in copying ssh key from [%s] to [%s].", > + ssh_key_src, tmp_keyfile); > + CU_DEBUG("Got error in copying ssh key from [%s] to [%s].", > + ssh_key_src, tmp_keyfile); > + } > + > + out: > + METHOD_RETURN(results, s.rc); > + return s; > +} > + > +static CMPIStatus migrate_sshkey_delete(CMPIMethodMI *self, > + const CMPIContext *ctx, > + const CMPIResult *results, > + const CMPIObjectPath *ref, > + const CMPIArgs *argsin, > + CMPIArgs *argsout) > +{ > + CMPIStatus s = {CMPI_RC_OK, NULL}; > + int ret; > + struct stat sb; Should we check for "MigrationWithoutRootKey" here too? Is it possible for one thread to request migration without root key while another wants root key? Does the caller really need to know/care? It looks to be an object setting, so we probably do care. > + > + const char *tmp_keyfile = get_mig_ssh_tmp_key(); > + if (!tmp_keyfile) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Migration with special ssh key " > + "is not enabled in config file."); > + CU_DEBUG("Migration with special ssh key " > + "is not enabled in config file."); > + goto out; > + } > + > + ret = stat(tmp_keyfile, &sb); > + if (ret == 0) { > + /* need delete */ > + ret = unlink(tmp_keyfile); > + if (ret < 0) { > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Failed to delete [%s].", > + tmp_keyfile); > + CU_DEBUG("Failed to delete [%s].", tmp_keyfile); > + } > + } else { > + /* not exist */ > + cu_statusf(_BROKER, &s, > + CMPI_RC_ERR_FAILED, > + "Can not find file [%s] before delete.", > + tmp_keyfile); > + CU_DEBUG("Can not find file [%s] before delete.", tmp_keyfile); Which perhaps means our other code above did the unlink() for us in another thread? Do you want an error here? John > + } > + > + out: > + METHOD_RETURN(results, s.rc); > + return s; > +}; > + > static struct method_handler vsimth = { > .name = "CheckVirtualSystemIsMigratableToHost", > .handler = vs_migratable_host, > .args = {{"ComputerSystem", CMPI_ref, false}, > {"DestinationHost", CMPI_string, false}, > + {"MigrationWithoutRootKey", CMPI_boolean, true}, > {"MigrationSettingData", CMPI_instance, true}, > {"NewSystemSettingData", CMPI_instance, true}, > {"NewResourceSettingData", CMPI_instanceA, true}, > @@ -1633,6 +1868,7 @@ static struct method_handler mvsth = { > .handler = migrate_vs_host, > .args = {{"ComputerSystem", CMPI_ref, false}, > {"DestinationHost", CMPI_string, false}, > + {"MigrationWithoutRootKey", CMPI_boolean, true}, > {"MigrationSettingData", CMPI_instance, true}, > {"NewSystemSettingData", CMPI_instance, true}, > {"NewResourceSettingData", CMPI_instanceA, true}, > @@ -1652,11 +1888,28 @@ static struct method_handler mvsts = { > } > }; > > +static struct method_handler msshkc = { > + .name = "MigrateSSHKeyCopy", > + .handler = migrate_sshkey_copy, > + .args = {{"SSH_Key_Src", CMPI_string, true}, > + ARG_END > + } > +}; > + > +static struct method_handler msshkd = { > + .name = "MigrateSSHKeyDelete", > + .handler = migrate_sshkey_delete, > + .args = {ARG_END > + } > +}; > + > static struct method_handler *my_handlers[] = { > &vsimth, > &vsimts, > &mvsth, > &mvsts, > + &msshkc, > + &msshkd, > NULL > }; > > From jferlan at redhat.com Fri Mar 22 20:58:39 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:58:39 -0400 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <514A82AF.5040404@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <514A82AF.5040404@linux.vnet.ibm.com> Message-ID: <514CC5FF.5010308@redhat.com> My series is now posted. I have run both your patches and my patches through cimtest on my f18 box. Although it was not a very enjoyable experience today as recent yum updates and subsequent reboot made things quite frustrating. I couldn't seem to convince the libvirt-cim build to find the libcmpiutil in the 64 bit area. It had something to do with the 'PKG_CONFIG_PATH' variable. Once I worked through that the generation of the rpm was failing because of 'BuildConflicts: sblim-cmpi-devel' in libvirt-cim.spec. My cimtest still has problems with any of the *Indications cimtests - I get errors such as: ComputerSystemIndication - 01_created_indication.py: FAIL Error connecting to CIMOM: [Errno 110] Connection timed out There's a significant pause. Perhaps there's some sort of iptables thing I have to do - I haven't really investigated. I've been able to procure a RHEL6 box and will probably move my testing there (when I have time). John From jferlan at redhat.com Fri Mar 22 20:47:12 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:12 -0400 Subject: [Libvirt-cim] [PATCH 6/8] libxkutil: Adjust get_dominfo() logic In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-7-git-send-email-jferlan@redhat.com> Need to really handle the error on the get_dominfo_from_xml() call Need to be sure to free(xml) before returning --- libxkutil/device_parsing.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index 845a953..264d4cc 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -1246,7 +1246,7 @@ int get_dominfo_from_xml(const char *xml, struct domain **dominfo) int get_dominfo(virDomainPtr dom, struct domain **dominfo) { char *xml; - int ret; + int ret = 0; int start; xml = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); @@ -1256,18 +1256,17 @@ int get_dominfo(virDomainPtr dom, struct domain **dominfo) return 0; } - ret = get_dominfo_from_xml(xml, dominfo); - if (ret != 1) { + if (get_dominfo_from_xml(xml, dominfo) == 0) { CU_DEBUG("Failed to translate xml into struct domain"); goto out; } if (virDomainGetAutostart(dom, &start) != 0) { CU_DEBUG("Failed to get dom autostart with libvirt API."); - ret = 0; goto out; } (*dominfo)->autostrt = start; + ret = 1; out: free(xml); -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:11 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:11 -0400 Subject: [Libvirt-cim] [PATCH 5/8] libxkutil: Use virConnectListAllDomains() to fetch domains In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-6-git-send-email-jferlan@redhat.com> This is an optimization over using the multistep approach to get a count, get some memory, and get the list of domains (active and defined). Followed other examples to ensure only building the code if the libvirt version is correct. The API was added in 0.9.13. --- libxkutil/cs_util_instance.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/libxkutil/cs_util_instance.c b/libxkutil/cs_util_instance.c index a383147..e95052a 100644 --- a/libxkutil/cs_util_instance.c +++ b/libxkutil/cs_util_instance.c @@ -33,6 +33,29 @@ #include "cs_util.h" #include +#if LIBVIR_VERSION_NUMBER >= 9013 +int get_domain_list(virConnectPtr conn, virDomainPtr **_list) +{ + virDomainPtr *nameList = NULL; + int n_names; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names > 0) { + *_list = nameList; + } else if (n_names == 0) { + /* Since there are no elements, no domain ptrs to free + * but still must free the nameList returned + */ + free(nameList); + } + + return n_names; +} +#else int get_domain_list(virConnectPtr conn, virDomainPtr **_list) { char **names = NULL; @@ -113,6 +136,7 @@ int get_domain_list(virConnectPtr conn, virDomainPtr **_list) return idx; } +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ void set_instance_class_name(CMPIInstance *instance, char *name) { -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:09 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:09 -0400 Subject: [Libvirt-cim] [PATCH 3/8] Remove empty newline at bottom In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-4-git-send-email-jferlan@redhat.com> --- schema/SwitchService.registration | 1 - 1 file changed, 1 deletion(-) diff --git a/schema/SwitchService.registration b/schema/SwitchService.registration index b8e4f23..82a5c04 100644 --- a/schema/SwitchService.registration +++ b/schema/SwitchService.registration @@ -3,4 +3,3 @@ Xen_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance KVM_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance LXC_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance - -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:06 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:06 -0400 Subject: [Libvirt-cim] [PATCHv2 0/8] Additional patches for 0.6.2 Message-ID: <1363985234-31302-1-git-send-email-jferlan@redhat.com> This series replaces my last set. It is a followup after rebase and rework to: https://www.redhat.com/archives/libvirt-cim/2013-March/msg00029.html Changes in v2: * Rework libxkutil/cs_util_instance.c to mirror functions as requested * Rework src/Virt_DevicePool.c to mirror functions as requested * Just merged the Makefile.am changes into one * Previous patch 4/10 to CSI is removed due to code change already posted Still to be reviewed is Makefile.am. John Ferlan (8): Makefile.am: Remove the $(top_srcdir) from subst command libvirt-cim.spec: Use systemctl for tog-pegasus restart Remove empty newline at bottom xmlgen: Only support script on bridge for xen domains libxkutil: Use virConnectListAllDomains() to fetch domains libxkutil: Adjust get_dominfo() logic DevicePool: Use the virConnectListAll interfaces register: Adjust the chatter output Makefile.am | 18 +-- libvirt-cim.spec.in | 12 +- libxkutil/cs_util_instance.c | 24 ++++ libxkutil/device_parsing.c | 7 +- libxkutil/xmlgen.c | 25 +++-- provider-register.sh | 9 +- schema/SwitchService.registration | 1 - src/Virt_DevicePool.c | 230 ++++++++++++++++++++++++++++++++++++++ 8 files changed, 296 insertions(+), 30 deletions(-) -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:07 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:07 -0400 Subject: [Libvirt-cim] [PATCH 1/8] Makefile.am: Remove the $(top_srcdir) from subst command In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-2-git-send-email-jferlan@redhat.com> During the postinstall and preuninstall phases various variables are modified to build up the list of mofs to be installed. The generated output had ".//usr/local/share/libvirt-cim/*" which caused issues finding files. This is a followup to commit '22022870' which changed the paths using to schema for each of the variables. --- Makefile.am | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0fdd8bb..63ed3c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,7 +189,7 @@ install-data-local: $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_MOFS) $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_REGS) if [[ @CIMSERVER@ != pegasus ]]; then \ - sed -i '/^# --/,/^# --!/d' $(subst ./schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ + sed -i '/^# --/,/^# --!/d' $(subst $(top_srcdir)/schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ fi uninstall-local: @@ -206,21 +206,21 @@ preinstall: # Un/Register the providers and class definitions from/to the current CIMOM. # @CIMSERVER@ is set by the configure script postinstall: - sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi virsh -v | grep -q '^0.3' && cp examples/diskpool.conf $(DISK_POOL_CONFIG) || true mkdir -p $(INFO_STORE) preuninstall: - sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi rpm: clean -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:14 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:14 -0400 Subject: [Libvirt-cim] [PATCH 8/8] register: Adjust the chatter output In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-9-git-send-email-jferlan@redhat.com> Caused error during make postinstall. Rather than print the $PROVIDERMODULES it attempted to execute the second one in the list. Added extra output just prior to CIMMOF commands to show which namespace is being modified from which directory. There appears to be some sort of issue registering some mofs as the following message is generated numerous times: Warning: the instance already exists. In this implementation, that means it cannot be changed. --- provider-register.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/provider-register.sh b/provider-register.sh index 0616a14..b907df1 100755 --- a/provider-register.sh +++ b/provider-register.sh @@ -90,10 +90,10 @@ pegasus_transform() chatter "cimserver version is " $version if compare_version "$version" "2.11.0" then - chatter "Processing provider modules (w/o ModuleGroupName):" \ - $PROVIDERMODULES + chatter "Processing provider modules (w/o ModuleGroupName):" for pm in $PROVIDERMODULES do + chatter "...processing " $pm cat >> $OUTFILE <> $OUTFILE < References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-5-git-send-email-jferlan@redhat.com> A change was made in 0.9.10 to disallow a script on a bridge device for qemu guests, see 'libvirt' commit id '1734cdb99'. --- libxkutil/xmlgen.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c index 2dcd0d2..099fdd2 100644 --- a/libxkutil/xmlgen.c +++ b/libxkutil/xmlgen.c @@ -270,16 +270,21 @@ static const char *set_net_source(xmlNodePtr nic, } -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, + int domtype) { const char *script = "vif-bridge"; xmlNodePtr tmp; const char *msg = NULL; - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); - if (tmp == NULL) - return XML_ERROR; - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + /* Scripts only supported on Xen guests see 'libvirt' + * commit id 1734cdb99 (since 0.9.10) */ + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); + if (tmp == NULL) + return XML_ERROR; + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + } msg = set_net_source(nic, dev, "bridge"); @@ -375,13 +380,13 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo) } #endif - if (STREQ(dev->dev.net.type, "network")) + if (STREQ(dev->dev.net.type, "network")) { msg = set_net_source(nic, net, "network"); - else if (STREQ(dev->dev.net.type, "bridge")) - msg = bridge_net_to_xml(nic, net); - else if (STREQ(dev->dev.net.type, "user")) + } else if (STREQ(dev->dev.net.type, "bridge")) { + msg = bridge_net_to_xml(nic, net, dominfo->type); + } else if (STREQ(dev->dev.net.type, "user")) { continue; - else if (STREQ(dev->dev.net.type, "direct")) { + } else if (STREQ(dev->dev.net.type, "direct")) { msg = set_net_source(nic, net, "direct"); if (net->vsi.vsi_type != NULL) { struct vsi_device *vsi = &dev->dev.net.vsi; -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:13 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:13 -0400 Subject: [Libvirt-cim] [PATCH 7/8] DevicePool: Use the virConnectListAll interfaces In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-8-git-send-email-jferlan@redhat.com> Rather than the somewhat unreliable get a count and get a list of active names, use the newer virConnectListAll* interfaces in order to retrieve both a count and list in one call. --- src/Virt_DevicePool.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 230 insertions(+) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 185e3cc..bfca972 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -142,6 +142,76 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) return ret; } +#if LIBVIR_VERSION_NUMBER >= 100002 +static int get_diskpool_config(virConnectPtr conn, + struct tmp_disk_pool **_pools, + int *_count) +{ + int i, realcount = 0, count = 0; + virStoragePoolPtr *nameList = NULL; + int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; + struct tmp_disk_pool *pools = NULL; + int ret = 0; + bool bret; + + realcount = virConnectListAllStoragePools(conn, + &nameList, + flags); + if (realcount < 0) { + CU_DEBUG("Failed to get storage pools, return %d.", realcount); + ret = realcount; + goto out; + } + if (realcount == 0) { + CU_DEBUG("Zero pools got, but prelist is %d.", count); + goto set_parent; + } + + pools = calloc(realcount, sizeof(*pools)); + if (pools == NULL) { + CU_DEBUG("Failed to alloc space for %i pool structs", + realcount); + ret = -2; + goto free_names; + } + + for (i = 0; i < realcount; i++) { + pools[i].tag = strdup(virStoragePoolGetName(nameList[i])); + if (pools[i].tag == NULL) { + CU_DEBUG("Failed in strdup for storage pool name."); + ret = -3; + goto free_pools; + } + pools[i].primordial = false; + } + + set_parent: + bret = get_disk_parent(&pools, &realcount); + if (bret != true) { + CU_DEBUG("Failed in adding parentpool."); + ret = -4; + goto free_pools; + } + + /* succeed */ + *_pools = pools; + *_count = realcount; + goto free_names; + + free_pools: + free_diskpool(pools, realcount); + + free_names: + if (nameList != NULL) { + for (i = 0; i < realcount; i++) + virStoragePoolFree(nameList[i]); + free(nameList); + } + + out: + return ret; +} +#else /* This function returns 0 on sucess, negative on fail. */ static int get_diskpool_config(virConnectPtr conn, struct tmp_disk_pool **_pools, @@ -219,6 +289,7 @@ static int get_diskpool_config(virConnectPtr conn, out: return ret; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static bool diskpool_set_capacity(virConnectPtr conn, CMPIInstance *inst, @@ -524,6 +595,46 @@ static char *diskpool_member_of(const CMPIBroker *broker, return pool; } + +#if LIBVIR_VERSION_NUMBER >= 100002 +static virNetworkPtr bridge_to_network(virConnectPtr conn, + const char *bridge) +{ + int i, num; + virNetworkPtr *nameList = NULL; + virNetworkPtr network = NULL; + int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; + + num = virConnectListAllNetworks(conn, + &nameList, + flags); + if (num < 0) { + CU_DEBUG("Failed to get network pools."); + return NULL; + } + + for (i = 0; i < num; i++) { + const char *_netname; + char *_bridge; + + _netname = virNetworkGetName(nameList[i]); + _bridge = virNetworkGetBridgeName(network); + CU_DEBUG("Network `%s' has bridge `%s'", _netname, _bridge); + if (STREQ(bridge, _bridge)) { + network = nameList[i]; + nameList[i] = NULL; + i = num; /* Loop breaker */ + } + free(_bridge); + } + + for (i = 0; i < num; i++) { + virNetworkFree(nameList[i]); + } + free(nameList); + return network; +} +#else static virNetworkPtr bridge_to_network(virConnectPtr conn, const char *bridge) { @@ -567,6 +678,7 @@ static virNetworkPtr bridge_to_network(virConnectPtr conn, return network; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static char *_netpool_member_of(virConnectPtr conn, const struct net_device *ndev) @@ -743,6 +855,39 @@ static bool mempool_set_total(CMPIInstance *inst, virConnectPtr conn) return memory != 0; } +#if LIBVIR_VERSION_NUMBER >= 9013 +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) +{ + uint64_t memory = 0; + virDomainPtr *nameList = NULL; + int n_names, i; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names < 0) { + CU_DEBUG("Failed to get a list of all domains"); + goto out; + } + + for (i = 0; i < n_names; i++) { + virDomainInfo dom_info; + if (virDomainGetInfo(nameList[i], &dom_info) == 0) + memory += dom_info.memory; + virDomainFree(nameList[i]); + } + free(nameList); + + out: + CMSetProperty(inst, "Reserved", + (CMPIValue *)&memory, CMPI_uint64); + CMSetProperty(inst, "CurrentlyConsumedResource", + (CMPIValue *)&memory, CMPI_uint64); + + return memory != 0; +} +#else static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) { uint64_t memory = 0; @@ -787,6 +932,7 @@ static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) return memory != 0; } +#endif /* LIBVIR_VERSION_NUMBER >= 9013 */ static bool procpool_set_total(CMPIInstance *inst, virConnectPtr conn) { @@ -1026,6 +1172,89 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, return s; } +#if LIBVIR_VERSION_NUMBER >= 100002 +static CMPIStatus netpool_instance(virConnectPtr conn, + struct inst_list *list, + const char *ns, + const char *id, + const CMPIBroker *broker) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + char **netnames = NULL; + int i; + int nets = 0; + virNetworkPtr *nameList = NULL; + int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; + + if (id != NULL) { + return _netpool_for_network(list, + ns, + conn, + id, + pfx_from_conn(conn), + broker); + } + + nets = virConnectListAllNetworks(conn, + &nameList, + flags); + if (nets < 0) { + virt_set_status(broker, &s, + CMPI_RC_ERR_FAILED, + conn, + "Unable to list networks"); + + goto out; + } + + /* +1 for our primordial entry */ + netnames = calloc(nets+1, sizeof(*netnames)); + if (netnames == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to allocate memory for %i net names", nets); + goto out; + } + + for (i = 0; i < nets; i++) { + netnames[i] = strdup(virNetworkGetName(nameList[i])); + if (netnames[i] == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to strdup memory for %i net names", + nets); + goto out; + } + } + + /* Remember we allocated extra slot already */ + netnames[nets] = strdup("0"); + + for (i = 0; i < nets + 1; i++) { + _netpool_for_network(list, + ns, + conn, + netnames[i], + pfx_from_conn(conn), + broker); + } + + out: + if (nameList != NULL) { + for (i = 0; i < nets; i++) + virNetworkFree(nameList[i]); + free(nameList); + } + if (netnames != NULL) { + /* +1 to account for primordial */ + for (i = 0; i < nets + 1; i++) + free(netnames[i]); + free(netnames); + } + + return s; +} +#else static CMPIStatus netpool_instance(virConnectPtr conn, struct inst_list *list, const char *ns, @@ -1095,6 +1324,7 @@ static CMPIStatus netpool_instance(virConnectPtr conn, return s; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, virConnectPtr conn, -- 1.8.1.4 From jferlan at redhat.com Fri Mar 22 20:47:08 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 22 Mar 2013 16:47:08 -0400 Subject: [Libvirt-cim] [PATCH 2/8] libvirt-cim.spec: Use systemctl for tog-pegasus restart In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <1363985234-31302-3-git-send-email-jferlan@redhat.com> For Fedora 17 and RHEL7 use systemd, so change the pegasus startup to use that and make a dependency upon it. --- libvirt-cim.spec.in | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in index 3def978..0679d7f 100644 --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -6,7 +6,7 @@ Version: @PACKAGE_VERSION@ Release: 1%{?dist}%{?extra_release} License: LGPLv2+ Group: Development/Libraries -Source: libvirt-cim-%{version}.tar.gz +Source: ftp://libvirt.org/libvirt-cim/libvirt-cim-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root URL: http://libvirt.org/CIM/ Requires: libxml2 >= 2.6.0 @@ -27,6 +27,9 @@ BuildRequires: libconfig-devel BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 +BuildRequires: systemd-units +%endif BuildConflicts: sblim-cmpi-devel %description @@ -85,7 +88,12 @@ rm -fr $RPM_BUILD_ROOT %{_datadir}/%{name}/install_base_schema.sh %{_datadir}/%{name} -/etc/init.d/tog-pegasus condrestart +# Fedora 17 / RHEL-7 are first where we use systemd. +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 + systemctl restart tog-pegasus +%else + /etc/init.d/tog-pegasus condrestart +%endif %{_datadir}/%{name}/provider-register.sh -t pegasus \ -n @CIM_VIRT_NS@ \ -- 1.8.1.4 From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:02:22 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:02:22 +0800 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <514B94B8.7070601@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <514A82AF.5040404@linux.vnet.ibm.com> <514B94B8.7070601@redhat.com> Message-ID: <514EA4FE.2040404@linux.vnet.ibm.com> ? 2013-3-22 7:16, John Ferlan ??: > On 03/20/2013 11:46 PM, Wenchao Xia wrote: >> Hi, John >> These were recoded patches, removing script for bridge patch >> is removed, please add yours after it. >> After reconsideration, I think we should stick to libvirt 0.9.0 >> for libvirt-cim0.6.2, which makes 0.6.2 as steady version and allow >> user to update to it without any trouble. After it we can raise >> the libvirt version requirement in config file. >> Also please add signed-off in your patches. >> >> Many thanks. >> > > I'll repost the bridge patch tomorrow at some point. > > As for 0.9.0 vs. later - I understand your position, maybe there's some > other mechanism that would allow the "choice" for someone to build using > a later version that would allow the use of those All API's. What I Possiblely a macro or condition in configure could do it, but I'd like leave the work to be done later. > don't know/understand is when libvirt-cim is built, is a 0.9.0 > environment used? Not that it should matter, but I guess I'm just curious. no need to be 0.9.0, my env is 0.9.4 on RH6.3. I remember RH6.2 have a lower libvirt version and some user used it. > > For those patches I had questions/issues with - just post an update and > let's take it from there. I don't think you have to repost the whole > series unless that's what DV would prefer. I think repost full serial will make patch review/pick easier, we can make sure correct right version will be picked as a complete serial, the changes will be mentioned in the cover-letter so reviewer can skip unchanged patches. > > I'm not sure what you mean by "add signed-off in your patches". I'm > still a bit of a novice w/ git and the process. > when commit, use command 'git commit -s FILE -m COMMENT' will add this line, which declare the author of it. > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:05:10 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:05:10 +0800 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <514CC5FF.5010308@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <514A82AF.5040404@linux.vnet.ibm.com> <514CC5FF.5010308@redhat.com> Message-ID: <514EA5A6.5050001@linux.vnet.ibm.com> ? 2013-3-23 4:58, John Ferlan ??: > > My series is now posted. I have run both your patches and my patches > through cimtest on my f18 box. Although it was not a very enjoyable > experience today as recent yum updates and subsequent reboot made things > quite frustrating. I couldn't seem to convince the libvirt-cim build to > find the libcmpiutil in the 64 bit area. It had something to do with the > 'PKG_CONFIG_PATH' variable. Once I worked through that the generation > of the rpm was failing because of 'BuildConflicts: sblim-cmpi-devel' in > libvirt-cim.spec. > > My cimtest still has problems with any of the *Indications cimtests - I > get errors such as: > > ComputerSystemIndication - 01_created_indication.py: FAIL > Error connecting to CIMOM: [Errno 110] Connection timed out > Possible event/indication is not enabled, command "cimconfig -c -l" will list the settings, you can change it by "cimconfig -p -s PROPERTY=VALUE", and then restart tog-pegasus and retry. > > There's a significant pause. Perhaps there's some sort of iptables > thing I have to do - I haven't really investigated. I've been able to > procure a RHEL6 box and will probably move my testing there (when I have > time). > > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:11:16 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:11:16 +0800 Subject: [Libvirt-cim] [PATCH V5 01/15] Remove property CreationClassName in some instance In-Reply-To: <514B3715.2010803@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-2-git-send-email-xiawenc@linux.vnet.ibm.com> <514B3715.2010803@redhat.com> Message-ID: <514EA714.5030006@linux.vnet.ibm.com> ? 2013-3-22 0:36, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> There are some instances which did not register this property, so this >> patch added a parameter in get_typed_instance(). The caller must set it >> clearly whether to set the property. >> When tog-pegasus > 2.12 and its log >= WARNING, tog-pegasus will >> report this problem in log. >> >> Signed-off-by: Wenchao Xia >> --- >> libxkutil/misc_util.c | 12 ++++++++---- >> libxkutil/misc_util.h | 3 ++- >> src/Virt_AllocationCapabilities.c | 3 ++- >> src/Virt_ComputerSystem.c | 6 ++++-- >> src/Virt_ComputerSystemIndication.c | 3 ++- >> src/Virt_ConsoleRedirectionService.c | 3 ++- >> src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 ++- >> src/Virt_Device.c | 18 ++++++++++++------ >> src/Virt_DevicePool.c | 20 +++++++++++++------- >> src/Virt_EnabledLogicalElementCapabilities.c | 3 ++- >> src/Virt_FilterEntry.c | 3 ++- >> src/Virt_FilterList.c | 3 ++- >> src/Virt_HostSystem.c | 3 ++- >> src/Virt_KVMRedirectionSAP.c | 3 ++- >> src/Virt_RASD.c | 3 ++- >> src/Virt_ReferencedProfile.c | 3 ++- >> src/Virt_RegisteredProfile.c | 3 ++- >> src/Virt_ResourcePoolConfigurationCapabilities.c | 3 ++- >> src/Virt_ResourcePoolConfigurationService.c | 8 ++++++-- >> src/Virt_SettingsDefineCapabilities.c | 6 ++++-- >> src/Virt_SwitchService.c | 3 ++- >> src/Virt_VSMigrationCapabilities.c | 3 ++- >> src/Virt_VSMigrationService.c | 6 ++++-- >> src/Virt_VSMigrationSettingData.c | 3 ++- >> src/Virt_VSSD.c | 3 ++- >> src/Virt_VirtualSystemManagementCapabilities.c | 3 ++- >> src/Virt_VirtualSystemManagementService.c | 6 ++++-- >> src/Virt_VirtualSystemSnapshotService.c | 3 ++- >> ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 ++- >> 29 files changed, 97 insertions(+), 48 deletions(-) >> >> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c >> index 2d149ae..f1b93e4 100644 >> --- a/libxkutil/misc_util.c >> +++ b/libxkutil/misc_util.c >> @@ -341,7 +341,8 @@ char *get_typed_class(const char *refcn, const char *new_base) >> CMPIInstance *get_typed_instance(const CMPIBroker *broker, >> const char *refcn, >> const char *base, >> - const char *namespace) >> + const char *namespace, >> + bool ccn_flag) > > While it may seem obvious to you why one would want to provide 'true' or > 'false' here, could the function header elaborate a bit so that in the > future when someone "adds" a call to this function they will know > whether they should pass true or false. IOW which type of instances > need this and which do not. > > If the answer is "as according to the DSP" - I think that's fine. I > don't know where to find the DSP (yet) or at least where/how to make the > determination that the caller would (or not) need the property. > There is a standard for virtulization with CIM, whether setting it depends on that. http://dmtf.org/standards/vman the path is: DSP standard doc->cim schema file->libvirt-cim code. At least schema need to be consistent with libvirt-cim code, when not sure the standard doc can be checked. >>From my scan of these - it sems *Capabilities, *Indications, *Filter, > *Profiles, & *RASDs type classes don't need the property, while specific > element classes (ComputerSystem, HostSystem, LogicalDisk, NetworkPort, > etc) and *Service classes need the property. Is that a "fair" summary? > I think so. > ACK with description > > the remainder looks fine. > > > John >> { >> char *new_cn; >> CMPIObjectPath *op; >> @@ -360,8 +361,10 @@ CMPIInstance *get_typed_instance(const CMPIBroker *broker, >> if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) >> goto out; >> >> - CMSetProperty(inst, "CreationClassName", >> - (CMPIValue *)new_cn, CMPI_chars); >> + if (ccn_flag) { >> + CMSetProperty(inst, "CreationClassName", >> + (CMPIValue *)new_cn, CMPI_chars); >> + } >> >> out: >> free(new_cn); >> @@ -467,7 +470,8 @@ CMPIInstance *make_reference(const CMPIBroker *broker, >> ref_inst = get_typed_instance(broker, >> CLASSNAME(source_ref), >> assoc_classname, >> - NAMESPACE(source_ref)); >> + NAMESPACE(source_ref), >> + false); >> >> if (ref_inst != NULL) { >> CMPIObjectPath *target_ref; >> diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h >> index c7a2122..90fb2da 100644 >> --- a/libxkutil/misc_util.h >> +++ b/libxkutil/misc_util.h >> @@ -85,7 +85,8 @@ char *get_typed_class(const char *refcn, const char *new_base); >> CMPIInstance *get_typed_instance(const CMPIBroker *broker, >> const char *refcn, >> const char *base, >> - const char *namespace); >> + const char *namespace, >> + bool ccn_flag); >> >> /* Parse an OrgID:LocID string into its constituent parts */ >> int parse_instance_id(char *iid, char **orgid, char **locid); >> diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c >> index 970abeb..b358fac 100644 >> --- a/src/Virt_AllocationCapabilities.c >> +++ b/src/Virt_AllocationCapabilities.c >> @@ -46,7 +46,8 @@ static CMPIStatus ac_from_pool(const CMPIBroker *broker, >> *alloc_cap = get_typed_instance(broker, >> CLASSNAME(ref), >> "AllocationCapabilities", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (*alloc_cap == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c >> index e6c7e55..4a9b26d 100644 >> --- a/src/Virt_ComputerSystem.c >> +++ b/src/Virt_ComputerSystem.c >> @@ -440,7 +440,8 @@ CMPIStatus instance_from_dominfo(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> prefix, >> "ComputerSystem", >> - namespace); >> + namespace, >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Could not init CS instance. " >> @@ -560,7 +561,8 @@ static CMPIStatus instance_from_dom(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "ComputerSystem", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c >> index 2d0a94e..3096683 100644 >> --- a/src/Virt_ComputerSystemIndication.c >> +++ b/src/Virt_ComputerSystemIndication.c >> @@ -239,7 +239,8 @@ static bool _do_indication(const CMPIBroker *broker, >> ind = get_typed_instance(broker, >> prefix, >> ind_type_name, >> - args->ns); >> + args->ns, >> + false); >> >> /* Generally report errors and hope to continue, since we have no one >> to actually return status to. */ >> diff --git a/src/Virt_ConsoleRedirectionService.c b/src/Virt_ConsoleRedirectionService.c >> index 7b20c0d..16cade8 100644 >> --- a/src/Virt_ConsoleRedirectionService.c >> +++ b/src/Virt_ConsoleRedirectionService.c >> @@ -129,7 +129,8 @@ CMPIStatus get_console_rs(const CMPIObjectPath *reference, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "ConsoleRedirectionService", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get typed instance"); >> diff --git a/src/Virt_ConsoleRedirectionServiceCapabilities.c b/src/Virt_ConsoleRedirectionServiceCapabilities.c >> index 11f2986..88fb3a4 100644 >> --- a/src/Virt_ConsoleRedirectionServiceCapabilities.c >> +++ b/src/Virt_ConsoleRedirectionServiceCapabilities.c >> @@ -91,7 +91,8 @@ CMPIStatus get_console_rs_caps(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "ConsoleRedirectionServiceCapabilities", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_Device.c b/src/Virt_Device.c >> index e047a94..c7dcbc3 100644 >> --- a/src/Virt_Device.c >> +++ b/src/Virt_Device.c >> @@ -100,7 +100,8 @@ static CMPIInstance *net_instance(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "NetworkPort", >> - ns); >> + ns, >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get instance for NetworkPort"); >> @@ -138,7 +139,8 @@ static CMPIInstance *disk_instance(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "LogicalDisk", >> - ns); >> + ns, >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get instance for LogicalDisk"); >> @@ -185,7 +187,8 @@ static CMPIInstance *mem_instance(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "Memory", >> - ns); >> + ns, >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get instance for Memory"); >> @@ -234,7 +237,8 @@ static CMPIInstance *graphics_instance(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "DisplayController", >> - ns); >> + ns, >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get instance for DisplayController"); >> @@ -320,7 +324,8 @@ static CMPIInstance *input_instance(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "PointingDevice", >> - ns); >> + ns, >> + true); >> if (inst == NULL) { >> CU_DEBUG("Failed to get instance of %s_PointingDevice", >> pfx_from_conn(conn)); >> @@ -407,7 +412,8 @@ static bool vcpu_inst(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "Processor", >> - ns); >> + ns, >> + true); >> if (inst == NULL) >> return false; >> >> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c >> index 202e509..56c9715 100644 >> --- a/src/Virt_DevicePool.c >> +++ b/src/Virt_DevicePool.c >> @@ -803,7 +803,8 @@ static CMPIStatus mempool_instance(virConnectPtr conn, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "MemoryPool", >> - ns); >> + ns, >> + false); >> >> if (inst == NULL) { >> cu_statusf(broker, &s, >> @@ -842,7 +843,8 @@ static CMPIStatus procpool_instance(virConnectPtr conn, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "ProcessorPool", >> - ns); >> + ns, >> + false); >> >> if (inst == NULL) { >> cu_statusf(broker, &s, >> @@ -872,7 +874,8 @@ static CMPIStatus _netpool_for_parent(struct inst_list *list, >> inst = get_typed_instance(broker, >> refcn, >> "NetworkPool", >> - ns); >> + ns, >> + false); >> if (inst == NULL) { >> CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", >> ns, refcn); >> @@ -928,7 +931,8 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, >> inst = get_typed_instance(broker, >> refcn, >> "NetworkPool", >> - ns); >> + ns, >> + false); >> if (inst == NULL) { >> CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", >> ns, refcn); >> @@ -1046,7 +1050,7 @@ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, >> CMPIInstance *inst; >> char *poolid = NULL; >> >> - inst = get_typed_instance(broker, refcn, "DiskPool", ns); >> + inst = get_typed_instance(broker, refcn, "DiskPool", ns, false); >> >> if (inst == NULL) { >> cu_statusf(broker, &s, >> @@ -1136,7 +1140,8 @@ static CMPIStatus graphicspool_instance(virConnectPtr conn, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "GraphicsPool", >> - ns); >> + ns, >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> @@ -1172,7 +1177,8 @@ static CMPIStatus inputpool_instance(virConnectPtr conn, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "InputPool", >> - ns); >> + ns, >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_EnabledLogicalElementCapabilities.c b/src/Virt_EnabledLogicalElementCapabilities.c >> index 7ba5eae..2fcdef1 100644 >> --- a/src/Virt_EnabledLogicalElementCapabilities.c >> +++ b/src/Virt_EnabledLogicalElementCapabilities.c >> @@ -61,7 +61,8 @@ static CMPIInstance *_get_elec(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "EnabledLogicalElementCapabilities", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c >> index 126615b..3c4a3e6 100644 >> --- a/src/Virt_FilterEntry.c >> +++ b/src/Virt_FilterEntry.c >> @@ -546,7 +546,8 @@ static CMPIInstance *convert_rule_to_instance( >> inst = get_typed_instance(broker, >> CLASSNAME(reference), >> basename, >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> cu_statusf(broker, s, >> diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c >> index 9b5dbae..79776cd 100644 >> --- a/src/Virt_FilterList.c >> +++ b/src/Virt_FilterList.c >> @@ -50,7 +50,8 @@ static CMPIInstance *convert_filter_to_instance( >> inst = get_typed_instance(broker, >> CLASSNAME(reference), >> "FilterList", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> if (inst == NULL) { >> cu_statusf(broker, s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_HostSystem.c b/src/Virt_HostSystem.c >> index 724a5ea..c31d6cf 100644 >> --- a/src/Virt_HostSystem.c >> +++ b/src/Virt_HostSystem.c >> @@ -135,7 +135,8 @@ static CMPIStatus fake_host(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "HostSystem", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> cu_statusf(broker, &s, >> diff --git a/src/Virt_KVMRedirectionSAP.c b/src/Virt_KVMRedirectionSAP.c >> index db34d57..38ad468 100644 >> --- a/src/Virt_KVMRedirectionSAP.c >> +++ b/src/Virt_KVMRedirectionSAP.c >> @@ -125,7 +125,8 @@ static CMPIInstance *get_console_sap(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "KVMRedirectionSAP", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> cu_statusf(broker, s, >> diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c >> index 9493077..6e8a244 100644 >> --- a/src/Virt_RASD.c >> +++ b/src/Virt_RASD.c >> @@ -716,7 +716,8 @@ CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> CLASSNAME(ref), >> base, >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) >> return inst; >> >> diff --git a/src/Virt_ReferencedProfile.c b/src/Virt_ReferencedProfile.c >> index 150be1f..e78a8d3 100644 >> --- a/src/Virt_ReferencedProfile.c >> +++ b/src/Virt_ReferencedProfile.c >> @@ -242,7 +242,8 @@ static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, >> ref_inst = get_typed_instance(_BROKER, >> CLASSNAME(source_ref), >> assoc_classname, >> - NAMESPACE(source_ref)); >> + NAMESPACE(source_ref), >> + false); >> >> source = get_reg_prof_by_ref(source_ref); >> if (source->scoping_profile != NULL) >> diff --git a/src/Virt_RegisteredProfile.c b/src/Virt_RegisteredProfile.c >> index 389a179..e644708 100644 >> --- a/src/Virt_RegisteredProfile.c >> +++ b/src/Virt_RegisteredProfile.c >> @@ -54,7 +54,8 @@ CMPIStatus get_profile(const CMPIBroker *broker, >> instance = get_typed_instance(broker, >> pfx, >> "RegisteredProfile", >> - CIM_INTEROP_NS); >> + CIM_INTEROP_NS, >> + false); >> >> if (instance == NULL) { >> cu_statusf(broker, &s, >> diff --git a/src/Virt_ResourcePoolConfigurationCapabilities.c b/src/Virt_ResourcePoolConfigurationCapabilities.c >> index 32274ed..2dcbbcf 100644 >> --- a/src/Virt_ResourcePoolConfigurationCapabilities.c >> +++ b/src/Virt_ResourcePoolConfigurationCapabilities.c >> @@ -69,7 +69,8 @@ static CMPIStatus get_rpc_cap(const CMPIObjectPath *reference, >> inst = get_typed_instance(_BROKER, >> pfx_from_conn(conn), >> "ResourcePoolConfigurationCapabilities", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + false); >> if (inst == NULL) { >> cu_statusf(_BROKER, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c >> index 751d016..0c0cc06 100644 >> --- a/src/Virt_ResourcePoolConfigurationService.c >> +++ b/src/Virt_ResourcePoolConfigurationService.c >> @@ -781,6 +781,8 @@ static const char *rasd_to_res(CMPIInstance *inst, >> return msg; >> } >> >> +/* Warning: returned instance is not freed manually in caller, need confirm >> + if server will auto free it. */ >> static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, >> const CMPIObjectPath *ref, >> CMPIStatus *s) >> @@ -798,7 +800,8 @@ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, >> inst = get_typed_instance(_BROKER, >> CLASSNAME(ref), >> "StorageVolumeResourceAllocationSettingData", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(_BROKER, s, >> CMPI_RC_ERR_FAILED, >> @@ -1279,7 +1282,8 @@ CMPIStatus get_rpcs(const CMPIObjectPath *reference, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "ResourcePoolConfigurationService", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c >> index 9eb9e57..5091205 100644 >> --- a/src/Virt_SettingsDefineCapabilities.c >> +++ b/src/Virt_SettingsDefineCapabilities.c >> @@ -113,7 +113,8 @@ static CMPIInstance *default_vssd_instance(const char *prefix, >> inst = get_typed_instance(_BROKER, >> prefix, >> "VirtualSystemSettingData", >> - ns); >> + ns, >> + false); >> if (inst == NULL) { >> CU_DEBUG("Failed to create default VSSD instance"); >> goto out; >> @@ -303,7 +304,8 @@ static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, >> inst = get_typed_instance(_BROKER, >> CLASSNAME(ref), >> base, >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> >> if (inst == NULL) { >> cu_statusf(_BROKER, s, >> diff --git a/src/Virt_SwitchService.c b/src/Virt_SwitchService.c >> index 7e59d38..8991426 100644 >> --- a/src/Virt_SwitchService.c >> +++ b/src/Virt_SwitchService.c >> @@ -229,7 +229,8 @@ static CMPIStatus get_switchservice(const CMPIObjectPath *reference, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "SwitchService", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get typed instance"); >> diff --git a/src/Virt_VSMigrationCapabilities.c b/src/Virt_VSMigrationCapabilities.c >> index 4f0e434..3e53f68 100644 >> --- a/src/Virt_VSMigrationCapabilities.c >> +++ b/src/Virt_VSMigrationCapabilities.c >> @@ -134,7 +134,8 @@ CMPIStatus get_migration_caps(const CMPIObjectPath *ref, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemMigrationCapabilities", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c >> index 76e3d25..1f6659d 100644 >> --- a/src/Virt_VSMigrationService.c >> +++ b/src/Virt_VSMigrationService.c >> @@ -831,7 +831,8 @@ static CMPIInstance *prepare_indication(const CMPIBroker *broker, >> ind = get_typed_instance(broker, >> pfx, >> ind_name, >> - job->ref_ns); >> + job->ref_ns, >> + false); >> if (ind == NULL) { >> CU_DEBUG("Failed to create ind, type '%s:%s_%s'", >> job->ref_ns, pfx, ind_name); >> @@ -1686,7 +1687,8 @@ CMPIStatus get_migration_service(const CMPIObjectPath *ref, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemMigrationService", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + true); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_VSMigrationSettingData.c b/src/Virt_VSMigrationSettingData.c >> index a6707bd..eb545f1 100644 >> --- a/src/Virt_VSMigrationSettingData.c >> +++ b/src/Virt_VSMigrationSettingData.c >> @@ -79,7 +79,8 @@ CMPIStatus get_migration_sd(const CMPIObjectPath *ref, >> inst = get_typed_instance(broker, >> CLASSNAME(ref), >> "VirtualSystemMigrationSettingData", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c >> index 499b157..975623b 100644 >> --- a/src/Virt_VSSD.c >> +++ b/src/Virt_VSSD.c >> @@ -285,7 +285,8 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemSettingData", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + false); >> >> if (inst == NULL) { >> cu_statusf(broker, s, >> diff --git a/src/Virt_VirtualSystemManagementCapabilities.c b/src/Virt_VirtualSystemManagementCapabilities.c >> index 020ce8a..51738ee 100644 >> --- a/src/Virt_VirtualSystemManagementCapabilities.c >> +++ b/src/Virt_VirtualSystemManagementCapabilities.c >> @@ -129,7 +129,8 @@ CMPIStatus get_vsm_cap(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemManagementCapabilities", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c >> index 10adf8b..96c8a03 100644 >> --- a/src/Virt_VirtualSystemManagementService.c >> +++ b/src/Virt_VirtualSystemManagementService.c >> @@ -1928,7 +1928,8 @@ static CMPIStatus raise_rasd_indication(const CMPIContext *context, >> ind = get_typed_instance(_BROKER, >> CLASSNAME(ref), >> base_type, >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (ind == NULL) { >> CU_DEBUG("Failed to get indication instance"); >> s.rc = CMPI_RC_ERR_FAILED; >> @@ -3293,7 +3294,8 @@ CMPIStatus get_vsms(const CMPIObjectPath *reference, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemManagementService", >> - NAMESPACE(reference)); >> + NAMESPACE(reference), >> + true); >> >> if (inst == NULL) { >> CU_DEBUG("Failed to get typed instance"); >> diff --git a/src/Virt_VirtualSystemSnapshotService.c b/src/Virt_VirtualSystemSnapshotService.c >> index aae628f..8c0889d 100644 >> --- a/src/Virt_VirtualSystemSnapshotService.c >> +++ b/src/Virt_VirtualSystemSnapshotService.c >> @@ -681,7 +681,8 @@ CMPIStatus get_vsss(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemSnapshotService", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + true); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> diff --git a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c >> index 69c8e97..04a9c7a 100644 >> --- a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c >> +++ b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c >> @@ -117,7 +117,8 @@ CMPIStatus get_vss_cap(const CMPIBroker *broker, >> inst = get_typed_instance(broker, >> pfx_from_conn(conn), >> "VirtualSystemSnapshotServiceCapabilities", >> - NAMESPACE(ref)); >> + NAMESPACE(ref), >> + false); >> if (inst == NULL) { >> cu_statusf(broker, &s, >> CMPI_RC_ERR_FAILED, >> > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:12:20 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:12:20 +0800 Subject: [Libvirt-cim] [PATCH V5 02/15] VSSD: add missing property IsFullVirt in schema In-Reply-To: <514B3BBD.3030102@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> <514B3BBD.3030102@redhat.com> Message-ID: <514EA754.7020104@linux.vnet.ibm.com> ? 2013-3-22 0:56, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> This property is used but not defined, so add it. >> >> Signed-off-by: Wenchao Xia >> --- >> schema/Virt_VSSD.mof | 3 +++ >> 1 files changed, 3 insertions(+), 0 deletions(-) >> >> diff --git a/schema/Virt_VSSD.mof b/schema/Virt_VSSD.mof >> index baf4ac2..b960450 100644 >> --- a/schema/Virt_VSSD.mof >> +++ b/schema/Virt_VSSD.mof >> @@ -27,4 +27,7 @@ class Virt_VirtualSystemSettingData : CIM_VirtualSystemSettingData >> [Description ("Flag to determine whether this guest has to be autostarted on reboot")] >> uint16 AutoStart; >> >> + [Description ("Flag to determine whether this guest is a full virtualization")] >> + boolean IsFullVirt; >> + >> }; >> > > Follow up note... Is this "isFullVirt" or "IsFullVirt" - I see it used > both ways, so I'm confused. > It should be later one, in code it must be miss spelled. > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:13:51 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:13:51 +0800 Subject: [Libvirt-cim] [PATCH V5 03/15] SDC: use property BootDevices instead of BootDevice In-Reply-To: <514B3CB1.9060209@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-4-git-send-email-xiawenc@linux.vnet.ibm.com> <514B3CB1.9060209@redhat.com> Message-ID: <514EA7AF.1050405@linux.vnet.ibm.com> ? 2013-3-22 1:00, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> The property registerted is BootDevices, so correct it. >> >> Signed-off-by: Wenchao Xia >> --- >> src/Virt_SettingsDefineCapabilities.c | 4 ++-- >> 1 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c >> index 5091205..1e7a778 100644 >> --- a/src/Virt_SettingsDefineCapabilities.c >> +++ b/src/Virt_SettingsDefineCapabilities.c >> @@ -172,7 +172,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, >> if (inst == NULL) >> goto error; >> >> - CMSetProperty(inst, "BootDevice", >> + CMSetProperty(inst, "BootDevices", >> (CMPIValue *)"hda", CMPI_chars); >> >> CMSetProperty(inst, "isFullVirt", >> @@ -211,7 +211,7 @@ static CMPIStatus _kvm_vsmc_to_vssd(virConnectPtr conn, >> CMSetProperty(inst, "VirtualSystemIdentifier", >> (CMPIValue *)"KVM_guest", CMPI_chars); >> >> - CMSetProperty(inst, "BootDevice", >> + CMSetProperty(inst, "BootDevices", >> (CMPIValue *)"hda", CMPI_chars); >> >> inst_list_add(list, inst); >> > > ACK > > Note: In this module, the "isFullVirt" is used - hence my follow-up > question to patch 2/15. > It should be a misspelling, I'll fix it also in next version. > I also found two instances where "BootDevice" is used in CU_DEBUG > messages (not that it matters, but it's a consistency thing for me). > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 07:16:43 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 15:16:43 +0800 Subject: [Libvirt-cim] [PATCH V5 07/15] DevicePool, fix debug print crash In-Reply-To: <514B40FC.8040906@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-8-git-send-email-xiawenc@linux.vnet.ibm.com> <514B40FC.8040906@redhat.com> Message-ID: <514EA85B.7090301@linux.vnet.ibm.com> ? 2013-3-22 1:18, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> Signed-off-by: Wenchao Xia >> Reviewed-by: John Ferlan >> --- >> src/Virt_DevicePool.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> > > ACK > > Although "theoretically speaking" this could/should be combined with > 5/15 and 9/15 since they are similar (eg, via git rebase -i and squash 3 > into 1 patch). > > John > OK, will squash them. > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 08:10:14 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 16:10:14 +0800 Subject: [Libvirt-cim] [PATCH V5 02/15] VSSD: add missing property IsFullVirt in schema In-Reply-To: <514B3A8C.2010307@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-3-git-send-email-xiawenc@linux.vnet.ibm.com> <514B3A8C.2010307@redhat.com> Message-ID: <514EB4E6.9070101@linux.vnet.ibm.com> ? 2013-3-22 0:51, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> This property is used but not defined, so add it. >> >> Signed-off-by: Wenchao Xia >> --- >> schema/Virt_VSSD.mof | 3 +++ >> 1 files changed, 3 insertions(+), 0 deletions(-) >> >> diff --git a/schema/Virt_VSSD.mof b/schema/Virt_VSSD.mof >> index baf4ac2..b960450 100644 >> --- a/schema/Virt_VSSD.mof >> +++ b/schema/Virt_VSSD.mof >> @@ -27,4 +27,7 @@ class Virt_VirtualSystemSettingData : CIM_VirtualSystemSettingData >> [Description ("Flag to determine whether this guest has to be autostarted on reboot")] >> uint16 AutoStart; >> >> + [Description ("Flag to determine whether this guest is a full virtualization")] >> + boolean IsFullVirt; >> + >> }; >> > > This property is found in 'VSSD.mof': > > class Xen_VirtualSystemSettingData : Virt_VirtualSystemSettingData > { > > [Description ("Flag to determine whether this guest is > fully-virtualized")] > boolean IsFullVirt; > ... > > > Since that is a child of the one you are placing the the property into, > shouldn't it be removed from the child? > I found this property is used for KVM/Xen, no LXC, so I guess adding it in KVM_VSSD in VSSD.mof is a better way. I'll change it in next version. Note there is a bug like code in vssd_to_domain(), which treat this property as a condition before entering child class property retrieving. It is why I added it in parent class before. > Also I think the Description in VSSD.mof is better than the one in > Virt_VSSD.mof. > > > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 08:31:25 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 16:31:25 +0800 Subject: [Libvirt-cim] [PATCH V5 08/15] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <514B4B63.8090207@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-9-git-send-email-xiawenc@linux.vnet.ibm.com> <514B4B63.8090207@redhat.com> Message-ID: <514EB9DD.80009@linux.vnet.ibm.com> ? 2013-3-22 2:03, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> Original implemetion may return pools with NULL name if >> some pool disappear between two libvirt pool API call. And >> originally it return the number of pools and negative value >> when error happens, but caller of this function consider >> number = 0 as error. >> As a fix, this patch changed the function prototype, it do >> not return the pool number anymore, it returns 0 on success >> and negative on fail now. Code for checking the risk of returning >> pools with NULL name is also added. >> Another small fix is, return false in get_disk_parent() when >> strdup fail. >> >> Signed-off-by: Wenchao Xia >> --- >> src/Virt_DevicePool.c | 176 +++++++++++++++++++++++++++++++++---------------- >> 1 files changed, 120 insertions(+), 56 deletions(-) >> >> diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c >> index 08677e2..185e3cc 100644 >> --- a/src/Virt_DevicePool.c >> +++ b/src/Virt_DevicePool.c >> @@ -51,6 +51,22 @@ struct tmp_disk_pool { >> bool primordial; >> }; >> >> +static void free_diskpool(struct tmp_disk_pool *pools, int count) >> +{ >> + int i; >> + >> + if (pools == NULL) { >> + return; >> + } >> + >> + for (i = 0; i < count; i++) { >> + free(pools[i].tag); >> + free(pools[i].path); >> + } >> + >> + free(pools); >> +} >> + >> /* >> * Right now, detect support and use it, if available. >> * Later, this can be a configure option if needed >> @@ -78,6 +94,10 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, >> } >> >> pools[count].tag = strdup("0"); >> + if (pools[count].tag == NULL) { >> + count++; >> + goto free; >> + } >> pools[count].path = NULL; >> pools[count].primordial = true; >> count++; >> @@ -85,12 +105,17 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, >> *_count = count; >> *_pools = pools; >> ret = true; >> + goto out; >> >> + free: >> + free_diskpool(pools, count); >> + /* old pool is invalid, update it */ >> + *_count = 0; >> + *_pools = NULL; >> out: >> return ret; >> } >> >> - >> #if VIR_USE_LIBVIRT_STORAGE >> int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) >> { >> @@ -117,52 +142,82 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) >> return ret; >> } >> >> +/* This function returns 0 on sucess, negative on fail. */ >> static int get_diskpool_config(virConnectPtr conn, >> - struct tmp_disk_pool **_pools) >> + struct tmp_disk_pool **_pools, >> + int *_count) >> { >> - int count = 0; >> + int count = 0, realcount = 0; >> int i; >> char ** names = NULL; >> struct tmp_disk_pool *pools = NULL; >> + int ret = 0; >> + bool bret; >> >> count = virConnectNumOfStoragePools(conn); >> - if (count <= 0) >> + if (count < 0) { >> + ret = count; >> goto out; >> + } else if (count == 0) { >> + goto set_parent; >> + } >> >> names = calloc(count, sizeof(char *)); >> if (names == NULL) { >> CU_DEBUG("Failed to alloc space for %i pool names", count); >> - count = 0; >> + ret = -1; >> goto out; >> } >> >> - if (virConnectListStoragePools(conn, names, count) == -1) { >> - CU_DEBUG("Failed to get storage pools"); >> - count = 0; >> - goto out; >> + realcount = virConnectListStoragePools(conn, names, count); >> + if (realcount < 0) { >> + CU_DEBUG("Failed to get storage pools, return %d.", realcount); >> + ret = realcount; >> + goto free_names; >> + } >> + if (realcount == 0) { >> + CU_DEBUG("Zero pools got, but prelist is %d.", count); >> + goto set_parent; >> } >> >> - pools = calloc(count, sizeof(*pools)); >> + pools = calloc(realcount, sizeof(*pools)); >> if (pools == NULL) { >> - CU_DEBUG("Failed to alloc space for %i pool structs", count); >> - goto out; >> + CU_DEBUG("Failed to alloc space for %i pool structs", >> + realcount); >> + ret = -2; >> + goto free_names; >> } >> >> - for (i = 0; i < count; i++) { >> - pools[i].tag = strdup(names[i]); >> + for (i = 0; i < realcount; i++) { >> + pools[i].tag = names[i]; >> + names[i] = NULL; >> pools[i].primordial = false; >> } >> >> - out: >> - for (i = 0; i < count; i++) >> - free(names[i]); >> - free(names); >> - >> - get_disk_parent(&pools, &count); >> + set_parent: >> + bret = get_disk_parent(&pools, &realcount); >> + if (bret != true) { >> + CU_DEBUG("Failed in adding parentpool."); >> + ret = -4; >> + goto free_pools; > > If here, we will have already called free_diskpools() which is probably > a good thing since at this point pools and realcount will be inaccurate. > So just jump to free_names instead (also leave a reason why!!!) > OK, I'll add comment in get_disk_parent() that pools will be freed on fail. >> + } >> >> + /* succeed */ >> *_pools = pools; >> + *_count = realcount; >> + goto free_names; >> + >> + free_pools: >> + free_diskpool(pools, realcount); >> >> - return count; >> + free_names: >> + for (i = 0; i < count; i++) { >> + free(names[i]); >> + } >> + free(names); >> + >> + out: >> + return ret; >> } >> >> static bool diskpool_set_capacity(virConnectPtr conn, >> @@ -294,42 +349,59 @@ static int parse_diskpool_line(struct tmp_disk_pool *pool, >> return (ret == 2); >> } >> >> +/* return 0 on sucess, negative on fail. */ >> static int get_diskpool_config(virConnectPtr conn, >> - struct tmp_disk_pool **_pools) >> + struct tmp_disk_pool **_pools, >> + int *_count) >> { >> const char *path = DISK_POOL_CONFIG; >> FILE *config; >> char *line = NULL; >> size_t len = 0; >> - int count = 0; >> - struct tmp_disk_pool *pools = NULL; >> + int count = 0, ret = 0; >> + struct tmp_disk_pool *pools = NULL, *new_pools = NULL; >> + bool bret; >> >> config = fopen(path, "r"); >> if (config == NULL) { >> CU_DEBUG("Failed to open %s: %m", path); >> - return 0; >> + ret = -1; >> + goto out; >> } >> >> while (getline(&line, &len, config) > 0) { >> - pools = realloc(pools, >> - (count + 1) * (sizeof(*pools))); >> - if (pools == NULL) { >> + new_pools = realloc(pools, >> + (count + 1) * (sizeof(*pools))); >> + if (new_pools == NULL) { >> CU_DEBUG("Failed to alloc new pool"); >> - goto out; >> + ret = -2; >> + goto free_pools; >> } >> + pools = new_pools; > > Once the realloc is successful, then pools will have count+1 elems. If > for some reason the next line files, then I don't think we need to > realloc again in this loop. Makes the logic a bit more messy though. > I'll re-code this old bug like section. >> >> if (parse_diskpool_line(&pools[count], line)) >> count++; > > Since you have a free(line) below, won't you need a free(line) and line > = NULL each time through this loop (the line = NULL is so that the > free(line) below doesn't double deallocate). > >> } >> >> + bret = get_disk_parent(&pools, &count); >> + if (bret != true) { >> + CU_DEBUG("Failed in adding parentpool."); >> + ret = -3; >> + goto free_pools; > > If here, we will have already called free_diskpools() which is probably > a good thing since at this point pools and count will be inaccurate. So > just jump to clean instead (also leave a reason why!!!) > >> + } >> >> - get_disk_parent(&pools, &count); >> - out: >> - free(line); >> + /* succeed */ >> *_pools = pools; >> - fclose(config); >> + *_count = count; >> + goto clean; >> >> - return count; >> + free_pools: >> + free_diskpool(pools, count); >> + clean: >> + free(line); > > Seeing this free(line) made me realize the issue above... > > The rest is fine. > > John > >> + fclose(config); >> + out: >> + return ret; >> } >> >> static bool diskpool_set_capacity(virConnectPtr conn, >> @@ -367,39 +439,23 @@ static bool diskpool_set_capacity(virConnectPtr conn, >> } >> >> static bool _diskpool_is_member(virConnectPtr conn, >> - const struct disk_pool *pool, >> + const struct tmp_disk_pool *pool, >> const char *file) >> { >> return STARTS_WITH(file, pool->path); >> } >> #endif >> >> -static void free_diskpool(struct tmp_disk_pool *pools, int count) >> -{ >> - int i; >> - >> - if (pools == NULL) >> - return; >> - >> - for (i = 0; i < count; i++) { >> - free(pools[i].tag); >> - free(pools[i].path); >> - } >> - >> - free(pools); >> -} >> - >> static char *_diskpool_member_of(virConnectPtr conn, >> const char *file) >> { >> struct tmp_disk_pool *pools = NULL; >> int count; >> - int i; >> + int i, ret; >> char *pool = NULL; >> >> - count = get_diskpool_config(conn, &pools); >> - if (count == 0) { >> - free(pools); >> + ret = get_diskpool_config(conn, &pools, &count); >> + if (ret < 0) { >> return NULL; >> } >> >> @@ -1088,9 +1144,17 @@ static CMPIStatus diskpool_instance(virConnectPtr conn, >> CMPIStatus s = {CMPI_RC_OK, NULL}; >> struct tmp_disk_pool *pools = NULL; >> int count = 0; >> - int i; >> + int i, ret; >> >> - count = get_diskpool_config(conn, &pools); >> + ret = get_diskpool_config(conn, &pools, &count); >> + if (ret < 0) { >> + CU_DEBUG("Failed to get diskpool config, return is %d.", ret); >> + cu_statusf(broker, &s, >> + CMPI_RC_ERR_FAILED, >> + "Failed to get diskpool config, return is %d.", >> + ret); >> + return s; >> + } >> if ((id == NULL) && (count == 0)) { >> CU_DEBUG("No defined DiskPools"); >> free(pools); >> > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 08:35:15 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 16:35:15 +0800 Subject: [Libvirt-cim] [PATCH V5 12/15] CSI: Move native CSI code together In-Reply-To: <514B526C.8020309@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-13-git-send-email-xiawenc@linux.vnet.ibm.com> <514B526C.8020309@redhat.com> Message-ID: <514EBAC3.8080805@linux.vnet.ibm.com> ? 2013-3-22 2:33, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> This is a pure code move patch. Now codes using libvirt event >> or native event, are moved into one macro protection, which make >> code easy to read, and in futher they can be moved into new file >> as CSI-libvirt.c. >> This patch also fix code style problem in moved code. >> >> Signed-off-by: Wenchao Xia >> --- >> src/Virt_ComputerSystemIndication.c | 851 ++++++++++++++++++----------------- >> 1 files changed, 429 insertions(+), 422 deletions(-) >> > > ACK - lots of trust here as it's not fun looking around for code > movement :-) > > Personally, I prefer interlaced code as it's somewhat easier to maintain > long term. Now there's lots duplicated (eg, cut-n-paste) code that's > can be the source of future "issues" when one stream is changed but not > the other. > Yes, that would be a problem. Duplicated code is not many now(activate/deactite, etc), we can adjust them later. > John > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 08:39:41 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 16:39:41 +0800 Subject: [Libvirt-cim] [PATCH V5 13/15] VSSD: report success if not all VS fail in enum In-Reply-To: <514B54DF.4020001@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-14-git-send-email-xiawenc@linux.vnet.ibm.com> <514B54DF.4020001@redhat.com> Message-ID: <514EBBCD.3020606@linux.vnet.ibm.com> ? 2013-3-22 2:43, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> Original code 'continue' in the 'for' in return_enum_vssd() when >> one VSDS fail in retrieving, but forgot to set s to normal. This patch >> fix this case. >> Also many debug message is added to log the error if met. >> >> Signed-off-by: Wenchao Xia >> --- >> src/Virt_VSSD.c | 43 +++++++++++++++++++++++++++++++++++++++++-- >> 1 files changed, 41 insertions(+), 2 deletions(-) >> >> diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c >> index 975623b..3d2de26 100644 >> --- a/src/Virt_VSSD.c >> +++ b/src/Virt_VSSD.c >> @@ -181,8 +181,10 @@ static int instance_from_dom(const CMPIBroker *broker, >> struct domain *dominfo = NULL; >> >> ret = get_dominfo(dom, &dominfo); >> - if (!ret) >> + if (!ret) { >> + CU_DEBUG("Failed in get_dominfo()."); >> goto out; >> + } >> >> op = CMGetObjectPath(inst, NULL); >> pfx = class_prefix_name(CLASSNAME(op)); >> @@ -245,6 +247,7 @@ static int instance_from_dom(const CMPIBroker *broker, >> (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU)) { >> s = _set_fv_prop(broker, dominfo, inst); >> if (s.rc != CMPI_RC_OK) { >> + CU_DEBUG("Failed to set full virtual props."); >> ret = 0; >> goto out; >> } >> @@ -259,6 +262,7 @@ static int instance_from_dom(const CMPIBroker *broker, >> dominfo->type); >> >> if (asprintf(&vsid, "%s:%s", pfx, dominfo->name) == -1) { >> + CU_DEBUG("Failed in asprintf()."); >> ret = 0; >> goto out; >> } >> @@ -328,14 +332,34 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, >> } else if (count == 0) >> goto out; >> >> + int fail_count = 0; > > Put this with the other decls. > OK. >> for (i = 0; i < count; i++) { >> CMPIInstance *inst = NULL; >> >> inst = _get_vssd(_BROKER, reference, conn, list[i], &s); >> >> virDomainFree(list[i]); >> - if (inst == NULL) >> + if (inst == NULL) { >> + /* log the error */ >> + const char *dom_name = virDomainGetName(list[i]); > > You'll need to do this before you virDomainFree(list[i]) or reformat the > code a bit to do the virDomainFree() twice. Once before the continue > below and once if inst != NULL > What a stupid error I have, I should be more careful about this. My bad, thank u for the mention! > Or do the virDomainFree() below in a for loop before free(list). > > The rest seems fine. > > John > >> + if (s.msg) { >> + CU_DEBUG("Failed to get VSSD instance from " >> + "domain [%s], status msg [%s].", >> + dom_name, CMGetCharPtr(s.msg)); >> + } else { >> + CU_DEBUG("Failed to get VSSD instance from " >> + "domain [%s].", >> + dom_name); >> + } >> + /* restore s until last one */ >> + if (i < count - 1) { >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_OK, >> + "NULL"); >> + } >> + fail_count++; >> continue; >> + } >> >> if (names_only) >> cu_return_instance_name(results, inst); >> @@ -343,6 +367,21 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, >> CMReturnInstance(results, inst); >> } >> >> + /* check if some VS fail */ >> + if (fail_count > 0) { >> + CU_DEBUG("Failed to get %d VSSD in enum, total is %d.", >> + fail_count, count); >> + if (fail_count < count) { >> + /* consider it succeed, some VSSD will be returned */ >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_OK, >> + "Got %d/%d VSSD, " >> + "some VS may changed during enum", >> + count - fail_count, count); >> + } >> + } >> + >> + >> out: >> free(list); >> virConnectClose(conn); >> > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 08:57:55 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 16:57:55 +0800 Subject: [Libvirt-cim] [PATCH V5 15/15] migration: allow ssh based migration with non root's key file In-Reply-To: <514C5B22.9020401@redhat.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1363837158-11509-16-git-send-email-xiawenc@linux.vnet.ibm.com> <514C5B22.9020401@redhat.com> Message-ID: <514EC013.2090507@linux.vnet.ibm.com> ? 2013-3-22 21:22, John Ferlan ??: > On 03/20/2013 11:39 PM, Wenchao Xia wrote: >> This patch allow libvirt-cim to use non-root's ssh key in migration >> to avoid exposing root's ssh login on server. In some case server are >> forbidden to expose or provide any root ssh login, and still use ssh >> encryption between two migration nodes with key of special account >> created for virtual machine management. >> >> When it is enabled in config file: >> 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key >> to be copied. It will be copied to [migrate_ssh_temp_key]. >> 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, >> use bool property [MigrationWithoutRootKey], to tell whether to use the key >> as [migrate_ssh_temp_key]. >> 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be >> deleted. >> >> Details: >> libvirt-cim would run shell command "cp -f [SSH_Key_Src] >> [migrate_ssh_temp_key]", then use [migrate_ssh_temp_key] to generate uri >> suffix for remote connection to migration destination. >> >> Signed-off-by: Wenchao Xia >> --- >> libvirt-cim.conf | 19 +++ >> libxkutil/misc_util.c | 9 ++ >> libxkutil/misc_util.h | 3 + >> src/Virt_VSMigrationService.c | 263 ++++++++++++++++++++++++++++++++++++++++- >> 4 files changed, 289 insertions(+), 5 deletions(-) >> >> diff --git a/libvirt-cim.conf b/libvirt-cim.conf >> index d3cb2c3..37d7b0f 100644 >> --- a/libvirt-cim.conf >> +++ b/libvirt-cim.conf >> @@ -11,3 +11,22 @@ >> # Default value: false >> # >> # readonly = false; >> + >> +# migrate_ssh_temp_key (string) >> +# Defines a temp key file which would be used as ssh key in ssh migration, >> +# Only when it is set, following methods in VirtualSystemMigrationService >> +# could be used: >> +# 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key >> +# to be copied. It will be copied to [migrate_ssh_temp_key]. >> +# 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, >> +# use bool property [MigrationWithoutRootKey], to tell whether to use the key >> +# as [migrate_ssh_temp_key]. >> +# 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be >> +# deleted. >> +# Note: migrate_ssh_temp_key must be set in a directory completely owned by >> +# root from bottom to top, such as /root/A, or /tmp/A. >> +# >> +# Possible values: {any path plus filename on host} >> +# Default value: NULL, that is not set. >> +# >> +# migrate_ssh_temp_key = "/root/vm_migrate_tmp_id_rsa"; >> diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c >> index 820b42d..00eb4b1 100644 >> --- a/libxkutil/misc_util.c >> +++ b/libxkutil/misc_util.c >> @@ -227,6 +227,15 @@ static int is_read_only(void) >> return prop.value_bool; >> } >> >> +const char *get_mig_ssh_tmp_key(void) >> +{ >> + static LibvirtcimConfigProperty prop = { >> + "migrate_ssh_temp_key", CONFIG_STRING, {0}, 0}; >> + >> + libvirt_cim_config_get(&prop); >> + return prop.value_string; >> +} >> + >> virConnectPtr connect_by_classname(const CMPIBroker *broker, >> const char *classname, >> CMPIStatus *s) >> diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h >> index 90fb2da..0f52290 100644 >> --- a/libxkutil/misc_util.h >> +++ b/libxkutil/misc_util.h >> @@ -152,6 +152,9 @@ int virt_set_status(const CMPIBroker *broker, >> >> #define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL)) >> >> +/* get libvirt-cim config */ >> +const char *get_mig_ssh_tmp_key(void); >> + >> /* >> * Local Variables: >> * mode: C >> diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c >> index 1f6659d..d03e1a0 100644 >> --- a/src/Virt_VSMigrationService.c >> +++ b/src/Virt_VSMigrationService.c >> @@ -150,6 +150,7 @@ static CMPIStatus get_migration_uri(CMPIInstance *msd, >> >> static char *dest_uri(const char *cn, >> const char *dest, >> + const char *dest_params, >> uint16_t transport) >> { >> const char *prefix; >> @@ -157,6 +158,7 @@ static char *dest_uri(const char *cn, >> const char *param = ""; >> char *uri = NULL; >> int rc; >> + int param_labeled = 0; >> >> if (STARTS_WITH(cn, "Xen")) >> prefix = "xen"; >> @@ -197,16 +199,54 @@ static char *dest_uri(const char *cn, >> goto out; >> } >> >> - if (!STREQC(param, "")) >> + if (!STREQC(param, "")) { >> rc = asprintf(&uri, "%s/%s", uri, param); >> + param_labeled = 1; >> + } >> >> - if (rc == -1) >> + if (rc == -1) { >> uri = NULL; >> + goto out; >> + } >> >> + if (dest_params) { >> + if (param_labeled == 0) { >> + rc = asprintf(&uri, "%s?%s", uri, dest_params); >> + } else { >> + /* ? is already added */ >> + rc = asprintf(&uri, "%s%s", uri, dest_params); >> + } >> + if (rc == -1) { >> + uri = NULL; >> + goto out; >> + } >> + } >> out: >> return uri; >> } >> >> +/* Todo: move it to libcmpiutil */ >> +static CMPIrc cu_get_bool_arg_my(const CMPIArgs *args, >> + const char *name, >> + bool *target) >> +{ >> + CMPIData argdata; >> + CMPIStatus s; >> + >> + argdata = CMGetArg(args, name, &s); >> + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) { >> + return CMPI_RC_ERR_INVALID_PARAMETER; >> + } >> + >> + if (argdata.type != CMPI_boolean) { >> + return CMPI_RC_ERR_TYPE_MISMATCH; >> + } >> + >> + *target = (bool)argdata.value.boolean; >> + >> + return CMPI_RC_OK; >> +} >> + > > I don't believe the above function is necessary - there is already a > cu_get_bool_prop(). > A bit different, this function use const CMPIArgs *args, that one use *inst. > >> static CMPIStatus get_msd_values(const CMPIObjectPath *ref, >> const char *destination, >> const CMPIArgs *argsin, >> @@ -217,6 +257,13 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, >> CMPIInstance *msd; >> uint16_t uri_type; >> char *uri = NULL; >> + bool no_root_ssh_key = false; > > s/no_root_ssh_key/use_non_root_ssh_key/ > > Just a consideration, not a requirement. When I first saw the variable > in use I had to think about it. "no_root_ssh_key" just had a different > meaning in my mind. > OK. >> + char *dest_params = NULL; >> + int ret; >> + >> + cu_get_bool_arg_my(argsin, >> + "MigrationWithoutRootKey", >> + &no_root_ssh_key); > > Why not use the existing cu_get_bool_prop(). You don't even check the > return value here, so what's the use of your local routine? > can't use cu_get_bool_prop(), parameter is different. it have a default value, so no need to check whether fail. > >> >> s = get_msd(ref, argsin, &msd); >> if (s.rc != CMPI_RC_OK) >> @@ -230,7 +277,27 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, >> if (s.rc != CMPI_RC_OK) >> goto out; >> >> - uri = dest_uri(CLASSNAME(ref), destination, uri_type); >> + if (no_root_ssh_key) { >> + const char *tmp_keyfile = get_mig_ssh_tmp_key(); >> + if (!tmp_keyfile) { >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_ERR_FAILED, >> + "Migration with special ssh key " >> + "is not enabled in config file."); >> + CU_DEBUG("Migration with special ssh key " >> + "is not enabled in config file."); >> + goto out; >> + } >> + CU_DEBUG("Trying migrate with specified ssh key file [%s].", >> + tmp_keyfile); >> + ret = asprintf(&dest_params, "keyfile=%s", tmp_keyfile); >> + if (ret < 0) { >> + CU_DEBUG("Failed in generating param string."); >> + goto out; >> + } >> + } >> + >> + uri = dest_uri(CLASSNAME(ref), destination, dest_params, uri_type); >> if (uri == NULL) { >> cu_statusf(_BROKER, &s, >> CMPI_RC_ERR_FAILED, >> @@ -238,6 +305,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, >> goto out; >> } >> >> + CU_DEBUG("Migrate tring to connect remote host with uri %s.", uri); >> *conn = virConnectOpen(uri); >> if (*conn == NULL) { >> CU_DEBUG("Failed to connect to remote host (%s)", uri); >> @@ -249,7 +317,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, >> >> out: >> free(uri); >> - >> + free(dest_params); >> return s; >> } >> >> @@ -1538,7 +1606,7 @@ static CMPIStatus migrate_vs_host(CMPIMethodMI *self, >> const char *dhost = NULL; >> CMPIObjectPath *system; >> const char *name = NULL; >> - >> + >> cu_get_str_arg(argsin, "DestinationHost", &dhost); >> cu_get_ref_arg(argsin, "ComputerSystem", &system); >> >> @@ -1604,11 +1672,178 @@ static CMPIStatus migrate_vs_system(CMPIMethodMI *self, >> return migrate_do(ref, ctx, name, dname, argsin, results, argsout); >> } >> >> +/* return 0 on success */ >> +static int pipe_exec(const char *cmd) >> +{ >> + FILE *stream = NULL; >> + int ret = 0; >> + char buf[256]; >> + >> + CU_DEBUG("executing system cmd [%s].", cmd); >> + /* Todo: We need a better popen, currently stdout have been closed >> + and SIGCHILD is handled by tog-pegasus, so fgets always got NULL >> + making error detection not possible. */ >> + stream = popen(cmd, "r"); >> + if (stream == NULL) { >> + CU_DEBUG("Failed to open pipe to run the command."); >> + ret = -1; >> + goto out; >> + } >> + usleep(10000); >> + >> + buf[255] = 0; >> + while (fgets(buf, sizeof(buf), stream) != NULL) { >> + CU_DEBUG("Exception got: [%s].", buf); >> + ret = -2; >> + goto out; >> + } >> + >> + out: >> + if (stream != NULL) { >> + pclose(stream); >> + } >> + return ret; >> +} >> + >> +/* >> + * libvirt require private key specified to be placed in a directory owned by >> + * root, because libvirt-cim now runs as root. So here the key would be copied. >> + * In this way libvirt-cim could borrow a non-root ssh private key, instead of >> + * using root's private key, avoid security risk. >> + */ >> +static int ssh_key_copy(const char *src, const char *dest) >> +{ >> + char *cmd = NULL; >> + int ret = 0; >> + struct stat sb; >> + >> + /* try delete it */ >> + unlink(dest); >> + ret = stat(dest, &sb); >> + if (ret == 0) { >> + CU_DEBUG("Can not delete [%s] before copy, " >> + "maybe someone is using it.", >> + dest); >> + /* not a fatal fault */ > > Maybe not fatal, but what makes you believe a subsequent copy will OK, I'll make it fail here as a strict check. > succeed? Is there a way to keep track of this being "in use" by some > other thread that could delete it? It's almost like there needs to be a > reference count. User can guarentee that no one is using it since all non-root-migrate is started by him and he knows if they have complete or fail. > > Is it possible for two threads to be using it at the same time? Just Yes, possible, and it is normal they share the key. > thinking out loud and trying to consider the negative consequences. In a > former job we allowed 1 migration at a time and I'm not aware of the > libvirt "restrictions" (yet). > > IOW, Before we unlink it, if it's already there what does that mean? > The user just forgot delete it last time, I think it can be deleted and recopy, since there is config file and user knows it is only used by libvirt-cim. >> + } >> + >> + ret = asprintf(&cmd, "cp -f %s %s", src, dest); >> + if (ret < 0) { >> + CU_DEBUG("Failed in combination for shell command."); >> + goto out; >> + } >> + >> + ret = pipe_exec(cmd); >> + if (ret < 0) { >> + CU_DEBUG("Error in executing command [%s]"); >> + goto out; >> + } >> + >> + ret = stat(dest, &sb); >> + if (ret < 0) { >> + CU_DEBUG("Can not find file [%s] after copy.", dest); >> + } >> + out: >> + free(cmd); >> + return ret; >> +} >> + >> +static CMPIStatus migrate_sshkey_copy(CMPIMethodMI *self, >> + const CMPIContext *ctx, >> + const CMPIResult *results, >> + const CMPIObjectPath *ref, >> + const CMPIArgs *argsin, >> + CMPIArgs *argsout) >> +{ >> + CMPIStatus s = {CMPI_RC_OK, NULL}; >> + const char *ssh_key_src = NULL; >> + int ret; >> + >> + const char *tmp_keyfile = get_mig_ssh_tmp_key(); >> + if (!tmp_keyfile) { >> + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, >> + "Migration with special ssh key " >> + "is not enabled in config file."); >> + CU_DEBUG("Migration with special ssh key " >> + "is not enabled in config file."); >> + goto out; >> + } >> + >> + cu_get_str_arg(argsin, "SSH_Key_Src", &ssh_key_src); >> + if (!ssh_key_src) { >> + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, >> + "Failed to get property 'SSH_Key_Src'."); >> + CU_DEBUG("Failed to get property 'SSH_Key_Src'."); >> + goto out; >> + } >> + >> + ret = ssh_key_copy(ssh_key_src, tmp_keyfile); >> + if (ret < 0) { >> + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, >> + "Got error in copying ssh key from [%s] to [%s].", >> + ssh_key_src, tmp_keyfile); >> + CU_DEBUG("Got error in copying ssh key from [%s] to [%s].", >> + ssh_key_src, tmp_keyfile); >> + } >> + >> + out: >> + METHOD_RETURN(results, s.rc); >> + return s; >> +} >> + >> +static CMPIStatus migrate_sshkey_delete(CMPIMethodMI *self, >> + const CMPIContext *ctx, >> + const CMPIResult *results, >> + const CMPIObjectPath *ref, >> + const CMPIArgs *argsin, >> + CMPIArgs *argsout) >> +{ >> + CMPIStatus s = {CMPI_RC_OK, NULL}; >> + int ret; >> + struct stat sb; > > Should we check for "MigrationWithoutRootKey" here too? Is it possible No, this parameter is not needed, it just delete the key, will fail if config is not set. > for one thread to request migration without root key while another wants > root key? Does the caller really need to know/care? Yes, it is allowed. This patch just added an option. It looks to be an > object setting, so we probably do care. > >> + >> + const char *tmp_keyfile = get_mig_ssh_tmp_key(); >> + if (!tmp_keyfile) { >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_ERR_FAILED, >> + "Migration with special ssh key " >> + "is not enabled in config file."); >> + CU_DEBUG("Migration with special ssh key " >> + "is not enabled in config file."); >> + goto out; >> + } >> + >> + ret = stat(tmp_keyfile, &sb); >> + if (ret == 0) { >> + /* need delete */ >> + ret = unlink(tmp_keyfile); >> + if (ret < 0) { >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_ERR_FAILED, >> + "Failed to delete [%s].", >> + tmp_keyfile); >> + CU_DEBUG("Failed to delete [%s].", tmp_keyfile); >> + } >> + } else { >> + /* not exist */ >> + cu_statusf(_BROKER, &s, >> + CMPI_RC_ERR_FAILED, >> + "Can not find file [%s] before delete.", >> + tmp_keyfile); >> + CU_DEBUG("Can not find file [%s] before delete.", tmp_keyfile); > > Which perhaps means our other code above did the unlink() for us in > another thread? Do you want an error here? It is possible user called the method twice, so report the error here. > > John > >> + } >> + >> + out: >> + METHOD_RETURN(results, s.rc); >> + return s; >> +}; >> + >> static struct method_handler vsimth = { >> .name = "CheckVirtualSystemIsMigratableToHost", >> .handler = vs_migratable_host, >> .args = {{"ComputerSystem", CMPI_ref, false}, >> {"DestinationHost", CMPI_string, false}, >> + {"MigrationWithoutRootKey", CMPI_boolean, true}, >> {"MigrationSettingData", CMPI_instance, true}, >> {"NewSystemSettingData", CMPI_instance, true}, >> {"NewResourceSettingData", CMPI_instanceA, true}, >> @@ -1633,6 +1868,7 @@ static struct method_handler mvsth = { >> .handler = migrate_vs_host, >> .args = {{"ComputerSystem", CMPI_ref, false}, >> {"DestinationHost", CMPI_string, false}, >> + {"MigrationWithoutRootKey", CMPI_boolean, true}, >> {"MigrationSettingData", CMPI_instance, true}, >> {"NewSystemSettingData", CMPI_instance, true}, >> {"NewResourceSettingData", CMPI_instanceA, true}, >> @@ -1652,11 +1888,28 @@ static struct method_handler mvsts = { >> } >> }; >> >> +static struct method_handler msshkc = { >> + .name = "MigrateSSHKeyCopy", >> + .handler = migrate_sshkey_copy, >> + .args = {{"SSH_Key_Src", CMPI_string, true}, >> + ARG_END >> + } >> +}; >> + >> +static struct method_handler msshkd = { >> + .name = "MigrateSSHKeyDelete", >> + .handler = migrate_sshkey_delete, >> + .args = {ARG_END >> + } >> +}; >> + >> static struct method_handler *my_handlers[] = { >> &vsimth, >> &vsimts, >> &mvsth, >> &mvsts, >> + &msshkc, >> + &msshkd, >> NULL >> }; >> >> > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Sun Mar 24 09:02:56 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Sun, 24 Mar 2013 17:02:56 +0800 Subject: [Libvirt-cim] [PATCHv2 0/8] Additional patches for 0.6.2 In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <514EC140.1080607@linux.vnet.ibm.com> Hi, John thanks for rebasing. I'll review the patches and add it in the tail of my modified patches, as V6 in one or two days. Then we are sync and that serial would be easy to be pulled. I'll mark any changes in the cover-letter, you can skip those unchanged ones to save time. > This series replaces my last set. It is a followup after rebase and rework to: > > https://www.redhat.com/archives/libvirt-cim/2013-March/msg00029.html > > Changes in v2: > * Rework libxkutil/cs_util_instance.c to mirror functions as requested > * Rework src/Virt_DevicePool.c to mirror functions as requested > * Just merged the Makefile.am changes into one > * Previous patch 4/10 to CSI is removed due to code change already posted > > Still to be reviewed is Makefile.am. > > John Ferlan (8): > Makefile.am: Remove the $(top_srcdir) from subst command > libvirt-cim.spec: Use systemctl for tog-pegasus restart > Remove empty newline at bottom > xmlgen: Only support script on bridge for xen domains > libxkutil: Use virConnectListAllDomains() to fetch domains > libxkutil: Adjust get_dominfo() logic > DevicePool: Use the virConnectListAll interfaces > register: Adjust the chatter output > > Makefile.am | 18 +-- > libvirt-cim.spec.in | 12 +- > libxkutil/cs_util_instance.c | 24 ++++ > libxkutil/device_parsing.c | 7 +- > libxkutil/xmlgen.c | 25 +++-- > provider-register.sh | 9 +- > schema/SwitchService.registration | 1 - > src/Virt_DevicePool.c | 230 ++++++++++++++++++++++++++++++++++++++ > 8 files changed, 296 insertions(+), 30 deletions(-) > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:32:41 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:32:41 +0800 Subject: [Libvirt-cim] [PATCHv2 0/8] Additional patches for 0.6.2 In-Reply-To: <1363985234-31302-1-git-send-email-jferlan@redhat.com> References: <1363985234-31302-1-git-send-email-jferlan@redhat.com> Message-ID: <515019B9.5020300@linux.vnet.ibm.com> Hi, John All patches looks fine. There is s small code style issue: change from: if (a==b) xxxxx; to: if (a==b){ xxxx; } Since libvirt-cim lacks a script to check the code style I used qemu's script to do it, which reported this. I directly changed them in your patch, hope you are OK with it. Another change is made: For those patches using new interface, I added macro to enable them, and by default they are not used, to avoid inconsistent of build env and runtime env, and silent routine change when build env changes, since we have not set the requirement in spec file. Actually I think we should change it in configure in the future. > This series replaces my last set. It is a followup after rebase and rework to: > > https://www.redhat.com/archives/libvirt-cim/2013-March/msg00029.html > > Changes in v2: > * Rework libxkutil/cs_util_instance.c to mirror functions as requested > * Rework src/Virt_DevicePool.c to mirror functions as requested > * Just merged the Makefile.am changes into one > * Previous patch 4/10 to CSI is removed due to code change already posted > > Still to be reviewed is Makefile.am. > > John Ferlan (8): > Makefile.am: Remove the $(top_srcdir) from subst command > libvirt-cim.spec: Use systemctl for tog-pegasus restart > Remove empty newline at bottom > xmlgen: Only support script on bridge for xen domains > libxkutil: Use virConnectListAllDomains() to fetch domains > libxkutil: Adjust get_dominfo() logic > DevicePool: Use the virConnectListAll interfaces > register: Adjust the chatter output > > Makefile.am | 18 +-- > libvirt-cim.spec.in | 12 +- > libxkutil/cs_util_instance.c | 24 ++++ > libxkutil/device_parsing.c | 7 +- > libxkutil/xmlgen.c | 25 +++-- > provider-register.sh | 9 +- > schema/SwitchService.registration | 1 - > src/Virt_DevicePool.c | 230 ++++++++++++++++++++++++++++++++++++++ > 8 files changed, 296 insertions(+), 30 deletions(-) > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:42 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:42 +0800 Subject: [Libvirt-cim] [PATCH V6 02/20] SDC: Fix spelling for property IsFullVirt In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-3-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia --- src/Virt_SettingsDefineCapabilities.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index 5091205..b255cf5 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -160,7 +160,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, CMSetProperty(inst, "Bootloader", (CMPIValue *)"/usr/bin/pygrub", CMPI_chars); - CMSetProperty(inst, "isFullVirt", + CMSetProperty(inst, "IsFullVirt", (CMPIValue *)&isfv, CMPI_boolean); inst_list_add(list, inst); @@ -175,7 +175,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, CMSetProperty(inst, "BootDevice", (CMPIValue *)"hda", CMPI_chars); - CMSetProperty(inst, "isFullVirt", + CMSetProperty(inst, "IsFullVirt", (CMPIValue *)&isfv, CMPI_boolean); inst_list_add(list, inst); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:43 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:43 +0800 Subject: [Libvirt-cim] [PATCH V6 03/20] SDC: use property BootDevices instead of BootDevice In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-4-git-send-email-xiawenc@linux.vnet.ibm.com> The property registerted is BootDevices, so correct it, also fix the spelling in debug message. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- src/Virt_SettingsDefineCapabilities.c | 4 ++-- src/Virt_VirtualSystemManagementService.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index b255cf5..3b39a80 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -172,7 +172,7 @@ static CMPIStatus _xen_vsmc_to_vssd(virConnectPtr conn, if (inst == NULL) goto error; - CMSetProperty(inst, "BootDevice", + CMSetProperty(inst, "BootDevices", (CMPIValue *)"hda", CMPI_chars); CMSetProperty(inst, "IsFullVirt", @@ -211,7 +211,7 @@ static CMPIStatus _kvm_vsmc_to_vssd(virConnectPtr conn, CMSetProperty(inst, "VirtualSystemIdentifier", (CMPIValue *)"KVM_guest", CMPI_chars); - CMSetProperty(inst, "BootDevice", + CMSetProperty(inst, "BootDevices", (CMPIValue *)"hda", CMPI_chars); inst_list_add(list, inst); diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index 96c8a03..6322daf 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -408,7 +408,7 @@ static int bootord_vssd_to_domain(CMPIInstance *inst, bl_size = CMGetArrayCount(bootlist, &s); if (s.rc != CMPI_RC_OK) { - CU_DEBUG("Invalid BootDevice array size"); + CU_DEBUG("Invalid BootDevices array size"); return 0; } @@ -428,7 +428,7 @@ static int bootord_vssd_to_domain(CMPIInstance *inst, NULL); if (CMIsNullValue(boot_elem)) { - CU_DEBUG("Null BootDevice"); + CU_DEBUG("Null BootDevices"); free(tmp_str_arr); return 0; } -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:41 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:41 +0800 Subject: [Libvirt-cim] [PATCH V6 01/20] Remove property CreationClassName in some instance In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-2-git-send-email-xiawenc@linux.vnet.ibm.com> There are some instances which did not register this property, so this patch added a parameter in get_typed_instance(). The caller must set it clearly whether to set the property. When tog-pegasus > 2.12 and its log >= WARNING, tog-pegasus will report this problem in log. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- libxkutil/misc_util.c | 12 ++++++++---- libxkutil/misc_util.h | 3 ++- src/Virt_AllocationCapabilities.c | 3 ++- src/Virt_ComputerSystem.c | 6 ++++-- src/Virt_ComputerSystemIndication.c | 3 ++- src/Virt_ConsoleRedirectionService.c | 3 ++- src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 ++- src/Virt_Device.c | 18 ++++++++++++------ src/Virt_DevicePool.c | 20 +++++++++++++------- src/Virt_EnabledLogicalElementCapabilities.c | 3 ++- src/Virt_FilterEntry.c | 3 ++- src/Virt_FilterList.c | 3 ++- src/Virt_HostSystem.c | 3 ++- src/Virt_KVMRedirectionSAP.c | 3 ++- src/Virt_RASD.c | 3 ++- src/Virt_ReferencedProfile.c | 3 ++- src/Virt_RegisteredProfile.c | 3 ++- src/Virt_ResourcePoolConfigurationCapabilities.c | 3 ++- src/Virt_ResourcePoolConfigurationService.c | 8 ++++++-- src/Virt_SettingsDefineCapabilities.c | 6 ++++-- src/Virt_SwitchService.c | 3 ++- src/Virt_VSMigrationCapabilities.c | 3 ++- src/Virt_VSMigrationService.c | 6 ++++-- src/Virt_VSMigrationSettingData.c | 3 ++- src/Virt_VSSD.c | 3 ++- src/Virt_VirtualSystemManagementCapabilities.c | 3 ++- src/Virt_VirtualSystemManagementService.c | 6 ++++-- src/Virt_VirtualSystemSnapshotService.c | 3 ++- ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 ++- 29 files changed, 97 insertions(+), 48 deletions(-) diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index 2d149ae..f1b93e4 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -341,7 +341,8 @@ char *get_typed_class(const char *refcn, const char *new_base) CMPIInstance *get_typed_instance(const CMPIBroker *broker, const char *refcn, const char *base, - const char *namespace) + const char *namespace, + bool ccn_flag) { char *new_cn; CMPIObjectPath *op; @@ -360,8 +361,10 @@ CMPIInstance *get_typed_instance(const CMPIBroker *broker, if ((s.rc != CMPI_RC_OK) || CMIsNullObject(inst)) goto out; - CMSetProperty(inst, "CreationClassName", - (CMPIValue *)new_cn, CMPI_chars); + if (ccn_flag) { + CMSetProperty(inst, "CreationClassName", + (CMPIValue *)new_cn, CMPI_chars); + } out: free(new_cn); @@ -467,7 +470,8 @@ CMPIInstance *make_reference(const CMPIBroker *broker, ref_inst = get_typed_instance(broker, CLASSNAME(source_ref), assoc_classname, - NAMESPACE(source_ref)); + NAMESPACE(source_ref), + false); if (ref_inst != NULL) { CMPIObjectPath *target_ref; diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h index c7a2122..90fb2da 100644 --- a/libxkutil/misc_util.h +++ b/libxkutil/misc_util.h @@ -85,7 +85,8 @@ char *get_typed_class(const char *refcn, const char *new_base); CMPIInstance *get_typed_instance(const CMPIBroker *broker, const char *refcn, const char *base, - const char *namespace); + const char *namespace, + bool ccn_flag); /* Parse an OrgID:LocID string into its constituent parts */ int parse_instance_id(char *iid, char **orgid, char **locid); diff --git a/src/Virt_AllocationCapabilities.c b/src/Virt_AllocationCapabilities.c index 970abeb..b358fac 100644 --- a/src/Virt_AllocationCapabilities.c +++ b/src/Virt_AllocationCapabilities.c @@ -46,7 +46,8 @@ static CMPIStatus ac_from_pool(const CMPIBroker *broker, *alloc_cap = get_typed_instance(broker, CLASSNAME(ref), "AllocationCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (*alloc_cap == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index e6c7e55..4a9b26d 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -440,7 +440,8 @@ CMPIStatus instance_from_dominfo(const CMPIBroker *broker, inst = get_typed_instance(broker, prefix, "ComputerSystem", - namespace); + namespace, + true); if (inst == NULL) { CU_DEBUG("Could not init CS instance. " @@ -560,7 +561,8 @@ static CMPIStatus instance_from_dom(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "ComputerSystem", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 2d0a94e..3096683 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -239,7 +239,8 @@ static bool _do_indication(const CMPIBroker *broker, ind = get_typed_instance(broker, prefix, ind_type_name, - args->ns); + args->ns, + false); /* Generally report errors and hope to continue, since we have no one to actually return status to. */ diff --git a/src/Virt_ConsoleRedirectionService.c b/src/Virt_ConsoleRedirectionService.c index 7b20c0d..16cade8 100644 --- a/src/Virt_ConsoleRedirectionService.c +++ b/src/Virt_ConsoleRedirectionService.c @@ -129,7 +129,8 @@ CMPIStatus get_console_rs(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "ConsoleRedirectionService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_ConsoleRedirectionServiceCapabilities.c b/src/Virt_ConsoleRedirectionServiceCapabilities.c index 11f2986..88fb3a4 100644 --- a/src/Virt_ConsoleRedirectionServiceCapabilities.c +++ b/src/Virt_ConsoleRedirectionServiceCapabilities.c @@ -91,7 +91,8 @@ CMPIStatus get_console_rs_caps(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "ConsoleRedirectionServiceCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_Device.c b/src/Virt_Device.c index e047a94..c7dcbc3 100644 --- a/src/Virt_Device.c +++ b/src/Virt_Device.c @@ -100,7 +100,8 @@ static CMPIInstance *net_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "NetworkPort", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for NetworkPort"); @@ -138,7 +139,8 @@ static CMPIInstance *disk_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "LogicalDisk", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for LogicalDisk"); @@ -185,7 +187,8 @@ static CMPIInstance *mem_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "Memory", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for Memory"); @@ -234,7 +237,8 @@ static CMPIInstance *graphics_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "DisplayController", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance for DisplayController"); @@ -320,7 +324,8 @@ static CMPIInstance *input_instance(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "PointingDevice", - ns); + ns, + true); if (inst == NULL) { CU_DEBUG("Failed to get instance of %s_PointingDevice", pfx_from_conn(conn)); @@ -407,7 +412,8 @@ static bool vcpu_inst(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "Processor", - ns); + ns, + true); if (inst == NULL) return false; diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 202e509..56c9715 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -803,7 +803,8 @@ static CMPIStatus mempool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "MemoryPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, @@ -842,7 +843,8 @@ static CMPIStatus procpool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "ProcessorPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, @@ -872,7 +874,8 @@ static CMPIStatus _netpool_for_parent(struct inst_list *list, inst = get_typed_instance(broker, refcn, "NetworkPool", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", ns, refcn); @@ -928,7 +931,8 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, inst = get_typed_instance(broker, refcn, "NetworkPool", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Unable to get instance: %s:%s_NetworkPool", ns, refcn); @@ -1046,7 +1050,7 @@ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, CMPIInstance *inst; char *poolid = NULL; - inst = get_typed_instance(broker, refcn, "DiskPool", ns); + inst = get_typed_instance(broker, refcn, "DiskPool", ns, false); if (inst == NULL) { cu_statusf(broker, &s, @@ -1136,7 +1140,8 @@ static CMPIStatus graphicspool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "GraphicsPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, @@ -1172,7 +1177,8 @@ static CMPIStatus inputpool_instance(virConnectPtr conn, inst = get_typed_instance(broker, pfx_from_conn(conn), "InputPool", - ns); + ns, + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_EnabledLogicalElementCapabilities.c b/src/Virt_EnabledLogicalElementCapabilities.c index 7ba5eae..2fcdef1 100644 --- a/src/Virt_EnabledLogicalElementCapabilities.c +++ b/src/Virt_EnabledLogicalElementCapabilities.c @@ -61,7 +61,8 @@ static CMPIInstance *_get_elec(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "EnabledLogicalElementCapabilities", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(broker, s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_FilterEntry.c b/src/Virt_FilterEntry.c index 126615b..3c4a3e6 100644 --- a/src/Virt_FilterEntry.c +++ b/src/Virt_FilterEntry.c @@ -546,7 +546,8 @@ static CMPIInstance *convert_rule_to_instance( inst = get_typed_instance(broker, CLASSNAME(reference), basename, - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_FilterList.c b/src/Virt_FilterList.c index 9b5dbae..79776cd 100644 --- a/src/Virt_FilterList.c +++ b/src/Virt_FilterList.c @@ -50,7 +50,8 @@ static CMPIInstance *convert_filter_to_instance( inst = get_typed_instance(broker, CLASSNAME(reference), "FilterList", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_HostSystem.c b/src/Virt_HostSystem.c index 724a5ea..c31d6cf 100644 --- a/src/Virt_HostSystem.c +++ b/src/Virt_HostSystem.c @@ -135,7 +135,8 @@ static CMPIStatus fake_host(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "HostSystem", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, diff --git a/src/Virt_KVMRedirectionSAP.c b/src/Virt_KVMRedirectionSAP.c index db34d57..38ad468 100644 --- a/src/Virt_KVMRedirectionSAP.c +++ b/src/Virt_KVMRedirectionSAP.c @@ -125,7 +125,8 @@ static CMPIInstance *get_console_sap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "KVMRedirectionSAP", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_RASD.c b/src/Virt_RASD.c index 9493077..6e8a244 100644 --- a/src/Virt_RASD.c +++ b/src/Virt_RASD.c @@ -716,7 +716,8 @@ CMPIInstance *rasd_from_vdev(const CMPIBroker *broker, inst = get_typed_instance(broker, CLASSNAME(ref), base, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) return inst; diff --git a/src/Virt_ReferencedProfile.c b/src/Virt_ReferencedProfile.c index 150be1f..e78a8d3 100644 --- a/src/Virt_ReferencedProfile.c +++ b/src/Virt_ReferencedProfile.c @@ -242,7 +242,8 @@ static CMPIInstance *make_ref(const CMPIObjectPath *source_ref, ref_inst = get_typed_instance(_BROKER, CLASSNAME(source_ref), assoc_classname, - NAMESPACE(source_ref)); + NAMESPACE(source_ref), + false); source = get_reg_prof_by_ref(source_ref); if (source->scoping_profile != NULL) diff --git a/src/Virt_RegisteredProfile.c b/src/Virt_RegisteredProfile.c index 389a179..e644708 100644 --- a/src/Virt_RegisteredProfile.c +++ b/src/Virt_RegisteredProfile.c @@ -54,7 +54,8 @@ CMPIStatus get_profile(const CMPIBroker *broker, instance = get_typed_instance(broker, pfx, "RegisteredProfile", - CIM_INTEROP_NS); + CIM_INTEROP_NS, + false); if (instance == NULL) { cu_statusf(broker, &s, diff --git a/src/Virt_ResourcePoolConfigurationCapabilities.c b/src/Virt_ResourcePoolConfigurationCapabilities.c index 32274ed..2dcbbcf 100644 --- a/src/Virt_ResourcePoolConfigurationCapabilities.c +++ b/src/Virt_ResourcePoolConfigurationCapabilities.c @@ -69,7 +69,8 @@ static CMPIStatus get_rpc_cap(const CMPIObjectPath *reference, inst = get_typed_instance(_BROKER, pfx_from_conn(conn), "ResourcePoolConfigurationCapabilities", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_ResourcePoolConfigurationService.c b/src/Virt_ResourcePoolConfigurationService.c index 751d016..0c0cc06 100644 --- a/src/Virt_ResourcePoolConfigurationService.c +++ b/src/Virt_ResourcePoolConfigurationService.c @@ -781,6 +781,8 @@ static const char *rasd_to_res(CMPIInstance *inst, return msg; } +/* Warning: returned instance is not freed manually in caller, need confirm + if server will auto free it. */ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, const CMPIObjectPath *ref, CMPIStatus *s) @@ -798,7 +800,8 @@ static CMPIInstance *get_resource_rasd(struct virt_pool_res *res, inst = get_typed_instance(_BROKER, CLASSNAME(ref), "StorageVolumeResourceAllocationSettingData", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(_BROKER, s, CMPI_RC_ERR_FAILED, @@ -1279,7 +1282,8 @@ CMPIStatus get_rpcs(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "ResourcePoolConfigurationService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_SettingsDefineCapabilities.c b/src/Virt_SettingsDefineCapabilities.c index 9eb9e57..5091205 100644 --- a/src/Virt_SettingsDefineCapabilities.c +++ b/src/Virt_SettingsDefineCapabilities.c @@ -113,7 +113,8 @@ static CMPIInstance *default_vssd_instance(const char *prefix, inst = get_typed_instance(_BROKER, prefix, "VirtualSystemSettingData", - ns); + ns, + false); if (inst == NULL) { CU_DEBUG("Failed to create default VSSD instance"); goto out; @@ -303,7 +304,8 @@ static CMPIInstance *sdc_rasd_inst(CMPIStatus *s, inst = get_typed_instance(_BROKER, CLASSNAME(ref), base, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(_BROKER, s, diff --git a/src/Virt_SwitchService.c b/src/Virt_SwitchService.c index 7e59d38..8991426 100644 --- a/src/Virt_SwitchService.c +++ b/src/Virt_SwitchService.c @@ -229,7 +229,8 @@ static CMPIStatus get_switchservice(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "SwitchService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_VSMigrationCapabilities.c b/src/Virt_VSMigrationCapabilities.c index 4f0e434..3e53f68 100644 --- a/src/Virt_VSMigrationCapabilities.c +++ b/src/Virt_VSMigrationCapabilities.c @@ -134,7 +134,8 @@ CMPIStatus get_migration_caps(const CMPIObjectPath *ref, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemMigrationCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c index 76e3d25..1f6659d 100644 --- a/src/Virt_VSMigrationService.c +++ b/src/Virt_VSMigrationService.c @@ -831,7 +831,8 @@ static CMPIInstance *prepare_indication(const CMPIBroker *broker, ind = get_typed_instance(broker, pfx, ind_name, - job->ref_ns); + job->ref_ns, + false); if (ind == NULL) { CU_DEBUG("Failed to create ind, type '%s:%s_%s'", job->ref_ns, pfx, ind_name); @@ -1686,7 +1687,8 @@ CMPIStatus get_migration_service(const CMPIObjectPath *ref, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemMigrationService", - NAMESPACE(ref)); + NAMESPACE(ref), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSMigrationSettingData.c b/src/Virt_VSMigrationSettingData.c index a6707bd..eb545f1 100644 --- a/src/Virt_VSMigrationSettingData.c +++ b/src/Virt_VSMigrationSettingData.c @@ -79,7 +79,8 @@ CMPIStatus get_migration_sd(const CMPIObjectPath *ref, inst = get_typed_instance(broker, CLASSNAME(ref), "VirtualSystemMigrationSettingData", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c index 499b157..975623b 100644 --- a/src/Virt_VSSD.c +++ b/src/Virt_VSSD.c @@ -285,7 +285,8 @@ static CMPIInstance *_get_vssd(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSettingData", - NAMESPACE(reference)); + NAMESPACE(reference), + false); if (inst == NULL) { cu_statusf(broker, s, diff --git a/src/Virt_VirtualSystemManagementCapabilities.c b/src/Virt_VirtualSystemManagementCapabilities.c index 020ce8a..51738ee 100644 --- a/src/Virt_VirtualSystemManagementCapabilities.c +++ b/src/Virt_VirtualSystemManagementCapabilities.c @@ -129,7 +129,8 @@ CMPIStatus get_vsm_cap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemManagementCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VirtualSystemManagementService.c b/src/Virt_VirtualSystemManagementService.c index 10adf8b..96c8a03 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -1928,7 +1928,8 @@ static CMPIStatus raise_rasd_indication(const CMPIContext *context, ind = get_typed_instance(_BROKER, CLASSNAME(ref), base_type, - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (ind == NULL) { CU_DEBUG("Failed to get indication instance"); s.rc = CMPI_RC_ERR_FAILED; @@ -3293,7 +3294,8 @@ CMPIStatus get_vsms(const CMPIObjectPath *reference, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemManagementService", - NAMESPACE(reference)); + NAMESPACE(reference), + true); if (inst == NULL) { CU_DEBUG("Failed to get typed instance"); diff --git a/src/Virt_VirtualSystemSnapshotService.c b/src/Virt_VirtualSystemSnapshotService.c index aae628f..8c0889d 100644 --- a/src/Virt_VirtualSystemSnapshotService.c +++ b/src/Virt_VirtualSystemSnapshotService.c @@ -681,7 +681,8 @@ CMPIStatus get_vsss(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSnapshotService", - NAMESPACE(ref)); + NAMESPACE(ref), + true); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, diff --git a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c index 69c8e97..04a9c7a 100644 --- a/src/Virt_VirtualSystemSnapshotServiceCapabilities.c +++ b/src/Virt_VirtualSystemSnapshotServiceCapabilities.c @@ -117,7 +117,8 @@ CMPIStatus get_vss_cap(const CMPIBroker *broker, inst = get_typed_instance(broker, pfx_from_conn(conn), "VirtualSystemSnapshotServiceCapabilities", - NAMESPACE(ref)); + NAMESPACE(ref), + false); if (inst == NULL) { cu_statusf(broker, &s, CMPI_RC_ERR_FAILED, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:45 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:45 +0800 Subject: [Libvirt-cim] [PATCH V6 05/20] CSI, DevicePool, RASDIndication: fix debug print crash In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-6-git-send-email-xiawenc@linux.vnet.ibm.com> Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan Reviewed-by: Sharad Mishra --- src/Virt_ComputerSystemIndication.c | 2 +- src/Virt_DevicePool.c | 2 +- src/Virt_ResourceAllocationSettingDataIndication.c | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 3096683..8250850 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -504,7 +504,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; } diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 56c9715..08677e2 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; } 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 Mon Mar 25 09:52:46 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:46 +0800 Subject: [Libvirt-cim] [PATCH V6 06/20] CSI, add lock to protect shared data in lifecycle_thread In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-7-git-send-email-xiawenc@linux.vnet.ibm.com> This patch use lock 'lifecycle_mutex' to protect global shared data in lifecycle_thread(). This lock exist in Activate/Deactivate Enable/Disable method, which is meant to protect the global shared data, but forgot to be added in new libvirt based CSI thread. This patch can avoid following risk at least: Original code have a small chance to free thread->args in child thread just after main thread malloc it, for that thread->id is set to zero allowing main thread to enter that code. This patch focus on adding missing lock, the CSI can be still improved as: smaller lock, folder lock into a structure with data to tip better what it is doing. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- 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 8250850..3df47fa 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, @@ -491,6 +493,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, @@ -503,10 +507,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); @@ -538,7 +545,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) { @@ -546,12 +555,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); @@ -559,7 +572,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: @@ -580,10 +595,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; } @@ -595,33 +612,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; @@ -629,6 +660,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 Mar 25 09:52:47 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:47 +0800 Subject: [Libvirt-cim] [PATCH V6 07/20] DevicePool, reimplement get_diskpool_config with libvirt In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-8-git-send-email-xiawenc@linux.vnet.ibm.com> Original implemetion may return pools with NULL name if some pool disappear between two libvirt pool API call. And originally it return the number of pools and negative value when error happens, but caller of this function consider number = 0 as error. As a fix, this patch changed the function prototype, it do not return the pool number anymore, it returns 0 on success and negative on fail now. Code for checking the risk of returning pools with NULL name is also added. Other small fixes are: return false in get_disk_parent() when strdup() fail, set member to NULL in parse_diskpool_line() after free, removed the duplicated macro declaration in Virt_DevicePool.c file for VIR_USE_LIBVIRT_STORAGE, refined the code in get_diskpool_config() when VIR_USE_LIBVIRT_STORAGE == 0. Signed-off-by: Wenchao Xia --- src/Virt_DevicePool.c | 220 ++++++++++++++++++++++++++++++++----------------- src/Virt_DevicePool.h | 4 + 2 files changed, 149 insertions(+), 75 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index 08677e2..a8dc9cd 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -51,21 +51,30 @@ struct tmp_disk_pool { bool primordial; }; +static void free_diskpool(struct tmp_disk_pool *pools, int count) +{ + int i; + + if (pools == NULL) { + return; + } + + for (i = 0; i < count; i++) { + free(pools[i].tag); + free(pools[i].path); + } + + free(pools); +} + /* - * Right now, detect support and use it, if available. - * Later, this can be a configure option if needed + * If fail, *_pools will be freed and set to NULL, and *_count will be set to + * zero. */ -#if LIBVIR_VERSION_NUMBER > 4000 -# define VIR_USE_LIBVIRT_STORAGE 1 -#else -# define VIR_USE_LIBVIRT_STORAGE 0 -#endif - static bool get_disk_parent(struct tmp_disk_pool **_pools, int *_count) { struct tmp_disk_pool *pools = NULL; - int ret = false; int count; count = *_count; @@ -74,23 +83,31 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, pools = realloc(pools, (count + 1) * (sizeof(*pools))); if (pools == NULL) { CU_DEBUG("Failed to alloc new pool"); - goto out; + pools = *_pools; + goto fail; } - pools[count].tag = strdup("0"); pools[count].path = NULL; pools[count].primordial = true; + pools[count].tag = strdup("0"); + if (pools[count].tag == NULL) { + count++; + goto fail; + } count++; *_count = count; *_pools = pools; - ret = true; + return true; - out: - return ret; + fail: + free_diskpool(pools, count); + /* old pool is invalid, update it */ + *_count = 0; + *_pools = NULL; + return false; } - #if VIR_USE_LIBVIRT_STORAGE int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) { @@ -117,52 +134,80 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) return ret; } +/* + * return 0 on success, negative on fail, *pools and *_count will be set + * only on success . + */ static int get_diskpool_config(virConnectPtr conn, - struct tmp_disk_pool **_pools) + struct tmp_disk_pool **_pools, + int *_count) { - int count = 0; + int count = 0, realcount = 0; int i; char ** names = NULL; struct tmp_disk_pool *pools = NULL; + int ret = 0; count = virConnectNumOfStoragePools(conn); - if (count <= 0) + if (count < 0) { + ret = count; goto out; + } else if (count == 0) { + goto set_parent; + } names = calloc(count, sizeof(char *)); if (names == NULL) { CU_DEBUG("Failed to alloc space for %i pool names", count); - count = 0; + ret = -1; goto out; } - if (virConnectListStoragePools(conn, names, count) == -1) { - CU_DEBUG("Failed to get storage pools"); - count = 0; - goto out; + realcount = virConnectListStoragePools(conn, names, count); + if (realcount < 0) { + CU_DEBUG("Failed to get storage pools, return %d.", realcount); + ret = realcount; + goto free_names; + } + if (realcount == 0) { + CU_DEBUG("Zero pools got, but prelist is %d.", count); + goto set_parent; } - pools = calloc(count, sizeof(*pools)); + pools = calloc(realcount, sizeof(*pools)); if (pools == NULL) { - CU_DEBUG("Failed to alloc space for %i pool structs", count); - goto out; + CU_DEBUG("Failed to alloc space for %i pool structs", + realcount); + ret = -2; + goto free_names; } - for (i = 0; i < count; i++) { - pools[i].tag = strdup(names[i]); + for (i = 0; i < realcount; i++) { + pools[i].tag = names[i]; + names[i] = NULL; pools[i].primordial = false; } - out: - for (i = 0; i < count; i++) - free(names[i]); - free(names); - - get_disk_parent(&pools, &count); + set_parent: + if (!get_disk_parent(&pools, &realcount)) { + CU_DEBUG("Failed in adding parentpool."); + ret = -4; + /* pools is already freed in get_disk_parent().*/ + goto free_names; + } + /* succeed */ *_pools = pools; + *_count = realcount; + + free_names: + for (i = 0; i < count; i++) { + free(names[i]); + } + free(names); - return count; + out: + return ret; } static bool diskpool_set_capacity(virConnectPtr conn, @@ -279,8 +324,8 @@ static bool _diskpool_is_member(virConnectPtr conn, return result; } #else -static int parse_diskpool_line(struct tmp_disk_pool *pool, - const char *line) +static bool parse_diskpool_line(struct tmp_disk_pool *pool, + const char *line) { int ret; @@ -288,48 +333,81 @@ static int parse_diskpool_line(struct tmp_disk_pool *pool, if (ret != 2) { free(pool->tag); free(pool->path); + pool->tag = NULL; + pool->path = NULL; } pool->primordial = false; return (ret == 2); } +/* + * return 0 on success, negative on fail, *pools and *_count will be set + * only on success . + */ static int get_diskpool_config(virConnectPtr conn, - struct tmp_disk_pool **_pools) + struct tmp_disk_pool **_pools, + int *_count) { const char *path = DISK_POOL_CONFIG; FILE *config; char *line = NULL; size_t len = 0; - int count = 0; - struct tmp_disk_pool *pools = NULL; + int count = 0, ret = 0; + struct tmp_disk_pool *pools = NULL, *new_pools = NULL, *pool = NULL; config = fopen(path, "r"); if (config == NULL) { CU_DEBUG("Failed to open %s: %m", path); - return 0; + ret = -1; + goto out; } + pool = calloc(1, sizeof(*pool)); + if (!pool) { + CU_DEBUG("Failed to calloc pool"); + ret = -2; + goto close; + } + + /* *line will be automatically freed by getline() */ while (getline(&line, &len, config) > 0) { - pools = realloc(pools, - (count + 1) * (sizeof(*pools))); - if (pools == NULL) { - CU_DEBUG("Failed to alloc new pool"); - goto out; + if (parse_diskpool_line(pool, line)) { + new_pools = realloc(pools, + (count + 1) * (sizeof(*pools))); + if (new_pools == NULL) { + CU_DEBUG("Failed to alloc new pool"); + ret = -3; + goto free_pools; + } + pools = new_pools; + pools[count] = *pool; + memset(pool, 0, sizeof(*pool)); + count++; } + } - if (parse_diskpool_line(&pools[count], line)) - count++; + if (!get_disk_parent(&pools, &count)) { + CU_DEBUG("Failed in adding parentpool."); + ret = -4; + /* pools is already freed by get_disk_parent() */ + goto clean; } + /* succeed */ + *_pools = pools; + *_count = count; + goto clean; - get_disk_parent(&pools, &count); - out: + free_pools: + free_diskpool(pools, count); + clean: free(line); - *_pools = pools; + free_diskpool(pool, 1); + close: fclose(config); - - return count; + out: + return ret; } static bool diskpool_set_capacity(virConnectPtr conn, @@ -367,39 +445,23 @@ static bool diskpool_set_capacity(virConnectPtr conn, } static bool _diskpool_is_member(virConnectPtr conn, - const struct disk_pool *pool, + const struct tmp_disk_pool *pool, const char *file) { return STARTS_WITH(file, pool->path); } #endif -static void free_diskpool(struct tmp_disk_pool *pools, int count) -{ - int i; - - if (pools == NULL) - return; - - for (i = 0; i < count; i++) { - free(pools[i].tag); - free(pools[i].path); - } - - free(pools); -} - static char *_diskpool_member_of(virConnectPtr conn, const char *file) { struct tmp_disk_pool *pools = NULL; int count; - int i; + int i, ret; char *pool = NULL; - count = get_diskpool_config(conn, &pools); - if (count == 0) { - free(pools); + ret = get_diskpool_config(conn, &pools, &count); + if (ret < 0) { return NULL; } @@ -1088,9 +1150,17 @@ static CMPIStatus diskpool_instance(virConnectPtr conn, CMPIStatus s = {CMPI_RC_OK, NULL}; struct tmp_disk_pool *pools = NULL; int count = 0; - int i; + int i, ret; - count = get_diskpool_config(conn, &pools); + ret = get_diskpool_config(conn, &pools, &count); + if (ret < 0) { + CU_DEBUG("Failed to get diskpool config, return is %d.", ret); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to get diskpool config, return is %d.", + ret); + return s; + } if ((id == NULL) && (count == 0)) { CU_DEBUG("No defined DiskPools"); free(pools); diff --git a/src/Virt_DevicePool.h b/src/Virt_DevicePool.h index d160bf1..6b44863 100644 --- a/src/Virt_DevicePool.h +++ b/src/Virt_DevicePool.h @@ -28,6 +28,10 @@ #include "pool_parsing.h" +/* + * Right now, detect support and use it, if available. + * Later, this can be a configure option if needed + */ #if LIBVIR_VERSION_NUMBER > 4000 # define VIR_USE_LIBVIRT_STORAGE 1 #else -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:48 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:48 +0800 Subject: [Libvirt-cim] [PATCH V6 08/20] device parsing, add debug print In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-9-git-send-email-xiawenc@linux.vnet.ibm.com> Sometimes libvirt will fail in these APIs if there is low level error, what we saw is libvirt can't got xml for some domain. This patch adds debug log when met this error, so in future we can know what is wrong. Signed-off-by: Wenchao Xia Signed-off-by: John Ferlan --- libxkutil/device_parsing.c | 19 ++++++++++++++----- 1 files changed, 14 insertions(+), 5 deletions(-) diff --git a/libxkutil/device_parsing.c b/libxkutil/device_parsing.c index ceb4552..264d4cc 100644 --- a/libxkutil/device_parsing.c +++ b/libxkutil/device_parsing.c @@ -1246,20 +1246,29 @@ int get_dominfo_from_xml(const char *xml, struct domain **dominfo) int get_dominfo(virDomainPtr dom, struct domain **dominfo) { char *xml; - int ret; + int ret = 0; int start; 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) - return 0; + if (get_dominfo_from_xml(xml, dominfo) == 0) { + CU_DEBUG("Failed to translate xml into struct domain"); + goto out; + } + if (virDomainGetAutostart(dom, &start) != 0) { + CU_DEBUG("Failed to get dom autostart with libvirt API."); + goto out; + } (*dominfo)->autostrt = start; + ret = 1; + out: free(xml); return ret; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:49 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:49 +0800 Subject: [Libvirt-cim] [PATCH V6 09/20] CSI Discard libvirt event by default In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-10-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. Most possible is that tog-pegasus tries to manage all threads resulting the error. 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 Note that to make review easy, this patch try move the code as little as possible, a following "clean up" patch will move the code together. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- src/Virt_ComputerSystem.c | 60 +++- src/Virt_ComputerSystemIndication.c | 663 ++++++++++++++++++++++++++++- src/Virt_VirtualSystemManagementService.c | 57 +++- 3 files changed, 777 insertions(+), 3 deletions(-) diff --git a/src/Virt_ComputerSystem.c b/src/Virt_ComputerSystem.c index 4a9b26d..d37159f 100644 --- a/src/Virt_ComputerSystem.c +++ b/src/Virt_ComputerSystem.c @@ -45,8 +45,58 @@ #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 CMPIBroker *broker, + 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 libvirt-cim native ComputerSystem indication"); + + ind = get_typed_instance(broker, + CLASSNAME(ref), + ind_name, + NAMESPACE(ref), + false); + if (ind == NULL) { + CU_DEBUG("Failed to create ind '%s'", ind_name); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "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; +} +#else +static bool trigger_mod_indication(const CMPIBroker *broker, + const CMPIContext *context, + CMPIInstance *prev_inst, + const CMPIObjectPath *ref) +{ + return true; +} +#endif + /* Set the "Name" property of an instance from a domain */ static int set_name_from_dom(virDomainPtr dom, CMPIInstance *instance) { @@ -1258,8 +1308,16 @@ static CMPIStatus state_change(CMPIMethodMI *self, s = __state_change(name, state, reference); - if (s.rc == CMPI_RC_OK) + if (s.rc == CMPI_RC_OK) { rc = 0; + /* try trigger indication */ + bool ind_rc = trigger_mod_indication(_BROKER, context, + prev_inst, reference); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "state change, dom is '%s'", name); + } + } out: CMReturnData(results, &rc, CMPI_uint32); diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index 3df47fa..ef449ff 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -48,7 +48,6 @@ #include "Virt_ComputerSystemIndication.h" #include "Virt_HostSystem.h" - #define CSI_NUM_PLATFORMS 3 enum CSI_PLATFORMS { CSI_XEN, @@ -84,6 +83,8 @@ 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}}; +#ifndef USE_LIBVIRT_EVENT +#else /* * Domain manipulation */ @@ -180,6 +181,7 @@ static void csi_free_thread_data(void *data) stdi_free_ind_args(&thread->args); pthread_mutex_unlock(&lifecycle_mutex); } +#endif void set_source_inst_props(const CMPIBroker *broker, const CMPIContext *context, @@ -386,6 +388,394 @@ static bool create_deleted_guest_inst(const char *xml, return rc; } +#ifndef USE_LIBVIRT_EVENT +/* libvirt-cim's private CSI implement */ + +#define WAIT_TIME 60 +#define FAIL_WAIT_TIME 2 + +static pthread_cond_t lifecycle_cond = PTHREAD_COND_INITIALIZER; + +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)); + if (!dom_xml_list) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed calloc %d dom_xml.", dom_ptr_count); + return s; + } + 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 !ret; +} + +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 dilivery 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 %d", ind_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); + } else if (dom_changed(prev_xml[i], + cur_xml, cur_count)) { + 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; +} +#else static bool async_ind(struct ind_args *args, int ind_type, csi_dom_xml_t *dom, @@ -669,6 +1059,7 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) free(prefix); return (CMPI_THREAD_RETURN) 0; } +#endif static int platform_from_class(const char *cn) { @@ -682,6 +1073,162 @@ static int platform_from_class(const char *cn) return -1; } +#ifndef USE_LIBVIRT_EVENT +static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean first) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct std_indication_ctx *_ctx; + struct ind_args *args = NULL; + int platform; + bool error = false; + csi_thread_data_t *thread = NULL; + + CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); + + pthread_mutex_lock(&lifecycle_mutex); + + CU_DEBUG("Using libvirt-cim's event implemention."); + + _ctx = (struct std_indication_ctx *)mi->hdl; + + if (CMIsNullObject(op)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No ObjectPath given"); + goto out; + } + + /* FIXME: op is stale the second time around, for some reason */ + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + thread = &csi_thread_data[platform]; + thread->active_filters += 1; + + /* Check if thread is already running */ + if (thread->id > 0) { + goto out; + } + + args = malloc(sizeof(*args)); + if (args == NULL) { + CU_DEBUG("Failed to allocate ind_args"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + error = true; + goto out; + } + + args->context = CBPrepareAttachThread(_BROKER, ctx); + if (args->context == NULL) { + CU_DEBUG("Failed to create thread context"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to create thread context"); + error = true; + goto out; + } + + args->ns = strdup(NAMESPACE(op)); + args->classname = strdup(CLASSNAME(op)); + args->_ctx = _ctx; + + thread->args = args; + + thread->id = _BROKER->xft->newThread(lifecycle_thread_native, + thread, 0); + + if (thread->id <= 0) { + CU_DEBUG("Error, failed to create new thread."); + error = true; + } + + out: + if (error == true) { + thread->active_filters -= 1; + free(args); + } + + pthread_mutex_unlock(&lifecycle_mutex); + + return s; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean last) +{ + int platform; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); + + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + + pthread_mutex_lock(&lifecycle_mutex); + csi_thread_data[platform].active_filters -= 1; + pthread_mutex_unlock(&lifecycle_mutex); + + pthread_cond_signal(&lifecycle_cond); + + out: + return s; +} + +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; +} +#else static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, const CMPIContext* ctx, const CMPISelectExp* se, @@ -703,6 +1250,7 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, if (events_registered == 0) { events_registered = 1; + CU_DEBUG("Registering libvirt event."); virEventRegisterDefaultImpl(); } @@ -756,6 +1304,11 @@ static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, thread->args = args; 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) { thread->active_filters -= 1; @@ -795,6 +1348,7 @@ static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, out: return s; } +#endif static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, const CMPIContext *ctx) @@ -841,7 +1395,114 @@ static struct std_ind_filter *filters[] = { NULL, }; +#ifndef USE_LIBVIRT_EVENT +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)); + if (!args->classname || !args->ns) { + CU_DEBUG("Failed in strdup"); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed in strdup in indication raising"); + goto out; + } + 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 6322daf..cbb646d 100644 --- a/src/Virt_VirtualSystemManagementService.c +++ b/src/Virt_VirtualSystemManagementService.c @@ -107,6 +107,33 @@ enum ResourceAction { RESOURCE_MOD, }; +#ifndef USE_LIBVIRT_EVENT +static bool trigger_indication(const CMPIBroker *broker, + 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; +} +#else +static bool trigger_indication(const CMPIBroker *broker; + const CMPIContext *context, + const char *base_type, + const CMPIObjectPath *ref) +{ + return true; +} +#endif + #if LIBVIR_VERSION_NUMBER < 9000 /* Network QoS support */ static CMPIStatus add_qos_for_mac(const uint64_t qos, @@ -2167,6 +2194,16 @@ static CMPIStatus define_system(CMPIMethodMI *self, CMAddArg(argsout, "ResultingSystem", &result, CMPI_ref); } + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemCreatedIndication", reference); + if (!ind_rc) { + const char *dom_name = NULL; + cu_get_str_prop(vssd, "VirtualSystemIdentifier", &dom_name); + CU_DEBUG("Unable to trigger indication for " + "system create, dom is '%s'", dom_name); + } + out: if (s.rc == CMPI_RC_OK) rc = CIM_SVPC_RETURN_COMPLETED; @@ -2269,6 +2306,15 @@ error: NULL, reference, &list); + + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemDeletedIndication", reference); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "system delete, dom is '%s'", dom_name); + } + } virDomainFree(dom); @@ -2350,8 +2396,17 @@ 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); + /* try trigger indication */ + bool ind_rc = trigger_indication(_BROKER, context, + "ComputerSystemModifiedIndication", ref); + if (!ind_rc) { + CU_DEBUG("Unable to trigger indication for " + "system modify, dom is '%s'", name); + } + + } out: free(xml); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:52 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:52 +0800 Subject: [Libvirt-cim] [PATCH V6 12/20] misc_util: better way to read config In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-13-git-send-email-xiawenc@linux.vnet.ibm.com> This patch adds an common internal function to get property from libvirt-cim config, so it is easy to add properties later. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- libxkutil/misc_util.c | 114 +++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 100 insertions(+), 14 deletions(-) diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index f1b93e4..820b42d 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -106,14 +106,40 @@ static const char *cn_to_uri(const char *classname) return NULL; } -static int is_read_only(void) -{ - int readonly = 0; +/* config support */ +typedef enum LibvirtcimConfigType { + CONFIG_BOOL, + CONFIG_STRING, +} LibvirtcimConfigType; + +typedef struct LibvirtcimConfigProperty { + const char *name; + LibvirtcimConfigType value_type; + union { + int value_bool; + char *value_string; + }; + int have_read; +} LibvirtcimConfigProperty; #ifdef HAVE_LIBCONFIG +/* + * @prop must be initialized with zeros, except default value, return 0 means + * OK. prop->value_string will be automatically freed if not NULL, caller must + * never set it to const char*. + */ +static int libvirt_cim_config_get(LibvirtcimConfigProperty *prop) +{ + int error = 0; config_t conf; - int ret; - const char *readonly_str = "readonly"; + int ret = 0; + const char *value_string = NULL; + + /* try only once */ + if (prop->have_read == 1) { + return 0; + } + prop->have_read = 1; config_init(&conf); @@ -121,24 +147,84 @@ static int is_read_only(void) if (ret == CONFIG_FALSE) { CU_DEBUG("Error reading config file at line %d: '%s'\n", conf.error_line, conf.error_text); + error = -1; goto out; } - ret = config_lookup_bool(&conf, readonly_str, &readonly); - if (ret == CONFIG_FALSE) { - CU_DEBUG("'%s' not found in config file, assuming false\n", - readonly_str); - goto out; + switch (prop->value_type) { + case CONFIG_BOOL: + ret = config_lookup_bool(&conf, + prop->name, &prop->value_bool); + if (ret == CONFIG_FALSE) { + CU_DEBUG("Bool property '%s' in config file '%s' " + "not found.", + prop->name, LIBVIRTCIM_CONF); + error = -1; + goto out; + } + + CU_DEBUG("Bool property '%s' in config file '%s' is '%d'.", + prop->name, LIBVIRTCIM_CONF, prop->value_bool); + break; + case CONFIG_STRING: + ret = config_lookup_string(&conf, + prop->name, &value_string); + if (ret == CONFIG_FALSE) { + CU_DEBUG("String property '%s' in config file '%s' " + "not found.", + prop->name, LIBVIRTCIM_CONF); + error = -1; + goto out; + } + + CU_DEBUG("String property '%s' in config file '%s' is '%s'.", + prop->name, LIBVIRTCIM_CONF, value_string); + + if (prop->value_string) { + CU_DEBUG("String property '%s' have value '%s', will " + "be overwritten.", + prop->name, prop->value_string); + free(prop->value_string); + } + prop->value_string = strdup(value_string); + if (!prop->value_string) { + CU_DEBUG("Failed in duplicate value '%s'", + value_string); + error = -1; + goto out; + } + break; + default: + CU_DEBUG("Got invalid property type request %d.", + prop->value_type); + error = -1; + break; } - CU_DEBUG("'%s' value in '%s' config file: %d\n", readonly_str, - LIBVIRTCIM_CONF, readonly); out: config_destroy(&conf); + return error; +} +#else +static int libvirt_cim_config_get(LibvirtcimConfigProperty *prop) +{ + /* try only once */ + if (prop->have_read == 1) { + return 0; + } + prop->have_read = 1; + + CU_DEBUG("Built without libconfig, can't read '%s'.", prop->name); + return -2; +} #endif - /* Default value is 0 (false) */ - return readonly; +static int is_read_only(void) +{ + static LibvirtcimConfigProperty prop = { + "readonly", CONFIG_BOOL, {0}, 0}; + libvirt_cim_config_get(&prop); + return prop.value_bool; } virConnectPtr connect_by_classname(const CMPIBroker *broker, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:50 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:50 +0800 Subject: [Libvirt-cim] [PATCH V6 10/20] CSI: Move native CSI code together In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-11-git-send-email-xiawenc@linux.vnet.ibm.com> This is a pure code move patch. Now codes using libvirt event or native event, are moved into one macro protection, which make code easy to read, and in futher they can be moved into new file as CSI-libvirt.c. This patch also fix code style problem in moved code. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- src/Virt_ComputerSystemIndication.c | 851 ++++++++++++++++++----------------- 1 files changed, 429 insertions(+), 422 deletions(-) diff --git a/src/Virt_ComputerSystemIndication.c b/src/Virt_ComputerSystemIndication.c index ef449ff..247143c 100644 --- a/src/Virt_ComputerSystemIndication.c +++ b/src/Virt_ComputerSystemIndication.c @@ -83,106 +83,6 @@ 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}}; -#ifndef USE_LIBVIRT_EVENT -#else -/* - * Domain manipulation - */ -static void csi_dom_xml_free(void *data) -{ - csi_dom_xml_t *dom = (csi_dom_xml_t *) data; - free(dom->xml); - free(dom->name); - free(dom); -} - -static int csi_dom_xml_cmp(void *data, void *cmp_cb_data) -{ - csi_dom_xml_t *dom = (csi_dom_xml_t *) data; - const char *uuid = (const char *) cmp_cb_data; - - return strcmp(dom->uuid, uuid); -} - -static int csi_dom_xml_set(csi_dom_xml_t *dom, virDomainPtr dom_ptr, CMPIStatus *s) -{ - const char *name; - - name = virDomainGetName(dom_ptr); - if (name == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get domain name"); - return -1; - } - - dom->name = strdup(name); - - /* xml */ - dom->xml = virDomainGetXMLDesc(dom_ptr, - VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); - if (dom->xml == NULL) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get xml desc"); - return -1; - } - - return 0; -} - -static csi_dom_xml_t *csi_dom_xml_new(virDomainPtr dom_ptr, CMPIStatus *s) -{ - int rc; - csi_dom_xml_t *dom; - - dom = calloc(1, sizeof(*dom)); - if (dom == NULL) - return NULL; - - /* uuid */ - rc = virDomainGetUUIDString(dom_ptr, dom->uuid); - if (rc == -1) { - cu_statusf(_BROKER, s, - CMPI_RC_ERR_FAILED, - "Failed to get domain UUID"); - goto error; - } - - if (csi_dom_xml_set(dom, dom_ptr, s) == -1) - goto error; - - return dom; - - error: - csi_dom_xml_free(dom); - return NULL; -} - -static void csi_thread_dom_list_append(csi_thread_data_t *thread, - csi_dom_xml_t *dom) -{ - if (thread->dom_list == NULL) - thread->dom_list = list_new(csi_dom_xml_free, csi_dom_xml_cmp); - - list_append(thread->dom_list, dom); -} - -static void csi_free_thread_data(void *data) -{ - csi_thread_data_t *thread = (csi_thread_data_t *) 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); -} -#endif - void set_source_inst_props(const CMPIBroker *broker, const CMPIContext *context, const CMPIObjectPath *ref, @@ -388,6 +288,64 @@ static bool create_deleted_guest_inst(const char *xml, return rc; } +static int platform_from_class(const char *cn) +{ + if (STARTS_WITH(cn, "Xen")) { + return CSI_XEN; + } else if (STARTS_WITH(cn, "KVM")) { + return CSI_KVM; + } else if (STARTS_WITH(cn, "LXC")) { + return CSI_LXC; + } else { + return -1; + } +} + +static _EI_RTYPE EnableIndications(CMPIIndicationMI *mi, + const CMPIContext *ctx) +{ + CU_DEBUG("EnableIndications"); + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = true; + pthread_mutex_unlock(&lifecycle_mutex); + + _EI_RET(); +} + +static _EI_RTYPE DisableIndications(CMPIIndicationMI *mi, + const CMPIContext *ctx) +{ + CU_DEBUG("DisableIndications"); + pthread_mutex_lock(&lifecycle_mutex); + lifecycle_enabled = false; + pthread_mutex_unlock(&lifecycle_mutex); + + _EI_RET(); +} + +DECLARE_FILTER(xen_created, "Xen_ComputerSystemCreatedIndication"); +DECLARE_FILTER(xen_deleted, "Xen_ComputerSystemDeletedIndication"); +DECLARE_FILTER(xen_modified, "Xen_ComputerSystemModifiedIndication"); +DECLARE_FILTER(kvm_created, "KVM_ComputerSystemCreatedIndication"); +DECLARE_FILTER(kvm_deleted, "KVM_ComputerSystemDeletedIndication"); +DECLARE_FILTER(kvm_modified, "KVM_ComputerSystemModifiedIndication"); +DECLARE_FILTER(lxc_created, "LXC_ComputerSystemCreatedIndication"); +DECLARE_FILTER(lxc_deleted, "LXC_ComputerSystemDeletedIndication"); +DECLARE_FILTER(lxc_modified, "LXC_ComputerSystemModifiedIndication"); + +static struct std_ind_filter *filters[] = { + &xen_created, + &xen_deleted, + &xen_modified, + &kvm_created, + &kvm_deleted, + &kvm_modified, + &lxc_created, + &lxc_deleted, + &lxc_modified, + NULL, +}; + #ifndef USE_LIBVIRT_EVENT /* libvirt-cim's private CSI implement */ @@ -775,7 +733,377 @@ static CMPI_THREAD_RETURN lifecycle_thread_native(void *params) return (CMPI_THREAD_RETURN) 0; } + +static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean first) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + struct std_indication_ctx *_ctx; + struct ind_args *args = NULL; + int platform; + bool error = false; + csi_thread_data_t *thread = NULL; + + CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); + + pthread_mutex_lock(&lifecycle_mutex); + + CU_DEBUG("Using libvirt-cim's event implemention."); + + _ctx = (struct std_indication_ctx *)mi->hdl; + + if (CMIsNullObject(op)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "No ObjectPath given"); + goto out; + } + + /* FIXME: op is stale the second time around, for some reason */ + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + thread = &csi_thread_data[platform]; + thread->active_filters += 1; + + /* Check if thread is already running */ + if (thread->id > 0) { + goto out; + } + + args = malloc(sizeof(*args)); + if (args == NULL) { + CU_DEBUG("Failed to allocate ind_args"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to allocate ind_args"); + error = true; + goto out; + } + + args->context = CBPrepareAttachThread(_BROKER, ctx); + if (args->context == NULL) { + CU_DEBUG("Failed to create thread context"); + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Unable to create thread context"); + error = true; + goto out; + } + + args->ns = strdup(NAMESPACE(op)); + args->classname = strdup(CLASSNAME(op)); + args->_ctx = _ctx; + + thread->args = args; + + thread->id = _BROKER->xft->newThread(lifecycle_thread_native, + thread, 0); + + if (thread->id <= 0) { + CU_DEBUG("Error, failed to create new thread."); + error = true; + } + + out: + if (error == true) { + thread->active_filters -= 1; + free(args); + } + + pthread_mutex_unlock(&lifecycle_mutex); + + return s; +} + +static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, + const CMPIContext *ctx, + const CMPISelectExp *se, + const char *ns, + const CMPIObjectPath *op, + CMPIBoolean last) +{ + int platform; + CMPIStatus s = {CMPI_RC_OK, NULL}; + + CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); + + platform = platform_from_class(CLASSNAME(op)); + if (platform < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Unknown platform"); + goto out; + } + + + pthread_mutex_lock(&lifecycle_mutex); + csi_thread_data[platform].active_filters -= 1; + pthread_mutex_unlock(&lifecycle_mutex); + + pthread_cond_signal(&lifecycle_cond); + + out: + return s; +} + +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)); + if (!args->classname || !args->ns) { + CU_DEBUG("Failed in strdup"); + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed in strdup in indication raising"); + goto out; + } + 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; +} + +static struct std_indication_handler csi = { + .raise_fn = raise_indication, + .trigger_fn = trigger_indication, + .activate_fn = ActivateFilter, + .deactivate_fn = DeActivateFilter, + .enable_fn = EnableIndications, + .disable_fn = DisableIndications, +}; #else +/* Using libvirt's event to implement CSI */ + +/* + * Domain manipulation + */ +static void csi_dom_xml_free(void *data) +{ + csi_dom_xml_t *dom = (csi_dom_xml_t *) data; + free(dom->xml); + free(dom->name); + free(dom); +} + +static int csi_dom_xml_cmp(void *data, void *cmp_cb_data) +{ + csi_dom_xml_t *dom = (csi_dom_xml_t *) data; + const char *uuid = (const char *) cmp_cb_data; + + return strcmp(dom->uuid, uuid); +} + +static int csi_dom_xml_set(csi_dom_xml_t *dom, + virDomainPtr dom_ptr, + CMPIStatus *s) +{ + const char *name; + + name = virDomainGetName(dom_ptr); + if (name == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get domain name"); + return -1; + } + + dom->name = strdup(name); + + /* xml */ + dom->xml = virDomainGetXMLDesc(dom_ptr, + VIR_DOMAIN_XML_INACTIVE | VIR_DOMAIN_XML_SECURE); + if (dom->xml == NULL) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get xml desc"); + return -1; + } + + return 0; +} + +static csi_dom_xml_t *csi_dom_xml_new(virDomainPtr dom_ptr, CMPIStatus *s) +{ + int rc; + csi_dom_xml_t *dom; + + dom = calloc(1, sizeof(*dom)); + if (dom == NULL) { + return NULL; + } + + /* uuid */ + rc = virDomainGetUUIDString(dom_ptr, dom->uuid); + if (rc == -1) { + cu_statusf(_BROKER, s, + CMPI_RC_ERR_FAILED, + "Failed to get domain UUID"); + goto error; + } + + if (csi_dom_xml_set(dom, dom_ptr, s) == -1) { + goto error; + } + + return dom; + + error: + csi_dom_xml_free(dom); + return NULL; +} + +static void csi_thread_dom_list_append(csi_thread_data_t *thread, + csi_dom_xml_t *dom) +{ + if (thread->dom_list == NULL) { + thread->dom_list = list_new(csi_dom_xml_free, csi_dom_xml_cmp); + } + + list_append(thread->dom_list, dom); +} + +static void csi_free_thread_data(void *data) +{ + csi_thread_data_t *thread = (csi_thread_data_t *) 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); +} + static bool async_ind(struct ind_args *args, int ind_type, csi_dom_xml_t *dom, @@ -1059,176 +1387,7 @@ static CMPI_THREAD_RETURN lifecycle_thread(void *params) free(prefix); return (CMPI_THREAD_RETURN) 0; } -#endif - -static int platform_from_class(const char *cn) -{ - if (STARTS_WITH(cn, "Xen")) - return CSI_XEN; - else if (STARTS_WITH(cn, "KVM")) - return CSI_KVM; - else if (STARTS_WITH(cn, "LXC")) - return CSI_LXC; - else - return -1; -} - -#ifndef USE_LIBVIRT_EVENT -static CMPIStatus ActivateFilter(CMPIIndicationMI *mi, - const CMPIContext *ctx, - const CMPISelectExp *se, - const char *ns, - const CMPIObjectPath *op, - CMPIBoolean first) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; - struct std_indication_ctx *_ctx; - struct ind_args *args = NULL; - int platform; - bool error = false; - csi_thread_data_t *thread = NULL; - - CU_DEBUG("ActivateFilter for %s", CLASSNAME(op)); - - pthread_mutex_lock(&lifecycle_mutex); - - CU_DEBUG("Using libvirt-cim's event implemention."); - - _ctx = (struct std_indication_ctx *)mi->hdl; - - if (CMIsNullObject(op)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No ObjectPath given"); - goto out; - } - - /* FIXME: op is stale the second time around, for some reason */ - platform = platform_from_class(CLASSNAME(op)); - if (platform < 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unknown platform"); - goto out; - } - - thread = &csi_thread_data[platform]; - thread->active_filters += 1; - - /* Check if thread is already running */ - if (thread->id > 0) { - goto out; - } - - args = malloc(sizeof(*args)); - if (args == NULL) { - CU_DEBUG("Failed to allocate ind_args"); - cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Unable to allocate ind_args"); - error = true; - goto out; - } - - args->context = CBPrepareAttachThread(_BROKER, ctx); - if (args->context == NULL) { - CU_DEBUG("Failed to create thread context"); - cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, - "Unable to create thread context"); - error = true; - goto out; - } - - args->ns = strdup(NAMESPACE(op)); - args->classname = strdup(CLASSNAME(op)); - args->_ctx = _ctx; - - thread->args = args; - - thread->id = _BROKER->xft->newThread(lifecycle_thread_native, - thread, 0); - - if (thread->id <= 0) { - CU_DEBUG("Error, failed to create new thread."); - error = true; - } - - out: - if (error == true) { - thread->active_filters -= 1; - free(args); - } - - pthread_mutex_unlock(&lifecycle_mutex); - - return s; -} - -static CMPIStatus DeActivateFilter(CMPIIndicationMI *mi, - const CMPIContext *ctx, - const CMPISelectExp *se, - const char *ns, - const CMPIObjectPath *op, - CMPIBoolean last) -{ - int platform; - CMPIStatus s = {CMPI_RC_OK, NULL}; - - CU_DEBUG("DeActivateFilter for %s", CLASSNAME(op)); - platform = platform_from_class(CLASSNAME(op)); - if (platform < 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unknown platform"); - goto out; - } - - - pthread_mutex_lock(&lifecycle_mutex); - csi_thread_data[platform].active_filters -= 1; - pthread_mutex_unlock(&lifecycle_mutex); - - pthread_cond_signal(&lifecycle_cond); - - out: - return s; -} - -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; -} -#else static CMPIStatus ActivateFilter(CMPIIndicationMI* mi, const CMPIContext* ctx, const CMPISelectExp* se, @@ -1348,166 +1507,14 @@ static CMPIStatus DeActivateFilter(CMPIIndicationMI* mi, out: return s; } -#endif - -static _EI_RTYPE EnableIndications(CMPIIndicationMI* mi, - const CMPIContext *ctx) -{ - CU_DEBUG("EnableIndications"); - pthread_mutex_lock(&lifecycle_mutex); - lifecycle_enabled = true; - pthread_mutex_unlock(&lifecycle_mutex); - - _EI_RET(); -} - -static _EI_RTYPE DisableIndications(CMPIIndicationMI* mi, - const CMPIContext *ctx) -{ - CU_DEBUG("DisableIndications"); - pthread_mutex_lock(&lifecycle_mutex); - lifecycle_enabled = false; - pthread_mutex_unlock(&lifecycle_mutex); - - _EI_RET(); -} - -DECLARE_FILTER(xen_created, "Xen_ComputerSystemCreatedIndication"); -DECLARE_FILTER(xen_deleted, "Xen_ComputerSystemDeletedIndication"); -DECLARE_FILTER(xen_modified, "Xen_ComputerSystemModifiedIndication"); -DECLARE_FILTER(kvm_created, "KVM_ComputerSystemCreatedIndication"); -DECLARE_FILTER(kvm_deleted, "KVM_ComputerSystemDeletedIndication"); -DECLARE_FILTER(kvm_modified, "KVM_ComputerSystemModifiedIndication"); -DECLARE_FILTER(lxc_created, "LXC_ComputerSystemCreatedIndication"); -DECLARE_FILTER(lxc_deleted, "LXC_ComputerSystemDeletedIndication"); -DECLARE_FILTER(lxc_modified, "LXC_ComputerSystemModifiedIndication"); - -static struct std_ind_filter *filters[] = { - &xen_created, - &xen_deleted, - &xen_modified, - &kvm_created, - &kvm_deleted, - &kvm_modified, - &lxc_created, - &lxc_deleted, - &lxc_modified, - NULL, -}; - -#ifndef USE_LIBVIRT_EVENT -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)); - if (!args->classname || !args->ns) { - CU_DEBUG("Failed in strdup"); - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Failed in strdup in indication raising"); - goto out; - } - 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, .disable_fn = DisableIndications, }; +#endif DEFAULT_IND_CLEANUP(); DEFAULT_AF(); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:40 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:40 +0800 Subject: [Libvirt-cim] [PATCH V6 00/20] Bug fix patches for 0.6.2 Message-ID: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> This serial fix a batch of issues. v6: general change: rebase and add John Ferlan's patches after the tail. 2/20: do not add this property now, just fixed the spelling in code, since it is only set when Xen is used in libvirt-cim, so it is OK. 3/20: also fixed debug print spelling. 5/20: squashed patch for debug print crash issues. 6/20: spelling fix in commit message. 7/20: skipped free_diskpool on fail of setting parent pool, refined the code in get_diskpool_config() when libvirt pool was not used, removed the duplicated macro in .c file, set member to NULL in parse_diskpool_line when fail. 8/20: squashed the patch with John Ferlan's one about "adjust logic" for it. 11/20: free the domain ptr after domain name retrieving. 13/20: rename no_root_ssh_key to use_non_root_ssh_key, fail when file can't be deleted before copy in ssh_key_copy(). 17/20: small code style change for {} in if condition. 18/20: added a macro to activate it. 19/20: added three macro to activate them, added {} in if statement when only one sentence follow. John Ferlan (7): 14 Makefile.am: Remove the $(top_srcdir) from subst command 15 libvirt-cim.spec: Use systemctl for tog-pegasus restart 16 Remove empty newline at bottom 17 xmlgen: Only support script on bridge for xen domains 18 libxkutil: Use virConnectListAllDomains() to fetch domains 19 DevicePool: Use the virConnectListAll interfaces 20 register: Adjust the chatter output Wenchao Xia (13): 1 Remove property CreationClassName in some instance 2 SDC: Fix spelling for property IsFullVirt 3 SDC: use property BootDevices instead of BootDevice 4 do not deregister virt classes in yum upgrade 5 CSI, DevicePool, RASDIndication: fix debug print crash 6 CSI, add lock to protect shared data in lifecycle_thread 7 DevicePool, reimplement get_diskpool_config with libvirt 8 device parsing, add debug print 9 CSI Discard libvirt event by default 10 CSI: Move native CSI code together 11 VSSD: report success if not all VS fail in enum 12 misc_util: better way to read config 13 migration: allow ssh based migration with non root's key file Makefile.am | 18 +- libvirt-cim.conf | 19 + libvirt-cim.spec.in | 24 +- libxkutil/cs_util_instance.c | 26 + libxkutil/device_parsing.c | 19 +- libxkutil/misc_util.c | 135 +++- libxkutil/misc_util.h | 6 +- libxkutil/xmlgen.c | 26 +- provider-register.sh | 9 +- schema/SwitchService.registration | 1 - src/Virt_AllocationCapabilities.c | 3 +- src/Virt_ComputerSystem.c | 66 ++- src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- src/Virt_ConsoleRedirectionService.c | 3 +- src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- src/Virt_Device.c | 18 +- src/Virt_DevicePool.c | 480 ++++++++-- src/Virt_DevicePool.h | 4 + src/Virt_EnabledLogicalElementCapabilities.c | 3 +- src/Virt_FilterEntry.c | 3 +- src/Virt_FilterList.c | 3 +- src/Virt_HostSystem.c | 3 +- src/Virt_KVMRedirectionSAP.c | 3 +- src/Virt_RASD.c | 3 +- src/Virt_ReferencedProfile.c | 3 +- src/Virt_RegisteredProfile.c | 3 +- src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- src/Virt_ResourcePoolConfigurationService.c | 8 +- src/Virt_SettingsDefineCapabilities.c | 14 +- src/Virt_SwitchService.c | 3 +- src/Virt_VSMigrationCapabilities.c | 3 +- src/Virt_VSMigrationService.c | 270 +++++- src/Virt_VSMigrationSettingData.c | 3 +- src/Virt_VSSD.c | 50 +- src/Virt_VirtualSystemManagementCapabilities.c | 3 +- src/Virt_VirtualSystemManagementService.c | 67 ++- src/Virt_VirtualSystemSnapshotService.c | 3 +- ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- 39 files changed, 1990 insertions(+), 348 deletions(-) From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:54 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:54 +0800 Subject: [Libvirt-cim] [PATCH V6 14/20] Makefile.am: Remove the $(top_srcdir) from subst command In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-15-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan During the postinstall and preuninstall phases various variables are modified to build up the list of mofs to be installed. The generated output had ".//usr/local/share/libvirt-cim/*" which caused issues finding files. This is a followup to commit '22022870' which changed the paths using to schema for each of the variables. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- Makefile.am | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Makefile.am b/Makefile.am index 0fdd8bb..63ed3c7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -189,7 +189,7 @@ install-data-local: $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_MOFS) $(install_sh_DATA) -t "$(DESTDIR)$(pkgdatadir)" $(INTEROP_REGS) if [[ @CIMSERVER@ != pegasus ]]; then \ - sed -i '/^# --/,/^# --!/d' $(subst ./schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ + sed -i '/^# --/,/^# --!/d' $(subst $(top_srcdir)/schema,$(DESTDIR)$(pkgdatadir), $(PGINTEROP_REGS)); \ fi uninstall-local: @@ -206,21 +206,21 @@ preinstall: # Un/Register the providers and class definitions from/to the current CIMOM. # @CIMSERVER@ is set by the configure script postinstall: - sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi virsh -v | grep -q '^0.3' && cp examples/diskpool.conf $(DISK_POOL_CONFIG) || true mkdir -p $(INFO_STORE) preuninstall: - sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst schema,$(pkgdatadir), $(REGS)) -m $(subst schema,$(pkgdatadir), $(MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(INTEROP_MOFS)) - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst schema,$(pkgdatadir), $(CIMV2_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n @CIM_VIRT_NS@ -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/interop -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(INTEROP_MOFS)) + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/cimv2 -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(CIMV2_MOFS)) if [[ @CIMSERVER@ = pegasus ]]; then \ - sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ + sh provider-register.sh -v -d -t @CIMSERVER@ -n root/PG_InterOp -r $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_REGS)) -m $(subst $(top_srcdir)/schema,$(pkgdatadir), $(PGINTEROP_MOFS)); \ fi rpm: clean -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:44 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:44 +0800 Subject: [Libvirt-cim] [PATCH V6 04/20] do not deregister virt classes in yum upgrade In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-5-git-send-email-xiawenc@linux.vnet.ibm.com> Now yum upgrade will deregister the virt classes, make libvirt-cim not workable. This patch fixed it from now on. Signed-off-by: Wenchao Xia Reviewed-by: John Ferlan --- libvirt-cim.spec.in | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in index d78eee7..3def978 100644 --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -104,18 +104,22 @@ rm -fr $RPM_BUILD_ROOT -r %{CIMV2_REG} -m %{CIMV2_MOF} -v >/dev/null 2>&1 || true %preun -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ +#Deregister only in uninstall, do nothing in upgrade. +if [ "$1" = "0" ]; then + echo "Deleting registered classes in libvirt-cim..." + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n @CIM_VIRT_NS@ \ -r %{REGISTRATION} -m %{SCHEMA} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/interop \ -r %{INTEROP_REG} -m %{INTEROP_MOF} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/PG_InterOp \ -r %{PGINTEROP_REG} -m %{PGINTEROP_MOF} >/dev/null 2>&1 || true -%{_datadir}/%{name}/provider-register.sh -d -t pegasus \ + %{_datadir}/%{name}/provider-register.sh -d -t pegasus \ -n root/cimv2 \ -r %{CIMV2_REG} -m %{CIMV2_MOF} >/dev/null 2>&1 || true +fi %postun -p /sbin/ldconfig -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:56 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:56 +0800 Subject: [Libvirt-cim] [PATCH V6 16/20] Remove empty newline at bottom In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-17-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- schema/SwitchService.registration | 1 - 1 files changed, 0 insertions(+), 1 deletions(-) diff --git a/schema/SwitchService.registration b/schema/SwitchService.registration index b8e4f23..82a5c04 100644 --- a/schema/SwitchService.registration +++ b/schema/SwitchService.registration @@ -3,4 +3,3 @@ Xen_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance KVM_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance LXC_SwitchService root/virt Virt_SwitchService Virt_SwitchService instance - -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:57 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:57 +0800 Subject: [Libvirt-cim] [PATCH V6 17/20] xmlgen: Only support script on bridge for xen domains In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-18-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan A change was made in 0.9.10 to disallow a script on a bridge device for qemu guests, see 'libvirt' commit id '1734cdb99'. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- libxkutil/xmlgen.c | 26 ++++++++++++++++---------- 1 files changed, 16 insertions(+), 10 deletions(-) diff --git a/libxkutil/xmlgen.c b/libxkutil/xmlgen.c index 2dcd0d2..94fb7d3 100644 --- a/libxkutil/xmlgen.c +++ b/libxkutil/xmlgen.c @@ -270,16 +270,22 @@ static const char *set_net_source(xmlNodePtr nic, } -static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev) +static const char *bridge_net_to_xml(xmlNodePtr nic, struct net_device *dev, + int domtype) { const char *script = "vif-bridge"; xmlNodePtr tmp; const char *msg = NULL; - tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); - if (tmp == NULL) - return XML_ERROR; - xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + /* Scripts only supported on Xen guests see 'libvirt' + * commit id 1734cdb99 (since 0.9.10) */ + if (domtype == DOMAIN_XENPV || domtype == DOMAIN_XENFV) { + tmp = xmlNewChild(nic, NULL, BAD_CAST "script", NULL); + if (tmp == NULL) { + return XML_ERROR; + } + xmlNewProp(tmp, BAD_CAST "path", BAD_CAST script); + } msg = set_net_source(nic, dev, "bridge"); @@ -375,13 +381,13 @@ static const char *net_xml(xmlNodePtr root, struct domain *dominfo) } #endif - if (STREQ(dev->dev.net.type, "network")) + if (STREQ(dev->dev.net.type, "network")) { msg = set_net_source(nic, net, "network"); - else if (STREQ(dev->dev.net.type, "bridge")) - msg = bridge_net_to_xml(nic, net); - else if (STREQ(dev->dev.net.type, "user")) + } else if (STREQ(dev->dev.net.type, "bridge")) { + msg = bridge_net_to_xml(nic, net, dominfo->type); + } else if (STREQ(dev->dev.net.type, "user")) { continue; - else if (STREQ(dev->dev.net.type, "direct")) { + } else if (STREQ(dev->dev.net.type, "direct")) { msg = set_net_source(nic, net, "direct"); if (net->vsi.vsi_type != NULL) { struct vsi_device *vsi = &dev->dev.net.vsi; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:51 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:51 +0800 Subject: [Libvirt-cim] [PATCH V6 11/20] VSSD: report success if not all VS fail in enum In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-12-git-send-email-xiawenc@linux.vnet.ibm.com> Original code 'continue' in the 'for' in return_enum_vssd() when one VSDS fail in retrieving, but forgot to set s to normal. This patch fix this case. Also many debug message is added to log the error if met. Signed-off-by: Wenchao Xia --- src/Virt_VSSD.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 43 insertions(+), 4 deletions(-) diff --git a/src/Virt_VSSD.c b/src/Virt_VSSD.c index 975623b..24bf908 100644 --- a/src/Virt_VSSD.c +++ b/src/Virt_VSSD.c @@ -181,8 +181,10 @@ static int instance_from_dom(const CMPIBroker *broker, struct domain *dominfo = NULL; ret = get_dominfo(dom, &dominfo); - if (!ret) + if (!ret) { + CU_DEBUG("Failed in get_dominfo()."); goto out; + } op = CMGetObjectPath(inst, NULL); pfx = class_prefix_name(CLASSNAME(op)); @@ -245,6 +247,7 @@ static int instance_from_dom(const CMPIBroker *broker, (dominfo->type == DOMAIN_KVM) || (dominfo->type == DOMAIN_QEMU)) { s = _set_fv_prop(broker, dominfo, inst); if (s.rc != CMPI_RC_OK) { + CU_DEBUG("Failed to set full virtual props."); ret = 0; goto out; } @@ -259,6 +262,7 @@ static int instance_from_dom(const CMPIBroker *broker, dominfo->type); if (asprintf(&vsid, "%s:%s", pfx, dominfo->name) == -1) { + CU_DEBUG("Failed in asprintf()."); ret = 0; goto out; } @@ -312,7 +316,7 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, virConnectPtr conn; virDomainPtr *list; int count; - int i; + int i, fail_count = 0; CMPIStatus s = {CMPI_RC_OK, NULL}; conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); @@ -333,9 +337,29 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, inst = _get_vssd(_BROKER, reference, conn, list[i], &s); - virDomainFree(list[i]); - if (inst == NULL) + if (inst == NULL) { + /* log the error */ + const char *dom_name = virDomainGetName(list[i]); + if (s.msg) { + CU_DEBUG("Failed to get VSSD instance from " + "domain [%s], status msg [%s].", + dom_name, CMGetCharPtr(s.msg)); + } else { + CU_DEBUG("Failed to get VSSD instance from " + "domain [%s].", + dom_name); + } + /* restore s until last one */ + if (i < count - 1) { + cu_statusf(_BROKER, &s, + CMPI_RC_OK, + "NULL"); + } + fail_count++; + virDomainFree(list[i]); continue; + } + virDomainFree(list[i]); if (names_only) cu_return_instance_name(results, inst); @@ -343,6 +367,21 @@ static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, CMReturnInstance(results, inst); } + /* check if some VS fail */ + if (fail_count > 0) { + CU_DEBUG("Failed to get %d VSSD in enum, total is %d.", + fail_count, count); + if (fail_count < count) { + /* consider it succeed, some VSSD will be returned */ + cu_statusf(_BROKER, &s, + CMPI_RC_OK, + "Got %d/%d VSSD, " + "some VS may changed during enum", + count - fail_count, count); + } + } + + out: free(list); virConnectClose(conn); -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:53 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:53 +0800 Subject: [Libvirt-cim] [PATCH V6 13/20] migration: allow ssh based migration with non root's key file In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-14-git-send-email-xiawenc@linux.vnet.ibm.com> This patch allow libvirt-cim to use non-root's ssh key in migration to avoid exposing root's ssh login on server. In some case server are forbidden to expose or provide any root ssh login, and still use ssh encryption between two migration nodes with key of special account created for virtual machine management. When it is enabled in config file: 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key to be copied. It will be copied to [migrate_ssh_temp_key]. 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, use bool property [MigrationWithoutRootKey], to tell whether to use the key as [migrate_ssh_temp_key]. 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be deleted. Details: libvirt-cim would run shell command "cp -f [SSH_Key_Src] [migrate_ssh_temp_key]", then use [migrate_ssh_temp_key] to generate uri suffix for remote connection to migration destination. Signed-off-by: Wenchao Xia --- libvirt-cim.conf | 19 +++ libxkutil/misc_util.c | 9 ++ libxkutil/misc_util.h | 3 + src/Virt_VSMigrationService.c | 264 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 290 insertions(+), 5 deletions(-) diff --git a/libvirt-cim.conf b/libvirt-cim.conf index d3cb2c3..37d7b0f 100644 --- a/libvirt-cim.conf +++ b/libvirt-cim.conf @@ -11,3 +11,22 @@ # Default value: false # # readonly = false; + +# migrate_ssh_temp_key (string) +# Defines a temp key file which would be used as ssh key in ssh migration, +# Only when it is set, following methods in VirtualSystemMigrationService +# could be used: +# 1 MigrateSSHKeyCopy, use string property [SSH_Key_Src] to tell which key +# to be copied. It will be copied to [migrate_ssh_temp_key]. +# 2 MigrateVirtualSystemToHost and CheckVirtualSystemIsMigratableToHost, +# use bool property [MigrationWithoutRootKey], to tell whether to use the key +# as [migrate_ssh_temp_key]. +# 3 MigrateSSHKeyDelete, when it is called [migrate_ssh_temp_key] will be +# deleted. +# Note: migrate_ssh_temp_key must be set in a directory completely owned by +# root from bottom to top, such as /root/A, or /tmp/A. +# +# Possible values: {any path plus filename on host} +# Default value: NULL, that is not set. +# +# migrate_ssh_temp_key = "/root/vm_migrate_tmp_id_rsa"; diff --git a/libxkutil/misc_util.c b/libxkutil/misc_util.c index 820b42d..00eb4b1 100644 --- a/libxkutil/misc_util.c +++ b/libxkutil/misc_util.c @@ -227,6 +227,15 @@ static int is_read_only(void) return prop.value_bool; } +const char *get_mig_ssh_tmp_key(void) +{ + static LibvirtcimConfigProperty prop = { + "migrate_ssh_temp_key", CONFIG_STRING, {0}, 0}; + + libvirt_cim_config_get(&prop); + return prop.value_string; +} + virConnectPtr connect_by_classname(const CMPIBroker *broker, const char *classname, CMPIStatus *s) diff --git a/libxkutil/misc_util.h b/libxkutil/misc_util.h index 90fb2da..0f52290 100644 --- a/libxkutil/misc_util.h +++ b/libxkutil/misc_util.h @@ -152,6 +152,9 @@ int virt_set_status(const CMPIBroker *broker, #define REF2STR(r) CMGetCharPtr(CMObjectPathToString(r, NULL)) +/* get libvirt-cim config */ +const char *get_mig_ssh_tmp_key(void); + /* * Local Variables: * mode: C diff --git a/src/Virt_VSMigrationService.c b/src/Virt_VSMigrationService.c index 1f6659d..c701e7d 100644 --- a/src/Virt_VSMigrationService.c +++ b/src/Virt_VSMigrationService.c @@ -150,6 +150,7 @@ static CMPIStatus get_migration_uri(CMPIInstance *msd, static char *dest_uri(const char *cn, const char *dest, + const char *dest_params, uint16_t transport) { const char *prefix; @@ -157,6 +158,7 @@ static char *dest_uri(const char *cn, const char *param = ""; char *uri = NULL; int rc; + int param_labeled = 0; if (STARTS_WITH(cn, "Xen")) prefix = "xen"; @@ -197,16 +199,54 @@ static char *dest_uri(const char *cn, goto out; } - if (!STREQC(param, "")) + if (!STREQC(param, "")) { rc = asprintf(&uri, "%s/%s", uri, param); + param_labeled = 1; + } - if (rc == -1) + if (rc == -1) { uri = NULL; + goto out; + } + if (dest_params) { + if (param_labeled == 0) { + rc = asprintf(&uri, "%s?%s", uri, dest_params); + } else { + /* ? is already added */ + rc = asprintf(&uri, "%s%s", uri, dest_params); + } + if (rc == -1) { + uri = NULL; + goto out; + } + } out: return uri; } +/* Todo: move it to libcmpiutil */ +static CMPIrc cu_get_bool_arg_my(const CMPIArgs *args, + const char *name, + bool *target) +{ + CMPIData argdata; + CMPIStatus s; + + argdata = CMGetArg(args, name, &s); + if ((s.rc != CMPI_RC_OK) || CMIsNullValue(argdata)) { + return CMPI_RC_ERR_INVALID_PARAMETER; + } + + if (argdata.type != CMPI_boolean) { + return CMPI_RC_ERR_TYPE_MISMATCH; + } + + *target = (bool)argdata.value.boolean; + + return CMPI_RC_OK; +} + static CMPIStatus get_msd_values(const CMPIObjectPath *ref, const char *destination, const CMPIArgs *argsin, @@ -217,6 +257,13 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, CMPIInstance *msd; uint16_t uri_type; char *uri = NULL; + bool use_non_root_ssh_key = false; + char *dest_params = NULL; + int ret; + + cu_get_bool_arg_my(argsin, + "MigrationWithoutRootKey", + &use_non_root_ssh_key); s = get_msd(ref, argsin, &msd); if (s.rc != CMPI_RC_OK) @@ -230,7 +277,27 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, if (s.rc != CMPI_RC_OK) goto out; - uri = dest_uri(CLASSNAME(ref), destination, uri_type); + if (use_non_root_ssh_key) { + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + CU_DEBUG("Trying migrate with specified ssh key file [%s].", + tmp_keyfile); + ret = asprintf(&dest_params, "keyfile=%s", tmp_keyfile); + if (ret < 0) { + CU_DEBUG("Failed in generating param string."); + goto out; + } + } + + uri = dest_uri(CLASSNAME(ref), destination, dest_params, uri_type); if (uri == NULL) { cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, @@ -238,6 +305,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, goto out; } + CU_DEBUG("Migrate tring to connect remote host with uri %s.", uri); *conn = virConnectOpen(uri); if (*conn == NULL) { CU_DEBUG("Failed to connect to remote host (%s)", uri); @@ -249,7 +317,7 @@ static CMPIStatus get_msd_values(const CMPIObjectPath *ref, out: free(uri); - + free(dest_params); return s; } @@ -1538,7 +1606,7 @@ static CMPIStatus migrate_vs_host(CMPIMethodMI *self, const char *dhost = NULL; CMPIObjectPath *system; const char *name = NULL; - + cu_get_str_arg(argsin, "DestinationHost", &dhost); cu_get_ref_arg(argsin, "ComputerSystem", &system); @@ -1604,11 +1672,179 @@ static CMPIStatus migrate_vs_system(CMPIMethodMI *self, return migrate_do(ref, ctx, name, dname, argsin, results, argsout); } +/* return 0 on success */ +static int pipe_exec(const char *cmd) +{ + FILE *stream = NULL; + int ret = 0; + char buf[256]; + + CU_DEBUG("executing system cmd [%s].", cmd); + /* Todo: We need a better popen, currently stdout have been closed + and SIGCHILD is handled by tog-pegasus, so fgets always got NULL + making error detection not possible. */ + stream = popen(cmd, "r"); + if (stream == NULL) { + CU_DEBUG("Failed to open pipe to run the command."); + ret = -1; + goto out; + } + usleep(10000); + + buf[255] = 0; + while (fgets(buf, sizeof(buf), stream) != NULL) { + CU_DEBUG("Exception got: [%s].", buf); + ret = -2; + goto out; + } + + out: + if (stream != NULL) { + pclose(stream); + } + return ret; +} + +/* + * libvirt require private key specified to be placed in a directory owned by + * root, because libvirt-cim now runs as root. So here the key would be copied. + * In this way libvirt-cim could borrow a non-root ssh private key, instead of + * using root's private key, avoid security risk. + */ +static int ssh_key_copy(const char *src, const char *dest) +{ + char *cmd = NULL; + int ret = 0; + struct stat sb; + + /* try delete it */ + unlink(dest); + ret = stat(dest, &sb); + if (ret == 0) { + CU_DEBUG("Can not delete [%s] before copy, " + "maybe someone is using it.", + dest); + ret = -1; + goto out; + } + + ret = asprintf(&cmd, "cp -f %s %s", src, dest); + if (ret < 0) { + CU_DEBUG("Failed in combination for shell command."); + goto out; + } + + ret = pipe_exec(cmd); + if (ret < 0) { + CU_DEBUG("Error in executing command [%s]"); + goto out; + } + + ret = stat(dest, &sb); + if (ret < 0) { + CU_DEBUG("Can not find file [%s] after copy.", dest); + } + out: + free(cmd); + return ret; +} + +static CMPIStatus migrate_sshkey_copy(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *ssh_key_src = NULL; + int ret; + + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + + cu_get_str_arg(argsin, "SSH_Key_Src", &ssh_key_src); + if (!ssh_key_src) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Failed to get property 'SSH_Key_Src'."); + CU_DEBUG("Failed to get property 'SSH_Key_Src'."); + goto out; + } + + ret = ssh_key_copy(ssh_key_src, tmp_keyfile); + if (ret < 0) { + cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, + "Got error in copying ssh key from [%s] to [%s].", + ssh_key_src, tmp_keyfile); + CU_DEBUG("Got error in copying ssh key from [%s] to [%s].", + ssh_key_src, tmp_keyfile); + } + + out: + METHOD_RETURN(results, s.rc); + return s; +} + +static CMPIStatus migrate_sshkey_delete(CMPIMethodMI *self, + const CMPIContext *ctx, + const CMPIResult *results, + const CMPIObjectPath *ref, + const CMPIArgs *argsin, + CMPIArgs *argsout) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + int ret; + struct stat sb; + + const char *tmp_keyfile = get_mig_ssh_tmp_key(); + if (!tmp_keyfile) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Migration with special ssh key " + "is not enabled in config file."); + CU_DEBUG("Migration with special ssh key " + "is not enabled in config file."); + goto out; + } + + ret = stat(tmp_keyfile, &sb); + if (ret == 0) { + /* need delete */ + ret = unlink(tmp_keyfile); + if (ret < 0) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Failed to delete [%s].", + tmp_keyfile); + CU_DEBUG("Failed to delete [%s].", tmp_keyfile); + } + } else { + /* not exist */ + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Can not find file [%s] before delete.", + tmp_keyfile); + CU_DEBUG("Can not find file [%s] before delete.", tmp_keyfile); + } + + out: + METHOD_RETURN(results, s.rc); + return s; +}; + static struct method_handler vsimth = { .name = "CheckVirtualSystemIsMigratableToHost", .handler = vs_migratable_host, .args = {{"ComputerSystem", CMPI_ref, false}, {"DestinationHost", CMPI_string, false}, + {"MigrationWithoutRootKey", CMPI_boolean, true}, {"MigrationSettingData", CMPI_instance, true}, {"NewSystemSettingData", CMPI_instance, true}, {"NewResourceSettingData", CMPI_instanceA, true}, @@ -1633,6 +1869,7 @@ static struct method_handler mvsth = { .handler = migrate_vs_host, .args = {{"ComputerSystem", CMPI_ref, false}, {"DestinationHost", CMPI_string, false}, + {"MigrationWithoutRootKey", CMPI_boolean, true}, {"MigrationSettingData", CMPI_instance, true}, {"NewSystemSettingData", CMPI_instance, true}, {"NewResourceSettingData", CMPI_instanceA, true}, @@ -1652,11 +1889,28 @@ static struct method_handler mvsts = { } }; +static struct method_handler msshkc = { + .name = "MigrateSSHKeyCopy", + .handler = migrate_sshkey_copy, + .args = {{"SSH_Key_Src", CMPI_string, true}, + ARG_END + } +}; + +static struct method_handler msshkd = { + .name = "MigrateSSHKeyDelete", + .handler = migrate_sshkey_delete, + .args = {ARG_END + } +}; + static struct method_handler *my_handlers[] = { &vsimth, &vsimts, &mvsth, &mvsts, + &msshkc, + &msshkd, NULL }; -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:55 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:55 +0800 Subject: [Libvirt-cim] [PATCH V6 15/20] libvirt-cim.spec: Use systemctl for tog-pegasus restart In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-16-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan For Fedora 17 and RHEL7 use systemd, so change the pegasus startup to use that and make a dependency upon it. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- libvirt-cim.spec.in | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/libvirt-cim.spec.in b/libvirt-cim.spec.in index 3def978..0679d7f 100644 --- a/libvirt-cim.spec.in +++ b/libvirt-cim.spec.in @@ -6,7 +6,7 @@ Version: @PACKAGE_VERSION@ Release: 1%{?dist}%{?extra_release} License: LGPLv2+ Group: Development/Libraries -Source: libvirt-cim-%{version}.tar.gz +Source: ftp://libvirt.org/libvirt-cim/libvirt-cim-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root URL: http://libvirt.org/CIM/ Requires: libxml2 >= 2.6.0 @@ -27,6 +27,9 @@ BuildRequires: libconfig-devel BuildRequires: libxml2-devel BuildRequires: libcmpiutil-devel +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 +BuildRequires: systemd-units +%endif BuildConflicts: sblim-cmpi-devel %description @@ -85,7 +88,12 @@ rm -fr $RPM_BUILD_ROOT %{_datadir}/%{name}/install_base_schema.sh %{_datadir}/%{name} -/etc/init.d/tog-pegasus condrestart +# Fedora 17 / RHEL-7 are first where we use systemd. +%if 0%{?fedora} >= 17 || 0%{?rhel} >= 7 + systemctl restart tog-pegasus +%else + /etc/init.d/tog-pegasus condrestart +%endif %{_datadir}/%{name}/provider-register.sh -t pegasus \ -n @CIM_VIRT_NS@ \ -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:58 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:58 +0800 Subject: [Libvirt-cim] [PATCH V6 18/20] libxkutil: Use virConnectListAllDomains() to fetch domains In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-19-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan This is an optimization over using the multistep approach to get a count, get some memory, and get the list of domains (active and defined). Followed other examples to ensure only building the code if the libvirt version is correct. The API was added in 0.9.13. Macro USE_VIR_CONNECT_LIST_ALL_DOMAINS is used to activate it, which should be added in configure in the future. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- libxkutil/cs_util_instance.c | 26 ++++++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/libxkutil/cs_util_instance.c b/libxkutil/cs_util_instance.c index a383147..490017c 100644 --- a/libxkutil/cs_util_instance.c +++ b/libxkutil/cs_util_instance.c @@ -33,6 +33,31 @@ #include "cs_util.h" #include +#define USE_VIR_CONNECT_LIST_ALL_DOMAINS 0 + +#if LIBVIR_VERSION_NUMBER >= 9013 && USE_VIR_CONNECT_LIST_ALL_DOMAINS +int get_domain_list(virConnectPtr conn, virDomainPtr **_list) +{ + virDomainPtr *nameList = NULL; + int n_names; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE | + VIR_CONNECT_LIST_DOMAINS_INACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names > 0) { + *_list = nameList; + } else if (n_names == 0) { + /* Since there are no elements, no domain ptrs to free + * but still must free the nameList returned + */ + free(nameList); + } + + return n_names; +} +#else int get_domain_list(virConnectPtr conn, virDomainPtr **_list) { char **names = NULL; @@ -113,6 +138,7 @@ int get_domain_list(virConnectPtr conn, virDomainPtr **_list) return idx; } +#endif /* LIBVIR_VERSION_NUMBER >= 0913 */ void set_instance_class_name(CMPIInstance *instance, char *name) { -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:52:59 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:52:59 +0800 Subject: [Libvirt-cim] [PATCH V6 19/20] DevicePool: Use the virConnectListAll interfaces In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-20-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan Rather than the somewhat unreliable get a count and get a list of active names, use the newer virConnectListAll* interfaces in order to retrieve both a count and list in one call. Macro USE_VIR_CONNECT_LIST_ALL_STORAGE_POOLS, USE_VIR_CONNECT_LIST_ALL_NETWORKS and USE_VIR_CONNECT_LIST_ALL_DOMAINS are used to activate thses functions. It require libvirt > 1.0.0, and the code should be moved into a condition in configure later. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- src/Virt_DevicePool.c | 238 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 238 insertions(+), 0 deletions(-) diff --git a/src/Virt_DevicePool.c b/src/Virt_DevicePool.c index a8dc9cd..e375acc 100644 --- a/src/Virt_DevicePool.c +++ b/src/Virt_DevicePool.c @@ -109,6 +109,10 @@ static bool get_disk_parent(struct tmp_disk_pool **_pools, } #if VIR_USE_LIBVIRT_STORAGE +#define USE_VIR_CONNECT_LIST_ALL_STORAGE_POOLS 0 +#define USE_VIR_CONNECT_LIST_ALL_NETWORKS 0 +#define USE_VIR_CONNECT_LIST_ALL_DOMAINS 0 + int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) { char *xml; @@ -138,6 +142,77 @@ int get_disk_pool(virStoragePoolPtr poolptr, struct virt_pool **pool) * return 0 on success, negative on fail, *pools and *_count will be set * only on success . */ +#if LIBVIR_VERSION_NUMBER >= 100002 && USE_VIR_CONNECT_LIST_ALL_STORAGE_POOLS +static int get_diskpool_config(virConnectPtr conn, + struct tmp_disk_pool **_pools, + int *_count) +{ + int i, realcount = 0; + virStoragePoolPtr *nameList = NULL; + int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE; + struct tmp_disk_pool *pools = NULL; + int ret = 0; + bool bret; + + realcount = virConnectListAllStoragePools(conn, + &nameList, + flags); + if (realcount < 0) { + CU_DEBUG("Failed to get storage pools, return %d.", realcount); + ret = realcount; + goto out; + } + if (realcount == 0) { + CU_DEBUG("Zero pools got."); + goto set_parent; + } + + pools = calloc(realcount, sizeof(*pools)); + if (pools == NULL) { + CU_DEBUG("Failed to alloc space for %i pool structs", + realcount); + ret = -2; + goto free_names; + } + + for (i = 0; i < realcount; i++) { + pools[i].tag = strdup(virStoragePoolGetName(nameList[i])); + if (pools[i].tag == NULL) { + CU_DEBUG("Failed in strdup for storage pool name."); + ret = -3; + goto free_pools; + } + pools[i].primordial = false; + } + + set_parent: + bret = get_disk_parent(&pools, &realcount); + if (bret != true) { + CU_DEBUG("Failed in adding parentpool."); + ret = -4; + goto free_pools; + } + + /* succeed */ + *_pools = pools; + *_count = realcount; + goto free_names; + + free_pools: + free_diskpool(pools, realcount); + + free_names: + if (nameList != NULL) { + for (i = 0; i < realcount; i++) { + virStoragePoolFree(nameList[i]); + } + free(nameList); + } + + out: + return ret; +} +#else static int get_diskpool_config(virConnectPtr conn, struct tmp_disk_pool **_pools, int *_count) @@ -209,6 +284,7 @@ static int get_diskpool_config(virConnectPtr conn, out: return ret; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static bool diskpool_set_capacity(virConnectPtr conn, CMPIInstance *inst, @@ -530,6 +606,46 @@ static char *diskpool_member_of(const CMPIBroker *broker, return pool; } + +#if LIBVIR_VERSION_NUMBER >= 100002 && USE_VIR_CONNECT_LIST_ALL_NETWORKS +static virNetworkPtr bridge_to_network(virConnectPtr conn, + const char *bridge) +{ + int i, num; + virNetworkPtr *nameList = NULL; + virNetworkPtr network = NULL; + int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; + + num = virConnectListAllNetworks(conn, + &nameList, + flags); + if (num < 0) { + CU_DEBUG("Failed to get network pools."); + return NULL; + } + + for (i = 0; i < num; i++) { + const char *_netname; + char *_bridge; + + _netname = virNetworkGetName(nameList[i]); + _bridge = virNetworkGetBridgeName(network); + CU_DEBUG("Network `%s' has bridge `%s'", _netname, _bridge); + if (STREQ(bridge, _bridge)) { + network = nameList[i]; + nameList[i] = NULL; + i = num; /* Loop breaker */ + } + free(_bridge); + } + + for (i = 0; i < num; i++) { + virNetworkFree(nameList[i]); + } + free(nameList); + return network; +} +#else static virNetworkPtr bridge_to_network(virConnectPtr conn, const char *bridge) { @@ -573,6 +689,7 @@ static virNetworkPtr bridge_to_network(virConnectPtr conn, return network; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static char *_netpool_member_of(virConnectPtr conn, const struct net_device *ndev) @@ -749,6 +866,40 @@ static bool mempool_set_total(CMPIInstance *inst, virConnectPtr conn) return memory != 0; } +#if LIBVIR_VERSION_NUMBER >= 9013 && USE_VIR_CONNECT_LIST_ALL_DOMAINS +static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) +{ + uint64_t memory = 0; + virDomainPtr *nameList = NULL; + int n_names, i; + int flags = VIR_CONNECT_LIST_DOMAINS_ACTIVE; + + n_names = virConnectListAllDomains(conn, + &nameList, + flags); + if (n_names < 0) { + CU_DEBUG("Failed to get a list of all domains"); + goto out; + } + + for (i = 0; i < n_names; i++) { + virDomainInfo dom_info; + if (virDomainGetInfo(nameList[i], &dom_info) == 0) { + memory += dom_info.memory; + } + virDomainFree(nameList[i]); + } + free(nameList); + + out: + CMSetProperty(inst, "Reserved", + (CMPIValue *)&memory, CMPI_uint64); + CMSetProperty(inst, "CurrentlyConsumedResource", + (CMPIValue *)&memory, CMPI_uint64); + + return memory != 0; +} +#else static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) { uint64_t memory = 0; @@ -793,6 +944,7 @@ static bool mempool_set_consumed(CMPIInstance *inst, virConnectPtr conn) return memory != 0; } +#endif /* LIBVIR_VERSION_NUMBER >= 9013 */ static bool procpool_set_total(CMPIInstance *inst, virConnectPtr conn) { @@ -1032,6 +1184,91 @@ static CMPIStatus _netpool_for_network(struct inst_list *list, return s; } +#if LIBVIR_VERSION_NUMBER >= 100002 && USE_VIR_CONNECT_LIST_ALL_NETWORKS +static CMPIStatus netpool_instance(virConnectPtr conn, + struct inst_list *list, + const char *ns, + const char *id, + const CMPIBroker *broker) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + char **netnames = NULL; + int i; + int nets = 0; + virNetworkPtr *nameList = NULL; + int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE; + + if (id != NULL) { + return _netpool_for_network(list, + ns, + conn, + id, + pfx_from_conn(conn), + broker); + } + + nets = virConnectListAllNetworks(conn, + &nameList, + flags); + if (nets < 0) { + virt_set_status(broker, &s, + CMPI_RC_ERR_FAILED, + conn, + "Unable to list networks"); + + goto out; + } + + /* +1 for our primordial entry */ + netnames = calloc(nets+1, sizeof(*netnames)); + if (netnames == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to allocate memory for %i net names", nets); + goto out; + } + + for (i = 0; i < nets; i++) { + netnames[i] = strdup(virNetworkGetName(nameList[i])); + if (netnames[i] == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "Failed to strdup memory for %i net names", + nets); + goto out; + } + } + + /* Remember we allocated extra slot already */ + netnames[nets] = strdup("0"); + + for (i = 0; i < nets + 1; i++) { + _netpool_for_network(list, + ns, + conn, + netnames[i], + pfx_from_conn(conn), + broker); + } + + out: + if (nameList != NULL) { + for (i = 0; i < nets; i++) { + virNetworkFree(nameList[i]); + } + free(nameList); + } + if (netnames != NULL) { + /* +1 to account for primordial */ + for (i = 0; i < nets + 1; i++) { + free(netnames[i]); + } + free(netnames); + } + + return s; +} +#else static CMPIStatus netpool_instance(virConnectPtr conn, struct inst_list *list, const char *ns, @@ -1101,6 +1338,7 @@ static CMPIStatus netpool_instance(virConnectPtr conn, return s; } +#endif /* LIBVIR_VERSION_NUMBER >= 100002 */ static CMPIInstance *diskpool_from_path(struct tmp_disk_pool *pool, virConnectPtr conn, -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 09:53:00 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 17:53:00 +0800 Subject: [Libvirt-cim] [PATCH V6 20/20] register: Adjust the chatter output In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364205180-21124-21-git-send-email-xiawenc@linux.vnet.ibm.com> From: John Ferlan Caused error during make postinstall. Rather than print the $PROVIDERMODULES it attempted to execute the second one in the list. Added extra output just prior to CIMMOF commands to show which namespace is being modified from which directory. There appears to be some sort of issue registering some mofs as the following message is generated numerous times: Warning: the instance already exists. In this implementation, that means it cannot be changed. Signed-off-by: John Ferlan Reviewed-by: Wenchao Xia Signed-off-by: Wenchao Xia --- provider-register.sh | 9 +++++---- 1 files changed, 5 insertions(+), 4 deletions(-) diff --git a/provider-register.sh b/provider-register.sh index 0616a14..b907df1 100755 --- a/provider-register.sh +++ b/provider-register.sh @@ -90,10 +90,10 @@ pegasus_transform() chatter "cimserver version is " $version if compare_version "$version" "2.11.0" then - chatter "Processing provider modules (w/o ModuleGroupName):" \ - $PROVIDERMODULES + chatter "Processing provider modules (w/o ModuleGroupName):" for pm in $PROVIDERMODULES do + chatter "...processing " $pm cat >> $OUTFILE <> $OUTFILE < References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <51502160.9030706@linux.vnet.ibm.com> Hi, John This is the complete serial include your patches, I tested it on my RH6.3 env, seems fine. If you are installing RH system, can you have a test on RH6.4? > This serial fix a batch of issues. > > v6: > general change: > rebase and add John Ferlan's patches after the tail. > 2/20: do not add this property now, just fixed the spelling in code, since > it is only set when Xen is used in libvirt-cim, so it is OK. > 3/20: also fixed debug print spelling. > 5/20: squashed patch for debug print crash issues. > 6/20: spelling fix in commit message. > 7/20: skipped free_diskpool on fail of setting parent pool, refined the > code in get_diskpool_config() when libvirt pool was not used, removed the > duplicated macro in .c file, set member to NULL in parse_diskpool_line when > fail. > 8/20: squashed the patch with John Ferlan's one about "adjust logic" for it. > 11/20: free the domain ptr after domain name retrieving. > 13/20: rename no_root_ssh_key to use_non_root_ssh_key, fail when file can't > be deleted before copy in ssh_key_copy(). > 17/20: small code style change for {} in if condition. > 18/20: added a macro to activate it. > 19/20: added three macro to activate them, added {} in if statement when > only one sentence follow. > > John Ferlan (7): > 14 Makefile.am: Remove the $(top_srcdir) from subst command > 15 libvirt-cim.spec: Use systemctl for tog-pegasus restart > 16 Remove empty newline at bottom > 17 xmlgen: Only support script on bridge for xen domains > 18 libxkutil: Use virConnectListAllDomains() to fetch domains > 19 DevicePool: Use the virConnectListAll interfaces > 20 register: Adjust the chatter output > > Wenchao Xia (13): > 1 Remove property CreationClassName in some instance > 2 SDC: Fix spelling for property IsFullVirt > 3 SDC: use property BootDevices instead of BootDevice > 4 do not deregister virt classes in yum upgrade > 5 CSI, DevicePool, RASDIndication: fix debug print crash > 6 CSI, add lock to protect shared data in lifecycle_thread > 7 DevicePool, reimplement get_diskpool_config with libvirt > 8 device parsing, add debug print > 9 CSI Discard libvirt event by default > 10 CSI: Move native CSI code together > 11 VSSD: report success if not all VS fail in enum > 12 misc_util: better way to read config > 13 migration: allow ssh based migration with non root's key file > > Makefile.am | 18 +- > libvirt-cim.conf | 19 + > libvirt-cim.spec.in | 24 +- > libxkutil/cs_util_instance.c | 26 + > libxkutil/device_parsing.c | 19 +- > libxkutil/misc_util.c | 135 +++- > libxkutil/misc_util.h | 6 +- > libxkutil/xmlgen.c | 26 +- > provider-register.sh | 9 +- > schema/SwitchService.registration | 1 - > src/Virt_AllocationCapabilities.c | 3 +- > src/Virt_ComputerSystem.c | 66 ++- > src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- > src/Virt_ConsoleRedirectionService.c | 3 +- > src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- > src/Virt_Device.c | 18 +- > src/Virt_DevicePool.c | 480 ++++++++-- > src/Virt_DevicePool.h | 4 + > src/Virt_EnabledLogicalElementCapabilities.c | 3 +- > src/Virt_FilterEntry.c | 3 +- > src/Virt_FilterList.c | 3 +- > src/Virt_HostSystem.c | 3 +- > src/Virt_KVMRedirectionSAP.c | 3 +- > src/Virt_RASD.c | 3 +- > src/Virt_ReferencedProfile.c | 3 +- > src/Virt_RegisteredProfile.c | 3 +- > src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- > src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- > src/Virt_ResourcePoolConfigurationService.c | 8 +- > src/Virt_SettingsDefineCapabilities.c | 14 +- > src/Virt_SwitchService.c | 3 +- > src/Virt_VSMigrationCapabilities.c | 3 +- > src/Virt_VSMigrationService.c | 270 +++++- > src/Virt_VSMigrationSettingData.c | 3 +- > src/Virt_VSSD.c | 50 +- > src/Virt_VirtualSystemManagementCapabilities.c | 3 +- > src/Virt_VirtualSystemManagementService.c | 67 ++- > src/Virt_VirtualSystemSnapshotService.c | 3 +- > ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- > 39 files changed, 1990 insertions(+), 348 deletions(-) > > -- Best Regards Wenchao Xia From xiawenc at linux.vnet.ibm.com Mon Mar 25 10:46:07 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 18:46:07 +0800 Subject: [Libvirt-cim] [PATCH V6 21/21] libxkutil: set domain->dype to unknown by default In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <1364208367-6760-1-git-send-email-xiawenc@linux.vnet.ibm.com> It should not be default as XENPV, which will bring trouble when this value is not set. One case is script section in bridge xml generation, in resource add method it will be always added since this value is XENPV, so change it to unknown. Signed-off-by: Wenchao Xia --- libxkutil/device_parsing.h | 7 ++++--- 1 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h index d652f0f..6f6b0b4 100644 --- a/libxkutil/device_parsing.h +++ b/libxkutil/device_parsing.h @@ -147,10 +147,11 @@ struct lxc_os_info { }; struct domain { - enum { DOMAIN_XENPV, + enum { DOMAIN_UNKNOWN, + DOMAIN_XENPV, DOMAIN_XENFV, - DOMAIN_KVM, - DOMAIN_QEMU, + DOMAIN_KVM, + DOMAIN_QEMU, DOMAIN_LXC } type; char *name; char *typestr; /*xen, kvm, etc */ -- 1.7.1 From xiawenc at linux.vnet.ibm.com Mon Mar 25 10:54:58 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Mon, 25 Mar 2013 18:54:58 +0800 Subject: [Libvirt-cim] [PATCH V6 21/21] libxkutil: set domain->dype to unknown by default In-Reply-To: <1364208367-6760-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> <1364208367-6760-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <51502D02.3030209@linux.vnet.ibm.com> Sorry, This is a missed patch. Since Domain_XENPV was default value and in resource adding method it is not set causing the script will be added xml string, so change the default value to UNKNOWN. > It should not be default as XENPV, which will bring trouble when this value is > not set. One case is script section in bridge xml generation, in resource add > method it will be always added since this value is XENPV, so change it to unknown. > > Signed-off-by: Wenchao Xia > --- > libxkutil/device_parsing.h | 7 ++++--- > 1 files changed, 4 insertions(+), 3 deletions(-) > > diff --git a/libxkutil/device_parsing.h b/libxkutil/device_parsing.h > index d652f0f..6f6b0b4 100644 > --- a/libxkutil/device_parsing.h > +++ b/libxkutil/device_parsing.h > @@ -147,10 +147,11 @@ struct lxc_os_info { > }; > > struct domain { > - enum { DOMAIN_XENPV, > + enum { DOMAIN_UNKNOWN, > + DOMAIN_XENPV, > DOMAIN_XENFV, > - DOMAIN_KVM, > - DOMAIN_QEMU, > + DOMAIN_KVM, > + DOMAIN_QEMU, > DOMAIN_LXC } type; > char *name; > char *typestr; /*xen, kvm, etc */ > -- Best Regards Wenchao Xia From jferlan at redhat.com Mon Mar 25 12:31:54 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 25 Mar 2013 08:31:54 -0400 Subject: [Libvirt-cim] [PATCH V5 00/15] Bug fix patches for 0.6.2 In-Reply-To: <514EA5A6.5050001@linux.vnet.ibm.com> References: <1363837158-11509-1-git-send-email-xiawenc@linux.vnet.ibm.com> <514A82AF.5040404@linux.vnet.ibm.com> <514CC5FF.5010308@redhat.com> <514EA5A6.5050001@linux.vnet.ibm.com> Message-ID: <515043BA.4020201@redhat.com> On 03/24/2013 03:05 AM, Wenchao Xia wrote: > ? 2013-3-23 4:58, John Ferlan ??: >> >> ComputerSystemIndication - 01_created_indication.py: FAIL >> Error connecting to CIMOM: [Errno 110] Connection timed out >> > Possible event/indication is not enabled, command "cimconfig -c -l" > will list the settings, you can change it by "cimconfig -p -s > PROPERTY=VALUE", and then restart tog-pegasus and retry. > # cimconfig -c -l enableAssociationTraversal=true maxProviderProcesses=0 enableAuditLog=false sslClientVerificationMode=disabled forceProviderProcesses=true idleConnectionTimeout=0 listenAddress=All enableSubscriptionsForNonprivilegedUsers=false slp=false socketWriteTimeout=20 messageDir=msg shutdownTimeout=30 authorizedUserGroups= enableRemotePrivilegedUserAccess=true enableHttpsConnection=true enableIndicationService=true sslCipherSuite=DEFAULT enableNamespaceAuthorization=false sslTrustStoreUserName= maxFailedProviderModuleRestarts=3 enableHttpConnection=true Looks like it is enabled (enableIndicationService) unless I'm missing something. John From jferlan at redhat.com Mon Mar 25 22:18:45 2013 From: jferlan at redhat.com (John Ferlan) Date: Mon, 25 Mar 2013 18:18:45 -0400 Subject: [Libvirt-cim] [PATCH V6 00/20] Bug fix patches for 0.6.2 In-Reply-To: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> Message-ID: <5150CD45.8050800@redhat.com> On 03/25/2013 05:52 AM, Wenchao Xia wrote: > This serial fix a batch of issues. > > v6: > general change: > rebase and add John Ferlan's patches after the tail. > 2/20: do not add this property now, just fixed the spelling in code, since > it is only set when Xen is used in libvirt-cim, so it is OK. > 3/20: also fixed debug print spelling. > 5/20: squashed patch for debug print crash issues. > 6/20: spelling fix in commit message. > 7/20: skipped free_diskpool on fail of setting parent pool, refined the > code in get_diskpool_config() when libvirt pool was not used, removed the > duplicated macro in .c file, set member to NULL in parse_diskpool_line when > fail. > 8/20: squashed the patch with John Ferlan's one about "adjust logic" for it. > 11/20: free the domain ptr after domain name retrieving. > 13/20: rename no_root_ssh_key to use_non_root_ssh_key, fail when file can't > be deleted before copy in ssh_key_copy(). > 17/20: small code style change for {} in if condition. > 18/20: added a macro to activate it. > 19/20: added three macro to activate them, added {} in if statement when > only one sentence follow. > > John Ferlan (7): > 14 Makefile.am: Remove the $(top_srcdir) from subst command > 15 libvirt-cim.spec: Use systemctl for tog-pegasus restart > 16 Remove empty newline at bottom > 17 xmlgen: Only support script on bridge for xen domains > 18 libxkutil: Use virConnectListAllDomains() to fetch domains > 19 DevicePool: Use the virConnectListAll interfaces > 20 register: Adjust the chatter output > > Wenchao Xia (13): > 1 Remove property CreationClassName in some instance > 2 SDC: Fix spelling for property IsFullVirt > 3 SDC: use property BootDevices instead of BootDevice > 4 do not deregister virt classes in yum upgrade > 5 CSI, DevicePool, RASDIndication: fix debug print crash > 6 CSI, add lock to protect shared data in lifecycle_thread > 7 DevicePool, reimplement get_diskpool_config with libvirt > 8 device parsing, add debug print > 9 CSI Discard libvirt event by default > 10 CSI: Move native CSI code together > 11 VSSD: report success if not all VS fail in enum > 12 misc_util: better way to read config > 13 migration: allow ssh based migration with non root's key file > > Makefile.am | 18 +- > libvirt-cim.conf | 19 + > libvirt-cim.spec.in | 24 +- > libxkutil/cs_util_instance.c | 26 + > libxkutil/device_parsing.c | 19 +- > libxkutil/misc_util.c | 135 +++- > libxkutil/misc_util.h | 6 +- > libxkutil/xmlgen.c | 26 +- > provider-register.sh | 9 +- > schema/SwitchService.registration | 1 - > src/Virt_AllocationCapabilities.c | 3 +- > src/Virt_ComputerSystem.c | 66 ++- > src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- > src/Virt_ConsoleRedirectionService.c | 3 +- > src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- > src/Virt_Device.c | 18 +- > src/Virt_DevicePool.c | 480 ++++++++-- > src/Virt_DevicePool.h | 4 + > src/Virt_EnabledLogicalElementCapabilities.c | 3 +- > src/Virt_FilterEntry.c | 3 +- > src/Virt_FilterList.c | 3 +- > src/Virt_HostSystem.c | 3 +- > src/Virt_KVMRedirectionSAP.c | 3 +- > src/Virt_RASD.c | 3 +- > src/Virt_ReferencedProfile.c | 3 +- > src/Virt_RegisteredProfile.c | 3 +- > src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- > src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- > src/Virt_ResourcePoolConfigurationService.c | 8 +- > src/Virt_SettingsDefineCapabilities.c | 14 +- > src/Virt_SwitchService.c | 3 +- > src/Virt_VSMigrationCapabilities.c | 3 +- > src/Virt_VSMigrationService.c | 270 +++++- > src/Virt_VSMigrationSettingData.c | 3 +- > src/Virt_VSSD.c | 50 +- > src/Virt_VirtualSystemManagementCapabilities.c | 3 +- > src/Virt_VirtualSystemManagementService.c | 67 ++- > src/Virt_VirtualSystemSnapshotService.c | 3 +- > ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- > 39 files changed, 1990 insertions(+), 348 deletions(-) > > ACK on series. There were a couple of grammar things seen in commit messages and comments, but nothing that isn't understandable ;-) I was able to test using my fedora box, but haven't had the cycles to do the same on the rh64 box. With my cimtest changes I am down to very few errors now - mostly config type stuff (indications don't work for me and I don't have the right setup for a couple of network tests). John From xiawenc at linux.vnet.ibm.com Fri Mar 29 02:08:26 2013 From: xiawenc at linux.vnet.ibm.com (Wenchao Xia) Date: Fri, 29 Mar 2013 10:08:26 +0800 Subject: [Libvirt-cim] [PATCH V6 00/20] Bug fix patches for 0.6.2 In-Reply-To: <5150CD45.8050800@redhat.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> <5150CD45.8050800@redhat.com> Message-ID: <5154F79A.7040604@linux.vnet.ibm.com> ? 2013-3-26 6:18, John Ferlan ??: > On 03/25/2013 05:52 AM, Wenchao Xia wrote: >> This serial fix a batch of issues. >> >> v6: >> general change: >> rebase and add John Ferlan's patches after the tail. >> 2/20: do not add this property now, just fixed the spelling in code, since >> it is only set when Xen is used in libvirt-cim, so it is OK. >> 3/20: also fixed debug print spelling. >> 5/20: squashed patch for debug print crash issues. >> 6/20: spelling fix in commit message. >> 7/20: skipped free_diskpool on fail of setting parent pool, refined the >> code in get_diskpool_config() when libvirt pool was not used, removed the >> duplicated macro in .c file, set member to NULL in parse_diskpool_line when >> fail. >> 8/20: squashed the patch with John Ferlan's one about "adjust logic" for it. >> 11/20: free the domain ptr after domain name retrieving. >> 13/20: rename no_root_ssh_key to use_non_root_ssh_key, fail when file can't >> be deleted before copy in ssh_key_copy(). >> 17/20: small code style change for {} in if condition. >> 18/20: added a macro to activate it. >> 19/20: added three macro to activate them, added {} in if statement when >> only one sentence follow. >> >> John Ferlan (7): >> 14 Makefile.am: Remove the $(top_srcdir) from subst command >> 15 libvirt-cim.spec: Use systemctl for tog-pegasus restart >> 16 Remove empty newline at bottom >> 17 xmlgen: Only support script on bridge for xen domains >> 18 libxkutil: Use virConnectListAllDomains() to fetch domains >> 19 DevicePool: Use the virConnectListAll interfaces >> 20 register: Adjust the chatter output >> >> Wenchao Xia (13): >> 1 Remove property CreationClassName in some instance >> 2 SDC: Fix spelling for property IsFullVirt >> 3 SDC: use property BootDevices instead of BootDevice >> 4 do not deregister virt classes in yum upgrade >> 5 CSI, DevicePool, RASDIndication: fix debug print crash >> 6 CSI, add lock to protect shared data in lifecycle_thread >> 7 DevicePool, reimplement get_diskpool_config with libvirt >> 8 device parsing, add debug print >> 9 CSI Discard libvirt event by default >> 10 CSI: Move native CSI code together >> 11 VSSD: report success if not all VS fail in enum >> 12 misc_util: better way to read config >> 13 migration: allow ssh based migration with non root's key file >> >> Makefile.am | 18 +- >> libvirt-cim.conf | 19 + >> libvirt-cim.spec.in | 24 +- >> libxkutil/cs_util_instance.c | 26 + >> libxkutil/device_parsing.c | 19 +- >> libxkutil/misc_util.c | 135 +++- >> libxkutil/misc_util.h | 6 +- >> libxkutil/xmlgen.c | 26 +- >> provider-register.sh | 9 +- >> schema/SwitchService.registration | 1 - >> src/Virt_AllocationCapabilities.c | 3 +- >> src/Virt_ComputerSystem.c | 66 ++- >> src/Virt_ComputerSystemIndication.c | 1018 +++++++++++++++++--- >> src/Virt_ConsoleRedirectionService.c | 3 +- >> src/Virt_ConsoleRedirectionServiceCapabilities.c | 3 +- >> src/Virt_Device.c | 18 +- >> src/Virt_DevicePool.c | 480 ++++++++-- >> src/Virt_DevicePool.h | 4 + >> src/Virt_EnabledLogicalElementCapabilities.c | 3 +- >> src/Virt_FilterEntry.c | 3 +- >> src/Virt_FilterList.c | 3 +- >> src/Virt_HostSystem.c | 3 +- >> src/Virt_KVMRedirectionSAP.c | 3 +- >> src/Virt_RASD.c | 3 +- >> src/Virt_ReferencedProfile.c | 3 +- >> src/Virt_RegisteredProfile.c | 3 +- >> src/Virt_ResourceAllocationSettingDataIndication.c | 6 +- >> src/Virt_ResourcePoolConfigurationCapabilities.c | 3 +- >> src/Virt_ResourcePoolConfigurationService.c | 8 +- >> src/Virt_SettingsDefineCapabilities.c | 14 +- >> src/Virt_SwitchService.c | 3 +- >> src/Virt_VSMigrationCapabilities.c | 3 +- >> src/Virt_VSMigrationService.c | 270 +++++- >> src/Virt_VSMigrationSettingData.c | 3 +- >> src/Virt_VSSD.c | 50 +- >> src/Virt_VirtualSystemManagementCapabilities.c | 3 +- >> src/Virt_VirtualSystemManagementService.c | 67 ++- >> src/Virt_VirtualSystemSnapshotService.c | 3 +- >> ...Virt_VirtualSystemSnapshotServiceCapabilities.c | 3 +- >> 39 files changed, 1990 insertions(+), 348 deletions(-) >> >> > > ACK on series. There were a couple of grammar things seen in commit > messages and comments, but nothing that isn't understandable ;-) > > I was able to test using my fedora box, but haven't had the cycles to do > the same on the rh64 box. With my cimtest changes I am down to very few > errors now - mostly config type stuff (indications don't work for me and > I don't have the right setup for a couple of network tests). > > John > So nice to know patches are OK. Do you think it can be pulled? > > _______________________________________________ > Libvirt-cim mailing list > Libvirt-cim at redhat.com > https://www.redhat.com/mailman/listinfo/libvirt-cim > -- Best Regards Wenchao Xia From jferlan at redhat.com Fri Mar 29 10:17:37 2013 From: jferlan at redhat.com (John Ferlan) Date: Fri, 29 Mar 2013 06:17:37 -0400 Subject: [Libvirt-cim] [PATCH V6 00/20] Bug fix patches for 0.6.2 In-Reply-To: <5154F79A.7040604@linux.vnet.ibm.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> <5150CD45.8050800@redhat.com> <5154F79A.7040604@linux.vnet.ibm.com> Message-ID: <51556A41.8080800@redhat.com> On 03/28/2013 10:08 PM, Wenchao Xia wrote: > ? 2013-3-26 6:18, John Ferlan ??: >> On 03/25/2013 05:52 AM, Wenchao Xia wrote: >> >> ACK on series. There were a couple of grammar things seen in commit >> messages and comments, but nothing that isn't understandable ;-) >> >> I was able to test using my fedora box, but haven't had the cycles to do >> the same on the rh64 box. With my cimtest changes I am down to very few >> errors now - mostly config type stuff (indications don't work for me and >> I don't have the right setup for a couple of network tests). >> >> John >> > So nice to know patches are OK. Do you think it can be pulled? > I think DV is the maintainer, right? Not sure how that part works quite yet. That is - what the process is from here. I do know he also handles the libvirt releases as well and is in the middle of a release for that right now. I would be nice to perhaps include the cimtest changes that I posted as well, although not a requirement for the release. John From xiaxia347work at 163.com Fri Mar 29 10:58:24 2013 From: xiaxia347work at 163.com (xiaxia347work) Date: Fri, 29 Mar 2013 18:58:24 +0800 Subject: [Libvirt-cim] [PATCH V6 00/20] Bug fix patches for 0.6.2 In-Reply-To: <51556A41.8080800@redhat.com> References: <1364205180-21124-1-git-send-email-xiawenc@linux.vnet.ibm.com> <5150CD45.8050800@redhat.com> <5154F79A.7040604@linux.vnet.ibm.com><51556A41.8080800@redhat.com> Message-ID: <436d3a9e.9083.13db5cc715b.Coremail.xiaxia347work@163.com> >> So nice to know patches are OK. Do you think it can be pulled? >> >I think DV is the maintainer, right? Not sure how that part works quite >yet. That is - what the process is from here. I do know he also handles >the libvirt releases as well and is in the middle of a release for that >right now. >I would be nice to perhaps include the cimtest changes that I posted as >well, although not a requirement for the release. Yes it should be pushed also, another folks will come to check cimtest in about two weeks, I will also check it. >John Daniel: I am a bit eager for a steady release, do you have a plan for release libvirt-cim 0.6.2? Best Regards Wenchao Xia