* tools/virsh.c: avoid memory leak in cmdVolPath.
* src/libvirt.c: Add doc for virStorageVolGetPath to tell one
must free() the returned path after use.
* how to reproduce?
% dd if=/dev/zero of=/var/lib/libvirt/images/foo.img count=1 bs=10M
% virsh pool-refresh default
% valgrind -v --leak-check=full virsh vol-path --vol \
/var/lib/libvirt/images/foo.img
* actual results:
Detected in valgrind run:
==16436== 32 bytes in 1 blocks are definitely lost in loss record 7 of 22
==16436== at 0x4A05FDE: malloc (vg_replace_malloc.c:236)
==16436== by 0x386A314B3D: xdr_string (in /lib64/libc-2.12.so)
==16436== by 0x3DF8CD770D: xdr_remote_nonnull_string (remote_protocol.c:3
==16436== by 0x3DF8CD7EC8: xdr_remote_storage_vol_get_path_ret
% virsh pool-refresh default
% valgrind -v --leak-check=full virsh vol-path --vol \
/var/lib/libvirt/images/foo.img
Signed-off-by: Alex Jia <ajia@redhat.com>
Rename the existing --current flag to the new name --active,
while adding a new flag --current to expose the new
VIR_DOMAIN_AFFECT_CURRENT flag of virDomainGetVcpusFlags.
For backwards compability, the output does not change (even
though the label "current" no longer matches the spelling of
the option that would trigger that number in isolation), and
we accept "--current --live" as an undocumented synonym for
"--active --live" to avoid breaking any existing clients.
* tools/virsh.c (cmdVcpucount): Add --active flag, and rearrange
existing flag handling to expose VIR_DOMAIN_AFFECT_CURRENT support.
* tools/virsh.pod (vcpucount): Document this.
Define two new virsh commands:
* blockpull: Initiate a blockPull for the given disk
* blockjob: Retrieve progress info, modify speed, and cancel active block jobs
Share print_job_progress() with the migration code.
* tools/virsh.c: implement the new commands
Now you can edit a saved state file even if you forgot to grab
a dumpxml file prior to saving a domain. Plus, in-place editing
feels so much nicer.
* tools/virsh.c (cmdSaveImageDumpxml, cmdSaveImageDefine)
(cmdSaveImageEdit): New commands.
* tools/virsh.pod (save-image-dumpxml, save-image-define)
(save-image-edit): Document them.
Also, migrate was missing documentation for the --xml option
added in commit ec5301cb.
* tools/virsh.c (cmdSave, cmdRestore): Add xml argument.
* tools/virsh.pod (save, restore, migrate): Document it.
Wire up the new flag to several virsh commands. Also, the
'dump' command had undocumented flags.
* tools/virsh.c (cmdSave, cmdManagedSave, cmdDump, cmdStart)
(cmdRestore): Add new flag.
* tools/virsh.pod (save, managedsave, dump, start, restore):
Document flags.
If the domain has managed save image, and --managed-save is
not specified, then it fails with an error telling the user
that a managed save image still exists.
If the domain has managed save image, and --managed-save is
specified, it invokes virDomainUndefineFlags. If
virDomainUndefineFlags fails, then it tries to remove the managed
save image using virDomainManagedSaveRemove first, with
invoking virDomainUndefine following. (For compatibility between
new virsh with this patch and older libvirt without this patch).
Similarly if the domain has no managed save image. See the codes for
detail.
NOTE: Have not removing the codes checking if the domain is running
in function "cmdUndefine", it will go along with qemu driver's fix
(allow to undefine a running domain).
* tools/virsh.c: new column "Managed save" for "cmdDominfo".
* tools/virsh.pod: Update document of "managedsave" to tell one can
use "dominfo" to query whether a domain has any managed save image.
We can make the virsh migrate UI friendlier by supplying the
missing bit automatically instead of erroring out when requesting
--tunnelled without --p2p.
* tools/virsh.c (doMigrate): Make --p2p optional when using
--tunnelled.
* tools/virsh.pod (migrate): Tweak wording accordingly.
* tools/virsh.c: avoid double free of domain, when weight value of blkiotune
less than 0, codes will free domain and jump to cleanup section, however,
cleanup will free domain again.
Detected in valgrind run:
==21297== ERROR SUMMARY: 20 errors from 20 contexts (suppressed: 69 from 8)
==21297==
==21297== 1 errors in context 1 of 20:
==21297== Invalid read of size 4
==21297== at 0x40E209B: virDomainFree (libvirt.c:2096)
==21297== by 0x8065274: cmdBlkiotune (virsh.c:3695)
==21297== by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297== by 0x806B967: main (virsh.c:14487)
==21297== Address 0x446ad48 is 0 bytes inside a block of size 36 free'd
==21297== at 0x4005B0A: free (vg_replace_malloc.c:325)
==21297== by 0x406814D: virFree (memory.c:310)
==21297== by 0x40D6635: virReleaseDomain (datatypes.c:243)
==21297== by 0x40D6C5E: virUnrefDomain (datatypes.c:280)
==21297== by 0x40E20B9: virDomainFree (libvirt.c:2101)
==21297== by 0x8065297: cmdBlkiotune (virsh.c:3613)
==21297== by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297== by 0x806B967: main (virsh.c:14487)
==21297==
==21297==
==21297== 1 errors in context 2 of 20:
==21297== Invalid read of size 4
==21297== at 0x40E1FE6: virDomainFree (libvirt.c:2092)
==21297== by 0x8065274: cmdBlkiotune (virsh.c:3695)
==21297== by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297== by 0x806B967: main (virsh.c:14487)
==21297== Address 0x446ad48 is 0 bytes inside a block of size 36 free'd
==21297== at 0x4005B0A: free (vg_replace_malloc.c:325)
==21297== by 0x406814D: virFree (memory.c:310)
==21297== by 0x40D6635: virReleaseDomain (datatypes.c:243)
==21297== by 0x40D6C5E: virUnrefDomain (datatypes.c:280)
==21297== by 0x40E20B9: virDomainFree (libvirt.c:2101)
==21297== by 0x8065297: cmdBlkiotune (virsh.c:3613)
==21297== by 0x8054CC1: vshCommandRun (virsh.c:13135)
==21297== by 0x806B967: main (virsh.c:14487)
* how to reproduce?
% valgrind -v --leak-check=full virsh blkiotune guestname --weight -1
The documentation for vshCommandOptString claims that it returns
-1 on a missing required argument, but in reality, that error
message was unreachable (it was buried inside an if clause that
is true only if the argument was present). The code was so hairy
that I decided a rewrite would make it easier to understand,
and actually return the error values we want.
Meanwhile, our construction guarantees that all vshCmdOpt have
a non-null def member, so there are some redundant checks that
can be trimmed.
* tools/virsh.c (vshCommandOpt): Alter signature.
(vshCommandOptInt, vshCommandOptUInt, vshCommandOptUL)
(vshCommandOptString, vshCommandOptLongLong)
(vshCommandOptULongLong, vshCommandOptBool): Adjust all callers.
(vshCommandOptArgv): Remove dead condition.
This adds four options for virsh command attach-disk.
--cache option allows user to specify cache mode of disk device
from virsh command line when attaching a disk device.
--serial option allows user to specify serial string of disk device
from virsh command line when attaching a disk device.
--shareable option allows user to specify whether the disk device is
shareable between domains when attaching a disk device from virsh
command line.
--address option allows user to specify address of disk device when
attaching a disk device.
This patch adds the --current option to "virsh setvcpus"
command. Currently "virsh setvcpus" command supports
"--live" and "--config" , but "--current" option.
From view of consistency, it's reasonable to support
"--current" option too.
When --current is specified, it affects a "current"
domain.
Signed-off-by: Taku Izumi <izumi.taku@jp.fujitsu.com>
The last patch breaks make check for two reasons. First, it reverses the
condition but leaves default level unchanged, so instead of not printing
anything but errors before the patch it now prints all debug messages by
default. Second, you forgot to change -d5 option passed to virsh in
tests/virsh-optparse to -d0; the script wants to see all debug messages.
Aligning loglevel values of virsh to that of libvirt.
"DEBUG"=0 loglevel, when specified through commandline or
env variable, should log all the messages. "ERROR=4"
should log only error messages.
Signed-off-by: Supriya Kannery <supriyak@in.ibm.com>
Destroy has a rather negative English connotation. Try to reduce
the impact, so newbies aren't as scared to use it.
* tools/virsh.c: Tweak all destroy documentation.
* tools/virsh.pod: Likewise.
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.
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.
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>
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>
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
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.
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.
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
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>
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>
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.
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>
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>
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>
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".
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.
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.
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.
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.
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.
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
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
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.
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
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.
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.
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.
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.
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>
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.
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.
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.
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.
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.
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>
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>
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>
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.
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.
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
"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.
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>
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.
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
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
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
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.
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.
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
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.
* 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.
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.
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.
* .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.
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>
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
* 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".
* 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)
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
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.
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
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.
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
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
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
Per the gettext developer:
http://lists.gnu.org/archive/html/bug-gnu-utils/2010-10/msg00019.htmlhttp://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.
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.
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
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
* 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.