Commit Graph

11999 Commits

Author SHA1 Message Date
Daniel P. Berrange
051eb0238a Convert nwfilter ebtablesApplyDropAllRules to virFirewall
Convert the nwfilter ebtablesApplyDropAllRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:10 +01:00
Daniel P. Berrange
423735d763 Convert nwfilter ebtablesApplyDHCPOnlyRules to virFirewall
Convert the nwfilter ebtablesApplyDHCPOnlyRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:10 +01:00
Daniel P. Berrange
d01eb15303 Convert nwfilter ebtablesApplyBasicRules to virFirewall
Convert the nwfilter ebtablesApplyBasicRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:10 +01:00
Daniel P. Berrange
138ef25e99 Convert nwfilter ebiptablesTearNewRules to virFirewall
Convert the nwfilter ebiptablesTearNewRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:10 +01:00
Daniel P. Berrange
d7b83ab7c3 Convert nwfilter ebtablesRemoveBasicRules to virFirewall
Convert the nwfilter ebtablesRemoveBasicRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
3010fae592 Convert nwfilter ebiptablesTearOldRules to virFirewall
Convert the nwfilter ebiptablesTearOldRules method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
8d55986427 Convert nwfilter ebiptablesAllTeardown to virFirewall
Convert the nwfilter ebiptablesAllTeardown method to use the
virFirewall object APIs instead of creating shell scripts
using virBuffer APIs. This provides a performance improvement
through allowing direct use of firewalld dbus APIs and will
facilitate automated testing.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
3bf346a124 Convert ebtables code over to use firewall APIs
Convert the virebtables.{c,h} files to use the new virFirewall
APIs for changing ebtables rules.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
c13a952f69 Replace virNetworkObjPtr with virNetworkDefPtr in network platform APIs
The networkCheckRouteCollision, networkAddFirewallRules and
networkRemoveFirewallRules APIs all take a virNetworkObjPtr
instance, but only ever access the 'def' member. It thus
simplifies testing if the APIs are changed to just take a
virNetworkDefPtr instead

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
a66fc27d89 Convert bridge driver over to use new firewall APIs
Update the iptablesXXXX methods so that instead of directly
executing iptables commands, they populate rules in an
instance of virFirewallPtr. The bridge driver can thus
construct the ruleset and then invoke it in one operation
having rollback handled automatically.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
3a0ca7de51 Introduce an object for managing firewall rulesets
The network and nwfilter drivers both have a need to update
firewall rules. The currently share no code for interacting
with iptables / firewalld. The nwfilter driver is fairly
tied to the concept of creating shell scripts to execute
which makes it very hard to port to talk to firewalld via
DBus APIs.

This patch introduces a virFirewallPtr object which is able
to represent a complete sequence of rule changes, with the
ability to have multiple transactional checkpoints with
rollbacks. By formally separating the definition of the rules
to be applied from the mechanism used to apply them, it is
also possible to write a firewall engine that uses firewalld
DBus APIs natively instead of via the slow firewalld-cmd.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
89f244ba7c Preserve error when tearing down nwfilter rules
When a VM fails to launch due to error creating nwfilter
rules, we must avoid overwriting the original error when
tearing down the partially created rules.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
b1c1df05bf Remove two-stage construction of commands in nwfilter
The nwfilter ebiptables driver will build up commands to run in
two phases. The first phase contains all of the command, except
for the '-A' part. Instead it has a '%c' placeholder, along with
a '%s' placeholder for a position arg. The second phase than
substitutes these placeholders. The only values ever used for
these substitutions though is '-A' and '', so it is entirely
pointless. Remove the second phase entirely, since it will make
it harder to convert to the new firewall APIs

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
3f74b2eb2c Merge nwfilter createRuleInstance driver into applyNewRules
The current nwfilter tech driver API has a 'createRuleInstance' method
which populates virNWFilterRuleInstPtr with a command line string
containing variable placeholders. The 'applyNewRules' method then
expands the variables and executes the commands. This split of
responsibility won't work when switching to the virFirewallPtr
APIs, since we can't just build up command line strings. This patch
this merges the functionality of 'createRuleInstance' into the
applyNewRules method.

The virNWFilterRuleInstPtr struct is changed from holding an array
of opaque pointers, into holding generic metadata about the rules
to be processed. In essence this is the result of taking a linked
set of virNWFilterDefPtr's and flattening the tree to get a list
of virNWFilterRuleDefPtr's. At the same time we must keep track of
any nested virNWFilterObjPtr instances, so that the locks are held
for the duration of the 'applyNewRules' method.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
4dd7eaa36f Push virNWFilterRuleInstPtr out of (eb|ip)tablesCreateRuleInstance
Later refactoring will change use of the virNWFilterRuleInstPtr struct.
Prepare for this by pushing use of the virNWFilterRuleInstPtr parameter
out of the ebtablesCreateRuleInstance and iptablesCreateRuleInstance
methods. Instead they simply string(s) with the constructed rule data.
The ebiptablesCreateRuleInstance method will make use of the
virNWFilterRuleInstPtr struct instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
23b1d0c07d Add helper methods for determining what protocol layer is used
Add virNWFilterRuleIsProtocol{Ethernet,IPv4,IPv6} helper methods
to avoid having to write a giant switch statements with many cases.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
143a8a3038 Remove nwfilter tech driver 'displayRuleInstance' callback
The 'displayRuleInstance' callback in the nwfilter tech driver
is never invoked, so can be deleted.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
9b8aef1a02 Remove nwfilter tech driver 'removeRules' callback
The 'removeRules' callback in the nwfilter tech driver is never
invoked, so can be deleted.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
293d4fe2f1 Remove pointless storage of var names in virNWFilterHashTable
The virNWFilterHashTable struct contains a virHashTable and
then a 'char **names' field which keeps a copy of all the
hash keys. Presumably this was intended to record the ordering
of the hash keys. No code ever uses this and the ordering is
mangled whenever a variable is removed from the hash, because
the last element in the list is copied into the middle of the
list when shrinking the array.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
50859fc1dd Remove virDomainNetType parameter from nwfilter drivers
The 'virDomainNetType' is unused in every impl of the
virNWFilterRuleCreateInstance driver method. Remove it
from the code to avoid the dependancy on the external
enum.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
bc46c7fb92 Move virNWFilterTechDriver struct out of nwfilter_conf.h
The virNWFilterTechDriver struct is nothing to do with the nwfilter
XML configuration. It stores data specific to the driver implementation
so should be in a header in the driver directory instead.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Daniel P. Berrange
9b095625e4 Fix leak on OOM in virNWFilterVarValueCreateSimpleCopyValue
If virNWFilterVarValueCreateSimple fails with OOM, then
'val' will be leaked by virNWFilterVarValueCreateSimpleCopyValue

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 15:44:09 +01:00
Jiri Denemark
dff3ad004a qemu: Avoid overflow when setting migration speed on inactive domains
Commit c4206d7 fixed the overflow for running domains. However, we need
a similar check when setting migration speed on inactive domains.

At first look, it may seem the check in c4206d7 is now redundant but
qemuDomainMigrateSetMaxSpeed is not the only caller of
qemuMonitorSetMigrationSpeed so we need to check the bandwidth in both
places.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 16:13:25 +02:00
Daniel P. Berrange
dd477238bc Use virFileFindResource to locate CPU map XML
Replace use of cpuMapOverride with virFileFindResource
to locate CPU map from build dir.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Daniel P. Berrange
bc2f42a094 Use virFileFindResource to locate driver plugins
Replace virDriverModuleInitialize with virFileFindResource
usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Daniel P. Berrange
d3c7684220 Use virFileFindResource to locate lock manager plugins
Replace virLockManagerSetPluginDir with virFileFindResource
usage.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Nehal J Wani
c8e22a4c77 Use virFileFindResource to locate iohelper for fdstream
Instead of hardcoding LIBEXECDIR as the location of the libvirt_iohelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Nehal J Wani
12b8290fa5 Use virFileFindResource to locate parthelper for storage backend
Instead of hardcoding LIBEXECDIR as the location of the libvirt_parthelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Nehal J Wani
89de838f1b Use virFileFindResource to locate libvirt_lxc for capabilities
Instead of hardcoding LIBEXECDIR as the location of the libvirt_lxc
binary set in the LXC driver capabilities, use virFileFindResource
to optionally find it in the current build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Nehal J Wani
7d84ca4649 Use virFileFindResource to locate iohelper for virFileWrapperFdNew
Instead of hardcoding LIBEXECDIR as the location of the libvirt_iohelper
binary, use virFileFindResource to optionally find it in the current
build directory.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:46 +01:00
Daniel P. Berrange
391ac4d990 Activate build dir overrides in libvirtd, virtlockd, virsh & tests
Add calls to virFileActivateDirOverride so that the build dir
overrides are activated.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:32 +01:00
Daniel P. Berrange
63a92e7220 Add helpers for resolving path to resources in build tree
Add virFileFindResource which will try to locate files
in the local build tree if the calling binary (eg libvirtd or
test suite) is being run from the build tree. The corresponding
virFileActivateDirOverride should be called at startup passing
in argv[0]. This will be examined for evidence of libtool magic
binary prefix / sub-directory in order to activate the override.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:42:28 +01:00
Jiri Denemark
f22b7899a8 Add support for addressing backing stores by index
Each backing store of a given disk is associated with a unique index
(which is also formatted in domain XML) for easier addressing of any
particular backing store. With this patch, any backing store can be
addressed by its disk target and the index. For example, "vdc[4]"
addresses the backing store with index equal to 4 of the disk identified
by "vdc" target. Such shorthand can be used in any API in place for a
backing file path:

    virsh blockcommit domain vda --base vda[3] --top vda[2]

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 11:11:03 +02:00
Jiri Denemark
f5869657c8 virStorageFileChainLookup: Return virStorageSourcePtr
Returning both virStorageSourcePtr and its path member does not make a
lot of sense.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 09:48:00 +02:00
Jiri Denemark
f33eb9c115 qemuDomainBlockCommit: Track virStorageSourcePtr for base
virStorageFileChainLookup is able to give use virStorageSourcePtr which
contains the pointer to its canonical path. Let's use a more general
virStorageSourcePtr instead of just canonical path.

Former base_canon maps to baseSource->path.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 09:46:11 +02:00
Jiri Denemark
ca979b0680 qemuDomainBlockCommit: Don't track top_canon path separately
virStorageFileChainLookup is able to give use virStorageSourcePtr which
contains the pointer to its canonical path. There's no need for the
caller to store both of them.

Former top_meta maps to topSource and top_canon maps to topSource->path.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-25 09:43:20 +02:00
Eric Blake
fe19043485 build: avoid 'index' as variable name
Once again, gcc 4.4.7 (hello RHEL) rears its ugly head:

conf/domain_conf.c: In function 'virDomainDiskBackingStoreFormat':
conf/domain_conf.c:14940: error: declaration of 'index' shadows a global declaration [-Wshadow]
/usr/include/string.h:489: error: shadowed declaration is here [-Wshadow]

* src/conf/domain_conf.c (virDomainDiskBackingStoreFormat): Pacify
older gcc.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-24 15:46:56 -06:00
Martin Kletzander
9556681388 qemu: don't check for backing chains for formats w/o snapshot support
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1019926
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=868673

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-24 16:48:23 +02:00
Jiri Denemark
546154e3d4 conf: Format and parse backing chains in domain XML
This patch implements formating and parsing code for the backing store
schema defined and documented by the previous patch.

This patch does not aim at providing full persistent storage of disk
backing chains yet. The formatter is supposed to provide the backing
chain detected when starting a domain and thus it is not formatted into
an inactive domain XML. The parser is implemented mainly for the purpose
of testing the XML generated by the formatter and thus it does not
distinguish between no backingStore element and an empty backingStore
element. This will have to change once we fully implement support for
user-supplied backing chains.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-24 16:06:18 +02:00
Daniel P. Berrange
27b2b987bf Fix pci bus naming for PPC
Recent discussions around naming of 'pci' vs 'pci.0' for PPC
made me go back and look at the PPC emulator in every historical
version of QEMU since 1.0. The results were worse than I imagined.
This patch adds the logic required to make libvirt work with PPC
correctly with naming variations across all versions & machine
types.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-24 14:21:39 +01:00
Peter Krempa
8823272d41 util: storage: Invert the way recursive metadata retrieval works
To avoid having the root of a backing chain present twice in the list we
need to invert the working of virStorageFileGetMetadataRecurse.

Until now the recursive worker created a new backing chain element from
the name and other information passed as arguments. This required us to
pass the data of the parent in a deconstructed way and the worker
created a new entry for the parent.

This patch converts this function so that it just fills in metadata
about the parent and creates a backing chain element from those. This
removes the duplication of the first element.

To avoid breaking the test suite, virstoragetest now calls a wrapper
that creates the parent structure explicitly and pre-fills it with the
test data with same function signature as previously used.
2014-04-24 14:27:57 +02:00
Peter Krempa
cc92ee32cd util: virstoragefile: Don't mangle data stored about directories
Don't remove detected metadata about directory based storage volumes.
2014-04-23 23:11:08 +02:00
Peter Krempa
44551275a9 storage: Move disk->backingChain to the recursive disk->src.backingStore
Switch over to storing of the backing chain as a recursive
virStorageSource structure.

This is a string based move. Currently the first element will be present
twice in the backing chain as currently the retrieval function stores
the parent in the newly detected chain. This will be fixed later.
2014-04-23 23:11:07 +02:00
Peter Krempa
b627b8fd05 util: virstoragefile: Rename backingMeta to backingStore
To conform with the naming of the planned XML output rename the metadata
variable name.

s/backingMeta/backingStore/g
2014-04-23 23:11:07 +02:00
Peter Krempa
4905b983ea util: virstorage: Kill struct virStorageFileMetadata
Remove the now unused pieces of the structure.
2014-04-23 23:11:07 +02:00
Peter Krempa
d64d9ff948 maint: Switch over from struct virStorageFileMetadata to virStorageSource
Replace the old structure with the new one. This change is a trivial
name change operation (along with change of the freeing function).
2014-04-23 23:11:07 +02:00
Peter Krempa
0b5161d9c5 util: storagefile: Add fields from virStorageMetadata to virStorageSource
Add the required fields that are missing from the new structure that
will allow us to switch the storage file metadata code entirely to the
new structure.

Add "relPath" and "relDir" and the raw backing store name. Also allow
creating linked lists of virStorageSourcePtrs to express backing chains.
2014-04-23 23:11:07 +02:00
Peter Krempa
0bd54a10bd util: storagefile: Add function to free a virStorageSourcePtr
Add a free function as some parts of the code will allocate the
structure.
2014-04-23 23:11:06 +02:00
Peter Krempa
39c5aa4e4c virstoragefile: Kill "backingStore" field from virStorageFileMetadata
Remove the obsolete field replaced by data in "path".

The testsuite requires tweaking as the name of the backing file is now
stored one layer deeper in the backing chain linked list.
2014-04-23 23:11:06 +02:00
Peter Krempa
c366a1ef15 util: virstoragefile: Don't use "backingStore" directly
As a temporary step to allow killing of the "backingStore" field of
struct virStorageFileMetadata the recursive metadata retrieval function
will be converted not to use the field in the lookup process.
2014-04-23 23:11:06 +02:00
Peter Krempa
05bc536c83 util: storagefile: Rename "canonPath" to "path" in virStorageFileMetadata
As for the previous patch, this change is needed to achieve
compatibility with all the existing code, where we expect a fully
qualified path of local files to be present.
2014-04-23 23:11:06 +02:00
Peter Krempa
f34b829692 util: storage: Rename "path" to "relPath" in virStorageFileMetadata
To allow future change of virStorageFileMetadata to virStorageSource we
need to store a full path in the "path" variable as rest of the code
expects it to be a full path. Rename the "path" field to "relPath" to
keep tracking the info but allowing a real "path" field.
2014-04-23 23:11:06 +02:00
Peter Krempa
66d92473fa storage: util: Clean up arguments of virStorageFileGetMetadataInternal
Avoid passing lot of arguments into guts of metadata retrieval to fill
the actual structure. Temporarily fill the structure before passing it
down to the actual metadata extractor.

This will later help the inversion of the steps taken to extract the
metadata so that this function can be fully converted to
virStorageSource as the data struct.

This patch also fixes regression when starting a gluster storage pool
where the volumes don't have local representation so that the
canonicalization of the volume's file name failed. Broken by commit
79f11b35
2014-04-23 23:08:57 +02:00
Peter Krempa
67084ed4ae util: storage: Move checking of the actual backing image to the worker
Move the code checking the presence of the backing file to the recursive
worker function instead of the metadata parser. The recursive worker
will later be changed to parse more than just local files and this
change will help the separation.
2014-04-23 23:08:43 +02:00
Peter Krempa
5c43e2e027 util: storage: Remove obsolete argument virStorageFileGetMetadataInternal
As we already pass the whole structure down the call path there's no
need to return some stuff in a separate argument. Remove the argument
and tweak callers to avoid breaking semantics.

virStorageFileGetMetadataFromBuf will be refactored later along with the
storage driver.
2014-04-23 23:08:43 +02:00
Peter Krempa
9944b710a5 util: storagefile: Always store raw backing name in the metadata
Don't use the backingStoreRaw as a indication of broken chains. Fill it
always and tweak the broken image chain detector to avoid changing the
semantics.

The new semantics to detect a broken chain is the presence of string in
backingStoreRaw but the lack of the backing chain metadata structure in
the chain.

Now that the raw backing store name is always filled there's no need to
pass the raw name variable separately to fill in case the backing is not
a file. Tweak the function so that it can handle a NULL in that case.
2014-04-23 23:05:01 +02:00
Peter Krempa
00c272421d qemu: unexport qemuDiskChainCheckBroken
The function isn't used in any other source file. Move it so that it
doesn't need a declaration.
2014-04-23 23:05:01 +02:00
Ján Tomko
22a92eb0a7 Document behavior of setvcpus during guest boot
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1088748

The hotplugged vcpus could fail to show up in the guest if
they were added during boot, see:
https://bugzilla.redhat.com/show_bug.cgi?id=807508

Also change arbitrary to arbitrarily.
2014-04-23 14:24:21 +02:00
Ján Tomko
b396e602c9 Save domain status after cpu hotplug
The live change of vcpus was not reflected in the domain status
xml and it got lost during libvirtd restart.

https://bugzilla.redhat.com/show_bug.cgi?id=1088703
2014-04-23 14:24:21 +02:00
Roman Bogorodskiy
fa8a389ebb bhyve: bhyveDomainDefineXML fixes
- do not lose new definition for an active domain
- do not leak oldDef
- do not set dom->id if virDomainSaveConfig() fails
- do not call virObjectUnlock(vm) if vm is NULL
2014-04-23 15:59:33 +04:00
Li Zhang
7b6b9d3863 PPC64 prefers to set pci-ohci controller as default USB controller.
Currently, libvirt is using legacy USB controller as default. There
are problems with VGA which can't work correctly with USB Keyboard and
USB Mouse.

While providing -nodefaults, ppc64 should be specifying the usb
controller explicitly in place of using the legacy
controller(-usb). Qemu spapr initialization code when sees "-usb" adds a
USB Keyboard and USB Mouse by default. And libvirt has added a USB
keyboard and USB mouse.

A recent fix in the in qemu VGA code uncoverd this problem, which
resulted in addition of extra keyboard and mouse to the qemu machine.

This patch is to set pci-ohci as USB default controller.

Signed-off-by: Li Zhang <zhlcindy@linux.vnet.ibm.com>
2014-04-23 12:44:42 +01:00
Ján Tomko
17a65277ce Fix error for out of range vcpu in qemuDomainPinVcpuFlags
Changes:
error: invalid argument: vcpu number out of range 2 > 2
to slightly less confusing:
error: invalid argument: vcpu number out of range 2 > 1
2014-04-22 14:49:45 +02:00
Ján Tomko
180b996047 Make virDomainVcpuPinDel return void
Before, it only returned -1 on failure to shrink the array.
Since the switch to VIR_DELETE_ELEMENT in commit 2133441,
it returns either 0 or 0.
2014-04-22 14:49:45 +02:00
Ján Tomko
a0a8dc695e Properly free vcpupin info for unplugged CPUs
Remove the pointer from def->cputune.vcpupin after unplugging
the CPU and also free the bitmap contained in the structure
by calling virDomainVcpuPinDel instead of VIR_FREE.

Introduced by commit 0df1a79.

This makes virDomainLookupVcpuPin redundant.

https://bugzilla.redhat.com/show_bug.cgi?id=1088165
2014-04-22 14:49:25 +02:00
Nehal J Wani
3d5c29a17c Fix typos in src/*
Fix minor typos in source comments

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-21 16:49:08 -06:00
Wojciech Macek
6b3fa4a078 bhyve: domainCreateXML
Implement bhyveDomainCreateXML function.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2014-04-20 11:16:44 +04:00
Ján Tomko
062074c455 Remove QEMU_CAPS_MACHINE_USB_OPT from ComputeCmdFlags
The version check is for >=1.3.0, but ComputeCmdFlags
is only called for QEMU <1.2.0.
2014-04-18 15:01:43 +02:00
Ján Tomko
c3725db8d0 Only set QEMU_CAPS_NO_HPET on x86
QEMU only supports it on x86, but we've been assuming it for
all QEMUs when doing QMP capability detection.

https://bugzilla.redhat.com/show_bug.cgi?id=1066145
2014-04-18 15:01:27 +02:00
Nehal J Wani
ab07a7b358 Fix Memory Leak in virStorageFileGetMetadataRecurse()
While running virstoragetest, valgrind pointed out the following
memory leak:

==8142== 2 bytes in 1 blocks are definitely lost in loss record 1 of 92
==8142==    at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==8142==    by 0x4E7B53E: mdir_name (dirname-lgpl.c:78)
==8142==    by 0x4CBE2B0: virStorageFileGetMetadataInternal (virstoragefile.c:595)
==8142==    by 0x4CBE651: virStorageFileGetMetadataFromFDInternal (virstoragefile.c:1086)
==8142==    by 0x4CBEEB4: virStorageFileGetMetadataRecurse (virstoragefile.c:1175)
==8142==    by 0x4CBF1DE: virStorageFileGetMetadata (virstoragefile.c:1270)
==8142==    by 0x4028AD: testStorageChain (virstoragetest.c:275)
==8142==    by 0x407B91: virtTestRun (testutils.c:201)
==8142==    by 0x4039D7: mymain (virstoragetest.c:534)
==8142==    by 0x40830D: virtTestMain (testutils.c:789)
==8142==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)

...62 times
2014-04-18 09:17:07 +02:00
Stefan Berger
a4209f5379 qemu: Unlock the NWFilter update lock by leaving via the cleanup label
Fix a locking problem by leaving the function via the cleanup label.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2014-04-17 06:30:08 -04:00
John Ferlan
4090e15399 storage: netfs: Handle backend errors
Commit id '18642d10' caused a virt-test regression for NFS backend
storage error path checks when running the command:

    'virsh find-storage-pool-sources-as netfs Unknown  '

when the host did not have Gluster installed. Prior to the commit,
the test would fail with the error:

    error: internal error: Child process (/usr/sbin/showmount --no-headers
    --exports Unknown) unexpected exit status 1: clnt_create: RPC: Unknown host

After the commit, the error would be ignored, the call would succeed,
and an empty list of pool sources returned. This was tucked into the
commit message as an expected outcome.

When the target host does not have a GLUSTER_CLI this is a regression
over the previous release. Furthermore, even if Gluster CLI was present,
but had a failure to get devices, the API would return a failure even if
the NFS backend had found devices.

Modify the logic to return failure when the NFS backend check fails and
there's no GLUSTER_CLI or when both backend checks fail.

If either returns success and GLUSTER_CLI is defined, then fetch and return
a list of source devices even if it's empty
2014-04-16 07:32:17 -04:00
Eric Blake
8fb446754d conf: fix omission of <driver> in domain dumpxml
I noticed that depending on the <driver> attributes the user passed
in, the output may omit the <driver> element altogether.  For example,
the rerror_policy has had this problem since commit 4bb4109 in Oct
2011.  But in adding testsuite coverage to expose it, I found another
problem: the C code is just fine without a driver name, but the
XML validator required either a name or a cache mode.

* src/conf/domain_conf.c (virDomainDiskDefFormat): Update
conditional.
* docs/schemas/domaincommon.rng (diskDriver): Simplify.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.xml:
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-copy-on-read.args:
New files.
* tests/qemuxml2argvdata/qemuxml2argv-disk-drive-discard.xml:
Enhance test.
* tests/qemuxml2xmloutdata/qemuxml2xmlout-disk-drive-discard.xml:
Likewise.
* tests/qemuxml2argvtest.c (mymain): New test.
* tests/qemuxml2xmltest.c (mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-16 10:49:07 +02:00
Eric Blake
db7d7c0ee8 conf: restrict external snapshots to backing store formats
Domain snapshots should only permit an external snapshot into
a storage format that permits a backing chain, since the new
snapshot file necessarily must be backed by the existing file.
The C code for the qemu driver is a little bit stricter in
currently enforcing only qcow2 or qed, but at the XML parser
level, including virt-xml-validate, it is fairly easy to
enforce that a user can't request a 'raw' external snapshot.

* docs/schemas/storagecommon.rng (storageFormat): Split out...
(storageFormatBacking): ...new sublist.
* docs/schemas/domainsnapshot.rng (disksnapshotdriver): Use new
type.
* src/util/virstoragefile.h (virStorageFileFormat): Rearrange for
easier code management.
* src/util/virstoragefile.c (virStorageFileFormat, fileTypeInfo):
Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML): Use
new marker to limit selection of formats.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-15 13:57:15 +02:00
Ján Tomko
6077be466e Fix virsystemdtest without SYSTEMD_DAEMON
Commit 4897698 fixed the build without dbus by only building
the virSystemdPMSupportTarget with SYSTEMD_DAEMON.

Introduce a virDBusMessageUnref wrapper for dbus_message_unref
to let virsystemd.c build without dbus, while still allowing
virsystemdtest to run without SYSTEM_DAEMON.
2014-04-14 19:45:47 +02:00
Martin Kletzander
4897698110 build: Don't use code with dbus_message_unref when built without dbus
In order to do that, virNodeSuspendSupportsTargetPMUtils() and
virSystemdPMSupportTarget() are created even when pm-utils and dbus
are compiled out, respectively, but in that case returning -2 meaning
"unavailable" (this return code was already used for unavailability
before).  Error is reported in virNodeSuspendSupportsTarget() only if
both functions returned -2, otherwise the error (or success) is properly
propagated up the stack.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-14 18:19:36 +02:00
Jiri Denemark
c4206d7c7e qemu: Avoid overflow when setting migration speed
When passing migration bandwidth to QEMU, we multiply it by 1024 * 1024
to convert the speed to B/s and the result still needs to fit in
int64_t.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-14 13:42:48 +02:00
Eric Blake
e0292e0c2a conf: delete internal directory field
Another field no longer needed, getting us one step closer to
merging virStorageFileMetadata and virStorageSource.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Alter signature.
(virStorageFileFreeMetadata, virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataFromFD): Adjust clients.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-12 07:16:54 -06:00
Eric Blake
d193b34deb conf: tweak chain lookup internals
Thanks to the testsuite, I feel quite confident that this rewrite
is correct; it gives the same results for all cases except for one.
I can make the argument that _that_ case was a pre-existing bug:
when looking up relative names, the lookup is supposed to be
pegged to the directory that contains the parent qcow2 file.  Thus,
this resolves the fixme first mentioned in commit 367cd69 (even
though I accidentally removed the fixme comment early in 74430fe).

* src/util/virstoragefile.c (virStorageFileChainLookup): Depend on
new rather than old fields.
* tests/virstoragetest.c (mymain): Adjust test to match fix.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-12 07:16:03 -06:00
Eric Blake
74430fe364 conf: drop redundant parameter to chain lookup
The original chain lookup code had to pass in the starting name,
because it was not available in the chain.  But now that we have
added fields to the struct, this parameter is redundant.

* src/util/virstoragefile.h (virStorageFileChainLookup): Alter
signature.
* src/util/virstoragefile.c (virStorageFileChainLookup): Adjust
handling of top of chain.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Adjust caller.
* tests/virstoragetest.c (testStorageLookup, mymain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-11 22:09:37 -06:00
Eric Blake
6752bc2add conf: report error on chain lookup failure
The chain lookup function was inconsistent on whether it left
a message in the log when looking up a name that is not found
on the chain (leaving a message for OOM or if name was
relative but not part of the chain), and could litter the log
even when successful (when name was relative but deep in the
chain, use of virFindBackingFile early in the chain would complain
about a file not found).  It's easier to make the function
consistently emit a message exactly once on failure, and to let
all callers rely on the clean semantics.

* src/util/virstoragefile.c (virStorageFileChainLookup): Always
report error on failure.  Simplify relative lookups.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Avoid
overwriting error.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-11 22:03:33 -06:00
Eric Blake
91f349d8fd util: new virFileRelLinkPointsTo function
When checking if two filenames point to the same inode (whether
by hardlink or symlink), sometimes one of the names might be
relative.  This convenience function makes it easier to check.

* src/util/virfile.h (virFileRelLinkPointsTo): New prototype.
* src/util/virfile.c (virFileRelLinkPointsTo): New function.
* src/libvirt_private.syms (virfile.h): Export it.
* src/xen/xm_internal.c (xenXMDomainGetAutostart): Use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-11 20:00:42 -06:00
Cédric Bosdonnat
ec70f3696f Introduce --without-pm-utils to get rid of pm-is-supported dependency
This uses the dbus api of systemd to check the power management
capabilities of the node.
2014-04-11 15:51:10 -06:00
Wojciech Macek
1ee866cf33 bhyve: fix domain management
When domain is not persistent, it should be forgotten upon destroying.
2014-04-11 20:18:44 +04:00
Eric Blake
86cfa1f603 conf: delete useless backingStoreFormat field
Drop another redundant field from virStorageFileMetadata.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c
(virStorageFileGetMetadataFromFDInternal)
(virStorageFileGetMetadataFromFD)
(virStorageFileGetMetadataRecurse): Adjust callers.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:59:26 -06:00
Eric Blake
a4dfc8d31d conf: return backing information separately from metadata
A couple pieces of virStorageFileMetadata are used only while
collecting information about the chain, and don't need to
live permanently in the struct.  This patch refactors external
callers to collect the information separately, so that the
next patch can remove the fields.

* src/util/virstoragefile.h (virStorageFileGetMetadataFromBuf):
Alter signature.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Likewise.
(virStorageFileGetMetadataFromFDInternal): Adjust callers.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:56:16 -06:00
Eric Blake
c919ed7ea5 conf: delete useless backingStoreIsFile field
Finally starting to prune away some of the old fields that have
been made redundant by the new fields, on my way towards directly
reusing virStorageSource.

* src/util/virstoragefile.h (_virStorageFileMetadata): Drop
field.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileChainLookup): Adjust callers.
* tests/virstoragetest.c (_testFileData, testStorageChain)
(mymain): Simplify test.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:39:43 -06:00
Eric Blake
86f71e0a87 conf: expose probe for non-local storage
Deciding if a user string represents a local file instead of a
network path is an operation worth exposing directly, particularly
since the next patch will be removing a redundant variable that
was caching the information.

* src/util/virstoragefile.h (virStorageIsFile): New declaration.
* src/util/virstoragefile.c (virBackingStoreIsFile): Rename...
(virStorageIsFile): ...export, and allow NULL input.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.
* src/conf/domain_conf.c (virDomainDiskDefForeachPath): Use it.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.
* src/libvirt_private.syms (virstoragefile.h): Export function.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:37:01 -06:00
Eric Blake
7010768c5e conf: provide details on network backing store
So far, my work has been merely preserving the status quo of
backing file analysis.  But this patch starts to tread in the
territory of making the backing chain code more powerful - we
will eventually support network storage containing non-raw
formats.  Here, we expose metadata information about a network
backing store, even if that information is still hardcoded to
a raw format for now.

* src/util/virstoragefile.c (virStorageFileGetMetadataRecurse):
Also populate struct for non-file backing.
(virStorageFileGetMetadata, virStorageFileGetMetadatainternal):
Recognize non-file top image.
(virFindBackingFile): Add comment.
(virStorageFileChainGetBroken): Adjust comment, ensure output
is set.
* tests/virstoragetest.c (mymain): Update test to reflect it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-10 16:34:21 -06:00
Jiri Denemark
7eca4a5b32 cpu: Properly check input parameters
Most of the APIs in CPU driver do not expect to get NULL for input
parameters. Let's mark them with ATTRIBUTE_NONNULL and also check for
some members of virCPUDef when the APIs expect them have some specific
values.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-10 20:31:32 +02:00
Jiri Denemark
a1b1fcdcfe cpu: Add documentation for CPU driver APIs
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-04-10 20:31:32 +02:00
Ján Tomko
5dfcd6fbc6 Fix build on mingw32
My commit 897808e added a parameter to virCgroupGetPercpuStats,
but didn't change the stub for systems where cgroups are not supported.
2014-04-09 16:47:26 +02:00
Ján Tomko
2adf59ebde Clean up virCgroupGetPercpuStats
The iterator is checked for being less than or equal to need_cpus.
The 'n' variable is incremented need_cpus + 1 times.

Simplify the computation of need_cpus and make its value one larger,
to let it be used instead of 'n' and compared without the equal sign
in loop conditions.

Just index the sum_cpu_time array instead of using a helper variable.

Start the loop at start_cpu instead of continuing for all lower values.
2014-04-09 16:24:08 +02:00
Ján Tomko
9fe5267ade Check maximum startcpu value correctly
The cpus are indexed from 0, so a startcpu value equal
to the number of CPUs is invalid.

https://bugzilla.redhat.com/show_bug.cgi?id=1070680
2014-04-09 16:24:08 +02:00
Ján Tomko
dd74ab4e82 Rename id, max_id to need_cpus, total_cpus
total_cpus is the total number of CPUs on the host
need_cpus is the number of CPUs we need to look at

(need_cpus can be larger than ncpus, because we need to look
 at CPUs before the startcpu too, even if we aren't reporting
 their stats)
2014-04-09 16:24:08 +02:00
Ján Tomko
897808e74f Extend virCgroupGetPercpuStats to fill in vcputime too
Currently, virCgroupGetPercpuStats is only used by the LXC driver,
filling out the CPUTIME stats. qemuDomainGetPercpuStats does this
and also filles out VCPUTIME stats.

Extend virCgroupGetPercpuStats to also report VCPUTIME stats if
nvcpupids is non-zero. In the LXC driver, we don't have cpupids.
In the QEMU driver, there is at least one cpupid for a running domain,
so the behavior shouldn't change for QEMU either.

Also rename getSumVcpuPercpuStats to virCgroupGetPercpuVcpuSum.
2014-04-09 16:24:08 +02:00
Ján Tomko
23d2d863b7 Fix return value of virCgroupGetPercpuStats
We need to return the number of successfully populated stats,
not the nparams supplied by the user.
2014-04-09 16:24:08 +02:00
Ján Tomko
3e7e6ad6ee Don't require domain obj in qemuDomainGetPercpuStats
All we need is the virCgroupPtr and number of vcpupids.
This will allow the function to be moved to util/vircgroup.c.
2014-04-09 16:24:08 +02:00
Eric Blake
5976a9ac88 conf: track more fields in backing chain metadata
The current use of virStorageFileMetadata is awkward; to learn
some of the information about a child node, you have to read
fields in the parent node.  This does not lend itself well to
modifying backing chains (whether inserting a new node in the
chain, or consolidating existing nodes); better would be to
learn about a child node directly in that node.  This patch
sets up some new fields which contain redundant information,
although not necessarily in the final desired state for the
new fields (see the next patch for actual tests of what is there
now).  Then later patches will do any refactoring necessary to
get the fields to their desired states, and update clients to
get the information from the new fields, so we can finally
delete the fields that are tracking information about the wrong
node.

More concretely, compare these three example backing chains:

good <- one
missing <- two
gluster://server/vol/img <- three

Pre-patch, querying the chains gives:
{ .backingStore = "/path/to/good",
  .backingStoreRaw = "good",
  .backingStoreIsFile = true,
  .backingStoreFormat = VIR_STORAGE_FILE_RAW,
  .backingMeta = {
    .backingStore = NULL,
    .backingStoreRaw = NULL,
    .backingStoreIsFile = false,
    .backingMeta = NULL,
  }
}
{ .backingStore = NULL,
  .backingStoreRaw = "missing",
  .backingStoreIsFile = false,
  .backingStoreFormat = VIR_STORAGE_FILE_NONE,
  .backingMeta = NULL,
}
{ .backingStore = "gluster://server/vol/img",
  .backingStoreRaw = NULL,
  .backingStoreIsFile = false,
  .backingStoreFormat = VIR_STORAGE_FILE_RAW,
  .backingMeta = NULL,
}

Deciding whether to ignore a missing backing file (as in virsh
vol-dumpxml) or report an error (as in security manager sVirt
labeling) requires reading multiple fields.  Plus, the format
is hard-coded to treat all network protocols as end-of-the-chain,
as if they were raw.  By the end of this patch series, the goal
is to instead represent these three situations as:

{ .path = "one",
  .canonPath = "/path/to/one",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "good",
  .backingMeta = {
    .path = "good",
    .canonPath = "/path/to/good",
    .type = VIR_STORAGE_TYPE_FILE,
    .format = VIR_STORAGE_FILE_RAW,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}
{ .path = "two",
  .canonPath = "/path/to/two",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "missing",
  .backingMeta = NULL,
}
{ .path = "three",
  .canonPath = "/path/to/three",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "gluster://server/vol/img",
  .backingMeta = {
    .path = "gluster://server/vol/img",
    .canonPath = "gluster://server/vol/img",
    .type = VIR_STORAGE_TYPE_NETWORK,
    .format = VIR_STORAGE_FILE_RAW,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}

or, for the second file, maybe also allowing:
{ .path = "two",
  .canonPath = "/path/to/two",
  .type = VIR_STORAGE_TYPE_FILE,
  .format = VIR_STORAGE_FILE_QCOW2,
  .backingStoreRaw = "missing",
  .backingMeta = {
    .path = "missing",
    .canonPath = NULL,
    .type = VIR_STORAGE_TYPE_NONE,
    .format = VIR_STORAGE_FILE_NONE,
    .backingStoreRaw = NULL,
    .backingMeta = NULL,
  }
}

* src/util/virstoragefile.h (_virStorageFileMetadata): Add
path, canonPath, relDir, type, and format fields.  Reorder
existing fields, and add lots of comments.
* src/util/virstoragefile.c (virStorageFileFreeMetadata): Clean
new fields.
(virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Start populating new
fields.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:26 -06:00
Eric Blake
43f85b995b conf: earlier allocation during backing chain crawl
Right now, we are allocating virStorageFileMetadata near the bottom
of the callchain, only after we have identified that we are visiting
a file (and not a network resource).  I'm hoping to eventually
support parsing the backing chain from XML, where the backing chain
crawl then validates what was parsed rather than allocating a fresh
structure.  Likewise, I'm working towards a setup where we have a
backing element even for networks.  Both of these use cases are
easier to code if the allocation is hoisted earlier.

* src/util/virstoragefile.c (virStorageFileGetMetadataInternal)
(virStorageFileGetMetadataFromFDInternal): Change signature.
(virStorageFileGetMetadataFromBuf)
(virStorageFileGetMetadataRecurse, virStorageFileGetMetadata):
Update callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:26 -06:00
Eric Blake
79f11b35c7 conf: track user vs. canonical name through full chain lookup
The previous patch started a separation of error messages
reported against the user-specified name, vs. tracking the
canonical path that was actually opened.  This patch extends
that notion, by hoisting directory detection up front, passing
the canonical path through the entire call chain, and
simplifying lower-level functions that can now assume that
a canonical path and directory have been supplied.

* src/util/virstoragefile.c
(virStorageFileGetMetadataFromFDInternal)
(virStorageFileGetMetadataInternal): Add parameter, require
directory.
(virFindBackingFile): Require directory.
(virStorageFileGetMetadataFromFD): Pass canonical path.
(virStorageFileGetMetadataFromBuf): Likewise.
(virStorageFileGetMetadata): Determine initial directory.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-09 07:01:26 -06:00
Peter Krempa
90dbdff2ac qemu: Unexport qemuBuildNetworkDriveURI()
The function isn't used in any other file. Convert it to static.
2014-04-09 14:48:48 +02:00
Peter Krempa
816f0f93ea qemu: Refactor qemuGetDriveSourceString to take virStorageSourcePtr
Refactor the function to avoid multiple wrappers splitting identical
fields from the now common metadata struct.

The refactor is done by folding in the wrapper used for disk sources
which allows us to lookup secrets via the secret driver. This may allow
using stored secrets for snapshot disk images too in the future.
2014-04-09 14:39:34 +02:00
Peter Krempa
cecd656604 storage: Refactor location of metadata for storage drive access to files
Now that we store all metadata about a storage image in a
virStorageSource struct let's use it also to store information needed by
the storage driver to access and do operations on the files.
2014-04-09 14:34:19 +02:00
Peter Krempa
9689dfaad3 storage: Refactor storage file initialization to use virStorageSourcePtr
Now that storage source metadata is stored in a single struct we don't
need two initialization functions for different structs.
2014-04-09 14:31:12 +02:00
Peter Krempa
93c1f2cd70 conf: Refactor helpers to retrieve actual storage type
Now that the storage source definition is uniform convert the helpers to
retrieve the actual storage type to a single one.
2014-04-09 14:20:40 +02:00
John Ferlan
0c2305b31c storage: Don't update pool available/allocation if buildVol fails
https://bugzilla.redhat.com/show_bug.cgi?id=1024159

If adding a volume to a storage pool fails during the CreateXML or
CreateXMLFrom API's, we don't want to adjust the available and
allocation values for the storage pool during storageVolDelete
since we haven't adjusted the values for the create.

Refactor storageVolDelete() a bit to create a storageVolDeleteInternal()
which will handle the primary deletion activities.  Add a parameter
updateMeta which will signify whether to update the values or not.

Adjust the calls from CreateXML and CreateXMLFrom to directly call the
DeleteInternal with the pool lock held.  This does bypass the call
to virStorageVolDeleteEnsureACL().
2014-04-09 06:57:37 -04:00
Eric Blake
af095bfa0d conf: fix detection of infinite backing loop
While trying to refactor the backing file chain, I noticed that
if you have a self-referential qcow2 file via a relative name:

qemu-img create -f qcow2 loop 10M
qemu-img rebase -u -f qcow2 -F qcow2 -b loop loop

then libvirt was creating a chain 2 deep before realizing it
had hit a loop; furthermore, virStorageFileChainCheckBroken
was not identifying the chain as broken.  With this patch,
the loop is detected when the chain is only 1 deep; still
enough for storage volume XML to display the file, but now
with a proper error report about where the loop was found.

This patch adds a parameter to virStorageFileGetMetadataRecurse,
so that errors at the top of the chain remain unchanged; messages
issued for backing files now use the name provided by the user
instead of the canonical name (for VDSM, which uses relative
symlinks to device mapper block devices, this is actually more
useful).

* src/util/virstoragefile.c (virStorageFileGetMetadataRecurse):
Add parameter, require canonical path up front.  Mark chain
broken on OOM or loop detection.
(virStorageFileGetMetadata): Pass in canonical name.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-08 13:28:19 -06:00
Jean-Baptiste Rouault
2fe658ad90 vmware: set the driver version
Since commit 7457cbe8 the vmware driver version isn't set anymore.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-08 11:16:33 -06:00
Roman Bogorodskiy
b291cb5e90 bhyve: add domain metadata support
Implement domainSetMetadata and domainGetMetadata driver calls.
2014-04-08 20:40:39 +04:00
Roman Bogorodskiy
986a07c709 bhyve: fix ATTRIBUTE_NONNULL usage
Fix incorrect ATTRIBUTE_NONNULL usage introduced in 17b17565
which caused build failure:

bhyve/bhyve_driver.c:127:48: error: expected ')'
bhyveDriverGetCapabilities(bhyveConnPtr driver ATTRIBUTE_NONNULL)
                                               ^
bhyve/bhyve_driver.c:127:27: note: to match this '('
bhyveDriverGetCapabilities(bhyveConnPtr driver ATTRIBUTE_NONNULL)

Pushed under the build breaker rule.
2014-04-08 20:30:23 +04:00
Richard Weinberger
21ec87f4f1 LXC: Fix return code evaulation in lxcCheckNetNsSupport()
Commit b9dd878f (util: make it easier to grab only regular command exit)
changed the call semantics of virCommandRun() and therefore of virRun()
too. But lxcCheckNetNsSupport() was not updated.
As consequence of this lxcCheckNetNsSupport always failed and broke LXC.

Signed-off-by: Richard Weinberger <richard@nod.at>
2014-04-08 09:19:24 -06:00
Ján Tomko
27fbfc2a17 Fix incorrect values in redirdev ABI check error
My commit c9123fb introduced this copy-and-paste error.
2014-04-08 15:08:20 +02:00
Daniel P. Berrange
3f671e6c52 Use a static initializer for static mutexes
Now that we ditched our custom pthread impl for Win32, we can
use PTHREAD_MUTEX_INITIALIZER for static mutexes. This avoids
the need to use a virOnce one-time global initializer in a
number of places.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 13:46:29 +01:00
Daniel P. Berrange
3cfa19da22 Replace Pci with PCI throughout
Since it is an abbreviation, PCI should always be fully
capitalized or full lower case, never Pci.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:15:55 +01:00
Daniel P. Berrange
edfe82c7f9 Replace Usb with USB throughout
Since it is an abbreviation, USB should always be fully
capitalized or full lower case, never Usb.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:10:59 +01:00
Daniel P. Berrange
21a2446d92 Replace Scsi with SCSI throughout
Since it is an abbreviation, SCSI should always be fully
capitalized or full lower case, never Scsi.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-08 11:10:31 +01:00
Wangrui (K)
79bef03a2c virNetDev{Replace,Restore}MacAddress: Fix memory leak
Functions virNetDevRestoreMacAddress() and virNetDevRestoreMacAddress()
allocate memory for variable @path using virAsprintf(), but they
haven't freed that memory before returning out.

Signed-off-by: Zhang bo <oscar.zhangbo@huawei.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-04-08 10:51:53 +02:00
Michal Privoznik
23419a62c2 bhyveConnectGetCapabilities: Fix double caps unref
At the beginning of the function we gain a reference to the driver
capabilities. Then, we call format function (*) which if failed, unref
over caps is called. Then, at the end another unref occurs.

* - Moreover, the format was not called over gained caps, but over
privconn->caps directly which is not allowed anymore.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-04-08 09:17:01 +02:00
Michal Privoznik
17b17565e6 Simplify bhyveDriverGetCapabilities()
The driver passed as the only argument to the function should never be
NULL so there's no need to check it. After removing it, the whole
function collapses to a single line doing ref over driver
capabilities.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-04-08 09:17:01 +02:00
Michal Privoznik
87f24f3434 bhyve_capabilities: Add Semihalf to Copyright
Since b15a2bbd we have the new bhyve_capabilities.[ch] files.
However, the copyright is held by both Roman and Semihalf.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-04-08 09:17:00 +02:00
Eric Blake
8733303933 conf: avoid memleak on NULL path
I noticed that the apparmor code could request metadata even
for a cdrom with no media, which would cause a memory leak of
the hash table used to look for loops in the backing chain.
But even before that, we blindly dereferenced the path for
printing a debug statement, so it is just better to enforce
that this is only used on non-NULL names.

* src/util/virstoragefile.c (virStorageFileGetMetadata): Assume
non-NULL path.
* src/util/virstoragefile.h: Annotate this.
* src/security/virt-aa-helper.c (get_files): Fix caller.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-07 16:31:45 -06:00
Cédric Bosdonnat
8f4ef7e6b6 lxc conf2xml: don't let current vcpus at 0: define won't like it 2014-04-07 10:52:28 -06:00
Wojciech Macek
627d1439c2 bhyve: connectCompareCPU support
Implement support for connectCompareCPU.
2014-04-07 15:34:53 +02:00
Wojciech Macek
b15a2bbd64 bhyve: create capabilities submodule
- Move all capabilities functions to separate file
- Add initCPU
2014-04-07 15:34:53 +02:00
Wojciech Macek
36cf8174b6 bhyve: support for connectBaselineCPU
Implement bhyveConnectBaselineCPU to support OpenStack/Nova
2014-04-07 15:34:53 +02:00
Laine Stump
7284c499e5 interface: dump inactive xml when interface isn't active
Other drivers in libvirt (e.g. network, qemu) will automatically
return the "inactive" (persistent configuration) XML of an object when
that object is inactive. The netcf backend of the interface driver
would always try to return the live status XML of the interface, even
when it was down. Although netcf does return valid XML in that case,
for bond interfaces it is missing almost all of its content, including
the <bond> subelement itself, leading to this error message from
"virsh iface-dumpxml" of a bond interface that is inactive:

  error: XML error: bond interface misses the bond element

(this is because libvirt's validation of the XML returned by netcf
always requires a <bond> element be present).

This patch modifies the interface driver netcf backend to check if the
interface is inactive, and in that case always return the inactive XML
(which will always have a <bond> element, thus eliminating the error
message, as well as making operation more in line with other drivers.

This fixes the following bug:

  https://bugzilla.redhat.com/show_bug.cgi?id=878394
2014-04-07 16:25:40 +03:00
Eric Blake
09567144d6 hash: add common utility functions
I almost wrote a hash value free function that just called
VIR_FREE, then realized I couldn't be the first person to
do that.  Sure enough, it was worth factoring into a common
helper routine.

* src/util/virhash.h (virHashValueFree): New function.
* src/util/virhash.c (virHashValueFree): Implement it.
* src/util/virobject.h (virObjectFreeHashData): New function.
* src/libvirt_private.syms (virhash.h, virobject.h): Export them.
* src/nwfilter/nwfilter_learnipaddr.c (virNWFilterLearnInit): Use
common function.
* src/qemu/qemu_capabilities.c (virQEMUCapsCacheNew): Likewise.
* src/qemu/qemu_command.c (qemuDomainCCWAddressSetCreate):
Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorGetBlockInfo): Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/util/virclosecallbacks.c (virCloseCallbacksNew): Likewise.
* src/util/virkeyfile.c (virKeyFileParseGroup): Likewise.
* tests/qemumonitorjsontest.c
(testQemuMonitorJSONqemuMonitorJSONGetBlockInfo): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-07 06:14:45 -06:00
Antoni S. Puimedon
d9de144385 QoS: make tc filters match all traffic
Up until now the traffic control filters for the vNIC QoS were
matching only ip traffic. For egress traffic that was unnoticed
because the unmatched traffic would just go to the default htb class
and be shaped anyway. For ingress, though, since the policing of the
rate is done by the filter itself.

The problem is solved by changing protocol to all and making anything
match the filter.

Bug-Url: https://bugzilla.redhat.com/1084444
Signed-off-by: Antoni S. Puimedon <asegurap@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-04-07 11:35:29 +02:00
Roman Bogorodskiy
6c91134de4 bhyve: add console support through nmdm device
nmdm is a FreeBSD driver which allows to create a pair of tty
devices one of which is passed to the guest and second is used
by the client.

This patch adds new 'nmdm' character device type. Its definition
looks this way:

<serial type='nmdm'>
  <source master='/dev/nmdm0A' slave='/dev/nmdm0B'/>
</serial>

Master is passed to the hypervisior and slave is used for client
connection.

Also implement domainOpenConsole() for bhyve driver based on that.
2014-04-05 19:12:18 +04:00
David Shane Holden
6318a80168 bhyve: domain autostart support
Signed-off-by: Roman Bogorodskiy <bogorodskiy@gmail.com>
2014-04-05 14:44:49 +04:00
Eric Blake
9673418ce5 conf: track when storage type is still undetermined
Right now, virStorageFileMetadata tracks bool backingStoreIsFile
for whether the backing string specified in metadata can be
resolved as a file (covering both block and regular file
resources) or is treated as a network protocol.  But when
merging this struct with virStorageSource, it will be easier
to just actually track which type of resource it is, as well
as have a reserved value for the case where the resource type
is unknown (or had an error during probing).

* src/util/virstoragefile.h (virStorageType): Add a placeholder
value, swap order to match similar public enum.
* src/util/virstoragefile.c (virStorage): Update string mapping.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskDefParseXML, virDomainDiskDefFormat)
(virDomainDiskSourceFormat): Adjust clients.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML):
Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-04 10:58:23 -06:00
John Ferlan
30283b8640 NFS storage pool: Fix libvirtd crash due to refactor edit
Commit id '18642d10' refactored the call to virCommandRunRegex()
inside a new function virStorageBackendFileSystemNetFindNFSPoolSources(),
but the cut-n-paste didn't remove the "&state".  Now that state is passed
by reference, it results in a libvirtd core with a messages entry:

"...internal error: unknown storage pool type Unknow"
2014-04-04 09:55:00 -04:00
Olivia Yin
82d858ce42 Define CPUINFO_FILE_LEN and fix maxlen of cpuinfo file for all uses
For example, the file /proc/cpuinfo for 24 cores PowerPC platform is larger than
the previous maximum size 2KB.
It will fail to start libvirtd with the error message as below:
virFileReadAll: Failed to read file '/proc/cpuinfo': Value too large for defined
data type
virSysinfoRead: internal error Failed to open /proc/cpuinfo

This patch defines CPUINFO_FILE_LEN as 10KB which is enough for most architectures.

Signed-off-by: Olivia Yin <Hong-Hua.Yin@freescale.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-04-04 08:08:52 +02:00
Stefan Bader
7a1452f533 libxl: Set disk format for empty cdrom device
The XML config for a CDROM device can be without a source path,
indicating that there is no media present. Without this change
the libxl driver fails to start a guest in that case because
the libxl library checks for the LIBXL_DISK_FORMAT_EMPTY format
type and tries to stat the NULL pointer that gets passed on.

> libxl: error: libxl_device.c:265:libxl__device_disk_set_backend:
> Disk vdev=hdc failed to stat: (null): Bad address

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2014-04-03 17:27:46 +02:00
Stefan Bader
0e0c1a7489 libxl: Use id from virDomainObj inside the driver
There is a domain id in the virDomain structure as well as in the
virDomainObj structure. While the former can become stale the latter
is kept up to date. So it is safer to always (virDomainObjPtr)->def->id
internally.

This will fix issues seen when managing Xen guests through libvirt from
virt-manager (not being able to get domain info after define or reboot).
This was caused both though libxlDomainGetInfo() only but there were
a lot of places that might potentially cause issues, too.

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2014-04-03 17:27:46 +02:00
Ján Tomko
c9123fbe85 Add redirdevs to ABI stability check
Check the bus, type of the source device (tcp vs. spicevmc)
and the device address visible in the guest.

https://bugzilla.redhat.com/show_bug.cgi?id=1035128
2014-04-03 15:21:38 +02:00
Ján Tomko
904e6e906b Use the force flag for mkfs -t xfs
Without this, building an XFS pool on a formatted partition
fails with --overwrite.

https://bugzilla.redhat.com/show_bug.cgi?id=927172
2014-04-03 14:10:28 +02:00
Martin Kletzander
736e017e36 qemu: make sure agent returns error when required data are missing
Commit 5b3492fa aimed to fix this and caught one error but exposed
another one.  When agent command is being executed and the thread
waiting for the reply is woken up by an event (e.g. EOF in case of
shutdown), the command finishes with no data (rxObject == NULL), but
no error is reported, since this might be desired by the caller
(e.g. suspend through agent).  However, in other situations, when the
data are required (e.g. getting vCPUs), we proceed to getting desired
data out of the reply, but none of the virJSON*() functions works well
with NULLs.  I chose the way of a new parameter for qemuAgentCommand()
function that specifies whether reply is required and behaves
according to that.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-03 09:43:25 +02:00
Ján Tomko
246317d3d9 Include PCI address in the error in virDomainNetFindIdx
When looking up a net device by a MAC and PCI address, it is possible
that we've got a match on the MAC address but failed to match the
PCI address.

In that case, outputting just the MAC address can be confusing.

Partially resolves:
https://bugzilla.redhat.com/show_bug.cgi?id=872028
2014-04-03 08:59:36 +02:00
Ján Tomko
2fbae1b2a9 Move error reporting into virDomainNetFindIdx
Every caller checked the return value and logged an error
- one if no device with the specified MAC was found,
other if there were multiple devices matching the MAC address
(except for qemuDomainUpdateDeviceConfig which logged the same
 message in both cases).

Move the error reporting into virDomainNetFindIdx, since in both cases,
we couldn't find one single match - it's just the error messages that
differ.
2014-04-03 08:59:36 +02:00
Cole Robinson
138e65c3be storage: Report error from VolOpen by default
Currently VolOpen notifies the user of a potentially non-fatal failure by
returning -2 and logging a VIR_WARN or VIR_INFO. Unfortunately most
callers treat -2 as fatal but don't actually report any message with
the error APIs.

Rename the VOL_OPEN_ERROR flag to VOL_OPEN_NOERROR. If NOERROR is specified,
we preserve the current behavior of returning -2 (there's only one caller
that wants this).

However in the default case, only return -1, and actually use the error
APIs. Fix up a couple callers as a result.
2014-04-02 12:44:16 -04:00
Ján Tomko
66050f0f89 Fix coverity-reported leak in virSecurityManagerGenLabel
Coverity complains about a possible leak of seclabel if
!sec_managers[i]->drv->domainGenSecurityLabel is true
and the seclabel might be overwritten by the next iteration
of the loop.

This leak should never happen, because every security driver
has domainGenSecurityLabel defined.
2014-04-02 15:23:01 +02:00
Eric Blake
2279d5605c conf: modify tracking of encrypted images
A future patch will merge virStorageFileMetadata and virStorageSource,
but I found it easier to do if both structs use the same information
for tracking whether a source file needs encryption keys.

* src/util/virstoragefile.h (_virStorageFileMetadata): Prepare
full encryption struct instead of just a bool.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Use transfer semantics.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/util/virstoragefile.c (virStorageFileGetMetadataInternal):
Populate struct.
(virStorageFileFreeMetadata): Adjust clients.
* tests/virstoragetest.c (testStorageChain): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:01 -06:00
Eric Blake
ac9a0963fa conf: drop redundant parameters during probe
Now that each virStorageSource can track allocation information,
and given that we already have the information without extra
syscalls, it's easier to just always populate the information
directly into the struct than it is to sometimes pass the address
of the struct members down the call chain.

* src/storage/storage_backend.h (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Update signature.
* src/storage/storage_backend.c (virStorageBackendUpdateVolInfo)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Always populate struct
members instead.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol): Update client.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:01 -06:00
Eric Blake
cce2410a27 conf: track sizes directly in source struct
One of the features of qcow2 is that a wrapper file can have
more capacity than its backing file from the guest's perspective;
what's more, sparse files make tracking allocation of both
the active and backing file worthwhile.  As such, it makes
more sense to show allocation numbers for each file in a chain,
and not just the top-level file.  This sets up the fields for
the tracking, although it does not modify XML to display any
new information.

* src/util/virstoragefile.h (_virStorageSource): Add fields.
* src/conf/storage_conf.h (_virStorageVolDef): Drop redundant
fields.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(createRawFile, virStorageBackendCreateQemuImgCmd)
(virStorageBackendCreateQcowCreate): Update clients.
* src/storage/storage_driver.c (storageVolDelete)
(storageVolCreateXML, storageVolCreateXMLFrom, storageVolResize)
(storageVolWipeInternal, storageVolGetInfo): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget)
(virStorageBackendFileSystemRefresh)
(virStorageBackendFileSystemVolResize)
(virStorageBackendFileSystemVolRefresh): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalMakeVol)
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_scsi.c
(virStorageBackendSCSINewLun): Likewise.
* src/storage/storage_backend_mpath.c
(virStorageBackendMpathNewVol): Likewise.
* src/storage/storage_backend_rbd.c
(volStorageBackendRBDRefreshVolInfo)
(virStorageBackendRBDCreateImage): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskCreateVol): Likewise.
* src/storage/storage_backend_sheepdog.c
(virStorageBackendSheepdogBuildVol)
(virStorageBackendSheepdogParseVdiList): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageBackendGlusterRefreshVol): Likewise.
* src/conf/storage_conf.c (virStorageVolDefFormat)
(virStorageVolDefParseXML): Likewise.
* src/test/test_driver.c (testOpenVolumesForPool)
(testStorageVolCreateXML, testStorageVolCreateXMLFrom)
(testStorageVolDelete, testStorageVolGetInfo): Likewise.
* src/esx/esx_storage_backend_iscsi.c (esxStorageVolGetXMLDesc):
Likewise.
* src/esx/esx_storage_backend_vmfs.c (esxStorageVolGetXMLDesc)
(esxStorageVolCreateXML): Likewise.
* src/parallels/parallels_driver.c (parallelsAddHddByVolume):
Likewise.
* src/parallels/parallels_storage.c (parallelsDiskDescParseNode)
(parallelsStorageVolDefineXML, parallelsStorageVolCreateXMLFrom)
(parallelsStorageVolDefRemove, parallelsStorageVolGetInfo):
Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolCreateXML)
(vboxStorageVolGetXMLDesc): Likewise.
* tests/storagebackendsheepdogtest.c (test_vdi_list_parser):
Likewise.
* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Likewise.
2014-04-02 06:03:00 -06:00
Eric Blake
df17611525 conf: use common struct in storage volumes
A fairly smooth transition.  And now that domain disks and
storage volumes share a common struct, it opens the doors for
a future patch to expose more details in the XML for both
objects.

* src/conf/storage_conf.h (_virStorageVolTarget): Delete.
(_virStorageVolDef): Use common type.
* src/conf/storage_conf.c (virStorageVolDefFree)
(virStorageVolTargetDefFormat): Update clients.
* src/storage/storage_backend.h: Likewise.
* src/storage/storage_backend.c
(virStorageBackendDetectBlockVolFormatFD)
(virStorageBackendUpdateVolTargetInfo)
(virStorageBackendUpdateVolTargetInfoFD): Likewise.
* src/storage/storage_backend_fs.c (virStorageBackendProbeTarget):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:00 -06:00
Eric Blake
2a4fd2281e conf: move volume structs to util/
Another step towards unification of structures.  While we might
not expose everything in XML via domain disk as we do for
storage volume pointer, both places want to deal with (at least
part of) the backing chain; therefore, moving towards a single
struct usable from both contexts will make the backing chain
code more reusable.

* src/conf/storage_conf.h (_virStoragePerms)
(virStorageTimestamps): Move...
* src/util/virstoragefile.h: ...here.
(_virStorageSource): Add more fields.
* src/util/virstoragefile.c (virStorageSourceClear): Clean
additional fields.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:00 -06:00
Eric Blake
dae1568c6c conf: tweak volume target struct details
Some preparatory work before consolidating storage volume
structs with the rest of virstoragefile.  Making these
changes allows a volume target to be much closer to (a
subset of) the virStorageSource struct.

Making perms be a pointer allows it to be optional if we
have a storage pool that doesn't expose permissions in a
way we can access.  It also allows future patches to
optionally expose permissions details learned about a disk
image via domain <disk> listings, rather than just
limiting it to storage volume listings.

Disk partition types was only used by internal code to
control what type of partition to create when carving up
an MS-DOS partition table storage pool (and is not used
for GPT partition tables or other storage pools).  It was
not exposed in volume XML, and as it is more closely
related to extent information of the overall block device
than it is to the <target> information describing the host
file.  Besides, if we ever decide to expose it in XML down
the road, we can move it back as needed.

* src/conf/storage_conf.h (_virStorageVolTarget): Change perms to
pointer, enhance comments.  Move partition type...
(_virStorageVolSource): ...here.
* src/conf/storage_conf.c (virStorageVolDefFree)
(virStorageVolDefParseXML, virStorageVolTargetDefFormat): Update
clients.
* src/storage/storage_backend_fs.c (createFileDir): Likewise.
* src/storage/storage_backend.c (virStorageBackendCreateBlockFrom)
(virStorageBackendCreateRaw, virStorageBackendCreateExecCommand)
(virStorageBackendUpdateVolTargetInfoFD): Likewise.
* src/storage/storage_backend_logical.c
(virStorageBackendLogicalCreateVol): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskMakeDataVol)
(virStorageBackendDiskPartTypeToCreate): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:00 -06:00
Eric Blake
c99efbcd2a conf: manage disk source by struct instead of pieces
Now that we have a dedicated type for representing a disk source,
we might as well parse and format directly into that type instead
of piecemeal into pointers to members of the type.

* src/conf/domain_conf.h (virDomainDiskSourceDefFormatInternal)
(virDomainDiskSourceDefParse): Rename...
(virDomainDiskSourceFormat, virDomainDiskSourceParse): ...and
compress signatures.
* src/conf/domain_conf.c (virDomainDiskSourceParse)
(virDomainDiskSourceFormat): Rewrite to use common struct.
(virDomainDiskSourceDefFormat): Delete.
(virDomainDiskDefParseXML, virDomainDiskDefFormat): Update
callers.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotDiskDefFormat): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:00 -06:00
Eric Blake
93d4585e75 phyp: fix logic error on volume creation
The phyp code claims that it wants a non-zero value, but actually
enforces a capacity of zero.  It has been this way since commit
ebc46fe in June 2010.  Bummer that it has my name as the committer
- I guess I should have been much more stubborn about not blindly
taking someone else's 1600-line patch.

* src/phyp/phyp_driver.c (phypStorageVolCreateXML): Use correct
logic.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-02 06:03:00 -06:00
Martin Kletzander
e9d09fe196 qemu: remove unneeded forward declaration
by moving qemuAgentCommand() after qemuAgentCheckError().

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-02 13:59:32 +02:00
Martin Kletzander
5b3492fadb qemu: cleanup error checking on agent replies
On all the places where qemuAgentComand() was called, we did a check
for errors in the reply.  Unfortunately, some of the places called
qemuAgentCheckError() without checking for non-null reply which might
have resulted in a crash.

So this patch makes the error-checking part of qemuAgentCommand()
itself, which:

 a) makes it look better,

 b) makes the check mandatory and, most importantly,

 c) checks for the errors if and only if it is appropriate.

This actually fixes a potential crashers when qemuAgentComand()
returned 0, but reply was NULL.  Having said that, it *should* fix the
following bug:

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-02 07:47:01 +02:00
Eric Blake
17f826363d maint: fix spelling errors in disk pools
Noticed during my work on storage struct cleanups.

* src/storage/storage_backend_disk.c
(virStorageBackendDiskPartBoundaries): Fix spelling errors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 16:26:59 -06:00
Eric Blake
ca1ee0fd84 conf: let snapshots share disk source struct
Now that we have a common struct, it's time to start using it!
Since external snapshots make a longer backing chain, it is
only natural to use the same struct for the file created by
the snapshot as what we use for <domain> disks.

* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Use common
struct instead of open-coded duplicate fields.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear)
(virDomainSnapshotDiskDefParseXML, virDomainSnapshotAlignDisks)
(virDomainSnapshotDiskDefFormat)
(virDomainSnapshotDiskGetActualType): Adjust clients.
* src/qemu/qemu_conf.c (qemuTranslateSnapshotDiskSourcePool):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDiskGetSourceString)
(qemuDomainSnapshotCreateInactiveExternal)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/storage/storage_driver.c
(virStorageFileInitFromSnapshotDef): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:15 -06:00
Eric Blake
7a4fd22b17 conf: move common disk source functions
Move some functions out of domain_conf for use in the next
patch where snapshot starts to directly use structs in
virstoragefile.

* src/conf/domain_conf.c (virDomainDiskDefFree)
(virDomainDiskSourcePoolDefParse): Adjust callers.
(virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefFree)
(virDomainDiskAuthClear): Move...
* src/util/virstoragefile.c (virStorageSourceClear)
(virStorageSourcePoolDefFree, virStorageSourceAuthClear): ...and
rename.
* src/conf/domain_conf.h (virDomainDiskAuthClear): Drop
declaration.
* src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Adjust
caller.
* src/util/virstoragefile.h: Declare them.
* src/libvirt_private.syms (virstoragefile.h): Export them.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
885ac290ea util: don't support loopback and nbd when setuid
The only remaining reason that virt-login-shell was trying to
link against virstoragefile was because of a call to
virStorageFileFormatTypeToString when spawning a qemu-nbd
process - but setuid processes shouldn't be spawning qemu-nbd.

* src/util/virfile.c (virFileLoopDeviceAssociate)
(virFileNBDDeviceAssociate): Cripple in setuid builds.
* src/Makefile.am (libvirt_setuid_rpc_client_la_SOURCES):
Drop virstoragefile from the list.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
5160ab795a util: move detection of shared filesystems
The code in virstoragefile.c is getting more complex as I
consolidate backing chain handling code.  But for the setuid
virt-login-shell, we don't need to crawl backing chains.  It's
easier to audit things for setuid security if there are fewer
files involved, so this patch moves the one function that
virFileOpen() was actually relying on to also live in virfile.c.

* src/util/virstoragefile.c (virStorageFileIsSharedFS)
(virStorageFileIsSharedFSType): Move...
* src/util/virfile.c (virFileIsSharedFS, virFileIsSharedFSType):
...to here, and rename.
(virFileOpenAs): Update caller.
* src/security/security_selinux.c
(virSecuritySELinuxSetFileconHelper)
(virSecuritySELinuxSetSecurityAllLabel)
(virSecuritySELinuxRestoreSecurityImageLabelInt): Likewise.
* src/security/security_dac.c
(virSecurityDACRestoreSecurityImageLabelInt): Likewise.
* src/qemu/qemu_driver.c (qemuOpenFileAs): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/util/virstoragefile.h: Adjust declarations.
* src/util/virfile.h: Likewise.
* src/libvirt_private.syms (virfile.h, virstoragefile.h): Move
symbols as appropriate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
8a20e227f6 conf: move storage source type to util/
With this patch, all information related to a host resource in
a storage file backing chain now lives in util/virstoragefile.h.
The next step will be to consolidate various places that have
been tracking backing chain details to all use a common struct.

The changes to tools/Makefile.am were made necessary by the
fact that virstorageencryption includes uses of libxml, and is
now pulled in by inclusion from virstoragefile.h.  No
additional libraries are linked into the final image, and in
comparison, the build of the setuid library in src/Makefile.am
already was using LIBXML_CFLAGS via AM_CFLAGS.

* src/conf/domain_conf.h (virDomainDiskSourceDef): Move...
* src/util/virstoragefile.h (virStorageSource): ...and rename.
* src/conf/domain_conf.c (virDomainDiskSourceDefClear)
(virDomainDiskAuthClear): Adjust clients.
* tools/Makefile.am (virt_login_shell_CFLAGS)
(virt_host_validate_CFLAGS): Add libxml headers.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
c05d9dcad7 conf: move storage secret type to util/
This one is a relatively easy move.  We don't ever convert the
enum to or from strings (it is inferred from other elements in
the xml, rather than directly represented).

* src/conf/domain_conf.h (virDomainDiskSecretType): Move...
* src/util/virstoragefile.h (virStorageSecreteType): ...and
rename.
* src/conf/domain_conf.c (virDomainDiskSecretType): Drop unused
enum conversion.
(virDomainDiskAuthClear, virDomainDiskDefParseXML)
(virDomainDiskDefFormat): Adjust clients.
* src/qemu/qemu_command.c (qemuGetSecretString): Likewise.
* src/qemu/qemu_conf.c (qemuTranslateDiskSourcePoolAuth):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
b6edf2bfb4 conf: move source pool type to util/
Another struct being moved to util.  This one doesn't have as
much use yet, thankfully.

* src/conf/domain_conf.h (virDomainDiskSourcePoolMode)
(virDomainDiskSourcePoolDef): Move...
* src/util/virstoragefile.h (virStorageSourcePoolMode)
(virStorageSourcePoolDef): ...and rename.
* src/conf/domain_conf.c (virDomainDiskSourcePoolDefFree)
(virDomainDiskSourceDefClear, virDomainDiskSourcePoolDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Adjust clients.
* src/qemu/qemu_conf.c (qemuTranslateDiskSourcePool): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -06:00
Eric Blake
8fc328592c conf: move storage encryption type to util/
Encryption keys can be associated with each source file in a
backing chain; as such, this file belongs more in util/ where
it can be used by virstoragefile.h.

* src/conf/storage_encryption_conf.h: Rename...
* src/util/virstorageencryption.h: ...to this.
* src/conf/storage_encryption_conf.c: Rename...
* src/util/virstorageencryption.c: ...to this.
* src/Makefile.am (ENCRYPTION_CONF_SOURCES, CONF_SOURCES)
(UTIL_SOURCES): Update to new file names.
* src/libvirt_private.syms: Likewise.
* src/conf/domain_conf.h: Update client.
* src/conf/storage_conf.h: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:13 -06:00
Eric Blake
4220f76aed conf: move network disk protocol type to util/
Another enum moved to util/, this time the fallout from renaming
is not quite as large.

* src/conf/domain_conf.h (virDomainDiskProtocol): Move...
* src/util/virstoragefile.h (virStorageNetProtocol): ...and
rename.
* src/conf/domain_conf.c: Update clients.
* src/qemu/qemu_command.c: Likewise.
* src/qemu/qemu_conf.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/qemu/qemu_migration.c: Likewise.
* src/storage/storage_backend.c: Likewise.
* src/storage/storage_backend_gluster.c: Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:13 -06:00
Eric Blake
16ac4c9d64 conf: move host disk type to util/
A continuation of the migration of disk details to virstoragefile.
This patch moves a single enum, but converting the name has quite
a bit of fallout.

* src/conf/domain_conf.h (virDomainDiskType): Move...
* src/util/virstoragefile.h (virStorageType): ...and rename.
* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Update clients.
* src/conf/domain_conf.c (virDomainDiskSourceDefParse)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormatInternal)
(virDomainDiskDefFormat, virDomainDiskGetActualType)
(virDomainDiskDefForeachPath, virDomainDiskSourceIsBlockType):
Likewise.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefParseXML)
(virDomainSnapshotAlignDisks, virDomainSnapshotDiskDefFormat):
Likewise.
* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Likewise.
* src/locking/domain_lock.c (virDomainLockManagerAddDisk):
Likewise.
* src/lxc/lxc_controller.c
(virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/parallels/parallels_driver.c (parallelsGetHddInfo):
Likewise.
* src/phyp/phyp_driver.c (phypDiskType): Likewise.
* src/qemu/qemu_command.c (qemuGetDriveSourceString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuTranslateDiskSourcePool)
(qemuTranslateSnapshotDiskSourcePool): Likewise.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainDetermineDiskChain): Likewise.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskExternalBackingActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayActive)
(qemuDomainSnapshotPrepareDiskExternalOverlayInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/security/security_apparmor.c
(AppArmorRestoreSecurityImageLabel)
(AppArmorSetSecurityImageLabel): Likewise.
* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.
* src/storage/storage_backend.c (virStorageFileBackendForType):
Likewise.
* src/storage/storage_backend_fs.c (virStorageFileBackendFile)
(virStorageFileBackendBlock): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGluster): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Likewise.
* src/vmware/vmware_conf.c (vmwareVmxPath): Likewise.
* src/vmx/vmx.c (virVMXParseDisk, virVMXFormatDisk)
(virVMXFormatFloppy): Likewise.
* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk): Likewise.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk): Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:13 -06:00
Eric Blake
52fb53119a conf: split network host structs to util/
Continuing the refactoring of host-side storage descriptions out
of conf/domain_conf and into util/virstoragefile, this patch
focuses on details about a host name/port/transport as used by
a network storage volume.

* src/conf/domain_conf.h (virDomainDiskProtocolTransport)
(virDomainDiskHostDef, virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): Move...
* src/util/virstoragefile.h (virStorageNetHostTransport)
(virStorageNetHostDef, virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): ...here,
with better names.
* src/util/virstoragefile.c (virStorageNetHostDefClear)
(virStorageNetHostDefFree, virStorageNetHostDefCopy): Moved from...
* src/conf/domain_conf.c (virDomainDiskHostDefClear)
(virDomainDiskHostDefFree, virDomainDiskHostDefCopy): ...here.
(virDomainDiskSourceDefClear, virDomainDiskSourceDefParse)
(virDomainDiskSourceDefFormatInternal): Adjust callers.
* src/conf/snapshot_conf.h (_virDomainSnapshotDiskDef): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotDiskDefClear):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost)
(qemuParseDriveURIString, qemuParseNBDString)
(qemuBuildNetworkDriveURI, qemuParseCommandLineDisk)
(qemuParseCommandLine, qemuGetDriveSourceString): Likewise.
* src/qemu/qemu_command.h: Likewise.
* src/qemu/qemu_conf.c (qemuAddISCSIPoolSourceHost)
(qemuTranslateDiskSourcePool): Likewise.
* src/qemu/qemu_driver.c
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive): Likewise.
* src/storage/storage_backend_gluster.c
(virStorageFileBackendGlusterInit): Likewise.
* src/storage/storage_driver.c (virStorageFileFree)
(virStorageFileInitInternal): Likewise.
* src/storage/storage_driver.h (_virStorageFile): Likewise.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virstoragefile.h): ...as appropriate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:12 -06:00
Eric Blake
3e92938656 conf: split security label structs to util/
In order to reuse the newly-created host-side disk struct in
the virstoragefile backing chain code, I first have to move
it to util/.  This starts the process, by first moving the
security label structures.

* src/conf/domain_conf.h (virDomainDefGenSecurityLabelDef)
(virDomainDiskDefGenSecurityLabelDef, virSecurityLabelDefFree)
(virSecurityDeviceLabelDefFree, virSecurityLabelDef)
(virSecurityDeviceLabelDef): Move...
* src/util/virseclabel.h: ...to new file.
(virSecurityLabelDefNew, virSecurityDeviceLabelDefNew): Rename the
GenSecurity functions.
* src/qemu/qemu_process.c (qemuProcessAttach): Adjust callers.
* src/security/security_manager.c (virSecurityManagerGenLabel):
Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxSetSecurityFileLabel): Likewise.
* src/util/virseclabel.c: New file.
* src/conf/domain_conf.c: Move security code, and fix fallout.
* src/Makefile.am (UTIL_SOURCES): Build new file.
* src/libvirt_private.syms (domain_conf.h): Move symbols...
(virseclabel.h): ...to new section.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:12 -06:00
Peter Krempa
cb93802958 storage: gluster: Implement storage pool lookup
Use the previously implemented function to lookup glusterfs source pools
for the netfs pool to lookup native gluster pools too.
2014-04-01 11:06:06 +02:00
Peter Krempa
05671b95db storage: netfs: Support lookup of glusterfs pool sources
https://bugzilla.redhat.com/show_bug.cgi?id=1072714

Use the "gluster" command line tool to retrieve information about remote
volumes on a gluster server to allow storage pool source lookup.

Unfortunately gluster doesn't provide a management library so that we
could use that directly, instead the RPC calls are hardcoded in the
command line tool.
2014-04-01 11:06:05 +02:00
Peter Krempa
18642d100f storage: netfs: Split up and tidy up NFS storage pool source function
Extract the NFS related stuff into a separate function and tidy up the
rest of the code so we can reuse it to add gluster backend detection.

Additionally avoid reporting of errors from "showmount" and return an
empty source list instead. This will help when adding other detection
backends.
2014-04-01 11:06:05 +02:00
Martin Kletzander
7975216035 build: fix syntax-check for storage_backend
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-04-01 08:53:27 +02:00
Peter Krempa
0f6c50b9b6 gluster: Fix "key" attribute for gluster volumes
According to our documentation the "key" value has the following
meaning: "Providing an identifier for the volume which identifies a
single volume." The currently used keys for gluster volumes consist of
the gluster volume name and file path. This can't be considered unique
as a different storage server can serve a volume with the same name.

Unfortunately I wasn't able to figure out a way to retrieve the gluster
volume UUID which would avoid the possibility of having two distinct
keys identifying a single volume.

Use the full URI as the key for the volume to avoid the more critical
ambiguity problem and document the possible change to UUID.
2014-04-01 08:44:34 +02:00
Cole Robinson
fa5b5549cb storage: Rename VolOpenCheckMode to VolOpen
Remove the original VolOpen implementation, which is now only used in
one spot.
2014-03-31 18:32:03 -04:00
Cole Robinson
847a9eb17e storage: move block format lookup to shared UpdateVolInfo 2014-03-31 18:31:00 -04:00
Cole Robinson
16d75d19fc storage: Rename UpdateVolInfoFlags to UpdateVolInfo
And drop the original UpdateVolInfo. Makes it a bit easier to follow
the function usage.

And change the int parameter to an explicit bool.
2014-03-31 18:30:35 -04:00
Roman Bogorodskiy
1d8be34334 bhyve: don't leak tap devices on failures
On failures, virBhyveProcessStart() does not cleanup network
interfaces that could be created by virBhyveProcessBuildBhyveCmd(),
which results in a leaked tap device.

To fix that, extract network cleanup code to bhyveNetCleanup()
and use it in cleanup stage of virBhyveProcessStart().
2014-03-31 16:54:30 +04:00
Hongwei Bi
4ef09c4690 util: remove useless comment for virCgroupMoveTask in vircgroup.c
Signed-off-by: Hongwei Bi <hwbi2008@gmail.com>
2014-03-31 14:16:05 +02:00
Peter Krempa
6c312b0d1e util: storagefile: Don't pursue backing chain of NULL image
When virStorageFileGetMetadata is called with NULL path argument, the
invalid pointer boils down through the recursive worker and is caught by
virHashAddEntry which is thankfully resistant to NULL arguments. As it
doesn't make sense to pursue backing chains of NULL volumes, exit
earlier.

This was noticed in the virt-aahelper-test with a slightly modified
codebase.
2014-03-31 13:47:50 +02:00
Peter Krempa
ce5ec2f1da storage: gluster: Fix crash when initialization of storage backend fails
The libgfapi function glfs_fini doesn't tolerate NULL pointers. Add a
check on the error paths as it's possible to crash libvirtd if the
gluster volume can't be initialized.
2014-03-31 13:47:50 +02:00
Peter Krempa
8617e8c8bb storage: pool: Fix XML indentation in pool source lookup
The <source> elements need to be indented from <sources> elements.
2014-03-31 13:47:24 +02:00
Dawid Zamirski
5cc3cce5cc ESX: Add support for virtualHW version 10
This follows the same pattern when v8 and v9 were added. I've tested
this with my ESX 5.5 and seems to work fine.
2014-03-30 13:51:03 +02:00
Jincheng Miao
15a173fc13 Fix virNodeDeviceListCaps always returns empty
virNodeDeviceListCaps will always return empty for a pci nodedevice,
actually it should return 'pci'.

It is because the loop variable ncaps isn't increased.

Introduced by commit be2636f.

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

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-03-29 06:51:10 +01:00
Ján Tomko
63f22dc80f Create hostdevmgr in UserRuntimeDirectory for session libvirt
Without this, session libvirt won't start if it fails to create
the directory.
2014-03-28 10:07:52 +01:00
Ján Tomko
1fc4846b09 Remove double free in virHostdevManagerDispose
The object itself is freed by virObjectUnref.
2014-03-28 10:07:32 +01:00
Cédric Bosdonnat
74e86b6b25 Fix apparmor profile to make vfio pci passthrough work
See lp#1276719 for the bug description. As virt-aa-helper doesn't know
the VFIO groups to use for the guest, allow access to all
/dev/vfio/[0-9]* and /dev/vfio/vfio files if there is a potential need
for vfio

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 09:09:23 -06:00
Cédric Bosdonnat
0500fbd4b6 Fixed regression in apparmor profiles for qemu brought by 43c030f 2014-03-27 09:04:08 -06:00
Nehal J Wani
faad5582e4 Fix Memory Leak in virQEMUCapsInitGuestFromBinary()
While running qemucaps2xmltest, it was found that valgrind pointed out
the following memory leaks:

==29896== 0 bytes in 1 blocks are definitely lost in loss record 1 of 65
==29896==    at 0x4A0577B: calloc (vg_replace_malloc.c:593)
==29896==    by 0x4C6B45E: virAllocN (viralloc.c:191)
==29896==    by 0x4232A9: virQEMUCapsGetMachineTypesCaps (qemu_capabilities.c:1999)
==29896==    by 0x4234E7: virQEMUCapsInitGuestFromBinary (qemu_capabilities.c:789)
==29896==    by 0x41F10B: testQemuCapsXML (qemucaps2xmltest.c:118)
==29896==    by 0x41FFD1: virtTestRun (testutils.c:201)
==29896==    by 0x41EE7A: mymain (qemucaps2xmltest.c:203)
==29896==    by 0x42074D: virtTestMain (testutils.c:789)
==29896==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)
==29896==
==29896== 0 bytes in 1 blocks are definitely lost in loss record 2 of 65
==29896==    at 0x4A0577B: calloc (vg_replace_malloc.c:593)
==29896==    by 0x4C6B45E: virAllocN (viralloc.c:191)
==29896==    by 0x4232A9: virQEMUCapsGetMachineTypesCaps (qemu_capabilities.c:1999)
==29896==    by 0x4234E7: virQEMUCapsInitGuestFromBinary (qemu_capabilities.c:789)
==29896==    by 0x41F10B: testQemuCapsXML (qemucaps2xmltest.c:118)
==29896==    by 0x41FFD1: virtTestRun (testutils.c:201)
==29896==    by 0x41EEA3: mymain (qemucaps2xmltest.c:204)
==29896==    by 0x42074D: virtTestMain (testutils.c:789)
==29896==    by 0x3E6CE1ED1C: (below main) (libc-start.c:226)

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 07:03:04 -06:00
Hongwei Bi
b2ed4f68b4 util: fix a typo in virprocess.c and docs
s/forcably/forcibly

Signed-off-by: Hongwei Bi <hwbi2008@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-27 06:58:46 -06:00
Wojciech Macek
8433de2e1d bhyve: add domainLookupByID
Implement domain lookup by its ID.
2014-03-27 11:46:39 +04:00
Roman Bogorodskiy
a1bd8d2546 Move virBhyveTapGetRealDeviceName to virnetdevtap
To ease mocking for bhyve unit tests move virBhyveTapGetRealDeviceName()
out of bhyve_command.c to virnetdevtap and rename it to
virNetDevTapGetRealDeviceName().
2014-03-27 08:23:58 +04:00
Laine Stump
6612d1adb7 network: fix problems with SRV records
A patch submitted by Steven Malin last week pointed out a problem with
libvirt's DNS SRV record configuration:

  https://www.redhat.com/archives/libvir-list/2014-March/msg00536.html

When searching for that message later, I found another series that had
been posted by Guannan Ren back in 2012 that somehow slipped between
the cracks:

  https://www.redhat.com/archives/libvir-list/2012-July/msg00236.html

That patch was very much out of date, but also pointed out some real
problems.

This patch fixes all the noted problems by refactoring
virNetworkDNSSrvDefParseXML() and networkDnsmasqConfContents(), then
verifies those fixes by added several new records to the test case.

Problems fixed:

* both service and protocol now have an underscore ("_") prepended on
  the commandline, as required by RFC2782.

  <srv service='sip' protocol='udp' domain='example.com'
       target='tests.example.com' port='5060' priority='10'
       weight='150'/>

  before: srv-host=sip.udp.example.com,tests.example.com,5060,10,150
  after:  srv-host=_sip._udp.example.com,tests.example.com,5060,10,150

* if "domain" wasn't specified in the <srv> element, the extra
  trailing "." will no longer be added to the dnsmasq commandline.

  <srv service='sip' protocol='udp' target='tests.example.com'
       port='5060' priority='10' weight='150'/>

  before: srv-host=sip.udp.,tests.example.com,5060,10,150
  after:  srv-host=_sip._udp,tests.example.com,5060,10,150

* when optional attributes aren't specified, the separating comma is
  also now not placed on the dnsmasq commandline. If optional
  attributes in the middle of the line are not specified, they are
  replaced with a default value in the commandline (1 for port, 0 for
  priority and weight).

  <srv service='sip' protocol='udp' target='tests.example.com'
       port='5060'/>

  before: srv-host=sip.udp.,tests.example.com,5060,,
  after:  srv-host=_sip._udp,tests.example.com,5060

  (actually the would have generated an error, because "optional"
  attributes weren't really optional.)

* The allowed characters for both service and protocol are now limited
  to alphanumerics, plus a few special characters that are found in
  existing names in /etc/services and /etc/protocols. (One exception
  is that both of these files contain names with an embedded ".", but
  "."  can't be used in these fields of an SRV record because it is
  used as a field separator and there is no method to escape a "."
  into a field.) (Previously only the strings "tcp" and "udp" were
  allowed for protocol, but this restriction has been removed, since
  RFC2782 specifically says that it isn't limited to those, and that
  anyway it is case insensitive.)

* the "domain" attribute is no longer required in order to recognize
  the port, priority, and weight attributes during parsing. Only
  "target" is required for this.

* if "target" isn't specified, port, priority, and weight are not
  allowed (since they are meaningless - an empty target means "this
  service is *not available* for this domain").

* port, priority, and weight are now truly optional, as the comments
  originally suggested, but which was not actually true.
2014-03-26 16:42:43 +02:00
Ján Tomko
9d4306868c Shift the for loop over matched vars by one
Instead of adding one to the iterator on every use.
2014-03-26 15:06:10 +01:00
Ján Tomko
25c49db506 Use VIR_STRNDUP instead of modifying the matched string 2014-03-26 15:06:10 +01:00
Ján Tomko
d223cd76c3 Free groups in case of a partial match
If there are more than two regexes, but only one of them matches,
the matched groups would be leaked.
2014-03-26 15:06:10 +01:00
Ján Tomko
cf4fb7d9a0 Simplify the loop in virCommandRunRegex
Do not check for border iterator values inside the loop,
move the code before/after the loop instead.
2014-03-26 15:06:09 +01:00
Ján Tomko
f01f62d43d Remove useless 'maxReg' variable
It is used to break out of the loop early if one regex does not match.
Use the 'break' statement instead.
2014-03-26 15:06:09 +01:00
Michal Privoznik
220c0031fe qemuDomainAttachDeviceFlags: Parse device xml as inactive
In all other drivers we are doing so. Moreover, we don't want to parse
runtime information in attach (even if the attach is meant as live)
because we are generating the runtime info ourselves. We can't trust
users they supply sane values anyway.

==1140== 9 bytes in 1 blocks are definitely lost in loss record 72 of 1,151
==1140==    at 0x4A06C2B: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==1140==    by 0x623C758: xmlStrndup (in /usr/lib64/libxml2.so.2.9.1)
==1140==    by 0x50FD763: virXMLPropString (virxml.c:483)
==1140==    by 0x510F8B7: virDomainDeviceInfoParseXML (domain_conf.c:3685)
==1140==    by 0x511ACFD: virDomainChrDefParseXML (domain_conf.c:7535)
==1140==    by 0x5121D13: virDomainDeviceDefParse (domain_conf.c:9918)
==1140==    by 0x13AE6313: qemuDomainAttachDeviceFlags (qemu_driver.c:6926)
==1140==    by 0x13AE65FA: qemuDomainAttachDevice (qemu_driver.c:7005)
==1140==    by 0x51C77DA: virDomainAttachDevice (libvirt.c:10231)
==1140==    by 0x127FDD: remoteDispatchDomainAttachDevice (remote_dispatch.h:2404)
==1140==    by 0x127EC5: remoteDispatchDomainAttachDeviceHelper (remote_dispatch.h:2382)
==1140==    by 0x5241F81: virNetServerProgramDispatchCall (virnetserverprogram.c:437)

When doing live attach, we are passing the inactive definition anyway
since we are passing the result of virDomainDeviceDefCopy() which does
inactive copy by default.

Moreover, we are doing the same mistake in qemuhotplugtest.

Just a side note - it makes perfect sense to parse the runtime info
like alias in qemuDomainDetachDevice and qemuDomainUpdateDeviceFlags()
as in some cases the only difference to distinguish two devices can be
just their alias.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-26 13:49:47 +01:00
Francesco Romani
f35e89ffc1 qemu: extract guest capabilities initialization
This patch decouples the binary and the capabilities detection
from the guest initialization.

The purpose is to make testing easier.
2014-03-26 13:41:25 +01:00
Francesco Romani
85a3eb8a6d qemu: export disk snapshot support in capabilities
This patch adds an element to QEMU's capability XML, to
show if the underlying QEMU binary supports the live disk
snapshotting or not.
This allows any client to know ahead of time if the feature
is available.

Without this information available, the only way to check
for the snapshot support is to request one and check for
errors.

Signed-off-by: Francesco Romani <fromani@redhat.com>
2014-03-26 13:41:25 +01:00
Ján Tomko
97814d8ab3 Show the real cpu shares value in live XML
Currently, the Linux kernel treats values of '0' and '1' as
the minimum of 2. Values larger than the maximum are changed
to the maximum.

Re-reading the shares value after setting it reflects this in
the live domain XML.
2014-03-26 10:10:13 +01:00
Ján Tomko
bdffab0d5c Treat zero cpu shares as a valid value
Currently, <cputune><shares>0</shares></cputune> is treated
as if it were not specified.

Treat is as a valid value if it was explicitly specified
and write it to the cgroups.
2014-03-26 10:10:02 +01:00
John Ferlan
c668cd50cb Coverity: Resolve a RESOURCE_LEAK
On error the lofd would have been leaked.
2014-03-25 17:19:49 -04:00
John Ferlan
b2e4ace220 Coverity: Resolve a CHECKED_RETURN message
Recent changes to the module seemed to have caused Coverity to find a new
issue regarding the failure to check the return from a sendmsg. The code
doesn't seem to care about the return status, so just added an ignore_value
to keep Coverity quiet.
2014-03-25 17:13:27 -04:00
Tomoki Sekiyama
ff436380bc qemu: remove redundant virQEMUDriverGetConfig
qemuDomainSetSchedulerParametersFlags() calls virQEMUDriverGetConfig() twice
and makes the reference counter leak. This removes redundant call.

Problem introduced in commit 45ad1ad

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-25 15:07:49 -06:00
Roman Bogorodskiy
425eeed8c4 bhyve: don't fail on busy tap devices
We use virBhyveTapGetRealDeviceName() to map network interface name
to a real device path, trying to open possible devices and getting
names by ioctl.

Make it skip devices that fail to open with EBUSY because they're
most likely already used by other VMs.
2014-03-25 20:47:32 +04:00
Stefan Bader
139efe758c libxl: Create log directory earlier
Commit d9f19c30d0 moved a lot of the
configuration setup into libxlDriverConfigNew().
However that tries to create the libxl/libxl-driver.log before the
libxl directory gets created in libxlStateInitialize().

This causes the daemon to fail on systems that have not had the directory
created before.

Move the code to create the libxl directory into libxlDriverConfigNew().

Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
2014-03-25 10:14:06 -06:00
Ján Tomko
9e7ecabf94 Indent top-level labels by one space in the rest of src/ 2014-03-25 14:58:40 +01:00
Ján Tomko
6ffbc3e46d Indent top-level labels by one space in src/xen/ 2014-03-25 14:58:40 +01:00
Ján Tomko
8c6690c1df Indent top-level labels by one space in src/vbox/ 2014-03-25 14:58:40 +01:00
Ján Tomko
bada4222e5 Indent top-level labels by one space in src/util/ 2014-03-25 14:58:40 +01:00
Ján Tomko
d336111ee6 Indent top-level labels by one space in src/test/ 2014-03-25 14:58:40 +01:00
Ján Tomko
3eda88e94c Indent top-level labels by one space in src/storage/ 2014-03-25 14:58:40 +01:00
Ján Tomko
b69f99229c Indent top-level labels by one space in src/rpc/ 2014-03-25 14:58:40 +01:00
Ján Tomko
cdfaaa0a7f Indent top-level labels by one space in src/remote/ 2014-03-25 14:58:40 +01:00
Ján Tomko
5922d05aec Indent top-level labels by one space in src/qemu/ 2014-03-25 14:58:39 +01:00
Ján Tomko
34ff191cc9 Indent top-level labels by one space in src/parallels/ 2014-03-25 14:58:39 +01:00
Ján Tomko
5d8315975e Indent top-level labels by one space in src/nwfilter/ 2014-03-25 14:58:39 +01:00
Ján Tomko
c97cfce291 Indent top-level labels by one space in src/network/ 2014-03-25 14:58:39 +01:00
Ján Tomko
1577e2d497 Indent top-level labels by one space in src/lxc/ 2014-03-25 14:58:39 +01:00
Ján Tomko
40cc610a9d Indent top-level labels by one space in src/locking/ 2014-03-25 14:58:39 +01:00
Ján Tomko
d46f4a3c1f Indent top-level labels by one space in libvirt.c 2014-03-25 14:58:39 +01:00
Ján Tomko
37a0c27318 Indent top-level labels by one space in src/libxl/ 2014-03-25 14:58:38 +01:00
Ján Tomko
2bd4a172b1 Indent top-level labels by one space in src/esx/ 2014-03-25 14:58:38 +01:00
Ján Tomko
dc7238f518 Indent top-level labels by one space in src/cpu/ 2014-03-25 14:58:38 +01:00
Ján Tomko
df2013fad0 Indent top-level labels by one space in src/conf/ 2014-03-25 14:58:38 +01:00
Jiri Denemark
2cc27c34be sanlock: Forbid VIR_DOMAIN_LOCK_FAILURE_RESTART
https://bugzilla.redhat.com/show_bug.cgi?id=905282
https://bugzilla.redhat.com/show_bug.cgi?id=967494

When lock failure is detected by sanlock, our sanlock_helper kill script
will try to restart (shutdown followed by start) the affected domain
when RESTART action is configured for it. While shutting down kills QEMU
and removes all its leases (which is what sanlock wants to happen),
trying to start it again just hangs because libvirt tries reacquire the
locks in the failed lock space. Hence, this action cannot be supported
by sanlock driver.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-03-25 09:08:39 +01:00
Jiri Denemark
e3dd35e881 sanlock: Forbid VIR_DOMAIN_LOCK_FAILURE_IGNORE
https://bugzilla.redhat.com/show_bug.cgi?id=905280
https://bugzilla.redhat.com/show_bug.cgi?id=967493

Sanlock expects that the configured kill script either kills the PID on
lock failure or removes all locks the PID owns. If none of the two
options happen, sanlock will reboot the host. Although IGNORE action is
supposed to ignore the request to kill the PID or remove all leases,
it's certainly not designed to cause the host to be rebooted. That said,
IGNORE action is incompatible with sanlock and should be forbidden by
libvirt.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-03-25 09:08:39 +01:00
Peter Krempa
562112f4f9 util: Sanitize ATTRIBUTE_NONNULL use in viriscsi.h
Some of the function attributes marked as nonnull actually explicitly
handle the arguments for NULL. All changed functions handle missing
"initiatoriqn" argument well and virISCSIScanTargets also handles well
if the return pointers are missing. Remove some of the liberaly used
ATTRIBUTE_NONNULLs as coverity and possibly other compilers that honor
the attribute fail to compile the code.

Flaw introduced in commit 5e1d5dde
2014-03-25 08:26:39 +01:00
Qiao Nuohan
8c023e3187 qemu: add support for virDomainCoreDumpWithFormat API
This patch makes qemu driver support virDomainCoreDumpWithFormat API.

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
2014-03-24 14:14:14 -06:00
Qiao Nuohan
43177e2fd0 qemu: add qemuMonitorGetDumpGuestMemoryCapability
This patch adds qemuMonitorGetDumpGuestMemoryCapability, which is used to check
whether the specified dump-guest-memory format is supported by qemu.

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
2014-03-24 14:14:14 -06:00
Qiao Nuohan
9fbaff008c add new virDomainCoreDumpWithFormat API
--memory-only option is introduced without compression supported. Now qemu
has support for dumping domain's memory in kdump-compressed format. This
patch adds a new virDomainCoreDumpWithFormat API, so that the format in
which qemu dumps domain's memory can be specified.

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 14:14:11 -06:00
Peter Krempa
ccef7d7876 apparmor: Fix build after split of disk source metadata
Commit 4f20226664 breaks build with
AppArmor enabled as it missed the refactor to the new accessors.
2014-03-24 20:00:11 +01:00
Eric Blake
4f20226664 conf: prepare to track multiple host source files per <disk>
It's finally time to start tracking disk backing chains in
<domain> XML.  The first step is to start refactoring code
so that we have an object more convenient for representing
each host source resource in the context of a single guest
<disk>.  Ultimately, I plan to move the new type into src/util
where it can be reused by virStorageFile, but to make the
transition easier to review, this patch just creates the
new type then fixes everything until it compiles again.

* src/conf/domain_conf.h (_virDomainDiskDef): Split...
(_virDomainDiskSourceDef): ...to new struct.
(virDomainDiskAuthClear): Use new type.
* src/conf/domain_conf.c (virDomainDiskDefFree): Split...
(virDomainDiskSourceDefClear): ...to new function.
(virDomainDiskGetType, virDomainDiskSetType)
(virDomainDiskGetSource, virDomainDiskSetSource)
(virDomainDiskGetDriver, virDomainDiskSetDriver)
(virDomainDiskGetFormat, virDomainDiskSetFormat)
(virDomainDiskAuthClear, virDomainDiskGetActualType)
(virDomainDiskDefParseXML, virDomainDiskSourceDefFormat)
(virDomainDiskDefFormat, virDomainDiskDefForeachPath)
(virDomainDiskDefGetSecurityLabelDef)
(virDomainDiskSourceIsBlockType): Adjust all users.
* src/lxc/lxc_controller.c (virLXCControllerSetupDisk):
Likewise.
* src/lxc/lxc_driver.c (lxcDomainAttachDeviceMknodHelper):
Likewise.
* src/qemu/qemu_command.c (qemuAddRBDHost, qemuParseRBDString)
(qemuParseDriveURIString, qemuParseGlusterString)
(qemuParseISCSIString, qemuParseNBDString)
(qemuDomainDiskGetSourceString, qemuBuildDriveStr)
(qemuBuildCommandLine, qemuParseCommandLineDisk)
(qemuParseCommandLine): Likewise.
* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddISCSIPoolSourceHost, qemuTranslateDiskSourcePool):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainUpdateDeviceConfig)
(qemuDomainPrepareDiskChainElement)
(qemuDomainSnapshotCreateInactiveExternal)
(qemuDomainSnapshotPrepareDiskExternalBackingInactive)
(qemuDomainSnapshotPrepareDiskInternal)
(qemuDomainSnapshotPrepare)
(qemuDomainSnapshotCreateSingleDiskActive)
(qemuDomainSnapshotUndoSingleDiskActive)
(qemuDomainBlockPivot, qemuDomainBlockJobImpl)
(qemuDomainBlockCopy, qemuDomainBlockCommit): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessInitPasswords): Likewise.
* src/security/security_selinux.c
(virSecuritySELinuxSetSecurityFileLabel): Likewise.
* src/storage/storage_driver.c (virStorageFileInitFromDiskDef):
Likewise.
* tests/securityselinuxlabeltest.c (testSELinuxLoadDef):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 12:18:34 -06:00
Eric Blake
41a32b0a9b conf: use disk source accessors in xenxs/
Part of a series of cleanups to use new accessor methods.

* src/xenxs/xen_sxpr.c (xenParseSxprDisks, xenParseSxpr)
(xenFormatSxprDisk, xenFormatSxpr): Use accessors.
* src/xenxs/xen_xm.c (xenParseXM, xenFormatXMDisk, xenFormatXM):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 12:15:40 -06:00
Eric Blake
5b05358aba conf: use disk source accessors in xen/
Part of a series of cleanups to use new accessor methods.

* src/xen/xend_internal.c (virDomainXMLDevID): Use accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:51 -06:00
Eric Blake
f627468787 conf: use disk source accessors in vmx/
Part of a series of cleanups to use new accessor methods.

* src/vmx/vmx.c (virVMXHandleLegacySCSIDiskDriverName)
(virVMXParseDisk, virVMXFormatDisk, virVMXFormatFloppy): Use
accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:51 -06:00
Eric Blake
4ad6024bdf conf: use disk source accessors in vmware/
Part of a series of cleanups to use new accessor methods.

* src/vmware/vmware_conf.c (vmwareVmxPath): Use accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:51 -06:00
Eric Blake
6c1eb0847f conf: use disk source accessors in vbox/
Part of a series of cleanups to use new accessor methods.

* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives)
(vboxDomainAttachDeviceImpl, vboxDomainDetachDevice): Use
accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
8082d9bbda conf: use disk source accessors in uml/
Part of a series of cleanups to use new accessor methods.

* src/uml/uml_conf.c (umlBuildCommandLine): Use accessors.
* src/uml/uml_driver.c (umlDomainAttachUmlDisk): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
2aad0ebe2d conf: use disk source accessors in security/
Part of a series of cleanups to use new accessor methods.

* src/security/security_dac.c (virSecurityDACSetSecurityImageLabel)
(virSecurityDACRestoreSecurityImageLabelInt)
(virSecurityDACSetSecurityAllLabel): Use accessors.
* src/security/security_selinux.c
(virSecuritySELinuxRestoreSecurityImageLabelInt)
(virSecuritySELinuxSetSecurityImageLabel)
(virSecuritySELinuxSetSecurityAllLabel): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
cd01d2ad51 conf: use disk source accessors in qemu/
Part of a series of cleanups to use new accessor methods.

* src/qemu/qemu_conf.c (qemuCheckSharedDevice)
(qemuAddSharedDevice, qemuRemoveSharedDevice, qemuSetUnprivSGIO):
Use accessors.
* src/qemu/qemu_domain.c (qemuDomainDeviceDefPostParse)
(qemuDomainObjCheckDiskTaint, qemuDomainSnapshotForEachQcow2Raw)
(qemuDomainCheckRemoveOptionalDisk, qemuDomainCheckDiskPresence)
(qemuDiskChainCheckBroken, qemuDomainDetermineDiskChain):
Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia)
(qemuDomainCheckEjectableMedia)
(qemuDomainAttachVirtioDiskDevice, qemuDomainAttachSCSIDisk)
(qemuDomainAttachUSBMassstorageDevice)
(qemuDomainAttachDeviceDiskLive, qemuDomainRemoveDiskDevice)
(qemuDomainDetachVirtioDiskDevice, qemuDomainDetachDiskDevice):
Likewise.
* src/qemu/qemu_migration.c (qemuMigrationStartNBDServer)
(qemuMigrationDriveMirror, qemuMigrationCancelDriveMirror)
(qemuMigrationIsSafe): Likewise.
* src/qemu/qemu_process.c (qemuProcessGetVolumeQcowPassphrase)
(qemuProcessHandleIOError, qemuProcessHandleBlockJob)
(qemuProcessInitPasswords): Likewise.
* src/qemu/qemu_driver.c (qemuDomainChangeDiskMediaLive)
(qemuDomainGetBlockInfo, qemuDiskPathToAlias): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
73f4ae2a1f conf: use disk source accessors in phyp/
Part of a series of cleanups to use new accessor methods.

* src/phyp/phyp_driver.c (phypDomainAttachDevice, phypBuildLpar):
Use accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
e04a4ab926 conf: use disk source accessors in parallels/
Part of a series of cleanups to use new accessor methods.

* src/parallels/parallels_driver.c (parallelsGetHddInfo)
(parallelsAddHdd, parallelsApplyDisksParams, parallelsCreateVm):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
a7785ccfd7 conf: use disk source accessors in lxc/
Part of a series of cleanups to use new accessor methods.

* src/lxc/lxc_cgroup.c (virLXCCgroupSetupDeviceACL): Use
accessors.
* src/lxc/lxc_controller.c (virLXCControllerSetupLoopDeviceDisk)
(virLXCControllerSetupNBDDeviceDisk)
(virLXCControllerSetupLoopDevices, virLXCControllerSetupDisk):
Likewise.
* src/lxc/lxc_driver.c (lxcDomainAttachDeviceDiskLive)
(lxcDomainDetachDeviceDiskLive): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
6b44ccf7fe conf: use disk source accessors in locking/
Part of a series of cleanups to use new accessor methods.

* src/locking/domain_lock.c (virDomainLockManagerAddDisk): Use
accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
f7c81d8458 conf: use disk source accessors in libxl/
Part of a series of cleanups to use new accessor methods.

* src/libxl/libxl_conf.c (libxlMakeDisk): Use accessors.
* src/libxl/libxl_driver.c (libxlDomainChangeEjectableMedia)
(libxlDomainAttachDeviceDiskLive): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
3c9751187f conf: use disk source accessors in esx/
Part of a series of cleanups to use new accessor methods.

* src/esx/esx_driver.c (esxAutodetectSCSIControllerModel)
(esxDomainDefineXML): Use accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:50 -06:00
Eric Blake
119a258c4c conf: use disk source accessors in bhyve/
Part of a series of cleanups to use new accessor methods.

* src/bhyve/bhyve_command.c (bhyveBuildDiskArgStr)
(virBhyveProcessBuildLoadCmd): Use accessors.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:49 -06:00
Eric Blake
a9ab99cac2 conf: use disk source accessors in conf/
Part of a series of cleanups to use new accessor methods.

Several places in domain_conf.c still open-code raw field access,
but that code will be touched later with the diskDef struct split
so I'm avoiding churn here.

* src/conf/domain_audit.c (virDomainAuditStart): Use accessors.
* src/conf/domain_conf.c (virDomainDiskIndexByName)
(virDomainDiskPathByName, virDomainDiskDefForeachPath)
(virDomainDiskSourceIsBlockType): Likewise.
* src/conf/snapshot_conf.c (virDomainSnapshotAlignDisks):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:49 -06:00
Eric Blake
1014c34e3c conf: accessors for common source information
A future patch will split virDomainDiskDef, in order to track
multiple host resources per guest <disk>.  To reduce the size
of that patch, I've factored out the four most common accesses
into functions, so that I can incrementally upgrade the code
base to use the accessors, and so that code that doesn't care
about the distinction of per-file details won't have to be
changed when the struct changes.

* src/conf/domain_conf.h (virDomainDiskGetType)
(virDomainDiskSetType, virDomainDiskGetSource)
(virDomainDiskSetSource, virDomainDiskGetDriver)
(virDomainDiskSetDriver, virDomainDiskGetFormat)
(virDomainDiskSetFormat): New prototypes.
* src/conf/domain_conf.c (virDomainDiskGetType)
(virDomainDiskSetType, virDomainDiskGetSource)
(virDomainDiskSetSource, virDomainDiskGetDriver)
(virDomainDiskSetDriver, virDomainDiskGetFormat)
(virDomainDiskSetFormat): Implement them.
* src/libvirt_private.syms (domain_conf.h): Export them.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:59:49 -06:00
Eric Blake
e7b0e71d92 vmware: fix parse of disk source
While writing disk source refactoring, I discovered that conversion
from XML to vmware modified the disk source in place; if the same
code is reached twice, the second call behaves differently because
the first call didn't clean up its mess.

* src/vmware/vmware_conf.c (vmwareParsePath): Avoid munging input
string.
* src/vmware/vmware_conf.h (vmwareParsePath): Make static.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 11:55:05 -06:00
Michal Privoznik
0d93526fdd qemuDomainGetImageIds: Skip <seclabel/> without label
It's easy to shed the daemon these days. With this XML snippet:

    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/some/dummy/path/test.bin'>
        <seclabel model='dac' relabel='no'/>
      </source>
      <target dev='vdb' bus='virtio'/>
      <readonly/>
      <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
    </disk>

I get the SIGSEGV when starting the domain. The thing is, when
starting a domain, we check for its disk presence. For some reason,
when determining the disk chain, we parse the <seclabel/> (don't ask
me why). However, there's no label attribute in the XML, so we end up
calling virParseOwnershipIds() over NULL string:

 [Switching to Thread 0x7ffff10c4700 (LWP 30956)]
 __strchr_sse42 () at ../sysdeps/x86_64/multiarch/strchr.S:136
 136     ../sysdeps/x86_64/multiarch/strchr.S: No such file or directory.
 (gdb) bt
 #0  __strchr_sse42 () at ../sysdeps/x86_64/multiarch/strchr.S:136
 #1  0x00007ffff749f800 in virParseOwnershipIds (label=0x0, uidPtr=uidPtr@entry=0x7ffff10c2df0, gidPtr=gidPtr@entry=0x7ffff10c2df4) at util/virutil.c:2115
 #2  0x00007fffe929f006 in qemuDomainGetImageIds (gid=0x7ffff10c2df4, uid=0x7ffff10c2df0, disk=0x7fffe40cb000, vm=0x7fffe40a6410, cfg=0x7fffe409ae00) at qemu/qemu_domain.c:2385
 #3  qemuDomainDetermineDiskChain (driver=driver@entry=0x7fffe40120e0, vm=vm@entry=0x7fffe40a6410, disk=disk@entry=0x7fffe40cb000, force=force@entry=false) at qemu/qemu_domain.c:2414
 #4  0x00007fffe929f128 in qemuDomainCheckDiskPresence (driver=driver@entry=0x7fffe40120e0, vm=vm@entry=0x7fffe40a6410, cold_boot=cold_boot@entry=true) at qemu/qemu_domain.c:2250
 #5  0x00007fffe92b6fc8 in qemuProcessStart (conn=conn@entry=0x7fffd4000b60, driver=driver@entry=0x7fffe40120e0, vm=vm@entry=0x7fffe40a6410, migrateFrom=migrateFrom@entry=0x0, stdin_fd=stdin_fd@entry=-1, stdin_path=stdin_path@entry=0x0, snapshot=snapshot@entry=0x0,
     vmop=vmop@entry=VIR_NETDEV_VPORT_PROFILE_OP_CREATE, flags=flags@entry=1) at qemu/qemu_process.c:3813
 #6  0x00007fffe93087e8 in qemuDomainObjStart (conn=0x7fffd4000b60, driver=driver@entry=0x7fffe40120e0, vm=vm@entry=0x7fffe40a6410, flags=flags@entry=0) at qemu/qemu_driver.c:6051
 #7  0x00007fffe9308e32 in qemuDomainCreateWithFlags (dom=0x7fffcc000d50, flags=0) at qemu/qemu_driver.c:6105
 #8  0x00007ffff753c5cc in virDomainCreate (domain=domain@entry=0x7fffcc000d50) at libvirt.c:8861

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-24 16:51:34 +01:00