[PATCH] convert char pointers to use g_autofree
by Ryan Gahagan
From: bschoney <bschoney(a)utexas.edu>
additional conversions to the GLib API in src/util per issue #11.
Please let me know if there are additional changes I should make in the files updated so far.
I intend to submit work on additional files, and I want to be sure the changes so far are correct.
Related issue: https://gitlab.com/libvirt/libvirt/-/issues/11
Signed-off-by: bschoney <bschoney(a)utexas.edu>
---
src/util/vircgroupv1.c | 3 +--
src/util/virhostcpu.c | 4 +---
src/util/virlockspace.c | 6 ++----
src/util/virmacmap.c | 3 +--
src/util/virresctrl.c | 25 ++++++++-----------------
src/util/virsysinfo.c | 9 +++------
6 files changed, 16 insertions(+), 34 deletions(-)
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index 731e9d61d4..984cd50409 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -1549,7 +1549,7 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
unsigned long long *unevictable)
{
int ret = -1;
- char *stat = NULL;
+ g_autofree char *stat = NULL;
char *line = NULL;
unsigned long long cacheVal = 0;
unsigned long long activeAnonVal = 0;
@@ -1614,7 +1614,6 @@ virCgroupV1GetMemoryStat(virCgroupPtr group,
ret = 0;
cleanup:
- VIR_FREE(stat);
return ret;
}
diff --git a/src/util/virhostcpu.c b/src/util/virhostcpu.c
index c531d65f86..4f6c3390ce 100644
--- a/src/util/virhostcpu.c
+++ b/src/util/virhostcpu.c
@@ -87,7 +87,7 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
int *nparams)
{
const char *sysctl_name;
- long *cpu_times;
+ g_autofree long *cpu_times = NULL;
struct clockinfo clkinfo;
size_t i, j, cpu_times_size, clkinfo_size;
int cpu_times_num, offset, hz, stathz, ret = -1;
@@ -172,8 +172,6 @@ virHostCPUGetStatsFreeBSD(int cpuNum,
ret = 0;
cleanup:
- VIR_FREE(cpu_times);
-
return ret;
}
diff --git a/src/util/virlockspace.c b/src/util/virlockspace.c
index 2731d46dfc..c88a24be36 100644
--- a/src/util/virlockspace.c
+++ b/src/util/virlockspace.c
@@ -515,7 +515,7 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
const char *resname)
{
int ret = -1;
- char *respath = NULL;
+ g_autofree char *respath = NULL;
VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
@@ -538,7 +538,6 @@ int virLockSpaceCreateResource(virLockSpacePtr lockspace,
cleanup:
virMutexUnlock(&lockspace->lock);
- VIR_FREE(respath);
return ret;
}
@@ -547,7 +546,7 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
const char *resname)
{
int ret = -1;
- char *respath = NULL;
+ g_autofree char *respath = NULL;
VIR_DEBUG("lockspace=%p resname=%s", lockspace, resname);
@@ -575,7 +574,6 @@ int virLockSpaceDeleteResource(virLockSpacePtr lockspace,
cleanup:
virMutexUnlock(&lockspace->lock);
- VIR_FREE(respath);
return ret;
}
diff --git a/src/util/virmacmap.c b/src/util/virmacmap.c
index 2d203e72af..70b148acac 100644
--- a/src/util/virmacmap.c
+++ b/src/util/virmacmap.c
@@ -129,7 +129,7 @@ static int
virMacMapLoadFile(virMacMapPtr mgr,
const char *file)
{
- char *map_str = NULL;
+ g_autofree char *map_str = NULL;
virJSONValuePtr map = NULL;
int map_str_len = 0;
size_t i;
@@ -189,7 +189,6 @@ virMacMapLoadFile(virMacMapPtr mgr,
ret = 0;
cleanup:
- VIR_FREE(map_str);
virJSONValueFree(map);
return ret;
}
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index d3087b98c1..1c2d175295 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -709,7 +709,7 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
{
int ret = -1;
int rv = -1;
- char *featurestr = NULL;
+ g_autofree char *featurestr = NULL;
char **features = NULL;
size_t nfeatures = 0;
virResctrlInfoMongrpPtr info_monitor = NULL;
@@ -771,7 +771,6 @@ virResctrlGetMonitorInfo(virResctrlInfoPtr resctrl)
ret = 0;
cleanup:
- VIR_FREE(featurestr);
g_strfreev(features);
VIR_FREE(info_monitor);
return ret;
@@ -1736,7 +1735,7 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
const char *groupname,
virResctrlAllocPtr *alloc)
{
- char *schemata = NULL;
+ g_autofree char *schemata = NULL;
int rv = virFileReadValueString(&schemata,
SYSFS_RESCTRL_PATH "/%s/schemata",
groupname);
@@ -1753,11 +1752,9 @@ virResctrlAllocGetGroup(virResctrlInfoPtr resctrl,
if (virResctrlAllocParse(resctrl, *alloc, schemata) < 0)
goto error;
- VIR_FREE(schemata);
return 0;
error:
- VIR_FREE(schemata);
virObjectUnref(*alloc);
*alloc = NULL;
return -1;
@@ -2354,8 +2351,8 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
virResctrlAllocPtr alloc,
const char *machinename)
{
- char *schemata_path = NULL;
- char *alloc_str = NULL;
+ g_autofree char *schemata_path = NULL;
+ g_autofree char *alloc_str = NULL;
int ret = -1;
int lockfd = -1;
@@ -2403,8 +2400,6 @@ virResctrlAllocCreate(virResctrlInfoPtr resctrl,
ret = 0;
cleanup:
virResctrlUnlock(lockfd);
- VIR_FREE(alloc_str);
- VIR_FREE(schemata_path);
return ret;
}
@@ -2413,8 +2408,8 @@ static int
virResctrlAddPID(const char *path,
pid_t pid)
{
- char *tasks = NULL;
- char *pidstr = NULL;
+ g_autofree char *tasks = NULL;
+ g_autofree char *pidstr = NULL;
int ret = 0;
if (!path) {
@@ -2436,8 +2431,6 @@ virResctrlAddPID(const char *path,
ret = 0;
cleanup:
- VIR_FREE(tasks);
- VIR_FREE(pidstr);
return ret;
}
@@ -2657,8 +2650,8 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
size_t i = 0;
unsigned long long val = 0;
g_autoptr(DIR) dirp = NULL;
- char *datapath = NULL;
- char *filepath = NULL;
+ g_autofree char *datapath = NULL;
+ g_autofree char *filepath = NULL;
struct dirent *ent = NULL;
virResctrlMonitorStatsPtr stat = NULL;
@@ -2737,8 +2730,6 @@ virResctrlMonitorGetStats(virResctrlMonitorPtr monitor,
ret = 0;
cleanup:
- VIR_FREE(datapath);
- VIR_FREE(filepath);
virResctrlMonitorStatsFree(stat);
return ret;
}
diff --git a/src/util/virsysinfo.c b/src/util/virsysinfo.c
index 217f842a37..e1336bf566 100644
--- a/src/util/virsysinfo.c
+++ b/src/util/virsysinfo.c
@@ -532,9 +532,9 @@ static int
virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
{
const char *tmp_base;
- char *manufacturer = NULL;
- char *procline = NULL;
- char *ncpu = NULL;
+ g_autofree char *manufacturer = NULL;
+ g_autofree char *procline = NULL;
+ g_autofree char *ncpu = NULL;
int result = -1;
virSysinfoProcessorDefPtr processor;
@@ -593,9 +593,6 @@ virSysinfoParseS390Processor(const char *base, virSysinfoDefPtr ret)
result = 0;
error:
- VIR_FREE(manufacturer);
- VIR_FREE(procline);
- VIR_FREE(ncpu);
return result;
}
--
2.29.0
4 years, 1 month
[libvirt PATCH] Fix name prefix of VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE
by Daniel P. Berrangé
The enum constant names should all have a prefix that matches the enum
name. VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE was missing the "CREATE_"
part of the name prefix.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
include/libvirt/libvirt-domain-checkpoint.h | 4 ++--
src/libvirt-domain-checkpoint.c | 4 ++--
src/qemu/qemu_checkpoint.c | 4 ++--
tools/virsh-checkpoint.c | 2 +-
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/include/libvirt/libvirt-domain-checkpoint.h b/include/libvirt/libvirt-domain-checkpoint.h
index 58932c8a6a..a2f97531f8 100644
--- a/include/libvirt/libvirt-domain-checkpoint.h
+++ b/include/libvirt/libvirt-domain-checkpoint.h
@@ -57,8 +57,8 @@ typedef enum {
quiesce all mounted
file systems within
the domain */
- VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE = (1 << 2), /* validate disk data state
- when redefining a checkpoint */
+ VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE = (1 << 2), /* validate disk data state
+ when redefining a checkpoint */
} virDomainCheckpointCreateFlags;
/* Create a checkpoint using the current VM state. */
diff --git a/src/libvirt-domain-checkpoint.c b/src/libvirt-domain-checkpoint.c
index e0c2527ccb..e6ad4f4f5d 100644
--- a/src/libvirt-domain-checkpoint.c
+++ b/src/libvirt-domain-checkpoint.c
@@ -125,7 +125,7 @@ virDomainCheckpointGetConnect(virDomainCheckpointPtr checkpoint)
* has a way to resupply correct defaults). Not all hypervisors support
* this flag.
*
- * If @flags includes VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE along with
+ * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE along with
* VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE the state of the metadata related
* to the disk state of the redefined checkpoint is validated. Note that
* hypervisors may require that the @domain is running to perform validation.
@@ -160,7 +160,7 @@ virDomainCheckpointCreateXML(virDomainPtr domain,
VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE,
error);
- VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE,
+ VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE,
VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE,
error);
diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c
index c24376dbe8..eb33633a11 100644
--- a/src/qemu/qemu_checkpoint.c
+++ b/src/qemu/qemu_checkpoint.c
@@ -538,13 +538,13 @@ qemuCheckpointCreateXML(virDomainPtr domain,
virDomainCheckpointPtr checkpoint = NULL;
bool update_current = true;
bool redefine = flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE;
- bool validate_bitmaps = flags & VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE;
+ bool validate_bitmaps = flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE;
unsigned int parse_flags = 0;
g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
g_autoptr(virDomainCheckpointDef) def = NULL;
virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE |
- VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE, NULL);
+ VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE, NULL);
if (redefine) {
parse_flags |= VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE;
diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c
index cc2bbdae8a..f6396d16eb 100644
--- a/tools/virsh-checkpoint.c
+++ b/tools/virsh-checkpoint.c
@@ -125,7 +125,7 @@ cmdCheckpointCreate(vshControl *ctl,
if (vshCommandOptBool(cmd, "redefine"))
flags |= VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE;
if (vshCommandOptBool(cmd, "redefine-validate"))
- flags |= VIR_DOMAIN_CHECKPOINT_REDEFINE_VALIDATE;
+ flags |= VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE_VALIDATE;
if (vshCommandOptBool(cmd, "quiesce"))
flags |= VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE;
--
2.28.0
4 years, 1 month
[libvirt PATCH 0/2] Fix dependencies for python scripts
by Daniel P. Berrangé
Daniel P. Berrangé (2):
meson: ensure python script is run in utf8 env
meson: drop use of .path() for python args
docs/manpages/meson.build | 4 ++--
docs/meson.build | 8 ++++----
src/access/meson.build | 2 +-
src/admin/meson.build | 4 ++--
src/esx/meson.build | 4 ++--
src/hyperv/meson.build | 2 +-
src/meson.build | 18 +++++++++---------
src/qemu/meson.build | 2 +-
src/util/meson.build | 4 ++--
9 files changed, 24 insertions(+), 24 deletions(-)
--
2.28.0
4 years, 1 month
[PATCH 0/7] drop support for Windows versions prior to 2012R2
by Matt Coleman
Microsoft no longer supports Windows 2008R2 at all. Windows 2012 and
2012 R2 are still within extended support until October 9, 2023.
Hyper-V's WMI API has two versions. V1 is supported by 2008R2 and 2012.
2012 also offered initial support for V2, but it's incomplete.
2012R2 was the first version to offer full support for the V2 API.
This patchset drops support for the V1 WMI API.
Here's a GitLab merge request, if you'd prefer to review it there:
https://gitlab.com/iammattcoleman/libvirt/-/merge_requests/7
Matt Coleman (7):
hyperv: remove V1 classes from the WMI generator input
hyperv: remove hypervPrivate->wmiVersion
hyperv: remove support for multiple API versions from the WMI
generator
hyperv: remove hypervWmiClassInfoList, hypervWmiClassInfoListPtr, and
_hypervWmiClassInfoList
hyperv: do not generate *_CLASSNAME constants
docs: drop support for Windows versions prior to 2012R2
news: drop support for Windows versions prior to 2012R2
NEWS.rst | 6 +
docs/drvhyperv.html.in | 17 +-
docs/platforms.rst | 3 +-
scripts/hyperv_wmi_generator.py | 275 ++++-------------
src/hyperv/hyperv_driver.c | 299 +++++-------------
src/hyperv/hyperv_private.h | 7 -
src/hyperv/hyperv_wmi.c | 108 ++-----
src/hyperv/hyperv_wmi.h | 39 +--
src/hyperv/hyperv_wmi_classes.h | 13 -
src/hyperv/hyperv_wmi_generator.input | 422 +-------------------------
10 files changed, 180 insertions(+), 1009 deletions(-)
--
2.27.0
4 years, 1 month
[PATCH] qemustatusxml2xmltest: Remove 'virdeterministichash' mocking
by Peter Krempa
Commit 89a3115bac2c92ac67516 was not updated after recent changes to
hash table usage and was still referencing the now removed deterministic
hash mock, which caused CI failure.
Fixes: 89a3115bac2c92ac67516d04df6a45769f69a37c
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
Pushed as fix for CI.
tests/qemustatusxml2xmltest.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/tests/qemustatusxml2xmltest.c b/tests/qemustatusxml2xmltest.c
index 3168622be6..67a070c986 100644
--- a/tests/qemustatusxml2xmltest.c
+++ b/tests/qemustatusxml2xmltest.c
@@ -151,5 +151,4 @@ mymain(void)
VIR_TEST_MAIN_PRELOAD(mymain,
VIR_TEST_MOCK("virpci"),
VIR_TEST_MOCK("virrandom"),
- VIR_TEST_MOCK("domaincaps"),
- VIR_TEST_MOCK("virdeterministichash"))
+ VIR_TEST_MOCK("domaincaps"))
--
2.26.2
4 years, 1 month
[PULL 0/3] MIPS patches for 5.2-rc1
by Philippe Mathieu-Daudé
The following changes since commit 3493c36f0371777c62d1d72b205b0eb6117e2156:
Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20201106' into staging (2020-11-06 13:43:28 +0000)
are available in the Git repository at:
https://gitlab.com/philmd/qemu.git tags/mips-fixes-20201109
for you to fetch changes up to bf4ee88ab63fcf2dcb75f0d68cc6c8d2edb68212:
hw/mips/boston: Fix memory leak in boston_fdt_filter() error-handling paths (2020-11-09 00:40:44 +0100)
----------------------------------------------------------------
MIPS patches queue
- Deprecate nanoMIPS ISA
- Fix PageMask with variable page size (Huacai Chen)
- Fix memory leak in boston_fdt_filter (Coverity CID 1432275, Peter Maydell)
CI jobs results:
. https://cirrus-ci.com/build/5439131968864256
. https://gitlab.com/philmd/qemu/-/pipelines/213403385
. https://travis-ci.org/github/philmd/qemu/builds/742312387
----------------------------------------------------------------
Jiaxun Yang (1):
target/mips: Fix PageMask with variable page size
Peter Maydell (1):
hw/mips/boston: Fix memory leak in boston_fdt_filter() error-handling
paths
Philippe Mathieu-Daudé (1):
target/mips: Deprecate nanoMIPS ISA
docs/system/deprecated.rst | 23 +++++++++++++++++++++++
target/mips/cpu.h | 1 +
hw/mips/boston.c | 10 ++++------
target/mips/cp0_helper.c | 27 +++++++++++++++++++++------
MAINTAINERS | 6 +++++-
5 files changed, 54 insertions(+), 13 deletions(-)
--
2.26.2
4 years, 1 month
Libvirt Open Source Contribution
by Barrett J Schonefeld
Hey libvirt team,
We (Ryan Gahagan, Dustan Helm, and Barrett Schonefeld) are computer science
students at the University of Texas at Austin. We are taking a course in
virtualization, and we’d like to contribute to the libvirt repository as
part of this course. Here are the issues we are most interested in:
https://gitlab.com/libvirt/libvirt/-/issues/11
https://gitlab.com/libvirt/libvirt/-/issues/16
Additionally, we would like to take a look at issue 4 (
https://gitlab.com/libvirt/libvirt/-/issues/4), the UDP slowdown for QEMU.
We expect issue 4 to be more time-intensive, and we would like to
communicate with you to ensure we’re solving the problem effectively.
Our course only runs until the end of the fall semester, so our time to
contribute to this project is somewhat limited. If you think any of the
issues we picked would be too difficult to accomplish during that time
frame, we would appreciate alternative suggestions. We really hope to
contribute to this project and help make improvements where we can.
Best regards,
Dustan Helm: dustan.helm(a)yahoo.com
Barrett Schonefeld: bschoney(a)utexas.edu
Ryan Gahagan: ryangahagan18(a)gmail.com
4 years, 1 month
[PATCH 0/9] tests: Add testing of qemu migration cookie
by Peter Krempa
Note that this series probably depends on the hash table refactor.
Add testing of migration cookie as we don't have any schema or examples
of it to prevent breakage and help with development.
Peter Krempa (9):
qemuxml2xmltest: Remove 'WITH_QEMU' conditional
qemuxml2xmltest: Split out status XML testing to
qemustatusxml2xmltest.c
qemu_migration_cookie: Make header standalone
qemu_migration_cookie: Export qemuMigrationCookieXMLFormat for tests
tests: Add mock library for virGetHostname and virGetHostUUID
qemu_migration_cookie: Make cookie parsing robust against missing
domain job
tests: Add testing of qemu migration cookie
qemumigrationcookiexmltest: Add synthetic test case
virCPUDefFormatBufFull: Use virXMLFormatElement
src/conf/cpu_conf.c | 16 +-
src/qemu/qemu_migration_cookie.c | 4 +-
src/qemu/qemu_migration_cookie.h | 9 +
src/util/virutil.h | 2 +-
src/util/viruuid.h | 2 +-
tests/hostidmock.c | 36 ++
tests/meson.build | 3 +
.../basic-xml2xml-in.xml | 6 +
.../basic-xml2xml-out.xml | 9 +
.../full-xml2xml-in.xml | 221 ++++++++++++
.../full-xml2xml-out.xml | 219 ++++++++++++
.../modern-dom-out-dest.xml | 12 +
.../modern-dom-out-source.xml | 12 +
tests/qemumigrationcookiexmltest.c | 337 ++++++++++++++++++
tests/qemustatusxml2xmltest.c | 159 +++++++++
tests/qemuxml2xmltest.c | 136 ++-----
16 files changed, 1048 insertions(+), 135 deletions(-)
create mode 100644 tests/hostidmock.c
create mode 100644 tests/qemumigrationcookiexmldata/basic-xml2xml-in.xml
create mode 100644 tests/qemumigrationcookiexmldata/basic-xml2xml-out.xml
create mode 100644 tests/qemumigrationcookiexmldata/full-xml2xml-in.xml
create mode 100644 tests/qemumigrationcookiexmldata/full-xml2xml-out.xml
create mode 100644 tests/qemumigrationcookiexmldata/modern-dom-out-dest.xml
create mode 100644 tests/qemumigrationcookiexmldata/modern-dom-out-source.xml
create mode 100644 tests/qemumigrationcookiexmltest.c
create mode 100644 tests/qemustatusxml2xmltest.c
--
2.26.2
4 years, 1 month
[PATCH v2] virsh: Allow listing just domain IDs
by Michal Privoznik
Some completers for libvirt related tools might want to list
domain IDs only. Just like the one I've implemented for
virt-viewer [1]. I've worked around it using some awk magic,
but if it was possible to just 'virsh list --id' then I could
drop awk.
1: https://www.redhat.com/archives/virt-tools-list/2019-May/msg00014.html
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
Diff to v1:
- Documented the new switch in the manpage
- Allowed --id to be used with --all
docs/manpages/virsh.rst | 21 +++++++++---------
tools/virsh-domain-monitor.c | 42 +++++++++++++++++++++++++-----------
2 files changed, 39 insertions(+), 24 deletions(-)
diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index d34a1c8684..848e1a6458 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -621,7 +621,7 @@ list
list [--inactive | --all]
[--managed-save] [--title]
- { [--table] | --name | --uuid }
+ { [--table] | --name | --uuid | --id }
[--persistent] [--transient]
[--with-managed-save] [--without-managed-save]
[--autostart] [--no-autostart]
@@ -758,16 +758,15 @@ If *--managed-save* is specified, then domains that have managed save state
in the listing. This flag is usable only with the default *--table* output.
Note that this flag does not filter the list of domains.
-If *--name* is specified, domain names are printed instead of the table
-formatted one per line. If *--uuid* is specified domain's UUID's are printed
-instead of names. Flag *--table* specifies that the legacy table-formatted
-output should be used. This is the default.
-
-If both *--name* and *--uuid* are specified, domain UUID's and names
-are printed side by side without any header. Flag *--table* specifies
-that the legacy table-formatted output should be used. This is the
-default if neither *--name* nor *--uuid* are specified. Option
-*--table* is mutually exclusive with options *--uuid* and *--name*.
+If *--name* is specified, domain names are printed instead of the
+table formatted one per line. If *--uuid* is specified domain's UUID's
+are printed instead of names. If *--id* is specified then domain's ID's
+are printed indead of names. However, it is possible to combine
+*--name*, *--uuid* and *--id* to select only desired fields for
+printing. Flag *--table* specifies that the legacy table-formatted
+output should be used, but it is mutually exclusive with *--name*,
+*--uuid* and *--id*. This is the default and will be used if neither of
+*--name*, *--uuid* or *--id* is specified.
If *--title* is specified, then the short domain description (title) is
printed in an extra column. This flag is usable only with the default
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index e0491d48ac..5d0a03afa9 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -1919,6 +1919,10 @@ static const vshCmdOptDef opts_list[] = {
.type = VSH_OT_BOOL,
.help = N_("list domain names only")
},
+ {.name = "id",
+ .type = VSH_OT_BOOL,
+ .help = N_("list domain IDs only")
+ },
{.name = "table",
.type = VSH_OT_BOOL,
.help = N_("list table (default)")
@@ -1945,6 +1949,7 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
bool optTable = vshCommandOptBool(cmd, "table");
bool optUUID = vshCommandOptBool(cmd, "uuid");
bool optName = vshCommandOptBool(cmd, "name");
+ bool optID = vshCommandOptBool(cmd, "id");
size_t i;
char *title;
char uuid[VIR_UUID_STRING_BUFLEN];
@@ -1988,8 +1993,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
VSH_EXCLUSIVE_OPTIONS("table", "name");
VSH_EXCLUSIVE_OPTIONS("table", "uuid");
+ VSH_EXCLUSIVE_OPTIONS("table", "id");
- if (!optUUID && !optName)
+ if (!optUUID && !optName && !optID)
optTable = true;
if (!(list = virshDomainListCollect(ctl, flags)))
@@ -2007,6 +2013,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
}
for (i = 0; i < list->ndomains; i++) {
+ const char *sep = "";
+
dom = list->domains[i];
id = virDomainGetID(dom);
if (id != (unsigned int) -1)
@@ -2044,20 +2052,28 @@ cmdList(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- } else if (optUUID && optName) {
- if (virDomainGetUUIDString(dom, uuid) < 0) {
- vshError(ctl, "%s", _("Failed to get domain's UUID"));
- goto cleanup;
+ } else {
+ if (optUUID) {
+ if (virDomainGetUUIDString(dom, uuid) < 0) {
+ vshError(ctl, "%s", _("Failed to get domain's UUID"));
+ goto cleanup;
+ }
+ vshPrint(ctl, "%s", uuid);
+ sep = " ";
}
- vshPrint(ctl, "%-36s %-30s\n", uuid, virDomainGetName(dom));
- } else if (optUUID) {
- if (virDomainGetUUIDString(dom, uuid) < 0) {
- vshError(ctl, "%s", _("Failed to get domain's UUID"));
- goto cleanup;
+ if (optID) {
+ /* If we are asked to print IDs only then do that
+ * only for live domains. */
+ if (id == (unsigned int) -1 && !optUUID && !optName)
+ continue;
+ vshPrint(ctl, "%s%s", sep, id_buf);
+ sep = " ";
}
- vshPrint(ctl, "%s\n", uuid);
- } else if (optName) {
- vshPrint(ctl, "%s\n", virDomainGetName(dom));
+ if (optName) {
+ vshPrint(ctl, "%s%s", sep, virDomainGetName(dom));
+ sep = " ";
+ }
+ vshPrint(ctl, "\n");
}
}
--
2.26.2
4 years, 1 month