Commit Graph

727 Commits

Author SHA1 Message Date
Peter Krempa
bf72095954 virsh: Report errors if arguments of the schedinfo command are incorrect
Libvirt's helper API's when called directly don't raise the error so
that virsh remembers it. Subsequent calls to libvirt API's might reset
the error.

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

This patch adds function vshSaveLibvirtError() that can be called after
calling libvirt helper APIs to ensure the error is remembered.
2012-12-03 16:37:10 +01:00
Ján Tomko
8b235d4057 virsh: do timing even for unusable connections
Time values were uninitialized if the connection wasn't usable.
2012-11-29 10:10:08 -07:00
Eric Blake
9d91a18ebf virsh: make ,, escape parsing common
So far, none of the existing callers of vshStringToArray expected
the user to ever pass a literal comma; meanwhile, snapshot parsing
had rolled its own array parser.  Moving the comma escaping into
the common function won't affect any existing callers, and will make
this function reusable for adding memory handling to snapshot parsing.

As a bonus, the testsuite was already testing snapshot parsing, so
the fact that the test still passes means that we are now giving
testsuite exposure to vshStringToArray.

* tools/virsh-snapshot.c (vshParseSnapshotDiskspec): Move ,,
parsing...
* tools/virsh.c (vshStringToArray): ...into common function.
Also, vshStrdup can't fail.
2012-11-07 09:01:37 -07:00
Daniel P. Berrange
1c04f99970 Remove spurious whitespace between function name & open brackets
The libvirt coding standard is to use 'function(...args...)'
instead of 'function (...args...)'. A non-trivial number of
places did not follow this rule and are fixed in this patch.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-11-02 13:36:49 +00:00
Eric Blake
4dbd6e9654 build: prefer mkostemp for multi-thread safety
https://bugzilla.redhat.com/show_bug.cgi?id=871756

Commit cd1e8d1 assumed that systems new enough to have journald
also have mkostemp; but this is not true for uclibc.

For that matter, use of mkstemp[s] is unsafe in a multi-threaded
program.  We should prefer mkostemp[s] in the first place.

* bootstrap.conf (gnulib_modules): Add mkostemp, mkostemps; drop
mkstemp and mkstemps.
* cfg.mk (sc_prohibit_mkstemp): New syntax check.
* tools/virsh.c (vshEditWriteToTempFile): Adjust caller.
* src/qemu/qemu_driver.c (qemuDomainScreenshot)
(qemudDomainMemoryPeek): Likewise.
* src/secret/secret_driver.c (replaceFile): Likewise.
* src/vbox/vbox_tmpl.c (vboxDomainScreenshot): Likewise.
2012-10-31 10:06:10 -06:00
Doug Goldstein
5a33366f5c interface: add udev based backend for virInterface
Add a read-only udev based backend for virInterface. Useful for distros
that do not have netcf support yet. Multiple libvirt based utilities use
a HAL based fallback when virInterface is not available which is less
than ideal. This implements:
* virConnectNumOfInterfaces()
* virConnectListInterfaces()
* virConnectNumOfDefinedInterfaces()
* virConnectListDefinedInterfaces()
* virConnectListAllInterfaces()
* virConnectInterfaceLookupByName()
* virConnectInterfaceLookupByMACString()
2012-10-09 09:39:43 -06:00
Eric Blake
4ecb723b9e maint: fix up copyright notice inconsistencies
https://www.gnu.org/licenses/gpl-howto.html recommends that
the 'If not, see <url>.' phrase be a separate sentence.

* tests/securityselinuxhelper.c: Remove doubled line.
* tests/securityselinuxtest.c: Likewise.
* globally: s/;  If/.  If/
2012-09-20 16:30:55 -06:00
Doug Goldstein
6a1b0e37af virsh: Move daemon to misc since its not a network
Move the 'Daemon' entry to the Miscellaneous section since its not a
networking driver or component.
2012-09-19 14:19:45 -06:00
Doug Goldstein
b95ad92e05 build: define WITH_INTERFACE for the driver
Based exclusively on work by Eric Blake in a patch posted with the same
subject. However some modifications related to comments and my plans to
add another backend.

Added WITH_INTERFACE as the only automake variable deciding whether to
build the driver and using WITH_NETCF to identify that we're wanting to
use the netcf library as the backend.

* configure.ac: Added with_interface
* src/interface/netcf_driver.c: Renamed..
* src/interface/interface_backend_netcf.c: ..to this to match storage.
* src/interface/netcf_driver.h: Renamed..
* src/interface/interface_driver.h: ..to this.
* daemon/Makefile.am: Respect WITH_INTERFACE and WITH_NETCF.
* libvirt.spec.in: Add RPM support for --with-interface
2012-09-19 08:27:01 -06:00
Doug Goldstein
c88a4f2a46 virsh: Rename QEmu to QEMU to match upstream
Match upstream's naming of QEMU. There was a notice on the ML that said
the preferred spelling was QEMU a while back.
2012-09-19 06:59:19 -06:00
Osier Yang
f5fb059a78 virsh: Don't motify the const string
This improve helper vshStringToArray to accept const string as
argument instead. To not convert the const string when using
vshStringToArray, and thus avoid motifying it.
2012-09-17 11:29:31 +08:00
Osier Yang
f7eac4f722 list: Add helper to convert strings separated by ', ' to array
tools/virsh.c: New helper function vshStringToArray.
tools/virsh.h: Declare vshStringToArray.
tools/virsh-domain.c: use the helper in cmdUndefine.
2012-09-06 22:04:43 +08:00
Eric Blake
44342a0efe build: use re-entrant functions in virsh
Yesterday's commit 15d2c9f pointed out that virsh was still using
localtime(), which is not thread-safe, even though virsh is
definitely multi-threaded.  Even if we only ever triggered it from
one thread, it's better safe than sorry for maintenance purposes.

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

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

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

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

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

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

vshConnectionUsability() no longer needs to be exported and this patch
marks it static.
2012-08-31 16:22:22 +02:00
Peter Krempa
70e608918e virsh: Improve checking for connection when running commands
Almost each virsh command uses the function vshConnectionUsability
before doing anything, to check if the connection is "alive".  Commands
that don't need an conection are already conveniently marked with
VSH_CMD_FLAG_NOCONNECT. We can automaticaly check for the connection
before calling any remote command so we don't forget to do so.

This patch also upgrades the connection check to use virConnectIsAlive
along with the current approach.
2012-08-31 16:22:22 +02:00
Viktor Mihajlovski
641d406d27 virsh: fixed incorrect timing report
When executing virsh -t <command> the reported timing was off
by 3 orders of magnitude if the command took more than one
second.

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2012-08-31 20:00:20 +08:00
Eric Blake
f95f1ba4c0 virsh: split out virsh-volume.c
Last of the file splits.

* tools/virsh-volume.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-volume.c: Likewise.
(vshCommandOptVolBy): Fix flag usage.
2012-08-21 00:23:12 -06:00
Eric Blake
c0dbd5f352 virsh: split out virsh-snapshot.c
Almost done with the splits.

* tools/virsh-snapshot.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-snapshot.c: Likewise.
2012-08-21 00:19:10 -06:00
Eric Blake
9cbb0eda92 virsh: split out virsh-secret.c
One of the simpler splits.

* tools/virsh-secret.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-secret.c: Likewise.
2012-08-21 00:16:35 -06:00
Eric Blake
ef8d35830c virsh: split out virsh-pool.c
More in a series of file splits.

* tools/virsh-pool.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-pool.c: Likewise.
(virCommandOptPoolBy): Fix flag usage.
2012-08-21 00:11:29 -06:00
Eric Blake
69af4f7cb8 virsh: split out virsh-nwfilter.c
Yet another split file.

* tools/virsh-nwfilter.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-nwfilter.c: Likewise.
2012-08-21 00:07:30 -06:00
Eric Blake
ea3cf921f2 virsh: split out virsh-nodedev.c
Another worthwhile split, needed one more public function.

* tools/virsh-nodedev.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh-nodedev.c: Use new header.
* tools/virsh.c: Likewise.
(vshTreePrint): Export.
* tools/virsh.h (vshTreePrint): Declare.
2012-08-21 00:05:53 -06:00
Eric Blake
dcff981a70 virsh: split out virsh-network.c
Another relatively easy file split.

* tools/virsh-network.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-network.c: Likewise.
(vshCommandOptNetworkBy): Update signature.
2012-08-21 00:02:09 -06:00
Eric Blake
7aeb16a8c0 virsh: split out virsh-interface.c
Another relatively easy split, since helper functions were fixed
in the previous patch.

* tools/virsh-interface.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.c: Use new header.
* tools/virsh-interface.c: Likewise.
(vshCommandOptInterfaceBy): Check flags.
2012-08-20 23:59:06 -06:00
Eric Blake
4c10b3c7da virsh: declare more common functions
In preparation for splitting virsh-interface.c, I found these
functions need to be declared in virsh.h, as well as one that
belongs more properly in virsh-domain.h.  Also, since we
use the VSH_BY* flags in more than one function, I improved
how they are used.

* tools/virsh.h (vshNameSorter, vshCmdHasOption): Declare.
(VSH_BYID): Turn into enum.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.h): ...here.
* tools/virsh.c: (vshNameSorter): Export.
(cmd_has_option): Rename...
(vshCmdHasOption): ...and export.
(vshCommandOptDomainBy): Move...
* tools/virsh-domain.c (vshCommandOptDomainBy): ...here, adjust
signature, and check flags.
* tools/virsh-network.c (vshCommandOptNetworkBy): Update callers.
* tools/virsh-nwfilter.c (vshCommandOptNWFilterBy): Likewise.
* tools/virsh-secret.c (vshCommandOptSecret): Likewise.
* tools/virsh-domain-monitor.c (includes): Likewise.
* tools/virsh-host.c (includes): Likewise.
2012-08-20 23:56:18 -06:00
Eric Blake
ae8e89fb12 virsh: split out virsh-host.c
The splits are getting easier, with fewer cleanups needed in virsh.h.

* tools/virsh-host.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh-host.c: Use new header.
* tools/virsh.c: Likewise.
2012-08-20 23:51:29 -06:00
Eric Blake
99ae57f841 virsh: split out virsh-domain-monitor.c
Another file worth compiling on its own instead of by .c inclusion.

* tools/virsh-domain-monitor.h: New file.
* tools/Makefile.am (virsh_SOURCES): Build it.
* tools/virsh.h (vshGetDomainDescription): Move to correct
header.
* tools/virsh-domain-monitor.c: Use new header.
* tools/virsh.c: Likewise.
* tools/virsh-domain.c: Likewise.
2012-08-20 23:39:54 -06:00
Eric Blake
521b7ab7eb virsh: drop unused headers
The previous commit now trips up 'make syntax-check' due to a useless
use of <signal.h>.

* tools/virsh.c (includes): Drop useless includes.
2012-08-20 09:57:38 -06:00
Daniel P. Berrange
6a48179803 Fix build of virsh on Win32 by moving SA_SIGINFO stub
On Win32 SA_SIGINFO is not defined, so virsh.c stub'd it out
to 0, but recent changes moved the usage out of virsh.c and
into virsh-domain.c
2012-08-20 16:00:29 +01:00
Eric Blake
e68ee5e765 virsh: use common namespacing
Convert the exported items in virsh.h to use a common 'vsh' prefix.

* tools/virsh.h (VIRSH_MAX_XML_FILE): Rename...
(VSH_MAX_XML_FILE): ...and parenthesize.
(DIFF_MSEC, CTRL_CLOSE_BRACKET): Delete.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Remove prototype.
(editWriteToTempFile, editFile, editReadBackFile, prettyCapacity)
(virshReportError): Rename...
(vshEditWriteToTempFile, vshEditFile, vshEditReadBackFile)
(vshPrettyCapacity, vshReportError): ...into vsh namespace.
(jobWatchTimeoutFunc): Move to virsh-domain.c.
* tools/virsh.c (vshCommandRun): Inline former DIFF_MSEC.
(main): Inline former CTRL_CLOSE_BRACKET.
(vshUsage, vshInit, vshDeinit, vshParseArgv): Make static.
(prettyCapacity, virshReportError, editWriteToTempFile, editFile):
Fix naming, and adjust usage.
(vshAskReedit, vshCommandRun, vshEventLoop, vshInit): Adjust
usage.
* tools/virsh-domain.c (cmdAttachDevice, cmdCPUCompare)
(cmdCPUBaseline, cmdCreate, cmdDefine, cmdDetachDevice)
(cmdUpdateDevice, cmdDesc, cmdUndefine, cmdStart, cmdVcpucount)
(cmdAttachDevice, cmdDomjobinfo): Likewise.
* tools/virsh-edit.c (do): Likewise.
* tools/virsh-interface.c (cmdInterfaceDefine): Likewise.
* tools/virsh-network.c (cmdNetworkCreate, cmdNetworkDefine):
Likewise.
* tools/virsh-nodedev.c (cmdNodeDeviceCreate): Likewise.
* tools/virsh-nwfilter.c (cmdNWFilterDefine): Likewise.
* tools/virsh-pool.c (cmdPoolCreate, cmdPoolDefine)
(cmdPoolDiscoverSources, cmdPoolList): Likewise.
* tools/virsh-secret.c (cmdSecretDefine): Likewise.
* tools/virsh-snapshot.c (cmdSnapshotCreate, vshSnapshotCreate)
(vshLookupSnapshot, cmdSnapshotEdit, cmdSnapshotCurrent)
(vshGetSnapshotParent): Likewise.
* tools/virsh-volume.c (cmdVolCreate, cmdVolCreateFrom)
(cmdVolInfo, cmdVolList): Likewise.
2012-08-20 07:04:10 -06:00
Daniel P. Berrange
ee7b4e551e Make Win32 stub of vshAskReedit non-static
The main impl of vshAskReedit is non-static, so the Win32
stub must be the same
2012-08-20 13:29:14 +01:00
Eric Blake
6d96fab9cf virsh: kill some double underscores
C99 says that __foo naming is reserved for the compiler.  Besides,
we had several different styles in use; this consolidates things
to set up the typedefs up front then declare the types with
consistent naming.

* tools/virsh.h: Use consistent struct naming.
* tools/virsh.c (_vshCommandParser): Likewise.
2012-08-18 08:10:02 -06:00
Eric Blake
f4a7b87de0 virsh: split out virsh-domain.c
The virsh-domain.c file was pretty self-contained; the only
entry point was the table of command definitions.  The bulk
of this patch is making more functions in virsh.c reusable.
A later patch will clean up poor naming choices.

* tools/Makefile.am (virsh_SOURCES): Build virsh-domain.c.
* tools/virsh-domain.h: New file.
* tools/virsh.h (virshReportError, vshResetLibvirtError)
(vshAskReedit, vshStreamSink): Declare.
* tools/virsh.c: Switch from using .c to .h.
(virshReportError, vshResetLibvirtError, vshAskReedit)
(vshStreamSink, prettyCapacity): Export.
(vshCatchInt): Move...
* tools/virsh-domain.c: ...into sole user.  Use header.
2012-08-17 22:22:42 -06:00
Eric Blake
c2e494cc57 virsh: split out virsh.h
Having one .c file include another does not give any compilation
benefits; move towards modular .o files by first splitting out
reused declarations into a new virsh.h.  This patch doesn't try
very hard to see which functions are used or not, to make it
easier to review the file split.  Future patches can further trim
the header to be smaller.

* tools/Makefile.am (virsh_SOURCES): List new file, and prepare
for others.
* tools/virsh.c: Split declarations...
* tools/virsh.h: ...into new file, and make several functions
non-static.
* tools/virsh-domain-monitor.c (vshGetDomainDescription): Make
non-static.
2012-08-17 21:54:42 -06:00
Eric Blake
8e8809e131 virsh: move vshWatchJob earlier
It's easier to order things in topological order than it is to
forward declare in one file for use only by one other file.

* tools/virsh.c (vshWatchJob, parseRateStr)
(vshDomainStateToString, vshDomainStateReasonToString)
(vshDomainControlStateToString, vshDomainVcpuStateToString): Drop
useless prototypes.
* tools/virsh-domain.c (vshWatchJob): Move earlier.
2012-08-17 21:44:14 -06:00
Osier Yang
be023c0896 virsh: Add helper to avoid the strcase check for virsh-*.c
* tools/virsh.c: New macro vshStrcasecmp
* tools/virsh-domain-monitor.c: Use vshStrcasecmp instead of
                                strcasecmp
* tools/virsh-snapshot.c: Likewise
* cfg.mk: Only avoid doing strcase checking for virsh.c
2012-08-15 15:07:37 +08:00
Osier Yang
bb705e2519 Destroy virdomainlist.[ch]
As the consensus in:
https://www.redhat.com/archives/libvir-list/2012-July/msg01692.html,
this patch is to destroy conf/virdomainlist.[ch], folding the
helpers into conf/domain_conf.[ch].

* src/Makefile.am:
  - Various indention fixes incidentally
  - Add macro DATATYPES_SOURCES (datatypes.[ch])
  - Link datatypes.[ch] for libvirt_lxc

* src/conf/domain_conf.c:
  - Move all the stuffs from virdomainlist.c into it
  - Use virUnrefDomain and virUnrefDomainSnapshot instead of
    virDomainFree and virDomainSnapshotFree, which are defined
    in libvirt.c, and we don't want to link to it.
  - Remove "if" before "free" the object, as virObjectUnref
    is in the list "useless_free_options".

* src/conf/domain_conf.h:
  - Move all the stuffs from virdomainlist.h into it
  - s/LIST_FILTER/LIST_DOMAINS_FILTER/

* src/libxl/libxl_driver.c:
  - s/LIST_FILTER/LIST_DOMAINS_FILTER/
  - no (include "virdomainlist.h")

* src/libxl/libxl_driver.c: Likewise

* src/lxc/lxc_driver.c: Likewise

* src/openvz/openvz_driver.c: Likewise

* src/parallels/parallels_driver.c: Likewise

* src/qemu/qemu_driver.c: Likewise

* src/test/test_driver.c: Likewise

* src/uml/uml_driver.c: Likewise

* src/vbox/vbox_tmpl.c: Likewise

* src/vmware/vmware_driver.c: Likewise

* tools/virsh-domain-monitor.c: Likewise

* tools/virsh.c: Likewise
2012-08-14 17:27:49 +08:00
Cole Robinson
86157b594f virsh: make 'help' command ignore spurious options
Similar to the previous patch, prepending 'help' to a partial
command string doesn't cut us any slack.

$ virsh help pool-define-as --name foo --type dir
error: command 'help' doesn't support option --name

This patch adds a few hacks to make 'help' ignore everything after the
first data bit, so the above command shows help output for pool-define-as.
2012-08-13 15:33:44 -04:00
Cole Robinson
d2f971390e virsh: Convert '<cmd> --help' to 'help <cmd>'
Often times I find myself halfway through typing a long command when
I want to see 'help' output. I instinctively append '--help' to the
command I'm typing, only to get an error:

    $ virsh vol-create-as foo --help
    error: command 'vol-create-as' doesn't support option --help

This patch makes --help work in a pretty hacky way. One missing piece
here is that --help isn't listed as an option in the actual 'help <cmd>'
output, but maybe this can be a starting point for someone.
2012-08-13 15:33:44 -04:00
Cole Robinson
e7d1bdfbd2 virsh.c: Fix compiler warning
For some reason I only get this after applying subsequent upcoming
patches that touch virsh, but don't seem to actually cause the warning.

virsh.c: In function ‘vshCommandParse’:
virsh.c:2014:46: error: ‘opt_index’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
cc1: all warnings being treated as errors
2012-08-13 15:33:44 -04:00
Michal Privoznik
54b6334714 virsh: Switch to close callback
Since we've introduced close callbacks we can drop this SIGINT magic
(which doesn't work now neither) and fully utilize the new feature.
2012-08-02 19:15:16 +02:00
Osier Yang
a4bcefbcff maint: Use consistent copyright.
This is a follow up patch of commit f9ce7dad6, it modifies all
the files which declare the copyright like "See COPYING.LIB for
the License of this software" to use the detailed/consistent one.

And deserts the outdated comments like:

 * libvirt-qemu.h:
 * Summary: qemu specific interfaces
 * Description: Provides the interfaces of the libvirt library to handle
 *              qemu specific methods
 *
 * Copy:  Copyright (C) 2010, 2012 Red Hat, Inc.

Uses the more compact style like:

 * libvirt-qemu.h: Interfaces specific for QEMU/KVM driver
 *
 * Copyright (C) 2010, 2012 Red Hat, Inc.
2012-07-27 18:27:21 +08:00
Peter Krempa
3df9626c40 virsh: Refactor error clearing on graceful fallback paths
Virsh uses an error handler to save errors from libvirt. On some code
paths it's needed to clear libvirt errors and continue on fallback code
paths without reporting failure.

This patch adds function vshResetLibvirtError() that clears error
returned by libvirt and updates all places where the old two-line method
was used.
2012-07-27 10:28:22 +02:00
Ján Tomko
4fedf388f6 virsh: check if specified debug level is in range 2012-07-26 08:21:04 -06:00
Osier Yang
c4bdf307e0 virsh: Move command group definition into its own file
* virsh-domain-monitor.c: Add domMonitoringCmds
* virsh-domain.c: Add domManagementCmds
* virsh-host.c: Add hostAndHypervisorCmds
* virsh-interface.c: Add ifaceCmds
* virsh-network.c: Add networkCmds
* virsh-nodedev.c: Add nodedevCmds
* virsh-nwfilter.c: Add nwfilterCmds
* virsh-pool.c: Add storagePoolCmds
* virsh-secret.c: Add secretCmds
* virsh-snapshot.c: Add snapshotCmds
* virsh-volume.c: Add storageVolCmds
* virsh.c: Remove all the above *Cmds.
2012-07-26 12:00:43 +08:00
Osier Yang
49989d7025 virsh: Split cmds in node device group from virsh.c
Commands in node device group moved from virsh.c to virsh-nodedev.c,

* virsh.c: Remove commands in node device group.
* virsh-nodedev.c: New file, filled with commands in node device group
* po/POTFILES.in: Add virsh-nodedev.c
* cfg.mk: Skip to check config.h including for virsh-nodedev.c
2012-07-26 12:00:43 +08:00
Osier Yang
290eb0d9f2 virsh: Split cmds in host group from virsh.c
Commands in host group moved from virsh.c to virsh-host.c,

* virsh.c: Remove commands in host group.
* virsh-host.c: New file, filled with commands in host group
* po/POTFILES.in: Add virsh-host.c
* cfg.mk: Skip to check config.h including for virsh-host.c
2012-07-26 12:00:43 +08:00
Osier Yang
648ad2471b virsh: Split cmds to manage domain snapshot from virsh.c
Commands to manage domain snapshot are moved from virsh.c to
virsh-snapshot.c.

* virsh.c: Remove domain snapshot commands.
* virsh-snapshot.c: New file, filled with domain snapshot commands.
* po/POTFILES.in: Add virsh-snapshot.c
* cfg.mk: Skip strcase and config.h including checking for
          virsh-snapshot.c
2012-07-26 12:00:43 +08:00
Osier Yang
d7acdcf093 virsh: Split cmds to manage secret from virsh.c
Commands to manage secret are moved from virsh.c to virsh-secret.c,
with a few helpers for secret command use.

* virsh.c: Remove secret commands and a few helpers.
           (vshCommandOptSecret, and vshCommandOptSecretBy)
* virsh-secret.c: New file, filled with secret commands and its helpers.
* po/POTFILES.in: Add virsh-secret.c
* cfg.mk: Skip to check config.h including for virsh-secret.c
2012-07-26 12:00:43 +08:00
Osier Yang
e9d10055df virsh: Split cmds to manage network filter from virsh.c
Commands to manage network filter are moved from virsh.c to virsh-nwfilter.c,
with a few helpers for network filter command use.

* virsh.c: Remove network filter commands and a few helpers.
           (vshCommandOptNWFilter, and vshCommandOptNWFilterBy)
* virsh-nwfilter.c: New file, filled with network filter commands and its helpers.

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

* cfg.mk: Skip to check config.h including for virsh-nwfilter.c
2012-07-26 12:00:42 +08:00
Osier Yang
0c39ea2fa5 virsh: Split cmds to manage host interface from virsh.c
Commands to manage host interface are moved from virsh.c to
virsh-interface.c, with a few helpers for interface command use.

* virsh.c: Remove interface commands and a few helpers.
           (vshCommandOptInterface, vshCommandOptInterfaceBy)
* virsh-interface.c: New file, filled with interface commands and
                     its helpers.
* cfg.mk: Skip to check config.h including for virsh-interface.c
* po/POTFILES.in: Add virsh-interface.c
2012-07-26 12:00:27 +08:00
Osier Yang
0510f97e73 virsh: Split cmds to manage network from virsh.c
Commands to manage network are moved from virsh.c to virsh-network.c,
with a few helpers for network command use.

* virsh.c: Remove network commands and a few helpers.
* virsh-network.c: New file, filled with network commands and its
                   helpers.
* po/POTFILES.in: Add virsh-network.c
* cfg.mk: Skip to check config.h including for virsh-network.c
2012-07-26 11:57:58 +08:00
Osier Yang
2f033890c6 virsh: Split cmds of storage pool group from virsh.c
This splits commands of storage pool group into virsh-pool.c,
The helpers not for common use are moved too. Standard copyright
is added for the new file.

* tools/virsh.c:
  Remove commands for storage storage pool and a few helpers.
  (vshCommandOptVol, vshCommandOptVolBy).

* tools/virsh-pool.c:
  New file, filled with commands of storage pool group and its
  helpers.

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

* cfg.mk:
  Skip to check config.h including for virsh-pool.c
2012-07-26 11:57:51 +08:00
Osier Yang
9fbb344f6e virsh: Split cmds of storage volume group from virsh.c
This splits commands of storage volume group into virsh-volume.c,
The helpers not for common use are moved too. Standard copyright
is added for the new file.

* tools/virsh.c:
  Remove commands for storage storage volume and a few helpers.
  (vshCommandOptVol, vshCommandOptVolBy).

* tools/virsh-volume.c:
  New file, filled with commands of storage volume group and its
  helpers.

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

* cfg.mk:
  Skip to check config.h including for virsh-volume.c
2012-07-26 11:57:42 +08:00
Osier Yang
73b89ed838 virsh: Split cmds of domain group from virsh.c
This splits commands to manage domain into virsh-domain.c,The helpers
not for common use are moved into them too. Standard copyright is added
for the new file.

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

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

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

* cfg.mk:
  - Skip to check config.h including for virsh-domain.c
2012-07-26 11:57:18 +08:00
Osier Yang
9f4baa222e virsh: Split cmds for domain monitoring from virsh.c
This splits commands commands to monitor domain status into
virsh-domain-monitor.c. The helpers not for common use are moved too.
Standard copyright is added.

* tools/virsh.c:
  - Remove commands for domain monitoring group and a few helpers (
    vshDomainIOErrorToString, vshGetDomainDescription,
    vshDomainControlStateToString, vshDomainStateToString) not for
    common use.
  - Remove (incldue "intprops.h").

* tools/virsh-domain-monitor.c:
  - New file, filled with commands of domain monitor group.
  - Add "intprops.h".

* cfg.mk:
  - Skip strcase checking for virsh-domain-monitor.c
  - Skip to check config.h including for virsh-domain-monitor.c

* po/POTFILES.in
  - Add virsh-domain-monitor.c
2012-07-26 11:56:36 +08:00
Osier Yang
e92ff10b36 virsh: Move definition of cmds and cmd groups right at the top of main
This will avoid many conflicts if moving the codes for each command
group into separate files in later patches.
2012-07-26 11:04:44 +08:00
Martin Kletzander
8101d43433 virsh: fixed domdisplay command
The 'domdisplay' command didn't properly evaluate '--include-password'
option.
2012-07-24 16:58:20 +02:00
Guido Günther
0429e5f0c8 virsh: Add domhostname
to query the guest's hostname.
2012-07-20 21:54:35 +02:00
Sebastian Wiedenroth
29bc4fe646 Add a sheepdog backend for the storage driver
This patch brings support to manage sheepdog pools and volumes to libvirt.
It uses the "collie" command-line utility that comes with sheepdog for that.

A sheepdog pool in libvirt maps to a sheepdog cluster.
It needs a host and port to connect to, which in most cases
is just going to be the default of localhost on port 7000.

A sheepdog volume in libvirt maps to a sheepdog vdi.
To create one specify the pool, a name and the capacity.
Volumes can also be resized later.

In the volume XML the vdi name has to be put into the <target><path>.
To use the volume as a disk source for virtual machines specify
the vdi name as "name" attribute of the <source>.
The host and port information from the pool are specified inside the host tag.

  <disk type='network'>
    ...
    <source protocol="sheepdog" name="vdi_name">
      <host name="localhost" port="7000"/>
    </source>
  </disk>

To work right this patch parses the output of collie,
so it relies on the raw output option. There recently was a bug which caused
size information to be reported wrong. This is fixed upstream already and
will be in the next release.

Signed-off-by: Sebastian Wiedenroth <wiedi@frubar.net>
2012-07-18 20:08:27 +01:00
Stefan Berger
387117ad92 Convert 'raw MAC address' usages to use virMacAddr
Introduce new members in the virMacAddr 'class'
- virMacAddrSet: set virMacAddr from a virMacAddr
- virMacAddrSetRaw: setting virMacAddr from raw 6 byte MAC address buffer
- virMacAddrGetRaw: writing virMacAddr into raw 6 byte MAC address buffer
- virMacAddrCmp: comparing two virMacAddr
- virMacAddrCmpRaw: comparing a virMacAddr with a raw 6 byte MAC address buffer

then replace raw MAC addresses by replacing

- 'unsigned char *' with virMacAddrPtr
- 'unsigned char ... [VIR_MAC_BUFLEN]' with virMacAddr

and introduce usage of above functions where necessary.
2012-07-17 08:07:59 -04:00
Viktor Mihajlovski
ece765959a virsh: remove unnecessary sleep for nodecpustats --percent
Fix for a minor issue:
the sleep(1) statement was called twice,
effectively doubling the elapsed time
execution "virsh nodecpustats --percent".

Signed-off-by: Viktor Mihajlovski <mihajlov@linux.vnet.ibm.com>
2012-07-13 11:32:07 +02:00
Guido Günther
0f9ad736cb virsh: remove extra space between function name and opening brace
to match our CodingStyle.
2012-07-11 20:50:14 +02:00
Osier Yang
ea9509b9e8 virsh: Ensure the parents of the readline history path exists
Instead of changing the existed virFileMakePath to accept mode
argument and modifying a pile of its uses, this patch introduces
virFileMakePathWithMode, and use it instead of mkdir() to create
the readline history dir.
2012-07-10 21:37:13 +08:00
Peter Krempa
e16d434da7 virsh: Clarify documentation for virsh dompmsuspend command
Clarify the docs to make more clear what this command does and that it
requires a guest agent running in the guest.
2012-07-09 19:38:22 +02:00
Peter Krempa
3cdb3b4e64 virsh: Fix ordering of arguments when calling vshCalloc.
In vshSnapshotListCollect() vshCalloc was called with swapped nmemb and
size argument. This caused division by zero in xalloc_oversized as the
macro doesn't expect size to be zero.
2012-07-04 14:01:37 +02:00
Doug Goldstein
9faaaba432 virsh: Cleanup virsh -V output
Fixed up virsh -V output by removing invalid WITH_PROXY & WITH_ONE
checks, adding several missing checks, and fixing the DTrace check.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2012-06-29 15:40:22 -06:00
Doug Goldstein
421a200987 virsh: Add domdisplay cmd for VNC, SPICE and RDP
v2:
- Refactored to use virBuffer
- Refactored to use virXPath wrappers
- Added support for tls-port and password for SPICE
- Added optional flag to disable SPICE password to the URI
- Added support for RDP
- Fixed code reviews

Add a new 'domdisplay' command that provides a URI for VNC, SPICE and
RDP connections. Presently the 'vncdisplay' command provides you with
the port info that QEMU is listening on but there is no counterpart for
SPICE and RDP. Additionally this provides you with the bind address as
specified in the XML, which the existing 'vncdisplay' lacks. For SPICE
connections it supports secure and unsecure channels and optionally
providing the password for the SPICE channel.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2012-06-27 16:17:00 +02:00
Michal Privoznik
8d27005b50 storage: Introduce --inactive for pool-dumpxml
Storage is one of the last domains in libvirt where we don't fully
utilize inactive and live XML. Okay, it might be because we don't
have support for that. So implement such support. However, we need
to fallback when talking to old daemon which doesn't support this
new flag called VIR_STORAGE_XML_INACTIVE.
2012-06-25 13:23:28 +02:00
Daniel P. Berrange
3b9ca94025 Fix unused parameters / functions in virsh on Win32
The vshPrintRaw function is not used on Win32, and neither
is the 'msg' parameter of vshAskReedit. Change the nesting
of #ifdef WIN32 conditionals to address this

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-06-25 10:41:10 +01:00
Doug Goldstein
dcbfd57214 virsh: Use virXPath wrappers for vncdisplay cmd
Update the vncdisplay command to use the virXPath wrappers as well as
check if the domain is up rather than using the port set to -1 to mean
the domain is not up.

Signed-off-by: Doug Goldstein <cardoe@cardoe.com>
2012-06-25 11:25:50 +02:00
Peter Krempa
de924ca90a virsh: Improve error when trying to change vm's cpu count 0
This patch adds a check for the count of processors the user requests
for the guest machine so that invalid values produce a more helpful
error message.
2012-06-22 10:24:17 +02:00
Peter Krempa
d62e51f86b virsh: add support for virConnectListAllDomains and clean up cmdList
This patch makes use of the newly added api virConnectListAllDomains()
to list domains in virsh.

Virsh now represents lists of domains using an internal structure
vshDomainList. This structure contains the virDomainPtr list as provided
by virConnectListAllDomains() and the count of domains in the list.

For backwards compatibility, the function vshDomainListCollect was added
that tries to enumerate the domains using the new API and if the API is
not supported falls back to the older approach with the two list
functions.  The helper function also simulates filtering by all
currently supported flags added with virConnectListAllDomains().

This patch also cleans up the "list" command handler to use the new
helpers and adds new command line flags to make use of filtering.
2012-06-21 16:07:06 +02:00
Peter Krempa
f1b872b25a virsh: Rename namesorter to vshNameSorter and clean up indentation 2012-06-21 15:30:58 +02:00
Eric Blake
a7f7bf02fd list: use the new snapshot API in virsh when possible
Using the new API is so much shorter than the rest of the remainder
of the function.

* tools/virsh.c (vshSnapshotList): Use the new API.
2012-06-19 13:50:03 -06:00
Eric Blake
35ae18f3c6 snapshot: expose new flags in virsh
Previously, to get the name of all snapshots with children, it was
necessary to get the name of all snapshots and then remove the
name of leaf snapshots.  This is racy, and somewhat inefficient
compared to planned API additions.  We can emulate --no-metadata on
0.9.5-0.9.12, but for now, there is no emulation of --no-leaves.

* tools/virsh.c (cmdSnapshotList): Add new options --no-leaves and
--no-metadata.
(vshSnapshotList): Emulate where possible.
* tools/virsh.pod (snapshot-list): Document them.
2012-06-19 13:50:03 -06:00
Martin Kletzander
3dc733bb01 virsh: fix few typos on desc command
virsh help fix:
 - <--title> can also /get/ the title

virsh man page:
 - missing <domain-id>
 - <new_desc> should be <new-desc>
2012-06-19 18:20:44 +02:00
Martin Kletzander
4b2273074c virsh: make domiftune interface help string consistent
Append '(MAC Address)' after the help string of domiftune virsh
command as it takes the same type of argument as domif-{get,set}link
which have it specified.
2012-06-19 14:42:19 +02:00
Michal Privoznik
2872155bfe virsh: Update vol-create-as manpage
as we support qed format as well.
2012-06-18 14:40:32 +02:00
Eric Blake
90a61b3940 snapshot: use new virsh function for snapshot-list
Operating on a list of snapshot objects looks so much simpler.
In particular, since the helper function already trimmed out
irrelevant entries, we no longer have quite so many special cases
on finding the first snapshot to operate on.  Also, vshTreePrint
no longer has a generic callback struct; both clients now pass
something different according to their own needs.

* tools/virsh.c (cmdSnapshotList): Use previous patches.
(vshTreeArrayLookup): Rename...
(vshNodeListLookup): ...now that it only has one client.
(cmdNodeListDevices): Adjust caller.
2012-06-15 19:49:05 -06:00
Eric Blake
76d397b0d3 snapshot: new virsh function factored from snapshot-list
This patch is based on the fallback code out of cmdSnapshotList,
with tweaks to keep the snapshot objects around rather than just
their name, and to remove unwanted elements before returning.
It looks forward to a future patch when we add a way to list all
snapshot objects at once, and the next patch will simplify
cmdSnapshotList to take advantage of this factorization.

* tools/virsh.c (vshSnapshotList, vshSnapshotListFree): New functions.
2012-06-15 19:49:05 -06:00
Wen Congyang
440b8ad181 virsh: allow the user to specify vmcore's format
Add a new parameter --memory-only for 'virsh dump' command. So
the user can decide the vmcore's format.
2012-06-15 20:36:14 +08:00
Osier Yang
e3843d7f04 virsh: Null terminated the string memcpy from buffer explicitly
Detected by valgrind:

==16217== 1 errors in context 1 of 12:
==16217== Invalid read of size 1
==16217==    at 0x4A07804: __GI_strlen (mc_replace_strmem.c:284)
==16217==    by 0x3019F167F6: xdr_string (in /lib64/libc-2.12.so)
==16217==    by 0x3033709E8D: xdr_remote_nonnull_string (remote_protocol.c:31)
==16217==    by 0x303370E5CB: xdr_remote_domain_update_device_flags_args (remote_protocol.c:2028)
==16217==    by 0x30337197D1: virNetMessageEncodePayload (virnetmessage.c:341)
==16217==    by 0x30337135E1: virNetClientProgramCall (virnetclientprogram.c:327)
==16217==    by 0x30336F1EFD: callWithFD (remote_driver.c:4586)
==16217==    by 0x30336F1F7B: call (remote_driver.c:4607)
==16217==    by 0x30336F42F2: remoteDomainUpdateDeviceFlags (remote_client_bodies.h:2865)
==16217==    by 0x30336D46E5: virDomainUpdateDeviceFlags (libvirt.c:9457)
==16217==    by 0x41AEE8: cmdChangeMedia (virsh.c:15249)
==16217==    by 0x413CB4: vshCommandRun (virsh.c:18669)
==16217==  Address 0x4ec5e25 is 0 bytes after a block of size 293 alloc'd
==16217==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==16217==    by 0x303364F1DB: virAllocN (memory.c:129)
==16217==    by 0x41A844: vshPrepareDiskXML (virsh.c:15043)
==16217==    by 0x41AECC: cmdChangeMedia (virsh.c:15246)
==16217==    by 0x413CB4: vshCommandRun (virsh.c:18669)
==16217==    by 0x423973: main (virsh.c:20261)
2012-06-15 10:17:30 +08:00
Michal Privoznik
79521a5e5b virsh: Report name from edited object
There is a little easter egg in virsh: one can easily clone
an object (domain, network, ...). Just 'virsh edit' change the name
and remove <uuid>. And then, in the end when reporting success
the new name was printed out.
However, with recent edit rewrite we lost the final part and are
still printing the original name out.
2012-06-14 15:04:28 +02:00
Michal Privoznik
b00469b615 virsh: Honor reedit opts printing to a function
When printing reedit options we make stdin raw. However,
this results in stdout being raw as well. Therefore we need
to return carriage when doing new line. Unfortunately,
'\r' cannot be part of internationalized messages hence
we must move them to formatting string which then in turn
become huge and disarranged. To solve this, a new function
is introduced which takes variable string arguments and
prepend each with "\r\n" just before printing.
2012-06-14 15:04:28 +02:00
Peter Krempa
5b4740265c virsh: Don't generate invalid XML in attach-disk command
The attach-disk command used with parameter --cache created an invalid
XML snippet as the beginning of the <driver> element was not printed
when used solely with --cache and no other attribute to driver.
2012-06-14 10:07:54 +02:00
Laine Stump
1f145b2f0f network: fully support/use VIR_NETWORK_XML_INACTIVE flag
commit 52d064f42d added
VIR_NETWORK_XML_INACTIVE in order to allow suppressing the
auto-generated list of VFs in network definitions, and a --inactive
flag to virsh net-dumpxml to take advantage of the flag. However, it
missed out on two opportunities:

1) Use INACTIVE to get the current config of the network as it
   exists on disk, rather than the currently active config.

2) Add INACTIVE to the flags used for the virsh net-edit command, so
   that it won't include the forward-pool interfaces that were
   autogenerated, and so that a re-edit of the network prior to
   restarting it will show any other edits made since the last restart
   of the network. (prior to this patch, if you edited a network a 2nd
   time without restarting, all of the previous edits would magically
   disappear).

In order to fit with the new #define-based generic edit function in
virsh.c, a new function vshNetworkGetXMLDesc() was added. This
function first tries to call virNetworkGetXMLDesc with the INACTIVE
flag added, then retries without if the first attempt fails (in the
manner expected when the server doesn't support it).
2012-06-13 14:53:35 -04:00
Eric Blake
78d078c824 build: silence gettext warning
Otherwise, 'make dist' gives multiple warnings like:

libvirt.pot:20814: warning: internationalized messages should not contain the `\r' escape sequence

* tools/virsh.c (vshAskReedit): Avoid \r in _().
2012-06-12 21:46:36 -06:00
Eric Blake
757c47635d snapshot: add 'virsh snapshot-info'
Expose the recent API additions in virsh.  Borrows ideas from 'dominfo'
for the general type of information to display.

Output looks like:

$ tools/virsh snapshot-info fedora-local tmp
Name:           tmp
Domain:         fedora-local
Current:        no
State:          disk-snapshot
Parent:         -
Children:       1
Descendants:    2
Metadata:       yes

possibly with fewer lines when talking to older servers.

* tools/virsh.c (cmdSnapshotInfo): New command.
* tools/virsh.pod (snapshot-info): Document it.
2012-06-11 11:55:00 -06:00
Eric Blake
903560245f snapshot: virsh indentation cleanup
No semantic change; this will make it easier to refactor code.

* tools/virsh.c (cmdSnapshotList): Drop level of indentation, and
rename a variable.
2012-06-11 09:23:16 -06:00
Eric Blake
c8564ad476 virsh: make tree listing more flexible
Requiring the user to pass in parallel arrays of names and parents
is annoying; it means that you can't qsort one of the arrays without
invalidating the ordering of the other.  By refactoring this function
to use callbacks, we isolate the layout to be independent of the
printing, and a future patch can exploit that to improve layout.

* tools/virsh.c (vshTreePrintInternal): Use callbacks rather than
requiring a char** array.
(vshTreeArrayLookup): New helper function.
(vshTreePrint, cmdNodeListDevices, cmdSnapshotList): Update callers.
2012-06-11 09:23:16 -06:00
Eric Blake
ef981053ca virsh: remove limits on tree listing
I am not a fan of fixed-width buffers.  All it takes is a
linear chain of more than 100 snapshots to mess up 'virsh
snapshot-list --tree'.  Now that virBuffer is more powerful,
we might as well exploit its power.

* tools/virsh.c (cmdNodeListDevicesPrint): Simplify to use a
virBuffer instead of fixed-width prefix, factor guts, and rename...
(vshTreePrint, vshTreePrintInternal): ...along with new helper.
(cmdNodeListDevices, cmdSnapshotList): Update callers.
2012-06-11 09:23:16 -06:00
Eric Blake
d9f6066598 snapshot: avoid virsh crash with older servers
Commits 51082301, 16d7b39, and 521cc447 introduced support for
'virsh snapshot-list --from' when talking to a server older than
0.9.5, but broke support for plain 'virsh snapshot-list' for the
same old server in the process.  Because the code is not properly
gated, we end up with a SIGSEGV during a strcmp with a NULL argument.

* tools/virsh.c (cmdSnapshotList): Don't waste time on fallbacks
when --from is not present.
2012-06-11 08:22:03 -06:00
Osier Yang
ee58b581c4 virsh: Back out if the argument for vol-create-as is malformed 2012-06-05 14:56:40 +08:00
Osier Yang
68fcfdb8bd virsh: Accept UUID as an argument for net-info and net-start 2012-06-05 14:56:37 +08:00
Osier Yang
05f8917f96 virsh: Accept UUID as an argument for storage commands
Affected commands are: pool-start, vol-create-from.
2012-06-05 14:56:35 +08:00
Wen Congyang
c094b4b332 fix make syntax-check failed 2012-06-04 09:29:59 -06:00
Michal Privoznik
a7de052369 virsh: Allow users to reedit rejected XML
If users *-edit but make a mistake in XML all changes are
permanently lost. However, if virsh is not running within
a script we can ask user if he wants to re-edit the file
and correct the mistakes.
2012-06-02 10:42:54 +02:00
Michal Privoznik
0766783abb virsh: Switch from generated cmd*Edit commands to nongenerated
Currently, we either generate some cmd*Edit commands (cmdPoolEdit
and cmdNetworkEdit) via sed script or copy the body of cmdEdit
(e.g. cmdInterfaceEdit, cmdNWFilterEdit, etc.). This fact makes
it harder to implement any new feature to our editing system.
Therefore switch to new implementation - define macros to:
- dump XML (EDIT_GET_XML)
- take an action if XML wasn't changed,
  usually just vshPrint() (EDIT_NOT_CHANGED)
- define new object (EDIT_DEFINE) - the edited XML is in @doc_edited
- free object defined by EDIT_DEFINE (EDIT_FREE)
and #include "virsh-edit.c"
2012-06-02 10:40:51 +02:00
Eric Blake
dc4301c726 virsh: avoid strncpy
strncpy is generally evil - it runs the risk of missing NUL
termination, and more often than not wastes time zeroing way
more bytes than strictly necessary.  We've avoided this evil
in our virStrncpy wrapper, except for places where we forgot
to use the wrapper; meanwhile, we have also added an even
higher layer wrapper for setting virTypedParameter values.

* tools/virsh.c (cmdMemtune, cmdBlkdeviotune): Use modern API.
* cfg.mk (exclude_file_name_regexp--sc_prohibit_strncpy): Tighten.
2012-05-29 09:24:48 -06:00
Daniel P. Berrange
517368a377 Remove uid param from directory lookup APIs
Remove the uid param from virGetUserConfigDirectory,
virGetUserCacheDirectory, virGetUserRuntimeDirectory,
and virGetUserDirectory

These functions were universally called with the
results of getuid() or geteuid(). To make it practical
to port to Win32, remove the uid parameter and hardcode
geteuid()

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-28 10:55:06 +01:00
Daniel P. Berrange
ebbcc02639 Remove last usage of PATH_MAX and ban its future use
Remove a number of pointless checks against PATH_MAX and
add a syntax-check rule to prevent its use in future

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-05-28 10:43:01 +01:00
Wido den Hollander
74951eadef storage backend: Add RBD (RADOS Block Device) support
This patch adds support for a new storage backend with RBD support.

RBD is the RADOS Block Device and is part of the Ceph distributed storage
system.

It comes in two flavours: Qemu-RBD and Kernel RBD, this storage backend only
supports Qemu-RBD, thus limiting the use of this storage driver to Qemu only.

To function this backend relies on librbd and librados being present on the
local system.

The backend also supports Cephx authentication for safe authentication with
the Ceph cluster.

For storing credentials it uses the built-in secret mechanism of libvirt.

Signed-off-by: Wido den Hollander <wido@widodh.nl>
2012-05-21 12:37:38 -06:00
Hu Tao
d29a7aaa1a Add a new param 'vcpu_time' to virDomainGetCPUStats
Currently virDomainGetCPUStats gets total cpu usage, which consists
of:

  1. vcpu usage: the physical cpu time consumed by virtual cpu(s) of
     domain
  2. hypervisor: `total cpu usage' - `vcpu usage'

The param 'vcpu_time' is for getting vcpu usages.
2012-05-17 12:42:06 -06:00
William Jon McCann
32a9aac2e0 Use XDG Base Directories instead of storing in home directory
As defined in:
http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html

This offers a number of advantages:
 * Allows sharing a home directory between different machines, or
sessions (eg. using NFS)
 * Cleanly separates cache, runtime (eg. sockets), or app data from
user settings
 * Supports performing smart or selective migration of settings
between different OS versions
 * Supports reseting settings without breaking things
 * Makes it possible to clear cache data to make room when the disk
is filling up
 * Allows us to write a robust and efficient backup solution
 * Allows an admin flexibility to change where data and settings are stored
 * Dramatically reduces the complexity and incoherence of the
system for administrators
2012-05-14 15:15:58 +01:00
Jim Meyering
c6694ab85c virsh: avoid heap corruption leading to virsh abort
* tools/virsh.c (vshParseSnapshotDiskspec): Fix off-by-3 memmove
that would corrupt heap when parsing escaped --diskspec comma.
Bug introduced via commit v0.9.4-260-g35d52b5.
2012-05-07 21:40:38 +02:00
Eric Blake
706aa7c52b virsh: output scaled values with correct units
The recent push to use correct scaling terms (kB for 1000, KiB for
1024 - such as commit 9dfdead) missed some places in virsh.

* tools/virsh.c (prettyCapacity, cmdDominfo, cmdFreecell)
(cmdNodeinfo, cmdNodeMemStats, cmdMigrateSetMaxSpeed)
(cmdBlockCopy, cmdBlockPull, cmdBlockJob): Use KiB, not kB, when
referring to multiples of 1024.
* tests/virshtest.c: Update expected output to match.
2012-05-01 14:58:14 -06:00
Eric Blake
46e5d36b89 virsh: make -h always give help
https://bugzilla.redhat.com/show_bug.cgi?id=817244 mentions that
unlike most other tools, where --help or --version prevent all
further parsing of all later options, virsh was strange in that
--version stopped parsing but --help tried to plow on to the end.
There was no rationale for this original implementation (since
2005!), so I think we can safely conform to common usage patterns.

* tools/virsh.c (main): Drop useless 'help' variable.
2012-05-01 14:58:14 -06:00
Eric Blake
1f06c007fe blockjob: add 'blockcopy' to virsh
Rather than further overloading 'blockpull', I decided to create a
new virsh command to expose the new flags of virDomainBlockRebase.

Blocking until the command completes naturally is pointless, since
the block copy job is intended to run indefinitely.  Instead, I
made the command support three --wait modes: by default, it runs until
mirroring is started; with --pivot, it pivots as soon as mirroring
is started; and with --finish, it aborts (for a clean copy) as
soon as mirroring is started.

* tools/virsh.c (VSH_CMD_BLOCK_JOB_COPY): New mode.
(blockJobImpl): Support new flags.
(cmdBlockCopy): New command.
(cmdBlockJob): Support new job info, new abort flag.
* tools/virsh.pod (blockcopy, blockjob): Document the new command
and flags.
2012-04-23 07:44:30 -06:00
Eric Blake
bb65c8af33 virsh: avoid strtol
We were forgetting to check errno for overflow.

* tools/virsh.c (get_integer_keycode, vshCommandOptInt)
(vshCommandOptUInt, vshCommandOptUL, vshCommandOptLongLong)
(vshCommandOptULongLong): Rewrite to be safer.
2012-04-19 17:42:53 -06:00
Eric Blake
2aed9a97f8 virsh: avoid uninitialized memory usage
Detected by valgrind, via Alex Jia.  Caused by imcomplete
copy-and-paste from vshWatchJob in commit 3b96a892.

* tools/virsh.c (cmdBlockPull): fix uninitialized memory usage.

* How to reproduce?
$ qemu-img create /var/lib/libvirt/images/test 1M
$ cat > /tmp/test.xml <<EOF
<domain type='qemu'>
  <name>test</name>
  <memory>219200</memory>
  <vcpu>1</vcpu>
  <os>
    <type arch='x86_64'>hvm</type>
    <boot dev='hd'/>
  </os>
  <devices>
    <disk type='file' device='disk'>
      <driver name='qemu' type='raw'/>
      <source file='/var/lib/libvirt/images/test'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <input type='mouse' bus='ps2'/>
    <graphics type='spice' autoport='yes' listen='0.0.0.0'/>
  </devices>
</domain>
EOF
$ virsh define /tmp/test.xml
$ valgrind -v virsh blockpull test /var/lib/libvirt/images/test --wait

actual result:

==10906== 1 errors in context 1 of 1:
==10906== Syscall param rt_sigaction(act->sa_flags) points to uninitialised byte(s)
==10906==    at 0x39CF80F5BE: __libc_sigaction (sigaction.c:67)
==10906==    by 0x43016C: cmdBlockPull (virsh.c:7638)
==10906==    by 0x4150D4: vshCommandRun (virsh.c:18574)
==10906==    by 0x425E73: main (virsh.c:20178)
==10906==  Address 0x7fefffae8 is on thread 1's stack
2012-04-19 14:51:42 -06:00
Eric Blake
3b96a89242 blockjob: add virsh blockpull --wait
I'm tired of shell-scripting to wait for completion of a block pull,
when virsh can be taught to do the same.  I couldn't quite reuse
vshWatchJob, as this is not a case of a long-running command where
a second thread must be used to probe job status (at least, not unless
I make virsh start doing blocking waits for an event to fire), but it
served as inspiration for my simpler single-threaded loop.  There is
up to a half-second delay between sending SIGINT and the job being
aborted, but I didn't think it worth the complexity of a second thread
and use of poll() just to minimize that delay.

* tools/virsh.c (cmdBlockPull): Add new options to wait for
completion.
(blockJobImpl): Add argument.
(cmdBlockJob): Adjust caller.
* tools/virsh.pod (blockjob): Document new mode.
2012-04-17 11:11:47 -06:00
Eric Blake
4f06777e5b virsh: minor syntactic cleanups
No semantic change.

* tools/virsh.c: Fix some spacing issues, {} usage, long lines,
and redundant ().
2012-04-17 11:05:58 -06:00
Adam Litke
a696f8b71a blockjob: add API for async virDomainBlockJobAbort
Block job cancellation can take a while.  Now that upstream qemu 1.1
has asynchronous block cancellation, we want to expose that to the user.
Therefore, the following updates are made to the virDomainBlockJob API:

A new block job event type VIR_DOMAIN_BLOCK_JOB_CANCELED is managed by
libvirt.  Regardless of the flags used with virDomainBlockJobAbort, this
event will be raised: 1. when using synchronous block_job_cancel (the
event will be synthesized by libvirt), and 2. whenever it is received
from qemu (via asynchronous block-job-cancel).  Note that the event
may be detected by libvirt even before the virDomainBlockJobAbort
completes (always true when it is synthesized, but also possible if
cancellation was fast).

A new extension flag VIR_DOMAIN_BLOCK_JOB_ABORT_ASYNC is added to the
virDomainBlockJobAbort API.  When enabled, this function will allow
(but not require) asynchronous operation (ie, it returns as soon as
possible, which might be before the job has actually been canceled).
When the API is used in this mode, it is the responsibility of the
caller to wait for a VIR_DOMAIN_BLOCK_JOB_CANCELED event or poll via
the virDomainGetBlockJobInfo API to check the cancellation status.

This patch also exposes the new flag through virsh, and makes virsh
slightly easier to use (--async implies --abort, and lack of any options
implies --info), although it leaves the qemu implementation for later
patches.

Signed-off-by: Adam Litke <agl@us.ibm.com>
Cc: Stefan Hajnoczi <stefanha@gmail.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2012-04-11 20:52:18 -06:00
Peter Krempa
fd3f67e9d3 virsh: Clean up usage of boolean flag variables
This patch cleans up variables used to store boolean command flags that
are inquired by vshCommandOptBool to use the bool data type instead of
an integer.

Additionally this patch cleans up flag variables that are inferred from
existing flags.
2012-04-10 15:50:23 +02:00
Peter Krempa
cc5100654b virsh: Clarify use of the --managed-save flag for the list command
The documentation for the flag doesn't clearly state that the flag only
enhances the output and the user needs to specify other flags to list
inactive domains, that are enhanced by this flag.
2012-04-10 15:48:45 +02:00
Michal Privoznik
7960ce842b virsh: Clarify escape sequence
Currently, we put no strains on escape sequence possibly leaving users
with console that cannot be terminated. However, not all ASCII
characters can be used as escape sequence. Only those falling in
@ - _ can be; implement and document this constraint.
2012-04-03 17:03:53 +02:00
Yuri Chornoivan
867ed7bb9e Fix typos and spacing in messages. 2012-04-02 08:45:56 -06:00
Daniel P. Berrange
ec8cae93db Consistent style for usage of sizeof operator
The code is splattered with a mix of

  sizeof foo
  sizeof (foo)
  sizeof(foo)

Standardize on sizeof(foo) and add a syntax check rule to
enforce it

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-03-30 11:47:24 +01:00
Alex Jia
03ca3317a6 virsh: plug memory leaks on failure path
Leaks are introduced in commit 1cf0e3d and fe383bb.

Fixing memory leaks, in addition, the patch also fixes a potential missing
return value issue in 'if (from)' statement, without the fixing, although
the programming met a error, the subsequent codes will be executed
continually.

* tools/virsh.c (cmdSnapshotList): fix memory leaks and missing return value.

* How to reproduce?

% virsh snapshot-list <domain> --parent --roots
% virsh snapshot-list <domain> --parent --tree
% virsh snapshot-list <domain> --roots --tree

actual result:
error: --parent and --roots are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

error: --parent and --tree are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

error: --roots and --tree are mutually exclusive
error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

% virsh snapshot-create-as <domain> --name "hello"
% virsh snapshot-create-as <domain> --name "libvirt"
% virsh snapshot-list <domain> --roots --from "hello"

actual result:
error: --roots and --from are mutually exclusive
 Name                 Creation Time             State
------------------------------------------------------------
 libvirt              2012-03-28 13:46:51 +0800 running

Signed-off-by: Alex Jia <ajia@redhat.com>
2012-03-28 23:05:08 +08:00
Laine Stump
05c25e6071 build: fix "missing initializer" errors in virsh.c
Found when attempting to build on Fedora 17 alpha with:

   ./autogen.sh --system --enable-compile-warnings=error

(this same build command works without problem on Fedora 16). All
other struct initializers for this struct have the extra field filled
in (almost always to 0), so the two errant ones were fixed by adding
in the extra 0 field.
2012-03-26 17:08:30 -04:00
Martin Kletzander
9943276fd2 Cleanup for a return statement in source files
Return statements with parameter enclosed in parentheses were modified
and parentheses were removed. The whole change was scripted, here is how:

List of files was obtained using this command:
git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
grep -e '\.[ch]$' -e '\.py$'

Found files were modified with this command:
sed -i -e                                                                 \
's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
-e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'

Then checked for nonsense.

The whole command looks like this:
git grep -l -e '\<return\s*([^()]*\(([^()]*)[^()]*\)*)\s*;' |             \
grep -e '\.[ch]$' -e '\.py$' | xargs sed -i -e                            \
's_^\(.*\<return\)\s*(\(\([^()]*([^()]*)[^()]*\)*\))\s*\(;.*$\)_\1 \2\4_' \
-e 's_^\(.*\<return\)\s*(\([^()]*\))\s*\(;.*$\)_\1 \2\3_'
2012-03-26 14:45:22 -06:00
Eric Blake
4d5533ca87 snapshot: add atomic create flag
Right now, it is appallingly easy to cause qemu disk snapshots
to alter a domain then fail; for example, by requesting a two-disk
snapshot where the second disk name resides on read-only storage.
In this failure scenario, libvirt reports failure, but modifies
the live domain XML in-place to record that the first disk snapshot
was taken; and places a difficult burden on the management app
to grab the XML and reparse it to see which disks, if any, were
altered by the partial snapshot.

This patch adds a new flag where implementations can request that
the hypervisor make snapshots atomically; either no changes to
XML occur, or all disks were altered as a group.  If you request
the flag, you either get outright failure up front, or you take
advantage of hypervisor abilities to make an atomic snapshot. Of
course, drivers should prefer the atomic means even without the
flag explicitly requested.

There's no way to make snapshots 100% bulletproof - even if the
hypervisor does it perfectly atomic, we could run out of memory
during the followup tasks of updating our in-memory XML, and report
a failure.  However, these sorts of catastrophic failures are rare
and unlikely, and it is still nicer to know that either all
snapshots happened or none of them, as that is an easier state to
recover from.

* include/libvirt/libvirt.h.in
(VIR_DOMAIN_SNAPSHOT_CREATE_ATOMIC): New flag.
* src/libvirt.c (virDomainSnapshotCreateXML): Document it.
* tools/virsh.c (cmdSnapshotCreate, cmdSnapshotCreateAs): Expose it.
* tools/virsh.pod (snapshot-create, snapshot-create-as): Document
it.
2012-03-23 16:38:20 -06:00
Osier Yang
7c5a0c94e4 qemu: Update domain status to running while wakeup event is emitted
This introduces a new running reason VIR_DOMAIN_RUNNING_WAKEUP,
and new suspend event type VIR_DOMAIN_EVENT_STARTED_WAKEUP.

While a wakeup event is emitted, the domain which entered into
VIR_DOMAIN_PMSUSPENDED will be transferred to "running"
with reason VIR_DOMAIN_RUNNING_WAKEUP, and a new domain lifecycle
event emitted with type VIR_DOMAIN_EVENT_STARTED_WAKEUP.
2012-03-23 23:12:29 +08:00
Osier Yang
54d9026a2c New domain state pmsuspended
This introduces a new domain state pmsuspended to represent
the domain which has been suspended by guest power management,
e.g. (entered itno s3 state). Because a "running" state could
be confused in this case, one will see the guest is paused
actually while playing. And state "paused" is for the domain
which was paused by virDomainSuspend.
2012-03-23 23:12:22 +08:00
Eric Blake
787f4feb4d virsh: trim aliases from -h output
Commit af3f9aab taught 'virsh help' to ignore command aliases,
but forgot 'virsh -h'.

* tools/virsh.c (vshUsage): Handle aliases.
2012-03-16 22:37:05 -06:00
Osier Yang
6227a220cc virsh: A bit smarter attach-disk
Detects the file type of source path if no "--sourcetype" and
"driver" is specified, instead of always set the disk type as
"block".
2012-03-15 18:16:52 +08:00
Alex Jia
68fd6a3b34 virsh: fix invalid free
* tools/virsh.c (cmdDetachDisk): fix invalid free due to using
  uninitialised value.

* How to reproduce?
# virsh detach-disk a b
error: failed to get domain 'a'
*** glibc detected *** virsh: double free or corruption (out): 0x00007fff410ed1a0 ***
======= Backtrace: =========
/lib64/libc.so.6[0x39cf0750c6]
/usr/lib/libvirt.so.0(virFree+0x39)[0x7f045938a239]
virsh[0x41c768]
virsh[0x415075]
virsh[0x425d64]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x39cf01ecdd]
virsh[0x40a419]
======= Memory map: ========
00400000-0044e000 r-xp 00000000 08:0e 760441                             /usr/bin/virsh
0064e000-00650000 rw-p 0004e000 08:0e 760441                             /usr/bin/virsh
......
39d7229000-39d722b000 r--p 00029000 08:0e 2183477                        /lib64/libk5crypto.so.3.1
39d722b000-39d722c000 rw-p 0002b000 08:0e 2183477                        /lib64/lAborted (core dumped)

Signed-off-by: Alex Jia <ajia@redhat.com>
2012-03-15 14:59:51 +08:00
Eric Blake
759095f636 cpustats: report user and sys times
Thanks to cgroups, providing user vs. system time of the overall
guest is easy to add to our existing API.

* include/libvirt/libvirt.h.in (VIR_DOMAIN_CPU_STATS_USERTIME)
(VIR_DOMAIN_CPU_STATS_SYSTEMTIME): New constants.
* src/util/virtypedparam.h (virTypedParameterArrayValidate)
(virTypedParameterAssign): Enforce checking the result.
* src/qemu/qemu_driver.c (qemuDomainGetPercpuStats): Fix offender.
(qemuDomainGetTotalcpuStats): Implement new parameters.
* tools/virsh.c (cmdCPUStats): Tweak output accordingly.
2012-03-12 08:46:56 -06:00
Osier Yang
1e31b83560 virsh: Use option alias for outmoded "--persistent"
Since VIR_DOMAIN_AFFECT_{LIVE,CONFIG,CURRENT} was created,
all new virsh commands use "--config" to represents the
persistent changing. This patch add "--config" option
for the old commands which still use "--persistent",
and "--persistent" is now alias of "--config".

tools/virsh.c: (use "--config", and "--persistent" is
    alias of "--config" now).
    cmdDomIfSetLink, cmdDomIfGetLink, cmdAttachDevice,
    cmdDetachDevice, cmdUpdateDevice, cmdAttachInterface,
    cmdDetachInterface, cmdAttachDisk, cmdDetachDisk

toos/virsh.pod: Update docs of the changed commands, and
    add some missed docs for "--config" (detach-interface,
    detach-disk, and detach-device).
2012-03-09 13:21:01 +08:00
Eric Blake
210ed0e871 virsh: improve memory unit parsing
The last vestige of the inaccurate 'kilobytes' when we meant 1024 is
now gone.  And virsh is now useful for setting memory in units other
than KiB.

* tools/virsh.c (cmdSetmem, cmdSetmaxmem): Use new helper routine,
allow passing bogus arguments on to hypervisor to test driver
sanity checking, and fix leak on parse error.
(vshMemtuneGetSize): New helper.
(cmdMemtune): Use it.
* tools/virsh.pod (setmem, setmaxmem, memtune): Document this.
2012-03-07 18:24:45 -07:00
Eric Blake
ab95da4058 virsh: improve storage unit parsing
Now can now do:

virsh vol-resize $vol 10M
virsh blockresize $dom $vol 10M

to get both interfaces to resize to 10MiB.  The remaining wart
is that vol-resize defaults to bytes, but blockresize defaults
to KiB, but we can't break existing scripts; oh well, it's no
worse than the same wart of the underlying virDomainBlockResize.

The API for virStorageVolResize states that capacity must always
be positive, and that the presence of shrink and delta flags is
what implies a negative change.

* tools/virsh.c (vshCommandOptScaledInt): New function.
(cmdVolResize): Don't pass negative size.
(cmdVolSize): Rename...
(vshVolSize): ...and use new helper routine.
(cmdBlockResize): Use new helper routine, and support new bytes
flag.
* tools/virsh.pod (NOTES): Document suffixes.
(blockresize, vol-create-as, vol-resize): Point to notes.
2012-03-07 18:24:44 -07:00
Eric Blake
af3f9aabde virsh: add command aliases, and rename nodedev-detach
Just because our public API has a typo doesn't mean that virsh
has to keep the typo.

* tools/virsh.c (VSH_CMD_FLAG_ALIAS): New flag.
(nodedevCmds): Use it.
(cmdHelp): Omit alias commands.
(cmdNodeDeviceDettach): Rename...
(cmdNodeDeviceDetach): ...to this.
* tools/virsh.pod (nodedev-detach): Document it.
2012-03-07 18:24:44 -07:00
Eric Blake
3d150d328b virsh: use option aliases
Command line interfaces should use dash, not underscore, as many
keyboard layouts allow that to be typed with fewer shift key presses.

Also, the US spelling of --tunneled gets more google hits than the
UK spelling of --tunnelled.

* tools/virsh.c (opts_migrate): Allow US variant.
(opts_blkdeviotune): Prefer - over _.
* tools/virsh.pod (blkdeviotune): Fix spelling.
2012-03-07 18:24:44 -07:00
Eric Blake
1c56b9fe53 virsh: add option aliases
In the past, we have created some virsh options with less-than-stellar
names.  For back-compat reasons, those names must continue to parse,
but we don't want to document them in help output.  This introduces
a new option type, an alias, which points to a canonical option name
later in the option list.

I'm actually quite impressed that our code has already been factored
to do all option parsing through common entry points, such that I
got this added in relatively few lines of code!

* tools/virsh.c (VSH_OT_ALIAS): New option type.
(opts_echo): Hook up an alias, for easy testing.
(vshCmddefOptParse, vshCmddefHelp, vshCmddefGetOption): Allow for
aliases.
* tools/virsh.pod (NOTES): Document promise of back-compat.
* tests/virshtest.c (mymain): Test new feature.
2012-03-07 18:24:44 -07:00
KAMEZAWA Hiroyuki
31047e2ba3 cpu-stats command shows cpu statistics information of a domain.
CPU0:
	cpu_time   88.231593093 seconds
CPU1:
	cpu_time   123.613341883 seconds
Total:
	cpu_time   211.844934976 seconds

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
2012-03-06 21:54:48 -07:00
Eric Blake
3e2c3d8f6d build: use correct type for pid and similar types
No thanks to 64-bit windows, with 64-bit pid_t, we have to avoid
constructs like 'int pid'.  Our API in libvirt-qemu cannot be
changed without breaking ABI; but then again, libvirt-qemu can
only be used on systems that support UNIX sockets, which rules
out Windows (even if qemu could be compiled there) - so for all
points on the call chain that interact with this API decision,
we require a different variable name to make it clear that we
audited the use for safety.

Adding a syntax-check rule only solves half the battle; anywhere
that uses printf on a pid_t still needs to be converted, but that
will be a separate patch.

* cfg.mk (sc_correct_id_types): New syntax check.
* src/libvirt-qemu.c (virDomainQemuAttach): Document why we didn't
use pid_t for pid, and validate for overflow.
* include/libvirt/libvirt-qemu.h (virDomainQemuAttach): Tweak name
for syntax check.
* src/vmware/vmware_conf.c (vmwareExtractPid): Likewise.
* src/driver.h (virDrvDomainQemuAttach): Likewise.
* tools/virsh.c (cmdQemuAttach): Likewise.
* src/remote/qemu_protocol.x (qemu_domain_attach_args): Likewise.
* src/qemu_protocol-structs (qemu_domain_attach_args): Likewise.
* src/util/cgroup.c (virCgroupPidCode, virCgroupKillInternal):
Likewise.
* src/qemu/qemu_command.c(qemuParseProcFileStrings): Likewise.
(qemuParseCommandLinePid): Use pid_t for pid.
* daemon/libvirtd.c (daemonForkIntoBackground): Likewise.
* src/conf/domain_conf.h (_virDomainObj): Likewise.
* src/probes.d (rpc_socket_new): Likewise.
* src/qemu/qemu_command.h (qemuParseCommandLinePid): Likewise.
* src/qemu/qemu_driver.c (qemudGetProcessInfo, qemuDomainAttach):
Likewise.
* src/qemu/qemu_process.c (qemuProcessAttach): Likewise.
* src/qemu/qemu_process.h (qemuProcessAttach): Likewise.
* src/uml/uml_driver.c (umlGetProcessInfo): Likewise.
* src/util/virnetdev.h (virNetDevSetNamespace): Likewise.
* src/util/virnetdev.c (virNetDevSetNamespace): Likewise.
* tests/testutils.c (virtTestCaptureProgramOutput): Likewise.
* src/conf/storage_conf.h (_virStoragePerms): Use mode_t, uid_t,
and gid_t rather than int.
* src/security/security_dac.c (virSecurityDACSetOwnership): Likewise.
* src/conf/storage_conf.c (virStorageDefParsePerms): Avoid
compiler warning.
2012-03-02 06:57:43 -07:00
Eric Blake
ff4c25bae9 virsh: expose partial pull
Now virsh can call virDomainBlockRebase.

* tools/virsh.c (cmdBlockPull): Add --base parameter.
(blockJobImpl): Use it to expose BlockRebase API.
* tools/virsh.pod (blockpull): Document it.
2012-02-29 13:44:20 -07:00
Osier Yang
33855f5d04 virsh: New command cmdChangeMedia
One could use it to eject, insert, or update media of the CDROM
or floppy drive. See the documentation for more details.
2012-02-28 15:36:38 +08:00
Osier Yang
42accf1b67 virsh: Use vshFindDisk and vshPrepareDiskXML in cmdDetachDisk
The first use of the two new helper functions.
2012-02-28 14:38:34 +08:00
Osier Yang
025998eb79 virsh: Two new helper functions for disk device changes
vshFindDisk is to find the disk node in xml doc with given source
path or target of disk device, and type (indicates disk type,
normal disk or changeable disk).

vshPrepareDiskXML is to make changes on the disk node (e.g. create
and insert the new <source> node for inserting media of CDROM drive).

They are marked as unused temporarily.
2012-02-28 14:38:03 +08:00
Peter Krempa
afa4336e94 virsh: add support for VIR_DOMAIN_CONSOLE_* flags
This patch adds support for the newly introduced
VIR_DOMAIN_CONSOLE_FORCE and VIR_DOMAIN_CONSOLE_SAFE flags. The console
command now has an optional parameter --force that specifies that the
user wants to forcibly interrupt an ongoing console session and create
a new one. Flag --safe requests that the console should be opened only
if the hypervisor driver supports safe console handling.

The behaviour to this point was that the daemon opened two streams to
the console, that competed for data from the pipe, and the result was
that both of the consoles ended up scrambled.

This patch doesn't modify operation of other commands dealing with
console connections (start, create) as those open connections to newly
started domains making it virtually impossible for another client to race
for the console and steal it.

* tools/console.c:
        - add support for flag passthrough
* tools/console.h:
        - modify function prototypes to match impl.
* tools/virsh.c:
        - add flag --force for the console command
2012-02-27 15:05:17 +01:00
Michal Privoznik
a04d10f739 virsh: Expose virDomainPMWakeup 2012-02-27 11:44:10 +01:00
Laine Stump
4a92360091 virsh: fix informational message in iface-bridge command
See: https://bugzilla.redhat.com/show_bug.cgi?id=797066

The position of the bridge name and ethernet device name were
accidentally swapped in the message informing of success creating the
bridge.
2012-02-24 15:06:26 -05:00
Daniel P. Berrange
af6b61ba06 Improve error reporting when virsh console is run without a TTY
If attempting to run

  ssh root@somehost virsh console someguest

You'll get an error

  2012-02-15 13:11:47.683+0000: 4765: info : libvirt version: 0.9.10, package: 1.fc18 (Unknown, 2012-02-15-11:48:57, lettuce.camlab.fab.redhat.com)
  2012-02-15 13:11:47.683+0000: 4765: error : vshRunConsole:320 : unable to get tty attributes: Invalid argument
  Connected to domain f16x86_64
  Escape character is ^]

There are several problems here

 - The actual error message is bad for users
 - We shouldn't rely on VIR_ERROR for this case
 - The prompt makes it look like we still connected
   because we didn't flush stdout.

* virsh.c: Flush stdout before starting console and check
  for a valid tty
2012-02-24 16:43:26 +00:00
Jiri Denemark
0b7480e34e virsh: Add --unsafe option to migrate command 2012-02-23 14:23:26 +01:00
Peter Krempa
419e5fb3e6 virsh: Enhance list command to ease creation of shell scripts
This patch adds new options to the "virsh list" command enabling
filtering of persistent and transient domains along with the option to
print only UUIDs or names of domains instead of printing the table.

Option --name prints domain names (one per line) instead of the default
table. Similarly --uuid prints domain's UUID. The option --table is
an alias for the default behavior.

Aditionally --persistent and/or --transient may be specified to filter
the output of domains.
2012-02-22 12:12:13 +01:00
Peter Krempa
4f89138bd1 virsh: Fix flag semantics and docs for "desc" command
This patch fixes the domain modification impact flags for tie virsh
desc command to match the new semantics and fix the docs to match
actual behavior.
2012-02-08 16:39:09 +01:00
Alex Jia
faad9648cf virsh: Plug memory leak on cmdDesc 2012-02-08 13:50:06 +08:00
Osier Yang
c001eb5bbe virsh: Do not check the input XML at virsh layer for cmdDetachDevice
Any device XML doesn't use the same order as libvirt generates, or
uses decimal for attributes like "slot" of "<address>" will cause
device detaching to fail, as virsh compares the XML simply earlier
in strict manner before internal parsing.

This is regression introduced by ea7182c.
2012-02-08 09:36:17 +08:00
Peter Krempa
35d31954d2 virsh: Fix resource leak while listing inactive domains with titles
Commit fad5cd2108 introduces a new flag
that allows to show domain's title with domains. This commit introduced
resource leak while listing inactive domains with titles.
2012-02-06 15:25:05 +01:00
Alex Jia
f228917a5c virsh: Avoid invalid read of size errors
Detected by valgrind. the codes are allocating 0 bytes memory to variable
cpumap by vshCalloc function, and then the function VIR_USE_CPU will access
it later, a invalid read error will be hit.

* tools/virsh.c(cmdVcpuPin): fix invalid read error.

* How to reproduce?
% valgrind -v --read-var-info=yes virsh vcpupin <domain> 0 0

* Actual result:

==27271== ERROR SUMMARY: 5 errors from 2 contexts (suppressed: 8 from 6)
==27271==
==27271== 1 errors in context 1 of 2:
==27271== Invalid read of size 1
==27271==    at 0x39CF087E2E: __GI_memcpy (in /lib64/libc-2.12.so)
==27271==    by 0x39CF114FDC: xdrmem_putbytes (in /lib64/libc-2.12.so)
==27271==    by 0x39CF114707: xdr_opaque (in /lib64/libc-2.12.so)
==27271==    by 0x4D56194: xdr_remote_domain_pin_vcpu_args (remote_protocol.c:1844)
==27271==    by 0x4D6CCE1: virNetMessageEncodePayload (virnetmessage.c:341)
==27271==    by 0x4D5A44B: virNetClientProgramCall (virnetclientprogram.c:327)
==27271==    by 0x4D36EDB: callWithFD (remote_driver.c:4546)
==27271==    by 0x4D36F7B: call (remote_driver.c:4567)
==27271==    by 0x4D3B2C1: remoteDomainPinVcpu (remote_client_bodies.h:1566)
==27271==    by 0x4D199D3: virDomainPinVcpu (libvirt.c:8585)
==27271==    by 0x4241F4: cmdVcpuPin (virsh.c:5262)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==  Address 0x5602b80 is 0 bytes after a block of size 0 alloc'd
==27271==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==27271==    by 0x4C89BDF: virAllocN (memory.c:129)
==27271==    by 0x423868: _vshCalloc.clone.2 (virsh.c:454)
==27271==    by 0x423EF9: cmdVcpuPin (virsh.c:5190)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)
==27271==
==27271==
==27271== 4 errors in context 2 of 2:
==27271== Invalid read of size 1
==27271==    at 0x424133: cmdVcpuPin (virsh.c:5245)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)
==27271==  Address 0x5602b80 is 0 bytes after a block of size 0 alloc'd
==27271==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==27271==    by 0x4C89BDF: virAllocN (memory.c:129)
==27271==    by 0x423868: _vshCalloc.clone.2 (virsh.c:454)
==27271==    by 0x423EF9: cmdVcpuPin (virsh.c:5190)
==27271==    by 0x4150A6: vshCommandRun (virsh.c:17712)
==27271==    by 0x426583: main (virsh.c:19289)

Signed-off-by: Alex Jia <ajia@redhat.com>
2012-02-06 13:01:20 +08:00
Laine Stump
3e952ecc52 virsh: add --graceful switch to destroy command
This allows virsh to use the new VIR_DOMAIN_DESTROY_GRACEUL flag for
virDomainDestroyFlags.
2012-02-03 14:50:14 -05:00
Eric Blake
a7cfd709f4 build: prohibit raw malloc and free
Our HACKING discourages use of malloc and free, for at least
a couple of years now.  But we weren't enforcing it, until now :)

For now, I've exempted python and tests, and will clean those up
in subsequent patches.  Examples should be permanently exempt,
since anyone copying our examples won't have use of our
internal-only memory.h via libvirt_util.la.

* cfg.mk (sc_prohibit_raw_allocation): New rule.
(exclude_file_name_regexp--sc_prohibit_raw_allocation): and
exemptions.
* src/cpu/cpu.c (cpuDataFree): Avoid false positive.
* src/conf/network_conf.c (virNetworkDNSSrvDefParseXML): Fix
offenders.
* src/libxl/libxl_conf.c (libxlMakeDomBuildInfo, libxlMakeVfb)
(libxlMakeDeviceModelInfo): Likewise.
* src/rpc/virnetmessage.c (virNetMessageSaveError): Likewise.
* tools/virsh.c (_vshMalloc, _vshCalloc): Likewise.
2012-02-03 10:41:45 -07:00
Taku Izumi
2eaf71a6ab virsh: extension of virsh attach-disk for rawio
This patch extends "virsh attach-disk" command so that
we can specify "rawio" attribute.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2012-02-03 11:50:29 -05:00
Martin Kletzander
3d93706d0d Added RSS reporting
Added RSS information gathering into qemuMemoryStats into qemu driver
and the reporting into virsh dommemstat.
2012-02-03 20:54:58 +08:00
Alex Jia
6152c74595 virsh: Plug memory leak on cmdUndefine
Detected by valgrind. Leak is introduced in commit 3bb6bcf.

Free 'vol' memory before allocating memory, the codes will miss one time
free when 'vol_i = nvolumes' in for loop, so plug memory leak.

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

* How to reproduce?
% dd if=/dev/null of=/var/lib/libvirt/images/foo bs=1 count=1 seek=10M
% virsh define foo.xml                   (disk source file points to '/var/lib/libvirt/images/foo')
% virsh vol-clone foo foo-clone default  (the original guest name is 'foo')
% virsh pool-refresh default
% virsh vol-list default                 (make sure 'foo-clone' volume exists)
% virsh define foo-clone.xml             (disk source file points to '/var/lib/libvirt/images/foo-clone')
% valgrind -v --leak-check=full virsh undefine foo-clone --remove-all-storage

* Actual results:

1. virsh output
Domain foo-clone has been undefined
Volume '/var/lib/libvirt/images/foo-clone' removed.

error: Failed to disconnect from the hypervisor, 1 leaked reference(s)

2. valgrind result

==6515== 92 (40 direct, 52 indirect) bytes in 1 blocks are definitely lost in loss record 46 of 69
==6515==    at 0x4A04A28: calloc (vg_replace_malloc.c:467)
==6515==    by 0x4C89B71: virAlloc (memory.c:101)
==6515==    by 0x4CFCACE: virGetStorageVol (datatypes.c:724)
==6515==    by 0x4D4A8E0: remoteStorageVolLookupByPath (remote_driver.c:4664)
==6515==    by 0x4D07153: virStorageVolLookupByPath (libvirt.c:12508)
==6515==    by 0x4270E6: cmdUndefine (virsh.c:2828)
==6515==    by 0x4151B6: vshCommandRun (virsh.c:17693)
==6515==    by 0x4264D3: main (virsh.c:19270)
==6515==
==6515== LEAK SUMMARY:
==6515==    definitely lost: 40 bytes in 1 blocks

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

Signed-off-by: Alex Jia <ajia@redhat.com>
2012-02-02 11:41:40 +01:00
Peter Krempa
fad5cd2108 virsh: Add support for modifying domain description and titles
This patch adds a new command "desc" to show and modify titles and
description for the domains using the new API.

This patch also adds a new flag for the "list" command to show titles in
the domain list, to allow easy identification of VMs by storing a short
description.

Example:
virsh # list --title
 Id Name                 State      Title
 -----------------------------------------------
   0 Domain-0             running    Mailserver 1
   2 fedora               paused
2012-02-01 15:12:53 -07:00
Jiri Denemark
e08d2a9ad8 virsh: Implement domblkerror command
This command lists all disk devices with errors
2012-02-01 10:56:45 +01:00
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