Commit Graph

1410 Commits

Author SHA1 Message Date
Peter Krempa
59de544f6a virsh: man: Fix description of --live/--config usage
dommemstat and blkdeviotune's man page incorrectly stated the usage of
--live and --config.
2014-10-14 09:41:24 +02:00
Guido Günther
adac88c347 Make editor used for 'virsh edit' configurable
Debian wants to use 'sensible-editor' instead of vi other distros might
want to use other defaults. This avoids distro specific patches.
2014-10-01 20:17:48 +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
Tomoki Sekiyama
cd439dce7c virsh: Fix help message of allocpages
Fix info in the command definition of allocpages, which is currently
pointing info for 'capabilities'.

Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama@hds.com>
2014-09-29 08:21:48 +02:00
Michal Privoznik
3426d380bf virsh: Expose virNodeAllocPages
The new virsh command is named 'allocpages'.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-09-25 10:24:45 +02:00
Jim Fehlig
a9bad1a337 libvirt-guests: run after time-sync.target
When libvirt-guests is configured to start guests on host
boot, it is possible for guests start and read the host
clock before it is synchronized.  Services such as
libvirt-guests that require correct time should use the
Special Passive System Unit time-sync.target

http://www.freedesktop.org/software/systemd/man/systemd.special.html#time-sync.target
2014-09-23 14:35:43 -06: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
Jincheng Miao
c3e2d5929c virsh-host: fix pagesize unit of freepages
The unit of '--pagesize' of freepages is kibibytes.

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

Signed-off-by: Jincheng Miao <jmiao@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-09-23 10:23:20 +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
Wang Yufei
18a6dc93e5 maint: clean up _virDomainMemoryStat
Clean up all _virDomainMemoryStat.

Signed-off-by: James <james.wangyufei@huawei.com>
Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-17 11:28:48 -06:00
Wang Yufei
744d0f3de0 maint: clean up _virDomainBlockStats
Clean up all _virDomainBlockStats.

Signed-off-by: James <james.wangyufei@huawei.com>
Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-17 11:28:48 -06:00
Wang Yufei
ac64cc1016 maint: clean up _virDomainInterfaceStats
Clean up all _virDomainInterfaceStats.

Signed-off-by: Wang Yufei <james.wangyufei@huawei.com>
Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-17 11:28:48 -06:00
Peter Krempa
74cf34bc94 man: virsh: Add docs for supported stats groups
Document the fields returned.
2014-09-17 18:16:02 +02:00
Francesco Romani
1db475650a virsh: add options to query bulk stats group
Add new bulk stats groups to the domstats command.

Signed-off-by: Francesco Romani <fromani@redhat.com>
2014-09-17 18:15:11 +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
07334ccbac Resolve Coverity CHECKED_RETURN
Coverity complained that checking the return of virDomainCreate()
was not consistent amongst the callers - so added the return check
to the objecteventtest.c and adjust the virt-login-shell to compare
< 0 rather than just non zero for the failure condition.
2014-09-15 10:44:27 -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
b46b7785ac virsh: Resolve Coverity DEADCODE
Coverity points out that by using EMPTYSTR(type) we are guarding against
the possibility that it could be NULL; however, based on how 'type' was
initialized to NULL, then using nested ternary if-then-else's (?:?:)
setting either "ipv4", "ipv6", or "" - there is no way it could be NULL.
Since "-" is supposed to mean something empty in a field - modify the
nested ternary to an easier to read/process if-then-else leaving the
initialization to NULL to mean "-" in the formatted output.

Also changed the name from 'type' to 'typestr'.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2014-09-11 08:06:16 -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
eaee338ae6 qemu: Recompute downtime and total time when migration completes
Total time of a migration and total downtime transfered from a source to
a destination host do not count with the transfer time to the
destination host and with the time elapsed before guest CPUs are
resumed. Thus, source libvirtd remembers when migration started and when
guest CPUs were paused. Both timestamps are transferred to destination
libvirtd which uses them to compute total migration time and total
downtime. Obviously, this requires the time to be synchronized between
the two hosts. The reported times are useless otherwise but they would
be equally useless if we didn't do this recomputation so don't lose
anything by doing it.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-09-10 09:37:34 +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
2ad38fdba1 virsh: additional scaled output units
The parser accepts P and E, so the formatter should too.

* tools/virsh.c (vshPrettyCapacity): Handle larger units.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-09-09 08:19:02 -06: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
John Ferlan
adedda2cc8 virsh-network: Resolve Coverity RESOURCE_LEAK
Need to free 'xmlFromFile' on/for the error path when current was
returning false only
2014-08-28 08:12:16 -04:00
Peter Krempa
5e54297073 virsh: Implement command to excercise the bulk stats APIs
Add "domstats" command that excercises both of the new APIs depending if
you specify a domain list or not. The output is printed as a key=value
list of the returned parameters.
2014-08-28 13:28:32 +02:00
Erik Skultety
f284ee54ba virsh: fix keepalive error msg
resolves https://bugzilla.redhat.com/show_bug.cgi?id=1132305:

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

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

After this patch, it is:

error: Invalid value for option -k

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-08-27 16:26:26 -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
Li Yang
bf90846909 virsh: Fix help info for freepages
Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-08-22 12:22:59 +02:00
Li Yang
b2e87c3628 virsh: man: Add LXC format info for domxml-from/to-native
Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-08-21 15:47:48 +02:00
Peter Krempa
b470a38fa9 virsh: Don't print extra '-'s in error message for -k and -K options
The error message contains one extra dash.
2014-08-21 09:58:34 +02:00
Martin Kletzander
93cf8f9861 cleanup spaces between parentheses and braces
And add a syntax-check for '){$'.  It's not perfect, but better than
nothing.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-08-20 14:50:21 +02:00
Li Yang
48da618719 virsh: Fix comment for net-undefine
net-undefine doesn't only undefine an inactive network,
but also an active network(persistent), it just cannot
undefine a transient network.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-08-19 15:14:32 +02:00
Pradipta Kr. Banerjee
338ae9e2d4 man: virsh: add missing auto-converge option for 'migrate'
* tools/virsh.pod (migrate): Add --auto-converge flag

Signed-off-by: Pradipta Kr. Banerjee <bpradip@in.ibm.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2014-08-19 15:01:53 +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
Peter Krempa
c68ae7f611 virsh: man: Crosslink "desc" and "metadata" sections
Those two commands work with a single API so cross-link them.
2014-08-18 17:05:24 +02:00
Li Yang
b3fa5d724f man: virsh: Add 'vcpu_period' and 'vcpu_quota' support info for LXC
Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-08-18 15:53:36 +02:00
Peter Krempa
992318cbee man: virsh: Add man page for "virsh metadata"
Patch adding the command forgot to add the man page entry.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1130379
2014-08-15 17:12:33 +02:00
Roman Bogorodskiy
0257d06ba4 storage: ZFS support
Implement ZFS storage backend driver. Currently supported
only on FreeBSD because of ZFS limitations on Linux.

Features supported:

 - pool-start, pool-stop
 - pool-info
 - vol-list
 - vol-create / vol-delete

Pool definition looks like that:

 <pool type='zfs'>
  <name>myzfspool</name>
  <source>
    <name>actualpoolname</name>
  </source>
 </pool>

The 'actualpoolname' value is a name of the pool on the system,
such as shown by 'zpool list' command. Target makes no sense
here because volumes path is always /dev/zvol/$poolname/$volname.

User has to create a pool on his own, this driver doesn't
support pool creation currently.

A volume could be used with Qemu by adding an entry like this:

    <disk type='volume' device='disk'>
      <driver name='qemu' type='raw'/>
      <source pool='myzfspool' volume='vol5'/>
      <target dev='hdc' bus='ide'/>
    </disk>
2014-08-12 19:40:20 +04:00
Guido Günther
7dc11d6be4 Make 'uri' command a bit more prominent.
This tries to address

    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=688778

were libvirt autodetected vbox:///session and it wasn't listed in the
manpage.
2014-08-11 22:23:48 +02:00
Laine Stump
f91aa93149 virsh: clean up attach-interface paragraph in man page
This makes the paragaph about attach-interface more descriptive and
correct, adding in a few bits of information that were previously
missing, e.g. --script is only allowed for bridge interfaces of Xen
domains, target name is regenerated if it starts with vnet, mac
address will be autogenerated if not specified.

(I did this in response to an email asking why a script couldn't be
specified for a bridge interface of a qemu domain, and why an
interface of type='ethernet' couldn't be created with
attach-interface)
2014-08-07 13:04:53 -04: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
John Ferlan
4a85bf3e2f storage: Refresh storage pool after upload
https://bugzilla.redhat.com/show_bug.cgi?id=1072653

Upon successful upload of a volume, the target volume and storage pool
were not updated to reflect any changes as a result of the upload. Make
use of the existing stream close callback mechanism to force a backend
pool refresh to occur in a separate thread once the stream closes. The
separate thread should avoid potential deadlocks if the refresh needed
to wait on some event from the event loop which is used to perform
the stream callback.
2014-08-04 10:35:52 -04:00
Martin Kletzander
15e38ebbf1 libvirt-guests: fix some typos in a comment
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-07-25 12:06:07 +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
John Ferlan
83a928ef0a virsh: Document bandwidth maximum more clearly
Commit id '0e2d7305' modified the code to allow a negative value to be
supplied for the bandwidth argument of the various block virsh commands
and the migrate-setspeed; however, it failed to update the man page to
describe the "feature" whereby a very large value could be interpreted
by the hypervisor to mean maximum value allowed. Although initially
designed to handle a -1 value, the reality is just about any negative
value could be provided and essentially perform the same feature.
2014-07-17 13:15:12 -04:00
John Ferlan
570d0f6387 virsh vol-upload/download disallow negative offset
https://bugzilla.redhat.com/show_bug.cgi?id=1087104

Commit id 'c6212539' explicitly allowed a negative value to be used for
offset and length as a shorthand for the largest value after commit id
'f18c02ec' modified virStrToLong_ui() to essentially disallow a negative
value.

However, allowing a negative value for offset ONLY worked if the negative
value was -1 since the eventual lseek() does allow a -1 to mean the end
of the file.  Providing other negative values resulted in errors such as:

$ virsh vol-download --pool default qcow3-vol2 /home/vm-images/raw \
  --offset -2 --length -1000
error: cannot download from volume qcow3-vol2
error: Unable to seek /home/vm-images/qcow3-vol2 to 18446744073709551614: Invalid argument

$

Thus, it seems unreasonable to expect or allow a negative value for offset
since the only benefit is to lseek() to the end of the file and then only
take advantage of how the OS would handle such a seek. For the purposes of
upload or download of volume data, that seems to be a no-op.  Therefore,
disallow a negative value for offset.

Additionally, modify the man page for vol-upload and vol-download to provide
more details regarding the valid values for both offset and length.
2014-07-17 13:15:12 -04: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
Ján Tomko
3103a9770f Fix assignment of comparison against zero
Assign the value we're comparing:
(val = func()) < 0
instead of assigning the comparison value:
(val = func() < 0)

Both were introduced along with the code,
the TLS tests by commit bd789df in 0.9.4
net events by commit de87691 in 1.2.2.

Note that the event id type fix is a no-op:
vshNetworkEventIdTypeFromString can only return
-1 (failure) and the event is never used or
0 (the only possible event) and the value of 0 < 0 is still 0.
2014-07-16 09:39:57 +02:00
Peter Krempa
6f04fb151b doc: Be more specific about semantics of _REUSE_EXT flag
Snapshots and block-copy have a flag that forces qemu to re-use existing
file. Our docs weren't exactly clear on what the existing file should
contain for this to actually work.

Re-word the docs a bit to state that the file needs to be pre-created in
the desired format and the backing chain metadata needs to be set prior
to handing it over to qemu.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1084360
2014-07-14 09:26:39 +02:00
Peter Krempa
500f80a595 doc: Document that snapshot name of block-backed disk isn't autogenerated
Libvirt generates external snapshot target file names for file backed
storage but not for block backed storage. Document the limitation.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1032363
2014-07-14 09:26:26 +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
Pavel Hrdina
c5aaf0b456 tools/wireshark: fix rpm build
There is a missing include of $(top_srcdir)/include to handle
"libvirt/libvirt.h" header file.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
2014-07-08 09:30:45 +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
Michal Privoznik
e74fa5702a wireshark: Honor API change coming with 1.12 release
https://bugs.gentoo.org/show_bug.cgi?id=508336

At wireshark, they have this promise to change public dissector APIs
only with minor version number change. Which they did when releasing
the version of 1.12.

Firstly, they've changed tvb_memdup() in
a0c53ffaa1bb46d8c9db2ec739401aa411c9790e so now it takes four arguments
instead of three. The new argument is placed at the very beginning of
the list of arguments and basically says the scope where we'd like to
allocate the memory. According to the documentation NULL should be the
default value.

Then, the tcp_dissect_pdus() signature changed too. Well, the function
that actually dissects reassembled packets as tcp_dissect_pdus()
reorder TCP packets into one big chunk and then calls a user function
to dissect the PDU at once. The change is dated back to
8081cf1d90397cbbb4404f9720595e1537ed5e14.

Then, WS_DLL_PUBLIC_NOEXTERN was replaced with WS_DLL_PUBLIC_DEF in
5d87a8c46171f572568db5a47c093423482e342f.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-04 17:01:20 +02:00
Michal Privoznik
906d0abfe7 wireshark: Include more of libvirt internals
The rationale is to not duplicate code which is done in
packet-libvirt.h for instance. Moreover, this way we can drop
__attribute_((unused)) used int packet-libvirt.c in favor of
ATTRIBUTE_UNUSED.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-04 17:00:46 +02:00
Michal Privoznik
e9f2929f41 virsh: expose virConnectGetDomainCapabilities
The API is exposed under 'domcapabilities' command. Currently, with
the variety of drivers that libvirt supports, none of the command
arguments is obligatory, but all are optional instead.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-07-03 12:22:37 +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
Peter Krempa
02bffd47bd net: merge virNetworkGetDHCPLeases and virNetworkGetDHCPLeasesForMAC
Instead of maintaining two very similar APIs, add the "@mac" parameter
to virNetworkGetDHCPLeases and kill virNetworkGetDHCPLeasesForMAC. Both
of those functions would return data the same way, so making @mac an
optional filter simplifies a lot of stuff.
2014-06-27 09:38:13 +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
Jiri Denemark
a4743860f8 virsh: Remove bogus stat on log file
Let's just open the file right away and deal with errors. Moreover,
there's no reason to forbid logging to, e.g., a pipe.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
2014-06-26 00:43:38 +02:00
Nehal J Wani
59cac9a918 net-dhcp-leases: Add virsh support
Use virNetworkGetDHCPLeases and virNetworkGetDHCPLeasesForMAC in virsh.

The new feature supports the follwing methods:

1. Retrieve leases info for a given virtual network

2. Retrieve leases info for given network interface

tools/virsh-domain-monitor.c
   * Introduce new command : net-dhcp-leases
     Example Usage: net-dhcp-leases <network> [mac]

   virsh # net-dhcp-leases --network default6
   Expiry Time          MAC address        Protocol  IP address                Hostname        Client ID or DUID
   -------------------------------------------------------------------------------------------------------------------
   2014-06-16 03:40:14  52:54:00:85:90:e2  ipv4      192.168.150.231/24        fedora20-test   01:52:54:00:85:90:e2
   2014-06-16 03:40:17  52:54:00:85:90:e2  ipv6      2001:db8:ca2:2:1::c0/64   fedora20-test   00:04:b1:d8:86:42:e1:6a:aa:cf:d5:86:94:23:6f:94:04:cd
   2014-06-16 03:34:42  52:54:00:e8:73:eb  ipv4      192.168.150.181/24        ubuntu14-vm     -
   2014-06-16 03:34:46  52:54:00:e8:73:eb  ipv6      2001:db8:ca2:2:1::5b/64   -               00:01:00:01:1b:30:c6:aa:52:54:00:e8:73:eb

tools/virsh.pod
   * Document new command

src/internal.h
   * Introduce new macro: EMPTYSTR
2014-06-24 12:26:31 +01:00
Michal Privoznik
8d8e1d9dbc cmdFreepages: initialize @tmp
In the 404bac14 the @tmp variable was introduced. It's purpose is to
avoid typecasting when parsing --pagesize argument. However, if the
argument is not presented, tmp may be used uninitialized resulting in
bogus virNodeGetFreePages() API call:

virsh freepages --cellno 2
error: Failed to open file '/sys/devices/system/node/node2/hugepages/hugepages-4294967295kB/free_hugepages': No such file or directory

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-06-23 20:25:22 +02:00
Eric Blake
404bac14ab virsh: fix broken code in freepages
Commit 9e3efe53 broke the build under valgrind or clang, by writing
8 bytes through an allocation of 4 bytes.  It also risks multiplication
overflow when mallocing (that's a pervasive problem that needs an
audit in the rest of the code, but we might as well fix this one while
we are here), and had a typo.

* tools/virsh-host.c (cmdFreepages): Avoid integer overflow and
undefined behavior.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-19 09:21:08 -06:00
Michal Privoznik
9e3efe53de virsh: Expose virNodeGetFreePages
The new API is exposed under 'freepages' command.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-06-19 15:10:50 +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
Peter Krempa
011154764f virsh: man: Correctly spell QEMU
s/QEemu/QEMU/g
2014-06-18 11:26:37 +02:00
Peter Krempa
09e1ec19ae virsh: man: Fix examples and docs for virsh version
The version command now takes the --daemon parameter for a while and the
output example was pretty outdated.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1110673
2014-06-18 11:26:18 +02: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
c62125395b virsh: Reject negative numbers in vshCommandOptULongLong
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 vol-*load two bandwidth functions that use this helper
introduce vshCommandOptULongLongWrap.
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
Peter Krempa
37e663adb6 virsh: Reject negative numbers in vshCommandOptUInt
Use virStrToLong_uip instead of virStrToLong_ui to reject negative
numbers in the helper. None of the callers expects the wraparound
"feature" for negative numbers.

Also add a function that allows wrapping of negative numbers as it might
be used in the future and be explicit about the new semantics in the
function docs.
2014-06-12 14:06:20 +02:00
Roman Bogorodskiy
aec0c6d3d5 virsh: include bhyve in virsh -V output
Add 'Bhyve' in hypervisor list reported by 'virsh -V'
if it's compiled it.
2014-06-11 22:16:09 +04:00
Chen Fan
c85b09cd7a virsh: Add details about specified migration host
the 'migration_host' description may be a bit difficult to
understand for some users, so enhance the manual

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-06-10 11:20:06 -06: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
Michal Privoznik
289a3163de virsh-nodedev: Avoid spurious errors
Our public free functions explicitly don't accept NULL pointers
(sigh). Therefore, callers must do something like this:

    if (dev)
        virNodeDeviceFree(dev);

And we are not doing that on two places I've found. This leads to
dummy error message thrown by virsh:

    virsh # nodedev-dumpxml nonexistent-device
    error: Could not find matching device 'nonexistent-device'
    error: invalid node device pointer in virNodeDeviceFree

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-06-02 18:09:09 +02:00
Peter Krempa
6ef0b03483 virsh: Check whether found volume is member of the specified storage pool
When looking up storage volumes virsh uses multiple lookup steps. Some
of the steps don't require a pool name specified. This resulted into a
possibility that a volume would be part of a different pool than the
user specified:

Let's have a /var/lib/libvirt/images/test.qcow image in the 'default'
pool and a second pool 'emptypool':

Currently we'd return:
  $ virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
  Name:           test.qcow
  Type:           file
  Capacity:       100.00 MiB
  Allocation:     212.00 KiB

After the fix:
 $ tools/virsh vol-info --pool emptypool /var/lib/libvirt/images/test.qcow
 error: Requested volume '/var/lib/libvirt/images/test.qcow' is not in pool 'emptypool'

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1088667
2014-06-02 10:56:49 +02:00
Eric Blake
be673413a3 virsh: fix typos in virsh man page
* tools/virsh.pod (attach-disk): Drop duplicate --config, fix typo
in --sourcetype.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-28 20:10:38 -06:00
Eric Blake
88b5acb67f build: nuke more uses of 'sync'
Commit d5c86278 was incomplete; other functions also triggered
compiler warnings about collisions in the use of 'sync'.

* src/qemu/qemu_driver.c (qemuDomainSetTime): Fix another client.
* tools/virsh-domain-monitor.c (cmdDomTime): Likewise.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-19 17:07:47 -06:00
Eric Blake
ab5178188f maint: shorten 'TypeType' function names
The VIR_ENUM_DECL/VIR_ENUM_IMPL helper macros already append 'Type'
to the enum name being converted; it looks silly to have functions
with 'TypeType' in their name.  Even though some of our enums have
to have a 'Type' suffix, the corresponding string conversion
functions do not.

* src/conf/secret_conf.h (VIR_ENUM_DECL): Rename virSecretUsageType.
* src/conf/storage_conf.h (VIR_ENUM_DECL): Rename
virStoragePoolAuthType, virStoragePoolSourceAdapterType,
virStoragePartedFsType.
* src/conf/domain_conf.c (virDomainDiskDefParseXML)
(virDomainFSDefParseXML, virDomainFSDefFormat): Update callers.
* src/conf/secret_conf.c (virSecretDefParseUsage)
(virSecretDefFormatUsage): Likewise.
* src/conf/storage_conf.c (virStoragePoolDefParseAuth)
(virStoragePoolDefParseSource, virStoragePoolSourceFormat):
Likewise.
* src/lxc/lxc_controller.c (virLXCControllerSetupLoopDevices):
Likewise.
* src/storage/storage_backend_disk.c
(virStorageBackendDiskPartFormat): Likewise.
* src/util/virstorageencryption.c (virStorageEncryptionSecretParse)
(virStorageEncryptionSecretFormat): Likewise.
* tools/virsh-secret.c (cmdSecretList): Likewise.
* src/libvirt_private.syms (secret_conf.h, storage_conf.h): Export
corrected names.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-16 00:22:18 -06:00
Michal Privoznik
222fdbfd2b virsh: Expose virDomain{Get,Set}Time
These APIs are exposed under new virsh command 'domtime' which both gets
and sets (not at the same time of course :)).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-05-15 16:44:38 +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
Julio Faracco
1ce86e62e1 conf: use typedefs for enums in "src/conf/storage_conf.h"
In "src/conf/" there are many enumeration (enum) declarations.
Similar to the recent cleanup to "src/util" directory, it's
better to use a typedef for variable types, function types and
other usages. Other enumeration and folders will be changed to
typedef's in the future. Most of the files changed in this
commit are related to storage (storage_conf) enums.

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-05-14 10:18:35 -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
Li Yang
e4fe06e017 virsh: Replace list element to defined variable
Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-05-05 13:49:09 -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
Daniel P. Berrange
391ac4d990 Activate build dir overrides in libvirtd, virtlockd, virsh & tests
Add calls to virFileActivateDirOverride so that the build dir
overrides are activated.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-04-25 11:59:32 +01:00
Ján Tomko
22a92eb0a7 Document behavior of setvcpus during guest boot
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1088748

The hotplugged vcpus could fail to show up in the guest if
they were added during boot, see:
https://bugzilla.redhat.com/show_bug.cgi?id=807508

Also change arbitrary to arbitrarily.
2014-04-23 14:24:21 +02:00
Nehal J Wani
3d5c29a17c Fix typos in src/*
Fix minor typos in source comments

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-21 16:49:08 -06:00
Li Yang
00b1cce0c0 virsh: Fix comment of vshCmdInfo
The original comment of vshCmdInfo:
"name" - command name

Actually it's 'help' and the short description
of command, not the command name.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-04-09 16:29:58 +02:00
Guido Günther
5a05865773 libvirt-guests: avoid bashism
At least Debian uses dash to run the init scripts
2014-04-07 12:51:05 +02:00
Li Yang
cc7e150359 virsh: Make 'exit' action same as 'quit'
For now 'virsh quit' action like this:
--------------------------------
[root@localhost /]# virsh quit
[root@localhost /]#
--------------------------------
And 'virsh exit' action:
--------------------------------
[root@localhost /]# virsh exit

[root@localhost /]#
--------------------------------
There is a small difference('/n') between them.
According to manual said:
       quit, exit
           quit this interactive terminal

And in the code they all called cmdQuit func,
They should get same actions.

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-04-03 11:57:53 +02:00
Shanzhi Yu
34a4316308 virsh: man: delete the unexpected character in snapshot-list 2014-04-02 13:00:00 +02:00
Eric Blake
8a20e227f6 conf: move storage source type to util/
With this patch, all information related to a host resource in
a storage file backing chain now lives in util/virstoragefile.h.
The next step will be to consolidate various places that have
been tracking backing chain details to all use a common struct.

The changes to tools/Makefile.am were made necessary by the
fact that virstorageencryption includes uses of libxml, and is
now pulled in by inclusion from virstoragefile.h.  No
additional libraries are linked into the final image, and in
comparison, the build of the setuid library in src/Makefile.am
already was using LIBXML_CFLAGS via AM_CFLAGS.

* src/conf/domain_conf.h (virDomainDiskSourceDef): Move...
* src/util/virstoragefile.h (virStorageSource): ...and rename.
* src/conf/domain_conf.c (virDomainDiskSourceDefClear)
(virDomainDiskAuthClear): Adjust clients.
* tools/Makefile.am (virt_login_shell_CFLAGS)
(virt_host_validate_CFLAGS): Add libxml headers.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-04-01 10:38:14 -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
Shanzhi Yu
bfd2f54cf2 virsh: man: Fix spelling of parameters for --memspec in snapshot-create-as
https://bugzilla.redhat.com/show_bug.cgi?id=1080859

Snapshot type should be no, internal, or external.
2014-03-31 14:06:41 +02:00
Li Yang
09bfe11090 Modify help information of virsh list command
Use 'virsh list domain --title' option can get domain's title,
not description, the original help information 'show short
domain description' will confuse users, so modify it to
'show domain title'

Signed-off-by: Li Yang <liyang.fnst@cn.fujitsu.com>
2014-03-27 06:58:46 -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
962abaf538 domiftune: Reword bandwidth clearing paragraph
s/of value/value of/

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-03-19 16:20:18 +01:00
Daniel P. Berrange
2835c1e730 Add virLogSource variables to all source files
Any source file which calls the logging APIs now needs
to have a VIR_LOG_INIT("source.name") declaration at
the start of the file. This provides a static variable
of the virLogSource type.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2014-03-18 14:29:22 +00: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
cc9c62fef9 Require spaces around equality comparisons
Commit a1cbe4b5 added a check for spaces around assignments and this
patch extends it to checks for spaces around '=='.  One exception is
virAssertCmpInt where comma after '==' is acceptable (since it is a
macro and '==' is its argument).

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-18 11:29:44 +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
Ján Tomko
9b9d7704b5 Change file names in comments to match the files they are in
Some of these are leftovers from renaming the files, others
are just typos.

Also introduce an ugly awk script to enforce this.
2014-03-10 14:26:04 +01:00
Roman Bogorodskiy
356bf55e98 Fix locking in virsh console
vshRunConsole() uses virCondWait() which is a wrapper around
pthread_cond_wait(). On FreeBSD, pthread_cond_wait needs mutex to be
locked, otherwise it immediately fails with EPERM. On Linux, the
behaviour in this case is undefined.

So lock the mutex before calling virCondWait().
2014-03-10 14:51:32 +04:00
Martin Kletzander
fb235130fe virsh: Sort options alphabetically
Man page, help output and also parsing is sorted in order to find
options smoothly.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-03-10 10:50:06 +01:00
Eric Blake
cb9bd7963b virt-login-shell: silence coverity warning
Coverity spotted that 'nfdlist' (ssize_t) could be -1, but that we
were using 'i' (size_t) to iterate over the list at cleanup, with
crashing results because it promotes to a really big unsigned number.

* tools/virt-login-shell.c (main): Avoid treating -1 as unsigned.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-05 11:59:06 -07:00
Peter Krempa
a751e3452b virsh: volume: Fix lookup of volumes to provide better error messages
If a user specifies the pool explicitly, we should make sure to point
out that it's inactive instead of falling back to lookup by key/path and
failing at the end. Also if the pool isn't found there's no use in
continuing the lookup.

This changes the error in case the user-selected pool is inactive from:

 $ virsh vol-upload --pool inactivepool --vol somevolname volcontents
 error: failed to get vol 'somevolname'
 error: Storage volume not found: no storage vol with matching path
 somevolname

To a more descriptive:

 $ virsh vol-upload --pool inactivepool --vol somevolname volcontents
 error: pool 'inactivepool' is not active

And in case a user specifies an invalid pool from:

 $ virsh vol-upload --pool invalidpool --vol somevolname volcontents
 error: failed to get pool 'invalidpool'
 error: failed to get vol 'somevolname', specifying --pool might help
 error: Storage volume not found: no storage vol with matching path somevolname

To something less confusing:

 $ virsh vol-upload --pool invalidpool --vol somevolname volcontents
 error: failed to get pool 'invalidpool'
 error: Storage pool not found: no storage pool with matching name 'invalidpool'
2014-03-05 09:08:32 +01: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
730fc9622b virt-login-shell: saner exit value
virt-login-shell was exiting with status 0, regardless of what the
wrapped shell returned.  This is unkind to users; we should behave
more like env(1), nice(1), su(1), and other wrapper programs, by
preserving the invoked application's status (which includes the
distinction between death due to signal vs. normal death).

* tools/virt-login-shell.c (main): Pass through child exit status.
* tools/virt-login-shell.pod: Document exit status.

Signed-off-by: Eric Blake <eblake@redhat.com>
2014-03-03 12:40:32 -07:00
Eric Blake
4594a33b4b virt-login-shell: use single instead of double fork
Note that 'virsh lxc-enter-namespace' must double-fork, for two
reasons: some namespaces can only be done from a single thread,
while virsh is multithreaded; and because virsh can be run in
batch mode where we must not corrupt the namespace of that
execution upon return from the subsidiary command.

When virt-login-shell was first written, it blindly copied from
'virsh lxc-enter-namespace', including the double-fork.  But
neither of the reasons for double forking apply to
virt-login-shell (we are single-threaded, and we have nothing to
do after the child completes that would require us to preserve a
namespace), so we can simplify life by using a single fork.
In turn, this will make it easier for a future patch to pass the
child's exit status on to the invoking shell.

In flattening to a single fork, note that closing the fds must
be done after fork, because the parent process still needs to
use fds to control the virConnectPtr; meanwhile, chdir can be
done prior to forking (in fact, it's easier to report errors
on anything attempted before forking).

* tools/virt-login-shell.c (main): Single rather than double fork.
(virLoginShellFini): Delete, by inlining actions instead.

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
9c439e9bb2 domblkstat: Produce error message that at least sounds like English
Compare:

  # virsh domblkstat freebsd hdd
  error: Failed to get block stats freebsd hdd
  error: invalid argument: invalid path: hdd

with:

  # virsh domblkstat freebsd hdd
  error: Failed to get block stats for domain 'freebsd' device 'hdd'
  error: invalid argument: invalid path: hdd

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
2014-02-28 10:06:27 +01:00
Yuri Chornoivan
0e55eb0460 maint: Fix minor typo (unkown)
Signed-off-by: Eric Blake <eblake@redhat.com>
2014-02-26 10:36:42 -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
Ján Tomko
723e2f8468 virsh: mark CPU usage field names as translatable
My commit ac75801 removed the translation markers when
moving the field names into an array.
2014-02-25 08:32:11 +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