Commit Graph

798 Commits

Author SHA1 Message Date
Pino Toscano
b620bdee14 virsh: respect -q/--quiet more
Turn various vshPrint() informative messages into vshPrintExtra(), so
they are not printed when requesting the quiet mode; neither XML/info
outputs nor the results of commands are affected.
Also change the expected outputs of the virsh-undefine test, since virsh
is invoked in quiet mode there.

Some informative messages might still be converted (and thus silenced
when in quiet mode), but this is an improvements nonetheless.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1358179
2016-08-24 17:43:29 +02:00
Peter Krempa
8dbc95cbd1 virsh: qemu-monitor-command: Don't print extra newline with --pretty
The prettified JSON string already contains a newline so don't print
another one. This allows to pipe the json output (in conjunction with
the --quiet option) to files without having to truncate them afterwards.
2016-08-02 16:21:53 +02:00
Peter Krempa
8941c800ec virsh: qemu-monitor-command: Simplify control flow
Construct the query string by using virBufferTrim rather than having to
remember to add a space and simplify cleanup path.
2016-08-02 13:59:27 +02:00
Peter Krempa
36428fa80b virsh: qemu-monitor-command: Use macro for exclusive options 2016-08-02 13:55:47 +02:00
Jiri Denemark
d85c3a5451 Report auto convergence throttle rate in migration stats
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Jiri Denemark
f6e12b4029 Add auto convergence migration parameters
They can be used to tune auto-convergence algorithm (which is enabled
with VIR_MIGRATE_AUTO_CONVERGE).

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-22 15:54:21 +02:00
Peter Krempa
69e0cd3397 virsh: Add command 'guestvcpus' implementing virDomain(GS)etGuestVcpus
Add a straightforward implementation for using the new APIs.
2016-06-22 09:26:08 +02:00
Jiri Denemark
c61360e15b virsh migrate: Fix positional parameters
Thanks to our smart option parser which automatically assigns positional
parameters the following (previously working) command fails:

    virsh migrate test qemu+ssh://1.2.3.4/system tcp://1.2.3.4/
    error: invalid argument: Unsupported compression method
    'tcp://1.2.3.4/'

We need to make sure new options are added at the end of the list rather
than where they logically belong.

Reported by Brian Rak.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-06-21 10:11:03 +02:00
Ján Tomko
ff52e9d43a Remove separator argument from virBitmapParse
Most the callers pass 0 in one form or another, including
vircapstest which used VIR_ARCH_NONE.
2016-06-20 12:09:52 +02:00
Daniel P. Berrange
291e1a470c virsh: make lxc-enter-namespace also join the cgroups
Extend the lxc-enter-namespace command so that it joins the
containers' cgroups before starting new namespaces. This
ensures that the commands run have the normal resource
limits applied

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2016-06-10 11:03:01 +01:00
Pavel Hrdina
b1f6792cb6 virsh-domain: fix memory leak in cmdDomDisplay
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-09 09:14:32 +02:00
Pavel Hrdina
4ddde38e2d virsh: domdisplay: if listen is 0.0.0.0 or [::] print address from URI
Currently if a guest has listen address 0.0.0.0 or [::] and you run
"virsh domdisplay $domain" you always get "spice://localhost:$port".

We want to print better address if someone is connected from a different
computer using "virsh -c qemu+ssh://some.host/system".  This patch fixes the
behavior of virsh to print in this case "spice://some.host:$port".

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2016-06-08 13:54:25 +02:00
Nishith Shah
161713436e virsh: blkdeviotune: accept human readable values for bytes
https://bugzilla.redhat.com/show_bug.cgi?id=885380

Use vshCommandOptScaledInt instead of vshCommandOptULongLong so that
values with suffixes can be passed when bytes are being passed along.
Values for the iops parameters still need to be given in the absolute
form as they are not bytes but numbers.

Signed-off-by: Nishith Shah <nishithshah.2211@gmail.com>
2016-05-09 07:48:08 +02:00
Nitesh Konkar
aaf3ebf760 virsh: Pass the correct live/config xml to virshDomainDetachInterface.
cmdDetachInterface function checks for live config
flags and then passes the live/config domain xml
to virshDomainDetachInterface accordingly.

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
2016-05-04 11:33:22 -04:00
Nitesh Konkar
6289cebf40 virsh: Introduce virshDomainDetachInterface function
virshDomainDetachInterface handles virsh interface
detach from the specified live/config domain xml.

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
2016-05-04 11:30:46 -04:00
Yuri Chornoivan
50fc4b4bdd Fix minor typos in messages
Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
2016-04-30 15:37:31 +02:00
Peter Krempa
b4bc800cfc virsh: perf: Remove unnecessary 'error' label
The only place that uses it doesn't warrant a separate label.
2016-04-21 09:57:02 +02:00
Peter Krempa
f4f916a9e3 virsh: perf: Don't leak domain
After failing to parse the perf event list, the code would return
failure without freeing the previously acquired object. Rearrange the
code to avoid the problem.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1329046
2016-04-21 09:57:02 +02:00
Nitesh Konkar
0ed35e0939 Return error when --start <number> in cpu-stats is invalid.
Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
2016-04-15 15:20:11 +02:00
ShaoHe Feng
0d81f2318b virsh: add compression options for migration
Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-04-14 14:57:42 +02:00
Peter Krempa
5be120710e Add VIR_DOMAIN_EVENT_ID_DEVICE_REMOVAL_FAILED event
Since we didn't opt to use one single event for device lifecycle for a
VM we are missing one last event if the device removal failed. This
event will be emitted once we asked to eject the device but for some
reason it is not possible.
2016-04-13 13:26:29 +02:00
Nitesh Konkar
d9a0a885e2 Pass the correct cpu count when calling virDomainGetCPUStats.
When using the --start option, the show_count should not be set to
max_id as the --start <cpu> means we dont need those many initial cpu
stats. Hence, show_count should be adjusted accordingly.

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

Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2016-04-01 11:36:04 +02:00
Michal Privoznik
ed504ba392 virDomain{Get,Set}PerfEvents: support --config --live --current
Now that we have @flags we can support changing perf events just
in active or inactive configuration regardless of the other.
Previously, calling virDomainSetPerfEvents set events in both
active and inactive configuration at once. Even though we allow
users to set perf events that are to be enabled once domain is
started up. The virDomainGetPerfEvents API was flawed too. It
returned just runtime info.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-31 10:42:46 +02:00
Michal Privoznik
30cd5983b7 virsh: Make perf accept event list separated by commas
Everywhere else we use a comma separated list. There's no good
reason to make 'perf' command an exception. Currently, it accepts
string list separated by '|'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-31 10:22:14 +02:00
Michal Privoznik
ee34745f6a virsh: Prefer VIRSH_COMMON_OPT_DOMAIN_FULL over full enumeration
We have a macro that does exactly what is done via full
enumeration.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-31 07:24:36 +02:00
Michal Privoznik
3b6c818532 virDomain{Get,Set}PerfEvents: Add @flags argument
I've noticed that these APIs are missing @flags argument. Even
though we don't have a use for them, it's our policy that every
new API must have @flags.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-03-31 07:24:36 +02:00
Peter Krempa
d40d18fb8f virsh: blockpull: Support --bytes and scaled integers
Use vshBlockJobOptionBandwidth to parse the bandwidth value which will
allow users to specify bandwidth in bytes or as a scaled integer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
2016-03-29 15:59:19 +02:00
Peter Krempa
453a6d8092 virsh: blockcopy: Support --bytes and scaled integers
Use vshBlockJobOptionBandwidth to parse the bandwidth value which will
allow users to specify bandwidth in bytes or as a scaled integer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
2016-03-29 15:58:41 +02:00
Peter Krempa
e557bd28a2 virsh: blockcommit: Support --bytes and scaled integers
Use vshBlockJobOptionBandwidth to parse the bandwidth value which will
allow users to specify bandwidth in bytes or as a scaled integer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
2016-03-29 15:55:28 +02:00
Peter Krempa
e54b5484c9 virsh: blockjob: Support --bytes and scaled integers as bandwidth
Use vshBlockJobOptionBandwidth to parse the bandwidth value which will
allow users to specify bandwidth in bytes or as a scaled integer.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1288000
2016-03-29 15:52:10 +02:00
Qiaowei Ren
608e9e8802 virsh: implement new command to support perf
This patch add new perf command to enable/disable perf event
for a guest domain.

Signed-off-by: Qiaowei Ren <qiaowei.ren@intel.com>
Message-id: 1459171833-26416-8-git-send-email-qiaowei.ren@intel.com
2016-03-29 13:13:05 +01:00
Cristian Klein
4cdc4a76d3 virsh: Add --postcopy-after-precopy option to migrate
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Jiri Denemark
257060349e virsh: Configurable migrate --timeout action
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +01:00
Cristian Klein
179d97283f virsh: Add support for post-copy migration
Signed-off-by: Cristian Klein <cristiklein@gmail.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-21 15:15:46 +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
Nikolay Shirokovskiy
f486cb5ea0 migration: add target peer disks port
Some hypervisors (namely qemu) can have a separate connecton for
non-shared disks migration of active domains. Currently we have
no means to control the port of such a connection. At the same
time we have options to control port of memory migration traffic
(thru migration uri) as well as interfaces that target server
is bound to for incoming migration (thru VIR_MIGRATE_PARAM_LISTEN_ADDRESS).
Let's add the option for setting disks port too.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com>
2016-03-17 16:20:15 +01:00
Dmitry Andreev
8047d45704 Introduce new VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT sub-event
VIR_DOMAIN_EVENT_DEFINED_FROM_SNAPSHOT event should be emitted
when domain configuration was changed on revert to snapshot.
2016-03-15 14:57:26 -04:00
Peter Krempa
e7e6980dd8 virsh: vcpupin: Ask for pinning info for all vCPUs
The API docs state that the API queries pinning info for all vCPUs and
thus we should allocate the bitmap even for the inactive ones.

The API will currently return bitmap only for the active vCPUs but that
will change in the future.
2016-03-09 10:09:16 +01:00
Jiri Denemark
f289300181 Introduce job completed event
The VIR_DOMAIN_EVENT_ID_JOB_COMPLETED event will be triggered once a job
(such as migration) finishes and it will contain statistics for the job
as one would get by calling virDomainGetJobStats. Thanks to this event
it is now possible to get statistics of a completed migration of a
transient domain on the source host.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-03-08 16:26:00 +01:00
Nitesh Konkar
2652757070 virsh: reject migration with both --live and --offline
Signed-off-by: Nitesh Konkar <nitkon12@linux.vnet.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2016-02-26 12:45:20 +01:00
Michal Privoznik
4a3ae388ba cmdSaveImageEdit: Prefer VSH_EXCLUSIVE_OPTIONS over by hand check
Since we have the macro there's no need for us to unwind it by
hand and check for mutually exclusive flags ourselves.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-02-22 16:56:07 +01:00
Peter Krempa
773f3bd3cc virsh: cpupin: Extract getter code into a separate function 2016-02-19 15:24:54 +01:00
Peter Krempa
a7bc9841a4 virsh: cmdVcpuPin: Simplify handling of API flags
Rather than setting flags to -1 if none were specified, move the logic
to use the old API to the place where we need to decide. It simplifies
the logic a bit.
2016-02-19 15:13:21 +01:00
Peter Krempa
3ad5186ed3 virsh: Remove <backingStore> when changing cdrom media source
Since the code is changing the source image path by modifying the
existing XML snippet the <backingStore> stays in place.

As <backingStore> is relevant to the <source> part of the image, the
update of that part makes the element invalid.

CD/floppy images usually don't have a backing chain and the element is
currently ignored though but it might start being used in the future so
let's start behaving correctly.

Drop the <backingStore> subtree once we want to update the XML.

Before this patch, you'd get:
$ virsh change-media --eject --print-xml 10 hdc
<disk type="file" device="cdrom">
      <driver name="qemu" type="qcow2"/>

      <backingStore type="file" index="1">
        <format type="qcow2"/>
        <source file="/var/lib/libvirt/images/vm.1436949097"/>
        <backingStore/>
      </backingStore>
      <target dev="hdc" bus="ide"/>
      ...
    </disk>

After:

 $ virsh change-media --eject --print-xml 10 hdc
<disk type="file" device="cdrom">
      <driver name="qemu" type="qcow2"/>

      <target dev="hdc" bus="ide"/>
      ...
    </disk>
2016-02-18 09:50:45 +01:00
Peter Krempa
27fa42b24c vsh: Replace vshPrint macro with function
The macro would eat the first parameter. In some cases the format string
for vshPrint was eaten. In other cases the calls referenced variables
which did not exist in the given context. Avoid errors by doing compile
time checking.
2016-02-15 13:31:12 +01:00
Michael Chapman
86c4df83b9 virsh: improve waiting for block job readiness
After a block job hits 100%, we only need to apply a timeout waiting for
a block job event if exactly one of the BLOCK_JOB or BLOCK_JOB_2
callbacks were able to be registered.

If neither callback could be registered, there's clearly no need for a
timeout.

If both callbacks were registered, then we're guaranteed to eventually
get one of the events. The path being used by virsh must be exactly the
source path or target device in the domain's disk definition, and these
are the respective strings sent back in these two events.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2016-02-01 18:04:48 +01:00
Michael Chapman
8fa216bbb4 virsh: ensure SIGINT action is reset on all errors
If virTimeMillisNow() fails, the SIGINT action must be reset back to
its previous state.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2016-02-01 18:04:48 +01:00
Michael Chapman
15dee2ef24 virsh: be consistent with style of loop exit
When waiting for a block job, the various statuses (COMPLETED, READY,
CANCELED, etc.) should all be treated consistently by having the loop be
exited with "break". Use "goto cleanup" for the error cases only, when
no block job status is available.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2016-02-01 18:04:48 +01:00
Michael Chapman
704dfd6b0f virsh: avoid unnecessary progress updates
There is no need to call virshPrintJobProgress() unless the block job's
cur or end cursors have changed since the last iteration.

Signed-off-by: Michael Chapman <mike@very.puzzling.org>
2016-02-01 18:04:48 +01:00
Luyao Huang
985f01a65f virsh: fix cpu-stats command output format issue
After commit 57177f1, the cpu-stats command format change to:

CPU0:
    cpu_time         14401.507878990 seconds
    vcpu_time    14378732785511

vcpu_time is not user friendly. After this patch, it will
change back:
CPU0:
    cpu_time         14401.507878990 seconds
    vcpu_time        14378.732785511 seconds

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2016-01-26 09:23:49 +01:00
Peter Krempa
a2e80549a2 virsh: cpu-stats: Remove unneeded flags
virDomainGetCPUStats doesn't support flags so there's no need to carry
the 'flags' variable around. Additionally since the API is poorly
designed I doubt that it will be extended.
2016-01-25 17:45:09 +01:00
Peter Krempa
57177f1abd virsh: cpu-stats: Extract common printing code into a function
Simplify the code by extracting a common code path.
2016-01-25 17:45:09 +01:00
Michal Privoznik
9cbd1ecc3e virsh: Correctly detect inserted media in change-media command
https://bugzilla.redhat.com/show_bug.cgi?id=1250331

It all works like this. The change-media command dumps domain
XML, finds the corresponding cdrom device we want to change media
in and returns it in the xmlNodePtr form. This way we don't have
to bother with keeping all the subelements or attributes that we
don't care about in the XML that is fed back to libvirt for the
update API.

Now, the problem is we try to be clever here and detect if disk
already has a source (indicated by <source/> subelement).
However, bare fact that the element is there does not mean disk
has source. Make our clever check better.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2016-01-25 15:57:23 +01:00
Jiri Denemark
0b50f4a025 Introduce migration iteration event
The VIR_DOMAIN_EVENT_ID_MIGRATION_ITERATION event will be triggered
whenever VIR_DOMAIN_JOB_MEMORY_ITERATION changes its value, i.e.,
whenever a new iteration over guest memory pages is started during
migration.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-21 16:36:08 +01:00
Guido Günther
e8f771176e virsh: Update description of lxc-enter-namespace
Mention that we run a command in that namespace
2016-01-13 17:45:36 +01:00
John Ferlan
febf69b5e9 virsh: Create macro for common "file" 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 for the less common help string for each
command option.  Note that only file options using "OT_DATA" and
"OFLAG_REQ" will be replace - others are left as is.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05: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
c7ccd8b2e6 virsh: Create macro for common "persistent" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically.  Note that not all
'{.name = "persistent",' entries are replaced, just those that have the
common .help string of "make live change persistent".

Non replaced instances are unique to the command.

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
Andrea Bolognani
75a96e0cc4 virsh: Add timestamps to QEMU monitor events
Implement a --timestamp option for 'virsh qemu-monitor-event', similar
to the one for 'virsh event'.

When the option is used, the human-readable timestamp will be printed
before the message, and the timing information provided by QEMU will
not be displayed.
2016-01-11 12:45:21 +01:00
Jiri Denemark
eb084a733b qemu: Report more migration statistics
memory_dirty_rate corresponds to dirty-pages-rate in QEMU and
memory_iteration is what QEMU reports in dirty-sync-count.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 18:18:58 +01:00
Jiri Denemark
aa7735e9d1 virsh: Add timestamps to events
A new --timestamp option for event virsh command can be used to print
timestamp of each event.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 10:39:20 +01:00
Jiri Denemark
7cbb7f059a virsh: Refactor event printing
To reduce code duplication.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2016-01-08 10:39:20 +01:00
John Ferlan
2eba5c5635 virsh: Add --delete-snapshots flag for undefine and vol-delete
https://bugzilla.redhat.com/show_bug.cgi?id=1281710

Commit id '3c7590e0a' added the flag to the rbd backend, but provided
no means via virsh to use the flag.  This patch adds a '--delete-snapshots'
option to both the "undefine" and "vol-delete" commands.

For "undefine", the flag is combined with the "--remove-all-storage" flag
in order to add the appropriate flag for the virStorageVolDelete call;
whereas, for the "vol-delete" command, just the flag is sufficient since
it's only operating on one volume.

Currently only supported for rbd backends.
2015-12-18 10:51:08 -05:00
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
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
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
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
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
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
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
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
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
Peter Krempa
7408403560 virsh: Refactor block job waiting in cmdBlockCommit
Reuse the vshBlockJobWait infrastructure to refactor cmdBlockCommit to
use the common code. This additionally fixes a bug when working with
new qemus, where when doing an active commit with --pivot the pivoting
would fail, since qemu reaches 100% completion but the job doesn't
switch to synchronized phase right away.
2015-07-21 15:32:59 +02:00
Peter Krempa
2e78276364 virsh: Refactor block job waiting in cmdBlockPull
Introduce helper function that will provide logic for waiting for block
job completion so the 3 open coded places can be unified and improved.

This patch introduces the whole logic and uses it to fix
cmdBlockJobPull. The vshBlockJobWait function provides common logic for
block job waiting that should be robust enough to work across all
previous versions of libvirt. Since virsh allows passing user-provided
strings as paths of block devices we can't reliably use block job events
for detection of block job states so the function contains a great deal
of fallback logic.
2015-07-21 15:32:59 +02:00
Peter Krempa
44b18323e5 virsh: Refactor argument handling in cmdBlockPull
Put all argument parsing together and refactor the argument checking
code.
2015-07-21 15:32:59 +02:00
Peter Krempa
8e85f62826 virsh: Refactor argument handling in cmdBlockCopy
Put all argument parsing together and refactor the argument checking
code.
2015-07-21 15:32:59 +02:00
Peter Krempa
bd687cf9b9 virsh: Refactor argument checking in cmdBlockCommit
Use the VSH_EXCLUSIVE_OPTIONS to exclude combinations of --pivot and
--keep-overlay and refactor the enforcing of the --wait option and other
flags that imply --wait.
2015-07-21 15:32:59 +02:00
Peter Krempa
5dceea2c95 virsh: Kill blockJobImpl by moving the final impl into cmdBlockCommit
Final cleanup to get rid of the hub function.
2015-07-21 15:32:59 +02:00
Peter Krempa
bb5a145d2d virsh: Split out block pull implementation from blockJobImpl 2015-07-21 15:32:59 +02:00
Peter Krempa
a538ff8d9c virsh: block job: separate abort from blockJobImpl 2015-07-21 15:32:59 +02:00
Peter Krempa
42c9c6fcfc virsh: blockjob: Split out vshBlockJobSetSpeed from blockJobImpl 2015-07-21 15:32:58 +02:00
Peter Krempa
2f12cb9355 virsh: cmdBlockJob: Switch to declarative flag interlocking
Use the VSH_EXCLUSIVE_OPTIONS_VAR to interlock incompatible options.
Since a variable named 'abort' would conflict with older compilers use
VSH_EXCLUSIVE_OPTIONS for the --abort option.
2015-07-21 15:32:58 +02:00
Peter Krempa
dda95b531f virsh: blockjob: Extract block job info code into a separate function
cmdBlockJob will be converted to a hub that will call into the
individual executor functions.
2015-07-21 15:32:58 +02:00
Michal Privoznik
416d0e9418 cmdVcpuPin: Remove dead code
There's this condition:

flags & VIR_DOMAIN_AFFECT_CURRENT && virDomainIsActive(dom)

which can never be true since VIR_DOMAIN_AFFECT_CURRENT has hardcoded
value of zero. Therefore virDomainIsActive() is a dead code. However,
the condition could make sense if it is rewritten as the following:

!(flags & VIR_DOMAIN_AFFECT_CONFIG) && virDomainIsActive(dom)

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-07-15 11:40:41 +02:00
Luyao Huang
848ab685f7 virsh: report error if vcpu number exceed the guest maxvcpu number
Commit id '81dd81e' caused a regression when attempting to print a
specific vcpuid that is out of the range of the maximum vcpus for
the guest, such as:

 $ virsh vcpupin $dom 1000
 VCPU: CPU Affinity
 ----------------------------------

 $

Rather than just recover the old message, let's adjust the message based
on what would be displayed for a similar failure in the set path, such as:

 $ virsh vcpupin $dom 1000
 error: vcpu 1000 is out of range of persistent cpu count 2

 $ virsh vcpupin $dom 1000 --live
 error: vcpu 1000 is out of range of live cpu count 2

 $

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-07-02 06:26:37 -04:00
Boris Fiuczynski
1238dc29af Support for a new watchdog action inject-nmi
This patch provides support for a new watchdog action "inject-nmi" which
allows to define an inject of a non-maskable interrupt into a guest.

Signed-off-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Daniel Hansel <daniel.hansel@linux.vnet.ibm.com>
Reviewed-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: Tony Krowiak <akrowiak@linux.vnet.ibm.com>
2015-06-24 15:26:31 +02:00
Eric Farman
22b8a61756 Convert SCSI logical unit from unsigned int to unsigned long long
The SCSI Architecture Model defines a logical unit address
as 64-bits in length, so change the field accordingly so
that the entire value could be stored.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
2015-06-22 16:03:33 -04:00
Eric Farman
3b7983ad6d Print SCSI address attributes bus, target, unit as unsigned integer
The address elements are all unsigned integers, so we should
use the appropriate print directive when printing it.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
2015-06-22 16:03:33 -04:00
Eric Farman
f714f52882 Read SCSI address attributes bus, target, unit as positive integer
The SCSI address element attributes bus, target, and unit are expected
to be positive values, so make sure no one provides a negative value since
the value is stored as an unsigned.

Signed-off-by: Eric Farman <farman@linux.vnet.ibm.com>
2015-06-22 16:03:33 -04:00
Peter Krempa
e7d3ff8464 virsh: blockcopy: Report error if the copy job fails
When the block job would fail while watching it using the "--wait"
option for blockcopy, virsh would rather unhelpfully report:

$ virsh blockcopy vm hdc /tmp/raw.img --granularity 4096 --verbose --wait

Now in mirroring phase

Add a special case when the block job vanishes while waiting for it to
finish to improve the message:

$ virsh blockcopy vm hdc /tmp/raw.img --granularity 8192 --verbose --wait
error: Block Copy unexpectedly failed
2015-06-22 11:09:54 +02:00
Pavel Boldin
a4e92f9e14 virsh: selective block device migration
Add `virsh migrate' option `--migrate-disks' that allows CLI user to
explicitly specify block devices to migrate.

Signed-off-by: Pavel Boldin <pboldin@mirantis.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-06-18 16:46:09 +02:00
Peter Krempa
23e913671d virsh: change-media: Fix behavior with --update without a source
Docs state that it should behave like eject. Currently the code does not
do that. This is a regression since f4b5f53027.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1229592
2015-06-09 14:06:08 +02:00
Jiri Denemark
e9507fd41c virsh: Fix Ctrl-C behavior when watching a job
When watching a job (save, managedsave, dump, migrate) virsh spawns a
thread to call the appropriate API and waits for the result while
watching for interruption signals (SIGINT, Ctrl-C on the terminal).
Whenever such signal is caught, virsh calls virDomainAbortJob, stops
waiting for the job, and returns the result of virDomainAbortJob.

This is wrong because the job might have finished in the meantime or it
might have been cancelled by someone else and virsh would just report
the failure to abort the job. However, we are not interested in the
virDomainAbortJob's result at all, we need to keep waiting for the main
job to finish and report its result instead.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-06-03 09:53:02 +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
Ján Tomko
61139c4438 Fix the event name in vshEventTrayChangePrint
https://bugzilla.redhat.com/show_bug.cgi?id=1206114#c5

Reported by: zhenfeng wang <zhwang@redhat.com>
2015-05-28 14:14:47 +02:00
Ján Tomko
9bcadfabaa virsh: add set-user-password command
Expose the virDomainSetUserPassword API in virsh:
virsh set-user-password dom user 123456
2015-05-21 16:21:55 +02:00
Andrea Bolognani
8e2c5940cd virsh: Improve handling of send-process-signal --pid.
Use vshCommandOptLongLong() instead of retrieving the value as a
string and converting it to a number manually.
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
Luyao Huang
60107346a4 virsh: Report an error when cpulist parsing fails
When parsing a cpulist, the virBitmapParse is used. On an invalid
bitmap an error is reported, but the error gets cleared
immediately by subsequent public APIs call, e.g. virDomainFree().
Moreover, we don't check whether bitmap fits into maximal CPU ID
on the host. Therefore the following examples failed without any
error:

 # virsh vcpupin test3 1 aaa

 # virsh vcpupin test3 1 1000

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-05-14 14:16:07 +02:00
Jiri Denemark
05cda3d3a4 virsh: Don't check migrate parameters
Just pass anything a user specified to the appropriate API. It's the API
or libvirtd that should be responsible for checking its parameters.

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

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2015-05-04 15:06:33 +02:00
Luyao Huang
3dae162db7 tools: fix the wrong check when use virsh setvcpus --maximum
The --maximum option wasn't properly parsed and the equivalent flag
wasn't set.  Fix this bug and also rewrite the way we check this option
by using new macro.  The new approach is that --maximum requires
--config, no other combination is allowed, because they don't make sense.

The new error will be:

 # virsh setvcpus test --maximum 10
 error: Option --config is required by option --maximum

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-05-04 10:26:57 +02:00
John Ferlan
1f7e811249 virsh: Add iothreadadd and iothreaddel commands
https://bugzilla.redhat.com/show_bug.cgi?id=1161617

Add command to allow adding and removing IOThreads from the domain including
the configuration and live domain.

$ virsh iothreadadd --help
  NAME
    iothreadadd - add an IOThread to the guest domain

  SYNOPSIS
    iothreadadd <domain> <id> [--config] [--live] [--current]

  DESCRIPTION
    Add an IOThread to the guest domain.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--id] <number>  iothread for the new IOThread
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

$ virsh iothreaddel --help
  NAME
    iothreaddel - delete an IOThread from the guest domain

  SYNOPSIS
    iothreaddel <domain> <id> [--config] [--live] [--current]

  DESCRIPTION
    Delete an IOThread from the guest domain.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--id] <number>  iothread_id for the IOThread to delete
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

Assuming a running $dom with multiple IOThreads assigned and that
that the $dom has disks assigned to IOThread 1 and IOThread 2:

$ virsh iothreadinfo $dom
 IOThread ID     CPU Affinity
 ---------------------------------------------------
  1               2
  2               3
  3               0-1

$ virsh iothreadadd $dom 1
error: invalid argument: an IOThread is already using iothread_id '1' in iothreadpids

$ virsh iothreadadd $dom 1 --config
error: invalid argument: an IOThread is already using iothread_id '1' in persistent iothreadids

$ virsh iothreadadd $dom 4
$ virsh iothreadinfo $dom
 IOThread ID     CPU Affinity
 ---------------------------------------------------
  1               2
  2               3
  3               0-1
  4               0-3

$ virsh iothreadinfo $dom --config
 IOThread ID     CPU Affinity
 ---------------------------------------------------
  1               2
  2               3
  3               0-1

$ virsh iothreadadd $dom 4 --config
$ virsh iothreadinfo $dom --config
 IOThread ID     CPU Affinity
  ---------------------------------------------------
    1               2
    2               3
    3               0-1
    4               0-3

Assuming the same original configuration

$ virsh iothreaddel $dom 1
error: invalid argument: cannot remove IOThread 1 since it is being used by disk 'vde'

$ virsh iothreaddel $dom 3

$ virsh iothreadinfo $dom
 IOThread ID     CPU Affinity
 ---------------------------------------------------
  1               2
  2               3

$ virsh iothreadinfo $dom --config
 IOThread ID     CPU Affinity
 ---------------------------------------------------
  1               2
  2               3
  3               0-1
2015-04-27 12:36:36 -04:00
Jiri Denemark
aa9f139599 migration: Usable time statistics without requiring NTP
virDomainGetJobStats is able to report statistics of a completed
migration, however to get usable downtime and total time statistics both
hosts have to keep synchronized time. To provide at least some
estimation of the times even when NTP daemons are not running on both
hosts we can just ignore the time needed to transfer a migration cookie
to the destination host. The result will be also inaccurate but a bit
more predictable. The total/down time will just be at least what we
report.

https://bugzilla.redhat.com/show_bug.cgi?id=1213434
2015-04-24 15:02:00 +02:00
Ján Tomko
1882c0bd8d Add VIR_DOMAIN_EVENT_ID_DEVICE_ADDED event
The counterpart to VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED.

https://bugzilla.redhat.com/show_bug.cgi?id=1206114
2015-04-15 17:06:01 +02: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
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
Ján Tomko
ff6d2314d8 Rewrite vshParseCPUList
Use virBitmap helpers that were added after this function.

Change cpumaplen to int and fill it out by this function.
2015-04-13 17:20:59 +02:00
Ján Tomko
4c4b821ec3 Rewrite vshPrintPinInfo
Use virBitmapDataToString instead of constructing the ranges bit
by bit, remove the checking of parameters (that is already done
by the callers).

Let the callers choose the right bitmap, since there's only
one that uses this helper on a matrix-in-an-array.
2015-04-13 17:20:59 +02:00
Cole Robinson
e3aa4c91c8 virsh: Improve change-media success message
$ sudo virsh change-media f19 hdc /mnt/data/devel/media/Fedora-16-x86_64-Live-KDE.iso
succeeded to complete action update on media

Change the message to:

  Successfully {inserted,ejected,changed} media.

https://bugzilla.redhat.com/show_bug.cgi?id=967946
2015-04-06 16:32:31 -04:00
Ján Tomko
d64cd4a4c6 Fix indentation in cmdVcpuPin 2015-04-02 10:57:01 +02:00
Ján Tomko
d647ed858e virsh: remove stale comment
Copied from the vcpupin command, which has two modes of operation.
2015-04-02 10:46:30 +02:00
Ján Tomko
15e61034a5 Remove unnecessary includes from virsh.h
Include them in the files that need them instead.
2015-04-02 10:27:56 +02:00
Luyao Huang
390f218b83 virsh: blockCopy: Add missing jump on error path
The overflow check for the bandwidth parameter did not jump to the
cleanup label.

Additionally virsh should use vshError instead of virReportError.

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

Signed-off-by: Luyao Huang <lhuang@redhat.com>
2015-03-30 16:42:22 +02:00
Ján Tomko
a96b68e7a4 Rename DomainGetIOThreadsInfo to DomainGetIOThreadInfo
While it returns info about multiple threads, the version
without the plural is easier to read.
2015-03-26 16:11:10 +01:00
Ján Tomko
cf8b828a72 Rename virDomainIOThreadsInfoFree to virDomainIOThreadInfoFree
This function only frees the info for one thread.
2015-03-26 16:11:10 +01:00
Ján Tomko
fa67489d76 virsh: rename iothreadsinfo to iothreadinfo
The plural seems unnecessary.
2015-03-26 13:49:49 +01:00
Peter Krempa
f4b5f53027 virsh: domain: Fix the change-media command
The command did not modify the disk type and thus didn't allow to change
media from a file image to a block backed image or vice versa. In
addition when operating on a network backed removable devices the
command would replace the while <source> subelement with an invalid one.

This patch adds the --block option that allows to specify that the new
image is block backed and assumes that without that option all images
are file backed. Since network backends were always mangled it should
not cause problems.
2015-03-17 17:11:37 +01:00
Peter Krempa
4cbcaffb74 virsh: domain: Add --print-xml flag for command change-media
Allow printing the XML that would be used mostly for debugging purposes.
2015-03-17 17:11:37 +01:00
Peter Krempa
1cc820937a virsh: domain: Don't use vshPrepareDiskXML for creating XML to detach disk
Since cmdDetachDisk() calls into vshPrepareDiskXML() with
type == VSH_PREPARE_DISK_XML_NONE && source == NULL this would result
into skipping all the checks and effectively turn the function into a
XML formatter.

This patch changes the code to use the formatter directly so that the
function can be refactored in a easier way.
2015-03-17 17:11:37 +01:00
Eric Blake
ceec58ac9e virsh: fix report of non-active commit completion
Commit f182da20 (v1.2.6) caused a slight regression in virsh
reporting of a non-active block job; where it used to state
"Commit complete", it now states "Now in synchronized phase".
But the synchronized phase is only possible for an active commit.

For a reproducer, I created a chain 'a <- b <- c <- d <- e' and
ran virsh blockcommit $dom vda --top c --base a --verbose --wait

* tools/virsh-domain.c (cmdBlockCommit): Synchronized phase is
only possible on active commits.

Signed-off-by: Eric Blake <eblake@redhat.com>
2015-03-14 20:53:33 -06:00
John Ferlan
1cfc0a9990 virsh: Add iothreadpin command
https://bugzilla.redhat.com/show_bug.cgi?id=1135491

$ virsh iothread --help

  NAME
    iothreadpin - control domain IOThread affinity

  SYNOPSIS
    iothreadpin <domain> <iothread> <cpulist> [--config] [--live] [--current]

  DESCRIPTION
    Pin domain IOThreads to host physical CPUs.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    [--iothread] <number>  IOThread ID number
    [--cpulist] <string>  host cpu number(s) to set
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

Using the output from iothreadsinfo, allow changing the pinned CPUs for
a single IOThread.

$ virsh iothreadsinfo $dom
 IOThread ID    CPU Affinity
---------------------------------------------------
 1               2
 2               3
 3               0-1

$ virsh iothreadpin $dom 3 0-2

Then view the change

$ virsh iothreadsinfo $dom
 IOThread ID    CPU Affinity
---------------------------------------------------
 1               2
 2               3
 3               0-2

If an invalid value is supplied or require option missing,
then an error will be displayed:

$ virsh iothreadpin $dom 4 3
error: invalid argument: iothread value out of range 4 > 3

$ virsh iothreadpin $dom 3
error: command 'iothreadpin' requires <cpulist> option
2015-03-11 12:24:00 -04:00
John Ferlan
f41a5b844f virsh: Add 'iothreadsinfo' command
Add the 'iothreadsinfo' command to display IOThread Info data. Allow for
[--live] or [--config] options in order to display live or config data
for an active domain.

$ virsh iothreadsinfo --help
  NAME
    iothreadsinfo - view domain IOThreads

  SYNOPSIS
    iothreadsinfo <domain> [--config] [--live] [--current]

  DESCRIPTION
    Returns basic information about the domain IOThreads.

  OPTIONS
    [--domain] <string>  domain name, id or uuid
    --config         affect next boot
    --live           affect running domain
    --current        affect current domain

An active domain may return:

$ virsh iothreads $dom
 IOThread ID     CPU Affinity
---------------------------------------------------
  1               2
  2               3
  3               0

$ echo $?
0

For domains which don't have IOThreads the following is returned:

$ virsh iothreads $dom
No IOThreads found for the domain

$ echo $?
0

For domains which are not running the following is returned:

$ virsh iothreads $dom --live
error: Unable to get domain IOThreads information
error: Requested operation is not valid: domain is not running

$ echo $?
1

Editing a domains configuration and modifying the iothreadpin data for
thread 3 from nothing provided to setting a cpuset of '0-1' and then
displaying using --config would display:

$ virsh iothreads f18iothr --config
 IOThread ID     CPU Affinity
 ----------------------------
  1               2
  2               3
  3               0-1

$

Signed-off-by: John Ferlan <jferlan@redhat.com>
2015-03-06 06:49:32 -05:00
Pavel Hrdina
c2020b08ce virsh: fix memtune to also accept 0 as valid value
Fix vshMemtuneGetSize to return correct value.  We can then decide
according that return code whether a parameter is present and valid or
not.  This will allow as to accept 0 as a valid value.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-03-06 11:52:15 +01:00
Ján Tomko
c7b9f20666 Add --migratable support to virsh cpu-baseline
Wire up VIR_CONNECT_BASELINE_CPU_MIGRATABLE to this
command line option.
2015-03-02 07:59:12 +01:00
Pavel Hrdina
81dd81e475 virsh: fix vcpupin info
The "virDomainGetInfo" will get for running domain only live info and for
offline domain only config info. There was no way how to get config info
for running domain. We will use "vshCPUCountCollect" instead to get the
correct cpu count that we need to pass to "virDomainGetVcpuPinInfo".

Also cleanup some unnecessary variables and checks that are done by
drivers.

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

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2015-02-20 16:17:19 +01:00
Martin Kletzander
1bb1de83b2 virsh-edit: Make force editing usable
When editing a domain with 'virsh edit' and failing validation, the
usual message pops up:

  Failed. Try again? [y,n,f,?]:

Turning off validation can be useful, mainly for testing (but other
purposes too), so this patch adds support for relaxing definition in
virsh-edit and makes 'virsh edit <domain>' more usable.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2015-02-20 07:46:54 +01:00
Luyao Huang
073bef6412 virsh: fix IP address in vncdisplay for listen type='network'
Just like the fix for domdisplay in commit 1ba815.
2015-02-16 11:20:43 +01:00
Michal Privoznik
e008a03324 virsh attach-interface: Allow macvtap hotplug
Our hotplug code supports macvtap insertion to guests. However, we
somehow forgot about 'attach-interface' (which tries to build XML from
passed arguments and use virDomainAttachDeviceFlags()).
New type is accessible under 'direct' type, to keep the same type as
used in domain XML.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-13 09:33:12 +01:00
Michal Privoznik
dd6668f174 virsh attach-interface: Use virDomainNetType{From,To}String()
Instead of verbose string to enum conversion (if STREQ() else if
STREQ() else if STREQ() ...) lets use virDomainNetType{From,To}String.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-13 09:33:12 +01:00
Michal Privoznik
18bcba55cd virsh attach-interface: Use enum instead of arbitrary integers
The type of interface to attach is held in the variable 'typ'.
Depending on interface type selected by user, the variable is set
either to 1 (network), or 2 (bridge). Lets use already existing
enum from domain_conf.h instead: virDomainNetType.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2015-02-13 09:33:12 +01:00
Luyao Huang
1ba8156cc9 virsh: fix IP address in domdisplay for listen type='network'
https://bugzilla.redhat.com/show_bug.cgi?id=1191016

virsh's domdisplay command looks in /domain/devices/graphics/@listen
of the domain's XML for the listen address, however for listen
type='network' (added in libvirt 0.9.4), the <graphics> element
doesn't have a listen attribute, but has a <listen> subelement,
*still* with no address (this is the inactive XML):

 <graphics type='spice' autoport='yes' keymap='en-us'>
  <listen type='network' network='default'/>
 </graphics>

However, at domain start time the <listen> subelement gets its address
attribute filled in once libvirt figures out the IP address associated
with the named network (this is the status XML):

 <graphics type='spice' port='5901' autoport='yes' keymap='en-us'>
  <listen type='network' address='192.168.122.1' network='default'/>
 </graphics>

So in these cases, we need to look at
/domain/devices/graphics/listen/@address instead.

Even though another patch is being pushed that will backfill
listen/@address into @listen, this patch is still useful, as it fixes
domdisplay for cases of a new virsh (with this patch) connecting to a
libvirtd that is newer than 0.9.4 but doesn't have the followup patch.

Signed-off-by: Luyao Huang <lhuang@redhat.com>
Signed-off-by: Laine Stump <laine@laine.org>
2015-02-11 10:52:22 -05:00
Stefan Zimmermann
4b4c7208c9 S390: ccw support for virsh attach-disk address parameter
Adding ccw bus address support to the optional address parameter of virsh
attach-disk. The format used is ccw:cssid. ssid.devno, e.g.
ccw:0xfe.0x0.0x0201

Virtio-ccw devices must have their cssid set to 0xfe.

Signed-off-by: Stefan Zimmermann <stzi@linux.vnet.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy@linux.vnet.ibm.com>
Reviewed-by: Cornelia Huck <cornelia.huck@de.ibm.com>
2015-02-09 14:22:23 +01:00
Daniel P. Berrange
d7565bd8aa virsh: add support for domain XML validation
The 'virsh edit' command gets XML validation enabled by default,
with a --skip-validate option to disable it. The 'virsh define'
and 'virsh create' commands get a --validate option to enable
it, to avoid regressions for existing scripts.

The quality of error reporting from libxml2 varies depending
on the type of XML error made. Sometimes it is quite clear
and useful, other times it is obscure & inaccurate. At least
the user will see an error now, rather than having their
XML modification silently disappear.
2015-01-16 11:07:59 +00:00
Hao Liu
a0670aef37 virsh: Emit error for VSH_OT_DATA without VSH_OFLAG_REQ
Commit 6b9964 enforces checking invalid use of VSH_OT_STRING with
VSH_OFLAG_REQ. This commit tries to do the same thing to stop using
VSH_OT_DATA without VSH_OFLAG_REQ and also fix existing misuse.

Signed-off-by: Hao Liu <hliu@redhat.com>
2015-01-12 13:38:42 +01:00
Tomoki Sekiyama
fadfcd9164 virsh: expose virDomainGetFSInfo
Add a "domfsinfo" command that shows a list of filesystems info mounted in
the guest. For example:

virsh # domfsinfo vm1
Mountpoint                           Name     Type     Target
-------------------------------------------------------------------
/                                    sda1     ext4     hdc
/opt                                 dm-2     vfat     vda,vdb
/mnt/test                            sdb1     xfs      sda

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
2014-11-24 10:29:16 -05:00
Peter Krempa
1a4609101b event: Add guest agent lifecycle event
As qemu is now able to notify us about change of the channel state used
for communication with the guest agent we now can more precisely track
the state of the guest agent.

To allow notifying management apps this patch implements a new event
that will be triggered on changes of the guest agent state.
2014-11-24 15:39:17 +01:00
Martin Kletzander
4c1b9e22b9 virsh: sync domdisplay help and manual
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-11-21 12:56:44 +01:00
Eric Blake
0d5168392f build: avoid 32-bit failure on older gcc
On 32-bit platforms with old gcc (hello RHEL 5 gcc 4.1.2), the
build fails with:
virsh-domain.c: In function 'cmdBlockCopy':
virsh-domain.c:2172: warning: comparison is always false due to limited range of data type

Adjust the code to silence the warning.

* tools/virsh-domain.c (cmdBlockCopy): Pacify RHEL 5 gcc.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-11-20 08:32:30 -07:00
Erik Skultety
8312d44d72 virsh: Fix msg: blockjob is aborted from another client
When a block{pull, copy, commit} is aborted via keyboard interrupt,
the job is properly canceled followed by proper error message.
However, when the job receives an abort from another client connected
to the same domain, the error message incorrectly indicates that
a blockjob has been finished successfully, though the abort request
took effect. This patch introduces a new blockjob abort handler, which
is registered when the client calls block{copy,commit,pull} routine,
providing its caller the status of the finished blockjob.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1135442
2014-11-20 13:32:59 +01:00
Eric Blake
eb9093763f maint: forbid 'int foo = true'
I noticed this while working on qemuDomainGetBlockInfo.  Assigning
a bool value to an int variable compiles fine, but raises red flags
on the maintenance front as it becomes too easy to assign -1 or 2
or any other non-bool value to the same variable.

* cfg.mk (sc_prohibit_int_assign_bool): New rule.
* src/conf/snapshot_conf.c (virDomainSnapshotRedefinePrep): Fix
offenders.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo)
(qemuDomainSnapshotCreateXML): Likewise.
* src/test/test_driver.c (testDomainSnapshotAlignDisks):
Likewise.
* src/util/vircgroup.c (virCgroupSupportsCpuBW): Likewise.
* src/util/virpci.c (virPCIDeviceBindToStub): Likewise.
* src/util/virutil.c (virIsCapableVport): Likewise.
* tools/virsh-domain-monitor.c (cmdDomMemStat): Likewise.
* tools/virsh-domain.c (cmdBlockResize, cmdScreenshot)
(cmdInjectNMI, cmdSendKey, cmdSendProcessSignal)
(cmdDetachInterface): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-11-19 08:20:39 -07:00
Martin Kletzander
91cc3d9570 Remove unnecessary curly brackets in tools/
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-11-14 17:13:36 +01:00
Martin Kletzander
e09f9e4c32 virsh: Convert EDIT_NOT_CHANGED macro to do-while block.
This macro is being used as an inline body after an if and might get
pretty confusing.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-11-14 17:13:00 +01:00
Martin Kletzander
11d9dd1ad8 virsh: Reorder some options
According to comments in parsing functions, optional options should be
specified *after* required ones.  It makes sense and help output looks
cleaner.  The only exceptions are options with type == VSH_OT_ARGV.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-11-13 15:44:23 +01:00
Hao Liu
12bd207e21 Fix invalid log, misused option types and a typo
This patch fixes the following issues.

1)  When an invalid wwn is introduced, libvirt reports
    "Malformed wwn: %s". The template won't be replaced.

2)  "target" option for dompmsuspend and "xml" option for
    save-image-define are required options and should use
    VSH_OT_DATA instead of VSH_OT_STRING as an option type.

3)  A typo.

Signed-off-by: Hao Liu <hliu@redhat.com>
2014-11-11 11:05:43 +01:00
Matthias Gatto
72f808c41f virsh: Add bps_max and friends to virsh
Add the new throttle options to virsh, and send them to libvirt.

Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
2014-11-10 17:19:25 +01:00
Hao Liu
78d4c18440 virsh: Fix types for option bandwidth in block*
Bandwidth options in blockcommit, blockcopy, blockjob and blockpull
are parsed by vshCommandOptULWrap() and should be shown as a number
type option.

And a typo is fixed.

Signed-off-by: Hao Liu <hliu@redhat.com>
2014-11-06 09:37:20 +01:00
Eric Blake
0585332430 maint: avoid static zero init in tools
C guarantees that static variables are zero-initialized.  Some older
compilers (and also gcc -fno-zero-initialized-in-bss) create larger
binaries if you explicitly zero-initialize a static variable.

* tools/virsh-console.c (got_signal): Drop unused variable.
* tools/virsh-domain.c: Fix initialization.
* tools/virsh.c: Likewise.
* tools/virt-host-validate-common.c (virHostMsgWantEscape):
Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-10-29 09:55:09 -06:00
Shanzhi Yu
d8415b5469 virsh: Improve the job type reported of virsh cmd blockcommit
When starting an active block commit job in virsh, it will report
"Block Commit started", but for more precise message it could
report "Active Block Commit started".

Signed-off-by: Shanzhi Yu <shyu@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-10-29 00:16:32 +01:00
Peter Krempa
4d1852c485 virsh: domain: Use global constant for XML file size limit
Few places still used hardcoded limit for maximum XML size for commands
that accept XML files. The hardcoded limits ranged from 8k to 1M. Use
VSH_MAX_XML_FILE to express this limit in a unified way. This will bump
the limit for the commands that used hardcoded string lengths to 10M.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1152427
2014-10-14 10:04:31 +02:00
Peter Krempa
92427948b3 maint: Prohibit "devname" by a syntax check rules
and tweak the code to avoid using it.
2014-10-01 16:39:01 +02:00
Pavel Hrdina
e426718129 event: introduce new event for tunable values
This new event will use typedParameters to expose what has been actually
updated and the reason is that we can in the future extend any tunable
values or add new tunable values. With typedParameters we don't have to
worry about creating some other events, we will just use this universal
event to inform user about updates.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-09-23 21:49:57 +02:00
Michael R. Hines
9cc1586d2b qemu: Memory pre-pinning support for RDMA migration
RDMA Live migration requires registering memory with the hardware, and
thus QEMU offers a new 'capability' to pre-register / mlock() the guest
memory in advance for higher RDMA performance before the migration
begins. This capability is disabled by default, which means QEMU will
register the memory with the hardware in an on-demand basis.

This patch exposes this capability with the following example usage:

virsh migrate --live --rdma-pin-all --migrateuri rdma://hostname domain qemu+ssh://hostname/system

Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-09-23 08:11:50 +02:00
Michael R. Hines
30b24df165 qemu: Expose additional migration statistics
RDMA migration uses the 'setup' state in QEMU to optionally lock
all memory before the migration starts. The total time spent in
this state is exposed as VIR_DOMAIN_JOB_SETUP_TIME.

Additionally, QEMU also exports migration throughput (mbps) for both
memory and disk, so let's add them too: VIR_DOMAIN_JOB_MEMORY_BPS,
VIR_DOMAIN_JOB_DISK_BPS.

Signed-off-by: Michael R. Hines <mrhines@us.ibm.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-09-23 08:10:30 +02:00
John Ferlan
bc5a8090af virsh: Add iothread to 'attach-disk'
Add an iothread parameter to allow attaching to an IOThread, such as:

virsh attach-disk $dom $source $target --live --config --iothread 2 \
     --targetbus virtio --driver qemu --subdriver raw  --type disk
2014-09-15 13:18:55 -04:00
John Ferlan
0268a35db4 virsh: Resolve Coverity DEADCODE
Coverity complains that on the first pass through the for loop that
'params' cannot be true, thus the ternary setting to "&" cannot be
done. Since we can only ever get to this point once, drop the ternary
2014-09-15 10:44:27 -04:00
Michal Privoznik
273b6581ca virDomainUndefineFlags: Allow NVRAM unlinking
When a domain is undefined, there are options to remove it's
managed save state or snapshots. However, there's another file
that libvirt creates per domain: the NVRAM variable store file.
Make sure that the file is not left behind if the domain is
undefined.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-09-12 14:26:34 +02:00
John Ferlan
be365d8dff virsh: Resolve Coverity NEGATIVE_RETURNS
Coverity notes that after we VIR_ALLOC_N(params, nparams) a failed call to
virDomainGetCPUStats could result in nparams being set to -1. In that case,
the subsequent virTypedParamsFree in cleanup will pass -1 which isn't good.

Use the returned value as the number of stats to display in the loop as
it will be the value reported from the hypervisor and may be less than
nparams which is OK

Signed-off-by: John Ferlan <jferlan@redhat.com>
2014-09-12 06:12:50 -04:00
Jiri Denemark
58252332eb virsh: Move --completed from resume to domjobinfo
Because of similar contexts, git rebase I did just before pushing the
series which added --completed option patched the wrong command.
2014-09-12 10:18:04 +02:00
John Ferlan
60b029c7a0 virsh: Resolve Coverity DEADCODE
Coverity points out that if 'dom' isn't returned from virDomainQemuAttach,
then the code already jumps to cleanup, so there was no need for the
subsequent if (dom != NULL) check.

I moved the error message about failure into the goto cleanup on failure
and then removed the if (dom != NULL)

Signed-off-by: John Ferlan <jferlan@redhat.com>
2014-09-11 08:10:13 -04:00
John Ferlan
daf27d4d82 virsh: Resolve Coverity DEADCODE
Since 0766783abb

Coverity complains that the EDIT_FREE definition results in DEADCODE.

As it turns out with the change to use the EDIT_FREE macro the call to
vir*Free() wouldn't be necessary nor would it happen...

Prior code to above commitid would :

  vir*Ptr foo = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  vir*Free(foo);
  foo = vir*DefineXML()
  ...

And thus the free was needed.  With the change to use EDIT_FREE the
same code changed to:

  vir*Ptr foo = NULL;
  vir*Ptr foo_edited = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  if (foo_edited)
      vir*Free(foo_edited);
  foo_edited = vir*DefineXML()
  ...

However, foo_edited could never be set in the code path - even with
all the goto's since the only way for it to be set is if vir*DefineXML()
succeeds in which case the code to allow a retry (and thus all the goto's)
never leaves foo_edited set

All error paths lead to "cleanup:" which causes both foo and foo_edited
to call the respective vir*Free() routines if set.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2014-09-11 08:03:37 -04:00
Peter Krempa
78948e1c80 virsh: desc command in --title mode mentions description instead of title
Tweak the messages so that they mention "title" rather than
"description" when operating in title mode. Also fixes one missing "%s"
before non-formatted gettext message.

Before:
 $ virsh desc --title dom
 No description for domain: dom

After:
 $ virsh desc --title dom
 No title for domain: dom

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1140034
2014-09-10 14:39:46 +02:00
Peter Krempa
e22c5c57ee virsh: domain: Clean up handling of "dom" in "save" command 2014-09-10 10:12:42 +02:00
Jiri Denemark
13f3c4639f virsh: Add support for completed job stats
New --completed flag for virsh domjobinfo command.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-09-10 09:37:34 +02:00
Eric Blake
efe5061f5a blockjob: avoid 32-bit compilation warning
Commit c1d75de caused this warning on 32-bit platforms (fatal when
-Werror is enabled):

virsh-domain.c: In function 'cmdBlockCopy':
virsh-domain.c:2003:17: error: comparison is always false due to limited range of data type [-Werror=type-limits]

Forcing the left side of the < to be ull instead of ul shuts up
the 32-bit compiler while still protecting 64-bit code from overflow.

* tools/virsh-domain.c (cmdBlockCopy): Add type coercion.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-08 08:50:48 -06:00
Eric Blake
c1d75deea2 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>
2014-09-06 21:45:05 -06:00
Eric Blake
0eaad0a39c 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>
2014-09-06 09:28:54 -06:00
Eric Blake
b7e73585a8 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>
2014-09-05 13:13:50 -06:00
Eric Blake
1105c1deff 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>
2014-09-05 13:13:23 -06:00
Eric Blake
2019b7caca 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>
2014-09-05 12:47:19 -06:00
Eric Blake
c47f6aad95 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>
2014-09-05 11:48:51 -06:00
Eric Blake
d194d6e7e6 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>
2014-09-04 14:34:03 -06:00
Eric Blake
1db2f4f767 virsh: drop unused variable
While prepping for virDomainBlockJob patches, I found some dead code.

* tools/virsh-domain.c (blockJobImpl): Kill unused 'name'.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-26 22:17:07 -06:00
Peter Krempa
3b20e50ddb virsh: domain: Split out code to lookup domain from string
Split out guts of the function to reuse it to get domain objects from
string.
2014-08-26 22:48:05 +02:00
Ján Tomko
c285ffc4c2 virsh: Initialize vshData in cmdMigrate
If the virConnect did not succeeed, we called
virConnectClose on uninitialized data.

Introduced by commit 7eabd55.
2014-08-26 13:20:47 +02:00
Chunyan Liu
7eabd5503e cmdMigrate: move vshConnect before vshWatchJob
A possible fix to issue:
http://www.redhat.com/archives/libvir-list/2014-August/thread.html#00227

While doing migration on KVM host, found problem sometimes:
VM is already running on the target host and disappears from source
host, but 'virsh migrate' command line hangs, cannot exit normally.
If pressing "ENTER" key, it will exit.

The code hangs at tools/virsh-domain.c: cmdMigrate
->vshWatchJob->poll():
poll() is trying to select pipe_fd, which is used to receive message
from doMigrate thread. In debugging, found that doMigrate finishes
and at the end it does call safewrite() to write the retval ('0' or
'1') to pipe_fd, and the write is completed. But cmdMigrate poll()
cannot get the event. If pressing "ENTER" key, poll() can get the
event and select pipe_fd, then command line can exit.

In current code, authentication thread which is called by vshConnect
will use stdin, and at the same time, in cmdMigrate main process,
poll() is listening to stdin, that probably affect poll() to get
pipe_fd event. Better to move authentication before vshWatchJob. With
this change, above problem does not exist.

Signed-off-by: Chunyan Liu <cyliu@suse.com>
2014-08-19 11:32:51 +02:00
Ján Tomko
ee668206cd virsh: check if domiftune parameters fit into UINT
We parse the bandwidth rates as unsinged long long,
then try to fit them in VIR_TYPED_PARAM_UINT.

Report an error if they exceed UINT_MAX instead of
quietly using wrong values.

https://bugzilla.redhat.com/show_bug.cgi?id=1043735
2014-08-04 16:59:27 +02:00
Martin Kletzander
9318121db8 remove range checking for blkiotune weight
This was changed before:

https://www.redhat.com/archives/libvir-list/2013-October/msg00525.html

but not everywhere in the code.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-24 17:32:37 +02:00
Martin Kletzander
dd4791c00d virsh: add option for selecting domdisplay type
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=997802

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-24 16:23:41 +02:00
Martin Kletzander
e858628e45 virsh: add error message when no graphical display is found
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-24 16:23:41 +02:00
Michal Privoznik
607806f87f Fix const correctness
In many places we define a variable as a 'const char *' when in fact
we modify it just a few lines below. Or even free it. We should not do
that.

There's one exception though, in xenSessionFree() xenapi_utils.c. We
are freeing the xen_session structure which is defined in
xen/api/xen_common.h public header. The structure contains session_id
which is type of 'const char *' when in fact it should have been just
'char *'. So I'm leaving this unmodified, just noticing the fact in
comment.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-16 12:07:24 +02:00
Martin Kletzander
fd59f6c83e virsh: document the possibility of accepting integers for numatune mode
According to the code, 'virsh numatune' supports integers for
specifying --mode as well as the string definitions "strict",
"interleave", and "preferred".  However, this possibility was not
documented anywhere, so this patch adds it to both the man page and
command help.

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-09 15:08:23 +02:00
Peter Krempa
37183e5db8 lib: Introduce flag VIR_DOMAIN_BLOCK_REBASE_RELATIVE
Introduce flag for the block rebase API to allow the rebase operation to
leave the chain relatively addressed. Also adds a virsh switch to enable
this behavior.
2014-07-08 11:51:06 +02:00
Peter Krempa
bda44ca2ca lib: Introduce flag VIR_DOMAIN_BLOCK_COMMIT_RELATIVE
Introduce flag for the block commit API to allow the commit operation to
leave the chain relatively addressed. Also adds a virsh switch to enable
this behavior.
2014-07-08 11:45:04 +02:00
Peter Krempa
87388228f4 virsh: domain: Use inactive XML when unplugging interface with --config
Similary to cmdDetachDisk fetch the inactive definition when --config
is specified as the active may not contain the network interface
if it was plugged with --config.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1056902
2014-07-07 13:05:32 +02:00
Yanbing Du
7e157858b4 virsh: Allow attach-disk to specify disk target bus
By default, the bus type is inferred from the style of the device
name('target' in this command), e.g. a device named 'sda' will
typically be exported using a SCSI bus. Actually, not only SCSI bus,
but USB/SATA bus also use this kind of device name. So add '--bus'
option for attach-disk command to allow user specify the target bus.

Signed-off-by: Yanbing Du <ydu@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-02 13:01:45 +02:00
Jiri Denemark
80d0918bd2 virConnectCompareCPU: Introduce FAIL_INCOMPATIBLE flag
The new VIR_CONNECT_COMPARE_CPU_FAIL_INCOMPATIBLE flag for
virConnectCompareCPU can be used to get an error
(VIR_ERR_CPU_INCOMPATIBLE) describing the incompatibility instead of the
usual VIR_CPU_COMPARE_INCOMPATIBLE return code.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-06-26 00:44:02 +02:00
Eric Blake
f182da20b0 virsh: expose new active commit controls
Add knobs to virsh to manage a 2-phase active commit of the top
layer, similar to knobs already present on blockcopy.  While this
code will fail until later patches actually implement the new
knobs in the qemu driver, doing it now proves that the API is
usable and also makes it easier for testing the qemu changes as
they are made.

* tools/virsh-domain.c (cmdBlockCommit): Add --active, --pivot,
and --keep-overlay options, modeled after blockcopy.
(blockJobImpl): Support --active flag.
* tools/virsh.pod (blockcommit): Document new flags.
(blockjob): Mention 2-phase commit interaction.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-19 07:07:25 -06:00
Eric Blake
1bfe73a126 blockjob: use stable disk string in job event
When the block job event was first added, it was for block pull,
where the active layer of the disk remains the same name.  It was
also in a day where we only cared about local files, and so we
always had a canonical absolute file name.  But two things have
changed since then: we now have network disks, where determining
a single absolute string does not really make sense; and we have
two-phase jobs (copy and active commit) where the name of the
active layer changes between the first event (ready, on the old
name) and second (complete, on the pivoted name).

Adam Litke reported that having an unstable string between events
makes life harder for clients.  Furthermore, all of our API that
operate on a particular disk of a domain accept multiple strings:
not only the absolute name of the active layer, but also the
destination device name (such as 'vda').  As this latter name is
stable, even for network sources, it serves as a better string
to supply in block job events.

But backwards-compatibility demands that we should not change the
name handed to users unless they explicitly request it.  Therefore,
this patch adds a new event, BLOCK_JOB_2 (alas, I couldn't think of
any nicer name - but at least Migrate2 and Migrate3 are precedent
for a number suffix).  We must double up on emitting both old-style
and new-style events according to what clients have registered for
(see also how IOError and IOErrorReason emits double events, but
there the difference was a larger struct rather than changed
meaning of one of the struct members).

Unfortunately, adding a new event isn't something that can easily
be broken into pieces, so the commit is rather large.

* include/libvirt/libvirt.h.in (virDomainEventID): Add a new id
for VIR_DOMAIN_EVENT_ID_BLOCK_JOB_2.
(virConnectDomainEventBlockJobCallback): Document new semantics.
* src/conf/domain_event.c (_virDomainEventBlockJob): Rename field,
to ensure we catch all clients.
(virDomainEventBlockJobNew): Add parameter.
(virDomainEventBlockJobDispose)
(virDomainEventBlockJobNewFromObj)
(virDomainEventBlockJobNewFromDom)
(virDomainEventDispatchDefaultFunc): Adjust clients.
(virDomainEventBlockJob2NewFromObj)
(virDomainEventBlockJob2NewFromDom): New functions.
* src/conf/domain_event.h: Add new prototypes.
* src/libvirt_private.syms (domain_event.h): Export new functions.
* src/qemu/qemu_driver.c (qemuDomainBlockJobImpl): Generate two
different events.
* src/qemu/qemu_process.c (qemuProcessHandleBlockJob): Likewise.
* src/remote/remote_protocol.x
(remote_domain_event_block_job_2_msg): New struct.
(REMOTE_PROC_DOMAIN_EVENT_BLOCK_JOB_2): New RPC.
* src/remote/remote_driver.c
(remoteDomainBuildEventBlockJob2): New handler.
(remoteEvents): Register new event.
* daemon/remote.c (remoteRelayDomainEventBlockJob2): New handler.
(domainEventCallbacks): Register new event.
* tools/virsh-domain.c (vshEventCallbacks): Likewise.
(vshEventBlockJobPrint): Adjust client.
* src/remote_protocol-structs: Regenerate.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-19 06:54:12 -06:00
Eric Blake
1784037991 virsh: improve blockcopy UI
Peter's review of an early version of my addition of active block
commit pointed out some issues that I was copying from the block
copy code; fix them up now before perpetuating them.

For virsh commands that manage a single API call, it's nice to have
a 1:1 mapping of options to flags, so that we can test that
lower-layer software handles flag combinations correctly.  But where
virsh is introducing syntactic sugar to combine multiple API calls
into a single user interface, we might as well make that interface
compact.  That is, we should allow the shorter command-line of
'blockcopy $dom $disk --pivot' without having to explicitly specify
--wait, because this isn't directly a flag passed to a single
underlying API call.

Also, my use of embedded ?: ternaries bordered on unreadable.

* tools/virsh-domain.c (cmdBlockCopy): Make --pivot, --finish,
and --timeout imply --wait. Drop excess ?: operators.
* tools/virsh.pod (blockcopy): Update documentation.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-12 14:41:40 -06:00
Jincheng Miao
e430410480 virsh: forbid negative vcpu argument to vcpupin
The vcpupin command allowed specifying a negative number for the --vcpu
argument. This would the overflow when the underlying virDomainPinVcpu
API was called.

 $ virsh vcpupin r7 -1 0
 error: numerical overflow: input too large: 4294967295

Switch the vCPU variable to a unsigned int and parse it using the
corresponding function.

Also improve the vcpupin test to cover all the defects.

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

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2014-06-12 14:06:21 +02:00
Peter Krempa
0e2d73051a virsh: Reject negative numbers in vshCommandOptUL
To follow the new semantics of the vshCommandOptToU* functions convert
this one to reject negative numbers too. To allow using -1 for "maximum"
semantics for the two bandwidth functions that use this helper introduce
vshCommandOptULWrap. Although currently the migrate-setspeed function
for the qemu driver will reject -1 as maximum.
2014-06-12 14:06:20 +02:00
Eric Blake
b298025063 blockcommit: document semantics of committing active layer
Now that qemu 2.0 allows commit of the active layer, people are
attempting to use virsh blockcommit and getting into a stuck
state, because libvirt is unprepared to handle the two-phase
commit required by qemu.

Stepping back a bit, there are two valid semantics for a
commit operation:

1. Maintain a 'golden' base, and a transient overlay. Make
changes in the overlay, and if everything appears to work,
commit those changes into the base, but still keep the overlay
for the next round of changes; repeat the cycle as desired.

2. Create an external snapshot, then back up the stable state
in the backing file. Once the backup is complete, commit the
overlay back into the base, and delete the temporary snapshot.

Since qemu doesn't know up front which of the two styles is
preferred, a block commit of the active layer merely gets
the job into a synchronized state, and sends an event; then
the user must either cancel (case 1) or complete (case 2),
where qemu then sends a second event that actually ends the
job.  However, until commit e6bcbcd, libvirt was blindly
assuming the semantics that apply to a commit of an
intermediate image, where there is only one sane conclusion
(the job automatically ends with fewer elements in the chain);
and getting stuck because it wasn't prepared for qemu to enter
a second phase of the job.

This patch adds a flag to the libvirt API that a user MUST
supply in order to acknowledge that they will be using two-phase
semantics.  It might be possible to have a mode where if the
flag is omitted, we automatically do the case 2 semantics on
the user's behalf; but before that happens, I must do additional
patches to track the fact that we are doing an active commit
in the domain XML.  Later patches will add support of the flag,
and once 2-phase semantics are working, we can then decide
whether to relax things to allow an omitted flag to cause an
automatic pivot.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_BLOCK_COMMIT_ACTIVE)
(VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT): New enums.
* src/libvirt.c (virDomainBlockCommit): Document two-phase job
when committing active layer, through new flag.
(virDomainBlockJobAbort): Document that pivot also occurs after
active commit.
* tools/virsh-domain.c (vshDomainBlockJob): Cover new job.
* src/qemu/qemu_driver.c (qemuDomainBlockCommit): Explicitly
reject active copy; later patches will add it in.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-10 11:11:16 -06:00
Ján Tomko
a3173fef9d Implement pretty flag for vcpuinfo and nodecpumap
Report CPU affinities / online CPUs in human-readable form when
this flag is present:

Before:
CPU Affinity:   y-yy

After:
CPU Affinity:   0,2-3 (out of 4)

https://bugzilla.redhat.com/show_bug.cgi?id=985980
2014-06-06 14:35:19 +02:00
Ján Tomko
8f3f51b723 virsh: Separate API calls and result printing in cmdVcpuinfo
This allows reuse of the result printing code.
2014-06-06 14:35:18 +02:00
Ján Tomko
bec105e6db virsh: Invert logic in cmdVcpuinfo
Initialize 'ret' to false and introduce a cleanup label.
2014-06-06 14:35:18 +02:00
Li Yang
ed5950909d virsh: reject undefine --wipe-storage without also naming storage
For now, if only '--wipe-storage' is assigned, user can undefine a
domain normally. But actually '--wipe-storage' doesn't do anything,
and this may confuse user. Better is to require that '--wipe-storage'
only works if the user specifies volumes to be removed.

Before:
$ virsh undefine virt-tests-vm1 --wipe-storage
Domain virt-tests-vm1 has been undefined

After:
$ virsh undefine virt-tests-vm1 --wipe-storage
error: '--wipe-storage' requires '--storage <string>' or '--remove-all-storage'

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-14 11:11:50 -06:00
Peter Krempa
31b140eba4 virsh: domain: Fix output of the VNC display number for domdisplay
Commit 9976c4b9a6 broke the output for VNC
displays as the port number is converted to VNC display number by
subtracting 5900. This yields port 0 for the first display and thus the
output would be skipped.

Before:
 $ virsh domdisplay VM
 vnc://localhost

After:
 $ tools/virsh domdisplay VM
 vnc://localhost:0
2014-05-13 11:34:38 +02:00
Tomoki Sekiyama
061c6347e4 virsh: Expose new virDomainFSFreeze and virDomainFSThaw API
These are exposed under domfsfreeze command and domfsthaw command.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
2014-05-12 21:01:13 -06:00
Jim Fehlig
b98bf81151 Introduce a new flag for controlling shutdown/reboot
Add a new flag to virDomain{Reboot,Shutdown}FlagValues to allow
shutting down and rebooting a domain via the Xen paravirt control
interface.
2014-05-05 10:52:21 -06:00
Eric Blake
14d7fcc23a virsh: fix 'help event'
'virsh help event' included a summary line "event - (null)"
due to a misnamed info field.

* tools/virsh-domain.c (info_event): Use correct name.
* tools/virsh-network.c (info_network_event): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-31 08:37:39 -06:00
Ján Tomko
5d8793eebb Indent top-level labels by one space in tools/ 2014-03-25 14:58:41 +01:00
Qiao Nuohan
2f934550b9 allow "virsh dump --memory-only" specify dump format
This patch adds "[--format] <string>" to "virsh dump --memory-only", which is
changed to use the new virDomainCoreDumpWithFormat API.

Signed-off-by: Qiao Nuohan <qiaonuohan@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-24 14:14:14 -06:00
Chegu Vinod
05e1b06ab7 libvirt support to force convergence of live guest migration
Busy enterprise workloads hosted on large sized VM's tend to dirty
memory faster than the transfer rate achieved via live guest migration.
Despite some good recent improvements (& using dedicated 10Gig NICs
between hosts) the live migration may NOT converge.

Recently support was added in qemu (version 1.6) to allow a user to
choose if they wish to force convergence of their migration via a
new migration capability : "auto-converge". This feature allows for qemu
to auto-detect lack of convergence and trigger a throttle-down of the
VCPUs.

This patch includes the libvirt support needed to trigger this
feature. (Testing is in progress)

Signed-off-by:  Chegu Vinod <chegu_vinod@hp.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-03-21 14:17:15 +01:00
Eric Blake
43b17dd444 qemu: allow filtering events by regex
When listening for a subset of monitor events, it can be tedious
to register for each event name in series; nicer is to register
for multiple events in one go.  Implement a flag to use regex
interpretation of the event filter.

While at it, prove how much I hate the shift key, by adding a
way to filter for 'shutdown' instead of 'SHUTDOWN'. :)

* include/libvirt/libvirt-qemu.h
(virConnectDomainQemuMonitorEventRegisterFlags): New enum.
* src/libvirt-qemu.c (virConnectDomainQemuMonitorEventRegister):
Document flags.
* tools/virsh-domain.c (cmdQemuMonitorEvent): Expose them.
* tools/virsh.pod (qemu-monitor-event): Document this.
* src/conf/domain_event.c
(virDomainQemuMonitorEventStateRegisterID): Add flags.
(virDomainQemuMonitorEventFilter): Handle regex, and optimize
client side.
(virDomainQemuMonitorEventCleanup): Clean up regex.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-20 11:25:37 -06:00
Eric Blake
88996de1c3 qemu: virsh wrapper for qemu events
Any new API deserves a good virsh wrapper :)

    qemu-monitor-event [<domain>] [<event>] [--pretty] [--loop] [--timeout <number>]

Very similar to the previous work on 'virsh event'.  For an
example session:

$ virsh -c qemu:///system qemu-monitor-event --event SHUTDOWN&
$ virsh -c qemu:///system start f18-live
Domain f18-live started

$ virsh -c qemu:///system destroy f18-live
Domain f18-live destroyed

event SHUTDOWN at 1391212552.026544 for domain f18-live: (null)
events received: 1

[1]+  Done                    virsh -c qemu:///system qemu-monitor-event --event SHUTDOWN
$

* tools/virsh-domain.c (cmdQemuMonitorEvent): New command.
* tools/virsh.pod (qemu-monitor-event): Document it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-20 11:25:37 -06:00
Michal Privoznik
149733821d qemuDomainSetInterfaceParameters: Allow bandwidth clear out
We allow translation from no_bandwidth to has_bandwidth for a vnic.
However, going in the opposite direction is not implemented. It's not
limitation of the API rather than internal implementation. The problem
is, we correctly detect that user hasn't specified any outbound (say
he wants to clear out outbound). However, this gets overwritten by
current vnic outbound settings. Then, virNetDevBandwidthSet doesn't
change anything. We need to stop overwriting the outbound if users
don't want us to. Same applies for inbound.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-18 14:45:09 +01:00
Martin Kletzander
676cb4f4e7 virsh: Add keepalive in new vshConnect function
Introducing keepalive similarly to Guannan around 2 years ago.  Since
we want to introduce keepalive for every connection, it makes sense to
wrap the connecting function into new virsh one that can deal
keepalive as well.

Function vshConnect() is now used for connecting and keepalive added
in that function (if possible) helps preventing long waits e.g. while
nework goes down during migration.

This patch also adds the options for keepalive tuning into virsh and
fails connecting only when keepalives are explicitly requested and
cannot be set (whether it is due to missing support in connected
driver or remote server).  If not explicitely requested, a debug
message is printed (hence the addition to virsh-optparse test).

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

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-18 08:27:29 +01:00
Laine Stump
64bb902451 virsh: eliminate hardcoded indentation in xml generated for commands
These are never seen externally, only passed into libvirt APIs, so in
practice this makes no real difference, but it's good to be
consistent.
2014-03-14 00:02:38 -06:00
Eric Blake
2ebf593a05 virsh: report exit status of failed lxc-enter-namespace
'virsh lxc-enter-namespace' does not have a way to reflect exit
status to the caller in single-command mode, but we might as well
at least report the exit status.  Prior to this patch,

$ virsh -c lxc:/// lxc-enter-namespace shell /bin/sh 'exit 3'; echo $?
1

now it gives some details:

$ virsh -c lxc:/// lxc-enter-namespace shell /bin/sh -c 'exit 3'; echo $?
error: internal error: Child process (31557) unexpected exit status 3
1

Also useful:

$ virsh -c lxc:/// lxc-enter-namespace shell /bin/sh -c 'kill $$'; echo $?
error: internal error: Child process (31585) unexpected fatal signal 15
1

* tools/virsh-domain.c (cmdLxcEnterNamespace): Avoid magic numbers.
Dispatch any error.
* tools/virsh.pod: Document that non-zero exit status is collapsed.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-03 12:40:32 -07:00
Eric Blake
25f87817ab virFork: simplify semantics
The old semantics of virFork() violates the priciple of good
usability: it requires the caller to check the pid argument
after use, *even when virFork returned -1*, in order to properly
abort a child process that failed setup done immediately after
fork() - that is, the caller must call _exit() in the child.
While uses in virfile.c did this correctly, uses in 'virsh
lxc-enter-namespace' and 'virt-login-shell' would happily return
from the calling function in both the child and the parent,
leading to very confusing results. [Thankfully, I found the
problem by inspection, and can't actually trigger the double
return on error without an LD_PRELOAD library.]

It is much better if the semantics of virFork are impossible
to abuse.  Looking at virFork(), the parent could only ever
return -1 with a non-negative pid if it misused pthread_sigmask,
but this never happens.  Up until this patch series, the child
could return -1 with non-negative pid if it fails to set up
signals correctly, but we recently fixed that to make the child
call _exit() at that point instead of forcing the caller to do
it.  Thus, the return value and contents of the pid argument are
now redundant (a -1 return now happens only for failure to fork,
a child 0 return only happens for a successful 0 pid, and a
parent 0 return only happens for a successful non-zero pid),
so we might as well return the pid directly rather than an
integer of whether it succeeded or failed; this is also good
from the interface design perspective as users are already
familiar with fork() semantics.

One last change in this patch: before returning the pid directly,
I found cases where using virProcessWait unconditionally on a
cleanup path of a virFork's -1 pid return would be nicer if there
were a way to avoid it overwriting an earlier message.  While
such paths are a bit harder to come by with my change to a direct
pid return, I decided to keep the virProcessWait change in this
patch.

* src/util/vircommand.h (virFork): Change signature.
* src/util/vircommand.c (virFork): Guarantee that child will only
return on success, to simplify callers.  Return pid rather than
status, now that the situations are always the same.
(virExec): Adjust caller, also avoid open-coding process death.
* src/util/virprocess.c (virProcessWait): Tweak semantics when pid
is -1.
(virProcessRunInMountNamespace): Adjust caller.
* src/util/virfile.c (virFileAccessibleAs, virFileOpenForked)
(virDirCreate): Likewise.
* tools/virt-login-shell.c (main): Likewise.
* tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise.
* tests/commandtest.c (test23): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-03 12:40:32 -07:00
Eric Blake
c72e76c3d9 util: make it easier to grab only regular process exit
Right now, a caller waiting for a child process either requires
the child to have status 0, or must use WIFEXITED() and friends
itself.  But in many cases, we want the middle ground of treating
fatal signals as an error, and directly accessing the normal exit
value without having to use WEXITSTATUS(), in order to easily
detect an expected non-zero exit status.  This adds the middle
ground to the low-level virProcessWait; the next patch will add
it to virCommand.

* src/util/virprocess.h (virProcessWait): Alter signature.
* src/util/virprocess.c (virProcessWait): Add parameter.
(virProcessRunInMountNamespace): Adjust caller.
* src/util/vircommand.c (virCommandWait): Likewise.
* src/util/virfile.c (virFileAccessibleAs): Likewise.
* src/lxc/lxc_container.c (lxcContainerHasReboot)
(lxcContainerAvailable): Likewise.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* tools/virt-login-shell.c (main): Likewise.
* tools/virsh-domain.c (cmdLxcEnterNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* tests/commandtest.c (test23): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-03 12:40:31 -07:00
Eric Blake
0e16ae404c virsh: add --all flag to 'event' command
Similar to our event-test demo program, it's nice to be able to
have a mode where we can sniff all events at once, rather than
having to spawn multiple virsh in parallel with one for each
event type.

(Can I just say our RegisterAny design is lousy?  The fact that
the majority of our callback pointers have a function signature
with the opaque data in a different position, and that we have
to cast the function signature before registering it, makes it
hard to write a generic callback function; we have to write one
for every type of event id.  Life would have been easier if we
had designed the callback as a fixed signature with a void*
and size parameter, and then allowed the caller to downcast
the void* to a particular struct for data specific to their
callback id, where we could have then had a single function
with a switch statement for each event id, and register that
one function for all types of events.  It would also be nicer
if the callback functions knew which callbackID was being used
when invoking that callback, so that I could use a common data
structure among all registrations instead of having to create
an array of one data per callback.  But I really don't want to
go add yet another event API design.)

* tools/virsh-domain.c (cmdEvent): Add --all parameter; convert
all callbacks to support shared counter.
* tools/virsh.pod (event): Document it.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-28 13:54:04 -07:00
Eric Blake
bb4a9a527d virsh: support remaining domain events
Earlier, I added 'virsh event' for lifecycle events, to get the
concept approved; this patch finishes the support for all other
events, although the user still has to register for one event
type at a time.  A future patch may add an --all parameter to
make it possible to register for all events through a single
call.

* tools/virsh-domain.c (vshDomainEventWatchdogToString)
(vshDomainEventIOErrorToString, vshGraphicsPhaseToString)
(vshGraphicsAddressToString, vshDomainBlockJobStatusToString)
(vshDomainEventDiskChangeToString)
(vshDomainEventTrayChangeToString, vshEventGenericPrint)
(vshEventRTCChangePrint, vshEventWatchdogPrint)
(vshEventIOErrorPrint, vshEventGraphicsPrint)
(vshEventIOErrorReasonPrint, vshEventBlockJobPrint)
(vshEventDiskChangePrint, vshEventTrayChangePrint)
(vshEventPMChangePrint, vshEventBalloonChangePrint)
(vshEventDeviceRemovedPrint): New helper routines.
(cmdEvent): Support full array of event callbacks.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-28 13:54:04 -07:00
Michal Privoznik
e53b06246c virsh: Honour -q in domblklist, vcpupin and emulatorpin
If user wants to grep some info from domain, e.g. disk paths:

    # virsh -q domblklist win7 | awk '{print $2}'
    Source

    /var/lib/libvirt/images/windows.qcow2
    /home/zippy/work/tmp/en_windows_7_professional_x64_dvd_X15-65805.iso

while with my change:

    # virsh -q domblklist win7 | awk '{print $2}'
    /var/lib/libvirt/images/windows.qcow2
    /home/zippy/work/tmp/en_windows_7_professional_x64_dvd_X15-65805.iso

We don't print table header in other commands, like list.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-02-26 14:10:43 +01:00
Chen Hanxiao
7a8d7af685 virsh: initialize str to NULL to solve a build issue
Fix a -Werror=maybe-uninitialized issue.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-02-25 08:30:51 +01:00
Eric Blake
466b12ab79 virsh: use more compact VIR_ENUM_IMPL
Dan Berrange suggested that using VIR_ENUM_IMPL is more compact
than open-coding switch statements, and still just as forceful
at making us remember to update lists if we add enum values
in the future.  Make this change throughout virsh.

Sure enough, doing this change caught that we missed at least
VIR_STORAGE_VOL_NETDIR.

* tools/virsh-domain-monitor.c (vshDomainIOErrorToString)
(vshDomainControlStateToString, vshDomainStateToString)
(vshDomainStateReasonToString): Change switch to enum lookup.
(cmdDomControl, cmdDominfo): Update caller.
* tools/virsh-domain.c (vshDomainVcpuStateToString)
(vshDomainEventToString, vshDomainEventDetailToString): Change
switch to enum lookup.
(vshDomainBlockJobToString, vshDomainJobToString): New functions.
(cmdVcpuinfo, cmdBlockJob, cmdDomjobinfo, cmdEvent): Update
callers.
* tools/virsh-network.c (vshNetworkEventToString): Change switch
to enum lookup.
* tools/virsh-pool.c (vshStoragePoolStateToString): New function.
(cmdPoolList, cmdPoolInfo): Update callers.
* tools/virsh-volume.c (vshVolumeTypeToString): Change switch to
enum lookup.
(cmdVolInfo, cmdVolList): Update callers.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-24 11:47:18 -07:00
Ján Tomko
fe1b6e72d2 virsh: Don't leak buffer if GetFDs fails in cmdCreate
Change the logic of the function to return false by default
and move the freeing of the buffer to the cleanup section.

https://bugzilla.redhat.com/show_bug.cgi?id=1067338
2014-02-24 18:46:34 +01:00
Eric Blake
99fa96c390 virsh: add event command, for lifecycle events
Add 'virsh event --list' and 'virsh event [dom] --event=name
[--loop] [--timeout]'.  Borrows somewhat from event-test.c,
but defaults to a one-shot notification, and takes advantage
of the event loop integration to allow Ctrl-C to interrupt the
wait for an event.  For now, this just does lifecycle events.

* tools/virsh.pod (event): Document new command.
* tools/virsh-domain.c (vshDomainEventToString)
(vshDomainEventDetailToString, vshDomEventData)
(vshEventLifecyclePrint, cmdEvent): New struct and functions.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-20 16:23:27 -07:00
Eric Blake
5093b047ea virsh: common code for parsing --seconds
Several virsh commands ask for a --timeout parameter in
seconds, then use it to control interfaces that operate on
millisecond limits; I also plan on adding a 'virsh event'
command that also does this.  Factor this into a common
function.

* tools/virsh.h (vshCommandOptTimeoutToMs): New prototype.
* tools/virsh.c (vshCommandOptTimeoutToMs): New function.
* tools/virsh-domain.c (cmdBlockCommit, cmdBlockCopy)
(cmdBlockPull, cmdMigrate): Use it.
(vshWatchJob): Adjust timeout scale.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-20 16:23:07 -07:00
Jincheng Miao
6c1059ef24 virsh: fix memleak when starting a guest with invalid fd
When start a guest with --pass-fd, if the argument of --pass-fd is invalid,
virsh will exit, but doesn't free the variable 'dom'.

The valgrind said:
...
==24569== 63 (56 direct, 7 indirect) bytes in 1 blocks are definitely lost in loss record 130 of 234
==24569==    at 0x4C2A1D4: calloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
==24569==    by 0x4E879A4: virAllocVar (viralloc.c:544)
==24569==    by 0x4EBD625: virObjectNew (virobject.c:190)
==24569==    by 0x4F3A18A: virGetDomain (datatypes.c:226)
==24569==    by 0x4F9311F: remoteDomainLookupByName (remote_driver.c:6636)
==24569==    by 0x4F44F20: virDomainLookupByName (libvirt.c:2277)
==24569==    by 0x12F616: vshCommandOptDomainBy (virsh-domain.c:105)
==24569==    by 0x131C79: cmdStart (virsh-domain.c:3330)
==24569==    by 0x12C4AB: vshCommandRun (virsh.c:1752)
==24569==    by 0x127001: main (virsh.c:3218)

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

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-20 05:40:13 -07:00
Thorsten Behrens
721949059b maint: align whitespaces with project conventions. 2014-01-20 14:35:08 +01:00
Gao feng
8bbf1133ce virsh: add setting throttle blkio cgroup option to blkiotune
With this patch, user can setup the throttle blkio cgorup
for domain through the virsh cmd, such as:

virsh blkiotune domain1 --device-read-bytes-sec /dev/sda1,1000000,/dev/sda2,2000000
--device-write-bytes-sec /dev/sda1,1000000 --device-read-iops-sec /dev/sda1,10000
--device-write-iops-sec /dev/sda1,10000,/dev/sda2,0

This patch also add manpage for these new options.

Signed-off-by: Guan Qiang <hzguanqiang@corp.netease.com>
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
2014-01-20 10:52:47 +08:00
Peter Krempa
f9d06ebcef virsh: Use inactive definition when removing disk from config
https://bugzilla.redhat.com/show_bug.cgi?id=1049529

The 'detach-disk' command in virsh used the active XML definition of a
domain even when attempting to remove a disk from the config only. If
the disk was only in the inactive definition the operation failed. Fix
this by using the inactive XML in case that only the config is affected.
2014-01-08 09:47:44 +01:00
Peter Krempa
0bb64df1fc virsh: Don't use legacy API if --current is used on device hot(un)plug
https://bugzilla.redhat.com/show_bug.cgi?id=1049529

The legacy virDomainAttachDevice and virDomainDetachDevice operate only
on active domains. When a user specified --current flag with an inactive
domain the old API was used and reported an error. Fix it by calling the
new API if --current is specified explicitly.
2014-01-08 09:47:44 +01:00
Michal Privoznik
72ffbd1bf3 virkeycode: Allow ANSI_A
https://bugzilla.redhat.com/show_bug.cgi?id=1044806

Currently, sending the ANSI_A keycode from os_x codepage doesn't work as
it has a special value of 0x0. Our internal code handles that no
different to other not defined keycodes. Hence, in order to allow it we
must change all the undefined keycodes from 0 to -1 and adapt some code
too.

  # virsh send-key guestname --codeset os_x ANSI_A
  error: invalid keycode: 'ANSI_A'

  # virsh send-key guestname --codeset os_x ANSI_B
  # virsh send-key guestname --codeset os_x ANSI_C

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-12-24 17:36:47 +01:00
Peter Krempa
ef56cc43d1 virsh: domain: Fix undefine with storage of 'volume' disks
The undefine code that removes the storage along with the VM didn't take
into account the existence of 'volume' type disks. Add the functionality.
2013-12-18 16:43:07 +01:00
Eric Blake
aaa7484097 virsh: improve grammar in error message
Based on a suggestion from Mauricio Tavares.

* tools/virsh-domain.c (cmdDetachInterface, vshFindDisk): Improve
wording.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-12-02 14:40:15 -07:00
Eric Blake
57682aea36 maint: fix comma style issues: tests, tools
Most of our code base uses space after comma but not before;
fix the remaining uses before adding a syntax check.

* tests/sysinfotest.c: Consistently use commas.
* tests/viratomictest.c: Likewise.
* tests/vircgroupmock.c: Likewise.
* tools/virsh-domain.c: Likewise.
* tools/virsh-volume.c: Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-11-20 09:14:55 -07:00
Peter Krempa
bf45db6041 virsh-domain: Mark --live and --config mutually exclusive in vcpucount
The 'vcpucount' command is a getter command for the vCPUu count. When
one or more of the filtering flags are specified the command returns the
value only for the selected combination. In this case the --live and
--config combination isn't valid. This however didn't cause errors as
the combination of flags was rejected by the libvirt API but then the
fallback code kicked in and requested the count in a way where the clash
of the flags didn't matter.

Mark the flag combination mutually exclusive so that users aren't
confused.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1024245
2013-11-11 10:52:03 +01:00
Eric Blake
f919cf6917 virsh: undocument --shareable (--mode already covers it)
Commit e962a57 added 'attach-disk --shareable', even though we
already had 'attach-disk --mode=shareable'.  Worse, if the user
types 'attach-disk --mode=readonly --shareable', we create
non-sensical XML.  The best solution is just to undocument the
duplicate spelling, by having it fall back to the preferred
spelling.

* tools/virsh-domain.c (cmdAttachDisk): Let alias handling fix our
mistake in exposing a second spelling for an existing option.
* tools/virsh.pod: Fix documentation.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-24 11:17:42 +01:00
Peter Krempa
47e6396651 virsh: Fix job watching when STDIN is not a tty
In commit b46c4787dd I changed the code to
watch long running jobs in virsh. Unfortunately I didn't take into
account that poll may get a hangup if the terminal is not a TTY and will
be closed.

This patch avoids polling the STDIN fd when there's no TTY.
2013-10-22 15:01:26 +01:00
Chen Hanxiao
21f2d80b0c virsh: improve usability of '--print-xml' flag for attach-disk command
'--print-xml' option is very useful for doing some test.
But we had to specify a real domain for it.
This patch could enable us to specify a fake domain
when using --print-xml option.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-10-17 15:43:57 -06:00
Chen Hanxiao
55da09933f virsh: fix a typo in virsh-domain
s/it's/its

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
2013-10-17 09:08:25 +02:00
Michal Privoznik
72aafe9c81 Migration: Introduce VIR_MIGRATE_PARAM_LISTEN_ADDRESS
The parameter allows overriding default listen address for '-incoming'
cmd line argument on destination.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2013-10-11 10:51:36 +02:00
Ján Tomko
bc3070c719 Fix handling of IPv6 listen addresses in cmdDomDisplay
Use virSocketAddrIsWildcard instead of STREQ to check for the ANY
address and put brackets around the address if it contains ':'.
2013-10-01 14:45:20 +02:00
Hongwei Bi
7db19ff9ab virsh-domain: Free dom before return false in cmdDump 2013-09-30 14:54:30 +02:00
Christophe Fergeau
9976c4b9a6 virsh: Fix domdisplay when domain only uses TLS
It's possible to create a domain which will only use a TLS port
and will not have a non-TLS port set by using:
<graphics type='spice' autoport='yes' defaultMode='secure'/>
In such a setup, the 'graphics' node for the running domain will be:
<graphics type='spice' tlsPort='5900'
          autoport='yes' listen='127.0.0.1'
          defaultMode='secure'>

However, cmdDomDisplay loops over all the 'graphics' node, and it
ignores nodes which don't have a 'port' attribute. This means
'virsh domdisplay' will only return an empty string for domains
as the one above.

This commit looks for both 'port' and 'tlsPort' before deciding
to ignore a graphics node. It also makes sure 'port' is not printed
when it's not set.
This makes 'virsh domdisplay' return
'spice://127.0.0.1?tls-port=5900' for domains using only a TLS
port.

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
2013-09-27 17:40:11 +02:00
Hongwei Bi
b80fff1444 virsh-domain: Add a missing check and fix leak in cmdScreenshot
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-25 09:34:24 -06:00
Simone Gotti
fe64499dd1 virsh: add missing "async" option in opts_block_commit
After commit 8aecd35126 it'll detect
that a required option is not defined and it will assert and exit with:

virsh.c:1364: vshCommandOpt: Assertion `valid->name' failed.

Problem has been latent since commit ed23b106.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-09-19 12:14:03 -06:00
Peter Krempa
6bf4c77984 virsh: Don't shadow global variable "remove" in cmdMetadata
Some systems apparently have a global variable/function called remove
and thus break compilation of virsh-domain.c. Rename the variable to
avoid this.

Reported by GuanQiang.
2013-09-17 13:57:32 +02:00
Peter Krempa
01b03f59e7 virsh-domain: Add command to allow modifications of XML metadata
The metadata modification functions will support modification of the XML
metadata. Add a virsh command to allow using this approach.
2013-09-17 09:42:49 +02:00
Peter Krempa
3df33d7ad5 virsh-domain: use virXMLNodeToString instead of xmlNodeDump 2013-09-17 09:42:49 +02:00
Peter Krempa
cb356928a6 virsh-domain: Line up signal names array
Line up the array so that the grid is visible.
2013-09-17 09:42:49 +02:00
Peter Krempa
626d4dfc2e virsh-domain: Remove spurious ATTRIBUTE_UNUSED from cmdDesc
The "cmd" variable is actually used so remove the attribute.
2013-09-17 09:42:49 +02:00
yangdongsheng
6c038ee330 virsh: move command maxvcpus from domain group to host group.
Since the maxvcpus command query the maximum number of virtual
CPUs supported for a guest VM on this connection, it should be
in virsh-host.c but not virsh-domain.c.

Signed-off-by: yangdongsheng <yangds.fnst@cn.fujitsu.com>
2013-09-15 22:39:41 -05:00
Jiri Denemark
f084caae7c virsh domjobinfo: Do not return 1 if job is NONE
https://bugzilla.redhat.com/show_bug.cgi?id=1006864

Commit 38ab1225 changed the default value of ret from true to false but
forgot to set ret = true when job is NONE. Thus, virsh domjobinfo
returned 1 when there was no job running for a domain but it used to
(and should) return 0 in this case.
2013-09-12 11:31:49 +02:00
Daniel P. Berrange
bbcdd9b5dc Stop free'ing 'const char *' strings
The VIR_FREE() macro will cast away any const-ness. This masked a
number of places where we passed a 'const char *' string to
VIR_FREE. Fortunately in all of these cases, the variable was not
in fact const data, but a heap allocated string. Fix all the
variable declarations to reflect this.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-09-05 11:28:01 +01:00
Peter Krempa
02eaf1821c virsh: Rename vshMakeStdinRaw to vshTTYMakeRaw and move it to virsh.c
Move the function to virsh.c to the rest of the TTY managing functions
and change the code so that it mirrors the rest.
2013-09-03 14:06:11 +02:00
Peter Krempa
40f1d18fea tools: rename console.[ch] to virsh-console.[ch] and fix coding style 2013-09-03 14:06:11 +02:00
Peter Krempa
b46c4787dd virsh-domain: Avoid killing ssh transport tunnels when cancelling job
The vshWatchJob function registers a SIGINT handler that is used to
abort the active job and does not terminate virsh. Unfortunately, this
breaks when using the ssh transport as SIGINT is sent to the foreground
process group including the ssh transport processes which terminate.
This breaks the connection and migration is left in a insane state.

With this patch the terminal is modified to ignore key binding that
sends SIGINT and does the handling manually.

Resoves: https://bugzilla.redhat.com/show_bug.cgi?id=983348
2013-09-03 09:55:27 +02:00
Hongwei Bi
461b1c8b7b Fix memory leak in cmdAttachDisk
When virBufferError is ok in cmdAttachDisk, the latter
should 'goto cleanup', instead of returning a false to
prevent memory leaking.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-08-31 15:50:23 -06:00
Peter Krempa
8c725cc10d virsh-domain: rename print_job_progress to vshPrintJobProgress 2013-08-30 09:38:51 +02:00
Guannan Ren
9eb444364e virsh: fix return value error of cpu-stats
virsh cpu-stats guest --start 0 --count 3
It outputs right but the return value is 1 rather than 0
echo $?
1

Found by running libvirt-autotest
./run -t libvirt --tests virsh_cpu_stats
2013-08-27 15:17:03 +08:00
Tomas Meszaros
a88924bc21 virsh: C99 style for info_domfstrim and opts_lxc_enter_namespace
Change info_domfstrim and opts_lxc_enter_namespace initialization style
to C99.
2013-08-26 10:23:16 -06:00
Peter Krempa
04898f60d2 virsh: Don't leak list of volumes when undefining domain with storage
Use the new semantics of vshStringToArray to avoid leaking the array of
volumes to be deleted. The array would be leaked in case the first
volume was found in the domain definition. Also refactor the code a bit
to sanitize naming of variables hoding arrays and dimensions of the
arrays.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050
2013-08-20 17:55:08 +02:00
Don Dugger
d4952d36d0 Add flag to BaselineCPU API to return detailed CPU features
Currently the virConnectBaselineCPU API does not expose the CPU features
that are part of the CPU's model.  This patch adds a new flag,
VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES, that causes the API to explicitly
list all features that are part of that model.

Signed-off-by: Don Dugger <donald.d.dugger@intel.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2013-08-16 15:31:18 -06:00
Peter Krempa
f4ec861641 virsh-domain: Fix memleak in cmdCPUBaseline
https://bugzilla.redhat.com/show_bug.cgi?id=997765

==1349431== 8 bytes in 1 blocks are definitely lost in loss record 11 of 760
==1349431==    at 0x4C2A554: calloc (vg_replace_malloc.c:593)
==1349431==    by 0x4E9AA3E: virAllocN (in /usr/lib64/libvirt.so.0.1001.1)
==1349431==    by 0x4EF28C4: virXPathNodeSet (in /usr/lib64/libvirt.so.0.1001.1)
==1349431==    by 0x130B83: cmdCPUBaseline (in /usr/bin/virsh)
==1349431==    by 0x12C608: vshCommandRun (in /usr/bin/virsh)
==1349431==    by 0x12889A: main (in /usr/bin/virsh)
2013-08-16 10:37:39 +02:00
Peter Krempa
5075248ac9 virsh-domain: Fix memleak in cmdUndefine with storage
When undefining a domain with storage when the volume isn't managed by
libvirt the name and path strings weren't freed properly.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=996050
2013-08-15 16:47:49 +02:00
Peter Krempa
3abb6ec077 virsh-domain: Flip logic in cmdSetvcpus
To avoid having to assign a failure code to the returned variable switch
this function to negative logic. This will fix issue with invalid number
of cpus returning success return code.

https://bugzilla.redhat.com/show_bug.cgi?id=996466
2013-08-13 11:14:56 +02:00
Eric Blake
4c29772845 virsh: nicer abort of blockcopy
I attempted 'virsh blockcopy $dom vda $path --wait --verbose', then
hit Ctrl-C; I was a bit surprised to see this error message:

Block Copy: [  3 %]error: failed to query job for disk vda

when I had been expecting:

Block Copy: [  3 %]
Copy aborted

* tools/virsh-domain.c (cmdBlockCopy): Print graceful exit message
rather than error when ctrl-c interrupts job.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-08-12 11:04:11 -06:00
Guannan Ren
7729a16814 virsh: fix change-media bug on disk block type
Resolves:https://bugzilla.redhat.com/show_bug.cgi?id=923053
When cdrom is block type, the virsh change-media failed to insert
source info because virsh uses "<source block='/dev/sdb'/>" while
the correct name of the attribute for block disks is "dev".
2013-07-23 14:20:56 +08:00
Daniel P. Berrange
afb50d79db Enable FD passing when starting guests with virsh
Add a "--pass-fds N,M,..." arg to the virsh start/create
methods. This allows pre-opened file descriptors from the
shell to be passed on into the guest

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-18 12:07:53 +01:00
Daniel P. Berrange
111f6f4d73 Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-10 17:40:13 +01:00
Michal Privoznik
76fad65bdc Adapt to VIR_ALLOC and virAsprintf in tools/* 2013-07-10 11:07:33 +02:00
Jiri Denemark
4669543cb8 Introduce VIR_MIGRATE_PARAM_GRAPHICS_URI parameter
The parameter specifies connection parameters to use for migrating
client's connection to domain's graphical console.
2013-06-25 01:33:47 +02:00
Jiri Denemark
bdb6578a42 virsh: Use extensible migration APIs 2013-06-25 01:31:07 +02:00
Peter Krempa
cf6d56ac43 migration: Make erroring out on I/O error controllable by flag
Paolo Bonzini pointed out that it's actually possible to migrate a qemu
instance that was paused due to I/O error and it will be able to work on
the destination if the storage is accessible.

This patch introduces flag VIR_MIGRATE_ABORT_ON_ERROR that cancels the
migration in case an I/O error happens while it's being performed and
allows migration without this flag. This flag can be possibly used for
other error reasons that may be introduced in the future.
2013-06-18 14:52:26 +02:00
Peter Krempa
c2093b2aba Fix commit 29c1e913e4
This patch fixes changes done in commit 29c1e913e4
that was pushed without implementing review feedback.

The flag introduced by the patch is changed to VIR_DOMAIN_VCPU_GUEST and
documentation makes the difference between regular hotplug and this new
functionality more explicit.

The virsh options that enable the use of the new flag are changed to
"--guest" and the documentation is fixed too.
2013-06-10 09:52:49 +02:00
Peter Krempa
29c1e913e4 API: Introduce VIR_DOMAIN_VCPU_AGENT, for agent based CPU hot(un)plug
This flag will allow to use qemu guest agent commands to disable
(offline) and enable (online) processors in a live guest that has the
guest agent running.
2013-06-07 15:58:25 +02:00
Osier Yang
232240d095 virsh: Allow attach-disk to specify disk wwn
Commit 6e73850b01 support to set wwn for disks, but it was not
exposed to attach-disk.
2013-06-04 19:56:07 +08:00
Peter Krempa
08f1c0a9ae virsh-domain: Report errors and don't deref NULL in qemu-agent-command
Check the returned value for NULL and take the cleanup path
appropriately if the API fails.
2013-06-03 17:25:26 +02:00
Peter Krempa
33e300229c virsh-domain: Add --live, --config, --current logic to cmdAttachInterface
Use the approach established in commit
69ce3ffa8d to improve this function too.
2013-06-03 14:23:02 +02:00
Peter Krempa
37772499e0 virsh-domain: Add --live, --config, --current logic to cmdAttachDisk
Use the approach established in commit
69ce3ffa8d to improve this function too.
2013-06-03 14:23:02 +02:00
Peter Krempa
f81c95b31f virsh-domain: Add --live, --config, --current logic to cmdAttachDevice
Use the approach established in commit
69ce3ffa8d to improve this function too.
2013-06-03 14:23:01 +02:00
Cole Robinson
5e1de4fcdd virsh: migrate: Don't disallow --p2p and --migrateuri
Because it's a valid combination. p2p still uses a separate channel
for qemu migration, so there's value in letting the user specify a manual
migrate URI for overriding auto-port, or libvirt's FQDN lookup.

What _isn't_ allowed is --migrateuri and TUNNELLED, since there is
no separate migration channel. Disallow that instead
2013-05-29 12:31:00 -04:00
Eric Blake
146ba114a5 syntax: prefer space after semicolon in for loop
I noticed several unusual spacings in for loops, and decided to
fix them up.  See the next commit for the syntax check that found
all of these.

* examples/domsuspend/suspend.c (main): Fix spacing.
* python/libvirt-override.c: Likewise.
* src/conf/interface_conf.c: Likewise.
* src/security/virt-aa-helper.c: Likewise.
* src/util/virconf.c: Likewise.
* src/util/virhook.c: Likewise.
* src/util/virlog.c: Likewise.
* src/util/virsocketaddr.c: Likewise.
* src/util/virsysinfo.c: Likewise.
* src/util/viruuid.c: Likewise.
* src/vbox/vbox_tmpl.c: Likewise.
* src/xen/xen_hypervisor.c: Likewise.
* tools/virsh-domain-monitor.c (vshDomainStateToString): Drop
default case, to let compiler check us.
* tools/virsh-domain.c (vshDomainVcpuStateToString): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2013-05-28 07:56:07 -06:00
Martin Kletzander
0a24028f11 virsh: Fix virDomainFree for NULL domain in blkdeviotune 2013-05-23 13:02:19 +02:00
Osier Yang
c96f6ae845 tools: Remove the whitespace before ";" 2013-05-21 23:41:45 +08:00
Osier Yang
b77737372d virsh: Pretty the output of qemu-agent-command
This adds a new option "--pretty" for qemu-agent-command, to
pretty-format the returned JSON string.
2013-05-15 01:02:25 +08:00
Osier Yang
8b9eb14a6d virsh: Use vshPrint instead of printf 2013-05-15 01:02:18 +08:00
Ján Tomko
dcea5a492f get rid of virBufferAsprintf where possible
Use virBufferAddLit or virBufferAddChar instead.
2013-05-07 17:38:58 +02:00
Michal Privoznik
7c9a2d88cd virutil: Move string related functions to virstring.c
The source code base needs to be adapted as well. Some files
include virutil.h just for the string related functions (here,
the include is substituted to match the new file), some include
virutil.h without any need (here, the include is removed), and
some require both.
2013-05-02 16:56:55 +02:00
Peter Krempa
642261a866 virsh-domain: Refactor cmdVcpucount and fix output on inactive domains
This patch factors out the vCPU count retrieval including fallback means
into vshCPUCountCollect() and removes the duplicated code to retrieve
individual counts.

The --current flag (this flag is assumed by default) now works also with
--maximum or --active without the need to explicitly specify the state
of the domain that is requested.

This patch also fixes the output of "virsh vcpucount domain" on inactive
domains:

Before:
$ virsh vcpucount domain
maximum      config         4
error: Requested operation is not valid: domain is not running
current      config         4
error: Requested operation is not valid: domain is not running

After:
$virsh vcpucount domain
maximum      config         4
current      config         4

.. and for transient domains too:

Before:
$ virsh vcpucount transient-domain
error: Requested operation is not valid: cannot change persistent config of a transient domain
maximum      live           3
error: Requested operation is not valid: cannot change persistent config of a transient domain
current      live           1

After:
$ virsh vcpucount transient-domain
maximum      live           3
current      live           1
2013-04-19 14:02:10 +02:00
Peter Krempa
f78266dfc2 virsh-domain: Report errors on invalid --holdtime value for cmdSendKey
Using of a incorrect value for the --holdtime option was silently
ignored and 0 was used. In case a negative number was used, it
overflowed as the API expects a unsigned int.

Fix the data type and getter function type and report errors on
incorrect values.
2013-04-18 15:23:09 +02:00
Peter Krempa
35d0f3b14a virsh-domain: Clean up cmdSendKey
Rename the get_integer_keycode helper to vshKeyCodeGetInt and get rid of
a unneeded typecast.
2013-04-18 15:23:09 +02:00
John Ferlan
6528b7044f Add error handling to optional arguments in cmdCPUStats 2013-04-11 18:53:35 -04:00
John Ferlan
ad86ebb286 Remove extraneous comma in info_cpu_stats and opts_cpu_stats 2013-04-11 18:40:59 -04:00
Michal Privoznik
0aa8397c62 virsh: Update list of shutdown/reboot modes
As of 76d9f65644 we are supporting two new modes: initctl and signal.
However, these are missing in help listing.
2013-04-11 13:03:55 +02:00
Martin Kletzander
e7cd2844ca Allow multiple parameters for schedinfo
virsh schedinfo was able to set only one parameter at a time (not
counting the deprecated options), but it is useful to set more at
once, so this patch adds the possibility to do stuff like this:

virsh schedinfo <domain> cpu_shares=0 vcpu_period=0 vcpu_quota=0 \
emulator_period=0 emulator_quota=0

Invalid scheduler options are reported as well.  These were previously
reported only if the command hadn't updated any values (when
cmdSchedInfoUpdate returned 0).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919372
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919375
2013-04-03 08:49:30 +02:00
Michal Privoznik
deb86ee912 virsh: Call virDomainFree in cmdDomFSTrim
https://bugzilla.redhat.com/show_bug.cgi?id=928197

The virsh domfstrim command was not freeing allocated domain,
leaving leaked references behind.
2013-04-02 17:36:06 +02:00
Peter Krempa
b685a73ed9 virsh-domain: Add --live, --config, --current logic to cmdDetachDisk
Use the established approach to improve this function too.
2013-04-02 16:18:38 +02:00
Peter Krempa
d87f721073 virsh-domain: Add --live, --config, --current logic to cmdDetachDevice
Use the established approach to improve this function too.
2013-04-02 16:18:32 +02:00
Peter Krempa
c3d9f399b5 virsh-domain: Add --live, --config, --current logic to cmdDetachInterface
Use the established approach to improve this function too.
2013-04-02 16:18:05 +02:00
Peter Krempa
69ce3ffa8d virsh: Fix semantics of --config for "update-device" command
The man page states that with --config the next boot is affected. This
can be understood as if _only_ the next boot was affected. This isn't
true if the machine is running.

This patch adds the full --live, --config, --current infrastructure and
tweaks stuff to correctly support the obsolete --persistent flag.

Note that this patch changes the the behavior of the --config flag to match the
use of this flag in rest of libvirt. This flag was mistakenly renamed from
--persistent that originaly had different semantics.
2013-04-02 16:14:14 +02:00
Peter Krempa
cc0cc6b714 virsh-domain: Fix declarations of flag variables in cmdChangeMedia
The parameter options can be declared directly.

Also use macros for mutual exclusion on some of the incompatible
parameter variables.
2013-04-02 16:02:43 +02:00
Peter Krempa
803e467080 virsh-domain: Simplify usage of --current, --live and --config flags
This patch uses the new helper to avoid the more complex check for
domain state modification flags.
2013-04-02 16:02:43 +02:00
Osier Yang
8893df388e virsh: Add a helper to parse cpulist
The 'virsh vcpupin' and 'virsh emulatorpin' commands use the same
code to parse the cpulist. This patch abstracts the same code as
a helper. Along with various code style fixes, and error improvement
(only error "Physical CPU %d doesn't exist" if the specified CPU
exceed the range, no "cpulist: Invalid format", see the following
for an example of the error prior to this patch).

% virsh vcpupin 4 0 0-8
error: Physical CPU 4 doesn't exist.
error: cpulist: Invalid format.
2013-04-02 12:37:24 +08:00
Yanbing Du
4faf435cbd virsh: Correct DESCRIPTION for virsh help blockcopy
Signed-off-by: Yanbing Du <ydu@redhat.com>
2013-03-26 20:23:30 +01:00
Ján Tomko
41db895f9e virsh: error out on non-numeric timeout values
Some block commands and migrate ignored incorrect values.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=927495
2013-03-26 17:28:36 +01:00
Yanbing Du
5c925a4d82 Remove the redundant parentheses in migrate help
Signed-off-by: Yanbing Du <ydu@redhat.com>
2013-03-26 11:32:36 +08:00
Peter Krempa
020e210387 virsh-domain: Fix flag name in error message to match the check
The check is done on the "--paused" flag but the error message stated
"--saved"
2013-03-21 12:32:03 +01:00
Martin Kletzander
73cc87d161 Cleanup useless flags specifications
After we switched to C99 initialization, I noticed there were many
places where the specification of .flags parameter differed.  After
going through many options and deciding whether to unify the
initialization to be '.flags = 0' or '.flags = VSH_OFLAG_NONE', I
realized both can be removed and it makes the code easier to go
through.
2013-03-15 15:05:45 +01:00
Yanbing Du
8bf8a89ac1 Fix a copy & paste error for virsh dump help
Signed-off-by: Yanbing Du <ydu@redhat.com>
2013-03-15 16:22:49 +08:00
Daniel P. Berrange
e4e69e899e Apply security label when entering LXC namespaces
Add a new virDomainLxcEnterSecurityLabel() function as a
counterpart to virDomainLxcEnterNamespaces(), which can
change the current calling process to have a new security
context. This call runs client side, not in libvirtd
so we can't use the security driver infrastructure.

When entering a namespace, the process spawned from virsh
will default to running with the security label of virsh.
The actual desired behaviour is to run with the security
label of the container most of the time. So this changes
virsh lxc-enter-namespace command to invoke the
virDomainLxcEnterSecurityLabel method.

The current behaviour is:

LABEL                             PID TTY          TIME CMD
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 29 ? 00:00:00 dhclient
staff_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 47 ? 00:00:00 ps

Note the ps command is running as unconfined_t,  After this patch,

The new behaviour is this:

virsh -c lxc:/// lxc-enter-namespace dan -- /bin/ps -eZ
LABEL                             PID TTY          TIME CMD
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 1 pts/0 00:00:00 systemd
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 3 pts/1 00:00:00 sh
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 24 ? 00:00:00 systemd-journal
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 32 ? 00:00:00 dhclient
system_u:system_r:svirt_lxc_net_t:s0:c0.c1023 38 ? 00:00:00 ps

The '--noseclabel' flag can be used to skip security labelling.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-03-13 15:16:37 +00:00
Peter Krempa
38cc07b7bc virsh-domain: Remove unused vshCompleteXMLFromDomain
The function is marked as unused and breaks compilation on RHEL4. Remove
it from the tree until a new use case can be found.
2013-03-10 10:18:23 +01:00
Peter Krempa
406dc47757 Revert "Ensure xmlSaveToBuffer is always defined"
The commit originally fixed code that isn't being used. Revert
it and remove the unused code as a real fix.

This reverts commit a66b32d929.
2013-03-10 10:18:23 +01:00
Daniel P. Berrange
a66b32d929 Ensure xmlSaveToBuffer is always defined
RHEL4 vintage libxml2 header files are missing xmlSaveToBuffer
despite the symbol existing in the binary

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-03-07 18:10:35 +00:00
Jiri Denemark
e94aeb1428 virsh: Add migrate-compcache command
This is a command wrapping virDomainMigrateGetCompressionCache and
virDomainMigrateSetCompressionCache.
2013-02-22 17:35:59 +01:00
Jiri Denemark
38ab12251e virsh: Use virDomainGetJobStats in domjobinfo if available 2013-02-22 17:35:58 +01:00
Jiri Denemark
ecfff1dab3 Introduce VIR_MIGRATE_COMPRESSED flag
This flag may be used with migration APIs to request compression of
migration data.
2013-02-22 17:35:58 +01:00
Michal Privoznik
38d52f6318 virsh-domain.c: Switch to c99 initialization of vshCmdInfo 2013-02-12 17:50:21 +01:00
Michal Privoznik
df5fd11f86 virsh: Switch to c99 initialization of vshCmdDef 2013-02-12 17:50:21 +01:00
Peter Krempa
fa956d9055 virsh-domain: Update domain commands to use vshCommandOptStringReq 2013-02-04 14:17:44 +01:00
John Ferlan
46b1d8cf7a Enforce return check on virAsprintf() calls
Way back when I started making changes for Coverity messages my first set
were to a bunch of CHECKED_RETURN errors.  In particular virAsprintf() had
a few callers that Coverity noted didn't check their return (although some
did check if the buffer being printed to was NULL or not).

It was suggested at the time as a further patch an ATTRIBUTE_RETURN_CHECK
should be added to virAsprintf(), see:

https://www.redhat.com/archives/libvir-list/2013-January/msg00120.html

This patch does that and fixes a few more instances not found by Coverity
that failed the check.
2013-01-30 14:42:22 -07:00
Peter Krempa
f8d5119e4f virsh: Add --print-xml flag for attach-disk command
The flag causes the XML of the disk that would be attached to be printed
instead.
2013-01-25 20:53:37 +01:00
Peter Krempa
a54f25a946 virsh-domain: Refactor error paths for cmdCPUStats
This patch fixes the following issues in the cpu-stats virsh command:

1) Renames label failed_params to no_memory to match coding style
2) Uses proper typed parameter cleanup in error paths to avoid leaks
3) Adds a ret variable and simplifies error labels
4) Changes error message to a slightly more descriptive one and gets rid
   of the newline at the end:

Before:
$ virsh cpu-stats tr
error: Failed to virDomainGetCPUStats()

error: Requested operation is not valid: domain is not running

After:
$ tools/virsh cpu-stats tr
error: Failed to retrieve CPU statistics for domain 'tr'
error: Requested operation is not valid: domain is not running
2013-01-22 17:36:45 +01:00
Jiri Denemark
de78bf604c Introduce virTypedParamsClear public API
The function is just a renamed public version of former
virTypedParameterArrayClear.
2013-01-18 15:04:00 +01:00
Jiri Denemark
f52e9f1f4d virsh: Use virTypedParams* APIs in cpu-stats 2013-01-18 15:04:00 +01:00
Jiri Denemark
ec3e50644e virsh: Use virTypedParams* APIs in numatune 2013-01-18 15:04:00 +01:00
Jiri Denemark
7786233009 virsh: Use virTypedParams* APIs in memtune 2013-01-18 15:03:59 +01:00
Jiri Denemark
e982dacb45 virsh: Use virTypedParams* APIs in schedinfo 2013-01-18 15:03:59 +01:00
Jiri Denemark
9b2d2446af virsh: Use virTypedParams* APIs in domiftune 2013-01-18 15:03:59 +01:00
Jiri Denemark
39e5173a3d virsh: Use virTypedParams* APIs in blkiotune 2013-01-18 15:03:59 +01:00
Jiri Denemark
a8fca0da06 virsh: Use virTypedParams* APIs in blkdeviotune 2013-01-18 15:03:59 +01:00
Michal Privoznik
99419bd11e virsh-domain.c: Switch to C99 initialization of vshCmdOptDef 2013-01-17 13:58:52 +01:00
Daniel P. Berrange
e397f658b0 Add 'lxc-enter-namespace' command to virsh
Add a 'lxc-enter-namespace' command which accepts a domain name
and then a command + args to run, attached to the container

eg

  virsh -c lxc:/// lxc-enter-namespace demo -- /bin/ps -auxf

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-15 19:09:47 +00:00
Daniel P. Berrange
24bcd8d45a Move qemu-XXX commands from virsh-host.c to virsh-domain.c
The QEMU specific APIs all operate on domains, not the host,
so should be in the virsh-domain.c file / group

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-01-08 08:56:49 +00:00
Daniel P. Berrange
f24404a324 Rename virterror.c virterror_internal.h to virerror.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
556cf5f617 Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
44f6ae27fe Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
Daniel P. Berrange
ab9b7ec2f6 Rename memory.{c,h} to viralloc.{c,h} 2012-12-21 11:17:14 +00:00
Daniel P. Berrange
2005f7b552 Rename buf.{c,h} to virbuffer.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
Daniel P. Berrange
a27e4fbb72 Rename bitmap.{c,h} to virbitmap.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
liguang
8b9bf7879b Add support for offline migration
Offline migration transfers inactive definition of a domain (which may
or may not be active). After successful completion, the domain remains
in its current state on source host and is defined but inactive on
destination host. It's a bit more clever than virDomainGetXMLDesc() on
source host followed by virDomainDefineXML() on destination host, as
offline migration will run pre-migration hook to update the domain XML
on destination host. Currently, copying non-shared storage is not
supported during offline migration.

Offline migration can be requested with a new migration flag called
VIR_MIGRATE_OFFLINE (which has to be combined with
VIR_MIGRATE_PERSIST_DEST flag).
2012-12-10 21:52:15 +01:00
Peter Krempa
989a427de8 virsh: Fix usage of header termios.h
The termios struct exported by the termios.h header is used as an
argument for vshMakeStdinRaw(). The header isn't used anywhere in
tools/virsh-domain.c.

This patch adds the header to the header declaring vshMakeStdinRaw() and
removes other places in virsh.
2012-12-07 14:21:25 +01:00
Peter Krempa
bf72095954 virsh: Report errors if arguments of the schedinfo command are incorrect
Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

In case of schedinfo virDomainFree() in the cleanup section resets the
error when virTypedParameterAssignFromStr() fails.

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.
2012-12-03 16:37:10 +01:00
Peter Krempa
8312435707 maint: Misc whitespace cleanups 2012-12-03 15:13:32 +01:00
Eric Blake
7243752694 virsh: don't crash if shutdown --mode not provided
virStringSplit requires a non-NULL input, but commit cef78ed forgot
to follow the rule.

* tools/virsh-domain.c (cmdReboot, cmdShutdown): Avoid NULL deref.
2012-11-30 14:56:30 -07:00
Daniel P. Berrange
cef78ed84a Allow comma separated list of shutdown/reboot modes with virsh
The shutdown and reboot commands in virsh allow a comma
separated list of mode values

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-30 20:05:43 +00:00
Daniel P. Berrange
76d9f65644 Introduce two new methods for triggering controlled shutdown/reboot
The virDomainShutdownFlags and virDomainReboot APIs allow the caller
to request the operation is implemented via either acpi button press
or a guest agent. For containers, a couple of other methods make
sense, a message to /dev/initctl, and direct kill(SIGTERM|HUP) of
the container init process.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-30 19:19:38 +00:00
Ján Tomko
dc04b2a737 virsh: use correct sizeof when allocating cpumap
Found by coverity:
Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4754: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.

Error: SIZEOF_MISMATCH (CWE-569):
    libvirt-0.10.2/tools/virsh-domain.c:4942: suspicious_sizeof: Passing
    argument "8UL /* sizeof (cpumap) */" to function
    "_vshCalloc(vshControl *, size_t, size_t, char const *, int)" and
    then casting the return value to "unsigned char *" is suspicious.
2012-11-29 10:10:08 -07:00
Daniel P. Berrange
d9a52520c7 Add a 'send-process-signal' command to virsh
* tools/virsh.c: Add send-process-signal
* tools/virsh.pod: Document new command

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-29 15:50:12 +00:00
Michal Privoznik
4ded3fb1c2 maint: Fix use of invalid reboot flags
Throughout the code, we've always used VIR_DOMAIN_SHUTDOWN* flags
even for virDomainReboot() API and its implementation. Fortunately,
the appropriate macros has the same value. But if we want to keep
things consistent, we should be using the correct macros. This
patch doesn't break anything, luckily.
2012-11-28 17:45:30 +01:00
Martin Kletzander
1d4f41fdbe virsh: Rewrite cmdDomDisplay
Just a little rewrite of the cmdDomDisplay function to make it
consistent and hopefully more readable.  This also fixes a problem
with password not being displayed for vnc even with the
"--include-password" option.
2012-11-28 16:22:10 +01:00
Michal Privoznik
47c724e54f virsh: Expose new virDomainFSTrim API
It's exposed under domfstrim command. Although the API
doesn't support specifying mount point yet, expose it
anyway.
2012-11-28 16:15:01 +01:00
Eric Blake
79caaf70ae Revert "virsh: add aliases 'boot', 'stop', and 'restart'"
This reverts commits 5f63a5cb42
and ff86b0c97b.  After much list
discussion, consensus was that libvirt aliases should be reserved
to correct typos, otherwise it risks confusion.  Rather, we
should implement a way for users to provide their own aliases
as part of their virsh configuration preferences.
2012-11-16 08:23:57 -07:00
Ján Tomko
58110b4887 virsh: save: report an error if XML file can't be read
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=876868
2012-11-15 22:21:35 -07:00
Viktor Mihajlovski
2bbe624e1d virsh: Use virNodeGetCPUMap if possible
Modified the places where virNodeGetInfo was used for the purpose
of obtaining the maximum node CPU number. Transparently falling
back to virNodeGetInfo in case of failure.
Wrote utility function vshNodeGetCPUCount to compute node CPU
number.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2012-11-15 09:06:54 -07:00
Eric Blake
ff86b0c97b virsh: add aliases 'boot', 'stop', and 'restart'
https://bugzilla.redhat.com/show_bug.cgi?id=873344 suggested that
the grouping 'boot', 'shutdown', 'reboot'; as well as the grouping
'start', 'stop', 'restart'; might be easier to remember than the
current mix of 'start', 'shutdown', 'reboot'.

Also, touch up the wording of 'reboot' to be more accurate.

* tools/virsh-domain.c (domManagementCmds): Add other command names.
* tools/virsh.pod (start, shutdown, reboot): Document the aliases.
2012-11-06 08:03:48 -07:00
Daniel P. Berrange
1c04f99970 Remove spurious whitespace between function name & open brackets
The libvirt coding standard is to use 'function(...args...)'
instead of 'function (...args...)'. A non-trivial number of
places did not follow this rule and are fixed in this patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-02 13:36:49 +00:00
Laine Stump
def31e4c58 qemu: fix attach/detach of netdevs with matching mac addrs
This resolves:

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

which describes inconsistencies in dealing with duplicate mac
addresses on network devices in a domain.

(at any rate, it resolves *almost* everything, and prints out an
informative error message for the one problem that isn't solved, but
has a workaround.)

A synopsis of the problems:

1) you can't do a persistent attach-interface of a device with a mac
address that matches an existing device.

2) you *can* do a live attach-interface of such a device.

3) you *can* directly edit a domain and put in two devices with
matching mac addresses.

4) When running virsh detach-device (live or config), only MAC address
is checked when matching the device to remove, so the first device
with the desired mac address will be removed. This isn't always the
one that's wanted.

5) when running virsh detach-interface (live or config), the only two
items that can be specified to match against are mac address and model
type (virtio, etc) - if multiple netdevs match both of those
attributes, it again just finds the first one added and assumes that
is the only match.

Since it is completely valid to have multiple network devices with the
same MAC address (although it can cause problems in many cases, there
*are* valid use cases), what is needed is:

1) remove the restriction that prohibits doing a persistent add of a
netdev with a duplicate mac address.

2) enhance the backend of virDomainDetachDeviceFlags to check for
something that *is* guaranteed unique (but still work with just mac
address, as long as it yields only a single results.

This patch does three things:

1) removes the check for duplicate mac address during a persistent
netdev attach.

2) unifies the searching for both live and config detach of netdevices
in the subordinate functions of qemuDomainModifyDeviceFlags() to use the
new function virDomainNetFindIdx (which matches mac address and PCI
address if available, checking for duplicates if only mac address was
specified). This function returns -2 if multiple matches are found,
allowing the callers to print out an appropriate message.

Steps 1 & 2 are enough to fully fix the problem when using virsh
attach-device and detach-device (which require an XML description of
the device rather than a bunch of commandline args)

3) modifies the virsh detach-interface command to check for multiple
matches of mac address and show an error message suggesting use of the
detach-device command in cases where there are multiple matching mac
addresses.

Later we should decide how we want to input a PCI address on the virsh
commandline, and enhance detach-interface to take a --address option,
eliminating the need to use detach-device

* src/conf/domain_conf.c
* src/conf/domain_conf.h
* src/libvirt_private.syms
  * added new virDomainNetFindIdx function
  * removed now unused virDomainNetIndexByMac and
    virDomainNetRemoveByMac

* src/qemu/qemu_driver.c
  * remove check for duplicate max from qemuDomainAttachDeviceConfig
  * use virDomainNetFindIdx/virDomainNetRemove instead
    of virDomainNetRemoveByMac in qemuDomainDetachDeviceConfig
  * use virDomainNetFindIdx instead of virDomainIndexByMac
    in qemuDomainUpdateDeviceConfig

* src/qemu/qemu_hotplug.c
  * use virDomainNetFindIdx instead of a homespun loop in
    qemuDomainDetachNetDevice.

* tools/virsh-domain.c: modified detach-interface command as described
    above
2012-10-26 20:47:54 -04:00
Ján Tomko
c0fab87106 virsh: remove reference to migration in blockcopy 2012-10-11 21:12:45 -06:00
Ján Tomko
13fefaf37f virsh: block SIGINT while getting BlockJobInfo
SIGINT hasn't been blocked, which could lead to losing it somewhere in
virDomainGetBlockJobInfo and not aborting the job.
2012-10-11 21:01:54 -06:00
Jiri Denemark
28f8dfdccc Add MIGRATABLE flag for virDomainGetXMLDesc
Using VIR_DOMAIN_XML_MIGRATABLE flag, one can request domain's XML
configuration that is suitable for migration or save/restore. Such XML
may contain extra run-time stuff internal to libvirt and some default
configuration may be removed for better compatibility of the XML with
older libvirt releases.

This flag may serve as an easy way to get the XML that can be passed
(after desired modifications) to APIs that accept custom XMLs, such as
virDomainMigrate{,ToURI}2 or virDomainSaveFlags.
2012-10-11 15:11:42 +02:00
Eric Blake
4ecb723b9e maint: fix up copyright notice inconsistencies
https://www.gnu.org/licenses/gpl-howto.html recommends that
the 'If not, see <url>.' phrase be a separate sentence.

* tests/securityselinuxhelper.c: Remove doubled line.
* tests/securityselinuxtest.c: Likewise.
* globally: s/;  If/.  If/
2012-09-20 16:30:55 -06:00
Eric Blake
ed23b10660 blockjob: add virsh blockcommit
The new command 'virsh blockcommit $dom $disk' requests the start
of an asynchronous commit operation across the entire chain of
$disk.  Further arguments can fine-tune which portion of the
chain is committed.  Existing 'virsh blockjob' commands can then
track the status, change the bandwidth, or abort the commit job.

With a bit more on the command line, 'virsh blockcommit $dom $disk
--wait --verbose' can be used for blocking behavior, with visual
feedback on the overall status, and can be canceled with Ctrl-C.

The overall design, including the wait loop logic, borrows heavily
from the existing blockpull command.

* tools/virsh-domain.c (cmdBlockCommit): New function.
* tools/virsh.pod (blockcommit): Document it.
2012-09-17 21:44:49 -06:00
Hu Tao
0831a5bade bitmap: new member variable and function renaming
Add a new member variable map_len to store map len of bitmap.
and rename size to max_bit accordingly.

rename virBitmapAlloc to virBitmapNew.
2012-09-17 14:59:36 -04:00
Osier Yang
f5fb059a78 virsh: Don't motify the const string
This improve helper vshStringToArray to accept const string as
argument instead. To not convert the const string when using
vshStringToArray, and thus avoid motifying it.
2012-09-17 11:29:31 +08:00
Eric Blake
2387aa26c1 maint: fix missing spaces in message
I got an off-list report about a bad diagnostic:
Target network card mac 52:54:00:49:07:ccdoes not match source 52:54:00:49:07:b8

True to form, I've added a syntax check rule to prevent it
from recurring, and found several other offenders.

* cfg.mk (sc_require_whitespace_in_translation): New rule.
* src/conf/domain_conf.c (virDomainNetDefCheckABIStability): Add
space.
* src/esx/esx_util.c (esxUtil_ParseUri): Likewise.
* src/qemu/qemu_command.c (qemuCollectPCIAddress): Likewise.
* src/qemu/qemu_driver.c (qemuDomainSetMetadata)
(qemuDomainGetMetadata): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeNetBridge): Likewise.
* src/rpc/virnettlscontext.c
(virNetTLSContextCheckCertDNWhitelist): Likewise.
* src/vmware/vmware_driver.c (vmwareDomainResume): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainGetXMLDesc, vboxAttachDrives):
Avoid false negatives.
* tools/virsh-domain.c (info_save_image_dumpxml): Reword.
Based on a report by Luwen Su.
2012-09-12 11:55:29 -06:00
Peter Krempa
51907779ee virsh: Update only changed scheduler tunables
When setting the cpu tunables in virsh you are able to update only a
subset of them. Virsh while doing the update updated all of the
tunables, changed ones with new values and unchanged with old ones.
This is unfortunate as it:
a) might overwrite some other change by a race condition (unprobable)
b) fails with range checking as some of the old values saved might be
   out of range

This patch changes the update procedure so that only the changed value
is updated on the host.

This patch also fixes a very unprobable memory leak if the daemon would
return a string tunable parameter, as the typed parameter array was not
cleared.
2012-09-07 08:08:37 +02:00
Osier Yang
f7eac4f722 list: Add helper to convert strings separated by ', ' to array
tools/virsh.c: New helper function vshStringToArray.
tools/virsh.h: Declare vshStringToArray.
tools/virsh-domain.c: use the helper in cmdUndefine.
2012-09-06 22:04:43 +08:00
Eric Blake
44342a0efe build: use re-entrant functions in virsh
Yesterday's commit 15d2c9f pointed out that virsh was still using
localtime(), which is not thread-safe, even though virsh is
definitely multi-threaded.  Even if we only ever triggered it from
one thread, it's better safe than sorry for maintenance purposes.

* cfg.mk (exclude_file_name_regexp--sc_prohibit_nonreentrant):
Tighten the rule.
* tools/virsh.c (vshOutputLogFile): Avoid localtime.
(vshEditWriteToTempFile, vshEditReadBackFile, cmdCd, cmdPwd)
(vshCloseLogFile): Avoid strerror.
* tools/console.c (vshMakeStdinRaw): Likewise.
* tools/virsh-domain.c (vshGenFileName): Fix spacing in previous
patch.
2012-09-05 11:09:04 -06:00
Martin Kletzander
aa698a49dd docs: correct dompmwakeup description 2012-09-05 06:36:55 +02:00
Paul Eggert
15d2c9fad4 Pass a correct pointer type to localtime_r(3).
On 09/04/2012 08:20 AM, Eric Blake wrote:
> tv_sec is required by POSIX to be
> of type time_t; so this is a bug in the OpenBSD header
> [for declaring it as long]

Most likely this problem arose because of the patch I pushed
in gnulib commit e07d7c40f3ca5ec410cf5aa6fa03cfe51e712039.
Previously, gnulib required timeval's tv_sec to be
the same size as time_t.  But now, it requires only that
tv_sec be big enough to hold a time_t.

This patch was needed for Emacs.  Without the patch, gnulib
replaced struct timeval on OpenBSD, and this messed up
utimens.c, and Emacs wouldn't build.

Alternatively, gnulib could substitute its own struct timeval
for the system's, wrapping every struct timeval-using function
(gettimeofday, futimesat, futimes, lutimes, etc.  That'd be
more work, though.  And it would introduce some performance
issues with gettimeofday, which is supposed to be fast.

I've been trying to get away from using struct timeval,
and to use the higher-resolution struct timespec instead,
so messing with these obsolescent interfaces has been
lower priority for me.  But if someone wants to take the
more-ambitious approach that'd be fine, I expect.

For this particular case, though, how about if we avoid
the problem entirely?  libvirt doesn't need to use struct
timeval here at all.  It makes libvirt smaller and probably
faster, and it ports to OpenBSD without messing with gnulib.
2012-09-04 17:20:08 -06:00
Peter Krempa
67f83cd497 virsh: remove unneeded usage of vshConnectionUsability()
Now that vshCommandRun() checks for the connection automaticaly, remove
all of the redundant checks in the code.

vshConnectionUsability() no longer needs to be exported and this patch
marks it static.
2012-08-31 16:22:22 +02:00
Guannan Ren
c3e7245af5 doc: update option force to subcommand change-media
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=837761
2012-08-31 18:17:02 +08:00
Hu Tao
4860596044 new command emulatorpin 2012-08-22 16:38:13 +08:00
Hu Tao
272570dffb Add a new function vshPrintPinInfo.
This is a helper function to print vcpu pin info.
2012-08-22 16:35:50 +08:00
Eric Blake
4c10b3c7da virsh: declare more common functions
In preparation for splitting virsh-interface.c, I found these
functions need to be declared in virsh.h, as well as one that
belongs more properly in virsh-domain.h.  Also, since we
use the VSH_BY* flags in more than one function, I improved
how they are used.

* tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare.
(VSH_BYID): Turn into enum.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.h): ...here.
* tools/virsh.c: (vshNameSorter): Export.
(cmd_has_option): Rename...
(vshCmdHasOption): ...and export.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.c (vshCommandOptDomainBy): ...here, adjust
signature, and check flags.
* tools/virsh-network.c (vshCommandOptNetworkBy): Update callers.
* tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise.
* tools/virsh-secret.c (vshCommandOptSecret): Likewise.
* tools/virsh-domain-monitor.c (includes): Likewise.
* tools/virsh-host.c (includes): Likewise.
2012-08-20 23:56:18 -06:00
Eric Blake
99ae57f841 virsh: split out virsh-domain-monitor.c
Another file worth compiling on its own instead of by .c inclusion.

* tools/virsh-domain-monitor.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.h (vshGetDomainDescription): Move to correct
header.
* tools/virsh-domain-monitor.c: Use new header.
* tools/virsh.c: Likewise.
* tools/virsh-domain.c: Likewise.
2012-08-20 23:39:54 -06:00
Daniel P. Berrange
6a48179803 Fix build of virsh on Win32 by moving SA_SIGINFO stub
On Win32 SA_SIGINFO is not defined, so virsh.c stub'd it out
to 0, but recent changes moved the usage out of virsh.c and
into virsh-domain.c
2012-08-20 16:00:29 +01:00
Eric Blake
e68ee5e765 virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.

* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-20 07:04:10 -06:00
Eric Blake
f4a7b87de0 virsh: split out virsh-domain.c
The virsh-domain.c file was pretty self-contained; the only
entry point was the table of command definitions.  The bulk
of this patch is making more functions in virsh.c reusable.
A later patch will clean up poor naming choices.

* tools/Makefile.am (virsh_SOURCES): Build virsh-domain.c.
* tools/virsh-domain.h: New file.
* tools/virsh.h (virshReportError, vshResetLibvirtError)
(vshAskReedit, vshStreamSink): Declare.
* tools/virsh.c: Switch from using .c to .h.
(virshReportError, vshResetLibvirtError, vshAskReedit)
(vshStreamSink, prettyCapacity): Export.
(vshCatchInt): Move...
* tools/virsh-domain.c: ...into sole user.  Use header.
2012-08-17 22:22:42 -06:00
Eric Blake
8e8809e131 virsh: move vshWatchJob earlier
It's easier to order things in topological order than it is to
forward declare in one file for use only by one other file.

* tools/virsh.c (vshWatchJob, parseRateStr)
(vshDomainStateToString, vshDomainStateReasonToString)
(vshDomainControlStateToString, vshDomainVcpuStateToString): Drop
useless prototypes.
* tools/virsh-domain.c (vshWatchJob): Move earlier.
2012-08-17 21:44:14 -06:00
Daniel P. Berrange
9ef12b6ff5 Fix WIN32 conditional for disabling console command
The '#endif' for a WIN32 conditional was placed one function
too high, leaving the impl of the console command enabled
and referencing functions that were disabled
2012-08-15 21:43:01 +01:00
Ján Tomko
863399f06b virsh: say save-image-edit failed only when it does
The common code for editing files in virsh-edit.c expects EDIT_DEFINE to
return 0 on failure. virDomainSaveImageDefineXML returns 0 on success.
2012-08-14 08:54:55 +08:00
Peter Krempa
3df9626c40 virsh: Refactor error clearing on graceful fallback paths
Virsh uses an error handler to save errors from libvirt. On some code
paths it's needed to clear libvirt errors and continue on fallback code
paths without reporting failure.

This patch adds function vshResetLibvirtError() that clears error
returned by libvirt and updates all places where the old two-line method
was used.
2012-07-27 10:28:22 +02:00
Peter Krempa
dcfb7050c4 virsh: Check for existence of storage before undefining the domain
When undefining a domain and removing associated storage using "virsh
undefine --storage" the domain was at first undefined and after that the
storage removal proces was started. If the user specified an invalid
disk to remove, the error could not be corrected.

This patch moves enumeration and filtering of volumes that should be
removed before the domain is undefined, but the removal process is still
kept after the domain has been undefined.
2012-07-26 12:57:26 +02:00
Osier Yang
c4bdf307e0 virsh: Move command group definition into its own file
* virsh-domain-monitor.c: Add domMonitoringCmds
* virsh-domain.c: Add domManagementCmds
* virsh-host.c: Add hostAndHypervisorCmds
* virsh-interface.c: Add ifaceCmds
* virsh-network.c: Add networkCmds
* virsh-nodedev.c: Add nodedevCmds
* virsh-nwfilter.c: Add nwfilterCmds
* virsh-pool.c: Add storagePoolCmds
* virsh-secret.c: Add secretCmds
* virsh-snapshot.c: Add snapshotCmds
* virsh-volume.c: Add storageVolCmds
* virsh.c: Remove all the above *Cmds.
2012-07-26 12:00:43 +08:00
Osier Yang
73b89ed838 virsh: Split cmds of domain group from virsh.c
This splits commands to manage domain into virsh-domain.c,The helpers
not for common use are moved into them too. Standard copyright is added
for the new file.

* tools/virsh.c:
  - Remove commands for domain group, and one helper
    (vshDomainVcpuStateToString)
  - vshStreamSink is moved before commands's definition for it's
    also used by commands not of domain group, such as volUpload.

* tools/virsh-domain.c:
  - New file, commands for domain group and the one helper are
    moved into it.

* po/POTFILES.in:
  - Add virsh-domain.c

* cfg.mk:
  - Skip to check config.h including for virsh-domain.c
2012-07-26 11:57:18 +08:00