Commit Graph

567 Commits

Author SHA1 Message Date
Michal Privoznik
7c741763db virsh: Expose new virDomainPMSuspendForDuration API
under new command "dompmsuspend"
2012-01-28 10:20:46 +01:00
Zeeshan Ali (Khattak)
6714fd04d2 resize: add virStorageVolResize() API
Add a new function to allow changing of capacity of storage volumes.
Plan out several flags, even if not all of them will be implemented
up front.

Expose the new command via 'virsh vol-resize'.

Signed-off-by: Eric Blake <eblake@redhat.com>
2012-01-27 19:56:18 -07:00
Daniel P. Berrange
4ce98dadcc Rename virXXXXMacAddr to virMacAddrXXX
Rename virFormatMacAddr, virGenerateMacAddr and virParseMacAddr
to virMacAddrFormat, virMacAddrGenerate and virMacAddrParse
respectively
2012-01-27 17:53:44 +00:00
Michal Privoznik
adb99a05b1 storage: Support different wiping algorithms
Currently, we support only filling a volume with zeroes on wiping.
However, it is not enough as data might still be readable by
experienced and equipped attacker. Many technical papers have been
written, therefore we should support other wiping algorithms.
2012-01-26 13:59:30 +01:00
Michal Privoznik
6fba577e50 virsh: Expose new VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE flag
to cmdSnapshotCreate and cmdSnapshotCreateAs.
2012-01-25 10:59:41 +01:00
Daniel P. Berrange
17cfff6f17 Allow choice of shutdown method via virsh
Extend the 'shutdown' and 'reboot' methods so that they both
accept a new argument

    --mode acpi|agent

* tools/virsh.c: New args for shutdown/reboot
* tools/virsh.pod: Document new args
2012-01-24 12:19:51 +01:00
Taku Izumi
a3de9829d8 virsh: let domif-{get,set}link take target name
Other virsh domifXXX commands can accept target name
as a parameter to specify interface. From viewpoint of
consistency, virsh domif-getlink command should accept
target name as a parameter. This patch achieves this.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2012-01-20 16:53:36 -07:00
Eric Blake
7b4e5693c1 API: make declaration of _LAST enum values conditional
Although this is a public API break, it only affects users that
were compiling against *_LAST values, and can be trivially
worked around without impacting compilation against older
headers, by the user defining VIR_ENUM_SENTINELS before using
libvirt.h.  It is not an ABI break, since enum values do not
appear as .so entry points.  Meanwhile, it prevents users from
using non-stable enum values without explicitly acknowledging
the risk of doing so.

See this list discussion:
https://www.redhat.com/archives/libvir-list/2012-January/msg00804.html

* include/libvirt/libvirt.h.in: Hide all sentinels behind
LIBVIRT_ENUM_SENTINELS, and add missing sentinels.
* src/internal.h (VIR_DEPRECATED): Allow inclusion after
libvirt.h.
(LIBVIRT_ENUM_SENTINELS): Expose sentinels internally.
* daemon/libvirtd.h: Use the sentinels.
* src/remote/remote_protocol.x (includes): Don't expose sentinels.
* python/generator.py (enum): Likewise.
* tests/cputest.c (cpuTestCompResStr): Silence compiler warning.
* tools/virsh.c (vshDomainStateReasonToString)
(vshDomainControlStateToString): Likewise.
2012-01-20 16:05:51 -07:00
Eric Blake
61ca98b054 util: add new file for virTypedParameter utils
Preparation for another patch that refactors common patterns
into the new file for fewer lines of code overall.

* src/util/util.h (virTypedParameterArrayClear): Move...
* src/util/virtypedparam.h: ...to new file.
(virTypedParameterArrayValidate, virTypedParameterAssign): New
prototypes.
* src/util/util.c (virTypedParameterArrayClear): Likewise.
* src/util/virtypedparam.c: New file.
* po/POTFILES.in: Mark file for translation.
* src/Makefile.am (UTIL_SOURCES): Build it.
* src/libvirt_private.syms (util.h): Split...
(virtypedparam.h): to new section.
(virkeycode.h): Sort.
* daemon/remote.c: Adjust callers.
* tools/virsh.c: Likewise.
2012-01-19 13:14:10 -07:00
Taku Izumi
0f88c7c16e virsh domiflist: change output
When using "virsh domifstat" command or "virsh domiftune" command,
we pass an interface name as a parameter, so interface name is
important.

"virsh domiflist" output should display interface names
on the first row.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2012-01-13 08:16:17 -07:00
Osier Yang
5b4071333b virsh: Two new fields for command domblklist
Disk "type" and "device" are generally interesting stuff the
user may want to known, too. To not break any scripts which
parsed the output field, a new option "--details" is introduced
to output the two introduced fields.
2012-01-13 18:03:12 +08:00
Daniel P. Berrange
69f0b446a8 Allow 10 chars for domain IDs & 30 chars for names in virsh list
Domain IDs are at least 16 bits for most hypervisors, theoretically
event 32-bits.  3 characters is clearly too small an alignment.
Increase alignment to 5 characters to allow 16-bit domain IDs to
display cleanly. Commonly seen with LXC where domain IDs are the
process IDs by default.  Also increase the 'name' field from 20
to 30 characters to cope with longer guest names which are quite
common
2012-01-12 17:13:46 +00:00
Osier Yang
74e701f8e5 virsh: New command print summary of all virtual interfaces
Just like command "domblklist", the command extracts "type",
"source", "target", "model", and "MAC" of all virtual interfaces
from domain XML (live or persistent).
2012-01-12 17:42:02 +08:00
Shradha Shah
52d064f42d Added new option to virsh net-dumpxml called --inactive
The above option helps to differentiate between implicit and explicit
interface pools.
2012-01-11 13:15:09 -07:00
Alex Jia
c41a21de3a virsh: improve doMigrate function docs
When running virsh migrate with --xml option and actual xml file doesn't
exist, virsh hasn't output any error information, although return value
is 1.

* tools/virsh.c: Raising a appropriate error information when operation fails.

* How to reproduce?
% virsh migrate <domain> --live qemu+ssh://<target host>/system --xml non-existent.xml
% echo $?

* Fixed result:
error: file 'non-existent.xml' doesn't exist

Signed-off-by: Alex Jia <ajia@redhat.com>
2012-01-11 11:50:33 +01:00
Eric Blake
4e9953a426 snapshot: allow reuse of existing files in disk snapshot
When disk snapshots were first implemented, libvirt blindly refused
to allow an external snapshot destination that already exists, since
qemu will blindly overwrite the contents of that file during the
snapshot_blkdev monitor command, and we don't like a default of
data loss by default.  But VDSM has a scenario where NFS permissions
are intentionally set so that the destination file can only be
created by the management machine, and not the machine where the
guest is running, so that libvirt will necessarily see the destination
file already existing; adding a flag will allow VDSM to force the file
reuse without libvirt complaining of possible data loss.

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

* include/libvirt/libvirt.h.in (virDomainSnapshotCreateFlags): Add
VIR_DOMAIN_SNAPSHOT_CREATE_REUSE_EXT.
* src/libvirt.c (virDomainSnapshotCreateXML): Document it.  Add
note about partial failure.
* tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Add new
flag.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
it.
* src/qemu/qemu_driver.c (qemuDomainSnapshotDiskPrepare)
(qemuDomainSnapshotCreateXML): Implement the new flag.
2012-01-10 11:53:23 -07:00
Yuri Chornoivan
524ba58bb9 Fix typos in messages.
https://bugzilla.redhat.com/show_bug.cgi?id=770954
2012-01-03 20:30:33 -07:00
Peter Krempa
d82c6bcf30 virsh: Fix checking for reconnect conditions
virshReportError() function frees the most recent error reported from
libvirt. Condition that checks if connection to the daemon was broken
during last command was then limited to check for SIGPIPE signal not
taking into account possible errors signalized without SIGPIPE.

This patch moves the check before the error is freed, to take into
account code that does not emit SIGPIPE while failing.

* tools/virsh.c: - move check for broken connection before error print.
2012-01-02 18:01:09 +01:00
Hu Tao
b2310b2913 domiftune: Enable the virDomain{S,G}etInterfaceParameters in virsh
Add a new command domiftune to get/set interface parameters.

* tools/virsh.c: implement the new command
* tools/virsh.pod: documentation of the new command
2011-12-29 18:29:25 +08:00
Lai Jiangshan
96b3716c2a virsh: move version command to host group
Trivial patch, move version command to host commands group.

It has no any related with any domain.

It may connect to the daemon, so the flag is 0 but not VSH_CMD_FLAG_NOCONNECT.
2011-12-28 05:18:51 -07:00
Michal Privoznik
74ad69b708 virsh: Use vshWatchJob in cmdManagedSave
This patch alters saving code, so we can report progress
and allow cancel via ^C.
2011-12-22 11:31:51 +01:00
Michal Privoznik
6e4c540d28 virsh: Use vshWatchJob in cmdSave
This patch alters saving code, so we can report progress
and allow cancel via ^C.
2011-12-22 11:31:24 +01:00
Michal Privoznik
5ccc7f6488 virsh: Use vshWatchJob in cmdDump
This patch alters dumping code, so we can report progress
and allow cancel via ^C.
2011-12-22 11:11:28 +01:00
Michal Privoznik
8e7829f754 virsh: Move job watch code to a separate function
called vshWatchJob. This can be later used in other
job oriented commands like dump, save, managedsave
to report progress and allow user to cancel via ^C.
2011-12-22 11:05:15 +01:00
Alex Jia
ea964658af virsh: plug mem leaks in domxml-*-native
Detected by valgrind. Leaks introduced in commit 4d5383f.

* tools/virsh.c: fix memory leaks on cmdDomXMLFromNative and cmdDomXMLToNative.

* how to reproduce?

  % virsh dumpxml ${guest} > foo.xml
  % valgrind -v --leak-check=full virsh domxml-from-native qemu-argv foo.xml
  % valgrind -v --leak-check=full virsh domxml-to-native qemu-argv foo.xml

* actual valgrind results:

==9724== 8,193 bytes in 1 blocks are definitely lost in loss record 31 of 33
==9724==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==9724==    by 0x4A06167: realloc (vg_replace_malloc.c:525)
==9724==    by 0x4C7510B: virReallocN (memory.c:161)
==9724==    by 0x4C84679: virFileReadLimFD (util.c:394)
==9724==    by 0x4C84815: virFileReadAll (util.c:455)
==9724==    by 0x41A89F: cmdDomXMLFromNative (virsh.c:5532)
==9724==    by 0x414872: vshCommandRun (virsh.c:16464)
==9724==    by 0x425623: main (virsh.c:17971)
==9724==
==9724== LEAK SUMMARY:
==9724==    definitely lost: 8,193 bytes in 1 blocks
==9724==    indirectly lost: 0 bytes in 0 blocks
==9724==      possibly lost: 0 bytes in 0 blocks
==9724==    still reachable: 127,128 bytes in 1,347 blocks

==7409== 8,193 bytes in 1 blocks are definitely lost in loss record 31 of 33
==7409==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==7409==    by 0x4A06167: realloc (vg_replace_malloc.c:525)
==7409==    by 0x4C7510B: virReallocN (memory.c:161)
==7409==    by 0x4C84679: virFileReadLimFD (util.c:394)
==7409==    by 0x4C84815: virFileReadAll (util.c:455)
==7409==    by 0x41A7AF: cmdDomXMLToNative (virsh.c:5578)
==7409==    by 0x414892: vshCommandRun (virsh.c:16463)
==7409==    by 0x425633: main (virsh.c:17970)
==7409==
==7409== LEAK SUMMARY:
==7409==    definitely lost: 8,193 bytes in 1 blocks
==7409==    indirectly lost: 0 bytes in 0 blocks
==7409==      possibly lost: 0 bytes in 0 blocks
==7409==    still reachable: 127,128 bytes in 1,347 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-12-20 14:01:25 -07:00
Hu Tao
9da9a3b047 add new command numatune to virsh
add new command numatune to virsh to get/set numa parameters
2011-12-20 11:23:46 -07:00
Eric Blake
f8616336a3 virsh: simplify printing of typed parameters
No need to repeat code for formatting typed parameters.

* tools/virsh.c (vshGetTypedParamValue): Support strings, and exit
on OOM.
(cmdSchedinfo, cmdBlkiotune, cmdMemtune, cmdBlkdeviotune): Use
it for less code.
2011-12-19 17:19:36 -07:00
Peter Krempa
3bb6bcfc79 virsh: Add option to undefine storage with domains
Add an option for virsh undefine command, to remove associated storage
volumes while undefining a domain. This patch allows the user to remove
associated (libvirt managed ) storage volumes while undefining a domain.

The new option --storage for the undefine command takes a string
argument that consists of comma separated list of target or source path
of volumes to be undefined. Volumes are removed after the domain has
been successfully undefined,

If a volume is not part of a storage pool, the user is warned to remove
the volume in question himself.

Option --wipe-storage may be specified along with this, that ensures
the image is wiped before removing.

Option --remove-all-storage enables the user to remove all storage. The
name is chosen long as the users should be aware what they're about to
do.
2011-12-16 11:42:12 +01:00
KAMEZAWA Hiroyuki
65aefae1a8 virsh: support multifunction in attach-disk
PCI <address...> can be specified by attach-disk but multifunction cannot
be specified. Add --multifunction support.
2011-12-13 16:15:20 -07:00
Peter Krempa
b72c774b88 virsh: Print error message if argument parsing fails for cmdNodesuspend
If parsing of arguments failed, virsh did silently exit returning and
error state, but not specifying the possible problem.

 * tools/virsh: cmdNodesuspend: - error handling added
2011-12-13 15:36:50 +01:00
Michal Privoznik
0fe2b40d5a virsh: Free returned MIME type string
In terms of documentation to virDomainScreenshot, caller MUST free
returned value. But virsh was not.
2011-12-12 15:57:28 +01:00
Alex Jia
9707c2a8bc virsh: plug memory leak on cmdDomblklist
Detected by valgrind. Leak introduced in commit 88a993b:

* tools/virsh.c: fix memory leak on cmdDomblklist.

* how to reproduce?
  % valgrind -v --leak-check=full virsh domblklist <domain name>

* actual valgrind result:

==6573== 1,836 bytes in 1 blocks are definitely lost in loss record 110 of 124
==6573==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==6573==    by 0x330D71497D: xdr_string (in /lib64/libc-2.12.so)
==6573==    by 0x4D26CED: xdr_remote_nonnull_string (remote_protocol.c:30)
==6573==    by 0x4D28138: xdr_remote_domain_get_xml_desc_ret (remote_protocol.c:1418)
==6573==    by 0x4D3C0C2: virNetMessageDecodePayload (virnetmessage.c:382)
==6573==    by 0x4D3279F: virNetClientProgramCall (virnetclientprogram.c:382)
==6573==    by 0x4D0D50B: callWithFD (remote_driver.c:4339)
==6573==    by 0x4D0D5AB: call (remote_driver.c:4360)
==6573==    by 0x4D16EAF: remoteDomainGetXMLDesc (remote_client_bodies.h:861)
==6573==    by 0x4CF9F4F: virDomainGetXMLDesc (libvirt.c:4098)
==6573==    by 0x4154D9: cmdDomblklist (virsh.c:1722)
==6573==    by 0x4149E2: vshCommandRun (virsh.c:16365)
==6573==
==6573== 46,009 (352 direct, 45,657 indirect) bytes in 1 blocks are definitely lost in loss record 123 of 124
==6573==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==6573==    by 0x3318286DC6: xmlXPathNewContext (in /usr/lib64/libxml2.so.2.7.6)
==6573==    by 0x4C79AE2: virXMLParseHelper (xml.c:779)
==6573==    by 0x415512: cmdDomblklist (virsh.c:1726)
==6573==    by 0x4149E2: vshCommandRun (virsh.c:16365)
==6573==    by 0x427743: main (virsh.c:17867)
==6573==
==6573== LEAK SUMMARY:
==6573==    definitely lost: 2,188 bytes in 2 blocks
==6573==    indirectly lost: 45,657 bytes in 332 blocks
==6573==      possibly lost: 0 bytes in 0 blocks
==6573==    still reachable: 128,034 bytes in 1,364 blocks
==6573==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-12-09 10:36:30 -07:00
Peter Krempa
6235629648 virsh: return correct value from cmdDomIfGetLink
Reported by Alex Jia <ajia@redhat.com>. Function cmdDomIfGetLink did not
set a success return value on success path.

Signed-off-by: Alex Jia<ajia@redhat.com>
2011-12-09 12:20:18 +01:00
Alex Jia
f582199e60 virsh: plug memory leak on cmdDomIfGetLink() sucessful path
Detected by valgrind. Leak introduced in commit dc675f3:

* tools/virsh.c: fix memory leak on cmdDomIfGetLink.

* how to reproduce?
  % valgrind -v --leak-check=full virsh domif-getlink <domain name> 0

* actual valgrind result:

==13102== 18 bytes in 1 blocks are definitely lost in loss record 9 of 47
==13102==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==13102==    by 0x322A6A67DD: xmlStrndup (in /usr/lib64/libxml2.so.2.7.6)
==13102==    by 0x414892: cmdDomIfGetLink (virsh.c:1538)
==13102==    by 0x4136A2: vshCommandRun (virsh.c:16363)
==13102==    by 0x4253FB: main (virsh.c:17865)
==13102==
==13102== LEAK SUMMARY:
==13102==    definitely lost: 18 bytes in 1 blocks
==13102==    indirectly lost: 0 bytes in 0 blocks
==13102==      possibly lost: 0 bytes in 0 blocks
==13102==    still reachable: 127,888 bytes in 1,361 blocks
==13102==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-12-08 16:48:00 -07:00
Alex Jia
ecf75f83dc virsh: plug memory leak on cmdBlkdeviotune() sucessful path
Detected by valgrind. Leak introduced in commit e9bd9a0:

* tools/virsh.c: fix memory leak on cmdBlkdeviotune.

* how to reproduce?
  % valgrind -v --leak-check=full virsh blkdeviotune <domain name> <block device>

* actual valgrind result:

==12759== 576 bytes in 1 blocks are definitely lost in loss record 18 of 29
==12759==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==12759==    by 0x42134E: _vshCalloc.clone.2 (virsh.c:422)
==12759==    by 0x4217CB: cmdBlkdeviotune (virsh.c:6364)
==12759==    by 0x4136A2: vshCommandRun (virsh.c:16363)
==12759==    by 0x4253FB: main (virsh.c:17865)
==12759==
==12759== LEAK SUMMARY:
==12759==    definitely lost: 576 bytes in 1 blocks
==12759==    indirectly lost: 0 bytes in 0 blocks
==12759==      possibly lost: 0 bytes in 0 blocks
==12759==    still reachable: 126,964 bytes in 1,342 blocks
==12759==         suppressed: 0 bytes in 0 blocks

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-12-08 16:38:03 -07:00
Eric Blake
f59a941757 build: fix build with older libxml2
On RHEL 5, with libxml2-2.6.26, the build failed with:
virsh.c: In function 'vshNodeIsSuperset':
virsh.c:11951: warning: implicit declaration of function 'xmlChildElementCount'

(or if warnings aren't errors, a link failure later on).

* src/util/xml.h (virXMLChildElementCount): New prototype.
* src/util/xml.c (virXMLChildElementCount): New function.
* src/libvirt_private.syms (xml.h): Export it.
* tools/virsh.c (vshNodeIsSuperset): Use it.
2011-12-08 11:37:24 +08:00
Eric Blake
3a9ce767f1 maint: fix improper use of 'an'
https://bugzilla.redhat.com/show_bug.cgi?id=648855 mentioned a
misuse of 'an' where 'a' is proper; that has since been fixed,
but a search found other problems (some were a spelling error for
'and', while most were fixed by 'a').

* daemon/stream.c: Fix grammar.
* src/conf/domain_conf.c: Likewise.
* src/conf/domain_event.c: Likewise.
* src/esx/esx_driver.c: Likewise.
* src/esx/esx_vi.c: Likewise.
* src/rpc/virnetclient.c: Likewise.
* src/rpc/virnetserverprogram.c: Likewise.
* src/storage/storage_backend_fs.c: Likewise.
* src/util/conf.c: Likewise.
* src/util/dnsmasq.c: Likewise.
* src/util/iptables.c: Likewise.
* src/xen/xen_hypervisor.c: Likewise.
* src/xen/xend_internal.c: Likewise.
* src/xen/xs_internal.c: Likewise.
* tools/virsh.c: Likewise.
2011-12-03 17:11:56 -07:00
Eric Blake
77e62f132c virsh: translate net-info help
Reported by kato.tomoyuki@jp.fujitsu.com at
https://bugzilla.redhat.com/show_bug.cgi?id=749564

* tools/virsh.c (info_network_info): Mark string for translation.
2011-12-01 16:55:47 -07:00
Michal Privoznik
7a79648532 virsh: Allow other escape characters for console
Currently virsh supports only ^] as escape character for console.
However, some users might want to use something else. This patch
creates such ability by specifying '-e' switch on virsh command
line.
2011-12-01 09:51:25 +01:00
Jiri Denemark
cb1e7b61c8 virsh: Fix possible deadlock when virsh is about to exit
Not only was ctl->quit accessed without a mutex but unfortunately,
virEventAddTimeout only interrupts the poll when event loop is running
so the hack needs to add a timeout that will make next poll return
immediately without blocking.
2011-12-01 10:34:43 +08:00
Hu Tao
7e976db4ea virsh: fix setting weight and device-weights at the same time
When setting both blkio weight and device-weights at the same time, the weight
is lost. Fix it.
2011-11-30 12:11:25 -07:00
Lei Li
e9bd9a0809 Enable the blkdeviotune command in virsh
Support virsh command blkdeviotune. Can set or query a block disk
I/O throttle setting.

Signed-off-by: Lei Li <lilei@linux.vnet.ibm.com>
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-11-30 11:36:11 -07:00
Alex Jia
d082e1b966 virsh: correct return value error
Fix cmdDomblklist to return 'true' on success instead of '0'

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

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-11-30 11:04:13 +01:00
Hu Tao
6ac81c8ec8 blkiotune: add interface for blkiotune.device_weight
This adds per-device weights to <blkiotune>.  Note that the
cgroups implementation only supports weights per block device,
and not per-file within the device; hence this option must be
global to the domain definition rather than tied to individual
<devices>/<disk> entries:

<domain ...>
  <blkiotune>
    <device>
      <path>/path/to/block</path>
      <weight>1000</weight>
    </device>
  </blkiotune>
..

This patch also adds a parameter --device-weights to virsh command
blkiotune for setting/getting blkiotune.weight_device for any
hypervisor that supports it.  All <device> entries under
<blkiotune> are concatenated into a single string attribute under
virDomain{Get,Set}BlkioParameters, named "device_weight".

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-11-29 12:26:21 -07:00
Osier Yang
72908c7403 block_resize: Expose the new API to virsh 2011-11-29 21:45:22 +08:00
Srivatsa S. Bhat
34401a8b42 Add virsh command to initiate suspend on the host
Add a new command 'nodesuspend' to perform a timed suspend on the host.

Signed-off-by: Srivatsa S. Bhat <srivatsa.bhat@linux.vnet.ibm.com>
2011-11-29 17:29:17 +08:00
Michal Privoznik
2d0fc93fdd virsh: Don't traverse childless nodes in vshNodeIsSuperset
If both nodes do not have any children, we pass zero to
virBitmapAlloc which returns NULL. In turn we report OOM error
and return false (meaning nodes are different). This is not true.
2011-11-28 18:17:14 +01:00
Jiri Denemark
fd7e85ac6a virsh: Always run event loop
Since virsh already implements event loop, it has to also run it. So far
the event loop was only running during virsh console command.
2011-11-24 11:44:08 +01:00
Michal Prívozník
ea7182c29f virsh: Increase device-detach intelligence
Up to now users have to give a full XML description on input when
device-detaching. If they omitted something it lead to unclear
error messages (like generated MAC wasn't found, etc.).
With this patch users can specify only those information which
specify one device sufficiently precise. Remaining information is
completed from domain.
2011-11-23 10:24:43 +01:00
Laine Stump
1ae8eed1b4 virsh: add iface-bridge and iface-unbridge commands
One of the top questions by libvirt users is how to create a host
bridge device so that guests can be directly on the physical
network. There are several example documents that explain how to do
this manually, but following them often results in confusion and
failure. virt-manager does a good job of creating a bridge based on an
existing network device, but not everyone wants to use virt-manager.

This patch adds a new command, iface-bridge that makes it just about
as simple as possible to create a new bridge device based on an
existing ethernet/vlan/bond device (including associating IP
configuration with the bridge rather than the now-attached device),
and start that new bridge up ready for action, eg:

    virsh iface-bridge eth0 br0

For symmetry's sake, it also adds a command to remove a device from a
bridge, restoring the IP config to the now-unattached device:

    virsh iface-unbridge br0

(I had a short debate about whether to do "iface-unbridge eth0"
instead, but that would involve searching through all bridge devices
for the one that contained eth0, which seems like a bit too much
trouble).

NOTE: These two commands require that the netcf library be available
on the host. Hopefully this will provide some extra incentive for
people using suse, debian, ubuntu, and other similar systems to polish
up (and push downstream) the ports to those distros recently pushed to
the upstream netcf repo by Dan Berrange. Anyone interested in helping
with that effort in any way should join the netcf-devel mailing list
(subscription info at
https://fedorahosted.org/mailman/listinfo/netcf-devel)

During creation of the bridge, it's possible to specify whether or not
the STP protocol should be started up on the bridge and, if so, how
many seconds the bridge should squelch traffic from newly added
devices while learning new topology (defaults are stp='on' and
delay='0', which seems to usually work best for bridges used in the
context of libvirt guests).

There is also an option to not immediately start the bridge (and a
similar option to not immediately start the un-attached device after
destroying the bridge. Default is to start the new device, because in
the case of iface-unbridge not starting is strongly discouraged as it
will leave the system with no network connectivity on that interface
(because it's necessary to destroy/undefine the bridge device before
the unattached device can be defined), and it seemed better to make
the option for iface-bridge behave consistently.

NOTE TO THOSE TRYING THESE COMMANDS FOR THE FIRST TIME: to guard
against any "unexpected" change to configuration, it is advisable to
issue an "virsh iface-begin" command before starting any interface
config changes, and "virsh iface-commit" only after you've verified
that everything is working as you expect. If something goes wrong,
you can always run "virsh iface-rollback" or reboot the system (which
should automatically do iface-rollback).

Aside from adding the code for these two functions, and the two
entries into the command table, the only other change to virsh.c was
to add the option name to vshCommandOptInterfaceBy(), because the
iface-unbridge command names its interface option as "bridge".

virsh.pod has also been updated with short descriptions of these two
new commands.
2011-11-16 15:56:45 -05:00
Daniel P. Berrange
d3406045fd Split src/util/network.{c,h} into 5 pieces
The src/util/network.c file is a dumping ground for many different
APIs. Split it up into 5 pieces, along functional lines

 - src/util/virnetdevbandwidth.c: virNetDevBandwidth type & helper APIs
 - src/util/virnetdevvportprofile.c: virNetDevVPortProfile type & helper APIs
 - src/util/virsocketaddr.c: virSocketAddr and APIs
 - src/conf/netdev_bandwidth_conf.c: XML parsing / formatting
   for virNetDevBandwidth
 - src/conf/netdev_vport_profile_conf.c: XML parsing / formatting
   for virNetDevVPortProfile

* src/util/network.c, src/util/network.h: Split into 5 pieces
* src/conf/netdev_bandwidth_conf.c, src/conf/netdev_bandwidth_conf.h,
  src/conf/netdev_vport_profile_conf.c, src/conf/netdev_vport_profile_conf.h,
  src/util/virnetdevbandwidth.c, src/util/virnetdevbandwidth.h,
  src/util/virnetdevvportprofile.c, src/util/virnetdevvportprofile.h,
  src/util/virsocketaddr.c, src/util/virsocketaddr.h: New pieces
* daemon/libvirtd.h, daemon/remote.c, src/conf/domain_conf.c,
  src/conf/domain_conf.h, src/conf/network_conf.c,
  src/conf/network_conf.h, src/conf/nwfilter_conf.h,
  src/esx/esx_util.h, src/network/bridge_driver.c,
  src/qemu/qemu_conf.c, src/rpc/virnetsocket.c,
  src/rpc/virnetsocket.h, src/util/dnsmasq.h, src/util/interface.h,
  src/util/iptables.h, src/util/macvtap.c, src/util/macvtap.h,
  src/util/virnetdev.h, src/util/virnetdevtap.c,
  tools/virsh.c: Update include files
2011-11-15 10:27:54 +00:00
Daniel P. Berrange
0eee075dc7 Adjust naming of network device bandwidth management APIs
Rename virBandwidth to virNetDevBandwidth, and virRate to
virNetDevBandwidthRate.

* src/util/network.c, src/util/network.h: Rename bandwidth
  structs and APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/conf/network_conf.c, src/conf/network_conf.h,
  src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/util/macvtap.c,
  src/util/macvtap.h, tools/virsh.c: Update for API changes.
2011-11-09 17:10:28 +00:00
Xu He Jie
2d764cb472 virsh: Add VSH_OFLAG_EMPTY_OK for attach-disk command
As the description of removing CDROM media from
  http://wiki.libvirt.org/page/QEMUSwitchToLibvirt#eject_DEV

Add flag 'VSH_OFLAG_EMPTY_OK' to the option 'source' of attach-disk

Then avoid outputting <source> in the XML if 'source' was empty,
rather than trusting libvirt domain_conf.c to understand an empty
string.

Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-11-08 16:04:56 -07:00
Ryota Ozaki
6b5c9936ec virsh: Fix error message on vol-create-from failure
If vol-create-from is failed due to 'input volume not found',
virsh outputs like this:
  $ sudo virsh vol-create-from testpool test-vol.xml test.img
  error: failed to get vol 'test.img', specifying --pool might help
  error: Storage volume not found: no storage vol with matching path
However, '--pool' is incorrect because it is already specified as
second argument ('testpool' in this case). It should be "--inputpool".

The patch fixes this by using pooloptname, which will be "inputpool"
in this case and "pool" in other cases, as error message.
2011-10-27 21:28:22 -06:00
Ryota Ozaki
9981fc5828 virsh: Fix vol-info's 'Type' output
We have a new vol type "dir" in addition to "file" and "block", but
virsh doesn't know it. Fix it.

Additionally, the patch lets virsh output "unknown" if not matched
any of them.
2011-10-24 09:44:25 +08:00
Hu Tao
7b2723c5c1 support setting bandwidth from virsh attach-interface
Adds two options, inbound and outbound, to attach-interface to set
bandwidth when attaching interfaces
2011-10-20 10:31:50 +02:00
Guido Günther
07862822f3 Use virBufferEscapeShell in cmdEcho 2011-10-19 09:24:02 +02:00
Michal Privoznik
4dadfe59d5 virDomainCoreDump: Introduce VIR_DUMP_RESET flag
This flag is intended to allow user to do so called system reset
after dump, instead of sending ACPI reboot event.
2011-10-13 09:32:27 +02:00
Eric Blake
8b6d1a2068 snapshot: add API for filtering by leaves
Counterpart to --roots.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_LIST_LEAVES):
New flag.
* src/libvirt.c (virDomainSnapshotNum, virDomainSnapshotListNames)
(virDomainSnapshotNumChildren)
(virDomainSnapshotListChildrenNames): Document it.
* tools/virsh.c (cmdSnapshotList): Expose it.
* tools/virsh.pod (snapshot-list): Document --leaves.
2011-10-12 16:03:19 -06:00
Eric Blake
b77b203cac snapshot: virsh shorthand for operating on current snap
Rather than having to do:

$ virsh snapshot-revert dom $(virsh snapshot-current dom --name)

I thought it would be nice to do:

$ virsh snapshot-revert dom --current

I didn't add 'virsh snapshot-dumpxml --current' since we already have
'virsh snapshot-current' for the same task.  snapshot-list accepted
a name but did not require it, and that remains the case, with
--current serving in place of that name.  For all other commands,
name used to be required, and can now be replaced by --current;
I intentionally made it so that omitting both --current and a name
is an error (having the absence of a name imply --current seems
just a bit too magic, so --current must be explicit).  I also had
to keep snapshot-edit backwards-compatible, as the only command
that already had a --current argument alongside a name, which still
works to both edit a named snapshot and make it current.

* tools/virsh.c (vshLookupSnapshot): New helper function.
(cmdSnapshotEdit, cmdSnapshotList, cmdSnapshotParent)
(cmdSnapshotDelete, cmdDomainSnapshotRevert): Use it, adding an
option where needed.
* tools/virsh.pod (snapshot-delete, snapshot-edit)
(snapshot-list, snapshot-parent, snapshot-revert): Document
use of --current.
(snapshot-dumpxml): Mention alternative.
2011-10-11 16:38:48 -06:00
Eric Blake
521cc44700 snapshot: virsh fallback for snapshot-list --descendants --from
Given a list of snapshots and their parents, finding all descendants
requires a hairy traversal.  This code is O(n^3); it could maybe be
made to scale O(n^2) with the use of a hash table, but that costs more
memory.  Hopefully there aren't too many people with a hierarchy
so large as to approach REMOTE_DOMAIN_SNAPSHOT_LIST_NAMES_MAX (1024).

* tools/virsh.c (cmdSnapshotList): Add final fallback.
2011-10-10 17:24:47 -06:00
Eric Blake
16d7b3908e snapshot: virsh fallback for snapshot-list --from children
Iterating over one level of children requires parsing all snapshots
and their parents; a bit of code shuffling makes it pretty easy
to do this as well.

* tools/virsh.c (cmdSnapshotList): Add another fallback.
2011-10-10 17:22:07 -06:00
Eric Blake
510823018e snapshot: virsh fallback for snapshot-list --tree --from
Emulating --from requires grabbing the entire list of snapshots
and their parents, and recursively iterating over the list from
the point of interest - but we already do that for --tree.  This
turns on emulation for that situation.

* tools/virsh.c (__vshControl): Rename member.
(vshReconnect, cmdConnect, vshGetSnapshotParent): Update clients.
(cmdSnapshotList): Add fallback.
2011-10-10 17:19:11 -06:00
Eric Blake
fe383bb541 snapshot: virsh snapshot-list and children
Sometimes, we only care about one branch of the snapshot hierarchy.
Make it easier to list a single branch, by using the new APIs.

Technically, I could emulate these new virsh options on old servers
by doing a complete dump, then scraping xml to filter out just the
snapshots that I care about, but I didn't want to do that in this patch.

* tools/virsh.c (cmdSnapshotList): Add --from, --descendants.
* tools/virsh.pod (snapshot-list): Document them.
2011-10-10 17:11:05 -06:00
Eric Blake
bab4f31c78 snapshot: avoid accidental renames with snapshot-edit
I was a bit surprised that 'virsh snapshot-edit dom name' silently
allowed me to clone things, while still telling me the old name,
especially since other commands like 'virsh edit dom' reject rename
attempts (*).  This fixes things to be more explicit (**).

(*) Technically, 'virsh edit dom' relies on virDomainDefineXML
behavior, which rejects attempts to mix a new name with existing
uuid or new uuid with existing name, but you can create a new
domain by changing both uuid and name.  On the other hand, while
snapshot-edit --clone is a true clone, creating a new domain
would also have to decide whether to clone snapshot metadata,
managed save, and any other secondary data related to the domain.
Domain renames are not trivial either.

(**) Renaming or creating a clone is still a risky proposition -
for offline snapshots and system checkpoints, if the new name
does not match an actual name recorded in the qcow2 internal
snapshots, then you cannot revert to the new checkpoint.  But it
is assumed that anyone using the new virsh flags knows what they
are doing, and can deal with the fallout caused by a rename/clone;
that is, we can't completely prevent a user from shooting
themselves in the foot, so much as we are making the default
action less risky.

* tools/virsh.c (cmdSnapshotEdit): Add --rename, --clone.
* tools/virsh.pod (snapshot-edit): Document them.
2011-10-10 11:56:05 -06:00
Eric Blake
40baa1c899 snapshot: sort snapshot-list --tree
Otherwise, the results are not repeatable.

* tools/virsh.c (cmdSnapshotList): Print tree in predictable order.
2011-10-10 11:12:43 -06:00
tangchen
d5c4067d7b virsh: Update the help information for undefine command.
virsh undefine command can now undefine an active guest, but the help information is still the old.
This patch modifies it and make it coincident to the manpage of virsh.

Signed-off-by: tangchen <tangchen@cn.fujitsu.com>
2011-10-07 09:55:30 -06:00
Eric Blake
731f9a5e56 snapshot: let virsh edit disk snapshots
It was impossible for 'virsh snapshot-current dom name' to set name
as the current snapshot, if name is a disk-only snapshot.

Using strstr rather than full-blown xml parsing is safe, since the
xml is assumed to be well-formed coming from libvirtd rather than
arbitrary text coming from the user.

* tools/virsh.c (cmdSnapshotCurrent, cmdSnapshotEdit): Pass
disk_only flag when redefining a disk snapshot.
2011-10-07 08:29:50 -06:00
Eric Blake
203b361f09 snapshot: fix virsh error message typo
* tools/virsh.c (cmdSnapshotList): Spell exclusive correctly.
2011-10-07 07:53:27 -06:00
Eric Blake
3c797404a5 snapshot: add REVERT_FORCE to API
Although reverting to a snapshot is a form of data loss, this is
normally expected.  However, there are two cases where additional
surprises (failure to run the reverted state, or a break in
connectivity to the domain) can come into play.  Requiring extra
acknowledgment in these cases will make it less likely that
someone can get into an unrecoverable state due to a default revert.

Also create a new error code, so users can distinguish when forcing
would make a difference, rather than having to blindly request force.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_SNAPSHOT_REVERT_FORCE):
New flag.
* src/libvirt.c (virDomainRevertToSnapshot): Document it.
* include/libvirt/virterror.h (VIR_ERR_SNAPSHOT_REVERT_RISKY): New
error value.
* src/util/virterror.c (virErrorMsg): Implement it.
* tools/virsh.c (cmdDomainSnapshotRevert): Add --force to virsh.
* tools/virsh.pod (snapshot-revert): Document it.
2011-10-05 11:33:36 -06:00
Eric Blake
64703c03fc snapshot: better virsh handling of missing current, parent
Previously, virsh 'snapshot-parent' and 'snapshot-current' were
completely silent in the case where the code conclusively proved
there was no parent or current snapshot, but differed in exit
status; this silence caused some confusion on whether the commands
worked.  Furthermore, commit d1be48f introduced a regression where
snapshot-parent would leak output about an unknown function, but
only on the first attempt, when talking to an older server that
lacks virDomainSnapshotGetParent.  This changes things to consistenly
report an error message and exit with status 1 when no snapshot
exists, and to avoid leaking unknown function warnings when using
fallbacks.

* tools/virsh.c (vshGetSnapshotParent): Alter signature, to
distinguish between real error and missing parent.  Don't pollute
last_error on success.
(cmdSnapshotParent): Adjust caller.  Always output message on
failure.
(cmdSnapshotList): Adjust caller.
(cmdSnapshotCurrent): Always output message on failure.
2011-10-04 14:36:24 -06:00
Marc-André Lureau
41bf4e721e virsh: do not unlink NULL file
error:could not take a screenshot of xp
==6216== Syscall param unlink(pathname) points to unaddressable byte(s)
==6216==    at 0x373A0D4937: unlink (syscall-template.S:82)
==6216==    by 0x40FD73: cmdScreenshot (virsh.c:3070)
==6216==    by 0x42BA0D: vshCommandRun (virsh.c:14920)
==6216==    by 0x42EC97: main (virsh.c:16379)
==6216==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==6216==
error:Requested operation is not valid: domain is not running
2011-09-30 19:22:06 -06:00
Xu He Jie
0ec9a8c2f2 virsh: Add 'reset' command for virsh
Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
2011-09-29 07:04:14 -06:00
Eric Blake
1cf0e3db8b snapshot: add virsh snapshot-list --tree
Reuse the tree listing of nodedev-list, coupled with the new helper
function to efficiently grab snapshot parent names, to produce
tree output for a snapshot hierarchy.  For example:

$ virsh snapshot-list dom --tree
root1
 |
  +- sibling1
  +- sibling2
  |   |
  |   +- grandchild
  |
  +- sibling3

root2
 |
  +- child

* tools/virsh.c (cmdSnapshotList): Add --tree.
* tools/virsh.pod (snapshot-list): Document it.
2011-09-28 09:54:57 -06:00
Eric Blake
d1be48f976 snapshot: refactor virsh snapshot parent computation
Make parent computation reusable, using virDomainSnapshotGetParent
when possible.

* tools/virsh.c (vshGetSnapshotParent): New helper.
(cmdSnapshotParent): Use it.
2011-09-28 09:54:57 -06:00
Peter Krempa
b0889eae6a virsh: Allow using complete <capabilities> elements with cpu-baseline
This patch cleans the cpu baseline function using new libvirt helper
functions and fixes XPath expression that selects <cpu> elements from
the source file, that can contain concatenated <capabilities> XMLs,
domain XMLs and bare <cpu> elements. The fixed XPath expression ensures
not to select NUMA <cpu id=... elements.

This patch also removes vshRealloc function, that remained unused after
cleaning up cpu-baseline.

https://bugzilla.redhat.com/show_bug.cgi?id=731645
2011-09-28 09:17:56 +02:00
Peter Krempa
882e768ef0 virsh: Allow using domain and capabilities XMLs with cpu-compare
This patch adds extraction of the <cpu> element from capabilities and
domain definition XML documents to improve user experience.

https://bugzilla.redhat.com/show_bug.cgi?id=731151
2011-09-28 09:12:09 +02:00
Osier Yang
f858bcb2d6 virsh: Do not ignore the specified flags for cmdSaveImageDefine
Introduced by commit 42c52d53c, which added the support for new
flags, but forgot to update the API use to pass the flags.
2011-09-22 20:22:54 +08:00
Eric Blake
466f902446 virsh: fix regression in argv parsing
Prior to commit 85d2810, we had an issue where:

snapshot-create-as dom name --diskspec spec --diskspec spec

failed to parse the second spec, because the first spec had marked
that option as no longer requiring an argument.

In commit 85d2810, I fixed it by making argv options no longer mark
the option as seen.  But this in turn breaks mandatory argv options,
which now complain that the argv option is missing.

This patch reverts that part of 85d2810, and instead replaces it with
fixes to no longer clear opts_need_arg of an argv argument.

* tools/virsh.c (vshCmddefGetOption, vshCmddefGetData)
(vshCommandParse): Fix option parsing for required argv option.
(vshCmddefOptParse): Check that argv option is last.
* tests/virsh-optparse: Enhance test.
2011-09-22 13:28:18 +08:00
Osier Yang
2f0595244b virsh: More friendly err if no pool is specified for looking up a vol
There are 3 ways to lookup a volume, only virStorageVolLookupByName
needs pool object. So if no --pool is specified, it will tries to
get the volume via virStorageVolLookupByPath/virStorageVolLookupByKey.

But if all 3 ways fails, and no --pool is specified, a friendly
error might help the user get right way quickly.
2011-09-22 08:16:08 +08:00
Osier Yang
08c4de5984 virsh: Remove useless codes of cmdVolPath
Variable "name" is never used in the codes, it's useless.
2011-09-21 09:21:58 +08:00
Eric Blake
6d1c11e51c virsh: tweak previous domblkstat patch
Translators are likely to botch trailing spacing; by doing the
formatting outside of the translation, we can generally get
better alignment.  Also, for consistency, use 'bytes read' to
match 'bytes written'.

* tools/virsh.c (domblkstat_output): Drop trailing space. Tweak
rd_bytes output.
(cmdDomblkstat, DOMBLKSTAT_LEGACY_PRINT): Update formatting.
2011-09-19 17:54:05 -06:00
Peter Krempa
619077b9eb virsh: Add more human-friendly output of domblkstat command
Users of virsh complain that output of the domblkstat command
is not intuitive enough. This patch adds explanation of fields
returned by this command to the help section for domblkstat and
the man page of virsh. Also a switch --human is added for
domblkstat that prints the fields with more descriptive
texts.

This patch also changes sequence of the output fields and their
names back to the order and spelling established by previous
versions of virsh to maintain compatibility with scripts.

Example of ordered and "translated" output:

PRE-patch:

virsh # domblkstat 1 vda
vda wr_bytes 5170176
vda wr_operations 511
vda rd_bytes 82815488
vda rd_operations 3726

POST-patch:

virsh # domblkstat 1 vda
vda rd_req 3726
vda rd_bytes 82815488
vda wr_req 478
vda wr_bytes 4965376

Example of human readable output:

virsh # domblkstat 1 vda --human
Device: vda
 number of read operations:      3726
 number of read bytes:           82815488
 number of write operations:     478
 number of bytes written:        4965376

https://bugzilla.redhat.com/show_bug.cgi?id=731656
2011-09-19 14:24:08 -06:00
Jiri Denemark
d2d6776342 qemu: Introduce shutdown reason for paused state
Qemu sends STOP event as part of the shutdown process. Detect such STOP
event and consider shutdown to be reason of emitting such event. That's
the best we can do until qemu provides us the reason directly in STOP
event. This allows us to report shutdown reason for paused state so that
apps can detect domains that failed to finish the shutdown process
(e.g., because qemu is buggy and doesn't exit on SIGTERM or it is
blocked in flushing disk buffers).
2011-09-16 17:25:55 +02:00
Eric Blake
e9f55e4688 Revert "virsh: Use old API if remote libvirtd does not support new"
This reverts commit 799912fa05b8c3aa37bd04c57b196755f3f70552; now
that the rpc regression is fixed, virsh no longer needs the special
case here.
2011-09-16 08:20:32 -06:00
Eric Blake
85d2810823 snapshot: tweak snapshot-create-as diskspec docs
With this patch, it is hopefully a bit more obvious that for
snapshot-create-as, a literal '--diskspec' is mandatory if name
or description was omitted, but optional if all earlier options
were provided.

These all denote two diskspecs and a description:
virsh snapshot-create-as dom name desc vda vdb
virsh snapshot-create-as dom name desc --diskspec vda --diskspec vdb
virsh snapshot-create-as dom name desc --diskspec vda vdb
virsh snapshot-create-as dom name desc vda --diskspec vdb
virsh snapshot-create-as dom --diskspec vda --diskspec vdb name desc

This gives two diskspecs but no description:
virsh snapshot-create-as dom name --diskspec vda --diskspec vdb

And this treats 'vda' as the description, with only one diskspec:
virsh snapshot-create-as dom name vda vdb

The help output now shows:
    snapshot-create-as <domain> [<name>] [<description>] [--print-xml] [--no-metadata] [--halt] [--disk-only] [[--diskspec] <string>]...

I also checked the help output for echo and send-key, which are two
other variants of argv commands.

* tools/virsh.pod (snapshot-create-as): Document when a literal
--diskspec must preceed a diskspec argument.
* tools/virsh.c (vshCmddefHelp): Update help output for argv when
naming the option is useful.
(vshCmddefGetData): Fix logic on when argv was seen.
* tests/virsh-optparse: Add tests to avoid regressions.
2011-09-15 16:18:12 -06:00
Peter Krempa
b998f1f77c xml: Clean up rest of virtual XML document names for XML strings
Commit 498d783 cleans up some of virtual file names for parsing strings
in memory. This patch cleans up (hopefuly) the rest forgotten by the
first patch.

This patch also changes all of the previously modified "filenames" to
valid URI's replacing spaces for underscores.

Changes to v1:
- Replace all spaces for underscores, so that the strings form valid
  URI's
- Replace spaces in places changed by commit 498d783
2011-09-14 09:09:04 -06:00
Peter Krempa
799912fa05 virsh: Use old API if remote libvirtd does not support new
Commit ffe28ab74b introduced regression
while communicating with older libvirtd command 'domblkstat' used the new
API and did not check for VIR_ERR_RPC error code signalling the remote
server does not support this API and did not fall back to older API.
Thereafter 'domblkstat' ended with "error: unknown procedure: 243".
2011-09-13 16:55:04 -06:00
Peter Krempa
498d783387 xml: Change virtual file names of xml documents parsed in memory
While parsing XML strings from memory, the previous convention in
libvirt was to set the virtual file name to "domain.xml" or something
similar. This could potentialy trick the user into looking for a file
named domain.xml on the disk in an attempt to fix the error.

This patch changes these filenames to something that can't be as easily
confused for a valid filename.

Examples of error messages:
---------------------------
Error while loading file from disk:

15:07:59.015: 527: error : catchXMLError:709 : /path/to/domain.xml:1: StartTag: invalid element name
<domain type='kvm'><
--------------------^

Error while parsing definition in memory:

15:08:43.581: 525: error : catchXMLError:709 : (domain definition):2: error parsing attribute name
  <name>vm1</name>
--^
2011-09-08 17:20:33 +01:00
Eric Blake
a00c37f2f9 snapshot: use new API for less work
This has the added benefit of making 'snapshot-create dom --no-metadata'
now able to tell you the name of the just-generated snapshot.

* tools/virsh.c (vshSnapshotCreate, cmdSnapshotCurrent): Don't get
XML just for name.
2011-09-08 14:25:30 +01:00
Alex Jia
07331bba6d virsh: fix typo in opts_send_key
* tools/virsh.c: millseconds should be milliseconds in opts_send_key.

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-09-08 11:11:09 +01:00
Matthias Bolte
a6e2ef732d mingw: Don't use interface as an identifier
Because it's a define used in MSCOM and its usage as
identifier results in a compile error.
2011-09-06 21:34:05 +02:00
Peter Krempa
dc675f3789 link-state: virsh: Add wrapper commands for changing link state
Two new commands are added to virsh that wrap usage of
virDomainUpdateDeviceFlags for changing link state of domain's network
interfaces. These wrappers extract network devices's xml configuration
and modify the link state for easy manipulation from an user's perspective.

 - domif-setlink - set link state of a domains virtual network interface
 - domif-getlink - get link state

* tools/virsh.c   - Add functionality to virsh
* tools/virsh.pod - Manpage documentation
2011-09-06 16:31:59 +08:00
Osier Yang
ffe28ab74b latency: Update virsh command domblkstat to use new API
The modified function fallbacks to use virDomainBlockStats if
virDomainBlockStatsFlags is not supported by the hypervisor driver.
If the new API is supported, it will be invoked instead of the
old API.
2011-09-06 12:03:05 +08:00
Eric Blake
35d52b56bb snapshot: wire up disk-only flag to snapshot-create
Expose the disk-only flag through virsh.  Additionally, make
virsh snapshot-create-as take an arbitrary number of diskspecs,
which can be used to build up the xml for <domainsnapshot>.

* tools/virsh.c (cmdSnapshotCreate): Add --disk-only.
(cmdSnapshotCreateAs): Likewise, and add argv diskspec.
(vshParseSnapshotDiskspec): New helper function.
(vshCmddefGetOption): Allow naming of argv field.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
them.
* tests/virsh-optparse: Test snapshot-create-as parsing.
2011-09-05 07:03:04 -06:00
Eric Blake
88a993b129 snapshot: add virsh domblklist command
This adds a convenience function to virsh that parses out block
information from the domain xml, making it much easier to see
what strings can be used in all other contexts that demand a
specific block name, especially when given the previous patch
that allows using either target or unique source name.

As an example on a domain with one disk and an empty cdrom drive:

Target     Source
-------------------------------------------
vda        /var/lib/libvirt/images/fedora_12.img
hdc        -

* tools/virsh.c (cmdDomblklist): New function.
* tools/virsh.pod (domblklist): Document it.
2011-09-05 07:03:04 -06:00
Eric Blake
5b30b08d66 snapshot: support extra state in snapshots
In order to distinguish disk snapshots from system checkpoints, a
new state value that is only valid for snapshots is helpful.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_LAST): New placeholder.
* src/conf/domain_conf.h (virDomainSnapshotState): New enum mapping.
(VIR_DOMAIN_DISK_SNAPSHOT): New internal enum value.
* src/conf/domain_conf.c (virDomainState): Use placeholder.
(virDomainSnapshotState): Extend mapping by one for use in snapshot.
(virDomainSnapshotDefParseString, virDomainSnapshotDefFormat):
Handle new state.
(virDomainObjSetState, virDomainStateReasonToString)
(virDomainStateReasonFromString): Avoid compiler warnings.
* tools/virsh.c (vshDomainState, vshDomainStateReasonToString):
Likewise.
* src/libvirt_private.syms (domain_conf.h): Export new functions.
* docs/schemas/domainsnapshot.rng: Tighten state definition.
* docs/formatsnapshot.html.in: Document it.
* tests/domainsnapshotxml2xmlout/disk_snapshot.xml: New test.
2011-09-05 07:03:04 -06:00
Eric Blake
a891ffa446 snapshot: expose halt-after-creation in virsh
Easy enough to emulate even with older servers.

* tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Add
--halt flag.
(vshSnapshotCreate): Emulate halt when flag is unsupported.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
it.
2011-09-05 07:03:04 -06:00
Eric Blake
ddc882733a snapshot: expose new delete flag in virsh
It would technically be possible to have virsh compute the list
of descendants of a given snapshot, then delete those one at
a time.  But it's complex, and not worth writing for a first
cut at implementing the new flags.

* tools/virsh.c (cmdSnapshotDelete): Add --children-only,
--metadata.
* tools/virsh.pod (snapshot-delete): Document them.
2011-09-05 07:03:04 -06:00
Eric Blake
e88872e9a9 snapshot: teach virsh about new undefine flags
Similar to 'undefine --managed-save' (commit 83e849c1), we must
assume that the old API is unsafe; however, we cannot emulate
metadata-only deletion on older servers.  Additionally, we have
the wrinkle that while virDomainUndefineFlags and managed save
cleanup were introduced in 0.9.4, it wasn't until 0.9.5 that
snapshots block undefine of a domain.  Do the best we can given
the server we are talking to.

* tools/virsh.c (cmdUndefine): Add --snapshots-metadata flag.
* tools/virsh.pod (undefine, destroy, shutdown): Document effect
of snapshots.
2011-09-02 21:57:33 -06:00
Eric Blake
2b4d8deb6b snapshot: improve virsh snapshot-create, add snapshot-edit
Wire up the new snapshot creation flags in virsh.  For convenience,
teach 'snapshot-current' how to make an existing snapshot become
current (can be used after upgrading to newer libvirt to recover
from the fact that the older libvirt lost track of the current
snapshot after a restart).  The snapshot-create-as command is
intentionally not taught --redefine or --current, as this would
imply adding a lot of other options for everything else that can
appear in the <domainsnapshot> xml, but which is normally read-only.
Besides, redefining will usually be done on files created by
snapshot-dumpxml, rather than something built up by hand on the
command line.  And now that we can redefine, we can edit.

* tools/virsh.c (cmdSnapshotCreate): Add --redefine, --current,
and --no-metadata.
(cmdSnapshotCreateAs): Add --no-metadata.
(cmdSnapshotCurrent): Add snapshotname to alter current snapshot.
(cmdSnapshotEdit): New command.
* tools/virsh.pod (snapshot-create, snapshot-create-as)
(snapshot-current, snapshot-edit):  Document these.
2011-09-02 21:57:32 -06:00
Eric Blake
90ec08ed73 snapshot: refactor virsh snapshot creation
The next patch will make snapshot creation more complex, so it's
better to avoid repetition of the complexity.

* tools/virsh.c (vshSnapshotCreate): New helper function.
(cmdSnapshotCreate, cmdSnapshotCreateAs): Use it.
2011-09-02 17:44:45 -06:00
Eric Blake
22a833e789 snapshot: reflect new dumpxml and list options in virsh
New flag bits are worth exposing via virsh.  In the case of
snapshot-list --roots, it's possible to emulate this even when
talking to an older server that lacks the bit; whereas
--metadata requires a newer server.

Although we don't use --security-info yet, the flag is already
documented for other dumpxml operations, and turning it on now
will make it useful when a future patch actually has to honor it.

* tools/virsh.c (cmdSnapshotDumpXML, cmdSnapshotCurrent): Add
--security-info.
(cmdSnapshotList): Add --roots, --metadata.
* tools/virsh.pod (snapshot-dumpxml, snapshot-current)
(snapshot-list): Document these.
2011-09-02 17:07:36 -06:00
Eric Blake
d4a965c6a8 snapshot: add snapshot-list --parent to virsh
Even though I recently added 'virsh snapshot-parent', doing it one
snapshot at a time is painful, so make it possible to expand the
snapshot-list table at once.

* tools/virsh.c (cmdSnapshotList): Add --parent.
* tools/virsh.pod (snapshot-list): Document it.
2011-09-02 15:52:06 -06:00
Eric Blake
42c52d53c3 snapshot: expose --running and --paused in virsh
Pretty straight-forward exposure of new flags.  For most commands,
we let the API reject mutually exclusive flags; but for save-image-edit,
we do the sanity check ourselves to avoid looping on flag failure if
the edit cycle is ever enhanced to allow the user to retry an edit
to fix up an xml validation error.

* tools/virsh.c (cmdManagedSave, cmdRestore, cmdSave)
(cmdSaveImageDefine, cmdSaveImageEdit): Add new flags.
* tools/virsh.pod (managedsave, restore, save, save-image-define)
(save-image-edit): Document them.
2011-09-02 10:00:06 -06:00
Osier Yang
ddcd5674aa storage: Add virsh support for fs pool formating 2011-09-02 21:17:08 +08:00
Eric Blake
c2d4b4f704 virsh: improve send-key documentation
The 'virsh man' description of send-key was incomplete and used the
old style (literal 'optional name' instead of '[name]' metasyntax).
Meanwhile, none of the other virsh help texts include examples, so
I moved it out of virsh help and into the man page.

* tools/virsh.pod (send-key): Give better details.
* tools/virsh.c (info_send_key): Drop example from here.
2011-09-01 12:47:24 -06:00
Eric Blake
691ec08bac virsh: support 'virsh start --force-boot' on older servers
Managed save was added in 0.8.0, virDomainCreateWithFlags in 0.8.2,
and FORCE_BOOT in 0.9.5.  The virsh flag is more useful if we
emulate it for all older servers (note that if a hypervisor fails
the query for a managed save image, then it does not have one to
be removed, so the flag can be safely ignored).

* tools/virsh.c (cmdStart): Add emulation for new flag.
2011-09-01 12:42:48 -06:00
Alex Jia
59d4b170fc virsh: avoid memory leak on cmdVolCreateAs
* tools/virsh.c: fix memory leak on cmdVolCreateAs function.

* Detected in valgrind run:

==4746==
==4746== 48 (40 direct, 8 indirect) bytes in 1 blocks are definitely lost in loss record 26 of 52
==4746==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==4746==    by 0x4C76E51: virAlloc (memory.c:101)
==4746==    by 0x4CD9418: virGetStoragePool (datatypes.c:592)
==4746==    by 0x4D21367: remoteStoragePoolLookupByName (remote_driver.c:4126)
==4746==    by 0x4CE42B0: virStoragePoolLookupByName (libvirt.c:10232)
==4746==    by 0x40C276: vshCommandOptPoolBy (virsh.c:13660)
==4746==    by 0x40CA37: cmdVolCreateAs (virsh.c:8094)
==4746==    by 0x412AF2: vshCommandRun (virsh.c:13770)
==4746==    by 0x422F11: main (virsh.c:15127)
==4746==
==4746== 1,011 bytes in 1 blocks are definitely lost in loss record 45 of 52
==4746==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==4746==    by 0x4A06167: realloc (vg_replace_malloc.c:525)
==4746==    by 0x4C76ECB: virReallocN (memory.c:161)
==4746==    by 0x4C60319: virBufferGrow (buf.c:72)
==4746==    by 0x4C606AA: virBufferAdd (buf.c:106)
==4746==    by 0x40CB37: cmdVolCreateAs (virsh.c:8118)
==4746==    by 0x412AF2: vshCommandRun (virsh.c:13770)
==4746==    by 0x422F11: main (virsh.c:15127)
==4746==
==4746== LEAK SUMMARY:
==4746==    definitely lost: 1,051 bytes in 2 blocks
==4746==    indirectly lost: 8 bytes in 1 blocks
==4746==      possibly lost: 0 bytes in 0 blocks
==4746==    still reachable: 390,767 bytes in 1,373 blocks
==4746==         suppressed: 0 bytes in 0 blocks

* How to reproduce?

% valgrind -v --leak-check=full virsh vol-create-as default foo.img 10M \
  --allocation 0 --format qcow2 --backing-vol bar.img

Notes: bar.img doesn't exist.

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-09-01 12:41:00 -06:00
Jim Fehlig
1282bd80f7 virsh: Expose virDomainMigrateGetMaxSpeed API 2011-09-01 11:26:21 -06:00
Eric Blake
d1535e668a virsh: prefer unsigned flags
virsh had some leftover 'int flags', and even an 'int flag'
declaration, compared to our preferred style of 'unsigned int flags'.

* tools/virsh.c (cmdUndefine, cmdSave, cmdSaveImageDumpxml)
(cmdSaveImageEdit, cmdManagedSave, cmdRestore, cmdDump)
(cmdVcpuPin, cmdSetvcpus, cmdSetmem, cmdSetmaxmem, cmdDumpXML)
(cmdDomXMLFromNative, cmdDomXMLToNative, doMigrate)
(cmdInterfaceEdit, cmdInterfaceDumpXML, cmdEdit): Match coding
style for flags.
(struct vshComdOptDef): Rename field member.
(vshCmddefOptParse, vshCmddefHelp): Adjust clients.
2011-09-01 08:16:57 -06:00
Eric Blake
27c8526053 start: allow discarding managed save
There have been several instances of people having problems with
a broken managed save file, and not aware that they could use
'virsh managedsave-remove dom' to fix things.  Making it possible
to do this as part of starting a domain makes the same functionality
easier to find, and one less API call.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_START_FORCE_BOOT): New
flag.
* src/libvirt.c (virDomainCreateWithFlags): Document it.
* src/qemu/qemu_driver.c (qemuDomainObjStart): Alter signature.
(qemuAutostartDomain, qemuDomainStartWithFlags): Update callers.
* tools/virsh.c (cmdStart): Expose it in virsh.
* tools/virsh.pod (start): Document it.
2011-08-30 09:26:47 -06:00
Eric Blake
131540277e virsh: add list --managed-save
Knowing whether 'virsh start' will resume a saved image or do
a fresh boot is useful enough to expose via 'virsh list'.

Also, translate the state column.

* tools/virsh.c (cmdList): add --managed-save flag
* tools/virsh.pod (list): Document it.
Based on a suggestion by Miklos Vajna.
2011-08-24 08:34:49 -06:00
Osier Yang
fb6d616523 virsh: Substitute goto label out with cleanup
Introduced by 241cbc13a, pushed under urgent rule.
2011-08-23 22:22:51 +08:00
Osier Yang
241cbc13ac virsh: Do not try to free domain if it is NULL
Without these patch, there will be error like below if domain
is NULL.

error: invalid domain pointer in virDomainFree

Which is useless.
2011-08-23 21:42:22 +08:00
Osier Yang
dba7086fc3 virsh: Print error if specified bandwidth is invalid for blockjob
It's strange that the command fails but without any error if one
specifies as not a number.
2011-08-23 14:55:23 +08:00
Eric Blake
baac9c37d7 virsh: properly interleave shared stdout and stderr
Without this patch, invoking 'virsh >file 2>&1' results in
error messages appearing before normal output, even if they
occurred later in time than the normal output (since stderr
is unbuffered, but stdout waits until a full buffer).

* tools/virsh.c (print_job_progress, vshError): Flush between
stream transitions.
* tests/undefine: Test it.
2011-08-19 09:22:22 -06:00
Eric Blake
d89dd42d51 maint: simplify lots of libxml2 clients
Repetitive patterns should be factored.  The sign of a good
factorization is a change that kills 5x more lines than it adds :)

* src/conf/domain_conf.c (virDomainDeviceDefParse)
(virDomainSnapshotDefParseString): Use new convenience macros.
* src/conf/storage_conf.c (virStoragePoolDefParseSourceString):
Likewise.
* src/cpu/cpu.c (cpuCompareXML, cpuBaselineXML): Likewise.
* src/esx/esx_vi.c (esxVI_Context_Execute): Likewise.
* src/qemu/qemu_migration.c (qemuMigrationCookieXMLParseStr):
Likewise.
* src/security/virt-aa-helper.c (caps_mockup): Likewise.
* src/test/test_driver.c (testOpenFromFile): Likewise.
* tests/cputest.c (cpuTestLoadXML, cpuTestLoadMultiXML):
Likewise.
* tools/virsh.c (cmdFreecell, makeCloneXML, cmdVNCDisplay)
(cmdTTYConsole, cmdDetachInterface, cmdDetachDisk)
(cmdSnapshotCreate, cmdSnapshotCreateAs, cmdSnapshotCurrent)
(cmdSnapshotList, cmdSnapshotParent): Likewise.
2011-08-19 09:13:55 -06:00
Eric Blake
e472fe25c7 maint: treat more libxml2 functions as free-like
* cfg.mk (useless_free_options): Add xmlFreeDoc, xmlBufferFree.
* src/esx/esx_vi.c (ESX_VI__TEMPLATE__FREE): Fix offenders.
* tools/virsh.c (cmdFreecell, cmdVNCDisplay, cmdTTYConsole)
(cmdDetachInterface, cmdDetachDisk, cmdSnapshotCreate)
(cmdSnapshotCreateAs, cmdSnapshotList, cmdSnapshotParent):
Likewise.
2011-08-19 09:13:54 -06:00
Eric Blake
531c858131 virsh: concatenate qemu-monitor-command arguments
Call me lazy, but:

virsh qemu-monitor-command dom --hmp info status

is nicer than:

virsh qemu-monitor-command dom --hmp 'info status'

* tools/virsh.c (cmdQemuMonitorCommand): Allow multiple arguments,
for convenience.
2011-08-17 07:45:32 -06:00
Eric Blake
cfbccb3821 virsh: tweak misleading wording
Fixes confusing docs introduced in commit 98369d3.

* tools/virsh.c (cmdSnapshotParent): Operates on named snapshot,
not current.
2011-08-16 17:22:41 -06:00
Eric Blake
e08adab31d virsh: fix dead store
Two copy-and-paste bugs in a row.  :(

* tools/virsh.c (cmdUndefine): Also avoid dead store.
2011-08-12 12:27:06 -06:00
Eric Blake
2cc1ad61c7 virsh: fix logic bug
Bug introduced in commit 9a0ec36.

* tools/virsh.c (cmdUndefine): Add missing line.
2011-08-12 11:39:35 -06:00
Eric Blake
9a0ec36346 virsh: don't reject undefine on active domain
The public API documents that undefine may be used to transition a
running persistent domain into a transient one.  Many drivers still
do not support this usage, but virsh shouldn't be getting in the
way of those that do support it.

This also drops a redundant conditional; vshCommandOptString
guaranteed that name was non-NULL.

* tools/virsh.c (cmdUndefine): Allow undefine on active domains;
the drivers may still reject it, but it is a valid API usage.
* tests/undefine (error): Fix the test to match.
2011-08-12 07:39:25 -06:00
Peter Krempa
594f564c75 virsh: Add dir type for listing volumes with vol-list
Fix of output of detailed volume list. BZ #727088
2011-08-11 13:39:20 -06:00
Eric Blake
98369d314b virsh: add snapshot-parent
Down the road, I want to add virDomainSnapshotGetParent, and use
the new API rather than xml scraping; but this virsh command can
be implemented even without the new API.

* tools/virsh.c (cmdSnapshotParent): New command.
* tools/virsh.pod (snapshot-parent): Document it.
2011-08-11 13:18:24 -06:00
Eric Blake
23b4a3f95b virsh: add virsh snapshot-current --name
Sometimes, full XML is too much; since most snapshot commands
operate on a snapshot name, there should be an easy way to get
at the current snapshot's name.  For example:

virsh snapshot-revert dom `virsh snapshot-current dom --name`

* tools/virsh.c (cmdSnapshotCurrent): Add an option.
* tools/virsh.pod (snapshot-current): Document it.
2011-08-10 21:59:56 -06:00
Eric Blake
6927887829 virsh: fix snapshot-create-as to handle arbitrary names
Found this working on the next patch to use xpath to parse
arbitrary names back out.

* tools/virsh.c (cmdSnapshotCreateAs): Escape user input.
2011-08-10 21:54:20 -06:00
Alex Jia
22da8c941c virsh: fix memory leak in cmdNetworkInfo
* tools/virsh.c: avoid memory leak in cmdNetworkInfo.

* how to reproduce?
  % valgrind -v --leak-check=yes virsh net-info default

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

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-08-02 16:47:39 +08:00
Matthias Bolte
c9ee3d2675 virsh: Fix vol-name and vol-pool commands
This commands don't have a --pool option, so don't tell
vshCommandOptVolBy that there could be one. This made
vshCommandOptString for pooloptname fail and an "missing option"
error was reported.

Make pooloptname optional for vshCommandOptVolBy.
2011-08-01 15:27:55 +02:00
Alex Jia
3f39a0bf27 virsh: avoid missing zero value judgement in cmdBlkiotune
* tools/virsh.c: fix missing zero value judgement in cmdBlkiotune and correct
  vshError information.

  when weight is equal to 0, the cmdBlkiotune will not raise any error information
  when judge weight value first time, and execute else branch to judge weight
  value again, strncpy(temp->field, VIR_DOMAIN_BLKIO_WEIGHT, sizeof(temp->field))
  will be not executed for ever. However, if and only if param->field is equal
  to VIR_DOMAIN_BLKIO_WEIGHT, underlying qemuDomainSetBlkioParameters function
  will check whether weight value is in range [100, 1000].

* how to reproduce?

  % virsh blkiotune ${guestname} --weight 0

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-07-28 08:30:50 -06:00
Alex Jia
1768bf63ed virsh: fix memory leak in cmdVolPath code
* tools/virsh.c: avoid memory leak in cmdVolPath.
* src/libvirt.c: Add doc for virStorageVolGetPath to tell one
  must free() the returned path after use.

* how to reproduce?

% dd if=/dev/zero of=/var/lib/libvirt/images/foo.img count=1 bs=10M
% virsh pool-refresh default
% valgrind -v --leak-check=full virsh vol-path --vol \
/var/lib/libvirt/images/foo.img

* actual results:

Detected in valgrind run:

==16436== 32 bytes in 1 blocks are definitely lost in loss record 7 of 22
==16436==    at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==16436==    by 0x386A314B3D: xdr_string (in /lib64/libc-2.12.so)
==16436==    by 0x3DF8CD770D: xdr_remote_nonnull_string (remote_protocol.c:3
==16436==    by 0x3DF8CD7EC8: xdr_remote_storage_vol_get_path_ret
% virsh pool-refresh default
% valgrind -v --leak-check=full virsh vol-path --vol \
/var/lib/libvirt/images/foo.img

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-07-28 10:42:51 +08:00
Eric Blake
0d0bf8507c virsh: expose change-protection during migration
* tools/virsh.c (doMigrate): Add --change-protection flag.
* tools/virsh.pod (migrate): Document it.
2011-07-27 15:19:32 -06:00
Alex Jia
831c81fcd4 tools: format percent strings of nodecpustats
* tools/virsh.c: format strings display for virsh nodecpustats --percent.

* how to reproduce?

% virsh nodecpustats --percent
usage:            2.0%
    user  :       1.0%
    system:       1.0%
idle  :          98.0%
iowait:           0.0%

* after format strings

% virsh nodecpustats --percent
usage:            2.0%
user:             1.0%
system:           1.0%
idle:            98.0%
iowait:           0.0%

Signed-off-by: Alex Jia <ajia@redhat.com>
2011-07-26 09:57:36 -06:00
Eric Blake
7e853d6c1a virsh: use faster bit search
Now that gnulib gives us ffs, we might as well use it.

* tools/virsh.c (vshCmddefGetData): Use ffs rather than
count_one_bits.
2011-07-25 15:57:51 -06:00
Eric Blake
4b7a8e9c0d virsh: make vcpucount use --current consistently
Rename the existing --current flag to the new name --active,
while adding a new flag --current to expose the new
VIR_DOMAIN_AFFECT_CURRENT flag of virDomainGetVcpusFlags.

For backwards compability, the output does not change (even
though the label "current" no longer matches the spelling of
the option that would trigger that number in isolation), and
we accept "--current --live" as an undocumented synonym for
"--active --live" to avoid breaking any existing clients.

* tools/virsh.c (cmdVcpucount): Add --active flag, and rearrange
existing flag handling to expose VIR_DOMAIN_AFFECT_CURRENT support.
* tools/virsh.pod (vcpucount): Document this.
2011-07-25 15:51:22 -06:00
Adam Litke
b31abc6f03 Enable the virDomainBlockPull API in virsh
Define two new virsh commands:
 * blockpull: Initiate a blockPull for the given disk
 * blockjob: Retrieve progress info, modify speed, and cancel active block jobs

Share print_job_progress() with the migration code.

* tools/virsh.c: implement the new commands
2011-07-22 13:41:55 +08:00
Eric Blake
bfb485ced2 save: add virsh commands for manipulating save files
Now you can edit a saved state file even if you forgot to grab
a dumpxml file prior to saving a domain.  Plus, in-place editing
feels so much nicer.

* tools/virsh.c (cmdSaveImageDumpxml, cmdSaveImageDefine)
(cmdSaveImageEdit): New commands.
* tools/virsh.pod (save-image-dumpxml, save-image-define)
(save-image-edit): Document them.
2011-07-21 17:19:56 -06:00
Eric Blake
38149ec145 save: support --xml to virsh save/restore
Also, migrate was missing documentation for the --xml option
added in commit ec5301cb.

* tools/virsh.c (cmdSave, cmdRestore): Add xml argument.
* tools/virsh.pod (save, restore, migrate): Document it.
2011-07-21 16:24:08 -06:00
Eric Blake
a779d2ff2d save: add --bypass-cache flag to virsh save/restore operations
Wire up the new flag to several virsh commands.  Also, the
'dump' command had undocumented flags.

* tools/virsh.c (cmdSave, cmdManagedSave, cmdDump, cmdStart)
(cmdRestore): Add new flag.
* tools/virsh.pod (save, managedsave, dump, start, restore):
Document flags.
2011-07-21 16:24:08 -06:00
Eric Blake
8e22e08935 build: rename files.h to virfile.h
In preparation for a future patch adding new virFile APIs.

* src/util/files.h, src/util/files.c: Move...
* src/util/virfile.h, src/util/virfile.c: ...here, and rename
functions to virFile prefix.  Macro names are intentionally
left alone.
* *.c: All '#include "files.h"' uses changed.
* src/Makefile.am (UTIL_SOURCES): Reflect rename.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_close): Likewise.
* src/libvirt_private.syms: Likewise.
* docs/hacking.html.in: Likewise.
* HACKING: Regenerate.
2011-07-21 10:34:51 -06:00
Lai Jiangshan
7818b7ef85 send-key: Expose the new API in virsh
Also support string names for the linux keycode(auto detect)
* tools/virsh.c: add new command "send-key"
* tools/virsh.pod: documents the new command
2011-07-21 15:58:31 +08:00
Osier Yang
83e849c197 undefine: Extend virsh undefine to support the new flag
If the domain has managed save image, and --managed-save is
not specified, then it fails with an error telling the user
that a managed save image still exists.

If the domain has managed save image, and --managed-save is
specified, it invokes virDomainUndefineFlags. If
virDomainUndefineFlags fails, then it tries to remove the managed
save image using virDomainManagedSaveRemove first, with
invoking virDomainUndefine following. (For compatibility between
new virsh with this patch and older libvirt without this patch).

Similarly if the domain has no managed save image. See the codes for
detail.

NOTE: Have not removing the codes checking if the domain is running
in function "cmdUndefine", it will go along with qemu driver's fix
(allow to undefine a running domain).
2011-07-20 11:12:46 +08:00
Eric Blake
74594c57f1 Revert "virsh: make migrate --tunnelled imply --p2p"
This reverts commit 40143fb697.

The patch prevents future compatibility if migration ever learns
how to do tunnelled without p2p.
2011-07-19 07:14:43 -06:00
Osier Yang
73d4625a04 virsh: Extend virsh dominfo to display if managed save image exists
* tools/virsh.c: new column "Managed save" for "cmdDominfo".
* tools/virsh.pod: Update document of "managedsave" to tell one can
  use "dominfo" to query whether a domain has any managed save image.
2011-07-19 14:24:57 +08:00
Eric Blake
40143fb697 virsh: make migrate --tunnelled imply --p2p
We can make the virsh migrate UI friendlier by supplying the
missing bit automatically instead of erroring out when requesting
--tunnelled without --p2p.

* tools/virsh.c (doMigrate): Make --p2p optional when using
--tunnelled.
* tools/virsh.pod (migrate): Tweak wording accordingly.
2011-07-18 15:19:55 -06:00
Alex Jia
6f669d4ea5 virsh: avoid double free of domain
* tools/virsh.c: avoid double free of domain, when weight value of blkiotune
  less than 0, codes will free domain and jump to cleanup section, however,
  cleanup will free domain again.

Detected in valgrind run:

==21297== ERROR SUMMARY: 20 errors from 20 contexts (suppressed: 69 from 8)
==21297==
==21297== 1 errors in context 1 of 20:
==21297== Invalid read of size 4
==21297==    at 0x40E209B: virDomainFree (libvirt.c:2096)
==21297==    by 0x8065274: cmdBlkiotune (virsh.c:3695)
==21297==    by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297==    by 0x806B967: main (virsh.c:14487)
==21297==  Address 0x446ad48 is 0 bytes inside a block of size 36 free'd
==21297==    at 0x4005B0A: free (vg_replace_malloc.c:325)
==21297==    by 0x406814D: virFree (memory.c:310)
==21297==    by 0x40D6635: virReleaseDomain (datatypes.c:243)
==21297==    by 0x40D6C5E: virUnrefDomain (datatypes.c:280)
==21297==    by 0x40E20B9: virDomainFree (libvirt.c:2101)
==21297==    by 0x8065297: cmdBlkiotune (virsh.c:3613)
==21297==    by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297==    by 0x806B967: main (virsh.c:14487)
==21297==
==21297==
==21297== 1 errors in context 2 of 20:
==21297== Invalid read of size 4
==21297==    at 0x40E1FE6: virDomainFree (libvirt.c:2092)
==21297==    by 0x8065274: cmdBlkiotune (virsh.c:3695)
==21297==    by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297==    by 0x806B967: main (virsh.c:14487)
==21297==  Address 0x446ad48 is 0 bytes inside a block of size 36 free'd
==21297==    at 0x4005B0A: free (vg_replace_malloc.c:325)
==21297==    by 0x406814D: virFree (memory.c:310)
==21297==    by 0x40D6635: virReleaseDomain (datatypes.c:243)
==21297==    by 0x40D6C5E: virUnrefDomain (datatypes.c:280)
==21297==    by 0x40E20B9: virDomainFree (libvirt.c:2101)
==21297==    by 0x8065297: cmdBlkiotune (virsh.c:3613)
==21297==    by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297==    by 0x806B967: main (virsh.c:14487)

* how to reproduce?
  % valgrind -v --leak-check=full virsh blkiotune guestname --weight -1
2011-07-18 11:19:40 -06:00
Eric Blake
ca92c85756 virsh: improve option handling
The documentation for vshCommandOptString claims that it returns
-1 on a missing required argument, but in reality, that error
message was unreachable (it was buried inside an if clause that
is true only if the argument was present).  The code was so hairy
that I decided a rewrite would make it easier to understand,
and actually return the error values we want.

Meanwhile, our construction guarantees that all vshCmdOpt have
a non-null def member, so there are some redundant checks that
can be trimmed.

* tools/virsh.c (vshCommandOpt): Alter signature.
(vshCommandOptInt, vshCommandOptUInt, vshCommandOptUL)
(vshCommandOptString, vshCommandOptLongLong)
(vshCommandOptULongLong, vshCommandOptBool): Adjust all callers.
(vshCommandOptArgv): Remove dead condition.
2011-07-15 15:58:51 -06:00
Hu Tao
e962a57994 add --cache, --serial, --shareable and --address to attach-disk
This adds four options for virsh command attach-disk.

--cache option allows user to specify cache mode of disk device
from virsh command line when attaching a disk device.

--serial option allows user to specify serial string of disk device
from virsh command line when attaching a disk device.

--shareable option allows user to specify whether the disk device is
shareable between domains when attaching a disk device from virsh
command line.

--address option allows user to specify address of disk device when
attaching a disk device.
2011-07-15 12:14:36 -06:00
Taku Izumi
3807d552c7 setvcpus: add "--current" option to "virsh setvcpus"
This patch adds the --current option to "virsh setvcpus"
command. Currently "virsh setvcpus" command supports
"--live" and "--config" , but "--current" option.
From view of consistency, it's reasonable to support
"--current" option too.

When --current is specified, it affects a "current"
domain.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-07-15 08:19:24 -06:00
Jiri Denemark
f580a33ffd virsh: fix previous patch
The last patch breaks make check for two reasons. First, it reverses the
condition but leaves default level unchanged, so instead of not printing
anything but errors before the patch it now prints all debug messages by
default. Second, you forgot to change -d5 option passed to virsh in
tests/virsh-optparse to -d0; the script wants to see all debug messages.
2011-07-14 07:14:05 -06:00
Supriya Kannery
c1710ca6a0 virsh: Make "DEBUG" loglevel the superset
Aligning loglevel values of virsh to that of libvirt.
"DEBUG"=0 loglevel, when specified through commandline or
env variable, should log all the messages. "ERROR=4"
should log only error messages.

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
2011-07-14 07:06:16 -06:00
Supriya Kannery
2de8aa8fd0 virsh: Avoid using magic numbers for logging
Replace magic numbers with loglevel variables.

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
2011-07-14 07:03:40 -06:00
Eric Blake
0983905c5a virsh, daemon: prefer unsigned flags
* tools/virsh.c (vshCmdDef): Change flags type.
* daemon/remote.c (remoteDispatchOpen): Likewise.
2011-07-13 17:05:10 -06:00
Nan Zhang
23cbf1e0d4 virsh: fix missing prompt message for 'snapshot-delete' command
Make the command 'virsh snapshot-delete' has the appropriate prompt
message when executing sucessful or failed.
2011-07-13 11:28:42 -06:00
Daniel P. Berrange
eb7be6a606 Add a new 'virsh qemu-attach' command.
This command allows libvirt to attach to an existing QEMU
instance.

 $ qemu-kvm -cdrom ~/demo.iso \
     -monitor unix:/tmp/demo,server,nowait \
     -name foo \
     -uuid cece4f9f-dff0-575d-0e8e-01fe380f12ea  &
 $ QEMUPID=$!
 $ virsh qemu-attach $QEMUPID
2011-07-12 15:39:03 +01:00
Eric Blake
085d241531 virsh: make destroy sound less scary
Destroy has a rather negative English connotation.  Try to reduce
the impact, so newbies aren't as scared to use it.

* tools/virsh.c: Tweak all destroy documentation.
* tools/virsh.pod: Likewise.
2011-07-07 13:12:50 -06:00
Eric Blake
8437e738fa build: use gnulib pthread_sigmask
Gnulib finally learned how to do pthread_sigmask on mingw.

* .gnulib: Update to latest, for pthread_sigmask.
* bootstrap.conf (gnulib_modules): Add pthread_sigmask.
* configure.ac (AC_CHECK_FUNCS): Drop redundant check.
* src/rpc/virnetclient.c (virNetClientSetTLSSession)
(virNetClientIOEventLoop): Make code unconditional.
* src/util/command.c (virFork): Likewise.
* tools/virsh.c (doMigrate, cmdMigrate): Likewise.
2011-07-07 13:12:44 -06:00
Eric Blake
cdb0e0dc3f virsh: avoid uninitialized variable
Detected by Coverity; neither vshCmddefHelp nor vshCmdOptParse
was initializing opts_required.

* tools/virsh.c (vshCmddefOptParse): Always initialize bitmaps.
2011-06-30 11:36:51 -06:00
Eric Blake
6f9432fcaf virsh: avoid integer overflow
Detected by Coverity.  info.nrVirtCpu is unsigned short, but if
cpumaplen is int, then the product of the two in vshMalloc risks
unintended sign extension.  cmdVcpuinfo had already solved this
by using size_t cpumaplen.

* tools/virsh.c (cmdVcpuPin): Use correct type.
2011-06-30 11:36:51 -06:00
Osier Yang
e67bc20778 virsh: Fix a problem of buildPoolXML
It doesn't generate "<name>" and "<format>" nodes for "<source>"
even if they are explicitly specified. This patch fixes it.
2011-06-30 21:39:58 +08:00
Matthias Bolte
f0739fc579 Add node prefix to virNodeGet(CPU|Memory)Stats structs and defines 2011-06-28 17:18:33 +02:00
Eric Blake
28e45afc3f build: rename Vcpupin to VcpuPin
We already have a public virDomainPinVcpu, which implies that
Pin and Vcpu are treated as separate words.  Unreleased commit
e261987c introduced virDomainGetVcpupinInfo as the first public
API that used Vcpupin, although we had prior internal uses of
that spelling.  For consistency, change the spelling to be two
words everywhere, regardless of whether pin comes first or last.

* daemon/remote.c: Treat vcpu and pin as separate words.
* include/libvirt/libvirt.h.in: Likewise.
* src/conf/domain_conf.c: Likewise.
* src/conf/domain_conf.h: Likewise.
* src/driver.h: Likewise.
* src/libvirt.c: Likewise.
* src/libvirt_private.syms: Likewise.
* src/libvirt_public.syms: Likewise.
* src/libxl/libxl_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/xen/xend_internal.c: Likewise.
* tools/virsh.c: Likewise.
* src/remote/remote_protocol.x: Likewise.
* src/remote_protocol-structs: Likewise.
Suggested by Matthias Bolte.
2011-06-27 09:55:11 -06:00
Taku Izumi
e0858026a2 vcpupin: add query option to virsh vcpupin command
This patch teaches "virsh vcpupin" command to query if no list
is given. Its feature is to show CPU affinity information in more
reader-friendly way.

 # virsh vcpupin VM --config
 VCPU: CPU Affinity
 ----------------------------------
    0: 1-6,9-20
    1: 10
    2: 5,9-11,15-20
    3: 1,3,5,7,9,11,13,15

When cpulist is omitted, vcpu number is optional. When vcpu number is
provided, information of only specified vcpu is displayed.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-06-24 17:00:22 -06:00
Taku Izumi
ffb552ebf0 vcpuinfo: add the code to fallback to try new API
The "virsh vcpuinfo" command results in failure when the target domain
is inactive on KVM. This patch improves this behavior by adding the
fallback to invoke virDomainGetVcpupinInfo API in case of
virDomainGetVcpus API returns error and the target domain is inactive.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-06-24 17:00:22 -06:00
Eric Blake
f7f5e3e806 Revert "Enable the virDomainBlockPull API in virsh"
This reverts commit 3e2493ce28.
2011-06-24 08:41:24 -06:00
Daniel P. Berrange
3ba937da42 Allow automatic kill of guests when a connection is closed
If an application is using libvirt + KVM as a piece of its
internal infrastructure to perform a specific task, it can
be desirable to guarentee the VM dies when the virConnectPtr
disconnects from libvirtd. This ensures the app can't leak
any VMs it was using. Adding VIR_DOMAIN_START_AUTOKILL as
a flag when starting guests enables this to be done.

* include/libvirt/libvirt.h.in: All VIR_DOMAIN_START_AUTOKILL
* src/qemu/qemu_driver.c: Support automatic killing of guests
  upon connection close
* tools/virsh.c: Add --autokill flag to 'start' and 'create'
  commands
2011-06-24 12:15:10 +01:00
Eric Blake
491858bf3c virsh: avoid bogus description
https://bugzilla.redhat.com/show_bug.cgi?id=682121

Gettext reserves the empty string for internal use, and it must
not be passed through _().  We were violating this for commands
that (for whatever reason) used "" for their description.

* tools/virsh.c (vshCmddefHelp): Don't translate empty string.
Reported by Tatsuo Kawasaki.
2011-06-21 11:46:09 -06:00
Eric Blake
9256ad84fc virsh: enhance snapshot-create-as
Similar to pool-create-as.

* tools/virsh.c (cmdSnapshotCreateAs): Add --print-xml.
* tools/virsh.pod: Document it.
2011-06-20 10:44:08 -06:00
Eric Blake
1546dcf866 virsh: add snapshot-create-as command
Producing an xml file just for name and description fields is
overkill; this makes life easier from virsh.

* tools/virsh.c (cmdSnapshotCreateAs): New command.
(snapshotCmds): Install it.
* tools/virsh.pod: Document it.
2011-06-20 10:44:06 -06:00
Eric Blake
ea71d82816 virsh: clarify snapshot vs. save
* tools/virsh.c (info_snapshot_create, info_save): Clarify
description.
* tools/virsh.pod (save): Likewise.
2011-06-20 10:05:27 -06:00
Daniel P. Berrange
b325768064 Fix compile warnings in virsh vcpupin
The 'char *cur' variable was being assigned from a
'const char *' string, thus discarding constness.
As well as causing a compile warning, it masked a
piece of code which attempts to assign to the
previously const string.

* tools/virsh.c: Fix const-ness of 'cur' variable in vcpupin
2011-06-20 14:50:27 +01:00
Taku Izumi
c4a8ca71b1 vcpupin: add reset option to virsh vcpupin command
When resetting vcpupin setting, we have to specify all host physical
cpus as a cpulist parameter of virsh vcpupin command. It's a little
tedious.

This patch changes to allow to receive the special keyword 'r' as a cpulist
parameter of virsh vcpupin command when resetting vcpupin setting.

If you set the following:

 # virsh vcpupin VM 0 r

the vcpu0 will be pinned to all physical cpus.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-06-20 18:14:54 +08:00
Taku Izumi
2903534a30 vcpupin: improve vcpupin definition of virsh vcpupin
When using vcpupin command, we have to speficy comma-separated list as cpulist,
but this is tedious in case the number of phsycal cpus is large.
This patch improves this by introducing special markup "-" and "^" which are
similar to XML schema of "cpuset" attribute.

The example:

 # virsh vcpupin Guest 0 0-15,^8

 is identical to

 # virsh vcpupin Guest 0 0,1,2,3,4,5,6,7,9,10,11,12,13,14,15

NOTE: The expression is sequentially evaluated, so "0-15,^8" is not identical
to "^8,0-15".

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-06-20 18:14:54 +08:00
Hu Tao
1bb414af27 Add new parameters for blkiotune
Add --config, --live and --current for command blkiotune
2011-06-20 15:52:11 +08:00
Jiri Denemark
5f1bbecb7d virsh: Add support for virDomainGetControlInfo 2011-06-16 19:13:08 +02:00
Eric Blake
a2ff807a68 virsh: reduce complexity in argv iteration
This reduces things from O(n^2) to O(n).

* tools/virsh.c (vshCommandOptArgv): Change signature.
(cmdEcho): Update caller.
Based on a patch by Lai Jiangshan.
2011-06-15 07:43:01 -06:00
Adam Litke
3e2493ce28 Enable the virDomainBlockPull API in virsh
Define two new virsh commands:
 * blockpull: Perform block pull operations (incremental plus start
              and stop continuous streams)
 * blockpullinfo: Retrieve progress info for continuous block pull

Share print_job_progress() with the migration code.

* tools/virsh.c: implement the new commands

Signed-off-by: Adam Litke <agl@us.ibm.com>
2011-06-14 22:28:45 -06:00
Minoru Usui
64609328e0 virNodeGetMemoryStats: Implement virsh support
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
2011-06-14 16:36:13 -06:00
Minoru Usui
7e6cb82d1c virNodeGetCPUStats: Implement virsh support
Signed-off-by: Minoru Usui <usui@mxm.nes.nec.co.jp>
2011-06-14 15:32:37 -06:00
Lai Jiangshan
fb246acfa7 add VSH_OFLAG_REQ_OPT options
A VSH_OFLAG_REQ_OPT option means --optionname is required when used.
It will kill any ambiguity, even a !VSH_OFLAG_REQ option listed before
a VSH_OFLAG_REQ option, if the !VSH_OFLAG_REQ option is a
VSH_OFLAG_REQ_OPT option.

It will help us use optional argument with VSH_OT_ARGV argument.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2011-06-14 11:40:52 -06:00
Lai Jiangshan
6cf77ca7bf allow name for VSH_OT_ARGV options
A name will improve the usege, example

# virsh help echo
  NAME
    echo - echo arguments

  SYNOPSIS
    echo [--shell] [--xml] [<string>]...

  DESCRIPTION
    Echo back arguments, possibly with quoting.

  OPTIONS
    --shell          escape for shell use
    --xml            escape for XML use
    <string>         arguments to echo

"[<string>]..." is added to SYNOPSIS.
"<string>         arguments to echo" is added to OPTIONS.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2011-06-14 11:05:09 -06:00
Michal Privoznik
f67f965077 virsh: Add daemon version reporting
'virsh version' might report against which version of libvirtd is
running.
2011-06-14 10:49:01 +02:00
Osier Yang
41514f7b3e qemu: Parse current balloon value returned by query_balloon
Qemu once supported following memory stats which will returned by
"query_balloon":

    stat_put(dict, "actual", actual);
    stat_put(dict, "mem_swapped_in", dev->stats[VIRTIO_BALLOON_S_SWAP_IN]);
    stat_put(dict, "mem_swapped_out", dev->stats[VIRTIO_BALLOON_S_SWAP_OUT]);
    stat_put(dict, "major_page_faults", dev->stats[VIRTIO_BALLOON_S_MAJFLT]);
    stat_put(dict, "minor_page_faults", dev->stats[VIRTIO_BALLOON_S_MINFLT]);
    stat_put(dict, "free_mem", dev->stats[VIRTIO_BALLOON_S_MEMFREE]);
    stat_put(dict, "total_mem", dev->stats[VIRTIO_BALLOON_S_MEMTOT]);

But it later disabled all the stats except "actual" by commit
07b0403dfc2b2ac179ae5b48105096cc2d03375a.

libvirt doesn't parse "actual", so user will always see a empty result
with "virsh dommemstat $domain". Even qemu haven't disabled the stats,
we should support parsing "actual".
2011-06-14 11:21:35 +08:00
Hu Tao
fbd7820b2c Deprecate several CURRENT/LIVE/CONFIG enums
This patch deprecates following enums:

VIR_DOMAIN_MEM_CURRENT
VIR_DOMAIN_MEM_LIVE
VIR_DOMAIN_MEM_CONFIG

VIR_DOMAIN_VCPU_LIVE
VIR_DOMAIN_VCPU_CONFIG

VIR_DOMAIN_DEVICE_MODIFY_CURRENT
VIR_DOMAIN_DEVICE_MODIFY_LIVE
VIR_DOMAIN_DEVICE_MODIFY_CONFIG

And modify internal codes to use virDomainModificationImpact.
2011-06-13 14:17:16 -06:00
Taku Izumi
9a3404ed71 vcpupin: add the new option to "virsh vcpupin" command
This patch adds the new option (--live, --config and --current) to
"virsh vcpupin" command. The behavior of above aption is the same as
that of "virsh setmem", "virsh setvcpus", and whatnot.
When the --config option is specified, the command affects a persistent
domain, while --live option is specified, it affects a running (live) domain.
The --current option cannot be used with --config or --live at the same
time, and when --current is specified, it affects a "current" domain.
2011-06-13 23:51:04 +08:00
Eric Blake
1eca8c3e8c build: silence coverity false positives
Coverity complained about these intentional fallthrough cases, but
not about other cases that were explicitly marked with nice comments.

For some reason, Coverity doesn't seem smart enough to parse the
up-front English comment in virsh about intentional fallthrough :)

* tools/virsh.c (cmdVolSize): Mark fallthrough in a more typical
fashion.
* src/conf/nwfilter_conf.c (virNWFilterRuleDefDetailsFormat)
(virNWFilterRuleDetailsParse): Mark explicit fallthrough.
2011-06-08 05:30:56 -06:00
Osier Yang
b73f1f8d5c virsh: Expose virDomainMigrateSetMaxSpeed API to virsh
API virDomainMigrateSetMaxSpeed was introduced since 0.9.0, but
no command in virsh yet.
2011-06-08 10:40:57 +08:00
Eric Blake
33d90bafe7 API: consolidate common unreleased enums
This commit is safe precisely because there has been no release
for any of the enum values being deleted (they were added post-0.9.1).

After the 0.9.2 release, we can then take advantage of
virDomainModificationImpact in more places.

* include/libvirt/libvirt.h.in (virDomainModificationImpact): New
enum.
(virDomainSchedParameterFlags, virMemoryParamFlags): Delete, since
these were never released, and the new enum works fine here.
* src/libvirt.c	(virDomainGetMemoryParameters)
(virDomainSetMemoryParameters)
(virDomainGetSchedulerParametersFlags)
(virDomainSetSchedulerParametersFlags): Update documentation.
* src/qemu/qemu_driver.c (qemuDomainSetMemoryParameters)
(qemuDomainGetMemoryParameters, qemuSetSchedulerParametersFlags)
(qemuSetSchedulerParameters, qemuGetSchedulerParametersFlags)
(qemuGetSchedulerParameters): Adjust clients.
* tools/virsh.c (cmdSchedinfo, cmdMemtune): Likewise.
Based on ideas by Daniel Veillard and Hu Tao.
2011-06-04 09:58:53 +02:00
Eric Blake
72519f7331 docs: document iface-* commands
I intentionally set things up so 'virsh help interface' lists
commands in alphabetical order, but 'man virsh' lists them in
topical order; this matches our practice on some other commands.

* tools/virsh.pod: Document all iface commands.
* tools/virsh.c (ifaceCmds): Sort.
2011-06-02 13:29:12 -06:00
Michal Privoznik
3ef7350c42 screenshot: Expose the new API in virsh
* tools/virsh.c: Add screenshot command
* tools/virsh.pod: Document new command
* src/libvirt.c: Fix off-be-one error
2011-06-02 14:57:00 +02:00
Daniel P. Berrange
ef983dfe5a Fix sysinfo/virsh build problems on Win32
The virSysinfoIsEqual method was mistakenly inside a #ifndef WIN32
conditional.

The existing virSysinfoFormat is also stubbed out on Win32, even
though the code works without any trouble. This breaks XML output
on Win32, so the stub is removed.

virsh migrate mistakenly had some variables inside the conditional

* src/util/sysinfo.c: Build virSysinfoIsEqual on Win32 and remove
  Win32 stub for virSysinfoFormat
* tools/virsh.c: Fix variable declaration on Win32
2011-05-31 14:17:21 +01:00
Daniel P. Berrange
ec5301cb85 Allow virsh to pass in a custom XML document for migration
Switch virsh migrate over to use virDomainMigrate2 and
virDomainMigrateToURI2. This is still compatible with
older libvirts, because these methods dynamically choose
whether to perform v1, v2 or v3 migration based on declared
RPC support from the libvirtd instances

Add a --xml arg which allows the user to pass in a custom
XML document. This XML document must be ABI compatible
with the current *live* XML document for the running guest
on the source host. ABI compatibility will be enforced by
any driver supporting this function

* tools/virsh.c: Add '--xml' arg to migrate command
2011-05-31 12:14:57 +01:00
Eric Blake
97f63513ff virsh: improve schedinfo querying ability
Since we can now set just --live or --config, we also need to be
able to query that back.

In the case of setting both --live and --config, it shouldn't matter
which value we read back; otherwise, since querying treats the two
flags as mutually exclusive, so does this patch.

* tools/virsh.c (cmdSchedinfo): Use new API where appropriate.
2011-05-29 18:51:16 +08:00
Eric Blake
163e5f04ef maint: prefer newer API names internally
Rather mechanical in nature.

* src/driver.h: Use newer virTypedParameter API names.
* src/libvirt.c: Likewise.
* daemon/remote.c: Likewise.
* src/esx/esx_driver.c: Likewise.
* src/libxl/libxl_driver.c: Likewise.
* src/lxc/lxc_driver.c: Likewise.
* src/qemu/qemu_driver.c: Likewise.
* src/remote/remote_driver.c: Likewise.
* src/test/test_driver.c: Likewise.
* src/xen/xen_driver.c: Likewise.
* src/xen/xen_hypervisor.c: Likewise.
* src/xen/xen_hypervisor.h: Likewise.
* src/xen/xend_internal.c: Likewise.
* tools/virsh.c: Likewise.
2011-05-29 18:26:31 +08:00
Michal Privoznik
761d1880be interface: expose network config transaction API to virsh
This implements the commands iface-begin, iface-commit, and iface-rollback,
which simply call the corresponding functions in the libvirt API.
2011-05-27 14:29:25 -04:00
Hu Tao
118eac373d Add new flags for setting memory parameters
The new flags allow to pick current state, config or the live
parameter, with current being the existing API default (0).
This also hooks this to --config, --live, --current parameters for
the memtune virsh command

* include/libvirt/libvirt.h.in: defines the new flags
* tools/virsh.c: adds support at virsh level
* tools/virsh.pod: updates virsh documentation
2011-05-27 15:35:11 +08:00
Matthias Bolte
6df05081cb virsh: time_t is not a long on FreeBSD
localtime_r expects time_t.
2011-05-25 18:47:50 +02:00
Supriya Kannery
3c36f936b9 virsh: Use Env variables for debug level and logfile
Use variables VIRSH_DEBUG and VIRSH_LOG_FILE for controlling virsh logging.

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
2011-05-19 17:53:46 -06:00
Eric Blake
d218344e6c virsh: optimize creation of default connection
Ramon de Carvalho Valle reported a problem with:
virsh connect qemu:///system
as a non-root user.  The real root problem appears to be a regression
in libvirtd being auto-started on the default qemu:///session URI;
however, the symptom points to an independent flaw in virsh - we
shouldn't be wasting efforts on making a connection if we aren't going
to be using that connection.  Fixing virsh avoids Ramon's issue, while
I work in the meantime to fix the real libvirtd regression.

This patch looks big, but that's because 'gcc -Wmissing-field-initializers'
gets triggered by './autobuild.sh --enable-compile-warnings=error', so I
had to add 0 initialization to everyone (rather than my preference of
just adding the non-zero flags to virshCmds and to cmdConnect).

Meanwhile, if you use 'virsh -c URI', the connection must succeed; this
patch _only_ optimizes the default connection to be deferred to a later
point where we know if a particular command to be run needs a connection.

* tools/virsh.c (VSH_CMD_FLAG_NOCONNECT): New flag.
(vshCmdDef): Add new flags field.
(vshCommandRun): Honor new flag.
(domManagementCmds, domMonitoringCmds, storagePoolCmds)
(storageVolCmds, networkCmds, nodedevCmds, ifaceCmds)
(nwfilterCmds, secretCmds, virshCmds, snapshotCmds)
(hostAndHypervisorCmds): Populate new field.
(vshReconnect): Don't warn on initial connection.
2011-05-18 12:47:46 -06:00