[libvirt] [PATCH] spec: Use %make_install
by Cole Robinson
It's on RHEL7, saves a bit of typing, and lets us drop the comment
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
There's also a %make_build macro which handles smp_mflags, but it uses
make -O which makes build output noisier at least
libvirt.spec.in | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 4113579e47..01f4e07b1c 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1255,10 +1255,7 @@ rm -fr %{buildroot}
export SOURCE_DATE_EPOCH=$(stat --printf='%Y' %{_specdir}/%{name}.spec)
-# Avoid using makeinstall macro as it changes prefixes rather than setting
-# DESTDIR. Newer make_install macro would be better but it's not available
-# on RHEL 5, thus we need to expand it here.
-make %{?_smp_mflags} install DESTDIR=%{?buildroot} SYSTEMD_UNIT_DIR=%{_unitdir} V=1
+%make_install %{?_smp_mflags} SYSTEMD_UNIT_DIR=%{_unitdir} V=1
make %{?_smp_mflags} -C examples distclean V=1
--
2.17.1
6 years, 4 months
[libvirt] [PATCH] vircgroup: fix MinGW build
by Pavel Hrdina
Broken by commit <901d2b9c87>.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
Pushed under build-breaker rule.
src/util/vircgroup.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0ed83932ac..df38bb77e0 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4335,6 +4335,21 @@ virCgroupSetMemory(virCgroupPtr group ATTRIBUTE_UNUSED,
}
+int
+virCgroupGetMemoryStat(virCgroupPtr group ATTRIBUTE_UNUSED,
+ unsigned long long *cache ATTRIBUTE_UNUSED,
+ unsigned long long *activeAnon ATTRIBUTE_UNUSED,
+ unsigned long long *inactiveAnon ATTRIBUTE_UNUSED,
+ unsigned long long *activeFile ATTRIBUTE_UNUSED,
+ unsigned long long *inactiveFile ATTRIBUTE_UNUSED,
+ unsigned long long *unevictable ATTRIBUTE_UNUSED)
+{
+ virReportSystemError(ENOSYS, "%s",
+ _("Control groups not supported on this platform"));
+ return -1;
+}
+
+
int
virCgroupGetMemoryUsage(virCgroupPtr group ATTRIBUTE_UNUSED,
unsigned long *kb ATTRIBUTE_UNUSED)
--
2.17.1
6 years, 4 months
[libvirt] [PATCH 00/16] Revert Jansson usage
by Ján Tomko
For QEMU, we need a JSON parser that is able to handle its non-compliant
JSON usage:
https://bugzilla.redhat.com/show_bug.cgi?id=1614569
Unfortunately, this does not seem to be possible with Jansson.
Revert back to using yajl, which also lets us get rid of the 'dlopen'
hacks and their bugfixes.
(The QEMU default changes are not strictly required, but the patches
specifically use JANSSON)
Also available on:
git://repo.or.cz/libvirt/jtomko.git revert
Ján Tomko (16):
Revert "src: Move DLOPEN_LIBS to libraries introducing the dependency"
Revert "Fix link errors in tools/nss and tests"
Revert "remote: daemon: Make sure that JSON symbols are properly
loaded at startup"
Revert "util: jsoncompat: Stub out virJSONInitialize when compiling
without jansson"
Revert "tests: qemucapsprobe: Fix output after switching to jansson"
Revert "util: avoid symbol clash between json libraries"
Revert "tests: also skip qemuagenttest with old jansson"
Revert "m4: Introduce STABLE_ORDERING_JANSSON"
Revert "build: require Jansson if QEMU driver is enabled"
Revert "build: switch --with-qemu default from yes to check"
Revert "Remove virJSONValueNewStringLen"
Revert "build: remove references to WITH_YAJL for SETUID_RPC_CLIENT"
Revert "Remove functions using yajl"
Revert "Switch from yajl to Jansson"
Revert "build: undef WITH_JANSSON for SETUID_RPC_CLIENT"
Revert "build: add --with-jansson"
config-post.h | 3 +-
configure.ac | 3 -
libvirt.spec.in | 6 +-
m4/virt-driver-qemu.m4 | 9 +-
m4/virt-jansson.m4 | 32 --
m4/virt-nss.m4 | 4 +-
m4/virt-yajl.m4 | 27 +-
src/Makefile.am | 14 +-
src/libvirt_private.syms | 5 +-
src/qemu/qemu_driver.c | 2 +-
src/remote/remote_daemon.c | 4 -
src/util/Makefile.inc.am | 6 +-
src/util/virjson.c | 617 ++++++++++++++++++++++++-------
src/util/virjson.h | 1 +
src/util/virjsoncompat.c | 285 --------------
src/util/virjsoncompat.h | 88 -----
tests/Makefile.am | 12 +-
tests/cputest.c | 16 +-
tests/libxlxml2domconfigtest.c | 4 +-
tests/qemuagenttest.c | 4 +-
tests/qemublocktest.c | 6 -
tests/qemucapabilitiestest.c | 7 +-
tests/qemucaps2xmltest.c | 2 +-
tests/qemucapsprobemock.c | 2 -
tests/qemucommandutiltest.c | 7 +-
tests/qemuhotplugtest.c | 7 +-
tests/qemumigparamsdata/empty.json | 4 +-
tests/qemumigparamsdata/unsupported.json | 4 +-
tests/qemumigparamstest.c | 7 +-
tests/qemumonitorjsontest.c | 7 +-
tests/virjsontest.c | 5 -
tests/virmacmaptest.c | 5 -
tests/virmacmaptestdata/empty.json | 4 +-
tests/virmocklibxl.c | 4 +-
tests/virnetdaemontest.c | 7 +-
tests/virstoragetest.c | 4 +-
tools/Makefile.am | 6 +-
37 files changed, 557 insertions(+), 673 deletions(-)
delete mode 100644 m4/virt-jansson.m4
delete mode 100644 src/util/virjsoncompat.c
delete mode 100644 src/util/virjsoncompat.h
--
2.16.1
6 years, 4 months
[libvirt] [PATCH] qemu: Prefer nvdimmPath over hugepages for memory-backend-file
by Michal Privoznik
If a domain has hugepages configured and we're currently building
memory-backend-file for a nvdimm device that domain has we will
put hugepages path onto the command line. It should have been
nvdimm path configured in the XML.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_command.c | 10 ++--
.../hugepages-nvdimm.x86_64-latest.args | 38 ++++++++++++++
tests/qemuxml2argvdata/hugepages-nvdimm.xml | 59 ++++++++++++++++++++++
tests/qemuxml2argvtest.c | 1 +
tests/qemuxml2xmloutdata/hugepages-nvdimm.xml | 1 +
tests/qemuxml2xmltest.c | 1 +
6 files changed, 105 insertions(+), 5 deletions(-)
create mode 100644 tests/qemuxml2argvdata/hugepages-nvdimm.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/hugepages-nvdimm.xml
create mode 120000 tests/qemuxml2xmloutdata/hugepages-nvdimm.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a3fadc505d..ddb90895e0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3148,14 +3148,14 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
if (useHugepage || mem->nvdimmPath || memAccess ||
def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
- if (useHugepage) {
- if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) < 0)
- goto cleanup;
- prealloc = true;
- } else if (mem->nvdimmPath) {
+ if (mem->nvdimmPath) {
if (VIR_STRDUP(memPath, mem->nvdimmPath) < 0)
goto cleanup;
prealloc = true;
+ } else if (useHugepage) {
+ if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) < 0)
+ goto cleanup;
+ prealloc = true;
} else {
/* We can have both pagesize and mem source. If that's the case,
* prefer hugepages as those are more specific. */
diff --git a/tests/qemuxml2argvdata/hugepages-nvdimm.x86_64-latest.args b/tests/qemuxml2argvdata/hugepages-nvdimm.x86_64-latest.args
new file mode 100644
index 0000000000..3a6dd364da
--- /dev/null
+++ b/tests/qemuxml2argvdata/hugepages-nvdimm.x86_64-latest.args
@@ -0,0 +1,38 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/home/test \
+USER=test \
+LOGNAME=test \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-i686 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc,accel=tcg,usb=off,dump-guest-core=off,nvdimm=on \
+-m size=1048576k,slots=16,maxmem=1099511627776k \
+-realtime mlock=off \
+-smp 2,sockets=2,cores=1,threads=1 \
+-object memory-backend-file,id=ram-node0,prealloc=yes,\
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824 \
+-numa node,nodeid=0,cpus=0-1,memdev=ram-node0 \
+-object memory-backend-file,id=memnvdimm0,prealloc=yes,mem-path=/tmp/nvdimm,\
+share=yes,size=536870912 \
+-device nvdimm,node=0,memdev=memnvdimm0,id=nvdimm0,slot=0 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
+-device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/hugepages-nvdimm.xml b/tests/qemuxml2argvdata/hugepages-nvdimm.xml
new file mode 100644
index 0000000000..cdc409ff32
--- /dev/null
+++ b/tests/qemuxml2argvdata/hugepages-nvdimm.xml
@@ -0,0 +1,59 @@
+<domain type='qemu'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <maxMemory slots='16' unit='KiB'>1099511627776</maxMemory>
+ <memory unit='KiB'>1267710</memory>
+ <currentMemory unit='KiB'>1267710</currentMemory>
+ <memoryBacking>
+ <hugepages>
+ <page size='2048' unit='KiB'/>
+ </hugepages>
+ <access mode='shared'/>
+ </memoryBacking>
+ <vcpu placement='static' cpuset='0-1'>2</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu>
+ <topology sockets='2' cores='1' threads='1'/>
+ <numa>
+ <cell id='0' cpus='0-1' memory='1048576' unit='KiB'/>
+ </numa>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-i686</emulator>
+ <disk type='block' device='disk'>
+ <driver name='qemu' type='raw'/>
+ <source dev='/dev/HostVG/QEMUGuest1'/>
+ <target dev='hda' bus='ide'/>
+ <address type='drive' controller='0' bus='0' target='0' unit='0'/>
+ </disk>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <controller type='usb' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </memballoon>
+ <memory model='nvdimm'>
+ <source>
+ <path>/tmp/nvdimm</path>
+ </source>
+ <target>
+ <size unit='KiB'>523264</size>
+ <node>0</node>
+ </target>
+ <address type='dimm' slot='0'/>
+ </memory>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 96482a84a1..8a7b82a1f2 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -994,6 +994,7 @@ mymain(void)
DO_TEST_FAILURE("hugepages-memaccess3",
QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE,
QEMU_CAPS_VIRTIO_SCSI);
+ DO_TEST_CAPS_LATEST("hugepages-nvdimm");
DO_TEST("nosharepages", QEMU_CAPS_MEM_MERGE);
DO_TEST("disk-cdrom", NONE);
DO_TEST_CAPS_LATEST("disk-cdrom");
diff --git a/tests/qemuxml2xmloutdata/hugepages-nvdimm.xml b/tests/qemuxml2xmloutdata/hugepages-nvdimm.xml
new file mode 120000
index 0000000000..8288d3c58f
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/hugepages-nvdimm.xml
@@ -0,0 +1 @@
+../qemuxml2argvdata/hugepages-nvdimm.xml
\ No newline at end of file
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 7fe5043519..8e58c7b844 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -339,6 +339,7 @@ mymain(void)
DO_TEST("hugepages-shared", NONE);
DO_TEST("hugepages-memaccess", NONE);
DO_TEST("hugepages-memaccess2", NONE);
+ DO_TEST("hugepages-nvdimm", NONE);
DO_TEST("nosharepages", NONE);
DO_TEST("restore-v2", NONE);
DO_TEST("migrate", NONE);
--
2.16.4
6 years, 4 months
[libvirt] [PATCH] virsh: Add missed fields to pool-define-as item entry
by John Ferlan
Commit id d45bee449 updated the pool-define-as qualifier descriptions
to add some new fields, but neglected to modify the command item list
in order to add those fields as well.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
Discovered by QE while validating bz1601377.
tools/virsh.pod | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/tools/virsh.pod b/tools/virsh.pod
index a5e02c62cd..4e118851f8 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3831,7 +3831,9 @@ just I<--build> is provided, then B<pool-build> is called with no flags.
[I<--auth-type authtype> I<--auth-username username>
[I<--secret-usage usage> | I<--secret-uuid uuid>]]
[[I<--adapter-name name>] | [I<--adapter-wwnn> wwnn I<--adapter-wwpn> wwpn]
-[I<--adapter-parent parent>]]
+[I<--adapter-parent parent> |
+ I<--adapter-parent-wwnn parent_wwnn> I<adapter-parent-wwpn parent_wwpn> |
+ I<--adapter-parent-fabric-wwn parent_fabric_wwn>]]
[I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]] [I<--print-xml>]
--
2.17.1
6 years, 4 months
[libvirt] [PATCH] esx: Fix nodeGetInfo so cpu model fits inside nodeinfo->model
by Marcos Paulo de Souza
Commit 6c0d0210cbcd5d647f0d882c07f077d444bc707d changed the behavior of
virStr*cpy* functions, so now the nodeGetInfo call fails. Version 4.1.0
(default for Fedora 28) works:
Model: Intel Core i7-4500U CPU @ 1.80G
Current master tries to write "Intel Core i7-4500U CPU @ 1.80GHz", but
the string is bigger than nodeinfo->model (which is a char[32]). So this
patch "cuts" the string, and presents the same output from 4.1.0.
Signed-off-by: Marcos Paulo de Souza <marcos.souza.org(a)gmail.com>
---
When testing both qemu and lxc drivers, both return "x86_64", as both call
virCapabilitiesGetNodeInfo in order the get all info the "node", but they are a
Linux machine.
When it comes to ESX, it returns a string from the ESX server, which is same
info that I can find in /proc/cpuinfo of my machine (but without the () parts):
model name : Intel(R) Core(TM) i7-4500U CPU @ 1.80GHz
The question is: should libvirt increase the model size, or just find a better
way for ESX to present this info?
src/esx/esx_driver.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index c2154799fa..03a84d7630 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -1317,6 +1317,8 @@ esxNodeGetInfo(virConnectPtr conn, virNodeInfoPtr nodeinfo)
++ptr;
}
+ /* Make sure the string fits in mode */
+ dynamicProperty->val->string[sizeof(nodeinfo->model) - 1] = '\0';
if (virStrcpyStatic(nodeinfo->model, dynamicProperty->val->string) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("CPU Model %s too long for destination"),
--
2.17.1
6 years, 4 months
[libvirt] [PATCH] spec: Add libvirt-daemon-driver-storage-iscsi-direct
by Cole Robinson
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
libvirt.spec.in | 19 ++++++++++++++++++-
1 file changed, 18 insertions(+), 1 deletion(-)
diff --git a/libvirt.spec.in b/libvirt.spec.in
index 3edb60d2d2..09e69a9309 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -317,8 +317,10 @@ BuildRequires: /usr/bin/qemu-img
%endif
# For LVM drivers
BuildRequires: lvm2
-# For ISCSI driver
+# For pool type=iscsi
BuildRequires: iscsi-initiator-utils
+# For pool type=iscsi-direct
+BuildRequires: libiscsi
# For disk driver
BuildRequires: parted-devel
# For Multipath support
@@ -591,6 +593,16 @@ The storage driver backend adding implementation of the storage APIs for iscsi
volumes using the host iscsi stack.
+%package daemon-driver-storage-iscsi-direct
+Summary: Storage driver plugin for iscsi-direct
+Requires: libvirt-daemon-driver-storage-core = %{version}-%{release}
+Requires: libvirt-libs = %{version}-%{release}
+
+%description daemon-driver-storage-iscsi-direct
+The storage driver backend adding implementation of the storage APIs for iscsi
+volumes using libiscsi direct connection.
+
+
%package daemon-driver-storage-mpath
Summary: Storage driver plugin for multipath volumes
Requires: libvirt-daemon-driver-storage-core = %{version}-%{release}
@@ -667,6 +679,7 @@ Requires: libvirt-daemon-driver-storage-disk = %{version}-%{release}
Requires: libvirt-daemon-driver-storage-logical = %{version}-%{release}
Requires: libvirt-daemon-driver-storage-scsi = %{version}-%{release}
Requires: libvirt-daemon-driver-storage-iscsi = %{version}-%{release}
+Requires: libvirt-daemon-driver-storage-iscsi-direct = %{version}-%{release}
Requires: libvirt-daemon-driver-storage-mpath = %{version}-%{release}
%if %{with_storage_gluster}
Requires: libvirt-daemon-driver-storage-gluster = %{version}-%{release}
@@ -1174,6 +1187,7 @@ rm -f po/stamp-po
--with-storage-fs \
--with-storage-lvm \
--with-storage-iscsi \
+ --with-storage-iscsi-direct \
--with-storage-scsi \
--with-storage-disk \
--with-storage-mpath \
@@ -1639,6 +1653,9 @@ exit 0
%files daemon-driver-storage-iscsi
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_iscsi.so
+%files daemon-driver-storage-iscsi-direct
+%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_iscsi-direct.so
+
%files daemon-driver-storage-mpath
%{_libdir}/%{name}/storage-backend/libvirt_storage_backend_mpath.so
--
2.17.1
6 years, 4 months
[libvirt] [PATCH 1/2] Add API for printing tables.
by Simon Kobyda
It solves problems with alignment of columns. Width of each column
is calculated by its biggest cell. Should solve unicode bug.
In future, it may be implemented in virsh, virt-admin...
This API has 5 public functions:
- vshTableNew - adds new table and defines its header
- vshTableRowAppend - appends new row (for same number of columns as in
header)
- vshTablePrintToStdout
- vshTablePrintToString
- vshTableFree
https://bugzilla.redhat.com/show_bug.cgi?id=1574624
https://bugzilla.redhat.com/show_bug.cgi?id=1584630
Signed-off-by: Simon Kobyda <skobyda(a)redhat.com>
---
tools/Makefile.am | 4 +-
tools/vsh-table.c | 367 ++++++++++++++++++++++++++++++++++++++++++++++
tools/vsh-table.h | 42 ++++++
3 files changed, 412 insertions(+), 1 deletion(-)
create mode 100644 tools/vsh-table.c
create mode 100644 tools/vsh-table.h
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 26c887649e..ed23575aa7 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -144,7 +144,9 @@ libvirt_shell_la_LIBADD = \
$(READLINE_LIBS) \
../gnulib/lib/libgnu.la \
$(NULL)
-libvirt_shell_la_SOURCES = vsh.c vsh.h
+libvirt_shell_la_SOURCES = \
+ vsh.c vsh.h \
+ vsh-table.c vsh-table.h
virt_host_validate_SOURCES = \
virt-host-validate.c \
diff --git a/tools/vsh-table.c b/tools/vsh-table.c
new file mode 100644
index 0000000000..11dc807ba9
--- /dev/null
+++ b/tools/vsh-table.c
@@ -0,0 +1,367 @@
+/*
+ * vsh-table.c: table printing helper
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Simon Kobyda <skobyda(a)redhat.com>
+ *
+ */
+
+#include <config.h>
+#include "vsh-table.h"
+#include "virsh-util.h"
+
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+
+#include "viralloc.h"
+#include "virbuffer.h"
+#include "virstring.h"
+
+typedef void (*vshPrintCB)(vshControl *ctl, const char *fmt, ...);
+
+struct _vshTableRow {
+ char **cells;
+ size_t ncells;
+};
+
+struct _vshTable {
+ vshTableRowPtr *rows;
+ size_t nrows;
+};
+
+static void
+vshTableRowFree(vshTableRowPtr row)
+{
+ size_t i;
+
+ if (!row)
+ return;
+
+ for (i = 0; i < row->ncells; i++)
+ VIR_FREE(row->cells[i]);
+
+ VIR_FREE(row->cells);
+ VIR_FREE(row);
+}
+
+void
+vshTableFree(vshTablePtr table)
+{
+ size_t i;
+
+ if (!table)
+ return;
+
+ for (i = 0; i < table->nrows; i++)
+ vshTableRowFree(table->rows[i]);
+ VIR_FREE(table->rows);
+ VIR_FREE(table);
+}
+
+/**
+ * vshTableRowNew:
+ * @size: expected number of cells in row.
+ * @arg: the first argument.
+ * @ap: list of variadic arguments
+ *
+ * Creates a new row in the table. Each argument passed
+ * represents a cell in the row. If the number of cells is not
+ * equal to @size, then NULL is returned. However, if @size is
+ * equal to 0, the aforementioned check is suppressed.
+ *
+ * Returns: pointer to vshTableRowPtr row or NULL.
+ */
+static vshTableRowPtr
+vshTableRowNew(size_t size, const char *arg, va_list ap)
+{
+ vshTableRowPtr row = NULL;
+ char *tmp = NULL;
+
+ if (!arg) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Table row cannot be empty"));
+ goto error;
+ }
+
+ if (VIR_ALLOC(row) < 0)
+ goto error;
+
+ while (arg) {
+ if (VIR_STRDUP(tmp, arg) < 0)
+ goto error;
+
+ if (VIR_APPEND_ELEMENT(row->cells, row->ncells, tmp) < 0)
+ goto error;
+
+ arg = va_arg(ap, const char *);
+ }
+
+ if (size && row->ncells != size) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Incorrect number of cells in a table row"));
+ goto error;
+ }
+
+ return row;
+
+ error:
+ vshTableRowFree(row);
+ return NULL;
+}
+
+/**
+ * vshTableNew:
+ * @arg: List of column names (NULL terminated)
+ *
+ * Creates a new table.
+ *
+ * Returns: pointer to table or NULL.
+ */
+vshTablePtr
+vshTableNew(const char *arg, ...)
+{
+ vshTablePtr table;
+ vshTableRowPtr header = NULL;
+ va_list ap;
+
+ if (VIR_ALLOC(table) < 0)
+ goto error;
+
+ va_start(ap, arg);
+ header = vshTableRowNew(0, arg, ap);
+ va_end(ap);
+
+ if (!header)
+ goto error;
+
+ if (VIR_APPEND_ELEMENT(table->rows, table->nrows, header) < 0)
+ goto error;
+
+ return table;
+ error:
+ vshTableRowFree(header);
+ vshTableFree(table);
+ return NULL;
+}
+
+/**
+ * vshTableRowAppend:
+ * @table: table to append to
+ * @arg: cells of the row (NULL terminated)
+ *
+ * Appends new row into the @table. The number of cells in the row has
+ * to be equal to the number of cells in the table header.
+ *
+ * Returns: 0 if succeeded, -1 if failed.
+ */
+int
+vshTableRowAppend(vshTablePtr table, const char *arg, ...)
+{
+ vshTableRowPtr row = NULL;
+ size_t ncolumns = table->rows[0]->ncells;
+ va_list ap;
+ int ret = -1;
+
+ va_start(ap, arg);
+ row = vshTableRowNew(ncolumns, arg, ap);
+ va_end(ap);
+
+ if (!row)
+ goto cleanup;
+
+ if (VIR_APPEND_ELEMENT(table->rows, table->nrows, row) < 0)
+ goto cleanup;
+
+ ret = 0;
+ cleanup:
+ vshTableRowFree(row);
+ return ret;
+}
+
+/**
+ * vshTableGetColumnsWidths:
+ * @table: table
+ * @maxwidths: maximum count of characters for each columns
+ * @widths: count of characters for each cell in the table
+ *
+ * Fills passed @maxwidths and @widths arrays with maximum number
+ * of characters for columns and number of character per each
+ * table cell, respectively.
+ *
+ * Tries to handle unicode strings.
+ */
+static void
+vshTableGetColumnsWidths(vshTablePtr table,
+ size_t **maxwidths,
+ size_t ***widths)
+{
+ size_t i;
+ size_t j;
+
+ for (i = 0; i < table->nrows; i++) {
+ vshTableRowPtr row = table->rows[i];
+
+ for (j = 0; j < row->ncells; j++) {
+ size_t len;
+
+ len = mbstowcs(NULL, row->cells[j], 0);
+
+ if (len == (size_t) -1)
+ len = strlen(row->cells[j]);
+
+ (*widths)[i][j] = len;
+ if (len > (*maxwidths)[j])
+ (*maxwidths)[j] = len;
+ }
+ }
+}
+
+/**
+ * vshTableRowPrint:
+ * @ctl virtshell control structure
+ * @row: table to append to
+ * @maxwidths: maximum count of characters for each columns
+ * @widths: count of character for each cell in this row
+ * @printCB function for priting table
+ * @buf: buffer to store table (only if @toStdout == true)
+ * @toStdout: whetever print table to Stdout or return in buffer
+ */
+static void
+vshTableRowPrint(vshControl *ctl,
+ vshTableRowPtr row,
+ size_t *maxwidths,
+ size_t *widths,
+ vshPrintCB printCB,
+ virBufferPtr buf,
+ bool toStdout)
+{
+ size_t i;
+ size_t j;
+
+ if (toStdout) {
+ for (i = 0; i < row->ncells; i++) {
+ printCB(ctl, " %s", row->cells[i]);
+
+ for (j = 0; j < maxwidths[i] - widths[i] + 2; j++)
+ printCB(ctl, " ");
+ }
+ printCB(ctl, "\n");
+ } else {
+ for (i = 0; i < row->ncells; i++) {
+ virBufferAsprintf(buf, " %s", row->cells[i]);
+
+ for (j = 0; j < maxwidths[i] - widths[i] + 2; j++)
+ virBufferAddStr(buf, " ");
+ }
+ virBufferAddStr(buf, "\n");
+ }
+
+}
+
+/**
+ * vshTablePrint:
+ * @ctl virtshell control structure
+ * @table: table to print
+ * @toStdout: whetever to print to stdout (true) or return in string (false)
+ *
+ * Prints table. To get an alignment of columns right, function
+ * fills 2d array @widths with count of characters in each cell and
+ * array @maxwidths maximum count of character in each column.
+ * Function then prints tables header and content.
+ *
+ * Returns string containing table, or NULL if table was printed to
+ * stdout
+ */
+static char *
+vshTablePrint(vshControl *ctl, vshTablePtr table, bool toStdout)
+{
+ size_t i;
+ size_t j;
+ size_t *maxwidths;
+ size_t **widths;
+ virBuffer buf = VIR_BUFFER_INITIALIZER;
+ char *ret = NULL;
+
+ if (VIR_ALLOC_N(maxwidths, table->rows[0]->ncells))
+ goto cleanup;
+
+ if (VIR_ALLOC_N(widths, table->nrows))
+ goto cleanup;
+
+ /* retrieve widths of columns */
+ for (i = 0; i < table->nrows; i++) {
+ if (VIR_ALLOC_N(widths[i], table->rows[0]->ncells))
+ goto cleanup;
+ }
+
+ vshTableGetColumnsWidths(table, &maxwidths, &widths);
+
+ /* print header */
+ VIR_WARNINGS_NO_PRINTF
+ vshTableRowPrint(ctl, table->rows[0], maxwidths, widths[0],
+ vshPrintExtra, &buf, toStdout);
+ VIR_WARNINGS_RESET
+
+ /* print dividing line */
+ if (toStdout) {
+ for (i = 0; i < table->rows[0]->ncells; i++) {
+ for (j = 0; j < maxwidths[i] + 3; j++)
+ vshPrintExtra(ctl, "-");
+ }
+ vshPrintExtra(ctl, "\n");
+ } else {
+ for (i = 0; i < table->rows[0]->ncells; i++) {
+ for (j = 0; j < maxwidths[i] + 3; j++)
+ virBufferAddStr(&buf, "-");
+ }
+ virBufferAddStr(&buf, "\n");
+ }
+
+ /* print content */
+ for (i = 1; i < table->nrows; i++) {
+ VIR_WARNINGS_NO_PRINTF
+ vshTableRowPrint(ctl, table->rows[i], maxwidths, widths[0],
+ vshPrintExtra, &buf, toStdout);
+ VIR_WARNINGS_RESET
+ }
+
+ if (!toStdout)
+ ret = virBufferContentAndReset(&buf);
+
+ cleanup:
+ VIR_FREE(maxwidths);
+ for (i = 0; i < table->nrows; i++)
+ VIR_FREE(widths[i]);
+ VIR_FREE(widths);
+ return ret;
+}
+
+
+void
+vshTablePrintToStdout(vshControl *ctl, vshTablePtr table)
+{
+ vshTablePrint(ctl, table, true);
+}
+
+char *
+vshTablePrintToString(vshControl *ctl, vshTablePtr table)
+{
+ return vshTablePrint(ctl, table, false);
+}
diff --git a/tools/vsh-table.h b/tools/vsh-table.h
new file mode 100644
index 0000000000..41600fe06f
--- /dev/null
+++ b/tools/vsh-table.h
@@ -0,0 +1,42 @@
+/*
+ * vsh-table.h: table printing helper
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Simon Kobyda <skobyda(a)redhat.com>
+ *
+ */
+
+#ifndef VSH_TABLE_H
+# define VSH_TABLE_H
+
+# include "vsh.h"
+
+/* forward declarations */
+typedef struct _vshTable vshTable;
+typedef struct _vshTableRow vshTableRow;
+typedef vshTable *vshTablePtr;
+typedef vshTableRow *vshTableRowPtr;
+
+void vshTableFree(vshTablePtr table);
+vshTablePtr vshTableNew(const char *format, ...);
+int vshTableRowAppend(vshTablePtr table, const char *arg, ...);
+void vshTablePrintToStdout(vshControl *ctl, vshTablePtr table);
+char *vshTablePrintToString(vshControl *ctl, vshTablePtr table);
+
+#endif /* VSH_TABLE_H */
--
2.17.1
6 years, 4 months
[libvirt] [jenkins-ci PATCH 0/2] Don't build libvirt-dbus on Debian 8
by Andrea Bolognani
I thought that it would work, but I was clearly mistaken :/
Andrea Bolognani (2):
projects: Don't build libvirt-dbus on Debian 8
guests: Don't prepare Debian 8 for libvirt-dbus
guests/host_vars/libvirt-debian-8/main.yml | 1 -
projects/libvirt-dbus.yaml | 1 -
2 files changed, 2 deletions(-)
--
2.17.1
6 years, 4 months
[libvirt] [RFC 0/2] util: introduce timeout mode in virCommandRun/Async and virKModLoad
by Shi Lei
Hi, everyone!
It's possible that the running-time of a command is long than its caller
expected. Perhaps, it's useful to provide timeout mode for virCommandRun or
virCommandRunAsync + virCommandWait. And The caller can restrict the
running time of the command if necessary. I introduce a new function
virCommandSetTimeout for that.
And then, virKModLoad will get a default timeout of 3 seconds. I hope it
could solve the problem of "strange delay" as John mentioned.
Thanks!
Shi Lei (2):
introduce timeout mode in virCommandRun/Async
introduce timeout mode in virKModLoad
docs/internals/command.html.in | 68 +++++++
src/Makefile.am | 4 +-
src/libvirt_private.syms | 2 +
src/util/vircommand.c | 110 ++++++++++-
src/util/vircommand.h | 4 +
src/util/virkmod.c | 43 ++++-
src/util/virprocess.c | 107 ++++++++---
src/util/virprocess.h | 4 +
src/virt-command.conf | 10 +
tests/commandtest.c | 411 ++++++++++++++++++++++++++++++++++++++---
10 files changed, 706 insertions(+), 57 deletions(-)
create mode 100644 src/virt-command.conf
--
2.7.4
6 years, 4 months