]> git.ipfire.org Git - thirdparty/libvirt.git/log
thirdparty/libvirt.git
13 years agoavoid fd leak
Wen Congyang [Wed, 30 May 2012 09:20:46 +0000 (17:20 +0800)] 
avoid fd leak

virCommandRunAsync() will set errfd if it succeed. We should
close it if virFDStreamOpenInternal() fails.
(cherry picked from commit 655cffa0f25be40c68624036af80bde102177612)

13 years agoavoid closing uninitialized fd
Wen Congyang [Wed, 30 May 2012 09:20:41 +0000 (17:20 +0800)] 
avoid closing uninitialized fd

If the system does not support bypass cache, we will close fd,
but it is uninitialized.
(cherry picked from commit 0a045f01cfa48fabd41c801e3f44034a4e6da485)

13 years agoSet a sensible default master start port for ehci companion controllers
Daniel P. Berrange [Mon, 14 May 2012 12:22:58 +0000 (13:22 +0100)] 
Set a sensible default master start port for ehci companion controllers

The uhci1, uhci2, uhci3 companion controllers for ehci1 must
have a master start port set. Since this value is predictable
we should set it automatically if the app does not supply it
(cherry picked from commit 03b804a200e214e3faf264b16f41a640c1344962)

13 years agoFix logic for assigning PCI addresses to USB2 companion controllers
Daniel P. Berrange [Mon, 14 May 2012 10:16:22 +0000 (11:16 +0100)] 
Fix logic for assigning PCI addresses to USB2 companion controllers

Currently each USB2 companion controller gets put on a separate
PCI slot. Not only is this wasteful of PCI slots, but it is not
in compliance with the spec for USB2 controllers. The master
echi1 and all companion controllers should be in the same slot,
with echi1 in function 7, and uhci1-3 in functions 0-2 respectively.

* src/qemu/qemu_command.c: Special case handling of USB2 controllers
  to apply correct pci slot assignment
* tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.args,
  tests/qemuxml2argvdata/qemuxml2argv-usb-ich9-ehci-addr.xml: Expand
  test to cover automatic slot assignment
(cherry picked from commit 1ebd52cb871f87b7868503b28448e96d59e41d63)

Conflicts:

tests/qemuxml2xmltest.c

13 years agoFix virDomainDeviceInfoIsSet() to check all struct fields
Daniel P. Berrange [Tue, 15 May 2012 15:16:49 +0000 (16:16 +0100)] 
Fix virDomainDeviceInfoIsSet() to check all struct fields

The virDomainDeviceInfoIsSet API was only checking if an
address or alias was set in the struct. Thus if only a
rom bar setting / filename, boot index, or USB master
value was set, they could be accidentally dropped when
formatting XML
(cherry picked from commit 2c195fdbf3293792e39bc4f06755ae751025b0ea)

Conflicts:

src/conf/domain_conf.c

(crobinso: some elements aren't in maint branch, drop them)

13 years agolxc: use hand-rolled code in place of unlockpt and grantpt
Serge E. Hallyn [Wed, 19 Oct 2011 01:39:57 +0000 (20:39 -0500)] 
lxc: use hand-rolled code in place of unlockpt and grantpt

The glibc ones (intentionally) cannot handle ptys opened in a
devpts not mounted at /dev/pts.

Drop the (un-exported, unused) virFileOpenTtyAt.

Signed-off-by: Serge Hallyn <serge.hallyn@canonical.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
(cherry picked from commit 80710c69fee323870b2a8239d93c5e5dddf28366)

Conflicts:

src/lxc/lxc_controller.c

13 years agoxen: do not use ioemu type for any emulated NIC
Stefan Bader [Fri, 13 Apr 2012 13:14:56 +0000 (15:14 +0200)] 
xen: do not use ioemu type for any emulated NIC

When using the xm/xend stack to manage instances there is a bug
that causes the emulated interfaces to be unusable when the vif
config contains type=ioemu.

The current code already has a special quirk to not use this
keyword if no specific model is given for the emulated NIC
(defaulting to rtl8139).
Essentially it works because regardless of the type argument,i
the Xen stack always creates emulated and paravirt interfaces and
lets the guest decide which one to use. So neither xl nor xm stack
actually require the type keyword for emulated NICs.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
(cherry picked from commit 10c31135f321851f02ad1985684389a42f6f5e54)

13 years agoxend_internal: Use domain/status for shutdown check
Stefan Bader [Thu, 12 Apr 2012 13:42:37 +0000 (15:42 +0200)] 
xend_internal: Use domain/status for shutdown check

On newer xend (v3.x and after) there is no state and domid reported
for inactive domains. When initially creating connections this is
handled in various places by assigning domain->id = -1.
But once an instance has been running, the id is set to the current
domain id. And it does not change when the instance is shut down.
So when querying the domain info, the hypervisor driver, which gets
asked first will indicate it cannot find information, then the
xend driver is asked and will set the status to NOSTATE because it
checks for the -1 domain id.
Checking domain/status for 0 seems to be more reliable for that.

One note: I am not sure whether the domain->id also should get set
back to -1 whenever any sub-driver thinks the instance is no longer
running.

BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=746007
BugLink: http://bugs.launchpad.net/bugs/929626
Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
(cherry picked from commit 26e9ef476239e8cb79f819092c5aac4afdd47d0d)

(crobinso: Add Stefan to AUTHORS. maint only)

13 years agoxen-xm: SIGSEGV in xenXMDomainDefineXML: filename
Philipp Hahn [Mon, 6 Feb 2012 13:13:18 +0000 (14:13 +0100)] 
xen-xm: SIGSEGV in xenXMDomainDefineXML: filename

filename is not initialized to NULL while it's unconditionally freed in
the error path.

Signed-off-by: Philipp Hahn <hahn@univention.de>
(cherry picked from commit 360afebfb36cd7269b8a48db2e00e306bde0e641)

13 years agoxen_xm: Fix SIGSEGV in xenXMDomainDefineXML
Philipp Hahn [Mon, 6 Feb 2012 11:50:47 +0000 (12:50 +0100)] 
xen_xm: Fix SIGSEGV in xenXMDomainDefineXML

On CentOS5 with xen-3.0.3:

 Program received signal SIGSEGV, Segmentation fault.
 virFree (ptrptr=0x8) at util/memory.c:310
 310         free(*(void**)ptrptr);
 (gdb) bt
 #0  virFree (ptrptr=0x8) at util/memory.c:310
 #1  0x00002aaaaae167c8 in xenXMDomainDefineXML (conn=0x694e80, xml=0x6b2ce0 "P\fk") at xen/xm_internal.c:1199
 #2  0x00002aaaaae070d7 in xenUnifiedDomainDefineXML (conn=0x8,
     xml=0x6ac040 "<domain type='xen'>\n  <name>pv</name>\n  <uuid>20291bc0-453a-4d6c-c6ac-4e5af63b932c</uuid>\n  <memory>1048576</memory>\n  <currentMemory>1048576</currentMemory>\n  <vcpu>1</vcpu>\n  <os>\n    <type arch='x8"...) at xen/xen_driver.c:1524
 #3  0x00002aaaaada7803 in virDomainDefineXML (conn=0x694e80,
     xml=0x6ac040 "<domain type='xen'>\n  <name>pv</name>\n  <uuid>20291bc0-453a-4d6c-c6ac-4e5af63b932c</uuid>\n  <memory>1048576</memory>\n  <currentMemory>1048576</currentMemory>\n  <vcpu>1</vcpu>\n  <os>\n    <type arch='x8"...) at libvirt.c:7823
 #4  0x0000000000426173 in cmdEdit (ctl=0x7fffffffb8e0, cmd=<value optimized out>) at virsh.c:14882
 #5  0x000000000041c9ce in vshCommandRun (ctl=0x7fffffffb8e0, cmd=0x658c50) at virsh.c:17712
 #6  0x000000000042c3b9 in main (argc=1, argv=<value optimized out>) at virsh.c:19317

Signed-off-by: Philipp Hahn <hahn@univention.de>
(cherry picked from commit 046b0a6972a9adaeb7227c75fbbdfe5cf0dad62f)

13 years agoxen: Don't add <console> to xml for dom0
Cole Robinson [Sun, 29 Jan 2012 19:10:00 +0000 (14:10 -0500)] 
xen: Don't add <console> to xml for dom0

It just doesn't really make sense and confuses virt-manager
(cherry picked from commit efb0839c1d5471ab70ad81a36372c5cb6e5ed9a6)

Conflicts:

src/xenxs/xen_sxpr.c

13 years agoxen_xs: Guard against set but empty kernel argument
Guido Günther [Mon, 10 Oct 2011 16:22:44 +0000 (18:22 +0200)] 
xen_xs: Guard against set but empty kernel argument

On xen 4.1 I observed configurations that look like:

(image
    (hvm
        (kernel '')
        (loader '/foo/bar')
))

The kernel element is there but unset. This leads to an empty <kernel/>
element in the XML and even worse makes us skip the boot order parsing
and therefore not emit a <boot device='$dev>'/> element which breaks CD
booting.
(cherry picked from commit dca1a6b46fecca57eac8914f30ad5a41a9f038fe)

13 years agoxen: add error handling to UUID parsing
Guido Günther [Thu, 6 Oct 2011 10:42:39 +0000 (12:42 +0200)] 
xen: add error handling to UUID parsing

otherwise a missing UUID in a domain config just shows:

error: An error occurred, but the cause is unknown

Now we have:

error: configuration file syntax error: config value uuid was missing
(cherry picked from commit c5d2984c4270d257a5c01c236ca086162fd2849d)

13 years agoxenParseXM: don't dereference NULL pointer when script is empty
Guido Günther [Thu, 6 Oct 2011 10:56:52 +0000 (12:56 +0200)] 
xenParseXM: don't dereference NULL pointer when script is empty
(cherry picked from commit 6dd8532d96b0512ddb3b10cae8f51e16389d9cc7)

13 years agoFix sync issue in virNetClientStreamEventRemoveCallback
Radu Caragea [Mon, 4 Jun 2012 07:32:37 +0000 (09:32 +0200)] 
Fix sync issue in virNetClientStreamEventRemoveCallback

The stream lock is unlocked twice instead of being locked and then
unlocked. Probably a typo.
(cherry picked from commit 107f51b69c44b9902ed76ab0e33e89dde5d21cb1)

Conflicts:

AUTHORS

13 years agofdstream: Add internal callback on stream close
Peter Krempa [Thu, 23 Feb 2012 12:45:25 +0000 (13:45 +0100)] 
fdstream: Add internal callback on stream close

This patch adds another callback to a FDstream object. The original
callback is used by the daemon stream driver to handle events.

This callback is called if and only if the stream is about to be closed.
This might be used to handle cleanup steps after a fdstream exits. This
will be used later on in ensuring mutually exclusive access to consoles.

* src/fdstream.c:
        - emit the callback, when stream is being closed
        - add data structures needed to handle the callback
        - add function to register callback
* src/fdstream.h:
        - define function prototypes for the callback
(cherry picked from commit 0c4bfdda42f176633a9db7c52703802e3f0123fe)

13 years agofdstream: Emit stream abort callback even if poll() doesnt.
Peter Krempa [Thu, 23 Feb 2012 11:54:18 +0000 (12:54 +0100)] 
fdstream: Emit stream abort callback even if poll() doesnt.

This patch causes the fdstream driver to call the stream event callback
if virStreamAbort() is called on a stream using this driver.

A remote handler for a stream can only detect changes via stream events,
so this event callback is necessary in order to enable a daemon to abort
a stream in such a way that the client will see the change.

* src/fdstream.c:
        - modify close function to call stream event callback
(cherry picked from commit 95fdc1bc2b397909b9cefacf9ff91924897f5af4)

13 years agoDon't return a fatal error if receiving unexpected stream data
Daniel P. Berrange [Wed, 9 Nov 2011 13:54:01 +0000 (13:54 +0000)] 
Don't return a fatal error if receiving unexpected stream data

Due to the asynchronous nature of streams, we might continue to
receive some stream packets from the server even after we have
shutdown the stream on the client side. These should be discarded
silently, rather than raising an error in the RPC layer.

* src/rpc/virnetclient.c: Discard stream data silently
(cherry picked from commit a38710bd652c1a4a79df7d4ef171d20ff322e566)

13 years agoFix handling of stream EOF
Daniel P. Berrange [Fri, 7 Oct 2011 16:38:59 +0000 (17:38 +0100)] 
Fix handling of stream EOF

Very occasionally the sequence of events from poll would result
in getting a HANGUP on its own, instead of a HANGUP+READABLE
at the same time. In the former case we would send back an error
event to the client, but never send the empty packet to indicate
EOF.
(cherry picked from commit 1d46b2e900498a3f389fcbb89fc7b27d22f36d4a)

13 years agoIf receiving a stream error, mark EOF on the stream
Daniel P. Berrange [Fri, 7 Oct 2011 10:35:31 +0000 (11:35 +0100)] 
If receiving a stream error, mark EOF on the stream

If we receive an error on the stream, set the EOF marker so
that any further (bogus) incoming data is dropped.

* src/rpc/virnetclientstream.c: Set EOF on stream
(cherry picked from commit bc61aa1211666d5b0c2930a69b6b9db17288f003)

13 years agoSet to NULL members that have been freed to prevent crashes
Marc-André Lureau [Sat, 1 Oct 2011 01:39:14 +0000 (03:39 +0200)] 
Set to NULL members that have been freed to prevent crashes

Do not crash if virStreamFinish is called after error.

==11000== Invalid read of size 4
==11000==    at 0x373A8099A0: pthread_mutex_lock (pthread_mutex_lock.c:51)
==11000==    by 0x4C7CADE: virMutexLock (threads-pthread.c:85)
==11000==    by 0x4D57C31: virNetClientStreamRaiseError (virnetclientstream.c:203)
==11000==    by 0x4D385E4: remoteStreamFinish (remote_driver.c:3541)
==11000==    by 0x4D182F9: virStreamFinish (libvirt.c:14157)
==11000==    by 0x40FDC4: cmdScreenshot (virsh.c:3075)
==11000==    by 0x42BA40: vshCommandRun (virsh.c:14922)
==11000==    by 0x42ECCA: main (virsh.c:16381)
==11000==  Address 0x59b86c0 is 16 bytes inside a block of size 216 free'd
==11000==    at 0x4A06928: free (vg_replace_malloc.c:427)
==11000==    by 0x4C69E2B: virFree (memory.c:310)
==11000==    by 0x4D57B56: virNetClientStreamFree (virnetclientstream.c:184)
==11000==    by 0x4D3DB7A: remoteDomainScreenshot (remote_client_bodies.h:1812)
==11000==    by 0x4CFD245: virDomainScreenshot (libvirt.c:2903)
==11000==    by 0x40FB73: cmdScreenshot (virsh.c:3029)
==11000==    by 0x42BA40: vshCommandRun (virsh.c:14922)
==11000==    by 0x42ECCA: main (virsh.c:16381)
(cherry picked from commit be5ec76630c4af83404e8fbf2b5a6b7cb46656e7)

13 years agoFix synchronous reading of stream data
Daniel P. Berrange [Wed, 21 Sep 2011 13:51:33 +0000 (14:51 +0100)] 
Fix synchronous reading of stream data

commit 984840a2c292402926ad100aeea33f8859ff31a9 removed the
notification of waiting calls when VIR_NET_CONTINUE messages
arrive. This was to fix the case of a virStreamAbort() call
being prematurely notified of completion.

The problem is that sometimes there are dummy calls from a
virStreamRecv() call waiting that *do* need to be notified.

These dummy calls should have a status VIR_NET_CONTINUE. So
re-add the notification upon VIR_NET_CONTINUE, but only if
the waiter also has a status of VIR_NET_CONTINUE.

* src/rpc/virnetclient.c: Notify waiting call if stream data
  arrives
* src/rpc/virnetclientstream.c:  Mark dummy stream read packet
  with status VIR_NET_CONTINUE
(cherry picked from commit cb61009236a96f16fa7eabc92f5d6ed5f6313163)

13 years agobuild: fix stamp file name
Eric Blake [Fri, 11 May 2012 14:20:34 +0000 (08:20 -0600)] 
build: fix stamp file name

Ever since commit c964b6a, make was trying to find the timestamp
of '""./apibuild.py".stamp"', but only touching 'apibuild.py.stamp',
and thus always rebuilding.  Reported by Daniel P. Berrange.

* docs/Makefile.am (APIBUILD, APIBUILD_STAMP): Omit bogus quotes.
(cherry picked from commit c0057d9a49f6aead9a893c33069d2a11c03bc1e8)

13 years agoInstall API XML desc to a standard location
Daniel P. Berrange [Mon, 13 Feb 2012 16:46:29 +0000 (16:46 +0000)] 
Install API XML desc to a standard location

Language bindings may well want to use the libvirt-api.xml and
libvirt-qemu-api.xml files to either auto-generate themselves,
or sanity check the manually written bindings for completeness.
Currently these XML files are not installed as standard, merely
ending up as a %doc file in the RPM.

This changes them to be installed into $prefix/share/libvirt/apis/
The *-refs.xml files are not installed, since those are only
useful during generation of the online API doc files.

The pkg-config file is enhanced so that you can query the install
location of the API files. eg

  # pkg-config --variable=libvirt_qemu_api libvirt
  /home/berrange/builder/i686-pc-mingw32/sys-root/mingw/share/libvirt/libvirt-qemu-api.xml

* docs/Makefile.am: Install libvirt-api.xml & libvirt-qemu-api.xml
* libvirt.pc.in: Add vars for querying API install location
* libvirt.spec.in, mingw32-libvirt.spec.in: Include API XML files
(cherry picked from commit c95c90ee4a2e6e3e62b32909e2bd57972a73b4ab)

13 years agotests: work around pdwtags 1.9 failure
Eric Blake [Fri, 6 Jan 2012 23:07:34 +0000 (16:07 -0700)] 
tests: work around pdwtags 1.9 failure

On rawhide, gcc is new enough to output new DWARF information that
pdwtags has not yet learned, but the resulting 'make check' output
was rather confusing:

$ make -C src check
...
  GEN    virkeepaliveprotocol-structs
die__process_function: DW_TAG_INVALID (0x4109) @ <0x58c> not handled!
WARNING: your pdwtags program is too old
WARNING: skipping the virkeepaliveprotocol-structs test
WARNING: install dwarves-1.3 or newer
...
$ pdwtags --version
v1.9

I've filed the pdwtags deficiency as
https://bugzilla.redhat.com/show_bug.cgi?id=772358

* src/Makefile.am (PDWTAGS): Don't leave -t file behind on version
mismatch.  Soften warning message, since 1.9 is newer than 1.3.
Don't leak stderr from broken version.
(cherry picked from commit cf6d36257b9164ec7a4bcd31a3c56b6163169e02)

13 years agoxenapi: remove unused variable
Eric Blake [Fri, 11 Nov 2011 18:10:18 +0000 (11:10 -0700)] 
xenapi: remove unused variable

  CC     libvirt_driver_xenapi_la-xenapi_driver.lo
xenapi/xenapi_driver.c: In function 'xenapiDomainGetVcpus':
xenapi/xenapi_driver.c:1209:21: error: variable 'cpus' set but not used [-Werror=unused-but-set-variable]

* src/xenapi/xenapi_driver.c (xenapiDomainGetVcpus): Silence
compiler warning.
(cherry picked from commit 787b0a22389815190dd0a437c0ab6f3f995227b1)

13 years agobuild: fix 'make distcheck'
Eric Blake [Tue, 11 Oct 2011 21:10:17 +0000 (15:10 -0600)] 
build: fix 'make distcheck'

I got these distcheck failures with sanlock enabled:

ERROR: files left in build directory after distclean:
./tools/virt-sanlock-cleanup
./src/locking/qemu-sanlock.conf

* src/Makefile.am (DISTCLEANFILES) [HAVE_SANLOCK]: Clean built
file.
* tools/Makefile.am (DISTCLEANFILES): Likewise.
(cherry picked from commit c654ba889314c5ab50840584e55e3dfc3eac5860)
plus tweak to DISTCLEANFILES from commit ddf3bd32ce12, although that
full commit is too invasive to backport

13 years agobuild: fix 'make distcheck' with pdwtags installed
Eric Blake [Tue, 4 Oct 2011 16:24:40 +0000 (10:24 -0600)] 
build: fix 'make distcheck' with pdwtags installed

I am getting this failure with 'make distcheck':

  GEN    ../../src/remote_protocol-structs
/bin/sh: ../../src/remote_protocol-structs-t: Permission denied
make[4]: *** [../../src/remote_protocol-structs] Error 1

since it attempts a sub-run of a VPATH 'make check' where $(srcdir)
is intentionally read-only.  I'm not sure which commit introduced
the problem, although I suspect it was around 62dee6f when I
refactored protocol struct checking to be more powerful.

$(@F) is required by POSIX, and although it is not yet portable
to all make implementations, we already require GNU make.

* src/Makefile.am (PDWTAGS): Generate temp file into current
directory, since $(srcdir) is read-only during distcheck.
(cherry picked from commit 2d45ae5a013a0353688d92c3e93b7e53a2939a96)

13 years agopython: Fix doc directory name for stable releases
Cole Robinson [Fri, 27 Apr 2012 16:06:34 +0000 (12:06 -0400)] 
python: Fix doc directory name for stable releases

We were using the libvirt release version (like 0.9.11) and not
the configure version (which for stable releases is 0.9.11.X)

Most other places got this right so hopefully that's all the fallout
from the version format change :)

Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit 002b18b3fb8dc3c088d389344992959dfedeac9e)

13 years agodocs: Serialize running apibuild.py
Cole Robinson [Fri, 27 Apr 2012 16:05:12 +0000 (12:05 -0400)] 
docs: Serialize running apibuild.py

Use a witness file approach like we do for python/generator.py,
as suggested by Eric. Fixes the build issue reported here:

https://www.redhat.com/archives/libvir-list/2012-April/msg01435.html

Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit c964b6aac1c9d2fe02a814cbb1fddb8899656f50)

Conflicts:

.gitignore - context with other commits not backported

13 years agoconfigure: Use ustar format for dist tarball
Cole Robinson [Fri, 27 Apr 2012 16:03:44 +0000 (12:03 -0400)] 
configure: Use ustar format for dist tarball

Since for stable releases, some test files were over the 99 char
limit for traditional tar filenames.

Suggested by Osier here:
https://www.redhat.com/archives/libvir-list/2012-April/msg01435.html

Signed-off-by: Cole Robinson <crobinso@redhat.com>
(cherry picked from commit ddd6bef4dce89aa1ca52b208ba9c5cc4c22a551c)

13 years agoFix parallel build in docs/ directory
Daniel P. Berrange [Wed, 4 Apr 2012 11:26:04 +0000 (12:26 +0100)] 
Fix parallel build in docs/ directory

Every now & then, with parallel builds, we get a failure to
validate hvsupport.html.in.  I eventually noticed that this
is because we get 2 instances of the generator running at
once.

We already list hvsupport.html.in in BUILT_SOURCES but this
was not working. It turns out the flaw is that we were
adding deps to the 'all:' target instead of the 'all-am:'
target. BUILT_SOURCES is a dep of 'all', so any custom
targets written in Makefile.am must use 'all-am:' so that
they don't get run until BUILT_SOURCES are completely
generated

* docs/Makefile.am: s/all/all-am/
(cherry picked from commit 4f4b496e782dd20d105b89f89e07288772555346)
(cherry picked from commit 26fdec39b43d886948796b88fabc11beb967ef66)

13 years agotests: avoid test failure on rawhide gnutls
Eric Blake [Fri, 6 Jan 2012 21:07:23 +0000 (14:07 -0700)] 
tests: avoid test failure on rawhide gnutls

I hit a VERY weird testsuite failure on rawhide, which included
_binary_ output to stderr, followed by a hang waiting for me
to type something! (Here, using ^@ for NUL):

$ ./commandtest
TEST: commandtest
      WARNING: gnome-keyring:: couldn't send data: Bad file descriptor
.WARNING: gnome-keyring:: couldn't send data: Bad file descriptor
.WARNING: gnome-keyring:: couldn't send data: Bad file descriptor
WARNING: gnome-keyring:: couldn't send data: Bad file descriptor
.8^@^@^@8^@^@^@^A^@^@^@^Bay^A^@^@^@)PRIVATE-GNOME-KEYRING-PKCS11-PROTOCOL-V-1

I finally traced it to the fact that gnome-keyring, called via
gnutls_global_init which is turn called by virNetTLSInit, opens
an internal fd that it expects to communicate to via a
pthread_atfork handler (never mind that it violates POSIX by
using non-async-signal-safe functions in that handler:
https://bugzilla.redhat.com/show_bug.cgi?id=772320).

Our problem stems from the fact that we pulled the rug out from
under the library's expectations by closing an fd that it had
just opened.  While we aren't responsible for fixing the bugs
in that pthread_atfork handler, we can at least avoid the bugs
by not closing the fd in the first place.

* tests/commandtest.c (mymain): Avoid closing fds that were opened
by virInitialize.
(cherry picked from commit 74ff57506c762f7c1f2bdbcce55f6d620687caab)

13 years agostorage: Fix any VolLookupByPath if we have an empty logical pool
Cole Robinson [Wed, 25 Jan 2012 17:07:14 +0000 (12:07 -0500)] 
storage: Fix any VolLookupByPath if we have an empty logical pool

On F16 at least, empty volume groups don't have a directory under /dev.
The directory only appears once a logical volume is created.

This tickles some behavior in BackendStablePath which ends with
libvirt sleeping for 5 seconds while waiting for the directory to appear.
This causes all sorts of problems for the virStorageVolLookupByPath API
which virtinst uses, even if trying to resolve a path that is independent
of the logical pool.

In reality we don't even need to do that checking since logical pools
always have a stable target path. Short circuit the polling in that
case.

Fixes bug 782261
(cherry picked from commit 275155f664614fd32bcf5e963488e6f97b66dae4)

13 years agodaemon: Remove deprecated HAL from init script dependencies
Peter Krempa [Fri, 2 Mar 2012 14:12:32 +0000 (15:12 +0100)] 
daemon: Remove deprecated HAL from init script dependencies

The init script for the daemon requests to start HAL although it has
been deprecated long time ago. This patch removes the dependency.
(cherry picked from commit 2dcca3ec0a28c6562ebfbe7a5eae4729fb5de904)

13 years agovirCommand: Properly handle POLLHUP
Michal Privoznik [Tue, 3 Jan 2012 17:40:55 +0000 (18:40 +0100)] 
virCommand: Properly handle POLLHUP

It is a good practise to set revents to zero before doing any poll().
Moreover, we should check if event we waited for really occurred or
if any of fds we were polling on didn't encountered hangup.
(cherry picked from commit 06b9c5b9231ef4dbd4b5ff69564305cd4f814879)

13 years agoqemu: Check for domain being active on successful job acquire
Michal Privoznik [Tue, 11 Oct 2011 08:40:36 +0000 (10:40 +0200)] 
qemu: Check for domain being active on successful job acquire

As this is needed. Although some functions check for domain
being active before obtaining job, we need to check it after,
because obtaining job unlocks domain object, during which
a state of domain can be changed.
(cherry picked from commit 9bc9999b6eb815268798120d7fe8834d822f098d)

13 years agoAvoid crash in shunloadtest
Daniel P. Berrange [Thu, 1 Dec 2011 16:33:50 +0000 (11:33 -0500)] 
Avoid crash in shunloadtest

For unknown reasons, the shunloadtest will crash on Fedora 16
inside dlopen()

 (gdb) bt
 #0  0x00000000000050e6 in ?? ()
 #1  0x00007ff61a77b9d5 in floor () from /lib64/libm.so.6
 #2  0x00007ff61e522963 in _dl_relocate_object () from /lib64/ld-linux-x86-64.so.2
 #3  0x00007ff61e5297e6 in dl_open_worker () from /lib64/ld-linux-x86-64.so.2
 #4  0x00007ff61e525006 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
 #5  0x00007ff61e52917a in _dl_open () from /lib64/ld-linux-x86-64.so.2
 #6  0x00007ff61e0f6f26 in dlopen_doit () from /lib64/libdl.so.2
 #7  0x00007ff61e525006 in _dl_catch_error () from /lib64/ld-linux-x86-64.so.2
 #8  0x00007ff61e0f752f in _dlerror_run () from /lib64/libdl.so.2
 #9  0x00007ff61e0f6fc1 in dlopen@@GLIBC_2.2.5 () from /lib64/libdl.so.2
 #10 0x0000000000400a15 in main (argc=<optimized out>, argv=<optimized out>) at shunloadtest.c:105

Changing from RTLD_NOW to RTLD_LAZY avoids this problem,
but quite possibly does not fix the root cause.

* shunloadtest.c: s/NOW/LAZY/
(cherry picked from commit 24d9792821af4c6b304e5b0ee83f7b233cfa314e)

13 years agospec: make it easier to autoreconf when building rpm
Eric Blake [Mon, 5 Dec 2011 17:22:10 +0000 (10:22 -0700)] 
spec: make it easier to autoreconf when building rpm

Over time, Fedora and RHEL RPMs have often backported upstream
patches that touched configure.ac and/or Makefile.am; this
necessitates rerunning the autotools for the patch to be effective.
Making this a one-liner spec tweak will make it easier for future
backports to pull patches without having to find all the places
to touch to properly use the autotools.  Meanwhile, there have been
historical instances where an update in the autotools caused FTBFS
situations, so this is not on by default.

* libvirt.spec.in (enable_autotools): New variable, default off.
(BuildRequires): Conditionally add autotools.
(%build): Conditionally use them before configure.
* mingw32-libvirt.spec.in: Likewise.
(cherry picked from commit 9c417636c4045735712c066595ff31539ac88bff)

Conflicts:

mingw32-libvirt.spec.in - caused by change in context

13 years agotest: replace deprecated "fedora-13" machine with "pc-0.13"
Laine Stump [Fri, 9 Dec 2011 20:55:14 +0000 (15:55 -0500)] 
test: replace deprecated "fedora-13" machine with "pc-0.13"

One of the xml tests in the test suite was created using a
now-deprecated qemu machine type ("fedora-13", which was only ever
valid for Fedora builds of qemu). Although strictly speaking it's not
necessary to replace it with an actual supported qemu machine type
(since the xml in question is never actually sent to qemu), this patch
changes it to the actually-supported "pc-0.13" just for general
tidiness. (Also, on some Fedora builds which contain a special patch
to rid the world of "fedora-13", having it mentioned in the test suite
will cause make check to fail.)
(cherry picked from commit 7204a9fd31b06a6ce8fe5b08483c39a75faa0392)

13 years agonetwork: don't add iptables rules for externally managed networks
Laine Stump [Tue, 6 Dec 2011 20:13:50 +0000 (15:13 -0500)] 
network: don't add iptables rules for externally managed networks

This patch addresses https://bugzilla.redhat.com/show_bug.cgi?id=760442

When a network has any forward type other than route, nat or none, the
network configuration should be done completely external to libvirt -
libvirt only uses these types to allow configuring guests in a manner
that isn't tied to a specific host (all the host-specific information,
in particular interface names, port profile data, and bandwidth
configuration is in the network definition, and the guest
configuration only references it).

Due to a bug in the bridge network driver, libvirt was adding iptables
rules for networks with forward type='bridge' etc. any time libvirtd
was restarted while one of these networks was active.

This patch eliminates that error by only "reloading" iptables rules if
forward type is route, nat, or none.
(cherry picked from commit ae1232b298323dd7bef909426e2ebafa6bca9157)

13 years agospec: fix logic bug in deciding to turn on cgconfig
Eric Blake [Thu, 8 Dec 2011 20:32:37 +0000 (13:32 -0700)] 
spec: fix logic bug in deciding to turn on cgconfig

https://bugzilla.redhat.com/show_bug.cgi?id=738725

Commit ecd8725 tried to silence a spurious warning on the initial
libvirt install, and commit ba6cbb1 tried to fix up the logic to the
correct Fedora version, but the warning was still present due to a
logic bug: since %{fedora} and %{rhel} are never simulatanously
set, then 0%{rhel} <= 6 made the %if always true.  Checking for
minimum versions (via >=) is okay, but checking for maximum versions
(via <=) requires a prerequisite test that the platform being tested
is non-zero.

Also fix a bogus setting of with_libxl (although we previously
hard-code with_libxl to 0 for rhel earlier in the file, so this
was not as severe a bug).

* libvirt.spec.in (with_cgconfig): Don't enable cgconfig on F16.
(cherry picked from commit 3b95f284f19d2e43daa32a87cd10eaf42ea8bb4e)

13 years agospec: don't use chkconfig --list
Eric Blake [Tue, 6 Dec 2011 23:16:34 +0000 (16:16 -0700)] 
spec: don't use chkconfig --list

https://bugzilla.redhat.com/show_bug.cgi?id=694403 reports that
the specfile is incorrectly checking for a running libvirt-guests
service.  For example,

$ LC_ALL=es_ES chkconfig --list libvirt-guests
libvirt-guests    0:desactivado  1:desactivado    2:desactivado     3:activo  4:activo  5:activo     6:desactivado

will fail to find 5:on, even though it is active.  But chkconfig
already has a mode where you can silently use the exit status to
check for an active service.

* libvirt.spec.in (%post): Use simpler chkconfig options, to avoid
issues with localization.
(cherry picked from commit fea83dde7b7e0725e4353a2cc5b6e5c7c61cb294)

13 years agospec: add dmidecode as prereq
Eric Blake [Mon, 5 Dec 2011 17:32:41 +0000 (10:32 -0700)] 
spec: add dmidecode as prereq

https://bugzilla.redhat.com/show_bug.cgi?id=754909 complains that
because libvirt didn't require dmidecode, that the logs are noisy
and virConnectGetSysinfo needlessly fails.  Even 'virt-what' requires
dmidecode, so it's not that onerous of a dependency.  We may be
able to drop this in the future when we move to parsing sysfs data,
but for now, listing the dependency will help matters.

* libvirt.spec.in (Requires): Sort Requires before BuildRequires.
Add dmidecode.
(cherry picked from commit e7dfa468f9de796430a4cc9594eb256109a517bf)
extra requires for with_systemd removed, since the patch that adds
that hasn't been backported

13 years agoFix incorrect symbols for virtime.h module breaking Mingw32
Daniel P. Berrange [Mon, 5 Dec 2011 14:04:25 +0000 (14:04 +0000)] 
Fix incorrect symbols for virtime.h module breaking Mingw32

The Mingw32 linker highlighted that the symbols for virtime.h
declared in libvirt_private.syms were incorrect

* src/libvirt_private.syms: Fix virtime.h symbols
(cherry picked from commit b265beda55dd13c6e1a578285ae64191caed2694)

13 years agospec: mark directories in /var/run as ghosts
Eric Blake [Wed, 30 Nov 2011 22:34:42 +0000 (15:34 -0700)] 
spec: mark directories in /var/run as ghosts

We have several directories that are created on the fly, and which
only contain state relevant to a running libvirtd process (all
located in /var/run).  Since the directories are created as needed,
and make no sense without a running libvirtd, we want them deleted
if libvirt is uninstalled.  And in F15 and newer, /var/run is on
tmpfs (forcing us to recreate on the fly); which means that someone
trying to verify a complete rpm will fail if the directory does not
currently exist because libvirtd has not been started since boot.
The solution, then, is to mark the directories as %ghost, so that
rpm knows that we own them and will clean it up if libvirt is
uninstalled, but will no longer create the directory for us at
install, nor complain at verify time if the directory does not exist.

See https://bugzilla.redhat.com/show_bug.cgi?id=656611.

* libvirt.spec.in (%files): Add %ghost to temporary directories
that we don't install, but want cleaned up on libvirt removal.
(cherry picked from commit 764574f7c73d72e42f69f225b6bbe61fae5ab28b)

13 years agoRemove time APIs from src/util/util.h
Daniel P. Berrange [Tue, 29 Nov 2011 12:33:23 +0000 (12:33 +0000)] 
Remove time APIs from src/util/util.h

The virTimestamp and virTimeMs functions in src/util/util.h
duplicate functionality from virtime.h, in a non-async signal
safe manner. Remove them, and convert all code over to the new
APIs.

* src/util/util.c, src/util/util.h: Delete virTimeMs and virTimestamp
* src/lxc/lxc_driver.c, src/qemu/qemu_domain.c,
  src/qemu/qemu_driver.c, src/qemu/qemu_migration.c,
  src/qemu/qemu_process.c, src/util/event_poll.c: Convert to use
  virtime APIs
(cherry picked from commit a8bb75a3e65f0ae866f3b3fd60c57b2aa2050017)

Conflicts:

src/lxc/lxc_driver.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
 * the patches contained context with extra include files not
   yet introduced on the branch.
src/util/event_poll.c
 * the branch had context with a call to EVENT_DEBUG that
   was no longer existing in the original patch.

13 years agoMake logging async signal safe wrt time stamp generation
Daniel P. Berrange [Tue, 29 Nov 2011 12:32:31 +0000 (12:32 +0000)] 
Make logging async signal safe wrt time stamp generation

Use the new virTimeStringNowRaw() API for generating log timestamps
in an async signal safe manner

* src/util/logging.c: Use virTimeStringNowRaw
(cherry picked from commit 32d3ec7466a554f7a4a3e9d4017a24aa540ecf18)

Conflicts:

src/util/logging.c

13 years agoAdd internal APIs for dealing with time
Daniel P. Berrange [Tue, 29 Nov 2011 12:11:01 +0000 (12:11 +0000)] 
Add internal APIs for dealing with time

The logging APIs need to be able to generate formatted timestamps
using only async signal safe functions. This rules out using
gmtime/localtime/malloc/gettimeday(!) and much more.

Introduce a new internal API which is async signal safe.

  virTimeMillisNowRaw replacement for gettimeofday. Uses clock_gettime
                      where available, otherwise falls back to the unsafe
                      gettimeofday

  virTimeFieldsNowRaw  replacements for gmtime(), convert a timestamp
  virTimeFieldsThenRaw into a broken out set of fields. No localtime()
                       replacement is provided, because converting to
                       local time is not practical with only async signal
                       safe APIs.

  virTimeStringNowRaw  replacements for strftime() which print a timestamp
  virTimeStringThenRaw into a string, using a pre-determined format, with
                       a fixed size buffer (VIR_TIME_STRING_BUFLEN)

For each of these there is also a version without the Raw postfix
which raises a full libvirt error. These versions are not async
signal safe

* src/Makefile.am, src/util/virtime.c, src/util/virtime.h: New files
* src/libvirt_private.syms: New APis
* configure.ac: Check for clock_gettime in -lrt
* tests/virtimetest.c, tests/Makefile.am: Test new APIs
(cherry picked from commit 3ec128989606278635a7c5dfbeee959692d12e15)

Conflicts:

src/Makefile.am

13 years agologging: Add date to log timestamp
Jiri Denemark [Wed, 28 Sep 2011 14:44:50 +0000 (16:44 +0200)] 
logging: Add date to log timestamp
(cherry picked from commit 11c6e094e4e8789174502bd52c1441caa5865276)

13 years agologging: Do not log timestamp through syslog
Jiri Denemark [Wed, 28 Sep 2011 13:20:07 +0000 (15:20 +0200)] 
logging: Do not log timestamp through syslog

Syslog puts the timestamp to every message anyway so this removes
redundant data.
(cherry picked from commit 2a449549c1db0befef8a807bfe967a04af8b529b)

13 years agoqemu: make PCI multifunction support more manual
Laine Stump [Thu, 29 Sep 2011 17:00:32 +0000 (13:00 -0400)] 
qemu: make PCI multifunction support more manual

When support for was added for PCI multifunction cards (in commit
9f8baf, first included in libvirt 0.9.3), it was done by always
turning on the multifunction bit for all PCI devices. Since that time
it has been realized that this is not an ideal solution, and that the
multifunction bit must be selectively turned on. For example, see

  https://bugzilla.redhat.com/show_bug.cgi?id=728174

and the discussion before and after

  https://www.redhat.com/archives/libvir-list/2011-September/msg01036.html

This patch modifies multifunction support so that the multifunction=on
option is only added to the qemu commandline for a device if its PCI
<address> definition has the attribute "multifunction='on'", e.g.:

  <address type='pci' domain='0x0000' bus='0x00'
           slot='0x04' function='0x0' multifunction='on'/>

In practice, the multifunction bit should only be turned on if
function='0' AND other functions will be used in the same slot - it
usually isn't needed for functions 1-7 (although there are apparently
some exceptions, e.g. the Intel X53 according to the QEMU source
code), and should never be set if only function 0 will be used in the
slot. The test cases have been changed accordingly to illustrate.

With this patch in place, if a user attempts to assign multiple
functions in a slot without setting the multifunction bit for function
0, libvirt will issue an error when the domain is defined, and the
define operation will fail. In the future, we may decide to detect
this situation and automatically add multifunction=on to avoid the
error; even then it will still be useful to have a manual method of
turning on multifunction since, as stated above, there are some
devices that excpect it to be turned on for all functions in a slot.

A side effect of this patch is that attempts to use the same PCI
address for two different devices will now log an error (previously
this would cause the domain define operation to fail, but there would
be no log message generated). Because the function doing this log was
almost completely rewritten, I didn't think it worthwhile to make a
separate patch for that fix (the entire patch would immediately be
obsoleted).
(cherry picked from commit c329db7180d77c8077b9f9cd167a71d7f347227a)

13 years agoconf: remove unused VIR_ENUM_DECL
Laine Stump [Wed, 28 Sep 2011 18:19:59 +0000 (14:19 -0400)] 
conf: remove unused VIR_ENUM_DECL

While adding a new enum, I noticed a VIR_ENUM_DECL for a type that
doesn't exist. There is also of course no matching VIR_ENUM_IMPL for
it.
(cherry picked from commit be7bc4d5ccb502c2da85d3b3db804fd53b70449e)

13 years agospec: F15 still uses cgconfig, RHEL lacks hyperv
Eric Blake [Mon, 26 Sep 2011 20:28:47 +0000 (14:28 -0600)] 
spec: F15 still uses cgconfig, RHEL lacks hyperv

Commit ecd8725c dropped attempts to probe the cgconfig service on
new enough Fedora where systemd took over that aspect of the system,
but mistakenly used F14 instead of F15 as the cutoff point.

https://bugzilla.redhat.com/show_bug.cgi?id=741358

Also, RHEL does not include HyperV support yet.

* libvirt.spec.in (with_cgconfig): Check cgconfig service in F15.
(%{?rhel}): Provide default for with_hyperv.
(cherry picked from commit ba6cbb182b49ca1f94a40285f40f342f84c0bd2a)

14 years agoRelease of libvirt-0.9.6 v0.9.6
Daniel Veillard [Thu, 22 Sep 2011 06:53:23 +0000 (14:53 +0800)] 
Release of libvirt-0.9.6

14 years agosnapshot: also delete empty directory
Eric Blake [Wed, 21 Sep 2011 22:08:42 +0000 (16:08 -0600)] 
snapshot: also delete empty directory

The previous patch removed all snapshots, but not the directory
where the snapshots lived, which is still a form of stale data.

* src/qemu/qemu_domain.c (qemuDomainRemoveInactive): Wipe any
snapshot directory.

14 years agosnapshot: remove snapshot metadata on transient exit
Eric Blake [Thu, 22 Sep 2011 06:02:03 +0000 (14:02 +0800)] 
snapshot: remove snapshot metadata on transient exit

Commit 282fe1f0 documented that transient domains will auto-delete
any snapshot metadata when the last reference to the domain is
removed, and that management apps are in charge of grabbing any
snapshot metadata prior to that point.  However, this was not
actually implemented for qemu until now.

* src/qemu/qemu_driver.c (qemudDomainCreate)
(qemuDomainDestroyFlags, qemuDomainSaveInternal)
(qemudDomainCoreDump, qemuDomainRestoreFlags, qemudDomainDefine)
(qemuDomainUndefineFlags, qemuDomainMigrateConfirm3)
(qemuDomainRevertToSnapshot): Clean up snapshot metadata.
* src/qemu/qemu_migration.c (qemuMigrationPrepareAny)
(qemuMigrationPerformJob, qemuMigrationPerformPhase)
(qemuMigrationFinish): Likewise.
* src/qemu/qemu_process.c (qemuProcessHandleMonitorEOF)
(qemuProcessReconnect, qemuProcessReconnectHelper)
(qemuProcessAutoDestroyDom): Likewise.

14 years agosnapshot: prepare to remove transient snapshot metadata
Eric Blake [Wed, 21 Sep 2011 19:08:51 +0000 (13:08 -0600)] 
snapshot: prepare to remove transient snapshot metadata

This patch is mostly code motion - moving some functions out
of qemu_driver and into qemu_domain so they can be reused by
multiple qemu_* files (since qemu_driver.h must not grow).
It also adds a new helper function, qemuDomainRemoveInactive,
which will be used in the next patch.

* src/qemu/qemu_domain.h (qemuFindQemuImgBinary)
(qemuDomainSnapshotWriteMetadata, qemuDomainSnapshotForEachQcow2)
(qemuDomainSnapshotDiscard, qemuDomainSnapshotDiscardAll)
(qemuDomainRemoveInactive): New prototypes.
(struct qemu_snap_remove): New struct.
* src/qemu/qemu_domain.c (qemuDomainRemoveInactive)
(qemuDomainSnapshotDiscardAllMetadata): New functions.
(qemuFindQemuImgBinary, qemuDomainSnapshotWriteMetadata)
(qemuDomainSnapshotForEachQcow2, qemuDomainSnapshotDiscard)
(qemuDomainSnapshotDiscardAll): Move here...
* src/qemu/qemu_driver.c (qemuFindQemuImgBinary)
(qemuDomainSnapshotWriteMetadata, qemuDomainSnapshotForEachQcow2)
(qemuDomainSnapshotDiscard, qemuDomainSnapshotDiscardAll): ...from
here.
(qemuDomainUndefineFlags): Update caller.
* src/conf/domain_conf.c (virDomainRemoveInactive): Doc fixes.

14 years agosnapshot: fix logic bug in qemu undefine
Eric Blake [Wed, 21 Sep 2011 19:08:50 +0000 (13:08 -0600)] 
snapshot: fix logic bug in qemu undefine

Commit 19f8c98 introduced VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA,
with the intent that omitting the flag makes undefine fail, and
including the flag deletes metadata.  But it used the wrong logic.
Also, hoist the transient domain sooner, so that we don't
accidentally remove metadata of a transient domain.

* src/qemu/qemu_driver.c (qemuDomainUndefineFlags): Check correct
flag value.

14 years agosanlock: fix memory leak
Eric Blake [Wed, 21 Sep 2011 20:22:57 +0000 (14:22 -0600)] 
sanlock: fix memory leak

Detected by Coverity.  The only way to get to error_unlink is if
path was successfully assigned, so the if was useless.  Meanwhile,
there was a return statement that did not free path.

* src/locking/lock_driver_sanlock.c
(virLockManagerSanlockSetupLockspace): Fix mem-leak, and drop
useless if.

14 years agovirsh: fix regression in argv parsing
Eric Blake [Wed, 21 Sep 2011 14:54:47 +0000 (08:54 -0600)] 
virsh: fix regression in argv parsing

Prior to commit 85d2810, we had an issue where:

snapshot-create-as dom name --diskspec spec --diskspec spec

failed to parse the second spec, because the first spec had marked
that option as no longer requiring an argument.

In commit 85d2810, I fixed it by making argv options no longer mark
the option as seen.  But this in turn breaks mandatory argv options,
which now complain that the argv option is missing.

This patch reverts that part of 85d2810, and instead replaces it with
fixes to no longer clear opts_need_arg of an argv argument.

* tools/virsh.c (vshCmddefGetOption, vshCmddefGetData)
(vshCommandParse): Fix option parsing for required argv option.
(vshCmddefOptParse): Check that argv option is last.
* tests/virsh-optparse: Enhance test.

14 years agovirsh: More friendly err if no pool is specified for looking up a vol
Osier Yang [Wed, 21 Sep 2011 06:29:49 +0000 (14:29 +0800)] 
virsh: More friendly err if no pool is specified for looking up a vol

There are 3 ways to lookup a volume, only virStorageVolLookupByName
needs pool object. So if no --pool is specified, it will tries to
get the volume via virStorageVolLookupByPath/virStorageVolLookupByKey.

But if all 3 ways fails, and no --pool is specified, a friendly
error might help the user get right way quickly.

14 years agostorage: Wait udev events are handled before removing lvm vol
Osier Yang [Wed, 21 Sep 2011 06:02:30 +0000 (14:02 +0800)] 
storage: Wait udev events are handled before removing lvm vol

Related #BZ: https://bugzilla.redhat.com/show_bug.cgi?id=702260.

There are two problems described in the BZ:
1) "Can't remove open logical volume".
2) "Unable to deactivate logical volume "foo""

This patch just intends to fix 2), as 1) is expected if the vol
is still used by something, and you never known if "lvchange -an"
will fail or not either (sometime, it will succeed, sometimes not).
We'd better not look for trouble, :-)

For 2), that's caused by race between lvremove and udev event handling,
the only workable way now is to wait the events handling are finished,
though it might introduce latencies, as "udevadmin settle" exits
after *all* events are handled, it's the only way we can fix
the racing in libvirt layer.

See https://bugzilla.redhat.com/show_bug.cgi?id=570359 for more
details.

14 years agoqemu: avoid dereferencing a NULL pointer
Alex Jia [Wed, 21 Sep 2011 19:02:44 +0000 (03:02 +0800)] 
qemu: avoid dereferencing a NULL pointer

* src/qemu/qemu_process.c: Taking if (qemuDomainObjEndJob(driver, obj) == 0)
  true branch then 'obj' is NULL, virDomainObjIsActive(obj) and
  virDomainObjUnref(obj) will dereference NULL pointer.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agotests: improve test failure diagnosis
Oskari Saarenmaa [Wed, 21 Sep 2011 16:29:31 +0000 (19:29 +0300)] 
tests: improve test failure diagnosis

  * qemuhelptest prints test case name on failure.

14 years agoqemu: Avoid loop of fake reboots
Jiri Denemark [Wed, 21 Sep 2011 14:03:22 +0000 (16:03 +0200)] 
qemu: Avoid loop of fake reboots

Once virDomainReboot is called for a domain, guest OS initiated shutdown
would always result in reboot instead of shutdown. Only
virDomainShutdown would actually shutd such domain down. That's because
we forgot to reset fakeReboot flag once we asked the domain to reboot.

14 years agoqemu: Fix shutdown regression with buggy qemu
Jiri Denemark [Wed, 21 Sep 2011 08:25:29 +0000 (10:25 +0200)] 
qemu: Fix shutdown regression with buggy qemu

The commit that prevents disk corruption on domain shutdown
(96fc4784177ecb70357518fa863442455e45ad0e) causes regression with QEMU
0.14.* and 0.15.* because of a regression bug in QEMU that was fixed
only recently in QEMU git. The affected versions of QEMU do not quit on
SIGTERM if started with -no-shutdown, which we use to implement fake
reboot. Since -no-shutdown tells QEMU not to quit automatically on guest
shutdown, domains started using the affected QEMU cannot be shutdown
properly and stay in a paused state.

This patch disables fake reboot feature on such QEMU by not using
-no-shutdown, which makes shutdown work as expected. However,
virDomainReboot will not work in this case and it will report "Requested
operation is not valid: Reboot is not supported with this QEMU binary".

14 years agoAPI: prefer to use NULLSTR macro
Osier Yang [Wed, 21 Sep 2011 09:03:43 +0000 (17:03 +0800)] 
API: prefer to use NULLSTR macro

14 years agoremote: fix crash on OOM
Eric Blake [Tue, 20 Sep 2011 18:11:32 +0000 (12:11 -0600)] 
remote: fix crash on OOM

Bug introduced in commit 675464b.  On an OOM, this would try to
dereference a char* and free the contents as a pointer, which is
doomed to failure.

Adding a syntax check will prevent mistakes like this in the future.

* cfg.mk (sc_prohibit_internal_functions): New syntax check.
(exclude_file_name_regexp--sc_prohibit_internal_functions): Add
exemptions.
* daemon/remote.c (remoteRelayDomainEventIOError)
(remoteRelayDomainEventIOErrorReason)
(remoteRelayDomainEventGraphics, remoteRelayDomainEventBlockJob):
Use correct free function.

14 years agoxen: use typical allocations
Eric Blake [Tue, 20 Sep 2011 18:11:31 +0000 (12:11 -0600)] 
xen: use typical allocations

The next patch will add a syntax check that flags this usage in xen
as awkward - while it was valid memory management, it was very hard
to maintain.  Swapping to a more traditional allocation may be a bit
slower, but easier to understand.

* src/xen/xend_internal.c (xenDaemonListDomainsOld): Use two-level
allocation, rather than abusing allocation function.
(xenDaemonLookupByUUID): Update caller.

14 years agovirsh: Remove useless codes of cmdVolPath
Osier Yang [Tue, 20 Sep 2011 08:33:30 +0000 (16:33 +0800)] 
virsh: Remove useless codes of cmdVolPath

Variable "name" is never used in the codes, it's useless.

14 years agobuild: silence warning on 32-bit build
Eric Blake [Tue, 20 Sep 2011 22:53:58 +0000 (16:53 -0600)] 
build: silence warning on 32-bit build

gcc warns when building libvirt 0.9.5 on a 32-bit machine:

qemu/qemu_migration.c: In function 'qemuMigrationToFile':
qemu/qemu_migration.c:2727:38: error: large integer implicitly truncated to unsigned type [-Woverflow]

* src/qemu/qemu_domain.h (QEMU_DOMAIN_FILE_MIG_BANDWIDTH_MAX): Cap
to long when building for 32-bit platform.

14 years agoRelease of libvirt-0.9.5 v0.9.5
Daniel Veillard [Tue, 20 Sep 2011 06:17:47 +0000 (14:17 +0800)] 
Release of libvirt-0.9.5

* configure.ac docs/news.html.in libvirt.spec.in: update for the release
* po/*.po*: fetch updated translations from transifex and rebuilt

14 years agoFix crash on events due to allocation errors
Daniel Veillard [Tue, 20 Sep 2011 03:51:50 +0000 (11:51 +0800)] 
Fix crash on events due to allocation errors

remoteRelayDomainEventBlockJob, remoteRelayDomainEventIOError,
remoteRelayDomainEventIOErrorReason and remoteRelayDomainEventGraphics
were using const string directly in rpc structure, before calling
remoteDispatchDomainEventSend(). But that routine now frees up all
the pointed allocated memory from the rpc structure and we end up
with a double free.
This now strdup() all the strings passed and provide mem_error goto
labels to be used when an allocation error occurs.
Note that the cleanup isn't completely finished because all relaying
function also call make_nonnull_domain() which also allocate a string
and never handle the error case. This patches doesn't try to address
this as this is only error correctness a priori and touches far more
functions in this module:

* daemon/remote.c: fix string allocations and memory error handling
  for remoteRelayDomainEventBlockJob, remoteRelayDomainEventIOError,
  remoteRelayDomainEventIOErrorReason and remoteRelayDomainEventGraphics

14 years agoUpdate to require sanlock 1.8 for license compliance
Daniel P. Berrange [Mon, 19 Sep 2011 10:04:59 +0000 (11:04 +0100)] 
Update to require sanlock 1.8 for license compliance

Inexplicably the sanlock code all got placed under the GPLv2-only,
so libvirt's use of sanlock introduces a license incompatibility.
The sanlock developers have now rearranged the code such that there
is a 'sanlock_client.so' which is LGPLv2+ while their daemon remains
GPLv2-only. To use the new client library we need to call the new
sanlock_init and sanlock_align APIs instead of sanlock_direct_init
and sanlock_direct_align. These APIs calls are now routed via the
sanlock daemon, instead of doing direct I/O calls to disk.

For all this we require sanlock >= 1.8

* configure.ac: Check for sanlock_client.so instead of sanlock.so
  and fix various comments
* libvirt.spec.in: Mandate sanlock >= 1.8
* src/Makefile.am: Link to -lsanlock_client
* src/locking/lock_driver_sanlock.c: Use sanlock_init and
  sanlock_align

14 years agoconf: Assign newDef of active domain as persistent conf if it is NULL
Osier Yang [Thu, 1 Sep 2011 13:33:29 +0000 (21:33 +0800)] 
conf: Assign newDef of active domain as persistent conf if it is NULL

Libvirt loads the domain conf from status XML if it's running when
starting up. The problem is there is no record of the original conf.
(dom->newDef is NULL here).

So libvirt won't be able to restore the domain conf to original one
when destroying/shutdown. E.g.

1) attach a device without "--persistent"
2) restart libvirtd
3) destroy domain
4) start domain

One will see the the disk still exists.

This patch is to fix the peoblem by assigning persistent domain conf
to dom->newDef if it's NULL and the domain is running.

14 years agostorage: Ensure the device path exists before refreshing disk pool
Osier Yang [Mon, 19 Sep 2011 07:35:15 +0000 (15:35 +0800)] 
storage: Ensure the device path exists before refreshing disk pool

Doing libvirt_parthelper on an not existed device path will get
an unfriendly error message. This patch is to prohibit it.

14 years agodaemon: Error and exit if specified value for timeout is not valid
Osier Yang [Mon, 19 Sep 2011 04:16:45 +0000 (12:16 +0800)] 
daemon: Error and exit if specified value for timeout is not valid

Silently setting "timeout" as -1 if the specified value is invalid
is a bit confused.

14 years agoRemove devname identifier from autogenerated RPC code
Peter Krempa [Mon, 19 Sep 2011 14:14:34 +0000 (16:14 +0200)] 
Remove devname identifier from autogenerated RPC code

Patch 79cf07a missed one instance of "devname" in source for RPC code
generator.

14 years agovirsh: tweak previous domblkstat patch
Eric Blake [Mon, 19 Sep 2011 20:49:08 +0000 (14:49 -0600)] 
virsh: tweak previous domblkstat patch

Translators are likely to botch trailing spacing; by doing the
formatting outside of the translation, we can generally get
better alignment.  Also, for consistency, use 'bytes read' to
match 'bytes written'.

* tools/virsh.c (domblkstat_output): Drop trailing space. Tweak
rd_bytes output.
(cmdDomblkstat, DOMBLKSTAT_LEGACY_PRINT): Update formatting.

14 years agovirsh: doc: Fix supported driver types for attach-disk command
Peter Krempa [Mon, 19 Sep 2011 12:57:07 +0000 (14:57 +0200)] 
virsh: doc: Fix supported driver types for attach-disk command

Virsh man page lists driver types to be used with attach-device
command, but does not specify that those are usable only with the XEN
Hypervisor.

This patch adds statement, that those options specified are applicable
only on the Xen hypervisor and adds option usable with qemu emulator.

This patch also changes type of error returned by QEMU driver if the
user specifies incompatible driver type from VIR_ERR_INTERNAL_ERROR to
VIR_ERR_CONFIG_UNSUPPORTED.

14 years agomaint: Prefer names over email in 'git shortlog'
Eric Blake [Mon, 19 Sep 2011 22:34:10 +0000 (16:34 -0600)] 
maint: Prefer names over email in 'git shortlog'

Alex recently committed some patches with just an email instead
of a preferred name; this fixes things so 'git shortlog' gives
nicer output.

* .mailmap: Update.

14 years agovirsh: Add more human-friendly output of domblkstat command
Peter Krempa [Mon, 19 Sep 2011 12:23:12 +0000 (14:23 +0200)] 
virsh: Add more human-friendly output of domblkstat command

Users of virsh complain that output of the domblkstat command
is not intuitive enough. This patch adds explanation of fields
returned by this command to the help section for domblkstat and
the man page of virsh. Also a switch --human is added for
domblkstat that prints the fields with more descriptive
texts.

This patch also changes sequence of the output fields and their
names back to the order and spelling established by previous
versions of virsh to maintain compatibility with scripts.

Example of ordered and "translated" output:

PRE-patch:

virsh # domblkstat 1 vda
vda wr_bytes 5170176
vda wr_operations 511
vda rd_bytes 82815488
vda rd_operations 3726

POST-patch:

virsh # domblkstat 1 vda
vda rd_req 3726
vda rd_bytes 82815488
vda wr_req 478
vda wr_bytes 4965376

Example of human readable output:

virsh # domblkstat 1 vda --human
Device: vda
 number of read operations:      3726
 number of read bytes:           82815488
 number of write operations:     478
 number of bytes written:        4965376

https://bugzilla.redhat.com/show_bug.cgi?id=731656

14 years agovmx: avoid memory leak
ajia@redhat.com [Mon, 19 Sep 2011 02:34:06 +0000 (10:34 +0800)] 
vmx: avoid memory leak

* src/vmx/vmx.c: fix memory leak, 'def' has a initial value 'NULL', so
  'goto cleanup' is perfected instead of adding a virConfFree before
  'return NULL'.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agoutil: avoid memory leak
ajia@redhat.com [Sun, 18 Sep 2011 16:36:13 +0000 (00:36 +0800)] 
util: avoid memory leak

Leak in pciGetVirtualFunctionIndex present since commit 17d64ca.

* src/util/pci.c: fix memory leak.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agoremote: avoid memory leak
ajia@redhat.com [Sun, 18 Sep 2011 16:36:12 +0000 (00:36 +0800)] 
remote: avoid memory leak

Leak present since introduction of remoteDomainBuildEventGraphics
in commit 987e31e.

* src/remote/remote_driver.c: fix memory leak.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agoqemu: avoid memory leak
ajia@redhat.com [Sun, 18 Sep 2011 16:36:11 +0000 (00:36 +0800)] 
qemu: avoid memory leak

Leak introduced in commit 036ad50, affects only error case.

* src/qemu/qemu_command.c: fix memory leak.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agodaemon: avoid memory leak
ajia@redhat.com [Sun, 18 Sep 2011 16:36:10 +0000 (00:36 +0800)] 
daemon: avoid memory leak

Introduced in commit efa7fc9f.

* daemon/remote.c: fix memory leak in remoteDispatchDomainBlockStatsFlags

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agospec: silence warnings when installing in F16 v0.9.5-rc3
Eric Blake [Fri, 16 Sep 2011 22:40:25 +0000 (16:40 -0600)] 
spec: silence warnings when installing in F16

https://bugzilla.redhat.com/show_bug.cgi?id=738725 documents that
'yum install libvirt' in Fedora 16 is rather noisy.  This fixes
the problems.

* libvirt.spec.in (%post client): Silence chkconfig warning about
SysV services.
(%post) [with_cgconfig]: Drop for Fedora 15 and newer, where
systemd does this automatically.

14 years agosnapshot: allow disk snapshots of qcow2 disks
Eric Blake [Sat, 17 Sep 2011 12:16:08 +0000 (06:16 -0600)] 
snapshot: allow disk snapshots of qcow2 disks

For all types of disks other than qcow2, we were requesting that
SELinux labeling visit the new file as if it were qcow2, which
means labeling would try to find the backing files of an empty file.
And for a pre-existing qcow2 disk, we were passing NULL, which meant
that labelling tried to probe the file type (and if probing is
disabled, per the default qemu.conf, this made snapshots fail).
What we really want is to make SELinux labeling visit the new
file as raw; it will later be converted to qcow2 if qemu successfully
made the snapshot.

* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive): Force SELinux labeling
to avoid probe of new file.

14 years agosnapshot: affect persistent xml after disk snapshot
Eric Blake [Sat, 17 Sep 2011 03:46:21 +0000 (21:46 -0600)] 
snapshot: affect persistent xml after disk snapshot

For external snapshots to be useful on persistent domains, we must
alter the persistent definition alongside the running definition.
Thanks to the possibility of disk hotplug as well as of edits that
only affect the persistent xml, we can't assume that vm->def and
vm->newDef have the same disk at the same index, so we can only
update the persistent copy if the device destination matches up.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateDiskActive)
(qemuDomainSnapshotCreateSingleDiskActive): Also affect newDef, if
present.

14 years agobuild: work around lack of MacOS fdatasync
Eric Blake [Fri, 16 Sep 2011 15:12:07 +0000 (09:12 -0600)] 
build: work around lack of MacOS fdatasync

Mingw lacks fsync, but gnulib provides that.  Meanwhile, gnulib does
not (yet) provide fdatasync, so this is a quick hack to fake that
function on MacOS X; we can revert this configure change once gnulib
gives us a real module.

We have been implicitly relying on gnulib's largefile module being
pulled in by other modules, but it's better to make that explicit.

* bootstrap.conf (gnulib_modules): Add fsync.  Make largefile use
explicit.
* configure.ac (AC_CHECK_FUNCS_ONCE): Check for fdatasync, and
fake it with fsync when not present.

14 years agoPrevent crash from dlclose() of libvirt.so
Daniel P. Berrange [Thu, 1 Sep 2011 16:57:06 +0000 (17:57 +0100)] 
Prevent crash from dlclose() of libvirt.so

When libvirt calls virInitialize it creates a thread local
for the virErrorPtr storage, and registers a callback to
cleanup memory when a thread exits. When libvirt is dlclose()d
or otherwise made non-resident, the callback function is
removed from memory, but the thread local may still exist
and if a thread later exists, it will invoke the callback
and SEGV. There may also be other thread locals with callbacks
pointing to libvirt code, so it is in general never safe to
unload libvirt.so from memory once initialized.

To allow dlclose() to succeed, but keep libvirt.so resident
in memory, link with '-z nodelete'. This issue was first
found with the libvirt CIM provider, but can potentially
hit many of the dynamic language bindings which all ultimately
involve dlopen() in some way, either on libvirt.so itself,
or on the glue code for the binding which in turns links
to libvirt

* configure.ac, src/Makefile.am: Ensure libvirt.so is linked
  with -z nodelete
* cfg.mk, .gitignore, tests/Makefile.am, tests/shunloadhelper.c,
  tests/shunloadtest.c: A test case to unload libvirt while
  a thread is still running.

14 years agoqemu: add return value check
Alex Jia [Fri, 16 Sep 2011 15:51:20 +0000 (23:51 +0800)] 
qemu: add return value check

* src/qemu/qemu_command.c: missing return value check.

Signed-off-by: Alex Jia <ajia@redhat.com>
14 years agoqemu: Introduce shutdown reason for paused state
Jiri Denemark [Thu, 15 Sep 2011 13:07:51 +0000 (15:07 +0200)] 
qemu: Introduce shutdown reason for paused state

Qemu sends STOP event as part of the shutdown process. Detect such STOP
event and consider shutdown to be reason of emitting such event. That's
the best we can do until qemu provides us the reason directly in STOP
event. This allows us to report shutdown reason for paused state so that
apps can detect domains that failed to finish the shutdown process
(e.g., because qemu is buggy and doesn't exit on SIGTERM or it is
blocked in flushing disk buffers).

14 years agoqemu: Prevent disk corruption on domain shutdown
Jiri Denemark [Tue, 13 Sep 2011 16:11:26 +0000 (18:11 +0200)] 
qemu: Prevent disk corruption on domain shutdown

Ever since we introduced fake reboot, we call qemuProcessKill as a
reaction to SHUTDOWN event. Unfortunately, qemu doesn't guarantee it
flushed all internal buffers before sending SHUTDOWN, in which case
killing the process forcibly may result in (virtual) disk corruption.

By sending just SIGTERM without SIGKILL we give qemu time to to flush
all buffers and exit. Once qemu exits, we will see an EOF on monitor
connection and tear down the domain. In case qemu ignores SIGTERM or
just hangs there, the process stays running but that's not any different
from a possible hang anytime during the shutdown process so I think it's
just fine.

Also qemu (since 0.14 until it's fixed) has a bug in SIGTERM processing
which causes it not to exit but instead send new SHUTDOWN event and keep
waiting. I think the best we can do is to ignore duplicate SHUTDOWN
events to avoid a SHUTDOWN-SIGTERM loop and leave the domain in paused
state.

14 years agoqemu: Properly detect crash of a rebooted domain
Jiri Denemark [Tue, 13 Sep 2011 16:48:13 +0000 (18:48 +0200)] 
qemu: Properly detect crash of a rebooted domain

When a domain is rebooted using libvirt API, we use fake reboot
consisting of shutting down and resetting the domain. Thus we see a
SHUTDOWN event and set gotShutdown flag. But we never reset it back and
if the domain crashes after it was rebooted this way, we consider it was
a normal shutdown and not a crash.

14 years agoqemu: Fix shutoff reason when domain crashes
Jiri Denemark [Tue, 13 Sep 2011 16:35:21 +0000 (18:35 +0200)] 
qemu: Fix shutoff reason when domain crashes

Commit 4454a9efc728b91e791b1f14c26ea23a19d57f48 changed shutoff reason
from VIR_DOMAIN_SHUTOFF_CRASHED to VIR_DOMAIN_SHUTOFF_FAILED in case we
see an unexpected EOF on monitor connection. But FAILED reason is
dedicated for domains that fail to start. CRASHED reason is the right
one to use in this situation.

14 years agopython: Fix bindings generated in VPATH build
Jiri Denemark [Fri, 16 Sep 2011 09:46:46 +0000 (11:46 +0200)] 
python: Fix bindings generated in VPATH build

14 years agoRevert "virsh: Use old API if remote libvirtd does not support new"
Eric Blake [Wed, 14 Sep 2011 18:47:07 +0000 (12:47 -0600)] 
Revert "virsh: Use old API if remote libvirtd does not support new"

This reverts commit 799912fa05b8c3aa37bd04c57b196755f3f70552; now
that the rpc regression is fixed, virsh no longer needs the special
case here.