Commit Graph

19247 Commits

Author SHA1 Message Date
Michal Privoznik
96a21e975f Cleanup "/sys/class/net" usage
Throughout the code, we have several places need to construct a path
somewhere in /sys/class/net/... They are not consistent and nearly
each code piece invents its own way how to do it. So unify this by:

1) use virNetDevSysfsFile() wherever possible

2) At least use common macro SYSFS_NET_DIR declared in virnetdev.h at
   the rest of places which can't go with 1)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-15 16:43:28 +02:00
Michal Privoznik
598f3fddbc tests: Add virnetdevtestdata to EXTRA_DIST
In one of my previous commits (49ed6cff9) I've introduced a test
among with some files stored under virnetdevtestdata folder.
While this works perfectly within a git tree, the folder was not
getting into .tar.gz and therefore the dist-check would fail.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-15 16:43:28 +02:00
John Ferlan
960e009c58 tests: Resolve Coverity RESOURCE_LEAK
Commit id 'b77ce18a2' added a new bitmap, but neglected to virBitmapFree it
2015-04-15 10:29:41 -04:00
Eric Blake
31ef0836a7 virsh: fix regression in 'virsh event' by domain
Commit a0670ae caused a regression in 'virsh event' and
'virsh qemu-monitor-event' - if a user tries to filter the
command to a specific domain, an error message is printed:

$ virsh event dom --loop
error: internal error: virsh qemu-monitor-event: no domain VSH_OT_DATA option

and then the command continues as though no domain had been
supplied (giving events for ALL domains, instead of the
requested one).  This is because the code was incorrectly
assuming that all "domain" options would be supplied via a
mandatory VSH_OT_DATA, even though "domain" is optional for
these two commands, so we had changed them to VSH_OT_STRING
to quit failing for other reasons (ever since it was decided
that VSH_OT_DATA and VSH_OT_STRING should no longer be
synonyms).

In looking at the situation, though, the code for looking up
a domain was making a pointless check for whether the option
exists prior to finding the option's string value, as
vshCommandOptStringReq does just fine at reporting any errors
when looking up a string whether or not the option was present.

So this is a case of regression fixing by pure code deletion :)

* tools/virsh-domain.c (vshCommandOptDomainBy): Drop useless filter.
* tools/virsh-interface.c (vshCommandOptInterfaceBy): Likewise.
* tools/virsh-network.c (vshCommandOptNetworkBy): Likewise.
* tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise.
* tools/virsh-secret.c (vshCommandOptSecret): Likewise.
* tools/virsh.h (vshCmdHasOption): Drop unused function.
* tools/virsh.c (vshCmdHasOption): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2015-04-15 08:13:53 -06:00
Peter Krempa
ee1cc9a459 node: udev: Remove some redundant error reports
All the called functions already report an error.
2015-04-15 15:20:12 +02:00
Michal Privoznik
6515f3df94 virPidFileConstructPath: Drop useless VIR_FREE()
If a virAsprintf() within the function fails, we call VIR_FREE()
over @rundir variable and jump onto cleanup label, where it is
freed again.  It doesn't hurt, but not make much sense too.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-15 15:01:02 +02:00
Peter Krempa
7961713410 qemu: monitor: Fix qemuMonitorGetAllBlockStatsInfo with HMP
Commit f6563bc3 introduced HMP impl of the function (so that a different
uglier function could be removed). Before the HMP code is called there's
a leftover check that the monitor is JSON which inhibits the code from
working.
2015-04-15 13:58:26 +02:00
Peter Krempa
a745d83fe0 qemu: monitor: @running in qemuMonitorGetStatus is always non-NULL
Add the attribute and remove the check.
2015-04-15 13:58:26 +02:00
Peter Krempa
81d14c0252 qemu: monitor: Don't use 'ret' variable where not necessary
Quite a lot places set the 'ret' variable just once right before
returning it's value. Remove such usage.
2015-04-15 13:58:26 +02:00
Peter Krempa
ee591240c2 qemu: monitor: Ensure that qemuMonitorSetLink is called with non-null name 2015-04-15 13:58:26 +02:00
Peter Krempa
0e9fadd66d qemu: monitor: Sanitize control flow in qemuMonitorSetCapabilities 2015-04-15 13:58:26 +02:00
Peter Krempa
119aa5d35a qemu: monitor: Clean up coding style
Fix line spacing between functions, ensure that function return type is
on a separate line and reflow arguments for VIR_DEBUG statements.
2015-04-15 13:58:25 +02:00
Michal Privoznik
be78814ae0 virNetSocketNewConnectUNIX: Use flocks when spawning a daemon
https://bugzilla.redhat.com/show_bug.cgi?id=1200149

Even though we have a mutex mechanism so that two clients don't spawn
two daemons, it's not strong enough. It can happen that while one
client is spawning the daemon, the other one fails to connect.
Basically two possible errors can happen:

  error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': Connection refused

or:

  error: Failed to connect socket to '/home/mprivozn/.cache/libvirt/libvirt-sock': No such file or directory

The problem in both cases is, the daemon is only starting up, while we
are trying to connect (and fail). We should postpone the connecting
phase until the daemon is started (by the other thread that is
spawning it). In order to do that, create a file lock 'libvirt-lock'
in the directory where session daemon would create its socket. So even
when called from multiple processes, spawning a daemon will serialize
on the file lock. So only the first to come will spawn the daemon.

Tested-by: Richard W. M. Jones <rjones@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-15 13:39:13 +02:00
Martin Kletzander
bb6a62d4ab json: export non-static functions
Two non-static functions in virjson.c were missing their export info in
libvirt_private.syms, so they couldn't be used anywhere it the code (and
that's about to get changed).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-15 13:33:35 +02:00
Martin Kletzander
fae5b555c8 Change virConnectPtr into virObjectLocklable
It already had a virMutex inside, so this is just a cleanup.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-15 13:33:35 +02:00
Martin Kletzander
6dfbaca7b7 closeCallback is already lockable, initialize it as such
Luckily we are allocating structs as clean memory and
PTHREAD_MUTEX_INITIALIZER is "{ 0 }", so nothing happened, but it should
still be created as lockable object.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-15 13:33:35 +02:00
Martin Kletzander
5336a3a47c configure: Align messages
The first two were a bit off.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-15 13:33:35 +02:00
John Ferlan
5817451947 storage: Add duplicate devices check for zfs pool def
Check proposed pool definitions to ensure they aren't trying to use the
same devices as currently defined definitions - disallow the duplicate
2015-04-15 06:51:20 -04:00
John Ferlan
2184ade3a0 storage: Add duplicate source pool for Gluster pool def
Check the proposed pool source host XML definition against existing gluster
pools to ensure the incoming definition doesn't use the same source dir and
soure host XML definition as an existing pool.
2015-04-15 06:50:27 -04:00
John Ferlan
521add056e storage: Add duplicate host check for Sheepdog pool def
Check the proposed pool source host XML definition against existing sheepdog
pools to ensure the incoming definition doesn't use the same source host XML
definition as an existing pool.
2015-04-15 06:40:08 -04:00
John Ferlan
556a21f9fb storage: Remove default from switch in virStoragePoolSourceFindDuplicate
So that we can cover all the cases.
2015-04-15 06:40:08 -04:00
John Ferlan
d92be7f42f storage: Use virStoragePoolSourceMatchSingleHost for NETFS
Rather than have duplicate code doing the same check, have the netfs
matching processing code use the new virStoragePoolSourceMatchSingleHost.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-04-15 06:40:07 -04:00
John Ferlan
401623bcb4 storage: Add check for different ports for host duplicate matching
In virStoragePoolSourceMatchSingleHost, add a comparison for port number
being different prior to checking the 'name' field.
2015-04-15 06:40:07 -04:00
John Ferlan
9aced8c9d5 storage: Create virStoragePoolSourceMatchSingleHost
Split out the nhost == 1 and hosts[0].name logic into a separate routine

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-04-15 06:40:07 -04:00
John Ferlan
fc20b41271 storage: Refactor iSCSI Source matching
Create a separate iSCSI Source matching subroutine. Makes the calling
code a bit cleaner as well as sets up for future patches which need to
do better source hosts[0].name processing/checking.

As part of the effort the logic will be inverted from a multi-level
if statement to a series of single level checks for better readability
and further separation

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-04-15 06:40:01 -04:00
Jiri Denemark
4864e377c9 sanlock: Use VIR_ERR_RESOURCE_BUSY if sanlock_acquire fails
When acquiring resource via sanlock fails, we would report it as
VIR_ERR_INTERNAL_ERROR, which is not very friendly to applications using
libvirt. Moreover, the lockd driver would report the same failure as
VIR_ERR_RESOURCE_BUSY, which looks better.

Unfortunately, in sanlock driver we don't really know if acquiring the
resource failed because it was already locked or there was another
reason behind. But the end result is the same and I think using
VIR_ERR_RESOURCE_BUSY reason for all acquire failures is still better
than what we have now.

https://bugzilla.redhat.com/show_bug.cgi?id=1165119
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-04-15 09:40:42 +02:00
Eric Blake
58dfc53414 build: provide virNetDevSysfsFile on non-Linux
Commit 49ed6cff is broken on mingw and other non-linux platforms:

  CCLD     libvirt.la
  Cannot export virNetDevSysfsFile: symbol not defined
  collect2: error: ld returned 1 exit status

* src/util/virnetdev.c: Provide virNetDevSysfsFile fallback.

Signed-off-by: Eric Blake <eblake@redhat.com>
2015-04-14 13:53:50 -06:00
Eric Blake
e4ab084813 build: include correct header for time()
Found by ./autobuild.sh during a mingw cross-compile:

Commit 8a96e87 was not innocuous - glibc happens to leak the
definition of time() through other headers, so that even without
<sys/select.h>, virrandom.c compiled just fine.  But on mingw,
we were not so lucky; <sys/select.h> was important for its side
effect of dragging in <time.h>, and we now have nothing providing
the declaration of time():

../../src/util/virrandom.c: In function 'virRandomOnceInit':
../../src/util/virrandom.c:65:5: error: implicit declaration of function 'time' [-Werror=implicit-function-declaration]
     unsigned int seed = time(NULL) ^ getpid();
          ^
	  ../../src/util/virrandom.c:65:5: error: nested extern declaration of 'time' [-Werror=nested-externs]

Signed-off-by: Eric Blake <eblake@redhat.com>
2015-04-14 13:24:51 -06:00
Michal Privoznik
49ed6cff99 Introduce virnetdevtest
This is yet another test for check of basic functionality of our
NIC state handling code.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-04-14 19:33:02 +02:00
John Ferlan
d223ca67cb cfg: Disallow usage of 'index' as variable name
Since we've run afoul of the Xen-devel build for shadowing a global
declaration of 'index', just disallow using index for a variable name
2015-04-14 11:18:28 -04:00
John Ferlan
ba7e88edf7 nwfilter: Change 'index' to 'idx'
Forthcoming syntax check rule will disallow usage of 'int index', so
change it for nwfilter
2015-04-14 11:18:28 -04:00
John Ferlan
29359e99bf snapshot: Change 'index' to 'idx'
Forthcoming syntax check rule will disallow usage of 'int index', so
change it for snapshot
2015-04-14 11:18:28 -04:00
John Ferlan
454e52c89d util: Use 'idx' instead of 'index'
Impending syntax checker will disallow 'int index', so change it here.
2015-04-14 11:18:28 -04:00
John Ferlan
f44429a0bc qemu: Adjust the prototype to match the function
Changing the prototype to not have "int *index" since we'll soon be
disallowing index as a name. Curiously the original commit (a4504ac)
for the function used 'int idx' in the function - so they didn't match.
Now they do.
2015-04-14 11:18:28 -04:00
Ján Tomko
682ba8e930 Add articles to virDomainDeviceDetachFlags docs
Reported by John Ferlan.
2015-04-14 15:32:24 +02:00
Pavel Hrdina
e60c84f0ce xen: fix build error on rhel-5
../../src/xen/block_stats.c:82: warning: dereferencing type-punned
    pointer will break strict-aliasing rules [-Wstrict-aliasing]

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-04-14 15:14:58 +02:00
Martin Kletzander
f38bd06bff sparc: Add default PCI root controller
It is there even with -nodefaults and -no-user-config, so count with
that so we can start sparc domains.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-04-14 14:49:15 +02:00
Huanle Han
a959671da8 hostdev: fix loop index error when resetvfnetconfig
The variable 'last_processed_hostdev_vf' indicates index of the last
successfully configed vf. When resetvfnetconfig because of failure,
hostdevs[last_processed_hostdev_vf] should also be reset.

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
2015-04-14 14:49:15 +02:00
Huanle Han
c61ded8a7d qemu: fix index error when clean up vport profile
1. 'last_good_net' indicates the index of last successfully configured
net. so def->nets[last_good_net] should also be clean up if error occurs.

2. if error occurs in 'virNetDevMacVLanVPortProfileRegisterCallback'
(second 'goto err_exit' in loop), we should also do
'virNetDevVPortProfileDisassociate' cleanup for the
'virNetDevVPortProfileAssociate'(first code block in loop). So we should
consider the net is successfully configured after first code block in
loop finishes.

Signed-off-by: Huanle Han <hanxueluo@gmail.com>
2015-04-14 14:49:15 +02:00
Serge Hallyn
03d7462d87 virt-aa-helper: add unix channels (esp for qemu-guest-agent)
The original bug report was at
https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1393842

Also skip abstract unix sockets.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-04-14 14:06:27 +02:00
Shanzhi Yu
1db6212331 qemu: save domain status after set memory parameters
After set memory parameters for running domain, save the change to live
xml is needed otherwise it will disappear after restart libvirtd.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1211548
Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-04-14 13:50:08 +02:00
Shanzhi Yu
8ff9f2457d virsh: improve the error for wrong memtune parameters
When set guest memory with a invalid parameter of --soft-limit,
it posts weird error:

$ virsh memtune r7 --hard-limit 20417224 --soft-limit 9007199254740992 \
  --swap-hard-limit 35417224
error: Unable to parse integer parameter 'NAME

Change it to

error: Unable to parse integer parameter soft-limit

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1211550
Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-04-14 13:48:29 +02:00
John Ferlan
d375368790 qemu: Use 'idx' instead of 'index' for variable name
Apparently for Xen-devel 'index' is a global and causes a build failure,
so just use the shortened 'idx' instead to avoid the conflict.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-04-14 07:18:32 -04:00
Peter Krempa
634285f9c1 qemu: Refactor qemuDomainBlockJobAbort()
Change few variable names and refactor the code flow. As an additional
bonus the function now fails if the event state is not as expected.
2015-04-14 10:00:56 +02:00
Peter Krempa
8a609afb6f qemu: drivePivot: Fix assumption when 'block-job-complete' fails
QEMU does not abandon the mirror. The job carries on in the synchronised
phase and it might be either pivoted again or cancelled. The commit
hints that the described behavior was happening in a downstream version.

If the command returns false there are two possible options:
1) qemu did not reach the point where it would ask the block job to
pivot
2) pivotting failed in the actual qemu coroutine

If either of those would happen we return failure and reset the
condition that waits for the block job to complete. This makes the API
fail but in case where qemu would actually abandon the mirror the fact
is notified via the event and handled asynchronously.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1202704
2015-04-14 10:00:56 +02:00
Peter Krempa
065a81082d qemu: blockPull: Refactor the rest of qemuDomainBlockJobImpl
Since it now handles only block pull code paths we can refactor it and
remove tons of cruft.
2015-04-14 10:00:56 +02:00
Peter Krempa
cfc0a3d4ce qemu: blockjob: Separate qemuDomainBlockJobAbort from qemuDomainBlockJobImpl
Sacrifice a few lines of code in favor of the code being more readable.
2015-04-14 10:00:56 +02:00
Peter Krempa
1344a74ef2 qemu: blockjob: Split qemuDomainBlockJobSetSpeed from qemuDomainBlockJobImpl
qemuDomainBlockJobImpl become an unmaintainable mess over the years of
adding new stuff to it. This patch starts splitting up individual
functions from it until it can be killed entirely.

In bulk this will add lines of code rather than delete them but it will
be traded for maintainability.
2015-04-14 10:00:56 +02:00
Peter Krempa
7db64d6b0a qemu: monitor: Extract handling of JSON block job error codes
My intention is to split qemuMonitorJSONBlockJob() into simpler separate
functions for every block job type. Since the error handling code is the
same for all block jobs, this patch extracts the code into a separate
function that will later be reused in more places.

With the new helper qemuMonitorJSONErrorIsClass we can save a few
function calls as we can extract the error object once.
2015-04-14 10:00:56 +02:00
Peter Krempa
72613b18ac qemu: monitor: json: Refactor error code class checker
Split out the function that checks the actual error class string into a
separate helper as it will be useful later and refactor
qemuMonitorJSONHasError to return bool type and remove few useless
checks.

Basically virJSONValueObjectHasKey are useless here since the next call
to virJSONValueObjectGet is checking the return value again (which can't
fail at that point). By removing the first check we save a function
call.
2015-04-14 10:00:56 +02:00