]> xenbits.xensource.com Git - libvirt.git/log
libvirt.git
10 years agoqemu: snapshot: Fix job handling when creating snapshots
Peter Krempa [Wed, 3 Sep 2014 13:17:50 +0000 (15:17 +0200)]
qemu: snapshot: Fix job handling when creating snapshots

Creating snapshots modifies the domain state. Currently we wouldn't
enter the job for certain operations although they would modify the
state. Refactor job handling so that everything is covered by an async
job.

10 years agoqemu: Rename DEFAULT_JOB_MASK to QEMU_DEFAULT_JOB_MASK
Peter Krempa [Wed, 3 Sep 2014 11:16:41 +0000 (13:16 +0200)]
qemu: Rename DEFAULT_JOB_MASK to QEMU_DEFAULT_JOB_MASK

Be consistent with naming of private defines. Also line up code
correctly in few places where the macro is used.

10 years agoselinux: Avoid label reservations for type = none
Shivaprasad G Bhat [Thu, 4 Sep 2014 09:12:32 +0000 (14:42 +0530)]
selinux: Avoid label reservations for type = none

For security type='none' libvirt according to the docs should not
generate seclabel be it for selinux or any model. So, skip the
reservation of labels when type is none.

Signed-off-by: Shivaprasad G Bhat <sbhat@linux.vnet.ibm.com>
10 years agoblockcopy: remote implementation for new API
Eric Blake [Sun, 24 Aug 2014 02:09:56 +0000 (20:09 -0600)]
blockcopy: remote implementation for new API

Fairly straightforward - I got lucky that the generated functions
worked out of the box :)

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

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockcopy: expose new API in virsh
Eric Blake [Fri, 29 Aug 2014 21:47:28 +0000 (15:47 -0600)]
blockcopy: expose new API in virsh

Expose the new power of virDomainBlockCopy through virsh (well,
all but the finer-grained bandwidth, as that is its own can of
worms for a later patch).  Continue to use the older API where
possible, for maximum compatibility.

The command now requires either --dest (with optional --format
and --blockdev), to directly describe the file destination, or
--xml, to name a file that contains an XML description such as:

<disk type='network'>
  <driver type='raw'/>
  <source protocol='gluster' name='vol1/img'>
    <host name='red'/>
  </source>
</disk>

[well, it may be a while before the qemu driver is actually patched
to act on that particular xml beyond just parsing it, but the virsh
interface won't need changing at that time]

Non-zero option parameters are converted into virTypedParameters,
and if anything requires the new API, the command can synthesize
appropriate XML even if the --dest option was used instead of --xml.

The existing --raw flag remains for back-compat, but the preferred
spelling is now --format=raw, since the new API now allows us
to specify all formats rather than just a boolean raw to suppress
probing.

I hope I did justice in describing the effects of granularity and
buf-size on how they get passed through to qemu.

* tools/virsh-domain.c (cmdBlockCopy): Add new options --xml,
--granularity, --buf-size, --format. Make --raw an alias for
--format=raw. Call new API if new parameters are in use.
* tools/virsh.pod (blockcopy): Document new options.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: update to latest gnulib
Eric Blake [Thu, 4 Sep 2014 12:39:54 +0000 (06:39 -0600)]
maint: update to latest gnulib

The usual portability fixes; and this includes a fix that adds
a new syntax check for double semicolons (commit 28de556 fixed
some, but gnulib found a better check).

* .gnulib: Update to latest.
* src/xenconfig/xen_common.c (xenFormatConfigCommon): Fix offender.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockcopy: split out virsh implementation
Eric Blake [Fri, 29 Aug 2014 21:20:30 +0000 (15:20 -0600)]
blockcopy: split out virsh implementation

I'm about to extend the capabilities of blockcopy.  Hiding a few
common lines of implementation gets in the way of the new required
logic, and putting the new logic in the common implementation won't
benefit any of the other blockjob operations.  Therefore, it is
simpler to just do the work inline.  There should be no semantic
change in this patch.

* tools/virsh-domain.c (blockJobImpl): Move block copy guts...
(cmdBlockCopy): ...into their lone caller.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agostorage_conf: Fix libvirtd crash when defining scsi storage pool
Pradipta Kr. Banerjee [Fri, 5 Sep 2014 05:47:49 +0000 (00:47 -0500)]
storage_conf: Fix libvirtd crash when defining scsi storage pool

Since 9f781da69de02745acb719e78982df9aeccfcd7b

Resolve a libvirtd crash in virStoragePoolSourceFindDuplicate()
when there is an existing SCSI pool defined with adapter type as
'scsi_host' and defining a new SCSI pool with adapter type as
'fc_host' and parent attribute missing or vice versa.

For example, if there is an existing SCSI pool with adapter type
as 'scsi_host' defined using the following XML

<pool type='scsi'>
  <name>TEST_SCSI_POOL</name>
    <source>
       <adapter type='scsi_host' name='scsi_host1'/>
    </source>
    <target>
        <path>/dev/disk/by-path</path>
    </target>
</pool>

When defining another SCSI pool with adapter type as 'fc_host' using the
following XML will crash libvirtd

<pool type='scsi'>
  <name>TEST_SCSI_FC_POOL</name>
  <source>
     <adapter type='fc_host' wwnn='1234567890abcdef' wwpn='abcdef1234567890'/>
  </source>
  <target>
     <path>/dev/disk/by-path</path>
  </target>
</pool>

Same is true for the reverse case as well where there exists a SCSI pool
with adapter type as 'fc_host' and another SCSI pool is defined with
adapter type as 'scsi_host'.

This happens because for fc_host 'name' is optional attribute whereas for
scsi_host its mandatory. However the check in libvirt for finding duplicate
storage pools didn't take that into account while comparing

Signed-off-by: Pradipta Kr. Banerjee <bpradip@in.ibm.com>
10 years agoblockcopy: allow block device destination
Eric Blake [Thu, 28 Aug 2014 04:03:04 +0000 (22:03 -0600)]
blockcopy: allow block device destination

To date, anyone performing a block copy and pivot ends up with
the destination being treated as <disk type='file'>.  While this
works for data access for a block device, it has at least one
noticeable shortcoming: virDomainGetBlockInfo() reports allocation
differently for block devices visited as files (the size of the
device) than for block devices visited as <disk type='block'>
(the maximum sector used, as reported by qemu); and this difference
is significant when trying to manage qcow2 format on block devices
that can be grown as needed.

Of course, the more powerful virDomainBlockCopy() API can already
express the ability to set the <disk> type.  But a new API can't
be backported, while a new flag to an existing API can; and it is
also rather inconvenient to have to resort to the full power of
generating XML when just adding a flag to the older call will do
the trick.  So this patch enhances blockcopy to let the user flag
when the resulting XML after the copy must list the device as
type='block'.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_REBASE_COPY_DEV):
New flag.
* src/libvirt.c (virDomainBlockRebase): Document it.
* tools/virsh-domain.c (opts_block_copy, blockJobImpl): Add
--blockdev option.
* tools/virsh.pod (blockcopy): Document it.
* src/qemu/qemu_driver.c (qemuDomainBlockRebase): Allow new flag.
(qemuDomainBlockCopy): Remember the flag, and make sure it is only
used on actual block devices.
* tests/qemuxml2argvdata/qemuxml2argv-disk-mirror.xml: Test it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: add new --bytes flag to virsh blockjob
Eric Blake [Thu, 28 Aug 2014 23:39:25 +0000 (17:39 -0600)]
blockjob: add new --bytes flag to virsh blockjob

Expose the new flag just added to virDomainGetBlockJobInfo.
With --raw, the presence or absence of --bytes determines which
flag to use in the single API call.  Without --raw, the use of
--bytes forces an error if the server doesn't support it,
otherwise, the code tries to silently fall back to scaling the
MiB/s value.

My goal is to eventually also support --bytes in bandwidth mode;
but that's a bit further down the road (and needs a new API flag
added in libvirt.h first).

This changes the human output, but the previous patch added
raw output precisely so that we can have flexibility with the
human output.  For this commit, I used qemu-monitor-command to
force an unusual bandwidth, but the same will be possible once
qemu implements virDomainBlockCopy:

Before:
Block Copy: [100 %]    Bandwidth limit: 2 MiB/s
After:
Block Copy: [100 %]    Bandwidth limit: 1048577 bytes/s (1.000 MiB/s)

The cache avoids having to repeatedly checking whether the flag
works when talking to an older server, when multiple blockjob
commands are issued during a batch session and the user is
manually polling for job completion.

* tools/virsh.h (_vshControl): Add a cache.
* tools/virsh.c (cmdConnect, vshReconnect): Initialize the cache.
* tools/virsh-domain.c (opts_block_job): Add --bytes.
* tools/virsh.pod (blockjob): Document this.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: add new --raw flag to virsh blockjob
Eric Blake [Thu, 28 Aug 2014 23:23:49 +0000 (17:23 -0600)]
blockjob: add new --raw flag to virsh blockjob

The current output of 'blockjob [--info]' is a single line
designed for human consumption; it's not very nice for machine
parsing.  Furthermore, I have plans to modify the line in
response to the new flag for controlling bandwidth units.
Solve that by adding a --raw parameter, which outputs
information closer to the C struct.

$ virsh blockjob testvm1 vda --raw
 type=Block Copy
 bandwidth=1
 cur=197120
 end=197120

The information is indented, because I'd like for a later patch
to add a mode that iterates over all the vm's disks with status
for each; in that mode, each block name would be listed unindented
before information (if any) about that block.

Now that we have a raw mode, we can guarantee that it won't change
format over time.  Any app that cares about parsing the output can
try --raw, and if it fails, know that it was talking to an older
virsh and fall back to parsing the human-readable format which had
not changed until now; meanwhile, when not using --raw, we have
freed future virsh to change the output to whatever makes sense.

My first change to human mode: this command now guarantees a line
is printed on successful use of the API, even when the API did
not find a current block job (consistent with the rest of virsh).

Bonus: https://bugzilla.redhat.com/show_bug.cgi?id=1135441
complained that this message was confusing:

$ virsh blockjob test1 hda  --async --bandwidth 10
error: conflict between --abort, --info, and --bandwidth modes

even though the man page already documents that --async implies
abort mode, all because '--abort' wasn't present in the command
line.  Since I'm adding another case where options are tied
to or imply a mode, I changed that error to:

error: conflict between abort, info, and bandwidth modes

* tools/virsh-domain.c (cmdBlockJob): Add --raw parameter; tweak
error wording.
* tools/virsh.pod (blockjob): Document it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: split up virsh blockjob info
Eric Blake [Thu, 28 Aug 2014 19:18:22 +0000 (13:18 -0600)]
blockjob: split up virsh blockjob info

I have plans to make future enhancements to the job list mode,
which will be easier to do if the common blockJobImpl function
is not mixing a query command with multiple modify commands.
Besides, it just feels weird that all callers to blockJobImpl
had to supply both a bandwidth input argument (unused for info
mode) and an info output argument (unused for all other modes);
not to mention I just made similar cleanups on the libvirtd
side.

The only reason blockJobImpl returned int was because of info
mode returning -1/0/1 (all other job API are -1/0), so that
can also be cleaned up.  No user-visible changes in this commit.

* tools/virsh-domain.c (blockJobImpl): Change signature and return
value.  Drop info handling.
(cmdBlockJob): Handle info here.
(cmdBlockCommit, cmdBlockCopy, cmdBlockPull): Adjust callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: allow finer bandwidth tuning for query
Eric Blake [Wed, 27 Aug 2014 20:04:36 +0000 (14:04 -0600)]
blockjob: allow finer bandwidth tuning for query

While reviewing the new virDomainBlockCopy API, Peter Krempa
pointed out that our existing design of using MiB/s for block
job bandwidth is rather coarse, especially since qemu tracks
it in bytes/s; so virDomainBlockCopy only accepts bytes/s.
But once the new API is implemented for qemu, we will be in
the situation where it is possible to set a value that cannot
be accurately reflected back to the user, because the existing
virDomainGetBlockJobInfo defaults to the coarser units.

Fortunately, we have an escape hatch; and one that has already
served us well in the past: we can use the flags argument to
specify which scale to use (see virDomainBlockResize for prior
art).  This patch fixes the query side of the API; made easier
by previous patches that split the query side out from the
modification code.  Later patches will address the virsh
interface, as well retrofitting all other blockjob APIs to
also accept a flag for toggling bandwidth units.

* include/libvirt/libvirt.h.in (_virDomainBlockJobInfo)
(VIR_DOMAIN_BLOCK_COPY_BANDWIDTH): Document sizing issues.
(virDomainBlockJobInfoFlags): New enum.
* src/libvirt.c (virDomainGetBlockJobInfo): Document new flag.
* src/qemu/qemu_monitor.h (qemuMonitorBlockJobInfo): Add parameter.
* src/qemu/qemu_monitor.c (qemuMonitorBlockJobInfo): Likewise.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockJobInfo):
Likewise.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockJobInfo)
(qemuMonitorJSONGetBlockJobInfoOne): Likewise. Don't scale here.
* src/qemu/qemu_migration.c (qemuMigrationDriveMirror): Update
callers.
* src/qemu/qemu_driver.c (qemuDomainBlockPivot)
(qemuDomainBlockJobImpl): Likewise.
(qemuDomainGetBlockJobInfo): Likewise, and support new flag.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: add new monitor json conversions
Eric Blake [Fri, 5 Sep 2014 11:31:47 +0000 (05:31 -0600)]
blockjob: add new monitor json conversions

The previous patch hoisted some bounds checks to the callers;
but someone that is not aware of the hoisted check could now
try passing an integer between LLONG_MAX and ULLONG_MAX.  As a
safety measure, add new json conversion modes that let libvirt
error out early instead of pass bad numbers to qemu, if the
caller ever makes a mistake due to later refactoring.

Convert the various blockjob QMP calls to use the new modes,
and switch some of them to be optional (QMP has always supported
an omitted "speed" the same as "speed":0, for everything except
block-job-set-speed).

* src/qemu/qemu_monitor_json.c (qemuMonitorJSONMakeCommandRaw):
Add 'j'/'y' and 'J'/'Y' to error out on negative input.
(qemuMonitorJSONDriveMirror, qemuMonitorJSONBlockCommit)
(qemuMonitorJSONBlockJob): Use it.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: hoist bandwidth scaling out of monitor code
Eric Blake [Fri, 29 Aug 2014 19:58:45 +0000 (13:58 -0600)]
blockjob: hoist bandwidth scaling out of monitor code

qemu treats blockjob bandwidth as a 64-bit number, in the units
of bytes/second.  But we stupidly modeled block job bandwidth
after migration bandwidth, which in turn was an 'unsigned long'
and therefore subject to 32-bit vs. 64-bit interpretations, and
with a scale of MiB/s.  Our code already has to convert between
the two scales, and report overflow as appropriate; although
this conversion currently lives in the monitor code.  In fact,
our conversion code limited things to 63 bits, because we
checked against LLONG_MAX and reject what would be negative
bandwidth if treated as signed.

On the bright side, our use of MiB/s means that even with a
32-bit unsigned long, we still have no problem representing a
bandwidth of 2GiB/s, which is starting to be more feasible as
10-gigabit or even faster interfaces are used.  And once you
get past the physical speeds of existing interfaces, any larger
bandwidth number behaves the same - effectively unlimited.
But on the low side, the granularity of 1MiB/s tuning is rather
coarse.  So the new virDomainBlockJob API decided to go with
a direct 64-bit bytes/sec number instead of the scaled number
that prior blockjob APIs had used.  But there is no point in
rounding this number to MiB/s just to scale it back to bytes/s
for handing to qemu.

In order to make future code sharing possible between the old
virDomainBlockRebase and the new virDomainBlockCopy, this patch
moves the scaling and overflow detection into the driver code.
Several of the block job calls that can set speed are fed
through a common interface, so it was easier to adjust all block
jobs at once, for consistency.  This patch is just code motion;
there should be no user-visible change in behavior.

* src/qemu/qemu_monitor.h (qemuMonitorBlockJob)
(qemuMonitorBlockCommit, qemuMonitorDriveMirror): Change
parameter type and scale.
* src/qemu/qemu_monitor.c (qemuMonitorBlockJob)
(qemuMonitorBlockCommit, qemuMonitorDriveMirror): Move scaling
and overflow detection...
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl)
(qemuDomainBlockRebase, qemuDomainBlockCommit): ...here.
(qemuDomainBlockCopy): Use bytes/sec.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: split out block info monitor handling
Eric Blake [Wed, 27 Aug 2014 19:29:14 +0000 (13:29 -0600)]
blockjob: split out block info monitor handling

Another layer of overly-multiplexed code that deserves to be
split into obviously separate paths for query vs. modify.
This continues the cleanup started in commit cefe0ba.

In the process, make some tweaks to simplify the logic when
parsing the JSON reply.  There should be no user-visible
semantic changes.

* src/qemu/qemu_monitor.h (qemuMonitorBlockJob): Drop parameter.
(qemuMonitorBlockJobInfo): New prototype.
(BLOCK_JOB_INFO): Drop enum.
* src/qemu/qemu_monitor_json.h (qemuMonitorJSONBlockJob)
(qemuMonitorJSONBlockJobInfo): Likewise.
* src/qemu/qemu_monitor.c (qemuMonitorBlockJob): Split...
(qemuMonitorBlockJobInfo): ...into second function.
* src/qemu/qemu_monitor_json.c (qemuMonitorJSONBlockJob): Move
block info portions...
(qemuMonitorJSONGetBlockJobInfo): ...here, and rename...
(qemuMonitorJSONBlockJobInfo): ...and export.
(qemuMonitorJSONGetBlockJobInfoOne): Alter return semantics.
* src/qemu/qemu_driver.c (qemuDomainBlockPivot)
(qemuDomainBlockJobImpl, qemuDomainGetBlockJobInfo): Adjust
callers.
* src/qemu/qemu_migration.c (qemuMigrationDriveMirror)
(qemuMigrationCancelDriveMirror): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoDon't include non-migratable features in host-model
Ján Tomko [Fri, 5 Sep 2014 07:50:36 +0000 (09:50 +0200)]
Don't include non-migratable features in host-model

Commit fba6bc4 introduced support for the 'invtsc' feature,
which blocks migration. We should not include it in the
host-model CPU by default, because it's intended to be used
with migration.

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

10 years agotests: Add test cases for previous commit
Michal Privoznik [Wed, 3 Sep 2014 17:06:55 +0000 (19:06 +0200)]
tests: Add test cases for previous commit

This commit is rather big. Firstly, the in memory config
representation is adjusted like if security_driver was set to "none".
The rest is then just adaptation to the new code that will generate
different seclabels.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoconf: Fix even implicit labels
Michal Privoznik [Wed, 3 Sep 2014 16:07:45 +0000 (18:07 +0200)]
conf: Fix even implicit labels

https://bugzilla.redhat.com/show_bug.cgi?id=1027096#c8

There are two ways in which security model can make it way into
<seclabel/>. One is as the @model attribute, the second one is
via security_driver knob in qemu.conf. Then, while parsing
<seclabel/> several checks and fix ups of old, stale combinations
are performed. However, iff @model is specified. They are not
done in the latter case. So it's still possible to feed libvirt
with senseless combinations (if qemu.conf is adjusted correctly).

One example of a seclabel that needs some adjustment (in case
security_driver=none in qemu.conf) is:

    <seclabel type='dynamic' relabel='yes'/>

The fixup code is copied from virSecurityLabelDefParseXML
(covering the former case) into virSecurityLabelDefsParseXML
(which handles the latter case).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoblockjob: split out block info driver handling
Eric Blake [Fri, 29 Aug 2014 19:36:59 +0000 (13:36 -0600)]
blockjob: split out block info driver handling

The qemu implementation for virDomainGetBlockJobInfo() has a
minor bug: it grabs the qemu job with intent to QEMU_JOB_MODIFY,
which means it cannot be run in parallel with any other
domain-modifying command.  Among others, virDomainBlockJobAbort()
is such a modifying command, and it defaults to being
synchronous, and can wait as long as several seconds to ensure
that the job has actually finished.  Due to the job rules, this
means a user cannot obtain status about the job during that
timeframe, even though we know that some client management code
exists which is using a polling loop on status to see when a job
finishes.

This bug has been present ever since blockpull support was first
introduced (commit b976165, v0.9.4 in Jul 2011), all because we
stupidly tried to cram too much multiplexing through a single
helper routine, but was made worse in 97c59b9 (v1.2.7) when
BlockJobAbort was fixed to wait longer.  It's time to disentangle
some of the mess in qemuDomainBlockJobImpl, and in the process
relax block job query to use QEMU_JOB_QUERY, since it can safely
be used in parallel with any long running modify command.

Technically, there is one case where getting block job info can
modify domain XML - we do snooping to see if a 2-phase job has
transitioned into the second phase, for an optimization in the
case of old qemu that lacked an event for the transition.  I
claim this optimization is safe (the jobs are all about modifying
qemu state, not necessarily xml state); but if it proves to be
a problem, we could use the difference between the capabilities
QEMU_CAPS_BLOCKJOB_{ASYNC,SYNC} to determine whether we even
need snooping, and only request a modifying job in the case of
older qemu.

* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Move info
handling...
(qemuDomainGetBlockJobInfo): ...here, and relax job type.
(qemuDomainBlockJobAbort, qemuDomainBlockJobSetSpeed)
(qemuDomainBlockRebase, qemuDomainBlockPull): Adjust callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoblockjob: shuffle block rebase code
Eric Blake [Fri, 29 Aug 2014 19:27:18 +0000 (13:27 -0600)]
blockjob: shuffle block rebase code

The existing virDomainBlockRebase code rejected the combination of
_RELATIVE and _COPY flags, but only by accident.  It makes sense
to add support for the combination someday, at least for the case
of _SHALLOW and not _REUSE_EXT; but to implement it, libvirt would
have to pre-create the file with a relative backing name, and I'm
not ready to code that in yet.

Meanwhile, the code to forward on to the block copy code is getting
longer, and reorganizing the function to have the block pull done
early makes it easier to add even more block copy prep code.

This patch should have no semantic difference other than the quality
of the error message on the unsupported flag combination.  Pre-patch:

error: unsupported flags (0x10) in function qemuDomainBlockCopy

Post-patch:

error: argument unsupported: Relative backing during copy not supported yet

* src/qemu/qemu_driver.c (qemuDomainBlockRebase): Reorder code,
and improve error message of relative copy.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: tighten curly brace syntax checking
Eric Blake [Wed, 3 Sep 2014 22:18:19 +0000 (16:18 -0600)]
maint: tighten curly brace syntax checking

Now that hanging brace offenders have been fixed, we can automate
the check, and document our style.  Done as a separate commit from
code changes, to make it easier to just backport code changes, if
that is ever needed.

* cfg.mk (sc_curly_braces_style): Catch hanging braces.
* docs/hacking.html.in: Document it.
* HACKING: Regenerate.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use hanging curly braces
Eric Blake [Wed, 3 Sep 2014 22:24:43 +0000 (16:24 -0600)]
maint: use hanging curly braces

Our style overwhelmingly uses hanging braces (the open brace
hangs at the end of the compound condition, rather than on
its own line), with the primary exception of the top level function
body.  Fix the few remaining outliers, before adding a syntax
check in a later patch.

* src/interface/interface_backend_netcf.c (netcfStateReload)
(netcfInterfaceClose, netcf_to_vir_err): Correct use of { in
compound statement.
* src/conf/domain_conf.c (virDomainHostdevDefFormatSubsys)
(virDomainHostdevDefFormatCaps): Likewise.
* src/network/bridge_driver.c (networkAllocateActualDevice):
Likewise.
* src/util/virfile.c (virBuildPathInternal): Likewise.
* src/util/virnetdev.c (virNetDevGetVirtualFunctions): Likewise.
* src/util/virnetdevmacvlan.c
(virNetDevMacVLanVPortProfileCallback): Likewise.
* src/util/virtypedparam.c (virTypedParameterAssign): Likewise.
* src/util/virutil.c (virGetWin32DirectoryRoot)
(virFileWaitForDevices): Likewise.
* src/vbox/vbox_common.c (vboxDumpNetwork): Likewise.
* tests/seclabeltest.c (main): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: enforce previous if-else {} cleanups
Eric Blake [Wed, 3 Sep 2014 17:17:01 +0000 (11:17 -0600)]
maint: enforce previous if-else {} cleanups

Done as a separate commit in case earlier cleanups are backported
independently.

* cfg.mk (sc_require_space_before_label): New rule.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use consistent if-else braces in remaining spots
Eric Blake [Wed, 3 Sep 2014 19:39:21 +0000 (13:39 -0600)]
maint: use consistent if-else braces in remaining spots

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This patch focuses on all remaining problems, where there weren't
enough issues to warrant splitting it further.

* src/remote/remote_driver.c (doRemoteOpen): Correct use of {}.
* src/security/virt-aa-helper.c (vah_add_path, valid_path, main):
Likewise.
* src/rpc/virnetsocket.c (virNetSocketNewConnectLibSSH2):
Likewise.
* src/esx/esx_vi_types.c (esxVI_Type_FromString): Likewise.
* src/uml/uml_driver.c (umlDomainDetachDevice): Likewise.
* src/util/viralloc.c (virShrinkN): Likewise.
* src/util/virbuffer.c (virBufferURIEncodeString): Likewise.
* src/util/virdbus.c (virDBusCall): Likewise.
* src/util/virnetdev.c (virNetDevValidateConfig): Likewise.
* src/util/virnetdevvportprofile.c
(virNetDevVPortProfileGetNthParent): Likewise.
* src/util/virpci.c (virPCIDeviceIterDevices)
(virPCIDeviceWaitForCleanup)
(virPCIDeviceIsBehindSwitchLackingACS): Likewise.
* src/util/virsocketaddr.c (virSocketAddrGetNumNetmaskBits):
Likewise.
* src/util/viruri.c (virURIParseParams): Likewise.
* daemon/stream.c (daemonStreamHandleAbort): Likewise.
* tests/testutils.c (virtTestResult): Likewise.
* tests/cputest.c (cpuTestBaseline): Likewise.
* tools/virsh-domain.c (cmdDomPMSuspend): Likewise.
* tools/virsh-host.c (cmdNodeSuspend): Likewise.
* src/esx/esx_vi_generator.py (Type.generate_typefromstring):
Tweak generated code.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use consistent if-else braces in lxc, vbox, phyp
Eric Blake [Wed, 3 Sep 2014 19:28:14 +0000 (13:28 -0600)]
maint: use consistent if-else braces in lxc, vbox, phyp

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This patch focuses on drivers that had several issues.

* src/lxc/lxc_fuse.c (lxcProcGetattr, lxcProcReadMeminfo): Correct
use of {}.
* src/lxc/lxc_driver.c (lxcDomainMergeBlkioDevice): Likewise.
* src/phyp/phyp_driver.c (phypConnectNumOfDomainsGeneric)
(phypUUIDTable_Init, openSSHSession, phypStoragePoolListVolumes)
(phypConnectListStoragePools, phypDomainSetVcpusFlags)
(phypStorageVolGetXMLDesc, phypStoragePoolGetXMLDesc)
(phypConnectListDefinedDomains): Likewise.
* src/vbox/vbox_common.c (vboxAttachSound, vboxDumpDisplay)
(vboxDomainRevertToSnapshot, vboxDomainSnapshotDelete): Likewise.
* src/vbox/vbox_tmpl.c (vboxStorageVolGetXMLDesc): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use consistent if-else braces in xen and friends
Eric Blake [Wed, 3 Sep 2014 19:04:59 +0000 (13:04 -0600)]
maint: use consistent if-else braces in xen and friends

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This patch focuses on code related to xen.

* src/libxl/libxl_conf.c (libxlCapsInitGuests)
(libxlMakeDomBuildInfo): Correct use of {}.
* src/xen/xen_hypervisor.c (virXen_getvcpusinfo)
(xenHypervisorMakeCapabilitiesInternal): Likewise.
* src/xen/xend_internal.c (xenDaemonOpen)
(xenDaemonDomainMigratePerform, xend_detect_config_version)
(xenDaemonDetachDeviceFlags, xenDaemonDomainMigratePerform)
(xenDaemonDomainBlockPeek): Likewise.
* src/xenapi/xenapi_driver.c (xenapiConnectListDomains)
(xenapiDomainLookupByUUID, xenapiDomainGetOSType): Likewise.
* src/xenconfig/xen_common.c (xenParseCPUFeatures, xenFormatNet):
Likewise.
* src/xenconfig/xen_sxpr.c (xenParseSxpr, xenFormatSxprNet)
(xenFormatSxpr): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use consistent if-else braces in qemu
Eric Blake [Wed, 3 Sep 2014 19:32:36 +0000 (13:32 -0600)]
maint: use consistent if-else braces in qemu

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This commit focuses on the qemu driver.

* src/qemu/qemu_command.c (qemuParseISCSIString)
(qemuParseCommandLineDisk, qemuParseCommandLine)
(qemuBuildSmpArgStr, qemuBuildCommandLine)
(qemuParseCommandLineDisk, qemuParseCommandLineSmp): Correct use
of {}.
* src/qemu/qemu_capabilities.c (virQEMUCapsProbeCPUModels):
Likewise.
* src/qemu/qemu_driver.c (qemuDomainCoreDumpWithFormat)
(qemuDomainRestoreFlags, qemuDomainGetInfo)
(qemuDomainMergeBlkioDevice): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainAttachNetDevice): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextCreateSnapshot)
(qemuMonitorTextLoadSnapshot, qemuMonitorTextDeleteSnapshot):
Likewise.
* src/qemu/qemu_process.c (qemuProcessStop): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agomaint: use consistent if-else braces in conf and friends
Eric Blake [Wed, 3 Sep 2014 17:29:38 +0000 (11:29 -0600)]
maint: use consistent if-else braces in conf and friends

I'm about to add a syntax check that enforces our documented
HACKING style of always using matching {} on if-else statements.

This patch focuses on code shared between multiple drivers.

* src/conf/domain_conf.c (virDomainFSDefParseXML)
(virSysinfoParseXML, virDomainNetDefParseXML)
(virDomainWatchdogDefParseXML)
(virDomainRedirFilterUSBDevDefParseXML): Correct use of {}.
* src/conf/interface_conf.c (virInterfaceDefParseDhcp)
(virInterfaceDefParseIp, virInterfaceVlanDefFormat)
(virInterfaceDefParseStartMode, virInterfaceDefParseBondMode)
(virInterfaceDefParseBondMiiCarrier)
(virInterfaceDefParseBondArpValid): Likewise.
* src/conf/node_device_conf.c (virNodeDevCapStorageParseXML):
Likewise.
* src/conf/nwfilter_conf.c (virNWFilterRuleDetailsParse)
(virNWFilterRuleParse, virNWFilterDefParseXML): Likewise.
* src/conf/secret_conf.c (secretXMLParseNode): Likewise.
* src/cpu/cpu_x86.c (x86Baseline, x86FeatureLoad, x86ModelLoad):
Likewise.
* src/network/bridge_driver.c (networkKillDaemon)
(networkDnsmasqConfContents): Likewise.
* src/node_device/node_device_hal.c (dev_refresh): Likewise.
* src/nwfilter/nwfilter_gentech_driver.c (virNWFilterInstantiate):
Likewise.
* src/nwfilter/nwfilter_ebiptables_driver.c
(_iptablesCreateRuleInstance): Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskBuildPool): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoLXC: add HOME environment variable
Chen Hanxiao [Fri, 25 Jul 2014 06:39:55 +0000 (14:39 +0800)]
LXC: add HOME environment variable

We lacked of HOME environment variable,
set 'HOME=/' as default.

The kernel sets up $HOME for the init process.
Therefore any init can assume that $HOME is set.
libvirt currently violates that implicit rule.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoapparmor: allow reading cap_last_cap
Felix Geyer [Wed, 3 Sep 2014 19:52:03 +0000 (21:52 +0200)]
apparmor: allow reading cap_last_cap

libcap-ng >= 0.7.4 fails when it can't read /sys/kernel/cap_last_cap
and thus running a qemu guest fails.

Allow reading cap_last_cap in the libvirt-qemu apparmor abstraction.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agotests: force FIPS testing mode with new enough GNU TLS versions
Giuseppe Scrivano [Thu, 4 Sep 2014 09:23:16 +0000 (11:23 +0200)]
tests: force FIPS testing mode with new enough GNU TLS versions

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
10 years agosecurity: fix DH key generation when FIPS mode is on
Giuseppe Scrivano [Thu, 4 Sep 2014 08:05:36 +0000 (10:05 +0200)]
security: fix DH key generation when FIPS mode is on

When FIPS mode is on, gnutls_dh_params_generate2 will fail if 1024 is
specified as the prime's number of bits, a bigger value works in both
cases.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
10 years agolxc_container: Resolve Coverity RESOURCE_LEAK
Wang Rui [Mon, 1 Sep 2014 12:08:08 +0000 (20:08 +0800)]
lxc_container: Resolve Coverity RESOURCE_LEAK

Memory is allocated for 'mnt_src' by VIR_STRDUP in the loop. Next
loop it will be allocated again. So we need to free 'mnt_src'
before continue the loop.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agovircgroup: Resolve Coverity RESOURCE_LEAK
Wang Rui [Mon, 1 Sep 2014 12:08:07 +0000 (20:08 +0800)]
vircgroup: Resolve Coverity RESOURCE_LEAK

Need to free 'root' and 'opts' before 'return -1' if symlink fails.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agoqemu_process: Resolve Coverity RESOURCE_LEAK
Wang Rui [Mon, 1 Sep 2014 12:08:06 +0000 (20:08 +0800)]
qemu_process: Resolve Coverity RESOURCE_LEAK

If virSecurityManagerClearSocketLabel() fails, 'agent' won't
be freed before jumping to cleanup.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agoremote: Resolve Coverity RESOURCE_LEAK
Wang Rui [Mon, 1 Sep 2014 12:08:05 +0000 (20:08 +0800)]
remote: Resolve Coverity RESOURCE_LEAK

Need to free 'uri_out' on error path.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agotest_conf: Resolve Coverity RESOURCE_LEAK
Wang Rui [Mon, 1 Sep 2014 12:08:04 +0000 (20:08 +0800)]
test_conf: Resolve Coverity RESOURCE_LEAK

If the condition 'ret < 0' is true, the code will jump to
'cleanup' and 'conf' won't be freed.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agotests: Resolve Coverity RESOURCE_LEAK in commandhelper
Wang Rui [Wed, 3 Sep 2014 18:59:31 +0000 (14:59 -0400)]
tests: Resolve Coverity RESOURCE_LEAK in commandhelper

Coverity determined that 'log' and 'newenv' were not freed in
some cases. Free them in 'error' branch and normal branch.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agocommand: test umask support
Eric Blake [Wed, 3 Sep 2014 15:13:21 +0000 (09:13 -0600)]
command: test umask support

Add testsuite coverage for the recent commit 0e1a1a8.

* tests/commandhelper.c (main): Output umask.
* tests/commandtest.c (test15): Also test umask.
(mymain): Add test.
* tests/commanddata/*.log: Update expected output.

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoutil: don't shadow global umask declaration
Martin Kletzander [Wed, 3 Sep 2014 13:39:15 +0000 (15:39 +0200)]
util: don't shadow global umask declaration

Commit 0e1a1a8c introduced umask for virCommand, but the variables
used emit a warning on older compilers about shadowed global
declaration.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agosanlock: Avoid freeing uninitialized value
Jiri Denemark [Wed, 3 Sep 2014 11:18:59 +0000 (13:18 +0200)]
sanlock: Avoid freeing uninitialized value

https://bugzilla.redhat.com/show_bug.cgi?id=1136788
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoqemu: ensure sane umask for qemu process
Chunyan Liu [Wed, 3 Sep 2014 06:18:07 +0000 (14:18 +0800)]
qemu: ensure sane umask for qemu process

Add umask to _virCommand, allow user to set umask to command.
Set umask(002) to qemu process to overwrite the default umask
of 022 set by many distros, so that unix sockets created for
virtio-serial has expected permissions.

Fix problem reported here:
https://sourceware.org/bugzilla/show_bug.cgi?id=13078#c11
https://bugzilla.novell.com/show_bug.cgi?id=888166

To use virtio-serial device, unix socket created for chardev with
default umask(022) has insufficient permissions.
e.g.:
-device virtio-serial \
-chardev socket,path=/tmp/foo,server,nowait,id=foo \
-device virtserialport,chardev=foo,name=org.fedoraproject.port.0

srwxr-xr-x 1 qemu qemu 0 21. Jul 14:19 /tmp/somefile.sock

Other users in the same group (like real user, test engines, etc)
cannot write to this socket.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agospec: Fix preun script for daemon
Jiri Denemark [Wed, 3 Sep 2014 08:51:14 +0000 (10:51 +0200)]
spec: Fix preun script for daemon

%systemd_preun macro cannot be split into several lines.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoremote: Fix memory leak on error path when deserializing bulk stats
Peter Krempa [Tue, 2 Sep 2014 13:16:47 +0000 (15:16 +0200)]
remote: Fix memory leak on error path when deserializing bulk stats

The 'elem' variable along with the domain object would be leaked when
taking the error path.

Found by coverity.

10 years agoutil: Introduce flags field for macvtap creation
Matthew Rosato [Wed, 27 Aug 2014 14:34:13 +0000 (10:34 -0400)]
util: Introduce flags field for macvtap creation

Currently, there is one flag passed in during macvtap creation
(withTap) -- Let's convert this field to an unsigned int flag
field for future expansion.

Signed-off-by: Matthew Rosato <mjrosato@linux.vnet.ibm.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoFree ifname in testDomainGenerateIfnames
Ján Tomko [Tue, 2 Sep 2014 09:54:05 +0000 (11:54 +0200)]
Free ifname in testDomainGenerateIfnames

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

10 years agoPost-release version bump for new dev cycle
Michal Privoznik [Tue, 2 Sep 2014 08:07:15 +0000 (10:07 +0200)]
Post-release version bump for new dev cycle

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agoRelease of libvirt-1.2.8
Daniel Veillard [Tue, 2 Sep 2014 07:41:09 +0000 (09:41 +0200)]
Release of libvirt-1.2.8

* docs/news.html.in libvirt.spec.in: update for release
* po/*.po*: new localizations and regenerate pos

10 years agoblockcopy: allow larger buf-size
Eric Blake [Sun, 31 Aug 2014 04:02:19 +0000 (22:02 -0600)]
blockcopy: allow larger buf-size

While qemu definitely caps granularity to 64 MiB, it places no
limits on buf-size.  On a machine beefy enough for lots of
memory, a buf-size larger than 2 GiB is feasible, so we should
pass a 64-bit parameter.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_COPY_BUF_SIZE):
Allow 64 bits.

Signed-off-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
10 years agoselinux: properly label tap FDs with imagelabel
Martin Kletzander [Mon, 1 Sep 2014 13:27:00 +0000 (15:27 +0200)]
selinux: properly label tap FDs with imagelabel

The cleanup in commit cf976d9d used secdef->label to label the tap
FDs, but that is not possible since it's process-only label (svirt_t)
and not a object label (e.g. svirt_image_t).  Starting a domain failed
with EPERM, but simply using secdef->imagelabel instead of
secdef->label fixes it.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agoFix connection to already running session libvirtd
Christophe Fergeau [Thu, 28 Aug 2014 21:33:24 +0000 (23:33 +0200)]
Fix connection to already running session libvirtd

Since 1b807f92, connecting with virsh to an already running session
libvirtd fails with:
$ virsh list --all
error: failed to connect to the hypervisor
error: no valid connection
error: Failed to connect socket to
'/run/user/1000/libvirt/libvirt-sock': Transport endpoint is already
connected

This is caused by a logic error in virNetSocketNewConnectUnix: even if
the connection to the daemon socket succeeded, we still try to spawn the
daemon and then connect to it.
This commit changes the logic to not try to spawn libvirtd if we
successfully connected to its socket.

Most of this commit is whitespace changes, use of -w is recommended to
look at it.

10 years agostorage: zfs: fix double listing of new volumes
Roman Bogorodskiy [Wed, 27 Aug 2014 08:53:07 +0000 (12:53 +0400)]
storage: zfs: fix double listing of new volumes

Currently, after calling commands to create a new volumes,
virStorageBackendZFSCreateVol calls virStorageBackendZFSFindVols that
calls virStorageBackendZFSParseVol.

virStorageBackendZFSParseVol checks if a volume already exists by
trying to get it using virStorageVolDefFindByName.

For a just created volume it returns NULL, so volume is reported as
new and appended to pool->volumes. This causes a volume to be listed
twice as storageVolCreateXML appends this new volume to the list as
well.

Fix that by passing a new volume definition to
virStorageBackendZFSParseVol so it could determine if it needs to add
this volume to the list.

10 years agoqemu_driver: Resolve Coverity FORWARD_NULL
John Ferlan [Thu, 28 Aug 2014 16:49:30 +0000 (12:49 -0400)]
qemu_driver: Resolve Coverity FORWARD_NULL

In qemuDomainSnapshotCreateDiskActive() if we jumped to cleanup from a
failed actions = virJSONValueNewArray(), then 'cfg' would be NULL.

So just return -1, which in turn removes the need for cleanup:

10 years agovirnetserverservice: Resolve Coverity ARRAY_VS_SINGLETON
John Ferlan [Thu, 28 Aug 2014 13:03:47 +0000 (09:03 -0400)]
virnetserverservice: Resolve Coverity ARRAY_VS_SINGLETON

Coverity complained about the following:

(3) Event ptr_arith:
   Performing pointer arithmetic on "cur_fd" in expression "cur_fd++".
130             return virNetServerServiceNewFD(*cur_fd++,

The complaint is that pointer arithmetic taking place instead of the
expected auto increment of the variable...  Adding some well placed
parentheses ensures our order of operation.

10 years agoqemu: Allow use of iothreads for disk definitions
John Ferlan [Mon, 25 Aug 2014 19:59:32 +0000 (15:59 -0400)]
qemu: Allow use of iothreads for disk definitions

For virtio-blk-pci disks with the disk iothread attribute that are
running the correct emulator, add the "iothread=iothread#" to the
-device command line in order to enable iothreads for the disk as
long as the command is available, the disk iothread value provided is
valid, and is supported for the disk device being added

10 years agodomain_conf: Add support for iothreads in disk definition
John Ferlan [Mon, 25 Aug 2014 12:43:17 +0000 (08:43 -0400)]
domain_conf: Add support for iothreads in disk definition

Add a new disk "driver" attribute "iothread" to be parsed as the thread
number for the disk to use. In order to more easily facilitate the usage
and configuration of the iothread, a "zero" for the attribute indicates
iothreads are not supported for the device and a positive value indicates
the specific thread to try and use.

10 years agoqemu: Add support for iothreads
John Ferlan [Fri, 22 Aug 2014 22:15:30 +0000 (18:15 -0400)]
qemu: Add support for iothreads

Add a new capability to ensure the iothreads feature exists for the qemu
emulator being run - requires the "query-iothreads" QMP command. Using the
domain XML add correspoding command argument in order to generate the
threads. The iothreads will use a name space "iothread#" where, the
future patch to add support for using an iothread to a disk definition to
merely define which of the available threads to use.

Add tests to ensure the xml/argv processing is correct.  Note that no
change was made to qemuargv2xmltest.c as processing the -object element
would require knowing more than just iothreads.

10 years agodomain_conf: Introduce iothreads XML
John Ferlan [Fri, 22 Aug 2014 14:15:51 +0000 (10:15 -0400)]
domain_conf: Introduce iothreads XML

Introduce XML to allowing adding iothreads to the domain. These can be
used by virtio-blk-pci devices in order to assign a specific thread to
handle the workload for the device.  The iothreads are the official
implementation of the virtio-blk Data Plane that's been in tech preview
for QEMU.

10 years agolibxl_migration: Resolve Coverity NULL_RETURNS
John Ferlan [Thu, 28 Aug 2014 18:56:33 +0000 (14:56 -0400)]
libxl_migration: Resolve Coverity NULL_RETURNS

Coverity noted that all callers to libxlDomainEventQueue() could ensure
the second parameter (event) was true before calling except this case.
As I look at the code and how events are used - it seems that prior to
generating an event for the dom == NULL condition, the resume/suspend
event should be queue'd after the virDomainSaveStatus() call which will
goto cleanup and queue the saved event anyway.

Signed-off-by: John Ferlan <jferlan@redhat.com>
10 years agoqemu: Implement bulk stats API and one of the stats groups to return
Peter Krempa [Mon, 25 Aug 2014 16:54:49 +0000 (18:54 +0200)]
qemu: Implement bulk stats API and one of the stats groups to return

Implement the API function for virDomainListGetStats and
virConnectGetAllDomainStats in a modular way and implement the
VIR_DOMAIN_STATS_STATE group of statistics.

Although it may look like the function looks universal I'd rather not
expose it to other drivers as the coming stats groups are likely to do
qemu specific stuff to obtain the stats.

10 years agoqemu_command: Resolve Coverity DEADCODE
John Ferlan [Wed, 27 Aug 2014 20:33:12 +0000 (16:33 -0400)]
qemu_command: Resolve Coverity DEADCODE

One useless warning, but the other one rather pertinent. On entry
the 'trans' variable is initialized to VIR_DOMAIN_DISK_TRANS_DEFAULT.
When the "trans" was found in the parsing loop it def->geometry.trans
was assigned to the return from virDomainDiskGeometryTransTypeFromString
and then 'trans' was used to do the comparison to see if it was valid.

So remove 'trans' and use def->geometry.trans properly

10 years agoqemu_driver: Resolve Coverity DEADCODE
John Ferlan [Wed, 27 Aug 2014 20:24:34 +0000 (16:24 -0400)]
qemu_driver: Resolve Coverity DEADCODE

A bunch of false positives brought on by our own doings

10 years agodomain_conf: Resolve Coverity DEADCODE
John Ferlan [Wed, 27 Aug 2014 20:15:06 +0000 (16:15 -0400)]
domain_conf: Resolve Coverity DEADCODE

A bunch of a useless warnings brought on by our own doing.

10 years agoqemu_monitor: Resolve Coverity NESTING_INDENT_MISMATCH
John Ferlan [Wed, 27 Aug 2014 19:59:08 +0000 (15:59 -0400)]
qemu_monitor: Resolve Coverity NESTING_INDENT_MISMATCH

The PROBE macro can expand to more than one line/statement - put curly
braces around the if statement to be safe

10 years agostorage_conf: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:40:57 +0000 (15:40 -0400)]
storage_conf: Resolve Coverity RESOURCE_LEAK

If there was a failure processing 'authdef' and the code went to cleanup
before the setting to source->auth, then it'd be leaked.

10 years agoqemu_driver: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:37:13 +0000 (15:37 -0400)]
qemu_driver: Resolve Coverity RESOURCE_LEAK

Coverity found that the 'buf' wasn't VIR_FREE'd at exit.

10 years agophyp_driver: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:31:38 +0000 (15:31 -0400)]
phyp_driver: Resolve Coverity RESOURCE_LEAK

Coverity determines that when jumping to the connected: label, the
addressinfo (ai) is not free'd.

10 years agolibxl_migration: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:22:33 +0000 (15:22 -0400)]
libxl_migration: Resolve Coverity RESOURCE_LEAK

In libxlDomainMigrationPrepare() if the uri_in is false, then
'hostname' is allocated and used "generically" in the routine,
but not freed.  Conversely, if uri_in is true, then a uri is
allocated and hostname is set to the uri->hostname value and
likewise generically used.

At function exit, hostname wasn't free'd in the !uri_in path,
so that was added.  To just make it clearer on usage the else
path became the call to virURIFree() although I suppose technically
it didn't have to since it would be a call using (NULL)

10 years agobridge_driver: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:15:05 +0000 (15:15 -0400)]
bridge_driver: Resolve Coverity RESOURCE_LEAK

In the error path the 'ipaddr' wasn't VIR_FREE'd before jumping to cleanup

10 years agovirsh-network: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 19:06:56 +0000 (15:06 -0400)]
virsh-network: Resolve Coverity RESOURCE_LEAK

Need to free 'xmlFromFile' on/for the error path when current was
returning false only

10 years agonetwork_conf: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:57:53 +0000 (14:57 -0400)]
network_conf: Resolve Coverity RESOURCE_LEAK

Need to VIR_FREE the startip/endip we allocated for the error message

10 years agoqemu_capabilities: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:57:08 +0000 (14:57 -0400)]
qemu_capabilities: Resolve Coverity RESOURCE_LEAK

Coverity determined that on error path that 'mach' wouldn't be free'd
Since virCapabilitiesFreeGuestMachine() isn't globally available, we'll
insert first and then if the VIR_STRDUP's fail they it will eventually
cause the 'mach' to be freed in the error path

10 years agolibxl_domain: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:47:43 +0000 (14:47 -0400)]
libxl_domain: Resolve Coverity RESOURCE_LEAK

On the error path need to free the chrdef

10 years agoqemu_agent: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:42:41 +0000 (14:42 -0400)]
qemu_agent: Resolve Coverity RESOURCE_LEAK

Coverity found that on error paths, the 'arg' value wasn't be cleaned
up. Followed the example in qemuAgentSetVCPUs() where upon successful call
to qemuAgentCommand() the 'cpus' is set to NULL; otherwise, when cleanup
occurs the free the memory for 'arg'

10 years agoqemu_command: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:32:27 +0000 (14:32 -0400)]
qemu_command: Resolve Coverity RESOURCE_LEAK

In qemuParseISCSIString() if an error was returned, then the call
to qemuParseDriveURIString() where the uri is free'd wouldn't be run

10 years agocpu_x86: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:27:07 +0000 (14:27 -0400)]
cpu_x86: Resolve Coverity RESOURCE_LEAK

Coverity determined that the copied 'oldguest' would be leaked for
both error and success paths.

10 years agodomain_conf: Resolve Coverity RESOURCE_LEAK
John Ferlan [Wed, 27 Aug 2014 18:14:56 +0000 (14:14 -0400)]
domain_conf: Resolve Coverity RESOURCE_LEAK

Resolve a few RESOURCE_LEAK's identified by Coverity

10 years agodaemon: Resolve Coverity NEGATIVE_RETURNS
John Ferlan [Wed, 27 Aug 2014 17:38:29 +0000 (13:38 -0400)]
daemon: Resolve Coverity NEGATIVE_RETURNS

In each of these cases, Coverity complains that the result count returned
on error paths would be -1 disregarding that the count and the corresponding
are "linked" together (it doesn't know that).  Simple enough to check and
remove the warning

10 years agovirsh: Implement command to excercise the bulk stats APIs
Peter Krempa [Tue, 26 Aug 2014 13:55:14 +0000 (15:55 +0200)]
virsh: Implement command to excercise the bulk stats APIs

Add "domstats" command that excercises both of the new APIs depending if
you specify a domain list or not. The output is printed as a key=value
list of the returned parameters.

10 years agoqemu_capabilities: Resolve Coverity RESOURCE_LEAK
Wang Rui [Thu, 28 Aug 2014 10:20:58 +0000 (18:20 +0800)]
qemu_capabilities: Resolve Coverity RESOURCE_LEAK

In function virQEMUCapsParseMachineTypesStr, VIR_STRNDUP allocates
memory for 'name' in {do,while} loop. If 'name' isn't freed before
'continue', its memory will be allocated again in the next loop.
In this case the memory allocated for 'name' in privious loop is
useless and not freed. Free it before continue this loop to fix that.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agotests: Resolve Coverity RESOURCE_LEAK
Wang Rui [Thu, 28 Aug 2014 10:20:57 +0000 (18:20 +0800)]
tests: Resolve Coverity RESOURCE_LEAK

The 'lib' handle will be leaked if 'dlsym' condition fails.
So close the handle before return.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agoutil: Resolve Coverity RESOURCE_LEAK
Wang Rui [Thu, 28 Aug 2014 10:20:56 +0000 (18:20 +0800)]
util: Resolve Coverity RESOURCE_LEAK

Coverity determined that 'conflict' would be leaked.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
10 years agoremote: Implement bulk domain stats APIs in the remote driver
Peter Krempa [Mon, 25 Aug 2014 11:22:13 +0000 (13:22 +0200)]
remote: Implement bulk domain stats APIs in the remote driver

Implement the remote driver support for shuffling the domain stats
around.

10 years agolib: Add few flags for the bulk stats APIs
Peter Krempa [Wed, 27 Aug 2014 15:02:50 +0000 (17:02 +0200)]
lib: Add few flags for the bulk stats APIs

Add domain list filtering functions and a flag to enforce checking
whether the remote daemon supports the requested stats groups.

10 years agoconf: Add helper to free domain list
Peter Krempa [Wed, 27 Aug 2014 12:56:45 +0000 (14:56 +0200)]
conf: Add helper to free domain list

Add helper to free a list of virDomainPtrs without raising or clearing
errors. Use it in one place and prepare it for reuse.

10 years agovirsh: fix keepalive error msg
Erik Skultety [Wed, 27 Aug 2014 14:20:29 +0000 (16:20 +0200)]
virsh: fix keepalive error msg

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

The error message for an out-of-range argument was confusing:

virsh -k 9999999999
error: option --k requires a positive numeric argument

After this patch, it is:

error: Invalid value for option -k

Signed-off-by: Eric Blake <eblake@redhat.com>
10 years agoqemu_capabilities: Resolve Coverity NULL_RETURNS
John Ferlan [Wed, 27 Aug 2014 13:43:52 +0000 (09:43 -0400)]
qemu_capabilities: Resolve Coverity NULL_RETURNS

Adjust the initialization of qemuCaps() to check for a NULL before
attempting to dereference like other callers/users do.

10 years agoqemu_driver: Resolve Coverity CONSTANT_EXPRESSION_RESULT
John Ferlan [Wed, 27 Aug 2014 13:14:16 +0000 (09:14 -0400)]
qemu_driver: Resolve Coverity CONSTANT_EXPRESSION_RESULT

The call to virDomainSnapshotRedefinePrep() had a spurrious ! in front of
it which caused Coverity to complan that the expression is always false.

10 years agodomain_conf: Resolve Coverity REVERSE_INULL
John Ferlan [Wed, 27 Aug 2014 12:51:15 +0000 (08:51 -0400)]
domain_conf: Resolve Coverity REVERSE_INULL

Coverity complains that checking for domain->def being non NULL in the
if (live) path of virDomainObjAssignDef() would be unnecessary or a
NULL deref since the call to virDomainObjIsActive() would already
dereference domain->def when checking if the def->id field was != -1.

Checked all callers to virDomainObjAssignDef() and each at some point
dereferences (vm)->def->{field} prior to calling when live is true.

10 years agoqemu_command: Resolve Coverity REVERSE_INULL
John Ferlan [Wed, 27 Aug 2014 12:35:08 +0000 (08:35 -0400)]
qemu_command: Resolve Coverity REVERSE_INULL

In qemuNetworkIfaceConnect() a call to virNetDevBandwidthSet() is
made where the function prototype requires the first parameter
(net->ifname) to be non NULL.  Coverity complains that the subsequent
non NULL check for net->ifname prior to the next call gets flagged as
an unnecessary check.  Resolve by removing the extra check

10 years agodomain_conf: Resolve Coverity REVERSE_INULL
John Ferlan [Wed, 27 Aug 2014 12:01:44 +0000 (08:01 -0400)]
domain_conf: Resolve Coverity REVERSE_INULL

In virDomainActualNetDefFormat() a call to virDomainNetGetActualType(def)
was made before a check for (!def) a few lines later. This triggered
Coverity to note the possible NULL deref.  Just moving the initialization
to after the !def checks resolves the issue

10 years agostorage_driver: Resolve Coverity REVERSE_INULL
John Ferlan [Wed, 27 Aug 2014 11:56:00 +0000 (07:56 -0400)]
storage_driver: Resolve Coverity REVERSE_INULL

There were two occurrances of attempting to initialize actualType by
calling virStorageSourceGetActualType(src) prior to a check if (!src)
resulting in Coverity complaining about the possible NULL dereference
in virStorageSourceGetActualType() of src.

Resolve by moving the actualType setting until after checking !src

10 years agoxen_xm: Resolve Coverity USE_AFTER_FREE
John Ferlan [Wed, 27 Aug 2014 11:48:37 +0000 (07:48 -0400)]
xen_xm: Resolve Coverity USE_AFTER_FREE

If virDomainDiskDefFree(disk) is called in 'skipdisk:', then it's possible
to either return to skipdisk without reallocating a new disk (via the if
condition just prior) or to end the loop having deleted the disk. Since
virDomainDiskDefFree() does not pass by reference, disk isn't changed in
this context, thus the possible issue.

10 years agoxen_common: Resolve Coverity USE_AFTER_FREE
John Ferlan [Wed, 27 Aug 2014 11:40:02 +0000 (07:40 -0400)]
xen_common: Resolve Coverity USE_AFTER_FREE

There were two warnings in this module

  If the VIR_ALLOC_N(def->serials, 1) fails, then a virDomainChrDefFree(chr)
  is called and we jump to cleanup which makes the same call. Just remove
  the one after VIR_ALLOC_N()

  In the label "skipnic:" a virDomainNetDefFree(net) is made; however, if
  in going back to the top of the loop we jump back down to skipnic for any
  reason, the call will attempt to free an already freed structure since
  "net" was not passed by reference to virDomainNetDefFree().  Just set
  net = NULL in skipnic: to resolve the issue.

10 years agoparallels: Resolve Coverity USE_AFTER_FREE
John Ferlan [Wed, 27 Aug 2014 11:32:11 +0000 (07:32 -0400)]
parallels: Resolve Coverity USE_AFTER_FREE

Coverity complains that calling virNetworkDefFree(def), then jumping
to the cleanup: label which calls virNetworkDefFree(def) could result
in a double_free.  Just remove the call from the if statement.

10 years agoconf: fix leak with def->mem.hugepages
Martin Kletzander [Wed, 27 Aug 2014 13:16:03 +0000 (15:16 +0200)]
conf: fix leak with def->mem.hugepages

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agovbox: Register per partes
Michal Privoznik [Fri, 22 Aug 2014 09:37:52 +0000 (11:37 +0200)]
vbox: Register per partes

Since times when vbox moved to the daemon (due to some licensing
issue) the subdrivers that vbox implements were registered, but not
opened since our generic subdrivers took priority. I've tried to fix
this in 65b7d553f39ff9 but it was not correct. Apparently moving
vbox driver registration upfront changes the default connection URI
which makes some users sad. So, this commit breaks vbox into pieces
and register vbox's network and storage drivers first, and vbox driver
then at the end. This way, the vbox driver is registered in the order
it always was, but its subdrivers are registered prior the generic
ones.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
10 years agovirDriverLoadModule: Honor libvirt func name tranlsation
Michal Privoznik [Fri, 22 Aug 2014 09:37:51 +0000 (11:37 +0200)]
virDriverLoadModule: Honor libvirt func name tranlsation

There's this unwritten rule in libvirt that vir_function is translated
into virFunction when needed (e.g. in remote protocol definition,
python, ...). Up till now we ignored such translation in driver module
loading and did fine. Well, we didn't have any module with an
underscore in its name. But this will change in next commit. The
problem is, once an a module is dlopen()-ed, we derive register
function name from its name. So instead of "driver_subdriverRegister"
do some magic to turn that into "driverSubdriverRegister".

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
10 years agovirdrivermoduletest: Test all the modules
Michal Privoznik [Fri, 22 Aug 2014 09:37:50 +0000 (11:37 +0200)]
virdrivermoduletest: Test all the modules

Even though we kept adding new and new modules (e.g. vbox or bhyve)
the test wasn't updated. Do that now. Moreover, while it's not
crucial, it's nice to reorder test cases to match the order in which
the daemon loads the modules.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>