Commit Graph

11310 Commits

Author SHA1 Message Date
Eric Blake
2cd4d8e506 virsh: add snapshot-create-as memspec support
External checkpoints could be created with snapshot-create, but
without libvirt supplying a default name for the memory file,
it is essential to add a new argument to snapshot-create-as to
allow the user to choose the memory file name.  This adds the
option --memspec [file=]name[,snapshot=type], where type can
be none, internal, or external.  For an example,

virsh snapshot-create-as $dom --memspec /path/to/file

is the shortest possible command line for creating an external
checkpoint, named after the current timestamp.

* tools/virsh-snapshot.c (vshParseSnapshotMemspec): New function.
(cmdSnapshotCreateAs): Use it.
* tests/virsh-optparse (test_url): Test it.
* tools/virsh.pod (snapshot-create-as): Document it.
2012-11-07 09:04:18 -07:00
Eric Blake
9d91a18ebf virsh: make ,, escape parsing common
So far, none of the existing callers of vshStringToArray expected
the user to ever pass a literal comma; meanwhile, snapshot parsing
had rolled its own array parser.  Moving the comma escaping into
the common function won't affect any existing callers, and will make
this function reusable for adding memory handling to snapshot parsing.

As a bonus, the testsuite was already testing snapshot parsing, so
the fact that the test still passes means that we are now giving
testsuite exposure to vshStringToArray.

* tools/virsh-snapshot.c (vshParseSnapshotDiskspec): Move ,,
parsing...
* tools/virsh.c (vshStringToArray): ...into common function.
Also, vshStrdup can't fail.
2012-11-07 09:01:37 -07:00
Michal Privoznik
a08fc66d90 qemu: Emit event if 'cont' fails
Some operations, APIs needs domain to be paused prior operation can be
performed, e.g. (managed-) save of a domain. The processors should be
restored in the end. However, if 'cont' fails for some reason, we log a
message but this is not sufficient as an event should be emitted as
well. Mgmt application can then decide what to do.
2012-11-07 12:06:09 +01:00
Michal Privoznik
adb29a8869 Introduce new VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR event
This is supposed to be thrown every time we need to pause domain
because of API execution (e.g. qemuDomainSaveInternal) but fails
to restore it back after. In this case, domain remains paused,
however, none of existing reasons can fit this scenario.
2012-11-07 12:06:05 +01:00
Eric Blake
5f63a5cb42 virsh: document which term is older
Make it clear that the alternate terms have no difference except
for length of time they were supported.

* tools/virsh.pod (start, shutdown, reboot): More documentation.
2012-11-06 08:09:32 -07:00
Eric Blake
ff86b0c97b virsh: add aliases 'boot', 'stop', and 'restart'
https://bugzilla.redhat.com/show_bug.cgi?id=873344 suggested that
the grouping 'boot', 'shutdown', 'reboot'; as well as the grouping
'start', 'stop', 'restart'; might be easier to remember than the
current mix of 'start', 'shutdown', 'reboot'.

Also, touch up the wording of 'reboot' to be more accurate.

* tools/virsh-domain.c (domManagementCmds): Add other command names.
* tools/virsh.pod (start, shutdown, reboot): Document the aliases.
2012-11-06 08:03:48 -07:00
Peter Krempa
fb58f8e2a4 qemu: Don't corrupt pointer in qemuDomainSaveMemory()
The code that was split out into the qemuDomainSaveMemory expands the
pointer containing the XML description of the domain that it gets from
higher layers. If the pointer changes the old one is invalid and the
upper layer function tries to free it causing an abort.

This patch changes the expansion of the original string to a new
allocation and copy of the contents.
2012-11-06 14:45:27 +01:00
Martin Kletzander
9c294e6f9a esx: Yet another connection fix for 5.1
After the connection to ESX 5.1 being broken since g1e7cd39, the fix
in bab7752c helped a bit, but still missed a spot, so the connection
is now successful, but some APIs (for example defineXML) don't work.
Two cases missing are added in this patch to avoid that.
2012-11-06 11:09:00 +01:00
Michal Privoznik
a95c9406a2 tests: Add test for controller order 2012-11-06 10:11:35 +01:00
Michal Privoznik
0f720ab35a qemu: Add controllers in specified order
qemu is sensitive to the order of arguments passed. Hence, if a
device requires a controller, the controller cmd string must
precede device cmd string. The same apply for controllers, when
for instance ccid controller requires usb controller. So
controllers create partial ordering in which they should be added
to qemu cmd line.
2012-11-06 10:11:34 +01:00
Michal Privoznik
77b93dbc3e qemu: Wrap controllers code into dummy loop
which just re-indent code and prepare it for next patch.
2012-11-06 10:11:34 +01:00
Václav Pavlín
ec02d49dfd spec: replace scriptlets with new systemd macros
https://bugzilla.redhat.com/850186

I added %with_systemd_macros so it should now work in F17 with old
scriptlets and in F18+/RHEL7+ with systemd macros
(see https://fedoraproject.org/wiki/Packaging:ScriptletSnippets#Systemd)

I missed libvirt-guests.service because there is no systemctl call for
it. So I only added systemd macros calls.
2012-11-05 14:30:56 -07:00
Eric Blake
b61eadf3c6 spec: don't enable cgconfig under systemd
In Fedora 16, we quit enabling cgconfig because systemd set up
default cgroups that were good enough for our use.  But in F17,
when we switched to systemd, we reverted and started up cgconfig
again.  See also the tail of this thread:
https://www.redhat.com/archives/libvir-list/2012-October/msg01657.html

* libvirt.spec.in (with_systemd): Rely on systemd for cgroups.
2012-11-05 10:27:02 -07:00
Michal Privoznik
46325e5131 iohelper: Don't report errors on special FDs
Some FDs may not implement fdatasync() functionality,
e.g.  pipes. In that case EINVAL or EROFS is returned.
We don't want to fail then nor report any error.

Reported-by: Christophe Fergeau <cfergeau@redhat.com>
2012-11-05 16:55:42 +01:00
liguang
b27b712c24 gitignore: ignore more files
ignore cscope.in.out, cscope.po.out

Signed-off-by: liguang <lig.fnst@cn.fujitsu.com>
2012-11-05 15:56:42 +01:00
Peter Krempa
0dac29d89f snapshot: qemu: Remove restrictions preventing external checkpoints
Some of the pre-snapshot check have restrictions wired in regarding
configuration options that influence taking of external checkpoints.

This patch removes restrictions that would inhibit taking of such a
snapshot.
2012-11-04 20:17:57 +01:00
Peter Krempa
f569b87f51 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.
2012-11-04 16:53:32 +01:00
Peter Krempa
b5fd404471 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.
2012-11-03 15:06:09 +01:00
Peter Krempa
2a59a3d597 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.
2012-11-03 14:57:43 +01:00
Peter Krempa
5f75bd4bbe 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
2012-11-03 14:43:01 +01:00
Peter Krempa
2771f8b74c 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.
2012-11-03 11:49:41 +01:00
Peter Krempa
ec69ca14f9 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.
2012-11-03 11:26:39 +01:00
Peter Krempa
d38b934c49 cpu: Add AMD Opteron G5 cpu model 2012-11-02 20:57:17 +01:00
Peter Krempa
bafffe7a10 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
2012-11-02 20:52:40 +01:00
Peter Krempa
d0fc6dc831 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.
2012-11-02 20:18:46 +01:00
Eric Blake
de76cae971 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.
2012-11-02 10:19:03 -06:00
Eric Blake
e260e401a5 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.
2012-11-02 10:11:50 -06:00
Eric Blake
f9670bf8a4 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.
2012-11-02 10:02:57 -06:00
Eric Blake
4201a7ea1c 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.
2012-11-02 09:56:23 -06:00
Eric Blake
e66bdbb784 snapshot: simplify OOM checking during parse
* src/conf/snapshot_conf.c (virDomainSnapshotDefParseString):
Simplify OOM reporting.
2012-11-02 09:43:49 -06:00
Daniel P. Berrange
a3e95abeb5 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>
2012-11-02 14:00:32 +00:00
Daniel P. Berrange
1c04f99970 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>
2012-11-02 13:36:49 +00:00
Peter Krempa
0211fd6e04 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.
2012-11-02 13:28:40 +01:00
Peter Krempa
fa16957ccd 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.
2012-11-02 13:28:40 +01:00
Peter Krempa
b6dbbae128 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.
2012-11-02 13:28:40 +01:00
Peter Krempa
e87af617fc 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.
2012-11-02 13:28:40 +01:00
Peter Krempa
23ae3fe425 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.
2012-11-02 13:28:40 +01:00
Peter Krempa
a3258c0eb9 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.
2012-11-02 13:28:39 +01:00
Peter Krempa
f823089124 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.
2012-11-02 13:28:39 +01:00
Peter Krempa
947230fb56 conf: net: Fix helper for applying new network definition
When there's no new definition the helper overwrote the old one with
NULL.
2012-11-02 13:28:39 +01:00
Jiri Denemark
d055498d04 build: Do not ignore logging.c in sc_prohibit_mkstemp
Now that the offending code was removed, we may remove this as well.
2012-11-02 12:32:51 +01:00
Daniel Veillard
bd0cb27cf6 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
2012-11-02 19:23:13 +08:00
Michal Privoznik
30b398d5ef 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.
2012-11-02 11:19:04 +01:00
Guannan Ren
1851a0c864 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.
2012-11-02 12:55:29 +08:00
Daniel Veillard
2b435c153e 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
2012-11-02 12:08:11 +08:00
Eric Blake
3d0130cbcc 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.
2012-11-01 20:36:01 -06:00
Doug Goldstein
ba804d9fd1 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>
2012-11-01 17:50:02 -06:00
Dan Walsh
2e03b08ead 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.
2012-11-01 15:14:25 -06:00
Stefan Hajnoczi
23d47b33a2 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>
2012-11-01 13:23:27 -06:00
Stefan Hajnoczi
04ee70bfda 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>
2012-11-01 13:03:26 -06:00