Commit Graph

1505 Commits

Author SHA1 Message Date
Ján Tomko
ea723c4826 virsh: rename vshCommandOptString to vshCommandOptStringQuiet
This function does not set an error. Make it obvious in its name
to discourage its usage without reporting an error in the caller.
2015-12-09 10:44:26 +01:00
Ján Tomko
b15e26f939 virsh: remove custom error for cpulist from cmdIOThreadPin
Instead of the custom error:
error: iothreadpin: invalid cpulist.

use vshCommandOptStringReq and let it report a more specific error:
error: Failed to get option 'cpulist': Option argument is empty
2015-12-03 13:58:52 +01:00
Ján Tomko
45138725cf virsh: report errors for empty strings
Several callers were using vshCommandOptString without setting an error.
Use vshCommandOptStringReq which sets the error.

https://bugzilla.redhat.com/show_bug.cgi?id=1281707
2015-12-03 13:58:52 +01:00
Martin Kletzander
df8192aaf4 admin: Rename virAdmConnect to virAdmDaemon
virAdmConnect was named after virConnect, but after some discussions,
most of the APIs called will be working with remote daemon and starting
them virAdmDaemon will make more sense.  Only possibly controversal name
is CloseCallback (de)registration, and connecting to the daemon (which
will still be Open/Close), but even this makes sense if one thinks about
the daemon being opened and closed, e.g. as file, etc.

This way all the APIs working with the daemon will start with
virAdmDaemon prefix, they will accept virAdmDaemonPtr as first parameter
and that will better suit with other namings as well (virDomain*,
virAdmServer*, etc.).

Because in virt-admin, the connection name does not refer to a struct
that would have a connect in its name, also adjust 'connname' in
clients.  And because it is not used anywhere in the vsh code, move it
from there into each client.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-12-01 11:44:48 +01:00
Wei Jiangang
8dd47ead18 tools: fix output of list with state-shutoff
Due to the default of flags is VIR_CONNECT_LIST_DOMAINS_ACTIVE,
It doesn't show the domains that have been shutdown when we use
'virsh list' with only --state-shutoff.

Signed-off-by: Wei Jiangang <weijg.fnst@cn.fujitsu.com>
2015-11-30 15:08:44 +01:00
Michal Privoznik
90f3c0d717 conf: Split virDomainObjList into a separate file
Our domain_conf.* files are big enough. Not only they contain XML
parsing code, but they served as a storage of all functions whose
name is virDomain prefixed. This is just wrong as it gathers not
related functions (and modules) into one big file which is then
harder to maintain. Split virDomainObjList module into a separate
file called virdomainobjlist.[ch].

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-11-30 13:55:10 +01:00
Erik Skultety
163a781e63 virt-admin: Provide a man page for virt-admin 2015-11-30 09:44:28 +01:00
Erik Skultety
a474371fc6 admin: Introduce virAdmConnectGetLibVersion
Introduce a new API to get libvirt version. It is worth noting, that
libvirt-admin and libvirt share the same version number. Unfortunately,
our existing API isn't generic enough to be used with virAdmConnectPtr
as well. Also this patch wires up this API to the virt-admin client
as a generic cmdVersion command.
2015-11-30 09:44:28 +01:00
Erik Skultety
6dd7e42d89 admin: Add support for connection close callbacks
As we need a client disconnect handler, we also need a mechanism to register
such handlers for a client. This patch introduced both the close callbacks and
also the client vshAdmCatchDisconnect handler to be registered with it. By
registering the handler we still need to make sure the client can react to
daemon's events like disconnect or keepalive, so asynchronous I/O event polling
is necessary to be enabled too.
2015-11-30 09:44:28 +01:00
Erik Skultety
dbecb87f94 admin: Add URI support and introduce virAdmGetDefaultURI
Since virt-admin should be able to connect to various admin servers
on hosted different daemons, we need to provide URI support to
libvirt-admin.
2015-11-30 09:44:28 +01:00
Erik Skultety
47a089f06c admin: Introduce virAdmConnectIsAlive
Since most of our APIs rely on an acive functional connection to a daemon and
we have such a mechanism in libvirt already, there's need to have such a way in
libvirt-admin as well. By introducing a new public API, this patch provides
support to check for an active connection.
2015-11-30 09:44:28 +01:00
Erik Skultety
6409578790 virt-admin: Introduce first working skeleton
This patch introduces virt-admin client which is based on virsh client,
but had to reimplement several methods to meet virt-admin specific needs
or remove unnecessary virsh specific logic.
2015-11-30 09:44:28 +01:00
Martin Kletzander
adac38dbbd virsh: Try to keep printed XML pretty with change-media
When adding a new media with change-media and --print-xml, let's try
making it more readable and nice.

Before:
<disk type="file" device="cdrom">
...
      <target dev="hdb" bus="ide"/>
      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
    <source file="/tmp/a.iso"/></disk>

After:
<disk type="file" device="cdrom">
...
      <source file="/tmp/a.iso"/>
      <target dev="hdb" bus="ide"/>
      <address type="drive" controller="0" bus="0" target="0" unit="1"/>
    </disk>

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-11-26 15:10:55 +01:00
Guido Günther
ba08d16d6c libvirt-guests: Disable shutdown timeout
Since we can't know at service start how many VMs will be running we
can't calculate an apropriate shutdown timeout. So instead of killing
off the service just let it use it's own internal timeout mechanism.

References:
    http://bugs.debian.org/803714
    https://bugzilla.redhat.com/show_bug.cgi?id=1195544
2015-11-18 08:15:12 +01:00
Pavel Hrdina
a9a583d6df virsh-domain: update attach-interface to support type=hostdev
Adding this feature will allow users to easily attach a hostdev network
interface using PCI passthrough.

The interface can be attached using --type=hostdev and PCI address or
as --source.  This command also allows you to tell, whether the interface
should be managed.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-11-11 15:03:42 +01:00
Pavel Hrdina
18657e9919 virsh.pod: improve attach-interface section
Rewrite the attach-interface section in man page to be more readable and
extendable.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-11-11 15:01:37 +01:00
Pavel Hrdina
8eddc307e9 virsh-domain: use correct base for virStrToLong_ui
While parsing device addresses we should use correct base and don't
count on auto-detect.  For example, PCI address uses hex numbers, but
each number starting with 0 will be auto-detected as octal number and
that's wrong.  Another wrong use-case is for PCI address if for example
bus is 10, than it's incorrectly parsed as decimal number.

PCI and CCW addresses have all values as hex numbers, IDE and SCSI
addresses are in decimal numbers.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-10-27 15:26:44 +01:00
Luyao Huang
c62c59a984 virsh: Display an error when passing count <= 0 to setvcpus
The number of vCPUs for a guest must be between 1 and the
maximum value configured in the domain XML. This commit
introduces checks to make sure that passing count <= 0
results in an error.

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-10-22 09:22:44 +02:00
Peter Krempa
4ceaa7491e virsh: Use 'format' argument only when specified
The condition checking whether --format was specified was incorrect.
virsh crashed if the following format was used:

 virsh dump VM dump --format '' --memory-only

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1272301
2015-10-16 09:01:17 +02:00
Daniel P. Berrange
9139b46a6b virt-host-validate: check for IOMMU support
This looks for existance of DMAR (Intel) and IVRS (AMD)
files under /sys/firmware/acpi/tables/, as a sign that
the platform has IOMMU present & enabled in the BIOS.

If these are present and /sys/kernel/iommu_groups does
not contain any entries this is taken as a sign that
the kernel has not enabled the IOMMU currently.

If no ACPI tables are found we can't distinguish between
disabled in BIOS and not present in the hardware, so we
have to give the user a generic hint.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-13 10:54:09 +01:00
Daniel P. Berrange
09a7a34076 virt-host-validate: disable mntent code on Win32
Win32 does not have support for mntent.h header, so the
method which uses this must be stubbed out.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-12 14:37:37 +01:00
Daniel P. Berrange
9bf595b172 virt-host-validate: check for required cgroups
Extend the virt-host-validate checks to see if the required
cgroups are compiled into the kernel and that they are
mounted on the system. The cgroups are all optional except
for 3 that LXC mandates

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-12 13:15:00 +01:00
Daniel P. Berrange
fd6d506c50 virt-host-validate: distinguish exists vs accessible for devices
Currently we just check that various devices are accessible.
This leads to inaccurate errors reported for /dev/kvm and
/dev/vhost-net if they exist but an unprivileged user lacks
access. Switch existing checks to look for file existance,
and add a separate check for accessibility of /dev/kvm
since some distros don't grant users access by default.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-12 13:15:00 +01:00
Daniel P. Berrange
8a6b6037f8 virt-host-validate.c: check for kernel namespaces
The LXC driver requires the uts, mnt, pid & ipc
namespaces, while net & user namespaces are
optional. Validate all these are present.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2015-10-12 13:15:00 +01:00
Michal Privoznik
d72a8f7465 virsh: Preserve startupPolicy in change-media command
https://bugzilla.redhat.com/show_bug.cgi?id=1250331

Even after my rework of startupPolicy handling, one command
slipped my attention. The change-media command has a very unique
approach to constructing disk XML. However, it will not preserve
startupPolicy attribute.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-29 13:29:29 +02:00
Michal Privoznik
1fb8ac4c79 tools: Link libvirt.la and readline to libvirt_shell.a
So, our mingw build is broken. It's because while libvirt_shell
library is using some of our internal APIs, e.g. virStrndup, and
readline API but it's not being linked with nor libvirt.la nor
libreadline.  Only subsequent users of the library, like virsh,
do link to the needed libraries. In fact, I'm surprised Linux
linker doesn't care, because how can it make a static library
with missing symbols is mystery to me.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-25 14:33:06 +02:00
Erik Skultety
2d9fcb3102 vsh: create a noinstall libvirt_shell library
Instead of referencing vsh sources in all relevant client targets,
create a library that the client can link against.
2015-09-24 16:58:28 +02:00
John Ferlan
35369a7d48 virsh: Resolve Coverity DEADCODE
Use 'dead_error_condition' instead of 'dead_error_begin'
2015-09-24 09:53:38 -04:00
Peter Krempa
7acfb940f7 virsh: Fix job status indicator for 0 length block jobs
Although 0 length block jobs aren't entirely useful, the output of virsh
blockjob is empty due to the condition that suppresses the output for
migration jobs that did not start. Since the only place that actually
uses the condition that suppresses the output is in migration, let's
move the check there and thus add support for 0 of 0 equaling to 100%.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1196711
2015-09-23 15:06:56 +02:00
Jiri Denemark
035947eb87 virsh: Notify users about disconnects
After my "client rpc: Report proper error for keepalive disconnections"
patch, virsh would no long print a warning when it closes a connection
to a daemon after a keepalive timeout. Although the warning

    virsh # 2015-09-15 10:59:26.729+0000: 642080: info :
    libvirt version: 1.2.19
    2015-09-15 10:59:26.729+0000: 642080: warning :
    virKeepAliveTimerInternal:143 : No response from client
    0x7efdc0a46730 after 1 keepalive messages in 2 seconds

was pretty ugly, it was still useful. This patch brings the useful part
back while making it much nicer:

virsh # error: Disconnected from qemu:///system due to keepalive timeout

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-09-23 13:09:50 +02:00
Michal Privoznik
41d4104d3e virsh: Teach attach-interface to --print-xml
We have the same argument to many other commands that produce an
XML based on what user typed. But unfortunately attach-interface
was missing it. Maybe nobody had needed it yet. Well, I did
just now.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-16 16:10:48 +02:00
Michal Privoznik
0efe8f5065 virsh: Slightly rework cmdDomblklist
Let's move some variables from an inside loop to global function
declaration header block. It's going to be easier for next
patches. At the same time, order the cleanup calls at the
function's end so it's easier to track which variables are freed
and which not.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-07 11:01:11 +02:00
Erik Skultety
682775fbb8 vsh: Make vshInitDebug static
There's no reason why debug initialization could not be made completely
hidden, just like readline initialization is. The point of the global
initializer vshInit is to make initialization of smaller features transparent
to the user/caller.
2015-09-04 14:12:34 +02:00
Erik Skultety
a02de849a0 virsh: Do not make interactive mode default
Currently, we set interactive mode as default possibly reverting the
setting after we parse the command line arguments. There's nothing
particulary wrong with that, but a call to vshReadlineInit is performed
always in the global initializer just because the default mode is interactive.
Rather than moving vshReadlineInit call somewhere else (because another client
might want to implement interactive mode only), we could make the decision
if we're about to run in interactive mode once the command line is parsed.
2015-09-04 14:12:34 +02:00
Erik Skultety
f59d51f518 vsh: Introduce vshInitReload
Commit a0b6a36f separated vshInitDebug from the original vshInit
(before virsh got split and vshInit became virshInit - commit 834c5720)
in order to be able to debug command line parsing.
After the parsing is finished, debugging is reinitialized to work properly.
There might as well be other features that require re-initialization as
the command line could specify parameters that override our defaults which
had been set prior to calling vshArgvParse.
2015-09-04 14:12:34 +02:00
Erik Skultety
57b8a38840 vsh: adjust vshInit signature and remove redundant error label
As part of the effort to stay consistent, change the vshInit signature
from returning int to returning bool. Moreover, remove the
unnecessary error label as there is no cleanup that would make use of
it.
2015-09-04 14:12:34 +02:00
Michal Privoznik
4fdd873f1a vshInit: Don't leak @histsize_env
Caller is responsible for freeing the result of virStringJoin()
when no longer needed:

==10701== 1 bytes in 1 blocks are definitely lost in loss record 1 of 806
==10701==    at 0x4C29F80: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==10701==    by 0xAADB679: strdup (in /lib64/libc-2.20.so)
==10701==    by 0x4F18655: virStrdup (virstring.c:726)
==10701==    by 0x4F175AF: virStringJoin (virstring.c:165)
==10701==    by 0x131D4D: vshReadlineInit (vsh.c:2572)
==10701==    by 0x1322DF: vshInit (vsh.c:2736)
==10701==    by 0x1347C1: main (virsh.c:907)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-09-03 14:44:57 +02:00
Jonathan Toppins
5c668a78d8 qemu: add udp interface support
Adds a new interface type using UDP sockets, this seems only applicable
to QEMU but have edited tree-wide to support the new interface type.

The interface type required the addition of a "localaddr" (local
address), this then maps into the following xml and qemu call.

<interface type='udp'>
  <mac address='52:54:00:5c:67:56'/>
  <source address='127.0.0.1' port='11112'>
    <local address='127.0.0.1' port='22222'/>
  </source>
  <model type='virtio'/>
  <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/>
</interface>

QEMU call:
	-net socket,udp=127.0.0.1:11112,localaddr=127.0.0.1:22222

Notice the xml "local" entry becomes the "localaddr" for the qemu call.

reference:
http://lists.gnu.org/archive/html/qemu-devel/2011-11/msg00629.html

Signed-off-by: Jonathan Toppins <jtoppins@cumulusnetworks.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2015-09-02 10:17:50 +02:00
Luyao Huang
70f56dd72c virsh: Reset global error after successfull domain lookup
When looking up a domain, we try to look up by ID, UUID and NAME
consequently while not really caring which of those lookups succeeds.
The problem is that if any of them fails, we dispatch the error from the
driver and that means setting both threadlocal and global error. Let's
say the last lookup (by NAME) succeeds and resets the threadlocal error as any
other API does, however leaving the global error unchanged. If the underlying
virsh command does not succeed afterwards, our cleanup routine in
vshCommandRun ensures that no libvirt error will be forgotten and that's
exactly where this global error comes in incorrectly.

 # virsh domif-setlink 123 vnet1 up
 error: interface (target: vnet1) not found
 error: Domain not found: no domain with matching id 123

This patch also resets the global error which would otherwise cause some
minor confusion in reported error messages.

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2015-08-18 14:54:45 +02:00
Luyao Huang
b2da1d453f virsh: fix always return false in domrename
Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-08-17 12:43:17 -04:00
Moshe Levi
0181975689 Remove static keyword from vshReadline when readline does not exist
This patch removes the static keyword from the vshReadline which was
introduced in commit 834c5720e4. With
readline the vshReadline function is not static but when compiling
without readline it was defined as static which caused compilation
error.
2015-08-15 17:14:12 +02:00
Erik Skultety
834c5720e4 tools: Introduce new client generic module vsh
In order to share as much virsh' logic as possible with upcomming
virt-admin client we need to split virsh logic into virsh specific and
client generic features.

Since majority of virsh methods should be generic enough to be used by
other clients, it's much easier to rename virsh specific data to virshX
than doing this vice versa. It moved generic virsh commands (including info
and opts structures) to generic module vsh.c.

Besides renaming methods and structures, this patch also involves introduction
of a client specific control structure being referenced as private data in the
original control structure, introduction of a new global vsh Initializer,
which currently doesn't do much, but there is a potential for added
functionality in the future.
Lastly it introduced client hooks which are especially necessary during
client connecting phase.
2015-08-14 15:45:44 +02:00
Tomas Meszaros
9877d8406c Introduce new VIR_DOMAIN_EVENT_DEFINED_RENAMED event
This should be emitted whenever a domain is renamed.

Signed-off-by: Tomas Meszaros <exo@tty.sk>
2015-08-14 10:50:20 +02:00
Tomas Meszaros
ff486e0d29 virsh: Implement "domrename" command
This patch implements new virsh command, domrename.

Using domrename, it will be possible to rename domain from the virsh shell by
calling virRenameDomain API.

It takes two arguments, current domain name and new domain name.

Example:

virsh # list --all
 Id    Name                           State
 ----------------------------------------------------
  -     bar                            shut off

virsh # domrename bar foo
Domain successfully renamed

virsh # list --all
 Id    Name                           State
 ----------------------------------------------------
  -     foo                            shut off

virsh #

Signed-off-by: Tomas Meszaros <exo@tty.sk>
2015-08-14 10:50:20 +02:00
Michal Privoznik
68b2405c67 cmdAttachInterface: Fully implement @floor support
In my previous commit d7f5c88961 I tried to introduce support
for inbound.floor. But the code change was incomplete. This is
the change needed to fully enable the feature.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-08-12 10:57:36 +02:00
Peter Krempa
73ca6f98a3 virsh: Refactor parseRateStr to avoid false-positive uninitialized variable
Commit 6983d6d2 tried to improve parseRateStr but broke the build
instead for compilers that were not able to properly introspect the for
loop indexed by the enum resulting into the following error:

virsh-domain.c: In function 'parseRateStr':
virsh-domain.c:916:13: error: 'field_name' may be used uninitialized in this function [-Werror=maybe-uninitialized]
             vshError(ctl, _("malformed %s field"), field_name);
             ^
virsh-domain.c:915:13: error: 'tmp' may be used uninitialized in this function [-Werror=maybe-uninitialized]
         if (virStrToLong_ullp(token, NULL, 10, tmp) < 0) {
             ^
Rather than trying to fix the code, refactor the function again by
reusing virStringSplit.
2015-08-12 07:33:06 +02:00
Michal Privoznik
d7f5c88961 virsh: Implement VIR_DOMAIN_BANDWIDTH_IN_FLOOR
We have a function parseRateStr() that parses --inbound and
--outbound arguments to both attach-interface and domiftune.
Now that we have all virTypedParams macros needed for QoS,
lets parse even floor attribute. The extended format for the
arguments looks like this then:

  --inbound average[,peak[,burst[,floor]]]

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-08-11 16:10:32 +02:00
Michal Privoznik
6983d6d2c3 virsh: Rework parseRateStr
The function is used to parse a tuple delimited by commas into
virNetDevBandwidth structure. So far only three out of fore
fields are supported: average, peak and burst. The single missing
field is floor. Well, the parsing works, but I think we can do
better. Especially when we will need to parse floor too in very
close future.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-08-11 16:10:32 +02:00
Luyao Huang
ee6160b549 virsh: fix domfsinfo output in quiet mode
https://bugzilla.redhat.com/show_bug.cgi?id=1250287

When run domfsinfo in quiet mode, we cannot get any
useful information (just get \n), this is because
we didn't use vshPrint to print useful information.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-08-05 09:58:32 +02:00
Peter Krempa
faa1439123 virsh: Refactor block job waiting in cmdBlockCopy
Similarly to the refactor of cmdBlockCommit in a previous commit this
does the same change for cmdBlockCopy.
2015-07-21 15:32:59 +02:00