]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
13 years agoqemu: drop driver lock while trying to terminate qemu process
Laine Stump [Tue, 7 Feb 2012 16:13:57 +0000 (11:13 -0500)]
qemu: drop driver lock while trying to terminate qemu process

This patch is based on an earlier patch by Eric Blake which was never
committed:

https://www.redhat.com/archives/libvir-list/2011-November/msg00243.html

Aside from rebasing, this patch only drops the driver lock once (prior
to the first time the function sleeps), then leaves it dropped until
it returns (Eric's patch would drop and re-acquire the lock around
each call to sleep).

At the time Eric sent his patch, the response (from Dan Berrange) was
that, while it wasn't a good thing to be holding the driver lock while
sleeping, we really need to rethink locking wrt the driver object,
switching to a finer-grained approach that locks individual items
within the driver object separately to allow for greater concurrency.

This is a good plan, and at the time it made sense to not apply the
patch because there was no known bug related to the driver lock being
held in this function.

However, we now know that the length of the wait in qemuProcessKill is
sometimes too short to allow the qemu process to fully flush its disk
cache before SIGKILL is sent, so we need to lengthen the timeout (in
order to improve the situation with management applications until they
can be updated to use the new VIR_DOMAIN_DESTROY_GRACEFUL flag added
in commit 72f8a7f19753506ed957b78ad800c0f3892c9304). But, if we
lengthen the timeout, we also lengthen the amount of time that all
other threads in libvirtd are essentially blocked from doing anything
(since just about everything needs to acquire the driver lock, if only
for long enough to get a pointer to a domain).

The solution is to modify qemuProcessKill to drop the driver lock
while sleeping, as proposed in Eric's patch. Then we can increase the
timeout with a clear conscience, and thus at least lower the chances
that someone running with existing management software will suffer the
consequence's of qemu's disk cache not being flushed.

In the meantime, we still should work on Dan's proposal to make
locking within the driver object more fine grained.

(NB: although I couldn't find any instance where qemuProcessKill() was
called with no jobs active for the domain (or some other guarantee
that the current thread had at least one refcount on the domain
object), this patch still follows Eric's method of temporarily adding
a ref prior to unlocking the domain object, because I couldn't
convince myself 100% that this was the case.)

13 years agoFix typos in API XML file paths
Daniel P. Berrange [Wed, 15 Feb 2012 11:29:38 +0000 (11:29 +0000)]
Fix typos in API XML file paths

* libvirt.pc.in: Add missing '/api/' in path
* libvirt.spec.in, mingw32-libvirt.spec.in: s/apis/api/

13 years agoqemu: Implement DomainPMSuspendForDuration
Michal Privoznik [Mon, 13 Feb 2012 11:27:25 +0000 (12:27 +0100)]
qemu: Implement DomainPMSuspendForDuration

via user agent. Allow targets mem & hybrid iff system_wakeup
monitor command is available.

13 years agoqemu: Set capabilities based on supported monitor commands
Michal Privoznik [Mon, 13 Feb 2012 11:19:24 +0000 (12:19 +0100)]
qemu: Set capabilities based on supported monitor commands

In the future (my next patch in fact) we may want to make
decisions depending on qemu having a monitor command or not.
Therefore, we want to set qemuCaps flag instead of querying
on the monitor each time we are about to make that decision.

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

13 years agoqemu: make block io tuning smarter
Eric Blake [Fri, 10 Feb 2012 21:53:49 +0000 (14:53 -0700)]
qemu: make block io tuning smarter

When blkdeviotune was first committed in 0.9.8, we had the limitation
that setting one value reset all others.  But bytes and iops should
be relatively independent.  Furthermore, setting tuning values on
a live domain followed by dumpxml did not output the new settings.

* src/qemu/qemu_driver.c (qemuDiskPathToAlias): Add parameter, and
update callers.
(qemuDomainSetBlockIoTune): Don't lose previous unrelated
settings.  Make live changes reflect to dumpxml output.
* tools/virsh.pod (blkdeviotune): Update documentation.

13 years agoRelease of libvirt-0.9.10
Daniel Veillard [Mon, 13 Feb 2012 14:31:31 +0000 (22:31 +0800)]
Release of libvirt-0.9.10

* configure.ac docs/news.html.in libvirt.spec.in: updated for the release
* po/*.po*: update ja, it and uk localization, fixed the ja one

13 years agovirsh: Fix name of domain suspend command
Michal Privoznik [Mon, 13 Feb 2012 13:37:09 +0000 (14:37 +0100)]
virsh: Fix name of domain suspend command

It's dompmsuspend, not suspend-duration.

13 years agovirpidfile: Allow whitespace character at the end of pidfile
Michal Privoznik [Mon, 13 Feb 2012 13:27:15 +0000 (14:27 +0100)]
virpidfile: Allow whitespace character at the end of pidfile

Some programs, notably dnsmasq, which are writing pidfiles on their
own do append a whitespace character after pid, e.g. '\n'.

13 years agoRevert "qemu: add ibmvscsi controller model"
Daniel Veillard [Mon, 13 Feb 2012 13:37:03 +0000 (21:37 +0800)]
Revert "qemu: add ibmvscsi controller model"

This reverts commit 7b345b69f28eb112238b941b743c5f6d57bd4a04.

Conflicts:

tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-vscsi.xml

13 years agoRevert "qemu: add virtio-scsi controller model"
Daniel Veillard [Mon, 13 Feb 2012 13:36:02 +0000 (21:36 +0800)]
Revert "qemu: add virtio-scsi controller model"

This reverts commit c9abfadf3721505e8eaffbf56ef1e53202c1db3c.

Conflicts:

tests/qemuxml2argvdata/qemuxml2argv-disk-scsi-virtio-scsi.xml

13 years agopython: make other APIs share common {get, set}PyVirTypedParameter
Guannan Ren [Fri, 10 Feb 2012 10:17:26 +0000 (18:17 +0800)]
python: make other APIs share common {get, set}PyVirTypedParameter

        *libvirt_virDomainBlockStatsFlags
        *libvirt_virDomainGetSchedulerParameters
        *libvirt_virDomainGetSchedulerParametersFlags
        *libvirt_virDomainSetSchedulerParameters
        *libvirt_virDomainSetSchedulerParametersFlags
        *libvirt_virDomainSetBlkioParameters
        *libvirt_virDomainGetBlkioParameters
        *libvirt_virDomainSetMemoryParameters
        *libvirt_virDomainGetMemoryParameters
        *libvirt_virDomainSetBlockIoTune
        *libvirt_virDomainGetBlockIoTune

13 years agovirpidfile: replace fopen/fwrite/fscanf with more portable version
Marc-André Lureau [Thu, 2 Feb 2012 00:28:30 +0000 (01:28 +0100)]
virpidfile: replace fopen/fwrite/fscanf with more portable version

Replace calls to fwrite() and fscanf() with more portable-friendly
version, such as snprintf() and virStrToLong().

13 years agoutil: Do not use PRIx64 macro
Osier Yang [Fri, 10 Feb 2012 11:21:53 +0000 (19:21 +0800)]
util: Do not use PRIx64 macro

It breaks the build on Mingw32,  because PRIx64 is coming
from the Win32 headers, but virAsprintf uses the gnulib printf.

13 years agorpc: Plug memory leaks on doRemoteOpen() failure path
Alex Jia [Fri, 10 Feb 2012 05:26:29 +0000 (13:26 +0800)]
rpc: Plug memory leaks on doRemoteOpen() failure path

Detected by valgrind. Leaks are introduced in commit c1b2264.

* src/remote/remote_driver.c (doRemoteOpen): free client program memory in failure path.

* How to reproduce?
% valgrind -v --leak-check=full virsh -c qemu:

* Actual result

==3969== 40 bytes in 1 blocks are definitely lost in loss record 8 of 28
==3969==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
    ==3969==    by 0x4C89C41: virAlloc (memory.c:101)
    ==3969==    by 0x4D5A236: virNetClientProgramNew (virnetclientprogram.c:60)
    ==3969==    by 0x4D47AB4: doRemoteOpen (remote_driver.c:658)
    ==3969==    by 0x4D49FFF: remoteOpen (remote_driver.c:871)
    ==3969==    by 0x4D13373: do_open (libvirt.c:1196)
    ==3969==    by 0x4D14535: virConnectOpenAuth (libvirt.c:1422)
    ==3969==    by 0x425627: main (virsh.c:18537)
    ==3969==
    ==3969== 40 bytes in 1 blocks are definitely lost in loss record 9 of 28
    ==3969==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
    ==3969==    by 0x4C89C41: virAlloc (memory.c:101)
    ==3969==    by 0x4D5A236: virNetClientProgramNew (virnetclientprogram.c:60)
    ==3969==    by 0x4D47AD7: doRemoteOpen (remote_driver.c:664)
    ==3969==    by 0x4D49FFF: remoteOpen (remote_driver.c:871)
    ==3969==    by 0x4D13373: do_open (libvirt.c:1196)
    ==3969==    by 0x4D14535: virConnectOpenAuth (libvirt.c:1422)
    ==3969==    by 0x425627: main (virsh.c:18537)
    ==3969==
    ==3969== LEAK SUMMARY:
    ==3969==    definitely lost: 80 bytes in 2 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agonpiv: Auto-generate WWN if it's not specified
Osier Yang [Fri, 10 Feb 2012 04:51:47 +0000 (12:51 +0800)]
npiv: Auto-generate WWN if it's not specified

The auto-generated WWN comply with the new addressing schema of WWN:

<quote>
the first nibble is either hex 5 or 6 followed by a 3-byte vendor
identifier and 36 bits for a vendor-specified serial number.
</quote>

We choose hex 5 for the first nibble. And for the 3-bytes vendor ID,
we uses the OUI according to underlying hypervisor type, (invoking
virConnectGetType to get the virt type). e.g. If virConnectGetType
returns "QEMU", we use Qumranet's OUI (00:1A:4A), if returns
ESX|VMWARE, we use VMWARE's OUI (00:05:69). Currently it only
supports qemu|xen|libxl|xenapi|hyperv|esx|vmware drivers. The last
36 bits are auto-generated.

13 years agoRemove single quotes from audit records
Marcelo Cerri [Thu, 9 Feb 2012 19:06:00 +0000 (17:06 -0200)]
Remove single quotes from audit records

Some audit records generated by libvirt contain fields enclosed by single
quotes. Since those fields are inside the msg field, which is enclosed by
single quotes, these records generated by libvirt are not correctly parsed by
libauparse.

13 years agoGetCPUStats: fix overflow test
Lai Jiangshan [Thu, 9 Feb 2012 10:43:10 +0000 (18:43 +0800)]
GetCPUStats: fix overflow test

Bug introduced in commit c6ec021b.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
13 years agodomain: add implicit USB controller
Marc-André Lureau [Wed, 8 Feb 2012 00:48:25 +0000 (01:48 +0100)]
domain: add implicit USB controller

Some tools, such as virt-manager, prefers having the default USB
controller explicit in the XML document. This patch makes sure there
is one. With this patch, it is now possible to switch from USB1 to
USB2 from the release 0.9.1 of virt-manager.

Fix tests to pass with this change.

13 years agopython: refactoring virTypedParameter conversion for NUMA tuning APIs
Guannan Ren [Wed, 8 Feb 2012 12:20:50 +0000 (20:20 +0800)]
python: refactoring virTypedParameter conversion for NUMA tuning APIs

          *getPyVirTypedParameter
          *setPyVirTypedParameter
          *virDomainSetNumaParameters
          *virDomainGetNumaParameters

Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agodocs: fix typo in python bindings
Eric Blake [Thu, 9 Feb 2012 00:19:30 +0000 (17:19 -0700)]
docs: fix typo in python bindings

* docs/python.html.in: Class is virConnect, not virConn.

13 years agoconf: small changes to comments in virDomainDeviceInfo
Laine Stump [Thu, 9 Feb 2012 07:33:29 +0000 (02:33 -0500)]
conf: small changes to comments in virDomainDeviceInfo

romfile wasn't mentioned in the comment, and the fact that rombar is
now supported for network interfaces also wasn't there.

13 years agopython: Correct arguments number for migrateSetMaxSpeed
Osier Yang [Wed, 8 Feb 2012 09:33:22 +0000 (17:33 +0800)]
python: Correct arguments number for migrateSetMaxSpeed

The API definition accepts "flags" argument, however, the
implementation ignores it, though "flags" is unused currently,
we should expose it instead of hard coding, the API
implementation inside hypervisor driver is responsible to check
if the passed "flags" is valid.

13 years agoqemu: fix persistent setting of blkiodevice weights
Eric Blake [Wed, 8 Feb 2012 00:38:41 +0000 (17:38 -0700)]
qemu: fix persistent setting of blkiodevice weights

virsh blkiotune dom --device-weights /dev/sda,400 --config

wasn't working correctly.

* src/qemu/qemu_driver.c (qemuDomainSetBlkioParameters): Use
correct definition.

13 years agoqemu: make blkiodevice weights easier to read
Eric Blake [Wed, 8 Feb 2012 00:38:01 +0000 (17:38 -0700)]
qemu: make blkiodevice weights easier to read

The merge code had too many indirections to easily analyze.

* src/qemu/qemu_driver.c (qemuDomainMergeDeviceWeights): Pick
better variable names.

13 years agosysinfo: simplify function signature
Eric Blake [Tue, 7 Feb 2012 22:35:03 +0000 (15:35 -0700)]
sysinfo: simplify function signature

Now that no one is relying on the return value being a pointer to
somewhere inside of the passed-in argument, we can simplify the
callers to simply return success or failure.  Also wrap some long
lines and add some const-correctness.

* src/util/sysinfo.c (virSysinfoParseBIOS, virSysinfoParseSystem)
(virSysinfoParseProcessor, virSysinfoParseMemory): Change return.
(virSysinfoRead): Adjust caller.

13 years agoPopulate /dev/std{in,out,err} symlinks in LXC containers
Daniel P. Berrange [Wed, 8 Feb 2012 14:21:28 +0000 (14:21 +0000)]
Populate /dev/std{in,out,err} symlinks in LXC containers

Some applications expect /dev/std{in,out,err} to exist. Populate
them during container startup as symlinks to /proc/self/fd

13 years agoReplace truncate() with ftruncate()
Daniel P. Berrange [Wed, 8 Feb 2012 14:03:29 +0000 (14:03 +0000)]
Replace truncate() with ftruncate()

Mingw32 does not have any truncate() API defined, but it does
have ftruncate(). So replace use of the former with the latter

13 years agoUpdate symbols file for virFileDirectFd/virFileWrapperFd rename
Daniel P. Berrange [Wed, 8 Feb 2012 14:03:01 +0000 (14:03 +0000)]
Update symbols file for virFileDirectFd/virFileWrapperFd rename

13 years agovirsh: Fix flag semantics and docs for "desc" command
Peter Krempa [Wed, 8 Feb 2012 10:31:10 +0000 (11:31 +0100)]
virsh: Fix flag semantics and docs for "desc" command

This patch fixes the domain modification impact flags for tie virsh
desc command to match the new semantics and fix the docs to match
actual behavior.

13 years agoqemu: Fix memory leak when building -cpu argument
Jiri Denemark [Wed, 8 Feb 2012 13:35:12 +0000 (14:35 +0100)]
qemu: Fix memory leak when building -cpu argument

Reported by Alex Jia:

==21503== 112 (32 direct, 80 indirect) bytes in 1 blocks are
definitely lost in loss record 37 of 40
==21503==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==21503==    by 0x4A8991: virAlloc (memory.c:101)
==21503==    by 0x505A6C: x86DataCopy (cpu_x86.c:247)
==21503==    by 0x507B34: x86Compute (cpu_x86.c:1225)
==21503==    by 0x43103C: qemuBuildCommandLine (qemu_command.c:3561)
==21503==    by 0x41C9F7: testCompareXMLToArgvHelper
(qemuxml2argvtest.c:183)
==21503==    by 0x41E10D: virtTestRun (testutils.c:141)
==21503==    by 0x41B942: mymain (qemuxml2argvtest.c:705)
==21503==    by 0x41D7E7: virtTestMain (testutils.c:696)

13 years agoqemu: Always use iohelper for domain save
Jiri Denemark [Wed, 8 Feb 2012 13:08:54 +0000 (14:08 +0100)]
qemu: Always use iohelper for domain save

This is probably not strictly needed as save operation is not live but
we may have other reasons to avoid blocking qemu's main loop.

13 years agosecurity: Driver 'none' cannot create confined guests
Jiri Denemark [Tue, 7 Feb 2012 18:54:59 +0000 (19:54 +0100)]
security: Driver 'none' cannot create confined guests

In case the caller specifies that confined guests are required but the
security driver turns out to be 'none', we should return an error since
this driver clearly cannot meet that requirement.  As a result of this
error, libvirtd fails to start when the host admin explicitly sets
confined guests are required but there is no security driver available.

Since security driver 'none' cannot create confined guests, we override
default confined setting so that hypervisor drivers do not thing they
should create confined guests.

13 years agoseclabel: Do not output relabel attribute for type 'none'
Jiri Denemark [Tue, 7 Feb 2012 18:19:01 +0000 (19:19 +0100)]
seclabel: Do not output relabel attribute for type 'none'

Security label type 'none' requires relabel to be set to 'no' so there's
no reason to output this extra attribute.  Moreover, since relabel is
internally stored in a negative from (norelabel), the default value for
relabel would be 'yes' in case there is no <seclabel> element in domain
configuration.  In case VIR_DOMAIN_SECLABEL_DEFAULT turns into
VIR_DOMAIN_SECLABEL_NONE, we would incorrectly output relabel='yes' for
seclabel type 'none'.

13 years agoqemu: Always use iohelper for dumping domain core
Jiri Denemark [Mon, 6 Feb 2012 13:53:24 +0000 (14:53 +0100)]
qemu: Always use iohelper for dumping domain core

Qemu uses non-blocking I/O which doesn't play nice with regular file
descriptors. We need to pass a pipe to qemu instead, which can easily be
done using iohelper.

13 years agoutil: Generalize virFileDirectFd
Jiri Denemark [Mon, 6 Feb 2012 13:40:48 +0000 (14:40 +0100)]
util: Generalize virFileDirectFd

virFileDirectFd was used for accessing files opened with O_DIRECT using
libvirt_iohelper. We will want to use the helper for accessing files
regardless on O_DIRECT and thus virFileDirectFd was generalized and
renamed to virFileWrapperFd.

13 years agovirsh: Plug memory leak on cmdDesc
Alex Jia [Wed, 8 Feb 2012 05:50:06 +0000 (13:50 +0800)]
virsh: Plug memory leak on cmdDesc

13 years agovirsh: Do not check the input XML at virsh layer for cmdDetachDevice
Osier Yang [Tue, 7 Feb 2012 15:56:08 +0000 (23:56 +0800)]
virsh: Do not check the input XML at virsh layer for cmdDetachDevice

Any device XML doesn't use the same order as libvirt generates, or
uses decimal for attributes like "slot" of "<address>" will cause
device detaching to fail, as virsh compares the XML simply earlier
in strict manner before internal parsing.

This is regression introduced by ea7182c.

13 years agopython: drop unused function
Eric Blake [Wed, 8 Feb 2012 00:14:11 +0000 (17:14 -0700)]
python: drop unused function

Gcc warned about an unused static function.

* python/libvirt-qemu-override.c (py_str): Delete.

13 years agoOn systems with dmidecode version 2.10 or older,
Prerna Saxena [Tue, 7 Feb 2012 11:35:37 +0000 (17:05 +0530)]
On systems with dmidecode version 2.10 or older,

 dmidecode displays processor information, followed by BIOS, system and
 memory-DIMM details.
 Calls to virSysinfoParseBIOS(), virSysinfoParseSystem() would update
 the buffer pointer 'base', so the processor information would be lost
 before virSysinfoParseProcessor() was called. Sysinfo would therefore
 not be able to display processor details -- It only described <bios>,
 <system> and <memory_device> details.
 This patch attempts to insulate sysinfo from ordering of dmidecode
 output.

Before the fix:
---------------
virsh # sysinfo
<sysinfo type='smbios'>
  <bios>
    ....
  </bios>
  <system>
    ....
  </system>
  <memory_device>
    ....
  </memory_device>

After the fix:
-------------
virsh # sysinfo
<sysinfo type='smbios'>
  <bios>
    ....
  </bios>
  <system>
    ....
  </system>
  <processor>
    ....
  </processor>
  <memory_device>
    ....
  </memory_device>

13 years agostorage: Don't unsparsify images when cloning
Cole Robinson [Tue, 7 Feb 2012 19:46:30 +0000 (14:46 -0500)]
storage: Don't unsparsify images when cloning

Input to the volume cloning code is a source volume and an XML
descriptor for the new volume. It is possible for the new volume
to have a greater size than source volume, at which point libvirt
will just stick 0s on the end of the new image (for raw format
anyways).

Unfortunately a logic error messed up our tracking of the of the
excess amount that needed to be written: end result is that sparse
clones were made very much non-sparse, and cloning regular disk
images could end up excessively sized (though data unaltered).

Drop the 'remain' variable entriely here since it's redundant, and
track actual allocation directly against the desired 'total'.

13 years agobuild: don't require avahi during install
Laine Stump [Tue, 7 Feb 2012 09:54:59 +0000 (04:54 -0500)]
build: don't require avahi during install

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

The specfile requires avahi during install if libvirt was built with
avahi support, but there are many situations where it is undesirable
to install avahi due to security concerns. This patch requires only
the avahi-libs package, which is needed by libvirt to call the
function that tries to attach to the avahi daemon, but will instead
silently fail because the avahi-daemon is in the main avahi package,
and that package isn't installed.

13 years agoAllow polkit auth for VNC and SSH users
Cole Robinson [Tue, 7 Feb 2012 16:50:29 +0000 (11:50 -0500)]
Allow polkit auth for VNC and SSH users

If you are sitting in front of a physical machine and logged in as
a regular user, you can connect to the system libvirtd instance
by providing a root password to policykit. This is how most
virt-manager users talk to libvirt.

However, if you are launching virt-manager over ssh -X, or over
VNC started from say /etc/sysconfig/vncservers, our policykit policy
rejects the user outright, providing no option to provide the root
password. This is confusing to users and doesn't seem to serve much
point.

Change the policy to allow inactive (VNC) and non-local (SSH, VNC)
to provide root credentials for accessing system libvirtd. We use
auth_admin rather than auth_admin_keep so that credentials aren't
cached at all, and every subsequent reconnection to libvirt requires
auth.

Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=625115
Similar change to PackageKit policy:
https://bugzilla.redhat.com/show_bug.cgi?id=528511

13 years agopyhton: Don't link against libvirt_util.la
Michal Privoznik [Tue, 7 Feb 2012 12:30:42 +0000 (13:30 +0100)]
pyhton: Don't link against libvirt_util.la

As we already link with libvirt.la which contains libvirt_utils.la.
Double linking causes global symbols to be presented twice and
thus confusion. This partially reverts c700613b8d463212d142c97108b7a2352e23e559

13 years agobuild: avoid gcc 4.7 warning about inlines
Eric Blake [Tue, 7 Feb 2012 03:06:37 +0000 (20:06 -0700)]
build: avoid gcc 4.7 warning about inlines

gcc 4.7 complains:

util/virhashcode.c:49:17: error: always_inline function might not be inlinable [-Werror=attributes]
util/virhashcode.c:35:17: error: always_inline function might not be inlinable [-Werror=attributes]

Normal 'inline' is a hint that the compiler may ignore; the fact
that the function is static is good enough.  We don't care if the
compiler decided not to inline after all.

* src/util/virhashcode.c (getblock, fmix): Relax attribute.

13 years agoClarify the purpose of domxml-from-native
Dave Allan [Mon, 6 Feb 2012 22:17:03 +0000 (17:17 -0500)]
Clarify the purpose of domxml-from-native

Someone mentioned to me that they interpreted this section of the KVM
driver page as suggesting that new guests should be created by
creating a qemu commandline and converting it to XML with
domxml-from-native.  I don't think that's the intent of
domxml-from-native, so I added that clarification.

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>
13 years agoxen-xm: fix data loss in domain edit
Philipp Hahn [Mon, 6 Feb 2012 13:09:12 +0000 (14:09 +0100)]
xen-xm: fix data loss in domain edit

On CentOS5:
If "virsh edit $DOM" is used and an error happens (for example changing
any live cycle action to a non-existing value), libvirt forgets that
$DOM exists, since it is already removed from the internal hash tables,
which are used for domain lookup.
In once case (unreproducible) even the persistent configuration
/etc/xen/$DOM was deleted.

Instead of using the compound function xenXMConfigSaveFile() explicitly
use xenFomatXM() and virConfWriteFile() to distinguish between a failure
in converting the libvirt definition to the xen-xm format and a problem
when writing the file.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoseclabel: make code and RNG match
Eric Blake [Sat, 4 Feb 2012 14:01:56 +0000 (07:01 -0700)]
seclabel: make code and RNG match

Commit b170eb99 introduced a bug: domains that had an explicit
<seclabel type='none'/> when started would not be reparsed if
libvirtd restarted.  It turns out that our testsuite was not
exercising this because it never tried anything but inactive
parsing.  Additionally, the live XML for such a domain failed
to re-validate.  Applying just the tests/ portion of this patch
will expose the bugs that are fixed by the other two files.

* docs/schemas/domaincommon.rng (seclabel): Allow relabel under
type='none'.
* src/conf/domain_conf.c (virSecurityLabelDefParseXML): Per RNG,
presence of <seclabel> with no type implies dynamic.  Don't
require sub-elements for type='none'.
* tests/qemuxml2xmltest.c (mymain): Add test.
* tests/qemuxml2argvtest.c (mymain): Likewise.
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-none.xml: Add file.
* tests/qemuxml2argvdata/qemuxml2argv-seclabel-none.args: Add file.
Reported by Ansis Atteka.

13 years agomaint: Add test output files to .gitignore
Peter Krempa [Mon, 6 Feb 2012 17:27:40 +0000 (18:27 +0100)]
maint: Add test output files to .gitignore

Commit 8f00276c8a6140cec6a6d50441c802981d329c0c consolidated other
.gitignore files to the master one, but forgot to add some test output
files.

13 years agoUpdate myself in AUTHORS
Alex Jia [Mon, 6 Feb 2012 10:33:57 +0000 (18:33 +0800)]
Update myself in AUTHORS

Move myself from 'Previous maintainers' section to 'the primary maintainers and
people with commit access rights' section, because I have a commit rights now.

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agovirsh: Fix resource leak while listing inactive domains with titles
Peter Krempa [Mon, 6 Feb 2012 14:25:05 +0000 (15:25 +0100)]
virsh: Fix resource leak while listing inactive domains with titles

Commit fad5cd210899dfde4afe36712754dc921c3f3051 introduces a new flag
that allows to show domain's title with domains. This commit introduced
resource leak while listing inactive domains with titles.

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>
13 years agodocs: Enhance documentation of the old-style boot configuration
Jiri Denemark [Fri, 3 Feb 2012 12:33:36 +0000 (13:33 +0100)]
docs: Enhance documentation of the old-style boot configuration

Also encourages people to use per-device boot elements for better
control.

13 years agoqemu: Fix seamless spice migration
Jiri Denemark [Thu, 2 Feb 2012 15:34:08 +0000 (16:34 +0100)]
qemu: Fix seamless spice migration

Calling qemuDomainMigrateGraphicsRelocate notifies spice clients to
connect to destination qemu so that they can seamlessly switch streams
once migration is done. Unfortunately, current qemu is not able to
accept any connections while incoming migration connection is open.
Thus, we need to delay opening the migration connection to the point
spice client is already connected to the destination qemu.

13 years agotests: Fix build with -Werror
Jiri Denemark [Mon, 6 Feb 2012 08:35:47 +0000 (09:35 +0100)]
tests: Fix build with -Werror

13 years agoapparmor: Add missing comma
Jiri Denemark [Mon, 6 Feb 2012 08:22:46 +0000 (09:22 +0100)]
apparmor: Add missing comma

Typo introduced by c18a88ac

13 years agovirsh: Avoid invalid read of size errors
Alex Jia [Mon, 6 Feb 2012 03:39:41 +0000 (11:39 +0800)]
virsh: Avoid invalid read of size errors

Detected by valgrind. the codes are allocating 0 bytes memory to variable
cpumap by vshCalloc function, and then the function VIR_USE_CPU will access
it later, a invalid read error will be hit.

* tools/virsh.c(cmdVcpuPin): fix invalid read error.

* How to reproduce?
% valgrind -v --read-var-info=yes virsh vcpupin <domain> 0 0

* Actual result:

==27271== ERROR SUMMARY: 5 errors from 2 contexts (suppressed: 8 from 6)
==27271==
==27271== 1 errors in context 1 of 2:
==27271== Invalid read of size 1
==27271==    at 0x39CF087E2E: __GI_memcpy (in /lib64/libc-2.12.so)
==27271==    by 0x39CF114FDC: xdrmem_putbytes (in /lib64/libc-2.12.so)
==27271==    by 0x39CF114707: xdr_opaque (in /lib64/libc-2.12.so)
==27271==    by 0x4D56194: xdr_remote_domain_pin_vcpu_args (remote_protocol.c:1844)
==27271==    by 0x4D6CCE1: virNetMessageEncodePayload (virnetmessage.c:341)
==27271==    by 0x4D5A44B: virNetClientProgramCall (virnetclientprogram.c:327)
==27271==    by 0x4D36EDB: callWithFD (remote_driver.c:4546)
==27271==    by 0x4D36F7B: call (remote_driver.c:4567)
==27271==    by 0x4D3B2C1: remoteDomainPinVcpu (remote_client_bodies.h:1566)
==27271==    by 0x4D199D3: virDomainPinVcpu (libvirt.c:8585)
==27271==    by 0x4241F4: cmdVcpuPin (virsh.c:5262)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==  Address 0x5602b80 is 0 bytes after a block of size 0 alloc'd
==27271==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==27271==    by 0x4C89BDF: virAllocN (memory.c:129)
==27271==    by 0x423868: _vshCalloc.clone.2 (virsh.c:454)
==27271==    by 0x423EF9: cmdVcpuPin (virsh.c:5190)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)
==27271==
==27271==
==27271== 4 errors in context 2 of 2:
==27271== Invalid read of size 1
==27271==    at 0x424133: cmdVcpuPin (virsh.c:5245)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)
==27271==  Address 0x5602b80 is 0 bytes after a block of size 0 alloc'd
==27271==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==27271==    by 0x4C89BDF: virAllocN (memory.c:129)
==27271==    by 0x423868: _vshCalloc.clone.2 (virsh.c:454)
==27271==    by 0x423EF9: cmdVcpuPin (virsh.c:5190)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agomaint: consolidate several .gitignore files
Eric Blake [Fri, 3 Feb 2012 21:30:06 +0000 (14:30 -0700)]
maint: consolidate several .gitignore files

Unlike .cvsignore under CVS, git allows for ignoring nested
names.  We weren't very consistent where new tests were
being ignored (some in .gitignore, some in tests/.gitignore),
and I found it easier to just consolidate everything.

* .gitignore: Subsume entries from subdirectories.
* daemon/.gitignore: Delete.
* docs/.gitignore: Likewise.
* docs/devhelp/.gitignore: Likewise.
* docs/html/.gitignore: Likewise.
* examples/dominfo/.gitignore: Likewise.
* examples/domsuspend/.gitignore: Likewise.
* examples/hellolibvirt/.gitignore: Likewise.
* examples/openauth/.gitignore: Likewise.
* examples/domain-events/events-c/.gitignore: Likewise.
* include/libvirt/.gitignore: Likewise.
* src/.gitignore: Likewise.
* src/esx/.gitignore: Likewise.
* tests/.gitignore: Likewise.
* tools/.gitignore: Likewise.

13 years agoqemu: eliminate "Ignoring open failure" when using root-squash NFS
Laine Stump [Thu, 12 Jan 2012 18:24:45 +0000 (13:24 -0500)]
qemu: eliminate "Ignoring open failure" when using root-squash NFS

This eliminates the warning message reported in:

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

It was caused by a failure to open an image file that is not
accessible by root (the uid libvirtd is running as) because it's on a
root-squash NFS share, owned by a different user, with permissions of
660 (or maybe 600).

The solution is to use virFileOpenAs() rather than open(). The
codepath that generates the error is during qemuSetupDiskCGroup(), but
the actual open() is in a lower-level generic function called from
many places (virDomainDiskDefForeachPath), so some other pieces of the
code were touched just to add dummy (or possibly useful) uid and gid
arguments.

Eliminating this warning message has the nice side effect that the
requested operation may even succeed (which in this case isn't
necessary, but shouldn't hurt anything either).

13 years agoutil: refactor virFileOpenAs
Laine Stump [Fri, 13 Jan 2012 20:26:45 +0000 (15:26 -0500)]
util: refactor virFileOpenAs

virFileOpenAs previously would only try opening a file as the current
user, or as a different user, but wouldn't try both methods in a
single call. This made it cumbersome to use as a replacement for
open(2). Additionally, it had a lot of historical baggage that led to
it being difficult to understand.

This patch refactors virFileOpenAs in the following ways:

* reorganize the code so that everything dealing with both the parent
  and child sides of the "fork+setuid+setgid+open" method are in a
  separate function. This makes the public function easier to understand.

* Allow a single call to virFileOpenAs() to first attempt the open as
  the current user, and if that fails to automatically re-try after
  doing fork+setuid (if deemed appropriate, i.e. errno indicates it
  would now be successful, and the file is on a networkFS). This makes
  it possible (in many, but possibly not all, cases) to drop-in
  virFileOpenAs() as a replacement for open(2).

  (NB: currently qemuOpenFile() calls virFileOpenAs() twice, once
  without forking, then again with forking. That unfortunately can't
  be changed without at least some discussion of the ramifications,
  because the requested file permissions are different in each case,
  which is something that a single call to virFileOpenAs() can't deal
  with.)

* Add a flag so that any fchown() of the file to a different uid:gid
  is explicitly requested when the function is called, rather than it
  being implied by the presence of the O_CREAT flag. This just makes
  for less subtle surprises to consumers. (Commit
  b1643dc15c5de886fefe56ad18608d65f1325a2c added the check for O_CREAT
  before forcing ownership. This patch just makes that restriction
  more explicit.)

* If either the uid or gid is specified as "-1", virFileOpenAs will
  interpret this to mean "the current [gu]id".

All current consumers of virFileOpenAs should retain their present
behavior (after a few minor changes to their setup code and
arguments).

13 years agoutil: rename netlink.[ch] to virnetlink.[ch]
D. Herrendoerfer [Fri, 3 Feb 2012 14:13:19 +0000 (15:13 +0100)]
util: rename netlink.[ch] to virnetlink.[ch]

Rename the src/util/netlink files to src/util/virnetlink to
better fit the naming scheme. Also rename nlComm to virNetlinkCommand.

Signed-off-by: D. Herrendoerfer <d.herrendoerfer@herrendoerfer.name>
13 years agovirsh: add --graceful switch to destroy command
Laine Stump [Fri, 3 Feb 2012 19:14:36 +0000 (14:14 -0500)]
virsh: add --graceful switch to destroy command

This allows virsh to use the new VIR_DOMAIN_DESTROY_GRACEUL flag for
virDomainDestroyFlags.

13 years agoqemu: new GRACEFUL flag for virDomainDestroy w/ QEMU support
Laine Stump [Fri, 27 Jan 2012 18:28:23 +0000 (13:28 -0500)]
qemu: new GRACEFUL flag for virDomainDestroy w/ QEMU support

When libvirt's virDomainDestroy API is shutting down the qemu process,
it first sends SIGTERM, then waits for 1.6 seconds and, if it sees the
process still there, sends a SIGKILL.

There have been reports that this behavior can lead to data loss
because the guest running in qemu doesn't have time to flush its disk
cache buffers before it's unceremoniously whacked.

This patch maintains that default behavior, but provides a new flag
VIR_DOMAIN_DESTROY_GRACEFUL to alter the behavior. If this flag is set
in the call to virDomainDestroyFlags, SIGKILL will never be sent to
the qemu process; instead, if the timeout is reached and the qemu
process still exists, virDomainDestroy will return an error.

Once this patch is in, the recommended method for applications to call
virDomainDestroyFlags will be with VIR_DOMAIN_DESTROY_GRACEFUL
included. If that fails, then the application can decide if and when
to call virDomainDestroyFlags again without
VIR_DOMAIN_DESTROY_GRACEFUL (to force the issue with SIGKILL).

(Note that this does not address the issue of existing applications
that have not yet been modified to use VIR_DOMAIN_DESTROY_GRACEFUL.
That is a separate patch.)

13 years agovirterror.c: Fix several spelling mistakes
Philipp Hahn [Fri, 3 Feb 2012 18:20:22 +0000 (19:20 +0100)]
virterror.c: Fix several spelling mistakes

compat{a->i}bility
erron{->e}ous
nec{c->}essary.
Either "the" or "a".

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agoAdded missing memory reporting into python bindings
Martin Kletzander [Fri, 3 Feb 2012 14:53:06 +0000 (15:53 +0100)]
Added missing memory reporting into python bindings

Two types of memory stats were not reported by python bindings. This
patch fixes both of them.

13 years agopython: use libvirt_util to avoid raw free
Eric Blake [Thu, 2 Feb 2012 22:45:54 +0000 (15:45 -0700)]
python: use libvirt_util to avoid raw free

This patch starts the process of elevating the python binding code
to be on the same level as the rest of libvirt when it comes to
requiring good coding styles.  Statically linking against the
libvirt_util library makes it much easier to write good code,
rather than having to open-code and reinvent things locally.

Done by global search and replace of s/free(/VIR_FREE(/, followed
by hand-inspection of remaining malloc and redundant memset.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation):
Remove python from exemption.
* python/Makefile.am (INCLUDES): Add gnulib and src/util.  Drop
$(top_builddir)/$(subdir), as automake already guarantees that.
(mylibs, myqemulibs): Pull in libvirt_util and gnulib.
(libvirtmod_la_CFLAGS): Catch compiler warnings if configured to
use -Werror.
* python/typewrappers.c (libvirt_charPtrSizeWrap)
(libvirt_charPtrWrap): Convert free to VIR_FREE.
* python/generator.py (print_function_wrapper): Likewise.
* python/libvirt-override.c: Likewise.

13 years agobuild: expand rule to cover testsuite
Eric Blake [Thu, 2 Feb 2012 23:16:43 +0000 (16:16 -0700)]
build: expand rule to cover testsuite

The bulk of this patch was done with:

sed -i 's/\(\bfree *(/VIR_FREE(/g' tests/*.c

followed by fixing the few compile errors that resulted.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_raw_allocation):
Remove tests from exemption.
* tests/testutils.h: Add common header.
* tests/commandhelper.c: Fix offenders.
* tests/cputest.c: Likewise.
* tests/domainsnapshotxml2xmltest.c: Likewise.
* tests/interfacexml2xmltest.c: Likewise.
* tests/networkxml2argvtest.c: Likewise.
* tests/networkxml2xmltest.c: Likewise.
* tests/nodedevxml2xmltest.c: Likewise.
* tests/nodeinfotest.c: Likewise.
* tests/nwfilterxml2xmltest.c: Likewise.
* tests/qemuargv2xmltest.c: Likewise.
* tests/qemuxml2argvtest.c: Likewise.
* tests/qemuxml2xmltest.c: Likewise.
* tests/qemuxmlnstest.c: Likewise.
* tests/qparamtest.c: Likewise.
* tests/sexpr2xmltest.c: Likewise.
* tests/storagepoolxml2xmltest.c: Likewise.
* tests/storagevolxml2xmltest.c: Likewise.
* tests/testutils.c: Likewise.
* tests/virshtest.c: Likewise.
* tests/xencapstest.c: Likewise.
* tests/xmconfigtest.c: Likewise.
* tests/xml2sexprtest.c: Likewise.

13 years agobuild: prohibit raw malloc and free
Eric Blake [Thu, 2 Feb 2012 22:47:04 +0000 (15:47 -0700)]
build: prohibit raw malloc and free

Our HACKING discourages use of malloc and free, for at least
a couple of years now.  But we weren't enforcing it, until now :)

For now, I've exempted python and tests, and will clean those up
in subsequent patches.  Examples should be permanently exempt,
since anyone copying our examples won't have use of our
internal-only memory.h via libvirt_util.la.

* cfg.mk (sc_prohibit_raw_allocation): New rule.
(exclude_file_name_regexp--sc_prohibit_raw_allocation): and
exemptions.
* src/cpu/cpu.c (cpuDataFree): Avoid false positive.
* src/conf/network_conf.c (virNetworkDNSSrvDefParseXML): Fix
offenders.
* src/libxl/libxl_conf.c (libxlMakeDomBuildInfo, libxlMakeVfb)
(libxlMakeDeviceModelInfo): Likewise.
* src/rpc/virnetmessage.c (virNetMessageSaveError): Likewise.
* tools/virsh.c (_vshMalloc, _vshCalloc): Likewise.

13 years agopython: drop redundant function
Eric Blake [Thu, 2 Feb 2012 23:28:26 +0000 (16:28 -0700)]
python: drop redundant function

I noticed some redundant code while preparing my next patch.

* python/generator.py (py_types): Fix 'const char *' mapping.
* python/typewrappers.h (libvirt_charPtrConstWrap): Drop.
* python/typewrappers.c (libvirt_charPtrConstWrap): Delete, since
it is identical to libvirt_constcharPtrWrap.

13 years agobuild: clean up CPPFLAGS/INCLUDES usage
Eric Blake [Thu, 2 Feb 2012 20:20:09 +0000 (13:20 -0700)]
build: clean up CPPFLAGS/INCLUDES usage

Our syntax checker missed all-lower-case variables (this will
be fixed by the next .gnulib update).  Additionally, anywhere
that we mix in-tree files with generated files, automake recommends
listing builddir prior to srcdir for VPATH builds.

* src/Makefile.am (*_la_CFLAGS): Favor $(top_srcdir).
(INCLUDES): Likewise, and follow automake recommendations on
builddir before srcdir.
* python/Makefile.am (INCLUDES): Swap directory order.
* tests/Makefile.am (INCLUDES): Likewise.
* tools/Makefile.am (INCLUDES): Likewise.
* daemon/Makefile.am (INCLUDES): Likewise.
(libvirtd.init, libvirtd.service): Favor $().
* examples/hellolibvirt/Makefile.am (hellolibvirt_LDADD):
Likewise.
* examples/openauth/Makefile.am (openauth_LDADD): Likewise.
* examples/dominfo/Makefile.am (INCLUDES): Drop dead include.
* examples/domsuspend/Makefile.am (INCLUDES): Likewise.

13 years agocommand: allow merging stdout and stderr in string capture
Eric Blake [Fri, 27 Jan 2012 22:40:20 +0000 (15:40 -0700)]
command: allow merging stdout and stderr in string capture

Sometimes, its easier to run children with 2>&1 in shell notation,
and just deal with stdout and stderr interleaved.  This was already
possible for fd handling; extend it to also work when doing string
capture of a child process.

* docs/internals/command.html.in: Document this.
* src/util/command.c (virCommandSetErrorBuffer): Likewise.
(virCommandRun, virExecWithHook): Implement it.
* tests/commandtest.c (test14): Test it.
* daemon/remote.c (remoteDispatchAuthPolkit): Use new command
feature.

13 years agomaint: prune duplicate listings in AUTHORS
Eric Blake [Fri, 3 Feb 2012 16:56:45 +0000 (09:56 -0700)]
maint: prune duplicate listings in AUTHORS

* AUTHORS: Remove duplicates.
* .mailmap: Update accordingly.

13 years agovirsh: extension of virsh attach-disk for rawio
Taku Izumi [Fri, 3 Feb 2012 04:33:13 +0000 (13:33 +0900)]
virsh: extension of virsh attach-disk for rawio

This patch extends "virsh attach-disk" command so that
we can specify "rawio" attribute.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
13 years agoFixed connection definition for non-SELinux builds
Martin Kletzander [Fri, 3 Feb 2012 15:03:18 +0000 (16:03 +0100)]
Fixed connection definition for non-SELinux builds

This patch fixes the access of variable "con" in two files where the
variable was declared only on SELinux builds and thus the build failed
without SELinux. It's a rather nasty fix but helps fix the build
quickly and without any major changes to the code.

13 years agoAdded RSS reporting
Martin Kletzander [Tue, 24 Jan 2012 13:25:05 +0000 (14:25 +0100)]
Added RSS reporting

Added RSS information gathering into qemuMemoryStats into qemu driver
and the reporting into virsh dommemstat.

13 years agoAdded RSS information gathering into qemudGetProcessInfo
Martin Kletzander [Tue, 24 Jan 2012 13:25:04 +0000 (14:25 +0100)]
Added RSS information gathering into qemudGetProcessInfo

One more parameter added into the function parsing /proc/<pid>/stat
and the call of the function is fixed as well.

13 years agoReplace TAB with white spaces
Osier Yang [Fri, 3 Feb 2012 10:32:59 +0000 (18:32 +0800)]
Replace TAB with white spaces

13 years agolxc: Fix build with AppArmor
Jiri Denemark [Fri, 3 Feb 2012 09:49:31 +0000 (10:49 +0100)]
lxc: Fix build with AppArmor

13 years agoconf: Plug memory on virDomainDiskDefParseXML
Alex Jia [Fri, 3 Feb 2012 08:42:22 +0000 (16:42 +0800)]
conf: Plug memory on virDomainDiskDefParseXML

Detected by valgrind. Leak is introduced in commit 397e6a7.

* src/conf/domain_conf.c(virDomainDiskDefParseXML): fix memory leak.

How to reproduce?
% make -C tests check TESTS=qemuxml2argvtest
% cd tests && valgrind -v --leak-check=full ./qemuxml2argvtest

* Actual result:

==16352== 4 bytes in 1 blocks are definitely lost in loss record 12 of 147
==16352==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==16352==    by 0x39D90A67DD: xmlStrndup (xmlstring.c:45)
==16352==    by 0x4E83D5: virDomainDiskDefParseXML (domain_conf.c:2894)
==16352==    by 0x4F542D: virDomainDefParseXML (domain_conf.c:7626)
==16352==    by 0x4F8683: virDomainDefParseNode (domain_conf.c:8390)
==16352==    by 0x4F904E: virDomainDefParse (domain_conf.c:8340)
==16352==    by 0x41C626: testCompareXMLToArgvHelper (qemuxml2argvtest.c:105)
==16352==    by 0x41DED1: virtTestRun (testutils.c:142)
==16352==    by 0x418172: mymain (qemuxml2argvtest.c:486)
==16352==    by 0x41D5C7: virtTestMain (testutils.c:697)
==16352==    by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoSet a security context on /dev and /dev/pts mounts
Daniel P. Berrange [Wed, 25 Jan 2012 14:12:54 +0000 (14:12 +0000)]
Set a security context on /dev and /dev/pts mounts

To allow the container to access /dev and /dev/pts when under
sVirt, set an explicit mount option. Also set a max size on
the /dev mount to prevent DOS on memory usage

* src/lxc/lxc_container.c: Set /dev mount context
* src/lxc/lxc_controller.c: Set /dev/pts mount context

13 years agoAdd support for sVirt in the LXC driver
Daniel P. Berrange [Wed, 25 Jan 2012 14:12:53 +0000 (14:12 +0000)]
Add support for sVirt in the LXC driver

For the sake of backwards compat, LXC guests are *not*
confined by default. This is because it is not practical
to dynamically relabel containers using large filesystem
trees. Applications can create confined containers though,
by giving suitable XML configs

* src/Makefile.am: Link libvirt_lxc to security drivers
* src/lxc/libvirtd_lxc.aug, src/lxc/lxc_conf.h,
  src/lxc/lxc_conf.c, src/lxc/lxc.conf,
  src/lxc/test_libvirtd_lxc.aug: Config file handling for
  security driver
* src/lxc/lxc_driver.c: Wire up security driver functions
* src/lxc/lxc_controller.c: Add a '--security' flag to
  specify which security driver to activate
* src/lxc/lxc_container.c, src/lxc/lxc_container.h: Set
  the process label just before exec'ing init.

13 years agoAdd two new security label types
Daniel P. Berrange [Wed, 25 Jan 2012 14:12:52 +0000 (14:12 +0000)]
Add two new security label types

Curently security labels can be of type 'dynamic' or 'static'.
If no security label is given, then 'dynamic' is assumed. The
current code takes advantage of this default, and avoids even
saving <seclabel> elements with type='dynamic' to disk. This
means if you temporarily change security driver, the guests
can all still start.

With the introduction of sVirt to LXC though, there needs to be
a new default of 'none' to allow unconfined LXC containers.

This patch introduces two new security label types

 - default:  the host configuration decides whether to run the
             guest with type 'none' or 'dynamic' at guest start
 - none:     the guest will run unconfined by security policy

The 'none' label type will obviously be undesirable for some
deployments, so a new qemu.conf option allows a host admin to
mandate confined guests. It is also possible to turn off default
confinement

  security_default_confined = 1|0  (default == 1)
  security_require_confined = 1|0  (default == 0)

* src/conf/domain_conf.c, src/conf/domain_conf.h: Add new
  seclabel types
* src/security/security_manager.c, src/security/security_manager.h:
  Set default sec label types
* src/security/security_selinux.c: Handle 'none' seclabel type
* src/qemu/qemu.conf, src/qemu/qemu_conf.c, src/qemu/qemu_conf.h,
  src/qemu/libvirtd_qemu.aug: New security config options
* src/qemu/qemu_driver.c: Tell security driver about default
  config

13 years agoRe-add domain device seclabel parsing / formatting
Daniel P. Berrange [Wed, 25 Jan 2012 14:12:51 +0000 (14:12 +0000)]
Re-add domain device seclabel parsing / formatting

This re-introduces parsing & formatting for per device seclabels.
There is a new virDomainDeviceSeclabelPtr struct and corresponding
APIs for parsing/formatting.

13 years agoRevert changes to sec label parsing
Daniel P. Berrange [Wed, 25 Jan 2012 14:12:50 +0000 (14:12 +0000)]
Revert changes to sec label parsing

Revert parsing changes:

  commit 302fe95ffa1bc5f1c61c0beb31a1adfbc38c668e
  Author: Eric Blake <eblake@redhat.com>
  Date:   Wed Jan 4 16:01:24 2012 -0700

    seclabel: fix regression in libvirtd restart

  commit b43432931aef92325920953ff92beabfbe5224c8
  Author: Eric Blake <eblake@redhat.com>
  Date:   Thu Dec 22 17:47:50 2011 -0700

    seclabel: allow a seclabel override on a disk src

These two commits changed the sec label parsing code so that
the same code dealt with both the VM level sec label, and the
per device label. Unfortunately, as we add more options to the
VM level sec label, the logic required to use the same parsing
code for the per device label becomes unintelligible.

* src/conf/domain_conf.c: Remove support for parsing per
  device sec labels

13 years agoAdd detail to documentation on storage pools and volumes.
Dave Allan [Thu, 2 Feb 2012 22:06:48 +0000 (17:06 -0500)]
Add detail to documentation on storage pools and volumes.

The storage pools page contains details about the capabilities of the
various pool types, but not an overview of how they are intended to be
used.  This patch adds some explanation of what pools and volumes can
be used for and why an administrator might want to use them.

13 years agovirsh: Plug memory leak on cmdUndefine
Alex Jia [Thu, 2 Feb 2012 06:25:25 +0000 (14:25 +0800)]
virsh: Plug memory leak on cmdUndefine

Detected by valgrind. Leak is introduced in commit 3bb6bcf.

Free 'vol' memory before allocating memory, the codes will miss one time
free when 'vol_i = nvolumes' in for loop, so plug memory leak.

* tools/virsh.c: fix memory leak on cmdUndefine.

* How to reproduce?
% dd if=/dev/null of=/var/lib/libvirt/images/foo bs=1 count=1 seek=10M
% virsh define foo.xml                   (disk source file points to '/var/lib/libvirt/images/foo')
% virsh vol-clone foo foo-clone default  (the original guest name is 'foo')
% virsh pool-refresh default
% virsh vol-list default                 (make sure 'foo-clone' volume exists)
% virsh define foo-clone.xml             (disk source file points to '/var/lib/libvirt/images/foo-clone')
% valgrind -v --leak-check=full virsh undefine foo-clone --remove-all-storage

* Actual results:

1. virsh output
Domain foo-clone has been undefined
Volume '/var/lib/libvirt/images/foo-clone' removed.

error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

2. valgrind result

==6515== 92 (40 direct, 52 indirect) bytes in 1 blocks are definitely lost in loss record 46 of 69
==6515==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==6515==    by 0x4C89B71: virAlloc (memory.c:101)
==6515==    by 0x4CFCACE: virGetStorageVol (datatypes.c:724)
==6515==    by 0x4D4A8E0: remoteStorageVolLookupByPath (remote_driver.c:4664)
==6515==    by 0x4D07153: virStorageVolLookupByPath (libvirt.c:12508)
==6515==    by 0x4270E6: cmdUndefine (virsh.c:2828)
==6515==    by 0x4151B6: vshCommandRun (virsh.c:17693)
==6515==    by 0x4264D3: main (virsh.c:19270)
==6515==
==6515== LEAK SUMMARY:
==6515==    definitely lost: 40 bytes in 1 blocks

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

Signed-off-by: Alex Jia <ajia@redhat.com>
13 years agoUpdate gnulib to fix mingw64 compilation errors
Marc-André Lureau [Thu, 2 Feb 2012 00:28:28 +0000 (01:28 +0100)]
Update gnulib to fix mingw64 compilation errors

13 years agotests: dynamically replace dnsmasq path
Philipp Hahn [Mon, 30 Jan 2012 17:13:08 +0000 (18:13 +0100)]
tests: dynamically replace dnsmasq path

The path to the dnsmasq binary can be configured while in the test data
the path is hard-coded to /usr/bin/. This break the test suite if a the
binary is located in a different location, like /usr/local/sbin/.

Replace the hard coded path in the test data by a token, which is
dynamically replaced in networkxml2argvtest with the configured path
after the test data has been loaded.

(Another option would have been to modify configure.ac to generate the
 test data during configure, but I do not know of an easy way do trick
 configure into mass-generate those test files without listing every
 single one, which I consider less flexible.)

- unit-test the unit-test:
  #include <assert.h>
  #define TEST(in,token,rep,out) { char *buf = strdup(in); assert(!replaceTokens(&buf, token, rep) && !strcmp(buf, out)); free(buf); }
  TEST("", "AA", "B", "");
  TEST("A", "AA", "B", "A");
  TEST("AA", "AA", "B", "B");
  TEST("AAA", "AA", "B", "BA");
  TEST("AA", "AA", "BB", "BB");
  TEST("AA", "AA", "BBB", "BBB");
  TEST("<AA", "AA", "B", "<B");
  TEST("<AA", "AA", "BB", "<BB");
  TEST("<AA", "AA", "BBB", "<BBB");
  TEST("AA>", "AA", "B", "B>");
  TEST("AA>", "AA", "BB", "BB>");
  TEST("AA>", "AA", "BBB", "BBB>");
  TEST("<AA>", "AA", "B", "<B>");
  TEST("<AA>", "AA", "BB", "<BB>");
  TEST("<AA>", "AA", "BBB", "<BBB>");
  TEST("<AA|AA>", "AA", "B", "<B|B>");
  TEST("<AA|AA>", "AA", "BB", "<BB|BB>");
  TEST("<AA|AA>", "AA", "BBB", "<BBB|BBB>");
  TEST("<AAAA>", "AA", "B", "<BB>");
  TEST("<AAAA>", "AA", "BB", "<BBBB>");
  TEST("<AAAA>", "AA", "BBB", "<BBBBBB>");
  TEST("AAAA>", "AA", "B", "BB>");
  TEST("AAAA>", "AA", "BB", "BBBB>");
  TEST("AAAA>", "AA", "BBB", "BBBBBB>");
  TEST("<AAAA", "AA", "B", "<BB");
  TEST("<AAAA", "AA", "BB", "<BBBB");
  TEST("<AAAA", "AA", "BBB", "<BBBBBB");
  alarm(1); /* no infinite loop */
  TEST("A", "A", "A", "A");
  TEST("AA", "A", "A", "AA");
  alarm(0);

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agonetwork: fix testsuite regression
Eric Blake [Wed, 1 Feb 2012 23:42:33 +0000 (16:42 -0700)]
network: fix testsuite regression

I slightly botched commit be9fb5a - I converted '--arg=value' to
'--arg value', which has no semantic change, but did trip up the
testsuite.

* src/network/bridge_driver.c (networkBuildDnsmasqArgv): Restore
expected output.

13 years agotests: virnettlscontexttest needs gnutls-2.6.0
Philipp Hahn [Mon, 30 Jan 2012 17:44:13 +0000 (18:44 +0100)]
tests: virnettlscontexttest needs gnutls-2.6.0

virnettlscontexttest uses gnutls_x509_crt_set_subject_alt_name() and
GNUTLS_FSAN_APPEND, which - according to
<http://www.gnu.org/software/gnutls/manual/gnutls.html> - are only
available since 2.6.0.

Since libvirt still works fine with gnutls-1.0.25 from RHEL5, only
enable the test when the version of GNUTLS is at least 2.6.0.

Signed-off-by: Philipp Hahn <hahn@univention.de>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoxen_xs: name xendConfigVersion magic numbers
Philipp Hahn [Tue, 31 Jan 2012 17:08:09 +0000 (18:08 +0100)]
xen_xs: name xendConfigVersion magic numbers

libvirt supports 4 different versions of the user-land XenD daemon. When
queried the daemon just returns its generation number, which is hard to
match to the version of the Xen tools.

Replace the magic generation numbers by named enum definitions to
improve code readability.

Signed-off-by: Philipp Hahn <hahn@univention.de>
13 years agonetwork: Avoid memory leaks on networkBuildDnsmasqArgv
Alex Jia [Wed, 1 Feb 2012 09:22:21 +0000 (17:22 +0800)]
network: Avoid memory leaks on networkBuildDnsmasqArgv

Detected by valgrind. Leaks introduced in commit 973af236.

* src/network/bridge_driver.c: fix memory leaks on failure and successful path.

* How to reproduce?
% make -C tests check TESTS=networkxml2argvtest
% cd tests && valgrind -v --leak-check=full ./networkxml2argvtest

* Actual result:

==2226== 3 bytes in 1 blocks are definitely lost in loss record 1 of 24
==2226==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226==    by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226==    by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226==    by 0x41E0B7: virAsprintf (util.c:1695)
==2226==    by 0x41A2D9: networkBuildDhcpDaemonCommandLine (bridge_driver.c:545)
==2226==    by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226==    by 0x4156A1: virtTestRun (testutils.c:141)
==2226==    by 0x414332: mymain (networkxml2argvtest.c:123)
==2226==    by 0x414D97: virtTestMain (testutils.c:696)
==2226==    by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== 3 bytes in 1 blocks are definitely lost in loss record 2 of 24
==2226==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226==    by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226==    by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226==    by 0x41E0B7: virAsprintf (util.c:1695)
==2226==    by 0x41A307: networkBuildDhcpDaemonCommandLine (bridge_driver.c:551)
==2226==    by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226==    by 0x4156A1: virtTestRun (testutils.c:141)
==2226==    by 0x414332: mymain (networkxml2argvtest.c:123)
==2226==    by 0x414D97: virtTestMain (testutils.c:696)
==2226==    by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== 5 bytes in 1 blocks are definitely lost in loss record 4 of 24
==2226==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==2226==    by 0x39CF0FEDE7: __vasprintf_chk (in /lib64/libc-2.12.so)
==2226==    by 0x41DFF7: virVasprintf (stdio2.h:199)
==2226==    by 0x41E0B7: virAsprintf (util.c:1695)
==2226==    by 0x41A2AB: networkBuildDhcpDaemonCommandLine (bridge_driver.c:539)
==2226==    by 0x4145C8: testCompareXMLToArgvHelper (networkxml2argvtest.c:47)
==2226==    by 0x4156A1: virtTestRun (testutils.c:141)
==2226==    by 0x414332: mymain (networkxml2argvtest.c:123)
==2226==    by 0x414D97: virtTestMain (testutils.c:696)
==2226==    by 0x39CF01ECDC: (below main) (in /lib64/libc-2.12.so)
==2226==
==2226== LEAK SUMMARY:
==2226==    definitely lost: 11 bytes in 3 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
13 years agoblock rebase: initial qemu implementation
Eric Blake [Wed, 1 Feb 2012 04:52:58 +0000 (21:52 -0700)]
block rebase: initial qemu implementation

This is a trivial implementation, which works with the current
released qemu 1.0 with backports of preliminary block pull but
no partial rebase.  Future patches will update the monitor handling
to support an optional parameter for partial rebase; but as qemu
1.1 is unreleased, it can be in later patches, designed to be
backported on top of the supported API.

* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Add parameter,
and adjust callers.  Drop redundant check.
(qemuDomainBlockPull): Move guts...
(qemuDomainBlockRebase): ...to new function.

13 years agoblock rebase: wire up remote protocol
Eric Blake [Wed, 1 Feb 2012 04:39:18 +0000 (21:39 -0700)]
block rebase: wire up remote protocol

Nice and simple.

* src/remote/remote_protocol.x (REMOTE_PROC_DOMAIN_BLOCK_REBASE):
New RPC.
* src/remote/remote_driver.c (remote_driver): Wire it up.
* src/remote_protocol-structs: Regenerate.

13 years agoblock rebase: add new API virDomainBlockRebase
Eric Blake [Wed, 1 Feb 2012 04:19:51 +0000 (21:19 -0700)]
block rebase: add new API virDomainBlockRebase

Qemu is adding the ability to do a partial rebase.  That is, given:

base <- intermediate <- current

virDomainBlockPull will produce:

current

but qemu now has the ability to leave base in the chain, to produce:

base <- current

Note that current qemu can only do a forward merge, and only with
the current image as the destination, which is fully described by
this API without flags.  But in the future, it may be possible to
enhance this API for additional scenarios by using flags:

Merging the current image back into a previous image (that is,
undoing a live snapshot), could be done by passing base as the
destination and flags with a bit requesting a backward merge.

Merging any other part of the image chain, whether forwards (the
backing image contents are pulled into the newer file) or backwards
(the deltas recorded in the newer file are merged back into the
backing file), could also be done by passing a new flag that says
that base should be treated as an XML snippet rather than an
absolute path name, where the XML could then supply the additional
instructions of which part of the image chain is being merged into
any other part.

* include/libvirt/libvirt.h.in (virDomainBlockRebase): New
declaration.
* src/libvirt.c (virDomainBlockRebase): Implement it.
* src/libvirt_public.syms (LIBVIRT_0.9.10): Export it.
* src/driver.h (virDrvDomainBlockRebase): New driver callback.
* src/rpc/gendispatch.pl (long_legacy): Add exemption.
* docs/apibuild.py (long_legacy_functions): Likewise.

13 years agoqemu: Add support for virDomainGetMetadata and virDomainSetMetadata
Peter Krempa [Wed, 1 Feb 2012 13:03:52 +0000 (14:03 +0100)]
qemu: Add support for virDomainGetMetadata and virDomainSetMetadata

This patch adds support for the new api into the qemu driver to support
modification and retrieval of domain description and title. This patch
does not add support for modifying the <metadata> element.

13 years agovirsh: Add support for modifying domain description and titles
Peter Krempa [Wed, 1 Feb 2012 13:03:51 +0000 (14:03 +0100)]
virsh: Add support for modifying domain description and titles

This patch adds a new command "desc" to show and modify titles and
description for the domains using the new API.

This patch also adds a new flag for the "list" command to show titles in
the domain list, to allow easy identification of VMs by storing a short
description.

Example:
virsh # list --title
 Id Name                 State      Title
 -----------------------------------------------
   0 Domain-0             running    Mailserver 1
   2 fedora               paused

13 years agoAPI: Add api to set and get domain metadata
Peter Krempa [Wed, 1 Feb 2012 13:03:50 +0000 (14:03 +0100)]
API: Add api to set and get domain metadata

This patch adds API to modify domain metadata for running and stopped
domains. The api supports changing description, title as well as the
newly added <metadata> element. The API has support for storing data in
the metadata element using xml namespaces.

* include/libvirt/libvirt.h.in
* src/libvirt_public.syms
        - add function headers
        - add enum to select metadata to operate on
        - export functions
* src/libvirt.c
        - add public api implementation
* src/driver.h
        - add driver support
* src/remote/remote_driver.c
* src/remote/remote_protocol.x
        - wire up the remote protocol
* include/libvirt/virterror.h
* src/util/virterror.c
        - add a new error message note that metadata for domain are
        missing

13 years agoxml: Add element <title> to allow short description of domains
Peter Krempa [Wed, 1 Feb 2012 13:03:49 +0000 (14:03 +0100)]
xml: Add element <title> to allow short description of domains

This patch adds a new element <title> to the domain XML. This attribute
can hold a short title defined by the user to ease the identification of
domains. The title may not contain newlines and should be reasonably short.

 *docs/formatdomain.html.in
 *docs/schemas/domaincommon.rng
        - add schema grammar for the new element and documentation
  *src/conf/domain_conf.c
  *src/conf/domain_conf.h
        - add field to hold the new attribute
        - add code to parse and create XML with the new attribute