[libvirt] [PATCH] Fix up "make check"
by Chris Lalancette
While running make check, I noticed that it was actually using
the virsh binary from my system, in /usr/bin/virsh, and not the
one that was just compiled. This is actually caused by a bug
in Makefile.am, where we didn't update the PATH to include tools.
While here, I also updated all of the scripts to properly define
the srcdir, abs_top_srcdir, and abs_top_builddir environment
variables. This is required if you want to be able to run the
tests standalone (i.e. ./test instead of from make check). I've
tested this on both RHEL-5 and Fedora-10 machines, and make check
works on both, as does running the individual tests by hand.
Signed-off-by: Chris Lalancette <clalance(a)redhat.com>
---
tests/Makefile.am | 2 +-
tests/cpuset | 12 ++++++++----
tests/daemon-conf | 18 +++++++++++-------
tests/define-dev-segfault | 10 ++++++----
tests/int-overflow | 20 ++++++++++----------
tests/libvirtd-fail | 10 ++++++----
tests/libvirtd-pool | 10 ++++++----
tests/read-bufsiz | 15 ++++++++-------
tests/read-non-seekable | 12 ++++++++----
tests/start | 10 ++++++----
tests/test_conf.sh | 14 ++++++++------
tests/undefine | 14 +++++++++-----
tests/vcpupin | 12 ++++++++----
tests/virsh-all | 12 +++++++-----
tests/virsh-synopsis | 11 +++++++----
15 files changed, 109 insertions(+), 73 deletions(-)
diff --git a/tests/Makefile.am b/tests/Makefile.am
index abda4ad..4caca8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -150,7 +150,7 @@ TESTS += nodedevxml2xmltest
TESTS += interfacexml2xmltest
-path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/daemon
+path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/daemon$(PATH_SEPARATOR)$$abs_top_builddir/tools
# NB, automake < 1.10 does not provide the real
# abs_top_{src/build}dir variables, so don't rely
diff --git a/tests/cpuset b/tests/cpuset
index eeb0ee2..9f43269 100755
--- a/tests/cpuset
+++ b/tests/cpuset
@@ -16,17 +16,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
fail=0
# generate input
-virsh --connect test:///default dumpxml 1 > xml || fail=1
+$abs_top_builddir/tools/virsh --connect test:///default dumpxml 1 > xml || fail=1
# require the presence of the string we'll transform
grep '<vcpu>' xml > /dev/null || fail=1
@@ -34,7 +38,7 @@ grep '<vcpu>' xml > /dev/null || fail=1
sed "s/vcpu>/vcpu cpuset='aaa'>/" xml > xml-invalid || fail=1
# Require failure and a diagnostic.
-virsh --connect test:///default define xml-invalid > out 2>&1 && fail=1
+$abs_top_builddir/tools/virsh --connect test:///default define xml-invalid > out 2>&1 && fail=1
cat <<\EOF > exp || fail=1
error: Failed to define domain from xml-invalid
error: failed Xen syscall topology cpuset syntax error
diff --git a/tests/daemon-conf b/tests/daemon-conf
index 071497e..722fe4e 100755
--- a/tests/daemon-conf
+++ b/tests/daemon-conf
@@ -1,16 +1,20 @@
#!/bin/sh
# Get coverage of libvirtd's config-parsing code.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- libvirtd --version
+ $abs_top_builddir/daemon/libvirtd --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
+
+test -z "$CONFIG_HEADER" && CONFIG_HEADER="$abs_top_builddir/config.h"
-grep '^#define WITH_QEMU 1' $CONFIG_HEADER > /dev/null ||
+grep '^#define WITH_QEMU 1' "$CONFIG_HEADER" > /dev/null ||
skip_test_ "configured without QEMU support"
conf="$abs_top_srcdir/daemon/libvirtd.conf"
@@ -40,7 +44,7 @@ while :; do
esac
# Run libvirtd, expecting it to fail.
- libvirtd --config=$f 2> err && fail=1
+ $abs_top_builddir/daemon/libvirtd --config=$f 2> err && fail=1
case $rhs in
# '"'*) msg='should be a string';;
@@ -73,7 +77,7 @@ sed 's,^log_outputs.*,log_outputs="3:file:'"$(pwd)/log"'",' tmp.conf > k \
mv k tmp.conf || fail=1
printf "running libvirtd with a valid config file ($sleep_secs seconds)\n" 1>&2
-libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$!
+$abs_top_builddir/daemon/libvirtd --pid-file=pid-file --config=tmp.conf > log 2>&1 & pid=$!
sleep $sleep_secs
kill $pid
diff --git a/tests/define-dev-segfault b/tests/define-dev-segfault
index 4ae286f..e0b953a 100755
--- a/tests/define-dev-segfault
+++ b/tests/define-dev-segfault
@@ -2,13 +2,15 @@
# Exercise a bug whereby defining a valid domain could kill libvirtd.
# The bug can also be exercised with a simple define/dumpxml pair to virsh.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
. "$srcdir/test-lib.sh"
fail=0
@@ -62,7 +64,7 @@ cat <<\EOF > D.xml || fail=1
EOF
url=test:///default
-virsh --connect "$url" 'define D.xml; dumpxml D' > out 2>&1 || fail=1
+$abs_top_builddir/tools/virsh --connect "$url" 'define D.xml; dumpxml D' > out 2>&1 || fail=1
cat > exp <<EOF || fail=1
Domain D defined from D.xml
diff --git a/tests/int-overflow b/tests/int-overflow
index ac3119b..c9f5de9 100755
--- a/tests/int-overflow
+++ b/tests/int-overflow
@@ -2,16 +2,16 @@
# Ensure that an invalid domain ID isn't interpreted as a valid one.
# Before, an ID of 2^32+2 would be treated just like an ID of 2.
-# Boilerplate code to set up a test directory, cd into it,
-# and to ensure we remove it upon completion.
-this_test_() { echo "./$0" | sed 's,.*/,,'; }
-t_=$(this_test_)-$$
-init_cwd_=$(pwd)
-trap 'st=$?; d='"$t_"';
- cd '"$init_cwd_"' && chmod -R u+rwx "$d" && rm -rf "$d" && exit $st' 0
-trap '(exit $?); exit $?' 1 2 13 15
-mkdir "$t_" || fail=1
-cd "$t_" || fail=1
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
+if test "$VERBOSE" = yes; then
+ set -x
+ $abs_top_builddir/tools/virsh --version
+fi
+
+. "$srcdir/test-lib.sh"
echo "error: failed to get domain '4294967298'" > exp || fail=1
echo domname 4294967298 | $abs_top_builddir/tools/virsh --quiet \
diff --git a/tests/libvirtd-fail b/tests/libvirtd-fail
index eeb1ee6..c6b6876 100755
--- a/tests/libvirtd-fail
+++ b/tests/libvirtd-fail
@@ -1,18 +1,20 @@
#!/bin/sh
# Ensure that libvirt fails when given nonexistent --config=FILE
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- libvirtd --version
+ $abs_top_builddir/daemon/libvirtd --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
. "$srcdir/test-lib.sh"
fail=0
-libvirtd --config=no-such-conf --timeout=5 2> log
+$abs_top_builddir/daemon/libvirtd --config=no-such-conf --timeout=5 2> log
RET=$?
test "$RET" != "0" && exit 0 || exit 1
diff --git a/tests/libvirtd-pool b/tests/libvirtd-pool
index 59da5a6..ca1db94 100755
--- a/tests/libvirtd-pool
+++ b/tests/libvirtd-pool
@@ -1,20 +1,22 @@
#!/bin/sh
# Get coverage of virsh pool-define-as XML formatting
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
. "$srcdir/test-lib.sh"
fail=0
pwd=$(pwd) || fail=1
-virsh --connect test:///default \
+$abs_top_builddir/tools/virsh --connect test:///default \
pool-define-as --print-xml \
P dir src-host /src/path /src/dev S /target-path \
1>out 2>&1
diff --git a/tests/read-bufsiz b/tests/read-bufsiz
index 7d53735..5baa7c5 100755
--- a/tests/read-bufsiz
+++ b/tests/read-bufsiz
@@ -16,20 +16,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=`pwd`
+test -z "$abs_top_srcdir" && abs_top_srcdir=`pwd`/..
+test -z "$abs_top_builddir" && abs_top_builddir=`pwd`/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=`pwd`
-test -z "$abs_top_srcdir" && abs_top_srcdir=`pwd`/..
-
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
fail=0
# Output a valid definition, to be used as input.
-virsh -c test:///default dumpxml 1 > xml || fail=1
+$abs_top_builddir/tools/virsh -c test:///default dumpxml 1 > xml || fail=1
for i in before after; do
# The largest BUFSIZ I've seen is 128K. This is slightly larger.
@@ -38,7 +39,7 @@ for i in before after; do
# Append or prepend enough spaces to push the size over the limit:
( test $i = before && cat sp xml || cat xml sp ) > $in || fail=1
- virsh --connect test:///default define $in > out || fail=1
+ $abs_top_builddir/tools/virsh --connect test:///default define $in > out || fail=1
printf "Domain test defined from $in\n\n" > exp || fail=1
compare exp out || fail=1
done
diff --git a/tests/read-non-seekable b/tests/read-non-seekable
index 8a7bdcd..59c2389 100755
--- a/tests/read-non-seekable
+++ b/tests/read-non-seekable
@@ -16,12 +16,16 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=`pwd`
+test -z "$abs_top_srcdir" && abs_top_srcdir=`pwd`/..
+test -z "$abs_top_builddir" && abs_top_builddir=`pwd`/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
fail=0
@@ -40,11 +44,11 @@ cat <<\EOF > dom
</domain>
EOF
-virsh -c test:///default define dom > /dev/null || fail=1
+$abs_top_builddir/tools/virsh -c test:///default define dom > /dev/null || fail=1
mkfifo_or_skip_ fifo
cat dom > fifo &
-virsh -c test:///default define fifo > /dev/null || fail=1
+$abs_top_builddir/tools/virsh -c test:///default define fifo > /dev/null || fail=1
(exit $fail); exit $fail
diff --git a/tests/start b/tests/start
index f457d59..930a6d9 100755
--- a/tests/start
+++ b/tests/start
@@ -16,13 +16,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
. "$srcdir/test-lib.sh"
fail=0
@@ -30,7 +32,7 @@ fail=0
test_url=test:///default
# expect this to fail
-virsh -c $test_url start test > out 2> err && fail=1
+$abs_top_builddir/tools/virsh -c $test_url start test > out 2> err && fail=1
# stdout gets a newline
echo > exp || fail=1
diff --git a/tests/test_conf.sh b/tests/test_conf.sh
index 62c2324..682f1f5 100755
--- a/tests/test_conf.sh
+++ b/tests/test_conf.sh
@@ -1,17 +1,19 @@
#!/bin/sh
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+test -z "$abs_srcdir" && abs_srcdir=$(pwd)
+test -z "$abs_builddir" && abs_builddir=$(pwd)
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
set -e
-if test "x$abs_srcdir" = x; then
- abs_srcdir=`pwd`
- abs_builddir=`pwd`
-fi
fail=0
i=1
diff --git a/tests/undefine b/tests/undefine
index fafdae7..48b0ad9 100755
--- a/tests/undefine
+++ b/tests/undefine
@@ -16,17 +16,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
fail=0
# Attempt to undefine a running domain, by domain name.
-virsh -q -c test:///default undefine test > out 2>&1
+$abs_top_builddir/tools/virsh -q -c test:///default undefine test > out 2>&1
test $? = 1 || fail=1
cat <<\EOF > exp || fail=1
error: Failed to undefine domain test
@@ -35,7 +39,7 @@ EOF
compare exp out || fail=1
# A different diagnostic when specifying a domain ID
-virsh -q -c test:///default undefine 1 > out 2>&1
+$abs_top_builddir/tools/virsh -q -c test:///default undefine 1 > out 2>&1
test $? = 1 || fail=1
cat <<\EOF > exp || fail=1
error: a running domain like 1 cannot be undefined;
@@ -44,7 +48,7 @@ EOF
compare exp out || fail=1
# Succeed, now: first shut down, then undefine, both via name.
-virsh -q -c test:///default 'shutdown test; undefine test' > out 2>&1
+$abs_top_builddir/tools/virsh -q -c test:///default 'shutdown test; undefine test' > out 2>&1
test $? = 0 || fail=1
cat <<\EOF > exp || fail=1
Domain test is being shutdown
diff --git a/tests/vcpupin b/tests/vcpupin
index 79b02dc..a72ad4c 100755
--- a/tests/vcpupin
+++ b/tests/vcpupin
@@ -16,17 +16,21 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-. $srcdir/test-lib.sh
+. "$srcdir/test-lib.sh"
fail=0
# Invalid syntax.
-virsh --connect test:///default vcpupin test a 0,1 > out 2>&1
+$abs_top_builddir/tools/virsh --connect test:///default vcpupin test a 0,1 > out 2>&1
test $? = 1 || fail=1
cat <<\EOF > exp || fail=1
error: vcpupin: Invalid or missing vCPU number.
@@ -35,7 +39,7 @@ EOF
compare exp out || fail=1
# An out-of-range vCPU number deserves a diagnostic, too.
-virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1
+$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1
test $? = 1 || fail=1
cat <<\EOF > exp || fail=1
error: vcpupin: Invalid vCPU number.
diff --git a/tests/virsh-all b/tests/virsh-all
index 03ea466..81b3e57 100755
--- a/tests/virsh-all
+++ b/tests/virsh-all
@@ -16,27 +16,29 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
-test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
. "$srcdir/test-lib.sh"
fail=0
test_url=test:///default
-virsh -c $test_url help > cmds || framework_failure
+$abs_top_builddir/tools/virsh -c $test_url help > cmds || framework_failure
cmds=$(sed -n 's/^ \([^ ][^ ]*\) .*/\1/p' cmds) || framework_failure
test -n "$cmds" || framework_failure
for i in $cmds; do
echo testing $i... 1>&2
# For now, just run the command and ignore output and exit status.
- virsh -c $test_url $i < /dev/null > /dev/null 2>&1
+ $abs_top_builddir/tools/virsh -c $test_url $i < /dev/null > /dev/null 2>&1
done
(exit $fail); exit $fail
diff --git a/tests/virsh-synopsis b/tests/virsh-synopsis
index 24038dd..d72e887 100755
--- a/tests/virsh-synopsis
+++ b/tests/virsh-synopsis
@@ -16,24 +16,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+test -z "$srcdir" && srcdir=$(pwd)
+test -z "$abs_top_srcdir" && abs_top_srcdir=$(pwd)/..
+test -z "$abs_top_builddir" && abs_top_builddir=$(pwd)/..
+
if test "$VERBOSE" = yes; then
set -x
- virsh --version
+ $abs_top_builddir/tools/virsh --version
fi
-test -z "$srcdir" && srcdir=$(pwd)
. "$srcdir/test-lib.sh"
fail=0
test_url=test:///default
-virsh -c $test_url help > cmds || framework_failure
+$abs_top_builddir/tools/virsh -c $test_url help > cmds || framework_failure
cmds=$(sed -n 's/^ \([^ ][^ ]*\) .*/\1/p' cmds) || framework_failure
test -n "$cmds" || framework_failure
for i in $cmds; do
- virsh -c $test_url help $i > help || fail=1
+ $abs_top_builddir/tools/virsh -c $test_url help $i > help || fail=1
grep -A1 '^ SYNOPSIS$' help > synopsis \
|| { echo 1>&2 missing or invalid help SYNOPSIS for $i; fail=1; }
sed -n 2p synopsis > s2 || framework_failure
--
1.6.0.6
15 years, 7 months
[libvirt] boot.kernel.org support in libvirt
by Itamar Reis Peixoto
Hello guy's
what you think to add bko support in libvirt/virt-manager
for example
boot from hard disk
boot from network / pxe
boot from kernel.org
please look -->
http://boot.kernel.org/
--
------------
Itamar Reis Peixoto
e-mail/msn: itamar(a)ispbrasil.com.br
sip: itamar(a)ispbrasil.com.br
skype: itamarjp
icq: 81053601
+55 11 4063 5033
+55 34 3221 8599
15 years, 7 months
Re: [libvirt] Xen: Domain.migrate() causes invalid listDomains() output
by Thomas Treutner
On Wednesday 07 October 2009 10:25:11 Thomas Treutner wrote:
> Shall I provide more debug output?
Here the debug output of libvirtd:
http://tt.scripty.at/tmp/node01.txt.gz
http://tt.scripty.at/tmp/node02.txt.gz
At start, domain wp01 is @ node01, and
wp02 @ node02. Then their placement is exchanged.
After migration:
node01:~# xm list
Name ID Mem VCPUs State
Time(s)
Domain-0 0 256 2 r----- 37.9
wp02 2 512 2 -b---- 0.9
node02:~# xm list
Name ID Mem VCPUs State
Time(s)
Domain-0 0 192 2 r----- 52.4
wp01 3 512 2 -b---- 1.0
virt-top etc. don't see wp01@node02 anymore. libvirt obviously returns ID 1
for it, which can't be resolved. As there is no alternative to
int[] listDomains() (f.e., return UUIDs), I'm stuck here.
NB: Doing migration with xm migrate works fine, libvirt isn't confused by
that.
-t-
15 years, 7 months
[libvirt] cann't connect kvm hypervisor
by Liu, Zhentao
Hello,
I have used virsh to connect my hypervisor, what is the reason?
-------------------------------------------------------------------------------
root@forest:/# virsh -c qemu:///system list
error: unable to connect to '/var/run/libvirt/libvirt-sock': Connection refused
error: failed to connect to the hypervisor
---------------------------------------------------------------------------------
Thanks
Zhentao Liu
15 years, 7 months
[libvirt] [PATCH] Support for IPv6 / multiple ifaces in interface_conf.[ch]
by Laine Stump
This patch updates the xml parsing and formatting, and the associated
virInterfaceDef data structure to support IPv6, along the way adding
support for multiple protocols per interface, and multiple IP
addresses per protocol.
Note that netcf appears to not accept defining both ipv4 and ipv6 on
the same interface, and still can't report live config of IPv6 (or
multiple IPv4 addresses), so the usefulness of this patch is limited
until those items are fixed in netcf.
This patch applies on top of commit
1ceabc5a152efa8892954cb4f45b85553edfee9f, which I submitted on Sept 28.
---
src/conf/interface_conf.c | 308 ++++++++++++++++++++++++++++++++++-----------
src/conf/interface_conf.h | 21 +++-
2 files changed, 247 insertions(+), 82 deletions(-)
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index b422464..24f111c 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -53,9 +53,32 @@ void virInterfaceBareDefFree(virInterfaceBareDefPtr def) {
VIR_FREE(def);
}
+static
+void virInterfaceIpDefFree(virInterfaceIpDefPtr def) {
+ if (def == NULL)
+ return;
+ VIR_FREE(def->address);
+ VIR_FREE(def->source);
+}
+
+static
+void virInterfaceProtocolDefFree(virInterfaceProtocolDefPtr def) {
+ int ii;
+
+ if (def == NULL)
+ return;
+ for (ii = 0; ii < def->nips; ii++) {
+ virInterfaceIpDefFree(def->ips[ii]);
+ }
+ VIR_FREE(def->ips);
+ VIR_FREE(def->family);
+ VIR_FREE(def->gateway);
+ VIR_FREE(def);
+}
+
void virInterfaceDefFree(virInterfaceDefPtr def)
{
- int i;
+ int i, pp;
if (def == NULL)
return;
@@ -89,11 +112,11 @@ void virInterfaceDefFree(virInterfaceDefPtr def)
break;
}
- VIR_FREE(def->proto.family);
- VIR_FREE(def->proto.address);
- VIR_FREE(def->proto.gateway);
- VIR_FREE(def->proto.source);
-
+ /* free all protos */
+ for (pp = 0; pp < def->nprotos; pp++) {
+ virInterfaceProtocolDefFree(def->protos[pp]);
+ }
+ VIR_FREE(def->protos);
VIR_FREE(def);
}
@@ -226,22 +249,22 @@ virInterfaceDefParseBondArpValid(virConnectPtr conn, xmlXPathContextPtr ctxt) {
}
static int
-virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceDefPtr def,
+virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceProtocolDefPtr def,
xmlNodePtr dhcp, xmlXPathContextPtr ctxt) {
xmlNodePtr save;
char *tmp;
int ret = 0;
- def->proto.dhcp = 1;
+ def->dhcp = 1;
save = ctxt->node;
ctxt->node = dhcp;
/* Not much to do in the current version */
tmp = virXPathString(conn, "string(./@peerdns)", ctxt);
if (tmp) {
if (STREQ(tmp, "yes"))
- def->proto.peerdns = 1;
+ def->peerdns = 1;
else if (STREQ(tmp, "no"))
- def->proto.peerdns = 0;
+ def->peerdns = 0;
else {
virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
_("unknown dhcp peerdns value %s"), tmp);
@@ -249,88 +272,209 @@ virInterfaceDefParseDhcp(virConnectPtr conn, virInterfaceDefPtr def,
}
VIR_FREE(tmp);
} else
- def->proto.peerdns = -1;
+ def->peerdns = -1;
ctxt->node = save;
return(ret);
}
static int
-virInterfaceDefParseIp(virConnectPtr conn, virInterfaceDefPtr def,
- xmlNodePtr ip ATTRIBUTE_UNUSED, xmlXPathContextPtr ctxt) {
+virInterfaceDefParseIp(virConnectPtr conn, virInterfaceIpDefPtr def,
+ xmlXPathContextPtr ctxt) {
int ret = 0;
char *tmp;
long l;
- tmp = virXPathString(conn, "string(./ip[1]/@address)", ctxt);
- def->proto.address = tmp;
+ tmp = virXPathString(conn, "string(./@address)", ctxt);
+ def->address = tmp;
if (tmp != NULL) {
- ret = virXPathLong(conn, "string(./ip[1]/@prefix)", ctxt, &l);
+ ret = virXPathLong(conn, "string(./@prefix)", ctxt, &l);
if (ret == 0)
- def->proto.prefix = (int) l;
+ def->prefix = (int) l;
else if (ret == -2) {
virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
"%s", _("Invalid ip address prefix value"));
return(-1);
}
- tmp = virXPathString(conn, "string(./ip[1]/@source)", ctxt);
- def->proto.source = tmp;
+ tmp = virXPathString(conn, "string(./@source)", ctxt);
+ def->source = tmp;
}
- tmp = virXPathString(conn, "string(./route[1]/@gateway)", ctxt);
- def->proto.gateway = tmp;
return(0);
}
static int
-virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceDefPtr def,
+virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceProtocolDefPtr def,
xmlXPathContextPtr ctxt) {
- xmlNodePtr dhcp, ip;
- int ret = 0;
+ xmlNodePtr dhcp;
+ xmlNodePtr *ipNodes = NULL;
+ int nIpNodes, ii, ret = 0;
+ char *tmp;
+
+ tmp = virXPathString(conn, "string(./route[1]/@gateway)", ctxt);
+ def->gateway = tmp;
dhcp = virXPathNode(conn, "./dhcp", ctxt);
if (dhcp != NULL)
ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt);
+ if (ret != 0)
+ return(ret);
+
+ nIpNodes = virXPathNodeSet(conn, "./ip", ctxt, &ipNodes);
+ if (ipNodes == NULL)
+ return 0;
+
+ if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) {
+ virReportOOMError(conn);
+ ret = -1;
+ goto error;
+ }
+
+ def->nips = 0;
+ for (ii = 0; ii < nIpNodes; ii++) {
+ virInterfaceIpDefPtr ip;
+
+ if (VIR_ALLOC(ip) < 0) {
+ virReportOOMError(conn);
+ break;
+ }
+
+ ctxt->node = ipNodes[ii];
+ ret = virInterfaceDefParseIp(conn, ip, ctxt);
+ if (ret != 0) {
+ virInterfaceIpDefFree(ip);
+ break;
+ }
+ def->ips[def->nips++] = ip;
+ }
+
+error:
+ VIR_FREE(ipNodes);
+ return(ret);
+}
+
+static int
+virInterfaceDefParseProtoIPv6(virConnectPtr conn, virInterfaceProtocolDefPtr def,
+ xmlXPathContextPtr ctxt) {
+ xmlNodePtr dhcp, autoconf;
+ xmlNodePtr *ipNodes = NULL;
+ int nIpNodes, ii, ret = 0;
+ char *tmp;
+
+ tmp = virXPathString(conn, "string(./route[1]/@gateway)", ctxt);
+ def->gateway = tmp;
+
+ autoconf = virXPathNode(conn, "./autoconf", ctxt);
+ if (autoconf != NULL)
+ def->autoconf = 1;
+
+ dhcp = virXPathNode(conn, "./dhcp", ctxt);
+ if (dhcp != NULL)
+ ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt);
if (ret != 0)
return(ret);
- ip = virXPathNode(conn, "./ip", ctxt);
- if (ip != NULL)
- ret = virInterfaceDefParseIp(conn, def, ip, ctxt);
+ nIpNodes = virXPathNodeSet(conn, "./ip", ctxt, &ipNodes);
+ if (ipNodes == NULL)
+ return 0;
+
+ if (VIR_ALLOC_N(def->ips, nIpNodes) < 0) {
+ virReportOOMError(conn);
+ ret = -1;
+ goto error;
+ }
+
+ def->nips = 0;
+ for (ii = 0; ii < nIpNodes; ii++) {
+
+ virInterfaceIpDefPtr ip;
+
+ if (VIR_ALLOC(ip) < 0) {
+ virReportOOMError(conn);
+ break;
+ }
+
+ ctxt->node = ipNodes[ii];
+ ret = virInterfaceDefParseIp(conn, ip, ctxt);
+ if (ret != 0) {
+ virInterfaceIpDefFree(ip);
+ break;
+ }
+ def->ips[def->nips++] = ip;
+ }
+
+error:
+ VIR_FREE(ipNodes);
return(ret);
}
static int
virInterfaceDefParseIfAdressing(virConnectPtr conn, virInterfaceDefPtr def,
xmlXPathContextPtr ctxt) {
- xmlNodePtr cur, save;
- int ret;
+ xmlNodePtr save;
+ xmlNodePtr *protoNodes = NULL;
+ int nProtoNodes, pp, ret = 0;
char *tmp;
- cur = virXPathNode(conn, "./protocol[1]", ctxt);
- if (cur == NULL)
- return(0);
save = ctxt->node;
- ctxt->node = cur;
- tmp = virXPathString(conn, "string(./@family)", ctxt);
- if (tmp == NULL) {
- virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
- "%s", _("protocol misses the family attribute"));
- ret = -1;
- goto done;
+
+ nProtoNodes = virXPathNodeSet(conn, "./protocol", ctxt, &protoNodes);
+ if (nProtoNodes <= 0) {
+ /* no protocols is an acceptable outcome */
+ return 0;
}
- if (STREQ(tmp, "ipv4")) {
- def->proto.family = tmp;
- ret = virInterfaceDefParseProtoIPv4(conn, def, ctxt);
- } else {
- virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
- _("unsupported protocol family '%s'"), tmp);
+
+ if (VIR_ALLOC_N(def->protos, nProtoNodes) < 0) {
+ virReportOOMError(conn);
ret = -1;
- VIR_FREE(tmp);
+ goto error;
}
-done:
+ def->nprotos = 0;
+ for (pp = 0; pp < nProtoNodes; pp++) {
+
+ virInterfaceProtocolDefPtr proto;
+
+ if (VIR_ALLOC(proto) < 0) {
+ virReportOOMError(conn);
+ break;
+ }
+
+ ctxt->node = protoNodes[pp];
+ tmp = virXPathString(conn, "string(./@family)", ctxt);
+ if (tmp == NULL) {
+ virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
+ "%s", _("protocol misses the family attribute"));
+ virInterfaceProtocolDefFree(proto);
+ ret = -1;
+ break;
+ }
+ proto->family = tmp;
+ if (STREQ(tmp, "ipv4")) {
+ ret = virInterfaceDefParseProtoIPv4(conn, proto, ctxt);
+ if (ret != 0) {
+ virInterfaceProtocolDefFree(proto);
+ break;
+ }
+ } else if (STREQ(tmp, "ipv6")) {
+ ret = virInterfaceDefParseProtoIPv6(conn, proto, ctxt);
+ if (ret != 0) {
+ virInterfaceProtocolDefFree(proto);
+ break;
+ }
+ } else {
+ virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
+ _("unsupported protocol family '%s'"), tmp);
+ ret = -1;
+ virInterfaceProtocolDefFree(proto);
+ break;
+ }
+ def->protos[def->nprotos++] = proto;
+ }
+
+error:
+ VIR_FREE(protoNodes);
ctxt->node = save;
return(ret);
@@ -1005,36 +1149,48 @@ virInterfaceVlanDefFormat(virConnectPtr conn, virBufferPtr buf,
static int
virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferPtr buf, const virInterfaceDefPtr def) {
- char prefixStr[16];
- if (def->proto.family == NULL)
- return(0);
- virBufferVSprintf(buf, " <protocol family='%s'>\n", def->proto.family);
- if (def->proto.dhcp) {
- if (def->proto.peerdns == 0)
- virBufferAddLit(buf, " <dhcp peerdns='no'/>\n");
- else if (def->proto.peerdns == 1)
- virBufferAddLit(buf, " <dhcp peerdns='yes'/>\n");
- else
- virBufferAddLit(buf, " <dhcp/>\n");
- }
- if (def->proto.address != NULL) {
- if (def->proto.prefix != 0)
- snprintf(prefixStr, sizeof(prefixStr), "%d", def->proto.prefix);
-
- virBufferVSprintf(buf, " <ip address='%s'%s%s%s%s%s%s/>\n",
- def->proto.address,
- def->proto.prefix ? " prefix='" : "",
- def->proto.prefix ? prefixStr : "",
- def->proto.prefix ? "'" : "",
- def->proto.source ? " source='" : "",
- def->proto.source ? def->proto.source : "",
- def->proto.source ? "'" : "");
- }
- if (def->proto.gateway != NULL) {
- virBufferVSprintf(buf, " <route gateway='%s'/>\n",
- def->proto.gateway);
+ int pp, ii;
+
+ for (pp = 0; pp < def->nprotos; pp++) {
+
+ virBufferVSprintf(buf, " <protocol family='%s'>\n", def->protos[pp]->family);
+
+ if (def->protos[pp]->autoconf) {
+ virBufferAddLit(buf, " <autoconf/>\n");
+ }
+
+ if (def->protos[pp]->dhcp) {
+ if (def->protos[pp]->peerdns == 0)
+ virBufferAddLit(buf, " <dhcp peerdns='no'/>\n");
+ else if (def->protos[pp]->peerdns == 1)
+ virBufferAddLit(buf, " <dhcp peerdns='yes'/>\n");
+ else
+ virBufferAddLit(buf, " <dhcp/>\n");
+ }
+
+ for (ii = 0; ii < def->protos[pp]->nips; ii++) {
+ if (def->protos[pp]->ips[ii]->address != NULL) {
+
+ virBufferVSprintf(buf, " <ip address='%s'",
+ def->protos[pp]->ips[ii]->address);
+ if (def->protos[pp]->ips[ii]->prefix != 0) {
+ virBufferVSprintf(buf, " prefix='%d'",
+ def->protos[pp]->ips[ii]->prefix);
+ }
+ if (def->protos[pp]->ips[ii]->source != NULL) {
+ virBufferVSprintf(buf, " source='%s'",
+ def->protos[pp]->ips[ii]->source);
+ }
+ virBufferAddLit(buf, "/>\n");
+ }
+ }
+ if (def->protos[pp]->gateway != NULL) {
+ virBufferVSprintf(buf, " <route gateway='%s'/>\n",
+ def->protos[pp]->gateway);
+ }
+
+ virBufferAddLit(buf, " </protocol>\n");
}
- virBufferAddLit(buf, " </protocol>\n");
return(0);
}
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index df871aa..49acdd6 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -123,16 +123,25 @@ struct _virInterfaceVlanDef {
char *devname; /* device name for vlan */
};
+typedef struct _virInterfaceIpDef virInterfaceIpDef;
+typedef virInterfaceIpDef *virInterfaceIpDefPtr;
+struct _virInterfaceIpDef {
+ char *address; /* ip address */
+ int prefix; /* ip prefix */
+ char *source; /* source of address - "device" or "config" (default) */
+};
+
+
typedef struct _virInterfaceProtocolDef virInterfaceProtocolDef;
typedef virInterfaceProtocolDef *virInterfaceProtocolDefPtr;
struct _virInterfaceProtocolDef {
- char *family; /* ipv4 only right now */
+ char *family; /* ipv4 or ipv6 */
int dhcp; /* use dhcp */
int peerdns; /* dhcp peerdns ? */
- char *address; /* ip address */
- int prefix; /* ip prefix */
+ int autoconf; /* only useful if family is ipv6 */
+ int nips;
+ virInterfaceIpDefPtr *ips; /* ptr to array of ips[nips] */
char *gateway; /* route gateway */
- char *source; /* source of address - "device" or "config" (default) */
};
@@ -152,8 +161,8 @@ struct _virInterfaceDef {
virInterfaceBondDef bond;
} data;
- /* separated as we may allow multiple of those in the future */
- virInterfaceProtocolDef proto;
+ int nprotos;
+ virInterfaceProtocolDefPtr *protos; /* ptr to array of protos[nprotos] */
};
typedef struct _virInterfaceObj virInterfaceObj;
--
1.6.2.5
15 years, 7 months
[libvirt] [PATCH] Support reporting live interface IP/netmask.
by Laine Stump
From: root <root(a)vlap.laine.org>
This patch adds the flag VIR_INTERFACE_XML_INACTIVE to
virInterfaceGetXMLDesc's flags. When it is *not* set (the default),
the live interface info will be returned in the XML. in particular,
the IP address(es) and netmask(s) will be retrieved by querying the
device directly, rather than just reporting what's in the config
file. The backend of this is in netcf's new ncf_if_xml_state()
function.
Any live interface ip address info in the xml will have the property
"source" set to "device", eg:
<ip address='10.24.0.1' prefix='24' source='device'/>
Also, if an interface is currently inactive, no ip addresses will be
returned, since an inactive interface device can't be queried for IP
addresses (effectively it has none).
A difference in the XML from previously - it is now acceptable to have
both a dhcp *and* an ip node (or neither) within the protocol
node. Before you had to have one or the other, but couldn't have both.
Note that you need at least netcf 0.1.2 for this to build and work,
and an upcoming release (patches submitted today) for it to work
exactly as described above.
---
include/libvirt/libvirt.h.in | 4 +++
src/conf/interface_conf.c | 62 ++++++++++++++++++++++-------------------
src/conf/interface_conf.h | 1 +
src/interface/netcf_driver.c | 8 ++++-
src/libvirt.c | 15 +++++++---
tools/virsh.c | 10 +++++-
6 files changed, 63 insertions(+), 37 deletions(-)
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 4e63e48..fd0c90b 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -922,6 +922,10 @@ virInterfacePtr virInterfaceLookupByMACString (virConnectPtr conn,
const char* virInterfaceGetName (virInterfacePtr iface);
const char* virInterfaceGetMACString (virInterfacePtr iface);
+typedef enum {
+ VIR_INTERFACE_XML_INACTIVE = 1 /* dump inactive interface information */
+} virInterfaceXMLFlags;
+
char * virInterfaceGetXMLDesc (virInterfacePtr iface,
unsigned int flags);
virInterfacePtr virInterfaceDefineXML (virConnectPtr conn,
diff --git a/src/conf/interface_conf.c b/src/conf/interface_conf.c
index e646351..b422464 100644
--- a/src/conf/interface_conf.c
+++ b/src/conf/interface_conf.c
@@ -92,6 +92,7 @@ void virInterfaceDefFree(virInterfaceDefPtr def)
VIR_FREE(def->proto.family);
VIR_FREE(def->proto.address);
VIR_FREE(def->proto.gateway);
+ VIR_FREE(def->proto.source);
VIR_FREE(def);
}
@@ -272,6 +273,8 @@ virInterfaceDefParseIp(virConnectPtr conn, virInterfaceDefPtr def,
"%s", _("Invalid ip address prefix value"));
return(-1);
}
+ tmp = virXPathString(conn, "string(./ip[1]/@source)", ctxt);
+ def->proto.source = tmp;
}
tmp = virXPathString(conn, "string(./route[1]/@gateway)", ctxt);
def->proto.gateway = tmp;
@@ -282,22 +285,19 @@ virInterfaceDefParseIp(virConnectPtr conn, virInterfaceDefPtr def,
static int
virInterfaceDefParseProtoIPv4(virConnectPtr conn, virInterfaceDefPtr def,
xmlXPathContextPtr ctxt) {
- xmlNodePtr cur;
- int ret;
+ xmlNodePtr dhcp, ip;
+ int ret = 0;
- cur = virXPathNode(conn, "./dhcp", ctxt);
- if (cur != NULL)
- ret = virInterfaceDefParseDhcp(conn, def, cur, ctxt);
- else {
- cur = virXPathNode(conn, "./ip", ctxt);
- if (cur != NULL)
- ret = virInterfaceDefParseIp(conn, def, cur, ctxt);
- else {
- virInterfaceReportError(conn, VIR_ERR_XML_ERROR,
- "%s", _("interface miss dhcp or ip adressing"));
- ret = -1;
- }
- }
+ dhcp = virXPathNode(conn, "./dhcp", ctxt);
+ if (dhcp != NULL)
+ ret = virInterfaceDefParseDhcp(conn, def, dhcp, ctxt);
+
+ if (ret != 0)
+ return(ret);
+
+ ip = virXPathNode(conn, "./ip", ctxt);
+ if (ip != NULL)
+ ret = virInterfaceDefParseIp(conn, def, ip, ctxt);
return(ret);
}
@@ -1005,6 +1005,7 @@ virInterfaceVlanDefFormat(virConnectPtr conn, virBufferPtr buf,
static int
virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferPtr buf, const virInterfaceDefPtr def) {
+ char prefixStr[16];
if (def->proto.family == NULL)
return(0);
virBufferVSprintf(buf, " <protocol family='%s'>\n", def->proto.family);
@@ -1015,20 +1016,23 @@ virInterfaceProtocolDefFormat(virConnectPtr conn ATTRIBUTE_UNUSED,
virBufferAddLit(buf, " <dhcp peerdns='yes'/>\n");
else
virBufferAddLit(buf, " <dhcp/>\n");
- } else {
- /* theorically if we don't have dhcp we should have an address */
- if (def->proto.address != NULL) {
- if (def->proto.prefix != 0)
- virBufferVSprintf(buf, " <ip address='%s' prefix='%d'/>\n",
- def->proto.address, def->proto.prefix);
- else
- virBufferVSprintf(buf, " <ip address='%s'/>\n",
- def->proto.address);
- }
- if (def->proto.gateway != NULL) {
- virBufferVSprintf(buf, " <route gateway='%s'/>\n",
- def->proto.gateway);
- }
+ }
+ if (def->proto.address != NULL) {
+ if (def->proto.prefix != 0)
+ snprintf(prefixStr, sizeof(prefixStr), "%d", def->proto.prefix);
+
+ virBufferVSprintf(buf, " <ip address='%s'%s%s%s%s%s%s/>\n",
+ def->proto.address,
+ def->proto.prefix ? " prefix='" : "",
+ def->proto.prefix ? prefixStr : "",
+ def->proto.prefix ? "'" : "",
+ def->proto.source ? " source='" : "",
+ def->proto.source ? def->proto.source : "",
+ def->proto.source ? "'" : "");
+ }
+ if (def->proto.gateway != NULL) {
+ virBufferVSprintf(buf, " <route gateway='%s'/>\n",
+ def->proto.gateway);
}
virBufferAddLit(buf, " </protocol>\n");
return(0);
diff --git a/src/conf/interface_conf.h b/src/conf/interface_conf.h
index bb9dce4..df871aa 100644
--- a/src/conf/interface_conf.h
+++ b/src/conf/interface_conf.h
@@ -132,6 +132,7 @@ struct _virInterfaceProtocolDef {
char *address; /* ip address */
int prefix; /* ip prefix */
char *gateway; /* route gateway */
+ char *source; /* source of address - "device" or "config" (default) */
};
diff --git a/src/interface/netcf_driver.c b/src/interface/netcf_driver.c
index ca14fb0..b5c3664 100644
--- a/src/interface/netcf_driver.c
+++ b/src/interface/netcf_driver.c
@@ -326,7 +326,7 @@ cleanup:
}
static char *interfaceGetXMLDesc(virInterfacePtr ifinfo,
- unsigned int flags ATTRIBUTE_UNUSED)
+ unsigned int flags)
{
struct interface_driver *driver = ifinfo->conn->interfacePrivateData;
struct netcf_if *iface = NULL;
@@ -342,7 +342,11 @@ static char *interfaceGetXMLDesc(virInterfacePtr ifinfo,
goto cleanup;
}
- xmlstr = ncf_if_xml_desc(iface);
+ if ((flags & VIR_INTERFACE_XML_INACTIVE)) {
+ xmlstr = ncf_if_xml_desc(iface);
+ } else {
+ xmlstr = ncf_if_xml_state(iface);
+ }
if (!xmlstr) {
const char *errmsg, *details;
int errcode = ncf_error(driver->netcf, &errmsg, &details);
diff --git a/src/libvirt.c b/src/libvirt.c
index bcb89e1..bd712dc 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -5915,10 +5915,17 @@ virInterfaceGetMACString(virInterfacePtr iface)
/**
* virInterfaceGetXMLDesc:
* @iface: an interface object
- * @flags: an OR'ed set of extraction flags, not used yet
+ * @flags: an OR'ed set of extraction flags. Current valid bits:
+ *
+ * VIR_INTERFACE_XML_INACTIVE - return the static configuration,
+ * suitable for use redefining the
+ * interface via virInterfaceDefineXML()
*
- * Provide an XML description of the interface. The description may be reused
- * later to redefine the interface with virInterfaceDefineXML().
+ * Provide an XML description of the interface. If
+ * VIR_INTERFACE_XML_INACTIVE is set, the description may be reused
+ * later to redefine the interface with virInterfaceDefineXML(). If it
+ * is not set, the ip address and netmask will be the current live
+ * setting of the interface, not the settings from the config files.
*
* Returns a 0 terminated UTF-8 encoded XML instance, or NULL in case of error.
* the caller must free() the returned value.
@@ -5935,7 +5942,7 @@ virInterfaceGetXMLDesc(virInterfacePtr iface, unsigned int flags)
virLibInterfaceError(NULL, VIR_ERR_INVALID_INTERFACE, __FUNCTION__);
return (NULL);
}
- if (flags != 0) {
+ if ((flags & ~VIR_INTERFACE_XML_INACTIVE) != 0) {
virLibInterfaceError(iface, VIR_ERR_INVALID_ARG, __FUNCTION__);
goto error;
}
diff --git a/tools/virsh.c b/tools/virsh.c
index 3482389..77f1d70 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -2763,7 +2763,7 @@ cmdInterfaceEdit (vshControl *ctl, const vshCmd *cmd)
char *doc = NULL;
char *doc_edited = NULL;
char *doc_reread = NULL;
- int flags = 0;
+ int flags = VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
goto cleanup;
@@ -3297,6 +3297,7 @@ static const vshCmdInfo info_interface_dumpxml[] = {
static const vshCmdOptDef opts_interface_dumpxml[] = {
{"interface", VSH_OT_DATA, VSH_OFLAG_REQ, gettext_noop("interface name or MAC address")},
+ {"inactive", VSH_OT_BOOL, 0, gettext_noop("show inactive defined XML")},
{NULL, 0, 0, NULL}
};
@@ -3306,6 +3307,11 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
virInterfacePtr iface;
int ret = TRUE;
char *dump;
+ int flags = 0;
+ int inactive = vshCommandOptBool(cmd, "inactive");
+
+ if (inactive)
+ flags |= VIR_INTERFACE_XML_INACTIVE;
if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
return FALSE;
@@ -3313,7 +3319,7 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd)
if (!(iface = vshCommandOptInterface(ctl, cmd, NULL)))
return FALSE;
- dump = virInterfaceGetXMLDesc(iface, 0);
+ dump = virInterfaceGetXMLDesc(iface, flags);
if (dump != NULL) {
printf("%s", dump);
free(dump);
--
1.6.2.5
15 years, 7 months
[libvirt] [RFC] Multi-IQN proposal
by Shyam_Iyer@Dell.com
Would this proposal be acceptable ?
Example XML schema for an iSCSI storage pool created --
<pool type="iscsi">
<name>dell</name>
<uuid>cf354733-b01b-8870-2040-94888640e24d</uuid>
<capacity>0</capacity>
<allocation>0</allocation>
<available>0</available>
- <source>
<initiator iqnname = "<initiator IQN1>">
<initiator iqnname = "<initiator IQN2>">
........................................
........................................
<host name="<iSCSI target hostname or Target IP address>" />
<device path="<iSCSI Target IQN name>" />
</source>
- <target>
<path>/dev/disk/by-path</path>
- <permissions>
<mode>0700</mode>
<owner>0</owner>
<group>0</group>
</permissions>
</target>
</pool>
Each initiator iqn name can be parsed to create the unique sessions.
This should solve the following possibilities --
* possibility of multiple IQNs for a single Guest
* option for Guest's own BIOS & initiator to use these IQNs (iSCSI in
Guest)
* option for hypervisor's initiator to use these IQNs on behalf of the
guest
(Multi-IQN)
Compile tested only. Needs beatification.
diff --git a/src/storage_conf.c b/src/storage_conf.c
index cb063cc..915e897 100644
--- a/src/storage_conf.c
+++ b/src/storage_conf.c
@@ -116,6 +116,7 @@ enum {
VIR_STORAGE_POOL_SOURCE_DIR = (1<<2),
VIR_STORAGE_POOL_SOURCE_ADAPTER = (1<<3),
VIR_STORAGE_POOL_SOURCE_NAME = (1<<4),
+ VIR_STORAGE_POOL_SOURCE_INITIATOR_IQN = (1<<5),
};
@@ -537,6 +538,33 @@ virStoragePoolDefParseXML(virConnectPtr conn,
goto cleanup;
}
}
+
+/* Read the conf here */
+ if (options->flags & VIR_STORAGE_POOL_SOURCE_INITATOR_IQN) {
+ int niqn, i;
+
+ if ((niqn = virXPathNodeSet(conn, "./source/host/initiator",
ctxt, &nodeset)) < 0) {
+ virStorageReportError(conn, VIR_ERR_XML_ERROR,
+ "%s", _("cannot extract storage pool source
devices"));
+ goto cleanup;
+ }
+ if (VIR_ALLOC_N(ret->source.niqn, niqn) < 0) {
+ VIR_FREE(nodeset);
+ virReportOOMError(conn);
+ goto cleanup;
+ }
+ for (i = 0 ; i < niqn ; i++ ) {
+ xmlChar *name = xmlGetProp(nodeset[i], BAD_CAST "iqnname");
+ if (path == NULL) {
+ VIR_FREE(nodeset);
+ virStorageReportError(conn, VIR_ERR_XML_ERROR,
+ "%s", _("missing storage pool source device
path"));
+ goto cleanup;
+ }
+ ret->source.initiator[i].iqnname = (char *)name;
+ }
+ }
if (options->flags & VIR_STORAGE_POOL_SOURCE_DEVICE) {
xmlNodePtr *nodeset = NULL;
int nsource, i;
diff --git a/src/storage_conf.h b/src/storage_conf.h
index 421d305..c2504be 100644
--- a/src/storage_conf.h
+++ b/src/storage_conf.h
@@ -202,7 +202,12 @@ struct _virStoragePoolSourceDevice {
} geometry;
};
-
+/* Initiator Attributes */
+typedef virStoragePoolSourceInitiatorAttr
*virStoragePoolSourceInitiatorAttrPtr;
+struct virStoragePoolSourceInitiatorAttr {
+ char *iqnname;
+ /* We could put other initiator specific things here */
+}
typedef struct _virStoragePoolSource virStoragePoolSource;
typedef virStoragePoolSource *virStoragePoolSourcePtr;
@@ -214,6 +219,9 @@ struct _virStoragePoolSource {
int ndevice;
virStoragePoolSourceDevicePtr devices;
+ /*And either one or more initiators*/
+ virStoragePoolSourceInitiatorAttrPtr initiator;
+
/* Or a directory */
char *dir;
15 years, 7 months
[libvirt] [RFC PATCH 0/6] Series short description
by Gerhard Stenzel
The following series of patches is a prototype implementation of a ebtables based MAC address filter. This is currently not intended for inclusion, but rather to get some feedback/comments about the approach and the implementation.
At the moment, some defaults are set when libvirtd starts and when a domain is started or destroyed. The plan is to extend this filter capability to the API level and virsh command level. The plan is also to add more filtering features like VLAN filtering and QoS filtering.
Thanks, Gerhard
---
Gerhard Stenzel (6):
remove currently unused parameter to pass make check test
add MAC address based port filtering to qemu
add MAC address based port filtering to libvirt
add the ebtables wrapper to network driver
add build support for ebtables wrapper
add ebtables wrapper
configure.in | 3
include/libvirt/libvirt.h.in | 14 +
src/Makefile.am | 1
src/conf/network_conf.h | 10
src/driver.h | 14 +
src/libvirt.c | 119 +++++
src/libvirt_private.syms | 26 +
src/libvirt_public.syms | 3
src/network/bridge_driver.c | 175 ++++++++
src/qemu/qemu.conf | 3
src/qemu/qemu_conf.c | 14 +
src/qemu/qemu_conf.h | 2
src/qemu/qemu_driver.c | 23 +
src/test/test_driver.c | 3
src/util/ebtables.c | 961 ++++++++++++++++++++++++++++++++++++++++++
src/util/ebtables.h | 134 ++++++
16 files changed, 1505 insertions(+), 0 deletions(-)
create mode 100644 src/util/ebtables.c
create mode 100644 src/util/ebtables.h
--
15 years, 7 months
[libvirt] Regarding connecting to libvirt from windows
by anuj rampal
Hi,
I can connect to libvirt over TCP/IP from windows and call all the
functions.
what i want is to do some kind of authentication like entering some kind of
username/password.
im using virConnectOpen(const char* name) function.
i tried using virConnectOpenAuth().. but whatever parameter ii give it gets
connected and there is no option to pass username/password.
Thanks in advance.
Regards
Anuj
15 years, 7 months