[libvirt] [PATCH] maint: Sort .gitignore
by Peter Krempa
Sorting of the .gitignore file was broken after the last addition. After
a clean build the scripts re-sort it making the working tree dirty.
---
Pushed under trivial rule.
---
.gitignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index 51d83a6..98ce398 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,3 @@
-.#*
*#*#
*.#*#
*.a
@@ -18,6 +17,7 @@
*.rej
*.s
*~
+.#*
.deps
.gdb_history
.git
--
1.7.12.4
12 years, 1 month
[libvirt] [PATCH] virsh: Remove --flags from nodesuspend
by Jiri Denemark
We always expose individual bits from flags as separate options rather
than exposing a raw flags options. Since virNodeSuspendForDuration does
not currently support any flags, the only way of using this --flags
options that would not fail is "--flags 0", which is equivalent to
omitting the option. Thus it is highly unlikely anyone would actually be
using it and removing it should be safe.
---
tools/virsh-host.c | 10 +---------
tools/virsh.pod | 2 +-
2 files changed, 2 insertions(+), 10 deletions(-)
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 0f9b3f3..2ea24ac 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -506,7 +506,6 @@ static const vshCmdOptDef opts_node_suspend[] = {
{"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("mem(Suspend-to-RAM), "
"disk(Suspend-to-Disk), hybrid(Hybrid-Suspend)")},
{"duration", VSH_OT_INT, VSH_OFLAG_REQ, N_("Suspend duration in seconds, at least 60")},
- {"flags", VSH_OT_INT, VSH_OFLAG_NONE, N_("Suspend flags, 0 for default")},
{NULL, 0, 0, NULL}
};
@@ -516,7 +515,6 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
const char *target = NULL;
unsigned int suspendTarget;
long long duration;
- unsigned int flags = 0;
if (vshCommandOptString(cmd, "target", &target) < 0) {
vshError(ctl, _("Invalid target argument"));
@@ -528,11 +526,6 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
return false;
}
- if (vshCommandOptUInt(cmd, "flags", &flags) < 0) {
- vshError(ctl, _("Invalid flags argument"));
- return false;
- }
-
if (STREQ(target, "mem"))
suspendTarget = VIR_NODE_SUSPEND_TARGET_MEM;
else if (STREQ(target, "disk"))
@@ -549,8 +542,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
return false;
}
- if (virNodeSuspendForDuration(ctl->conn, suspendTarget, duration,
- flags) < 0) {
+ if (virNodeSuspendForDuration(ctl->conn, suspendTarget, duration, 0) < 0) {
vshError(ctl, "%s", _("The host was not suspended"));
return false;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 76f32c2..321dbe3 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -294,7 +294,7 @@ statistics during 1 second.
Returns memory stats of the node.
If I<cell> is specified, this will prints specified cell statistics only.
-=item B<nodesuspend> [I<target>] [I<duration>] [I<flags>]
+=item B<nodesuspend> [I<target>] [I<duration>]
Puts the node (host machine) into a system-wide sleep state such as
Suspend-to-RAM, Suspend-to-Disk or Hybrid-Suspend and sets up a
--
1.7.12.4
12 years, 1 month
[libvirt] [PATCH] maint: ignore unsaved emacs files
by Eric Blake
I did a 'git add .', then realized that it ended up trying to
add the emacs lock file for a corresponding file that I had not
yet saved all my edits; thankfully I noticed it in time. Since
we already exclude other temporary files, this makes the most
sense for preventing such a mistake from actually hitting upstream.
* .gitignore: Add .#* to the exclude list.
---
If you don't like this patch, then I will be updating my local
.git/info/exclude file; I could understand someone wanting to
reject this patch on the grounds that 'make' does not create
any temporary files under this name, but only my choice of
editor (and not everyone shares that choice in editor). So
I'll wait for an ack instead of claiming the trivial rule.
.gitignore | 1 +
1 file changed, 1 insertion(+)
diff --git a/.gitignore b/.gitignore
index 804eda4..51d83a6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+.#*
*#*#
*.#*#
*.a
--
1.7.11.7
12 years, 1 month
[libvirt] [PATCHv3] virNodeGetCPUMap: Add python binding
by Viktor Mihajlovski
Added a method getCPUMap to virConnect.
It can be used as follows:
import libvirt
import sys
import os
conn = libvirt.openReadOnly(None)
if conn == None:
print 'Failed to open connection to the hypervisor'
sys.exit(1)
try:
(cpus, cpumap, online) = conn.getCPUMap(0)
except:
print 'Failed to extract the node cpu map information'
sys.exit(1)
print 'CPUs total %d, online %d' % (cpus, online)
print 'CPU map %s' % str(cpumap)
del conn
print "OK"
sys.exit(0)
Signed-off-by: Viktor Mihajlovski <mihajlov(a)linux.vnet.ibm.com>
---
Rework of patch 9/9 of initial virNodeGetCPUMap series.
squashed in Eric Blake's changes
added missing error handling
reordered return value processing
Note: The code is a bit verbose, e.g. the NULL checks,
but that seems to be the prevailing style here.
---
python/libvirt-override-api.xml | 6 +++
python/libvirt-override.c | 70 +++++++++++++++++++++++++++++++++++++++
2 files changed, 76 insertions(+), 0 deletions(-)
diff --git a/python/libvirt-override-api.xml b/python/libvirt-override-api.xml
index b76fb4e..e54701c 100644
--- a/python/libvirt-override-api.xml
+++ b/python/libvirt-override-api.xml
@@ -542,5 +542,11 @@
<arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
<arg name='flags' type='int' info='unused, always pass 0'/>
</function>
+ <function name='virNodeGetCPUMap' file='python'>
+ <info>Get node CPU information</info>
+ <return type='str *' info='(cpunum, online, cpumap) on success, None on error'/>
+ <arg name='conn' type='virConnectPtr' info='pointer to the hypervisor connection'/>
+ <arg name='flags' type='int' info='unused, pass 0'/>
+ </function>
</symbols>
</api>
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 83dc925..0609803 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -6397,6 +6397,75 @@ cleanup:
return ret;
}
+static PyObject *
+libvirt_virNodeGetCPUMap(PyObject *self ATTRIBUTE_UNUSED,
+ PyObject *args)
+{
+ virConnectPtr conn;
+ PyObject *pyobj_conn;
+ PyObject *ret = NULL;
+ PyObject *pycpumap = NULL;
+ PyObject *pyused = NULL;
+ PyObject *pycpunum = NULL;
+ PyObject *pyonline = NULL;
+ int i_retval;
+ unsigned char *cpumap = NULL;
+ unsigned int online = 0;
+ unsigned int flags;
+ int i;
+
+ if (!PyArg_ParseTuple(args, (char *)"Oi:virNodeGetCPUMap",
+ &pyobj_conn, &flags))
+ return NULL;
+ conn = (virConnectPtr) PyvirConnect_Get(pyobj_conn);
+
+ LIBVIRT_BEGIN_ALLOW_THREADS;
+ i_retval = virNodeGetCPUMap(conn, &cpumap, &online, flags);
+ LIBVIRT_END_ALLOW_THREADS;
+
+ if (i_retval < 0)
+ return VIR_PY_NONE;
+
+ if ((ret = PyTuple_New(3)) == NULL)
+ goto error;
+
+ /* 0: number of CPUs */
+ if ((pycpunum = PyLong_FromLong(i_retval)) == NULL ||
+ PyTuple_SetItem(ret, 0, pycpunum) < 0)
+ goto error;
+
+ /* 1: CPU map */
+ if ((pycpumap = PyList_New(i_retval)) == NULL)
+ goto error;
+
+ for (i = 0; i < i_retval; i++) {
+ if ((pyused = PyBool_FromLong(VIR_CPU_USED(cpumap, i))) == NULL)
+ goto error;
+ if (PyList_SetItem(pycpumap, i, pyused) < 0)
+ goto error;
+ }
+
+ if (PyTuple_SetItem(ret, 1, pycpumap) < 0)
+ goto error;
+
+ /* 2: number of online CPUs */
+ if((pyonline = PyLong_FromLong(online)) == NULL ||
+ PyTuple_SetItem(ret, 2, pyonline) < 0)
+ goto error;
+
+cleanup:
+ VIR_FREE(cpumap);
+ return ret;
+error:
+ Py_XDECREF(ret);
+ Py_XDECREF(pycpumap);
+ Py_XDECREF(pyused);
+ Py_XDECREF(pycpunum);
+ Py_XDECREF(pyonline);
+ ret = NULL;
+ goto cleanup;
+}
+
/************************************************************************
* *
@@ -6514,6 +6583,7 @@ static PyMethodDef libvirtMethods[] = {
{(char *) "virDomainGetDiskErrors", libvirt_virDomainGetDiskErrors, METH_VARARGS, NULL},
{(char *) "virNodeGetMemoryParameters", libvirt_virNodeGetMemoryParameters, METH_VARARGS, NULL},
{(char *) "virNodeSetMemoryParameters", libvirt_virNodeSetMemoryParameters, METH_VARARGS, NULL},
+ {(char *) "virNodeGetCPUMap", libvirt_virNodeGetCPUMap, METH_VARARGS, NULL},
{NULL, NULL, 0, NULL}
};
--
1.7.0.4
12 years, 1 month
[libvirt] [PATCHv2] snapshot: improve snapshot-list error message
by Eric Blake
https://bugzilla.redhat.com/show_bug.cgi?id=869100 mentioned some
confusion about 'virsh snapshot-list' errors. Clean up a
misleading error message, and add some documentation.
* tools/virsh-snapshot.c (cmdSnapshotList): Mention --current
rather than --from when appropriate.
* tools/virsh.pod (snapshot-list): Mention that the named starting
point is NOT part of the list except under --tree.
---
v2: This is my take at the problem; v1 was written by Osier:
https://www.redhat.com/archives/libvir-list/2012-October/msg01183.html
tools/virsh-snapshot.c | 2 ++
tools/virsh.pod | 4 +++-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c
index 53de2b3..1641f90 100644
--- a/tools/virsh-snapshot.c
+++ b/tools/virsh-snapshot.c
@@ -1197,6 +1197,8 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd)
}
if (from) {
vshError(ctl, "%s",
+ vshCommandOptBool(cmd, "current") ?
+ _("--roots and --current are mutually exclusive") :
_("--roots and --from are mutually exclusive"));
goto cleanup;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 76f32c2..372c5e9 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -2764,7 +2764,9 @@ start at the current snapshot. When used in isolation or with
I<--parent>, the list is limited to direct children unless
I<--descendants> is also present. When used with I<--tree>, the
use of I<--descendants> is implied. This option is not compatible
-with I<--roots>.
+with I<--roots>. Note that the starting point of I<--from> or
+I<--current> is not included in the list unless the I<--tree>
+option is also present.
If I<--leaves> is specified, the list will be filtered to just
snapshots that have no children. Likewise, if I<--no-leaves> is
--
1.7.11.7
12 years, 1 month
[libvirt] [PATCH v2] tools: Only install guests init script if --with-init=script=redhat
by Cole Robinson
Most of this deals with moving the libvirt-guests.sh script which
does all the work to /usr/libexec, so it can be shared by both
systemd and traditional init. Previously systemd depended on
the script being in /etc/init.d
Required to fix https://bugzilla.redhat.com/show_bug.cgi?id=789747
---
v2:
Break out common functionality, move to /usr/libexec/libvirt-guests.sh
.gitignore | 1 +
libvirt.spec.in | 6 +-
po/POTFILES.in | 2 +-
tools/Makefile.am | 18 +-
tools/libvirt-guests.init.in | 27 ++
tools/libvirt-guests.init.sh | 597 ----------------------------------------
tools/libvirt-guests.service.in | 4 +-
tools/libvirt-guests.sh.in | 573 ++++++++++++++++++++++++++++++++++++++
8 files changed, 620 insertions(+), 608 deletions(-)
create mode 100644 tools/libvirt-guests.init.in
delete mode 100644 tools/libvirt-guests.init.sh
create mode 100644 tools/libvirt-guests.sh.in
diff --git a/.gitignore b/.gitignore
index 804eda4..1f1b26f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -177,6 +177,7 @@
/tools/*.[18]
/tools/libvirt-guests.init
/tools/libvirt-guests.service
+/tools/libvirt-guests.sh
/tools/virsh
/tools/virsh-*-edit.c
/tools/virt-*-validate
diff --git a/libvirt.spec.in b/libvirt.spec.in
index ebebfab..d701977 100644
--- a/libvirt.spec.in
+++ b/libvirt.spec.in
@@ -1380,8 +1380,6 @@ rm -rf $RPM_BUILD_ROOT%{_sysconfdir}/logrotate.d/libvirtd.uml
mv $RPM_BUILD_ROOT%{_datadir}/doc/libvirt-%{version} \
$RPM_BUILD_ROOT%{_datadir}/doc/libvirt-docs-%{version}
-sed -i -e "s|$RPM_BUILD_ROOT||g" $RPM_BUILD_ROOT%{_sysconfdir}/rc.d/init.d/libvirt-guests
-
%if %{with_dtrace}
%ifarch %{power64} s390x x86_64 ia64 alpha sparc64
mv $RPM_BUILD_ROOT%{_datadir}/systemtap/tapset/libvirt_probes.stp \
@@ -1600,10 +1598,13 @@ fi
%dir %attr(0700, root, root) %{_sysconfdir}/libvirt/nwfilter/
+%attr(0755, root, root) %{_libexecdir}/libvirt-guests.sh
%if %{with_systemd}
%{_unitdir}/libvirtd.service
+%{_unitdir}/libvirt-guests.service
%else
%{_sysconfdir}/rc.d/init.d/libvirtd
+%{_sysconfdir}/rc.d/init.d/libvirt-guests
%endif
%doc daemon/libvirtd.upstart
%config(noreplace) %{_sysconfdir}/sysconfig/libvirtd
@@ -1865,7 +1866,6 @@ rm -f $RPM_BUILD_ROOT%{_sysconfdir}/sysctl.d/libvirtd
%{_datadir}/libvirt/cpu_map.xml
-%{_sysconfdir}/rc.d/init.d/libvirt-guests
%if %{with_systemd}
%{_unitdir}/libvirt-guests.service
%endif
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9768528..cbf5bc6 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -190,7 +190,7 @@ src/xenapi/xenapi_utils.c
src/xenxs/xen_sxpr.c
src/xenxs/xen_xm.c
tools/console.c
-tools/libvirt-guests.init.sh
+tools/libvirt-guests.sh.in
tools/virsh.c
tools/virsh-domain-monitor.c
tools/virsh-domain.c
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 0d7822d..281f010 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -41,6 +41,7 @@ DISTCLEANFILES =
bin_SCRIPTS = virt-xml-validate virt-pki-validate
bin_PROGRAMS = virsh virt-host-validate
+libexec_SCRIPTS = libvirt-guests.sh
if HAVE_SANLOCK
sbin_SCRIPTS = virt-sanlock-cleanup
@@ -177,7 +178,7 @@ uninstall-sysconfig:
rm -f $(DESTDIR)$(sysconfdir)/sysconfig/libvirt-guests
rmdir $(DESTDIR)$(sysconfdir)/sysconfig ||:
-EXTRA_DIST += libvirt-guests.init.sh
+EXTRA_DIST += libvirt-guests.sh.in libvirt-guests.init.in
install-initscript: libvirt-guests.init
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/rc.d/init.d
@@ -198,7 +199,7 @@ install-init:
uninstall-init:
endif # LIBVIRT_INIT_SCRIPT_RED_HAT
-libvirt-guests.init: libvirt-guests.init.sh $(top_builddir)/config.status
+libvirt-guests.sh: libvirt-guests.sh.in $(top_builddir)/config.status
$(AM_V_GEN)sed \
-e 's!\@PACKAGE\@!$(PACKAGE)!g' \
-e 's!\@bindir\@!$(bindir)!g' \
@@ -209,20 +210,26 @@ libvirt-guests.init: libvirt-guests.init.sh $(top_builddir)/config.status
< $< > $@-t && \
chmod a+x $@-t && \
mv $@-t $@
+BUILT_SOURCES += libvirt-guests.sh
+libvirt-guests.init: libvirt-guests.init.in libvirt-guests.sh
+ $(AM_V_GEN)sed \
+ -e 's!\@libexecdir\@!$(libexecdir)!g' \
+ < $< > $@-t && \
+ chmod a+x $@-t && \
+ mv $@-t $@
EXTRA_DIST += libvirt-guests.service.in
-
SYSTEMD_UNIT_DIR = /lib/systemd/system
if LIBVIRT_INIT_SCRIPT_SYSTEMD
-install-systemd: libvirt-guests.service install-initscript install-sysconfig
+install-systemd: libvirt-guests.service install-sysconfig libvirt-guests.sh
$(MKDIR_P) $(DESTDIR)$(SYSTEMD_UNIT_DIR)
$(INSTALL_DATA) libvirt-guests.service \
$(DESTDIR)$(SYSTEMD_UNIT_DIR)/libvirt-guests.service
-uninstall-systemd: uninstall-initscript uninstall-sysconfig
+uninstall-systemd: uninstall-sysconfig
rm -f $(DESTDIR)$(SYSTEMD_UNIT_DIR)/libvirt-guests.service
rmdir $(DESTDIR)$(SYSTEMD_UNIT_DIR) ||:
@@ -241,6 +248,7 @@ libvirt-guests.service: libvirt-guests.service.in $(top_builddir)/config.status
-e 's!\@localstatedir\@!$(localstatedir)!g' \
-e 's!\@sbindir\@!$(sbindir)!g' \
-e 's!\@sysconfdir\@!$(sysconfdir)!g' \
+ -e 's!\@libexecdir\@!$(libexecdir)!g' \
< $< > $@-t && \
chmod a+x $@-t && \
mv $@-t $@
diff --git a/tools/libvirt-guests.init.in b/tools/libvirt-guests.init.in
new file mode 100644
index 0000000..5f9a60e
--- /dev/null
+++ b/tools/libvirt-guests.init.in
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# the following is the LSB init header
+#
+### BEGIN INIT INFO
+# Provides: libvirt-guests
+# Required-Start: libvirtd
+# Required-Stop: libvirtd
+# Default-Start: 2 3 4 5
+# Default-Stop: 0 1 6
+# Short-Description: suspend/resume libvirt guests on shutdown/boot
+# Description: This is a script for suspending active libvirt guests
+# on shutdown and resuming them on next boot
+# See http://libvirt.org
+### END INIT INFO
+
+# the following is chkconfig init header
+#
+# libvirt-guests: suspend/resume libvirt guests on shutdown/boot
+#
+# chkconfig: 345 99 01
+# description: This is a script for suspending active libvirt guests \
+# on shutdown and resuming them on next boot \
+# See http://libvirt.org
+#
+
+exec @libexecdir(a)/libvirt-guests.sh "$@"
diff --git a/tools/libvirt-guests.init.sh b/tools/libvirt-guests.init.sh
deleted file mode 100644
index 99ef331..0000000
--- a/tools/libvirt-guests.init.sh
+++ /dev/null
@@ -1,597 +0,0 @@
-#!/bin/sh
-
-# the following is the LSB init header
-#
-### BEGIN INIT INFO
-# Provides: libvirt-guests
-# Required-Start: libvirtd
-# Required-Stop: libvirtd
-# Default-Start: 2 3 4 5
-# Default-Stop: 0 1 6
-# Short-Description: suspend/resume libvirt guests on shutdown/boot
-# Description: This is a script for suspending active libvirt guests
-# on shutdown and resuming them on next boot
-# See http://libvirt.org
-### END INIT INFO
-
-# the following is chkconfig init header
-#
-# libvirt-guests: suspend/resume libvirt guests on shutdown/boot
-#
-# chkconfig: 345 99 01
-# description: This is a script for suspending active libvirt guests \
-# on shutdown and resuming them on next boot \
-# See http://libvirt.org
-#
-
-sysconfdir="@sysconfdir@"
-localstatedir="@localstatedir@"
-libvirtd="@sbindir@"/libvirtd
-
-# Source function library.
-test ! -r "$sysconfdir"/rc.d/init.d/functions ||
- . "$sysconfdir"/rc.d/init.d/functions
-
-# Source gettext library.
-# Make sure this file is recognized as having translations: _("dummy")
-. "@bindir@"/gettext.sh
-
-export TEXTDOMAIN="@PACKAGE@" TEXTDOMAINDIR="@localedir@"
-
-URIS=default
-ON_BOOT=start
-ON_SHUTDOWN=suspend
-SHUTDOWN_TIMEOUT=300
-PARALLEL_SHUTDOWN=0
-START_DELAY=0
-BYPASS_CACHE=0
-
-test -f "$sysconfdir"/sysconfig/libvirt-guests &&
- . "$sysconfdir"/sysconfig/libvirt-guests
-
-LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
-VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
-
-RETVAL=0
-
-# retval COMMAND ARGUMENTS...
-# run command with arguments and convert non-zero return value to 1 and set
-# the global return variable
-retval() {
- "$@"
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- else
- return 0
- fi
-}
-
-# run_virsh URI ARGUMENTS...
-# start virsh and let it execute ARGUMENTS on URI
-# If URI is "default" virsh is called without the "-c" argument
-# (using libvirt's default connection)
-run_virsh() {
- uri=$1
- shift
-
- if [ "x$uri" = xdefault ]; then
- virsh "$@" </dev/null
- else
- virsh -c "$uri" "$@" </dev/null
- fi
-}
-
-# run_virsh_c URI ARGUMENTS
-# Same as "run_virsh" but the "C" locale is used instead of
-# the system's locale.
-run_virsh_c() {
- ( export LC_ALL=C; run_virsh "$@" )
-}
-
-# test_connect URI
-# check if URI is reachable
-test_connect()
-{
- uri=$1
-
- run_virsh "$uri" connect 2>/dev/null
- if [ $? -ne 0 ]; then
- eval_gettext "Can't connect to \$uri. Skipping."
- echo
- return 1
- fi
-}
-
-# list_guests URI PERSISTENT
-# List running guests on URI.
-# PERSISTENT argument options:
-# --persistent: list only persistent guests
-# --transient: list only transient guests
-# [none]: list both persistent and transient guests
-list_guests() {
- uri=$1
- persistent=$2
-
- list=$(run_virsh_c "$uri" list --uuid $persistent)
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- fi
-
- echo $list
-}
-
-# guest_name URI UUID
-# return name of guest UUID on URI
-guest_name() {
- uri=$1
- uuid=$2
-
- run_virsh "$uri" domname "$uuid" 2>/dev/null
-}
-
-# guest_is_on URI UUID
-# check if guest UUID on URI is running
-# Result is returned by variable "guest_running"
-guest_is_on() {
- uri=$1
- uuid=$2
-
- guest_running=false
- id=$(run_virsh "$uri" domid "$uuid")
- if [ $? -ne 0 ]; then
- RETVAL=1
- return 1
- fi
-
- [ -n "$id" ] && [ "x$id" != x- ] && guest_running=true
- return 0
-}
-
-# started
-# Create the startup lock file
-started() {
- touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
-}
-
-# start
-# Start or resume the guests
-start() {
- [ -f "$LISTFILE" ] || { started; return 0; }
-
- if [ "x$ON_BOOT" != xstart ]; then
- gettext "libvirt-guests is configured not to start any guests on boot"
- echo
- rm -f "$LISTFILE"
- started
- return 0
- fi
-
- isfirst=true
- bypass=
- test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache
- while read uri list; do
- configured=false
- set -f
- for confuri in $URIS; do
- set +f
- if [ "x$confuri" = "x$uri" ]; then
- configured=true
- break
- fi
- done
- set +f
- if ! "$configured"; then
- eval_gettext "Ignoring guests on \$uri URI"; echo
- continue
- fi
-
- test_connect "$uri" || continue
-
- eval_gettext "Resuming guests on \$uri URI..."; echo
- for guest in $list; do
- name=$(guest_name "$uri" "$guest")
- eval_gettext "Resuming guest \$name: "
- if guest_is_on "$uri" "$guest"; then
- if "$guest_running"; then
- gettext "already active"; echo
- else
- if "$isfirst"; then
- isfirst=false
- else
- sleep $START_DELAY
- fi
- retval run_virsh "$uri" start $bypass "$name" \
- >/dev/null && \
- gettext "done"; echo
- fi
- fi
- done
- done <"$LISTFILE"
-
- rm -f "$LISTFILE"
- started
-}
-
-# suspend_guest URI GUEST
-# Do a managed save on a GUEST on URI. This function returns after the guest
-# was saved.
-suspend_guest()
-{
- uri=$1
- guest=$2
-
- name=$(guest_name "$uri" "$guest")
- label=$(eval_gettext "Suspending \$name: ")
- bypass=
- slept=0
- test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache
- printf '%s...\n' "$label"
- run_virsh "$uri" managedsave $bypass "$guest" >/dev/null &
- virsh_pid=$!
- while true; do
- sleep 1
- kill -0 "$virsh_pid" >/dev/null 2>&1 || break
-
- slept=$(($slept + 1))
- if [ $(($slept % 5)) -eq 0 ]; then
- progress=$(run_virsh_c "$uri" domjobinfo "$guest" 2>/dev/null | \
- awk '/^Data processed:/{print $3, $4}')
- if [ -n "$progress" ]; then
- printf '%s%s\n' "$label" "$progress"
- else
- printf '%s%s\n' "$label" "..."
- fi
- fi
- done
- retval wait "$virsh_pid" && printf '%s%s\n' "$label" "$(gettext "done")"
-}
-
-# shutdown_guest URI GUEST
-# Start a ACPI shutdown of GUEST on URI. This function return after the quest
-# was successfully shutdown or the timeout defined by $SHUTDOWN_TIMEOUT expires.
-shutdown_guest()
-{
- uri=$1
- guest=$2
-
- name=$(guest_name "$uri" "$guest")
- eval_gettext "Starting shutdown on guest: \$name"
- echo
- retval run_virsh "$uri" shutdown "$guest" >/dev/null || return
- timeout=$SHUTDOWN_TIMEOUT
- check_timeout=false
- if [ $timeout -gt 0 ]; then
- check_timeout=true
- format=$(eval_gettext "Waiting for guest %s to shut down, %d seconds left\n")
- else
- slept=0
- format=$(eval_gettext "Waiting for guest %s to shut down\n")
- fi
- while ! $check_timeout || [ "$timeout" -gt 0 ]; do
- sleep 1
- guest_is_on "$uri" "$guest" || return
- "$guest_running" || break
-
- if $check_timeout; then
- if [ $(($timeout % 5)) -eq 0 ]; then
- printf "$format" "$name" "$timeout"
- fi
- timeout=$(($timeout - 1))
- else
- slept=$(($slept + 1))
- if [ $(($slept % 5)) -eq 0 ]; then
- printf "$format" "$name"
- fi
- fi
- done
-
- if guest_is_on "$uri" "$guest"; then
- if "$guest_running"; then
- eval_gettext "Shutdown of guest \$name failed to complete in time."
- else
- eval_gettext "Shutdown of guest \$name complete."
- fi
- fi
-}
-
-# shutdown_guest_async URI GUEST
-# Start a ACPI shutdown of GUEST on URI. This function returns after the command
-# was issued to libvirt to allow parallel shutdown.
-shutdown_guest_async()
-{
- uri=$1
- guest=$2
-
- name=$(guest_name "$uri" "$guest")
- eval_gettext "Starting shutdown on guest: \$name"
- echo
- retval run_virsh "$uri" shutdown "$guest" > /dev/null
-}
-
-# guest_count GUEST_LIST
-# Returns number of guests in GUEST_LIST
-guest_count()
-{
- set -- $1
- echo $#
-}
-
-# check_guests_shutdown URI GUESTS
-# check if shutdown is complete on guests in "GUESTS" and returns only
-# guests that are still shutting down
-check_guests_shutdown()
-{
- uri=$1
- guests=$2
-
- guests_up=
- for guest in $guests; do
- if ! guest_is_on "$uri" "$guest" >/dev/null 2>&1; then
- eval_gettext "Failed to determine state of guest: \$guest. Not tracking it anymore."
- echo
- continue
- fi
- if "$guest_running"; then
- guests_up="$guests_up $guest"
- fi
- done
- echo "$guests_up"
-}
-
-# print_guests_shutdown URI BEFORE AFTER
-# Checks for differences in the lists BEFORE and AFTER and prints
-# a shutdown complete notice for guests that have finished
-print_guests_shutdown()
-{
- uri=$1
- before=$2
- after=$3
-
- for guest in $before; do
- case " $after " in
- *" $guest "*) continue;;
- esac
-
- name=$(guest_name "$uri" "$guest")
- eval_gettext "Shutdown of guest \$name complete."
- echo
- done
-}
-
-# shutdown_guests_parallel URI GUESTS
-# Shutdown guests GUESTS on machine URI in parallel
-shutdown_guests_parallel()
-{
- uri=$1
- guests=$2
-
- on_shutdown=
- check_timeout=false
- timeout=$SHUTDOWN_TIMEOUT
- if [ $timeout -gt 0 ]; then
- check_timeout=true
- format=$(eval_gettext "Waiting for %d guests to shut down, %d seconds left\n")
- else
- slept=0
- format=$(eval_gettext "Waiting for %d guests to shut down\n")
- fi
- while [ -n "$on_shutdown" ] || [ -n "$guests" ]; do
- while [ -n "$guests" ] &&
- [ $(guest_count "$on_shutdown") -lt "$PARALLEL_SHUTDOWN" ]; do
- set -- $guests
- guest=$1
- shift
- guests=$*
- shutdown_guest_async "$uri" "$guest"
- on_shutdown="$on_shutdown $guest"
- done
- sleep 1
-
- set -- $guests
- guestcount=$#
- set -- $on_shutdown
- shutdowncount=$#
-
- if $check_timeout; then
- if [ $(($timeout % 5)) -eq 0 ]; then
- printf "$format" $(($guestcount + $shutdowncount)) "$timeout"
- fi
- timeout=$(($timeout - 1))
- if [ $timeout -le 0 ]; then
- eval_gettext "Timeout expired while shutting down domains"; echo
- RETVAL=1
- return
- fi
- else
- slept=$(($slept + 1))
- if [ $(($slept % 5)) -eq 0 ]; then
- printf "$format" $(($guestcount + $shutdowncount))
- fi
- fi
-
- on_shutdown_prev=$on_shutdown
- on_shutdown=$(check_guests_shutdown "$uri" "$on_shutdown")
- print_guests_shutdown "$uri" "$on_shutdown_prev" "$on_shutdown"
- done
-}
-
-# stop
-# Shutdown or save guests on the configured uris
-stop() {
- # last stop was not followed by start
- [ -f "$LISTFILE" ] && return 0
-
- suspending=true
- if [ "x$ON_SHUTDOWN" = xshutdown ]; then
- suspending=false
- if [ $SHUTDOWN_TIMEOUT -lt 0 ]; then
- gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0"
- echo
- RETVAL=6
- return
- fi
- fi
-
- : >"$LISTFILE"
- set -f
- for uri in $URIS; do
- set +f
-
- test_connect "$uri" || continue
-
- eval_gettext "Running guests on \$uri URI: "
-
- list=$(list_guests "$uri")
- if [ $? -eq 0 ]; then
- empty=true
- for uuid in $list; do
- "$empty" || printf ", "
- printf %s "$(guest_name "$uri" "$uuid")"
- empty=false
- done
-
- if "$empty"; then
- gettext "no running guests."
- fi
- echo
- fi
-
- if "$suspending"; then
- transient=$(list_guests "$uri" "--transient")
- if [ $? -eq 0 ]; then
- empty=true
- for uuid in $transient; do
- if "$empty"; then
- eval_gettext "Not suspending transient guests on URI: \$uri: "
- empty=false
- else
- printf ", "
- fi
- printf %s "$(guest_name "$uri" "$uuid")"
- done
- echo
- # reload domain list to contain only persistent guests
- list=$(list_guests "$uri" "--persistent")
- if [ $? -ne 0 ]; then
- eval_gettext "Failed to list persistent guests on \$uri"
- echo
- RETVAL=1
- set +f
- return
- fi
- else
- gettext "Failed to list transient guests"
- echo
- RETVAL=1
- set +f
- return
- fi
- fi
-
- if [ -n "$list" ]; then
- echo "$uri" "$list" >>"$LISTFILE"
- fi
- done
- set +f
-
- if [ -s "$LISTFILE" ]; then
- while read uri list; do
- if "$suspending"; then
- eval_gettext "Suspending guests on \$uri URI..."; echo
- else
- eval_gettext "Shutting down guests on \$uri URI..."; echo
- fi
-
- if [ "$PARALLEL_SHUTDOWN" -gt 1 ] &&
- ! "$suspending"; then
- shutdown_guests_parallel "$uri" "$list"
- else
- for guest in $list; do
- if "$suspending"; then
- suspend_guest "$uri" "$guest"
- else
- shutdown_guest "$uri" "$guest"
- fi
- done
- fi
- done <"$LISTFILE"
- else
- rm -f "$LISTFILE"
- fi
-
- rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
-}
-
-# gueststatus
-# List status of guests
-gueststatus() {
- set -f
- for uri in $URIS; do
- set +f
- echo "* $uri URI:"
- retval run_virsh "$uri" list || echo
- done
- set +f
-}
-
-# rh_status
-# Display current status: whether saved state exists, and whether start
-# has been executed. We cannot use status() from the functions library,
-# since there is no external daemon process matching this init script.
-rh_status() {
- if [ -f "$LISTFILE" ]; then
- gettext "stopped, with saved guests"; echo
- RETVAL=3
- else
- if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
- gettext "started"; echo
- else
- gettext "stopped, with no saved guests"; echo
- fi
- RETVAL=0
- fi
-}
-
-# usage [val]
-# Display usage string, then exit with VAL (defaults to 2).
-usage() {
- program_name=$0
- eval_gettext "Usage: \$program_name {start|stop|status|restart|"\
-"condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"; echo
- exit ${1-2}
-}
-
-# See how we were called.
-if test $# != 1; then
- usage
-fi
-case "$1" in
- --help)
- usage 0
- ;;
- start|stop|gueststatus)
- "$1"
- ;;
- restart)
- stop && start
- ;;
- condrestart|try-restart)
- [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ] && stop && start
- ;;
- reload|force-reload)
- # Nothing to do; we reread configuration on each invocation
- ;;
- status)
- rh_status
- ;;
- shutdown)
- ON_SHUTDOWN=shutdown
- stop
- ;;
- *)
- usage
- ;;
-esac
-exit $RETVAL
diff --git a/tools/libvirt-guests.service.in b/tools/libvirt-guests.service.in
index 0f0c41c..d41bf2b 100644
--- a/tools/libvirt-guests.service.in
+++ b/tools/libvirt-guests.service.in
@@ -6,8 +6,8 @@ After=syslog.target network.target
EnvironmentFile=-/etc/sysconfig/libvirt-guests
# Hack just call traditional service until we factor
# out the code
-ExecStart=/etc/init.d/libvirt-guests start
-ExecStop=/etc/init.d/libvirt-guests stop
+ExecStart=@libexecdir(a)/libvirt-guests.sh start
+ExecStop=@libexecdir(a)/libvirt-guests.sh stop
Type=oneshot
RemainAfterExit=yes
StandardOutput=journal+console
diff --git a/tools/libvirt-guests.sh.in b/tools/libvirt-guests.sh.in
new file mode 100644
index 0000000..1c9c46b
--- /dev/null
+++ b/tools/libvirt-guests.sh.in
@@ -0,0 +1,573 @@
+#!/bin/sh
+
+sysconfdir="@sysconfdir@"
+localstatedir="@localstatedir@"
+libvirtd="@sbindir@"/libvirtd
+
+# Source function library.
+test ! -r "$sysconfdir"/rc.d/init.d/functions ||
+ . "$sysconfdir"/rc.d/init.d/functions
+
+# Source gettext library.
+# Make sure this file is recognized as having translations: _("dummy")
+. "@bindir@"/gettext.sh
+
+export TEXTDOMAIN="@PACKAGE@" TEXTDOMAINDIR="@localedir@"
+
+URIS=default
+ON_BOOT=start
+ON_SHUTDOWN=suspend
+SHUTDOWN_TIMEOUT=300
+PARALLEL_SHUTDOWN=0
+START_DELAY=0
+BYPASS_CACHE=0
+
+test -f "$sysconfdir"/sysconfig/libvirt-guests &&
+ . "$sysconfdir"/sysconfig/libvirt-guests
+
+LISTFILE="$localstatedir"/lib/libvirt/libvirt-guests
+VAR_SUBSYS_LIBVIRT_GUESTS="$localstatedir"/lock/subsys/libvirt-guests
+
+RETVAL=0
+
+# retval COMMAND ARGUMENTS...
+# run command with arguments and convert non-zero return value to 1 and set
+# the global return variable
+retval() {
+ "$@"
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ else
+ return 0
+ fi
+}
+
+# run_virsh URI ARGUMENTS...
+# start virsh and let it execute ARGUMENTS on URI
+# If URI is "default" virsh is called without the "-c" argument
+# (using libvirt's default connection)
+run_virsh() {
+ uri=$1
+ shift
+
+ if [ "x$uri" = xdefault ]; then
+ virsh "$@" </dev/null
+ else
+ virsh -c "$uri" "$@" </dev/null
+ fi
+}
+
+# run_virsh_c URI ARGUMENTS
+# Same as "run_virsh" but the "C" locale is used instead of
+# the system's locale.
+run_virsh_c() {
+ ( export LC_ALL=C; run_virsh "$@" )
+}
+
+# test_connect URI
+# check if URI is reachable
+test_connect()
+{
+ uri=$1
+
+ run_virsh "$uri" connect 2>/dev/null
+ if [ $? -ne 0 ]; then
+ eval_gettext "Can't connect to \$uri. Skipping."
+ echo
+ return 1
+ fi
+}
+
+# list_guests URI PERSISTENT
+# List running guests on URI.
+# PERSISTENT argument options:
+# --persistent: list only persistent guests
+# --transient: list only transient guests
+# [none]: list both persistent and transient guests
+list_guests() {
+ uri=$1
+ persistent=$2
+
+ list=$(run_virsh_c "$uri" list --uuid $persistent)
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ fi
+
+ echo $list
+}
+
+# guest_name URI UUID
+# return name of guest UUID on URI
+guest_name() {
+ uri=$1
+ uuid=$2
+
+ run_virsh "$uri" domname "$uuid" 2>/dev/null
+}
+
+# guest_is_on URI UUID
+# check if guest UUID on URI is running
+# Result is returned by variable "guest_running"
+guest_is_on() {
+ uri=$1
+ uuid=$2
+
+ guest_running=false
+ id=$(run_virsh "$uri" domid "$uuid")
+ if [ $? -ne 0 ]; then
+ RETVAL=1
+ return 1
+ fi
+
+ [ -n "$id" ] && [ "x$id" != x- ] && guest_running=true
+ return 0
+}
+
+# started
+# Create the startup lock file
+started() {
+ touch "$VAR_SUBSYS_LIBVIRT_GUESTS"
+}
+
+# start
+# Start or resume the guests
+start() {
+ [ -f "$LISTFILE" ] || { started; return 0; }
+
+ if [ "x$ON_BOOT" != xstart ]; then
+ gettext "libvirt-guests is configured not to start any guests on boot"
+ echo
+ rm -f "$LISTFILE"
+ started
+ return 0
+ fi
+
+ isfirst=true
+ bypass=
+ test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache
+ while read uri list; do
+ configured=false
+ set -f
+ for confuri in $URIS; do
+ set +f
+ if [ "x$confuri" = "x$uri" ]; then
+ configured=true
+ break
+ fi
+ done
+ set +f
+ if ! "$configured"; then
+ eval_gettext "Ignoring guests on \$uri URI"; echo
+ continue
+ fi
+
+ test_connect "$uri" || continue
+
+ eval_gettext "Resuming guests on \$uri URI..."; echo
+ for guest in $list; do
+ name=$(guest_name "$uri" "$guest")
+ eval_gettext "Resuming guest \$name: "
+ if guest_is_on "$uri" "$guest"; then
+ if "$guest_running"; then
+ gettext "already active"; echo
+ else
+ if "$isfirst"; then
+ isfirst=false
+ else
+ sleep $START_DELAY
+ fi
+ retval run_virsh "$uri" start $bypass "$name" \
+ >/dev/null && \
+ gettext "done"; echo
+ fi
+ fi
+ done
+ done <"$LISTFILE"
+
+ rm -f "$LISTFILE"
+ started
+}
+
+# suspend_guest URI GUEST
+# Do a managed save on a GUEST on URI. This function returns after the guest
+# was saved.
+suspend_guest()
+{
+ uri=$1
+ guest=$2
+
+ name=$(guest_name "$uri" "$guest")
+ label=$(eval_gettext "Suspending \$name: ")
+ bypass=
+ slept=0
+ test "x$BYPASS_CACHE" = x0 || bypass=--bypass-cache
+ printf '%s...\n' "$label"
+ run_virsh "$uri" managedsave $bypass "$guest" >/dev/null &
+ virsh_pid=$!
+ while true; do
+ sleep 1
+ kill -0 "$virsh_pid" >/dev/null 2>&1 || break
+
+ slept=$(($slept + 1))
+ if [ $(($slept % 5)) -eq 0 ]; then
+ progress=$(run_virsh_c "$uri" domjobinfo "$guest" 2>/dev/null | \
+ awk '/^Data processed:/{print $3, $4}')
+ if [ -n "$progress" ]; then
+ printf '%s%s\n' "$label" "$progress"
+ else
+ printf '%s%s\n' "$label" "..."
+ fi
+ fi
+ done
+ retval wait "$virsh_pid" && printf '%s%s\n' "$label" "$(gettext "done")"
+}
+
+# shutdown_guest URI GUEST
+# Start a ACPI shutdown of GUEST on URI. This function return after the quest
+# was successfully shutdown or the timeout defined by $SHUTDOWN_TIMEOUT expires.
+shutdown_guest()
+{
+ uri=$1
+ guest=$2
+
+ name=$(guest_name "$uri" "$guest")
+ eval_gettext "Starting shutdown on guest: \$name"
+ echo
+ retval run_virsh "$uri" shutdown "$guest" >/dev/null || return
+ timeout=$SHUTDOWN_TIMEOUT
+ check_timeout=false
+ if [ $timeout -gt 0 ]; then
+ check_timeout=true
+ format=$(eval_gettext "Waiting for guest %s to shut down, %d seconds left\n")
+ else
+ slept=0
+ format=$(eval_gettext "Waiting for guest %s to shut down\n")
+ fi
+ while ! $check_timeout || [ "$timeout" -gt 0 ]; do
+ sleep 1
+ guest_is_on "$uri" "$guest" || return
+ "$guest_running" || break
+
+ if $check_timeout; then
+ if [ $(($timeout % 5)) -eq 0 ]; then
+ printf "$format" "$name" "$timeout"
+ fi
+ timeout=$(($timeout - 1))
+ else
+ slept=$(($slept + 1))
+ if [ $(($slept % 5)) -eq 0 ]; then
+ printf "$format" "$name"
+ fi
+ fi
+ done
+
+ if guest_is_on "$uri" "$guest"; then
+ if "$guest_running"; then
+ eval_gettext "Shutdown of guest \$name failed to complete in time."
+ else
+ eval_gettext "Shutdown of guest \$name complete."
+ fi
+ fi
+}
+
+# shutdown_guest_async URI GUEST
+# Start a ACPI shutdown of GUEST on URI. This function returns after the command
+# was issued to libvirt to allow parallel shutdown.
+shutdown_guest_async()
+{
+ uri=$1
+ guest=$2
+
+ name=$(guest_name "$uri" "$guest")
+ eval_gettext "Starting shutdown on guest: \$name"
+ echo
+ retval run_virsh "$uri" shutdown "$guest" > /dev/null
+}
+
+# guest_count GUEST_LIST
+# Returns number of guests in GUEST_LIST
+guest_count()
+{
+ set -- $1
+ echo $#
+}
+
+# check_guests_shutdown URI GUESTS
+# check if shutdown is complete on guests in "GUESTS" and returns only
+# guests that are still shutting down
+check_guests_shutdown()
+{
+ uri=$1
+ guests=$2
+
+ guests_up=
+ for guest in $guests; do
+ if ! guest_is_on "$uri" "$guest" >/dev/null 2>&1; then
+ eval_gettext "Failed to determine state of guest: \$guest. Not tracking it anymore."
+ echo
+ continue
+ fi
+ if "$guest_running"; then
+ guests_up="$guests_up $guest"
+ fi
+ done
+ echo "$guests_up"
+}
+
+# print_guests_shutdown URI BEFORE AFTER
+# Checks for differences in the lists BEFORE and AFTER and prints
+# a shutdown complete notice for guests that have finished
+print_guests_shutdown()
+{
+ uri=$1
+ before=$2
+ after=$3
+
+ for guest in $before; do
+ case " $after " in
+ *" $guest "*) continue;;
+ esac
+
+ name=$(guest_name "$uri" "$guest")
+ eval_gettext "Shutdown of guest \$name complete."
+ echo
+ done
+}
+
+# shutdown_guests_parallel URI GUESTS
+# Shutdown guests GUESTS on machine URI in parallel
+shutdown_guests_parallel()
+{
+ uri=$1
+ guests=$2
+
+ on_shutdown=
+ check_timeout=false
+ timeout=$SHUTDOWN_TIMEOUT
+ if [ $timeout -gt 0 ]; then
+ check_timeout=true
+ format=$(eval_gettext "Waiting for %d guests to shut down, %d seconds left\n")
+ else
+ slept=0
+ format=$(eval_gettext "Waiting for %d guests to shut down\n")
+ fi
+ while [ -n "$on_shutdown" ] || [ -n "$guests" ]; do
+ while [ -n "$guests" ] &&
+ [ $(guest_count "$on_shutdown") -lt "$PARALLEL_SHUTDOWN" ]; do
+ set -- $guests
+ guest=$1
+ shift
+ guests=$*
+ shutdown_guest_async "$uri" "$guest"
+ on_shutdown="$on_shutdown $guest"
+ done
+ sleep 1
+
+ set -- $guests
+ guestcount=$#
+ set -- $on_shutdown
+ shutdowncount=$#
+
+ if $check_timeout; then
+ if [ $(($timeout % 5)) -eq 0 ]; then
+ printf "$format" $(($guestcount + $shutdowncount)) "$timeout"
+ fi
+ timeout=$(($timeout - 1))
+ if [ $timeout -le 0 ]; then
+ eval_gettext "Timeout expired while shutting down domains"; echo
+ RETVAL=1
+ return
+ fi
+ else
+ slept=$(($slept + 1))
+ if [ $(($slept % 5)) -eq 0 ]; then
+ printf "$format" $(($guestcount + $shutdowncount))
+ fi
+ fi
+
+ on_shutdown_prev=$on_shutdown
+ on_shutdown=$(check_guests_shutdown "$uri" "$on_shutdown")
+ print_guests_shutdown "$uri" "$on_shutdown_prev" "$on_shutdown"
+ done
+}
+
+# stop
+# Shutdown or save guests on the configured uris
+stop() {
+ # last stop was not followed by start
+ [ -f "$LISTFILE" ] && return 0
+
+ suspending=true
+ if [ "x$ON_SHUTDOWN" = xshutdown ]; then
+ suspending=false
+ if [ $SHUTDOWN_TIMEOUT -lt 0 ]; then
+ gettext "SHUTDOWN_TIMEOUT must be equal or greater than 0"
+ echo
+ RETVAL=6
+ return
+ fi
+ fi
+
+ : >"$LISTFILE"
+ set -f
+ for uri in $URIS; do
+ set +f
+
+ test_connect "$uri" || continue
+
+ eval_gettext "Running guests on \$uri URI: "
+
+ list=$(list_guests "$uri")
+ if [ $? -eq 0 ]; then
+ empty=true
+ for uuid in $list; do
+ "$empty" || printf ", "
+ printf %s "$(guest_name "$uri" "$uuid")"
+ empty=false
+ done
+
+ if "$empty"; then
+ gettext "no running guests."
+ fi
+ echo
+ fi
+
+ if "$suspending"; then
+ transient=$(list_guests "$uri" "--transient")
+ if [ $? -eq 0 ]; then
+ empty=true
+ for uuid in $transient; do
+ if "$empty"; then
+ eval_gettext "Not suspending transient guests on URI: \$uri: "
+ empty=false
+ else
+ printf ", "
+ fi
+ printf %s "$(guest_name "$uri" "$uuid")"
+ done
+ echo
+ # reload domain list to contain only persistent guests
+ list=$(list_guests "$uri" "--persistent")
+ if [ $? -ne 0 ]; then
+ eval_gettext "Failed to list persistent guests on \$uri"
+ echo
+ RETVAL=1
+ set +f
+ return
+ fi
+ else
+ gettext "Failed to list transient guests"
+ echo
+ RETVAL=1
+ set +f
+ return
+ fi
+ fi
+
+ if [ -n "$list" ]; then
+ echo "$uri" "$list" >>"$LISTFILE"
+ fi
+ done
+ set +f
+
+ if [ -s "$LISTFILE" ]; then
+ while read uri list; do
+ if "$suspending"; then
+ eval_gettext "Suspending guests on \$uri URI..."; echo
+ else
+ eval_gettext "Shutting down guests on \$uri URI..."; echo
+ fi
+
+ if [ "$PARALLEL_SHUTDOWN" -gt 1 ] &&
+ ! "$suspending"; then
+ shutdown_guests_parallel "$uri" "$list"
+ else
+ for guest in $list; do
+ if "$suspending"; then
+ suspend_guest "$uri" "$guest"
+ else
+ shutdown_guest "$uri" "$guest"
+ fi
+ done
+ fi
+ done <"$LISTFILE"
+ else
+ rm -f "$LISTFILE"
+ fi
+
+ rm -f "$VAR_SUBSYS_LIBVIRT_GUESTS"
+}
+
+# gueststatus
+# List status of guests
+gueststatus() {
+ set -f
+ for uri in $URIS; do
+ set +f
+ echo "* $uri URI:"
+ retval run_virsh "$uri" list || echo
+ done
+ set +f
+}
+
+# rh_status
+# Display current status: whether saved state exists, and whether start
+# has been executed. We cannot use status() from the functions library,
+# since there is no external daemon process matching this init script.
+rh_status() {
+ if [ -f "$LISTFILE" ]; then
+ gettext "stopped, with saved guests"; echo
+ RETVAL=3
+ else
+ if [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ]; then
+ gettext "started"; echo
+ else
+ gettext "stopped, with no saved guests"; echo
+ fi
+ RETVAL=0
+ fi
+}
+
+# usage [val]
+# Display usage string, then exit with VAL (defaults to 2).
+usage() {
+ program_name=$0
+ eval_gettext "Usage: \$program_name {start|stop|status|restart|"\
+"condrestart|try-restart|reload|force-reload|gueststatus|shutdown}"; echo
+ exit ${1-2}
+}
+
+# See how we were called.
+if test $# != 1; then
+ usage
+fi
+case "$1" in
+ --help)
+ usage 0
+ ;;
+ start|stop|gueststatus)
+ "$1"
+ ;;
+ restart)
+ stop && start
+ ;;
+ condrestart|try-restart)
+ [ -f "$VAR_SUBSYS_LIBVIRT_GUESTS" ] && stop && start
+ ;;
+ reload|force-reload)
+ # Nothing to do; we reread configuration on each invocation
+ ;;
+ status)
+ rh_status
+ ;;
+ shutdown)
+ ON_SHUTDOWN=shutdown
+ stop
+ ;;
+ *)
+ usage
+ ;;
+esac
+exit $RETVAL
--
1.7.11.7
12 years, 1 month
[libvirt] [PATCH] network: fix networkValidate check for default portgroup and vlan
by Laine Stump
This was found during testing of the fix for:
https://bugzilla.redhat.com/show_bug.cgi?id=868483
networkValidate was supposed to check for the existence of multiple
portgroups and report an error if this was encountered. It did, but
there were two problems:
1) even though it logged an error, it still returned success, allowing
the operation to continue.
2) It could exit the portgroup checking loop early (or possibly not
even do it once) if a vlan tag was supplied in the base network config
or one of the portgroups.
This patch fixes networkValidate to return failure in addition to
logging the error, and also changes it to not exit the portgroup
checking loop early. The logic was a bit off in the checking for vlan
anyway, and it's intertwined with fixing the early loop exit, so I
fixed that as well. Now it correctly checks for combinations where a
<virtualport> is specified in the base network def and <vlan> is given
in a portgroup, as well as the opposite (<vlan> in base network def
and <virtualport> in portgroup), and ignores the case of a disallowed
vlan when using *no* portgroup if there is a default portgroup (since
in that case there is no way to not use any portgroup).
---
src/network/bridge_driver.c | 42 +++++++++++++++++++++++++++++-------------
1 file changed, 29 insertions(+), 13 deletions(-)
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 8837843..f814f6f 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -2617,8 +2617,8 @@ static int
networkValidate(virNetworkDefPtr def)
{
int ii;
- bool vlanUsed, vlanAllowed;
- const char *defaultPortGroup = NULL;
+ bool vlanUsed, vlanAllowed, badVlanUse = false;
+ virPortGroupDefPtr defaultPortGroup = NULL;
/* The only type of networks that currently support transparent
* vlan configuration are those using hostdev sr-iov devices from
@@ -2630,14 +2630,23 @@ networkValidate(virNetworkDefPtr def)
def->virtPortProfile->virtPortType == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH);
vlanUsed = def->vlan.nTags > 0;
- for (ii = 0; ii < def->nPortGroups && !(vlanUsed && vlanAllowed); ii++) {
- if (def->portGroups[ii].vlan.nTags > 0)
- vlanUsed = true;
- if (def->forwardType == VIR_NETWORK_FORWARD_BRIDGE &&
- def->portGroups[ii].virtPortProfile &&
- (def->portGroups[ii].virtPortProfile->virtPortType
- == VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH)) {
- vlanAllowed = true;
+ for (ii = 0; ii < def->nPortGroups; ii++) {
+ if (vlanUsed || def->portGroups[ii].vlan.nTags > 0) {
+ /* anyone using this portgroup will get a vlan tag. Verify
+ * that they will also be using an openvswitch connection,
+ * as that is the only type of network that currently
+ * supports a vlan tag.
+ */
+ if (def->portGroups[ii].virtPortProfile) {
+ if (def->forwardType != VIR_NETWORK_FORWARD_BRIDGE ||
+ def->portGroups[ii].virtPortProfile->virtPortType
+ != VIR_NETDEV_VPORT_PROFILE_OPENVSWITCH) {
+ badVlanUse = true;
+ }
+ } else if (!vlanAllowed) {
+ /* virtualport taken from base network definition */
+ badVlanUse = true;
+ }
}
if (def->portGroups[ii].isDefault) {
if (defaultPortGroup) {
@@ -2645,13 +2654,20 @@ networkValidate(virNetworkDefPtr def)
_("network '%s' has multiple default "
"<portgroup> elements (%s and %s), "
"but only one default is allowed"),
- def->name, defaultPortGroup,
+ def->name, defaultPortGroup->name,
def->portGroups[ii].name);
+ return -1;
}
- defaultPortGroup = def->portGroups[ii].name;
+ defaultPortGroup = &def->portGroups[ii];
}
}
- if (vlanUsed && !vlanAllowed) {
+ if (badVlanUse ||
+ (vlanUsed && !vlanAllowed && !defaultPortGroup)) {
+ /* NB: if defaultPortGroup is set, we don't directly look at
+ * vlanUsed && !vlanAllowed, because the network will never be
+ * used without having a portgroup added in, so all necessary
+ * checks were done in the loop above.
+ */
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("<vlan> element specified for network %s, "
"whose type doesn't support vlan configuration"),
--
1.7.11.7
12 years, 1 month
[libvirt] [PATCHv3 0/4] implement virNodeGetCPUMap
by Eric Blake
This is the prerequisite patches I promised, plus v3 of patches
7-8 of 9 from Viktor's v2 series (1-6 are already committed,
and patch 9 for python bindings I'm leaving for Viktor to touch up).
Eric Blake (2):
bitmap: add virBitmapCountBits
nodeinfo: improve probing node cpu bitmap
Viktor Mihajlovski (2):
virNodeGetCPUMap: Implement support function in nodeinfo
virNodeGetCPUMap: Implement driver support
src/libvirt_private.syms | 4 +-
src/lxc/lxc_driver.c | 1 +
src/nodeinfo.c | 104 +++++++++++++++++++++++++++++++++------------
src/nodeinfo.h | 11 +++--
src/openvz/openvz_driver.c | 1 +
src/qemu/qemu_driver.c | 7 +--
src/test/test_driver.c | 31 ++++++++++++++
src/uml/uml_driver.c | 1 +
src/util/bitmap.c | 26 ++++++++++--
src/util/bitmap.h | 6 ++-
tests/virbitmaptest.c | 7 +++
11 files changed, 162 insertions(+), 37 deletions(-)
--
1.7.11.7
12 years, 1 month
[libvirt] [PATCH] maint: consistent whitespace after 'if'
by Eric Blake
Noticed during the review of the previous patch.
* python/libvirt-override.c: Use space between 'if ('.
---
Pushing under the trivial rule.
python/libvirt-override.c | 54 +++++++++++++++++++++++------------------------
1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 320f26a..cd48227 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -4405,13 +4405,13 @@ static PyObject *libvirt_dom_class = NULL;
static PyObject *
getLibvirtModuleObject (void) {
- if(libvirt_module)
+ if (libvirt_module)
return libvirt_module;
// PyImport_ImportModule returns a new reference
/* Bogus (char *) cast for RHEL-5 python API brokenness */
libvirt_module = PyImport_ImportModule((char *)"libvirt");
- if(!libvirt_module) {
+ if (!libvirt_module) {
DEBUG("%s Error importing libvirt module\n", __FUNCTION__);
PyErr_Print();
return NULL;
@@ -4422,12 +4422,12 @@ getLibvirtModuleObject (void) {
static PyObject *
getLibvirtDictObject (void) {
- if(libvirt_dict)
+ if (libvirt_dict)
return libvirt_dict;
// PyModule_GetDict returns a borrowed reference
libvirt_dict = PyModule_GetDict(getLibvirtModuleObject());
- if(!libvirt_dict) {
+ if (!libvirt_dict) {
DEBUG("%s Error importing libvirt dictionary\n", __FUNCTION__);
PyErr_Print();
return NULL;
@@ -4439,13 +4439,13 @@ getLibvirtDictObject (void) {
static PyObject *
getLibvirtDomainClassObject (void) {
- if(libvirt_dom_class)
+ if (libvirt_dom_class)
return libvirt_dom_class;
// PyDict_GetItemString returns a borrowed reference
libvirt_dom_class = PyDict_GetItemString(getLibvirtDictObject(),
"virDomain");
- if(!libvirt_dom_class) {
+ if (!libvirt_dom_class) {
DEBUG("%s Error importing virDomain class\n", __FUNCTION__);
PyErr_Print();
return NULL;
@@ -4506,18 +4506,18 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
virDomainRef(dom);
pyobj_dom = libvirt_virDomainPtrWrap(dom);
pyobj_dom_args = PyTuple_New(2);
- if(PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
+ if (PyTuple_SetItem(pyobj_dom_args, 0, pyobj_conn_inst)!=0) {
DEBUG("%s error creating tuple",__FUNCTION__);
goto cleanup;
}
- if(PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
+ if (PyTuple_SetItem(pyobj_dom_args, 1, pyobj_dom)!=0) {
DEBUG("%s error creating tuple",__FUNCTION__);
goto cleanup;
}
Py_INCREF(pyobj_conn_inst);
dom_class = getLibvirtDomainClassObject();
- if(!PyClass_Check(dom_class)) {
+ if (!PyClass_Check(dom_class)) {
DEBUG("%s dom_class is not a class!\n", __FUNCTION__);
goto cleanup;
}
@@ -4528,7 +4528,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
Py_DECREF(pyobj_dom_args);
- if(!pyobj_dom_inst) {
+ if (!pyobj_dom_inst) {
DEBUG("%s Error creating a python instance of virDomain\n",
__FUNCTION__);
PyErr_Print();
@@ -4545,7 +4545,7 @@ libvirt_virConnectDomainEventCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
Py_DECREF(pyobj_dom_inst);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -4973,7 +4973,7 @@ libvirt_virEventInvokeHandleCallback(PyObject *self ATTRIBUTE_UNUSED,
cb = (virEventHandleCallback) PyvirEventHandleCallback_Get(py_f);
opaque = (void *) PyvirVoidPtr_Get(py_opaque);
- if(cb) {
+ if (cb) {
LIBVIRT_BEGIN_ALLOW_THREADS;
cb (watch, fd, event, opaque);
LIBVIRT_END_ALLOW_THREADS;
@@ -5000,7 +5000,7 @@ libvirt_virEventInvokeTimeoutCallback(PyObject *self ATTRIBUTE_UNUSED,
cb = (virEventTimeoutCallback) PyvirEventTimeoutCallback_Get(py_f);
opaque = (void *) PyvirVoidPtr_Get(py_opaque);
- if(cb) {
+ if (cb) {
LIBVIRT_BEGIN_ALLOW_THREADS;
cb (timer, opaque);
LIBVIRT_END_ALLOW_THREADS;
@@ -5189,7 +5189,7 @@ libvirt_virConnectDomainEventLifecycleCallback(virConnectPtr conn ATTRIBUTE_UNUS
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5233,7 +5233,7 @@ libvirt_virConnectDomainEventGenericCallback(virConnectPtr conn ATTRIBUTE_UNUSED
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5280,7 +5280,7 @@ libvirt_virConnectDomainEventRTCChangeCallback(virConnectPtr conn ATTRIBUTE_UNUS
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5327,7 +5327,7 @@ libvirt_virConnectDomainEventWatchdogCallback(virConnectPtr conn ATTRIBUTE_UNUSE
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5376,7 +5376,7 @@ libvirt_virConnectDomainEventIOErrorCallback(virConnectPtr conn ATTRIBUTE_UNUSED
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5426,7 +5426,7 @@ libvirt_virConnectDomainEventIOErrorReasonCallback(virConnectPtr conn ATTRIBUTE_
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5513,7 +5513,7 @@ libvirt_virConnectDomainEventGraphicsCallback(virConnectPtr conn ATTRIBUTE_UNUSE
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5560,7 +5560,7 @@ libvirt_virConnectDomainEventBlockJobCallback(virConnectPtr conn ATTRIBUTE_UNUSE
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
#if DEBUG_ERROR
printf("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
#endif
@@ -5612,7 +5612,7 @@ libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5659,7 +5659,7 @@ libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5706,7 +5706,7 @@ libvirt_virConnectDomainEventPMWakeupCallback(virConnectPtr conn ATTRIBUTE_UNUSE
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5753,7 +5753,7 @@ libvirt_virConnectDomainEventPMSuspendCallback(virConnectPtr conn ATTRIBUTE_UNUS
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5800,7 +5800,7 @@ libvirt_virConnectDomainEventBalloonChangeCallback(virConnectPtr conn ATTRIBUTE_
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
@@ -5847,7 +5847,7 @@ libvirt_virConnectDomainEventPMSuspendDiskCallback(virConnectPtr conn ATTRIBUTE_
Py_DECREF(pyobj_cbData);
Py_DECREF(pyobj_dom);
- if(!pyobj_ret) {
+ if (!pyobj_ret) {
DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
PyErr_Print();
} else {
--
1.7.11.7
12 years, 1 month