Commit Graph

360 Commits

Author SHA1 Message Date
Eric Blake
8437e738fa build: use gnulib pthread_sigmask
Gnulib finally learned how to do pthread_sigmask on mingw.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

If you set the following:

 # virsh vcpupin VM 0 r

the vcpu0 will be pinned to all physical cpus.

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

The example:

 # virsh vcpupin Guest 0 0-15,^8

 is identical to

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

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

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

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

Share print_job_progress() with the migration code.

* tools/virsh.c: implement the new commands

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

It will help us use optional argument with VSH_OT_ARGV argument.

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

# virsh help echo
  NAME
    echo - echo arguments

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

  DESCRIPTION
    Echo back arguments, possibly with quoting.

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

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

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

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

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

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

VIR_DOMAIN_MEM_CURRENT
VIR_DOMAIN_MEM_LIVE
VIR_DOMAIN_MEM_CONFIG

VIR_DOMAIN_VCPU_LIVE
VIR_DOMAIN_VCPU_CONFIG

VIR_DOMAIN_DEVICE_MODIFY_CURRENT
VIR_DOMAIN_DEVICE_MODIFY_LIVE
VIR_DOMAIN_DEVICE_MODIFY_CONFIG

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

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

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

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

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

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

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

virsh migrate mistakenly had some variables inside the conditional

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

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

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

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

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

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

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

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

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

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

* tools/virsh.c (VSH_CMD_FLAG_NOCONNECT): New flag.
(vshCmdDef): Add new flags field.
(vshCommandRun): Honor new flag.
(domManagementCmds, domMonitoringCmds, storagePoolCmds)
(storageVolCmds, networkCmds, nodedevCmds, ifaceCmds)
(nwfilterCmds, secretCmds, virshCmds, snapshotCmds)
(hostAndHypervisorCmds): Populate new field.
(vshReconnect): Don't warn on initial connection.
2011-05-18 12:47:46 -06:00
Hu Tao
42af244347 virsh: add parameters --live, --config and --current to cmd schedinfo
This enables user to modify cpu.shares even when domain is inactive.
2011-05-17 10:52:16 -06:00
Jiri Denemark
c256542e76 virsh: Correctly initialize libvirt
virsh didn't call virInitialize(), which (among other things)
initializes virLastErr thread local variable. As a result of that, virsh
could just segfault in virEventRegisterDefaultImpl() since that is the
first call that touches (resets) virLastErr.

I have no idea what lucky coincidence made this bug visible but I was
able to reproduce it in 100% cases but only in one specific environment
which included building in sandbox.
2011-05-17 12:37:30 +02:00
Matthias Bolte
33a5f8ca82 virsh: Report an error when virGetUserDirectory fails
Otherwise virsh shows the interactive greeting and then silently exists
instead of entering interactive mode.
2011-05-16 18:40:04 +02:00
Jiri Denemark
0eaf4d93be virsh: Prefer virDomainGetState over virDomainGetInfo 2011-05-16 10:04:19 +02:00
Matthias Bolte
992f2b4e32 virsh: Fix uninitialized variable warning
Reported on FreeBSD only.
2011-05-14 06:54:18 +02:00
Lai Jiangshan
a083d44c87 inject-nmi: Expose the new API in virsh 2011-05-10 11:40:51 -06:00
Matthias Bolte
fc0ab50abd Fix two uninitialized variable warnings
gcc only reports them when compiling with -O3.
2011-05-10 08:39:56 +02:00
Eric Blake
f84fe150e1 maint: avoid comparisons to bool constants
HACKING already mentions that comparisons against literal 'true'
are unsafe; for consistency, also shorten comparisons against 'false'.

* src/conf/domain_conf.c (virDomainNetDefParseXML): Simplify.
* src/nwfilter/nwfilter_gentech_driver.c
(virNWFilterDomainFWUpdateCB): Likewise.
* tools/virsh.c (cmdVolDownload, vshCommandRun, vshPrintExtra):
Likewise.
2011-05-06 10:28:28 -06:00
Eric Blake
f99e1389cc virsh: use new method for easier log to file
Easier to maintain, and no longer an arbitrary line length limit.

* tools/virsh.c (vshOutputLogFile): Replace snprintf with
virBuffer.
2011-05-05 13:48:19 -06:00
Eric Blake
68ea80cfdd maint: rename virBufferVSprintf to virBufferAsprintf
We already have virAsprintf, so picking a similar name helps for
seeing a similar purpose.  Furthermore, the prefix V before printf
generally implies 'va_list', even though this variant was '...', and
the old name got in the way of adding a new va_list version.

global rename performed with:

$ git grep -l virBufferVSprintf \
  | xargs -L1 sed -i 's/virBufferVSprintf/virBufferAsprintf/g'

then revert the changes in ChangeLog-old.
2011-05-05 13:47:40 -06:00
Eric Blake
44699b3283 virsh: avoid null pointer dereference
Clang detected that vol-download will call unlink(NULL) if there
is a parse error during option parsing.  Also, mingw doesn't like
unlinking an open file.

* tools/virsh.c (cmdVolDownload): Only unlink file if created.
2011-05-03 11:00:25 -06:00
Supriya Kannery
0431551435 virsh: fix regression in log to file
Commit 36deff04 introduced a regression due to which virsh is not able
to log to a file - msg_buf was changed from an array to a pointer
without corresponding change to usage of "sizeof()".

Fix regression in virsh logging

Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
2011-04-30 10:28:02 -06:00
Eric Blake
e39c46a5fd build: fix getcwd portability problems
* bootstrap.conf (gnulib_modules): Add getcwd-lgpl.
* tests/commandtest.c (checkoutput): Drop unused cwd.
* tests/commandhelper.c (main): Let getcwd malloc.
* tests/testutils.c (virTestMain): Likewise.
* tools/virsh.c (cmdPwd): Likewise.
(virshCmds): Expose cmdPwd and cmdCd on mingw.
2011-04-29 12:08:26 -06:00
Eric Blake
c63ec6e347 virsh: avoid compiler warning on mingw
We don't use gnulib's sanitizations for vfprintf, but vshDebug
was used with %zu, which means that it would fail on mingw.
Thank goodness the compiler indirectly caught this for us :)

virsh.c: In function 'vshDebug':
virsh.c:12105:5: warning: function might be possible candidate for
'ms_printf' format attribute [-Wmissing-format-attribute]

since mingw <stdio.h> hasn't yet added gcc attributes to vfprintf.

* tools/virsh.c (vshDebug): Avoid vfprintf.
(vshPrintExtra): Use lighter-weight fputs.
Reported by Matthias Bolte.
2011-04-28 15:09:08 -06:00
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
Osier Yang
33e38e7710 virsh: update help for "virsh help help"
As virsh help supports both command and command group now,
update "cmdHelp" to print consite help, (this patch is
increment of "7829052757953023b0826e0293ffe18ed4ab89e9").

And also remove redundant empty line in "vshUsage".

* tools/virsh.c
2010-12-01 09:13:11 -07:00
Justin Clift
270b0b5f2e virsh: remove a badly placed line break in virsh -h output
The output was previously:

    -c | --connect <uri>    hypervisor connection URI
    -r | --readonly         connect readonly
    -d | --debug <num>      debug level [0-5]
    -h | --help             this help
    -q | --quiet            quiet mode
    -t | --timing           print timing information
    -l | --log <file>       output logging to file
    -v | --version[=short]  program version

    -V | --version=long     version and full options

(note the blank line between the --version types)

This patch removes the extra blank line.
2010-12-02 00:28:10 +11:00
Osier Yang
7829052757 virsh: Categorize commands into groups for virsh help
Change the virsh help out. The new output of "virsh help" and
"virsh --help" will be like:

 Secret (help keyword 'secret'):
    secret-define                  define or modify a secret from an XML file
    secret-dumpxml                 secret attributes in XML
    secret-set-value               set a secret value
    secret-get-value               Output a secret value
    secret-undefine                undefine a secret
    secret-list                    list secrets

 Snapshot (help keyword 'snapshot'):
    snapshot-create                Create a snapshot
    snapshot-current               Get the current snapshot
    snapshot-delete                Delete a domain snapshot
    snapshot-dumpxml               Dump XML for a domain snapshot
    snapshot-list                  List snapshots for a domain
    snapshot-revert                Revert a domain to a snapshot

Also support output help information of specified command group, e.g.

% ./tools/virsh help "Network Filter"
 Network Filter (help keyword 'filter'):
    nwfilter-define                define or update a network filter from an XML file
    nwfilter-undefine              undefine a network filter
    nwfilter-dumpxml               network filter information in XML
    nwfilter-list                  list network filters
    nwfilter-edit                  edit XML configuration for a network filter

Each group has a help keyword, e.g.

% ./tools/virsh help filter
 Network Filter (help keyword 'filter'):
    nwfilter-define                define or update a network filter from an XML file
    nwfilter-undefine              undefine a network filter
    nwfilter-dumpxml               network filter information in XML
    nwfilter-list                  list network filters
    nwfilter-edit                  edit XML configuration for a network filter

* tools/virsh.c:
  - introduce new struct "vshCmdGrp" and macros to define the groups.
  - split previous array "commands" into small arrays which are orgnized
    by group
  - changed some functions, e.g. "vshCmdDefSearch"
  - Added new functions, e.g. "vshCmdGrpSearch"
  - commands of each group are in "alphabetical order" now.
  - command groups are in "alphabetical order" now.
  - the commands are categorized with reference of
    http://wiki.libvirt.org/page/VirshHelpV2 (by Justin)
  - the modifications doesn't affect tests

* TODO:
  - doc
2010-11-30 13:35:32 -07:00
Eric Blake
416c09bcc0 maint: prohibit most uses of xmlGetProp
Making this change makes it easier to spot the memory leaks
that will be fixed in the next patch.

* cfg.mk (sc_prohibit_xmlGetProp): New rule.
* .x-sc_prohibit_xmlGetProp: New exception.
* Makefile.am (EXTRA_DIST): Ship exception file.
* tools/virsh.c (cmdDetachInterface, cmdDetachDisk): Adjust
offenders.
* src/conf/storage_conf.c (virStoragePoolDefParseSource):
Likewise.
* src/conf/network_conf.c (virNetworkDHCPRangeDefParseXML)
(virNetworkIPParseXML): Likewise.
2010-11-24 15:23:43 -07:00
Daniel P. Berrange
227ed26614 Fix error handling in virsh when listing storage volumes
virsh was not checking for a error code when listing storage
volumes. So when listing volumes in a pool that was shutoff,
no output was displayed

* tools/virsh.c: Fix error handling when listing volumes
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
4d0350fc38 Remove bogus port handling code in virsh
The "find-storage-pool-sources-as" command takes two arguments,
a hostname and a port number. For some reason the code would
also then look for a port number appended to the hostname
string by searching for ':'. This totally breaks if the user
gives an IPv6 address, and is redundant, since you can already
provide a port as a separate argument

* tools/virsh.c: Remove bogus port number handling code
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
9a7caeffdf Allow iSCSI IQN to be set with find-storage-pool-sources-as command
Allow an iSCSI initiator IQN to be set with the XML for the
find-storage-pool-sources-as virsh command

* tools/virsh.c: Add iSCSI IQN support
2010-11-23 15:00:35 +00:00
Daniel P. Berrange
1bae28e49b Switch the virsh XML generation to use virBuffer instead of virAsprintf
The code generating XML for storage pool source discovery is
hardcoded to only allow a hostname and optional port number.
Refactor this code to make it easier to add support for extra
parameters.

* tools/virsh.c: Refactor XML generator
2010-11-23 15:00:34 +00:00
Eric Blake
e8aba782e7 maint: avoid remaining sprintf uses
* cfg.mk (sc_prohibit_sprintf): New rule.
(sc_prohibit_asprintf): Avoid false positives.
* docs/hacking.html.in (Printf-style functions): Document the
policy.
* HACKING: Regenerate.
* .x-sc_prohibit_sprintf: New exemptions.
* Makefile.am (syntax_check_exceptions): Ship new file.
* src/vbox/vbox_tmpl.c (vboxStartMachine, vboxAttachUSB): Use
virAsprintf instead.
* src/uml/uml_driver.c (umlOpenMonitor): Use snprintf instead.
* tools/virsh.c (cmdDetachInterface): Likewise.
* src/security/security_selinux.c (SELinuxGenSecurityLabel):
Likewise.
* src/openvz/openvz_driver.c (openvzDomainDefineCmd): Likewise,
and ensure large enough buffer.
2010-11-17 10:13:12 -07:00
Eric Blake
981d2cdab4 maint: improve i18n on non-Linux
Per the gettext developer:
http://lists.gnu.org/archive/html/bug-gnu-utils/2010-10/msg00019.html
http://lists.gnu.org/archive/html/bug-gnu-utils/2010-10/msg00021.html

gettext() doesn't work correctly on all platforms unless you have
called setlocale().  Furthermore, gnulib's gettext.h has provisions
for setting up a default locale, which is the preferred method for
libraries to use gettext without having to call textdomain() and
override the main program's default domain (virInitialize already
calls bindtextdomain(), but this is insufficient without the
setlocale() added in this patch; and a redundant bindtextdomain()
in this patch doesn't hurt, but serves as a good example for other
packages that need to bind a second translation domain).

This patch is needed to silence a new gnulib 'make syntax-check'
rule in the next patch.

* daemon/libvirtd.c (main): Setup locale and gettext.
* src/lxc/lxc_controller.c (main): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/storage/parthelper.c (main): Likewise.
* tools/virsh.c (main): Fix exit status.
* src/internal.h (DEFAULT_TEXT_DOMAIN): Define, for gettext.h.
(_): Simplify definition accordingly.
* po/POTFILES.in: Add src/storage/parthelper.c.
2010-11-17 10:12:57 -07:00
Eric Blake
0d5f54bb21 maint: use gnulib configmake rather than open-coding things
* bootstrap.conf (gnulib_modules): Add configmake.
* daemon/Makefile.am (libvirtd_CFLAGS): Drop defines provided by
gnulib.
* src/Makefile.am (INCLUDES): Likewise.
* tests/Makefile.am (INCLUDES): Likewise.
* tools/Makefile.am (virsh_CFLAGS): Likewise.
* daemon/libvirtd.c (qemudInitPaths, usage, main): Update
clients.
* src/cpu/cpu_map.c (CPUMAPFILE): Likewise.
* src/driver.c (DEFAULT_DRIVER_DIR): Likewise.
* src/internal.h (_): Likewise.
* src/libvirt.c (virInitialize): Likewise.
* src/lxc/lxc_conf.h (LXC_CONFIG_DIR, LXC_STATE_DIR, LXC_LOG_DIR):
Likewise.
* src/lxc/lxc_conf.c (lxcCapsInit, lxcLoadDriverConfig):
Likewise.
* src/network/bridge_driver.c (NETWORK_PID_DIR)
(NETWORK_STATE_DIR, DNSMASQ_STATE_DIR, networkStartup): Likewise.
* src/nwfilter/nwfilter_driver.c (nwfilterDriverStartup):
Likewise.
* src/qemu/qemu_conf.c (qemudLoadDriverConfig): Likewise.
* src/qemu/qemu_driver.c (qemudStartup): Likewise.
* src/remote/remote_driver.h (LIBVIRTD_PRIV_UNIX_SOCKET)
(LIBVIRTD_PRIV_UNIX_SOCKET_RO, LIBVIRTD_CONFIGURATION_FILE)
(LIBVIRT_PKI_DIR): Likewise.
* src/secret/secret_driver.c (secretDriverStartup): Likewise.
* src/security/security_apparmor.c (VIRT_AA_HELPER): Likewise.
* src/security/virt-aa-helper.c (main): Likewise.
* src/storage/storage_backend_disk.c (PARTHELPER): Likewise.
* src/storage/storage_driver.c (storageDriverStartup): Likewise.
* src/uml/uml_driver.c (TEMPDIR, umlStartup): Likewise.
* src/util/hooks.c (LIBVIRT_HOOK_DIR): Likewise.
* tools/virsh.c (main): Likewise.
* docs/hooks.html.in: Likewise.
2010-11-17 08:58:58 -07:00
Stefan Berger
8e3051af84 replace last instances of close()
I am replacing the last instances of close() I found with VIR_CLOSE() / VIR_FORCE_CLOSE respectively.

The first part patches virsh, which I missed out on previously.

The 2nd patch I had left out intentionally to look at it more carefully:
The 'closed' variable could be easily removed since it wasn't used anywhere else. The possible race condition that could result from the filedescriptor being closed and not set to -1 (and possibly let us write into 'something' totally different if the fd was allocated by another thread) seems to be prevented by the qemuMonitorLock() already placed around the code that reads from or writes to the fd. So the change of this code as shown in the patch should not have any side-effects.
2010-11-17 10:19:13 -05:00
Osier Yang
21f5283328 virsh: add net-info command
To list basic information about the network.

* tools/virsh.c
* tools/virsh.pod
2010-11-16 09:18:06 -07:00
Daniel P. Berrange
a926156792 Fix reference counting bug in virsh console
The event watches need to be removed before the event loop
terminates, otherwise they cause a dangling reference to
be held on the virStreamPtr, which in turns holds a reference
on virConnectPtr, which in turn causes errors like

  "Failed to disconnect from the hypervisor"

* tools/console.c: Remove watches before event loop quits
* tools/virsh.c: Print out dangling reference count
2010-11-11 16:03:36 +00:00
Daniel P. Berrange
dad4b5d47f Re-write virsh console to use streams
This re-writes the 'virsh console' command so that it uses
the new streams API. This lets it run remotely and/or as a
non-root user. This requires that virsh be linked against
the simple event loop from libvirtd in daemon/event.c
As an added bonus, it can now connect to any console device,
not just the first one.

* tools/Makefile.am: Link to event.c
* tools/console.c, tools/console.h: Rewrite to use the
  virDomainOpenConsole() APIs with streams
* tools/virsh.c: Support choosing the console name
  via --devname $NAME
2010-11-11 16:03:20 +00:00
Eric Blake
51c83a2b1a virsh: supply long option for -V
* tools/virsh.c (vshParseArgv): Use NULL instead of 0 for pointer,
and symbolic names for has_arg.  Give --version an optional arg.
(vshUsage): Document this.
* tools/virsh.pod: Likewise.
2010-11-10 16:57:40 -07:00
Laine Stump
ff4a31d969 virsh: fix non-literal string format
These are in the newly added -V output.
2010-11-09 17:37:05 -05:00
Stefan Berger
60ae1c34ad bye to close(), welcome to VIR_(FORCE_)CLOSE()
Using automated replacement with sed and editing I have now replaced all
occurrences of close() with VIR_(FORCE_)CLOSE() except for one, of
course. Some replacements were straight forward, others I needed to pay
attention. I hope I payed attention in all the right places... Please
have a look. This should have at least solved one more double-close
error.
2010-11-09 15:48:48 -05:00
Jiri Denemark
fb76151c28 virsh: Add .xml suffix to tmp files used in *edit commands
This helps editors with detecting the temporary files as XML since the
temporary files do not contain <?xml ...?> declaration.

Requested by https://bugzilla.redhat.com/show_bug.cgi?id=602277
2010-11-09 13:42:54 +01:00
Daniel Veillard
5879c15dfd Show compiled in options in virsh -V
To ease debugging this trivial patch allows to find what was compiled
in in the local version of libvirt, this doesn't work for remote access
but that's probably sufficient. With the patch I get on my machine:

paphio:~/libvirt/tools -> ./virsh -V
Virsh command line tool of libvirt 0.8.4
See web site at http://libvirt.org/

Compiled with support for:
 Hypervisors: Xen QEmu/KVM UML OpenVZ LXC ESX PHYP Test
 Networking: Remote Daemon Network Bridging Netcf Nwfilter
 Storage: Dir Disk Filesystem SCSI Multipath iSCSI LVM
 Miscellaneous: SELinux Secrets Debug Readline
paphio:~/libvirt/tools ->

* tools/virsh.c: add -V option
* tools/virsh.pod: document the extension
2010-11-09 12:01:33 +01:00
Justin Clift
c690cf831d virsh: fix incorrect help text mentioning non-existent network 'id' 2010-11-09 01:35:27 +11:00
Chris Lalancette
a5b5307da2 Implement virsh qemu-monitor-command.
Now that the virsh parsing has been revamped, we can
implement qemu-monitor-command.  This is basically the same
as it was in previous iterations, but has now been tested to
work both with the plain text monitor and the QMP monitor.

Signed-off-by: Chris Lalancette <clalance@redhat.com>
2010-11-05 12:14:21 -04:00
Justin Clift
3fb71895e8 virsh: improve the help description for managedsave and start
Updated the descriptions for managedsave and start in virsh and
the virsh man page, and also for managedsave-remove in the virsh
man page.
2010-10-29 11:52:31 +11:00
Eric Blake
bac73e7f68 virsh: use - not _ in memtune option names
* tools/virsh.c (opts_memtune): All other options in virsh use -
for separating words.
2010-10-26 15:55:12 -06:00
Eric Blake
009035ffad virsh: fix range of memtune command
* tools/virsh.c (cmdMemtune): Use long long for memory
sizes. Simplify allocation, and plug memory leak.
2010-10-26 09:31:42 -06:00
Eric Blake
c1564268c4 virsh: improve help text where integers are expected
* tools/virsh.c (opts_freecell, opts_memtune, opts_vcpupin)
(opts_setvcpus, opts_setmaxmem, opts_setmem)
(opts_migrate_setmaxdowntime): Use VSH_OT_INT when only an integer
is expected.
(vshCmddefHelp, vshCmddefGetData): Allow mandatory VSH_OT_INT
arguments.
2010-10-26 09:31:42 -06:00
Osier Yang
1a29a14a2f virsh: Add option 'model' for attach-interface
* tools/virsh.c: add missing option from the CLI to allows setting
  up the NIC model type when attaching an interface
* tools/virsh.pod: extend documentation
* AUTHORS: add Osier Yang to the list
2010-10-26 10:36:40 +02:00
Matthias Bolte
076cf3a0bd virsh: Don't read nparams when virDomainGetMemoryParameters fails
Also exit early when nparams is 0.
2010-10-20 19:33:11 +02:00
Matthias Bolte
916f95b7aa Rename VIR_DOMAIN_SWAP_HARD_LIMIT to VIR_DOMAIN_MEMORY_SWAP_HARD_LIMIT
To get them under the common VIR_DOMAIN_MEMORY_* prefix.
2010-10-20 19:33:11 +02:00
Eric Blake
bf945ee97b vcpu: add virsh support
* tools/virsh.c (cmdSetvcpus): Add new flags.  Let invalid
commands through to driver, to ease testing of hypervisor argument
validation.
(cmdMaxvcpus, cmdVcpucount): New commands.
(commands): Add new commands.
* tools/virsh.pod (setvcpus, vcpucount, maxvcpus): Document new
behavior.
2010-10-19 10:06:11 -06:00
Nikunj A. Dadhania
0a22f54248 memtune: Add min_guarantee to the virsh memtune command
* tools/virsh.c: Add new memory tunable "min_guarantee", currently only
  ESX can use this
* tools/virsh.pod: Update the manpage
2010-10-19 14:45:35 +02:00
Eric Blake
b2aedb8e98 virsh: new echo command
* tools/virsh.c (cmdEcho): New command.
(commands): Add it.
* tools/virsh.pod (echo): Document it.
2010-10-15 14:25:39 -06:00
Eric Blake
72e884d577 virsh: add support for accepting arbitrary argv
* tools/virsh.c (vshCmdOptType): Add VSH_OT_ARGV.  Delete
unused VSH_OT_NONE.
(vshCmddefGetData): Special case new opt flag.
(vshCmddefHelp): Display help for argv.
(vshCommandOptArgv): New function.
2010-10-15 14:25:39 -06:00
Eric Blake
59ce32b0dd virsh: update comment about parsing
* tools/virsh.c: Update comments to match patch series.
2010-10-13 07:52:33 -06:00
Eric Blake
ce828d1015 virsh: move code into topological order
* tools/virsh.c (vshCommandParse): Float up, to avoid the need for
a forward declaration.
2010-10-13 07:52:33 -06:00
Eric Blake
5405cffcb4 virsh: simplify top-level option parsing
This makes 'virsh --conn test:///default help help' work right;
previously, the abbreviation confused our hand-rolled option parsing.

* tools/virsh.c (vshParseArgv): Use getopt_long feature, rather
than (incorrectly) reparsing options ourselves.
2010-10-13 07:52:33 -06:00
Lai Jiangshan
227f5df842 virsh: add -- support
"--" means no option at the following arguments.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:33 -06:00
Lai Jiangshan
57868d121b virsh: support single quote
Some users may type command like this at the virsh shell:
virsh # somecmd 'some arg'

because they often use single quote in linux shell.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:33 -06:00
Lai Jiangshan
5232101487 virsh: add escaper \ for command string parsing
add escaper \ for command string parsing, example:

virsh # cd /path/which/have/a/double\"quote

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:33 -06:00
Lai Jiangshan
a2943243c4 virsh: rework command parsing
Old virsh command parsing mashes all the args back into a string and
miss the quotes, this patches fix it. It is also needed for introducing
qemu-monitor-command which is very useful.

This patches uses the new vshCommandParser abstraction and adds
vshCommandArgvParse() for arguments vector, so we don't need
to mash arguments vector into a command sting.

And the usage was changed:
old:
virsh [options] [commands]

new:
virsh [options]... [<command_string>]
virsh [options]... <command> [args...]

So we still support commands like:
"define D.xml; dumpxml D" was parsed as a commands-string.

and support commands like:
we will not mash them into a string, we use new argv parser for it.

But we don't support the command like:
"define D.xml; dumpxml" was parsed as a command-name, but we have no such command-name.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:32 -06:00
Lai Jiangshan
a93f514f5f virsh: add vshCommandParser abstraction
add vshCommandParser and make vshCommandParse() accept different
parsers.

the current code for parse command string is integrated as
vshCommandStringParse().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:32 -06:00
Lai Jiangshan
4417f08de4 virsh: better handling the boolean option
in old code the following commands are equivalent:
     virsh # dumpxml --update-cpu=vm1
     virsh # dumpxml --update-cpu vm1
because the old code split the option argument into 2 parts:
--update-cpu=vm1 is split into update-cpu and vm1,
and update-cpu is a boolean option, so the parser takes vm1 as another
argument, very strange.

after this patch applied, the first one will become illegal.

To achieve this, we don't parse/check options when parsing command sting,
but check options when parsing a command argument. And the argument is
not split when parsing command sting.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:32 -06:00
Lai Jiangshan
cdfe543fc8 virsh: allow zero length arguments
the following command is allowed at shell, we also make it allowed at virsh shell.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
2010-10-13 07:52:32 -06:00