Commit Graph

203 Commits

Author SHA1 Message Date
Wen Congyang
2225a49106 fix virsh's regression
This patch does the following things:
1. The return value of cmdSchedInfoUpdate() can be -1, 0 and 1. So the
   type of return value should be int not bool.(This function is not a
   entry of a virsh command, but the name of this function likes cmdXXX)

2. The type of cmdSchedinfo()'s, cmdFreecell()'s, cmdPoolList()'s and
   cmdVolList()'s return value is bool not int, so change the type of
   variable ret_val, func_ret and functionReturn.

3. Add a variable functionReturn for cmdMigrate(), cmdAttachInterface(),
   cmdDetachInterface(), cmdAttachDisk() and cmdDetachDisk() to save the
   return value.

4. Change the type of variable ret in the function cmdAttachDevice(),
   cmdDetachDevice(), cmdUpdateDevice(), cmdAttachInterface(),
   cmdDetachInterface(), cmdAttachDisk() and cmdDetachDisk() to int, as
   we use it to save the return value of virXXX() and the type of virXXX()'s
   return value is int not bool.

5. Do some cleanup when virBuff.error is 1.

The bug 1-4 were introduced by commit b56fa5bb.
2011-04-28 12:25:59 +08:00
Eric Blake
b56fa5bb37 virsh: nuke use of TRUE and FALSE
Gnulib already guarantees <stdbool.h>, so it is easier to just
use the standardized spellings.

* tools/virsh.c (vshCmdDef): Change callback to return real bool.
(__vshControl): Change several fields to bool.
(vshCommandOptBool): Change return type.
All callers updated.
* tools/Makefile.am (virsh-net-edit.c, virsh-pool-edit.c):
Likewise.
2011-04-19 08:16:14 -06:00
Eric Blake
b9973f526c virsh: fix regression in parsing optional integer
Regression introduced in 0.8.5, commit c1564268.  The command
'virsh freecell 0' quit working when it changed from an optional
string to an optional integer.

This patch introduces a slight change that specifying an option
twice is now detected as an error.  It also changes things so
that a command that has more than 1 required option will not
complain about missing options if one but not all of the options
were given in long format, as in 'virsh vol-create --pool p file',
as well as making positional parsing work for all optional
options (each positional argument is associated with the earliest
option that has not yet been seen by name).

Optional boolean options can appear before required argument
options, because they don't affect positional argument parsing,
and obviously a required boolean option makes no sense.

Technically, this patch renders VSH_OT_STRING and VSH_OT_DATA
redundant; but cleaning that up can be a separate patch.

No command should ever need more than 32 options, right? :)

* tools/virsh.c (vshCmddefGetData, vshCmddefGetOption)
(vshCommandCheckOpts): Alter parameters to use bitmaps.
(vshCmddefOptParse): New function.
(vshCommandParse): Update for better handling of positional
arguments.
(vshCmddefHelp): Allow unit tests to validate options.
2011-04-15 16:08:18 -06:00
Eric Blake
6b75a1a5b0 virsh: list required options first
The current state of virsh parsing is that:

$ virsh vol-info /path/to/image
$ virsh vol-info --pool default /path/to/image
$ virsh vol-info --pool default --vol /path/to/image

all lookup the volume by path (technically, the last two also attempt
a name lookup within a pool, whereas the first skips that step, but
the end result is the same); meanwhile:

$ virsh vol-info default /path/to/image

complains about unexpected data.  Why?  Because the --pool option is
optional, so default was parsed as the --vol argument, and
/path/to/image.img doesn't match up with any remaining options that
require an argument.  For proof, note that:

$ virsh vol-info default --vol /path/to/image

complains about looking up 'default' - the parser mis-associated both
arguments with --vol.  Given the above, the only way to specify pool
is with an explicit "--pool" argument (you can't specify it
positionally).  However, named arguments can appear in any order, so:

$ virsh vol-info /path/to/image --pool default
$ virsh vol-info --vol /path/to/image --pool default

have also always worked.  Therefore, this patch has no functional
change on vol-info option parsing, but only on 'virsh help vol-info'
synopsis layout.  However, it also allows the next patch to 1) enforce
that required options are always first (without this patch, the next
patch would fail the testsuite), and 2) allow the user to omit the
"--pool" argument.  That is, the next patch makes it possible to do:

$ virsh vol-info /path/to/image default

which to date was not possible.

* tools/virsh.c (opts_vol_create_from, opts_vol_clone)
(opts_vol_upload, opts_vol_download, opts_vol_delete)
(opts_vol_wipe, opts_vol_info, opts_vol_dumpxml, opts_vol_key)
(opts_vol_path): List optional pool parameter after required
arguments.
2011-04-15 15:39:53 -06:00
Taku Izumi
0ad06c1116 setmaxmem: add the new options to "virsh setmaxmem" command
This patch adds the new options (--live, --config, and --current) to
"virsh setmaxmem" command. The behavior of above options is the same
as that of "virsh setmem".  When the --config option is specified, a
modification is effective for the persistent domain, while the --live
option is specified, a modification is effective for an active
domain. The --current option is specified, it affects a current
domain.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-08 20:22:12 -06:00
Taku Izumi
80427f1d87 setmem: add --current option to virsh setmem command
This patch adds the new option (--current) to the "virsh setmem" command.
When --current option is specified, it affects a "current" domain.
The word "current" denotes that if a domain is running, it affects
a running domain only; otherwise it affects a persistent domain.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-07 17:19:46 -06:00
Taku Izumi
74891d9488 setmaxmem: remove the code to invoke virDomainSetMemory in cmdSetmaxmem
When the new maximum memory size becomes less than the current memory size,
I think it is not the libvirt client but the each driver that decides the behavior
(reject the operation or shrink the current memory size).

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-04-07 16:18:43 -06:00
Daniel P. Berrange
7d76d5d506 Enable -Wmissing-format-attribute warning
Add a couple of missing ATTRIBUTE_FMT_PRINTF annotations

* tools/virsh.c, tests/testutils.c: Add printf format attribute
* m4/virt-compile-warnings.m4: Enable -Wmissing-format-attribute
2011-04-05 11:39:52 +01:00
Matthias Bolte
36deff0499 virsh: Remove two 4kb stack allocations 2011-04-05 09:07:40 +02:00
Jiri Denemark
1e8f20799c virsh: Fix documentation for memtune command
Commit 78ba748ef1 claims to fix
documentation for swap_hard_limit virsh memtune option but it only fixes
documentation in formatdomain.html and libvirt.h. This patch completes
the task by fixing "virsh help memtune" output and memtune section of
virsh man page.
2011-04-01 11:31:10 +02:00
Eric Blake
6c9e89bbd2 maint: avoid locale-sensitivity in string case comparisons
strcase{cmp/str} have the drawback of being sensitive to the global
locale; this is unacceptable in a library setting.  Prefer a
hard-coded C locale alternative for all but virsh, which is user
facing and where the global locale isn't changing externally.

* .gnulib: Update to latest, for c-strcasestr change.
* bootstrap.conf (gnulib_modules): Drop strcasestr, add c-strcase
and c-strcasestr.
* cfg.mk (sc_avoid_strcase): New rule.
(exclude_file_name_regexp--sc_avoid_strcase): New exception.
* src/internal.h (STRCASEEQ, STRCASENEQ, STRCASEEQLEN)
(STRCASENEQLEN): Adjust offenders.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextEjectMedia):
Likewise.
* tools/virsh.c (namesorter): Document exception.
2011-03-30 20:26:27 -06:00
Daniel P. Berrange
6299ca71c4 Add vol-upload and vol-download commands to virsh
The new commands vol-upload and vol-download, allow a local file
to be transferred to/from a storage volume.

* tools/virsh.c: Add vol-upload and vol-download commands
* tools/virsh.pod: Document new commands
2011-03-29 12:17:38 +01:00
Eric Blake
6eaa4ee41b virsh: allow empty string arguments
"virsh connect ''" should try to connect to the default connection,
but the previous patch made it issue a warning about an invalid URI.

* tools/virsh.c (VSH_OFLAG_EMPTY_OK): New option flag.
(vshCommandOptString): Per the declaration, value is required to
be non-NULL.  Honor new flag.
(opts_connect): Allow empty string connection.
2011-03-15 14:33:54 -06:00
Michal Privoznik
e6a8f9a16a virsh: Insert error messages to avoid a quiet abortion of commands
in case of incorrect option parsing.
2011-03-14 09:33:55 -06:00
Jiri Denemark
976eb124e7 virsh: Allow starting domains by UUID 2011-03-14 12:34:39 +01:00
Gui Jianfeng
17e7556dcf virsh: Adding blkiotune command to virsh tool
Adding blkiotune command to virsh tool

Signed-off-by: Gui Jianfeng <guijianfeng@cn.fujitsu.com>
2011-03-10 17:54:08 -07:00
Taku Izumi
2d70a46911 setmem: add the new options to "virsh setmem" command
This patch adds the new options (--live and --config)  to "virsh setmem" command.
The behavior of above options is the same as that of "virsh setvcpus" and so on.
That is, when the --config option is specified, a modification is effective for
the persistent domain. Moreover we can modify the memory size of inactive domains
as well as that of active domains.

Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
2011-03-10 15:02:58 -07:00
Michal Privoznik
d03f199595 virsh: Change option parsing functions to return tri-state information
This is needed to detect situations when optional argument was
specified with non-integer value: '--int-opt foo'. To keep functions
uniform vshCommandOptString function was also changed, because it
returns tri-state value as well. Given result pointer is updated only
in case of success. If parsing fails, result is not updated at all.
2011-03-08 13:25:52 -07:00
Michal Privoznik
dc3d60ecd5 virsh: change vshCommandOptString return type and fix const-correctness
This function should return pointer to const, because we don't want
to change command option value. Therefore we can ensure const-correctness.
2011-03-08 13:25:37 -07:00
Daniel P. Berrange
2ed6cc7bec Expose event loop implementation as a public API
Not all applications have an existing event loop they need
to integrate with. Forcing them to implement the libvirt
event loop integration APIs is an undue burden. This just
exposes our simple poll() based implementation for apps
to use. So instead of calling

   virEventRegister(....callbacks...)

The app would call

   virEventRegisterDefaultImpl()

And then have a thread somewhere calling

    static bool quit = false;
    ....
    while (!quit)
      virEventRunDefaultImpl()

* daemon/libvirtd.c, tools/console.c,
  tools/virsh.c: Convert to public event loop APIs
* include/libvirt/libvirt.h.in, src/libvirt_private.syms: Add
  virEventRegisterDefaultImpl and virEventRunDefaultImpl
* src/util/event.c: Implement virEventRegisterDefaultImpl
  and virEventRunDefaultImpl using poll() event loop
* src/util/event_poll.c: Add full error reporting
* src/util/virterror.c, include/libvirt/virterror.h: Add
  VIR_FROM_EVENTS
2011-03-07 14:16:13 +00:00
Daniel P. Berrange
343eaa150b Move event code out of the daemon/ into src/util/
The event loop implementation is used by more than just the
daemon, so move it into the shared area.

* daemon/event.c, src/util/event_poll.c: Renamed
* daemon/event.h, src/util/event_poll.h: Renamed
* tools/Makefile.am, tools/console.c, tools/virsh.c: Update
  to use new virEventPoll APIs
* daemon/mdns.c, daemon/mdns.c, daemon/Makefile.am: Update
  to use new virEventPoll APIs
2011-03-07 14:16:13 +00:00
Phil Petty
5a81401235 fixes for several memory leaks
Signed-off-by: Eric Blake <eblake@redhat.com>
2011-03-04 09:52:12 -07:00
Daniel P. Berrange
449b4c87b5 Fix discard of expected errors
In a couple of commands virsh catches & ignores errors, but fails
to reset last_error. Thus the error is ignored, but still reported
to the user.

* tools/virsh.c: Reset last_error if ignoring an error
2011-02-23 11:11:55 +00:00
Osier Yang
8fcc76a6e2 virsh: replace vshPrint with vshPrintExtra for snapshot list
Otherwise extra information will be printed even if "--quiet"
is specified.

* tools/virsh.c
2011-02-22 10:06:08 +08:00
Michal Privoznik
595174aeb7 virsh: freecell --all getting wrong NUMA nodes count
Virsh freecell --all was not only getting wrong NUMA nodes count, but
even the NUMA nodes IDs. They doesn't have to be continuous, as I've
found out during testing this. Therefore a modification of
nodeGetCellsFreeMemory() error message.
2011-02-18 09:26:40 -07:00
Eric Blake
1a82c5f7c6 build: silence some clang warnings
* tools/virsh.c (cmdHelp): Kill dead variables.
2011-02-15 10:43:40 -07:00
Eric Blake
92f0ed0353 virsh: avoid mingw compiler warnings
Compilation on mingw was warning about %lld use in fprintf, and
in the gnulib strptime module about dead labels.

* tools/virsh.c (vshPrint): Change redirect.
(vshPrintExtra): Allow use within vshPrint.  Avoid fprintf on
arbitrary formats, since we aren't using gnulib module; instead,
use virVasprintf to pre-format.
(vshError): Likewise.
* .gnulib: Update to latest, for mingw strptime warning fix.
Reported by Matthias Bolte.
2011-02-12 06:39:27 -07:00
Daniel P. Berrange
100f4a63a2 Avoid pthread_sigmask on Win32 platforms
Win32 doesn't have a concept of signal masks so disable that
code. It is unclear how SIGINT is delivered (if at all) on
Win32, so this might further work to provide an alternative
to pthread_sigmask

* tools/virsh.c: Avoid pthread_sigmask on Win32
2011-02-10 14:30:10 +00:00
Eric Blake
c82be0530e sysinfo: implement virsh support
* tools/virsh.c (cmdSysinfo): New function.
(hostAndHypervisorCmds): Add it.
* tools/virsh.pod: Document it.
2011-02-08 19:29:48 -07:00
Jiri Denemark
2169472ab6 qemu: Add shortcut for HMP pass through
Currently users who want to use virDomainQemuMonitorCommand() API or
it's virsh equivalent has to use the same protocol as libvirt uses for
communication to qemu. Since the protocol is QMP with current qemu and
HMP much more usable for humans, one ends up typing something like the
following:

    virsh qemu-monitor-command DOM \
'{"execute":"human-monitor-command","arguments":{"command-line":"info kvm"}}'

which is not a very convenient way of debugging qemu.

This patch introduces --hmp option to qemu-monitor-command, which says
that the provided command is in HMP. If libvirt uses QMP to talk with
qemu, the command will automatically be converted into QMP. So the
example above is simplified to just

    virsh qemu-monitor-command --hmp DOM "info kvm"

Also the result is converted from

    {"return":"kvm support: enabled\r\n"}

to just plain HMP:

    kvm support: enabled

If libvirt talks to qemu in HMP, --hmp flag is obviously a noop.
2011-02-03 22:20:30 +01:00
Eric Blake
e67ae61991 build: avoid close, system
* src/fdstream.c (virFDStreamOpenFile, virFDStreamCreateFile):
Use VIR_FORCE_CLOSE instead of close.
* tests/commandtest.c (mymain): Likewise.
* tools/virsh.c (editFile): Use virCommand instead of system.
* src/util/util.c (__virExec): Special case preservation of std
file descriptors to child.
2011-01-29 10:36:45 -07:00
Michal Privoznik
30e21374ea virsh: added --all flag to freecell command
This will iterate over all NUMA nodes, showing
free memory for each and sum at the end.
Existing default behavior is not changed.
2011-01-28 15:13:48 -07:00
Wen Congyang
f15cad2916 Force guest suspend at timeout
If the memory of guest OS is changed constantly, the live migration
can not be ended ever for ever.

We can use the command 'virsh migrate-setmaxdowntime' to control the
live migration. But the value of maxdowntime is diffcult to calculate
because it depends on the transfer speed of network and constantly
changing memroy size. We need a easy way to control the live migration.

This patch adds the support of forcing guest to suspend at timeout.
With this patch, when we migrate the guest OS, we can specify a
timeout. If the live migration timeouts, auto-suspend the guest OS,
where the migration will complete offline.
2011-01-27 15:30:42 -07:00
Wen Congyang
d183e9d1e8 Show migration progress.
Show migration progress if `migrate --verbose'.
2011-01-27 15:29:24 -07:00
Hu Tao
8e6d9860cd Cancel migration if user presses Ctrl-C when migration is in progress
While migration is in progress and virsh is waiting for its
completion, user may want to terminate the progress by pressing
Ctrl-C. But virsh just exits on user's Ctrl-C leaving migration
in background that user isn't even aware of. It's not reasonable.

This patch changes the behaviour for migration. For other
commands Ctrl-C still terminates virsh itself.
2011-01-27 15:26:20 -07:00
Michal Privoznik
cee47aace1 virsh: require --mac to avoid detach-interface ambiguity
bugfix for https://bugzilla.redhat.com/show_bug.cgi?id=671050

virsh simply refutes to detach-interface in case when multiple
interfaces are attached and --mac is not specified.
2011-01-25 10:47:28 -07:00
Eric Blake
c5b11b3cc4 build: use more gnulib modules for simpler code
* .gnulib: Update to latest, for sigpipe and sigaction modules.
* bootstrap.conf (gnulib_modules): Add siaction, sigpipe, strerror_r.
* tools/virsh.c (vshSetupSignals) [!SIGPIPE]: Delete, now that
gnulib guarantees it.
(SA_SIGINFO): Define for mingw fallback.
* src/util/virterror.c (virStrerror): Simplify, now that gnulib
guarantees the POSIX interface.
* configure.ac (AC_CHECK_FUNCS_ONCE): Drop redundant check.
(AM_PROG_CC_STDC): Move earlier, to keep autoconf happy.
2011-01-18 15:35:41 -07:00
Matthias Bolte
2095dc39af virsh: Use WITH_SECDRIVER_APPARMOR to detect AppArmor support
There is no ENABLE_SECDRIVER_APPARMOR.
2011-01-15 18:52:36 +01:00
Nikunj A. Dadhania
d94a14f89d memtune: Let virsh know the unlimited value for memory tunables
Display or set unlimited values for memory parameters. Unlimited is
represented by INT64_MAX in memory cgroup.

Signed-off-by: Nikunj A. Dadhania <nikunj@linux.vnet.ibm.com>
Reported-by: Justin Clift <jclift@redhat.com>
2011-01-14 17:17:27 -07:00
Justin Clift
6935a1e289 virsh: ensure --maximum flag used only with --config for setvcpus 2011-01-13 11:02:59 -07:00
Wen Congyang
2fd1a2525b doc: improve the documentation of desturi
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com>
2011-01-12 09:52:51 -07:00
Jiri Denemark
0fdd82e66e virsh: Add --force option to update-device 2010-12-23 09:07:17 +01:00
Hu Tao
29f92d64d3 Fix memory leak in virsh 2010-12-22 08:44:23 -07:00
Justin Clift
6f7c6f8c1f virsh: fix a typo in the memtune help description 2010-12-09 01:53:56 +11:00
Justin Clift
e3cb5a26d2 Moved the nodeinfo command to the 'host' help keyword group 2010-12-08 11:24:37 +11:00
Osier Yang
8eb236c5f7 virsh: Remove redundant commands in group domain
"echo" is already in group "virsh", "freecell" and "hostname" are
already in group "host", so remove them from group "domain"

* tools/virsh.c
2010-12-07 08:23:09 -07:00
Eric Blake
c6506ff8e9 build: avoid shadowing devname() on BSD systems
* tools/virsh.c (cmdRunConsole, cmdConsole): Rename problematic
symbol.
Reported by Justin Clift.
2010-12-03 08:26:40 -07:00
Osier Yang
2636f50842 virsh: Remove redundant optional option for cmdHelp
Remove the optional option "group", as cmdHelp should accepts
only one option ("virsh help" supports both command and command
group now, and user rarely uses the options, so it doesn't matter
much for it being longer, :-)

* tools/virsh.c
2010-12-03 08:22:17 -07:00
Osier Yang
30277bb54c virsh: move two commands from domain group to storage pool group
* tools/virsh.c (find-storage-pool-sources-as and find-storage-pool-sources
should't be in command group "Domain Management", move them to group
"Storage Pool".
2010-12-02 16:09:19 -07:00
Osier Yang
84f7b286c2 virsh: Remove using phy as default disk driver in cmdAttachDisk
* tools/virsh.c (virsh shouldn't use 'phy' as the disk driver if
user doesn't specify "--driver", it causes bugs, as not all of
hypervisor driver supports 'phy', and actually hypervisor should
known the correct default disk driver and subdriver, so remove it)
2010-12-01 19:01:06 -07:00