Commit Graph

798 Commits

Author SHA1 Message Date
Peter Krempa
c344784b88 virsh: cmdDesc: Use 'vshTempFile' type to simplify cleanup
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:57 +01:00
Peter Krempa
a3ef5414ed virsh: cmdDesc: Use separate flags variable for getters
The getters have a different set of flags. Add a variable for the getter
to avoid having to construct flags when calling the getter.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
2337098b63 virsh: cmdSchedinfo: Add separate variable for holding flags used for query
Instead of having two ad-hoc places which decide whether the original
flags can be used add another variable specifically for flags used for
query.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
82217a2c7b virshGetOneDisplay: Refactor formatting of URI params
Unconditionally format the start of the query ('?') and make delimiters
('&') part of the arguments. At the end we can trim off 1 char from the
end of the buffer unconditionally.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
3c73ed7300 virshGetOneDisplay: Don't reuse 'xpath' variable
Add autofreed per-xpath variables to simplify the code.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
d6574a0d2b virshGetOneDisplay: Automaticaly free extracted data
Use automatic memory freeing for the temporary variables holding the
data extracted from the XML.

The code in this function was originally extracted from a loop so we can
also drop pre-clearing of the pointers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
bdc9269b99 virsh: cmdDomDisplay: Remove unneeded 'cleanup' label
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
364b4f0a0d virsh: cmdDomDisplay: Extract loop body fetching display URIs into 'virshGetOneDisplay'
Separate the code so that the function is not as massive. Note that this
is a minimal extraction which does not clean up the code meant for
looping.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
ea3e64fefd virsh: Move 'cmdEvent' and all of its machinery to virsh-domain-event.c
'cmdEvent' along with all the helper functions it needs is ~950 LOC.
Move it out from virsh-domain.c to virsh-domain-event.c along with the
completer function so that the new module doesn't have to expose any new
types.

Semantically this creates a new category in 'virsh help' but all other
behaviour stays the same.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
c704d27d4a virsh: Move 'virshDomainBlockJobToString' to virsh-util
The helper function is used in virshBlockJobInfo and also in the
callbacks of cmdEvent. Upcoming patch is going to move out the event
code into a helper so this needs to be in a shared place.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
bf9de8cb51 virshEventPrint: Use automatic memory clearing
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
8500571466 virsh: Use NULLSTR_EMPTY instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
34244cc20d virsh: virshVcpuinfoPrintAffinity: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
3a00632667 virsh: cmdRestore: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
8c383ea960 virsh: doSave: Use if-else instead of ternary operator
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
38b600166f virsh: cmdStart: Rewrite ternary operator use to standard if conditions
Rewrite the invocation of the virDomainCreate(WithFiles/Flags) APIs
based on the arguments into if-else instead of (nested) ternary
operators.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
1cd95f858a virsh: cmdBlockcopy: Use virXMLFormatElement
Rewrite the formatting of the block copy target xml using
virXMLFormatElement.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-03 11:06:56 +01:00
Peter Krempa
44ea7749f8 virsh: Require option name for '--pass-fd' argument of 'qemu-monitor-command'
Require the option name for this argument as otherwise a part of the
'cmd' argument will be claimed.

Fixes: 43edde82af
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
2022-03-01 14:29:39 +01:00
Peter Krempa
43edde82af virsh: Implement support for virDomainQemuMonitorCommandWithFiles
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-03-01 13:29:49 +01:00
Hyman Huang(黄勇)
72e60ddf1b virsh: Add mode option to domdirtyrate-calc virsh api
Extend domdirtyrate-calc virsh api with mode option, either
of these three options "page-sampling,dirty-bitmap,dirty-ring"
can be specified when calculating dirty page rate.

Signed-off-by: Hyman Huang(黄勇) <huangy81@chinatelecom.cn>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-02-21 13:34:16 +01:00
Peter Krempa
d2bc5a04c0 virsh-domain: Move and rename cmdStartGetFDs to virshFetchPassFdsList
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-17 15:53:58 +01:00
Peter Krempa
b0015df263 cmdStartGetFDs: Modernize
Calculate the length of the FD list beforehand to avoid multiple
expansions and mainly simplify the code and use automatic freeing to
remove the error code path.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-17 15:53:58 +01:00
Daniel P. Berrangé
7904e521b2 tools: add --reset-nvram arg to several virsh commands
This wires up support for resetting NVRAM for all APIs that allow
this feature.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2022-02-08 13:04:20 +00:00
Michal Privoznik
87a43a907f lib: Use g_clear_pointer() more
This change was generated using the following spatch:

  @ rule1 @
  expression a;
  identifier f;
  @@
    <...
  - f(*a);
    ... when != a;
  - *a = NULL;
  + g_clear_pointer(a, f);
    ...>

  @ rule2 @
  expression a;
  identifier f;
  @@
    <...
  - f(a);
    ... when != a;
  - a = NULL;
  + g_clear_pointer(&a, f);
    ...>

Then, I left some of the changes out, like tools/nss/ (which
doesn't link with glib) and put back a comment in
qemuBlockJobProcessEventCompletedActiveCommit() which coccinelle
decided to remove (I have no idea why).

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2022-02-08 08:42:07 +01:00
Ján Tomko
d248e3dca8 virsh: domsetlaunchsecstate: report error if no options are passed
We already exit if they are not present.

Report an error, but do not mark them as required in case a future
version of this command will want to accept a different set of
parameters.

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

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2022-01-31 13:38:11 +01:00
Jim Fehlig
3fc65ae9e2 tools: Add domsetlaunchsecstate virsh command
After attesting a domain with the help of domlaunchsecinfo,
domsetlaunchsecstate can be used to set a secret in the guest
domain's memory prior to running the vcpus.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
2022-01-04 10:56:00 -07:00
Michal Privoznik
dfd1ffc544 virsh-completer: Provide completer for numatune --mode
The completer is trivial, just iterate over
virDomainNumatuneMemMode enum and convert each integer into its
string comrade.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
2021-12-17 13:18:42 +01:00
Daniel P. Berrangé
ac79e9ff5c tools: add 'domlaunchsecinfo' virsh command
This command reports the launch security parameters for
a guest, allowing an external tool to perform a launch
attestation.

Reviewed-by: Peter Krempa <pkrempa@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
2021-12-14 16:04:17 +00:00
Peter Krempa
33eb88cdc9 virshParseCPUList: Refactor cleanup
Use automatic memory freeing for the temporary bitmap and remove the
pointless 'cleanup' section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-10 16:36:24 +01:00
Peter Krempa
51d1c08fe9 virDomainMigrate: Introduce VIR_MIGRATE_NON_SHARED_SYNCHRONOUS_WRITES flag
Non-shared storage migration of guests which are disk I/O intensive and
have fast local storage may actually never converge if the guest happens
to dirty the disk faster than it can be copied.

This patch introduces a new flag
'VIR_MIGRATE_NON_SHARED_SYNCHRONOUS_WRITES' which will instruct
hypervisors to synchronize local I/O writes with the writes to remote
storage used for migration so that the guest can't overwhelm the
migration. This comes at a cost of decreased local I/O performance for
guests which behave well on average.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-07 09:00:39 +01:00
Peter Krempa
b54c313c33 virDomainBlockCopy: Introduce VIR_DOMAIN_BLOCK_COPY_SYNCHRONOUS_WRITES flag
In cases when the destination storage is slower than the normal VM
storage and the VM does intensive I/O to the disk a block copy job may
never converge.

Switching it to synchronous mode will ensure that all writes done by the
guest are propagated to the destination at the cost of slowing down I/O
of the guest to the synchronous speed.

This patch adds the new API flag and implements virsh support.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-12-07 09:00:39 +01:00
Michal Privoznik
784e9e2b62 lib: Drop needless one line labels
In some cases we have a label that contains nothing but a return
statement. The amount of such labels rises as we use automagic
cleanup. Anyway, such labels are pointless and can be dropped.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-11-22 12:39:59 +01:00
Peter Krempa
813ee9fb62 virsh: domain: Replace virJSONValueObjectCreate by virJSONValueObjectAdd
virJSONValueObjectAdd now works identically to virJSONValueObjectCreate
when used with a NULL argument. Replace all callers.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-11-17 12:04:11 +01:00
zhanglei
c6d009620a virsh: add interface information to guestinfo command
The new parameter group returns information about network interfaces

Signed-off-by: zhanglei <zhanglei@smartx.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
2021-11-05 13:38:40 +01:00
Han Han
6f31f3c9a0 virsh: Fix ambiguous output in metadata-change event
When you set metadata with type element like the following:
dom.setMetadata(libvirt.VIR_DOMAIN_METADATA_ELEMENT, "<test/>", 'abc', "HAHAH", 0)

Then for `virsh event --all`, then it will output this message:
event 'metadata-change' for domain 'rhel9': element HAHAH

The message is ambiguous since it looks like the params for
metadata-change event is the element HAHAH. Actually that means the type is
element while the url is HAHAH. Let's make it more clear.

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-11-01 17:00:41 +01:00
Peter Krempa
289aa4bc5b virsh: Add QMP command wrapping for 'qemu-monitor-command'
Issuing simple QMP commands is pain as they need to be wrapped by the
JSON wrapper:

 { "execute": "COMMAND" }

and optionally also:

 { "execute": "COMMAND", "arguments":...}

For simple commands without arguments we can add syntax sugar to virsh
which allows simple usage of QMP and additionally prepares also for
passing through of the 'arguments' section:

 virsh qemu-monitor-command $VM query-status

is equivalent to

 virsh qemu-monitor-command $VM '{"execute":"query-status"}'

and

 virsh qemu-monitor-command $VM query-named-block-nodes '{"flat":true}'
 or
 virsh qemu-monitor-command $VM query-named-block-nodes '"flat":true'

is equivalent to

 virsh qemu-monitor-command $VM '{"execute":"query-named-block-nodes", "arguments":{"flat":true}}'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-10-18 16:04:17 +02:00
Michal Privoznik
1b2e06b1bf virsh: Use VIR_AUTOCLOSE more
There are few places where we can replace explicit
VIR_FORCE_CLOSE() with VIR_AUTOCLOSE annotation.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-10-06 09:28:19 +02:00
Michal Privoznik
f427e6c643 virsh: Add wrapper for virStreamFree
Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-10-06 09:27:43 +02:00
Michal Privoznik
717b6549d5 virsh: Add wrapper for virStorageVolFree
Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-10-06 09:25:22 +02:00
Michal Privoznik
663a29f42e virsh: Add wrapper for virStoragePoolFree
Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-10-06 09:24:17 +02:00
Michal Privoznik
3ad0690015 virsh: Fix --nvram and --keep-nvram help strings
The --nvram and --keep-nvram options of the undefine command can
be used regardless of the domain status (the only consumer so far
- qemuDomainUndefineFlags() doesn't care about the domain
status). Yet, their corresponding help strings say something
about inactive domains while manpage says nothing. Remove the
reference to domain state.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2007659
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
2021-10-05 08:54:32 +02:00
Michal Privoznik
f72e4edf50 virsh: Introduce update-memory-device command
New 'update-memory-device' command is introduced which aims on
making it user friendly to change <memory/> device. So far I just
need to change <requested/> so I'm introducing --requested-size
only; but the idea is that this is extensible for other cases
too. For instance, want to change <myElement/>? A new
--my-element argument can be easily introduced.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-01 11:05:05 +02:00
Michal Privoznik
9985f62b51 qemu: Wire up MEMORY_DEVICE_SIZE_CHANGE event
As advertised in previous commit, this event is delivered to us
when virtio-mem module changes the allocation inside the guest.
It comes with one attribute - size - which holds the new size of
the virtio-mem (well, allocated size), in bytes.
Mind you, this is not necessarily the same number as 'requested
size'. It almost certainly will be when sizing the memory up, but
it might not be when sizing the memory down - the guest kernel
might be unable to free some blocks.

This current size is reported in the domain XML as an output
element only.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-10-01 11:04:47 +02:00
Kristina Hanicova
49d74124a5 virsh: domain: remove else branch
I removed else branches after return/break as they are not
necessary and the code looks cleaner without them.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:53 +02:00
Kristina Hanicova
bd82e3d81a virsh: domain: remove 'ret' variable and use 'count' instead
This patch also includes use of an early return in case of an
error. I think the changes make the functions more readable.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:43 +02:00
Kristina Hanicova
24ddb0cdfe virsh: domain: use early return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:30:09 +02:00
Kristina Hanicova
6e1cdf928c virsh: domain: remove 'ret' variable, use early return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:28:51 +02:00
Kristina Hanicova
9a5db04fe6 virsh: domain: remove 'ret' variable and use direct return when possible
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:28:45 +02:00
Kristina Hanicova
a1fe822801 virsh: domain: remove nested 'if' in cmdAttachDisk()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:27:34 +02:00
Kristina Hanicova
14a804ee67 virsh: domain: use early return in virshDomainDefine()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:25:56 +02:00
Kristina Hanicova
bc7b8a34fa virsh: domain: remove unnecessary variable and label in cmdMigrateSetMaxDowntime()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:16:30 +02:00
Kristina Hanicova
0987edbedf virsh: domain: fix mistake in cmdMigrateSetMaxDowntime()
If there was added a new return value indicating success to the
function virDomainMigrateSetMaxDowntime() in the future, because
of the way the function is called it would be treated it as an
error state and would return false (indicating failure). This
patch fixes it, so that the call of the function follows the same
pattern as is currently set in libvirt.

Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-25 09:14:56 +02:00
Kristina Hanicova
ba78db1f73 virsh: domain: refactor cmdLxcEnterNamespace()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Kristina Hanicova
637d98b329 virsh: domain: refactor virshCPUCountCollect()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Kristina Hanicova
e31502544c virsh: domain: refactor cmdSchedinfo()
Signed-off-by: Kristina Hanicova <khanicov@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-24 09:52:42 +02:00
Michal Privoznik
8eefc7afc8 virsh: Provide local path completer for screenshot --file
The screenshot command takes optional --file argument which can
point to an existing local path (in which case the file is
overwritten). Set the argument's completer so that self-test
doesn't report it as missing.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-09-21 10:20:41 +02:00
Peter Krempa
c580c8db70 virsh-completer: Provide completer for '--top' and '--base' for blockjobs
Complete with the indexed targets (e.g. vda[3]) based on existing
indexes.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
071bab399a virsh: Introduce virshCompleteEmpty and use it for places where we can't suggest anything
For now this serves just as an annotation because readline and also the
bash completion script insist on completing local paths when an empty
list is returned.

This will serve for future reference once we'll be able to properly
refuse to suggest anything.

The completer is used for fields such as names for new objects,
description strings, password strings etc, URIs and hostnames which we
can't feasibly autocomplete.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
2732d81984 virsh: Use 'virshCompletePathLocalExisting' for options reading local files
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
bc4739ed77 virsh: Expand VIRSH_COMMON_OPT_FILE for cases when it's not a local file used by virsh
In cases such as the APIs for managed save management, the file path
provided via the '--file' option is passed to the API.

We'll need to make them distinct from cases for when virsh is using the
file so that different completers can be used.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Peter Krempa
119b139c76 virsh: Provide completers for options taking comma separated list of disk targets
'--storage' of the 'undefine' command and '--migrate-disks' of the
'migrate' command take a list of disk targets as an argument.

We can simply combine 'virshDomainDiskTargetCompleter' with
'virshCommaStringListComplete' to provide the completions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-09-17 09:40:46 +02:00
Jiri Denemark
88810c5267 virsh: Make code flow in cmdManagedSaveRemove more straightforward
By doing so we can get rid of the code which violates our coding style
guidelines.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-16 16:47:54 +02:00
Peter Krempa
eb2e317c65 virshDomainGetVcpuBitmap: Refactor cleanup
Rename the temp variable that is being returned and use automatic
pointer clearing for it.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-15 15:31:17 +02:00
Peter Krempa
59e74c3193 virshDomainGetVcpuBitmap: Return bitmap when taking the fallback path
In case the specific VCPU states are not present in the XML we were
taking a fallback code path just noting that all cpus of the VM are
enabled.

This was broken by a mistake in a recent refactor where a 'goto cleanup'
was mistakenly replaced by a 'return NULL'. This broke reporting of cpus
and also caused a memory leak.

Return the fallback cpu map.

Fixes: bd1f40fe7d
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2004429
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
2021-09-15 15:31:17 +02:00
Michal Privoznik
868bacd380 virsh: Support vhostuser in attach-interface
Recently, I wanted to attach an vhost-user interface but found
out that attach-interface command doesn't support it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-18 14:21:40 +02:00
Ján Tomko
bd1f40fe7d tools: virsh: remove redundant labels
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
fba265e2b2 tools: virsh: use g_autofree
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
07b40abe0f tools: virsh: use automatic cleanup for char **
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
851e66e05d tools: virsh: reduce variable scope to use automatic cleanup
Some variables are used in a loop and only freed in the cleanup
section because we need to be able to jump out of the loop.

Reduce their scope and free them automatically.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
4b72960b4e tools: virsh: use automatic cleanup for vshTable
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
5f7cdb0efc tools: virsh: use automatic cleanup for xmlDoc
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
2a7e5240ff tools: virsh: use automatic cleanup for xmlXPathObject
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:34 +02:00
Ján Tomko
be72434d79 tools: virsh: use automatic cleanup for xmlXPathContext
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Ján Tomko
cf337df3d6 tools: virsh: use automatic cleanup for virDomainObj
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Ján Tomko
65551e2239 tools: virsh: split variable declarations
One variable per line.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
2021-08-16 13:10:33 +02:00
Peter Krempa
98f6f2081d util: alloc: Reimplement VIR_APPEND_ELEMENT using virAppendElement
Use virAppendElement instead of virInsertElementsN to implement
VIR_APPEND_ELEMENT which allows us to remove error handling as the
only relevant errors were removed when switching to aborting memory
allocation functions.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-08-06 08:53:25 +02:00
Pavel Hrdina
dc721f99df virsh: fix setmem flags logic
When we dropped virDomainSetMemory usage it got kind of tricky to
figure out the flags correctly.

Originally the logic was following:

    no option | --current | --live | --config | --live --config
    ----------+-----------+--------+----------+----------------
       LIVE   |  CURRENT  |  LIVE  |  CONFIG  |  LIVE & CONFIG

But after the commit removing virDomainSetMemory usage it changed to:

    no option | --current | --live |    --config     | --live --config
    ----------+-----------+--------+-----------------+----------------
       LIVE   |  CURRENT  |  LIVE  |  LIVE & CONFIG  |  LIVE & CONFIG

This commit fixes the logic back to the original behavior except for
ESX, HyperV and Virtuozzo drivers where virDomainSetMemory() default
behavior was CURRENT instead of LIVE.

Fixes: ce8138564b
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1980199
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-07-23 11:24:51 +02:00
Peter Krempa
9e7f32790a virsh-domain: Avoid 'vir' prefix for locally declared VIR_ENUM* helpers
Stuff used in virsh should use 'virsh'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-07-23 09:59:12 +02:00
Peter Krempa
cc530c4557 virsh-host: Avoid 'vir' prefix for locally declared VIR_ENUM* helpers
Stuff used in virsh should use 'virsh'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-07-23 09:59:12 +02:00
Han Han
78b1a53df1 virsh: Fix the order of format arguments in doDump
According to definition of virDomainCoreDumpFormat, the "elf" should be
the first argument in VIR_ENUM_*.

Fixes: 84cc4543be

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1981625

Signed-off-by: Han Han <hhan@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-07-13 11:21:23 +02:00
Lin Ma
8cdbca6213 virsh: Add format completion to blockcopy command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:28:02 +02:00
Lin Ma
8de9a54b9e virsh: Add target completion to dompmsuspend command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:59 +02:00
Lin Ma
b41811b93d virsh: Use VIR_ENUM_* for --target argument in cmdDomPMSuspend
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:57 +02:00
Lin Ma
a61a6978d3 virsh: Add comp-methods completion to migrate command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-15 10:27:47 +02:00
Lin Ma
564512e916 virsh: Add coredump format completion to dump command
Signed-off-by: Lin Ma <lma@suse.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-07 16:30:59 +02:00
Lin Ma
84cc4543be virsh: Use VIR_ENUM_* for --format argument in doDump
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-06-07 16:30:56 +02:00
Michal Privoznik
ce8138564b virsh-domain: Drop support for old APIs in cmdSetmem and cmdSetmaxmem
Some of our really old APIs are missing @flags argument. We
introduced their variants with "Flags" suffix and wired some
logic into virsh to call the new variant only if necessary. This
enables virsh to talk to older daemon which may be lacking new
APIs.

However, in case of cmdSetmem() we are talking about v0.1.1
(virDomainSetMemory()) vs. v0.9.0 (virDomainSetMemoryFlags()) and
in case of cmdSetmaxmem() we are talking about v0.0.3
(virDomainSetMaxMemory()) vs v0.9.0 (virDomainSetMemoryFlags()).

Libvirt v0.9.0 was released more than 10 years ago and recently
we dropped support for RHEL-7 which has v4.5.0 (released ~3 years
ago). Thus it is not really necessary to have support in virsh
for such old daemons.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-06-02 10:13:50 +02:00
Michal Privoznik
3de70da32d virsh: Expose new win-dmp dump format
In previous commit the virDomainCoreDumpWithFormat() API gained
new format. Expose it.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-20 16:24:06 +02:00
Michal Privoznik
01a2339e1f virsh-domain: Fix @ret handling in cmdSetmem and cmdSetmaxmem
These functions initialize @ret to true and only after something
fails either they call cleanup code (which consists only from
virshDomainFree()) and return false, or they set ret = false and
carry on (when the failure occurred close to cleanup code).

Switch them to the usual pattern in which ret is initialized to
failure, goto cleanup is used and ret is set to true only after
everything succeeded.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-19 15:31:36 +02:00
Michal Privoznik
168190e19c virsh: Fix logic wrt to --current flag in cmdSetmem
In my commit of v7.1.0-rc1~376 I've simplified the logic of
handling @flags. My assumption back then was that calling
virDomainSetMemory() is equivalent to
virDomainSetMemoryFlags(flags = 0). But that is not the case,
because it is equivalent to virDomainSetMemoryFlags(flags =
VIR_DOMAIN_AFFECT_LIVE). Fix the condition that calls the old
API.

Fixes: b5e267e8c5
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1961118
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-05-19 15:31:17 +02:00
Lin Ma
14c36b107d virsh: Add mountpoint completion to domfsfreeze/domfsthaw command
Signed-off-by: Lin Ma <lma@suse.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-04-22 13:46:44 +02:00
Michal Privoznik
c8238579fb lib: Drop internal virXXXPtr typedefs
Historically, we declared pointer type to our types:

  typedef struct _virXXX virXXX;
  typedef virXXX *virXXXPtr;

But usefulness of such declaration is questionable, at best.
Unfortunately, we can't drop every such declaration - we have to
carry some over, because they are part of public API (e.g.
virDomainPtr). But for internal types - we can do drop them and
use what every other C project uses 'virXXX *'.

This change was generated by a very ugly shell script that
generated sed script which was then called over each file in the
repository. For the shell script refer to the cover letter:

https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Peter Krempa <pkrempa@redhat.com>
2021-04-13 17:00:38 +02:00
Peter Krempa
def579e88a virshParseRateStr: Use g_strsplit instead of virStringSplitCount
Count the elements after splitting the string.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
d9c3b652ef virshParseRateStr: Refactor cleanup
Use g_auto for the string list and remove 'ret' and 'cleanup'.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Peter Krempa
d7e2bca9b7 virshParseEventStr: Use g_strsplit and automatic memory freeing
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
2021-04-12 15:55:09 +02:00
Michal Privoznik
0c30e7221c lib: Use g_steal_pointer() more
Generated by the following spatch:

  @@
  expression a, b;
  @@

  + b = g_steal_pointer(&a);
  - b = a;
    ... when != a
  - a = NULL;

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-03-24 13:57:51 +01:00
Jiri Denemark
7d2fd6ef01 Do not check return value of VIR_EXPAND_N
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
2021-03-22 12:44:18 +01:00
Hao Wang
a2ae2dad06 migration/dirtyrate: Introduce domdirtyrate-calc virsh api
Introduce domdirtyrate-calc virsh api to start calculating domain's
memory dirty rate:
	# virsh domdirtyrate-calc <domain> [--seconds <sec>]

Signed-off-by: Hao Wang <wanghao232@huawei.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
2021-03-18 08:50:25 +01:00
Peter Krempa
ec6e2a2c97 util: xml: Add wrapper for 'xmlNewNode'
Add a wrapper that will handle the out of memory condition by abort()
and also prevents callers from having to typecast the argument.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
2021-03-02 09:50:19 +01:00
Daniel Henrique Barboza
953be56eea virsh-domain.c: use g_auto* in cmdDetachDevice()
Use g_auto* pointers to avoid the need of a cleanup label. The
type of the pointer 'virDomainPtr dom' was changed to its alias
'virshDomainPtr' to allow the use of g_autoptr().

Reviewed-by: Laine Stump <laine@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
2021-03-01 12:25:33 -03:00