Commit Graph

57 Commits

Author SHA1 Message Date
John Ferlan
5b42dbed98 virsh: Create macro for common "current" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which for many options in virsh-domain.c
is simply "affect current domain". So, create a second macro within that
file in order to define the more common use as a revector to the
common macro with the common _helpstr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
John Ferlan
8e4108f039 virsh: Create macro for common "live" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which for many options in virsh-domain.c
is simply "affect running domain". So, create a second macro within that
file in order to define the more common use as a revector to the
common macro with the common _helpstr.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
John Ferlan
b6fb1e245c virsh: Create macro for common "domain" option
Rather than continually cut-n-paste the strings into each command,
create a common macro to be used generically. The macro will take a
single argument _helpstr which will be used to pass the translatable
helpstr since not all domain options can take the same string.

The majority of the options take 'N_("domain name, id or uuid")', so
create a separate macro with a _FULL suffix while those that do not
take the same string will use the VIRSH_COMMON_OPT_DOMAIN macro.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2016-01-11 18:14:00 -05:00
Erik Skultety
834c5720e4 tools: Introduce new client generic module vsh
In order to share as much virsh' logic as possible with upcomming
virt-admin client we need to split virsh logic into virsh specific and
client generic features.

Since majority of virsh methods should be generic enough to be used by
other clients, it's much easier to rename virsh specific data to virshX
than doing this vice versa. It moved generic virsh commands (including info
and opts structures) to generic module vsh.c.

Besides renaming methods and structures, this patch also involves introduction
of a client specific control structure being referenced as private data in the
original control structure, introduction of a new global vsh Initializer,
which currently doesn't do much, but there is a potential for added
functionality in the future.
Lastly it introduced client hooks which are especially necessary during
client connecting phase.
2015-08-14 15:45:44 +02:00
Andrea Bolognani
be6ff4da95 virsh: Pass vshControl to all vshCommandOpt*() calls
This will allow us to use vshError() to report errors from inside
vshCommandOpt*(), instead of replicating the same logic and error
messages all over the place.

We also have more context inside the vshCommandOpt*() functions,
for example the actual value used on the command line, which means
we can produce more detailed error messages.

vshCommandOptBool() is the exception here, because it's explicitly
designed not to report any error.
2015-06-02 09:20:31 -04:00
Ján Tomko
15e61034a5 Remove unnecessary includes from virsh.h
Include them in the files that need them instead.
2015-04-02 10:27:56 +02:00
Hao Liu
a0670aef37 virsh: Emit error for VSH_OT_DATA without VSH_OFLAG_REQ
Commit 6b9964 enforces checking invalid use of VSH_OT_STRING with
VSH_OFLAG_REQ. This commit tries to do the same thing to stop using
VSH_OT_DATA without VSH_OFLAG_REQ and also fix existing misuse.

Signed-off-by: Hao Liu <hliu@redhat.com>
2015-01-12 13:38:42 +01:00
Martin Kletzander
e09f9e4c32 virsh: Convert EDIT_NOT_CHANGED macro to do-while block.
This macro is being used as an inline body after an if and might get
pretty confusing.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
2014-11-14 17:13:00 +01:00
John Ferlan
daf27d4d82 virsh: Resolve Coverity DEADCODE
Since 0766783abb

Coverity complains that the EDIT_FREE definition results in DEADCODE.

As it turns out with the change to use the EDIT_FREE macro the call to
vir*Free() wouldn't be necessary nor would it happen...

Prior code to above commitid would :

  vir*Ptr foo = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  vir*Free(foo);
  foo = vir*DefineXML()
  ...

And thus the free was needed.  With the change to use EDIT_FREE the
same code changed to:

  vir*Ptr foo = NULL;
  vir*Ptr foo_edited = NULL;
  ...
  foo = vir*GetXMLDesc()
  ...
  if (foo_edited)
      vir*Free(foo_edited);
  foo_edited = vir*DefineXML()
  ...

However, foo_edited could never be set in the code path - even with
all the goto's since the only way for it to be set is if vir*DefineXML()
succeeds in which case the code to allow a retry (and thus all the goto's)
never leaves foo_edited set

All error paths lead to "cleanup:" which causes both foo and foo_edited
to call the respective vir*Free() routines if set.

Signed-off-by: John Ferlan <jferlan@redhat.com>
2014-09-11 08:03:37 -04:00
Ján Tomko
5d8793eebb Indent top-level labels by one space in tools/ 2014-03-25 14:58:41 +01:00
Laine Stump
64bb902451 virsh: eliminate hardcoded indentation in xml generated for commands
These are never seen externally, only passed into libvirt APIs, so in
practice this makes no real difference, but it's good to be
consistent.
2014-03-14 00:02:38 -06:00
Peter Krempa
d64af6ce3c virsh: modify vshStringToArray to duplicate the elements too
At a slightly larger memory expense allow stealing of items from the
string array returned from vshStringToArray and turn the result into a
string list compatible with virStringSplit. This will allow to use the
common dealloc function.

This patch also fixes a few forgotten checks of return from
vshStringToArray and one memory leak.
2013-08-20 17:53:49 +02:00
Jim Fehlig
e3b21cdc31 Fix virsh snapshot-list error reporting
Noticed that the expected "not supported" error is dropped when
invoking 'virsh snapshot-list dom' on a Xen installation running
the libxl driver

 virsh snapshot-list test
 error: Invalid snapshot: virDomainSnapshotFree

The error is overwritten by a call to virDomainSnapshotFree
in cleanup code within cmdSnapshotList.  Prevent overwritting
the real error by not calling virDomainSnapshotFree with a NULL
virDomainSnapshotPtr.
2013-07-25 14:22:47 -06:00
Daniel P. Berrange
111f6f4d73 Convert 'int i' to 'size_t i' in tools/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-10 17:40:13 +01:00
Laine Stump
bfe7721d50 util: move virFile* functions from virutil.c to virfile.c
These all existed before virfile.c was created, and for some reason
weren't moved.

This is mostly straightfoward, although the syntax rule prohibiting
write() had to be changed to have an exception for virfile.c instead
of virutil.c.

This movement pointed out that there is a function called
virBuildPath(), and another almost identical function called
virFileBuildPath(). They really should be a single function, which
I'll take care of as soon as I figure out what the arglist should look
like.
2013-05-10 13:09:30 -04:00
Michal Privoznik
7c9a2d88cd virutil: Move string related functions to virstring.c
The source code base needs to be adapted as well. Some files
include virutil.h just for the string related functions (here,
the include is substituted to match the new file), some include
virutil.h without any need (here, the include is removed), and
some require both.
2013-05-02 16:56:55 +02:00
Peter Krempa
03122d7baf virsh-snapshot: Simplify cleanup path in cmdSnapshotEdit 2013-03-21 12:32:04 +01:00
Peter Krempa
29882a054e virsh-snapshot: Use the mutually exclusive params macro in cmdSnapshotEdit 2013-03-21 12:32:03 +01:00
Peter Krempa
4baf00fc30 virsh-snapshot: Refactor cmdSnapshotCurrent
Use the exclusive parameter checker and touch up some parts to simplify
code.
2013-03-21 12:32:03 +01:00
Peter Krempa
55b3b15cd0 virsh-snapshot: Refactor virsh snapshot-list
Simplify error handling and mutually exclusive option checking.
2013-03-21 12:32:03 +01:00
Martin Kletzander
73cc87d161 Cleanup useless flags specifications
After we switched to C99 initialization, I noticed there were many
places where the specification of .flags parameter differed.  After
going through many options and deciding whether to unify the
initialization to be '.flags = 0' or '.flags = VSH_OFLAG_NONE', I
realized both can be removed and it makes the code easier to go
through.
2013-03-15 15:05:45 +01:00
Martin Kletzander
66f1bbc350 Fix snapshot-create-as syntax in help output
According to the man page, the memspec parameter should have the
'--memspec' option mandatory and this is as close as we can get to
that.  What this change does is explained below.

man virsh:

snapshot-create-as ... [[--live] [--memspec memspec]]

virsh help snapshot-create-as before this patch:

  SYNOPSIS
    snapshot-create-as ... [<memspec>] ...
...
  OPTIONS
    [--memspec] <string> ...

virsh help snapshot-create-as after this patch:

  SYNOPSIS
    snapshot-create-as ... [--memspec <string>] ...
...
  OPTIONS
    --memspec <string> ...
2013-03-15 15:05:44 +01:00
Ján Tomko
2fc5ff11ab virsh: fix snapshot-create with no xmlfile
Properly check the return value of vshCommandOptStringReq for xmlfile:
* error out on incorrect input (--xmlfile '')
* use default XML <domainsnapshot/> with no --xmlfile specified

(Broken by commit b2e8585)

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=919826
2013-03-11 13:39:11 +01:00
Peter Krempa
0d00c7a3bd virsh-snapshot: Add ability to print only snapshot names
Help script creators by not having to parse the names from the table.
2013-03-05 08:34:48 +01:00
Michal Privoznik
53b574812b virsh-snapshot.c: Switch to c99 initialization of vshCmdInfo 2013-02-12 17:50:22 +01:00
Michal Privoznik
df5fd11f86 virsh: Switch to c99 initialization of vshCmdDef 2013-02-12 17:50:21 +01:00
Peter Krempa
fe69656ea9 virsh-snapshot: Reject --no-metadata together with --print-xml
Manual for "virsh snapshot-create-as" states that --no-metadata and
--print-xml are incompatible. Honor this detail in the code.
2013-02-11 14:50:20 +01:00
Peter Krempa
02b0d3f3ac virsh-snapshot: Refactor some details in virsh snapshot-create-as
This patch simplifies the creation of XML, some error paths and adds
correct approach to check for virBuffer errors.
2013-02-11 14:50:20 +01:00
Peter Krempa
e06816289c virsh-snapshot: Fix XPath query to determine snapshot state
The query didn't match the external state correctly for offline internal
snapshots.
2013-02-08 15:38:22 +01:00
Peter Krempa
b2e8585555 virsh-snapshot: Update snapshot commands to use vshCommandOptStringReq
also avoids potential NULL pointer dereference:

$ virsh snapshot-current asdf ""
error: invalid snapshotname argument '(null)'

by removing the error message in favor of vshCommandOptStringReq
2013-02-04 14:17:45 +01:00
Peter Krempa
351f7a2f2c virsh-snapshot: Refactor cmdSnapshotDumpXML
This patch simplifies error paths and switches to use
vshCommandOptStringReq for argument retrieval in cmdSnapshotDumpXML
2013-02-04 14:17:44 +01:00
Peter Krempa
f4464002fc virsh-snapshot: Fix coding style and remove dead code
buffer won't be NULL in any case when reaching the check and the first
block of the if statement was lacking parentheses
2013-02-04 10:34:33 +01:00
Michal Privoznik
8571608924 virsh-snapshot.c: Switch to C99 initialization of vshCmdOptDef 2013-01-17 13:58:53 +01:00
Daniel P. Berrange
556cf5f617 Rename xml.{c,h} to virxml.{c,h} 2012-12-21 11:19:50 +00:00
Daniel P. Berrange
44f6ae27fe Rename util.{c,h} to virutil.{c,h} 2012-12-21 11:19:49 +00:00
Daniel P. Berrange
ab9b7ec2f6 Rename memory.{c,h} to viralloc.{c,h} 2012-12-21 11:17:14 +00:00
Daniel P. Berrange
2005f7b552 Rename buf.{c,h} to virbuffer.{c,h}
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2012-12-21 11:17:12 +00:00
Peter Krempa
fe910efd8a virsh: Report error when taking a snapshot with empty --memspec argument
When the value of memspec was empty taking of a snapshot failed without
reporting an error.
2012-11-23 13:55:43 +01:00
Eric Blake
0f9b6ee42d snapshot: expose location through virsh snapshot-info
Now that we can filter on this information, we should also make
it easy to get at.

* tools/virsh-snapshot.c (cmdSnapshotInfo): Add another output
row, and switch to XPath queries rather than strstr.
2012-11-19 14:16:52 -07:00
Eric Blake
1d272e8f22 snapshot: add virsh back-compat support for new filters
Snapshot filtering based on types is useful enough to add
back-compat support into virsh.  It is also rather easy - all
versions of libvirt that don't understand the new filter flags
already gave us sufficient information in a single XML field
to reconstruct all the information we need (that is, it isn't
until libvirt 1.0.1 that we have more interesting types of
snapshots, such as offline external).

* tools/virsh-snapshot.c (vshSnapshotFilter): New function.
(vshSnapshotListCollect): Add fallback support.
2012-11-19 14:16:36 -07:00
Eric Blake
e9028f4b73 snapshot: add two more filter sets to API
As we enable more modes of snapshot creation, it becomes more important
to be able to quickly filter based on snapshot properties.  This patch
introduces new filter flags; subsequent patches will introduce virsh
back-compat filtering, as well as actual libvirt filtering.

* include/libvirt/libvirt.h.in (virDomainSnapshotListFlags): Add
five new flags in two new groups.
* src/libvirt.c (virDomainSnapshotNum, virDomainSnapshotListNames)
(virDomainListAllSnapshots, virDomainSnapshotNumChildren)
(virDomainSnapshotListChildrenNames)
(virDomainSnapshotListAllChildren): Document them.
* src/conf/snapshot_conf.h (VIR_DOMAIN_SNAPSHOT_FILTERS_STATUS)
(VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION): Add new convenience filter
collection macros.
* tools/virsh-snapshot.c (cmdSnapshotList): Add 5 new flags.
* tools/virsh.pod (snapshot-list): Document them.
2012-11-19 08:43:00 -07:00
Ján Tomko
689b64d666 virsh: fix uninitialized variable in cmdSnapshotEdit
If the domain can't be looked up, name is used unitialized after the
cleanup label.

Found by coverity.
2012-11-15 11:45:40 +01:00
Eric Blake
2cd4d8e506 virsh: add snapshot-create-as memspec support
External checkpoints could be created with snapshot-create, but
without libvirt supplying a default name for the memory file,
it is essential to add a new argument to snapshot-create-as to
allow the user to choose the memory file name.  This adds the
option --memspec [file=]name[,snapshot=type], where type can
be none, internal, or external.  For an example,

virsh snapshot-create-as $dom --memspec /path/to/file

is the shortest possible command line for creating an external
checkpoint, named after the current timestamp.

* tools/virsh-snapshot.c (vshParseSnapshotMemspec): New function.
(cmdSnapshotCreateAs): Use it.
* tests/virsh-optparse (test_url): Test it.
* tools/virsh.pod (snapshot-create-as): Document it.
2012-11-07 09:04:18 -07:00
Eric Blake
9d91a18ebf virsh: make ,, escape parsing common
So far, none of the existing callers of vshStringToArray expected
the user to ever pass a literal comma; meanwhile, snapshot parsing
had rolled its own array parser.  Moving the comma escaping into
the common function won't affect any existing callers, and will make
this function reusable for adding memory handling to snapshot parsing.

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

* tools/virsh-snapshot.c (vshParseSnapshotDiskspec): Move ,,
parsing...
* tools/virsh.c (vshStringToArray): ...into common function.
Also, vshStrdup can't fail.
2012-11-07 09:01:37 -07:00
Peter Krempa
5f75bd4bbe snapshot: Add flag to enable creating checkpoints in live state
The default behavior while creating external checkpoints is to pause the
guest while the memory state is captured. We want the users to sacrifice
space saving for creating the memory save image while the guest is live
to minimize downtime.

This patch adds a flag that causes the guest not to be paused before
taking the snapshot.
 *include/libvirt/libvirt.h.in:
    - add new paused reason: VIR_DOMAIN_PAUSED_SNAPSHOT
    - add new flag for taking snapshot: VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh-domain-monitor.c:
    - add string representation for VIR_DOMAIN_PAUSED_SNAPSHOT
 *tools/virsh-snapshot.c:
    - add support for VIR_DOMAIN_SNAPSHOT_CREATE_LIVE
 *tools/virsh.pod:
    - add docs for --live option added to use
    VIR_DOMAIN_SNAPSHOT_CREATE_LIVE flag
2012-11-03 14:43:01 +01:00
Eric Blake
3cdf4dd49a snapshot: improve snapshot-list error message
https://bugzilla.redhat.com/show_bug.cgi?id=869100 mentioned some
confusion about 'virsh snapshot-list' errors.  Clean up a
misleading error message, and add some documentation.

* tools/virsh-snapshot.c (cmdSnapshotList): Mention --current
rather than --from when appropriate.
* tools/virsh.pod (snapshot-list): Mention that the named starting
point is NOT part of the list except under --tree.
2012-10-25 16:48:08 -06:00
Osier Yang
e0ad466983 virsh: Fix segfault of snapshot-list
'snaps' is used after free()'ed.
2012-10-22 22:52:05 +08:00
Eric Blake
4ecb723b9e maint: fix up copyright notice inconsistencies
https://www.gnu.org/licenses/gpl-howto.html recommends that
the 'If not, see <url>.' phrase be a separate sentence.

* tests/securityselinuxhelper.c: Remove doubled line.
* tests/securityselinuxtest.c: Likewise.
* globally: s/;  If/.  If/
2012-09-20 16:30:55 -06:00
Peter Krempa
67f83cd497 virsh: remove unneeded usage of vshConnectionUsability()
Now that vshCommandRun() checks for the connection automaticaly, remove
all of the redundant checks in the code.

vshConnectionUsability() no longer needs to be exported and this patch
marks it static.
2012-08-31 16:22:22 +02:00
Guannan Ren
44574a8789 virsh: don't print error info when snapshot xml is not changed
If xml is not changed, error message is printed.
So check ret value instead of edit variable for error message.
2012-08-22 19:15:03 +08:00