]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
12 years agosnapshot: qemu: Add support for external checkpoints
Peter Krempa [Mon, 8 Oct 2012 17:38:44 +0000 (19:38 +0200)]
snapshot: qemu: Add support for external checkpoints

This patch adds support to take external system checkpoints.

The functionality is layered on top of the previous disk-only snapshot
code. When the checkpoint is requested the domain memory is saved to the
memory image file using migration to file. (The user may specify to
take the memory image while the guest is live with the
VIR_DOMAIN_SNAPSHOT_CREATE_LIVE flag.)

The memory save image shares format with the image created by
virDomainSave() API.

12 years agosnapshot: qemu: Rename qemuDomainSnapshotCreateActive
Peter Krempa [Mon, 8 Oct 2012 14:45:04 +0000 (16:45 +0200)]
snapshot: qemu: Rename qemuDomainSnapshotCreateActive

Before now, libvirt supported only internal snapshots for active guests.
This patch renames this function to qemuDomainSnapshotCreateActiveInternal
to prepare the grounds for external active snapshots.

12 years agosnapshot: qemu: Add async job type for snapshots
Peter Krempa [Mon, 8 Oct 2012 14:34:19 +0000 (16:34 +0200)]
snapshot: qemu: Add async job type for snapshots

The new external system checkpoints will require an async job while the
snapshot is taken. This patch adds QEMU_ASYNC_JOB_SNAPSHOT to track this
job type.

12 years agosnapshot: Add flag to enable creating checkpoints in live state
Peter Krempa [Tue, 9 Oct 2012 10:11:56 +0000 (12:11 +0200)]
snapshot: Add flag to enable creating checkpoints in live state

The default behavior while creating external checkpoints is to pause the
guest while the memory state is captured. We want the users to sacrifice
space saving for creating the memory save image while the guest is live
to minimize downtime.

This patch adds a flag that causes the guest not to be paused before
taking the snapshot.
 *include/libvirt/libvirt.h.in:
    - add new paused reason: VIR_DOMAIN_PAUSED_SNAPSHOT
    - add new flag for taking snapshot: VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh-domain-monitor.c:
    - add string representation for VIR_DOMAIN_PAUSED_SNAPSHOT
 *tools/virsh-snapshot.c:
    - add support for VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh.pod:
    - add docs for --live option added to use
    VIR_DOMAIN_SNAPSHOT_CREATE_LIVE flag

12 years agoqemu: Split out domain memory saving code to allow reuse
Peter Krempa [Wed, 26 Sep 2012 12:10:56 +0000 (14:10 +0200)]
qemu: Split out domain memory saving code to allow reuse

The code that saves domain memory by migration to file can be reused
while doing external checkpoints of a machine. This patch extracts the
common code and places it in a separate function.

12 years agoqemu: Clean up snapshot retrieval to use the new helper
Peter Krempa [Thu, 11 Oct 2012 09:59:40 +0000 (11:59 +0200)]
qemu: Clean up snapshot retrieval to use the new helper

Two other places were left with the old code to look up snapshots.
Change them to use the snapshot lookup helper.

12 years agocpu: Add AMD Opteron G5 cpu model
Peter Krempa [Tue, 30 Oct 2012 15:15:35 +0000 (16:15 +0100)]
cpu: Add AMD Opteron G5 cpu model

12 years agocpu: Add newly added cpu flags
Peter Krempa [Tue, 30 Oct 2012 13:58:55 +0000 (14:58 +0100)]
cpu: Add newly added cpu flags

This patch adds a few new processor feature flags. Namely:
 f16c rdrand lwp tbm topoext perfctr_core perfctr_nb fsgsbase bmi1 hle
 avx2 bmi2 erms invpcid rtm rdseed adx tce

12 years agoqemu: Fix possible race when pausing guest
Peter Krempa [Thu, 1 Nov 2012 14:45:47 +0000 (15:45 +0100)]
qemu: Fix possible race when pausing guest

When pausing the guest while migration is running (to speed up
convergence) the virDomainSuspend API checks if the migration job is
active before entering the job. This could cause a possible race if the
virDomainSuspend is called while the job is active but ends before the
Suspend API enters the job (this would require that the migration is
aborted). This would cause a incorrect event to be emitted.

12 years agosnapshot: merge pre-snapshot checks
Eric Blake [Tue, 23 Oct 2012 15:12:26 +0000 (17:12 +0200)]
snapshot: merge pre-snapshot checks

Both system checkpoint snapshots and disk snapshots were iterating
over all disks, doing a final sanity check before doing any work.
But since future patches will allow offline snapshots to be either
external or internal, it makes sense to share the pass over all
disks, and then relax restrictions in that pass as new modes are
implemented.  Future patches can then handle external disks when
the domain is offline, then handle offline --disk-snapshot, and
finally, combine with migration to file to gain a complete external
system checkpoint snapshot of an active domain without using 'savevm'.

* src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare)
(qemuDomainSnapshotIsAllowed): Merge...
(qemuDomainSnapshotPrepare): ...into one function.
(qemuDomainSnapshotCreateXML): Update caller.

12 years agosnapshot: populate new XML info for qemu snapshots
Eric Blake [Tue, 23 Oct 2012 15:12:25 +0000 (17:12 +0200)]
snapshot: populate new XML info for qemu snapshots

Now that the XML supports listing internal snapshots, it is worth
always populating the <memory> and <disks> element to match.

* src/qemu/qemu_driver.c (qemuDomainSnapshotCreateXML): Always
parse disk info and set memory info.

12 years agosnapshot: improve disk align checking
Eric Blake [Tue, 23 Oct 2012 15:12:24 +0000 (17:12 +0200)]
snapshot: improve disk align checking

There were not previous callers with require_match set to true.
I originally implemented this bool with the intent of supporting
ESX snapshot semantics, where the choice of internal vs. external
vs. non-checkpointable must be made at domain start, but as ESX
has not been wired up to use it yet, we might as well fix it to
work with our next qemu patch for now, and worry about any further
improvements (changing the bool to a flags argument) if the ESX
driver decides to use this function in the future.

* src/conf/snapshot_conf.c (virDomainSnapshotAlignDisks): Alter
logic when require_match is true to deal with new XML.

12 years agosnapshot: new XML for external system checkpoint
Eric Blake [Tue, 23 Oct 2012 15:12:23 +0000 (17:12 +0200)]
snapshot: new XML for external system checkpoint

Each <domainsnapshot> can now contain an optional <memory>
element that describes how the VM state was handled, similar
to disk snapshots.  The new element will always appear in
output; for back-compat, an input that lacks the element will
assume 'no' or 'internal' according to the domain state.

Along with this change, it is now possible to pass <disks> in
the XML for an offline snapshot; this also needs to be wired up
in a future patch, to make it possible to choose internal vs.
external on a per-disk basis for each disk in an offline domain.
At that point, using the --disk-only flag for an offline domain
will be able to work.

For some examples below, remember that qemu supports the
following snapshot actions:

qemu-img: offline external and internal disk
savevm: online internal VM and disk
migrate: online external VM
transaction: online external disk

=====
<domainsnapshot>
  <memory snapshot='no'/>
  ...
</domainsnapshot>

implies that there is no VM state saved (mandatory for
offline and disk-only snapshots, not possible otherwise);
using qemu-img for offline domains and transaction for online.

=====
<domainsnapshot>
  <memory snapshot='internal'/>
  ...
</domainsnapshot>

state is saved inside one of the disks (as in qemu's 'savevm'
system checkpoint implementation).  If needed in the future,
we can also add an attribute pointing out _which_ disk saved
the internal state; maybe disk='vda'.

=====
<domainsnapshot>
  <memory snapshot='external' file='/path/to/state'/>
  ...
</domainsnapshot>

This is not wired up yet, but future patches will allow this to
control a combination of 'virsh save /path/to/state' plus disk
snapshots from the same point in time.

=====

So for 1.0.1 (and later, as needed), I plan to implement this table
of combinations, with '*' designating new code and '+' designating
existing code reached through new combinations of xml and/or the
existing DISK_ONLY flag:

domain  memory  disk   disk-only | result
-----------------------------------------
offline omit    omit   any       | memory=no disk=int, via qemu-img
offline no      omit   any       |+memory=no disk=int, via qemu-img
offline omit/no no     any       | invalid combination (nothing to snapshot)
offline omit/no int    any       |+memory=no disk=int, via qemu-img
offline omit/no ext    any       |*memory=no disk=ext, via qemu-img
offline int/ext any    any       | invalid combination (no memory to save)
online  omit    omit   off       | memory=int disk=int, via savevm
online  omit    omit   on        | memory=no disk=default, via transaction
online  omit    no/ext off       | unsupported for now
online  omit    no     on        | invalid combination (nothing to snapshot)
online  omit    ext    on        | memory=no disk=ext, via transaction
online  omit    int    off       |+memory=int disk=int, via savevm
online  omit    int    on        | unsupported for now
online  no      omit   any       |+memory=no disk=default, via transaction
online  no      no     any       | invalid combination (nothing to snapshot)
online  no      int    any       | unsupported for now
online  no      ext    any       |+memory=no disk=ext, via transaction
online  int/ext any    on        | invalid combination (disk-only vs. memory)
online  int     omit   off       |+memory=int disk=int, via savevm
online  int     no/ext off       | unsupported for now
online  int     int    off       |+memory=int disk=int, via savevm
online  ext     omit   off       |*memory=ext disk=default, via migrate+trans
online  ext     no     off       |+memory=ext disk=no, via migrate
online  ext     int    off       | unsupported for now
online  ext     ext    off       |*memory=ext disk=ext, via migrate+transaction

* docs/schemas/domainsnapshot.rng (memory): New RNG element.
* docs/formatsnapshot.html.in: Document it.
* src/conf/snapshot_conf.h (virDomainSnapshotDef): New fields.
* src/conf/domain_conf.c (virDomainSnapshotDefFree)
(virDomainSnapshotDefParseString, virDomainSnapshotDefFormat):
Manage new fields.
* tests/domainsnapshotxml2xmltest.c: New test.
* tests/domainsnapshotxml2xmlin/*.xml: Update existing tests.
* tests/domainsnapshotxml2xmlout/*.xml: Likewise.

12 years agosnapshot: simplify OOM checking during parse
Eric Blake [Thu, 25 Oct 2012 22:26:41 +0000 (16:26 -0600)]
snapshot: simplify OOM checking during parse

* src/conf/snapshot_conf.c (virDomainSnapshotDefParseString):
Simplify OOM reporting.

12 years agoDocument bracket whitespace rules & add syntax-check rule
Daniel P. Berrange [Wed, 17 Oct 2012 09:25:35 +0000 (10:25 +0100)]
Document bracket whitespace rules & add syntax-check rule

This documents the following whitespace rules

      if(foo)   // Bad
      if (foo)  // Good

      int foo (int wizz)  // Bad
      int foo(int wizz)   // Good

      bar = foo (wizz);  // Bad
      bar = foo(wizz);   // Good

      typedef int (*foo) (int wizz);  // Bad
      typedef int (*foo)(int wizz);   // Good

      int foo( int wizz );  // Bad
      int foo(int wizz);    // Good

There is a syntax-check rule extension to validate all these rules.
Checking for 'function (...args...)' is quite difficult since it
needs to ignore valid usage with keywords like 'if (...test...)'
and while/for/switch. It must also ignore source comments and
quoted strings.

It is not possible todo this with a simple regex in the normal
syntax-check style. So a short Perl script is created instead
to analyse the source. In practice this works well enough. The
only thing it can't cope with is multi-line quoted strings of
the form

 "start of string\
more lines\
more line\
the end"

but this can and should be written as

 "start of string"
 "more lines"
 "more line"
 "the end"

with this simple change, the bracket checking script does not
have any false positives across libvirt source, provided it
is only run against .c files. It is not practical to run it
against .h files, since those use whitespace extensively to
get alignment (though this is somewhat inconsistent and could
arguably be fixed).

The only limitation is that it cannot detect a violation where
the first arg starts with a '*', eg

   foo(*wizz);

since this generates too many false positives on function
typedefs which can't be supressed efficiently.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoRemove spurious whitespace between function name & open brackets
Daniel P. Berrange [Wed, 17 Oct 2012 09:23:12 +0000 (10:23 +0100)]
Remove spurious whitespace between function name & open brackets

The libvirt coding standard is to use 'function(...args...)'
instead of 'function (...args...)'. A non-trivial number of
places did not follow this rule and are fixed in this patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agonet: Mark network persistent when assigning persistent definition
Peter Krempa [Fri, 26 Oct 2012 12:37:26 +0000 (14:37 +0200)]
net: Mark network persistent when assigning persistent definition

When assigning the new persistent definition for a transient network
(thus making it persistent) the network needs to be marked persistent
before actually atempting to assign the definition.

12 years agonet: Add support for changing persistent networks to transient
Peter Krempa [Thu, 25 Oct 2012 14:32:29 +0000 (16:32 +0200)]
net: Add support for changing persistent networks to transient

Until now, the network undefine API was able to undefine only inactive
networks. The restriction doesn't make sense any more so this patch
implements changing networks to transient.

12 years agonet: Re-use checks when creating transient networks
Peter Krempa [Thu, 25 Oct 2012 14:27:07 +0000 (16:27 +0200)]
net: Re-use checks when creating transient networks

When a transient network was created some of the checks weren't run on
the definition allowing to start invalid networks.

This patch splits out code to the network validation function and
re-uses that code when creating transient networks.

12 years agonet: Remove dnsmasq and radvd files also when destroying transient nets
Peter Krempa [Thu, 25 Oct 2012 14:13:57 +0000 (16:13 +0200)]
net: Remove dnsmasq and radvd files also when destroying transient nets

The network driver didn't care about config files when a network was
destroyed, just when it was undefined leaving behind files for transient
networks.

This patch splits out the cleanup code to a helper function that handles
the cleanup if the inactive network object is being removed and re-uses
this code when getting rid of inactive networks.

12 years agonet: Move creation of dnsmasq hosts file to function starting dnsmasq
Peter Krempa [Thu, 25 Oct 2012 12:41:28 +0000 (14:41 +0200)]
net: Move creation of dnsmasq hosts file to function starting dnsmasq

The hosts file was created in the network definition function. This
patch moves the place the file is being created to the point where
dnsmasq is being started.

12 years agonet: Change argument type of virNetworkObjIsDuplicate()
Peter Krempa [Thu, 25 Oct 2012 12:19:59 +0000 (14:19 +0200)]
net: Change argument type of virNetworkObjIsDuplicate()

The argument check_active is used only as a boolean so this patch
changes the type and updates callers.

12 years agoconf: net: Fix deadlock if assignment of network def fails
Peter Krempa [Fri, 26 Oct 2012 12:33:13 +0000 (14:33 +0200)]
conf: net: Fix deadlock if assignment of network def fails

When the assignment fails, the network object is not unlocked and next
call that would use it deadlocks.

12 years agoconf: net: Fix helper for applying new network definition
Peter Krempa [Thu, 25 Oct 2012 15:06:04 +0000 (17:06 +0200)]
conf: net: Fix helper for applying new network definition

When there's no new definition the helper overwrote the old one with
NULL.

12 years agobuild: Do not ignore logging.c in sc_prohibit_mkstemp
Jiri Denemark [Fri, 2 Nov 2012 11:06:57 +0000 (12:06 +0100)]
build: Do not ignore logging.c in sc_prohibit_mkstemp

Now that the offending code was removed, we may remove this as well.

12 years agoRemove a chunk which should not have been pushed as part of 1.0.0
Daniel Veillard [Fri, 2 Nov 2012 11:23:13 +0000 (19:23 +0800)]
Remove a chunk which should not have been pushed as part of 1.0.0

I didn't noticed that that small old patch was still applied locally

12 years agologging.c: Properly indent and ignore one syntax-check rule
Michal Privoznik [Fri, 2 Nov 2012 10:07:54 +0000 (11:07 +0100)]
logging.c: Properly indent and ignore one syntax-check rule

With our fix of mkostemp (pushed as 2b435c15) we define a macro
to compile with uclibc. However, this definition is conditional
and thus needs to be properly indented. Moreover, with this definition
sc_prohibit_mkstemp syntax-check rule keeps yelling:

  src/util/logging.c:63:# define mkostemp(x,y) mkstemp(x)
  maint.mk: use mkostemp with O_CLOEXEC instead of mkstemp

Therefore we should ignore this file for this rule.

12 years agoqemu: use default machine type if missing it in qemu command line
Guannan Ren [Thu, 1 Nov 2012 11:43:03 +0000 (19:43 +0800)]
qemu: use default machine type if missing it in qemu command line

BZ:https://bugzilla.redhat.com/show_bug.cgi?id=871273
when using virsh qemu-attach to attach an existing qemu process,
if it misses the -M option in qemu command line, libvirtd crashed
because the NULL value of def->os.machine in later use.

Example:
/usr/libexec/qemu-kvm -name foo \
                      -cdrom /var/lib/libvirt/images/boot.img \
                      -monitor unix:/tmp/demo,server,nowait \

error: End of file while reading data: Input/output error
error: Failed to reconnect to the hypervisor

This patch tries to set default machine type if the value of
def->os.machine is still NULL after qemu command line parsing.

12 years agoRelease of libvirt-1.0.0
Daniel Veillard [Fri, 2 Nov 2012 04:08:11 +0000 (12:08 +0800)]
Release of libvirt-1.0.0

* configure.ac docs/news.html.in libvirt.spec.in: update for the new release
* po/*.po*: update from transifex, a lot of added support e.g. Indian
  languages, and regenerate

12 years agocpumap: optimize for clients that don't need online count
Eric Blake [Thu, 1 Nov 2012 23:55:43 +0000 (17:55 -0600)]
cpumap: optimize for clients that don't need online count

It turns out that calling virNodeGetCPUMap(conn, NULL, NULL, 0)
is both useful, and with Viktor's patches, common enough to
optimize.  Since this interface hasn't been released yet, we
can change the RPC call.

A bit more background on the optimization - learning the cpu count
is a single file read (/sys/devices/system/cpu/possible), but
learning the number of online cpus can possibly trigger a file
read per cpu, depending on the age of the kernel, and all wasted
if the caller passed NULL for both arguments.

* src/nodeinfo.c (nodeGetCPUMap): Avoid bitmap when not needed.
* src/remote/remote_protocol.x (remote_node_get_cpu_map_args):
Supply two separate flags for needed arguments.
* src/remote/remote_driver.c (remoteNodeGetCPUMap): Update
caller.
* daemon/remote.c (remoteDispatchNodeGetCPUMap): Likewise.
* src/remote_protocol-structs: Regenerate.

12 years agoqemu: QMP capabilities support starts with 1.2
Doug Goldstein [Thu, 1 Nov 2012 22:15:35 +0000 (17:15 -0500)]
qemu: QMP capabilities support starts with 1.2

Per the code comment in qemuCapsInitQMPBasic() and commit 43e23c7, we
should only use QMP for capabilities probing starting with 1.2 and
newer.  The old code had dead logic that probed on 1.0 and newer.

Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agoLinux Containers are not allowed to create device nodes.
Dan Walsh [Thu, 1 Nov 2012 18:54:39 +0000 (14:54 -0400)]
Linux Containers are not allowed to create device nodes.

This needs to be done before the container starts. Turning
off the mknod capability is noticed by systemd, which will
no longer attempt to create device nodes.

This eliminates SELinux AVC messages and ugly failure messages in the journal.

12 years agoqemu: Fix name comparison in qemuMonitorJSONBlockIoThrottleInfo()
Stefan Hajnoczi [Thu, 1 Nov 2012 17:20:56 +0000 (18:20 +0100)]
qemu: Fix name comparison in qemuMonitorJSONBlockIoThrottleInfo()

The string comparison logic was inverted and matched the first drive
that does *not* have the name we search for.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12 years agoqemu: Keep QEMU host drive prefix in BlkIoTune
Stefan Hajnoczi [Thu, 1 Nov 2012 17:20:55 +0000 (18:20 +0100)]
qemu: Keep QEMU host drive prefix in BlkIoTune

The QEMU -drive id= begins with libvirt's QEMU host drive prefix
("drive-"), which is stripped off in several places two convert between
host ("-drive") and guest ("-device") device names.

In the case of BlkIoTune it is unnecessary to strip the QEMU host drive
prefix because we operate on "info block"/"query-block" output that uses
host drive names.

Stripping the prefix incorrectly caused string comparisons to fail since
we were comparing the guest device name against the host device name.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
12 years agonet-update docs: s/domain/network/
Michal Privoznik [Thu, 1 Nov 2012 14:51:28 +0000 (15:51 +0100)]
net-update docs: s/domain/network/

A leftover from copy paste.

12 years agoiohelper: fdatasync() at the end
Michal Privoznik [Tue, 30 Oct 2012 18:15:48 +0000 (19:15 +0100)]
iohelper: fdatasync() at the end

Currently, when we are doing (managed) save, we insert the
iohelper between the qemu and OS. The pipe is created, the
writing end is passed to qemu and the reading end to the
iohelper. It reads data and write them into given file. However,
with write() being asynchronous data may still be in OS
caches and hence in some (corner) cases, all migration data
may have been read and written (not physically though). So
qemu will report success, as well as iohelper. However, with
some non local filesystems, where ENOSPACE is polled every X
time units, we may get into situation where all operations
succeeded but data hasn't reached the disk. And in fact will
never do. Therefore we ought sync caches to make sure data
has reached the block device on remote host.

12 years agodaemon: Make the default PolicyKit policy auth_admin_keep.
Richard W.M. Jones [Mon, 15 Oct 2012 08:01:13 +0000 (09:01 +0100)]
daemon: Make the default PolicyKit policy auth_admin_keep.

12 years agoconf: Fix private symbols exported by files in conf
Peter Krempa [Fri, 19 Oct 2012 09:52:54 +0000 (11:52 +0200)]
conf: Fix private symbols exported by files in conf

Some of the functions were moved to other files but the private symbol
file wasn't tweaked to reflect that.

12 years agoFix arch detection for qemu-system-i386 with QMP
Daniel P. Berrange [Wed, 31 Oct 2012 16:49:13 +0000 (16:49 +0000)]
Fix arch detection for qemu-system-i386 with QMP

QEMU uses 'i386' for its 32-bit x86 architecture, but libvirt
wants that to be 'i686', so we must fix it up

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agoDon't assume pid_t is the same size as an int
Daniel P. Berrange [Wed, 31 Oct 2012 17:00:50 +0000 (17:00 +0000)]
Don't assume pid_t is the same size as an int

virPidFileReadPathIfAlive passed in an 'int *' where a 'pid_t *'
was expected, which breaks on Mingw64 targets. Also a few places
were using '%d' for formatting pid_t, change them to '%lld' and
force a cast to the longer type as done elsewhere in the same
file.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
12 years agobuild: Fix RPM build for non-x86 platforms
Viktor Mihajlovski [Wed, 31 Oct 2012 21:21:06 +0000 (22:21 +0100)]
build: Fix RPM build for non-x86 platforms

Make the post install script for the lock-sanlock package optional
to prevent break on non-x86 platforms.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agodocs: libvirtd no longer uses abstract namespace
Eric Blake [Wed, 31 Oct 2012 15:46:36 +0000 (09:46 -0600)]
docs: libvirtd no longer uses abstract namespace

Commit 905be03d2 quit using the abstract namespace, but didn't
update the --help text to match.

* daemon/libvirtd.c (daemonUsage): Correct socket listing.

12 years agobuild: prefer mkostemp for multi-thread safety
Eric Blake [Wed, 31 Oct 2012 14:13:47 +0000 (08:13 -0600)]
build: prefer mkostemp for multi-thread safety

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

Commit cd1e8d1 assumed that systems new enough to have journald
also have mkostemp; but this is not true for uclibc.

For that matter, use of mkstemp[s] is unsafe in a multi-threaded
program.  We should prefer mkostemp[s] in the first place.

* bootstrap.conf (gnulib_modules): Add mkostemp, mkostemps; drop
mkstemp and mkstemps.
* cfg.mk (sc_prohibit_mkstemp): New syntax check.
* tools/virsh.c (vshEditWriteToTempFile): Adjust caller.
* src/qemu/qemu_driver.c (qemuDomainScreenshot)
(qemudDomainMemoryPeek): Likewise.
* src/secret/secret_driver.c (replaceFile): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainScreenshot): Likewise.

12 years agogitignore: Ignore 'tags'
Michal Privoznik [Wed, 31 Oct 2012 15:47:34 +0000 (16:47 +0100)]
gitignore: Ignore 'tags'

12 years agoqemu: Fix EmulatorPinInfo without emulatorpin
Martin Kletzander [Wed, 31 Oct 2012 14:49:08 +0000 (15:49 +0100)]
qemu: Fix EmulatorPinInfo without emulatorpin

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

Recent fixes made almost all the right steps to make emulator pinned
to the cpuset of the whole domain in case <emulatorpin> isn't
specified, but qemudDomainGetEmulatorPinInfo still reports all the
CPUs even when cpuset is specified.  This patch fixes that.

12 years agoutil: Improve error reporting from absolutePathFromBaseFile helper
Peter Krempa [Wed, 31 Oct 2012 10:17:41 +0000 (11:17 +0100)]
util: Improve error reporting from absolutePathFromBaseFile helper

There are multiple reasons canonicalize_file_name() used in
absolutePathFromBaseFile helper can fail. This patch enhances error
reporting from that helper.

12 years agoMake non-KVM machines work with QMP probing
Martin Kletzander [Wed, 31 Oct 2012 07:31:49 +0000 (08:31 +0100)]
Make non-KVM machines work with QMP probing

When there is no 'qemu-kvm' binary and the emulator used for a machine
is, for example, 'qemu-system-x86_64' that, by default, runs without
kvm enabled, libvirt still supplies '-no-kvm' option to this process,
even though it does not recognize such option (making the start of a
domain fail in that case).

This patch fixes building a command-line for QEMU machines without KVM
acceleration and is based on following assumptions:

 - QEMU_CAPS_KVM flag means that QEMU is running KVM accelerated
   machines by default (without explicitly requesting that using a
   command-line option).  It is the closest to the truth according to
   the code with the only exception being the comment next to the
   flag, so it's fixed in this patch as well.

 - QEMU_CAPS_ENABLE_KVM flag means that QEMU is, by default, running
   without KVM acceleration and in case we need KVM acceleration it
   needs to be explicitly instructed to do so.  This is partially
   true for the past (this option essentially means that QEMU
   recognizes the '-enable-kvm' option, even though it's almost the
   same).

12 years agobugfix: ip6tables rule removal
Gene Czarcinski [Tue, 30 Oct 2012 21:18:34 +0000 (17:18 -0400)]
bugfix: ip6tables rule removal

Three FORWARD chain rules are added and two INPUT chain rules
are added when a network is started but only the FORWARD chain
rules are removed when the network is destroyed.

12 years agomaint: log xml during volume creation
Eric Blake [Tue, 30 Oct 2012 20:53:56 +0000 (14:53 -0600)]
maint: log xml during volume creation

I noticed this while answering a list question about Java bindings
of volume creation.  All other functions that take xml logged xmlDesc.

* src/libvirt.c (virStorageVolCreateXML)
(virStorageVolCreateXMLFrom): Use consistent spelling of xmlDesc,
and log the argument.

12 years agoCreate temporary dir for socket
Guido Günther [Mon, 29 Oct 2012 08:28:15 +0000 (09:28 +0100)]
Create temporary dir for socket

to avoid ENAMETOOLONG:

https://buildd.debian.org/status/fetch.php?pkg=libvirt&arch=amd64&ver=1.0.0~rc1-1&stamp=1351453521

12 years agoutil: do a better job of matching up pids with their binaries
Laine Stump [Mon, 29 Oct 2012 22:05:41 +0000 (18:05 -0400)]
util: do a better job of matching up pids with their binaries

This patch resolves: https://bugzilla.redhat.com/show_bug.cgi?id=871201

If libvirt is restarted after updating the dnsmasq or radvd packages,
a subsequent "virsh net-destroy" will fail to kill the dnsmasq/radvd
process.

The problem is that when libvirtd restarts, it re-reads the dnsmasq
and radvd pidfiles, then does a sanity check on each pid it finds,
including checking that the symbolic link in /proc/$pid/exe actually
points to the same file as the path used by libvirt to execute the
binary in the first place. If this fails, libvirt assumes that the
process is no longer alive.

But if the original binary has been replaced, the link in /proc is set
to "$binarypath (deleted)" (it literally has the string " (deleted)"
appended to the link text stored in the filesystem), so even if a new
binary exists in the same location, attempts to resolve the link will
fail.

In the end, not only is the old dnsmasq/radvd not terminated when the
network is stopped, but a new dnsmasq can't be started when the
network is later restarted (because the original process is still
listening on the ports that the new process wants).

The solution is, when the initial "use stat to check for identical
inodes" check for identity between /proc/$pid/exe and $binpath fails,
to check /proc/$pid/exe for a link ending with " (deleted)" and if so,
truncate that part of the link and compare what's left with the
original binarypath.

A twist to this problem is that on systems with "merged" /sbin and
/usr/sbin (i.e. /sbin is really just a symlink to /usr/sbin; Fedora
17+ is an example of this), libvirt may have started the process using
one path, but /proc/$pid/exe lists a different path (indeed, on F17
this is the case - libvirtd uses /sbin/dnsmasq, but /proc/$pid/exe
shows "/usr/sbin/dnsmasq"). The further bit of code to resolve this is
to call virFileResolveAllLinks() on both the original binarypath and
on the truncated link we read from /proc/$pid/exe, and compare the
results.

The resulting code still succeeds in all the same cases it did before,
but also succeeds if the binary was deleted or replaced after it was
started.

12 years agocpu: Fix definition of flag smap
Peter Krempa [Tue, 30 Oct 2012 14:01:27 +0000 (15:01 +0100)]
cpu: Fix definition of flag smap

A mild case of dyslexia caused that commit
012f9b19ef3812884e207dc431571502de4cebce specifies wrong mask for the
smap cpu feature flag. This patch fixes that mistake.

12 years agonodeinfotest: Delete NUL bytes from test data
Peter Krempa [Tue, 30 Oct 2012 09:35:58 +0000 (10:35 +0100)]
nodeinfotest: Delete NUL bytes from test data

The test data contained extra \0 bytes after newlines probably due to a
kernel off-by-one bug.

12 years agosanlock: Introduce 'user' and 'group' conf variables
Michal Privoznik [Tue, 23 Oct 2012 14:34:21 +0000 (16:34 +0200)]
sanlock: Introduce 'user' and 'group' conf variables

through which user set under what permissions does sanlock
daemon run so libvirt will set the same permissions for
files exposed to it.

12 years agoqemu: pass -usb and usb hubs earlier, so USB disks with static address are handled...
Vladislav Bogdanov [Fri, 26 Oct 2012 09:09:22 +0000 (09:09 +0000)]
qemu: pass -usb and usb hubs earlier, so USB disks with static address are handled properly

12 years agoqemu: Do not ignore address for USB disks
Vladislav Bogdanov [Fri, 26 Oct 2012 09:09:21 +0000 (09:09 +0000)]
qemu: Do not ignore address for USB disks

12 years agoesx: Fix connection to ESX 5.1
Martin Kletzander [Tue, 30 Oct 2012 07:32:37 +0000 (08:32 +0100)]
esx: Fix connection to ESX 5.1

After separating 5.x and 5.1 versions of ESX, we forgot to add 5.1
into the list of allowed connections, so connections to 5.1 fail since
v1.0.0-rc1-5-g1e7cd39

12 years agobuild: place attributes in correct location
Eric Blake [Mon, 29 Oct 2012 22:37:05 +0000 (16:37 -0600)]
build: place attributes in correct location

Ever since commit eefb881, ATTRIBUTE_NONNULL has normally been a
no-op under gcc (since it tends to cause more bugs than it cures
given gcc's current lame implementation of the attribute).  However,
the macro is still useful to Coverity and other static-analysis
tools, but only if we use it correctly.  Coverity follows gcc's lead
in accepting function declarations with attributes at the end, but
function bodies must attach attributes to the return type.  That is,
these are valid:

void foo(void *arg) ATTRIBUTE_NONNULL(1);
void ATTRIBUTE_NONNULL(1) foo(void *arg);
void ATTRIBUTE_NONNULL(1) foo(void *arg) {}

but this is not:

void foo(void *arg) ATTRIBUTE_NONNULL(1) {}

even though you don't get a compile failure until you do static
analysis.  Bug introduced in commit 80533ca, with these symptoms:

nodeinfo.c:206: error: expected ',' or ';' before '{' token
cc1: warning: unrecognized command line option "-Wno-suggest-attribute=const"
cc1: warning: unrecognized command line option "-Wno-suggest-attribute=pure"
make[3]: *** [libvirt_driver_la-nodeinfo.lo] Error 1

* src/nodeinfo.c (virNodeParseNode): Fix syntax error when
non-null attribute is in use.

12 years agobuild: fix linking with systemtap probes
Eric Blake [Mon, 29 Oct 2012 20:17:03 +0000 (14:17 -0600)]
build: fix linking with systemtap probes

Commit 34e8f63a3 altered virfile.o to drag in additional symbols,
which in turn led to pulling in other .o files and eventually causing
a link failure when systemtap probes are enabled, such as:

./.libs/libvirt_util.a(libvirt_util_la-event_poll.o): In function `virEventPollRunOnce':
/home/dummy/libvirt/src/util/event_poll.c:614: undefined reference to `libvirt_event_poll_run_semaphore'
./.libs/libvirt_util.a(libvirt_util_la-event_poll.o):(.note.stapsdt+0x24): undefined reference to `libvirt_event_poll_add_handle_semaphore'

Even though libvirt_iohelper and libvirt_parthelper don't directly
use the portion of virfile.o that drags in probing, it was easier
to satisfy the linker and get the build back up, than to figure out
whether it is even possible or worth trying to disentangle the mess.

* src/Makefile.am (libvirt_iohelper_LDADD)
(libvirt_parthelper_LDADD): Use libvirt_probes.lo when needed.

12 years agoqemu: Report errors from iohelper
Michal Privoznik [Mon, 22 Oct 2012 15:07:49 +0000 (17:07 +0200)]
qemu: Report errors from iohelper

Currently, we use iohelper when saving/restoring a domain.
However, if there's some kind of error (like I/O) it is not
propagated to libvirt. Since it is not qemu who is doing
the actual write() it will not get error. The iohelper does.
Therefore we should check for iohelper errors as it makes
libvirt more user friendly.

12 years agoutil: Re-format literal strings in virXMLEmitWarning
Peter Krempa [Mon, 29 Oct 2012 13:38:24 +0000 (14:38 +0100)]
util: Re-format literal strings in virXMLEmitWarning

And drop a stray space at the end of the first line of the warning.

12 years agoxml: print uuids in the warning
Ján Tomko [Mon, 29 Oct 2012 12:15:55 +0000 (13:15 +0100)]
xml: print uuids in the warning

In the XML warning, we print a virsh command line that can be used to
edit that XML. This patch prints UUIDs if the entity name contains
special characters (like shell metacharacters, or "--" that would break
parsing of the XML comment). If the entity doesn't have a UUID, just
print the virsh command that can be used to edit it.

12 years agoRevert "qemu: Do not require hostuuid in migration cookie"
Jiri Denemark [Fri, 26 Oct 2012 13:06:17 +0000 (15:06 +0200)]
Revert "qemu: Do not require hostuuid in migration cookie"

This reverts commit 8d75e47edefdd77b86df1ee9af3cd5001d456f73.

Libvirt was never released with support for migration cookies without
hostuuid.

12 years agoqemu: Fix domxml-to-native network model conversion
Cole Robinson [Sun, 21 Oct 2012 02:28:34 +0000 (22:28 -0400)]
qemu: Fix domxml-to-native network model conversion

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

12 years agobuild: typo fix for qemu cpu affinity
Eric Blake [Sat, 27 Oct 2012 14:08:54 +0000 (08:08 -0600)]
build: typo fix for qemu cpu affinity

Introduced in commit 0039a32f.

* src/qemu/qemu_process.c (qemuPrepareCpumap): s/covert/convert/

12 years agoblockjob: relabel entire existing chain
Eric Blake [Sun, 14 Oct 2012 03:39:40 +0000 (21:39 -0600)]
blockjob: relabel entire existing chain

When using block copy to pivot over to a new chain, the backing files
for the new chain might still need labeling (particularly if the user
passes --reuse-ext with a relative backing file name).  Relabeling a
file that is already labeled won't hurt, so this just labels the entire
chain at the point of the pivot.  Doing the relabel of the chain uses
the fact that we already safely probed the file type of an external
file at the start of the block copy.

* src/qemu/qemu_driver.c (qemuDomainBlockPivot): Relabel chain before
asking qemu to pivot.

12 years agoblockjob: allow mirroring under SELinux and cgroup
Eric Blake [Sat, 27 Oct 2012 13:32:19 +0000 (07:32 -0600)]
blockjob: allow mirroring under SELinux and cgroup

Use the recent addition of qemuDomainPrepareDiskChainElement to
obtain locking manager lease, permit a block device through cgroups,
and set the SELinux label; then audit the fact that we hand a new
file over to qemu.  Alas, releasing the lease and label at the end
of the mirroring is a trickier prospect (we would have to trace the
backing chain of both source and destination, and be sure not to
revoke rights to any part of the chain that is shared), so for now,
virDomainBlockJobAbort still leaves things with additional access
granted (as block-pull and block-commit have the same problem of
not clamping access after completion, a future cleanup would cover
all three commands).

* src/qemu/qemu_driver.c (qemuDomainBlockCopy): Set up labeling.

12 years agoblockjob: allow for existing files in block-copy
Eric Blake [Sat, 27 Oct 2012 13:30:30 +0000 (07:30 -0600)]
blockjob: allow for existing files in block-copy

Support the REUSE_EXT flag, in part by copying sanity checks from
snapshot code.  This code introduces a case of probing an external
file for its type; such an action would be a security risk if the
existing file is supposed to be raw but the contents resemble some
other format; however, since the virDomainBlockRebase API has a
flag to force treating the file as raw rather than probe, we can
assume that probing is safe in all other instances.  Besides, if
we don't probe or force raw, then qemu will.

* src/qemu/qemu_driver.c (qemuDomainBlockRebase): Allow REUSE_EXT
flag.
(qemuDomainBlockCopy): Wire up flag, and add some sanity checks.

12 years agoblockjob: implement block copy for qemu
Eric Blake [Fri, 19 Oct 2012 23:46:08 +0000 (17:46 -0600)]
blockjob: implement block copy for qemu

Minimal patch to wire up all the pieces in the previous patches
to actually enable a block copy job.  By minimal, I mean that
qemu creates the file (that is, no REUSE_EXT flag support yet),
SELinux must be disabled, a lock manager is not informed, and the
audit logs aren't updated.  But those will be added as
improvements in future patches.

This patch is designed so that if we ever add a future API
virDomainBlockCopy with more bells and whistles (such as letting
the user specify a destination image format different than the
source), where virDomainBlockRebase is a wrapper around the
simpler portions of the new functionality, then the new API can
just reuse the new qemuDomainBlockCopy function and already
support _SHALLOW and _REUSE_EXT flags.  Also note that libvirt.c
already filtered the new flags if _COPY is not present, so that
we are not impacting the case of BlockRebase being a wrapper
around BlockPull.

* src/qemu/qemu_driver.c (qemuDomainBlockCopy): New function.
(qemuDomainBlockRebase): Call it when appropriate.

12 years agoblockjob: make block pivot safer
Eric Blake [Fri, 14 Sep 2012 03:58:44 +0000 (21:58 -0600)]
blockjob: make block pivot safer

Since libvirt drops locks between issuing a monitor command and
getting a response, it is possible for libvirtd to be restarted
before getting a response on a block-job-complete command; worse, it
is also possible for the guest to shut itself down during the window
while libvirtd is down, ending the qemu process.  A management app
needs to know if the pivot happened (and the destination file
contains guest contents not in the source) or failed (and the source
file contains guest contents not in the destination), but since
the job is finished, 'query-block-jobs' no longer tracks the
status of the job, and if the qemu process itself has disappeared,
even 'query-block' cannot be checked to ask qemu its current state.

At the time of this patch, the design for persistent bitmap has not
been clarified, so a followup patch will be needed once qemu
actually figures out how to expose it, and we figure out how to use
it.  In the meantime, we have a solution that avoids the worst of
the problem.  [This problem was first analyzed with the RHEL 6.3
__com.redhat_drive-reopen command; which partly explains why
upstream qemu 1.3 ditched the drive-reopen idea and went with
block-job-complete plus persistent bitmap instead.]

If we surround 'drive-reopen' with a pause/resume pair, then we can
guarantee that the guest cannot modify either source or destination
files in the window of libvirtd uncertainty, and the management app
is guaranteed that either libvirt knows the outcome and reported it
correctly; or that on libvirtd restart, the guest will still be
paused and that the qemu process cannot have disappeared due to
guest shutdown; and use that as a clue that the management app must
implement recovery protocol, with both source and destination files
still being in sync and with 'query-block' still being an option as
part of that recovery.  My testing shows that the pause window will
typically be only a fraction of a second.

* src/qemu/qemu_driver.c (qemuDomainBlockPivot): Pause around
drive-reopen.
(qemuDomainBlockJobImpl): Update caller.

12 years agoblockjob: support pivot operation on cancel
Eric Blake [Mon, 16 Apr 2012 22:19:19 +0000 (16:19 -0600)]
blockjob: support pivot operation on cancel

This is the bare minimum to end a copy job (of course, until a
later patch adds the ability to start a copy job, this patch
doesn't do much in isolation; I've just split the patches to
ease the review).

This patch intentionally avoids SELinux, lock manager, and audit
actions.  Also, if libvirtd restarts at the exact moment that a
'block-job-complete' is in flight, the proposed proper way to
detect the outcome of that would be with a persistent bitmap and
some additional query commands when libvirtd restarts.  This
patch is enough to test the common case of success when used
correctly, while saving the subtleties of proper cleanup for
worst-case errors for later.

When a mirror job is started, cancelling the job safely reverts back
to the source disk, regardless of whether the destination is in
phase 1 (streaming, in which case the destination is worthless) or
phase 2 (mirroring, in which case the destination is synced up to
the source at the time of the cancel).  Our existing code does just
fine in either phase, other than some bookkeeping cleanup; this
implements live block copy.

Ideas for future enhancements via new flags:

Depending on when persistent bitmap support is added, it may be
worth adding a VIR_DOMAIN_REBASE_COPY_ATOMIC flag that fails up
front if we detect an older qemu with risky pivot operation.

Interesting side note: while snapshot-create --disk-only creates a
copy of the disk at a point in time by moving the domain on to a
new file (the copy is the file now in the just-extended backing
chain), blockjob --abort of a copy job creates a copy of the disk
while keeping the domain on the original file.  There may be
potential improvements to the snapshot code to exploit block copy
over multiple disks all at one point in time.  And, if
'block-job-cancel' were made part of 'transaction', you could
copy multiple disks at the same point in time without pausing
the domain.  This also implies we may want to add a --quiesce flag
to virDomainBlockJobAbort, so that when breaking a mirror (whether
by cancel or pivot), the side of the mirror that we are abandoning
is at least in a stable state with regards to guest I/O.

* src/qemu/qemu_driver.c (qemuDomainBlockJobAbort): Accept new flag.
(qemuDomainBlockPivot): New helper function.
(qemuDomainBlockJobImpl): Implement it.

12 years agoblockjob: return appropriate event and info
Eric Blake [Fri, 12 Oct 2012 20:06:10 +0000 (14:06 -0600)]
blockjob: return appropriate event and info

Handle the new type of block copy event and info.  Of course,
this patch does nothing until a later patch actually allows the
creation/abort of a block copy job.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_JOB_READY): New
block job status.
* src/libvirt.c (virDomainBlockRebase): Document the event.
* src/qemu/qemu_monitor_json.c (eventHandlers): New event.
(qemuMonitorJSONHandleBlockJobReady): New function.
(qemuMonitorJSONGetBlockJobInfoOne): Translate new job type.
(qemuMonitorJSONHandleBlockJobImpl): Handle new event and job type.
* src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Recognize
the event to minimize snooping.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Snoop a successful
info query to save effort on a pivot request.

12 years agoblockjob: react to active block copy
Eric Blake [Tue, 10 Apr 2012 02:39:47 +0000 (20:39 -0600)]
blockjob: react to active block copy

For now, disk migration via block copy job is not implemented in
libvirt.  But when we do implement it, we have to deal with the
fact that qemu does not yet provide an easy way to re-start a qemu
process with mirroring still intact.  Paolo has proposed an idea
for a persistent dirty bitmap that might make this possible, but
until that design is complete, it's hard to say what changes
libvirt would need.  Even something like 'virDomainSave' becomes
hairy, if you realize the implications that 'virDomainRestore'
would be stuck with recreating the same mirror layout.

But if we step back and look at the bigger picture, we realize that
the initial client of live storage migration via disk mirroring is
oVirt, which always uses transient domains, and that if a transient
domain is destroyed while a mirror exists, oVirt can easily restart
the storage migration by creating a new domain that visits just the
source storage, with no loss in data.

We can make life a lot easier by being cowards for now, forbidding
certain operations on a domain.  This patch guarantees that we
never get in a state where we would have to restart a domain with
a mirroring block copy, by preventing saves, snapshots, migration,
hot unplug of a disk in use, and conversion to a persistent domain
(thankfully, it is still relatively easy to 'virsh undefine' a
running domain to temporarily make it transient, run tests on
'virsh blockcopy', then 'virsh define' to restore the persistence).
Later, if the qemu design is enhanced, we can relax our code.

The change to qemudDomainDefine looks a bit odd for undoing an
assignment, rather than probing up front to avoid the assignment,
but this is because of how virDomainAssignDef combines both a
lookup and assignment into a single function call.

* src/conf/domain_conf.h (virDomainHasDiskMirror): New prototype.
* src/conf/domain_conf.c (virDomainHasDiskMirror): New function.
* src/libvirt_private.syms (domain_conf.h): Export it.
* src/qemu/qemu_driver.c (qemuDomainSaveInternal)
(qemuDomainSnapshotCreateXML, qemuDomainRevertToSnapshot)
(qemuDomainBlockJobImpl, qemudDomainDefine): Prevent dangerous
actions while block copy is already in action.
* src/qemu/qemu_hotplug.c (qemuDomainDetachDiskDevice): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsAllowed): Likewise.

12 years agoblockjob: add qemu capabilities related to block jobs
Eric Blake [Fri, 28 Sep 2012 23:29:53 +0000 (17:29 -0600)]
blockjob: add qemu capabilities related to block jobs

Upstream qemu 1.3 is adding two new monitor commands, 'drive-mirror'
and 'block-job-complete'[1], which can drive live block copy and
storage migration.  [Additionally, RHEL 6.3 had backported an earlier
version of most of the same functionality, but under the names
'__com.redhat_drive-mirror' and '__com.redhat_drive-reopen' and with
slightly different JSON arguments, and has been using patches similar
to these upstream patches for several months now.]

The libvirt API virDomainBlockRebase as already committed for 0.9.12
is flexible enough to expose the basics of block copy, but some
additional features in the 'drive-mirror' qemu command, such as
setting error policy, setting granularity, or using a persistent
bitmap, may later require a new libvirt API virDomainBlockCopy.  I
will wait to add that API until we know more about what qemu 1.3
will finally provide.

This patch caters only to the upstream qemu 1.3 interface, although
I have proven that the changes for RHEL 6.3 can be isolated to
just qemu_monitor_json.c, and the rest of this series will
gracefully handle either interface once the JSON differences are
papered over in a downstream patch.

For consistency with other block job commands, libvirt must handle
the bandwidth argument as MiB/sec from the user, even though qemu
exposes the speed argument as bytes/sec; then again, qemu rounds
up to cluster size internally, so using MiB hides the worst effects
of that rounding if you pass small numbers.

[1]https://lists.gnu.org/archive/html/qemu-devel/2012-10/msg04123.html

* src/qemu/qemu_capabilities.h (QEMU_CAPS_DRIVE_MIRROR)
(QEMU_CAPS_DRIVE_REOPEN): New bits.
* src/qemu/qemu_capabilities.c (qemuCaps): Name them.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONCheckCommands): Set
them.
(qemuMonitorJSONDriveMirror, qemuMonitorDrivePivot): New functions.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONDriveMirror)
(qemuMonitorDrivePivot): Declare them.
* src/qemu/qemu_monitor.c (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): New passthroughs.
* src/qemu/qemu_monitor.h (qemuMonitorDriveMirror)
(qemuMonitorDrivePivot): Declare them.

12 years agoqemu: fix attach/detach of netdevs with matching mac addrs
Laine Stump [Thu, 25 Oct 2012 20:03:35 +0000 (16:03 -0400)]
qemu: fix attach/detach of netdevs with matching mac addrs

This resolves:

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

which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.

(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)

A synopsis of the problems:

1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.

2) you *can* do a live attach-interface of such a device.

3) you *can* directly edit a domain and put in two devices with
matching mac addresses.

4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.

5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.

Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:

1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.

2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.

This patch does three things:

1) removes the check for duplicate mac address during a persistent
netdev attach.

2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.

Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)

3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.

Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device

* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
  * added new virDomainNetFindIdx function
  * removed now unused virDomainNetIndexByMac and
    virDomainNetRemoveByMac

* src/qemu/qemu_driver.c
  * remove check for duplicate max from qemuDomainAttachDeviceConfig
  * use virDomainNetFindIdx/virDomainNetRemove instead
    of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
  * use virDomainNetFindIdx instead of virDomainIndexByMac
    in qemuDomainUpdateDeviceConfig

* src/qemu/qemu_hotplug.c
  * use virDomainNetFindIdx instead of a homespun loop in
    qemuDomainDetachNetDevice.

* tools/virsh-domain.c: modified detach-interface command as described
    above

12 years agocpustat: fix regression when cpus are offline
Eric Blake [Thu, 25 Oct 2012 20:44:32 +0000 (14:44 -0600)]
cpustat: fix regression when cpus are offline

It turns out that the cpuacct results properly account for offline
cpus, and always returns results for every possible cpu, not just
the online ones.  So there is no need to check the map of online
cpus in the first place, merely only a need to know the maximum
possible cpu.  Meanwhile, virNodeGetCPUBitmap had a subtle change
from returning the maximum id to instead returning the width of
the bitmap (one larger than the maximum id) in commit 2f4c5338,
which made this code encounter some off-by-one logic leading to
bad error messages when a cpu was offline:

$ virsh cpu-stats dom
error: Failed to virDomainGetCPUStats()

error: An error occurred, but the cause is unknown

Cleaning this up unraveled a chain of other unused variables.

* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Drop
pointless check for cpumap changes, and use correct number of
cpus.  Simplify signature.
(qemuDomainGetCPUStats): Adjust caller.
* src/nodeinfo.h (nodeGetCPUCount): New prototype.
(nodeGetCPUBitmap): Drop unused parameter.
* src/nodeinfo.c (nodeGetCPUBitmap): Likewise.
(nodeGetCPUMap): Adjust caller.
(nodeGetCPUCount): New function.
* src/libvirt_private.syms (nodeinfo.h): Export it.

12 years agobuild: fix syntax-check tab violation
Eric Blake [Fri, 26 Oct 2012 21:27:25 +0000 (15:27 -0600)]
build: fix syntax-check tab violation

* tools/Makefile.am: Fix tab damage in previous patch.

12 years agobuild: check for pod errors
Eric Blake [Fri, 26 Oct 2012 15:06:54 +0000 (09:06 -0600)]
build: check for pod errors

Patch 61299a1c fixed a long-standing pod error in the man page.
But we should be preventing these up front.
See also https://bugzilla.redhat.com/show_bug.cgi?id=870273

* tools/Makefile.am (virt-xml-validate.1, virt-pki-validate.1)
(virt-host-validate.1, virt-sanlock-cleanup.8, virsh.1): Reject
pod conversion errors.
* daemon/Makefile.am ($(srcdir)/libvirtd.8.in): Likewise.

12 years agobuild: silence compiler warning about signedness
Eric Blake [Fri, 26 Oct 2012 20:28:40 +0000 (14:28 -0600)]
build: silence compiler warning about signedness

Commit 246143b fixed a warning on older gcc, but caused a warning
on newer gcc.

../../src/rpc/virnetserverservice.c: In function 'virNetServerServiceNewPostExecRestart':
../../src/rpc/virnetserverservice.c:277:41: error: pointer targets in passing argument 3 of 'virJSONValueObjectGetNumberUint' differ in signedness [-Werror=pointer-sign]

* src/rpc/virnetserverservice.c: Use correct types.

12 years agobuild: fix type-punning bug
Eric Blake [Fri, 26 Oct 2012 18:53:45 +0000 (12:53 -0600)]
build: fix type-punning bug

With older gcc and 64-bit size_t, the compiler issues a real warning:
rpc/virnetserverservice.c:277: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]

Introduced in commit 0cc79255.  Depending on machine endianness,
this warning represents a real bug that could mis-interpret the
value by a factor of 2^32.  I don't know why I couldn't get newer
gcc to report the same warning message.

* src/rpc/virnetserverservice.c
(virNetServerServiceNewPostExecRestart): Use temporary instead.

12 years agoparallels: fix build for some older compilers
Laine Stump [Fri, 26 Oct 2012 17:23:56 +0000 (13:23 -0400)]
parallels: fix build for some older compilers

Found this when building on RHEL5:

parallels/parallels_storage.c: In function 'parallelsStorageOpen':
parallels/parallels_storage.c:180: error: 'for' loop initial declaration used outside C99 mode

(and similar error in parallels_driver.c). This was in spite of
configuring with "-Wno-error".

12 years agodocumentation: HTML tag fix
Philipp Hahn [Fri, 26 Oct 2012 08:38:02 +0000 (10:38 +0200)]
documentation: HTML tag fix

Replace '%' by '&' for correct escaping of '>' in Domain specification.

Signed-off-by: Philipp Hahn <hahn@univention.de>
12 years agomaint: Sort .gitignore
Peter Krempa [Fri, 26 Oct 2012 12:39:55 +0000 (14:39 +0200)]
maint: Sort .gitignore

Sorting of the .gitignore file was broken after the last addition. After
a clean build the scripts re-sort it making the working tree dirty.

12 years agovirsh: Fix POD syntax
Jiri Denemark [Fri, 26 Oct 2012 10:25:14 +0000 (12:25 +0200)]
virsh: Fix POD syntax

The first two hunks fix "Unterminated I<...> sequence" error and the
last one fixes "’=item’ outside of any ’=over’" error.

12 years agovirsh: Remove --flags from nodesuspend
Jiri Denemark [Thu, 25 Oct 2012 08:14:38 +0000 (10:14 +0200)]
virsh: Remove --flags from nodesuspend

We always expose individual bits from flags as separate options rather
than exposing a raw flags options. Since virNodeSuspendForDuration does
not currently support any flags, the only way of using this --flags
options that would not fail is "--flags 0", which is equivalent to
omitting the option. Thus it is highly unlikely anyone would actually be
using it and removing it should be safe.

12 years agosnapshot: improve snapshot-list error message
Eric Blake [Thu, 25 Oct 2012 21:17:38 +0000 (15:17 -0600)]
snapshot: improve snapshot-list error message

https://bugzilla.redhat.com/show_bug.cgi?id=869100 mentioned some
confusion about 'virsh snapshot-list' errors.  Clean up a
misleading error message, and add some documentation.

* tools/virsh-snapshot.c (cmdSnapshotList): Mention --current
rather than --from when appropriate.
* tools/virsh.pod (snapshot-list): Mention that the named starting
point is NOT part of the list except under --tree.

12 years agomaint: ignore unsaved emacs files
Eric Blake [Thu, 25 Oct 2012 22:12:46 +0000 (16:12 -0600)]
maint: ignore unsaved emacs files

I did a 'git add .', then realized that it ended up trying to
add the emacs lock file for a corresponding file that I had not
yet saved all my edits; thankfully I noticed it in time.  Since
we already exclude other temporary files, this makes the most
sense for preventing such a mistake from actually hitting upstream.

* .gitignore: Add .#* to the exclude list.

12 years agodaemon: Fix LIBVIRT_DEBUG=1 default output
Cole Robinson [Wed, 24 Oct 2012 20:51:44 +0000 (16:51 -0400)]
daemon: Fix LIBVIRT_DEBUG=1 default output

This commit changes the behavior of LIBVIRT_DEBUG=1 libvirtd:

$ git show 7022b09111d4322d21396a70d58320a9ad773962
commit 7022b09111d4322d21396a70d58320a9ad773962
Author: Daniel P. Berrange <berrange@redhat.com>
Date:   Thu Sep 27 13:13:09 2012 +0100

    Automatically enable systemd journal logging

    Probe to see if the systemd journal is accessible, and if
    so enable logging to the journal by default, rather than
    stderr (current default under systemd).

Previously  'LIBVIRT_DEBUG=1 /usr/sbin/libvirtd' would show all debug
output to stderr, now it send debug output to the journal.

Only use the journal by default if running in daemon mode, or
if stdin is _not_ a tty. This should make libvirtd launched from
systemd use the journal, but preserve the old behavior in most
situations.

12 years agonetwork: fix networkValidate check for default portgroup and vlan
Laine Stump [Thu, 25 Oct 2012 15:13:52 +0000 (11:13 -0400)]
network: fix networkValidate check for default portgroup and vlan

This was found during testing of the fix for:

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

networkValidate was supposed to check for the existence of multiple
portgroups and report an error if this was encountered. It did, but
there were two problems:

1) even though it logged an error, it still returned success, allowing
the operation to continue.

2) It could exit the portgroup checking loop early (or possibly not
even do it once) if a vlan tag was supplied in the base network config
or one of the portgroups.

This patch fixes networkValidate to return failure in addition to
logging the error, and also changes it to not exit the portgroup
checking loop early. The logic was a bit off in the checking for vlan
anyway, and it's intertwined with fixing the early loop exit, so I
fixed that as well. Now it correctly checks for combinations where a
<virtualport> is specified in the base network def and <vlan> is given
in a portgroup, as well as the opposite (<vlan> in base network def
and <virtualport> in portgroup), and ignores the case of a disallowed
vlan when using *no* portgroup if there is a default portgroup (since
in that case there is no way to not use any portgroup).

12 years agomaint: consistent whitespace after 'if'
Eric Blake [Thu, 25 Oct 2012 17:36:43 +0000 (11:36 -0600)]
maint: consistent whitespace after 'if'

Noticed during the review of the previous patch.

* python/libvirt-override.c: Use space between 'if ('.

12 years agovirNodeGetCPUMap: Add python binding
Viktor Mihajlovski [Thu, 25 Oct 2012 14:59:08 +0000 (16:59 +0200)]
virNodeGetCPUMap: Add python binding

Added a method getCPUMap to virConnect.
It can be used as follows:

import libvirt
import sys
import os

conn = libvirt.openReadOnly(None)
if conn == None:
    print 'Failed to open connection to the hypervisor'
    sys.exit(1)

try:
    (cpus, cpumap, online) = conn.getCPUMap(0)
except:
    print 'Failed to extract the node cpu map information'
    sys.exit(1)

print 'CPUs total %d, online %d' % (cpus, online)
print 'CPU map %s' % str(cpumap)

del conn
print "OK"

sys.exit(0)

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
12 years agovirNodeGetCPUMap: Implement driver support
Viktor Mihajlovski [Tue, 16 Oct 2012 14:05:15 +0000 (16:05 +0200)]
virNodeGetCPUMap: Implement driver support

Driver support added for:
- test: pretending 8 host CPUS, 3 being online
- qemu, lxc, openvz, uml: using nodeGetCPUMap

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agovirNodeGetCPUMap: Implement support function in nodeinfo
Viktor Mihajlovski [Tue, 16 Oct 2012 14:05:14 +0000 (16:05 +0200)]
virNodeGetCPUMap: Implement support function in nodeinfo

Added an implemention of virNodeGetCPUMap to nodeinfo.c,
(nodeGetCPUMap) which can be used by all drivers for a Linux
hypervisor host.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
12 years agonodeinfo: improve probing node cpu bitmap
Eric Blake [Wed, 24 Oct 2012 22:43:26 +0000 (16:43 -0600)]
nodeinfo: improve probing node cpu bitmap

Callers should not need to know what the name of the file to
be read in the Linux-specific version of nodeGetCPUmap;
furthermore, qemu cares about online cpus, not present cpus,
when determining which cpus to skip.

While at it, I fixed the fact that we were computing the maximum
online cpu id by doing a slow iteration, when what we really want
to know is the max available cpu.

* src/nodeinfo.h (nodeGetCPUmap): Rename...
(nodeGetCPUBitmap): ...and simplify signature.
* src/nodeinfo.c (linuxParseCPUmax): New function.
(linuxParseCPUmap): Simplify and alter signature.
(nodeGetCPUBitmap): Change implementation.
* src/libvirt_private.syms (nodeinfo.h): Reflect rename.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Update
caller.

12 years agobitmap: add virBitmapCountBits
Eric Blake [Thu, 25 Oct 2012 00:44:27 +0000 (18:44 -0600)]
bitmap: add virBitmapCountBits

Sometimes it's handy to know how many bits are set.

* src/util/bitmap.h (virBitmapCountBits): New prototype.
(virBitmapNextSetBit): Use correct type.
* src/util/bitmap.c (virBitmapNextSetBit): Likewise.
(virBitmapSetAll): Maintain invariant of clear tail bits.
(virBitmapCountBits): New function.
* src/libvirt_private.syms (bitmap.h): Export it.
* tests/virbitmaptest.c (test2): Test it.

12 years agoFix build with apparmor
Jiri Denemark [Wed, 24 Oct 2012 10:13:48 +0000 (12:13 +0200)]
Fix build with apparmor

Recent storage patches changed signature of virStorageFileGetMetadata
and replaced chain with backingChain in virDomainDiskDef.

12 years agoesx: Update version checks for vSphere 5.1
Matthias Bolte [Wed, 24 Oct 2012 17:50:15 +0000 (19:50 +0200)]
esx: Update version checks for vSphere 5.1

Also remove warnings for upcoming versions. There hadn't been any
compatibility problems with new ESX version over the whole lifetime
of the ESX driver, so I don't expect any in the future.

Update documentation to mention vSphere 5.x support.

12 years agocpu: Add recently added cpu feature flags.
Peter Krempa [Wed, 24 Oct 2012 13:10:51 +0000 (15:10 +0200)]
cpu: Add recently added cpu feature flags.

Qemu has added some new feature flags. This patch adds them to libvirt.

The new features are for the cpuid function 0x7 that takes an argument
in the ecx register. Currently only 0x0 is used as the argument so I was
lazy and I just clear the registers to 0 before calling cpuid. In future
when there maybe will be some other possible arguments, we will need to
improve the cpu detection code to take this into account.

12 years agoqemu: Prohibit chaning affinity of domain process if placement is 'auto'
Osier Yang [Wed, 24 Oct 2012 09:46:00 +0000 (17:46 +0800)]
qemu: Prohibit chaning affinity of domain process if placement is 'auto'

On one hand, numad probably will manage the affinity of domain process
dynamically in future. On the other hand, even numad won't manage it,
it still could confusion. Let's make things simpler enough to avoid
the lair for now.

12 years agoqemu: Keep the affinity when creating cgroup for emulator thread
Osier Yang [Wed, 24 Oct 2012 09:27:56 +0000 (17:27 +0800)]
qemu: Keep the affinity when creating cgroup for emulator thread

When the cpu placement model is "auto", it sets the affinity for
domain process with the advisory nodeset from numad, however,
creating cgroup for the domain process (called emulator thread
in some contexts) later overrides that with pinning it to all
available pCPUs.

How to reproduce:

  * Configure the domain with "auto" placement for <vcpu>, e.g.
    <vcpu placement='auto'>4</vcpu>
  * % virsh start dom
  * % cat /proc/$dompid/status

Though the emulator cgroup cause conflicts, but we can't simply
prohibit creating it, as other tunables are still useful, such
as "emulator_period", which is used by API
virDomainSetSchedulerParameter. So this patch doesn't prohibit
creating the emulator cgroup, but inherit the nodeset from numad,
and reset the affinity for domain process.

* src/qemu/qemu_cgroup.h: Modify definition of qemuSetupCgroupForEmulator
                          to accept the passed nodenet
* src/qemu/qemu_cgroup.c: Set the affinity with the passed nodeset