Commit Graph

13932 Commits

Author SHA1 Message Date
John Ferlan
1e5a8ddc81 remote: Implement the remote plumbing for virDomainGetIOThreadsInfo
Implement the remote plumbing for virDomainGetIOThreadsInfo

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-03-06 06:49:32 -05:00
John Ferlan
11a5a0956f Implement public API for virDomainGetIOThreadsInfo
Add virDomainGetIOThreadInfo in order to return a list of
virDomainIOThreadInfoPtr structures which list the IOThread ID
and the CPU Affinity map for each IOThread for the domain.

For an active domain, the live data will be returned, while for
an inactive domain, the config data will be returned.

The API supports either the --live or --config flag, but not both.

Also added virDomainIOThreadsInfoFree in order to free the cpumap
and the IOThreadInfo structure.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-03-06 06:49:32 -05:00
Pavel Hrdina
cf521fc8ba memtune: change the way how we store unlimited value
There was a mess in the way how we store unlimited value for memory
limits and how we handled values provided by user.  Internally there
were two possible ways how to store unlimited value: as 0 value or as
VIR_DOMAIN_MEMORY_PARAM_UNLIMITED.  Because we chose to store memory
limits as unsigned long long, we cannot use -1 to represent unlimited.
It's much easier for us to say that everything greater than
VIR_DOMAIN_MEMORY_PARAM_UNLIMITED means unlimited and leave 0 as valid
value despite that it makes no sense to set limit to 0.

Remove unnecessary function virCompareLimitUlong.  The update of test
is to prevent the 0 to be miss-used as unlimited in future.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-03-06 11:52:24 +01:00
Pavel Hrdina
a73395ae66 virutil: introduce helper functions for memory limits
The first one is to truncate the memory limit to
VIR_DOMAIN_MEMORY_PARAM_UNLIMITED if the value is greater and the second
one is to decide whether the memory limit is set or not, unlimited means
that it's not set.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-03-06 11:52:23 +01:00
Stefan Berger
9954a8bfc2 qemu: Pass file descriptor when using TPM passthrough
Pass the TPM file descriptor to QEMU via command line.
Instead of passing /dev/tpm0 we now pass /dev/fdset/10 and the additional
parameters -add-fd set=10,fd=20.

This addresses the use case when QEMU is started with non-root privileges
and QEMU cannot open /dev/tpm0 for example.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-05 18:57:06 -05:00
Stefan Berger
42bee147fe qemu: Move TPM command line build code into own function
Move the TPM command line build code into its own function.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-05 18:57:06 -05:00
Stefan Berger
a06e9ce11d utils: Implement virCommandPassFDGetFDIndex
Implement virCommandPassFDGetFDIndex to determine the index a given
file descriptor will have when passed to the child process.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2015-03-05 18:57:06 -05:00
Jim Fehlig
3b7f589571 libxl: remove unneeded cleanup_unlock label
In the old days of a global driver lock, it was necessary to unlock
the driver after a domain restore operation.  When the global lock
was removed from the driver, some remnants were left behind in
libxlDomainRestoreFlags.  Remove this unneeded (and incorrect) code.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:35 -07:00
Jim Fehlig
b1d159d889 libxl: use libxl_ctx passed to libxlConsoleCallback
Instead of using the libxl_ctx in the libxlDomainObjPrivatePtr,
use the ctx passed to the callback.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:34 -07:00
Jim Fehlig
fc3ef44ea4 libxl: remove redundant calls to libxl_evdisable_domain_death
Domain death watch is already disabled in libxlDomainCleanup.  No
need to disable it a second and third time.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
2015-03-05 09:05:34 -07:00
Peter Krempa
7909300498 conf: Remove duplicate entries in <metadata> by namespace
Since the APIs support just one element per namespace and while
modifying an element all duplicates would be removed, let's do this
right away in the post parse callback.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1190590
2015-03-05 16:24:34 +01:00
Michal Privoznik
5aee81a0cb qemu: Allow spaces in disk serial
https://bugzilla.redhat.com/show_bug.cgi?id=1195660

There's been a bug report appearing on the qemu-devel list, that
libvirt is unable to pass spaces in disk serial number [1]. Not only
our RNG schema forbids that, the code is not prepared either. However,
with a bit of escaping (if needed) we can allow spaces there.

1: https://lists.gnu.org/archive/html/qemu-devel/2015-02/msg04041.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-05 13:35:55 +01:00
Ján Tomko
41c5baeafb Fix build on mingw
Last commit unconditionally included a linux-specific header.

Do not do that.
2015-03-05 12:04:11 +01:00
James Chapman
c9027d8f44 SRIOV NIC offload feature discovery
Adding functionality to libvirt that will allow it
query the ethtool interface for the availability
of certain NIC HW offload features

Here is an example of the feature XML definition:

<device>
<name>net_eth4_90_e2_ba_5e_a5_45</name>
  <path>/sys/devices/pci0000:00/0000:00:03.0/0000:08:00.1/net/eth4</path>
  <parent>pci_0000_08_00_1</parent>
  <capability type='net'>
    <interface>eth4</interface>
    <address>90:e2:ba:5e:a5:45</address>
    <link speed='10000' state='up'/>
    <feature name='rx'/>
    <feature name='tx'/>
    <feature name='sg'/>
    <feature name='tso'/>
    <feature name='gso'/>
    <feature name='gro'/>
    <feature name='rxvlan'/>
    <feature name='txvlan'/>
    <feature name='rxhash'/>
    <capability type='80203'/>
  </capability>
</device>

Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-03-05 11:31:05 +01:00
Michal Privoznik
6954e7da52 parallels: Cleanup partly opened drivers on connect open failure
Well, the parallelsConnectOpen() joins several sub-driver openings
into one big if condition. If any of sub-driver fails to open, the
whole API finishes immediately. The problem is, sub-drivers may have
left some memory allocated. Fortunately, we have a free function for
that: parallelsConnectClose(). This is, however, not prepared for
partially allocated driver structure. So, prepare the free function
for it and call it at the right place, in the if body.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-05 08:38:21 +01:00
Erik Skultety
3fde7986d6 storage: tweak condition to properly test lseek
According to the POSIX standard, off_t (returned by lseek) is defined as
signed integral type no shorter than int. Because our offset variable is defined
as unsigned long long, the original check was passed successfully if UINT64_MAX had
been used as offset value, due to implicit conversion.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1177219
2015-03-04 14:51:44 +01:00
Shanzhi Yu
f7c1410b0e qemu: snapshot: Don't skip check for qcow2 format with network disks
When the domain's source disk type is network, if source protocol is rbd
or sheepdog, the 'if().. break' will end the current case, which lead to
miss check the driver type is raw or qcow2. Libvirt will allow to create
internal snapshot for a running domain with raw format disk which based
on rbd storage.

While both protocols support internal snapshots of the disk qemu is not
able to use it as it requires some place to store the memory image. The
check if the disk is backed by a qcow2 image needs to be executed
always.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1179533
Signed-off-by: Shanzhi Yu <shyu@redhat.com>
2015-03-04 14:13:06 +01:00
Peter Krempa
3923d98e05 qemu: Allow inactive domains in qemuDomainGetControlInfo()
Inactive domains can still be stuck in a job or other problems. Add a
way to detect it.
2015-03-04 10:41:30 +01:00
Peter Krempa
31a55c7cb4 qemu: Properly report error state in qemuDomainGetControlInfo()
Previously when a domain would get stuck in a domain job due to a
programming mistake we'd report the following control state:

$ virsh domcontrol domain
occupied (1424343406.150s)

The timestamp is invalid as the monitor was not entered for that domain.
We can use that to detect that the domain has an active job and report a
better error instead:

$ virsh domcontrol domain
error: internal (locking) error
2015-03-04 10:41:30 +01:00
Michal Privoznik
53cae19561 conf: s/virNetworkFindByName/virNetworkObjFindByName/
It's returning virNetworkObjPtr after all. And it matches the
pattern laid out by domain_conf.h.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:12:16 +01:00
Michal Privoznik
82f240ae56 conf: s/virNetworkFindByUUID/virNetworkObjFindByUUID/
It's returning virNetworkObjPtr after all. And it matches the
pattern laid out by domain_conf.h.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:11:40 +01:00
Michal Privoznik
2ea3ce332b bridge_driver: s/virNetworkObjList/virNetworkObjListPtr/
In order to hide the object internals (and use just accessors
everywhere), lets store a pointer to the object, instead of object
itself.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:11:24 +01:00
Michal Privoznik
c3dfec15ae parallels: s/virNetworkObjList/virNetworkObjListPtr/
In order to hide the object internals (and use just accessors
everywhere), lets store a pointer to the object, instead of object
itself.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:10:50 +01:00
Michal Privoznik
a9ba542272 test_driver: s/virNetworkObjList/virNetworkObjListPtr/
In order to hide the object internals (and use just accessors
everywhere), lets store a pointer to the object, instead of object
itself.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:09:45 +01:00
Michal Privoznik
bbbc7e41e0 virNetworkObjListExport: Pass virNetworkObjListPtr
Instead of copying the whole object onto stack when calling the
function, just pass the pointer to the object and save up some
space on the stack. Moreover, this prepares the code to hide the
virNetworkObjList structure into network_conf.c and use accessors
only.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:09:30 +01:00
Michal Privoznik
5b86f9aa1c virNetworkObjListFree: Accept NULL
All of our vir*Free() functions should accept NULL, even though
that there's no way of actually passing NULL with current code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:09:10 +01:00
Michal Privoznik
9432ac70b2 virNetworkObjIsDuplicate: s/@doms/@nets/
This is probably a copy-paste error from virDomainObj*
counterpart.  But when speaking of virNetworkObj we should use
variable @nets for an array of networks, rather than @doms. It's
just confusing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:09:04 +01:00
Michal Privoznik
5c6b8226f3 networkGetNetworkAddress: Drop empty 'error' label
Moreover, there are two points within the function, where we're
missing 'goto cleanup'. Fix this too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:08:24 +01:00
Michal Privoznik
77ea6f7b0b testNetworkUpdate: Unlock network at the end
Silly this bug went unnoticed so long. At the beginning we try to
find the passed network in the list of network objects. If found,
it's locked and real work takes place. Then, in the end, the
network object is never unlocked.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:08:14 +01:00
Michal Privoznik
7b8c12d8ce bridge_driver: Don't check network active unlocked
Okay, this is mainly for educational purposes since is called
from single point only with all the possible locks held. So
there's no way for other thread to hop in and do something wrong.
Nevertheless, we should not give bad example.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:08:07 +01:00
Michal Privoznik
bf1afdd491 networkLookupByUUID: Improve error message
We have this function networkObjFromNetwork() which for given
virNetworkPtr tries to find corresponding virNetworkObjPtr. If no
object is found, a nice error message is printed out:

  no network with matching uuid '$uuid' ($name)

Let's improve the error message produced by networkLookupByUUID to
follow that logic.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-04 10:07:59 +01:00
Michal Privoznik
63889e0c77 qemuProcessReconnect: Fill in pid file path
https://bugzilla.redhat.com/show_bug.cgi?id=1197600

So, libvirt uses pid file to track pid of started qemus. Whenever
a domain is started, its pid is put into corresponding pid file.
The pid file path is generated based on domain name and stored
into domain object internals. However, it's not stored in the
status XML and therefore lost on daemon restarts. Hence, later,
when domain is being shut down, the daemon does not know which
pid file to unlink, and the correct pid file is left behind. To
avoid this, lets generate the pid file path again in
qemuProcessReconnect().

Reported-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-03 12:10:15 +01:00
Pavel Hrdina
a16e5f0a91 qemu: check defaultMode for spice graphics independently
Instead of checking defaultMode for every channel that has no mode
configured, test it only once outside of channel loop.  This fixes a bug
that in case all possible channels are fore example set to insecure, but
defaultMode is set to secure, we wouldn't auto-generate TLS port.  This
results in failure while starting a guest.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-03-03 11:42:33 +01:00
Pavel Hrdina
e4983952b4 qemu: remove duplicated code for allocating spice ports
We have two different places that needs to be updated while touching
code for allocation spice ports.  Add a bool option to
'qemuProcessSPICEAllocatePorts' function to switch between true and fake
allocation so we can use this function also in qemu_driver to generate
native domain definition.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-03-03 11:41:46 +01:00
Martin Kletzander
2fd5880b3b conf: De-duplicate scheduling policy enums
Since adding the support for scheduler policy settings in commit
8680ea97, there are two enums with the same information.  That was
caused by rewriting the patch since first draft.

Find out thanks to clang, but there was no impact whatsoever.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-03-03 09:26:59 +01:00
Martin Kletzander
b3ea0a8fb8 qemu: Don't crash in qemuDomainOpenChannel()
The problem here was that when opening a channel, we were checking
whether the channel given is alias (can't be NULL for running domain) or
it's name, which can be NULL (for example with spicevmc).  In case of
such domain qemuDomainOpenChannel() made the daemon crash.
STREQ_NULLABLE() is safe to use since the code in question is wrapped in
"if (name)" and is more readable, so use that instead of checking for
non-NULL "vm->def->channels[i]->target.name".

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-03-03 09:26:59 +01:00
John Ferlan
30f69ae86b iscsi: Adjust error message for findStorageSources backend
The virStorageBackendISCSIFindPoolSources API only needs the 'host' name
in order to discover iSCSI pools, it returns the various device paths.
On input, it's also possible to further restrict a search by providing the
port attribute for the host element and the (undocumented) initiator element.

For example:

$  virsh find-storage-pool-sources-as iscsi
error: Failed to find any iscsi pool sources
error: invalid argument: hostname and device path must be specified for iscsi sources

$ virsh find-storage-pool-sources-as iscsi 192.168.122.1
<sources>
  <source>
    <host name='192.168.122.1' port='3260'/>
    <device path='iqn.2013-12.com.example:iscsi-chap-lclpool'/>
  </source>
</sources>
2015-03-02 22:57:27 -05:00
John Ferlan
832a9256b2 disk: Provide a default storage source format type.
https://bugzilla.redhat.com/show_bug.cgi?id=1181062

According to the formatstorage.html description for <source> element
and "format" attribute: "All drivers are required to have a default
value for this, so it is optional."

As it turns out the disk backend did not choose a default value, so I
added a default of "msdos" if the source type is "unknown" as well as
updating the storage.html backend disk volume driver documentation to
indicate the default format is dos.
2015-03-02 22:42:25 -05:00
John Ferlan
e0e290552b disk: Disallow duplicated target 'dev' values
https://bugzilla.redhat.com/show_bug.cgi?id=1142631

This patch resolves a situation where the same "<target dev='$name'...>"
can be used for multiple disks in the domain.

While the $name is "mostly" advisory regarding the expected order that
the disk is added to the domain and not guaranteed to map to the device
name in the guest OS, it still should be unique enough such that other
domblk* type operations can be performed.

Without the patch, the domblklist will list the same Target twice:

$ virsh domblklist $dom
Target     Source
------------------------------------------------
sda        /var/lib/libvirt/images/file.qcow2
sda        /var/lib/libvirt/images/file.img

Additionally, getting domblkstat, domblkerror, domblkinfo, and other block*
type calls will not be able to reference the second target.

Fortunately, hotplug disallows adding a "third" sda value:

$ qemu-img create -f raw /var/lib/libvirt/images/file2.img 10M
$ virsh attach-disk $dom /var/lib/libvirt/images/file2.img sda
error: Failed to attach disk
error: operation failed: target sda already exists

$

BUT, it since 'sdb' doesn't exist one would get the following on the same
hotplug attempt, but changing to use 'sdb' instead of 'sda'

$ virsh attach-disk $dom /var/lib/libvirt/images/file2.img sdb
error: Failed to attach disk
error: internal error: unable to execute QEMU command 'device_add': Duplicate ID 'scsi0-0-1' for device

$

Since we cannot fix this issue at parsing time, the best that can be done so
as to not "lose" a domain is to make the check prior to starting the guest
with the results as follows:

$ virsh start $dom
error: Failed to start domain $dom
error: XML error: target 'sda' duplicated for disk sources '/var/lib/libvirt/images/file.qcow2' and '/var/lib/libvirt/images/file.img'

$

Running 'make check' found a few more instances in the tests where this
duplicated target dev value was being used. These also exhibited some
duplicated 'id=' values (negating the uniqueness argument of aliases) in
the corresponding .args file and of course the *xmlout version of a few
input XML files.
2015-03-02 22:38:36 -05:00
Peter Krempa
8968c4946c conf: numa: Add helper to count total memory size configured in NUMA
The total NUMA memory consists of the sum of individual NUMA node memory
amounts.
2015-03-02 16:42:51 +01:00
Peter Krempa
389634e667 qemu: Forbid setting maximum memory size with the API with NUMA enabled
NUMA enabled guest configuration explicitly specifies memory sizes for
individual nodes. Allowing the virDomainSetMemoryFlags API (and friends)
to change the total doesn't make sense as the individual node configs
are not updated in that case.

Forbid use of the API in case NUMA is specified.
2015-03-02 16:41:32 +01:00
Peter Krempa
812a9e5e66 phyp: Fix error messages mentioning memory
The messages for currentMemory and memory were swapped.
2015-03-02 14:39:58 +01:00
Peter Krempa
1fcb9351d7 storage: sheepdog: Avoid skipping variable initialization
Commit 155ca616eb added a error message
that skips initialization of the 'cmd' variable. Fortunately it was not
released.
2015-03-02 10:09:49 +01:00
Ján Tomko
723522328f Check if domain is running in qemuDomainAgentIsAvailable
If the domain is not running, the agent will not respond.
Do not even try.

https://bugzilla.redhat.com/show_bug.cgi?id=872424
2015-03-02 08:07:56 +01:00
Ján Tomko
fbb94044ea Pass virDomainObjPtr to qemuDomainAgentAvailable
Not just the DomainObj's private data.
2015-03-02 08:07:56 +01:00
Ján Tomko
c8b80b49f6 Check for qemu guest agent availability after getting the job
This way checks requiring the job can be done in qemuDomainAgentAvailable.
2015-03-02 08:07:56 +01:00
Ján Tomko
155ca616eb Allow creating volumes with a backing store but no capacity
The tool creating the image can get the capacity from the backing
storage. Just refresh the volume afterwards.

https://bugzilla.redhat.com/show_bug.cgi?id=958510
2015-03-02 08:07:11 +01:00
Ján Tomko
813e4b7f83 Allow omitting volume capacity when backing store is specified
Add VIR_VOL_XML_PARSE_OPT_CAPACITY flag to virStorageVolDefParseXML.
With this flag, no error is reported when the capacity is missing
if there is a backing store.
2015-03-02 08:07:11 +01:00
Ján Tomko
d3452a3f73 Revert "Restore skipping of setting capacity"
This reverts commit f1856eb622.

Now that we can update capacity from image metadata,
we don't need to skip the update.
2015-03-02 08:07:11 +01:00
Ján Tomko
a760ba3a7f Probe for capacity in virStorageBackendUpdateVolTargetInfo
Instead of just looking at the output of fstat, call
virStorageFileGetMetadata to get the full capacity from
image headers.

Note that the capacity is probed unconditionally. The updateCapacity
bool parameter is ignored and will be removed in the following commit.
2015-03-02 08:07:11 +01:00
Ján Tomko
e3f1d2a820 Allow cloning volumes with no capacity specified
In virStorageVolCreateXML, add VIR_VOL_XML_PARSE_NO_CAPACITY
to the call parsing the XML of the new volume to make the capacity
optional.

If the capacity is omitted, use the capacity of the old volume.
We already do that for values that are less than the original
volume capacity.
2015-03-02 08:07:11 +01:00
Ján Tomko
2bd47d9c64 Allow parsing volumes without specifying the capacity
Add VIR_VOL_XML_PARSE_NO_CAPACITY flag to the volume XML
parser. When set, it allows the capacity element to be omitted.
2015-03-02 08:07:11 +01:00
Ján Tomko
21f58a5854 Parse backingStore before capacity in volume XML
So we can allow omitting the capacity element if backing store is
present.
2015-03-02 08:07:11 +01:00
Ján Tomko
cbd788eba6 Add flags argument to virStorageVolDefParse*
Allow the callers to pass down libvirt-internal flags.
2015-03-02 08:07:11 +01:00
Ján Tomko
000b21da83 Trivially implement VIR_CONNECT_BASELINE_CPU_MIGRATABLE for non-x86 cpus
Assume no features block migration.
2015-03-02 07:59:12 +01:00
Ján Tomko
496156807b Implement VIR_CONNECT_BASELINE_CPU_MIGRATABLE in the x86 cpu driver
Filter out non-migratable features if
VIR_CONNECT_BASELINE_CPU_MIGRATABLE was specified.
2015-03-02 07:59:12 +01:00
Ján Tomko
02c8b66d6a Add VIR_CONNECT_BASELINE_CPU_MIGRATABLE flag
This flag for virConnectBaselineCPU will allow filtering out
CPU features that block migration from the result.

https://bugzilla.redhat.com/show_bug.cgi?id=1171484
2015-03-02 07:59:12 +01:00
Ján Tomko
995ca6cbf3 Use virBufferTrim when generating boot options
Instead of tracking the number of added parameters,
add a comma at the end of each one unconditionally
and trim the trailing one at the end.
2015-03-02 07:39:09 +01:00
Ján Tomko
354425dcd2 Make -boot arg generation more readable
If we combine the boot order on the command line with other
boot options, we prepend order= in front of it.

Instead of checking if the number of added arguments is between
0 and 2, separate the strings for boot order and options
and prepend boot order only if both strings are not empty.
2015-03-02 07:39:09 +01:00
Ján Tomko
92572c3d71 Remove code handling the QEMU_CAPS_DOMID capability
This option is xenner-only (since commit b81a7ece),
and we dropped support for xenner in commit de9be0a.
2015-03-02 07:39:09 +01:00
Ján Tomko
9aa316612a Remove bootloader option from QEMU
It was only supported by xenner (since commit 763a59d8),
for which we removed support in commit de9be0a.

Remove the code generating this command line option,
refuse to parse it and delete the outdated tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1176050
2015-03-02 07:39:09 +01:00
Ján Tomko
c75f42f331 Really fix XML formatting flags in SaveImageUpdateDef
Commit cf2d4c6 used a logical or instead of bitwise or,
effectively passing 1, that is VIR_DOMAIN_XML_INACTIVE.

This was caught by a warning when building with clang.

https://bugzilla.redhat.com/show_bug.cgi?id=1183869
2015-02-27 12:01:31 +01:00
Ján Tomko
8c45e8bec8 Ignore listen attribute of <graphics> for type network listens
Commit 6992994 started filling the listen attribute
of the parent <graphics> elements from type='network' listens.

When this XML is passed to UpdateDevice, parsing fails:
XML error: graphics listen attribute 10.20.30.40 must match
address attribute of first listen element (found none)

Ignore the address in the parent <graphics> attribute
when no type='address' listens are found,
the same we ignore the address for the <listen> subelements
when parsing inactive XML.
2015-02-27 08:27:21 +01:00
Peter Krempa
ef2e6f4089 util: storage: Fix error type in virStorageSourceParseBackingURI
The gluster volume name extraction code was copied from the XML parser
without changing the VIR_ERR_XML_ERROR error code. Use
VIR_ERR_CONFIG_UNSUPPORTED instead.
2015-02-26 11:50:38 +01:00
Peter Krempa
fc56ecd735 util: storagefile: Don't crash on gluster URIs without path
Similar to commit fdb80ed4f6 libvirtd
would crash if a gluster URI without path would be used in the backing
chain of a volume. The crash happens in the gluster specific part of the
parser that extracts the gluster volume name from the path.

Fix the crash by checking that the PATH is NULL.

This patch does not contain a test case as it's not possible to test it
with the current infrastructure as the test suite would attempt to
contact the gluster server in the URI. I'm working on the test suite
addition but that will be post-release material.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1196528
2015-02-26 11:50:38 +01:00
Ján Tomko
b15b21f3a5 conf: error out on missing dhcp host attributes
In virNetworkDHCPHostDefParseXML an error is reported
when partialOkay == true, and none of ip, mac, name
were supplied.

Add the missing goto and error out in this case.
2015-02-26 09:03:09 +01:00
Luyao Huang
719cd2182b conf: error out on invalid host id
https://bugzilla.redhat.com/show_bug.cgi?id=1196503

We already check whether the host id is valid or not, add a jump
to forbid invalid host id.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-26 08:52:43 +01:00
Laine Stump
4bbe1029f2 qemu: fix ifindex array reported to systemd
Commit f7afeddc added code to report to systemd an array of interface
indexes for all tap devices used by a guest. Unfortunately it not only
didn't add code to report the ifindexes for macvtap interfaces
(interface type='direct') or the tap devices used by type='ethernet',
it ended up sending "-1" as the ifindex for each macvtap or hostdev
interface. This resulted in a failure to start any domain that had a
macvtap or hostdev interface (or actually any type other than
"network" or "bridge").

This patch does the following with the nicindexes array:

1) Modify qemuBuildInterfaceCommandLine() to only fill in the
nicindexes array if given a non-NULL pointer to an array (and modifies
the test jig calls to the function to send NULL). This is because
there are tests in the test suite that have type='ethernet' and still
have an ifname specified, but that device of course doesn't actually
exist on the test system, so attempts to call virNetDevGetIndex() will
fail.

2) Even then, only add an entry to the nicindexes array for
appropriate types, and to do so for all appropriate types ("network",
"bridge", and "direct"), but only if the ifname is known (since that
is required to call virNetDevGetIndex().
2015-02-25 13:11:14 -05:00
Laine Stump
153b06c6d1 util: check for null ifname inside virNetDevBandwidthSet()
Previously this function relied on having ATTRIBUTE_NONNULL(1) in its
prototype rather than explicitly checking for a null
ifname. Unfortunately, ATTRIBUTE_NONNULL is just a hint to the
optimizer and code analyzers like Coverity, it doesn't actually check
anything at execution time, so the result was possible warnings from
Coverity, along with the possibility of null dereferences when ifname
wasn't available.

This patch removes the ATTRIBUTE_NONNULL from the prototype, and
checks ifname inside the function, logging an error if it's NULL (once
we've determined that the user really is trying to set a bandwidth).
2015-02-25 13:10:34 -05:00
Laine Stump
118b240808 network: only clear bandwidth if it has been set
libvirt was unconditionally calling virNetDevBandwidthClear() for
every interface (and network bridge) of a type that supported
bandwidth, whether it actually had anything set or not. This doesn't
hurt anything (unless ifname == NULL!), but is wasteful.

This patch makes sure that all calls to virNetDevBandwidthClear() are
qualified by checking that the interface really had some bandwidth
setup done, and checks for a null ifname inside
virNetDevBandwidthClear(), silently returning success if it is null
(as well as removing the ATTRIBUTE_NONNULL from that function's
prototype, since we can't guarantee that it is never null,
e.g. sometimes a type='ethernet' interface has no ifname as it is
provided on the fly by qemu).
2015-02-25 13:09:34 -05:00
Yuri Chornoivan
8a833d1eb0 Fix typos in messages
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-25 14:12:51 +01:00
Ján Tomko
6784acc7b0 Fix error messages in virStorageFileGetMetadataFromFD
Do not use relPath, it has not been filled by virStorageFileMetadataNew.
2015-02-25 12:14:30 +01:00
Ján Tomko
c6807b507a Clarify behavior or virDomainDetachDevice
Document that a complete device definition should be used
and a partial match can lead to the device being detached.

https://bugzilla.redhat.com/show_bug.cgi?id=872028
2015-02-25 10:06:41 +01:00
Ján Tomko
52a166f493 Assign default SCSI controller model before checking attribute validity
If the qemu binary on x86 does not support lsi SCSI controller,
but it supports virtio-scsi, we reject the virtio-specific attributes
for no reason.

Move the default controller assignment before the check.

https://bugzilla.redhat.com/show_bug.cgi?id=1168849
2015-02-25 10:04:58 +01:00
Michal Privoznik
cf2d4c603c qemu: Use correct flags for ABI stability check in SaveImageUpdateDef
https://bugzilla.redhat.com/show_bug.cgi?id=1183869

Soo. you've successfully started yourself a domain. And since you want
to use it on your host exclusively you are confident enough to
passthrough the host CPU model, like this:

  <cpu mode='host-passthrough'/>

Then, after a while, you want to save the domain into a file (e.g.
virsh save dom dom.save). And here comes the trouble. The file consist
of two parts: Libvirt header (containing domain XML among other
things), and qemu migration data. Now, the domain XML in the header is
formatted using special flags (VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_UPDATE_CPU | VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_MIGRATABLE).

Then, on your way back from the bar, you think of changing something
in the XML in the saved file (we have a command for it after all), say
listen address for graphics console. So you successfully type in the
command:

  virsh save-image-edit dom.save

Change all the bits, and exit the editor. But instead of success
you're left with sad error message:

  error: unsupported configuration: Target CPU model <null> does not
  match source Pentium Pro

Sigh. Digging into the code you see lines, where we check for ABI
stability. The new XML you've produced is compared with the old one
from the saved file to see if qemu ABI will break or not. Wait, what?
We are using different flags to parse the XML you've provided so we
were just lucky it worked in some cases? Yep, that's right.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-25 09:28:54 +01:00
Michal Privoznik
0e69d97648 cpu: Format <cpu/> properly
Well, not that we are not formatting invalid XML, rather than not as
beautiful as we can:

  <cpu mode='host-passthrough'>
  </cpu>

If there are no children, let's use the singleton element.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-25 09:26:04 +01:00
Michal Privoznik
33912cc03e virCPUDefFormatBufFull: Use our general error handling pattern
Well, so far there are no variables to free, no cleanup work needed on
an error, so bare 'return -1;' after each error is just okay. But this
will change in a while.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-25 09:23:45 +01:00
Michal Privoznik
83c5467ee9 util: Introduce virBufferAddBuffer
This API joins the following two lines:

char *s = virBufferContentAndReset(buf1);
virBufferAdd(buf2, s, -1);

into one:

virBufferAddBuffer(buf2, buf1);

With one exception: there's no re-indentation applied to @buf1.
The idea is, that in general both can have different indentation
(like the test I'm adding proves)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-25 09:23:42 +01:00
Pavel Hrdina
efd30e2e1c qemu: fix memory leak while starting a guest
In commit cc41c648 I've re-factored qemuMonitorFindBalloonObjectPath, but
missed that there is a memory leak. The "nextpath" variable is
overwritten while looping in for cycle and we have to free it before next
cycle.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-24 16:38:50 +01:00
Michal Privoznik
39df9d2f12 network_conf: Forbid commas in DNS TXT
https://bugzilla.redhat.com/show_bug.cgi?id=1151942

While the restriction doesn't have origin in any RFC, it matters
to us while constructing the dnsmasq config file (or command line
previously). For better picture, this is how the corresponding
part of network XML look like:

  <dns>
    <forwarder addr='8.8.4.4'/>
    <txt name='example' value='example value'/>
  </dns>

And this is how the config file looks like then:

  server=8.8.4.4
  txt-record=example,example value

Now we can see why there can't be any commas in the TXT name.
They are used by dnsmasq to separate @name and @value.

Funny, we have it in the documentation, but the code (which was
pushed back in 2011) didn't reflect that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-24 10:07:47 +01:00
Stefan Zimmermann
8e6ee9f280 Rework s390 architecture checking
Making use of the ARCH_IS_S390 macro introduced with
e808357528

Signed-off-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2015-02-23 14:51:02 -05:00
Stefan Zimmermann
09ab9dcc85 Prevent default creation of usb controller on s390 and s390x
Since s390 does not support usb the default creation of a usb controller
for a domain should not occur.

Also adjust s390 test cases by removing usb device instances since
usb devices are no longer created by default for s390 the s390
test cases need to be adjusted.

Signed-off-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
2015-02-23 14:50:15 -05:00
Cole Robinson
f2f1e388e1 qemu: Fix AAVMF/OVMF #define names
The AAVMF and OVMF names were swapped. Reorder the one usage where it
matters so behavior doesn't change.
2015-02-21 14:44:46 -05:00
Marek Marczykowski
d0106d5828 libxl: support backend domain setting for disk and net devices
This implement handling of <backenddomain name=''/>  parameter introduced
in previous patch.

Works on Xen >= 4.3, because only there libxl supports setting backend
domain by name.  Specifying backend domain by ID or UUID is currently not
supported.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-20 14:50:24 -07:00
Marek Marczykowski
c374353ca0 conf: support backend domain name in disk and network devices
At least Xen supports backend drivers in another domain (aka "driver
domain"). This patch introduces an XML config option for specifying the
backend domain name for <disk> and <interface> devices.  E.g.

  <disk>
    <backenddomain name='diskvm'/>
    ...
  </disk>
  <interface type='bridge'>
    <backenddomain name='netvm'/>
    ...
  </interface>

In the future, same option will be needed for USB devices (hostdev
objects), but for now libxl doesn't have support for PVUSB.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-20 14:50:24 -07:00
Laine Stump
8f8e581a17 network: allow <pf> together with <interface>/<address> in network status
The function that parses the <forward> subelement of a network used to
fail/log an error if the network definition contained both a <pf>
element as well as at least one <interface> or <address> element. That
check was present because the configuration of a network should have
either one <pf>, one or more <interface>, or one or more <address>,
but never combinations of multiple kinds.

This caused a problem when libvirtd was restarted with a network
already active - when a network with a <pf> element is started, the
referenced PF (Physical Function of an SRIOV-capable network card) is
checked for VFs (Virtual Functions), and the <forward> is filled in
with a list of all VFs for that PF either in the form of their PCI
addresses (a list of <address>) or their netdev names (a list of
<interface>); the <pf> element is not removed though. When libvirtd is
restarted, it parses the network status and finds both the original
<pf> from the config, as well as the list of either <address> or
<interface>, fails the parse, and the network is not added to the
active list. This failure is often obscured because the network is
marked as autostart so libvirt immediately restarts it.

It seems odd to me that <interface> and <address> are stored in the
same array rather than keeping two separate arrays, and having
separate arrays would have made the check much simpler. However,
changing to use two separate arrays would have required changes in
more places, potentially creating more conflicts and (more
importantly) more possible regressions in the event of a backport, so
I chose to keep the existing data structure in order to localize the
change.

It appears that this problem has been in the code ever since support
for <pf> was added (0.9.10), but until commit
34cc3b2f10 (first in libvirt 1.2.4)
networks with interface pools were not properly marked as active on
restart anyway, so there is no point in backporting this patch any
further than that.
2015-02-20 15:06:30 -05:00
Peter Krempa
103707d4b7 qemu: caps: Add capability bit for the "pc-dimm" device
The pc-dimm device represents a RAM memory module.
2015-02-20 19:25:09 +01:00
Peter Krempa
e5c7864cfc conf: Hoist validation of memory size into the post parse callback
Later patches will need to access the full definition to do check the
memory size and thus the checking needs to be done after the whole
definition including devices is known.
2015-02-20 19:25:09 +01:00
Peter Krempa
b98596a717 conf: numa: Check ABI stability of NUMA configuration
Add helper to compare initial sizes of indivitual NUMA nodes and the map
of belonging vCPUs. Other configuration is not ABI.
2015-02-20 19:23:38 +01:00
Peter Krempa
e431c3c092 conf: ABI: Hugepage backing definition is not guest ABI
The backing of the vm's memory isn't influencing the guest ABI thus
shouldn't be checked.
2015-02-20 18:19:59 +01:00
Peter Krempa
181742d43f conf: Move all NUMA configuration to virDomainNuma
For historical reasons data regarding NUMA configuration were split
between the CPU definition and numatune. We cannot do anything about the
XML still being split, but we certainly can at least store the relevant
data in one place.

This patch moves the NUMA stuff to the right place.
2015-02-20 17:50:08 +01:00
Peter Krempa
b9ddb25822 conf: numa: Add setter/getter for NUMA node memory size
Add the helpers and refactor places where the value is accessed without
them.
2015-02-20 17:50:08 +01:00
Peter Krempa
7800d473f5 conf: numa: Add accessor to NUMA node's memory access mode 2015-02-20 17:50:08 +01:00
Peter Krempa
d9a779a36e conf: numa: Add accessor for the NUMA node cpu mask
Add virDomainNumaGetNodeCpumask() and refactor a few places that would
get the cpu mask without the helper.
2015-02-20 17:50:08 +01:00
Peter Krempa
be22d07315 conf: numa: Add helper to get guest NUMA node count and refactor users
Add an accessor so that a later refactor is simpler.
2015-02-20 17:50:07 +01:00
Peter Krempa
ba2183a331 qemu: command: Unify retrieval of NUMA cell count in qemuBuildNumaArgStr
The function uses the cell count in 6 places. Add a temp variable to
hold the count as it will greatly simplify the refactor.
2015-02-20 17:50:07 +01:00
Peter Krempa
b83543c563 conf: numa: Don't pass double pointer to virDomainNumatuneParseXML
virDomainNumatuneParseXML now doesn't allocate the def->numa object any
longer so we don't need to pass a double pointer.
2015-02-20 17:50:07 +01:00
Peter Krempa
fa9930720b numa: conf: Tweak parameters of virDomainNumatuneSet
As virDomainNumatuneSet now doesn't allocate the virDomainNuma object
any longer it's not necessary to pass the pointer to a pointer to store
the object as it will not change any longer.

While touching the parameter definitions I've also changed the name of
the parameter to "numa".
2015-02-20 17:50:07 +01:00
Peter Krempa
21008c013c conf: numa: Always allocate the NUMA config
Since our formatter now handles well if the config is allocated and not
filled we can safely always-allocate the NUMA config and remove the
ad-hoc allocation code.

This will help in later patches as the parser will be refactored to just
fill the data.
2015-02-20 17:48:48 +01:00
Peter Krempa
c03411199e conf: Allocate domain definition with the new helper
Use the virDomainDefNew() helper to allocate the definition instead of
doing it via VIR_ALLOC.
2015-02-20 17:43:05 +01:00
Peter Krempa
61e43ce9df conf: Separate helper for creating domain objects
Move the existing virDomainDefNew to virDomainDefNewFull as it's setting
a few things in the conf and re-introduce virDomainDefNew as a function
without parameters for common use.
2015-02-20 17:43:05 +01:00
Peter Krempa
121cde4726 conf: numa: Format <numatune> XML only if necessary
Do a content-aware check if formatting of the <numatune> element is
necessary. Later on the def->numa structure will be always present so we
cannot decide only on the basis whether it's allocated.
2015-02-20 17:43:04 +01:00
Peter Krempa
638e3d270f conf: numa: Refactor logic in virDomainNumatuneParseXML
Shuffling around the logic will allow to simplify the code quite a bit.
As an additional bonus the change in the logic now reports an error if
automatic placement is selected and individual placement is configured.
2015-02-20 17:43:04 +01:00
Peter Krempa
67bd807c4d conf: numa: Reformat virDomainNumatuneParseXML
Collapse few of the conditions so that the program flow is more clear.
2015-02-20 17:43:04 +01:00
Peter Krempa
60a2ce4962 conf: numa: Improve error message in case a numa node doesn't have cpus
Currently the code would exit without reporting an error as
virBitmapParse reports one only if it fails to parse the bitmap, whereas
the code was jumping to the error label even in case 0 cpus were
correctly parsed in the map.
2015-02-20 17:43:04 +01:00
Peter Krempa
6b6166329f conf: numa: Recalculate rather than remember total NUMA cpu count
It's easier to recalculate the number in the one place it's used as
having a separate variable to track it. It will also help with moving
the NUMA code to the separate module.
2015-02-20 17:43:04 +01:00
Peter Krempa
a3673b225d conf: Move enum virMemAccess to the NUMA code and rename it
Name it virNumaMemAccess and add it to conf/numa_conf.[ch]

Note that to avoid a circular dependency the type of the NUMA cell
memAccess variable was changed to int. It will be turned back later
after the circular dependency will not exist.
2015-02-20 17:43:04 +01:00
Peter Krempa
6bc80fa86d conf: numa: Rename virDomainNumatune to virDomainNuma
The structure will gradually become the only place for NUMA related
config, thus rename it appropriately.
2015-02-20 17:43:04 +01:00
Peter Krempa
456268d46b conf: Move NUMA cell formatter to numa_conf
Move the code that formats the /domain/cpu/numa element to numa_conf as
it belongs there.
2015-02-20 17:43:04 +01:00
Peter Krempa
2562141f19 conf: numa: Don't duplicate NUMA cell cpumask
The mask was stored both as a bitmap and as a string. The string is used
for XML output only. Remove the string, as it can be reconstructed from
the bitmap.

The test change is necessary as the bitmap formatter doesn't "optimize"
using the '^' operator.
2015-02-20 17:43:03 +01:00
Peter Krempa
34a1dd73b8 conf: Refactor virDomainNumaDefCPUParseXML
Rewrite the function to save a few local variables and reorder the code
to make more sense.

Additionally the ncells_max member of the virCPUDef structure is used
only for tracking allocation when parsing the numa definition, which can
be avoided by switching to VIR_ALLOC_N as the array is not resized
after initial allocation.
2015-02-20 17:43:03 +01:00
Peter Krempa
5bba61fd58 conf: Move NUMA cell parsing code from cpu conf to numa conf
For weird historical reasons NUMA cells are added as a subelement of
<cpu> while the actual configuration is done in <numatune>.

This patch splits out the cell parser code from cpu config to NUMA
config. Note that the changes to the code are minimal just to make it
work and the function will be refactored in the next patch.
2015-02-20 17:43:03 +01:00
Peter Krempa
fcee64e73c conf: Move numatune_conf to numa_conf
For a while now there are two places that gather information about NUMA
related guest configuration. While the XML can't be changed we can at
least store the data in one place in the definition.

Rename the numatune_conf.[ch] files to numa_conf as later patches will
move the rest of the definitions from the cpu definition to this one.
2015-02-20 17:43:03 +01:00
Michal Privoznik
af20423264 virQEMUCapsCacheLookupCopy: Filter qemuCaps based on machineType
Not all machine types support all devices, device properties, backends,
etc. So until we create a matrix of [machineType, qemuCaps], lets just
filter out some capabilities before we return them to the consumer
(which is going to make decisions based on them straight away).
Currently, as qemu is unable to tell which capabilities are (not)
enabled for given machine types, it's us who has to hardcode the matrix.
One day maybe the hardcoding will go away and we can create the matrix
dynamically on the fly based on a few monitor calls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-20 13:28:04 +01:00
Michal Privoznik
37cf163ab2 virQEMUCapsCacheLookupCopy: Pass machine type
It will come handy in the near future when we will filter some
capabilities based on it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-20 13:27:59 +01:00
Mikhail Feoktistov
675fa6b360 parallels: Set the first HDD from XML as bootable
1. Delete all boot devices for VM instance
2. Find the first HDD from XML and set it as bootable

Now we support only one boot device and it should be HDD.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-19 16:32:49 +01:00
Mikhail Feoktistov
6783cf63b0 parallels: Use IS_CT() macro instead of STREQ("exe") 2015-02-19 16:32:49 +01:00
Mikhail Feoktistov
0268eabd7d parallels: code aligment 2015-02-19 16:32:49 +01:00
Jiri Denemark
bc6e206322 Search for schemas and cpu_map.xml in source tree
Not all files we want to find using virFileFindResource{,Full} are
generated when libvirt is built, some of them (such as RNG schemas) are
distributed with sources. The current API was not able to find source
files if libvirt was built in VPATH.

Both RNG schemas and cpu_map.xml are distributed in source tarball.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-02-19 15:25:04 +01:00
Michal Privoznik
80c5f10e86 qemuMigrationDriveMirror: Listen to events
https://bugzilla.redhat.com/show_bug.cgi?id=1179678

When migrating with storage, libvirt iterates over domain disks and
instruct qemu to migrate the ones we are interested in (shared, RO and
source-less disks are skipped). The disks are migrated in series. No
new disk is transferred until the previous one hasn't been quiesced.
This is checked on the qemu monitor via 'query-jobs' command. If the
disk has been quiesced, it practically went from copying its content
to mirroring state, where all disk writes are mirrored to the other
side of migration too. Having said that, there's one inherent error in
the design. The monitor command we use reports only active jobs. So if
the job fails for whatever reason, we will not see it anymore in the
command output. And this can happen fairly simply: just try to migrate
a domain with storage. If the storage migration fails (e.g. due to
ENOSPC on the destination) we resume the host on the destination and
let it run on partly copied disk.

The proper fix is what even the comment in the code says: listen for
qemu events instead of polling. If storage migration changes state an
event is emitted and we can act accordingly: either consider disk
copied and continue the process, or consider disk mangled and abort
the migration.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-19 14:12:38 +01:00
Michal Privoznik
76c61cdca2 qemuProcessHandleBlockJob: Take status into account
Upon BLOCK_JOB_COMPLETED event delivery, we check if the job has
completed (in qemuMonitorJSONHandleBlockJobImpl()). For better image,
the event looks something like this:

"timestamp": {"seconds": 1423582694, "microseconds": 372666}, "event":
"BLOCK_JOB_COMPLETED", "data": {"device": "drive-virtio-disk0", "len":
8412790784, "offset": 409993216, "speed": 8796093022207, "type":
"mirror", "error": "No space left on device"}}

If "len" does not equal "offset" it's considered an error, and we can
clearly see "error" field filled in. However, later in the event
processing this case was handled no differently to case of job being
aborted via separate API. It's time that we start differentiate these
two because of the future work.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-19 14:12:38 +01:00
Michal Privoznik
c37943a068 qemuProcessHandleBlockJob: Set disk->mirrorState more often
Currently, upon BLOCK_JOB_* event, disk->mirrorState is not updated
each time. The callback code handling the events checks if a blockjob
was started via our public APIs prior to setting the mirrorState.
However, some block jobs may be started internally (e.g. during
storage migration), in which case we don't bother with setting
disk->mirror (there's nothing we can set it to anyway), or other
fields. But it will come handy if we update the mirrorState in these
cases too. The event wasn't delivered just for fun - we've started the
job after all.

So, in this commit, the mirrorState is set to whatever job status
we've obtained. Of course, there are some actions on some statuses
that we want to perform. But instead of if {} else if {} else {} ...
enumeration, let's move to switch().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-19 14:12:38 +01:00
Peter Krempa
0df2f0404f qemu: Exit job on error path of qemuDomainSetVcpusFlags()
Commit e105dc9814 moved some code but
didn't adjust the jump labels so that the job would be terminated.
2015-02-18 18:17:54 +01:00
Pavel Hrdina
77a9dc0b8d qemu_cgroup: initialize mem_mask to NULL
If 'virNumaGetHostNodeset()' fails then the error path will try to free
uninitialized pointer mem_mask. Introduced by commit af2a1f058.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-17 14:22:50 +01:00
Prerna Saxena
5e4f49ab8a PowerPC : Forbid NULL CPU model with 'host-model' mode.
PowerPC : Forbid NULL CPU model with 'host-model' mode in qemu command line.

This ensures that an XML such as following:
...
  <cpu mode='host-model'>
    <model fallback='allow'/>
  </cpu>
...

will not generate a '-cpu host,compat=(null)' command line with qemu-system-ppc64.

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
2015-02-17 12:20:40 +01:00
Prerna Saxena
bdbe723fcd PowerPC : Make 'qemu-system-ppc64' the default emulator on ppc64[le].
PowerPC : Explicitly associate 'qemu-system-ppc64' as the
 default emulator for all 64-bit PowerPC guests ( both Big & Little Endian )

Signed-off-by: Prerna Saxena <prerna@linux.vnet.ibm.com>
2015-02-17 12:20:40 +01:00
Luyao Huang
337265bb52 qemu: fix vm deadlock when try to use numatune in session mode
https://bugzilla.redhat.com/show_bug.cgi?id=1126762

Commit 43b67f introduced a deadlock issue when we use numatune
to change numa settings to a vm in session mode.

Jump to endjob instead of jump to cleanup.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-17 11:08:00 +01:00
Michal Privoznik
7832fac847 qemuBuildMemoryBackendStr: Report backend requirement more appropriately
So, when building the '-numa' command line, the
qemuBuildMemoryBackendStr() function does quite a lot of checks to
chose the best backend, or to check if one is in fact needed. However,
it returned that backend is needed even for this little fella:

  <numatune>
    <memory mode="strict" nodeset="0,2"/>
  </numatune>

This can be guaranteed via CGroups entirely, there's no need to use
memory-backend-ram to let qemu know where to get memory from. Well, as
long as there's no <memnode/> element, which explicitly requires the
backend. Long story short, we wouldn't have to care, as qemu works
either way. However, the problem is migration (as always). Previously,
libvirt would have started qemu with:

  -numa node,memory=X

in this case and restricted memory placement in CGroups. Today, libvirt
creates more complicated command line:

  -object memory-backend-ram,id=ram-node0,size=X
  -numa node,memdev=ram-node0

Again, one wouldn't find anything wrong with these two approaches.
Both work just fine. Unless you try to migrated from the older libvirt
into the newer one. These two approaches are, unfortunately, not
compatible. My suggestion is, in order to allow users to migrate, lets
use the older approach for as long as the newer one is not needed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-17 09:07:09 +01:00
Michal Privoznik
65c0fd9dfc numatune_conf: Expose virDomainNumatuneNodeSpecified
This function is going to be needed in the near future.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-17 08:38:19 +01:00
John Ferlan
4438646c0d libxl: Resolve Coverity CHECKED_RETURN
Periodically my Coverity scan will return a checked_return failure
for libxlDomainShutdownThread call to libxlDomainStart. Followed the
libxlAutostartDomain example in order to check the status, emit a
message, and continue on.
2015-02-14 07:31:41 -05:00
John Ferlan
5a36cdbcce security: Resolve Coverity RESOURCE_LEAK
Introduced by commit id 'c3d9d3bb' - return from virSecurityManagerCheckModel
wasn't VIR_FREE()'ing the virSecurityManagerGetNested allocated memory.
2015-02-14 07:31:36 -05:00
Luyao Huang
8e6492f298 lxc: Fix container cleanup for LXCProcessStart
Jumping to the cleanup label prior to starting the container failed to
properly clean everything up that is handled by the virLXCProcessCleanup
which is called if virLXCProcessStop is called on failure after the
container properly starts. Most importantly is prior to this patch none
of the stop/release hooks, host device reattachment, and network cleanup
(that is reverse of virLXCProcessSetupInterfaces).

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-13 13:44:52 -05:00
John Ferlan
2b8e018ad8 lxc: Modify/add some debug messages
Modify the VIR_DEBUG message in virLXCProcessCleanup to make it clearer
about the path.  Also add some more VIR_DEBUG messages in virLXCProcessStart
in order to help debug error flow.
2015-02-13 13:44:52 -05:00
Luyao Huang
72129907c1 lxc: Move console checks in LXCProcessStart
https://bugzilla.redhat.com/show_bug.cgi?id=1176503

Move the two console checks - one for zero nconsoles present and the
other for an invalid console type to earlier in the processing rather than
getting after performing some setup that has to be undone for what amounts
to an invalid configuration.

This resolves the above bug since it's not not possible to have changed
the security labels when we cause the configuration check failure.
2015-02-13 13:44:52 -05:00
Erik Skultety
aee3b77c33 security: Refactor virSecurityManagerGenLabel
if (mgr == NULL || mgr->drv == NULL)
    return ret;

This check isn't really necessary, security manager cannot be a NULL
pointer as it is either selinux (by default) or 'none', if no other driver is
set in the config. Even with no config file driver name yields 'none'.

The other hunk checks for domain's security model validity, but we should
also check devices' security model as well, therefore this hunk is moved into
a separate function which is called by virSecurityManagerCheckAllLabel that
checks both the domain's security model and devices' security model.

https://bugzilla.redhat.com/show_bug.cgi?id=1165485
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-13 14:49:23 +01:00
Erik Skultety
c3d9d3bbc9 security: introduce virSecurityManagerCheckAllLabel function
We do have a check for valid per-domain security model, however we still
do permit an invalid security model for a domain's device (those which
are specified with <source> element).
This patch introduces a new function virSecurityManagerCheckAllLabel
which compares user specified security model against currently
registered security drivers. That being said, it also permits 'none'
being specified as a device security model.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1165485
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-13 14:37:54 +01:00
Ján Tomko
6ba5d1afec Wire up mrg_rxbuf option for qemu
<interface ...>
  ...
  <model type='virtio'/>
  <driver ...>
    <host mrg_rxbuf='off'/>
  </driver>
</interface>

will result in:
-device virtio-net-pci,mrg_rxbuf=off,...

https://bugzilla.redhat.com/show_bug.cgi?id=1186886
2015-02-13 12:31:38 +01:00
Ján Tomko
6067182b0d Add mrg_rxbuf option to virtio interfaces
Add an XML attribute to allow disabling merge of rx buffers
on the host:
<interface ...>
  ...
  <model type='virtio'/>
  <driver ...>
    <host mrg_rxbuf='off'/>
  </driver>
</interface>

https://bugzilla.redhat.com/show_bug.cgi?id=1186886
2015-02-13 12:31:38 +01:00
Michal Privoznik
9993736f45 libvirt_private.syms: Expose virDomainNetTypeFromString
The enum converters are defined in the domain_conf.h (so
accessible widely across the code), but on the symbol layer, only
virDomainNetTypeToString was exposed. However, FromString variant
is going to be needed shortly.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-13 09:33:12 +01:00
Pavel Hrdina
94cc577807 virprocess: fix MinGW build and RHEL-5 build
Commit b6a2828e introduced new functions to set process scheduler. There
is a small typo in ELSE path for systems where scheduler is not
available.

Also some of the definitions were introduced later in kernel. For
example RHEL-5 is running on kernel 2.6.18, but SCHED_IDLE was introduces
in 2.6.23 [1] and SCHED_BATCH in 2.6.16 [1]. We should not count only on
existence of function sched_setscheduler(), we must also check for
existence of used macros as they might not be defined.

[1] see 'man 7 sched'

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-12 18:00:21 +01:00
Daniel P. Berrange
aa9aa6a975 Allow shrinking of file based volumes
While the main storage driver code allows the flag
VIR_STORAGE_VOL_RESIZE_SHRINK to be set, none of the backend
drivers are supporting it. At the very least this can work
for plain file based volumes since we just ftruncate() them
to the new size. It does not work with qcow2 volumes, but we
can arguably delegate to qemu-img for error reporting for that
instead of second guessing this for ourselves:

$ virsh vol-resize --shrink /home/berrange/VirtualMachines/demo.qcow2 2G
error: Failed to change size of volume 'demo.qcow2' to 2G

error: internal error: Child process (/usr/bin/qemu-img resize /home/berrange/VirtualMachines/demo.qcow2 2147483648) unexpected exit status 1: qemu-img: qcow2 doesn't support shrinking images yet
qemu-img: This image does not support resize

See also https://bugzilla.redhat.com/show_bug.cgi?id=1021802
2015-02-12 11:11:52 +00:00
Daniel P. Berrange
9358b63a0d qemu: do upfront check for vcpupids being null when querying pinning
The qemuDomainHelperGetVcpus attempted to report an error when the
vcpupids info was NULL. Unfortunately earlier code would clamp the
value of 'maxinfo' to 0 when nvcpupids was 0, so the error reporting
would end up being skipped.

This lead to 'virsh vcpuinfo <dom>' just returning an empty list
instead of giving the user a clear error.
2015-02-12 10:02:50 +00:00
Daniel P. Berrange
a103bb105c qemu: fix setting of VM CPU affinity with TCG
If a previous commit I fixed the incorrect handling of vcpu pids
for TCG mode QEMU:

  commit b07f3d821d
  Author: Daniel P. Berrange <berrange@redhat.com>
  Date:   Thu Dec 18 16:34:39 2014 +0000

    Don't setup fake CPU pids for old QEMU

    The code assumes that def->vcpus == nvcpupids, so when we setup
    fake CPU pids for old QEMU with nvcpupids == 1, we cause the
    later code to read off the end of the array. This has fun results
    like sche_setaffinity(0, ...) which changes libvirtd's own CPU
    affinity, or even better sched_setaffinity($RANDOM, ...) which
    changes the affinity of a random OS process.

The intent was that this would merely disable the ability to set
per-vCPU affinity. It should still have been possible to set VM
level host CPU affinity.

Unfortunately, when you set  <vcpu cpuset='0-1'>4</vcpu>, the XML
parser will internally take this & initialize an entry in the
def->cputune.vcpupin array for every VCPU. IOW this is implicitly
being treated as

  <cputune>
    <vcpupin cpuset='0-1' vcpu='0'/>
    <vcpupin cpuset='0-1' vcpu='1'/>
    <vcpupin cpuset='0-1' vcpu='2'/>
    <vcpupin cpuset='0-1' vcpu='3'/>
  </cputune>

Even more fun, the faked cputune elements are hidden from view when
querying the live XML, because their cpuset mask is the same as the
VM default cpumask.

The upshot was that it was impossible to set VM level CPU affinity.

To fix this we must update qemuProcessSetVcpuAffinities so that it
only reports a fatal error if the per-VCPU cpu mask is different
from the VM level cpu mask.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-02-12 10:02:50 +00:00
Marek Marczykowski-Górecki
98780c6be6 libxl: disable VNC and SDL until explicitly enabled
When initializing a libxl_domain_build_info struct with
libxl_domain_build_info_init(), VNC is enabled by default.  As a
result, VMs configured with no graphics still have VNC enabled.
This behavior is a regression wrt to the legacy Xen driver.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-11 20:24:20 -07:00
Marek Marczykowski-Górecki
8703ee58bd libxl: pass ipaddr to libxl toolstack
Do not silently ignore its value. LibXL support only one address, so
refuse multiple IPs.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-11 16:46:36 -07:00
Martin Kletzander
104ba5966a qemu: Add support for setting vCPU and I/O thread scheduler setting
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1178986

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-02-11 17:30:07 +01:00
Martin Kletzander
8680ea9749 docs, schema, conf: Add support for setting scheduler parameters of guest threads
In order for QEMU vCPU (and other) threads to run with RT scheduler,
libvirt needs to take care of that so QEMU doesn't have to run privileged.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-02-11 17:30:06 +01:00
Martin Kletzander
b6a2828e53 util: Add virProcessSetScheduler() function for scheduler settings
This function uses sched_setscheduler() function so it works with
processes and threads as well (even threads not created by us, which is
what we'll need in the future).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-02-11 17:30:06 +01:00
Laine Stump
89d26890ee domain: include portgroup in interface status xml
Prior to commit 7d5bf48474 (first appearing in libvirt 1.2.2), the
status XML of a domain's interface was missing a lot of important
information; mainly it just output the config of the interface, plus
the name of the tap device and qemu device alias. Commit 7d5bf48474
changed the status XML to include many important bits of information
that were required to make network "hook" scripts useful - bandwidth
information, vlan tag, the name of the bridge (or physical device in
the case of macvtap) that the tap/macvtap device was attached to - the
commit log for 7d5bf48474 has a very detailed explanation of the
change. For quick reference - in the example given there, prior to the
change, status XML looked like figure [C]:

      <interface type='network'>
        <source network='testnet' portgroup='admin'/>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

and after the change, it looked like figure [E]:

      <interface type='direct'>
        <source dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

You'll notice that bandwidth info, physdev, and macvtap mode have been
added, but the network and portgroup names are now missing - I didn't
think that this information was of any use once the needed
bandwidth/vlan/etc config had been pulled from the network/portgroup.

I was wrong.

A few months after that change a user on IRC asked what happened to
portgroup in the status XML and described how he used it (more or less
as a tag to decide what external information to use in a hook script
that was run at startup/migration time - see
http://wiki.libvirt.org/page/OVS_and_PVLANS ). At that time I planned
to make a patch to re-add portgroup, but life intervened as that was
just prior to a transatlantic move involving several weeks of
"vacation". During this time I somehow forgot to make the patch, and
also mistakenly remembered that I *had* made it.

Subsequent to this, as a part of mprivozn's work to add support for
network-specific hooks, I did re-add the output of the network name in
status XML, but once again completely forgot about portgroup. This was
in commit a3609121 (first appearing in libvirt 1.2.11). This made the
status XML from the above example look like this:

      <interface type='direct'>
        <source network='testnet' dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

*This* patch just adds the portgroup back to the status XML, so the
 same example interface will look like this:

      <interface type='direct'>
        <source network='testnet' portgroup='admin'
                dev='p4p1_0' mode='bridge'/>
        <bandwidth>
            <inbound average='1000' peak='5000' burst='1024'/>
            <outbound average='128' peak='256' burst='256'/>
        </bandwidth>
        <target dev='macvtap0'/>
        <alias name='net0'/>
        <address type='pci' domain='0x0000' bus='0x00'
                 slot='0x03' function='0x0'/>
      </interface>

The result is that the status XML now contains all information about
how the interface is setup (bandwidth, physical device, tap device,
etc), in addition to pointers to its origin (the network and
portgroup).
2015-02-11 11:16:16 -05:00
Laine Stump
6d1194ffc0 domain: avoid potential memory leak in virDomainGraphicsListenSet*()
virDomainGraphicsListenSetAddress() and
virDomainGraphicsListenSetNetwork() both set their respective char* to
NULL directly when asked to set it to NULL, which is okay as long as
it's already set to NULL. If these functions are ever called to clear
a listen object that has a valid string in address or network, it will
end up leaking the old value. Currently that doesn't happen, so this
is just a preemptive strike.
2015-02-11 11:05:35 -05:00
Laine Stump
699299419b domain: backfill listen address to parent <graphics> listen attribute
Prior to 0.9.4, libvirt only supported a single listen, and it had to
be an IP address:

   <graphics listen='1.2.3.4' ..../>

Starting with 0.9.4, a graphics element could have a <listen>
subelement (actually the grammar supports multiples, but all of the
drivers only support a single <listen> per <graphics>), and that
listen element can be of type='address' or type='network'. For
type='address', <listen> also has an attribute called 'address' which
contains the IP address for listening:

    <graphics ....>
      <listen type='address' address='1.2.3.4' .../>
    </graphics>

type can also be "network", and in that case listen will have a
"network" attribute which will contain the name of a libvirt
network:

    <graphics ....>
      <listen type='network' network='testnet' .../>
    </graphics>

At domain start (or migrate) time, libvirt will attempt to
find an IP address associated with that network (e.g. the IP address
of the bridge device used by the network, or the physical device
listed in <forward dev='physdev'/>) and fill in that address in the
status XML:

    <graphics ....>
      <listen type='network' network='testnet' address='1.2.3.4' .../>
    </graphics>

In the case that a <graphics> element has a <listen> subelement of
type='address', that listen subelement's "address" attribute is
backfilled into the parent graphics element's "listen" *attribute* for
backward compatibility (so that a management application unaware of
the separate <listen> element can still learn the listen
address). This backfill should be done with the IP learned from
type='network' as well, and that's what this patch does:

    <graphics listen='1.2.3.4' ....>
      <listen type='network' network='testnet' address='1.2.3.4' .../>
    </graphics>

This is a continuation of the fix for:

   https://bugzilla.redhat.com/show_bug.cgi?id=1191016
2015-02-11 11:04:25 -05:00
John Ferlan
92f09dab50 qemu: qemuOpenFileAs - set flag VIR_FILE_OPEN_FORCE_MODE
In the event we're falling into the code that tries to create the file
in a forked environment (VIR_FILE_OPEN_FORK) we pass different mode bits,
but those are never set because the virFileOpenForceOwnerMode has a check
if the OPEN_FORCE_MODE bit is set before attempting to change the mode.

Since this is a special case it seems reasonable to set u+rw,g+rw,o
2015-02-11 07:29:29 -05:00
John Ferlan
92d9114eac virfile: Adjust error path for virFileOpenForked
Rather than have a dummy waitpid loop and return of the failure status
from recvfd, adjust the logic to save the recvfd error & fd and then
in priority order:

- if waitpid failed, use that errno value
- waitpid succeeded, but if the child exited abnormally, report failure
(use EACCES to report as return failure, since either EACCES or EPERM is
what caused us to fall into the fork+setuid path)
- waitpid succeeded, but if the child reported non-zero status, report
failure (use the errno value that the child encoded into exit status)
- waitpid succeeded, but if recvfd failed, report recvfd_errno
- waitpid and recvfd succeeded, use the fd

NOTE: Original logic to retry the open and force owner mode was
"documented" as only being attempted if we had already tried opening
with the fork+setuid, but checked flags vs. VIR_FILE_OPEN_NOFORK which
is counter to how we would get to that point. So that code was removed.
2015-02-11 07:28:58 -05:00
Luyao Huang
45853b5289 qemu: fix crash when migrateuri has no scheme
https://bugzilla.redhat.com/show_bug.cgi?id=1191355

When we attempt to migrate a vm with a migrateuri that has no scheme:

 # virsh migrate test4 --live qemu+ssh://lhuang/system --migrateuri 127.0.0.1

target libvirtd will crash because uri->scheme is NULL in
qemuMigrationPrepareDirect on this line:

     if (STRNEQ(uri->scheme, "tcp") &&

Add a value check before this line. Also fix a bug like this in
doNativeMigrate, that could only happen when destination libvirtd
returned an incorrect URI.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-11 13:20:30 +01:00
Zhang Bo
2d27dcb0e9 conf: Fix libvirtd crash and memory leak caused by virDomainVcpuPinDel()
The function virDomainVcpuPinDel() used vcpupin_list to stand for
def->cputune.vcpupin, which made the codes more readable.
However, in this function, it will realloc vcpupin_list later.
As the definition of realloc(), it may free vcpupin_list and then
points it to a new-realloced address, but def->cputune.vcpupin doesn't
point to the new address(it's freed however).
Thus,
1) When we refer to the def->cputune.vcpupin afterwards, which was freed
by realloc(), an INVALID READ occurs, and libvirtd may crash.
2) As no one will use vcpupin_list any more, and no one frees it(it's just
alloced by realloc()), memory leak occurs.

Part of the valgrind logs are shown as below:
==1837== Thread 15:
==1837== Invalid read of size 8
==1837==    at 0x5367337: virDomainDefFormatInternal (domain_conf.c:18392)
        which is : virBufferAsprintf(buf, "<vcpupin vcpu='%u' ",
                          def->cputune.vcpupin[i]->vcpuid);
==1837==    by 0x536966C: virDomainObjFormat (domain_conf.c:18970)
==1837==    by 0x5369743: virDomainSaveStatus (domain_conf.c:19166)
==1837==    by 0x117B26DC: qemuDomainPinVcpuFlags (qemu_driver.c:4586)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)
==1837==    by 0x171E6E: virNetServerHandleJob (virnetserver.c:193)
==1837==    by 0x5318E78: virThreadPoolWorker (virthreadpool.c:145)
==1837==  Address 0x12ea2870 is 0 bytes inside a block of size 16 free'd
==1837==    at 0x4C291AC: realloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==1837==    by 0x52A3D14: virReallocN (viralloc.c:245)
==1837==    by 0x52A3DFB: virShrinkN (viralloc.c:372)
==1837==    by 0x52A3F57: virDeleteElementsN (viralloc.c:503)
==1837==    by 0x533939E: virDomainVcpuPinDel (domain_conf.c:15405)  //doReset为true时才会进到。
==1837==    by 0x117B2642: qemuDomainPinVcpuFlags (qemu_driver.c:4573)
==1837==    by 0x53EA313: virDomainPinVcpuFlags (libvirt.c:9803)
==1837==    by 0x14CB7D: remoteDispatchDomainPinVcpuFlags (remote_dispatch.h:6762)
==1837==    by 0x14CC81: remoteDispatchDomainPinVcpuFlagsHelper (remote_dispatch.h:6740)
==1837==    by 0x5464C30: virNetServerProgramDispatchCall (virnetserverprogram.c:437)
==1837==    by 0x546507A: virNetServerProgramDispatch (virnetserverprogram.c:307)
==1837==    by 0x171B83: virNetServerProcessMsg (virnetserver.c:172)

Steps to reproduce the problem:
1) use virDomainPinVcpuFlags() to pin a guest's vcpu to all the pcpus
of the host.

This patch uses def->cputune.vcpupin instead of vcpupin_list to do the
realloc() job, to avoid invalid read or memory leaking.

Signed-off-by: Zhang Bo <oscar.zhangbo@huawei.com>
Signed-off-by: Yue Wenyuan <yuewenyuan@huawei.com@huawei.com>
2015-02-11 10:49:39 +01:00
Erik Skultety
357f0072ca conf: forbid seclabel duplicates for domain devices
Parser checks for per-domain seclabel duplicates, so it would be nice if
it checked for per-device seclabel duplicates the same way

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1165485
2015-02-11 09:45:22 +01:00
Ján Tomko
a7c9c7a6ab Fix qemu job handling in SetSchedulerParameters
Commit c5ee5cf added a job to SetSchedulerParameters, but
forgot to change one label in the SCHED_RANGE_CHECK macro.
2015-02-10 14:36:03 +01:00
Luyao Huang
862473fa12 qemu: Implement random number generator hotunplug
Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:23 +01:00
Luyao Huang
980b265d08 qemu: Implement random number generator hotplug
Export the required helpers and add backend code to hotplug RNG devices.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:22 +01:00
Peter Krempa
fe6acfbd0e qemu: Implement random number generator cold (un)plug
Add support for using the attach/detach device APIs on the inactive
configuration to add RNG devices.
2015-02-10 13:05:22 +01:00
Luyao Huang
37b620059b conf: Add helpers to insert/remove/find RNG devices in domain def
The helpers will be useful when implementing hotplug and coldplug of
random number generator devices.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:22 +01:00
Luyao Huang
ad3e99e21b audit: export virDomainAuditRNG
Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-10 13:05:22 +01:00
Peter Krempa
25e2d89788 qemu: command: Refactor creation of RNG device commandline
As the RNG device is using an -object as backend refactor the code to
use the JSON to commandline generator so that we can reuse the code
later in hotplug.
2015-02-10 13:05:22 +01:00
Peter Krempa
b9f2d781d9 qemu: command: Break some very long lines in qemuBuildRNGDevStr() 2015-02-10 13:05:22 +01:00
Peter Krempa
d7ec244f6e qemu: command: Shuffle around formatting of alias for RNG device backend
Move the alias name right after the object type for rng-egd backend so
that we can later use the JSON to commandline generator to create the
command line.
2015-02-10 13:05:22 +01:00
Luyao Huang
98e982b455 qemu: command: Make RNG backend device IDs unique
Libvirt didn't prefix the random number generator backend object alias
with any string thus the device alias and object alias were identical.

To avoid possible problems, rename the alias for the backend object and
tweak tests to comply with the change.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:22 +01:00
Luyao Huang
58a4eee81a qemu: refactor qemuBuildRNGDeviceArgs to allow reuse in RNG hotplug
Rename qemuBuildRNGDeviceArgs to qemuBuildRNGDevStr and change the
return type so that it can be reused in the device hotplug code later.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:22 +01:00
Luyao Huang
3921d13581 qemu: Add helper to assign RNG device aliases
This function is used to assign an alias for a RNG device. It will be
later reused when hotplugging RNGs.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2015-02-10 13:05:22 +01:00
Peter Krempa
c88b323bf5 conf: Introduce helper to find duplicate device address
When adding devices to the definition it's useful to check whether the
devices don't reside on a conflicting address. This patch adds a helper
that iterates all device info and compares the addresses with the given
info.
2015-02-10 13:05:22 +01:00
Martin Kletzander
3f9f4aa84f conf: disallow invalid values for video attributes
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1190956

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-02-10 09:05:36 +01:00
Erik Skultety
8b8a7b4e97 conf: fix a minor typo 2015-02-09 11:02:18 +01:00
Cédric Bosdonnat
88a1b54208 Clear dynamic seclabels on LXCProcessStart failure
commit a58e1cb4 didn't fix the bug if the security_default_confined is
not set to 1. We now clean up even if there is no seclabel defined or
the default one.
2015-02-09 10:29:00 +01:00
Laine Stump
2aa7ce6334 network: don't allow multiple portgroups with the same name in a network
When defining and creating networks, we have been checking to make
sure there is only a single "default" portgroup, but haven't verified
that no two portgroups have the same name. We *do* check for multiple
definitions when updating the portgroups in an existing network
though.

This patch adds a check to networkValidate(), which is called when a
network is defined or created, to disallow duplicate names. It would
actually make sense to do this in the network XML parser (since it's
not really "something that might make sense but isn't supported by
this driver", but is instead "something that should never be
allowed"), but doing that carries the danger of causing errors when
rereading the config of existing networks when libvirtd is restarted
after an upgrade, and that would result in networks disappearing from
libvirt's list. (I'm thinking I should change the error to "XML_ERROR"
instead of "UNSUPPORTED", even though that's not the type of error
that networkValidate is intended for)

This resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1115858
2015-02-06 10:37:54 -05:00
Ján Tomko
8e724e9f3e Error out when custom tap device path makes no sense
It is only usable for NETWORK and BRIDGE type interfaces.
Error out when trying to start a domain where the custom
tap device path is specified for interfaces of other types,
or when the daemon is not privileged.

Note that this cannot be checked at definition time, because
the comparison is against actual type.

https://bugzilla.redhat.com/show_bug.cgi?id=1147195
2015-02-06 12:52:50 +01:00
Ján Tomko
84f741812f Only parse custom vhost path for virtio interfaces
It is only supported for virtio adapters.
Silently drop it if it was specified for other models,
as is done for other virtio attributes.

Also mention this in the documentation.

https://bugzilla.redhat.com/show_bug.cgi?id=1147195
2015-02-06 12:52:50 +01:00
Ján Tomko
481881f50a Trivially support DomainHasManagedSaveImage
Return 0 instead of ERR_NO_SUPPORT in each driver
where we don't support managed save or -1 if
the domain does not exist.

This avoids spamming daemon logs when 'virsh dominfo' is run.

https://bugzilla.redhat.com/show_bug.cgi?id=1095637
2015-02-06 12:52:50 +01:00
Daniel P. Berrange
95fd6a91c6 qemu: include libvirt & QEMU versions in QEMU log files
It is often helpful to know which version of libvirt and QEMU
was present when a guest was first launched. Ensure this info
is written into the QEMU log file for each guest.
2015-02-06 10:22:07 +00:00
Marek Marczykowski-Górecki
490be8c724 libxl: update dom->id in libxlDomainCreateWithFlags
Otherwise domainCreateWithFlags via remote returns -1 as domid.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
2015-02-05 13:58:47 -07:00
John Ferlan
f44ec9c1ab nodedev: check/add for scsi_host caps for NumOfCaps and ListCaps
Commit id '652a2ec6' introduced two new node device capability flags
and the ability to use those flags as a way to search for a specific
subset of a 'scsi_host' device - namely a 'fc_host' and/or 'vports'.
The code modified the virNodeDeviceCapMatch whichs allows for searching
using the 'virsh nodedev-list [cap]' via virConnectListAllNodeDevices.

However, the original patches did not account for other searches for
the same capability key from virNodeDeviceNumOfCaps and virNodeDeviceListCaps
using nodeDeviceNumOfCaps and nodeDeviceListCaps. Since 'fc_host' and
'vports' are self defined bits of a 'scsi_host' device mere string
comparison against the basic/root type is not sufficient.

This patch adds the check for the 'fc_host' and 'vports' bits within
a 'scsi_host' device and allows the following python code to find the
capabilities for the device:

import libvirt
conn = libvirt.openReadOnly('qemu:///system')
devs = conn.listAllDevices()
for dev in devs:
    if 'fc_host' in dev.listCaps() or 'vports' in dev.listCaps():
        print dev.name(),dev.numOfCaps(),dev.listCaps()
2015-02-05 07:50:32 -05:00
Shivaprasad G Bhat
e8fcac8ecb nodedev: check/add for scsi_host caps for ListDevices
Commit id '652a2ec6' introduced two new node device capability flags
and the ability to use those flags as a way to search for a specific
subset of a 'scsi_host' device - namely a 'fc_host' and/or 'vports'.
The code modified the virNodeDeviceCapMatch whichs allows for searching
using the 'virsh nodedev-list [cap]' via virConnectListAllNodeDevices.

However, the original patches did not account for other searches for
the same capability key from virNodeListDevices using virNodeDeviceHasCap.
Since 'fc_host' and 'vports' are self defined bits of a 'scsi_host'
device mere string comparison against the basic/root type is not
sufficient.

This patch adds the check for the 'fc_host' and 'vports' bits within
a 'scsi_host' device and allows the following python code to find the
capabilities for the device:

import libvirt
conn = libvirt.openReadOnly('qemu:///system')
fc = conn.listDevices('fc_host', 0)
print(fc)
fc = conn.listDevices('vports', 0)
print(fc)

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
2015-02-05 07:50:24 -05:00
Luyao Huang
1b2c9ce752 qemu: Properly report error on uuid mismatch in the migration cookie
Add the missing jump to the error label when the uuid in the
migration cookie XML does not match the uuid of the migrated
domain.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-02-05 08:14:36 +01:00
Luyao Huang
4cef725782 lxc: fix double close handshakefds[1]
Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-04 15:42:43 +01:00
Olivia Yin
5a1998d3c4 cpu: add Freescale ppc64 CPU models
With this patch, Freescale ppc64 CPU modesl could be recognized.

virsh # cpu-models ppc64
POWERPC_e6500
POWERPC_e5500
power8
power8e
power7+
power7
power6
POWER8_v1.0
POWER7+_v2.1
POWER7_v2.3
POWER7_v2.1
POWER7

virsh # capabilities
<capabilities>
  <host>
    <uuid>5a54efa6-20dc-4da7-b271-0b7fb7062cb8</uuid>
    <cpu>
      <arch>ppc64</arch>
      <model>POWERPC_e6500</model>
      <vendor>Freescale</vendor>
2015-02-04 12:41:01 +01:00
Peter Krempa
fdb80ed4f6 util: storage: Fix parsing of nbd:// URI without path
If a storage file would be backed with a NBD device without path
(nbd://localhost) libvirt would crash when parsing the backing path for
the disk as the URI structure's path element is NULL in such case but
the NBD parser would access it shamelessly.
2015-02-04 08:38:25 +01:00
Luyao Huang
76b284c968 conf: Properly report error of unsupported input bus type
https://bugzilla.redhat.com/show_bug.cgi?id=1188914

Add a missing jump to the error label in case the input device bus is
invalid.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-04 07:51:23 +01:00
Luyao Huang
de3d32407b conf: Properly report error when an unsupported chr device name is passed
Add the missing jump to thje error label. The error message shouldn't
ever be triggered though as it's called only on pre-selected nodes.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-02-04 07:49:37 +01:00
Pavel Hrdina
47dd6c4335 virutil: fix MinGW build
Commit b38da584 introduced two new functions to get a page size but it
won't work on Windows. We should take care of this.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-03 16:37:01 +01:00
Pavel Hrdina
8bda903528 virnetdev: fix some issues found by coverity and mingw builds
Commit e562a61a introduced new function to get/set interface state but
there was misuse of ATTRIBUTE_NONNULL on non-pointer attributes and also
we need to wrap that functions by #ifdef to not break mingw build.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-03 16:34:35 +01:00
Daniel P. Berrange
b38da58423 Make tests independant of system page size
Some code paths have special logic depending on the page size
reported by sysconf, which in turn affects the test results.
We must mock this so tests always have a consistent page size.
2015-02-02 20:27:43 +00:00
Laine Stump
df2cc650c0 util: make virNetDev(Get|Set)IFFlags() static
e562a61a07 added these two new helper functions and only used them
within virnetdev.c, but declared them in the .h file. If some
currently unsupported interface flags need to be accessed in the
future, it will make more sense to write the appropriate higher level
function rather than require us to artificially define IFF_* on some
mythical platform that doesn't have SIOC[SG]IFFLAGS (and therefore
doesn't have IFF_*) just so we can call virNetDevSetIFFFlags() to
return an error.

To help someone in not going down the wrong road, this patch makes the
two helper functions static, hopefully making it less likely that
someone will want to use them outside of virnetdev.c.
2015-02-02 14:50:19 -05:00
John Ferlan
1d2e4d8ca2 storage: Need to clear pool prior to refreshPool during Autostart
https://bugzilla.redhat.com/show_bug.cgi?id=1176510

When storageDriverAutostart is called path virStateReload via a 'service
libvirtd reload', then because the volume list in the pool wasn't cleared
prior to the call, each volume would be listed multiple times (as many
times as we reload). I believe the issue would be introduced by commit
id '9e093f0b' at least for the libvirtd reload path, although I suppose
the introduction of virStateReload (commit id '70da0494') could be a
different cause.

Thus like other places prior to calling refreshPool, we need to call
virStoragePoolObjClearVols
2015-01-31 07:56:15 -05:00
Peter Krempa
b92a003710 qemu: command: Don't combine old and modern NUMA node creation
Change done by commit f309db1f4d wrongly
assumes that qemu can start with a combination of NUMA nodes specified
with the "memdev" option and the appropriate backends, and the legacy
way by specifying only "mem" as a size argument. QEMU rejects such
commandline though:

$ /usr/bin/qemu-system-x86_64 -S -M pc -m 1024 -smp 2 \
-numa node,nodeid=0,cpus=0,mem=256 \
-object memory-backend-ram,id=ram-node1,size=12345 \
-numa node,nodeid=1,cpus=1,memdev=ram-node1
qemu-system-x86_64: -numa node,nodeid=1,cpus=1,memdev=ram-node1: qemu: memdev option must be specified for either all or no nodes

To fix this issue we need to check if any of the nodes requires the new
definition with the backend and if so, then all other nodes have to use
it too.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1182467
2015-01-31 08:53:22 +01:00
Peter Krempa
8795adf7d1 qemu: command: Refactor NUMA backend object formatting to use JSON objs
With the new JSON to argv formatter we are now able to represent the
memory backend definitions in the JSON object format that is reusable
for monitor use (hotplug) and then convert it into the shell string.
This will avoid having two separate instances of the same code that
would create the different formats.

Previous refactors now allow to make this step without changes to the
test suite.
2015-01-31 08:53:22 +01:00
Peter Krempa
b50b4ef30c qemu: command: Switch to bytes when formatting size for memory backends
QEMU's command line visitor as well as the JSON interface take bytes by
default for memory object sizes. Convert mebibytes to bytes so that we
can later refactor the existing code for hotplug purposes.
2015-01-31 08:53:22 +01:00
Peter Krempa
a47174c508 qemu: command: Unify values for boolean values when formating memory backends
QEMU's qapi visitor code allows yes/on/y for true and no/off/n for false
value of boolean properities. Unify the used style so that we can
generate it later and fix test cases.
2015-01-31 08:53:22 +01:00
Peter Krempa
172100ac85 qemu: command: Shuffle around formating of alias for memory backend objs
Move the alias as the second formated argument and tweak the tests so
that a future refactor that will change the order doesn't break tests.
2015-01-31 08:53:22 +01:00
Peter Krempa
db3b1c4a1c qemu: Extract code to setup memory backing objects
Extract the memory backend device code into a separate function so that
it can be later easily refactored and reused.

Few small changes for future reusability, namely:
- new (currently unused) parameter for user specified page size
- size of the memory is specified in kibibytes, divided up in the
function
- new (currently unused) parameter for user specifed source nodeset
- option to enforce capability check
2015-01-31 08:53:22 +01:00
Peter Krempa
331b2583ec qemu: command: Add helper to format -object strings from JSON representation
Unlike -device, qemu uses a JSON object to add backend "objects" via the
monitor rather than the string that would be passed on the commandline.

To be able to reuse code parts that configure backends for various
devices, this patch adds a helper that will allow generating the command
line representations from the JSON property object.
2015-01-31 08:53:22 +01:00
Peter Krempa
a6f277a67b util: json: add helper to iterate JSON object key=value pairs
This helper eases iterating all key=value pairs stored in a JSON
object. Usually we pick only certain known keys from a JSON object, but
this will allow to walk complete objects and have the callback act on
those.
2015-01-31 08:53:21 +01:00
Peter Krempa
58f61d24a4 util: json: Add functions to convert JSON arrays from/to virBitmaps
To be able to easily represent nodesets and other data stored in
virBitmaps in libvirt, this patch introduces a set of helpers that allow
to convert the bitmap to and from JSON value objects.
2015-01-31 08:53:21 +01:00