Re: [libvirt] Having some issue with : virConnectRef
On 12/14/2009 07:18 AM, anuj rampal wrote: Hi, Im trying to call libvirt functions from a widows machine. The client version i'm using is 0.6.1. My application is a multi-Threaded application. This is the way my application works: 1. I connect to Libvirt using virConnectOpen. (this done only once when my application starts). 2. For funther interaction with libvirt i just call virConnectRef and then i call some other function like virNodeGetInfo. 3. Then i call virConnectClose. Now my understanding is for every virConnectRef call there has to be a corrosponding virConnectClose. In my application call to number of calls to virConnectClose is always equal to virConnectRef. and virConnectClose corrosponding to virConnectOpen is called when the application is closed. So connection to libvirt should always be there till the time my application is running. But what is happening is, even if i call virConnectRef twice, a single call to virConnectClose closes the connection with libvirt. Is there anything that im doing wrong here...?? Connection reference counting was pretty broken prior to 0.7.1, so that's probably your problem. I would try again with a newer libvirt, and see if it fixes your issue. -- Chris Lalancette -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Suppress cgroup error message on sucess in qemudStartVMDaemon
On Mon, Dec 14, 2009 at 07:31:35AM +0900, Ryota Ozaki wrote: On Thu, Nov 19, 2009 at 11:27 PM, Daniel Veillard veill...@redhat.com wrote: On Thu, Nov 19, 2009 at 09:45:48PM +0900, Ryota Ozaki wrote: Even if qemudStartVMDaemon suceeds, an error is logged such as 'qemuRemoveCgroup:1778 : internal error Unable to find cgroup for'. This is because qemudStartVMDaemon calls qemuRemoveCgroup to ensure that old cgroup does not remain. This workaround makes sense but leaving an error message may confuse users. This patch simply adds an option to suppress the error log if not needed. --- src/qemu/qemu_driver.c | 16 +--- 1 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a4a87ac..84ee942 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1763,7 +1763,8 @@ cleanup: static int qemuRemoveCgroup(virConnectPtr conn, struct qemud_driver *driver, - virDomainObjPtr vm) + virDomainObjPtr vm, + int quiet) { virCgroupPtr cgroup; int rc; @@ -1773,9 +1774,10 @@ static int qemuRemoveCgroup(virConnectPtr conn, rc = virCgroupForDomain(driver-cgroup, vm-def-name, cgroup, 0); if (rc != 0) { - qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, - _(Unable to find cgroup for %s\n), - vm-def-name); + if (!quiet) + qemudReportError(conn, NULL, NULL, VIR_ERR_INTERNAL_ERROR, + _(Unable to find cgroup for %s\n), + vm-def-name); return rc; } @@ -2142,7 +2144,7 @@ static int qemudStartVMDaemon(virConnectPtr conn, return -1; /* Ensure no historical cgroup for this VM is lieing around bogus settings */ - qemuRemoveCgroup(conn, driver, vm); + qemuRemoveCgroup(conn, driver, vm, 1); if ((vm-def-ngraphics == 1) vm-def-graphics[0]-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC @@ -2327,7 +2329,7 @@ cleanup: VIR_FREE(vm-def-seclabel.label); VIR_FREE(vm-def-seclabel.imagelabel); } - qemuRemoveCgroup(conn, driver, vm); + qemuRemoveCgroup(conn, driver, vm, 0); if ((vm-def-ngraphics == 1) vm-def-graphics[0]-type == VIR_DOMAIN_GRAPHICS_TYPE_VNC vm-def-graphics[0]-data.vnc.autoport) @@ -2416,7 +2418,7 @@ static void qemudShutdownVMDaemon(virConnectPtr conn, qemuDomainReAttachHostDevices(conn, driver, vm-def); retry: - if ((ret = qemuRemoveCgroup(conn, driver, vm)) 0) { + if ((ret = qemuRemoveCgroup(conn, driver, vm, 0)) 0) { if (ret == -EBUSY (retries++ 5)) { usleep(200*1000); goto retry; ACK, looks fine to me, but I would rather apply this after the 0.7.3 release as this is just a superfluous error message Please remind me to push this next week if I forget :-) I remember this patch ;-) Could you apply it? Ah, right ! Thanks for the reminder ! Done, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] Get QEMU pty paths from the monitor
On Thu, Dec 10, 2009 at 01:41:39PM +, Matthew Booth wrote: This change makes the QEMU driver get pty paths from the output of the monitor 'info chardev' command. This output is structured, and contains both the name of the device and the path on the same line. This is considerably more reliable than parsing the startup log output, which requires the parsing code to know which order QEMU will print pty information in. Note that we still need to parse the log output as the monitor itself may be on a pty. This should be rare, however, and the new code will replace all pty paths parsed by the log output method once the monitor is available. * src/qemu/qemu_monitor.(c|h) src/qemu_monitor_text.(c|h): Implement qemuMonitorGetPtyPaths(). * src/qemu/qemu_driver.c: Get pty path information using qemuMonitorGetPtyPaths(). Okay, I have pushed the 3 patches, code looks fine, and lot of regression tests ! I just changed that last patch to reformat the macro and replaced a free() into VIR_FREE() ... IIRC those were pointed by danpb in his last review. thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] Get QEMU pty paths from the monitor
On Wed, Nov 25, 2009 at 11:31:37AM +, Daniel P. Berrange wrote: On Mon, Nov 23, 2009 at 12:30:29PM +, Matthew Booth wrote: @@ -1291,7 +1330,7 @@ qemudWaitForMonitor(virConnectPtr conn, { char buf[4096]; /* Plenty of space to get startup greeting */ int logfd; -int ret; +int ret = -1; if ((logfd = qemudLogReadFD(conn, driver-logDir, vm-def-name, pos)) 0) @@ -1317,7 +1356,32 @@ qemudWaitForMonitor(virConnectPtr conn, if (qemuConnectMonitor(vm) 0) return -1; -return 0; +/* Try to get the pty path mappings again via the monitor. This is much more + * reliable if it's available. + * Note that the monitor itself can be on a pty, so we still need to try the + * log output method. */ +virHashTablePtr paths = virHashCreate(0); +if (paths == NULL) { +virReportOOMError(NULL); +goto cleanup; +} + +qemuDomainObjEnterMonitor(vm); This needs to be EnterMonitorWithDriver(driver, vm), since the 'driver' is locked in this context +qemuDomainObjPrivatePtr priv = vm-privateData; +ret = qemuMonitorGetPtyPaths(priv-mon, paths); +qemuDomainObjExitMonitor(vm); And ExitMonitorWithDriver Loooks serious and was missing fro last patch so I made the change +/* Path is everything after needle to the end of the line */ +*eol = '\0'; +char *path = needle + strlen(NEEDLE); + +virHashAddEntry(paths, id, strdup(path)); Not checking OOM on strdup() here, or for failure of virHashAddEntry() I fixed that too, I pushed the attached patch to clean those 2 issues, please check :-) Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ commit a7d1eb3c446fdbbd4183ba398c7f21a9fc0c1696 Author: Daniel Veillard veill...@redhat.com Date: Mon Dec 14 11:05:55 2009 +0100 Fix a couple of problems in last patch Those were pointed by DanB in his review but not yet fixed * src/qemu/qemu_driver.c: qemudWaitForMonitor() use EnterMonitorWithDriver() and ExitMonitorWithDriver() there * src/qemu/qemu_monitor_text.c: checking fro strdu failure and hash table add error in qemuMonitorTextGetPtyPaths() diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7b8c447..5a61b8c 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1534,10 +1534,10 @@ qemudWaitForMonitor(virConnectPtr conn, goto cleanup; } -qemuDomainObjEnterMonitor(vm); +qemuDomainObjEnterMonitorWithDriver(driver, vm); qemuDomainObjPrivatePtr priv = vm-privateData; ret = qemuMonitorGetPtyPaths(priv-mon, paths); -qemuDomainObjExitMonitor(vm); +qemuDomainObjExitMonitorWithDriver(driver, vm); VIR_DEBUG(qemuMonitorGetPtyPaths returned %i, ret); if (ret == 0) { diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 3ed45ba..0cb9ea6 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1650,9 +1650,19 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, /* Path is everything after needle to the end of the line */ *eol = '\0'; -char *path = needle + strlen(NEEDLE); +char *path = strdup(needle + strlen(NEEDLE)); +if (path == NULL) { +virReportOOMError(NULL); +goto cleanup; +} -virHashAddEntry(paths, id, strdup(path)); +if (virHashAddEntry(paths, id, path) 0) { +qemudReportError(NULL, NULL, NULL, VIR_ERR_OPERATION_FAILED, + _(failed to save chardev path '%s'), + path); +VIR_FREE(path); +goto cleanup; +} #undef NEEDLE next: -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] fix various breakages in qemu virsh dump
On Mon, Nov 30, 2009 at 10:13:34AM +, Daniel P. Berrange wrote: On Fri, Nov 27, 2009 at 06:33:13PM +0100, Paolo Bonzini wrote: 1) qemuMigrateToCommand uses so we have to truncate the file before starting the migration; 2) the command wasn't updated to chown the driver and set/restore the security lavels; 3) the VM does not have to be resumed if migration fails; 4) the file is not removed when migration fails. * src/qemu/qemu_driver.c (qemuDomainCoreDump): Truncate file before dumping, set/restore ownership and security labels for the file. --- src/qemu/qemu_driver.c | 48 +--- 1 files changed, 45 insertions(+), 3 deletions(-) ACK, looks good. Yup, pushed, I just had to slightly rebase the patch, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
Without this patch, a symlink pointing to a 4096-byte name could make this code write NUL into the byte beyond end of buffer: if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } devpath[n] = '\0'; From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): Leave one byte for the trailing NUL we'll append. --- src/node_device/node_device_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..eda5d5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] PING pushing option support patches for virsh dump
On Tue, Dec 08, 2009 at 04:00:14PM +0100, Paolo Bonzini wrote: http://permalink.gmane.org/gmane.comp.emulators.libvirt/18779 [libvirt] [PATCH 1/2] add --crash support to virsh dump http://permalink.gmane.org/gmane.comp.emulators.libvirt/18811 [libvirt] [PATCH 2/2 v2] add --live support to virsh dump Okay, I have pushed the 2 patches, I got a merge error in the cleanup section of the QEmu dump entry point, which I manually applied hope it's fine, I also had to cleanup some TAB used for indentation (hint use make syntax-check to catch those), thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Fix possible NULL pointer dereference
If there are no references remaining to the object, vm is set to NULL and vm-persistent cannot be accessed. Fixed by this trivial patch. * src/qemu/qemu_driver.c (qemudDomainCoreDump): Avoid possible NULL pointer dereference on --crash dump. --- Okay, I have pushed the 2 patches, I got a merge error in the cleanup section of the QEmu dump entry point, which I manually applied hope it's fine, I also had to cleanup some TAB used for indentation (hint use make syntax-check to catch those), Here is a little adjustment. Thanks! src/qemu/qemu_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3946c27..faeb838 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3914,7 +3914,7 @@ endjob: if (qemuDomainObjEndJob(vm) == 0) vm = NULL; -if ((ret == 0) (flags VIR_DUMP_CRASH) !vm-persistent) { +else if ((ret == 0) (flags VIR_DUMP_CRASH) !vm-persistent) { virDomainRemoveInactive(driver-domains, vm); vm = NULL; -- 1.6.5.2 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
On Mon, Dec 14, 2009 at 12:07:18PM +0100, Jim Meyering wrote: Without this patch, a symlink pointing to a 4096-byte name could make this code write NUL into the byte beyond end of buffer: if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } devpath[n] = '\0'; From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): Leave one byte for the trailing NUL we'll append. --- src/node_device/node_device_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..eda5d5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; Subtle ! ACK, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] remote_driver.c: also zero out -saslDecodedOffset member
Technically, the initialization of -saslDecodedOffset is not required, but... What could go wrong if saslDecodedOffset is left with some positive value in the if-block below? Well, in that same if-block priv-saslDecoded is set to NULL, and in that case, the code above *usually* sets priv-saslDecodedOffset to 0, but not if we hit one of the intervening returns. In that case, you have to wonder if priv-saslDecoded can be set to non-NULL, yet with priv-saslDecodedOffset still left with the now-bogus positive value. In that case, with an initial saslDecodedLength of 0, we'd compute this: wantData = (priv-saslDecodedLength - priv-saslDecodedOffset and that would be negative. The very next statement would cause trouble, as the negative value treated-as-size_t would wreak havoc: memcpy(priv-buffer + priv-bufferOffset, priv-saslDecoded + priv-saslDecodedOffset, wantData); Luckily, the semantics of sasl_decode ensure that does not happen. Hence, an alternate (though riskier) patch would be to skip that of priv-saslDecodedOffset altogether. From a3578fc03714a210678e6bcf62d162d92c9d07c0 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 13:00:01 +0100 Subject: [PATCH] remote_driver.c: also zero out -saslDecodedOffset member * src/remote/remote_driver.c (remoteIOReadMessage): ...rather than zeroing out priv-saslDecodedLength twice. --- src/remote/remote_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index affeb0f..77962fe 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7782,7 +7782,7 @@ remoteIOReadMessage(virConnectPtr conn, struct private_data *priv, priv-saslDecodedOffset += wantData; priv-bufferOffset += wantData; if (priv-saslDecodedOffset == priv-saslDecodedLength) { -priv-saslDecodedLength = priv-saslDecodedLength = 0; +priv-saslDecodedOffset = priv-saslDecodedLength = 0; priv-saslDecoded = NULL; } -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] add AppArmor test and examples to dist
On Tue, Dec 01, 2009 at 11:00:01AM -0600, Jamie Strandboge wrote: tests/virt-aa-helper-test and examples/apparmor are not included in official tarballs, but should be. Attached is a patch to fix that which works when apparmor is and is not available. Thanks to Daniel P. Berrange for pointing me in the right direction. Okay, makes sense, sorry for not noticing before, pushed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
On Mon, Dec 14, 2009 at 12:07:18PM +0100, Jim Meyering wrote: Without this patch, a symlink pointing to a 4096-byte name could make this code write NUL into the byte beyond end of buffer: if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } devpath[n] = '\0'; From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): Leave one byte for the trailing NUL we'll append. --- src/node_device/node_device_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..eda5d5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; Actually, now that I think about it, shouldn't we use virFileResolveLink() there and drop the static buffer and use the convenience wrapper function ? That would be even cleaner/safer no ? I checked that virFileResolveLink() does not suffer from this and might not have the static 4K limitation. thoughs ? Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Re: [PATCH] Fix possible NULL pointer dereference
On Mon, Dec 14, 2009 at 12:22:40PM +0100, Paolo Bonzini wrote: If there are no references remaining to the object, vm is set to NULL and vm-persistent cannot be accessed. Fixed by this trivial patch. * src/qemu/qemu_driver.c (qemudDomainCoreDump): Avoid possible NULL pointer dereference on --crash dump. --- Okay, I have pushed the 2 patches, I got a merge error in the cleanup section of the QEmu dump entry point, which I manually applied hope it's fine, I also had to cleanup some TAB used for indentation (hint use make syntax-check to catch those), Here is a little adjustment. Thanks! src/qemu/qemu_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 3946c27..faeb838 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -3914,7 +3914,7 @@ endjob: if (qemuDomainObjEndJob(vm) == 0) vm = NULL; -if ((ret == 0) (flags VIR_DUMP_CRASH) !vm-persistent) { +else if ((ret == 0) (flags VIR_DUMP_CRASH) !vm-persistent) { virDomainRemoveInactive(driver-domains, vm); vm = NULL; Oops I didn't realized that vm could be NULL there when fixing the merge conflict ! thanks for catching this, pushed ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] virsh: avoid double-free
I didn't try to trigger the double free, but it looks feasible. From 864cc161ffaf6c08cb980e66a673b53ac5ea52ab Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 14:34:29 +0100 Subject: [PATCH] virsh: avoid double-free * tools/virsh.c (vshCommandParse): Avoid double-free of tkdata. Set it to NULL immediately after free in the (cmd == NULL) case, just as in the other case, in case the final free(tkdata) is triggered by a syntax error. --- tools/virsh.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 62c1270..0312945 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -8044,6 +8044,7 @@ vshCommandParse(vshControl *ctl, char *cmdstr) goto syntaxError; /* ... or ignore this command only? */ } free(tkdata); +tkdata = NULL; } else if (tk == VSH_TK_OPTION) { if (!(opt = vshCmddefGetOption(cmd, tkdata))) { vshError(ctl, -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
Jim Meyering wrote: Without this patch, a symlink pointing to a 4096-byte name could make this code write NUL into the byte beyond end of buffer: if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } devpath[n] = '\0'; From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): Leave one byte for the trailing NUL we'll append. --- src/node_device/node_device_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..eda5d5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; The above is correct, but Daniel Veillard suggested a better (albeit slightly larger) change: use virFileResolveLink instead of readlink: From 4ae050481d481629fc98e8e7f5322ce6d724d3f7 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): The previous code would write one byte beyond the end of the 4KiB stack buffer when presented with a symlink value of exactly that length (very unlikely). Remove the automatic buffer and use virFileResolveLink in place of readlink. Suggested by Daniel Veillard. --- src/node_device/node_device_driver.c |7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..ecbac0f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -78,10 +78,9 @@ static int update_driver_name(virConnectPtr conn, virNodeDeviceObjPtr dev) { char *driver_link = NULL; -char devpath[PATH_MAX]; +char *devpath; char *p; int ret = -1; -int n; VIR_FREE(dev-def-driver); @@ -97,12 +96,11 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if (virFileResolveLink(driver_link, devpath) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } -devpath[n] = '\0'; p = strrchr(devpath, '/'); if (p) { @@ -116,6 +114,7 @@ static int update_driver_name(virConnectPtr conn, cleanup: VIR_FREE(driver_link); +free(devpath); return ret; } #else -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Cleanup temporary #define after use
* src/qemu/qemu_driver.c: #undef LOOKUP_PTYS after use --- src/qemu/qemu_driver.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7e55c23..4567a66 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1436,6 +1436,7 @@ qemudFindCharDevicePTYsMonitor(virConnectPtr conn, LOOKUP_PTYS(vm-def-serials, vm-def-nserials, serial); LOOKUP_PTYS(vm-def-parallels, vm-def-nparallels, parallel); LOOKUP_PTYS(vm-def-channels, vm-def-nchannels, channel); +#undef LOOKUP_PTYS return 0; } -- 1.6.5.2 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] nodedev: Add removable storage 'media_label' prop
On Thu, Dec 03, 2009 at 11:08:01PM +0100, Matthias Bolte wrote: 2009/12/1 Cole Robinson crobi...@redhat.com: Provides the CDROM label for current media. Only implemented for the udev backend. Signed-off-by: Cole Robinson crobi...@redhat.com --- docs/schemas/nodedev.rng | 5 + src/conf/node_device_conf.c | 8 src/conf/node_device_conf.h | 1 + src/node_device/node_device_udev.c | 5 + tests/nodedevschemadata/DVD_with_media.xml | 16 tests/nodedevxml2xmltest.c | 1 + 6 files changed, 36 insertions(+), 0 deletions(-) create mode 100644 tests/nodedevschemadata/DVD_with_media.xml diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 6003ab1..a0d256c 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -422,6 +422,11 @@ char *virNodeDeviceDefFormat(virConnectPtr conn, /media_available\n, avl ? 1 : 0); virBufferVSprintf(buf, media_size%llu/media_size\n, data-storage.removable_media_size); + if (data-storage.media_label) + virBufferVSprintf(buf, + media_label%s/media_label\n, + data-storage.media_label); + You should use virBufferEscapeString instead of virBufferVSprintf. Good point, if the label includes or this would break the XML if (data-storage.logical_block_size 0) virBufferVSprintf(buf, logical_block_size%llu /logical_block_size\n, ACK. Applied with teh suggested fix, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Fix and improve domain xml video element description
On Sun, Dec 13, 2009 at 10:15:20PM +0100, Matthias Bolte wrote: The description mismatched the actual structure since the video element was introduced. The nvram attribute is actually called vram. Specify the unit of the vram attribute. --- docs/formatdomain.html.in | 30 ++ 1 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 5b7aa10..3d418b9 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -768,20 +768,34 @@ qemu-kvm -net nic,model=? /dev/null pre ... - lt;video type='vga' nvram='8192' heads='1'gt; -lt;acceleration accel3d='yes' accel3d='yes' /gt; + lt;videogt; +lt;model type='vga' vram='8192' heads='1'gt; + lt;acceleration accel3d='yes' accel3d='yes'/gt; +lt;/modelgt; lt;/videogt; .../pre dl dtcodevideo/code/dt - ddThe codevideo/code element has a mandatory codetype/code - attribute which takes the value vga, cirrus, vmvga, xen or vbox. - You can also provide the amount of video memory using codenvram/code, - the number of screen with codeheads/code, and whether acceleration - should be enabled (if supported) using the codeaccel3d/code and - codeaccel2d/code attributes in the codeacceleration/code element. + dd +The codevideo/code element is the a container for describing +video devices. + /dd + + dtcodemodel/code/dt + dd +The codemodel/code element has a mandatory codetype/code +attribute which takes the value vga, cirrus, vmvga, xen or vbox. +You can also provide the amount of video memory in kilobytes using +codevram/code and the number of screen with codeheads/code. + /dd + dtcodeacceleration/code/dt + dd +If acceleration should be enabled (if supported) using the +codeaccel3d/code and codeaccel2d/code attributes in the +codeacceleration/code element. + /dd /dl h4a name=elementsConsoleConsoles, serial, parallel amp; channel devices/a/h4 ACK, thanks for the cleanup ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] implement --pool option for virsh vol-path
On Fri, Dec 11, 2009 at 04:39:31PM -0500, Dave Allan wrote: This patch fixes the problem reported in: https://bugzilla.redhat.com/show_bug.cgi?id=509306 The bug reporter says that vol-delete does not support the --pool option, but that's not the case in the current head. This patch makes vol-path behave the same way as vol-delete. Dave From 97199f44caeeeb38e64079c88fb02fcef35eadaa Mon Sep 17 00:00:00 2001 From: David Allan dal...@redhat.com Date: Thu, 10 Dec 2009 15:22:20 -0500 Subject: [PATCH 1/1] Add --pool option to vol-path * Modified vol-path to use the same logic as vol-delete, allowing the syntax: virsh vol-path --pool testdirpool testvol0 --- tools/virsh.c |6 -- 1 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 94a99e9..7d81c68 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -5275,12 +5275,14 @@ static int cmdVolPath(vshControl *ctl, const vshCmd *cmd) { virStorageVolPtr vol; +char *name = NULL; if (!vshConnectionUsability(ctl, ctl-conn, TRUE)) return FALSE; -if (!(vol = vshCommandOptVolBy(ctl, cmd, vol, pool, NULL, - VSH_BYUUID))) + +if (!(vol = vshCommandOptVol(ctl, cmd, vol, pool, name))) { return FALSE; +} vshPrint(ctl, %s\n, virStorageVolGetPath(vol)); virStorageVolFree(vol); Okay, small and makes sense, ACK and pushed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Fix use of virEventAddHandleImpl()
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/node_device/node_device_udev.c | 10 +- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index cf23be1..6b6e244 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -37,7 +37,7 @@ #include uuid.h #include util.h #include buf.h -#include daemon/event.h +#include event.h #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -1526,10 +1526,10 @@ static int udevDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED) * enumeration. The alternative is to register the callback after * we enumerate, in which case we will fail to create any devices * that appear while the enumeration is taking place. */ -if (virEventAddHandleImpl(udev_monitor_get_fd(udev_monitor), - VIR_EVENT_HANDLE_READABLE, - udevEventHandleCallback, - NULL, NULL) == -1) { +if (virEventAddHandle(udev_monitor_get_fd(udev_monitor), + VIR_EVENT_HANDLE_READABLE, + udevEventHandleCallback, + NULL, NULL) == -1) { ret = -1; goto out; } -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu_driver.c: avoid double free on error path
Note that there's nearly identical code in the same file where there is already an event = NULL; statement right after two identical lines. From 69f3c74b6cdc36fb4958f4c9cc2d4497a03d40c1 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 15:55:19 +0100 Subject: [PATCH] qemu_driver.c: avoid double free on error path * src/qemu/qemu_driver.c (qemudDomainMigrateFinish2): Set event to NULL after qemuDomainEventQueue frees it, so a subsequent free (after endjob label) upon qemuMonitorStartCPUs failure does not cause a double free. --- src/qemu/qemu_driver.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 34fa582..43f7927 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7668,6 +7668,7 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn, VIR_DOMAIN_EVENT_DEFINED_UPDATED); if (event) qemuDomainEventQueue(driver, event); +event = NULL; } qemuDomainObjPrivatePtr priv = vm-privateData; -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
On Mon, Dec 14, 2009 at 02:48:51PM +0100, Jim Meyering wrote: Jim Meyering wrote: Without this patch, a symlink pointing to a 4096-byte name could make this code write NUL into the byte beyond end of buffer: if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } devpath[n] = '\0'; From a075e207bc8fb279c43c9f4f43a960ffbd9a8a70 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): Leave one byte for the trailing NUL we'll append. --- src/node_device/node_device_driver.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..eda5d5e 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -97,7 +97,7 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if ((n = readlink(driver_link, devpath, sizeof devpath - 1)) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; The above is correct, but Daniel Veillard suggested a better (albeit slightly larger) change: use virFileResolveLink instead of readlink: From 4ae050481d481629fc98e8e7f5322ce6d724d3f7 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): The previous code would write one byte beyond the end of the 4KiB stack buffer when presented with a symlink value of exactly that length (very unlikely). Remove the automatic buffer and use virFileResolveLink in place of readlink. Suggested by Daniel Veillard. --- src/node_device/node_device_driver.c |7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..ecbac0f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -78,10 +78,9 @@ static int update_driver_name(virConnectPtr conn, virNodeDeviceObjPtr dev) { char *driver_link = NULL; -char devpath[PATH_MAX]; +char *devpath; char *p; int ret = -1; -int n; VIR_FREE(dev-def-driver); @@ -97,12 +96,11 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if (virFileResolveLink(driver_link, devpath) 0) { virReportSystemError(conn, errno, _(cannot resolve driver link %s), driver_link); goto cleanup; } -devpath[n] = '\0'; p = strrchr(devpath, '/'); if (p) { @@ -116,6 +114,7 @@ static int update_driver_name(virConnectPtr conn, cleanup: VIR_FREE(driver_link); +free(devpath); return ret; } #else ACK, thanks Jim ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Cleanup temporary #define after use
On Mon, Dec 14, 2009 at 01:53:03PM +, Matthew Booth wrote: * src/qemu/qemu_driver.c: #undef LOOKUP_PTYS after use --- src/qemu/qemu_driver.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 7e55c23..4567a66 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1436,6 +1436,7 @@ qemudFindCharDevicePTYsMonitor(virConnectPtr conn, LOOKUP_PTYS(vm-def-serials, vm-def-nserials, serial); LOOKUP_PTYS(vm-def-parallels, vm-def-nparallels, parallel); LOOKUP_PTYS(vm-def-channels, vm-def-nchannels, channel); +#undef LOOKUP_PTYS return 0; } Fine, not a big deal IMHO :-) Applied, will push soonish ! thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Fix use of virEventAddHandleImpl()
On Mon, Dec 14, 2009 at 03:29:42PM +0100, Jiri Denemark wrote: Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/node_device/node_device_udev.c | 10 +- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c index cf23be1..6b6e244 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -37,7 +37,7 @@ #include uuid.h #include util.h #include buf.h -#include daemon/event.h +#include event.h #define VIR_FROM_THIS VIR_FROM_NODEDEV @@ -1526,10 +1526,10 @@ static int udevDeviceMonitorStartup(int privileged ATTRIBUTE_UNUSED) * enumeration. The alternative is to register the callback after * we enumerate, in which case we will fail to create any devices * that appear while the enumeration is taking place. */ -if (virEventAddHandleImpl(udev_monitor_get_fd(udev_monitor), - VIR_EVENT_HANDLE_READABLE, - udevEventHandleCallback, - NULL, NULL) == -1) { +if (virEventAddHandle(udev_monitor_get_fd(udev_monitor), + VIR_EVENT_HANDLE_READABLE, + udevEventHandleCallback, + NULL, NULL) == -1) { ret = -1; goto out; } Ah, right, thanks for the fix ! Applied and pushed, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] Python script and extension module directory handling
On Sat, Dec 12, 2009 at 11:12:31AM +, Daniel P. Berrange wrote: On Sat, Dec 12, 2009 at 12:47:46AM +0100, Matthias Bolte wrote: From 1f5083be1dcbf6877dfbae44e9ea4e50ebaec708 Mon Sep 17 00:00:00 2001 From: Matthias Bolte matthias.bo...@googlemail.com Date: Sat, 12 Dec 2009 00:11:31 +0100 Subject: [PATCH] Fix install location for Python bindings Commit 66137344feb488ea87b0d92f3c03844d9a7a7786 changed the Python detection mechanism in configure to use AM_PATH_PYTHON. This results in a changed install location for the Python bindings, at least on Fedora 12 64bit systems. Before this commit libvirt.py and libvirtmod.so were installed to /usr/lib64/python2.6/site-packages After this commit they are installed to /usr/lib/python2.6/site-packages Mixed Python packages (containing *.py and *.so files) should be installed to the pyexecdir directory detected by AM_PATH_PYTHON. This restores the install location from before the AM_PATH_PYTHON commit. * configure.in: remove unnecessary pythondir export * python/Makefile.am: switch from pythondir to pyexecdir ACK this looks correct to me. ACK I was wondering a bit about the location for the .py, but I prefer this approach, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Eliminate failure to delete empty storage pools
On Sat, Dec 12, 2009 at 01:26:43AM -0500, Laine Stump wrote: virStorageBackendFileSystemDelete was incorrectly calling unlink() in an attempt to remove a directory. It should be calling rmdir() instead. (remove() would also work, but could potentially succeed on a non-empty pool if the pool was a symlink to somewhere else). --- src/storage/storage_backend_fs.c |4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index 16e4bd9..b7d4bd6 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -693,9 +693,9 @@ virStorageBackendFileSystemDelete(virConnectPtr conn, { /* XXX delete all vols first ? */ -if (unlink(pool-def-target.path) 0) { +if (rmdir(pool-def-target.path) 0) { virReportSystemError(conn, errno, - _(cannot unlink path '%s'), + _(failed to remove pool '%s'), pool-def-target.path); return -1; } Right, ACK ! Pushed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] add missing doc for device shareable/ option
On Sun, Dec 13, 2009 at 06:23:53PM +0100, Matthias Bolte wrote: 2009/12/11 Daniel Veillard veill...@redhat.com: This has been there forever, but we never documented it in the domain format page. The description is not fantastic, so improvements welcome :-) Daniel Typo: s/desactivated/deactivated/ Heh, that's the french verb popping out :-) ACK. thanks, pushed ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Fix owner and group in example volume XML
On Fri, Dec 11, 2009 at 03:56:14PM +, Matthew Booth wrote: The owner and group in the documentation examples were confusingly given as '0744'. They should be numeric uid and gid. Changed the examples to use the default uid and gid assigned to qemu in F12. * docs/formatstorage.html.in: Change example owner and group in volume XML Good point, pushed, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Fix parsing of 'info chardev' line endings
This change makes the 'info chardev' parser ignore any trailing whitespace on a line. This fixes a specific problem handling a '\r\n' line ending. * src/qemu/qemu_monitor_text.c: Ignore trailing whitespace in 'info chardev' output. --- src/qemu/qemu_monitor_text.c | 26 +- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c index 0cb9ea6..4fd8c4a 100644 --- a/src/qemu/qemu_monitor_text.c +++ b/src/qemu/qemu_monitor_text.c @@ -1622,15 +1622,26 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } -char *pos = reply; /* The current start of searching */ -char *end = pos + strlen(reply);/* The end of the reply string */ +char *pos; /* The current start of searching */ +char *next = reply; /* The start of the next line */ char *eol; /* The character which ends the current line */ +char *end = reply + strlen(reply); /* The end of the reply string */ + +while (next) { +pos = next; -while (pos end) { /* Split the output into lines */ eol = memchr(pos, '\n', end - pos); -if (eol == NULL) +if (eol == NULL) { eol = end; +next = NULL; +} else { +next = eol + 1; +} + +/* Ignore all whitespace immediately before eol */ +while (eol pos c_isspace(*(eol-1))) +eol -= 1; /* Look for 'filename=pty:' */ #define NEEDLE filename=pty: @@ -1638,13 +1649,13 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, /* If it's not there we can ignore this line */ if (!needle) -goto next; +continue; /* id is everthing from the beginning of the line to the ':' * find ':' and turn it into a terminator */ char *colon = memchr(pos, ':', needle - pos); if (colon == NULL) -goto next; +continue; *colon = '\0'; char *id = pos; @@ -1664,9 +1675,6 @@ int qemuMonitorTextGetPtyPaths(qemuMonitorPtr mon, goto cleanup; } #undef NEEDLE - -next: -pos = eol + 1; } ret = 0; -- 1.6.5.2 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] getSchedulerParameters() always returning nullpointerexception in JAVA
Can you send me more info on the use case.. and I will try and recreate it? In the mean time.. tell me if the patched jar file at: http://bkearney.fedorapeople.org/libvirt-0.4.0-PATCH.jar works. You will need to download this and copy it into /usr/share/java/libvirt-0.4.0.jar -- bk On 12/14/2009 04:22 AM, Marc Gonzalez Mateo wrote: OK, let's see if Bryan has an idea/solution about this. Thanks guys! MARC El 11/12/2009, a las 14:29, Daniel Veillard escribió: On Fri, Dec 11, 2009 at 02:01:36PM +0100, Marc Gonzalez Mateo wrote: Hi everyvody, I'm developing a new API based on libvirt. I'm currently stucked using getSchedulerParameters, always is returning a nullpointerexception, no matter which Xen Domain I'm passing to the function. Enclosing both the code and the error console: public int getCPUPriority(String name) { int res=-1; try { Domain d = getDomain(name); SchedParameter[] pars = d.getSchedulerParameters(); Hum, it seems Domain.getSchedulerParameters() does SchedParameter[] returnValue = new SchedParameter[0]; and public static SchedParameter create(virSchedParameter vParam) { SchedParameter returnValue = null; switch (vParam.type) { case (1): and the create method getting there gets a null pointer as the initialization argument, which it first dereference ... so not surprizing looking at the code, maybe Bryan has an idea of what is going on there, I'm a bit lost in this initialization process ... Daniel for (SchedParameter pri : pars) { if (pri.field==weight) res=Integer.parseInt(pri.getValueAsString()); } } catch (LibvirtException e) { log.error( Error: getting CPU priority of \+name+\. + e.getClass()); e.printStackTrace(); } return res; } Dec 11, 2009 1:04:18 PM net.emotivecloud.virtmonitor.VirtMonitor getCPUCapacity SEVERE: Error: getting CPU capacity of XenTest. java.lang.NullPointerException at org.libvirt.SchedParameter.create(Unknown Source) at org.libvirt.Domain.getSchedulerParameters(Unknown Source) at net.emotivecloud.virtmonitor.VirtMonitor.getCPUCapacity(VirtMonitor.java:462) at net.emotivecloud.virtmonitor.VirtMonitor.main(VirtMonitor.java:763) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:616) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:283) at java.lang.Thread.run(Thread.java:636) Any ideas? Thanks in advance, Marc Gonzalez Mateo -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu_driver.c: don't unlink(NULL) on OOM error path
Not terribly likely, but not impossible, either: From dc8fe76ed209d04b1e962b94b20da17a077e102f Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 16:41:11 +0100 Subject: [PATCH] qemu_driver.c: don't unlink(NULL) on OOM error path * src/qemu/qemu_driver.c (qemudDomainMigratePrepareTunnel): Upon an out of memory error, we would end up with unixfile==NULL and attempt to unlink(NULL). Skip the unlink when it's NULL. --- src/qemu/qemu_driver.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 56bcec5..04b2511 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6903,7 +6903,8 @@ endjob: cleanup: virDomainDefFree(def); -unlink(unixfile); +if (unixfile) + unlink(unixfile); VIR_FREE(unixfile); if (vm) virDomainObjUnlock(vm); -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] libvirtd: avoid a NULL dereference on error path
From f124b132913884ced6e9fbae8233056e0e97cd0a Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 16:45:11 +0100 Subject: [PATCH] libvirtd: avoid a NULL dereference on error path * daemon/libvirtd.c (qemudDispatchServer): Since client may be NULL in the cleanup: block, free client-rx only when it's not. --- daemon/libvirtd.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 6b7e33d..de6fc27 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1422,7 +1422,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket if (client client-tlssession) gnutls_deinit (client-tlssession); close (fd); -VIR_FREE(client-rx); +if (client) +VIR_FREE(client-rx); VIR_FREE(client); return -1; } -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_driver.c: don't unlink(NULL) on OOM error path
Jim Meyering wrote: Not terribly likely, but not impossible, either: From dc8fe76ed209d04b1e962b94b20da17a077e102f Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 16:41:11 +0100 Subject: [PATCH] qemu_driver.c: don't unlink(NULL) on OOM error path * src/qemu/qemu_driver.c (qemudDomainMigratePrepareTunnel): Upon an out of memory error, we would end up with unixfile==NULL and attempt to unlink(NULL). Skip the unlink when it's NULL. --- src/qemu/qemu_driver.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 56bcec5..04b2511 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6903,7 +6903,8 @@ endjob: cleanup: virDomainDefFree(def); -unlink(unixfile); +if (unixfile) + unlink(unixfile); Oops. Should have indented by 4, not 2. Adjusted that: From d73b657113804a092473a5fa59ad00d105c7dbaa Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 16:41:11 +0100 Subject: [PATCH] qemu_driver.c: don't unlink(NULL) on OOM error path * src/qemu/qemu_driver.c (qemudDomainMigratePrepareTunnel): Upon an out of memory error, we would end up with unixfile==NULL and attempt to unlink(NULL). Skip the unlink when it's NULL. --- src/qemu/qemu_driver.c |3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 56bcec5..c782f0d 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -6903,7 +6903,8 @@ endjob: cleanup: virDomainDefFree(def); -unlink(unixfile); +if (unixfile) +unlink(unixfile); VIR_FREE(unixfile); if (vm) virDomainObjUnlock(vm); -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Allow versioned pc machines for QEmu
On Fri, Dec 11, 2009 at 09:03:56PM +0100, Diego Elio “Flameeyes” Pettenò wrote: Il giorno Fri, 11/12/2009 alle 20.02 +, Daniel P. Berrange ha scritto: My preference is that we delete this choice block entirely and just declare it with a regex allowing a-Z, 0-9, _, -, . I guess whatever choice works ;) I'm mostly concerned that right now my configuration files don't validate… Okay, I commited the following patch, that should solve the problem, thanks ! Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ dan...@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/ diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index d1d3efb..784f9b1 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -167,13 +167,11 @@ /optional optional attribute name=machine - choice -valuexenfv/value -valuepc/value -valueisapc/value - /choice + data type=string +param name=pattern[a-zA-Z0-9_\.\-]+/param + /data /attribute -/optional + /optional /group /define define name=hvmmips -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] qemu migration: avoid NULL-deref given an invalid input
The fix here is to add the missing goto. Nearly every other use of qemudReportError is followed closely by a goto or a return statement. From 898033ec5bb0399f7cc6a22ffd9f351552ced85b Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 17:02:56 +0100 Subject: [PATCH] qemu migration: avoid NULL-deref given an invalid input * src/qemu/qemu_driver.c (doNonTunnelMigrate): Don't let a NULL uri_out provoke a NULL-dereference in doNativeMigrate: supply omitted goto-after-qemudReportError. --- src/qemu/qemu_driver.c |1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index c782f0d..9ef6c35 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7430,6 +7430,7 @@ static int doNonTunnelMigrate(virDomainPtr dom, if (uri_out == NULL) { qemudReportError(NULL, NULL, NULL, VIR_ERR_INTERNAL_ERROR, %s, _(domainMigratePrepare2 did not set uri)); +goto cleanup; } if (doNativeMigrate(dom, driver, vm, uri_out, flags, dname, resource) 0) -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] libvirt.c: don't let a NULL cpumaps argument provoke a NULL-deref
From 94923b161a9d066146271bb533b78ab7877e4501 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 17:17:53 +0100 Subject: [PATCH] libvirt.c: don't let a NULL cpumaps argument provoke a NULL-deref * src/libvirt.c (virDomainGetVcpus): Update spec to say that maplen is ignored when cpumaps is NULL. Set maplen to 0 in that case. --- src/libvirt.c |7 +++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index 008e322..4325aa4 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -4753,6 +4753,7 @@ error: * virDomainPinVcpu() API. * @maplen: number of bytes in one cpumap, from 1 up to size of CPU map in * underlying virtualization system (Xen...). + * Ignored when cpumaps is NULL. * * Extract information about virtual CPUs of domain, store it in info array * and also in cpumaps if this pointer isn't NULL. @@ -4776,6 +4777,12 @@ virDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__); goto error; } + +/* Ensure that domainGetVcpus (aka remoteDomainGetVcpus) does not + try to memcpy anything into a NULL pointer. */ +if (cpumaps == NULL) +maplen = 0; + if (cpumaps != NULL maplen 1) { virLibDomainError(domain, VIR_ERR_INVALID_ARG, __FUNCTION__); goto error; -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
On 12/14/2009 02:48 PM, Jim Meyering wrote: From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): The previous code would write one byte beyond the end of the 4KiB stack buffer when presented with a symlink value of exactly that length (very unlikely). Remove the automatic buffer and use virFileResolveLink in place of readlink. Suggested by Daniel Veillard. --- src/node_device/node_device_driver.c |7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..ecbac0f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -78,10 +78,9 @@ static int update_driver_name(virConnectPtr conn, virNodeDeviceObjPtr dev) { char *driver_link = NULL; -char devpath[PATH_MAX]; +char *devpath; char *p; int ret = -1; -int n; VIR_FREE(dev-def-driver); @@ -97,12 +96,11 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if (virFileResolveLink(driver_link, devpath) 0) { FYI; I found out today that virFileResolveLink() doesn't work on filesystems backed by sysfs (which unfortunately this code path is). The problem is that sysfs doesn't follow the POSIX-specified behavior of placing the size of the name of the real path in st.st_size; instead, on sysfs, st.st_size for symlinks is *always* 0 (at least on my F-12 box here). So this code path is probably broken now. DV said he will take a look at putting a patch together to make virFileResolveLink() handle the 0 case. -- Chris Lalancette -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink
Chris Lalancette wrote: On 12/14/2009 02:48 PM, Jim Meyering wrote: From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 12:05:38 +0100 Subject: [PATCH] node_device_driver.c: don't write beyond EOB for 4K-byte symlink * src/node_device/node_device_driver.c (update_driver_name): The previous code would write one byte beyond the end of the 4KiB stack buffer when presented with a symlink value of exactly that length (very unlikely). Remove the automatic buffer and use virFileResolveLink in place of readlink. Suggested by Daniel Veillard. --- src/node_device/node_device_driver.c |7 +++ 1 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_device_driver.c index f083f16..ecbac0f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -78,10 +78,9 @@ static int update_driver_name(virConnectPtr conn, virNodeDeviceObjPtr dev) { char *driver_link = NULL; -char devpath[PATH_MAX]; +char *devpath; char *p; int ret = -1; -int n; VIR_FREE(dev-def-driver); @@ -97,12 +96,11 @@ static int update_driver_name(virConnectPtr conn, goto cleanup; } -if ((n = readlink(driver_link, devpath, sizeof devpath)) 0) { +if (virFileResolveLink(driver_link, devpath) 0) { FYI; I found out today that virFileResolveLink() doesn't work on filesystems backed by sysfs (which unfortunately this code path is). The problem is that sysfs doesn't follow the POSIX-specified behavior of placing the size of the name of the real path in st.st_size; instead, on sysfs, st.st_size for symlinks is *always* 0 (at least on my F-12 box here). So this code path is probably broken now. DV said he will take a look at putting a patch together to make virFileResolveLink() handle the 0 case. Good point. Don't bother rolling your own. I'll prepare a patch to use gnulib's areadlink module. -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] xm_internal.c: remove misleading dead code
This code triggered a warning about possible NULL-dereference. Actually it's more about being self-contradictory, since the NULL-dereference is not possible. From 796e3a3254cb08fc20bce790997b5787dab51902 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 21:37:54 +0100 Subject: [PATCH] xm_internal.c: remove misleading dead code * src/xen/xm_internal.c (xenXMConfigGetULong): Remove useless and misleading test (always false) for val-str == NULL before code that always dereferences val-str. val comes from virConfGetValue, and at that point, val-str is guaranteed to be non-NULL. (xenXMConfigGetBool): Likewise. --- src/xen/xm_internal.c |6 -- 1 files changed, 0 insertions(+), 6 deletions(-) diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 3dc655b..944d5d5 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -152,9 +152,6 @@ static int xenXMConfigGetBool(virConnectPtr conn, if (val-type == VIR_CONF_LONG) { *value = val-l ? 1 : 0; } else if (val-type == VIR_CONF_STRING) { -if (!val-str) { -*value = def; -} *value = STREQ(val-str, 1) ? 1 : 0; } else { xenXMError(conn, VIR_ERR_INTERNAL_ERROR, @@ -183,9 +180,6 @@ static int xenXMConfigGetULong(virConnectPtr conn, *value = val-l; } else if (val-type == VIR_CONF_STRING) { char *ret; -if (!val-str) { -*value = def; -} *value = strtol(val-str, ret, 10); if (ret == val-str) { xenXMError(conn, VIR_ERR_INTERNAL_ERROR, -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] Python script and extension module directory handling
2009/12/14 Daniel Veillard veill...@redhat.com: On Sat, Dec 12, 2009 at 11:12:31AM +, Daniel P. Berrange wrote: On Sat, Dec 12, 2009 at 12:47:46AM +0100, Matthias Bolte wrote: From 1f5083be1dcbf6877dfbae44e9ea4e50ebaec708 Mon Sep 17 00:00:00 2001 From: Matthias Bolte matthias.bo...@googlemail.com Date: Sat, 12 Dec 2009 00:11:31 +0100 Subject: [PATCH] Fix install location for Python bindings Commit 66137344feb488ea87b0d92f3c03844d9a7a7786 changed the Python detection mechanism in configure to use AM_PATH_PYTHON. This results in a changed install location for the Python bindings, at least on Fedora 12 64bit systems. Before this commit libvirt.py and libvirtmod.so were installed to /usr/lib64/python2.6/site-packages After this commit they are installed to /usr/lib/python2.6/site-packages Mixed Python packages (containing *.py and *.so files) should be installed to the pyexecdir directory detected by AM_PATH_PYTHON. This restores the install location from before the AM_PATH_PYTHON commit. * configure.in: remove unnecessary pythondir export * python/Makefile.am: switch from pythondir to pyexecdir ACK this looks correct to me. ACK I was wondering a bit about the location for the .py, but I prefer this approach, thanks ! Daniel Okay, pushed. Matthias -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] Fix and improve domain xml video element description
2009/12/14 Daniel Veillard veill...@redhat.com: On Sun, Dec 13, 2009 at 10:15:20PM +0100, Matthias Bolte wrote: The description mismatched the actual structure since the video element was introduced. The nvram attribute is actually called vram. Specify the unit of the vram attribute. --- docs/formatdomain.html.in | 30 ++ 1 files changed, 22 insertions(+), 8 deletions(-) diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in index 5b7aa10..3d418b9 100644 --- a/docs/formatdomain.html.in +++ b/docs/formatdomain.html.in @@ -768,20 +768,34 @@ qemu-kvm -net nic,model=? /dev/null pre ... - lt;video type='vga' nvram='8192' heads='1'gt; - lt;acceleration accel3d='yes' accel3d='yes' /gt; + lt;videogt; + lt;model type='vga' vram='8192' heads='1'gt; + lt;acceleration accel3d='yes' accel3d='yes'/gt; + lt;/modelgt; lt;/videogt; .../pre dl dtcodevideo/code/dt - ddThe codevideo/code element has a mandatory codetype/code - attribute which takes the value vga, cirrus, vmvga, xen or vbox. - You can also provide the amount of video memory using codenvram/code, - the number of screen with codeheads/code, and whether acceleration - should be enabled (if supported) using the codeaccel3d/code and - codeaccel2d/code attributes in the codeacceleration/code element. + dd + The codevideo/code element is the a container for describing + video devices. + /dd + + dtcodemodel/code/dt + dd + The codemodel/code element has a mandatory codetype/code + attribute which takes the value vga, cirrus, vmvga, xen or vbox. + You can also provide the amount of video memory in kilobytes using + codevram/code and the number of screen with codeheads/code. + /dd + dtcodeacceleration/code/dt + dd + If acceleration should be enabled (if supported) using the + codeaccel3d/code and codeaccel2d/code attributes in the + codeacceleration/code element. + /dd /dl h4a name=elementsConsoleConsoles, serial, parallel amp; channel devices/a/h4 ACK, thanks for the cleanup ! Daniel Okay, pushed. Matthias -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 00/14] CPU selection patches
Hi, Here it is, finally. Jirka Jiri Denemark (14): XML schema for CPU flags XML parsing/formating code for CPU flags Public API Internal driver API Public API implementation Wire protocol format Remote driver Server side dispatcher CPU selection infrastructure CPU map for models and features CPU driver implementation Set getHostCPU handler in drivers Implement CPU selection in QEMU driver Implement virsh commands configure.in| 20 + daemon/Makefile.am |2 + daemon/libvirtd.c |3 + daemon/remote.c | 42 ++ daemon/remote_dispatch_prototypes.h | 16 + docs/schemas/capability.rng | 46 ++- docs/schemas/domain.rng | 62 ++ include/libvirt/libvirt.h.in| 15 + include/libvirt/virterror.h |2 + src/Makefile.am | 43 ++- src/conf/capabilities.c | 31 +- src/conf/capabilities.h |6 + src/conf/cpu_conf.c | 366 +++ src/conf/cpu_conf.h | 116 src/conf/domain_conf.c | 15 + src/conf/domain_conf.h |2 + src/cpu/cpu.c | 206 +++ src/cpu/cpu.h | 124 src/cpu/cpu_driver.c| 190 ++ src/cpu/cpu_driver.h| 40 ++ src/cpu/cpu_generic.c | 123 src/cpu/cpu_generic.h | 32 + src/cpu/cpu_map.c | 130 src/cpu/cpu_map.h | 41 ++ src/cpu/cpu_map.xml | 304 ++ src/cpu/cpu_x86.c | 1142 +++ src/cpu/cpu_x86.h | 31 + src/cpu/cpu_x86_data.h | 45 ++ src/datatypes.h |2 + src/driver.h| 20 + src/esx/esx_driver.c|1 + src/libvirt.c | 129 src/libvirt_private.syms| 19 + src/libvirt_public.syms |6 + src/lxc/lxc_driver.c|1 + src/openvz/openvz_driver.c |1 + src/qemu/qemu_conf.c| 401 - src/qemu/qemu_conf.h|7 + src/qemu/qemu_driver.c | 37 +- src/remote/remote_driver.c | 125 src/remote/remote_protocol.c| 27 + src/remote/remote_protocol.x| 18 +- src/test/test_driver.c |1 + src/uml/uml_driver.c|1 + src/util/virterror.c|8 + src/vbox/vbox_tmpl.c|1 + tools/virsh.c | 65 ++ 47 files changed, 4029 insertions(+), 36 deletions(-) create mode 100644 src/conf/cpu_conf.c create mode 100644 src/conf/cpu_conf.h create mode 100644 src/cpu/cpu.c create mode 100644 src/cpu/cpu.h create mode 100644 src/cpu/cpu_driver.c create mode 100644 src/cpu/cpu_driver.h create mode 100644 src/cpu/cpu_generic.c create mode 100644 src/cpu/cpu_generic.h create mode 100644 src/cpu/cpu_map.c create mode 100644 src/cpu/cpu_map.h create mode 100644 src/cpu/cpu_map.xml create mode 100644 src/cpu/cpu_x86.c create mode 100644 src/cpu/cpu_x86.h create mode 100644 src/cpu/cpu_x86_data.h -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 01/14] XML schema for CPU flags
Firstly, CPU topology and model with optional features have to be advertised in host capabilities: host cpu archARCHITECTURE/arch features !-- old-style features are here -- /features modelNAME/model topology sockets=S cores=C threads=T/ feature name=NAME/ /cpu ... /host Secondly, drivers which support detailed CPU specification have to advertise it in guest capabilities: guest ... features cpuselection/ /features /guest And finally, CPU may be configured in domain XML configuration: domain ... cpu match=MATCH modelNAME/model topology sockets=S cores=C threads=T/ feature policy=POLICY name=NAME/ /cpu /domain Where MATCH can be one of: - 'minimum' specified CPU is the minimum requested CPU - 'exact' disable all additional features provided by host CPU - 'strict' fail if host CPU doesn't exactly match POLICY can be one of: - 'force' turn on the feature, even if host doesn't have it - 'require' fail if host doesn't have the feature - 'optional'match host - 'disable' turn off the feature, even if host has it - 'forbid' fail if host has the feature 'force' and 'disable' policies turn on/off the feature regardless of its availability on host. 'force' is unlikely to be used but its there for completeness since Xen and VMWare allow it. 'require' and 'forbid' policies prevent a guest from being started on a host which doesn't/does have the feature. 'forbid' is for cases where you disable the feature but a guest may still try to access it anyway and you don't want it to succeed. 'optional' policy sets the feature according to its availability on host. When a guest is booted on a host that has the feature and then migrated to another host, the policy changes to 'require' as we can't take the feature away from a running guest. Default policy for features provided by host CPU but not specified in domain configuration is set using match attribute of cpu tag. If 'minimum' match is requested, additional features will be treated as if they were specified with 'optional' policy. 'exact' match implies 'disable' policy and 'strict' match stands for 'forbid' policy. Signed-off-by: Jiri Denemark jdene...@redhat.com --- docs/schemas/capability.rng | 46 +++- docs/schemas/domain.rng | 62 +++ 2 files changed, 107 insertions(+), 1 deletions(-) diff --git a/docs/schemas/capability.rng b/docs/schemas/capability.rng index 3e8944c..378652e 100644 --- a/docs/schemas/capability.rng +++ b/docs/schemas/capability.rng @@ -25,6 +25,9 @@ optional ref name='cpufeatures'/ /optional + optional + ref name='cpuspec'/ + /optional /element optional ref name='migration'/ @@ -67,6 +70,31 @@ /element /define + define name='cpuspec' +element name='model' + text/ +/element +element name='topology' + attribute name='sockets' +ref name='positiveInteger'/ + /attribute + attribute name='cores' +ref name='positiveInteger'/ + /attribute + attribute name='threads' +ref name='positiveInteger'/ + /attribute +/element +zeroOrMore + element name='feature' +attribute name='name' + ref name='featureName'/ +/attribute +empty/ + /element +/zeroOrMore + /define + define name='migration' element name='migration_features' optional @@ -259,6 +287,11 @@ empty/ /element /optional + optional +element name='cpuselection' + empty/ +/element + /optional /element /define @@ -293,8 +326,14 @@ /define + define name='positiveInteger' +data type='positiveInteger' + param name=pattern[0-9]+/param +/data + /define + define name='uint' -data type='string' +data type='unsignedInt' param name=pattern[0-9]+/param /data /define @@ -305,4 +344,9 @@ /data /define + define name='featureName' +data type='string' + param name='pattern'[a-zA-Z0-9\-_]+/param +/data + /define /grammar diff --git a/docs/schemas/domain.rng b/docs/schemas/domain.rng index 784f9b1..566b117 100644 --- a/docs/schemas/domain.rng +++ b/docs/schemas/domain.rng @@ -27,6 +27,9 @@ optional ref name=description/ /optional +optional + ref name=cpu/ +/optional ref name=os/ ref name=clock/ ref name=resources/ @@ -1235,6 +1238,55 @@ /optional /define !-- + CPU specification + -- + define name=cpu +element name=cpu + attribute name=match +choice + valueminimum/value + valueexact/value
[libvirt] [PATCH 02/14] XML parsing/formating code for CPU flags
Signed-off-by: Jiri Denemark jdene...@redhat.com --- include/libvirt/virterror.h |1 + src/Makefile.am |9 +- src/conf/capabilities.c | 31 - src/conf/capabilities.h |6 + src/conf/cpu_conf.c | 366 +++ src/conf/cpu_conf.h | 116 ++ src/conf/domain_conf.c | 15 ++ src/conf/domain_conf.h |2 + src/libvirt_private.syms|9 + src/util/virterror.c|3 + 10 files changed, 555 insertions(+), 3 deletions(-) create mode 100644 src/conf/cpu_conf.c create mode 100644 src/conf/cpu_conf.h diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 8548a8d..30f88e8 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -68,6 +68,7 @@ typedef enum { VIR_FROM_ESX, /* Error from ESX driver */ VIR_FROM_PHYP, /* Error from IBM power hypervisor */ VIR_FROM_SECRET,/* Error from secret storage */ +VIR_FROM_CPU, /* Error from CPU driver */ } virErrorDomain; diff --git a/src/Makefile.am b/src/Makefile.am index b639915..432a66e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -114,6 +114,9 @@ NODE_DEVICE_CONF_SOURCES = \ ENCRYPTION_CONF_SOURCES = \ conf/storage_encryption_conf.c conf/storage_encryption_conf.h +CPU_CONF_SOURCES = \ + conf/cpu_conf.c conf/cpu_conf.h + CONF_SOURCES = \ $(DOMAIN_CONF_SOURCES) \ $(DOMAIN_EVENT_SOURCES) \ @@ -122,7 +125,8 @@ CONF_SOURCES = \ $(STORAGE_CONF_SOURCES) \ $(ENCRYPTION_CONF_SOURCES) \ $(INTERFACE_CONF_SOURCES) \ - $(SECRET_CONF_SOURCES) + $(SECRET_CONF_SOURCES) \ + $(CPU_CONF_SOURCES) # The remote RPC driver, covering domains, storage, networks, etc REMOTE_DRIVER_SOURCES =\ @@ -831,7 +835,8 @@ libvirt_lxc_SOURCES = \ $(UTIL_SOURCES) \ $(NODE_INFO_SOURCES)\ $(ENCRYPTION_CONF_SOURCES) \ - $(DOMAIN_CONF_SOURCES) + $(DOMAIN_CONF_SOURCES) \ + $(CPU_CONF_SOURCES) libvirt_lxc_LDFLAGS = $(WARN_CFLAGS) $(COVERAGE_LDCFLAGS) $(CAPNG_LIBS) $(YAJL_LIBS) libvirt_lxc_LDADD = $(LIBXML_LIBS) $(NUMACTL_LIBS) ../gnulib/lib/libgnu.la libvirt_lxc_CFLAGS = \ diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 476bba6..47976af 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -27,6 +27,7 @@ #include buf.h #include memory.h #include util.h +#include cpu_conf.h /** * virCapabilitiesNew: @@ -171,6 +172,8 @@ virCapabilitiesFree(virCapsPtr caps) { VIR_FREE(caps-host.arch); VIR_FREE(caps-host.secModel.model); VIR_FREE(caps-host.secModel.doi); +virCPUDefFree(caps-host.cpu); + VIR_FREE(caps); } @@ -263,6 +266,27 @@ virCapabilitiesAddHostNUMACell(virCapsPtr caps, return 0; } + +/** + * virCapabilitiesSetHostCPU: + * @caps: capabilities to extend + * @cpu: CPU definition + * + * Sets host CPU specification + */ +int +virCapabilitiesSetHostCPU(virCapsPtr caps, + virCPUDefPtr cpu) +{ +if (cpu == NULL) +return -1; + +caps-host.cpu = cpu; + +return 0; +} + + /** * virCapabilitiesAllocMachines: * @machines: machine variants for emulator ('pc', or 'isapc', etc) @@ -653,6 +677,10 @@ virCapabilitiesFormatXML(virCapsPtr caps) } virBufferAddLit(xml, /features\n); } + +virCPUDefFormatBuf(NULL, xml, caps-host.cpu, , + VIR_CPU_FORMAT_EMBEDED); + virBufferAddLit(xml, /cpu\n); if (caps-host.offlineMigrate) { @@ -750,7 +778,8 @@ virCapabilitiesFormatXML(virCapsPtr caps) for (j = 0 ; j caps-guests[i]-nfeatures ; j++) { if (STREQ(caps-guests[i]-features[j]-name, pae) || STREQ(caps-guests[i]-features[j]-name, nonpae) || -STREQ(caps-guests[i]-features[j]-name, ia64_be)) { +STREQ(caps-guests[i]-features[j]-name, ia64_be) || +STREQ(caps-guests[i]-features[j]-name, cpuselection)) { virBufferVSprintf(xml, %s/\n, caps-guests[i]-features[j]-name); } else { diff --git a/src/conf/capabilities.h
[libvirt] [PATCH 03/14] Public API
Signed-off-by: Jiri Denemark jdene...@redhat.com --- include/libvirt/libvirt.h.in | 15 +++ src/libvirt_public.syms |6 ++ 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index 6c3aded..ec7f475 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -1676,6 +1676,21 @@ int virInterfaceIsActive(virInterfacePtr iface); int virConnectIsEncrypted(virConnectPtr conn); int virConnectIsSecure(virConnectPtr conn); +/* + * CPU specification API + */ + +typedef enum { +VIR_CPU_COMPARE_ERROR = -1, +VIR_CPU_COMPARE_INCOMPATIBLE= 0, +VIR_CPU_COMPARE_IDENTICAL = 1, +VIR_CPU_COMPARE_SUPERSET= 2 +} virCPUCompareResult; + +int virConnectCompareCPU(virConnectPtr conn, + const char *xmlDesc); + +char *virConnectGetHostCPU(virConnectPtr conn); #ifdef __cplusplus diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index b4f57e7..2193151 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -343,4 +343,10 @@ LIBVIRT_0.7.3 { virInterfaceIsActive; } LIBVIRT_0.7.2; +LIBVIRT_0.7.5 { +global: +virConnectCompareCPU; +virConnectGetHostCPU; +} LIBVIRT_0.7.3; + # define new API here using predicted next version number -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 04/14] Internal driver API
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/driver.h | 20 src/libvirt_private.syms |1 + 2 files changed, 21 insertions(+), 0 deletions(-) diff --git a/src/driver.h b/src/driver.h index 09ce8e2..16bf9bf 100644 --- a/src/driver.h +++ b/src/driver.h @@ -349,6 +349,9 @@ typedef int typedef int (*virDrvDomainIsPersistent)(virDomainPtr dom); +typedef char * +(*virDrvGetHostCPU)(virConnectPtr conn); + /** * _virDriver: * @@ -435,6 +438,7 @@ struct _virDriver { virDrvConnectIsSecure isSecure; virDrvDomainIsActive domainIsActive; virDrvDomainIsPersistent domainIsPersistent; +virDrvGetHostCPUgetHostCPU; }; typedef int @@ -944,6 +948,21 @@ struct _virStreamDriver { }; +typedef int (*virDrvCPUCompare)(virConnectPtr conn, +const char *cpu); + + +typedef struct _virCPUDriver virCPUDriver; +typedef virCPUDriver *virCPUDriverPtr; +struct _virCPUDriver { +const char *name;/* the name of the driver */ +virDrvOpen open; +virDrvClose close; + +virDrvCPUComparecompare; +}; + + /* * Registration * TODO: also need ways to (des)activate a given driver @@ -955,6 +974,7 @@ int virRegisterInterfaceDriver(virInterfaceDriverPtr); int virRegisterStorageDriver(virStorageDriverPtr); int virRegisterDeviceMonitor(virDeviceMonitorPtr); int virRegisterSecretDriver(virSecretDriverPtr); +int virRegisterCPUDriver(virCPUDriverPtr); #ifdef WITH_LIBVIRTD int virRegisterStateDriver(virStateDriverPtr); #endif diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 9acd062..f10527a 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -276,6 +276,7 @@ virRegisterStateDriver; virRegisterStorageDriver; virRegisterDeviceMonitor; virRegisterSecretDriver; +virRegisterCPUDriver; # json.h -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 05/14] Public API implementation
Signed-off-by: Jiri Denemark jdene...@redhat.com --- include/libvirt/virterror.h |1 + src/libvirt.c | 129 +++ src/util/virterror.c|5 ++ 3 files changed, 135 insertions(+), 0 deletions(-) diff --git a/include/libvirt/virterror.h b/include/libvirt/virterror.h index 30f88e8..85d562e 100644 --- a/include/libvirt/virterror.h +++ b/include/libvirt/virterror.h @@ -175,6 +175,7 @@ typedef enum { VIR_ERR_OPERATION_TIMEOUT, /* timeout occurred during operation */ VIR_ERR_MIGRATE_PERSIST_FAILED, /* a migration worked, but making the VM persist on the dest host failed */ +VIR_WAR_NO_CPU, /* failed to start cpu driver */ } virErrorNumber; /** diff --git a/src/libvirt.c b/src/libvirt.c index 008e322..997cdcc 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -87,6 +87,8 @@ static virDeviceMonitorPtr virDeviceMonitorTab[MAX_DRIVERS]; static int virDeviceMonitorTabCount = 0; static virSecretDriverPtr virSecretDriverTab[MAX_DRIVERS]; static int virSecretDriverTabCount = 0; +static virCPUDriverPtr virCPUDriverTab[MAX_DRIVERS]; +static int virCPUDriverTabCount = 0; #ifdef WITH_LIBVIRTD static virStateDriverPtr virStateDriverTab[MAX_DRIVERS]; static int virStateDriverTabCount = 0; @@ -745,6 +747,37 @@ virRegisterSecretDriver(virSecretDriverPtr driver) } /** + * virRegisterCPUDriver: + * @driver: pointer to a cpu driver block + * + * Register a CPU driver + * + * Returns the driver priority or -1 in case of error. + */ +int +virRegisterCPUDriver(virCPUDriverPtr driver) +{ +if (virInitialize() 0) + return -1; + +if (driver == NULL) { +virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); +return(-1); +} + +if (virCPUDriverTabCount = MAX_DRIVERS) { +virLibConnError(NULL, VIR_ERR_INVALID_ARG, __FUNCTION__); +return(-1); +} + +DEBUG (registering %s as cpu driver %d, + driver-name, virCPUDriverTabCount); + +virCPUDriverTab[virCPUDriverTabCount] = driver; +return virCPUDriverTabCount++; +} + +/** * virRegisterDriver: * @driver: pointer to a driver block * @@ -1180,6 +1213,25 @@ do_open (const char *name, } } +for (i = 0; i virCPUDriverTabCount; i++) { +res = virCPUDriverTab[i]-open (ret, auth, flags); +DEBUG(cpu driver %d %s returned %s, + i, virCPUDriverTab[i]-name, + res == VIR_DRV_OPEN_SUCCESS ? SUCCESS : + (res == VIR_DRV_OPEN_DECLINED ? DECLINED : + (res == VIR_DRV_OPEN_ERROR ? ERROR : unknown status))); +if (res == VIR_DRV_OPEN_ERROR) { +if (STREQ(virCPUDriverTab[i]-name, remote)) { +virLibConnWarning (NULL, VIR_WAR_NO_CPU, + Is the daemon running ?); +} +break; +} else if (res == VIR_DRV_OPEN_SUCCESS) { +ret-cpuDriver = virCPUDriverTab[i]; +break; +} +} + return ret; failed: @@ -10701,3 +10753,80 @@ error: virSetConnError(conn); return -1; } + + +/** + * virConnectCompareCPU: + * @conn: virConnect connection + * @xml: XML describing the CPU to compare with host CPU + * + * Returns comparison result according to enum virCPUCompareResult + */ +int +virConnectCompareCPU(virConnectPtr conn, const char *xmlDesc) +{ +VIR_DEBUG(conn=%p, xmlDesc=%s, conn, xmlDesc); + +virResetLastError(); + +if (!VIR_IS_CONNECT(conn)) { +virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); +return VIR_CPU_COMPARE_ERROR; +} +if (xmlDesc == NULL) { +virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__); +goto error; +} + +if (conn-cpuDriver != NULL conn-cpuDriver-compare != NULL) { +int ret; + +ret = conn-cpuDriver-compare(conn, xmlDesc); +if (ret == VIR_CPU_COMPARE_ERROR) +goto error; +return ret; +} + +virLibConnError(conn, VIR_ERR_NO_SUPPORT, __FUNCTION__); + +error: +/* Copy to connection error object for back compatibility */ +virSetConnError(conn); +return VIR_CPU_COMPARE_ERROR; +} + +/** + * virConnectGetHostCPU: + * @conn: virConnect connection + * + * Returns XML description of host CPU. The returned cpu element contains + * data from the cpu element of host capabilities which correspond to the + * structure of cpu element in domain configuration XML. + */ +char * +virConnectGetHostCPU(virConnectPtr conn) +{ +VIR_DEBUG(conn=%p, conn); + +virResetLastError(); + +if (!VIR_IS_CONNECT(conn)) { +virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__); +return NULL; +} + +if (conn-driver != NULL conn-driver-getHostCPU != NULL) { +char *ret; + +if ((ret = conn-driver-getHostCPU(conn)) != NULL) { +VIR_DEBUG(result=%s, ret); +return ret; +} +} + +
[libvirt] [PATCH 07/14] Remote driver
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/remote/remote_driver.c | 125 1 files changed, 125 insertions(+), 0 deletions(-) diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index affeb0f..b60d6d4 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -7465,6 +7465,122 @@ done: return rv; } + +static virDrvOpenStatus ATTRIBUTE_NONNULL (1) +remoteCPUOpen(virConnectPtr conn, + virConnectAuthPtr auth ATTRIBUTE_UNUSED, + int flags ATTRIBUTE_UNUSED) +{ +if (inside_daemon) +return VIR_DRV_OPEN_DECLINED; + +if (conn-driver +STREQ (conn-driver-name, remote)) { +struct private_data *priv = conn-privateData; +/* If we're here, the remote driver is already + * in use due to a) a QEMU uri, or b) a remote + * URI. So we can re-use existing connection + */ +remoteDriverLock(priv); +priv-localUses++; +conn-cpuPrivateData = priv; +remoteDriverUnlock(priv); +return VIR_DRV_OPEN_SUCCESS; +} else if (conn-networkDriver + STREQ (conn-networkDriver-name, remote)) { +struct private_data *priv = conn-networkPrivateData; +remoteDriverLock(priv); +conn-cpuPrivateData = priv; +priv-localUses++; +remoteDriverUnlock(priv); +return VIR_DRV_OPEN_SUCCESS; +} else { +/* Using a non-remote driver, so we need to open a + * new connection for network APIs, forcing it to + * use the UNIX transport. This handles Xen driver + * which doesn't have its own impl of the network APIs. + */ +struct private_data *priv; +int ret; +ret = remoteOpenSecondaryDriver(conn, +auth, +flags, +priv); +if (ret == VIR_DRV_OPEN_SUCCESS) +conn-cpuPrivateData = priv; +return ret; +} +} + + +static int remoteCPUClose(virConnectPtr conn) +{ +int ret = 0; +struct private_data *priv = conn-cpuPrivateData; + +remoteDriverLock(priv); +priv-localUses--; +if (!priv-localUses) { +ret = doRemoteClose(conn, priv); +conn-cpuPrivateData = NULL; +remoteDriverUnlock(priv); +virMutexDestroy(priv-lock); +VIR_FREE(priv); +} +if (priv) +remoteDriverUnlock(priv); +return ret; +} + + +static int +remoteCPUCompare (virConnectPtr conn, const char *xmlDesc) +{ +struct private_data *priv = conn-cpuPrivateData; +remote_cpu_compare_args args; +remote_cpu_compare_ret ret; +int rv = VIR_CPU_COMPARE_ERROR; + +remoteDriverLock (priv); + +args.xml = (char *) xmlDesc; + +memset (ret, 0, sizeof (ret)); +if (call (conn, priv, 0, REMOTE_PROC_CPU_COMPARE, + (xdrproc_t) xdr_remote_cpu_compare_args, (char *) args, + (xdrproc_t) xdr_remote_cpu_compare_ret, (char *) ret) == -1) +goto done; + +rv = ret.result; + +done: +remoteDriverUnlock (priv); +return rv; +} + +static char * +remoteGetHostCPU (virConnectPtr conn) +{ +char *rv = NULL; +remote_get_host_cpu_ret ret; +struct private_data *priv = conn-privateData; + +remoteDriverLock(priv); + +memset (ret, 0, sizeof ret); +if (call (conn, priv, 0, REMOTE_PROC_GET_HOST_CPU, + (xdrproc_t) xdr_void, (char *) NULL, + (xdrproc_t) xdr_remote_get_host_cpu_ret, (char *)ret) == -1) +goto done; + +/* Caller frees this. */ +rv = ret.cpu; + +done: +remoteDriverUnlock(priv); +return rv; +} + /*--*/ @@ -8830,6 +8946,7 @@ static virDriver remote_driver = { remoteIsSecure, /* isSecure */ remoteDomainIsActive, /* domainIsActive */ remoteDomainIsPersistent, /* domainIsPersistent */ +remoteGetHostCPU, /* getHostCPU */ }; static virNetworkDriver network_driver = { @@ -8928,6 +9045,13 @@ static virSecretDriver secret_driver = { .undefine = remoteSecretUndefine }; +static virCPUDriver cpu_driver = { +.name = remote, +.open = remoteCPUOpen, +.close = remoteCPUClose, +.compare = remoteCPUCompare +}; + static virDeviceMonitor dev_monitor = { .name = remote, .open = remoteDevMonOpen, @@ -8967,6 +9091,7 @@ remoteRegister (void) if (virRegisterStorageDriver (storage_driver) == -1) return -1; if (virRegisterDeviceMonitor (dev_monitor) == -1) return -1; if (virRegisterSecretDriver (secret_driver) == -1) return -1; +if (virRegisterCPUDriver (cpu_driver) == -1) return -1; #ifdef WITH_LIBVIRTD if (virRegisterStateDriver (state_driver) == -1) return -1; #endif -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 06/14] Wire protocol format
Signed-off-by: Jiri Denemark jdene...@redhat.com --- daemon/remote_dispatch_prototypes.h | 16 src/remote/remote_protocol.c| 27 +++ src/remote/remote_protocol.x| 18 +- 3 files changed, 60 insertions(+), 1 deletions(-) diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h index b05a9a4..a6c13f0 100644 --- a/daemon/remote_dispatch_prototypes.h +++ b/daemon/remote_dispatch_prototypes.h @@ -50,6 +50,14 @@ static int remoteDispatchClose( remote_error *err, void *args, void *ret); +static int remoteDispatchCpuCompare( +struct qemud_server *server, +struct qemud_client *client, +virConnectPtr conn, +remote_message_header *hdr, +remote_error *err, +remote_cpu_compare_args *args, +remote_cpu_compare_ret *ret); static int remoteDispatchDomainAttachDevice( struct qemud_server *server, struct qemud_client *client, @@ -458,6 +466,14 @@ static int remoteDispatchGetCapabilities( remote_error *err, void *args, remote_get_capabilities_ret *ret); +static int remoteDispatchGetHostCpu( +struct qemud_server *server, +struct qemud_client *client, +virConnectPtr conn, +remote_message_header *hdr, +remote_error *err, +void *args, +remote_get_host_cpu_ret *ret); static int remoteDispatchGetHostname( struct qemud_server *server, struct qemud_client *client, diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c index a10558a..221e81c 100644 --- a/src/remote/remote_protocol.c +++ b/src/remote/remote_protocol.c @@ -2857,6 +2857,33 @@ xdr_remote_interface_is_active_ret (XDR *xdrs, remote_interface_is_active_ret *o } bool_t +xdr_remote_cpu_compare_args (XDR *xdrs, remote_cpu_compare_args *objp) +{ + + if (!xdr_remote_nonnull_string (xdrs, objp-xml)) + return FALSE; +return TRUE; +} + +bool_t +xdr_remote_cpu_compare_ret (XDR *xdrs, remote_cpu_compare_ret *objp) +{ + + if (!xdr_int (xdrs, objp-result)) + return FALSE; +return TRUE; +} + +bool_t +xdr_remote_get_host_cpu_ret (XDR *xdrs, remote_get_host_cpu_ret *objp) +{ + + if (!xdr_remote_nonnull_string (xdrs, objp-cpu)) + return FALSE; +return TRUE; +} + +bool_t xdr_remote_procedure (XDR *xdrs, remote_procedure *objp) { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 92f7010..1a06c16 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -1433,6 +1433,20 @@ struct remote_interface_is_active_ret { }; +struct remote_cpu_compare_args { +remote_nonnull_string xml; +}; + +struct remote_cpu_compare_ret { +int result; +}; + + +struct remote_get_host_cpu_ret { +remote_nonnull_string cpu; +}; + + /*- Protocol. -*/ /* Define the program number, protocol version and procedure numbers here. */ @@ -1611,7 +1625,9 @@ enum remote_procedure { REMOTE_PROC_STORAGE_POOL_IS_ACTIVE = 154, REMOTE_PROC_STORAGE_POOL_IS_PERSISTENT = 155, REMOTE_PROC_INTERFACE_IS_ACTIVE = 156, -REMOTE_PROC_GET_LIB_VERSION = 157 +REMOTE_PROC_GET_LIB_VERSION = 157, +REMOTE_PROC_CPU_COMPARE = 158, +REMOTE_PROC_GET_HOST_CPU = 159 /* * Notice how the entries are grouped in sets of 10 ? -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 08/14] Server side dispatcher
Signed-off-by: Jiri Denemark jdene...@redhat.com --- daemon/remote.c | 42 ++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index 7a43046..7a3 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -5226,6 +5226,48 @@ static int remoteDispatchIsSecure(struct qemud_server *server ATTRIBUTE_UNUSED, } +static int +remoteDispatchCpuCompare (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + remote_cpu_compare_args *args, + remote_cpu_compare_ret *ret) +{ +int result; + +result = virConnectCompareCPU (conn, args-xml); +if (result == VIR_CPU_COMPARE_ERROR) { +remoteDispatchConnError (err, conn); +return -1; +} + +ret-result = result; +return 0; +} + +static int +remoteDispatchGetHostCpu (struct qemud_server *server ATTRIBUTE_UNUSED, + struct qemud_client *client ATTRIBUTE_UNUSED, + virConnectPtr conn, + remote_message_header *hdr ATTRIBUTE_UNUSED, + remote_error *err, + void *args ATTRIBUTE_UNUSED, + remote_get_host_cpu_ret *ret) +{ +char *cpu; + +cpu = virConnectGetHostCPU (conn); +if (cpu == NULL) { +remoteDispatchConnError(err, conn); +return -1; +} + +ret-cpu = cpu; +return 0; +} + /*- Helpers. -*/ /* get_nonnull_domain and get_nonnull_network turn an on-wire -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 10/14] CPU map for models and features
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/Makefile.am |2 + src/cpu/cpu_map.xml | 304 +++ 2 files changed, 306 insertions(+), 0 deletions(-) create mode 100644 src/cpu/cpu_map.xml diff --git a/src/Makefile.am b/src/Makefile.am index 471e403..7d731de 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -287,6 +287,8 @@ CPU_SOURCES = \ cpu/cpu_x86.h cpu/cpu_x86.c cpu/cpu_x86_data.h \ cpu/cpu_map.h cpu/cpu_map.c +EXTRA_DIST += cpu/cpu_map.xml + # # # Build up list of libvirt.la source files based on configure conditions diff --git a/src/cpu/cpu_map.xml b/src/cpu/cpu_map.xml new file mode 100644 index 000..3d1cef9 --- /dev/null +++ b/src/cpu/cpu_map.xml @@ -0,0 +1,304 @@ +cpus + arch name=x86 +!-- standard features, EDX -- +feature name='fpu' !-- CPUID_FP87 -- + cpuid function='0x0001' edx='0x0001'/ +/feature +feature name='vme' !-- CPUID_VME -- + cpuid function='0x0001' edx='0x0002'/ +/feature +feature name='de' !-- CPUID_DE -- + cpuid function='0x0001' edx='0x0004'/ +/feature +feature name='pse' !-- CPUID_PSE -- + cpuid function='0x0001' edx='0x0008'/ +/feature +feature name='tsc' !-- CPUID_TSC -- + cpuid function='0x0001' edx='0x0010'/ +/feature +feature name='msr' !-- CPUID_MSR -- + cpuid function='0x0001' edx='0x0020'/ +/feature +feature name='pae' !-- CPUID_PAE -- + cpuid function='0x0001' edx='0x0040'/ +/feature +feature name='mce' !-- CPUID_MCE -- + cpuid function='0x0001' edx='0x0080'/ +/feature +feature name='cx8' !-- CPUID_CX8 -- + cpuid function='0x0001' edx='0x0100'/ +/feature +feature name='apic' !-- CPUID_APIC -- + cpuid function='0x0001' edx='0x0200'/ +/feature +feature name='sep' !-- CPUID_SEP -- + cpuid function='0x0001' edx='0x0800'/ +/feature +feature name='mtrr' !-- CPUID_MTRR -- + cpuid function='0x0001' edx='0x1000'/ +/feature +feature name='pge' !-- CPUID_PGE -- + cpuid function='0x0001' edx='0x2000'/ +/feature +feature name='mca' !-- CPUID_MCA -- + cpuid function='0x0001' edx='0x4000'/ +/feature +feature name='cmov' !-- CPUID_CMOV -- + cpuid function='0x0001' edx='0x8000'/ +/feature +feature name='pat' !-- CPUID_PAT -- + cpuid function='0x0001' edx='0x0001'/ +/feature +feature name='pse36' !-- CPUID_PSE36 -- + cpuid function='0x0001' edx='0x0002'/ +/feature +feature name='pn' !-- CPUID_PN -- + cpuid function='0x0001' edx='0x0004'/ +/feature +feature name='clflush' !-- CPUID_CLFLUSH -- + cpuid function='0x0001' edx='0x0008'/ +/feature +feature name='ds' !-- CPUID_DTS -- + cpuid function='0x0001' edx='0x0020'/ +/feature +feature name='acpi' !-- CPUID_ACPI -- + cpuid function='0x0001' edx='0x0040'/ +/feature +feature name='mmx' !-- CPUID_MMX -- + cpuid function='0x0001' edx='0x0080'/ +/feature +feature name='fxsr' !-- CPUID_FXSR -- + cpuid function='0x0001' edx='0x0100'/ +/feature +feature name='sse' !-- CPUID_SSE -- + cpuid function='0x0001' edx='0x0200'/ +/feature +feature name='sse2' !-- CPUID_SSE2 -- + cpuid function='0x0001' edx='0x0400'/ +/feature +feature name='ss' !-- CPUID_SS -- + cpuid function='0x0001' edx='0x0800'/ +/feature +feature name='ht' !-- CPUID_HT -- + cpuid function='0x0001' edx='0x1000'/ +/feature +feature name='tm' !-- CPUID_TM -- + cpuid function='0x0001' edx='0x2000'/ +/feature +feature name='ia64' !-- CPUID_IA64 -- + cpuid function='0x0001' edx='0x4000'/ +/feature +feature name='pbe' !-- CPUID_PBE -- + cpuid function='0x0001' edx='0x8000'/ +/feature + +!-- standard features, ECX -- +feature name='pni' !-- CPUID_EXT_SSE3 -- + cpuid function='0x0001' ecx='0x0001'/ +/feature +feature name='monitor' !-- CPUID_EXT_MONITOR -- + cpuid function='0x0001' ecx='0x0008'/ +/feature +feature name='ds_cpl' !-- CPUID_EXT_DSCPL -- + cpuid function='0x0001' ecx='0x0010'/ +/feature +feature name='vmx' !-- CPUID_EXT_VMX -- + cpuid function='0x0001' ecx='0x0020'/ +/feature +feature name='est' !-- CPUID_EXT_EST -- + cpuid function='0x0001' ecx='0x0080'/ +/feature +feature name='tm2' !-- CPUID_EXT_TM2 -- + cpuid function='0x0001' ecx='0x0100'/ +/feature +feature name='ssse3' !-- CPUID_EXT_SSSE3 -- + cpuid function='0x0001'
[libvirt] [PATCH 11/14] CPU driver implementation
Signed-off-by: Jiri Denemark jdene...@redhat.com --- daemon/Makefile.am |2 + daemon/libvirtd.c|3 + src/Makefile.am | 20 +- src/cpu/cpu_driver.c | 190 ++ src/cpu/cpu_driver.h | 40 +++ src/datatypes.h |2 + 6 files changed, 256 insertions(+), 1 deletions(-) create mode 100644 src/cpu/cpu_driver.c create mode 100644 src/cpu/cpu_driver.h diff --git a/daemon/Makefile.am b/daemon/Makefile.am index ab3f238..d239a89 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -110,6 +110,8 @@ endif if WITH_NODE_DEVICES libvirtd_LDADD += ../src/libvirt_driver_nodedev.la endif + +libvirtd_LDADD += ../src/libvirt_driver_cpu.la endif libvirtd_LDADD += ../src/libvirt.la diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 6b7e33d..56c16dc 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -94,6 +94,7 @@ #include node_device/node_device_driver.h #endif #include secret/secret_driver.h +#include cpu/cpu_driver.h #endif @@ -867,6 +868,7 @@ static struct qemud_server *qemudInitialize(void) { virDriverLoadModule(lxc); virDriverLoadModule(uml); virDriverLoadModule(one); +virDriverLoadModule(cpu); #else #ifdef WITH_NETWORK networkRegister(); @@ -893,6 +895,7 @@ static struct qemud_server *qemudInitialize(void) { #ifdef WITH_ONE oneRegister(); #endif +cpuRegister(); #endif virEventRegisterImpl(virEventAddHandleImpl, diff --git a/src/Makefile.am b/src/Makefile.am index 7d731de..3551a10 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -289,6 +289,9 @@ CPU_SOURCES = \ EXTRA_DIST += cpu/cpu_map.xml +CPU_DRIVER_SOURCES = \ + cpu/cpu_driver.h cpu/cpu_driver.c + # # # Build up list of libvirt.la source files based on configure conditions @@ -696,6 +699,20 @@ libvirt_driver_security_la_CFLAGS += $(APPARMOR_CFLAGS) libvirt_driver_security_la_LDFLAGS += $(APPARMOR_LIBS) endif + +if WITH_DRIVER_MODULES +mod_LTLIBRARIES += libvirt_driver_cpu.la +else +noinst_LTLIBRARIES += libvirt_driver_cpu.la +libvirt_la_LIBADD += libvirt_driver_cpu.la +endif +libvirt_driver_cpu_la_CFLAGS = \ + -...@top_srcdir@/src/conf +if WITH_DRIVER_MODULES +libvirt_driver_cpu_la_LDFLAGS = -module -avoid-version +endif +libvirt_driver_cpu_la_SOURCES = $(CPU_DRIVER_SOURCES) + # Add all conditional sources just in case... EXTRA_DIST += \ $(TEST_DRIVER_SOURCES) \ @@ -724,7 +741,8 @@ EXTRA_DIST += \ $(SECURITY_DRIVER_SELINUX_SOURCES) \ $(SECURITY_DRIVER_APPARMOR_SOURCES) \ $(SECRET_DRIVER_SOURCES)\ - $(VBOX_DRIVER_EXTRA_DIST) + $(VBOX_DRIVER_EXTRA_DIST) \ + $(CPU_DRIVER_SOURCES) check-local: if WITH_QEMU diff --git a/src/cpu/cpu_driver.c b/src/cpu/cpu_driver.c new file mode 100644 index 000..60425b4 --- /dev/null +++ b/src/cpu/cpu_driver.c @@ -0,0 +1,190 @@ +/* + * cpu_driver.c: Unified CPU driver; unified interface to architecture + * specific CPU drivers. + * + * Copyright (C) 2009 Red Hat, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Authors: + * Jiri Denemark jdene...@redhat.com + */ + +#include config.h + +#include memory.h +#include datatypes.h +#include virterror_internal.h +#include logging.h +#include driver.h + +#include cpu_driver.h +#include cpu.h + + +#define VIR_FROM_THIS VIR_FROM_CPU + + +struct cpu_driver { +virMutex lock; + +virCPUDefPtr host_cpu; +}; + + +static virCPUDefPtr +cpuParseString(virConnectPtr conn, + const char *cpu, + enum virCPUType mode) +{ +xmlDocPtr xml = NULL; +xmlXPathContextPtr ctxt = NULL; +virCPUDefPtr def = NULL; + +xml = xmlParseMemory(cpu, strlen(cpu)); + +if (xml == NULL || (ctxt = xmlXPathNewContext(xml)) == NULL) { +virReportOOMError(conn); +goto cleanup; +} + +ctxt-node =
[libvirt] [PATCH 09/14] CPU selection infrastructure
Each driver supporting CPU selection must fill in host CPU capabilities. When filling them, drivers for hypervisors running on the same node as libvirtd can use cpuNodeData() to obtain raw CPU data. Other drivers, such as VMware, need to implement their own way of getting such data. Raw data can be decoded into virCPUDefPtr using cpuDecode() function. For each guest for which a driver supports selecting CPU models, it must set the appropriate feature in guest's capabilities: virCapabilitiesAddGuestFeature(guest, cpuselection, 1, 0) Actions needed when a domain is being created depend on whether the hypervisor understands raw CPU data (currently CPUID for i686, x86_64 architectures) or symbolic names has to be used. Typical use by hypervisors which prefer CPUID (such as VMware and Xen): - convert guest CPU configuration from domain's XML into a set of raw data structures each representing one of the feature policies: cpuEncode(conn, architecture, guest_cpu_config, forced_data, required_data, optional_data, disabled_data, forbidden_data) - create a mask or whatever the hypervisor expects to see and pass it to the hypervisor Typical use by hypervisors with symbolic model names (such as QEMU): - get raw CPU data for a computed guest CPU: cpuGuestData(conn, host_cpu, guest_cpu_config, data) - decode raw data into virCPUDefPtr with a possible restriction on allowed model names: cpuDecode(conn, guest, data, n_allowed_models, allowed_models) - pass guest-model and guest-features to the hypervisor Signed-off-by: Jiri Denemark jdene...@redhat.com --- configure.in | 20 + src/Makefile.am | 12 + src/cpu/cpu.c| 206 + src/cpu/cpu.h| 124 + src/cpu/cpu_generic.c| 123 + src/cpu/cpu_generic.h| 32 ++ src/cpu/cpu_map.c| 130 ++ src/cpu/cpu_map.h| 41 ++ src/cpu/cpu_x86.c| 1142 ++ src/cpu/cpu_x86.h| 31 ++ src/cpu/cpu_x86_data.h | 45 ++ src/libvirt_private.syms |9 + 12 files changed, 1915 insertions(+), 0 deletions(-) create mode 100644 src/cpu/cpu.c create mode 100644 src/cpu/cpu.h create mode 100644 src/cpu/cpu_generic.c create mode 100644 src/cpu/cpu_generic.h create mode 100644 src/cpu/cpu_map.c create mode 100644 src/cpu/cpu_map.h create mode 100644 src/cpu/cpu_x86.c create mode 100644 src/cpu/cpu_x86.h create mode 100644 src/cpu/cpu_x86_data.h diff --git a/configure.in b/configure.in index 6135932..15f2b3d 100644 --- a/configure.in +++ b/configure.in @@ -78,6 +78,26 @@ AC_SUBST(VERSION_SCRIPT_FLAGS) LIBVIRT_COMPILE_WARNINGS([maximum]) +AC_MSG_CHECKING([for CPUID instruction]) +AC_COMPILE_IFELSE(AC_LANG_PROGRAM( + [[ +#include stdint.h + ]], + [[ +uint32_t eax, ebx, ecx, edx; +asm volatile ( +cpuid +: =a (eax), =b (ebx), =c (ecx), =d (edx) +: a (eax)); + ]]), + [have_cpuid=yes], + [have_cpuid=no]) +if test x$have_cpuid = xyes; then + AC_DEFINE_UNQUOTED([HAVE_CPUID], 1, [whether CPUID instruction is supported]) +fi +AC_MSG_RESULT([$have_cpuid]) + + dnl Support large files / 64 bit seek offsets. dnl Use --disable-largefile if you don't want this. AC_SYS_LARGEFILE diff --git a/src/Makefile.am b/src/Makefile.am index 432a66e..471e403 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,7 @@ INCLUDES = \ -DSBINDIR=\$(sbindir)\ \ -DSYSCONF_DIR=\$(sysconfdir)\ \ -DLOCALEBASEDIR=\$(datadir)/locale\ \ + -DDATADIR=\$(datadir)/libvirt\ \ -DLOCAL_STATE_DIR=\$(localstatedir)\\ -DGETTEXT_PACKAGE=\$(PACKAGE)\\ $(WARN_CFLAGS) \ @@ -280,6 +281,11 @@ NODE_DEVICE_DRIVER_UDEV_SOURCES = \ node_device/node_device_udev.c \ node_device/node_device_udev.h +CPU_SOURCES = \ + cpu/cpu.h cpu/cpu.c \ + cpu/cpu_generic.h cpu/cpu_generic.c \ + cpu/cpu_x86.h cpu/cpu_x86.c cpu/cpu_x86_data.h \ + cpu/cpu_map.h cpu/cpu_map.c # # @@ -301,6 +307,12 @@ libvirt_conf_la_SOURCES = $(CONF_SOURCES) libvirt_conf_la_CFLAGS = libvirt_conf_la_LDFLAGS = +noinst_LTLIBRARIES += libvirt_cpu.la +libvirt_la_LIBADD += libvirt_cpu.la +libvirt_cpu_la_CFLAGS = \ + -...@top_srcdir@/src/conf +libvirt_cpu_la_SOURCES = $(CPU_SOURCES) + noinst_LTLIBRARIES += libvirt_driver.la libvirt_la_LIBADD += libvirt_driver.la diff --git a/src/cpu/cpu.c b/src/cpu/cpu.c new file mode 100644 index 000..e204303 --- /dev/null +++ b/src/cpu/cpu.c @@
[libvirt] [PATCH 12/14] Set getHostCPU handler in drivers
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/esx/esx_driver.c |1 + src/lxc/lxc_driver.c |1 + src/openvz/openvz_driver.c |1 + src/test/test_driver.c |1 + src/uml/uml_driver.c |1 + src/vbox/vbox_tmpl.c |1 + 6 files changed, 6 insertions(+), 0 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index ea464a3..953ee55 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -3428,6 +3428,7 @@ static virDriver esxDriver = { esxIsSecure, /* isSecure */ esxDomainIsActive, /* domainIsActive */ esxDomainIsPersistent, /* domainIsPersistent */ +NULL,/* getHostCPU */ }; diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index c8e2dca..e574e9e 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -2454,6 +2454,7 @@ static virDriver lxcDriver = { lxcIsSecure, lxcDomainIsActive, lxcDomainIsPersistent, +NULL, /* getHostCPU */ }; static virStateDriver lxcStateDriver = { diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index 1c0fccc..faabd26 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -1533,6 +1533,7 @@ static virDriver openvzDriver = { openvzIsSecure, openvzDomainIsActive, openvzDomainIsPersistent, +NULL, /* getHostCPU */ }; int openvzRegister(void) { diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 7db9a4c..d2e77f9 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5236,6 +5236,7 @@ static virDriver testDriver = { testIsSecure, /* isEncrypted */ testDomainIsActive, /* domainIsActive */ testDomainIsPersistent, /* domainIsPersistent */ +NULL, /* getHostCPU */ }; static virNetworkDriver testNetworkDriver = { diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index 48ef103..9ef8e95 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1922,6 +1922,7 @@ static virDriver umlDriver = { umlIsSecure, umlDomainIsActive, umlDomainIsPersistent, +NULL, /* getHostCPU */ }; diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index d6b681c..16a3caf 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -7049,6 +7049,7 @@ virDriver NAME(Driver) = { vboxIsSecure, vboxDomainIsActive, vboxDomainIsPersistent, +NULL, /* getHostCPU */ }; virNetworkDriver NAME(NetworkDriver) = { -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 13/14] Implement CPU selection in QEMU driver
Signed-off-by: Jiri Denemark jdene...@redhat.com --- src/qemu/qemu_conf.c | 401 +--- src/qemu/qemu_conf.h |7 + src/qemu/qemu_driver.c | 37 -- 3 files changed, 415 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 86172c6..237c9b7 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -52,6 +52,7 @@ #include nodeinfo.h #include logging.h #include network.h +#include cpu/cpu.h #define VIR_FROM_THIS VIR_FROM_QEMU @@ -608,6 +609,151 @@ qemudGetOldMachines(const char *ostype, return 0; } + +typedef int +(*qemudParseCPUModels)(const char *output, + unsigned int *retcount, + const char ***retcpus); + +/* Format: + * arch model + */ +static int +qemudParseX86Models(const char *output, +unsigned int *retcount, +const char ***retcpus) +{ +const char *p = output; +const char *next; +unsigned int count = 0; +const char **cpus = NULL; +int i; + +do { +const char *t; + +if ((next = strchr(p, '\n'))) +next++; + +if (!(t = strchr(p, ' ')) || (next t = next)) +continue; + +if (!STRPREFIX(p, x86)) +continue; + +p = t; +while (*p == ' ') +p++; + +if (*p == '\0' || *p == '\n') +continue; + +if (retcpus) { +if (VIR_REALLOC_N(cpus, count + 1) 0) +goto error; + +if (next) +cpus[count] = strndup(p, next - p - 1); +else +cpus[count] = strdup(p); + +if (!cpus[count]) +goto error; +} +count++; +} while ((p = next)); + +if (retcount) +*retcount = count; +if (retcpus) +*retcpus = cpus; + +return 0; + +error: +if (cpus) { +for (i = 0; i count; i++) +VIR_FREE(cpus[i]); +} +VIR_FREE(cpus); + +return -1; +} + + +int +qemudProbeCPUModels(const char *qemu, +const char *arch, +unsigned int *count, +const char ***cpus) +{ +const char *const qemuarg[] = { qemu, -cpu, ?, NULL }; +const char *const qemuenv[] = { LC_ALL=C, NULL }; +enum { MAX_MACHINES_OUTPUT_SIZE = 1024*4 }; +char *output = NULL; +int newstdout = -1; +int ret = -1; +pid_t child; +int status; +int len; +qemudParseCPUModels parse; + +if (count) +*count = 0; +if (cpus) +*cpus = NULL; + +if (STREQ(arch, i686) || STREQ(arch, x86_64)) +parse = qemudParseX86Models; +else { +VIR_DEBUG(_(don't know how to parse %s CPU models), arch); +return 0; +} + +if (virExec(NULL, qemuarg, qemuenv, NULL, +child, -1, newstdout, NULL, VIR_EXEC_CLEAR_CAPS) 0) +return -1; + +len = virFileReadLimFD(newstdout, MAX_MACHINES_OUTPUT_SIZE, output); +if (len 0) { +virReportSystemError(NULL, errno, %s, + _(Unable to read QEMU supported CPU models)); +goto cleanup; +} + +if (parse(output, count, cpus) 0) { +virReportOOMError(NULL); +goto cleanup; +} + +ret = 0; + +cleanup: +VIR_FREE(output); +if (close(newstdout) 0) +ret = -1; + +rewait: +if (waitpid(child, status, 0) != child) { +if (errno == EINTR) +goto rewait; + +VIR_ERROR(_(Unexpected exit status from qemu %d pid %lu), + WEXITSTATUS(status), (unsigned long)child); +ret = -1; +} +/* Check log unexpected exit status, but don't fail, + * as there's really no need to throw an error if we did + * actually read a valid version number above */ +if (WEXITSTATUS(status) != 0) { +VIR_WARN(_(Unexpected exit status '%d', qemu probably failed), + WEXITSTATUS(status)); +} + +return ret; +} + + static int qemudCapsInitGuest(virCapsPtr caps, virCapsPtr old_caps, @@ -624,6 +770,7 @@ qemudCapsInitGuest(virCapsPtr caps, virCapsGuestMachinePtr *machines = NULL; int nmachines = 0; struct stat st; +unsigned int ncpus; /* Check for existance of base emulator, or alternate base * which can be used with magic cpu choice @@ -725,6 +872,11 @@ qemudCapsInitGuest(virCapsPtr caps, guest-arch.defaultInfo.emulator_mtime = binary_mtime; +if (qemudProbeCPUModels(binary, info-arch, ncpus, NULL) == 0 + ncpus 0 + !virCapabilitiesAddGuestFeature(guest, cpuselection, 1, 0)) +return -1; + if (hvm) { if (virCapabilitiesAddGuestDomain(guest, qemu, @@ -808,6 +960,49 @@ qemudCapsInitGuest(virCapsPtr caps, return 0; } + +static int +qemudCapsInitCPU(virCapsPtr caps, + const char
[libvirt] [PATCH 14/14] Implement virsh commands
Signed-off-by: Jiri Denemark jdene...@redhat.com --- tools/virsh.c | 65 + 1 files changed, 65 insertions(+), 0 deletions(-) diff --git a/tools/virsh.c b/tools/virsh.c index 8f96ca8..e992999 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -6836,6 +6836,70 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd) return ret; } +/* + * cpu-compare command + */ +static const vshCmdInfo info_cpu_compare[] = { +{help, gettext_noop(compare host CPU with a CPU described by an XML file)}, +{desc, gettext_noop(compare CPU with host CPU)}, +{NULL, NULL} +}; + +static const vshCmdOptDef opts_cpu_compare[] = { +{file, VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop(file containing an XML CPU description)}, +{NULL, 0, 0, NULL} +}; + +static int +cmdCPUCompare(vshControl *ctl, const vshCmd *cmd) +{ +char *from; +int found; +int ret = TRUE; +char *buffer; +int result; + +if (!vshConnectionUsability(ctl, ctl-conn, TRUE)) +return FALSE; + +from = vshCommandOptString(cmd, file, found); +if (!found) +return FALSE; + +if (virFileReadAll(from, VIRSH_MAX_XML_FILE, buffer) 0) +return FALSE; + +result = virConnectCompareCPU(ctl-conn, buffer); +free (buffer); + +switch (result) { +case VIR_CPU_COMPARE_INCOMPATIBLE: +vshPrint(ctl, _(CPU described in %s is incompatible with host CPU\n), + from); +ret = FALSE; +break; + +case VIR_CPU_COMPARE_IDENTICAL: +vshPrint(ctl, _(CPU described in %s is identical to host CPU\n), + from); +ret = TRUE; +break; + +case VIR_CPU_COMPARE_SUPERSET: +vshPrint(ctl, _(Host CPU is a superset of CPU described in %s\n), + from); +ret = TRUE; +break; + +case VIR_CPU_COMPARE_ERROR: +default: +vshError(ctl, _(Failed to compare host CPU with %s), from); +ret = FALSE; +} + +return ret; +} + /* Common code for the edit / net-edit / pool-edit functions which follow. */ static char * editWriteToTempFile (vshControl *ctl, const char *doc) @@ -7207,6 +7271,7 @@ static const vshCmdDef commands[] = { #ifndef WIN32 {console, cmdConsole, opts_console, info_console}, #endif +{cpu-compare, cmdCPUCompare, opts_cpu_compare, info_cpu_compare}, {create, cmdCreate, opts_create, info_create}, {start, cmdStart, opts_start, info_start}, {destroy, cmdDestroy, opts_destroy, info_destroy}, -- 1.6.5.6 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] Fix memory leak in qemudBuildCommandLine
--- src/qemu/qemu_conf.c |2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 86172c6..2ee2042 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1893,7 +1893,7 @@ int qemudBuildCommandLine(virConnectPtr conn, } ADD_ARG_LIT(-monitor); -ADD_ARG_LIT(virBufferContentAndReset(buf)); +ADD_ARG(virBufferContentAndReset(buf)); } if (def-localtime) -- 1.6.0.4 -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu_driver.c: avoid double free on error path
2009/12/14 Jim Meyering j...@meyering.net: Note that there's nearly identical code in the same file where there is already an event = NULL; statement right after two identical lines. From 69f3c74b6cdc36fb4958f4c9cc2d4497a03d40c1 Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 15:55:19 +0100 Subject: [PATCH] qemu_driver.c: avoid double free on error path * src/qemu/qemu_driver.c (qemudDomainMigrateFinish2): Set event to NULL after qemuDomainEventQueue frees it, so a subsequent free (after endjob label) upon qemuMonitorStartCPUs failure does not cause a double free. --- src/qemu/qemu_driver.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 34fa582..43f7927 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -7668,6 +7668,7 @@ qemudDomainMigrateFinish2 (virConnectPtr dconn, VIR_DOMAIN_EVENT_DEFINED_UPDATED); if (event) qemuDomainEventQueue(driver, event); + event = NULL; } qemuDomainObjPrivatePtr priv = vm-privateData; -- 1.6.6.rc2.275.g51e2d ACK. Matthias -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] libvirtd: avoid a NULL dereference on error path
2009/12/14 Jim Meyering j...@meyering.net: From f124b132913884ced6e9fbae8233056e0e97cd0a Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Mon, 14 Dec 2009 16:45:11 +0100 Subject: [PATCH] libvirtd: avoid a NULL dereference on error path * daemon/libvirtd.c (qemudDispatchServer): Since client may be NULL in the cleanup: block, free client-rx only when it's not. --- daemon/libvirtd.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 6b7e33d..de6fc27 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1422,7 +1422,8 @@ static int qemudDispatchServer(struct qemud_server *server, struct qemud_socket if (client client-tlssession) gnutls_deinit (client-tlssession); close (fd); - VIR_FREE(client-rx); + if (client) + VIR_FREE(client-rx); VIR_FREE(client); return -1; } -- 1.6.6.rc2.275.g51e2d ACK. Matthias -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] Cannot start domain w/xenner emulator
# virsh start Ubuntu-domU-x86-1 Connecting to uri: qemu:///system error: Failed to start domain Ubuntu-domU-x86-1 error: internal error unable to start guest: libvir: error : cannot execute binary /usr/bin/xenner: Permission denied # ls -l /usr/bin/xenner -rwxr-xr-x 1 root root 118936 2009-12-14 17:05 /usr/bin/xenner Sure looks executable. And there's no SELinux on the box. libvirt is 0.7.0 What the..? -Gerry -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH] avoid malfunction when virFileResolveLink is applied to non-POSIX FS
Without this patch, virFileResolveLink could misbehave when applied to a file on a POSIX-nonconforming file system. The fix is to use gnulib's areadlink module, but it's GPL'd. I'm ready to relax it to LGPLv2+, and have asked the other author for his rubber stamp. Once that's fixed, this change will depend on having an up-to-date gnulib submodule. That will be the subject of my next message. From a3133b2e8b1453578b30e4b9c83c7473feb7c65b Mon Sep 17 00:00:00 2001 From: Jim Meyering meyer...@redhat.com Date: Tue, 15 Dec 2009 08:27:53 +0100 Subject: [PATCH] avoid malfunction when virFileResolveLink is applied to non-POSIX FS The virFileResolveLink utility function relied on the POSIX guarantee that stat.st_size of a symlink is the length of the value. However, on some types of file systems, it is invalid, so do not rely on it. Use gnulib's areadlink module instead. * bootstrap (modules): Add areadlink. * src/util/util.c: Include areadlink.h. Let areadlink perform the readlink and malloc. * configure.in (AC_CHECK_FUNCS): Remove readlink. No need, since it's presence is guaranteed by gnulib. --- bootstrap |1 + configure.in|2 +- src/util/util.c | 27 +++ 3 files changed, 5 insertions(+), 25 deletions(-) diff --git a/bootstrap b/bootstrap index 667af4f..c07d851 100755 --- a/bootstrap +++ b/bootstrap @@ -65,6 +65,7 @@ gnulib_tool=$GNULIB_SRCDIR/gnulib-tool $gnulib_tool || exit modules=' +areadlink base64 c-ctype close diff --git a/configure.in b/configure.in index 6135932..6ed2efd 100644 --- a/configure.in +++ b/configure.in @@ -83,7 +83,7 @@ dnl Use --disable-largefile if you don't want this. AC_SYS_LARGEFILE dnl Availability of various common functions (non-fatal if missing). -AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid posix_fallocate mmap readlink]) +AC_CHECK_FUNCS([cfmakeraw regexec uname sched_getaffinity getuid getgid posix_fallocate mmap]) dnl Availability of various not common threadsafe functions AC_CHECK_FUNCS([strerror_r strtok_r getmntent_r getgrnam_r getpwuid_r]) diff --git a/src/util/util.c b/src/util/util.c index 694838a..44a4b2f 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -64,6 +64,7 @@ #include mntent.h #endif +#include areadlink.h #include virterror_internal.h #include logging.h #include event.h @@ -1059,10 +1060,7 @@ int virFileLinkPointsTo(const char *checkLink, int virFileResolveLink(const char *linkpath, char **resultpath) { -#ifdef HAVE_READLINK struct stat st; -char *buf; -int n; *resultpath = NULL; @@ -1075,28 +1073,9 @@ int virFileResolveLink(const char *linkpath, return 0; } -/* Posix says that 'st_size' field from - * result of an lstat() call is filled with - * number of bytes in the destination - * filename. - */ -if (VIR_ALLOC_N(buf, st.st_size + 1) 0) -return -ENOMEM; - -if ((n = readlink(linkpath, buf, st.st_size)) 0) { -VIR_FREE(buf); -return -errno; -} - -buf[n] = '\0'; +*resultpath = areadlink (linkpath); -*resultpath = buf; -return 0; -#else -if (!(*resultpath = strdup(linkpath))) -return -ENOMEM; -return 0; -#endif +return *resultpath == NULL ? -1 : 0; } /* -- 1.6.6.rc2.275.g51e2d -- Libvir-list mailing list Libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list