[libvirt] [PATCH] interface.rng: Make miimon and arpmon optional for bond interfaces
by Laine Stump
This has been optional in netcf for awhile, but the change hadn't been
propogated to the libvirt copy of the RNG.
---
I noticed this was out of date while updating the netcf RNG with the
new regex for ipv4-address.
Note that, although the diff is long, it's just adding
<optional>...</optional> around the section, and re-indenting.
Everything in the middle is only whitespace changes.
docs/schemas/interface.rng | 77 +++++++++++++++++++++++---------------------
1 files changed, 40 insertions(+), 37 deletions(-)
diff --git a/docs/schemas/interface.rng b/docs/schemas/interface.rng
index 75893b5..4dd1bb4 100644
--- a/docs/schemas/interface.rng
+++ b/docs/schemas/interface.rng
@@ -177,43 +177,46 @@
xmit_hash_policy (since 2.6.3/3.2.2)
-->
- <choice>
- <element name="miimon">
- <!-- miimon frequency in ms -->
- <attribute name="freq"><ref name="uint"/></attribute>
- <optional>
- <attribute name="downdelay"><ref name="uint"/></attribute>
- </optional>
- <optional>
- <attribute name="updelay"><ref name="uint"/></attribute>
- </optional>
- <optional>
- <!-- use_carrier -->
- <attribute name="carrier">
- <choice>
- <!-- use MII/ETHTOOL ioctl -->
- <value>ioctl</value>
- <!-- use netif_carrier_ok() -->
- <value>netif</value>
- </choice>
- </attribute>
- </optional>
- </element>
- <element name="arpmon">
- <attribute name="interval"><ref name="uint"/></attribute>
- <attribute name="target"><ref name="ipv4-addr"/></attribute>
- <optional>
- <attribute name="validate">
- <choice>
- <value>none</value>
- <value>active</value>
- <value>backup</value>
- <value>all</value>
- </choice>
- </attribute>
- </optional>
- </element>
- </choice>
+ <optional>
+ <choice>
+ <element name="miimon">
+ <!-- miimon frequency in ms -->
+ <attribute name="freq"><ref name="uint"/></attribute>
+ <optional>
+ <attribute name="downdelay"><ref name="uint"/></attribute>
+ </optional>
+ <optional>
+ <attribute name="updelay"><ref name="uint"/></attribute>
+ </optional>
+ <optional>
+ <!-- use_carrier -->
+ <attribute name="carrier">
+ <choice>
+ <!-- use MII/ETHTOOL ioctl -->
+ <value>ioctl</value>
+ <!-- use netif_carrier_ok() -->
+ <value>netif</value>
+ </choice>
+ </attribute>
+ </optional>
+ </element>
+ <element name="arpmon">
+ <attribute name="interval"><ref name="uint"/></attribute>
+ <attribute name="target"><ref name="ipv4-addr"/></attribute>
+ <optional>
+ <attribute name="validate">
+ <choice>
+ <value>none</value>
+ <value>active</value>
+ <value>backup</value>
+ <value>all</value>
+ </choice>
+ </attribute>
+ </optional>
+ </element>
+ </choice>
+ </optional>
+
<oneOrMore>
<!-- The slave interfaces -->
<ref name="bare-ethernet-interface"/>
--
1.7.2.3
14 years, 1 month
[libvirt] [PATCH] [TCK] Convert scripts to also run with dash
by Stefan Berger
I am converting the shell-scripted tap tests to also run using the dash
shell, fixing some other problems on the way as well.
Two of the tests' data files contained '\\1' in an sed command. This
created char(1) with the dash, '\1' with the bash. I found it easier to
replace the sed command with a different one than figuring out how to
solve this escape problem so it works for both shells.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
scripts/networks/100-apply-verify-host.t | 9
scripts/networks/networkApplyTest.sh | 133 +++-----
scripts/networks/networkxml2hostout/tck-testnet-1.dat | 2
scripts/networks/networkxml2hostout/tck-testnet-2.dat | 2
scripts/nwfilter/050-apply-verify-host.t | 9
scripts/nwfilter/nwfilter2vmtest.sh | 298 ++++++++----------
6 files changed, 215 insertions(+), 238 deletions(-)
Index: libvirt-tck/scripts/networks/networkApplyTest.sh
===================================================================
--- libvirt-tck.orig/scripts/networks/networkApplyTest.sh
+++ libvirt-tck/scripts/networks/networkApplyTest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
VIRSH=virsh
@@ -33,8 +33,8 @@ TAP_FAIL_LIST=""
TAP_FAIL_CTR=0
TAP_TOT_CTR=0
-function usage() {
- local cmd="$0"
+usage() {
+ cmd="$0"
cat <<EOF
Usage: ${cmd} [--help|-h|-?] [--noattach] [--wait] [--verbose]
[--libvirt-test] [--tap-test]
@@ -56,37 +56,37 @@ EOF
}
-function tap_fail() {
- echo "not ok $1 - ${2:0:66}"
- TAP_FAIL_LIST+="$1 "
- ((TAP_FAIL_CTR++))
- ((TAP_TOT_CTR++))
+tap_fail() {
+ txt=$(echo "$2" | gawk '{print substr($0,1,66)}')
+ echo "not ok $1 - ${txt}"
+ TAP_FAIL_LIST="$TAP_FAIL_LIST $1 "
+ TAP_FAIL_CTR=$((TAP_FAIL_CTR+1))
+ TAP_TOT_CTR=$((TAP_TOT_CTR+1))
}
-function tap_pass() {
- echo "ok $1 - ${2:0:70}"
- ((TAP_TOT_CTR++))
+tap_pass() {
+ txt=$(echo "$2" | gawk '{print substr($0,1,66)}')
+ echo "ok $1 - ${txt}"
+ TAP_TOT_CTR=$((TAP_TOT_CTR+1))
}
-function tap_final() {
- local okay
-
+tap_final() {
[ -n "${TAP_FAIL_LIST}" ] && echo "FAILED tests ${TAP_FAIL_LIST}"
okay=$(echo "($TAP_TOT_CTR-$TAP_FAIL_CTR)*100/$TAP_TOT_CTR" | bc -l)
- echo "Failed ${TAP_FAIL_CTR}/${TAP_TOT_CTR} tests, ${okay:0:5}% okay"
+ txt=$(echo $okay | gawk '{print substr($0,1,5)}')
+ echo "Failed ${TAP_FAIL_CTR}/${TAP_TOT_CTR} tests, ${txt}% okay"
}
# A wrapper for mktemp in case it does not exist
# Echos the name of a secure temporary directory.
-function mktmpdir() {
- local tmp
+mktmpdir() {
{
- tmp=$( (umask 077 && mktemp -d ./nwfvmtest.XXXXXX) 2>/dev/null) &&
+ tmp=$( (umask 077 && mktemp -d ./nwtst.XXXXXX) 2>/dev/null) &&
test -n "$tmp" && test -d "$tmp"
} ||
{
- tmp=./nwfvmtest$$-$RANDOM
+ tmp=./nwtst$$-$RANDOM
(umask 077 && mkdir "$tmp")
} || { echo "failed to create secure temporary directory" >&2; exit 1; }
echo "${tmp}"
@@ -94,12 +94,11 @@ function mktmpdir() {
}
-function checkExpectedOutput() {
- local xmlfile="$1"
- local datafile="$2"
- local flags="$3"
- local skipregex="$4"
- local cmd line tmpdir tmpfile tmpfile2 skip
+checkExpectedOutput() {
+ xmlfile="$1"
+ datafile="$2"
+ flags="$3"
+ skipregex="$4"
tmpdir=$(mktmpdir)
tmpfile=$tmpdir/file
@@ -112,8 +111,8 @@ function checkExpectedOutput() {
exec 4<"${datafile}"
- read <&4
- line="${REPLY}"
+ IFS=""
+ read line <&4
while [ "x${line}x" != "xx" ]; do
cmd=$(echo "${line##\#}")
@@ -128,10 +127,11 @@ function checkExpectedOutput() {
: >"${tmpfile2}"
while :; do
- read <&4
- line="${REPLY}"
+ read line <&4
+
+ letter=$(echo ${line} | gawk '{print substr($1,1,1)}')
- if [ "${line:0:1}" == "#" ] || [ "x${line}x" == "xx" ]; then
+ if [ "x${letter}x" = "x#x" ] || [ "x${line}x" = "xx" ]; then
if [ ${skip} -ne 0 ]; then
break
@@ -144,18 +144,18 @@ function checkExpectedOutput() {
echo "FAIL ${xmlfile} : ${cmd}"
diff "${tmpfile}" "${tmpfile2}"
fi
- ((failctr++))
+ failctr=$((failctr+1))
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "tmp files: $tmpfile, $tmpfile2"
echo "Press enter"
- read
+ read enter
fi
[ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
test_result $((passctr+failctr)) "" 1
[ $((flags & FLAG_TAP_TEST)) -ne 0 ] && \
tap_fail $((passctr+failctr)) "${xmlfile} : ${cmd}"
else
- ((passctr++))
+ passctr=$((passctr+1))
[ $((flags & FLAG_VERBOSE)) -ne 0 ] && \
echo "PASS ${xmlfile} : ${cmd}"
[ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
@@ -177,12 +177,11 @@ function checkExpectedOutput() {
}
-function doTest() {
- local xmlfile="$1"
- local datafile="$2"
- local postdatafile="$3"
- local flags="$4"
- local netname
+doTest() {
+ xmlfile="$1"
+ datafile="$2"
+ postdatafile="$3"
+ flags="$4"
if [ ! -r "${xmlfile}" ]; then
echo "FAIL : Cannot access filter XML file ${xmlfile}."
@@ -205,24 +204,20 @@ function doTest() {
}
-function runTests() {
- local xmldir="$1"
- local hostoutdir="$2"
- local flags="$3"
- local datafiles f c
- local tap_total=0 ctr=0
-
- pushd "${PWD}" > /dev/null
- cd "${hostoutdir}"
- datafiles=$(ls *.dat)
- popd > /dev/null
+runTests() {
+ xmldir="$1"
+ hostoutdir="$2"
+ flags="$3"
+ tap_total=0 ctr=0
+
+ datafiles=$(cd "${hostoutdir}";ls *.dat)
if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
# Need to count the number of total tests
for fil in ${datafiles}; do
c=$(grep -c "^#" "${hostoutdir}/${fil}")
- ((tap_total+=c))
- ((ctr++))
+ tap_total=$((tap_total+c))
+ ctr=$((ctr+1))
done
echo "1..${tap_total}"
fi
@@ -250,22 +245,20 @@ function runTests() {
}
-function main() {
- local prgname="$0"
- local vm1 vm2
- local xmldir="networkxml2xmlin"
- local hostoutdir="networkxml2hostout"
- local res rc
- local flags
+main() {
+ prgname="$0"
+ xmldir="networkxml2xmlin"
+ hostoutdir="networkxml2hostout"
+ flags=0
while [ $# -ne 0 ]; do
case "$1" in
--help|-h|-\?) usage ${prgname}; exit 0;;
- --wait) ((flags |= FLAG_WAIT ));;
- --verbose) ((flags |= FLAG_VERBOSE ));;
- --libvirt-test) ((flags |= FLAG_LIBVIRT_TEST ));;
- --tap-test) ((flags |= FLAG_TAP_TEST ));;
- --force) ((flags |= FLAG_FORCE_CLEAN ));;
+ --wait) flags=$((flags | FLAG_WAIT ));;
+ --verbose) flags=$((flags | FLAG_VERBOSE ));;
+ --libvirt-test) flags=$((flags | FLAG_LIBVIRT_TEST ));;
+ --tap-test) flags=$((flags | FLAG_TAP_TEST ));;
+ --force) flags=$((flags | FLAG_FORCE_CLEAN ));;
*) usage ${prgname}; exit 1;;
esac
shift 1
@@ -290,8 +283,8 @@ function main() {
do
case ${name} in
tck*)
- if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
- $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" ] || \
+ [ $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
res=$(virsh destroy ${name} 2>&1)
res=$(virsh undefine ${name} 2>&1)
if [ $? -ne 0 ]; then
@@ -309,8 +302,8 @@ function main() {
do
case ${name} in
tck*)
- if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
- $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" ] || \
+ [ $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
res=$(virsh net-destroy ${name} 2>&1)
rc=$?
res=$(virsh net-undefine ${name} 2>&1)
@@ -327,13 +320,13 @@ function main() {
fi
if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- pushd "${PWD}" > /dev/null
+ curdir="${PWD}"
. ./test-lib.sh
if [ $? -ne 0 ]; then
exit 1
fi
test_intro $this_test
- popd > /dev/null
+ cd "${curdir}"
fi
res=$(${VIRSH} capabilities 2>&1)
Index: libvirt-tck/scripts/nwfilter/nwfilter2vmtest.sh
===================================================================
--- libvirt-tck.orig/scripts/nwfilter/nwfilter2vmtest.sh
+++ libvirt-tck/scripts/nwfilter/nwfilter2vmtest.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
ORIG_IFNAME="vnet0"
ATTACH_IFNAME="attach0"
@@ -6,17 +6,20 @@ TESTFILTERNAME="nwfiltertestfilter"
TESTVM2FWALLDATA="nwfilterxml2fwallout/testvm.fwall.dat"
VIRSH=virsh
-uri=
-if [ "x${LIBVIRT_TCK_CONFIG}x" != "xx" ]; then
- uri_exp=`cat ${LIBVIRT_TCK_CONFIG} | grep "^uri\s*=" | sed -e 's/uri\s*=\s*//' | tail -n 1`
- if [ "x${uri_exp}x" != "xx" ]; then
- eval "uri=${uri_exp}"
- fi
-else
- uri="qemu:///system"
-fi
-LIBVIRT_URI=${uri}
+# For each line starting with uri=, remove the prefix and set the hold
+# space to the rest of the line. Then at file end, print the hold
+# space, which is effectively the last uri= line encountered.
+uri=$(sed -n '/^uri[ ]*=[ ]*/ {
+ s///
+ h
+}
+$ {
+ x
+ p
+}' < "$LIBVIRT_TCK_CONFIG")
+: "${uri:=qemu:///system}"
+LIBVIRT_URI=${uri}
FLAG_WAIT="$((1<<0))"
FLAG_ATTACH="$((1<<1))"
@@ -34,8 +37,8 @@ TAP_FAIL_LIST=""
TAP_FAIL_CTR=0
TAP_TOT_CTR=0
-function usage() {
- local cmd="$0"
+usage() {
+ cmd="$0"
cat <<EOF
Usage: ${cmd} [--help|-h|-?] [--noattach] [--wait] [--verbose]
[--libvirt-test] [--tap-test]
@@ -60,66 +63,61 @@ EOF
}
-function tap_fail() {
- echo "not ok $1 - ${2:0:66}"
- TAP_FAIL_LIST+="$1 "
- ((TAP_FAIL_CTR++))
- ((TAP_TOT_CTR++))
+tap_fail() {
+ txt=$(echo "$2" | gawk '{print substr($0,1,66)}')
+ echo "not ok $1 - ${txt}"
+ TAP_FAIL_LIST="$TAP_FAIL_LIST $1 "
+ TAP_FAIL_CTR=$((TAP_FAIL_CTR+1))
+ TAP_TOT_CTR=$((TAP_TOT_CTR+1))
}
-function tap_pass() {
- echo "ok $1 - ${2:0:70}"
- ((TAP_TOT_CTR++))
+tap_pass() {
+ txt=$(echo "$2" | gawk '{print substr($0,1,70)}')
+ echo "ok $1 - ${txt}"
+ TAP_TOT_CTR=$((TAP_TOT_CTR+1))
}
-function tap_final() {
- local okay
-
+tap_final() {
[ -n "${TAP_FAIL_LIST}" ] && echo "FAILED tests ${TAP_FAIL_LIST}"
okay=`echo "($TAP_TOT_CTR-$TAP_FAIL_CTR)*100/$TAP_TOT_CTR" | bc -l`
- echo "Failed ${TAP_FAIL_CTR}/${TAP_TOT_CTR} tests, ${okay:0:5}% okay"
+ txt=$(echo $okay | gawk '{print substr($0,1,5)}')
+ echo "Failed ${TAP_FAIL_CTR}/${TAP_TOT_CTR} tests, ${txt}% okay"
}
# A wrapper for mktemp in case it does not exist
# Echos the name of a temporary file.
-function mktmpfile() {
- local tmp
- type -P mktemp > /dev/null
- if [ $? -eq 0 ]; then
- tmp=$(mktemp -t nwfvmtest.XXXXXX)
- echo ${tmp}
- else
- while :; do
- tmp="/tmp/nwfvmtest.${RANDOM}"
- if [ ! -f ${tmp} ]; then
- touch ${tmp}
- chmod 666 ${tmp}
- echo ${tmp}
- break
- fi
- done
- fi
+mktmpdir() {
+ {
+ tmp=$( (umask 077 && mktemp -d ./nwfvmtest.XXXXXX) 2>/dev/null) &&
+ test -n "$tmp" && test -d "$tmp"
+ } ||
+ {
+ tmp=./nwfvmtest$$-$RANDOM
+ (umask 077 && mkdir "$tmp")
+ } || { echo "failed to create secure temporary directory" >&2; exit 1; }
+ echo "${tmp}"
return 0
}
-function checkExpectedOutput() {
- local xmlfile="$1"
- local fwallfile="$2"
- local ifname="$3"
- local flags="$4"
- local skipregex="$5"
- local regex="s/${ORIG_IFNAME}/${ifname}/g"
- local cmd line tmpfile tmpfile2 skip
-
- tmpfile=`mktmpfile`
- tmpfile2=`mktmpfile`
+checkExpectedOutput() {
+ xmlfile="$1"
+ fwallfile="$2"
+ ifname="$3"
+ flags="$4"
+ skipregex="$5"
+ regex="s/${ORIG_IFNAME}/${ifname}/g"
+
+ tmpdir=$(mktmpdir)
+ tmpfile=$tmpdir/file
+ tmpfile2=$tmpdir/file2
exec 4<${fwallfile}
- read <&4
- line="${REPLY}"
+ IFS=""
+
+ read line <&4
while [ "x${line}x" != "xx" ]; do
cmd=`echo ${line##\#} | sed ${regex}`
@@ -135,10 +133,11 @@ function checkExpectedOutput() {
touch ${tmpfile2}
while [ 1 ]; do
- read <&4
- line="${REPLY}"
+ read line <&4
- if [ "${line:0:1}" == "#" ] || [ "x${line}x" == "xx" ]; then
+ letter=$(echo $line | gawk '{print substr($1,1,1)}')
+
+ if [ "x${letter}x" = "x#x" ] || [ "x${line}x" = "xx" ]; then
if [ ${skip} -ne 0 ]; then
break
@@ -151,18 +150,18 @@ function checkExpectedOutput() {
echo "FAIL ${xmlfile} : ${cmd}"
diff ${tmpfile} ${tmpfile2}
fi
- ((failctr++))
+ failctr=$((failctr+1))
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "tmp files: $tmpfile, $tmpfile2"
echo "Press enter"
- read
+ read enter
fi
[ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
test_result $((passctr+failctr)) "" 1
[ $((flags & FLAG_TAP_TEST)) -ne 0 ] && \
tap_fail $((passctr+failctr)) "${xmlfile} : ${cmd}"
else
- ((passctr++))
+ passctr=$((passctr+1))
[ $((flags & FLAG_VERBOSE)) -ne 0 ] && \
echo "PASS ${xmlfile} : ${cmd}"
[ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
@@ -180,19 +179,18 @@ function checkExpectedOutput() {
exec 4>&-
- rm -rf "${tmpfile}" "${tmpfile2}" 2>/dev/null
+ rm -rf "${tmpdir}"
}
-function doTest() {
- local xmlfile="$1"
- local fwallfile="$2"
- local vm1name="$3"
- local vm2name="$4"
- local flags="$5"
- local testnum="$6"
- local linenums ctr=0
- local tmpfile b msg rc
+doTest() {
+ xmlfile="$1"
+ fwallfile="$2"
+ vm1name="$3"
+ vm2name="$4"
+ flags="$5"
+ testnum="$6"
+ ctr=0
if [ ! -r "${xmlfile}" ]; then
echo "FAIL : Cannot access filter XML file ${xmlfile}."
@@ -209,7 +207,8 @@ function doTest() {
if [ $((flags & FLAG_ATTACH)) -ne 0 ]; then
- tmpfile=`mktmpfile`
+ tmpdir=$(mktmpdir)
+ tmpfile=$tmpdir/tmpfile
b=`{ ${VIRSH} dumpxml ${vm1name} | tr -d "\n"; echo; } | \
sed "s/.*\<interface.*source bridge='\([a-zA-Z0-9_]\+\)'.*<\/interface>.*/\1/"`
@@ -225,7 +224,7 @@ EOF
msg=`${VIRSH} attach-device "${vm1name}" "${tmpfile}" > /dev/null`
rc=$?
- ((attachctr++))
+ attachctr=$((attachctr+1))
if [ $rc -eq 0 ]; then
checkExpectedOutput "${xmlfile}" "${fwallfile}" "${ATTACH_IFNAME}" \
@@ -245,48 +244,45 @@ EOF
checkExpectedOutput "${TESTFILTERNAME}" "${TESTVM2FWALLDATA}" \
"${vm2name}" "${flags}" #"(PRE|POST)ROUTING"
fi
-
- ((attachfailctr++))
+
+ attachfailctr=$((attachfailctr+1))
if [ $((flags & FLAG_VERBOSE)) -ne 0 ]; then
echo "FAIL: Could not attach interface to vm ${vm1name}."
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter"
- read
+ read enter
fi
fi
fi
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
fi
return 0
}
-function runTests() {
- local vm1name="$1"
- local vm2name="$2"
- local xmldir="$3"
- local fwalldir="$4"
- local flags="$5"
- local fwallfiles f c
- local tap_total=0 ctr=0
-
- pushd ${PWD} > /dev/null
- cd ${fwalldir}
- fwallfiles=`ls *.fwall`
- popd > /dev/null
+runTests() {
+ vm1name="$1"
+ vm2name="$2"
+ xmldir="$3"
+ fwalldir="$4"
+ flags="$5"
+ tap_total=0
+ ctr=0
+
+ fwallfiles=$(cd ${fwalldir}; ls *.fwall)
if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
# Need to count the number of total tests
for fil in ${fwallfiles}; do
c=$(grep -c "^#" ${fwalldir}/${fil})
- ((tap_total+=c))
- ((ctr++))
+ tap_total=$((tap_total+c))
+ ctr=$((ctr+1))
done
c=$(grep -c "^#" "${TESTVM2FWALLDATA}")
- ((tap_total+=c*ctr))
- [ $((flags & FLAG_ATTACH)) -ne 0 ] && ((tap_total*=2))
+ tap_total=$((tap_total+c*ctr))
+ [ $((flags & FLAG_ATTACH)) -ne 0 ] && tap_total=$((tap_total*2))
echo "1..${tap_total}"
fi
@@ -310,14 +306,14 @@ function runTests() {
}
-function createVM() {
- local vmname="$1"
- local filtername="$2"
- local ipaddr="$3"
- local macaddr="$4"
- local flags="$5"
- local res
- local tmpfile='mktmpfile'
+createVM() {
+ vmname="$1"
+ filtername="$2"
+ ipaddr="$3"
+ macaddr="$4"
+ flags="$5"
+ tmpdir=$(mktmpdir)
+ tmpfile=$tmpdir/tmpfile
cat > ${tmpfile} << EOF
<domain type='kvm'>
@@ -365,7 +361,7 @@ EOF
echo "Could not start VM ${vmname} : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
$(${VIRSH} undefine ${vmname})
return 1
@@ -373,23 +369,22 @@ EOF
[ $((flags & FLAG_VERBOSE)) -ne 0 ] && echo "Created VM ${vmname}."
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
return 0
}
-function destroyVM() {
- local vmname="$1"
- local flags="$2"
- local res
+destroyVM() {
+ vmname="$1"
+ flags="$2"
res=$(${VIRSH} destroy ${vmname})
if [ $? -ne 0 ]; then
echo "Could not destroy VM ${vmname} : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -399,7 +394,7 @@ function destroyVM() {
echo "Could not undefine VM ${vmname} : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -410,10 +405,10 @@ function destroyVM() {
}
-function createTestFilters() {
- local flags="$1"
- local tmpfile=`mktmpfile`
- local res
+createTestFilters() {
+ flags="$1"
+ tmpdir=$(mktmpdir)
+ tmpfile=$tmpdir/tmpfile
cat >${tmpfile} << EOF
<filter name="${TESTFILTERNAME}">
@@ -433,9 +428,9 @@ EOF
echo "Could not define filter : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
return 1
fi
@@ -448,28 +443,27 @@ EOF
echo "Could not define filter : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
return 1
fi
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
return 0
}
-function deleteTestFilter() {
- local flags="$1"
- local res
+deleteTestFilter() {
+ flags="$1"
res=$(${VIRSH} nwfilter-undefine ${TESTFILTERNAME} 2>&1)
if [ $? -ne 0 ]; then
echo "Could not undefine filter : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -478,7 +472,7 @@ function deleteTestFilter() {
echo "Could not undefine filter : ${res}"
if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -486,27 +480,25 @@ function deleteTestFilter() {
}
-function main() {
- local prgname="$0"
- local vm1 vm2
- local xmldir="nwfilterxml2xmlin"
- local fwalldir="nwfilterxml2fwallout"
- local found=0 vms res
- local filtername="tck-testcase"
- local libvirtdpid=-1
- local flags OPWD
+main() {
+ prgname="$0"
+ xmldir="nwfilterxml2xmlin"
+ fwalldir="nwfilterxml2fwallout"
+ found=0
+ filtername="tck-testcase"
+ libvirtdpid=-1
- ((flags=${FLAG_ATTACH}))
+ flags=${FLAG_ATTACH}
while [ $# -ne 0 ]; do
case "$1" in
--help|-h|-\?) usage ${prgname}; exit 0;;
- --noattach) ((flags &= ~FLAG_ATTACH ));;
- --wait) ((flags |= FLAG_WAIT ));;
- --verbose) ((flags |= FLAG_VERBOSE ));;
- --libvirt-test) ((flags |= FLAG_LIBVIRT_TEST ));;
- --tap-test) ((flags |= FLAG_TAP_TEST ));;
- --force) ((flags |= FLAG_FORCE_CLEAN ));;
+ --noattach) flags=$((flags & ~FLAG_ATTACH));;
+ --wait) flags=$((flags | FLAG_WAIT ));;
+ --verbose) flags=$((flags | FLAG_VERBOSE ));;
+ --libvirt-test) flags=$((flags | FLAG_LIBVIRT_TEST ));;
+ --tap-test) flags=$((flags | FLAG_TAP_TEST ));;
+ --force) flags=$((flags | FLAG_FORCE_CLEAN ));;
*) usage ${prgname}; exit 1;;
esac
shift 1
@@ -527,15 +519,17 @@ function main() {
exit 0
fi
- for name in `virsh list | awk '{print $2}'`
+ for name in `virsh list --all | awk '{print $2}'`
do
case ${name} in
tck*)
- if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
- $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" = "x1" ] || \
+ [ $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
res=$(virsh destroy ${name} 2>&1)
+ rc1=$?
res=$(virsh undefine ${name} 2>&1)
- if [ $? -ne 0 ]; then
+ rc2=$?
+ if [ $rc1 -ne 0 ] && [ $rc2 -ne 0 ]; then
echo "Bail out! Could not undefine nwfiler ${name}: ${res}"
exit 0
fi
@@ -550,15 +544,15 @@ function main() {
do
case ${name} in
tck*)
- if [ "x${LIBVIRT_TCK_AUTOCLEAN}" == "x1" -o \
- $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
+ if [ "x${LIBVIRT_TCK_AUTOCLEAN}" = "x1" ] || \
+ [ $((flags & FLAG_FORCE_CLEAN)) -ne 0 ]; then
res=$(virsh nwfilter-undefine ${name} 2>&1)
if [ $? -ne 0 ]; then
- echo "Bail out! Could not undefine domain ${name}: ${res}"
+ echo "Bail out! Could not undefine filter ${name}: ${res}"
exit 1
fi
else
- echo "Bail out! Domain ${name} already exists, use --force to clean"
+ echo "Bail out! Filter ${name} already exists, use --force to clean"
exit 1
fi
esac
@@ -566,19 +560,19 @@ function main() {
fi
if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- pushd ${PWD} > /dev/null
+ curdir="${PWD}"
. test-lib.sh
if [ $? -ne 0 ]; then
exit 1
fi
test_intro $this_test
- popd > /dev/null
+ cd "${curdir}"
fi
res=$(${VIRSH} capabilities 2>&1)
- vm1="tck-testvm${RANDOM}"
- vm2="tck-testvm${RANDOM}"
+ vm1="tck-test$$1"
+ vm2="tck-test$$2"
createTestFilters "${flags}"
if [ $? -ne 0 ]; then
Index: libvirt-tck/scripts/networks/100-apply-verify-host.t
===================================================================
--- libvirt-tck.orig/scripts/networks/100-apply-verify-host.t
+++ libvirt-tck/scripts/networks/100-apply-verify-host.t
@@ -1,10 +1,5 @@
-#!/bin/bash
+#!/bin/sh
pwd=$(dirname $0)
-pushd ${PWD} > /dev/null
-
-cd ${pwd}
-bash ./networkApplyTest.sh --tap-test
-
-popd > /dev/null
+(cd ${pwd}; sh ./networkApplyTest.sh --tap-test)
Index: libvirt-tck/scripts/nwfilter/050-apply-verify-host.t
===================================================================
--- libvirt-tck.orig/scripts/nwfilter/050-apply-verify-host.t
+++ libvirt-tck/scripts/nwfilter/050-apply-verify-host.t
@@ -1,10 +1,5 @@
-#!/bin/bash
+#!/bin/sh
pwd=$(dirname $0)
-pushd ${PWD} > /dev/null
-
-cd ${pwd}
-bash ./nwfilter2vmtest.sh --tap-test --noattach
-
-popd > /dev/null
\ No newline at end of file
+(cd ${pwd}; sh ./nwfilter2vmtest.sh --tap-test --noattach)
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.dat
===================================================================
--- libvirt-tck.orig/scripts/networks/networkxml2hostout/tck-testnet-1.dat
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.dat
@@ -5,7 +5,7 @@ MASQUERADE all -- 10.1.2.0/24
#iptables -n -L FORWARD | grep ' 10\\.1\\.2\\.'
ACCEPT all -- 0.0.0.0/0 10.1.2.0/24 state RELATED,ESTABLISHED
ACCEPT all -- 10.1.2.0/24 0.0.0.0/0
-#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*\\(dnsmasq[[:print:]*]\\)|\\1|p'
+#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*dnsmasq|dnsmasq|p'
dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/libvirt/network/tck-testnet.pid --conf-file= --listen-address 10.1.2.1 --except-interface lo --dhcp-range 10.1.2.2,10.1.2.254 --dhcp-lease-max=253 --dhcp-no-override
#route -n | grep '10\\.1\\.2\\.'
10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.dat
===================================================================
--- libvirt-tck.orig/scripts/networks/networkxml2hostout/tck-testnet-2.dat
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.dat
@@ -2,7 +2,7 @@
ACCEPT all -- 0.0.0.0/0 10.1.2.0/24
ACCEPT all -- 10.1.2.0/24 0.0.0.0/0
#iptables -t nat -L -n | grep ' 10\\.1\\.2\\.'
-#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*\\(dnsmasq[[:print:]*]\\)|\\1|p'
+#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*dnsmasq|dnsmasq|p'
dnsmasq --strict-order --bind-interfaces --pid-file=/var/run/libvirt/network/tck-testnet.pid --conf-file= --listen-address 10.1.2.1 --except-interface lo --dhcp-range 10.1.2.2,10.1.2.254 --dhcp-lease-max=253 --dhcp-no-override
#route -n | grep '10\\.1\\.2\\.'
10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
14 years, 1 month
[libvirt] [PATCH v2] macvtap: convert send / recv function to use libnl
by Stefan Berger
-V2:
- adapting patch due to changes in the same file by another patch
In a second step I am converting the netlink send/receive functions to
use libnl.
I tested this with 802.1Qbg profiles and my test server and did not see
a regression.
Caveat: The online documentation of libnl talks about nl_socket_alloc()
but the header file provides nl_handle_alloc() -- this could be a hint
to a possible problem between libnl versions...
http://www.infradead.org/~tgr/libnl/doc/group__socket.html
versus
http://libnl.sourcearchive.com/documentation/1.1/group__socket_gf903c9ea0...
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
src/util/macvtap.c | 82 +++++++++++++++++++----------------------------------
1 file changed, 30 insertions(+), 52 deletions(-)
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -83,16 +83,6 @@ enum virVirtualPortOp {
};
-static int nlOpen(void)
-{
- int fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
- if (fd < 0)
- virReportSystemError(errno,
- "%s",_("cannot open netlink socket"));
- return fd;
-}
-
-
/**
* nlComm:
* @nlmsg: pointer to netlink message
@@ -106,8 +96,8 @@ static int nlOpen(void)
* buffer will be returned.
*/
static
-int nlComm(struct nlmsghdr *nlmsg,
- char **respbuf, unsigned int *respbuflen,
+int nlComm(struct nl_msg *nl_msg,
+ unsigned char **respbuf, unsigned int *respbuflen,
int nl_pid)
{
int rc = 0;
@@ -116,24 +106,29 @@ int nlComm(struct nlmsghdr *nlmsg,
.nl_pid = nl_pid,
.nl_groups = 0,
};
- int rcvChunkSize = 1024; // expecting less than that
- int rcvoffset = 0;
ssize_t nbytes;
struct timeval tv = {
.tv_sec = NETLINK_ACK_TIMEOUT_S,
};
fd_set readfds;
- int fd = nlOpen();
+ int fd;
int n;
+ struct nl_handle *nlhandle = nl_handle_alloc();
+ struct nlmsghdr *nlmsg = nlmsg_hdr(nl_msg);
- if (fd < 0)
+ if (!nlhandle)
return -1;
+ if (nl_connect(nlhandle, NETLINK_ROUTE) < 0) {
+ rc = -1;
+ goto err_exit;
+ }
+
+ nlmsg_set_dst(nl_msg, &nladdr);
+
nlmsg->nlmsg_pid = getpid();
- nlmsg->nlmsg_flags |= NLM_F_ACK;
- nbytes = sendto(fd, (void *)nlmsg, nlmsg->nlmsg_len, 0,
- (struct sockaddr *)&nladdr, sizeof(nladdr));
+ nbytes = nl_send_auto_complete(nlhandle, nl_msg);
if (nbytes < 0) {
virReportSystemError(errno,
"%s", _("cannot send to netlink socket"));
@@ -141,6 +136,8 @@ int nlComm(struct nlmsghdr *nlmsg,
goto err_exit;
}
+ fd = nl_socket_get_fd(nlhandle);
+
FD_ZERO(&readfds);
FD_SET(fd, &readfds);
@@ -156,28 +153,9 @@ int nlComm(struct nlmsghdr *nlmsg,
goto err_exit;
}
- while (1) {
- if (VIR_REALLOC_N(*respbuf, rcvoffset+rcvChunkSize) < 0) {
- virReportOOMError();
- rc = -1;
- goto err_exit;
- }
-
- socklen_t addrlen = sizeof(nladdr);
- nbytes = recvfrom(fd, &((*respbuf)[rcvoffset]), rcvChunkSize, 0,
- (struct sockaddr *)&nladdr, &addrlen);
- if (nbytes < 0) {
- if (errno == EAGAIN || errno == EINTR)
- continue;
- virReportSystemError(errno, "%s",
- _("error receiving from netlink socket"));
- rc = -1;
- goto err_exit;
- }
- rcvoffset += nbytes;
- break;
- }
- *respbuflen = rcvoffset;
+ *respbuflen = nl_recv(nlhandle, &nladdr, respbuf, NULL);
+ if (*respbuflen <= 0)
+ rc = -1;
err_exit:
if (rc == -1) {
@@ -186,7 +164,7 @@ err_exit:
*respbuflen = 0;
}
- VIR_FORCE_CLOSE(fd);
+ nl_handle_destroy(nlhandle);
return rc;
}
@@ -206,7 +184,7 @@ link_add(const char *type,
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
int ifindex;
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
struct nlattr *linkinfo, *info_data;
@@ -255,7 +233,7 @@ link_add(const char *type,
nla_nest_end(nl_msg, linkinfo);
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
rc = -1;
goto err_exit;
}
@@ -327,7 +305,7 @@ link_del(const char *ifname)
struct nlmsghdr *resp;
struct nlmsgerr *err;
struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC };
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen;
struct nl_msg *nl_msg;
@@ -344,7 +322,7 @@ link_del(const char *ifname)
if (nla_put(nl_msg, IFLA_IFNAME, strlen(ifname)+1, ifname) < 0)
goto buffer_too_small;
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, 0) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, 0) < 0) {
rc = -1;
goto err_exit;
}
@@ -739,7 +717,7 @@ getLldpadPid(void) {
static int
link_dump(bool nltarget_kernel, const char *ifname, int ifindex,
- struct nlattr **tb, char **recvbuf)
+ struct nlattr **tb, unsigned char **recvbuf)
{
int rc = 0;
struct nlmsghdr *resp;
@@ -776,7 +754,7 @@ link_dump(bool nltarget_kernel, const ch
}
}
- if (nlComm(nlmsg_hdr(nl_msg), recvbuf, &recvbuflen, pid) < 0) {
+ if (nlComm(nl_msg, recvbuf, &recvbuflen, pid) < 0) {
rc = -1;
goto err_exit;
}
@@ -862,7 +840,7 @@ ifaceGetNthParent(int ifindex, const cha
{
int rc;
struct nlattr *tb[IFLA_MAX + 1] = { NULL, };
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
bool end = false;
unsigned int i = 0;
@@ -1022,7 +1000,7 @@ doPortProfileOpSetLink(bool nltarget_ker
.ifi_family = AF_UNSPEC,
.ifi_index = ifindex,
};
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
unsigned int recvbuflen = 0;
uint32_t pid = 0;
struct nl_msg *nl_msg;
@@ -1133,7 +1111,7 @@ doPortProfileOpSetLink(bool nltarget_ker
}
}
- if (nlComm(nlmsg_hdr(nl_msg), &recvbuf, &recvbuflen, pid) < 0) {
+ if (nlComm(nl_msg, &recvbuf, &recvbuflen, pid) < 0) {
rc = -1;
goto err_exit;
}
@@ -1201,7 +1179,7 @@ doPortProfileOpCommon(bool nltarget_kern
uint8_t op)
{
int rc;
- char *recvbuf = NULL;
+ unsigned char *recvbuf = NULL;
struct nlattr *tb[IFLA_MAX + 1] = { NULL , };
int repeats = STATUS_POLL_TIMEOUT_USEC / STATUS_POLL_INTERVL_USEC;
uint16_t status = 0;
14 years, 1 month
[libvirt] [PATCH] RFC: Remove all object hashtable caches from virConnectPtr
by Daniel P. Berrange
The virConnectPtr struct will cache instances of all other
objects. APIs like virDomainLookupByUUID will return a
cached object, so if you do virDomainLookupByUUID twice in
a row, you'll get the same exact virDomainPtr instance.
This does not have any performance benefit, since the actual
logic in virDomainLookupByUUID (and other APIs returning
virDomainPtr, etc instances) is not short-circuited. All
it does is to ensure there is only one single virDomainPtr
in existance for any given UUID.
The caching has a number of downsides though, all relating
to stale data. If APIs aren't careful to always overwrite
the 'id' field in virDomainPtr it may become out of data.
Likewise for the name field, if a guest is renamed, or if
a guest is deleted, and then a new one created with the
same UUID but different name.
This has been an ongoing, endless source of bugs for all
applications using libvirt from languages with garbage
collection, causing them to get virDomainPtr instances
from long ago with stale data.
The caching is also a waste of memory resources, since
both applications, and language bindings often maintain
their own hashtable caches of object instances.
This patch removes all the hash table caching, so all
APIs return brand new virDomainPtr (etc) object instances.
Other options include
- Explicitly overrite the 'name' field in the cached
objects every time they are looked up, to ensure
fully up2date objects
- Add a flag to virConnectOpen to allow apps to
turn off caching themselves.
* src/datatypes.h: Delete all hash tables.
* src/datatypes.c: Remove all object caching code
---
src/datatypes.c | 657 +++++++++++++------------------------------------------
src/datatypes.h | 10 -
2 files changed, 149 insertions(+), 518 deletions(-)
diff --git a/src/datatypes.c b/src/datatypes.c
index 46009ae..66dbc99 100644
--- a/src/datatypes.c
+++ b/src/datatypes.c
@@ -41,120 +41,6 @@
* *
************************************************************************/
-/**
- * virDomainFreeName:
- * @domain: a domain object
- *
- * Destroy the domain object, this is just used by the domain hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virDomainFreeName(virDomainPtr domain, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefDomain(domain));
-}
-
-/**
- * virNetworkFreeName:
- * @network: a network object
- *
- * Destroy the network object, this is just used by the network hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virNetworkFreeName(virNetworkPtr network, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefNetwork(network));
-}
-
-/**
- * virInterfaceFreeName:
- * @interface: an interface object
- *
- * Destroy the interface object, this is just used by the interface hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virInterfaceFreeName(virInterfacePtr iface, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefInterface(iface));
-}
-
-/**
- * virStoragePoolFreeName:
- * @pool: a pool object
- *
- * Destroy the pool object, this is just used by the pool hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virStoragePoolFreeName(virStoragePoolPtr pool, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefStoragePool(pool));
-}
-
-/**
- * virStorageVolFreeName:
- * @vol: a vol object
- *
- * Destroy the vol object, this is just used by the vol hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virStorageVolFreeName(virStorageVolPtr vol, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefStorageVol(vol));
-}
-
-/**
- * virSecretFreeName:
- * @secret_: a secret object
- *
- * Destroy the secret object, this is just used by the secret hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static void
-virSecretFreeName(void *secret_, const char *name ATTRIBUTE_UNUSED)
-{
- virSecretPtr secret;
-
- secret = secret_;
- virUnrefSecret(secret);
-}
-
-/**
- * virNWFilterPoolFreeName:
- * @pool: a nwfilter pool object
- *
- * Destroy the nwfilter pool object, this is just used by the nwfilter pool hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virNWFilterPoolFreeName(virNWFilterPtr pool, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefNWFilter(pool));
-}
-
-/**
- * virDomainSnapshotFreeName:
- * @snapshot: a domain snapshotobject
- *
- * Destroy the domain snapshot object, this is just used by the domain hash callback.
- *
- * Returns 0 in case of success and -1 in case of failure.
- */
-static int
-virDomainSnapshotFreeName(virDomainSnapshotPtr snapshot, const char *name ATTRIBUTE_UNUSED)
-{
- return (virUnrefDomainSnapshot(snapshot));
-}
/**
* virGetConnect:
@@ -182,53 +68,12 @@ virGetConnect(void) {
ret->privateData = NULL;
ret->networkPrivateData = NULL;
ret->interfacePrivateData = NULL;
- ret->domains = virHashCreate(20);
- if (ret->domains == NULL)
- goto failed;
- ret->networks = virHashCreate(20);
- if (ret->networks == NULL)
- goto failed;
- ret->interfaces = virHashCreate(20);
- if (ret->interfaces == NULL)
- goto failed;
- ret->storagePools = virHashCreate(20);
- if (ret->storagePools == NULL)
- goto failed;
- ret->storageVols = virHashCreate(20);
- if (ret->storageVols == NULL)
- goto failed;
- ret->nodeDevices = virHashCreate(256);
- if (ret->nodeDevices == NULL)
- goto failed;
- ret->secrets = virHashCreate(20);
- if (ret->secrets == NULL)
- goto failed;
- ret->nwfilterPools = virHashCreate(20);
- if (ret->nwfilterPools == NULL)
- goto failed;
ret->refs = 1;
return(ret);
failed:
if (ret != NULL) {
- if (ret->domains != NULL)
- virHashFree(ret->domains, (virHashDeallocator) virDomainFreeName);
- if (ret->networks != NULL)
- virHashFree(ret->networks, (virHashDeallocator) virNetworkFreeName);
- if (ret->interfaces != NULL)
- virHashFree(ret->interfaces, (virHashDeallocator) virInterfaceFreeName);
- if (ret->storagePools != NULL)
- virHashFree(ret->storagePools, (virHashDeallocator) virStoragePoolFreeName);
- if (ret->storageVols != NULL)
- virHashFree(ret->storageVols, (virHashDeallocator) virStorageVolFreeName);
- if (ret->nodeDevices != NULL)
- virHashFree(ret->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
- if (ret->secrets != NULL)
- virHashFree(ret->secrets, virSecretFreeName);
- if (ret->nwfilterPools != NULL)
- virHashFree(ret->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
-
virMutexDestroy(&ret->lock);
VIR_FREE(ret);
}
@@ -247,22 +92,6 @@ failed:
static void
virReleaseConnect(virConnectPtr conn) {
DEBUG("release connection %p", conn);
- if (conn->domains != NULL)
- virHashFree(conn->domains, (virHashDeallocator) virDomainFreeName);
- if (conn->networks != NULL)
- virHashFree(conn->networks, (virHashDeallocator) virNetworkFreeName);
- if (conn->interfaces != NULL)
- virHashFree(conn->interfaces, (virHashDeallocator) virInterfaceFreeName);
- if (conn->storagePools != NULL)
- virHashFree(conn->storagePools, (virHashDeallocator) virStoragePoolFreeName);
- if (conn->storageVols != NULL)
- virHashFree(conn->storageVols, (virHashDeallocator) virStorageVolFreeName);
- if (conn->nodeDevices != NULL)
- virHashFree(conn->nodeDevices, (virHashDeallocator) virNodeDeviceFree);
- if (conn->secrets != NULL)
- virHashFree(conn->secrets, virSecretFreeName);
- if (conn->nwfilterPools != NULL)
- virHashFree(conn->nwfilterPools, (virHashDeallocator) virNWFilterPoolFreeName);
virResetError(&conn->err);
@@ -353,36 +182,23 @@ virGetDomain(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virUUIDFormat(uuid, uuidstr);
- ret = (virDomainPtr) virHashLookup(conn->domains, uuidstr);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_DOMAIN_MAGIC;
- ret->conn = conn;
- ret->id = -1;
- memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- ret->snapshots = virHashCreate(20);
-
- if (virHashAddEntry(conn->domains, uuidstr, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add domain to connection hash table"));
- goto error;
- }
- conn->refs++;
- DEBUG("New hash entry %p", ret);
- } else {
- DEBUG("Existing hash entry %p: refs now %d", ret, ret->refs+1);
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->magic = VIR_DOMAIN_MAGIC;
+ ret->conn = conn;
+ ret->id = -1;
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -415,18 +231,9 @@ virReleaseDomain(virDomainPtr domain) {
virUUIDFormat(domain->uuid, uuidstr);
DEBUG("release domain %p %s %s", domain, domain->name, uuidstr);
- if (virHashRemoveEntry(conn->domains, uuidstr, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("domain missing from connection hash table"));
- conn = NULL;
- }
-
domain->magic = -1;
domain->id = -1;
VIR_FREE(domain->name);
- if (domain->snapshots != NULL)
- virHashFree(domain->snapshots, (virHashDeallocator) virDomainSnapshotFreeName);
VIR_FREE(domain);
if (conn) {
@@ -499,31 +306,22 @@ virGetNetwork(virConnectPtr conn, const char *name, const unsigned char *uuid) {
virUUIDFormat(uuid, uuidstr);
- ret = (virNetworkPtr) virHashLookup(conn->networks, uuidstr);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NETWORK_MAGIC;
- ret->conn = conn;
- memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
- if (virHashAddEntry(conn->networks, uuidstr, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add network to connection hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->magic = VIR_NETWORK_MAGIC;
+ ret->conn = conn;
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -556,13 +354,6 @@ virReleaseNetwork(virNetworkPtr network) {
virUUIDFormat(network->uuid, uuidstr);
DEBUG("release network %p %s %s", network, network->name, uuidstr);
- if (virHashRemoveEntry(conn->networks, uuidstr, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("network missing from connection hash table"));
- conn = NULL;
- }
-
network->magic = -1;
VIR_FREE(network->name);
VIR_FREE(network);
@@ -641,70 +432,28 @@ virGetInterface(virConnectPtr conn, const char *name, const char *mac) {
virMutexLock(&conn->lock);
- ret = (virInterfacePtr) virHashLookup(conn->interfaces, name);
-
- if (ret != NULL) {
- if (STRCASENEQ(ret->mac, mac)) {
- /*
- * If the mac address has changed, try to modify it in
- * place, which will only work if the new mac is the
- * same length as, or shorter than, the old mac.
- */
- size_t newmaclen = strlen(mac);
- size_t oldmaclen = strlen(ret->mac);
- if (newmaclen <= oldmaclen) {
- strcpy(ret->mac, mac);
- } else {
- /*
- * If it's longer, we're kind of screwed, because we
- * can't add a new hashtable entry (it would clash
- * with the existing entry of same name), and we can't
- * free/re-alloc the existing entry's mac, as some
- * other thread may already be using the existing mac
- * pointer. Fortunately, this should never happen,
- * since the length of the mac address for any
- * interface is determined by the type of the
- * interface, and that is unlikely to change.
- */
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- _("Failed to change interface mac address "
- "from %s to %s due to differing lengths."),
- ret->mac, mac);
- ret = NULL;
- goto error;
- }
- }
- } else {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->mac = strdup(mac);
- if (ret->mac == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->mac = strdup(mac);
+ if (ret->mac == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
- ret->magic = VIR_INTERFACE_MAGIC;
- ret->conn = conn;
+ ret->magic = VIR_INTERFACE_MAGIC;
+ ret->conn = conn;
- if (virHashAddEntry(conn->interfaces, name, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add interface to connection hash table"));
- goto error;
- }
- conn->refs++;
- }
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -735,15 +484,6 @@ virReleaseInterface(virInterfacePtr iface) {
virConnectPtr conn = iface->conn;
DEBUG("release interface %p %s", iface, iface->name);
- if (virHashRemoveEntry(conn->interfaces, iface->name, NULL) < 0) {
- /* unlock before reporting error because error report grabs lock */
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("interface missing from connection hash table"));
- /* don't decr the conn refct if we weren't connected to it */
- conn = NULL;
- }
-
iface->magic = -1;
VIR_FREE(iface->name);
VIR_FREE(iface->mac);
@@ -820,31 +560,22 @@ virGetStoragePool(virConnectPtr conn, const char *name, const unsigned char *uui
virUUIDFormat(uuid, uuidstr);
- ret = (virStoragePoolPtr) virHashLookup(conn->storagePools, uuidstr);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_STORAGE_POOL_MAGIC;
- ret->conn = conn;
- memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
- if (virHashAddEntry(conn->storagePools, uuidstr, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to add storage pool to connection hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->magic = VIR_STORAGE_POOL_MAGIC;
+ ret->conn = conn;
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -878,13 +609,6 @@ virReleaseStoragePool(virStoragePoolPtr pool) {
virUUIDFormat(pool->uuid, uuidstr);
DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
- if (virHashRemoveEntry(conn->storagePools, uuidstr, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("pool missing from connection hash table"));
- conn = NULL;
- }
-
pool->magic = -1;
VIR_FREE(pool->name);
VIR_FREE(pool);
@@ -958,42 +682,33 @@ virGetStorageVol(virConnectPtr conn, const char *pool, const char *name, const c
}
virMutexLock(&conn->lock);
- ret = (virStorageVolPtr) virHashLookup(conn->storageVols, key);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->pool = strdup(pool);
- if (ret->pool == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- if (virStrcpyStatic(ret->key, key) == NULL) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- _("Volume key %s too large for destination"), key);
- goto error;
- }
- ret->magic = VIR_STORAGE_VOL_MAGIC;
- ret->conn = conn;
-
- if (virHashAddEntry(conn->storageVols, key, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add storage vol to connection hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->pool = strdup(pool);
+ if (ret->pool == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ if (virStrcpyStatic(ret->key, key) == NULL) {
+ virMutexUnlock(&conn->lock);
+ virLibConnError(VIR_ERR_INTERNAL_ERROR,
+ _("Volume key %s too large for destination"), key);
+ goto error;
}
+ ret->magic = VIR_STORAGE_VOL_MAGIC;
+ ret->conn = conn;
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -1025,13 +740,6 @@ virReleaseStorageVol(virStorageVolPtr vol) {
virConnectPtr conn = vol->conn;
DEBUG("release vol %p %s", vol, vol->name);
- if (virHashRemoveEntry(conn->storageVols, vol->key, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("vol missing from connection hash table"));
- conn = NULL;
- }
-
vol->magic = -1;
VIR_FREE(vol->name);
VIR_FREE(vol->pool);
@@ -1105,30 +813,21 @@ virGetNodeDevice(virConnectPtr conn, const char *name)
}
virMutexLock(&conn->lock);
- ret = (virNodeDevicePtr) virHashLookup(conn->nodeDevices, name);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NODE_DEVICE_MAGIC;
- ret->conn = conn;
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
-
- if (virHashAddEntry(conn->nodeDevices, name, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to add node dev to conn hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->magic = VIR_NODE_DEVICE_MAGIC;
+ ret->conn = conn;
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -1159,13 +858,6 @@ virReleaseNodeDevice(virNodeDevicePtr dev) {
virConnectPtr conn = dev->conn;
DEBUG("release dev %p %s", dev, dev->name);
- if (virHashRemoveEntry(conn->nodeDevices, dev->name, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("dev missing from connection hash table"));
- conn = NULL;
- }
-
dev->magic = -1;
VIR_FREE(dev->name);
VIR_FREE(dev->parent);
@@ -1239,30 +931,21 @@ virGetSecret(virConnectPtr conn, const unsigned char *uuid,
virUUIDFormat(uuid, uuidstr);
- ret = virHashLookup(conn->secrets, uuidstr);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_SECRET_MAGIC;
- ret->conn = conn;
- memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
- ret->usageType = usageType;
- if (!(ret->usageID = strdup(usageID))) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- if (virHashAddEntry(conn->secrets, uuidstr, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add secret to conn hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->magic = VIR_SECRET_MAGIC;
+ ret->conn = conn;
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+ ret->usageType = usageType;
+ if (!(ret->usageID = strdup(usageID))) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return ret;
@@ -1294,13 +977,6 @@ virReleaseSecret(virSecretPtr secret) {
virUUIDFormat(secret->uuid, uuidstr);
DEBUG("release secret %p %s", secret, uuidstr);
- if (virHashRemoveEntry(conn->secrets, uuidstr, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("secret missing from connection hash table"));
- conn = NULL;
- }
-
VIR_FREE(secret->usageID);
secret->magic = -1;
VIR_FREE(secret);
@@ -1433,31 +1109,22 @@ virGetNWFilter(virConnectPtr conn, const char *name, const unsigned char *uuid)
virUUIDFormat(uuid, uuidstr);
- ret = (virNWFilterPtr) virHashLookup(conn->nwfilterPools, uuidstr);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_NWFILTER_MAGIC;
- ret->conn = conn;
- memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
-
- if (virHashAddEntry(conn->nwfilterPools, uuidstr, ret) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("failed to add network filter pool to connection hash table"));
- goto error;
- }
- conn->refs++;
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->magic = VIR_NWFILTER_MAGIC;
+ ret->conn = conn;
+ memcpy(&(ret->uuid[0]), uuid, VIR_UUID_BUFLEN);
+
+ conn->refs++;
ret->refs++;
virMutexUnlock(&conn->lock);
return(ret);
@@ -1491,13 +1158,6 @@ virReleaseNWFilterPool(virNWFilterPtr pool) {
virUUIDFormat(pool->uuid, uuidstr);
DEBUG("release pool %p %s %s", pool, pool->name, uuidstr);
- if (virHashRemoveEntry(conn->nwfilterPools, uuidstr, NULL) < 0) {
- virMutexUnlock(&conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("pool missing from connection hash table"));
- conn = NULL;
- }
-
pool->magic = -1;
VIR_FREE(pool->name);
VIR_FREE(pool);
@@ -1558,33 +1218,21 @@ virGetDomainSnapshot(virDomainPtr domain, const char *name)
}
virMutexLock(&domain->conn->lock);
- ret = (virDomainSnapshotPtr) virHashLookup(domain->snapshots, name);
- if (ret == NULL) {
- if (VIR_ALLOC(ret) < 0) {
- virMutexUnlock(&domain->conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->name = strdup(name);
- if (ret->name == NULL) {
- virMutexUnlock(&domain->conn->lock);
- virReportOOMError();
- goto error;
- }
- ret->magic = VIR_SNAPSHOT_MAGIC;
- ret->domain = domain;
-
- if (virHashAddEntry(domain->snapshots, name, ret) < 0) {
- virMutexUnlock(&domain->conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("failed to add snapshot to domain hash table"));
- goto error;
- }
- domain->refs++;
- DEBUG("New hash entry %p", ret);
- } else {
- DEBUG("Existing hash entry %p: refs now %d", ret, ret->refs+1);
+ if (VIR_ALLOC(ret) < 0) {
+ virMutexUnlock(&domain->conn->lock);
+ virReportOOMError();
+ goto error;
+ }
+ ret->name = strdup(name);
+ if (ret->name == NULL) {
+ virMutexUnlock(&domain->conn->lock);
+ virReportOOMError();
+ goto error;
}
+ ret->magic = VIR_SNAPSHOT_MAGIC;
+ ret->domain = domain;
+
+ domain->refs++;
ret->refs++;
virMutexUnlock(&domain->conn->lock);
return(ret);
@@ -1604,13 +1252,6 @@ virReleaseDomainSnapshot(virDomainSnapshotPtr snapshot)
virDomainPtr domain = snapshot->domain;
DEBUG("release snapshot %p %s", snapshot, snapshot->name);
- if (virHashRemoveEntry(domain->snapshots, snapshot->name, NULL) < 0) {
- virMutexUnlock(&domain->conn->lock);
- virLibConnError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("snapshot missing from domain hash table"));
- domain = NULL;
- }
-
snapshot->magic = -1;
VIR_FREE(snapshot->name);
VIR_FREE(snapshot);
diff --git a/src/datatypes.h b/src/datatypes.h
index bbeb7cf..0409ab1 100644
--- a/src/datatypes.h
+++ b/src/datatypes.h
@@ -24,7 +24,6 @@
# include "internal.h"
-# include "hash.h"
# include "driver.h"
# include "threads.h"
@@ -188,14 +187,6 @@ struct _virConnect {
virErrorFunc handler; /* associated handlet */
void *userData; /* the user data */
- virHashTablePtr domains; /* hash table for known domains */
- virHashTablePtr networks; /* hash table for known domains */
- virHashTablePtr interfaces; /* hash table for known interfaces */
- virHashTablePtr storagePools;/* hash table for known storage pools */
- virHashTablePtr storageVols;/* hash table for known storage vols */
- virHashTablePtr nodeDevices; /* hash table for known node devices */
- virHashTablePtr secrets; /* hash taboe for known secrets */
- virHashTablePtr nwfilterPools; /* hash tables ofr known nw filter pools */
int refs; /* reference count */
};
@@ -211,7 +202,6 @@ struct _virDomain {
char *name; /* the domain external name */
int id; /* the domain ID */
unsigned char uuid[VIR_UUID_BUFLEN]; /* the domain unique identifier */
- virHashTablePtr snapshots; /* hash table for known snapshots */
};
/**
--
1.7.2.3
14 years, 1 month
[libvirt] [RFC] Proposed API to support block device streaming
by Adam Litke
I've been working with Anthony Liguori and Stefan Hajnoczi to enable data
streaming to copy-on-read disk images in qemu. This work is working its way
through peer review and I expect it to be upstream soon as part of the support
for the new QED disk image format.
I would like to enable these commands in libvirt in order to support at least
two compelling use cases:
1) Rapid deployment of domains:
Creating a new domain from a central repository of images can be time consuming
since a local copy of the image must be made before the domain can be started.
With copy-on-read and streaming, up-front copy time is eliminated and the
domain can be started immediately. Streaming can run while the domain runs
to fully populate the disk image.
2) Post-copy live block migration:
A qemu-nbd server is started on the source host and serves the domain's block
device to the destination host. A QED image is created on the destination host
with backing to the nbd server. The domain is migrated as normal. When
migration completes, a stream command is executed to fully populate the
destination QED image. After streaming completes, the qemu-nbd server can
be shut down and the domain (including local storage) is fully independent of
the source host.
Qemu will support two streaming modes: full device and single sector. Full
device streaming is the easiest to use because one command will cause the whole
device to be streamed as fast as possible. Single sector mode can be used if
one wants to throttle streaming to reduce I/O pressure. In this mode, the user
issues individual commands to stream single sectors.
To enable this support in libvirt, I propose the following API...
virDomainStreamDisk() initiates either a full device stream or a single sector
stream (depending on virDomainStreamDiskFlags). For a full device stream, it
returns either 0 or -1. For a single sector stream, it returns an offset that
can be used to continue streaming with a subsequent call to virDomainStreamDisk().
virDomainStreamDiskInfo() returns the status of a currently-running full device
stream (the device name, current streaming position, and total size).
Comments on this design would be greatly appreciated. Thanks!
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 81db3a2..d80a8b5 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -1046,6 +1046,39 @@ int virDomainUpdateDeviceFlags(virDomainPtr domain,
const char *xml, unsigned int flags);
/*
+ * Disk Streaming
+ */
+typedef enum {
+ VIR_STREAM_DISK_FULL = 1, /* Stream the entire disk */
+ VIR_STREAM_DISK_ONE = 2, /* Stream a single disk unit */
+} virDomainStreamDiskFlags;
+
+#define VIR_STREAM_PATH_BUFLEN 100
+#define VIR_STREAM_DISK_MAX_STREAMS 10
+
+typedef struct _virStreamDiskState virStreamDiskState;
+struct _virStreamDiskState {
+ char path[VIR_STREAM_PATH_BUFLEN];
+ /*
+ * The unit of measure for size and offset is unspecified. These fields
+ * are meant to indicate the progress of a continuous streaming operation.
+ */
+ unsigned long long offset; /* Current offset of active streaming */
+ unsigned long long size; /* Disk size */
+};
+typedef virStreamDiskState *virStreamDiskStatePtr;
+
+unsigned long long virDomainStreamDisk(virDomainPtr dom,
+ const char *path,
+ unsigned long long offset,
+ unsigned int flags);
+
+int virDomainStreamDiskInfo(virDomainPtr dom,
+ virStreamDiskStatePtr infos,
+ unsigned int nr_infos,
+ unsigned int flags);
+
+/*
* NUMA support
*/
--
Thanks,
Adam
14 years, 1 month
[libvirt] Ask for help about libvirt error: this function is not supported by the connection driver..
by Feng Dan Liu
Hi,
I'm a libvirt user, I encountered a problem when I use the libvirt java
bindings, could you please help me take a look? Thanks in advance! Any
suggestions from anyone of you will be very appreciated.
Here is my scenario:
Remote access machine A is a RHEL 5.4 workstation with the command "virsh
version" results:
Compiled against library: libvir 0.8.1
Using library: libvir 0.8.1
Using API: Xen 3.0.1
Running hypervisor: Xen 3.1.0
Hypervisor machine B is a Fedora Core 14 Linux workstation with the
command "virsh version" results:
Compiled against library: libvir 0.8.3
Using library: libvir 0.8.3
Using API: QEMU 0.8.3
Running hypervisor: QEMU 0.13.0
I finished the code using libvirt java bindings and run it on machine A,
try to remote connect to the hypervisor on machine B. It can be connected
succussfully, but when the code calls the function of
conn.listDefinedStoragePools() or conn.listStoragePools, the libvirt on
machine B will get the errors below:
04:19:10.467: error : phypStorageOpen:3884 : invalid argument in
phypStorageOpen: unsupported flags (0x1)
04:19:11.354: warning : qemudParsePCIDeviceStrs:1422 : Unexpected exit
status '1', qemu probably failed
04:19:12.128: error : virLibConnError:448 : this function is not supported
by the connection driver: virConnectNumOfStoragePools
With the errors above, my code can't run the functions of
conn.listDefinedStoragePools() or conn.listStoragePools successfully.
Could you please give me some suggestions?
By the way, I try to use the libvirt java bindings 0.3.2 and 0.4.6, both
of them have this problem.
Best Regards,
Fengdan Liu, Casey
AdTech, Tivoli China Development,
China Software Development Lab, IBM Greater China Group
Phone: 86-10-82453004
Email: liufengd(a)cn.ibm.com
Addr: No.28 Building, Zhong Guan Cun Software Park, No. 8 Dong Bei Wang
West Road, ShangDi, Haidian District, Beijing 100193, P.R.China
14 years, 1 month
[libvirt] [PATCH] Use python discovered through env instead of hardcoding a path
by Matthias Bolte
This is more flexible regarding the location of the python binary
but doesn't allow to pass the -u flag. The -i flag can be passed
from inside the script using the PYTHONINSPECT env variable.
This fixes a problem with the esx_vi_generator.py on FreeBSD.
---
examples/python/dominfo.py | 2 +-
examples/python/domrestore.py | 2 +-
examples/python/domsave.py | 2 +-
examples/python/domstart.py | 2 +-
examples/python/esxlist.py | 2 +-
python/generator.py | 2 +-
python/libvirt-override.py | 5 +++++
src/esx/esx_vi_generator.py | 2 +-
8 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/examples/python/dominfo.py b/examples/python/dominfo.py
index e41709c..2f250e7 100755
--- a/examples/python/dominfo.py
+++ b/examples/python/dominfo.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
# dominfo - print some information about a domain
import libvirt
diff --git a/examples/python/domrestore.py b/examples/python/domrestore.py
index b032138..ccc82f6 100755
--- a/examples/python/domrestore.py
+++ b/examples/python/domrestore.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/python/domsave.py b/examples/python/domsave.py
index 35e2c8a..12ffac1 100755
--- a/examples/python/domsave.py
+++ b/examples/python/domsave.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/python/domstart.py b/examples/python/domstart.py
index 52fb79e..b1e89b8 100755
--- a/examples/python/domstart.py
+++ b/examples/python/domstart.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
# domstart - make sure a given domU is running, if not start it
import libvirt
diff --git a/examples/python/esxlist.py b/examples/python/esxlist.py
index a0602e8..c55424f 100755
--- a/examples/python/esxlist.py
+++ b/examples/python/esxlist.py
@@ -1,4 +1,4 @@
-#! /usr/bin/python
+#!/usr/bin/env python
# esxlist - list active domains of an ESX host and print some info.
# also demonstrates how to use the libvirt.openAuth() method
diff --git a/python/generator.py b/python/generator.py
index 68009b9..15751bd 100755
--- a/python/generator.py
+++ b/python/generator.py
@@ -1010,7 +1010,7 @@ def buildWrappers():
classes = open("libvirt.py", "w")
extra = open(os.path.join(srcPref,"libvirt-override.py"), "r")
- classes.write("#!/usr/bin/python -i\n")
+ classes.write("#!/usr/bin/env python\n")
classes.write("#\n")
classes.write("# WARNING WARNING WARNING WARNING\n")
classes.write("#\n")
diff --git a/python/libvirt-override.py b/python/libvirt-override.py
index d544a0e..909ebe3 100644
--- a/python/libvirt-override.py
+++ b/python/libvirt-override.py
@@ -2,6 +2,11 @@
# Manually written part of python bindings for libvirt
#
+# Specify -i commandline option after python was started
+if __name__ == "__main__":
+ import os
+ os.environ["PYTHONINSPECT"] = "1"
+
# On cygwin, the DLL is called cygvirtmod.dll
try:
import libvirtmod
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index 01636aa..4593379 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/env python
#
# esx_vi_generator.py: generates most of the SOAP type mapping code
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] esx: Avoid warnings about breaking strict-aliasing rules on FreeBSD
by Matthias Bolte
---
src/esx/esx_vi_generator.py | 10 ++++++++--
1 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/src/esx/esx_vi_generator.py b/src/esx/esx_vi_generator.py
index c2f7044..01636aa 100755
--- a/src/esx/esx_vi_generator.py
+++ b/src/esx/esx_vi_generator.py
@@ -699,7 +699,10 @@ class Object:
if self.features & Object.FEATURE__LIST:
if self.extends is not None:
- source += " esxVI_%s_Free((esxVI_%s **)&item->_next);\n\n" % (self.extends, self.extends)
+ # avoid "dereferencing type-punned pointer will break strict-aliasing rules" warnings
+ source += " esxVI_%s *next = (esxVI_%s *)item->_next;\n\n" % (self.extends, self.extends)
+ source += " esxVI_%s_Free(&next);\n" % self.extends
+ source += " item->_next = (esxVI_%s *)next;\n\n" % self.name
else:
source += " esxVI_%s_Free(&item->_next);\n\n" % self.name
@@ -719,7 +722,10 @@ class Object:
if self.features & Object.FEATURE__LIST:
if self.extends is not None:
- source += " esxVI_%s_Free((esxVI_%s **)&item->_next);\n\n" % (self.extends, self.extends)
+ # avoid "dereferencing type-punned pointer will break strict-aliasing rules" warnings
+ source += " esxVI_%s *next = (esxVI_%s *)item->_next;\n\n" % (self.extends, self.extends)
+ source += " esxVI_%s_Free(&next);\n" % self.extends
+ source += " item->_next = (esxVI_%s *)next;\n\n" % self.name
else:
source += " esxVI_%s_Free(&item->_next);\n\n" % self.name
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] Make sure struct sockaddr_in is defined on FreeBSD
by Matthias Bolte
---
src/util/network.h | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/src/util/network.h b/src/util/network.h
index 0900e29..724a5f8 100644
--- a/src/util/network.h
+++ b/src/util/network.h
@@ -21,6 +21,10 @@
# include <netdb.h>
# include <stdbool.h>
+# ifdef __FreeBSD__
+# include <netinet/in.h>
+# endif
+
typedef struct {
union {
struct sockaddr sa;
--
1.7.0.4
14 years, 1 month
[libvirt] [PATCH] configure: Disable FS storage driver if mntent.h is not available
by Matthias Bolte
This is the case on FreeBSD.
---
configure.ac | 12 ++++++++++++
1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/configure.ac b/configure.ac
index 66237e1..d21d558 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1497,6 +1497,18 @@ if test "$with_osx" = "yes"; then
fi
if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then
+ AC_CHECK_HEADER([mntent.h],,
+ [
+ if test "$with_storage_fs" = "check"; then
+ with_storage_fs=no
+ AC_MSG_NOTICE([<mntent.h> is required for the FS storage driver, disabling it])
+ else
+ AC_MSG_ERROR([<mntent.h> is required for the FS storage driver])
+ fi
+ ])
+fi
+
+if test "$with_storage_fs" = "yes" || test "$with_storage_fs" = "check"; then
AC_PATH_PROG([MOUNT], [mount], [], [$PATH:/sbin:/usr/sbin])
AC_PATH_PROG([UMOUNT], [umount], [], [$PATH:/sbin:/usr/sbin])
if test "$with_storage_fs" = "yes" ; then
--
1.7.0.4
14 years, 1 month