Commit Graph

106 Commits

Author SHA1 Message Date
Tomáš Golembiovský
aee0465508 qemu: Add entry for balloon stat stat-disk-caches
QEMU commit bf1e7140e adds reporting of new balloon statistic to QEMU
2.12. Value represents the amount of memory that can be quickly
reclaimed without additional I/O. Let's add that too.

Signed-off-by: Tomáš Golembiovský <tgolembi@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-07-16 17:42:23 -04:00
Chen Hanxiao
62c3919328 cmdDomblkinfo: add --all to show all block devices info
This patch introduces --all to show all block devices info
of guests like:

virsh # domblkinfo w08 --all
Target     Capacity        Allocation      Physical
---------------------------------------------------
hda        42949672960     9878110208      9878110208
vda        10737418240     10736439296     10737418240

Target     Capacity        Allocation      Physical
---------------------------------------------------
hda        40.000 GiB      9.200 GiB       9.200 GiB
vda        10.000 GiB      9.999 GiB       10.000 GiB

For inactive domains using networked storage, a "-" will
be printed instead of the value since it's not possible
to determine the value without the storage connection.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-06-21 17:39:22 -04:00
Chen Hanxiao
4afcaa8843 cmdDomblkinfo: introduce helper cmdDomblkinfoPrint
Introduce helper cmdDomblkinfoPrint for printing.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-06-21 17:39:19 -04:00
Michal Privoznik
9486ed9071 virsh: Introduce --nowait to domstats
This new switch can be used to set
VIR_CONNECT_GET_ALL_DOMAINS_STATS_NOWAIT flag for stats
fetching API.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2018-06-19 07:08:13 +02:00
ramyelkest
2b6667abbf all: Replace virGetLastError with virGetLastErrorCode where we can
Replace instances where we previously called virGetLastError just to
either get the code or to check if an error exists with
virGetLastErrorCode to avoid a validity pre-check.

Signed-off-by: Ramy Elkest <ramyelkest@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2018-06-05 18:44:05 +02:00
Lin Ma
27e97d5c17 virsh: Add target name completion for block device options
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-05-17 17:06:11 +02:00
Lin Ma
919bb45b56 virsh: Apply macro for current VSH_OT_ARGV "domain" options
Signed-off-by: Lin Ma <lma@suse.com>
2018-05-10 10:01:15 +02:00
Lin Ma
8379895227 virsh: Move the definition of macro VIRSH_COMMON_OPT_DOMAIN_FULL to virsh.h
centralize the definition of macro VIRSH_COMMON_OPT_DOMAIN_FULL to virsh.h
to avoid unnecessary duplicated definition

Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-05-10 07:51:37 +02:00
Chen Hanxiao
c595fc788e virsh: add missing help info of --source to domifaddr
commit b4b5c82ce forgot to add this.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-03-29 13:29:49 -04:00
Chen Hanxiao
b4b5c82ce8 virsh: add --source arp to domifaddr
We can use:
  domifaddr f26-cloud --source arp
to get the address.

Acked-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2018-03-15 11:22:42 +01:00
Michal Privoznik
7e7db4bfe0 virsh: Introduce virshDomainInterfaceCompleter
For given domain fetch list of defined interfaces. This can be
used for commands like domif-getlink and others. If available,
the interface name is returned (e.g. "vnet0", usually available
only for running domains), if not the MAC address is returned.
Moreover, the detach-interface command requires only MAC address
and therefore we have new flag that forces the completer to
return just the MAC address.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-11 18:53:04 +01:00
Michal Privoznik
ec3403be7e virsh: Introduce virshDomainNameCompleter
Now that we have everything prepared let the fun begin. This
completer is very simple and returns domain names. Moreover,
depending on the command it can return just a subset of domains
(e.g. only running/paused/transient/.. ones).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2018-01-11 18:53:04 +01:00
ZhiPeng Lu
5a8f5a997f virsh: domifstat: enhance the command's help output
According to the man page <interface-device> can be specified either by
name or MAC address, adjust the command's help accordingly.

Signed-off-by:ZhiPeng Lu <lu.zhipeng@zte.com.cn>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
Signed-off-by: Erik Skultety <eskultet@redhat.com>
2017-11-22 13:06:56 +01:00
Michal Privoznik
27b67eba22 virsh: Define multi line macros properly
In some cases there's dangling backward slash at the end of multi
line macros. While technically the code works, it will stop if
some empty lines are removed.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2017-11-04 08:38:08 +01:00
Andrea Bolognani
3e7db8d3e8 Remove backslash alignment attempts
Right-aligning backslashes when defining macros or using complex
commands in Makefiles looks cute, but as soon as any changes is
required to the code you end up with either distractingly broken
alignment or unnecessarily big diffs where most of the changes
are just pushing all backslashes a few characters to one side.

Generated using

  $ git grep -El '[[:blank:]][[:blank:]]\\$' | \
    grep -E '*\.([chx]|am|mk)$$' | \
    while read f; do \
      sed -Ei 's/[[:blank:]]*[[:blank:]]\\$/ \\/g' "$f"; \
    done

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
2017-11-03 13:24:12 +01:00
Chen Hanxiao
b3aaff56db virsh: domifaddr: clarify description of --full option
Option --full will always display the name and MAC address of the
the interface. Both virsh help and virsh man page didn't mention that.

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2017-10-18 09:51:32 -04:00
Michal Privoznik
7a995c6b78 virsh: Deal with multiple matching devices in domif-getlink
The command tries to match interface in domain definition by MAC
address or interface name. However, since it's possible to
configure two interfaces with the same MAC address, it may
happen that the XPath returns two or more nodes. We should check
for that.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: John Ferlan <jferlan@redhat.com>
2017-10-13 13:47:17 -07:00
Julio Faracco
4b9af8625a virsh-domain-monitor: add human readable output for 'domblkinfo'.
https://bugzilla.redhat.com/show_bug.cgi?id=1330940

The virsh command 'domblkinfo' returns the capacity, allocation and phisycal
size of the devices attached in a domain. Usually, this sizes are very big
and hard to understand and calculate. This commits introduce a human readable
support to check the size of each field easilly.

For example, the command before:

virsh # domblkinfo my_domain hda
Capacity:       21474836480
Allocation:     14875545600
Physical:       21474836480

and after this patch:

virsh # domblkinfo my_domain hda --human
Capacity:       20.000G
Allocation:     13.900G
Physical:       20.000G

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2017-05-02 09:36:31 +02:00
Peter Krempa
6bd2889014 virsh-domain-monitor: Use the virsh wrappers for getting XML to simplify code
Reuse virshDomainGetXML and virshDomainGetXMLFromDom.
2017-04-12 14:14:17 +02:00
Peter Krempa
3a344d55d9 virsh-util: Add wrapper for virDomainFree
virDomainFree has it's quirks (does not like NULL pointers, resets
libvirt errors). Replace it by a virsh helper which will allow us to
centrally fix issues with it.

The syntax-check rule will prohibit new uses of virDomainFree.
2017-04-12 14:08:37 +02:00
Peter Krempa
aff5aab751 virsh-util: Move domain lookup helpers into virsh-util
Move virshLookupDomainBy, virshCommandOptDomainBy and
virshCommandOptDomainBy to the helper file. Additionally turn the
virshCommandOptDomainBy macro into a function.
2017-04-12 13:23:10 +02:00
Peter Krempa
e8a61ae4bd virsh: Add new file for utility functions and move a few
Don't accumulate helpers in virsh.c
2017-04-12 13:23:10 +02:00
Nitesh Konkar
78d2bb7486 Don't print extra newline in virsh domstats output
Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
2017-03-06 11:40:21 -05:00
Derbyshev Dmitry
200a40f94e qemu: expand domain memory statistics with 'last-update' timestamp
QEMU reports timestamp along with other memory statistics, but this information is not saved into domain statistics.
It could be useful to determine if the data reported is fresh or not.
Balloon statistics are not reported in hrf, so no modifications are made in qemu_monitor_text.c.

Signed-off-by: Derbyshev Dmitry <dderbyshev@virtuozzo.com>
2016-07-26 17:30:01 +02:00
Derbyshev Dmitry
65bf044686 qemu: expand domain memory statistics with 'usable'
'memtotal' in virtio drivers and qemu corresponds to 'available' in libvirt.
Because of that, 'stat-available-memory' is renamed into 'usable'.
Balloon statistics are not reported in hrf, so no modifications are made in qemu_monitor_text.c.

Signed-off-by: Derbyshev Dmitry <dderbyshev@virtuozzo.com>
2016-07-26 17:30:01 +02:00
Chen Hanxiao
8f5becf3a3 virsh: allow both --uuid and --name at same time
#virsh list --uuid --name
49c765a0-25e7-40d0-964f-dac99724b32c   c7
918f1dd6-b19f-412b-ba17-d113bad89af8   f23

Signed-off-by: Chen Hanxiao <chenhanxiao@gmail.com>
2016-07-11 14:00:51 +02:00
Qiaowei Ren
7d3b10a9fb virsh: extend domstats command
This patch extend domstats command to match extended
virDomainListGetStats API in previous patch.

Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
Message-id: 1459171833-26416-9-git-send-email-qiaowei.ren@intel.com
2016-03-29 13:13:05 +01:00
Jiri Denemark
5a9cbc6265 Add event and state details for post-copy
VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY and VIR_DOMAIN_PAUSED_POSTCOPY are
used on the source host once migration enters post-copy mode (which
means the domain gets paused on the source. After the destination host
takes over the execution of the domain, its virtual CPUs are resumed and
the domain enters VIR_DOMAIN_RUNNING_POSTCOPY state and
VIR_DOMAIN_EVENT_RESUMED_POSTCOPY event is emitted.

In case migration fails during post-copy mode and none of the hosts have
complete state of the domain, both domains will remain paused with
VIR_DOMAIN_PAUSED_POSTCOPY_FAILED reason and an upper layer may decide
what to do.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Michal Privoznik
3bd2ee5d55 virsh: Don't fetch status for all domains in cmdList
We are getting the list of domains and after that we iterate over
the list and try to get status for each domain hoping it will
skip over domains that disappeared meanwhile. However, this
solution to race is bogus - domain may disappear right after we
have checked its state and before we exec another API over it
(e.g. virDomainHasManagedSaveImage()). Also, when printing just
names or uuids (list --name / --uuid) we issue APIs to obtain the
values, however these require no RPC call as all requested info
is in virDomain object that client already has.
Therefore move the status obtaining only to the place that really
needs it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-21 08:13:34 +01:00
John Ferlan
5b42dbed98 virsh: Create macro for common "current" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which for many options in virsh-domain.c
is simply "affect current domain". So, create a second macro within that
file in order to define the more common use as a revector to the
common macro with the common _helpstr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
John Ferlan
8e4108f039 virsh: Create macro for common "live" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which for many options in virsh-domain.c
is simply "affect running domain". So, create a second macro within that
file in order to define the more common use as a revector to the
common macro with the common _helpstr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
John Ferlan
0dbac60b9e virsh: Create macro for common "config" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which for many options in virsh-domain.c
is simply "affect next boot". So, create a second macro within that
file in order to define the more common use as a revector to the
common macro with the common _helpstr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
John Ferlan
b6fb1e245c virsh: Create macro for common "domain" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which will be used to pass the translatable
helpstr since not all domain options can take the same string.

The majority of the options take 'N_("domain name, id or uuid")', so
create a separate macro with a _FULL suffix while those that do not
take the same string will use the VIRSH_COMMON_OPT_DOMAIN macro.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05: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
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
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
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
Andrea Bolognani
815dc963ee virsh: Move error messages inside vshCommandOpt*() functions 2015-06-02 09:20:31 -04:00
Andrea Bolognani
be6ff4da95 virsh: Pass vshControl to all vshCommandOpt*() calls
This will allow us to use vshError() to report errors from inside
vshCommandOpt*(), instead of replicating the same logic and error
messages all over the place.

We also have more context inside the vshCommandOpt*() functions,
for example the actual value used on the command line, which means
we can produce more detailed error messages.

vshCommandOptBool() is the exception here, because it's explicitly
designed not to report any error.
2015-06-02 09:20:31 -04:00
Andrea Bolognani
2f4a45a25e virsh: Fix dommemstat --period option type.
The option didn't have VSH_OT_INT type even thought it's expected
to be numeric, as shown by the fact that vshCommandOptInt() is later
used to retrieve its value.
2015-05-18 10:50:06 +02:00
Andrea Bolognani
449316701b virsh: Improve error message on integer value parsing failure.
Replace more than 30 ad-hoc error messages with a single, generic one
that contains the name of the option being processed and some hints
to help the user understand what could have gone wrong.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1207043
2015-05-18 10:50:06 +02:00
Peter Krempa
a5e89ae16e util: Make the virDomainListFree helper more universal
Extend it to a universal helper used for clearing lists of any objects.
Note that the argument type is specifically void * to allow implicit
typecasting.

Additionally add a helper that works on non-NULL terminated arrays once
we know the length.
2015-05-11 08:28:53 +02:00
Luyao Huang
156fde0b1a virsh: Fix domifaddr output in quiet mode
In virsh we have two printing functions: vshPrint() which prints a
string onto stdout and vshPrintExtra() which does not print anything
if virsh is run in quiet mode. Usually, the former is used to print
actual results, while the latter to print strings like table headers
and other formatting stuff. However, in cmdDomIfAddr we have
mistakenly used vshPrintExtra even for actual data. After this patch,
the output should look like the following:

  # virsh -q domifaddr test3 --source agent
  lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
  -          -                    ipv6         ::1/128
  ens8       52:54:00:1a:cb:3f    ipv6         fe80::5054:ff:fe1a:cb3f/64
  virbr0     52:54:00:db:51:e7    ipv4         192.168.122.1/24
  virbr0-nic 52:54:00:db:51:e7    N/A          N/A

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-04-03 12:23:03 +02:00
Eric Blake
75d56f51f7 build: avoid variable named 'interface', for mingw
Commit 2f36e6944 (re-)introduced a use of an identifier 'interface',
which causes this build failure on mingw:

../../tools/virsh-domain-monitor.c: In function 'cmdDomIfAddr':
../../tools/virsh-domain-monitor.c:2233:17: error: expected identifier or '(' before 'struct'
     const char *interface = NULL;
                      ^

See also commit 6512c8b.  Sadly, I'm not quite sure how to write a
syntax check that can poison the use of this identifier.

* tools/virsh-domain-monitor.c (cmdDomIfAddr): Use ifacestr instead.

Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-28 14:12:55 -06:00
Jiri Denemark
18441ab914 Use PAUSED state for domains that are starting up
When libvirt is starting a domain, it reports the state as SHUTOFF until
it's RUNNING. This is not ideal because domain startup may take a long
time (usually because of some configuration issues, firewalls blocking
access to network disks, etc.) and domain lists provided by libvirt look
awkward. One can see weird shutoff domains with IDs in a list of active
domains or even shutoff transient domains. In any case, it looks more
like a bug in libvirt than a normal state a domain goes through.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-03-18 10:08:22 +01:00
Michal Privoznik
0aff8fa829 cmdDomIfAddr: Free @ip_addr_str
The variable holds formatted suffix to each line printed out
(address type, address and prefix). However, the variable is
never freed. At the same time, honour fact, that data held in
the variable is not constant.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-18 09:13:53 +01:00
Michal Privoznik
50780207ef virsh: Adapt to new HW address scenario
Make sure we don't print (null) (which in fact is printf()'s
cleverness anyway, not ours). If no HW address is present, print
"N/A" string just like we do for other fields.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-03-18 09:12:52 +01:00
Nehal J Wani
2f36e6944e domifaddr: Add virsh support
tools/virsh-domain-monitor.c
   * Introduce new command : domifaddr
     Usage: domifaddr <domain> [interface] [--full] [--source lease|agent]

     Example outputs:
     virsh # domifaddr f20
     Name       MAC address          Protocol     Address
     -------------------------------------------------------------------------------
     lo         00:00:00:00:00:00    ipv4         127.0.0.1/8
     -          -                    ipv6         ::1/128
     vnet0      52:54:00:2e:45:ce    ipv4         10.1.33.188/24
     -          -                    ipv6         2001:db8:0:f101::2/64
     -          -                    ipv6         fe80::5054:ff:fe2e:45ce/64
     vnet1      52:54:00:b1:70:19    ipv4         192.168.105.201/16
     -          -                    ipv4         192.168.201.195/16
     -          -                    ipv6         fe80::5054:ff:feb1:7019/64
     vnet2      52:54:00:36:2a:e5    N/A          N/A
     vnet3      52:54:00:20:70:3d    ipv4         192.168.105.240/16
     -          -                    ipv6         fe80::5054:ff:fe20:703d/64

     virsh # domifaddr f20 eth1 --source lease
     Name       MAC address          Protocol     Address
     -------------------------------------------------------------------------------
     vnet1      52:54:00:b1:70:19    ipv4         192.168.105.201/16
     -          -                    ipv4         192.168.201.195/16
     -          -                    ipv6         fe80::5054:ff:feb1:7019/64

     virsh # domifaddr f20 eth0 --source agent --full
     Name       MAC address          Protocol     Address
     -------------------------------------------------------------------------------
     eth0       52:54:00:2e:45:ce    ipv4         10.1.33.188/24
     eth0       52:54:00:2e:45:ce    ipv6         2001:db8:0:f101::2/64
     eth0       52:54:00:2e:45:ce    ipv6         fe80::5054:ff:fe2e:45ce/64

tools/virsh.pod
   * Document new command

Signed-off-by: Nehal J Wani <nehaljw.kkd1@gmail.com>
2015-03-17 15:15:39 +00:00
Erik Skultety
d9c7f014ee virsh: tweak domif-getlink link state reporting message
According to docs, we only support 2 link states for an interface
up/down, 'up' being the default state if link state is unspecified in
domain's XML, so the message when no link state is provided should be
changed a little.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1141119
2015-03-04 14:47:50 +01:00