Devel
Threads by month
- ----- 2026 -----
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- 47 participants
- 40223 discussions
12 Aug '15
Hot-unplugging a disk from a guest that supports hot-unplugging generates an error
in the libvirt log when running QEMU with the "-msg timestamp=on" flag.
2015-08-06 10:48:59.945+0000: 11662: error : qemuMonitorTextDriveDel:2594 :
operation failed: deleting drive-virtio-disk4 drive failed:
2015-08-06T10:48:59.945058Z Device 'drive-virtio-disk4' not found
This error is caused because the HMP results are getting prefixed with a timestamp.
Parsing the output is not reliable with STRPREFIX as the results can be prefixed with a timestamp.
Using strstr ensures that parsing the output works whether the results are prefixed or not.
Cc: Stefan Hajnoczi <stefanha(a)redhat.com>
Cc: Daniel P. Berrange <berrange(a)redhat.com>
Signed-off-by: Frank Schreuder <fschreuder(a)transip.nl>
---
src/qemu/qemu_monitor_text.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/qemu/qemu_monitor_text.c b/src/qemu/qemu_monitor_text.c
index 2aa0460..d5ef089 100644
--- a/src/qemu/qemu_monitor_text.c
+++ b/src/qemu/qemu_monitor_text.c
@@ -2586,7 +2586,7 @@ int qemuMonitorTextDriveDel(qemuMonitorPtr mon,
/* (qemu) drive_del wark
* Device 'wark' not found */
- } else if (STRPREFIX(reply, "Device '") && (strstr(reply, "not found"))) {
+ } else if (strstr(reply, "Device '") && strstr(reply, "not found")) {
/* NB: device not found errors mean the drive was auto-deleted and we
* ignore the error */
} else if (STRNEQ(reply, "")) {
--
2.4.5
5
5
Otherwise we're leaking some 30+ symbols like
virAdmConnectClass
virAdmConnectNew
virConnectClass
virConnectCloseCallbackDataClass
virDomainClass
...
I marked the one symbol needed by the deamon as
LIBVIRT_ADMIN_PRIVATE_<VERSION> for now.
---
There's likely a better solution for xdr_admin_connect_open_args.
Cheers,
-- Guido
src/libvirt_admin.syms | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/src/libvirt_admin.syms b/src/libvirt_admin.syms
index d9e3c0b..de4f1b8 100644
--- a/src/libvirt_admin.syms
+++ b/src/libvirt_admin.syms
@@ -16,3 +16,12 @@ LIBVIRT_ADMIN_1.3.0 {
virAdmConnectClose;
virAdmConnectRef;
};
+
+
+LIBVIRT_ADMIN_PRIVATE_1.2.19 {
+ global:
+ xdr_admin_connect_open_args;
+
+ local:
+ *;
+};
--
2.1.4
3
6
[libvirt] [PATCH] Revert "qemu: Allow to plug virtio-net-pci into PCIe slot"
by Laine Stump 12 Aug '15
by Laine Stump 12 Aug '15
12 Aug '15
This reverts commit ede34470fde19c0f326cdb0dfca39fa86fd9ec16, which
was apparently written based on testing performed before commits
1e15be1 and 9a12b6 were pushed upstream. Once those two patches are in
place, commit ede34470 is redundant, and can even cause
incorrect/unexpected behavior when auto-assigning addresses for
virtio-net devices.
---
src/qemu/qemu_command.c | 8 --------
1 file changed, 8 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 84cbfe1..0d7b155 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1680,14 +1680,6 @@ qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
*/
flags = VIR_PCI_CONNECT_TYPE_PCI | VIR_PCI_CONNECT_TYPE_PCIE;
break;
-
- case VIR_DOMAIN_DEVICE_NET:
- if (STREQ(device->data.net->model, "virtio")) {
- /* virtio-net-pci adapter in qemu has to be plugged into PCIe slot
- * in order to be able to use irqfds with vhost-net
- */
- flags = VIR_PCI_CONNECT_TYPE_PCI | VIR_PCI_CONNECT_TYPE_PCIE;
- }
}
/* Ignore implicit controllers on slot 0:0:1.0:
--
2.1.0
3
4
Compiled libvirt 1.2.18 on Ubuntu 12.04.5 (installed over 12.04 libvirt-bin
0.9.9 package files); when I try to start libvirtd, I get the following
error / backtrace:
$ sudo /usr/sbin/libvirtd
*** stack smashing detected ***: /usr/sbin/libvirtd terminated
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x37)[0x7f02fe6d3e57]
/lib/x86_64-linux-gnu/libc.so.6(__fortify_fail+0x0)[0x7f02fe6d3e20]
/usr/lib/libvirt.so.0(+0xaa359)[0x7f02fec4f359]
/usr/lib/libvirt/connection-driver/libvirt_driver_nodedev.so(+0x99fe)[0x7f02f1fc59fe]
/usr/lib/libvirt/connection-driver/libvirt_driver_nodedev.so(+0xa672)[0x7f02f1fc6672]
/usr/lib/libvirt.so.0(virStateInitialize+0xaf)[0x7f02fed1cd2f]
/usr/sbin/libvirtd(+0x17d80)[0x7f02ff98dd80]
/usr/lib/libvirt.so.0(+0xd25d2)[0x7f02fec775d2]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x7e9a)[0x7f02fe98fe9a]
/lib/x86_64-linux-gnu/libc.so.6(clone+0x6d)[0x7f02fe6bd38d]
Not sure if this may be a bug with 1.2.18, or a fault with my
configure/compile/install process; please advise...
Thanks,
Will
3
5
Thanks to Peter who made me test this more and find some corner
cases. And even take a look on Coverity output.
Michal Privoznik (3):
networkBandwidthUpdate: Don't blindly dereference pointers
networkBandwidthGenericChecks: Drop useless check
cmdAttachInterface: Fully implement @floor support
src/network/bridge_driver.c | 7 ++-----
tools/virsh-domain.c | 8 ++++++--
2 files changed, 8 insertions(+), 7 deletions(-)
--
2.4.6
2
5
[libvirt] [PATCH 0/2] Fix problems introduced in 'Add missing QoS implementation'
by Peter Krempa 12 Aug '15
by Peter Krempa 12 Aug '15
12 Aug '15
Peter Krempa (2):
virsh: Refactor parseRateStr to avoid false-positive uninitialized
variable
virsh: Properly reject 'floor' settings in cmdAttachInterface
tools/virsh-domain.c | 96 ++++++++++++++++++++++------------------------------
1 file changed, 41 insertions(+), 55 deletions(-)
--
2.4.5
2
6
[libvirt] virnetsockettest test binary failed while building libvirt
by Dmitriy Slachshyov 12 Aug '15
by Dmitriy Slachshyov 12 Aug '15
12 Aug '15
Hi,
While building the libvirt version 1.2.18 on CentOS7 and also Fedora 22
with the latest updates I have got an error.
I also tried to build version 1.2.17 and had the same result.
Please, help to resolve this problem
Regurds,
Dmitriy
3
3
[libvirt] [PATCH] domain: Fix crash if trying to live update disk <serial>
by Cole Robinson 12 Aug '15
by Cole Robinson 12 Aug '15
12 Aug '15
If you pass <disk><serial> XML to UpdateDevice, and the original device
didn't have a <serial> block, libvirtd crashes trying to read the original
NULL serial string.
Use _NULLABLE string comparisons to avoid the crash. A couple other
properties needed the change too.
---
src/conf/domain_conf.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fd0450f..f1e02e3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -5871,28 +5871,28 @@ virDomainDiskDiffersSourceOnly(virDomainDiskDefPtr disk,
CHECK_EQ(transient, "transient", true);
- if (disk->serial && STRNEQ(disk->serial, orig_disk->serial)) {
+ if (disk->serial && STRNEQ_NULLABLE(disk->serial, orig_disk->serial)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("cannot modify field '%s' of the disk"),
"serial");
return false;
}
- if (disk->wwn && STRNEQ(disk->wwn, orig_disk->wwn)) {
+ if (disk->wwn && STRNEQ_NULLABLE(disk->wwn, orig_disk->wwn)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("cannot modify field '%s' of the disk"),
"wwn");
return false;
}
- if (disk->vendor && STRNEQ(disk->vendor, orig_disk->vendor)) {
+ if (disk->vendor && STRNEQ_NULLABLE(disk->vendor, orig_disk->vendor)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("cannot modify field '%s' of the disk"),
"vendor");
return false;
}
- if (disk->product && STRNEQ(disk->product, orig_disk->product)) {
+ if (disk->product && STRNEQ_NULLABLE(disk->product, orig_disk->product)) {
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
_("cannot modify field '%s' of the disk"),
"product");
--
2.4.3
3
5
12 Aug '15
Virt machine in qemu since v2.3.0 has PCI generic host controller, and
can use PCI devices. This provides performance improvement as well as
vhost-net with irqfd support for virtio-net. However libvirt currently
does not allow ARM virt machine to have PCI devices. This patchset adds
the necessary support.
Changes since v4:
- Rebased onto current master
- Added possibility to plug virtio-net-pci adapter directly into PCIe bus.
This is necessary for irqfds to work in qemu.
Changes since v3:
- Capability is based not on qemu version but on support of "gpex-pcihost"
device by qemu
- Added a workaround, allowing to pass "make check". The problem is that
test suite does not build capabilities cache. Unfortunately this means
that correct unit-test for the new functionality currently cannot be
written. Test suite framework needs to be improved.
Changes since v2:
Complete rework, use different approach
- Correctly model PCI Express bus on the machine. It is now possible to
explicitly specify <address-type='pci'> with attributes. This allows to
attach not only virtio, but any other PCI device to the model.
- Default is not changed and still mmio, for backwards compatibility with
existing installations. PCI bus has to be explicitly specified.
- Check for the capability in correct place, in v2 it actually did not
work
Changes since v1:
- Added capability based on qemu version number
- Recognize also "virt-" prefix
Pavel Fedin (4):
qemu: Introduce QEMU_CAPS_OBJECT_GPEX
Add PCI-Express root to ARM virt machine
Build correct command line for PCI NICs on ARM
Allow to plug virtio-net-pci into PCIe slot
src/qemu/qemu_capabilities.c | 10 ++++++++++
src/qemu/qemu_capabilities.h | 1 +
src/qemu/qemu_command.c | 11 ++++++++++-
src/qemu/qemu_domain.c | 17 +++++++++++++----
4 files changed, 34 insertions(+), 5 deletions(-)
--
1.9.5.msysgit.0
7
41
[libvirt] [PATCH] nodedev: Fix gfeature size to be according to running kernel
by Moshe Levi 11 Aug '15
by Moshe Levi 11 Aug '15
11 Aug '15
This patch add virNetDevGetGFeaturesSize to get the supported
gfeature size from the kernel
---
src/util/virnetdev.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 56 insertions(+), 4 deletions(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 1e20789..3fdf4bb 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -89,8 +89,10 @@ VIR_LOG_INIT("util.netdev");
#define RESOURCE_FILE_LEN 4096
#if HAVE_DECL_ETHTOOL_GFEATURES
+#define ETH_GSTRING_LEN 32
# define TX_UDP_TNL 25
-# define GFEATURES_SIZE 2
+# define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
+# define FEATURE_BITS_TO_BLOCKS(n_bits) DIV_ROUND_UP(n_bits, 32U)
# define FEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field)
# define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
# define FEATURE_BIT_IS_SET(blocks, index, field) \
@@ -3110,6 +3112,53 @@ virNetDevGFeatureAvailable(const char *ifname, struct ethtool_gfeatures *cmd)
ret = FEATURE_BIT_IS_SET(cmd->features, TX_UDP_TNL, active);
return ret;
}
+/**
+ * virNetDevGetGFeaturesSize
+ * This function return the number of gfeatures supported in
+ * the kernel
+ *
+ * @ifname: name of the interface
+ *
+ * Returns gfeature size on success, and 0 on failure or not supported.
+ */
+ static int
+virNetDevGetGFeaturesSize(const char *ifname)
+{
+ struct {
+ struct ethtool_sset_info hdr;
+ uint32_t buf[1];
+ } sset_info;
+ struct ethtool_gstrings *strings;
+ uint32_t size = 0;
+
+ sset_info.hdr.cmd = ETHTOOL_GSSET_INFO;
+ sset_info.hdr.reserved = 0;
+ sset_info.hdr.sset_mask = 1ULL << ETH_SS_FEATURES;
+
+ if (virNetDevSendEthtoolIoctl(ifname, &sset_info) == -1)
+ return size;
+ size = sset_info.hdr.sset_mask ? sset_info.hdr.data[0] : 0;
+
+ if (VIR_ALLOC_VAR(strings, struct ethtool_gstrings, sizeof(*strings) + size * ETH_GSTRING_LEN)) {
+ size = 0;
+ return size;
+ }
+
+ strings->cmd = ETHTOOL_GSTRINGS;
+ strings->string_set = ETH_SS_FEATURES;
+ strings->len = size;
+ if (size != 0 && virNetDevSendEthtoolIoctl(ifname, strings) == -1) {
+ size = 0;
+ goto cleanup;
+ }
+
+ size = FEATURE_BITS_TO_BLOCKS(size);
+
+ cleanup:
+ VIR_FREE(strings);
+ return size;
+}
+
# endif
@@ -3189,9 +3238,12 @@ virNetDevGetFeatures(const char *ifname,
# if HAVE_DECL_ETHTOOL_GFEATURES
g_cmd.cmd = ETHTOOL_GFEATURES;
- g_cmd.size = GFEATURES_SIZE;
- if (virNetDevGFeatureAvailable(ifname, &g_cmd))
- ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_TXUDPTNL));
+ g_cmd.size = virNetDevGetGFeaturesSize(ifname);
+ if (g_cmd.size == 0)
+ VIR_DEBUG("GFeatures unsupported or failure in getting GFeatures size on ifname %s", ifname);
+ else
+ if (virNetDevGFeatureAvailable(ifname, &g_cmd))
+ ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_TXUDPTNL));
# endif
if (virNetDevRDMAFeature(ifname, out) < 0)
--
1.7.1
3
6
[libvirt] [PATCH] qemu: fix qemuDomainSupportsPCI() for ARM machines of "virt" machinetype
by Laine Stump 11 Aug '15
by Laine Stump 11 Aug '15
11 Aug '15
Commit e8d5517 updated the domain post-parse to automatically add
pcie-root et al for certain ARM "virt" machinetypes, but didn't update
the function qemuDomainSupportsPCI() which is called later on when we
are auto-assigning PCI addresses and default settings for the PCI
controller <model> and <target> attributes. The result was that PCI
addresses weren't assigned, and the controllers didn't have their
attribute default values set, leading to an error when the domain was
started, e.g.:
internal error: autogenerated dmi-to-pci-bridge options not set
This patch duplicates the check made in the earlier patch, so that PCI
address auto-assignment and target/model default values will be set.
---
The example Cole gave in his email reporting this bug is fixed by this
patch.
src/qemu/qemu_command.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index ae03618..84cbfe1 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1742,7 +1742,7 @@ qemuCollectPCIAddress(virDomainDefPtr def ATTRIBUTE_UNUSED,
}
static bool
-qemuDomainSupportsPCI(virDomainDefPtr def)
+qemuDomainSupportsPCI(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
{
if ((def->os.arch != VIR_ARCH_ARMV7L) && (def->os.arch != VIR_ARCH_AARCH64))
return true;
@@ -1750,6 +1750,11 @@ qemuDomainSupportsPCI(virDomainDefPtr def)
if (STREQ(def->os.machine, "versatilepb"))
return true;
+ if ((STREQ(def->os.machine, "virt") ||
+ STRPREFIX(def->os.machine, "virt-")) &&
+ virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_GPEX))
+ return true;
+
return false;
}
@@ -2267,7 +2272,7 @@ qemuDomainAssignPCIAddresses(virDomainDefPtr def,
if (!(addrs = qemuDomainPCIAddressSetCreate(def, nbuses, false)))
goto cleanup;
- if (qemuDomainSupportsPCI(def)) {
+ if (qemuDomainSupportsPCI(def, qemuCaps)) {
if (qemuValidateDevicePCISlotsChipsets(def, qemuCaps, addrs) < 0)
goto cleanup;
--
2.1.0
2
2
[libvirt] [PATCH] virNetSocketCheckProtocols: handle EAI_NONAME as IPv6 unavailable
by Guido Günther 11 Aug '15
by Guido Günther 11 Aug '15
11 Aug '15
When running the test suite using "unshare -n" we might have IPv6 but no
configured addresses. Due to AI_ADDRCONFIG getaddrinfo then fails with
EAI_NONAME which we should then treat as IPv6 unavailable.
---
src/rpc/virnetsocket.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/rpc/virnetsocket.c b/src/rpc/virnetsocket.c
index 106d09a..5e5f1ab 100644
--- a/src/rpc/virnetsocket.c
+++ b/src/rpc/virnetsocket.c
@@ -183,7 +183,8 @@ int virNetSocketCheckProtocols(bool *hasIPv4,
if ((gaierr = getaddrinfo("::1", NULL, &hints, &ai)) != 0) {
if (gaierr == EAI_ADDRFAMILY ||
- gaierr == EAI_FAMILY) {
+ gaierr == EAI_FAMILY ||
+ gaierr == EAI_NONAME) {
*hasIPv6 = false;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
--
2.1.4
2
2
[libvirt] [PATCHv2] util: don't overwrite stack when getting ethtool gfeatures
by Laine Stump 11 Aug '15
by Laine Stump 11 Aug '15
11 Aug '15
This fixes the crash described here:
https://www.redhat.com/archives/libvir-list/2015-August/msg00162.html
In short, we were calling ioctl(SIOCETHTOOL) pointing to a too-short
object that was a local on the stack, resulting in the memory past the
end of the object being overwritten. This was because the struct used
by the ETHTOOL_GFEATURES command of SIOCETHTOOL ends with a 0-length
array, but we were telling ethtool that it could use 2 elements on the
array.
The fix is to allocate the necessary memory with VIR_ALLOC_VAR(),
including the extra length needed for a 2 element array at the end.
---
V2 difference: eliminate all the other cleanups that were in V1, just
fix the crash. I had misunderstood that a "failure" of the ioctl
shouldn't really be considered a *failure*, and don't have time to
tweak around with all the inconsequential stuff right now.
src/util/virnetdev.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 1e20789..c158ca3 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -3130,7 +3130,7 @@ virNetDevGetFeatures(const char *ifname,
size_t i = -1;
struct ethtool_value cmd = { 0 };
# if HAVE_DECL_ETHTOOL_GFEATURES
- struct ethtool_gfeatures g_cmd = { 0 };
+ struct ethtool_gfeatures *g_cmd;
# endif
struct elem{
const int cmd;
@@ -3188,10 +3188,14 @@ virNetDevGetFeatures(const char *ifname,
# endif
# if HAVE_DECL_ETHTOOL_GFEATURES
- g_cmd.cmd = ETHTOOL_GFEATURES;
- g_cmd.size = GFEATURES_SIZE;
- if (virNetDevGFeatureAvailable(ifname, &g_cmd))
+ if (VIR_ALLOC_VAR(g_cmd,
+ struct ethtool_get_features_block, GFEATURES_SIZE) < 0)
+ return -1;
+ g_cmd->cmd = ETHTOOL_GFEATURES;
+ g_cmd->size = GFEATURES_SIZE;
+ if (virNetDevGFeatureAvailable(ifname, g_cmd))
ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_TXUDPTNL));
+ VIR_FREE(g_cmd);
# endif
if (virNetDevRDMAFeature(ifname, out) < 0)
--
2.1.0
2
1
11 Aug '15
This started out as a fix for a crash reported in IRC and on libvir-list:
https://www.redhat.com/archives/libvir-list/2015-August/msg00162.html
but as I examined the existing code I found so many nits to pick that
I just did them all.
The most important fix here is that virNetDevGetFeatures was creating
a struct ethtool_gfeatures object as a local on the stack and,
although the struct is defined with 0 elements in its features array,
we were telling the ethtool ioctl that we had made space for 2
elements. This led to a crash, as outlined in the email above. The fix
for this is to allocate the memory for the ethtool_gfeatures object
using VIR_ALLOC_N to a char*, giving it the length:
sizeof(ethtool_gfeatures) + (2 * sizeof(ethtool_get_features_block)
because VIR_ALLOC_N is a macro and fails when you try to typecast a
pointer to char* within the invocation, I made a union that has both a
char* and an ethtool_gfeatures*, and used the char* of the union for
VIR_ALLOC_N, and the other for everything else.
Beyond that crash fixer, the following fixups were made to the
hierarchy of functions between virNetDevGetFeatures() and
virNetDevSendEthtoolIoctl():
* macros used to examine the gfeatures bits were renamed from
FEATURE_* to GFEATURE_*
virNetDevSentEthtoolIoctl():
* no need to initialize sock to -1, since it is always set at the top
of the function.
* remove VIR_DEBUG log (and subsequent *skipping* of error log!) when
errno is EPERM, EINVAL or EOPNOTSUPP. If one of those errors were
ever encountered, this would have been *very* problematic, as it
would have led to one of those situations where virsh reports "an
error was encountered but the cause is unknown" (or whatever the
message is when we have an error but no log message).
* always call VIR_FORCE_CLOSE(sock) since we know that sock is either
a valid fd, or else -1 (which VIR_FORCE_CLOSE() will skip).
virNetDevFeatureAvailable()
* simplify it - no need for ret.
* follow libvirt convention of checking for "bobLobLaw(lawblog) < 0"
instead of "!bobLobLaw(lawblog)".
virNetDevGFeatureAvailable()
* eliminate this function, as it was ill-conceived (it really was only
checking for one gfeature (TX_UDP_TNL), not *any* gfeature.
virNetDevGetFeatures()
* move all data tables (struct elem) out of the function so that they
will be statics instead of taking up space on the stack.
* remove pointless/incorrect initialization of i = -1.
* remove unnecessary static initialization of struct ethtool_value cmd
* put struct ethtool_gfeatures into a union with a char* as described above
* use libvirt convention of checking return from
virNetDevFeatureAvailable() < 0, instead of
"!virNetDevFeatureAvailable()", and immediately return to caller
with an error when virNetDevFeatureAvailable() returns an error
(previously it was ignored).
* remove superfluous size_t j, and just re-use i instead.
* runtime allocation/free of proper size object for ethtoolfeatures as
described above.
* directly call virNetDevSentEthtoolIoctl() instead of now defunct
virNetDevGFeatureAvailable().
===
NB: This patch does *not* attempt to determine the proper number of
elements for the gfeature array at runtime, as proposed in this patch:
https://www.redhat.com/archives/libvir-list/2015-August/msg00263.html
since that wasn't the cause of the crash. I'll leave it up to Moshe to
repost that patch rebased around this one (or whatever ends up being
pushed) if he thinks there is value to it.
Also - as I mentioned in earlier mail in response to the crash, I
noticed when looking into the gfeatures ethtool code that it looks to
me like TX_UDP_TNL should actually be 26 rather than 25, but I may be
missing something. Moshe - can you either confirm or deny that? Where
did you get the value 25 from?
---
src/util/virnetdev.c | 182 ++++++++++++++++++++++++---------------------------
1 file changed, 84 insertions(+), 98 deletions(-)
diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c
index 1e20789..7f0837d 100644
--- a/src/util/virnetdev.c
+++ b/src/util/virnetdev.c
@@ -91,10 +91,10 @@ VIR_LOG_INIT("util.netdev");
#if HAVE_DECL_ETHTOOL_GFEATURES
# define TX_UDP_TNL 25
# define GFEATURES_SIZE 2
-# define FEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field)
-# define FEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
-# define FEATURE_BIT_IS_SET(blocks, index, field) \
- (FEATURE_WORD(blocks, index, field) & FEATURE_FIELD_FLAG(index))
+# define GFEATURE_WORD(blocks, index, field) ((blocks)[(index) / 32U].field)
+# define GFEATURE_FIELD_FLAG(index) (1U << (index) % 32U)
+# define GFEATURE_BIT_IS_SET(blocks, index, field) \
+ (GFEATURE_WORD(blocks, index, field) & GFEATURE_FIELD_FLAG(index))
#endif
typedef enum {
@@ -3032,11 +3032,10 @@ static int
virNetDevSendEthtoolIoctl(const char *ifname, void *cmd)
{
int ret = -1;
- int sock = -1;
+ int sock;
virIfreq ifr;
- sock = socket(AF_LOCAL, SOCK_DGRAM, 0);
- if (sock < 0) {
+ if ((sock = socket(AF_LOCAL, SOCK_DGRAM, 0)) < 0) {
virReportSystemError(errno, "%s", _("Cannot open control socket"));
goto cleanup;
}
@@ -3044,27 +3043,11 @@ virNetDevSendEthtoolIoctl(const char *ifname, void *cmd)
memset(&ifr, 0, sizeof(ifr));
strcpy(ifr.ifr_name, ifname);
ifr.ifr_data = cmd;
- ret = ioctl(sock, SIOCETHTOOL, &ifr);
- if (ret != 0) {
- switch (errno) {
- case EPERM:
- VIR_DEBUG("ethtool ioctl: permission denied");
- break;
- case EINVAL:
- VIR_DEBUG("ethtool ioctl: invalid request");
- break;
- case EOPNOTSUPP:
- VIR_DEBUG("ethtool ioctl: request not supported");
- break;
- default:
- virReportSystemError(errno, "%s", _("ethtool ioctl error"));
- goto cleanup;
- }
- }
+ if ((ret = ioctl(sock, SIOCETHTOOL, &ifr)) < 0)
+ virReportSystemError(errno, "%s", _("ethtool ioctl error"));
cleanup:
- if (sock)
- VIR_FORCE_CLOSE(sock);
+ VIR_FORCE_CLOSE(sock);
return ret;
}
@@ -3081,35 +3064,50 @@ virNetDevSendEthtoolIoctl(const char *ifname, void *cmd)
static int
virNetDevFeatureAvailable(const char *ifname, struct ethtool_value *cmd)
{
- int ret = -1;
-
cmd = (void*)cmd;
- if (!virNetDevSendEthtoolIoctl(ifname, cmd))
- ret = cmd->data > 0 ? 1 : 0;
- return ret;
+ if (virNetDevSendEthtoolIoctl(ifname, cmd) < 0)
+ return -1;
+ return cmd->data > 0 ? 1 : 0;
}
-# if HAVE_DECL_ETHTOOL_GFEATURES
-/**
- * virNetDevGFeatureAvailable
- * This function checks for the availability of a network device gfeature
- *
- * @ifname: name of the interface
- * @cmd: reference to a gfeatures ethtool command structure
- *
- * Returns 0 if not found, 1 on success, and -1 on failure.
- */
-static int
-virNetDevGFeatureAvailable(const char *ifname, struct ethtool_gfeatures *cmd)
-{
- int ret = -1;
+/* static tables used by virNetDevGetFeatures() */
+struct elem {
+ const int cmd;
+ const virNetDevFeature feat;
+};
- cmd = (void*)cmd;
- if (!virNetDevSendEthtoolIoctl(ifname, cmd))
- ret = FEATURE_BIT_IS_SET(cmd->features, TX_UDP_TNL, active);
- return ret;
-}
+/* legacy ethtool getters */
+struct elem cmds[] = {
+ {ETHTOOL_GRXCSUM, VIR_NET_DEV_FEAT_GRXCSUM},
+ {ETHTOOL_GTXCSUM, VIR_NET_DEV_FEAT_GTXCSUM},
+ {ETHTOOL_GSG, VIR_NET_DEV_FEAT_GSG},
+ {ETHTOOL_GTSO, VIR_NET_DEV_FEAT_GTSO},
+# if HAVE_DECL_ETHTOOL_GGSO
+ {ETHTOOL_GGSO, VIR_NET_DEV_FEAT_GGSO},
+# endif
+# if HAVE_DECL_ETHTOOL_GGRO
+ {ETHTOOL_GGRO, VIR_NET_DEV_FEAT_GGRO},
+# endif
+};
+
+# if HAVE_DECL_ETHTOOL_GFLAGS
+/* ethtool masks */
+struct elem flags[] = {
+# if HAVE_DECL_ETH_FLAG_LRO
+ {ETH_FLAG_LRO, VIR_NET_DEV_FEAT_LRO},
+# endif
+# if HAVE_DECL_ETH_FLAG_TXVLAN
+ {ETH_FLAG_RXVLAN, VIR_NET_DEV_FEAT_RXVLAN},
+ {ETH_FLAG_TXVLAN, VIR_NET_DEV_FEAT_TXVLAN},
+# endif
+# if HAVE_DECL_ETH_FLAG_NTUBLE
+ {ETH_FLAG_NTUPLE, VIR_NET_DEV_FEAT_NTUPLE},
+# endif
+# if HAVE_DECL_ETH_FLAG_RXHASH
+ {ETH_FLAG_RXHASH, VIR_NET_DEV_FEAT_RXHASH},
+# endif
+};
# endif
@@ -3127,71 +3125,59 @@ int
virNetDevGetFeatures(const char *ifname,
virBitmapPtr *out)
{
- size_t i = -1;
- struct ethtool_value cmd = { 0 };
+ size_t i;
+ int ret;
+ struct ethtool_value cmd;
# if HAVE_DECL_ETHTOOL_GFEATURES
- struct ethtool_gfeatures g_cmd = { 0 };
+ union {
+ struct ethtool_gfeatures *cmd;
+ char *cmd_char;
+ } g;
# endif
- struct elem{
- const int cmd;
- const virNetDevFeature feat;
- };
- /* legacy ethtool getters */
- struct elem cmds[] = {
- {ETHTOOL_GRXCSUM, VIR_NET_DEV_FEAT_GRXCSUM},
- {ETHTOOL_GTXCSUM, VIR_NET_DEV_FEAT_GTXCSUM},
- {ETHTOOL_GSG, VIR_NET_DEV_FEAT_GSG},
- {ETHTOOL_GTSO, VIR_NET_DEV_FEAT_GTSO},
-# if HAVE_DECL_ETHTOOL_GGSO
- {ETHTOOL_GGSO, VIR_NET_DEV_FEAT_GGSO},
-# endif
-# if HAVE_DECL_ETHTOOL_GGRO
- {ETHTOOL_GGRO, VIR_NET_DEV_FEAT_GGRO},
-# endif
- };
if (!(*out = virBitmapNew(VIR_NET_DEV_FEAT_LAST)))
return -1;
+ /* first set of capabilities are one capability per
+ * command. cmd.data is set if the interface has that
+ * capability
+ */
for (i = 0; i < ARRAY_CARDINALITY(cmds); i++) {
cmd.cmd = cmds[i].cmd;
- if (virNetDevFeatureAvailable(ifname, &cmd))
+ if ((ret = virNetDevFeatureAvailable(ifname, &cmd)) < 0)
+ return -1;
+ if (ret)
ignore_value(virBitmapSetBit(*out, cmds[i].feat));
}
# if HAVE_DECL_ETHTOOL_GFLAGS
- size_t j = -1;
- /* ethtool masks */
- struct elem flags[] = {
-# if HAVE_DECL_ETH_FLAG_LRO
- {ETH_FLAG_LRO, VIR_NET_DEV_FEAT_LRO},
-# endif
-# if HAVE_DECL_ETH_FLAG_TXVLAN
- {ETH_FLAG_RXVLAN, VIR_NET_DEV_FEAT_RXVLAN},
- {ETH_FLAG_TXVLAN, VIR_NET_DEV_FEAT_TXVLAN},
-# endif
-# if HAVE_DECL_ETH_FLAG_NTUBLE
- {ETH_FLAG_NTUPLE, VIR_NET_DEV_FEAT_NTUPLE},
-# endif
-# if HAVE_DECL_ETH_FLAG_RXHASH
- {ETH_FLAG_RXHASH, VIR_NET_DEV_FEAT_RXHASH},
-# endif
- };
-
+ /* second set of capabilities are all stored as 1 bit each in
+ * cmd.data of the result of the single ETHTOOL_GFLAGS command
+ */
cmd.cmd = ETHTOOL_GFLAGS;
- if (virNetDevFeatureAvailable(ifname, &cmd)) {
- for (j = 0; j < ARRAY_CARDINALITY(flags); j++) {
- if (cmd.data & flags[j].cmd)
- ignore_value(virBitmapSetBit(*out, flags[j].feat));
- }
- }
+ if ((ret = virNetDevFeatureAvailable(ifname, &cmd)) < 0)
+ return -1;
+ for (i = 0; ret && i < ARRAY_CARDINALITY(flags); i++)
+ if (cmd.data & flags[i].cmd)
+ ignore_value(virBitmapSetBit(*out, flags[i].feat));
# endif
# if HAVE_DECL_ETHTOOL_GFEATURES
- g_cmd.cmd = ETHTOOL_GFEATURES;
- g_cmd.size = GFEATURES_SIZE;
- if (virNetDevGFeatureAvailable(ifname, &g_cmd))
+ /* allocate an object with GFEATURES_SIZE elements in the features array */
+ if (VIR_ALLOC_N(g.cmd_char,
+ sizeof(struct ethtool_gfeatures) +
+ (sizeof(struct ethtool_get_features_block) * GFEATURES_SIZE)) < 0)
+ return -1;
+
+ g.cmd->cmd = ETHTOOL_GFEATURES;
+ g.cmd->size = GFEATURES_SIZE;
+ if (virNetDevSendEthtoolIoctl(ifname, g.cmd) < 0) {
+ VIR_FREE(g.cmd);
+ return -1;
+ }
+ if (GFEATURE_BIT_IS_SET(g.cmd->features, TX_UDP_TNL, active))
ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_TXUDPTNL));
+ VIR_FREE(g.cmd);
# endif
if (virNetDevRDMAFeature(ifname, out) < 0)
--
2.1.0
3
5
Commit adb865d introduced some changes in ppc64DriverNodeData()
that cause libvirtd to crash on startup unless this patch is
applied as well.
---
src/cpu/cpu_ppc64.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/cpu/cpu_ppc64.c b/src/cpu/cpu_ppc64.c
index 33fec8b..85aa5bc 100644
--- a/src/cpu/cpu_ppc64.c
+++ b/src/cpu/cpu_ppc64.c
@@ -628,7 +628,7 @@ ppc64DriverNodeData(virArch arch)
if (VIR_ALLOC(nodeData) < 0)
goto error;
- if (VIR_ALLOC(data) < 0)
+ if (VIR_ALLOC(nodeData->data.ppc64) < 0)
goto error;
data = nodeData->data.ppc64;
--
2.4.3
2
2
11 Aug '15
Commit a6f9af8292b6 added checking for address colisions between
starting and ending addresses of forwarding addresses, but forgot that
there might be no addresses set at all.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
src/conf/network_conf.c | 22 +++++++++++++++++++---
....xml => nat-network-forward-nat-no-address.xml} | 1 -
....xml => nat-network-forward-nat-no-address.xml} | 1 -
tests/networkxml2xmltest.c | 1 +
4 files changed, 20 insertions(+), 5 deletions(-)
copy tests/networkxml2xmlin/{nat-network-forward-nat-address.xml => nat-network-forward-nat-no-address.xml} (93%)
copy tests/networkxml2xmlout/{nat-network-forward-nat-address.xml => nat-network-forward-nat-no-address.xml} (93%)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 374d723788e1..f9d894b12046 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1731,9 +1731,25 @@ virNetworkForwardNatDefParseXML(const char *networkName,
goto cleanup;
}
- /* verify that start <= end */
- if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
- goto cleanup;
+ if (addrStart && addrEnd) {
+ /* verify that start <= end */
+ if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
+ goto cleanup;
+ } else {
+ if (addrStart) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Only start address '%s' specified in <nat> in "
+ "<forward> in network '%s'"),
+ addrStart, networkName);
+ goto cleanup;
+ }
+ if (addrEnd) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("Only end address '%s' specified in <nat> in "
+ "<forward> in network '%s'"),
+ addrEnd, networkName);
+ }
+ }
/* ports for SNAT and MASQUERADE */
nNatPorts = virXPathNodeSet("./port", ctxt, &natPortNodes);
diff --git a/tests/networkxml2xmlin/nat-network-forward-nat-address.xml b/tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
similarity index 93%
copy from tests/networkxml2xmlin/nat-network-forward-nat-address.xml
copy to tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
index 403d058330ea..97a64526e94f 100644
--- a/tests/networkxml2xmlin/nat-network-forward-nat-address.xml
+++ b/tests/networkxml2xmlin/nat-network-forward-nat-no-address.xml
@@ -4,7 +4,6 @@
<bridge name="virbr0"/>
<forward mode="nat" dev="eth1">
<nat>
- <address start='10.20.30.40' end='10.20.30.44'/>
<port start='60000' end='65432'/>
</nat>
</forward>
diff --git a/tests/networkxml2xmlout/nat-network-forward-nat-address.xml b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
similarity index 93%
copy from tests/networkxml2xmlout/nat-network-forward-nat-address.xml
copy to tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
index faeba2470661..f19e34deecec 100644
--- a/tests/networkxml2xmlout/nat-network-forward-nat-address.xml
+++ b/tests/networkxml2xmlout/nat-network-forward-nat-no-address.xml
@@ -3,7 +3,6 @@
<uuid>81ff0d90-c91e-6742-64da-4a736edb9a9b</uuid>
<forward dev='eth1' mode='nat'>
<nat>
- <address start='10.20.30.40' end='10.20.30.44'/>
<port start='60000' end='65432'/>
</nat>
<interface dev='eth1'/>
diff --git a/tests/networkxml2xmltest.c b/tests/networkxml2xmltest.c
index 290336edbefd..8d60aa8fc665 100644
--- a/tests/networkxml2xmltest.c
+++ b/tests/networkxml2xmltest.c
@@ -99,6 +99,7 @@ mymain(void)
DO_TEST("nat-network-dns-forward-plain");
DO_TEST("nat-network-dns-forwarders");
DO_TEST("nat-network-forward-nat-address");
+ DO_TEST("nat-network-forward-nat-no-address");
DO_TEST("8021Qbh-net");
DO_TEST("direct-net");
DO_TEST("host-bridge-net");
--
2.5.0
3
3
11 Aug '15
Patches 01-07 are cleanups, 08-10 are bug fixes and 11-20
improve the driver.
Changes in v3:
* Fix a bug spotted by John thanks to Coverity
Changes in v2:
* Implement compatibility with guests defined on older
libvirt versions
* Always use fallback='forbid' when emitting CPU definitions
* Update all tests in one go instead of changing them
several times
* Handle test failure and system failure differently in
cpuTestGuestData()
* Simplify ppc64DriverNodeData()
* Simplify XML parsing code
* Remove unnecessary NULL checks
* Add even more test cases
* Other small changes such as shuffling chunks between
commits to make the history more readable
Cheers.
Andrea Bolognani (20):
cpu: Mark driver functions in ppc64 driver
cpu: Simplify NULL handling in ppc64 driver
cpu: Simplify ppc64ModelFromCPU()
cpu: Reorder functions in the ppc64 driver
cpu: Remove ISA information from CPU map XML
tests: Remove unused file
tests: Improve result handling in cpuTestGuestData()
cpu: Never skip CPU model name check in ppc64 driver
cpu: CPU model names have to match on ppc64
cpu: Use ppc64Compute() to implement ppc64DriverCompare()
tests: Temporarily disable ppc64 cpu tests
cpu: Align ppc64 CPU data with x86
cpu: Support multiple PVRs in the ppc64 driver
cpu: Simplify ppc64 part of CPU map XML
cpu: Parse and use PVR masks in the ppc64 driver
cpu: Add POWER8NVL information to CPU map XML
cpu: Implement backwards compatibility in the ppc64 driver
cpu: Forbid model fallback in the ppc64 driver
tests: Re-enable ppc64 cpu tests
tests: Add a bunch of cpu test case for ppc64
src/cpu/cpu.h | 2 +-
src/cpu/cpu_map.xml | 59 +--
src/cpu/cpu_ppc64.c | 451 +++++++++++++--------
src/cpu/cpu_ppc64_data.h | 12 +-
tests/cputest.c | 55 ++-
tests/cputestdata/ppc64-baseline-1-result.xml | 3 -
.../ppc64-baseline-incompatible-models.xml | 14 +
.../ppc64-baseline-incompatible-vendors.xml | 4 +-
tests/cputestdata/ppc64-baseline-legacy.xml | 14 +
.../ppc64-baseline-no-vendor-result.xml | 2 +-
tests/cputestdata/ppc64-baseline-no-vendor.xml | 2 +-
.../ppc64-baseline-same-model-result.xml | 3 +
tests/cputestdata/ppc64-baseline-same-model.xml | 14 +
tests/cputestdata/ppc64-exact.xml | 3 -
tests/cputestdata/ppc64-guest-exact.xml | 3 +
.../ppc64-guest-legacy-incompatible.xml | 3 +
tests/cputestdata/ppc64-guest-legacy-invalid.xml | 3 +
tests/cputestdata/ppc64-guest-legacy.xml | 3 +
tests/cputestdata/ppc64-guest-nofallback.xml | 3 +-
tests/cputestdata/ppc64-guest-strict.xml | 3 +
tests/cputestdata/ppc64-guest.xml | 3 +-
.../ppc64-host+guest,ppc_models-result.xml | 2 +-
... ppc64-host+guest-legacy,ppc_models-result.xml} | 2 +-
tests/cputestdata/ppc64-host-better.xml | 6 +
tests/cputestdata/ppc64-host-incomp-arch.xml | 6 +
tests/cputestdata/ppc64-host-no-vendor.xml | 5 +
tests/cputestdata/ppc64-host-worse.xml | 6 +
tests/cputestdata/ppc64-host.xml | 2 +-
tests/cputestdata/ppc64-strict.xml | 3 -
29 files changed, 444 insertions(+), 247 deletions(-)
delete mode 100644 tests/cputestdata/ppc64-baseline-1-result.xml
create mode 100644 tests/cputestdata/ppc64-baseline-incompatible-models.xml
create mode 100644 tests/cputestdata/ppc64-baseline-legacy.xml
create mode 100644 tests/cputestdata/ppc64-baseline-same-model-result.xml
create mode 100644 tests/cputestdata/ppc64-baseline-same-model.xml
delete mode 100644 tests/cputestdata/ppc64-exact.xml
create mode 100644 tests/cputestdata/ppc64-guest-exact.xml
create mode 100644 tests/cputestdata/ppc64-guest-legacy-incompatible.xml
create mode 100644 tests/cputestdata/ppc64-guest-legacy-invalid.xml
create mode 100644 tests/cputestdata/ppc64-guest-legacy.xml
create mode 100644 tests/cputestdata/ppc64-guest-strict.xml
rename tests/cputestdata/{ppc64-host+guest-nofallback,ppc_models,POWER7_v2.1-result.xml => ppc64-host+guest-legacy,ppc_models-result.xml} (64%)
create mode 100644 tests/cputestdata/ppc64-host-better.xml
create mode 100644 tests/cputestdata/ppc64-host-incomp-arch.xml
create mode 100644 tests/cputestdata/ppc64-host-no-vendor.xml
create mode 100644 tests/cputestdata/ppc64-host-worse.xml
delete mode 100644 tests/cputestdata/ppc64-strict.xml
--
2.4.3
2
43
This patch modifies virSocketAddrGetRange() to function properly when
the containing network/prefix of the address range isn't known, for
example in the case of the NAT range of a virtual network (since it is
a range of addresses on the *host*, not within the network itself). We
then take advantage of this new functionality to validate the NAT
range of a virtual network.
Extra test cases are also added to verify that virSocketAddrGetRange()
works properly in both positive and negative cases when the network
pointer is NULL.
This is the *real* fix for:
https://bugzilla.redhat.com/show_bug.cgi?id=985653
Commits 1e334a and 48e8b9 had earlier been pushed as fixes for that
bug, but I had neglected to read the report carefully, so instead of
fixing validation for the NAT range, I had fixed validation for the
DHCP range. sigh.
---
The changes to virSocketAddrGetRange() *look* like they are extensive,
but really they almost completely consist of:
1) reordering and reindenting some of the checks so that they are only
executed when we have a valid network address
2) modifying the error messages that could occur when there isn't a
valid network so that they don't attempt to use the network address
or prefix.
src/conf/network_conf.c | 4 ++
src/util/virsocketaddr.c | 168 +++++++++++++++++++++++++----------------------
tests/sockettest.c | 46 ++++++++++++-
3 files changed, 136 insertions(+), 82 deletions(-)
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index f77af15..b8d918c 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1731,6 +1731,10 @@ virNetworkForwardNatDefParseXML(const char *networkName,
goto cleanup;
}
+ /* verify that start <= end */
+ if (virSocketAddrGetRange(&def->addr.start, &def->addr.end, NULL, 0) < 0)
+ goto cleanup;
+
/* ports for SNAT and MASQUERADE */
nNatPorts = virXPathNodeSet("./port", ctxt, &natPortNodes);
if (nNatPorts < 0) {
diff --git a/src/util/virsocketaddr.c b/src/util/virsocketaddr.c
index 81539b3..900aa5b 100644
--- a/src/util/virsocketaddr.c
+++ b/src/util/virsocketaddr.c
@@ -628,126 +628,136 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end,
virSocketAddr netmask;
char *startStr = NULL, *endStr = NULL, *netStr = NULL;
- if (start == NULL || end == NULL || network == NULL) {
+ if (start == NULL || end == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("NULL argument - %p %p %p"), start, end, network);
+ _("NULL argument - %p %p"), start, end);
goto error;
}
startStr = virSocketAddrFormat(start);
endStr = virSocketAddrFormat(end);
- netStr = virSocketAddrFormat(network);
- if (!(startStr && endStr && netStr))
+ if (!startStr || !endStr)
goto error; /*error already reported */
- if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(end) ||
- VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(network)) {
+ if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(end)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("mismatch of address family in "
- "range %s - %s for network %s"),
- startStr, endStr, netStr);
+ _("mismatch of address family in range %s - %s"),
+ startStr, endStr);
goto error;
}
- if (prefix < 0 ||
- virSocketAddrPrefixToNetmask(prefix, &netmask,
- VIR_SOCKET_ADDR_FAMILY(network)) < 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("bad prefix %d for network %s when "
- " checking range %s - %s"),
- prefix, netStr, startStr, endStr);
- goto error;
- }
-
- /* both start and end of range need to be in the same network as
- * "network"
- */
- if (virSocketAddrCheckNetmask(start, network, &netmask) <= 0 ||
- virSocketAddrCheckNetmask(end, network, &netmask) <= 0) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s is not entirely within "
- "network %s/%d"),
- startStr, endStr, netStr, prefix);
- goto error;
- }
-
- if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) {
- virSocketAddrIPv4 t1, t2;
- virSocketAddr netaddr, broadcast;
+ if (network) {
+ /* some checks can only be done if we have details of the
+ * network the range should be within
+ */
+ if (!(netStr = virSocketAddrFormat(network)))
+ goto error;
- if (virSocketAddrBroadcast(network, &netmask, &broadcast) < 0 ||
- virSocketAddrMask(network, &netmask, &netaddr) < 0) {
+ if (VIR_SOCKET_ADDR_FAMILY(start) != VIR_SOCKET_ADDR_FAMILY(network)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("failed to construct broadcast or network "
- "address for network %s/%d"),
- netStr, prefix);
+ _("mismatch of address family in "
+ "range %s - %s for network %s"),
+ startStr, endStr, netStr);
goto error;
}
- /* Don't allow the start of the range to be the network
- * address (usually "...0") or the end of the range to be the
- * broadcast address (usually "...255"). (the opposite also
- * isn't allowed, but checking for that is implicit in all the
- * other combined checks) (IPv6 doesn't have broadcast and
- * network addresses, so this check is only done for IPv4)
- */
- if (virSocketAddrEqual(start, &netaddr)) {
+ if (prefix < 0 ||
+ virSocketAddrPrefixToNetmask(prefix, &netmask,
+ VIR_SOCKET_ADDR_FAMILY(network)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("start of range %s - %s in network %s/%d "
- "is the network address"),
- startStr, endStr, netStr, prefix);
+ _("bad prefix %d for network %s when "
+ " checking range %s - %s"),
+ prefix, netStr, startStr, endStr);
goto error;
}
- if (virSocketAddrEqual(end, &broadcast)) {
+ /* both start and end of range need to be within network */
+ if (virSocketAddrCheckNetmask(start, network, &netmask) <= 0 ||
+ virSocketAddrCheckNetmask(end, network, &netmask) <= 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("end of range %s - %s in network %s/%d "
- "is the broadcast address"),
+ _("range %s - %s is not entirely within "
+ "network %s/%d"),
startStr, endStr, netStr, prefix);
goto error;
}
- if ((virSocketAddrGetIPv4Addr(start, &t1) < 0) ||
- (virSocketAddrGetIPv4Addr(end, &t2) < 0)) {
+ if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) {
+ virSocketAddr netaddr, broadcast;
+
+ if (virSocketAddrBroadcast(network, &netmask, &broadcast) < 0 ||
+ virSocketAddrMask(network, &netmask, &netaddr) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("failed to construct broadcast or network "
+ "address for network %s/%d"),
+ netStr, prefix);
+ goto error;
+ }
+
+ /* Don't allow the start of the range to be the network
+ * address (usually "...0") or the end of the range to be the
+ * broadcast address (usually "...255"). (the opposite also
+ * isn't allowed, but checking for that is implicit in all the
+ * other combined checks) (IPv6 doesn't have broadcast and
+ * network addresses, so this check is only done for IPv4)
+ */
+ if (virSocketAddrEqual(start, &netaddr)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("start of range %s - %s in network %s/%d "
+ "is the network address"),
+ startStr, endStr, netStr, prefix);
+ goto error;
+ }
+
+ if (virSocketAddrEqual(end, &broadcast)) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("end of range %s - %s in network %s/%d "
+ "is the broadcast address"),
+ startStr, endStr, netStr, prefix);
+ goto error;
+ }
+ }
+ }
+
+ if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET)) {
+ virSocketAddrIPv4 t1, t2;
+
+ if (virSocketAddrGetIPv4Addr(start, &t1) < 0 ||
+ virSocketAddrGetIPv4Addr(end, &t2) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to get IPv4 address "
- "for start or end of range %s - %s "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ "for start or end of range %s - %s"),
+ startStr, endStr);
goto error;
}
- /* legacy check that everything except the last two bytes are
- * the same
+ /* legacy check that everything except the last two bytes
+ * are the same
*/
for (i = 0; i < 2; i++) {
if (t1[i] != t2[i]) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s is too large (> 65535) "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ _("range %s - %s is too large (> 65535)"),
+ startStr, endStr);
goto error;
}
}
ret = (t2[2] - t1[2]) * 256 + (t2[3] - t1[3]);
if (ret < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s is reversed "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ _("range %s - %s is reversed "),
+ startStr, endStr);
goto error;
}
ret++;
} else if (VIR_SOCKET_ADDR_IS_FAMILY(start, AF_INET6)) {
virSocketAddrIPv6 t1, t2;
- if ((virSocketAddrGetIPv6Addr(start, &t1) < 0) ||
- (virSocketAddrGetIPv6Addr(end, &t2) < 0)) {
+ if (virSocketAddrGetIPv6Addr(start, &t1) < 0 ||
+ virSocketAddrGetIPv6Addr(end, &t2) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to get IPv6 address "
- "for start or end of range %s - %s "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ "for start or end of range %s - %s"),
+ startStr, endStr);
goto error;
}
@@ -757,29 +767,27 @@ virSocketAddrGetRange(virSocketAddrPtr start, virSocketAddrPtr end,
for (i = 0; i < 7; i++) {
if (t1[i] != t2[i]) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s is too large (> 65535) "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ _("range %s - %s is too large (> 65535)"),
+ startStr, endStr);
goto error;
}
}
ret = t2[7] - t1[7];
if (ret < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
- _("range %s - %s start larger than end "
- "in network %s/%d"),
- startStr, endStr, netStr, prefix);
+ _("range %s - %s start larger than end"),
+ startStr, endStr);
goto error;
}
ret++;
} else {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unsupported address family "
- "for range %s - %s "
- "in network %s/%d, must be ipv4 or ipv6"),
- startStr, endStr, netStr, prefix);
+ "for range %s - %s, must be ipv4 or ipv6"),
+ startStr, endStr);
goto error;
}
+
cleanup:
VIR_FREE(startStr);
VIR_FREE(endStr);
diff --git a/tests/sockettest.c b/tests/sockettest.c
index 292edb6..8f46218 100644
--- a/tests/sockettest.c
+++ b/tests/sockettest.c
@@ -98,10 +98,11 @@ testRange(const char *saddrstr, const char *eaddrstr,
return -1;
if (virSocketAddrParse(&eaddr, eaddrstr, AF_UNSPEC) < 0)
return -1;
- if (virSocketAddrParse(&netaddr, netstr, AF_UNSPEC) < 0)
+ if (netstr && virSocketAddrParse(&netaddr, netstr, AF_UNSPEC) < 0)
return -1;
- int gotsize = virSocketAddrGetRange(&saddr, &eaddr, &netaddr, prefix);
+ int gotsize = virSocketAddrGetRange(&saddr, &eaddr,
+ netstr ? &netaddr : NULL, prefix);
VIR_DEBUG("Size want %d vs got %d", size, gotsize);
if (pass) {
/* fail if virSocketAddrGetRange returns failure, or unexpected size */
@@ -311,6 +312,15 @@ mymain(void)
ret = -1; \
} while (0)
+#define DO_TEST_RANGE_SIMPLE(saddr, eaddr, size, pass) \
+ do { \
+ struct testRangeData data \
+ = { saddr, eaddr, NULL, 0, size, pass }; \
+ if (virtTestRun("Test range " saddr " -> " eaddr "size " #size, \
+ testRangeHelper, &data) < 0) \
+ ret = -1; \
+ } while (0)
+
#define DO_TEST_NETMASK(addr1, addr2, netmask, pass) \
do { \
struct testNetmaskData data = { addr1, addr2, netmask, pass }; \
@@ -373,23 +383,55 @@ mymain(void)
DO_TEST_PARSE_AND_FORMAT("::1", AF_UNIX, false);
DO_TEST_PARSE_AND_FORMAT("::ffff", AF_UNSPEC, true);
+ /* tests that specify a network that should contain the range */
DO_TEST_RANGE("192.168.122.1", "192.168.122.1", "192.168.122.1", 24, 1, true);
DO_TEST_RANGE("192.168.122.1", "192.168.122.20", "192.168.122.22", 24, 20, true);
+ /* start of range is "network address" */
DO_TEST_RANGE("192.168.122.0", "192.168.122.254", "192.168.122.1", 24, -1, false);
+ /* end of range is "broadcast address" */
DO_TEST_RANGE("192.168.122.1", "192.168.122.255", "192.168.122.1", 24, -1, false);
DO_TEST_RANGE("192.168.122.0", "192.168.122.255", "192.168.122.1", 16, 256, true);
+ /* range is reversed */
DO_TEST_RANGE("192.168.122.20", "192.168.122.1", "192.168.122.1", 24, -1, false);
+ /* start address outside network */
DO_TEST_RANGE("10.0.0.1", "192.168.122.20", "192.168.122.1", 24, -1, false);
+ /* end address outside network and range reversed */
DO_TEST_RANGE("192.168.122.20", "10.0.0.1", "192.168.122.1", 24, -1, false);
+ /* entire range outside network */
DO_TEST_RANGE("172.16.0.50", "172.16.0.254", "1.2.3.4", 8, -1, false);
+ /* end address outside network */
DO_TEST_RANGE("192.168.122.1", "192.168.123.20", "192.168.122.22", 24, -1, false);
DO_TEST_RANGE("192.168.122.1", "192.168.123.20", "192.168.122.22", 23, 276, true);
DO_TEST_RANGE("2000::1", "2000::1", "2000::1", 64, 1, true);
DO_TEST_RANGE("2000::1", "2000::2", "2000::1", 64, 2, true);
+ /* range reversed */
DO_TEST_RANGE("2000::2", "2000::1", "2000::1", 64, -1, false);
+ /* range too large (> 65536) */
DO_TEST_RANGE("2000::1", "9001::1", "2000::1", 64, -1, false);
+ /* tests that *don't* specify a containing network
+ * (so fewer things can be checked)
+ */
+ DO_TEST_RANGE_SIMPLE("192.168.122.1", "192.168.122.1", 1, true);
+ DO_TEST_RANGE_SIMPLE("192.168.122.1", "192.168.122.20", 20, true);
+ DO_TEST_RANGE_SIMPLE("192.168.122.0", "192.168.122.255", 256, true);
+ /* range is reversed */
+ DO_TEST_RANGE_SIMPLE("192.168.122.20", "192.168.122.1", -1, false);
+ /* range too large (> 65536) */
+ DO_TEST_RANGE_SIMPLE("10.0.0.1", "192.168.122.20", -1, false);
+ /* range reversed */
+ DO_TEST_RANGE_SIMPLE("192.168.122.20", "10.0.0.1", -1, false);
+ DO_TEST_RANGE_SIMPLE("172.16.0.50", "172.16.0.254", 205, true);
+ DO_TEST_RANGE_SIMPLE("192.168.122.1", "192.168.123.20", 276, true);
+
+ DO_TEST_RANGE_SIMPLE("2000::1", "2000::1", 1, true);
+ DO_TEST_RANGE_SIMPLE("2000::1", "2000::2", 2, true);
+ /* range reversed */
+ DO_TEST_RANGE_SIMPLE("2000::2", "2000::1", -1, false);
+ /* range too large (> 65536) */
+ DO_TEST_RANGE_SIMPLE("2000::1", "9001::1", -1, false);
+
DO_TEST_NETMASK("192.168.122.1", "192.168.122.2",
"255.255.255.0", true);
DO_TEST_NETMASK("192.168.122.1", "192.168.122.4",
--
2.1.0
3
3
The first patch is unrelated to the rest, but I have it on the
same branch. The patches 2..5 fix a daemon crasher (since
domain_write ACL is required, I'm not going through
libvirt-security). Then, since after patch 5 we have nearly
everything prepared, patches 6..9 implement new feature: setting
@floor live on domain interfaces.
Michal Privoznik (9):
virNetDevParseMcast: Avoid magic constant
virNetDevBandwidthUpdateRate: turn class_id into integer
bridge_driver: Introduce networkBandwidthChangeAllowed
bridge_driver: Introduce networkBandwidthUpdate
qemuDomainSetInterfaceParameters: Use new functions to update
bandwidth
virsh: Rework parseRateStr
Introduce VIR_DOMAIN_BANDWIDTH_IN_FLOOR
virsh: Implement VIR_DOMAIN_BANDWIDTH_IN_FLOOR
qemu: Implement VIR_DOMAIN_BANDWIDTH_IN_FLOOR
include/libvirt/libvirt-domain.h | 7 ++
src/network/bridge_driver.c | 234 +++++++++++++++++++++++++++++++++------
src/network/bridge_driver.h | 22 ++++
src/qemu/qemu_driver.c | 30 ++++-
src/util/virnetdev.c | 2 +-
src/util/virnetdevbandwidth.c | 10 +-
src/util/virnetdevbandwidth.h | 2 +-
tools/virsh-domain.c | 99 +++++++++++------
tools/virsh.pod | 12 +-
9 files changed, 334 insertions(+), 84 deletions(-)
--
2.4.6
2
26
11 Aug '15
I'll send virt-admin list call once the virsh split series is merged.
Erik Skultety (6):
test: Replace tabs with spaces in input-data-admin-nomdns.json
rpc: Introduce new elements 'id' and 'name' to virnetserver structure
admin: Drop 'internal.h' include from libvirt-admin.h
admin: Move admin_server.{h,c} to admin.{h,c}
admin: Introduce adminDaemonConnectListServers API
admin: Usage example of the new server listing API
.gitignore | 1 +
Makefile.am | 2 +-
configure.ac | 1 +
daemon/Makefile.am | 4 +-
daemon/admin.c | 174 +++++++++++++++
daemon/admin.h | 36 +++
daemon/admin_server.c | 116 ++++------
daemon/admin_server.h | 23 +-
daemon/libvirtd.c | 6 +-
examples/admin/Makefile.am | 25 +++
examples/admin/listservers.c | 73 ++++++
include/libvirt/libvirt-admin.h | 14 +-
po/POTFILES.in | 2 +-
src/admin/admin_protocol.x | 27 ++-
src/datatypes.c | 35 +++
src/datatypes.h | 35 +++
src/libvirt-admin.c | 173 +++++++++++++++
src/libvirt_admin.syms | 4 +
src/locking/lock_daemon.c | 2 +-
src/lxc/lxc_controller.c | 2 +-
src/rpc/virnetdaemon.c | 16 ++
src/rpc/virnetdaemon.h | 2 +
src/rpc/virnetserver.c | 41 +++-
src/rpc/virnetserver.h | 4 +
.../virnetdaemondata/input-data-admin-nomdns.json | 246 +++++++++++----------
.../virnetdaemondata/input-data-anon-clients.json | 1 +
.../input-data-initial-nomdns.json | 1 +
tests/virnetdaemondata/input-data-initial.json | 1 +
tests/virnetdaemontest.c | 2 +-
29 files changed, 846 insertions(+), 223 deletions(-)
create mode 100644 daemon/admin.c
create mode 100644 daemon/admin.h
create mode 100644 examples/admin/Makefile.am
create mode 100644 examples/admin/listservers.c
--
2.4.3
2
13
[libvirt] [PATCH v2 0/2] Add support for virtio-scsi controllers with ioeventfd
by Martin Kletzander 10 Aug '15
by Martin Kletzander 10 Aug '15
10 Aug '15
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1150484
v2:
- Changed one occurence virTristateBool to virTristateSwitch as it should be
- wrapped one line to be <= 80 characters long
- Rebased on top of current master (with laine's patches pushed)
Martin Kletzander (2):
conf: Add ioeventfd option for controllers
qemu: Enable ioeventfd usage for virtio-scsi controllers
docs/formatdomain.html.in | 8 ++++++
docs/schemas/domaincommon.rng | 3 +++
src/conf/domain_conf.c | 20 +++++++++++++--
src/conf/domain_conf.h | 1 +
src/qemu/qemu_command.c | 7 ++++++
.../qemuxml2argv-disk-virtio-scsi-ioeventfd.args | 9 +++++++
.../qemuxml2argv-disk-virtio-scsi-ioeventfd.xml | 29 ++++++++++++++++++++++
tests/qemuxml2argvtest.c | 3 +++
tests/qemuxml2xmltest.c | 1 +
9 files changed, 79 insertions(+), 2 deletions(-)
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-ioeventfd.args
create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-disk-virtio-scsi-ioeventfd.xml
--
2.5.0
2
3
s is an effort to implement domain rename API. Presented patch series
consists of the following: virDomainRename API implementation for qemu,
implementation of the virsh command domrename and the additional support
code.
The idea behind this endeavor is to provide convenient and safe way to rename
a domain.
Instead of the:
virsh dumpxml domain > domain.xml
(change domain name in domain.xml)
virsh undefine domain
virsh define domain.xml
user can simply type:
virsh domrename foo bar
or call virDomainRename() API and domain "foo" will be renamed to "bar".
We currently support only renaming inactive domains without snapshots.
Renaming procedure takes care of domain log, config, guest agent path and should
be able to recover in case of failure.
I've been working on this functionality in collaboration with Michal Privoznik
who is my mentor during the GSoC 2015. If you have any questions, ideas
or criticism feel free to join the discussion.
v2:
- removed guest agent path rename code
- removed rename permission
- added code for emitting undefined+renamed event for the old domain
Tomas Meszaros (5):
Introduce virDomainRename API
virsh: Implement "domrename" command
domain_conf: Introducde virDomainObjListRenameAddNew() &
virDomainObjListRenameRemove()
Introduce new VIR_DOMAIN_EVENT_DEFINED_RENAMED event
qemu: Implement virDomainRename
examples/object-events/event-test.c | 4 +
include/libvirt/libvirt-domain.h | 4 +
src/access/viraccessperm.c | 3 +-
src/access/viraccessperm.h | 6 ++
src/conf/domain_conf.c | 35 +++++++++
src/conf/domain_conf.h | 5 ++
src/driver-hypervisor.h | 5 ++
src/libvirt-domain.c | 31 ++++++++
src/libvirt_private.syms | 2 +
src/libvirt_public.syms | 5 ++
src/qemu/qemu_driver.c | 144 ++++++++++++++++++++++++++++++++++++
src/remote/remote_driver.c | 1 +
src/remote/remote_protocol.x | 17 ++++-
src/remote_protocol-structs | 8 ++
tools/virsh-domain.c | 63 +++++++++++++++-
tools/virsh.pod | 7 ++
16 files changed, 336 insertions(+), 4 deletions(-)
--
2.1.0
2
7
https://bugzilla.redhat.com/show_bug.cgi?id=1251886
We do not allow delete an iothread which id is 0 in
virDomainDelIOThread, but allow it in virDomainAddIOThread,
Also we will output an error when parse an iothread which id
is 0.
Add a check for iothread_id in virDomainAddIOThread to fix
it.
Signed-off-by: Luyao Huang <lhuang(a)redhat.com>
---
Is that okay to fix it in this place ?
src/libvirt-domain.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c
index 837933f..8506942 100644
--- a/src/libvirt-domain.c
+++ b/src/libvirt-domain.c
@@ -7987,6 +7987,7 @@ virDomainAddIOThread(virDomainPtr domain,
virCheckDomainReturn(domain, -1);
virCheckReadOnlyGoto(domain->conn->flags, error);
+ virCheckNonZeroArgGoto(iothread_id, error);
conn = domain->conn;
--
1.8.3.1
4
4
10 Aug '15
V1 introduced quite a big refactor, so to be able to better keep track
of changes performed from v1 to v2, only this v2 diff patch is presented
and eventually will be squashed to the previous series with a different
commit message.
---
You can still checkout the forked repo
https://github.com/eskultety/libvirt/tree/virt-shell
cfg.mk | 2 +-
tools/virsh-domain-monitor.c | 3 +-
tools/virsh-domain.c | 668 ++++++++++++++++++++++---------------------
tools/virsh-domain.h | 3 +-
tools/virsh-edit.c | 8 +-
tools/virsh-interface.c | 42 +--
tools/virsh-interface.h | 2 +-
tools/virsh-network.c | 76 ++---
tools/virsh-network.h | 2 +-
tools/virsh-nodedev.c | 38 +--
tools/virsh-nwfilter.c | 34 +--
tools/virsh-nwfilter.h | 2 +-
tools/virsh-pool.c | 66 ++---
tools/virsh-pool.h | 2 +-
tools/virsh-secret.c | 28 +-
tools/virsh-snapshot.c | 94 +++---
tools/virsh-volume.c | 52 ++--
tools/virsh-volume.h | 2 +-
tools/virsh.c | 339 +---------------------
tools/virsh.h | 25 +-
tools/vsh.c | 559 ++++++++++++++++++++++++++++++------
tools/vsh.h | 32 ++-
22 files changed, 1062 insertions(+), 1017 deletions(-)
diff --git a/cfg.mk b/cfg.mk
index f26191f..e436434 100644
--- a/cfg.mk
+++ b/cfg.mk
@@ -1086,7 +1086,7 @@ $(srcdir)/src/admin/admin_client.h: $(srcdir)/src/admin/admin_protocol.x
$(MAKE) -C src admin/admin_client.h
# List all syntax-check exemptions:
-exclude_file_name_regexp--sc_avoid_strcase = ^tools/(virsh|vsh)\.h$$
+exclude_file_name_regexp--sc_avoid_strcase = ^tools/vsh\.h$$
_src1=libvirt-stream|fdstream|qemu/qemu_monitor|util/(vircommand|virfile)|xen/xend_internal|rpc/virnetsocket|lxc/lxc_controller|locking/lock_daemon
_test1=shunloadtest|virnettlscontexttest|virnettlssessiontest|vircgroupmock
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index 0762d6e..340a8e2 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -2165,7 +2165,8 @@ cmdDomstats(vshControl *ctl, const vshCmd *cmd)
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
if (!(dom = virshLookupDomainBy(ctl, opt->data,
- VSH_BYID | VSH_BYUUID | VSH_BYNAME)))
+ VIRSH_BYID |
+ VIRSH_BYUUID | VIRSH_BYNAME)))
goto cleanup;
if (VIR_INSERT_ELEMENT(domlist, ndoms - 1, ndoms, dom) < 0)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index df423c7..ff026fb 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -70,11 +70,11 @@ virshLookupDomainInternal(vshControl *ctl,
{
virDomainPtr dom = NULL;
int id;
- virCheckFlags(VSH_BYID | VSH_BYUUID | VSH_BYNAME, NULL);
+ virCheckFlags(VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME, NULL);
virshControlPtr priv = ctl->privData;
/* try it by ID */
- if (flags & VSH_BYID) {
+ if (flags & VIRSH_BYID) {
if (virStrToLong_i(name, NULL, 10, &id) == 0 && id >= 0) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> looks like ID\n",
cmdname);
@@ -83,7 +83,7 @@ virshLookupDomainInternal(vshControl *ctl,
}
/* try it by UUID */
- if (!dom && (flags & VSH_BYUUID) &&
+ if (!dom && (flags & VIRSH_BYUUID) &&
strlen(name) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain UUID\n",
cmdname);
@@ -91,7 +91,7 @@ virshLookupDomainInternal(vshControl *ctl,
}
/* try it by NAME */
- if (!dom && (flags & VSH_BYNAME)) {
+ if (!dom && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <domain> trying as domain NAME\n",
cmdname);
dom = virDomainLookupByName(priv->conn, name);
@@ -106,8 +106,8 @@ virshLookupDomainInternal(vshControl *ctl,
virDomainPtr
virshLookupDomainBy(vshControl *ctl,
- const char *name,
- unsigned int flags)
+ const char *name,
+ unsigned int flags)
{
return virshLookupDomainInternal(ctl, "unknown", name, flags);
}
@@ -265,7 +265,7 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd)
virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
}
@@ -902,8 +902,8 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
{
virDomainPtr dom = NULL;
const char *mac = NULL, *target = NULL, *script = NULL,
- *type = NULL, *source = NULL, *model = NULL,
- *inboundStr = NULL, *outboundStr = NULL;
+ *type = NULL, *source = NULL, *model = NULL,
+ *inboundStr = NULL, *outboundStr = NULL;
virNetDevBandwidthRate inbound, outbound;
virDomainNetType typ;
int ret;
@@ -1780,9 +1780,9 @@ virshPrintJobProgress(const char *label, unsigned long long remaining,
static volatile sig_atomic_t intCaught;
-static void vshCatchInt(int sig ATTRIBUTE_UNUSED,
- siginfo_t *siginfo ATTRIBUTE_UNUSED,
- void *context ATTRIBUTE_UNUSED)
+static void virshCatchInt(int sig ATTRIBUTE_UNUSED,
+ siginfo_t *siginfo ATTRIBUTE_UNUSED,
+ void *context ATTRIBUTE_UNUSED)
{
intCaught = 1;
}
@@ -1918,7 +1918,7 @@ cmdBlockCommit(vshControl *ctl, const vshCmd *cmd)
sigaddset(&sigmask, SIGINT);
intCaught = 0;
- sig_action.sa_sigaction = vshCatchInt;
+ sig_action.sa_sigaction = virshCatchInt;
sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action);
@@ -2183,7 +2183,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
sigaddset(&sigmask, SIGINT);
intCaught = 0;
- sig_action.sa_sigaction = vshCatchInt;
+ sig_action.sa_sigaction = virshCatchInt;
sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action);
@@ -2220,7 +2220,7 @@ cmdBlockCopy(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
if (xml) {
- if (virFileReadAll(xml, VIRSH_MAX_XML_FILE, &xmlstr) < 0) {
+ if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlstr) < 0) {
vshReportError(ctl);
goto cleanup;
}
@@ -2438,8 +2438,8 @@ static const vshCmdOptDef opts_block_job[] = {
{.name = NULL}
};
-VIR_ENUM_DECL(vshDomainBlockJob)
-VIR_ENUM_IMPL(vshDomainBlockJob,
+VIR_ENUM_DECL(virshDomainBlockJob)
+VIR_ENUM_IMPL(virshDomainBlockJob,
VIR_DOMAIN_BLOCK_JOB_TYPE_LAST,
N_("Unknown job"),
N_("Block Pull"),
@@ -2448,9 +2448,9 @@ VIR_ENUM_IMPL(vshDomainBlockJob,
N_("Active Block Commit"))
static const char *
-vshDomainBlockJobToString(int type)
+virshDomainBlockJobToString(int type)
{
- const char *str = vshDomainBlockJobTypeToString(type);
+ const char *str = virshDomainBlockJobTypeToString(type);
return str ? _(str) : _("Unknown job");
}
@@ -2547,14 +2547,14 @@ cmdBlockJob(vshControl *ctl, const vshCmd *cmd)
if (raw) {
vshPrint(ctl, _(" type=%s\n bandwidth=%lu\n cur=%llu\n end=%llu\n"),
- vshDomainBlockJobTypeToString(info.type),
+ virshDomainBlockJobTypeToString(info.type),
info.bandwidth, info.cur, info.end);
} else {
- virshPrintJobProgress(vshDomainBlockJobToString(info.type),
+ virshPrintJobProgress(virshDomainBlockJobToString(info.type),
info.end - info.cur, info.end);
if (speed) {
const char *unit;
- double val = virshPrettyCapacity(speed, &unit);
+ double val = vshPrettyCapacity(speed, &unit);
vshPrint(ctl, _(" Bandwidth limit: %llu bytes/s (%-.3lf %s/s)"),
speed, val, unit);
}
@@ -2654,7 +2654,7 @@ cmdBlockPull(vshControl *ctl, const vshCmd *cmd)
sigaddset(&sigmask, SIGINT);
intCaught = 0;
- sig_action.sa_sigaction = vshCatchInt;
+ sig_action.sa_sigaction = virshCatchInt;
sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action);
@@ -3527,7 +3527,7 @@ typedef struct {
virStorageVolPtr vol;
char *source;
char *target;
-} vshUndefineVolume;
+} virshUndefineVolume;
static bool
cmdUndefine(vshControl *ctl, const vshCmd *cmd)
@@ -3556,7 +3556,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
const char *vol_string = NULL; /* string containing volumes to delete */
char **vol_list = NULL; /* tokenized vol_string */
int nvol_list = 0;
- vshUndefineVolume *vols = NULL; /* info about the volumes to delete*/
+ virshUndefineVolume *vols = NULL; /* info about the volumes to delete*/
size_t nvols = 0;
char *def = NULL; /* domain def */
xmlDocPtr doc = NULL;
@@ -3680,7 +3680,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < nvol_nodes; i++) {
ctxt->node = vol_nodes[i];
- vshUndefineVolume vol;
+ virshUndefineVolume vol;
VIR_FREE(source);
VIR_FREE(target);
VIR_FREE(pool);
@@ -3996,7 +3996,7 @@ cmdStart(vshControl *ctl, const vshCmd *cmd)
int *fds = NULL;
if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
- VSH_BYNAME | VSH_BYUUID)))
+ VIRSH_BYNAME | VIRSH_BYUUID)))
return false;
if (virDomainGetID(dom) != (unsigned int)-1) {
@@ -4149,7 +4149,7 @@ doSave(void *opaque)
goto out;
if (xmlfile &&
- virFileReadAll(xmlfile, VIRSH_MAX_XML_FILE, &xml) < 0) {
+ virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0) {
vshReportError(ctl);
goto out;
}
@@ -4176,14 +4176,14 @@ typedef void (*jobWatchTimeoutFunc)(vshControl *ctl, virDomainPtr dom,
void *opaque);
static bool
-vshWatchJob(vshControl *ctl,
- virDomainPtr dom,
- bool verbose,
- int pipe_fd,
- int timeout_ms,
- jobWatchTimeoutFunc timeout_func,
- void *opaque,
- const char *label)
+virshWatchJob(vshControl *ctl,
+ virDomainPtr dom,
+ bool verbose,
+ int pipe_fd,
+ int timeout_ms,
+ jobWatchTimeoutFunc timeout_func,
+ void *opaque,
+ const char *label)
{
struct sigaction sig_action;
struct sigaction old_sig_action;
@@ -4202,7 +4202,7 @@ vshWatchJob(vshControl *ctl,
sigaddset(&sigmask, SIGINT);
intCaught = 0;
- sig_action.sa_sigaction = vshCatchInt;
+ sig_action.sa_sigaction = virshCatchInt;
sig_action.sa_flags = SA_SIGINFO;
sigemptyset(&sig_action.sa_mask);
sigaction(SIGINT, &sig_action, &old_sig_action);
@@ -4319,7 +4319,7 @@ cmdSave(vshControl *ctl, const vshCmd *cmd)
&data) < 0)
goto cleanup;
- ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Save"));
+ ret = virshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Save"));
virThreadJoin(&workerThread);
@@ -4440,7 +4440,7 @@ cmdSaveImageDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0)
return false;
- if (virFileReadAll(xmlfile, VIRSH_MAX_XML_FILE, &xml) < 0)
+ if (virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
goto cleanup;
if (virDomainSaveImageDefineXML(priv->conn, file, xml, flags) < 0) {
@@ -4644,8 +4644,8 @@ cmdManagedSave(vshControl *ctl, const vshCmd *cmd)
&data) < 0)
goto cleanup;
- ret = vshWatchJob(ctl, dom, verbose, p[0], 0,
- NULL, NULL, _("Managedsave"));
+ ret = virshWatchJob(ctl, dom, verbose, p[0], 0,
+ NULL, NULL, _("Managedsave"));
virThreadJoin(&workerThread);
@@ -5028,7 +5028,7 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd)
return false;
if (xmlfile &&
- virFileReadAll(xmlfile, VIRSH_MAX_XML_FILE, &xml) < 0)
+ virFileReadAll(xmlfile, VSH_MAX_XML_FILE, &xml) < 0)
goto cleanup;
if (((flags || xml)
@@ -5217,7 +5217,7 @@ cmdDump(vshControl *ctl, const vshCmd *cmd)
&data) < 0)
goto cleanup;
- ret = vshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Dump"));
+ ret = virshWatchJob(ctl, dom, verbose, p[0], 0, NULL, NULL, _("Dump"));
virThreadJoin(&workerThread);
@@ -5729,8 +5729,8 @@ static const vshCmdOptDef opts_domjobinfo[] = {
{.name = NULL}
};
-VIR_ENUM_DECL(vshDomainJob)
-VIR_ENUM_IMPL(vshDomainJob,
+VIR_ENUM_DECL(virshDomainJob)
+VIR_ENUM_IMPL(virshDomainJob,
VIR_DOMAIN_JOB_LAST,
N_("None"),
N_("Bounded"),
@@ -5740,9 +5740,9 @@ VIR_ENUM_IMPL(vshDomainJob,
N_("Cancelled"))
static const char *
-vshDomainJobToString(int type)
+virshDomainJobToString(int type)
{
- const char *str = vshDomainJobTypeToString(type);
+ const char *str = virshDomainJobTypeToString(type);
return str ? _(str) : _("unknown");
}
@@ -5818,7 +5818,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
vshPrint(ctl, "%-17s %-12s\n", _("Job type:"),
- vshDomainJobToString(info.type));
+ virshDomainJobToString(info.type));
if (info.type != VIR_DOMAIN_JOB_BOUNDED &&
info.type != VIR_DOMAIN_JOB_UNBOUNDED &&
(!(flags & VIR_DOMAIN_JOB_STATS_COMPLETED) ||
@@ -5842,20 +5842,20 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
info.timeRemaining);
if (info.dataTotal || info.dataRemaining || info.dataProcessed) {
- val = virshPrettyCapacity(info.dataProcessed, &unit);
+ val = vshPrettyCapacity(info.dataProcessed, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data processed:"), val, unit);
- val = virshPrettyCapacity(info.dataRemaining, &unit);
+ val = vshPrettyCapacity(info.dataRemaining, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data remaining:"), val, unit);
- val = virshPrettyCapacity(info.dataTotal, &unit);
+ val = vshPrettyCapacity(info.dataTotal, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Data total:"), val, unit);
}
if (info.memTotal || info.memRemaining || info.memProcessed) {
- val = virshPrettyCapacity(info.memProcessed, &unit);
+ val = vshPrettyCapacity(info.memProcessed, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory processed:"), val, unit);
- val = virshPrettyCapacity(info.memRemaining, &unit);
+ val = vshPrettyCapacity(info.memRemaining, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory remaining:"), val, unit);
- val = virshPrettyCapacity(info.memTotal, &unit);
+ val = vshPrettyCapacity(info.memTotal, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Memory total:"), val, unit);
if ((rc = virTypedParamsGetULLong(params, nparams,
@@ -5863,18 +5863,18 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
&value)) < 0) {
goto save_error;
} else if (rc && value) {
- val = virshPrettyCapacity(value, &unit);
+ val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s/s\n",
_("Memory bandwidth:"), val, unit);
}
}
if (info.fileTotal || info.fileRemaining || info.fileProcessed) {
- val = virshPrettyCapacity(info.fileProcessed, &unit);
+ val = vshPrettyCapacity(info.fileProcessed, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File processed:"), val, unit);
- val = virshPrettyCapacity(info.fileRemaining, &unit);
+ val = vshPrettyCapacity(info.fileRemaining, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File remaining:"), val, unit);
- val = virshPrettyCapacity(info.fileTotal, &unit);
+ val = vshPrettyCapacity(info.fileTotal, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("File total:"), val, unit);
if ((rc = virTypedParamsGetULLong(params, nparams,
@@ -5882,7 +5882,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
&value)) < 0) {
goto save_error;
} else if (rc && value) {
- val = virshPrettyCapacity(value, &unit);
+ val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s/s\n",
_("File bandwidth:"), val, unit);
}
@@ -5907,7 +5907,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
&value)) < 0) {
goto save_error;
} else if (rc) {
- val = virshPrettyCapacity(value, &unit);
+ val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Normal data:"), val, unit);
}
@@ -5944,7 +5944,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
&value)) < 0) {
goto save_error;
} else if (rc) {
- val = virshPrettyCapacity(value, &unit);
+ val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compression cache:"), val, unit);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
@@ -5952,7 +5952,7 @@ cmdDomjobinfo(vshControl *ctl, const vshCmd *cmd)
&value)) < 0) {
goto save_error;
} else if (rc) {
- val = virshPrettyCapacity(value, &unit);
+ val = vshPrettyCapacity(value, &unit);
vshPrint(ctl, "%-17s %-.3lf %s\n", _("Compressed data:"), val, unit);
}
if ((rc = virTypedParamsGetULLong(params, nparams,
@@ -6083,10 +6083,10 @@ static const vshCmdOptDef opts_vcpucount[] = {
*/
static int
-vshCPUCountCollect(vshControl *ctl,
- virDomainPtr dom,
- unsigned int flags,
- bool checkState)
+virshCPUCountCollect(vshControl *ctl,
+ virDomainPtr dom,
+ unsigned int flags,
+ bool checkState)
{
int ret = -2;
virDomainInfo info;
@@ -6204,12 +6204,16 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
return false;
if (all) {
- int conf_max = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_CONFIG |
- VIR_DOMAIN_VCPU_MAXIMUM, true);
- int conf_cur = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_CONFIG, true);
- int live_max = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_LIVE |
- VIR_DOMAIN_VCPU_MAXIMUM, true);
- int live_cur = vshCPUCountCollect(ctl, dom, VIR_DOMAIN_AFFECT_LIVE, true);
+ int conf_max = virshCPUCountCollect(ctl, dom,
+ VIR_DOMAIN_AFFECT_CONFIG |
+ VIR_DOMAIN_VCPU_MAXIMUM, true);
+ int conf_cur = virshCPUCountCollect(ctl, dom,
+ VIR_DOMAIN_AFFECT_CONFIG, true);
+ int live_max = virshCPUCountCollect(ctl, dom,
+ VIR_DOMAIN_AFFECT_LIVE |
+ VIR_DOMAIN_VCPU_MAXIMUM, true);
+ int live_cur = virshCPUCountCollect(ctl, dom,
+ VIR_DOMAIN_AFFECT_LIVE, true);
if (conf_max == -2 || conf_cur == -2 || live_max == -2 || live_cur == -2)
goto cleanup;
@@ -6223,7 +6227,7 @@ cmdVcpucount(vshControl *ctl, const vshCmd *cmd)
#undef PRINT_COUNT
} else {
- int count = vshCPUCountCollect(ctl, dom, flags, false);
+ int count = virshCPUCountCollect(ctl, dom, flags, false);
if (count < 0)
goto cleanup;
@@ -6400,7 +6404,7 @@ static const vshCmdOptDef opts_vcpupin[] = {
* Helper function to print vcpupin info.
*/
static bool
-vshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen)
+virshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen)
{
char *str = NULL;
@@ -6413,7 +6417,8 @@ vshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen)
}
static unsigned char *
-vshParseCPUList(vshControl *ctl, int *cpumaplen, const char *cpulist, int maxcpu)
+virshParseCPUList(vshControl *ctl, int *cpumaplen,
+ const char *cpulist, int maxcpu)
{
unsigned char *cpumap = NULL;
virBitmapPtr map = NULL;
@@ -6501,7 +6506,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
if (flags == -1)
flags = VIR_DOMAIN_AFFECT_CURRENT;
- if ((ncpus = vshCPUCountCollect(ctl, dom, flags, true)) < 0) {
+ if ((ncpus = virshCPUCountCollect(ctl, dom, flags, true)) < 0) {
if (ncpus == -1) {
if (flags & VIR_DOMAIN_AFFECT_LIVE)
vshError(ctl, "%s", _("cannot get vcpupin for offline domain"));
@@ -6536,8 +6541,8 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
continue;
vshPrint(ctl, "%4zu: ", i);
- ret = vshPrintPinInfo(VIR_GET_CPUMAP(cpumap, cpumaplen, i),
- cpumaplen);
+ ret = virshPrintPinInfo(VIR_GET_CPUMAP(cpumap, cpumaplen, i),
+ cpumaplen);
vshPrint(ctl, "\n");
if (!ret)
break;
@@ -6545,7 +6550,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
}
} else {
/* Pin mode: pinning specified vcpu to specified physical cpus*/
- if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
+ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
goto cleanup;
if (flags == -1) {
@@ -6658,14 +6663,14 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
vshPrintExtra(ctl, "%s %s\n", _("emulator:"), _("CPU Affinity"));
vshPrintExtra(ctl, "----------------------------------\n");
vshPrintExtra(ctl, " *: ");
- ret = vshPrintPinInfo(cpumap, cpumaplen);
+ ret = virshPrintPinInfo(cpumap, cpumaplen);
vshPrint(ctl, "\n");
}
goto cleanup;
}
/* Pin mode: pinning emulator threads to specified physical cpus*/
- if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
+ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
goto cleanup;
if (flags == -1)
@@ -6855,7 +6860,7 @@ cmdIOThreadInfo(vshControl *ctl, const vshCmd *cmd)
for (i = 0; i < niothreads; i++) {
vshPrint(ctl, " %-15u ", info[i]->iothread_id);
- ignore_value(vshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen));
+ ignore_value(virshPrintPinInfo(info[i]->cpumap, info[i]->cpumaplen));
vshPrint(ctl, "\n");
virDomainIOThreadInfoFree(info[i]);
}
@@ -6948,7 +6953,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
if ((maxcpu = virshNodeGetCPUCount(priv->conn)) < 0)
goto cleanup;
- if (!(cpumap = vshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
+ if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
goto cleanup;
if (virDomainPinIOThread(dom, iothread_id,
@@ -7165,7 +7170,7 @@ cmdCPUCompare(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
/* try to extract the CPU element from as it would appear in a domain XML*/
@@ -7277,7 +7282,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
/* add a separate container around the xml */
@@ -7589,7 +7594,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
@@ -7669,7 +7674,7 @@ cmdDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "validate"))
flags |= VIR_DOMAIN_DEFINE_VALIDATE;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
if (flags)
@@ -7857,15 +7862,15 @@ cmdDesc(vshControl *ctl, const vshCmd *cmd)
if (edit) {
/* Create and open the temporary file. */
- if (!(tmp = virshEditWriteToTempFile(ctl, desc)))
+ if (!(tmp = vshEditWriteToTempFile(ctl, desc)))
goto cleanup;
/* Start the editor. */
- if (virshEditFile(ctl, tmp) == -1)
+ if (vshEditFile(ctl, tmp) == -1)
goto cleanup;
/* Read back the edited file. */
- if (!(desc_edited = virshEditReadBackFile(ctl, tmp)))
+ if (!(desc_edited = vshEditReadBackFile(ctl, tmp)))
goto cleanup;
/* strip a possible newline at the end of file; some
@@ -7983,10 +7988,10 @@ static const vshCmdOptDef opts_metadata[] = {
/* helper to add new metadata using the --edit option */
static char *
-vshDomainGetEditMetadata(vshControl *ctl,
- virDomainPtr dom,
- const char *uri,
- unsigned int flags)
+virshDomainGetEditMetadata(vshControl *ctl,
+ virDomainPtr dom,
+ const char *uri,
+ unsigned int flags)
{
char *ret;
@@ -8051,7 +8056,7 @@ cmdMetadata(vshControl *ctl, const vshCmd *cmd)
vshPrint("%s\n", _("Metadata modified"));
} else if (edit) {
#define EDIT_GET_XML \
- vshDomainGetEditMetadata(ctl, dom, uri, flags)
+ virshDomainGetEditMetadata(ctl, dom, uri, flags)
#define EDIT_NOT_CHANGED \
do { \
vshPrint(ctl, "%s", _("Metadata not changed")); \
@@ -8160,7 +8165,7 @@ static const vshCmdOptDef opts_send_key[] = {
};
static int
-vshKeyCodeGetInt(const char *key_name)
+virshKeyCodeGetInt(const char *key_name)
{
unsigned int val;
@@ -8203,7 +8208,7 @@ cmdSendKey(vshControl *ctl, const vshCmd *cmd)
goto cleanup;
}
- if ((keycode = vshKeyCodeGetInt(opt->data)) < 0) {
+ if ((keycode = virshKeyCodeGetInt(opt->data)) < 0) {
if ((keycode = virKeycodeValueFromString(codeset, opt->data)) < 0) {
vshError(ctl, _("invalid keycode: '%s'"), opt->data);
goto cleanup;
@@ -8577,7 +8582,7 @@ static const vshCmdOptDef opts_memtune[] = {
};
/**
- * vshMemtuneGetSize
+ * virshMemtuneGetSize
*
* @cmd: pointer to vshCmd
* @name: name of a parameter for which we would like to get a value
@@ -8593,7 +8598,8 @@ static const vshCmdOptDef opts_memtune[] = {
* <0 in all other cases
*/
static int
-vshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd, const char *name, long long *value)
+virshMemtuneGetSize(vshControl *ctl, const vshCmd *cmd,
+ const char *name, long long *value)
{
int ret;
unsigned long long tmp;
@@ -8644,7 +8650,7 @@ cmdMemtune(vshControl *ctl, const vshCmd *cmd)
return false;
#define PARSE_MEMTUNE_PARAM(NAME, FIELD) \
- if ((rc = vshMemtuneGetSize(ctl, cmd, NAME, &tmpVal)) < 0) { \
+ if ((rc = virshMemtuneGetSize(ctl, cmd, NAME, &tmpVal)) < 0) { \
vshError(ctl, _("Unable to parse integer parameter %s"), NAME); \
goto cleanup; \
} \
@@ -8975,9 +8981,9 @@ struct virshQemuEventData {
typedef struct virshQemuEventData virshQemuEventData;
static void
-vshEventPrint(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom,
- const char *event, long long seconds, unsigned int micros,
- const char *details, void *opaque)
+virshEventPrint(virConnectPtr conn ATTRIBUTE_UNUSED, virDomainPtr dom,
+ const char *event, long long seconds, unsigned int micros,
+ const char *details, void *opaque)
{
virshQemuEventData *data = opaque;
virJSONValuePtr pretty = NULL;
@@ -9074,7 +9080,7 @@ cmdQemuMonitorEvent(vshControl *ctl, const vshCmd *cmd)
if ((eventId = virConnectDomainQemuMonitorEventRegister(priv->conn, dom,
event,
- vshEventPrint,
+ virshEventPrint,
&data, NULL,
flags)) < 0)
goto cleanup;
@@ -9539,7 +9545,7 @@ cmdDomXMLFromNative(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "config", &configFile) < 0)
return false;
- if (virFileReadAll(configFile, VIRSH_MAX_XML_FILE, &configData) < 0)
+ if (virFileReadAll(configFile, VSH_MAX_XML_FILE, &configData) < 0)
return false;
xmlData = virConnectDomainXMLFromNative(priv->conn, format, configData, flags);
@@ -9596,7 +9602,7 @@ cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0)
return false;
- if (virFileReadAll(xmlFile, VIRSH_MAX_XML_FILE, &xmlData) < 0)
+ if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
return false;
configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags);
@@ -9639,7 +9645,7 @@ cmdDomname(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom;
if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
- VSH_BYID|VSH_BYUUID)))
+ VIRSH_BYID|VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virDomainGetName(dom));
@@ -9676,7 +9682,7 @@ cmdDomid(vshControl *ctl, const vshCmd *cmd)
unsigned int id;
if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
- VSH_BYNAME|VSH_BYUUID)))
+ VIRSH_BYNAME|VIRSH_BYUUID)))
return false;
id = virDomainGetID(dom);
@@ -9717,7 +9723,7 @@ cmdDomuuid(vshControl *ctl, const vshCmd *cmd)
char uuid[VIR_UUID_STRING_BUFLEN];
if (!(dom = virshCommandOptDomainBy(ctl, cmd, NULL,
- VSH_BYNAME|VSH_BYID)))
+ VIRSH_BYNAME|VIRSH_BYID)))
return false;
if (virDomainGetUUIDString(dom, uuid) != -1)
@@ -9936,7 +9942,7 @@ doMigrate(void *opaque)
if (opt) {
char *xml;
- if (virFileReadAll(opt, VIRSH_MAX_XML_FILE, &xml) < 0) {
+ if (virFileReadAll(opt, VSH_MAX_XML_FILE, &xml) < 0) {
vshError(ctl, _("cannot read file '%s'"), opt);
goto save_error;
}
@@ -10019,9 +10025,9 @@ doMigrate(void *opaque)
}
static void
-vshMigrationTimeout(vshControl *ctl,
- virDomainPtr dom,
- void *opaque ATTRIBUTE_UNUSED)
+virshMigrationTimeout(vshControl *ctl,
+ virDomainPtr dom,
+ void *opaque ATTRIBUTE_UNUSED)
{
vshDebug(ctl, VSH_ERR_DEBUG, "suspending the domain, "
"since migration timed out\n");
@@ -10085,8 +10091,8 @@ cmdMigrate(vshControl *ctl, const vshCmd *cmd)
doMigrate,
&data) < 0)
goto cleanup;
- functionReturn = vshWatchJob(ctl, dom, verbose, p[0], timeout,
- vshMigrationTimeout, NULL, _("Migration"));
+ functionReturn = virshWatchJob(ctl, dom, verbose, p[0], timeout,
+ virshMigrationTimeout, NULL, _("Migration"));
virThreadJoin(&workerThread);
@@ -10205,7 +10211,7 @@ cmdMigrateCompCache(vshControl *ctl, const vshCmd *cmd)
if (virDomainMigrateGetCompressionCache(dom, &size, 0) < 0)
goto cleanup;
- value = virshPrettyCapacity(size, &unit);
+ value = vshPrettyCapacity(size, &unit);
vshPrint(ctl, _("Compression cache: %.3lf %s"), value, unit);
ret = true;
@@ -10734,7 +10740,7 @@ cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
*/
ATTRIBUTE_UNUSED
static bool
-vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
+virshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
{
xmlNodePtr child1, child2;
xmlAttrPtr attr;
@@ -10817,7 +10823,7 @@ vshNodeIsSuperset(xmlNodePtr n1, xmlNodePtr n2)
goto cleanup;
}
- if (!vshNodeIsSuperset(child1, child2))
+ if (!virshNodeIsSuperset(child1, child2))
goto cleanup;
break;
@@ -10918,7 +10924,7 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
}
@@ -11022,7 +11028,7 @@ cmdUpdateDevice(vshControl *ctl, const vshCmd *cmd)
virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
}
@@ -11228,7 +11234,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
typedef enum {
VIRSH_FIND_DISK_NORMAL,
VIRSH_FIND_DISK_CHANGEABLE,
-} vshFindDiskType;
+} virshFindDiskType;
/* Helper function to find disk device in XML doc. Returns the disk
* node on success, or NULL on failure. Caller must free the result
@@ -11236,9 +11242,9 @@ typedef enum {
* @type: Either VIRSH_FIND_DISK_NORMAL or VIRSH_FIND_DISK_CHANGEABLE.
*/
static xmlNodePtr
-vshFindDisk(const char *doc,
- const char *path,
- int type)
+virshFindDisk(const char *doc,
+ const char *path,
+ int type)
{
xmlDocPtr xml = NULL;
xmlXPathObjectPtr obj = NULL;
@@ -11324,7 +11330,7 @@ typedef enum {
VIRSH_UPDATE_DISK_XML_EJECT,
VIRSH_UPDATE_DISK_XML_INSERT,
VIRSH_UPDATE_DISK_XML_UPDATE,
-} vshUpdateDiskXMLType;
+} virshUpdateDiskXMLType;
/* Helper function to prepare disk XML. Could be used for disk
* detaching, media changing(ejecting, inserting, updating)
@@ -11332,11 +11338,11 @@ typedef enum {
* success, or NULL on failure. Caller must free the result.
*/
static char *
-vshUpdateDiskXML(xmlNodePtr disk_node,
- const char *new_source,
- bool source_block,
- const char *target,
- vshUpdateDiskXMLType type)
+virshUpdateDiskXML(xmlNodePtr disk_node,
+ const char *new_source,
+ bool source_block,
+ const char *target,
+ virshUpdateDiskXMLType type)
{
xmlNodePtr source = NULL;
char *device_type = NULL;
@@ -11505,7 +11511,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE;
- if (!(disk_node = vshFindDisk(doc, target, VIRSH_FIND_DISK_NORMAL)))
+ if (!(disk_node = virshFindDisk(doc, target, VIRSH_FIND_DISK_NORMAL)))
goto cleanup;
if (!(disk_xml = virXMLNodeToString(NULL, disk_node))) {
@@ -11613,8 +11619,8 @@ cmdEdit(vshControl *ctl, const vshCmd *cmd)
/*
* "event" command
*/
-VIR_ENUM_DECL(vshDomainEvent)
-VIR_ENUM_IMPL(vshDomainEvent,
+VIR_ENUM_DECL(virshDomainEvent)
+VIR_ENUM_IMPL(virshDomainEvent,
VIR_DOMAIN_EVENT_LAST,
N_("Defined"),
N_("Undefined"),
@@ -11627,25 +11633,25 @@ VIR_ENUM_IMPL(vshDomainEvent,
N_("Crashed"))
static const char *
-vshDomainEventToString(int event)
+virshDomainEventToString(int event)
{
- const char *str = vshDomainEventTypeToString(event);
+ const char *str = virshDomainEventTypeToString(event);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainEventDefined)
-VIR_ENUM_IMPL(vshDomainEventDefined,
+VIR_ENUM_DECL(virshDomainEventDefined)
+VIR_ENUM_IMPL(virshDomainEventDefined,
VIR_DOMAIN_EVENT_DEFINED_LAST,
N_("Added"),
N_("Updated"))
-VIR_ENUM_DECL(vshDomainEventUndefined)
-VIR_ENUM_IMPL(vshDomainEventUndefined,
+VIR_ENUM_DECL(virshDomainEventUndefined)
+VIR_ENUM_IMPL(virshDomainEventUndefined,
VIR_DOMAIN_EVENT_UNDEFINED_LAST,
N_("Removed"))
-VIR_ENUM_DECL(vshDomainEventStarted)
-VIR_ENUM_IMPL(vshDomainEventStarted,
+VIR_ENUM_DECL(virshDomainEventStarted)
+VIR_ENUM_IMPL(virshDomainEventStarted,
VIR_DOMAIN_EVENT_STARTED_LAST,
N_("Booted"),
N_("Migrated"),
@@ -11653,8 +11659,8 @@ VIR_ENUM_IMPL(vshDomainEventStarted,
N_("Snapshot"),
N_("Event wakeup"))
-VIR_ENUM_DECL(vshDomainEventSuspended)
-VIR_ENUM_IMPL(vshDomainEventSuspended,
+VIR_ENUM_DECL(virshDomainEventSuspended)
+VIR_ENUM_IMPL(virshDomainEventSuspended,
VIR_DOMAIN_EVENT_SUSPENDED_LAST,
N_("Paused"),
N_("Migrated"),
@@ -11664,15 +11670,15 @@ VIR_ENUM_IMPL(vshDomainEventSuspended,
N_("Snapshot"),
N_("API error"))
-VIR_ENUM_DECL(vshDomainEventResumed)
-VIR_ENUM_IMPL(vshDomainEventResumed,
+VIR_ENUM_DECL(virshDomainEventResumed)
+VIR_ENUM_IMPL(virshDomainEventResumed,
VIR_DOMAIN_EVENT_RESUMED_LAST,
N_("Unpaused"),
N_("Migrated"),
N_("Snapshot"))
-VIR_ENUM_DECL(vshDomainEventStopped)
-VIR_ENUM_IMPL(vshDomainEventStopped,
+VIR_ENUM_DECL(virshDomainEventStopped)
+VIR_ENUM_IMPL(virshDomainEventStopped,
VIR_DOMAIN_EVENT_STOPPED_LAST,
N_("Shutdown"),
N_("Destroyed"),
@@ -11682,53 +11688,53 @@ VIR_ENUM_IMPL(vshDomainEventStopped,
N_("Failed"),
N_("Snapshot"))
-VIR_ENUM_DECL(vshDomainEventShutdown)
-VIR_ENUM_IMPL(vshDomainEventShutdown,
+VIR_ENUM_DECL(virshDomainEventShutdown)
+VIR_ENUM_IMPL(virshDomainEventShutdown,
VIR_DOMAIN_EVENT_SHUTDOWN_LAST,
N_("Finished"))
-VIR_ENUM_DECL(vshDomainEventPMSuspended)
-VIR_ENUM_IMPL(vshDomainEventPMSuspended,
+VIR_ENUM_DECL(virshDomainEventPMSuspended)
+VIR_ENUM_IMPL(virshDomainEventPMSuspended,
VIR_DOMAIN_EVENT_PMSUSPENDED_LAST,
N_("Memory"),
N_("Disk"))
-VIR_ENUM_DECL(vshDomainEventCrashed)
-VIR_ENUM_IMPL(vshDomainEventCrashed,
+VIR_ENUM_DECL(virshDomainEventCrashed)
+VIR_ENUM_IMPL(virshDomainEventCrashed,
VIR_DOMAIN_EVENT_CRASHED_LAST,
N_("Panicked"))
static const char *
-vshDomainEventDetailToString(int event, int detail)
+virshDomainEventDetailToString(int event, int detail)
{
const char *str = NULL;
switch ((virDomainEventType) event) {
case VIR_DOMAIN_EVENT_DEFINED:
- str = vshDomainEventDefinedTypeToString(detail);
+ str = virshDomainEventDefinedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_UNDEFINED:
- str = vshDomainEventUndefinedTypeToString(detail);
+ str = virshDomainEventUndefinedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_STARTED:
- str = vshDomainEventStartedTypeToString(detail);
+ str = virshDomainEventStartedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_SUSPENDED:
- str = vshDomainEventSuspendedTypeToString(detail);
+ str = virshDomainEventSuspendedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_RESUMED:
- str = vshDomainEventResumedTypeToString(detail);
+ str = virshDomainEventResumedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_STOPPED:
- str = vshDomainEventStoppedTypeToString(detail);
+ str = virshDomainEventStoppedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_SHUTDOWN:
- str = vshDomainEventShutdownTypeToString(detail);
+ str = virshDomainEventShutdownTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_PMSUSPENDED:
- str = vshDomainEventPMSuspendedTypeToString(detail);
+ str = virshDomainEventPMSuspendedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_CRASHED:
- str = vshDomainEventCrashedTypeToString(detail);
+ str = virshDomainEventCrashedTypeToString(detail);
break;
case VIR_DOMAIN_EVENT_LAST:
break;
@@ -11736,8 +11742,8 @@ vshDomainEventDetailToString(int event, int detail)
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainEventWatchdog)
-VIR_ENUM_IMPL(vshDomainEventWatchdog,
+VIR_ENUM_DECL(virshDomainEventWatchdog)
+VIR_ENUM_IMPL(virshDomainEventWatchdog,
VIR_DOMAIN_EVENT_WATCHDOG_LAST,
N_("none"),
N_("pause"),
@@ -11748,56 +11754,56 @@ VIR_ENUM_IMPL(vshDomainEventWatchdog,
N_("inject-nmi"))
static const char *
-vshDomainEventWatchdogToString(int action)
+virshDomainEventWatchdogToString(int action)
{
- const char *str = vshDomainEventWatchdogTypeToString(action);
+ const char *str = virshDomainEventWatchdogTypeToString(action);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainEventIOError)
-VIR_ENUM_IMPL(vshDomainEventIOError,
+VIR_ENUM_DECL(virshDomainEventIOError)
+VIR_ENUM_IMPL(virshDomainEventIOError,
VIR_DOMAIN_EVENT_IO_ERROR_LAST,
N_("none"),
N_("pause"),
N_("report"))
static const char *
-vshDomainEventIOErrorToString(int action)
+virshDomainEventIOErrorToString(int action)
{
- const char *str = vshDomainEventIOErrorTypeToString(action);
+ const char *str = virshDomainEventIOErrorTypeToString(action);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshGraphicsPhase)
-VIR_ENUM_IMPL(vshGraphicsPhase,
+VIR_ENUM_DECL(virshGraphicsPhase)
+VIR_ENUM_IMPL(virshGraphicsPhase,
VIR_DOMAIN_EVENT_GRAPHICS_LAST,
N_("connect"),
N_("initialize"),
N_("disconnect"))
static const char *
-vshGraphicsPhaseToString(int phase)
+virshGraphicsPhaseToString(int phase)
{
- const char *str = vshGraphicsPhaseTypeToString(phase);
+ const char *str = virshGraphicsPhaseTypeToString(phase);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshGraphicsAddress)
-VIR_ENUM_IMPL(vshGraphicsAddress,
+VIR_ENUM_DECL(virshGraphicsAddress)
+VIR_ENUM_IMPL(virshGraphicsAddress,
VIR_DOMAIN_EVENT_GRAPHICS_ADDRESS_LAST,
N_("IPv4"),
N_("IPv6"),
N_("unix"))
static const char *
-vshGraphicsAddressToString(int family)
+virshGraphicsAddressToString(int family)
{
- const char *str = vshGraphicsAddressTypeToString(family);
+ const char *str = virshGraphicsAddressTypeToString(family);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainBlockJobStatus)
-VIR_ENUM_IMPL(vshDomainBlockJobStatus,
+VIR_ENUM_DECL(virshDomainBlockJobStatus)
+VIR_ENUM_IMPL(virshDomainBlockJobStatus,
VIR_DOMAIN_BLOCK_JOB_LAST,
N_("completed"),
N_("failed"),
@@ -11805,35 +11811,35 @@ VIR_ENUM_IMPL(vshDomainBlockJobStatus,
N_("ready"))
static const char *
-vshDomainBlockJobStatusToString(int status)
+virshDomainBlockJobStatusToString(int status)
{
- const char *str = vshDomainBlockJobStatusTypeToString(status);
+ const char *str = virshDomainBlockJobStatusTypeToString(status);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainEventDiskChange)
-VIR_ENUM_IMPL(vshDomainEventDiskChange,
+VIR_ENUM_DECL(virshDomainEventDiskChange)
+VIR_ENUM_IMPL(virshDomainEventDiskChange,
VIR_DOMAIN_EVENT_DISK_CHANGE_LAST,
N_("changed"),
N_("dropped"))
static const char *
-vshDomainEventDiskChangeToString(int reason)
+virshDomainEventDiskChangeToString(int reason)
{
- const char *str = vshDomainEventDiskChangeTypeToString(reason);
+ const char *str = virshDomainEventDiskChangeTypeToString(reason);
return str ? _(str) : _("unknown");
}
-VIR_ENUM_DECL(vshDomainEventTrayChange)
-VIR_ENUM_IMPL(vshDomainEventTrayChange,
+VIR_ENUM_DECL(virshDomainEventTrayChange)
+VIR_ENUM_IMPL(virshDomainEventTrayChange,
VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST,
N_("opened"),
N_("closed"))
static const char *
-vshDomainEventTrayChangeToString(int reason)
+virshDomainEventTrayChangeToString(int reason)
{
- const char *str = vshDomainEventTrayChangeTypeToString(reason);
+ const char *str = virshDomainEventTrayChangeTypeToString(reason);
return str ? _(str) : _("unknown");
}
@@ -11843,21 +11849,21 @@ struct vshEventCallback {
};
typedef struct vshEventCallback vshEventCallback;
-struct vshDomEventData {
+struct virshDomEventData {
vshControl *ctl;
bool loop;
int *count;
vshEventCallback *cb;
int id;
};
-typedef struct vshDomEventData vshDomEventData;
+typedef struct virshDomEventData virshDomEventData;
static void
-vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- void *opaque)
+virshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
@@ -11869,31 +11875,31 @@ vshEventGenericPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int event,
- int detail,
- void *opaque)
+virshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int event,
+ int detail,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event 'lifecycle' for domain %s: %s %s\n"),
- virDomainGetName(dom), vshDomainEventToString(event),
- vshDomainEventDetailToString(event, detail));
+ virDomainGetName(dom), virshDomainEventToString(event),
+ virshDomainEventDetailToString(event, detail));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventRTCChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- long long utcoffset,
- void *opaque)
+virshEventRTCChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ long long utcoffset,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
@@ -11905,63 +11911,63 @@ vshEventRTCChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventWatchdogPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int action,
- void *opaque)
+virshEventWatchdogPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int action,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event 'watchdog' for domain %s: %s\n"),
- virDomainGetName(dom), vshDomainEventWatchdogToString(action));
+ virDomainGetName(dom), virshDomainEventWatchdogToString(action));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventIOErrorPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *srcPath,
- const char *devAlias,
- int action,
- void *opaque)
+virshEventIOErrorPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *srcPath,
+ const char *devAlias,
+ int action,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event 'io-error' for domain %s: %s (%s) %s\n"),
virDomainGetName(dom), srcPath, devAlias,
- vshDomainEventIOErrorToString(action));
+ virshDomainEventIOErrorToString(action));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventGraphicsPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int phase,
- const virDomainEventGraphicsAddress *local,
- const virDomainEventGraphicsAddress *remote,
- const char *authScheme,
- const virDomainEventGraphicsSubject *subject,
- void *opaque)
-{
- vshDomEventData *data = opaque;
+virshEventGraphicsPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int phase,
+ const virDomainEventGraphicsAddress *local,
+ const virDomainEventGraphicsAddress *remote,
+ const char *authScheme,
+ const virDomainEventGraphicsSubject *subject,
+ void *opaque)
+{
+ virshDomEventData *data = opaque;
size_t i;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event 'graphics' for domain %s: "
"%s local[%s %s %s] remote[%s %s %s] %s"),
- virDomainGetName(dom), vshGraphicsPhaseToString(phase),
- vshGraphicsAddressToString(local->family),
+ virDomainGetName(dom), virshGraphicsPhaseToString(phase),
+ virshGraphicsAddressToString(local->family),
local->node, local->service,
- vshGraphicsAddressToString(remote->family),
+ virshGraphicsAddressToString(remote->family),
remote->node, remote->service,
authScheme);
for (i = 0; i < subject->nidentity; i++)
@@ -11974,108 +11980,108 @@ vshEventGraphicsPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventIOErrorReasonPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *srcPath,
- const char *devAlias,
- int action,
- const char *reason,
- void *opaque)
+virshEventIOErrorReasonPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *srcPath,
+ const char *devAlias,
+ int action,
+ const char *reason,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event 'io-error-reason' for domain %s: "
"%s (%s) %s due to %s\n"),
virDomainGetName(dom), srcPath, devAlias,
- vshDomainEventIOErrorToString(action), reason);
+ virshDomainEventIOErrorToString(action), reason);
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventBlockJobPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *disk,
- int type,
- int status,
- void *opaque)
+virshEventBlockJobPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *disk,
+ int type,
+ int status,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl, _("event '%s' for domain %s: %s for %s %s\n"),
data->cb->name, virDomainGetName(dom),
- vshDomainBlockJobToString(type),
- disk, vshDomainBlockJobStatusToString(status));
+ virshDomainBlockJobToString(type),
+ disk, virshDomainBlockJobStatusToString(status));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventDiskChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *oldSrc,
- const char *newSrc,
- const char *alias,
- int reason,
- void *opaque)
+virshEventDiskChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *oldSrc,
+ const char *newSrc,
+ const char *alias,
+ int reason,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl,
_("event 'disk-change' for domain %s disk %s: %s -> %s: %s\n"),
virDomainGetName(dom), alias, NULLSTR(oldSrc), NULLSTR(newSrc),
- vshDomainEventDiskChangeToString(reason));
+ virshDomainEventDiskChangeToString(reason));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventTrayChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *alias,
- int reason,
- void *opaque)
+virshEventTrayChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *alias,
+ int reason,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl,
_("event 'tray-change' for domain %s disk %s: %s\n"),
virDomainGetName(dom), alias,
- vshDomainEventTrayChangeToString(reason));
+ virshDomainEventTrayChangeToString(reason));
(*data->count)++;
if (!data->loop)
vshEventDone(data->ctl);
}
static void
-vshEventPMChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int reason ATTRIBUTE_UNUSED,
- void *opaque)
+virshEventPMChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int reason ATTRIBUTE_UNUSED,
+ void *opaque)
{
/* As long as libvirt.h doesn't define any reasons, we might as
* well treat all PM state changes as generic events. */
- vshEventGenericPrint(conn, dom, opaque);
+ virshEventGenericPrint(conn, dom, opaque);
}
static void
-vshEventBalloonChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- unsigned long long actual,
- void *opaque)
+virshEventBalloonChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ unsigned long long actual,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
@@ -12088,12 +12094,12 @@ vshEventBalloonChangePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventDeviceRemovedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- const char *alias,
- void *opaque)
+virshEventDeviceRemovedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ const char *alias,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
@@ -12106,12 +12112,12 @@ vshEventDeviceRemovedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventDeviceAddedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+virshEventDeviceAddedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainPtr dom,
const char *alias,
void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
@@ -12124,13 +12130,13 @@ vshEventDeviceAddedPrint(virConnectPtr conn ATTRIBUTE_UNUSED,
}
static void
-vshEventTunablePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- virTypedParameterPtr params,
- int nparams,
- void *opaque)
+virshEventTunablePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ virTypedParameterPtr params,
+ int nparams,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
size_t i;
char *value = NULL;
@@ -12154,15 +12160,15 @@ vshEventTunablePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
vshEventDone(data->ctl);
}
-VIR_ENUM_DECL(vshEventAgentLifecycleState)
-VIR_ENUM_IMPL(vshEventAgentLifecycleState,
+VIR_ENUM_DECL(virshEventAgentLifecycleState)
+VIR_ENUM_IMPL(virshEventAgentLifecycleState,
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_STATE_LAST,
N_("unknown"),
N_("connected"),
N_("disconnected"))
-VIR_ENUM_DECL(vshEventAgentLifecycleReason)
-VIR_ENUM_IMPL(vshEventAgentLifecycleReason,
+VIR_ENUM_DECL(virshEventAgentLifecycleReason)
+VIR_ENUM_IMPL(virshEventAgentLifecycleReason,
VIR_CONNECT_DOMAIN_EVENT_AGENT_LIFECYCLE_REASON_LAST,
N_("unknown"),
N_("domain started"),
@@ -12170,21 +12176,21 @@ VIR_ENUM_IMPL(vshEventAgentLifecycleReason,
#define UNKNOWNSTR(str) (str ? str : N_("unsupported value"))
static void
-vshEventAgentLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int state,
- int reason,
- void *opaque)
+virshEventAgentLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int state,
+ int reason,
+ void *opaque)
{
- vshDomEventData *data = opaque;
+ virshDomEventData *data = opaque;
if (!data->loop && *data->count)
return;
vshPrint(data->ctl,
_("event 'agent-lifecycle' for domain %s: state: '%s' reason: '%s'\n"),
virDomainGetName(dom),
- UNKNOWNSTR(vshEventAgentLifecycleStateTypeToString(state)),
- UNKNOWNSTR(vshEventAgentLifecycleReasonTypeToString(reason)));
+ UNKNOWNSTR(virshEventAgentLifecycleStateTypeToString(state)),
+ UNKNOWNSTR(virshEventAgentLifecycleReasonTypeToString(reason)));
(*data->count)++;
if (!data->loop)
@@ -12193,43 +12199,43 @@ vshEventAgentLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
static vshEventCallback vshEventCallbacks[] = {
{ "lifecycle",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventLifecyclePrint), },
- { "reboot", vshEventGenericPrint, },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventLifecyclePrint), },
+ { "reboot", virshEventGenericPrint, },
{ "rtc-change",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventRTCChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventRTCChangePrint), },
{ "watchdog",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventWatchdogPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventWatchdogPrint), },
{ "io-error",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventIOErrorPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorPrint), },
{ "graphics",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventGraphicsPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventGraphicsPrint), },
{ "io-error-reason",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventIOErrorReasonPrint), },
- { "control-error", vshEventGenericPrint, },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventIOErrorReasonPrint), },
+ { "control-error", virshEventGenericPrint, },
{ "block-job",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventBlockJobPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), },
{ "disk-change",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventDiskChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventDiskChangePrint), },
{ "tray-change",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventTrayChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventTrayChangePrint), },
{ "pm-wakeup",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
{ "pm-suspend",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
{ "balloon-change",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventBalloonChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventBalloonChangePrint), },
{ "pm-suspend-disk",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventPMChangePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventPMChangePrint), },
{ "device-removed",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventDeviceRemovedPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceRemovedPrint), },
{ "block-job-2",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventBlockJobPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventBlockJobPrint), },
{ "tunable",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventTunablePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventTunablePrint), },
{ "agent-lifecycle",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventAgentLifecyclePrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventAgentLifecyclePrint), },
{ "device-added",
- VIR_DOMAIN_EVENT_CALLBACK(vshEventDeviceAddedPrint), },
+ VIR_DOMAIN_EVENT_CALLBACK(virshEventDeviceAddedPrint), },
};
verify(VIR_DOMAIN_EVENT_ID_LAST == ARRAY_CARDINALITY(vshEventCallbacks));
@@ -12277,7 +12283,7 @@ cmdEvent(vshControl *ctl, const vshCmd *cmd)
virDomainPtr dom = NULL;
bool ret = false;
int timeout = 0;
- vshDomEventData *data = NULL;
+ virshDomEventData *data = NULL;
size_t i;
const char *eventName = NULL;
int event = -1;
@@ -12461,7 +12467,7 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
xmlNodePtr disk_node = NULL;
char *disk_xml = NULL;
bool ret = false;
- vshUpdateDiskXMLType update_type;
+ virshUpdateDiskXMLType update_type;
const char *action = NULL;
const char *success_msg = NULL;
bool config = vshCommandOptBool(cmd, "config");
@@ -12530,11 +12536,11 @@ cmdChangeMedia(vshControl *ctl, const vshCmd *cmd)
if (!doc)
goto cleanup;
- if (!(disk_node = vshFindDisk(doc, path, VIRSH_FIND_DISK_CHANGEABLE)))
+ if (!(disk_node = virshFindDisk(doc, path, VIRSH_FIND_DISK_CHANGEABLE)))
goto cleanup;
- if (!(disk_xml = vshUpdateDiskXML(disk_node, source, block, path,
- update_type)))
+ if (!(disk_xml = virshUpdateDiskXML(disk_node, source, block, path,
+ update_type)))
goto cleanup;
if (vshCommandOptBool(cmd, "print-xml")) {
diff --git a/tools/virsh-domain.h b/tools/virsh-domain.h
index 2f3ec30..462f560 100644
--- a/tools/virsh-domain.h
+++ b/tools/virsh-domain.h
@@ -37,7 +37,8 @@ virDomainPtr virshCommandOptDomainBy(vshControl *ctl, const vshCmd *cmd,
/* default is lookup by Id, Name and UUID */
# define virshCommandOptDomain(_ctl, _cmd, _name) \
- virshCommandOptDomainBy(_ctl, _cmd, _name, VSH_BYID|VSH_BYUUID|VSH_BYNAME)
+ virshCommandOptDomainBy(_ctl, _cmd, _name, \
+ VIRSH_BYID | VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef domManagementCmds[];
diff --git a/tools/virsh-edit.c b/tools/virsh-edit.c
index 49d4a5a..1b39cb7 100644
--- a/tools/virsh-edit.c
+++ b/tools/virsh-edit.c
@@ -70,7 +70,7 @@ do {
goto edit_cleanup;
/* Create and open the temporary file. */
- tmp = virshEditWriteToTempFile(ctl, doc);
+ tmp = vshEditWriteToTempFile(ctl, doc);
if (!tmp)
goto edit_cleanup;
@@ -81,12 +81,12 @@ do {
#endif
/* Start the editor. */
- if (virshEditFile(ctl, tmp) == -1)
+ if (vshEditFile(ctl, tmp) == -1)
goto edit_cleanup;
/* Read back the edited file. */
VIR_FREE(doc_edited);
- doc_edited = virshEditReadBackFile(ctl, tmp);
+ doc_edited = vshEditReadBackFile(ctl, tmp);
if (!doc_edited)
goto edit_cleanup;
@@ -118,7 +118,7 @@ do {
msg = _("Failed.");
if (msg) {
- int c = virshAskReedit(ctl, msg, relax_avail);
+ int c = vshAskReedit(ctl, msg, relax_avail);
switch (c) {
case 'y':
goto reedit;
diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c
index 9a00070..b69c685 100644
--- a/tools/virsh-interface.c
+++ b/tools/virsh-interface.c
@@ -49,7 +49,7 @@ virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
const char *n = NULL;
bool is_mac = false;
virMacAddr dummy;
- virCheckFlags(VSH_BYNAME | VSH_BYMAC, NULL);
+ virCheckFlags(VIRSH_BYNAME | VIRSH_BYMAC, NULL);
virshControlPtr priv = ctl->privData;
if (!optname)
@@ -68,13 +68,13 @@ virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
is_mac = true;
/* try it by NAME */
- if (!is_mac && (flags & VSH_BYNAME)) {
+ if (!is_mac && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface NAME\n",
cmd->def->name, optname);
iface = virInterfaceLookupByName(priv->conn, n);
/* try it by MAC */
- } else if (is_mac && (flags & VSH_BYMAC)) {
+ } else if (is_mac && (flags & VIRSH_BYMAC)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as interface MAC\n",
cmd->def->name, optname);
iface = virInterfaceLookupByMACString(priv->conn, n);
@@ -148,7 +148,7 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshInterfaceSorter(const void *a, const void *b)
+virshInterfaceSorter(const void *a, const void *b)
{
virInterfacePtr *ia = (virInterfacePtr *) a;
virInterfacePtr *ib = (virInterfacePtr *) b;
@@ -163,14 +163,14 @@ vshInterfaceSorter(const void *a, const void *b)
virInterfaceGetName(*ib));
}
-struct vshInterfaceList {
+struct virshInterfaceList {
virInterfacePtr *ifaces;
size_t nifaces;
};
-typedef struct vshInterfaceList *vshInterfaceListPtr;
+typedef struct virshInterfaceList *virshInterfaceListPtr;
static void
-vshInterfaceListFree(vshInterfaceListPtr list)
+virshInterfaceListFree(virshInterfaceListPtr list)
{
size_t i;
@@ -184,11 +184,11 @@ vshInterfaceListFree(vshInterfaceListPtr list)
VIR_FREE(list);
}
-static vshInterfaceListPtr
-vshInterfaceListCollect(vshControl *ctl,
- unsigned int flags)
+static virshInterfaceListPtr
+virshInterfaceListCollect(vshControl *ctl,
+ unsigned int flags)
{
- vshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshInterfaceListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
char **activeNames = NULL;
@@ -292,7 +292,7 @@ vshInterfaceListCollect(vshControl *ctl,
/* sort the list */
if (list->ifaces && list->nifaces)
qsort(list->ifaces, list->nifaces,
- sizeof(*list->ifaces), vshInterfaceSorter);
+ sizeof(*list->ifaces), virshInterfaceSorter);
/* truncate the list if filter simulation deleted entries */
if (deleted)
@@ -311,7 +311,7 @@ vshInterfaceListCollect(vshControl *ctl,
VIR_FREE(inactiveNames);
if (!success) {
- vshInterfaceListFree(list);
+ virshInterfaceListFree(list);
list = NULL;
}
@@ -349,7 +349,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
bool inactive = vshCommandOptBool(cmd, "inactive");
bool all = vshCommandOptBool(cmd, "all");
unsigned int flags = VIR_CONNECT_LIST_INTERFACES_ACTIVE;
- vshInterfaceListPtr list = NULL;
+ virshInterfaceListPtr list = NULL;
size_t i;
if (inactive)
@@ -358,7 +358,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
flags = VIR_CONNECT_LIST_INTERFACES_INACTIVE |
VIR_CONNECT_LIST_INTERFACES_ACTIVE;
- if (!(list = vshInterfaceListCollect(ctl, flags)))
+ if (!(list = virshInterfaceListCollect(ctl, flags)))
return false;
vshPrintExtra(ctl, " %-20s %-10s %s\n", _("Name"), _("State"),
@@ -374,7 +374,7 @@ cmdInterfaceList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
virInterfaceGetMACString(iface));
}
- vshInterfaceListFree(list);
+ virshInterfaceListFree(list);
return true;
}
@@ -406,7 +406,7 @@ cmdInterfaceName(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface;
if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
- VSH_BYMAC)))
+ VIRSH_BYMAC)))
return false;
vshPrint(ctl, "%s\n", virInterfaceGetName(iface));
@@ -442,7 +442,7 @@ cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface;
if (!(iface = virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL,
- VSH_BYNAME)))
+ VIRSH_BYNAME)))
return false;
vshPrint(ctl, "%s\n", virInterfaceGetMACString(iface));
@@ -538,7 +538,7 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
iface = virInterfaceDefineXML(priv->conn, buffer, 0);
@@ -837,7 +837,7 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd)
/* Get a handle to the original device */
if (!(if_handle = virshCommandOptInterfaceBy(ctl, cmd, "interface",
- &if_name, VSH_BYNAME))) {
+ &if_name, VIRSH_BYNAME))) {
goto cleanup;
}
@@ -1058,7 +1058,7 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd)
/* Get a handle to the original device */
if (!(br_handle = virshCommandOptInterfaceBy(ctl, cmd, "bridge",
- &br_name, VSH_BYNAME))) {
+ &br_name, VIRSH_BYNAME))) {
goto cleanup;
}
diff --git a/tools/virsh-interface.h b/tools/virsh-interface.h
index be756ec..44bf5e4 100644
--- a/tools/virsh-interface.h
+++ b/tools/virsh-interface.h
@@ -35,7 +35,7 @@ virInterfacePtr virshCommandOptInterfaceBy(vshControl *ctl, const vshCmd *cmd,
/* default is lookup by Name and MAC */
# define virshCommandOptInterface(_ctl, _cmd, _name) \
virshCommandOptInterfaceBy(_ctl, _cmd, NULL, _name, \
- VSH_BYMAC|VSH_BYNAME)
+ VIRSH_BYMAC | VIRSH_BYNAME)
extern const vshCmdDef ifaceCmds[];
diff --git a/tools/virsh-network.c b/tools/virsh-network.c
index 4e3eee5..00a50ef 100644
--- a/tools/virsh-network.c
+++ b/tools/virsh-network.c
@@ -40,7 +40,7 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
virNetworkPtr network = NULL;
const char *n = NULL;
const char *optname = "network";
- virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
+ virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
virshControlPtr priv = ctl->privData;
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
@@ -53,13 +53,13 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by UUID */
- if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
+ if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network UUID\n",
cmd->def->name, optname);
network = virNetworkLookupByUUIDString(priv->conn, n);
}
/* try it by NAME */
- if (!network && (flags & VSH_BYNAME)) {
+ if (!network && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as network NAME\n",
cmd->def->name, optname);
network = virNetworkLookupByName(priv->conn, n);
@@ -161,7 +161,7 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
network = virNetworkCreateXML(priv->conn, buffer);
@@ -213,7 +213,7 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
network = virNetworkDefineXML(priv->conn, buffer);
@@ -393,7 +393,7 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshNetworkSorter(const void *a, const void *b)
+virshNetworkSorter(const void *a, const void *b)
{
virNetworkPtr *na = (virNetworkPtr *) a;
virNetworkPtr *nb = (virNetworkPtr *) b;
@@ -408,14 +408,14 @@ vshNetworkSorter(const void *a, const void *b)
virNetworkGetName(*nb));
}
-struct vshNetworkList {
+struct virshNetworkList {
virNetworkPtr *nets;
size_t nnets;
};
-typedef struct vshNetworkList *vshNetworkListPtr;
+typedef struct virshNetworkList *virshNetworkListPtr;
static void
-vshNetworkListFree(vshNetworkListPtr list)
+virshNetworkListFree(virshNetworkListPtr list)
{
size_t i;
@@ -429,11 +429,11 @@ vshNetworkListFree(vshNetworkListPtr list)
VIR_FREE(list);
}
-static vshNetworkListPtr
-vshNetworkListCollect(vshControl *ctl,
- unsigned int flags)
+static virshNetworkListPtr
+virshNetworkListCollect(vshControl *ctl,
+ unsigned int flags)
{
- vshNetworkListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNetworkListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
char **names = NULL;
@@ -589,7 +589,7 @@ vshNetworkListCollect(vshControl *ctl,
/* sort the list */
if (list->nets && list->nnets)
qsort(list->nets, list->nnets,
- sizeof(*list->nets), vshNetworkSorter);
+ sizeof(*list->nets), virshNetworkSorter);
/* truncate the list if filter simulation deleted entries */
if (deleted)
@@ -603,7 +603,7 @@ vshNetworkListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
- vshNetworkListFree(list);
+ virshNetworkListFree(list);
list = NULL;
}
@@ -669,7 +669,7 @@ static const vshCmdOptDef opts_network_list[] = {
static bool
cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
- vshNetworkListPtr list = NULL;
+ virshNetworkListPtr list = NULL;
size_t i;
bool ret = false;
bool optName = vshCommandOptBool(cmd, "name");
@@ -701,7 +701,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (!optUUID && !optName)
optTable = true;
- if (!(list = vshNetworkListCollect(ctl, flags)))
+ if (!(list = virshNetworkListCollect(ctl, flags)))
return false;
if (optTable) {
@@ -740,7 +740,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
ret = true;
cleanup:
- vshNetworkListFree(list);
+ virshNetworkListFree(list);
return ret;
}
#undef FILTER
@@ -773,7 +773,7 @@ cmdNetworkName(vshControl *ctl, const vshCmd *cmd)
virNetworkPtr network;
if (!(network = virshCommandOptNetworkBy(ctl, cmd, NULL,
- VSH_BYUUID)))
+ VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virNetworkGetName(network));
@@ -990,7 +990,7 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd)
/* contents of xmldata is actually the name of a file that
* contains the xml.
*/
- if (virFileReadAll(xml, VIRSH_MAX_XML_FILE, &xmlFromFile) < 0)
+ if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlFromFile) < 0)
goto cleanup;
/* NB: the original xml is just a const char * that points
* to a string owned by the vshCmd object, and will be freed
@@ -1071,7 +1071,7 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd)
char uuid[VIR_UUID_STRING_BUFLEN];
if (!(network = virshCommandOptNetworkBy(ctl, cmd, NULL,
- VSH_BYNAME)))
+ VIRSH_BYNAME)))
return false;
if (virNetworkGetUUIDString(network, uuid) != -1)
@@ -1105,7 +1105,7 @@ static const vshCmdOptDef opts_network_edit[] = {
{.name = NULL}
};
-static char *vshNetworkGetXMLDesc(virNetworkPtr network)
+static char *virshNetworkGetXMLDesc(virNetworkPtr network)
{
unsigned int flags = VIR_NETWORK_XML_INACTIVE;
char *doc = virNetworkGetXMLDesc(network, flags);
@@ -1133,7 +1133,7 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
if (network == NULL)
goto cleanup;
-#define EDIT_GET_XML vshNetworkGetXMLDesc(network)
+#define EDIT_GET_XML virshNetworkGetXMLDesc(network)
#define EDIT_NOT_CHANGED \
do { \
vshPrint(ctl, _("Network %s XML configuration not changed.\n"), \
@@ -1163,8 +1163,8 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd)
/*
* "net-event" command
*/
-VIR_ENUM_DECL(vshNetworkEvent)
-VIR_ENUM_IMPL(vshNetworkEvent,
+VIR_ENUM_DECL(virshNetworkEvent)
+VIR_ENUM_IMPL(virshNetworkEvent,
VIR_NETWORK_EVENT_LAST,
N_("Defined"),
N_("Undefined"),
@@ -1172,21 +1172,21 @@ VIR_ENUM_IMPL(vshNetworkEvent,
N_("Stopped"))
static const char *
-vshNetworkEventToString(int event)
+virshNetworkEventToString(int event)
{
- const char *str = vshNetworkEventTypeToString(event);
+ const char *str = virshNetworkEventTypeToString(event);
return str ? _(str) : _("unknown");
}
-struct vshNetEventData {
+struct virshNetEventData {
vshControl *ctl;
bool loop;
int count;
};
-typedef struct vshNetEventData vshNetEventData;
+typedef struct virshNetEventData virshNetEventData;
-VIR_ENUM_DECL(vshNetworkEventId)
-VIR_ENUM_IMPL(vshNetworkEventId,
+VIR_ENUM_DECL(virshNetworkEventId)
+VIR_ENUM_IMPL(virshNetworkEventId,
VIR_NETWORK_EVENT_ID_LAST,
"lifecycle")
@@ -1197,12 +1197,12 @@ vshEventLifecyclePrint(virConnectPtr conn ATTRIBUTE_UNUSED,
int detail ATTRIBUTE_UNUSED,
void *opaque)
{
- vshNetEventData *data = opaque;
+ virshNetEventData *data = opaque;
if (!data->loop && data->count)
return;
vshPrint(data->ctl, _("event 'lifecycle' for network %s: %s\n"),
- virNetworkGetName(net), vshNetworkEventToString(event));
+ virNetworkGetName(net), virshNetworkEventToString(event));
data->count++;
if (!data->loop)
vshEventDone(data->ctl);
@@ -1249,7 +1249,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
bool ret = false;
int eventId = -1;
int timeout = 0;
- vshNetEventData data;
+ virshNetEventData data;
const char *eventName = NULL;
int event;
virshControlPtr priv = ctl->privData;
@@ -1258,7 +1258,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
size_t i;
for (i = 0; i < VIR_NETWORK_EVENT_ID_LAST; i++)
- vshPrint(ctl, "%s\n", vshNetworkEventIdTypeToString(i));
+ vshPrint(ctl, "%s\n", virshNetworkEventIdTypeToString(i));
return true;
}
@@ -1268,7 +1268,7 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd)
vshError(ctl, "%s", _("either --list or event type is required"));
return false;
}
- if ((event = vshNetworkEventIdTypeFromString(eventName)) < 0) {
+ if ((event = virshNetworkEventIdTypeFromString(eventName)) < 0) {
vshError(ctl, _("unknown event type %s"), eventName);
return false;
}
@@ -1343,7 +1343,7 @@ static const vshCmdOptDef opts_network_dhcp_leases[] = {
};
static int
-vshNetworkDHCPLeaseSorter(const void *a, const void *b)
+virshNetworkDHCPLeaseSorter(const void *a, const void *b)
{
int rv = -1;
@@ -1384,7 +1384,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
}
/* Sort the list according to MAC Address/IAID */
- qsort(leases, nleases, sizeof(*leases), vshNetworkDHCPLeaseSorter);
+ qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter);
vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n",
_("Expiry Time"), _("MAC address"), _("Protocol"),
diff --git a/tools/virsh-network.h b/tools/virsh-network.h
index 49823a8..92bb4b5 100644
--- a/tools/virsh-network.h
+++ b/tools/virsh-network.h
@@ -35,7 +35,7 @@ virshCommandOptNetworkBy(vshControl *ctl, const vshCmd *cmd,
/* default is lookup by Name and UUID */
# define virshCommandOptNetwork(_ctl, _cmd, _name) \
virshCommandOptNetworkBy(_ctl, _cmd, _name, \
- VSH_BYUUID|VSH_BYNAME)
+ VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef networkCmds[];
diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c
index d81afcf..cc359e2 100644
--- a/tools/virsh-nodedev.c
+++ b/tools/virsh-nodedev.c
@@ -70,7 +70,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
dev = virNodeDeviceCreateXML(priv->conn, buffer, 0);
@@ -164,22 +164,22 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd)
return ret;
}
-struct vshNodeList {
+struct virshNodeList {
char **names;
char **parents;
};
static const char *
-vshNodeListLookup(int devid, bool parent, void *opaque)
+virshNodeListLookup(int devid, bool parent, void *opaque)
{
- struct vshNodeList *arrays = opaque;
+ struct virshNodeList *arrays = opaque;
if (parent)
return arrays->parents[devid];
return arrays->names[devid];
}
static int
-vshNodeDeviceSorter(const void *a, const void *b)
+virshNodeDeviceSorter(const void *a, const void *b)
{
virNodeDevicePtr *na = (virNodeDevicePtr *) a;
virNodeDevicePtr *nb = (virNodeDevicePtr *) b;
@@ -194,14 +194,14 @@ vshNodeDeviceSorter(const void *a, const void *b)
virNodeDeviceGetName(*nb));
}
-struct vshNodeDeviceList {
+struct virshNodeDeviceList {
virNodeDevicePtr *devices;
size_t ndevices;
};
-typedef struct vshNodeDeviceList *vshNodeDeviceListPtr;
+typedef struct virshNodeDeviceList *virshNodeDeviceListPtr;
static void
-vshNodeDeviceListFree(vshNodeDeviceListPtr list)
+virshNodeDeviceListFree(virshNodeDeviceListPtr list)
{
size_t i;
@@ -215,13 +215,13 @@ vshNodeDeviceListFree(vshNodeDeviceListPtr list)
VIR_FREE(list);
}
-static vshNodeDeviceListPtr
-vshNodeDeviceListCollect(vshControl *ctl,
+static virshNodeDeviceListPtr
+virshNodeDeviceListCollect(vshControl *ctl,
char **capnames,
int ncapnames,
unsigned int flags)
{
- vshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNodeDeviceListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
virNodeDevicePtr device;
@@ -339,7 +339,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
/* sort the list */
if (list->devices && list->ndevices)
qsort(list->devices, list->ndevices,
- sizeof(*list->devices), vshNodeDeviceSorter);
+ sizeof(*list->devices), virshNodeDeviceSorter);
/* truncate the list if filter simulation deleted entries */
if (deleted)
@@ -353,7 +353,7 @@ vshNodeDeviceListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
- vshNodeDeviceListFree(list);
+ virshNodeDeviceListFree(list);
list = NULL;
}
@@ -395,7 +395,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
unsigned int flags = 0;
char **caps = NULL;
int ncaps = 0;
- vshNodeDeviceListPtr list = NULL;
+ virshNodeDeviceListPtr list = NULL;
int cap_type = -1;
ignore_value(vshCommandOptString(ctl, cmd, "cap", &cap_str));
@@ -458,7 +458,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
}
}
- if (!(list = vshNodeDeviceListCollect(ctl, caps, ncaps, flags))) {
+ if (!(list = virshNodeDeviceListCollect(ctl, caps, ncaps, flags))) {
ret = false;
goto cleanup;
}
@@ -466,7 +466,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (tree) {
char **parents = vshMalloc(ctl, sizeof(char *) * list->ndevices);
char **names = vshMalloc(ctl, sizeof(char *) * list->ndevices);
- struct vshNodeList arrays = { names, parents };
+ struct virshNodeList arrays = { names, parents };
for (i = 0; i < list->ndevices; i++)
names[i] = vshStrdup(ctl, virNodeDeviceGetName(list->devices[i]));
@@ -483,8 +483,8 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
for (i = 0; i < list->ndevices; i++) {
if (parents[i] == NULL &&
- virshTreePrint(ctl, vshNodeListLookup, &arrays,
- list->ndevices, i) < 0)
+ vshTreePrint(ctl, virshNodeListLookup, &arrays,
+ list->ndevices, i) < 0)
ret = false;
}
@@ -501,7 +501,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
cleanup:
virStringFreeList(caps);
- vshNodeDeviceListFree(list);
+ virshNodeDeviceListFree(list);
return ret;
}
diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c
index 8c64ac4..7732da8 100644
--- a/tools/virsh-nwfilter.c
+++ b/tools/virsh-nwfilter.c
@@ -41,7 +41,7 @@ virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
const char *optname = "nwfilter";
virshControlPtr priv = ctl->privData;
- virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
+ virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
return NULL;
@@ -53,13 +53,13 @@ virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by UUID */
- if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
+ if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter UUID\n",
cmd->def->name, optname);
nwfilter = virNWFilterLookupByUUIDString(priv->conn, n);
}
/* try it by NAME */
- if (!nwfilter && (flags & VSH_BYNAME)) {
+ if (!nwfilter && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as nwfilter NAME\n",
cmd->def->name, optname);
nwfilter = virNWFilterLookupByName(priv->conn, n);
@@ -105,7 +105,7 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
nwfilter = virNWFilterDefineXML(priv->conn, buffer);
@@ -210,7 +210,7 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshNWFilterSorter(const void *a, const void *b)
+virshNWFilterSorter(const void *a, const void *b)
{
virNWFilterPtr *fa = (virNWFilterPtr *) a;
virNWFilterPtr *fb = (virNWFilterPtr *) b;
@@ -225,14 +225,14 @@ vshNWFilterSorter(const void *a, const void *b)
virNWFilterGetName(*fb));
}
-struct vshNWFilterList {
+struct virshNWFilterList {
virNWFilterPtr *filters;
size_t nfilters;
};
-typedef struct vshNWFilterList *vshNWFilterListPtr;
+typedef struct virshNWFilterList *virshNWFilterListPtr;
static void
-vshNWFilterListFree(vshNWFilterListPtr list)
+virshNWFilterListFree(virshNWFilterListPtr list)
{
size_t i;
@@ -246,11 +246,11 @@ vshNWFilterListFree(vshNWFilterListPtr list)
VIR_FREE(list);
}
-static vshNWFilterListPtr
-vshNWFilterListCollect(vshControl *ctl,
- unsigned int flags)
+static virshNWFilterListPtr
+virshNWFilterListCollect(vshControl *ctl,
+ unsigned int flags)
{
- vshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshNWFilterListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
virNWFilterPtr filter;
@@ -317,7 +317,7 @@ vshNWFilterListCollect(vshControl *ctl,
/* sort the list */
if (list->filters && list->nfilters)
qsort(list->filters, list->nfilters,
- sizeof(*list->filters), vshNWFilterSorter);
+ sizeof(*list->filters), virshNWFilterSorter);
/* truncate the list for not found filter objects */
if (deleted)
@@ -331,7 +331,7 @@ vshNWFilterListCollect(vshControl *ctl,
VIR_FREE(names);
if (!success) {
- vshNWFilterListFree(list);
+ virshNWFilterListFree(list);
list = NULL;
}
@@ -360,9 +360,9 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
size_t i;
char uuid[VIR_UUID_STRING_BUFLEN];
- vshNWFilterListPtr list = NULL;
+ virshNWFilterListPtr list = NULL;
- if (!(list = vshNWFilterListCollect(ctl, 0)))
+ if (!(list = virshNWFilterListCollect(ctl, 0)))
return false;
vshPrintExtra(ctl, " %-36s %-20s \n", _("UUID"), _("Name"));
@@ -378,7 +378,7 @@ cmdNWFilterList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
virNWFilterGetName(nwfilter));
}
- vshNWFilterListFree(list);
+ virshNWFilterListFree(list);
return true;
}
diff --git a/tools/virsh-nwfilter.h b/tools/virsh-nwfilter.h
index a570813..1e4250e 100644
--- a/tools/virsh-nwfilter.h
+++ b/tools/virsh-nwfilter.h
@@ -35,7 +35,7 @@ virshCommandOptNWFilterBy(vshControl *ctl, const vshCmd *cmd,
/* default is lookup by Name and UUID */
# define virshCommandOptNWFilter(_ctl, _cmd, _name) \
virshCommandOptNWFilterBy(_ctl, _cmd, _name, \
- VSH_BYUUID|VSH_BYNAME)
+ VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef nwfilterCmds[];
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index f87b73c..cf5a8f3 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -41,7 +41,7 @@ virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
const char *n = NULL;
virshControlPtr priv = ctl->privData;
- virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
+ virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
return NULL;
@@ -53,13 +53,13 @@ virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
*name = n;
/* try it by UUID */
- if ((flags & VSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
+ if ((flags & VIRSH_BYUUID) && strlen(n) == VIR_UUID_STRING_BUFLEN-1) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool UUID\n",
cmd->def->name, optname);
pool = virStoragePoolLookupByUUIDString(priv->conn, n);
}
/* try it by NAME */
- if (!pool && (flags & VSH_BYNAME)) {
+ if (!pool && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as pool NAME\n",
cmd->def->name, optname);
pool = virStoragePoolLookupByName(priv->conn, n);
@@ -161,7 +161,7 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
pool = virStoragePoolCreateXML(priv->conn, buffer, 0);
@@ -252,10 +252,10 @@ static const vshCmdOptDef opts_pool_X_as[] = {
};
static int
-vshBuildPoolXML(vshControl *ctl,
- const vshCmd *cmd,
- const char **retname,
- char **xml)
+virshBuildPoolXML(vshControl *ctl,
+ const vshCmd *cmd,
+ const char **retname,
+ char **xml)
{
const char *name = NULL, *type = NULL, *srcHost = NULL, *srcPath = NULL,
*srcDev = NULL, *srcName = NULL, *srcFormat = NULL,
@@ -370,7 +370,7 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd)
bool printXML = vshCommandOptBool(cmd, "print-xml");
virshControlPtr priv = ctl->privData;
- if (!vshBuildPoolXML(ctl, cmd, &name, &xml))
+ if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
return false;
if (printXML) {
@@ -426,7 +426,7 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
pool = virStoragePoolDefineXML(priv->conn, buffer, 0);
@@ -465,7 +465,7 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd)
bool printXML = vshCommandOptBool(cmd, "print-xml");
virshControlPtr priv = ctl->privData;
- if (!vshBuildPoolXML(ctl, cmd, &name, &xml))
+ if (!virshBuildPoolXML(ctl, cmd, &name, &xml))
return false;
if (printXML) {
@@ -728,7 +728,7 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshStoragePoolSorter(const void *a, const void *b)
+virshStoragePoolSorter(const void *a, const void *b)
{
virStoragePoolPtr *pa = (virStoragePoolPtr *) a;
virStoragePoolPtr *pb = (virStoragePoolPtr *) b;
@@ -743,14 +743,14 @@ vshStoragePoolSorter(const void *a, const void *b)
virStoragePoolGetName(*pb));
}
-struct vshStoragePoolList {
+struct virshStoragePoolList {
virStoragePoolPtr *pools;
size_t npools;
};
-typedef struct vshStoragePoolList *vshStoragePoolListPtr;
+typedef struct virshStoragePoolList *virshStoragePoolListPtr;
static void
-vshStoragePoolListFree(vshStoragePoolListPtr list)
+virshStoragePoolListFree(virshStoragePoolListPtr list)
{
size_t i;
@@ -764,11 +764,11 @@ vshStoragePoolListFree(vshStoragePoolListPtr list)
VIR_FREE(list);
}
-static vshStoragePoolListPtr
-vshStoragePoolListCollect(vshControl *ctl,
- unsigned int flags)
+static virshStoragePoolListPtr
+virshStoragePoolListCollect(vshControl *ctl,
+ unsigned int flags)
{
- vshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshStoragePoolListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
char **names = NULL;
@@ -931,7 +931,7 @@ vshStoragePoolListCollect(vshControl *ctl,
/* sort the list */
if (list->pools && list->npools)
qsort(list->pools, list->npools,
- sizeof(*list->pools), vshStoragePoolSorter);
+ sizeof(*list->pools), virshStoragePoolSorter);
/* truncate the list if filter simulation deleted entries */
if (deleted)
@@ -944,7 +944,7 @@ vshStoragePoolListCollect(vshControl *ctl,
VIR_FREE(names[i]);
if (!success) {
- vshStoragePoolListFree(list);
+ virshStoragePoolListFree(list);
list = NULL;
}
@@ -1039,7 +1039,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
};
struct poolInfoText *poolInfoTexts = NULL;
unsigned int flags = VIR_CONNECT_LIST_STORAGE_POOLS_ACTIVE;
- vshStoragePoolListPtr list = NULL;
+ virshStoragePoolListPtr list = NULL;
const char *type = NULL;
bool details = vshCommandOptBool(cmd, "details");
bool inactive, all;
@@ -1129,7 +1129,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
virStringFreeList(poolTypes);
}
- if (!(list = vshStoragePoolListCollect(ctl, flags)))
+ if (!(list = virshStoragePoolListCollect(ctl, flags)))
goto cleanup;
poolInfoTexts = vshCalloc(ctl, list->npools, sizeof(*poolInfoTexts));
@@ -1185,17 +1185,17 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
double val;
const char *unit;
- val = virshPrettyCapacity(info.capacity, &unit);
+ val = vshPrettyCapacity(info.capacity, &unit);
if (virAsprintf(&poolInfoTexts[i].capacity,
"%.2lf %s", val, unit) < 0)
goto cleanup;
- val = virshPrettyCapacity(info.allocation, &unit);
+ val = vshPrettyCapacity(info.allocation, &unit);
if (virAsprintf(&poolInfoTexts[i].allocation,
"%.2lf %s", val, unit) < 0)
goto cleanup;
- val = virshPrettyCapacity(info.available, &unit);
+ val = vshPrettyCapacity(info.available, &unit);
if (virAsprintf(&poolInfoTexts[i].available,
"%.2lf %s", val, unit) < 0)
goto cleanup;
@@ -1378,7 +1378,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
}
VIR_FREE(poolInfoTexts);
- vshStoragePoolListFree(list);
+ virshStoragePoolListFree(list);
return ret;
}
@@ -1512,7 +1512,7 @@ cmdPoolDiscoverSources(vshControl * ctl, const vshCmd * cmd ATTRIBUTE_UNUSED)
if (vshCommandOptStringReq(ctl, cmd, "srcSpec", &srcSpecFile) < 0)
return false;
- if (srcSpecFile && virFileReadAll(srcSpecFile, VIRSH_MAX_XML_FILE,
+ if (srcSpecFile && virFileReadAll(srcSpecFile, VSH_MAX_XML_FILE,
&srcSpec) < 0)
return false;
@@ -1591,13 +1591,13 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd)
if (info.state == VIR_STORAGE_POOL_RUNNING ||
info.state == VIR_STORAGE_POOL_DEGRADED) {
- val = virshPrettyCapacity(info.capacity, &unit);
+ val = vshPrettyCapacity(info.capacity, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = virshPrettyCapacity(info.allocation, &unit);
+ val = vshPrettyCapacity(info.allocation, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
- val = virshPrettyCapacity(info.available, &unit);
+ val = vshPrettyCapacity(info.available, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Available:"), val, unit);
}
} else {
@@ -1635,7 +1635,7 @@ cmdPoolName(vshControl *ctl, const vshCmd *cmd)
{
virStoragePoolPtr pool;
- if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYUUID)))
+ if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virStoragePoolGetName(pool));
@@ -1757,7 +1757,7 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd)
virStoragePoolPtr pool;
char uuid[VIR_UUID_STRING_BUFLEN];
- if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VSH_BYNAME)))
+ if (!(pool = virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYNAME)))
return false;
if (virStoragePoolGetUUIDString(pool, uuid) != -1)
diff --git a/tools/virsh-pool.h b/tools/virsh-pool.h
index b5b0836..feee176 100644
--- a/tools/virsh-pool.h
+++ b/tools/virsh-pool.h
@@ -35,7 +35,7 @@ virshCommandOptPoolBy(vshControl *ctl, const vshCmd *cmd, const char *optname,
/* default is lookup by Name and UUID */
# define virshCommandOptPool(_ctl, _cmd, _optname, _name) \
virshCommandOptPoolBy(_ctl, _cmd, _optname, _name, \
- VSH_BYUUID|VSH_BYNAME)
+ VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef storagePoolCmds[];
diff --git a/tools/virsh-secret.c b/tools/virsh-secret.c
index e1fec56..db900c0 100644
--- a/tools/virsh-secret.c
+++ b/tools/virsh-secret.c
@@ -94,7 +94,7 @@ cmdSecretDefine(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0)
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
return false;
if (!(res = virSecretDefineXML(priv->conn, buffer, 0))) {
@@ -333,7 +333,7 @@ cmdSecretUndefine(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshSecretSorter(const void *a, const void *b)
+virshSecretSorter(const void *a, const void *b)
{
virSecretPtr *sa = (virSecretPtr *) a;
virSecretPtr *sb = (virSecretPtr *) b;
@@ -352,14 +352,14 @@ vshSecretSorter(const void *a, const void *b)
return vshStrcasecmp(uuid_sa, uuid_sb);
}
-struct vshSecretList {
+struct virshSecretList {
virSecretPtr *secrets;
size_t nsecrets;
};
-typedef struct vshSecretList *vshSecretListPtr;
+typedef struct virshSecretList *virshSecretListPtr;
static void
-vshSecretListFree(vshSecretListPtr list)
+virshSecretListFree(virshSecretListPtr list)
{
size_t i;
@@ -373,11 +373,11 @@ vshSecretListFree(vshSecretListPtr list)
VIR_FREE(list);
}
-static vshSecretListPtr
-vshSecretListCollect(vshControl *ctl,
- unsigned int flags)
+static virshSecretListPtr
+virshSecretListCollect(vshControl *ctl,
+ unsigned int flags)
{
- vshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
+ virshSecretListPtr list = vshMalloc(ctl, sizeof(*list));
size_t i;
int ret;
virSecretPtr secret;
@@ -447,7 +447,7 @@ vshSecretListCollect(vshControl *ctl,
/* sort the list */
if (list->secrets && list->nsecrets)
qsort(list->secrets, list->nsecrets,
- sizeof(*list->secrets), vshSecretSorter);
+ sizeof(*list->secrets), virshSecretSorter);
/* truncate the list for not found secret objects */
if (deleted)
@@ -463,7 +463,7 @@ vshSecretListCollect(vshControl *ctl,
}
if (!success) {
- vshSecretListFree(list);
+ virshSecretListFree(list);
list = NULL;
}
@@ -507,7 +507,7 @@ static bool
cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
{
size_t i;
- vshSecretListPtr list = NULL;
+ virshSecretListPtr list = NULL;
bool ret = false;
unsigned int flags = 0;
@@ -523,7 +523,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
if (vshCommandOptBool(cmd, "no-private"))
flags |= VIR_CONNECT_LIST_SECRETS_NO_PRIVATE;
- if (!(list = vshSecretListCollect(ctl, flags)))
+ if (!(list = virshSecretListCollect(ctl, flags)))
return false;
vshPrintExtra(ctl, " %-36s %s\n", _("UUID"), _("Usage"));
@@ -554,7 +554,7 @@ cmdSecretList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
ret = true;
cleanup:
- vshSecretListFree(list);
+ virshSecretListFree(list);
return ret;
}
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 839a322..3ab2104 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -207,7 +207,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
if (!from) {
buffer = vshStrdup(ctl, "<domainsnapshot/>");
} else {
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
goto cleanup;
}
@@ -227,7 +227,7 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd)
* "snapshot-create-as" command
*/
static int
-vshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
+virshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
{
int ret = -1;
const char *snapshot = NULL;
@@ -267,7 +267,7 @@ vshParseSnapshotMemspec(vshControl *ctl, virBufferPtr buf, const char *str)
}
static int
-vshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
+virshParseSnapshotDiskspec(vshControl *ctl, virBufferPtr buf, const char *str)
{
int ret = -1;
const char *name = NULL;
@@ -434,14 +434,14 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "memspec", &memspec) < 0)
goto cleanup;
- if (memspec && vshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
+ if (memspec && virshParseSnapshotMemspec(ctl, &buf, memspec) < 0)
goto cleanup;
if (vshCommandOptBool(cmd, "diskspec")) {
virBufferAddLit(&buf, "<disks>\n");
virBufferAdjustIndent(&buf, 2);
while ((opt = vshCommandOptArgv(ctl, cmd, opt))) {
- if (vshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0)
+ if (virshParseSnapshotDiskspec(ctl, &buf, opt->data) < 0)
goto cleanup;
}
virBufferAdjustIndent(&buf, -2);
@@ -478,9 +478,9 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd)
* present. On success, populate *SNAP and *NAME, before returning 0.
* On failure, return -1 after issuing an error message. */
static int
-vshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
- const char *arg, bool exclusive, virDomainPtr dom,
- virDomainSnapshotPtr *snap, const char **name)
+virshLookupSnapshot(vshControl *ctl, const vshCmd *cmd,
+ const char *arg, bool exclusive, virDomainPtr dom,
+ virDomainSnapshotPtr *snap, const char **name)
{
bool current = vshCommandOptBool(cmd, "current");
const char *snapname = NULL;
@@ -571,8 +571,8 @@ cmdSnapshotEdit(vshControl *ctl, const vshCmd *cmd)
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false;
- if (vshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
- &snapshot, &name) < 0)
+ if (virshLookupSnapshot(ctl, cmd, "snapshotname", false, dom,
+ &snapshot, &name) < 0)
goto cleanup;
#define EDIT_GET_XML \
@@ -755,8 +755,8 @@ cmdSnapshotCurrent(vshControl *ctl, const vshCmd *cmd)
* proven no parent exists), and -1 on failure with error reported
* (such as no snapshot support or domain deleted in meantime). */
static int
-vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
- char **parent_name)
+virshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
+ char **parent_name)
{
virDomainSnapshotPtr parent = NULL;
char *xml = NULL;
@@ -816,8 +816,8 @@ vshGetSnapshotParent(vshControl *ctl, virDomainSnapshotPtr snapshot,
* 1 if snapshot is okay (or if snapshot is already NULL), and -1 on
* failure, with error already reported. */
static int
-vshSnapshotFilter(vshControl *ctl, virDomainSnapshotPtr snapshot,
- unsigned int flags)
+virshSnapshotFilter(vshControl *ctl, virDomainSnapshotPtr snapshot,
+ unsigned int flags)
{
char *xml = NULL;
xmlDocPtr xmldoc = NULL;
@@ -921,8 +921,8 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL)
return false;
- if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
- &snapshot, &name) < 0)
+ if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
+ &snapshot, &name) < 0)
goto cleanup;
vshPrint(ctl, "%-15s %s\n", _("Name:"), name);
@@ -1045,18 +1045,18 @@ cmdSnapshotInfo(vshControl *ctl, const vshCmd *cmd)
}
/* Helpers for collecting a list of snapshots. */
-struct vshSnap {
+struct virshSnap {
virDomainSnapshotPtr snap;
char *parent;
};
-struct vshSnapshotList {
- struct vshSnap *snaps;
+struct virshSnapshotList {
+ struct virshSnap *snaps;
int nsnaps;
};
-typedef struct vshSnapshotList *virshSnapshotListPtr;
+typedef struct virshSnapshotList *virshSnapshotListPtr;
static void
-vshSnapshotListFree(virshSnapshotListPtr snaplist)
+virshSnapshotListFree(virshSnapshotListPtr snaplist)
{
size_t i;
@@ -1074,10 +1074,10 @@ vshSnapshotListFree(virshSnapshotListPtr snaplist)
}
static int
-vshSnapSorter(const void *a, const void *b)
+virshSnapSorter(const void *a, const void *b)
{
- const struct vshSnap *sa = a;
- const struct vshSnap *sb = b;
+ const struct virshSnap *sa = a;
+ const struct virshSnap *sb = b;
if (sa->snap && !sb->snap)
return -1;
@@ -1093,9 +1093,9 @@ vshSnapSorter(const void *a, const void *b)
* given, the list is filtered. If TREE is specified, then all but
* FROM or the roots will also have parent information. */
static virshSnapshotListPtr
-vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
- virDomainSnapshotPtr from,
- unsigned int orig_flags, bool tree)
+virshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
+ virDomainSnapshotPtr from,
+ unsigned int orig_flags, bool tree)
{
size_t i;
char **names = NULL;
@@ -1144,8 +1144,8 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
VIR_FREE(snaps);
if (tree) {
for (i = 0; i < count; i++) {
- if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
- &snaplist->snaps[i].parent) < 0)
+ if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
+ &snaplist->snaps[i].parent) < 0)
goto cleanup;
}
if (from) {
@@ -1295,8 +1295,8 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
if (tree)
continue;
}
- if (vshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
- &snaplist->snaps[i].parent) < 0)
+ if (virshGetSnapshotParent(ctl, snaplist->snaps[i].snap,
+ &snaplist->snaps[i].parent) < 0)
goto cleanup;
if ((from && ((tree && !snaplist->snaps[i].parent) ||
(!descendants &&
@@ -1387,8 +1387,8 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION))
orig_flags |= VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION;
for (i = 0; i < snaplist->nsnaps; i++) {
- switch (vshSnapshotFilter(ctl, snaplist->snaps[i].snap,
- orig_flags)) {
+ switch (virshSnapshotFilter(ctl, snaplist->snaps[i].snap,
+ orig_flags)) {
case 1:
break;
case 0:
@@ -1403,14 +1403,14 @@ vshSnapshotListCollect(vshControl *ctl, virDomainPtr dom,
}
}
qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps),
- vshSnapSorter);
+ virshSnapSorter);
snaplist->nsnaps -= deleted;
ret = snaplist;
snaplist = NULL;
cleanup:
- vshSnapshotListFree(snaplist);
+ virshSnapshotListFree(snaplist);
if (names && count > 0)
for (i = 0; i < count; i++)
VIR_FREE(names[i]);
@@ -1592,10 +1592,10 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
return false;
if ((from || current) &&
- vshLookupSnapshot(ctl, cmd, "from", true, dom, &start, &from_snap) < 0)
+ virshLookupSnapshot(ctl, cmd, "from", true, dom, &start, &from_snap) < 0)
goto cleanup;
- if (!(snaplist = vshSnapshotListCollect(ctl, dom, start, flags, tree)))
+ if (!(snaplist = virshSnapshotListCollect(ctl, dom, start, flags, tree)))
goto cleanup;
if (!tree && !name) {
@@ -1614,8 +1614,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
if (tree) {
for (i = 0; i < snaplist->nsnaps; i++) {
if (!snaplist->snaps[i].parent &&
- virshTreePrint(ctl, virshSnapshotListLookup, snaplist,
- snaplist->nsnaps, i) < 0)
+ vshTreePrint(ctl, virshSnapshotListLookup, snaplist,
+ snaplist->nsnaps, i) < 0)
goto cleanup;
}
ret = true;
@@ -1678,7 +1678,7 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
cleanup:
/* this frees up memory from the last iteration of the loop */
- vshSnapshotListFree(snaplist);
+ virshSnapshotListFree(snaplist);
VIR_FREE(parent_snap);
VIR_FREE(state);
if (start)
@@ -1802,11 +1802,11 @@ cmdSnapshotParent(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL)
goto cleanup;
- if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
- &snapshot, &name) < 0)
+ if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
+ &snapshot, &name) < 0)
goto cleanup;
- if (vshGetSnapshotParent(ctl, snapshot, &parent) < 0)
+ if (virshGetSnapshotParent(ctl, snapshot, &parent) < 0)
goto cleanup;
if (!parent) {
vshError(ctl, _("snapshot '%s' has no parent"), name);
@@ -1895,8 +1895,8 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL)
goto cleanup;
- if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
- &snapshot, &name) < 0)
+ if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
+ &snapshot, &name) < 0)
goto cleanup;
result = virDomainRevertToSnapshot(snapshot, flags);
@@ -1975,8 +1975,8 @@ cmdSnapshotDelete(vshControl *ctl, const vshCmd *cmd)
if (dom == NULL)
goto cleanup;
- if (vshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
- &snapshot, &name) < 0)
+ if (virshLookupSnapshot(ctl, cmd, "snapshotname", true, dom,
+ &snapshot, &name) < 0)
goto cleanup;
if (vshCommandOptBool(cmd, "children"))
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 11b54ce..7d76a06 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -53,7 +53,7 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
const char *n = NULL, *p = NULL;
virshControlPtr priv = ctl->privData;
- virCheckFlags(VSH_BYUUID | VSH_BYNAME, NULL);
+ virCheckFlags(VIRSH_BYUUID | VIRSH_BYNAME, NULL);
if (vshCommandOptStringReq(ctl, cmd, optname, &n) < 0)
return NULL;
@@ -80,19 +80,19 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
*name = n;
/* try it by name */
- if (pool && (flags & VSH_BYNAME)) {
+ if (pool && (flags & VIRSH_BYNAME)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol name\n",
cmd->def->name, optname);
vol = virStorageVolLookupByName(pool, n);
}
/* try it by key */
- if (!vol && (flags & VSH_BYUUID)) {
+ if (!vol && (flags & VIRSH_BYUUID)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol key\n",
cmd->def->name, optname);
vol = virStorageVolLookupByKey(priv->conn, n);
}
/* try it by path */
- if (!vol && (flags & VSH_BYUUID)) {
+ if (!vol && (flags & VIRSH_BYUUID)) {
vshDebug(ctl, VSH_ERR_DEBUG, "%s: <%s> trying as vol path\n",
cmd->def->name, optname);
vol = virStorageVolLookupByPath(priv->conn, n);
@@ -184,7 +184,7 @@ static const vshCmdOptDef opts_vol_create_as[] = {
};
static int
-vshVolSize(const char *data, unsigned long long *val)
+virshVolSize(const char *data, unsigned long long *val)
{
char *end;
if (virStrToLong_ull(data, &end, 10, val) < 0)
@@ -217,13 +217,13 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "capacity", &capacityStr) < 0)
goto cleanup;
- if (vshVolSize(capacityStr, &capacity) < 0) {
+ if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup;
}
if (vshCommandOptString(ctl, cmd, "allocation", &allocationStr) > 0 &&
- vshVolSize(allocationStr, &allocation) < 0) {
+ virshVolSize(allocationStr, &allocation) < 0) {
vshError(ctl, _("Malformed size %s"), allocationStr);
goto cleanup;
}
@@ -389,7 +389,7 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshSaveLibvirtError();
goto cleanup;
}
@@ -478,7 +478,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
if (!(inputvol = virshCommandOptVol(ctl, cmd, "vol", "inputpool", NULL)))
goto cleanup;
- if (virFileReadAll(from, VIRSH_MAX_XML_FILE, &buffer) < 0) {
+ if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) {
vshReportError(ctl);
goto cleanup;
}
@@ -506,7 +506,7 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
}
static xmlChar *
-vshMakeCloneXML(const char *origxml, const char *newname)
+virshMakeCloneXML(const char *origxml, const char *newname)
{
xmlDocPtr doc = NULL;
@@ -606,7 +606,7 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
if (!origxml)
goto cleanup;
- newxml = vshMakeCloneXML(origxml, name);
+ newxml = virshMakeCloneXML(origxml, name);
if (!newxml) {
vshPrint(ctl, "%s", _("Failed to allocate XML buffer"));
goto cleanup;
@@ -987,8 +987,8 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd)
}
-VIR_ENUM_DECL(vshStorageVol)
-VIR_ENUM_IMPL(vshStorageVol,
+VIR_ENUM_DECL(virshStorageVol)
+VIR_ENUM_IMPL(virshStorageVol,
VIR_STORAGE_VOL_LAST,
N_("file"),
N_("block"),
@@ -997,9 +997,9 @@ VIR_ENUM_IMPL(vshStorageVol,
N_("netdir"))
static const char *
-vshVolumeTypeToString(int type)
+virshVolumeTypeToString(int type)
{
- const char *str = vshStorageVolTypeToString(type);
+ const char *str = virshStorageVolTypeToString(type);
return str ? _(str) : _("unknown");
}
@@ -1047,12 +1047,12 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd)
const char *unit;
vshPrint(ctl, "%-15s %s\n", _("Type:"),
- vshVolumeTypeToString(info.type));
+ virshVolumeTypeToString(info.type));
- val = virshPrettyCapacity(info.capacity, &unit);
+ val = vshPrettyCapacity(info.capacity, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Capacity:"), val, unit);
- val = virshPrettyCapacity(info.allocation, &unit);
+ val = vshPrettyCapacity(info.allocation, &unit);
vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit);
} else {
ret = false;
@@ -1142,7 +1142,7 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd)
if (delta)
flags |= VIR_STORAGE_VOL_RESIZE_DELTA;
- if (vshVolSize(capacityStr, &capacity) < 0) {
+ if (virshVolSize(capacityStr, &capacity) < 0) {
vshError(ctl, _("Malformed size %s"), capacityStr);
goto cleanup;
}
@@ -1215,7 +1215,7 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd)
}
static int
-vshStorageVolSorter(const void *a, const void *b)
+virshStorageVolSorter(const void *a, const void *b)
{
virStorageVolPtr *va = (virStorageVolPtr *) a;
virStorageVolPtr *vb = (virStorageVolPtr *) b;
@@ -1319,7 +1319,7 @@ virshStorageVolListCollect(vshControl *ctl,
finished:
/* sort the list */
if (list->vols && list->nvols)
- qsort(list->vols, list->nvols, sizeof(*list->vols), vshStorageVolSorter);
+ qsort(list->vols, list->nvols, sizeof(*list->vols), virshStorageVolSorter);
if (deleted)
VIR_SHRINK_N(list->vols, list->nvols, deleted);
@@ -1423,14 +1423,14 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
/* Volume type */
volInfoTexts[i].type = vshStrdup(ctl,
- vshVolumeTypeToString(volumeInfo.type));
+ virshVolumeTypeToString(volumeInfo.type));
- val = virshPrettyCapacity(volumeInfo.capacity, &unit);
+ val = vshPrettyCapacity(volumeInfo.capacity, &unit);
if (virAsprintf(&volInfoTexts[i].capacity,
"%.2lf %s", val, unit) < 0)
goto cleanup;
- val = virshPrettyCapacity(volumeInfo.allocation, &unit);
+ val = vshPrettyCapacity(volumeInfo.allocation, &unit);
if (virAsprintf(&volInfoTexts[i].allocation,
"%.2lf %s", val, unit) < 0)
goto cleanup;
@@ -1610,7 +1610,7 @@ cmdVolName(vshControl *ctl, const vshCmd *cmd)
virStorageVolPtr vol;
if (!(vol = virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
- VSH_BYUUID)))
+ VIRSH_BYUUID)))
return false;
vshPrint(ctl, "%s\n", virStorageVolGetName(vol));
@@ -1653,7 +1653,7 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd)
/* Use the supplied string to locate the volume */
if (!(vol = virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL,
- VSH_BYUUID))) {
+ VIRSH_BYUUID))) {
return false;
}
diff --git a/tools/virsh-volume.h b/tools/virsh-volume.h
index be56928..e01ede4 100644
--- a/tools/virsh-volume.h
+++ b/tools/virsh-volume.h
@@ -36,7 +36,7 @@ virStorageVolPtr virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd,
/* default is lookup by Name and UUID */
# define virshCommandOptVol(_ctl, _cmd, _optname, _pooloptname, _name) \
virshCommandOptVolBy(_ctl, _cmd, _optname, _pooloptname, _name, \
- VSH_BYUUID|VSH_BYNAME)
+ VIRSH_BYUUID | VIRSH_BYNAME)
extern const vshCmdDef storageVolCmds[];
diff --git a/tools/virsh.c b/tools/virsh.c
index fcbd553..97294c5 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -84,45 +84,6 @@ static char *progname;
static const vshCmdGrp cmdGroups[];
static const vshClientHooks hooks;
-double
-virshPrettyCapacity(unsigned long long val, const char **unit)
-{
- double limit = 1024;
-
- if (val < limit) {
- *unit = "B";
- return val;
- }
- limit *= 1024;
- if (val < limit) {
- *unit = "KiB";
- return val / (limit / 1024);
- }
- limit *= 1024;
- if (val < limit) {
- *unit = "MiB";
- return val / (limit / 1024);
- }
- limit *= 1024;
- if (val < limit) {
- *unit = "GiB";
- return val / (limit / 1024);
- }
- limit *= 1024;
- if (val < limit) {
- *unit = "TiB";
- return val / (limit / 1024);
- }
- limit *= 1024;
- if (val < limit) {
- *unit = "PiB";
- return val / (limit / 1024);
- }
- limit *= 1024;
- *unit = "EiB";
- return val / (limit / 1024);
-}
-
/*
* Detection of disconnections and automatic reconnection support
*/
@@ -301,94 +262,6 @@ cmdConnect(vshControl *ctl, const vshCmd *cmd)
return true;
}
-
-#ifndef WIN32
-static void
-virshPrintRaw(vshControl *ctl, ...)
-{
- va_list ap;
- char *key;
-
- va_start(ap, ctl);
- while ((key = va_arg(ap, char *)) != NULL)
- vshPrint(ctl, "%s\r\n", key);
- va_end(ap);
-}
-
-/**
- * vshAskReedit:
- * @msg: Question to ask user
- *
- * Ask user if he wants to return to previously
- * edited file.
- *
- * Returns 'y' if he wants to
- * 'n' if he doesn't want to
- * 'i' if he wants to try defining it again while ignoring validation
- * 'f' if he forcibly wants to
- * -1 on error
- * 0 otherwise
- */
-int
-virshAskReedit(vshControl *ctl, const char *msg, bool relax_avail)
-{
- int c = -1;
-
- if (!isatty(STDIN_FILENO))
- return -1;
-
- vshReportError(ctl);
-
- if (vshTTYMakeRaw(ctl, false) < 0)
- return -1;
-
- while (true) {
- vshPrint(ctl, "\r%s %s %s: ", msg, _("Try again?"),
- relax_avail ? "[y,n,i,f,?]" : "[y,n,f,?]");
- c = c_tolower(getchar());
-
- if (c == '?') {
- virshPrintRaw(ctl,
- "",
- _("y - yes, start editor again"),
- _("n - no, throw away my changes"),
- NULL);
-
- if (relax_avail) {
- virshPrintRaw(ctl,
- _("i - turn off validation and try to redefine "
- "again"),
- NULL);
- }
-
- virshPrintRaw(ctl,
- _("f - force, try to redefine again"),
- _("? - print this help"),
- NULL);
- continue;
- } else if (c == 'y' || c == 'n' || c == 'f' ||
- (relax_avail && c == 'i')) {
- break;
- }
- }
-
- vshTTYRestore(ctl);
-
- vshPrint(ctl, "\r\n");
- return c;
-}
-#else /* WIN32 */
-int
-virshAskReedit(vshControl *ctl,
- const char *msg ATTRIBUTE_UNUSED,
- bool relax_avail ATTRIBUTE_UNUSED)
-{
- vshDebug(ctl, VSH_ERR_WARNING, "%s", _("This function is not "
- "supported on WIN32 platform"));
- return 0;
-}
-#endif /* WIN32 */
-
int virshStreamSink(virStreamPtr st ATTRIBUTE_UNUSED,
const char *bytes, size_t nbytes, void *opaque)
{
@@ -462,207 +335,6 @@ cmdHelp(vshControl *ctl, const vshCmd *cmd)
}
}
-/* Tree listing helpers. */
-
-static int
-virshTreePrintInternal(vshControl *ctl,
- vshTreeLookup lookup,
- void *opaque,
- int num_devices,
- int devid,
- int lastdev,
- bool root,
- virBufferPtr indent)
-{
- size_t i;
- int nextlastdev = -1;
- int ret = -1;
- const char *dev = (lookup)(devid, false, opaque);
-
- if (virBufferError(indent))
- goto cleanup;
-
- /* Print this device, with indent if not at root */
- vshPrint(ctl, "%s%s%s\n", virBufferCurrentContent(indent),
- root ? "" : "+- ", dev);
-
- /* Update indent to show '|' or ' ' for child devices */
- if (!root) {
- virBufferAddChar(indent, devid == lastdev ? ' ' : '|');
- virBufferAddChar(indent, ' ');
- if (virBufferError(indent))
- goto cleanup;
- }
-
- /* Determine the index of the last child device */
- for (i = 0; i < num_devices; i++) {
- const char *parent = (lookup)(i, true, opaque);
-
- if (parent && STREQ(parent, dev))
- nextlastdev = i;
- }
-
- /* If there is a child device, then print another blank line */
- if (nextlastdev != -1)
- vshPrint(ctl, "%s |\n", virBufferCurrentContent(indent));
-
- /* Finally print all children */
- virBufferAddLit(indent, " ");
- if (virBufferError(indent))
- goto cleanup;
- for (i = 0; i < num_devices; i++) {
- const char *parent = (lookup)(i, true, opaque);
-
- if (parent && STREQ(parent, dev) &&
- virshTreePrintInternal(ctl, lookup, opaque,
- num_devices, i, nextlastdev,
- false, indent) < 0)
- goto cleanup;
- }
- virBufferTrim(indent, " ", -1);
-
- /* If there was no child device, and we're the last in
- * a list of devices, then print another blank line */
- if (nextlastdev == -1 && devid == lastdev)
- vshPrint(ctl, "%s\n", virBufferCurrentContent(indent));
-
- if (!root)
- virBufferTrim(indent, NULL, 2);
- ret = 0;
- cleanup:
- return ret;
-}
-
-int
-virshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
- int num_devices, int devid)
-{
- int ret;
- virBuffer indent = VIR_BUFFER_INITIALIZER;
-
- ret = virshTreePrintInternal(ctl, lookup, opaque, num_devices,
- devid, devid, true, &indent);
- if (ret < 0)
- vshError(ctl, "%s", _("Failed to complete tree listing"));
- virBufferFreeAndReset(&indent);
- return ret;
-}
-
-/* Common code for the edit / net-edit / pool-edit functions which follow. */
-char *
-virshEditWriteToTempFile(vshControl *ctl, const char *doc)
-{
- char *ret;
- const char *tmpdir;
- int fd;
- char ebuf[1024];
-
- tmpdir = virGetEnvBlockSUID("TMPDIR");
- if (!tmpdir) tmpdir = "/tmp";
- if (virAsprintf(&ret, "%s/virshXXXXXX.xml", tmpdir) < 0) {
- vshError(ctl, "%s", _("out of memory"));
- return NULL;
- }
- fd = mkostemps(ret, 4, O_CLOEXEC);
- if (fd == -1) {
- vshError(ctl, _("mkostemps: failed to create temporary file: %s"),
- virStrerror(errno, ebuf, sizeof(ebuf)));
- VIR_FREE(ret);
- return NULL;
- }
-
- if (safewrite(fd, doc, strlen(doc)) == -1) {
- vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
- ret, virStrerror(errno, ebuf, sizeof(ebuf)));
- VIR_FORCE_CLOSE(fd);
- unlink(ret);
- VIR_FREE(ret);
- return NULL;
- }
- if (VIR_CLOSE(fd) < 0) {
- vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
- ret, virStrerror(errno, ebuf, sizeof(ebuf)));
- unlink(ret);
- VIR_FREE(ret);
- return NULL;
- }
-
- /* Temporary filename: caller frees. */
- return ret;
-}
-
-/* Characters permitted in $EDITOR environment variable and temp filename. */
-#define ACCEPTED_CHARS \
- "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@"
-
-int
-virshEditFile(vshControl *ctl, const char *filename)
-{
- const char *editor;
- virCommandPtr cmd;
- int ret = -1;
- int outfd = STDOUT_FILENO;
- int errfd = STDERR_FILENO;
-
- editor = virGetEnvBlockSUID("VISUAL");
- if (!editor)
- editor = virGetEnvBlockSUID("EDITOR");
- if (!editor)
- editor = DEFAULT_EDITOR;
-
- /* Check that filename doesn't contain shell meta-characters, and
- * if it does, refuse to run. Follow the Unix conventions for
- * EDITOR: the user can intentionally specify command options, so
- * we don't protect any shell metacharacters there. Lots more
- * than virsh will misbehave if EDITOR has bogus contents (which
- * is why sudo scrubs it by default). Conversely, if the editor
- * is safe, we can run it directly rather than wasting a shell.
- */
- if (strspn(editor, ACCEPTED_CHARS) != strlen(editor)) {
- if (strspn(filename, ACCEPTED_CHARS) != strlen(filename)) {
- vshError(ctl,
- _("%s: temporary filename contains shell meta or other "
- "unacceptable characters (is $TMPDIR wrong?)"),
- filename);
- return -1;
- }
- cmd = virCommandNewArgList("sh", "-c", NULL);
- virCommandAddArgFormat(cmd, "%s %s", editor, filename);
- } else {
- cmd = virCommandNewArgList(editor, filename, NULL);
- }
-
- virCommandSetInputFD(cmd, STDIN_FILENO);
- virCommandSetOutputFD(cmd, &outfd);
- virCommandSetErrorFD(cmd, &errfd);
- if (virCommandRunAsync(cmd, NULL) < 0 ||
- virCommandWait(cmd, NULL) < 0) {
- vshReportError(ctl);
- goto cleanup;
- }
- ret = 0;
-
- cleanup:
- virCommandFree(cmd);
- return ret;
-}
-
-char *
-virshEditReadBackFile(vshControl *ctl, const char *filename)
-{
- char *ret;
- char ebuf[1024];
-
- if (virFileReadAll(filename, VIRSH_MAX_XML_FILE, &ret) == -1) {
- vshError(ctl,
- _("%s: failed to read temporary file: %s"),
- filename, virStrerror(errno, ebuf, sizeof(ebuf)));
- return NULL;
- }
- return ret;
-}
-
-
/*
* "cd" command
*/
@@ -1021,8 +693,7 @@ virshDeinit(vshControl *ctl)
{
virshControlPtr priv = ctl->privData;
- vshReadlineDeinit(ctl);
- vshCloseLogFile(ctl);
+ vshDeinit(ctl);
VIR_FREE(ctl->name);
if (priv->conn) {
int ret;
@@ -1502,6 +1173,7 @@ main(int argc, char **argv)
ctl->imode = true; /* default is interactive mode */
ctl->log_fd = -1; /* Initialize log file descriptor */
ctl->debug = VSH_DEBUG_DEFAULT;
+ ctl->hooks = &hooks;
/* In order to distinguish default from setting to 0 */
ctl->keepalive_interval = -1;
@@ -1556,7 +1228,7 @@ main(int argc, char **argv)
if ((defaultConn = virGetEnvBlockSUID("VIRSH_DEFAULT_CONNECT_URI")))
ctl->name = vshStrdup(ctl, defaultConn);
- if (vshInit(ctl, &hooks, cmdGroups) < 0)
+ if (vshInit(ctl, cmdGroups, NULL) < 0)
exit(EXIT_FAILURE);
if (!virshParseArgv(ctl, argc, argv) ||
@@ -1578,11 +1250,6 @@ main(int argc, char **argv)
" 'quit' to quit\n\n"));
}
- if (vshReadlineInit(ctl) < 0) {
- virshDeinit(ctl);
- exit(EXIT_FAILURE);
- }
-
do {
const char *prompt = virshCtl.readonly ? VIRSH_PROMPT_RO
: VIRSH_PROMPT_RW;
diff --git a/tools/virsh.h b/tools/virsh.h
index d10ed66..6c4159a 100644
--- a/tools/virsh.h
+++ b/tools/virsh.h
@@ -38,8 +38,6 @@
# include "virthread.h"
# include "vsh.h"
-# define VIRSH_MAX_XML_FILE (10*1024*1024)
-
# define VIRSH_PROMPT_RW "virsh # "
# define VIRSH_PROMPT_RO "virsh > "
@@ -95,24 +93,19 @@ struct _virshCtrlData {
virConnectPtr dconn;
};
-virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);
+/* Filter flags for various vshCommandOpt*By() functions */
+typedef enum {
+ VIRSH_BYID = (1 << 1),
+ VIRSH_BYUUID = (1 << 2),
+ VIRSH_BYNAME = (1 << 3),
+ VIRSH_BYMAC = (1 << 4),
+} virshLookupByFlags;
+virConnectPtr virshConnect(vshControl *ctl, const char *uri, bool readonly);
int virshCommandOptTimeoutToMs(vshControl *ctl, const vshCmd *cmd, int *timeout);
-
-/* Given an index, return either the name of that device (non-NULL) or
- * of its parent (NULL if a root). */
-typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque);
-int virshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
- int num_devices, int devid);
-
int virshDomainState(vshControl *ctl, virDomainPtr dom, int *reason);
-char *virshEditWriteToTempFile(vshControl *ctl, const char *doc);
-int virshEditFile(vshControl *ctl, const char *filename);
-char *virshEditReadBackFile(vshControl *ctl, const char *filename);
-int virshAskReedit(vshControl *ctl, const char *msg, bool relax_avail);
int virshStreamSink(virStreamPtr st, const char *bytes, size_t nbytes,
- void *opaque);
-double virshPrettyCapacity(unsigned long long val, const char **unit);
+ void *opaque);
#endif /* VIRSH_H */
diff --git a/tools/vsh.c b/tools/vsh.c
index 9b810c9..f4c342b 100644
--- a/tools/vsh.c
+++ b/tools/vsh.c
@@ -67,12 +67,56 @@
# define SA_SIGINFO 0
#endif
-static const vshClientHooks *hooks;
-static const vshCmdGrp *cmdGroups;
+/* NOTE: It would be much nicer to have these two as part of vshControl
+ * structure, unfortunately readline doesn't support passing opaque data
+ * and only relies on static data accessible from the user-side callback
+ */
+const vshCmdGrp *cmdGroups;
+const vshCmdDef *cmdSet;
/* Bypass header poison */
#undef strdup
+double
+vshPrettyCapacity(unsigned long long val, const char **unit)
+{
+ double limit = 1024;
+
+ if (val < limit) {
+ *unit = "B";
+ return val;
+ }
+ limit *= 1024;
+ if (val < limit) {
+ *unit = "KiB";
+ return val / (limit / 1024);
+ }
+ limit *= 1024;
+ if (val < limit) {
+ *unit = "MiB";
+ return val / (limit / 1024);
+ }
+ limit *= 1024;
+ if (val < limit) {
+ *unit = "GiB";
+ return val / (limit / 1024);
+ }
+ limit *= 1024;
+ if (val < limit) {
+ *unit = "TiB";
+ return val / (limit / 1024);
+ }
+ limit *= 1024;
+ if (val < limit) {
+ *unit = "PiB";
+ return val / (limit / 1024);
+ }
+ limit *= 1024;
+ *unit = "EiB";
+ return val / (limit / 1024);
+}
+
+
void *
_vshMalloc(vshControl *ctl, size_t size, const char *filename, int line)
{
@@ -194,7 +238,7 @@ vshErrorHandler(void *opaque ATTRIBUTE_UNUSED, virErrorPtr error)
{
virFreeError(last_error);
last_error = virSaveLastError();
- if (virGetEnvAllowSUID("VIRSH_DEBUG") != NULL)
+ if (virGetEnvAllowSUID("VSH_DEBUG") != NULL)
virDefaultErrorFunc(error);
}
@@ -454,8 +498,8 @@ vshCommandCheckOpts(vshControl *ctl, const vshCmd *cmd, uint32_t opts_required,
return -1;
}
-const vshCmdDef *
-vshCmddefSearch(const char *cmdname)
+static const vshCmdDef *
+vshCmdDefSearchGrp(const char *cmdname)
{
const vshCmdGrp *g;
const vshCmdDef *c;
@@ -470,6 +514,28 @@ vshCmddefSearch(const char *cmdname)
return NULL;
}
+static const vshCmdDef *
+vshCmdDefSearchSet(const char *cmdname)
+{
+ const vshCmdDef *s;
+
+ for (s = cmdSet; s->name; s++) {
+ if (STREQ(s->name, cmdname))
+ return s;
+ }
+
+ return NULL;
+}
+
+const vshCmdDef *
+vshCmddefSearch(const char *cmdname)
+{
+ if (cmdGroups)
+ return vshCmdDefSearchGrp(cmdname);
+ else
+ return vshCmdDefSearchSet(cmdname);
+}
+
const vshCmdGrp *
vshCmdGrpSearch(const char *grpname)
{
@@ -722,7 +788,7 @@ vshCommandOpt(const vshCmd *cmd, const char *name, vshCmdOpt **opt,
/**
* vshCommandOptInt:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -784,7 +850,7 @@ vshCommandOptUIntInternal(vshControl *ctl,
/**
* vshCommandOptUInt:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -801,7 +867,7 @@ vshCommandOptUInt(vshControl *ctl, const vshCmd *cmd,
/**
* vshCommandOptUIntWrap:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -845,7 +911,7 @@ vshCommandOptULInternal(vshControl *ctl,
/*
* vshCommandOptUL:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -862,7 +928,7 @@ vshCommandOptUL(vshControl *ctl, const vshCmd *cmd,
/**
* vshCommandOptULWrap:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -879,7 +945,7 @@ vshCommandOptULWrap(vshControl *ctl, const vshCmd *cmd,
/**
* vshCommandOptString:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -908,7 +974,7 @@ vshCommandOptString(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd,
/**
* vshCommandOptStringReq:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command structure
* @name option name
* @value result (updated to NULL or the option argument)
@@ -953,7 +1019,7 @@ vshCommandOptStringReq(vshControl *ctl,
/**
* vshCommandOptLongLong:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -1010,7 +1076,7 @@ vshCommandOptULongLongInternal(vshControl *ctl,
/**
* vshCommandOptULongLong:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -1027,7 +1093,7 @@ vshCommandOptULongLong(vshControl *ctl, const vshCmd *cmd,
/**
* vshCommandOptULongLongWrap:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -1044,7 +1110,7 @@ vshCommandOptULongLongWrap(vshControl *ctl, const vshCmd *cmd,
/**
* vshCommandOptScaledInt:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @name option name
* @value result
@@ -1100,7 +1166,7 @@ vshCommandOptBool(const vshCmd *cmd, const char *name)
/**
* vshCommandOptArgv:
- * @ctl virsh control structure
+ * @ctl virtshell control structure
* @cmd command reference
* @opt starting point for the search
*
@@ -1131,6 +1197,7 @@ vshCommandOptArgv(vshControl *ctl ATTRIBUTE_UNUSED, const vshCmd *cmd,
bool
vshCommandRun(vshControl *ctl, const vshCmd *cmd)
{
+ const vshClientHooks *hooks = ctl->hooks;
bool ret = true;
while (cmd) {
@@ -1802,7 +1869,7 @@ vshEventTimeout(int timer ATTRIBUTE_UNUSED,
/**
* vshEventStart:
- * @ctl virsh command struct
+ * @ctl vsh command struct
* @timeout_ms max wait time in milliseconds, or 0 for indefinite
*
* Set up a wait for a libvirt event. The wait can be canceled by
@@ -1842,7 +1909,7 @@ vshEventStart(vshControl *ctl, int timeout_ms)
/**
* vshEventDone:
- * @ctl virsh command struct
+ * @ctl vsh command struct
*
* Call this from an event callback to let the main thread quit
* blocking on further events.
@@ -1859,7 +1926,7 @@ vshEventDone(vshControl *ctl)
/**
* vshEventWait:
- * @ctl virsh command struct
+ * @ctl vsh command struct
*
* Call this in the main thread after calling vshEventStart() then
* registering for one or more events. This call will block until
@@ -1890,7 +1957,7 @@ vshEventWait(vshControl *ctl)
/**
* vshEventCleanup:
- * @ctl virsh command struct
+ * @ctl vsh control struct
*
* Call at the end of any function that has used vshEventStart(), to
* tear down any remaining SIGINT or timeout handlers.
@@ -1907,65 +1974,6 @@ vshEventCleanup(vshControl *ctl)
virEventUpdateTimeout(ctl->eventTimerId, -1);
}
-
-/*
- * Initialize debug settings.
- */
-void
-vshInitDebug(vshControl *ctl)
-{
- const char *debugEnv;
-
- if (ctl->debug == VSH_DEBUG_DEFAULT) {
- /* log level not set from commandline, check env variable */
- debugEnv = virGetEnvAllowSUID("VIRSH_DEBUG");
- if (debugEnv) {
- int debug;
- if (virStrToLong_i(debugEnv, NULL, 10, &debug) < 0 ||
- debug < VSH_ERR_DEBUG || debug > VSH_ERR_ERROR) {
- vshError(ctl, "%s",
- _("VIRSH_DEBUG not set with a valid numeric value"));
- } else {
- ctl->debug = debug;
- }
- }
- }
-
- if (ctl->logfile == NULL) {
- /* log file not set from cmdline */
- debugEnv = virGetEnvBlockSUID("VIRSH_LOG_FILE");
- if (debugEnv && *debugEnv) {
- ctl->logfile = vshStrdup(ctl, debugEnv);
- vshOpenLogFile(ctl);
- }
- }
-}
-
-
-/*
- * Initialize global data
- */
-int
-vshInit(vshControl *ctl,
- const vshClientHooks *clhooks,
- const vshCmdGrp *clgrps)
-{
- if (!clhooks || !clhooks->connHandler) {
- vshError(ctl, "%s", _("client hooks must not be NULL"));
- return -1;
- }
-
- if (!clgrps) {
- vshError(ctl, "%s", _("command groups must not be NULL"));
- return -1;
- }
-
- hooks = clhooks;
- cmdGroups = clgrps;
- vshInitDebug(ctl);
- return 0;
-}
-
#define LOGFILE_FLAGS (O_WRONLY | O_APPEND | O_CREAT | O_SYNC)
/**
@@ -2092,6 +2100,295 @@ vshCloseLogFile(vshControl *ctl)
}
}
+#ifndef WIN32
+static void
+vshPrintRaw(vshControl *ctl, ...)
+{
+ va_list ap;
+ char *key;
+
+ va_start(ap, ctl);
+ while ((key = va_arg(ap, char *)) != NULL)
+ vshPrint(ctl, "%s\r\n", key);
+ va_end(ap);
+}
+
+/**
+ * vshAskReedit:
+ * @msg: Question to ask user
+ *
+ * Ask user if he wants to return to previously
+ * edited file.
+ *
+ * Returns 'y' if he wants to
+ * 'n' if he doesn't want to
+ * 'i' if he wants to try defining it again while ignoring validation
+ * 'f' if he forcibly wants to
+ * -1 on error
+ * 0 otherwise
+ */
+int
+vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail)
+{
+ int c = -1;
+
+ if (!isatty(STDIN_FILENO))
+ return -1;
+
+ vshReportError(ctl);
+
+ if (vshTTYMakeRaw(ctl, false) < 0)
+ return -1;
+
+ while (true) {
+ vshPrint(ctl, "\r%s %s %s: ", msg, _("Try again?"),
+ relax_avail ? "[y,n,i,f,?]" : "[y,n,f,?]");
+ c = c_tolower(getchar());
+
+ if (c == '?') {
+ vshPrintRaw(ctl,
+ "",
+ _("y - yes, start editor again"),
+ _("n - no, throw away my changes"),
+ NULL);
+
+ if (relax_avail) {
+ vshPrintRaw(ctl,
+ _("i - turn off validation and try to redefine "
+ "again"),
+ NULL);
+ }
+
+ vshPrintRaw(ctl,
+ _("f - force, try to redefine again"),
+ _("? - print this help"),
+ NULL);
+ continue;
+ } else if (c == 'y' || c == 'n' || c == 'f' ||
+ (relax_avail && c == 'i')) {
+ break;
+ }
+ }
+
+ vshTTYRestore(ctl);
+
+ vshPrint(ctl, "\r\n");
+ return c;
+}
+#else /* WIN32 */
+int
+vshAskReedit(vshControl *ctl,
+ const char *msg ATTRIBUTE_UNUSED,
+ bool relax_avail ATTRIBUTE_UNUSED)
+{
+ vshDebug(ctl, VSH_ERR_WARNING, "%s", _("This function is not "
+ "supported on WIN32 platform"));
+ return 0;
+}
+#endif /* WIN32 */
+
+
+/* Common code for the edit / net-edit / pool-edit functions which follow. */
+char *
+vshEditWriteToTempFile(vshControl *ctl, const char *doc)
+{
+ char *ret;
+ const char *tmpdir;
+ int fd;
+ char ebuf[1024];
+
+ tmpdir = virGetEnvBlockSUID("TMPDIR");
+ if (!tmpdir) tmpdir = "/tmp";
+ if (virAsprintf(&ret, "%s/virshXXXXXX.xml", tmpdir) < 0) {
+ vshError(ctl, "%s", _("out of memory"));
+ return NULL;
+ }
+ fd = mkostemps(ret, 4, O_CLOEXEC);
+ if (fd == -1) {
+ vshError(ctl, _("mkostemps: failed to create temporary file: %s"),
+ virStrerror(errno, ebuf, sizeof(ebuf)));
+ VIR_FREE(ret);
+ return NULL;
+ }
+
+ if (safewrite(fd, doc, strlen(doc)) == -1) {
+ vshError(ctl, _("write: %s: failed to write to temporary file: %s"),
+ ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+ VIR_FORCE_CLOSE(fd);
+ unlink(ret);
+ VIR_FREE(ret);
+ return NULL;
+ }
+ if (VIR_CLOSE(fd) < 0) {
+ vshError(ctl, _("close: %s: failed to write or close temporary file: %s"),
+ ret, virStrerror(errno, ebuf, sizeof(ebuf)));
+ unlink(ret);
+ VIR_FREE(ret);
+ return NULL;
+ }
+
+ /* Temporary filename: caller frees. */
+ return ret;
+}
+
+/* Characters permitted in $EDITOR environment variable and temp filename. */
+#define ACCEPTED_CHARS \
+ "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-/_.:@"
+
+int
+vshEditFile(vshControl *ctl, const char *filename)
+{
+ const char *editor;
+ virCommandPtr cmd;
+ int ret = -1;
+ int outfd = STDOUT_FILENO;
+ int errfd = STDERR_FILENO;
+
+ editor = virGetEnvBlockSUID("VISUAL");
+ if (!editor)
+ editor = virGetEnvBlockSUID("EDITOR");
+ if (!editor)
+ editor = DEFAULT_EDITOR;
+
+ /* Check that filename doesn't contain shell meta-characters, and
+ * if it does, refuse to run. Follow the Unix conventions for
+ * EDITOR: the user can intentionally specify command options, so
+ * we don't protect any shell metacharacters there. Lots more
+ * than virsh will misbehave if EDITOR has bogus contents (which
+ * is why sudo scrubs it by default). Conversely, if the editor
+ * is safe, we can run it directly rather than wasting a shell.
+ */
+ if (strspn(editor, ACCEPTED_CHARS) != strlen(editor)) {
+ if (strspn(filename, ACCEPTED_CHARS) != strlen(filename)) {
+ vshError(ctl,
+ _("%s: temporary filename contains shell meta or other "
+ "unacceptable characters (is $TMPDIR wrong?)"),
+ filename);
+ return -1;
+ }
+ cmd = virCommandNewArgList("sh", "-c", NULL);
+ virCommandAddArgFormat(cmd, "%s %s", editor, filename);
+ } else {
+ cmd = virCommandNewArgList(editor, filename, NULL);
+ }
+
+ virCommandSetInputFD(cmd, STDIN_FILENO);
+ virCommandSetOutputFD(cmd, &outfd);
+ virCommandSetErrorFD(cmd, &errfd);
+ if (virCommandRunAsync(cmd, NULL) < 0 ||
+ virCommandWait(cmd, NULL) < 0) {
+ vshReportError(ctl);
+ goto cleanup;
+ }
+ ret = 0;
+
+ cleanup:
+ virCommandFree(cmd);
+ return ret;
+}
+
+char *
+vshEditReadBackFile(vshControl *ctl, const char *filename)
+{
+ char *ret;
+ char ebuf[1024];
+
+ if (virFileReadAll(filename, VSH_MAX_XML_FILE, &ret) == -1) {
+ vshError(ctl,
+ _("%s: failed to read temporary file: %s"),
+ filename, virStrerror(errno, ebuf, sizeof(ebuf)));
+ return NULL;
+ }
+ return ret;
+}
+
+
+/* Tree listing helpers. */
+
+static int
+vshTreePrintInternal(vshControl *ctl,
+ vshTreeLookup lookup,
+ void *opaque,
+ int num_devices,
+ int devid,
+ int lastdev,
+ bool root,
+ virBufferPtr indent)
+{
+ size_t i;
+ int nextlastdev = -1;
+ int ret = -1;
+ const char *dev = (lookup)(devid, false, opaque);
+
+ if (virBufferError(indent))
+ goto cleanup;
+
+ /* Print this device, with indent if not at root */
+ vshPrint(ctl, "%s%s%s\n", virBufferCurrentContent(indent),
+ root ? "" : "+- ", dev);
+
+ /* Update indent to show '|' or ' ' for child devices */
+ if (!root) {
+ virBufferAddChar(indent, devid == lastdev ? ' ' : '|');
+ virBufferAddChar(indent, ' ');
+ if (virBufferError(indent))
+ goto cleanup;
+ }
+
+ /* Determine the index of the last child device */
+ for (i = 0; i < num_devices; i++) {
+ const char *parent = (lookup)(i, true, opaque);
+
+ if (parent && STREQ(parent, dev))
+ nextlastdev = i;
+ }
+
+ /* If there is a child device, then print another blank line */
+ if (nextlastdev != -1)
+ vshPrint(ctl, "%s |\n", virBufferCurrentContent(indent));
+
+ /* Finally print all children */
+ virBufferAddLit(indent, " ");
+ if (virBufferError(indent))
+ goto cleanup;
+ for (i = 0; i < num_devices; i++) {
+ const char *parent = (lookup)(i, true, opaque);
+
+ if (parent && STREQ(parent, dev) &&
+ vshTreePrintInternal(ctl, lookup, opaque,
+ num_devices, i, nextlastdev,
+ false, indent) < 0)
+ goto cleanup;
+ }
+ virBufferTrim(indent, " ", -1);
+
+ /* If there was no child device, and we're the last in
+ * a list of devices, then print another blank line */
+ if (nextlastdev == -1 && devid == lastdev)
+ vshPrint(ctl, "%s\n", virBufferCurrentContent(indent));
+
+ if (!root)
+ virBufferTrim(indent, NULL, 2);
+ ret = 0;
+ cleanup:
+ return ret;
+}
+
+int
+vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
+ int num_devices, int devid)
+{
+ int ret;
+ virBuffer indent = VIR_BUFFER_INITIALIZER;
+
+ ret = vshTreePrintInternal(ctl, lookup, opaque, num_devices,
+ devid, devid, true, &indent);
+ if (ret < 0)
+ vshError(ctl, "%s", _("Failed to complete tree listing"));
+ virBufferFreeAndReset(&indent);
+ return ret;
+}
+
#if WITH_READLINE
/* -----------------
@@ -2211,9 +2508,9 @@ vshReadlineCompletion(const char *text, int start,
return matches;
}
-# define VIRSH_HISTSIZE_MAX 500000
+# define VIRTSHELL_HISTSIZE_MAX 500000
-int
+static int
vshReadlineInit(vshControl *ctl)
{
char *userdir = NULL;
@@ -2224,27 +2521,30 @@ vshReadlineInit(vshControl *ctl)
* Work around ancient readline 4.1 (hello Mac OS X),
* which declared it as 'char *' instead of 'const char *'.
*/
- rl_readline_name = (char *) "virsh";
+ rl_readline_name = (char *) "virtshell";
/* Tell the completer that we want a crack first. */
rl_attempted_completion_function = vshReadlineCompletion;
/* Limit the total size of the history buffer */
- if ((histsize_str = virGetEnvBlockSUID("VIRSH_HISTSIZE"))) {
+ if ((histsize_str = virGetEnvBlockSUID("VIRTSHELL_HISTSIZE"))) {
if (virStrToLong_i(histsize_str, NULL, 10, &max_history) < 0) {
- vshError(ctl, "%s", _("Bad $VIRSH_HISTSIZE value."));
+ vshError(ctl, "%s", _("Bad $VIRTSHELL_HISTSIZE value."));
VIR_FREE(userdir);
return -1;
- } else if (max_history > VIRSH_HISTSIZE_MAX || max_history < 0) {
- vshError(ctl, _("$VIRSH_HISTSIZE value should be between 0 and %d"),
- VIRSH_HISTSIZE_MAX);
+ } else if (max_history > VIRTSHELL_HISTSIZE_MAX || max_history < 0) {
+ vshError(ctl, _("$VIRTSHELL_HISTSIZE value should be between 0 "
+ "and %d"),
+ VIRTSHELL_HISTSIZE_MAX);
VIR_FREE(userdir);
return -1;
}
}
stifle_history(max_history);
- /* Prepare to read/write history from/to the $XDG_CACHE_HOME/virsh/history file */
+ /* Prepare to read/write history from/to the
+ * $XDG_CACHE_HOME/virtshell/history file
+ */
userdir = virGetUserCacheDirectory();
if (userdir == NULL) {
@@ -2252,7 +2552,7 @@ vshReadlineInit(vshControl *ctl)
return -1;
}
- if (virAsprintf(&ctl->historydir, "%s/virsh", userdir) < 0) {
+ if (virAsprintf(&ctl->historydir, "%s/virtshell", userdir) < 0) {
vshError(ctl, "%s", _("Out of memory"));
VIR_FREE(userdir);
return -1;
@@ -2271,7 +2571,7 @@ vshReadlineInit(vshControl *ctl)
return 0;
}
-void
+static void
vshReadlineDeinit(vshControl *ctl)
{
if (ctl->historyfile != NULL) {
@@ -2297,14 +2597,14 @@ vshReadline(vshControl *ctl ATTRIBUTE_UNUSED, const char *prompt)
#else /* !WITH_READLINE */
-int
+static int
vshReadlineInit(vshControl *ctl ATTRIBUTE_UNUSED)
{
/* empty */
return 0;
}
-void
+static void
vshReadlineDeinit(vshControl *ctl ATTRIBUTE_UNUSED)
{
/* empty */
@@ -2330,3 +2630,76 @@ vshReadline(vshControl *ctl, const char *prompt)
}
#endif /* !WITH_READLINE */
+
+/*
+ * Initialize debug settings.
+ */
+void
+vshInitDebug(vshControl *ctl)
+{
+ const char *debugEnv;
+
+ if (ctl->debug == VSH_DEBUG_DEFAULT) {
+ /* log level not set from commandline, check env variable */
+ debugEnv = virGetEnvAllowSUID("VSH_DEBUG");
+ if (debugEnv) {
+ int debug;
+ if (virStrToLong_i(debugEnv, NULL, 10, &debug) < 0 ||
+ debug < VSH_ERR_DEBUG || debug > VSH_ERR_ERROR) {
+ vshError(ctl, "%s",
+ _("VSH_DEBUG not set with a valid numeric value"));
+ } else {
+ ctl->debug = debug;
+ }
+ }
+ }
+
+ if (ctl->logfile == NULL) {
+ /* log file not set from cmdline */
+ debugEnv = virGetEnvBlockSUID("VSH_LOG_FILE");
+ if (debugEnv && *debugEnv) {
+ ctl->logfile = vshStrdup(ctl, debugEnv);
+ vshOpenLogFile(ctl);
+ }
+ }
+}
+
+
+/*
+ * Initialize global data
+ */
+int
+vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set)
+{
+ int ret = -1;
+
+ if (!ctl->hooks) {
+ vshError(ctl, "%s", _("client hooks cannot be NULL"));
+ goto error;
+ }
+
+ if (!groups && !set) {
+ vshError(ctl, "%s", _("command groups and command set "
+ "cannot both be NULL"));
+ goto error;
+ }
+
+ cmdGroups = groups;
+ cmdSet = set;
+ vshInitDebug(ctl);
+
+ if (ctl->imode && vshReadlineInit(ctl) < 0)
+ goto error;
+
+ ret = 0;
+ error:
+ return ret;
+}
+
+void
+vshDeinit(vshControl *ctl)
+{
+ if (ctl->imode)
+ vshReadlineDeinit(ctl);
+ vshCloseLogFile(ctl);
+}
diff --git a/tools/vsh.h b/tools/vsh.h
index 1ad0287..66c9c3b 100644
--- a/tools/vsh.h
+++ b/tools/vsh.h
@@ -40,7 +40,7 @@
# define VIR_FROM_THIS VIR_FROM_NONE
# define GETTIMEOFDAY(T) gettimeofday(T, NULL)
-
+# define VSH_MAX_XML_FILE (10*1024*1024)
# define VSH_MATCH(FLAG) (flags & (FLAG))
/**
@@ -221,6 +221,8 @@ struct _vshControl {
struct termios termattr; /* settings of the tty terminal */
# endif
bool istty; /* is the terminal a tty */
+
+ const vshClientHooks *hooks;/* mandatory client specific hooks */
void *privData; /* client specific data */
};
@@ -294,19 +296,10 @@ const vshCmdOpt *vshCommandOptArgv(vshControl *ctl, const vshCmd *cmd,
const vshCmdOpt *opt);
bool vshCommandArgvParse(vshControl *ctl, int nargs, char **argv);
-/* Filter flags for various vshCommandOpt*By() functions */
-typedef enum {
- VSH_BYID = (1 << 1),
- VSH_BYUUID = (1 << 2),
- VSH_BYNAME = (1 << 3),
- VSH_BYMAC = (1 << 4),
-} vshLookupByFlags;
-
void vshPrintExtra(vshControl *ctl, const char *format, ...)
ATTRIBUTE_FMT_PRINTF(2, 3);
-int vshInit(vshControl *ctl, const vshClientHooks *clhooks,
- const vshCmdGrp *clgrps)
- ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3);
+int vshInit(vshControl *ctl, const vshCmdGrp *groups, const vshCmdDef *set);
+void vshDeinit(vshControl *ctl);
void vshInitDebug(vshControl *ctl);
void vshDebug(vshControl *ctl, int level, const char *format, ...)
ATTRIBUTE_FMT_PRINTF(3, 4);
@@ -324,8 +317,15 @@ virTypedParameterPtr vshFindTypedParamByName(const char *name,
char *vshGetTypedParamValue(vshControl *ctl, virTypedParameterPtr item)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+double vshPrettyCapacity(unsigned long long val, const char **unit);
int vshStringToArray(const char *str, char ***array);
+/* Given an index, return either the name of that device (non-NULL) or
+ * of its parent (NULL if a root). */
+typedef const char * (*vshTreeLookup)(int devid, bool parent, void *opaque);
+int vshTreePrint(vshControl *ctl, vshTreeLookup lookup, void *opaque,
+ int num_devices, int devid);
+
/* error handling */
extern virErrorPtr last_error;
void vshErrorHandler(void *opaque, virErrorPtr error);
@@ -333,6 +333,12 @@ void vshReportError(vshControl *ctl);
void vshResetLibvirtError(void);
void vshSaveLibvirtError(void);
+/* file handling */
+char *vshEditWriteToTempFile(vshControl *ctl, const char *doc);
+int vshEditFile(vshControl *ctl, const char *filename);
+char *vshEditReadBackFile(vshControl *ctl, const char *filename);
+int vshAskReedit(vshControl *ctl, const char *msg, bool relax_avail);
+
/* terminal modifications */
bool vshTTYIsInterruptCharacter(vshControl *ctl, const char chr);
int vshTTYDisableInterrupt(vshControl *ctl);
@@ -355,8 +361,6 @@ int vshEventWait(vshControl *ctl);
/* readline */
char * vshReadline(vshControl *ctl, const char *prompt);
-int vshReadlineInit(vshControl *ctl);
-void vshReadlineDeinit(vshControl *ctl);
/* allocation wrappers */
void *_vshMalloc(vshControl *ctl, size_t sz, const char *filename, int line);
--
1.9.3
3
2
[libvirt] [frankschreuder@outlook.com: Fwd: Reproducible live disk detach bug]
by Richard W.M. Jones 10 Aug '15
by Richard W.M. Jones 10 Aug '15
10 Aug '15
Forwarding from Frank Schreuder who was having some issues
sending this to the mailing list.
----- Begin forwarded message -----
> Subject: Reproducible live disk detach bug
>
> Hey guys,
>
> I am currently running into a reproducible libvirt bug when I detach a
> disk from a running VM using libvirt 1.2.18 and qemu 2.3.0.
>
> I can attach a disk to a running VM without any problems.
> During the attach operation I don't create a disk alias name, which
> results in libvirt generating an unique alias.
> Using virsh dumpxml I get the following output(snippet):
>
> <disk type='file' device='disk'>
> <driver name='qemu' type='raw' cache='none'/>
> <source file='/var/local/mnt/test-storage/test-storage.raw'/>
> <backingStore/>
> <target dev='vde' bus='virtio'/>
> <iotune>
> <read_bytes_sec>94371840</read_bytes_sec>
> <write_bytes_sec>31457280</write_bytes_sec>
> <read_iops_sec>1000</read_iops_sec>
> <write_iops_sec>200</write_iops_sec>
> </iotune>
> <alias name='virtio-disk4'/>
> <address type='pci' domain='0x0000' bus='0x00' slot='0x09' function='0x0'/>
> </disk>
>
> As you can see, libvirt generates 'virtio-disk4' as an alias. But as
> soon as I try to detach the disk from the running VM, I will receive the
> following two errors in my libvirt log:
>
> 2015-08-06 10:48:59.943+0000: 11657: warning :
> qemuMonitorJSONHandleDeviceDeleted:939 : missing device in device
> deleted event
> 2015-08-06 10:48:59.945+0000: 11662: error :
> qemuMonitorTextDriveDel:2594 : operation failed: deleting
> drive-virtio-disk4 drive failed: 2015-08-06T10:48:59.945058Z Device
> 'drive-virtio-disk4' not found
>
> Apparently libvirt tries to detach the disk with a drive- prefix, which
> doesn't exist? The drive seems to detach correctly though.
>
> I hope somebody with more extensive knowledge about libvirt can help me
> solve this issue. If more information is needed, feel free to contact me.
>
> Thanks,
> Frank
----- End forwarded message -----
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-df lists disk usage of guests without needing to install any
software inside the virtual machine. Supports Linux and Windows.
http://people.redhat.com/~rjones/virt-df/
5
5