Devel
Threads by month
- ----- 2026 -----
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- 44 participants
- 40057 discussions
16 Nov '10
I wrote (attached here, and to the bug) a quick patch that sets the process
name to the same value as the window title.
I'm unsure where to go from here. Should I add support for converting
"native" QEMU command lines to libvirt XML? What would that look like, since
I'm not modifying the libvirt format? Should it just drop any ,process= from
the QEMU command line it's parsing? I also imagine the test cases will need
updating.
If someone could give me some high-level guidance, I'd be happy to keep
going on this.
john
--
John Morrissey _o /\ ---- __o
jwm(a)horde.net _-< \_ / \ ---- < \,
www.horde.net/ __(_)/_(_)________/ \_______(_) /_(_)__
4
11
16 Nov '10
* src/nwfilter/nwfilter_ebiptables_driver.c
(ebiptablesWriteToTempFile): Use /bin/sh.
(bash_cmd_path): Delete.
(ebiptablesDriverInit, ebiptablesDriverShutdown): No need to
search for bash.
(CMD_EXEC): Prefer $() over ``, since we can assume POSIX.
(iptablesSetupVirtInPost): Use portable 'test' syntax.
(iptablesLinkIPTablesBaseChain): Use POSIX $(()) syntax.
---
It turns out that the current use of test x == x in nwfilter
was technically safe after all, since we were requiring the
existence of bash (and that was also relatively reasonable,
since nwfilter is only compiled for Linux). But that still
feels awkward, when it is easier to just fix things to work
with /bin/sh. Here, I went the easy route, and assumed that
since things are Linux, we can use shell constructs that
aren't strictly portable to all /bin/sh implementations, so
long as they are portable to POSIX (and will thus work with
dash or busybox sh).
src/nwfilter/nwfilter_ebiptables_driver.c | 25 +++++++++++++------------
1 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/src/nwfilter/nwfilter_ebiptables_driver.c b/src/nwfilter/nwfilter_ebiptables_driver.c
index 20d1ba3..c3a0d3e 100644
--- a/src/nwfilter/nwfilter_ebiptables_driver.c
+++ b/src/nwfilter/nwfilter_ebiptables_driver.c
@@ -52,12 +52,16 @@
#define CHAINPREFIX_HOST_IN_TEMP 'J'
#define CHAINPREFIX_HOST_OUT_TEMP 'P'
+/* This file generates a temporary shell script. Since ebiptables is
+ Linux-specific, we can be reasonably certain that /bin/sh is more
+ or less POSIX-compliant, so we can use $() and $(()). However, we
+ cannot assume that /bin/sh is bash, so stick to POSIX syntax. */
#define CMD_SEPARATOR "\n"
#define CMD_DEF_PRE "cmd='"
#define CMD_DEF_POST "'"
#define CMD_DEF(X) CMD_DEF_PRE X CMD_DEF_POST
-#define CMD_EXEC "eval res=\\`\"${cmd}\"\\`" CMD_SEPARATOR
+#define CMD_EXEC "eval res=\\$(\"${cmd}\")" CMD_SEPARATOR
#define CMD_STOPONERR(X) \
X ? "if [ $? -ne 0 ]; then" \
" echo \"Failure to execute command '${cmd}'.\";" \
@@ -76,7 +80,6 @@
static char *ebtables_cmd_path;
static char *iptables_cmd_path;
static char *ip6tables_cmd_path;
-static char *bash_cmd_path;
static char *grep_cmd_path;
static char *gawk_cmd_path;
@@ -427,7 +430,7 @@ static int iptablesLinkIPTablesBaseChain(const char *iptables_cmd,
" " CMD_DEF("%s -I %s %d -j %s") CMD_SEPARATOR
" " CMD_EXEC
" %s"
- " let r=r+1\n"
+ " r=$(( $r + 1 ))\n"
" " CMD_DEF("%s -D %s ${r}") CMD_SEPARATOR
" " CMD_EXEC
" %s"
@@ -650,7 +653,7 @@ iptablesSetupVirtInPost(const char *iptables_cmd,
virBufferVSprintf(buf,
"res=$(%s -n -L " VIRT_IN_POST_CHAIN
" | grep \"\\%s %s\")\n"
- "if [ \"${res}\" == \"\" ]; then "
+ "if [ \"${res}\" = \"\" ]; then "
CMD_DEF("%s"
" -A " VIRT_IN_POST_CHAIN
" %s %s -j ACCEPT") CMD_SEPARATOR
@@ -2431,7 +2434,7 @@ ebiptablesDisplayRuleInstance(virConnectPtr conn ATTRIBUTE_UNUSED,
*
* Write the string into a temporary file and return the name of
* the temporary file. The string is assumed to contain executable
- * commands. A line '#!/bin/bash' will automatically be written
+ * commands. A line '#!/bin/sh' will automatically be written
* as the first line in the file. The permissions of the file are
* set so that the file can be run as an executable script.
*/
@@ -2444,7 +2447,7 @@ ebiptablesWriteToTempFile(const char *string) {
char *header;
size_t written;
- virBufferVSprintf(&buf, "#!%s\n", bash_cmd_path);
+ virBufferAddLit(&buf, "#!/bin/sh\n");
if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf);
@@ -2513,10 +2516,10 @@ err_exit:
* commands executed via the script the was run.
*
* Returns 0 in case of success, != 0 in case of an error. The returned
- * value is NOT the result of running the commands inside the bash
+ * value is NOT the result of running the commands inside the shell
* script.
*
- * Execute a sequence of commands (held in the given buffer) as a bash
+ * Execute a sequence of commands (held in the given buffer) as a /bin/sh
* script and return the status of the execution.
*/
static int
@@ -3657,7 +3660,6 @@ ebiptablesDriverInit(void)
if (virMutexInit(&execCLIMutex))
return EINVAL;
- bash_cmd_path = virFindFileInPath("bash");
gawk_cmd_path = virFindFileInPath("gawk");
grep_cmd_path = virFindFileInPath("grep");
@@ -3701,9 +3703,9 @@ ebiptablesDriverInit(void)
VIR_FREE(ip6tables_cmd_path);
}
- /* ip(6)tables support needs bash, gawk & grep, ebtables doesn't */
+ /* ip(6)tables support needs gawk & grep, ebtables doesn't */
if ((iptables_cmd_path != NULL || ip6tables_cmd_path != NULL) &&
- (!grep_cmd_path || !bash_cmd_path || !gawk_cmd_path)) {
+ (!grep_cmd_path || !gawk_cmd_path)) {
virNWFilterReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("essential tools to support ip(6)tables "
"firewalls could not be located"));
@@ -3730,7 +3732,6 @@ static void
ebiptablesDriverShutdown()
{
VIR_FREE(gawk_cmd_path);
- VIR_FREE(bash_cmd_path);
VIR_FREE(grep_cmd_path);
VIR_FREE(ebtables_cmd_path);
VIR_FREE(iptables_cmd_path);
--
1.7.3.2
2
7
16 Nov '10
Now that the existing scripts are (hopefully) cleaned up and my POSIX
compliancy shell-scripting skills have temporarily :-) improved, I am
now adding a test case that exercises concurrency. The test case creates
and destroys 2 VMs concurrently as well as changes their referenced
filters in a tight loop. This kind of test previously uncovered
- deadlocks in libvirt due to lock-ordering in the nwfilter subsystem
- libvirt termination bug in libaugeas due to doubly closed file
descriptors and the side effects
All of these have been fixed recently.
The test script is known to run in bash, dash and ksh shells.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
scripts/nwfilter/060-concurrency.t | 5
scripts/nwfilter/concurrency/chg-vm-filter.sh | 19 +
scripts/nwfilter/concurrency/start-destroy-vm.sh | 19 +
scripts/nwfilter/concurrency/tck-vm1-filter1.xml | 26 +
scripts/nwfilter/concurrency/tck-vm1-filter2.xml | 26 +
scripts/nwfilter/concurrency/tck-vm1.xml | 30 +
scripts/nwfilter/concurrency/tck-vm2-filter1.xml | 26 +
scripts/nwfilter/concurrency/tck-vm2-filter2.xml | 26 +
scripts/nwfilter/concurrency/tck-vm2.xml | 30 +
scripts/nwfilter/nwfilter_concurrent.sh | 371 +++++++++++++++++++++++
10 files changed, 578 insertions(+)
Index: libvirt-tck/scripts/nwfilter/060-concurrency.t
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/060-concurrency.t
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+pwd=$(dirname -- "$0")
+
+(cd -- "${pwd}"; sh ./nwfilter_concurrent.sh --tap-test)
Index: libvirt-tck/scripts/nwfilter/nwfilter_concurrent.sh
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/nwfilter_concurrent.sh
@@ -0,0 +1,371 @@
+#!/bin/sh
+
+VIRSH=virsh
+
+# 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))"
+FLAG_VERBOSE="$((1<<2))"
+FLAG_LIBVIRT_TEST="$((1<<3))"
+FLAG_TAP_TEST="$((1<<4))"
+FLAG_FORCE_CLEAN="$((1<<5))"
+
+failctr=0
+passctr=0
+attachfailctr=0
+attachctr=0
+
+TAP_FAIL_LIST=""
+TAP_FAIL_CTR=0
+TAP_TOT_CTR=0
+
+usage() {
+ cmd="$0"
+cat <<EOF
+Usage: ${cmd} [--help|-h|-?] [--noattach] [--wait] [--verbose]
+ [--libvirt-test] [--tap-test]
+
+Options:
+ --help,-h,-? : Display this help screen.
+ --noattach : Skip tests that attach and detach a network interface
+ --wait : Wait for the user to press the enter key once an error
+ was detected
+ --verbose : Verbose output
+ --libvirt-test : Use the libvirt test output format
+ --tap-test : TAP format output
+ --force : Allow the automatic cleaning of VMs and nwfilters
+ previously created by the TCK test suite
+
+This test will create two virtual machines. The one virtual machine
+will use a filter called '${TESTFILTERNAME}', and reference the filter
+'clean-traffic' which should be available by default with every install.
+The other virtual machine will reference the filter 'tck-testcase' and will
+have its filter permanently updated.
+EOF
+}
+
+
+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))
+}
+
+tap_pass() {
+ txt=$(echo "$2" | gawk '{print substr($0,1,70)}')
+ echo "ok $1 - ${txt}"
+ TAP_TOT_CTR=$(($TAP_TOT_CTR + 1))
+}
+
+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`
+ 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.
+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
+}
+
+
+PRGDIR="./concurrency"
+CREATE_DES_VM1="${PRGDIR}/start-destroy-vm.sh 1"
+CREATE_DES_VM2="${PRGDIR}/start-destroy-vm.sh 2"
+CHG_FILTER_VM1="${PRGDIR}/chg-vm-filter.sh 1"
+CHG_FILTER_VM2="${PRGDIR}/chg-vm-filter.sh 2"
+
+
+startPrgs()
+{
+ flags="$1"
+
+ sh ${CHG_FILTER_VM1} "$4" 2>&1 >/dev/null &
+ [ $? -ne 0 ] && \
+ ( killPrgs "${flags}" "Could not start program 3" ; return 1; )
+ CHG_FILTER_VM1_THR=$!
+
+ sh ${CHG_FILTER_VM2} "$5" 2>&1 >/dev/null &
+ [ $? -ne 0 ] && \
+ ( killPrgs "${flags}" "Could not start program 4" ; return 1; )
+ CHG_FILTER_VM2_THR=$!
+
+ # Give some time for the filters to be created
+ sleep 2
+
+ sh ${CREATE_DES_VM1} "$2" 2>&1 >/dev/null &
+ [ $? -ne 0 ] && \
+ ( killPrgs "${flags}" "Could not start program 1" ; return 1; )
+ CREATE_DES_VM1_THR=$!
+
+ sh ${CREATE_DES_VM2} "$3" 2>&1 >/dev/null &
+ [ $? -ne 0 ] && \
+ ( killPrgs "${flags}" "Could not start program 2" ; return 1; )
+ CREATE_DES_VM2_THR=$!
+
+}
+
+
+killPrgs()
+{
+ msg="$1"
+
+ # terminate all process
+ [ "x${CREATE_DES_VM1_THR}x" != "xx" ] && \
+ kill -9 ${CREATE_DES_VM1_THR}
+ [ "x${CREATE_DES_VM2_THR}x" != "xx" ] && \
+ kill -9 ${CREATE_DES_VM2_THR}
+ [ "x${CHG_FILTER_VM1_THR}x" != "xx" ] && \
+ kill -9 ${CHG_FILTER_VM1_THR}
+ [ "x${CHG_FILTER_VM2_THR}x" != "xx" ] && \
+ kill -9 ${CHG_FILTER_VM2_THR}
+}
+
+
+testFail()
+{
+ flags="$1"
+ msg="$2"
+
+ failctr=$(($failctr + 1))
+ if [ $(($flags & $FLAG_VERBOSE)) -ne 0 ]; then
+ echo "FAIL : ${msg}"
+ fi
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
+ echo "Press enter"
+ read enter
+ fi
+ [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ] && \
+ test_result $(($passctr + $failctr)) "" 1
+ [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ] && \
+ tap_fail $(($passctr + $failctr)) "${msg}"
+}
+
+
+testPass()
+{
+ flags="$1"
+ msg="$2"
+
+ passctr=$(($passctr + 1))
+ if [ $(($flags & $FLAG_VERBOSE)) -ne 0 ]; then
+ echo "PASS : ${msg}"
+ fi
+ [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ] && \
+ test_result $(($passctr + $failctr)) "" 0
+ [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ] && \
+ tap_pass $(($passctr + $failctr)) "${msg}"
+}
+
+cleanup()
+{
+ rm -rf "$1"
+ killPrgs
+ exit $2
+}
+
+runTest()
+{
+ flags="$1"
+
+ passctr=0
+ failctr=0
+
+ tmpdir=`mktmpdir`
+ failctr=0
+ passctr=0
+ logvm1="${PWD}/${tmpdir}/logvm1"
+ logvm2="${PWD}/${tmpdir}/logvm2"
+ logfivm1="${PWD}/${tmpdir}/logfivm1"
+ logfivm2="${PWD}/${tmpdir}/logfivm2"
+
+ loops=15
+
+ trap "cleanup ${tmpdir} 1" INT
+
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
+ # Need to display the number of total tests
+ tap_total=$((4 * $loops))
+ echo "1..${tap_total}"
+ fi
+
+ startPrgs "${flags}" "${logvm1}" "${logvm2}" \
+ "${logfivm1}" "${logfivm2}"
+
+ [ $? -ne 0 ] && rm -rf "${tmpdir}" && return 1;
+
+ sleep 8
+
+ expect=1
+
+ while :;
+ do
+ # VM start/destroy cycles expected to be slow
+ tmp=$(($expect / 3))
+ # The logs give us the number of cycles the VMs were created
+ # and destroyed.
+ val=$(cat "${logvm1}" 2>/dev/null | tail -n 1)
+ ( [ "x${val}x" = "xx" ] || [ ${val} -lt ${tmp} ] ) \
+ && testFail "${flags}" \
+ "VM1 log - step ${expect} ($val < $tmp)" \
+ || testPass "${flags}" \
+ "VM1 log - step ${expect} ($val >= $tmp)"
+
+ val=$(cat "${logvm2}" 2>/dev/null | tail -n 1)
+ ( [ "x${val}x" = "xx" ] || [ ${val} -lt ${tmp} ] ) \
+ && testFail "${flags}" \
+ "VM2 log - step ${expect} ($val < $tmp)" \
+ || testPass "${flags}" \
+ "VM2 log - step ${expect} ($val >= $tmp)"
+
+ # The changing of the filters is expected to work much faster
+ tmp=$(($expect * 5))
+ # Also here the logs give us the number of filter change cycles
+ val=$(cat "${logfivm1}" 2>/dev/null | tail -n 1)
+ ( [ "x${val}x" = "xx" ] || [ ${val} -lt ${tmp} ] ) \
+ && testFail "${flags}" \
+ "VM1 filter log - step ${expect} ($val < $tmp)" \
+ || testPass "${flags}" \
+ "VM1 filter log - step ${expect} ($val >= $tmp)"
+
+ val=$(cat "${logfivm2}" 2>/dev/null | tail -n 1)
+ ( [ "x${val}x" = "xx" ] || [ ${val} -lt ${tmp} ] ) \
+ && testFail "${flags}" \
+ "VM2 filter log - step ${expect} ($val < $tmp)" \
+ || testPass "${flags}" \
+ "VM2 filter log - step ${expect} ($val >= $tmp)"
+
+ expect=$(($expect + 1))
+ [ ${expect} -gt ${loops} ] && break;
+
+ sleep 4
+ done
+
+ cleanup "${tmpdir}" 0
+}
+
+
+main() {
+ prgname="$0"
+ xmldir="nwfilterxml2xmlin"
+ fwalldir="nwfilterxml2fwallout"
+ found=0
+ filtername="tck-testcase"
+ libvirtdpid=-1
+
+ flags=${FLAG_ATTACH}
+
+ while [ $# -ne 0 ]; do
+ case "$1" in
+ --help|-h|-\?) usage ${prgname}; exit 0;;
+ --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
+ done
+
+ if [ `uname` != "Linux" ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
+ echo "1..0 # Skipped: Only valid on Linux hosts"
+ else
+ echo "This script will only run on Linux."
+ fi
+ exit 1;
+ fi
+
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ "${LIBVIRT_URI}" != "qemu:///system" ]; then
+ echo "1..0 # Skipped: Only valid for Qemu system driver"
+ exit 0
+ fi
+
+ for name in `virsh list --all | awk '{print $2}'`
+ do
+ case ${name} in
+ tck*)
+ 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)
+ rc2=$?
+ if [ $rc1 -ne 0 ] && [ $rc2 -ne 0 ]; then
+ echo "Bail out! Could not destroy VM ${name}: ${res}"
+ exit 0
+ fi
+ else
+ echo "Bail out! VM ${name} already exists, use --force to clean"
+ exit 1
+ fi
+ esac
+ done
+
+ for name in `virsh nwfilter-list | awk '{print $2}'`
+ do
+ case ${name} in
+ tck*)
+ 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 filter ${name}: ${res}"
+ exit 1
+ fi
+ else
+ echo "Bail out! Filter ${name} already exists, use --force to clean"
+ exit 1
+ fi
+ esac
+ done
+ fi
+
+ if [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ curdir="${PWD}"
+ . test-lib.sh
+ if [ $? -ne 0 ]; then
+ exit 1
+ fi
+ test_intro $this_test
+ cd "${curdir}"
+ [ $? -ne 0 ] && echo "cd failed" && exit 1
+ fi
+
+ runTest "${flags}"
+
+ return 0
+}
+
+main "$@"
Index: libvirt-tck/scripts/nwfilter/concurrency/chg-vm-filter.sh
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/chg-vm-filter.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+cd $(dirname "$0")
+ctr=0
+[ -z "$2" ] && exit 1
+idx="$1"
+logfile="$2"
+rm -f "${logfile}"
+touch "${logfile}"
+while :;
+do
+ virsh nwfilter-define tck-vm${idx}-filter1.xml
+ [ $? -ne 0 ] && break
+ [ ! -w "${logfile}" ] && break
+ virsh nwfilter-define tck-vm${idx}-filter2.xml
+ [ $? -ne 0 ] && break
+ ctr=$(($ctr + 1))
+ [ ! -w "${logfile}" ] && break
+ echo "${ctr}" >> "${logfile}"
+done
Index: libvirt-tck/scripts/nwfilter/concurrency/start-destroy-vm.sh
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/start-destroy-vm.sh
@@ -0,0 +1,19 @@
+#!/bin/sh
+cd $(dirname "$0")
+ctr=0
+[ -z "$2" ] && exit 1
+idx="$1"
+logfile="$2"
+rm -f "${logfile}"
+touch "${logfile}"
+while :;
+do
+ virsh create tck-vm${idx}.xml
+ [ $? -ne 0 ] && break
+ sleep 2
+ virsh destroy tck-vm${idx}
+ [ $? -ne 0 ] && break
+ ctr=$(($ctr + 1))
+ [ ! -w "${logfile}" ] && break
+ echo "${ctr}" >> "${logfile}"
+done
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm1-filter1.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm1-filter1.xml
@@ -0,0 +1,26 @@
+<filter name='tck-vm1-filter' chain='root'>
+ <uuid>464d2617-43d0-7694-b479-320b72dac187</uuid>
+ <filterref filter='clean-traffic'/>
+ <rule action='accept' direction='in' priority='500'>
+ <all comment='test'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <all/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='21' dstportend='22'/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='80'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <icmp/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <udp dstportstart='53'/>
+ </rule>
+ <rule action='drop' direction='inout' priority='500'>
+ <all/>
+ </rule>
+</filter>
+
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm1-filter2.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm1-filter2.xml
@@ -0,0 +1,26 @@
+<filter name='tck-vm1-filter' chain='root'>
+ <uuid>464d2617-43d0-7694-b479-320b72dac187</uuid>
+ <filterref filter='clean-traffic'/>
+ <rule action='accept' direction='in' priority='500'>
+ <all comment='test again'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <all/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='21' dstportend='22'/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='80'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <icmp/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <udp dstportstart='53'/>
+ </rule>
+ <rule action='drop' direction='inout' priority='500'>
+ <all/>
+ </rule>
+</filter>
+
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm1.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm1.xml
@@ -0,0 +1,30 @@
+ <domain type='kvm'>
+ <name>tck-vm1</name>
+ <memory>32768</memory>
+ <currentMemory>32768</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <interface type='bridge'>
+ <source bridge='virbr0'/>
+ <filterref filter='tck-vm1-filter'>
+ </filterref>
+ <target dev='tck-vm1-if0'/>
+ </interface>
+ <console type='pty'>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'/>
+ </devices>
+ </domain>
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm2-filter1.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm2-filter1.xml
@@ -0,0 +1,26 @@
+<filter name='tck-vm2-filter' chain='root'>
+ <uuid>364d2617-43d0-7694-b479-320b72dac187</uuid>
+ <filterref filter='clean-traffic'/>
+ <rule action='accept' direction='in' priority='500'>
+ <all comment='another test'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <all/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='21' dstportend='22'/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='80'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <icmp/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <udp dstportstart='53'/>
+ </rule>
+ <rule action='drop' direction='inout' priority='500'>
+ <all/>
+ </rule>
+</filter>
+
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm2-filter2.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm2-filter2.xml
@@ -0,0 +1,26 @@
+<filter name='tck-vm2-filter' chain='root'>
+ <uuid>364d2617-43d0-7694-b479-320b72dac187</uuid>
+ <filterref filter='clean-traffic'/>
+ <rule action='accept' direction='in' priority='500'>
+ <all comment='another test again'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <all/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='21' dstportend='22'/>
+ </rule>
+ <rule action='accept' direction='in' priority='500'>
+ <tcp dstportstart='80'/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <icmp/>
+ </rule>
+ <rule action='accept' direction='out' priority='500'>
+ <udp dstportstart='53'/>
+ </rule>
+ <rule action='drop' direction='inout' priority='500'>
+ <all/>
+ </rule>
+</filter>
+
Index: libvirt-tck/scripts/nwfilter/concurrency/tck-vm2.xml
===================================================================
--- /dev/null
+++ libvirt-tck/scripts/nwfilter/concurrency/tck-vm2.xml
@@ -0,0 +1,30 @@
+ <domain type='kvm'>
+ <name>tck-vm2</name>
+ <memory>32768</memory>
+ <currentMemory>32768</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <features>
+ <acpi/>
+ <apic/>
+ </features>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <interface type='bridge'>
+ <source bridge='virbr0'/>
+ <filterref filter='tck-vm2-filter'>
+ </filterref>
+ <target dev='tck-vm2-if0'/>
+ </interface>
+ <console type='pty'>
+ </console>
+ <input type='mouse' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'/>
+ </devices>
+ </domain>
2
2
16 Nov '10
v2:
- following Eric's suggestions from review of v1
- runs with ksh shell as well
I am converting the shell-scripted tap tests to also run using the dash
and ksh 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 | 11
scripts/networks/networkApplyTest.sh | 189 +++---
scripts/networks/networkxml2hostout/tck-testnet-1.dat | 10
scripts/networks/networkxml2hostout/tck-testnet-1.post.dat | 10
scripts/networks/networkxml2hostout/tck-testnet-2.dat | 10
scripts/networks/networkxml2hostout/tck-testnet-2.post.dat | 10
scripts/nwfilter/050-apply-verify-host.t | 11
scripts/nwfilter/nwfilter2vmtest.sh | 375 ++++++-------
scripts/nwfilter/nwfilterxml2fwallout/comment-test.fwall | 6
9 files changed, 310 insertions(+), 322 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,16 +94,16 @@ 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
tmpfile2=$tmpdir/file2
+ OIFS="${IFS}"
if echo a | grep -E '(a|b)' >/dev/null 2>&1
then EGREP='grep -E'
@@ -112,11 +112,12 @@ function checkExpectedOutput() {
exec 4<"${datafile}"
- read <&4
- line="${REPLY}"
+ IFS=""
+
+ read -r line <&4
while [ "x${line}x" != "xx" ]; do
- cmd=$(echo "${line##\#}")
+ cmd=$(printf %s\\n "${line##\#}")
skip=0
if [ "x${skipregex}x" != "xx" ]; then
@@ -128,10 +129,14 @@ function checkExpectedOutput() {
: >"${tmpfile2}"
while :; do
- read <&4
- line="${REPLY}"
+ read -r line <&4
+
+ case "${line}" in
+ '#'*) letter="#";;
+ *) letter="";;
+ esac
- 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
@@ -140,49 +145,50 @@ function checkExpectedOutput() {
diff "${tmpfile}" "${tmpfile2}" >/dev/null
if [ $? -ne 0 ]; then
- if [ $((flags & FLAG_VERBOSE)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_VERBOSE)) -ne 0 ]; then
echo "FAIL ${xmlfile} : ${cmd}"
diff "${tmpfile}" "${tmpfile2}"
fi
- ((failctr++))
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
- echo "tmp files: $tmpfile, $tmpfile2"
- echo "Press enter"
- read
+ failctr=$(($failctr + 1))
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
+ echo "tmp files: $tmpfile, $tmpfile2"
+ echo "Press enter"
+ 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}"
+ [ $(($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++))
- [ $((flags & FLAG_VERBOSE)) -ne 0 ] && \
- echo "PASS ${xmlfile} : ${cmd}"
- [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
- test_result $((passctr+failctr)) "" 0
- [ $((flags & FLAG_TAP_TEST)) -ne 0 ] && \
- tap_pass $((passctr+failctr)) "${xmlfile} : ${cmd}"
+ passctr=$(($passctr + 1))
+ [ $(($flags & $FLAG_VERBOSE)) -ne 0 ] && \
+ echo "PASS ${xmlfile} : ${cmd}"
+ [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ] && \
+ test_result $(($passctr + $failctr)) "" 0
+ [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ] && \
+ tap_pass $(($passctr + $failctr)) "${xmlfile} : ${cmd}"
fi
break
fi
- echo "${line}" >> "${tmpfile2}"
+ printf %s\\n "${line}" >> "${tmpfile2}"
done
done
exec 4>&-
rm -rf "${tmpdir}"
+
+ IFS="${OIFS}"
}
-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 +211,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
+ 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
@@ -236,9 +238,9 @@ function runTests() {
"${hostoutdir}/${f}.post.dat" "${flags}"
done
- if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- test_final $((passctr+failctr)) $failctr
- elif [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ test_final $(($passctr + $failctr)) $failctr
+ elif [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
tap_final
else
echo ""
@@ -250,29 +252,27 @@ 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
done
if [ $(uname) != "Linux" ]; then
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
echo "1..0 # Skipped: Only valid on Linux hosts"
else
echo "This script will only run on Linux."
@@ -280,7 +280,7 @@ function main() {
exit 1;
fi
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
if [ "${LIBVIRT_URI}" != "qemu:///system" ]; then
echo "1..0 # Skipped: Only valid for Qemu system driver"
exit 0
@@ -290,8 +290,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 +309,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)
@@ -326,18 +326,17 @@ function main() {
done
fi
- if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- pushd "${PWD}" > /dev/null
+ if [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ curdir="${PWD}"
. ./test-lib.sh
if [ $? -ne 0 ]; then
exit 1
fi
test_intro $this_test
- popd > /dev/null
+ cd "${curdir}"
+ [ $? -ne 0 ] && echo "cd failed" && exit 1
fi
- res=$(${VIRSH} capabilities 2>&1)
-
runTests "${xmldir}" "${hostoutdir}" "${flags}"
return 0
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,73 +63,69 @@ 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
+ OIFS="${IFS}"
exec 4<${fwallfile}
- read <&4
- line="${REPLY}"
+ IFS=""
+
+ read -r line <&4
while [ "x${line}x" != "xx" ]; do
- cmd=`echo ${line##\#} | sed ${regex}`
+ cmd=$(printf %s\\n ${line##\#} | sed ${regex})
skip=0
if [ "x${skipregex}x" != "xx" ]; then
- skip=`echo ${cmd} | grep -c -E ${skipregex}`
+ skip=`printf %s\\n ${cmd} | grep -c -E ${skipregex}`
fi
eval ${cmd} 2>&1 | tee ${tmpfile} 1>/dev/null
@@ -135,10 +134,14 @@ function checkExpectedOutput() {
touch ${tmpfile2}
while [ 1 ]; do
- read <&4
- line="${REPLY}"
+ read -r line <&4
- if [ "${line:0:1}" == "#" ] || [ "x${line}x" == "xx" ]; then
+ case "${line}" in
+ '#'*) letter="#";;
+ *) letter="";;
+ esac
+
+ if [ "x${letter}x" = "x#x" ] || [ "x${line}x" = "xx" ]; then
if [ ${skip} -ne 0 ]; then
break
@@ -147,52 +150,53 @@ function checkExpectedOutput() {
diff ${tmpfile} ${tmpfile2} >/dev/null
if [ $? -ne 0 ]; then
- if [ $((flags & FLAG_VERBOSE)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_VERBOSE)) -ne 0 ]; then
echo "FAIL ${xmlfile} : ${cmd}"
diff ${tmpfile} ${tmpfile2}
fi
- ((failctr++))
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ 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}"
+ [ $(($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++))
- [ $((flags & FLAG_VERBOSE)) -ne 0 ] && \
+ passctr=$(($passctr + 1))
+ [ $(($flags & $FLAG_VERBOSE)) -ne 0 ] && \
echo "PASS ${xmlfile} : ${cmd}"
- [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ] && \
- test_result $((passctr+failctr)) "" 0
- [ $((flags & FLAG_TAP_TEST)) -ne 0 ] && \
- tap_pass $((passctr+failctr)) "${xmlfile} : ${cmd}"
+ [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ] && \
+ test_result $(($passctr + $failctr)) "" 0
+ [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ] && \
+ tap_pass $(($passctr + $failctr)) "${xmlfile} : ${cmd}"
fi
break
fi
- echo "${line}" | sed ${regex} >> ${tmpfile2}
+ printf %s\\n "${line}" | sed ${regex} >> ${tmpfile2}
done
done
exec 4>&-
- rm -rf "${tmpfile}" "${tmpfile2}" 2>/dev/null
+ rm -rf "${tmpdir}"
+
+ IFS="${OIFS}"
}
-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}."
@@ -207,9 +211,10 @@ function doTest() {
checkExpectedOutput "${TESTFILTERNAME}" "${TESTVM2FWALLDATA}" \
"${vm2name}" "${flags}" ""
- if [ $((flags & FLAG_ATTACH)) -ne 0 ]; then
+ 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 +230,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}" \
@@ -237,7 +242,7 @@ EOF
echo "FAIL: Detach of interface failed."
fi
else
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
# In case of TAP, run the test anyway so we get to the full number
# of tests
checkExpectedOutput "${xmlfile}" "${fwallfile}" "${ATTACH_IFNAME}" \
@@ -245,48 +250,45 @@ EOF
checkExpectedOutput "${TESTFILTERNAME}" "${TESTVM2FWALLDATA}" \
"${vm2name}" "${flags}" #"(PRE|POST)ROUTING"
fi
-
- ((attachfailctr++))
- if [ $((flags & FLAG_VERBOSE)) -ne 0 ]; then
+
+ 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
+ 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
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ 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
@@ -296,9 +298,9 @@ function runTests() {
"${vm2name}" "${flags}"
done
- if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- test_final $((passctr+failctr)) $failctr
- elif [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ test_final $(($passctr + $failctr)) $failctr
+ elif [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
tap_final
else
echo ""
@@ -310,14 +312,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'>
@@ -363,33 +365,32 @@ EOF
res=$(${VIRSH} start ${vmname})
if [ $? -ne 0 ]; then
echo "Could not start VM ${vmname} : ${res}"
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
$(${VIRSH} undefine ${vmname})
return 1
fi
- [ $((flags & FLAG_VERBOSE)) -ne 0 ] && echo "Created VM ${vmname}."
+ [ $(($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
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -397,23 +398,23 @@ function destroyVM() {
res=$(${VIRSH} undefine ${vmname})
if [ $? -ne 0 ]; then
echo "Could not undefine VM ${vmname} : ${res}"
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
- [ $((flags & FLAG_VERBOSE)) -ne 0 ] && echo "Destroyed VM ${vmname}."
+ [ $(($flags & $FLAG_VERBOSE)) -ne 0 ] && echo "Destroyed VM ${vmname}."
return 0
}
-function createTestFilters() {
- local flags="$1"
- local tmpfile=`mktmpfile`
- local res
+createTestFilters() {
+ flags="$1"
+ tmpdir=$(mktmpdir)
+ tmpfile=$tmpdir/tmpfile
cat >${tmpfile} << EOF
<filter name="${TESTFILTERNAME}">
@@ -431,11 +432,11 @@ EOF
res=$(${VIRSH} nwfilter-define ${tmpfile})
if [ $? -ne 0 ]; then
echo "Could not define filter : ${res}"
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
- rm -rf ${tmpfile}
+ rm -rf ${tmpdir}
return 1
fi
@@ -446,39 +447,38 @@ EOF
res=$(${VIRSH} nwfilter-define ${tmpfile})
if [ $? -ne 0 ]; then
echo "Could not define filter : ${res}"
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ 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
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
res=$(${VIRSH} nwfilter-undefine tck-testcase 2>&1)
if [ $? -ne 0 ]; then
echo "Could not undefine filter : ${res}"
- if [ $((flags & FLAG_WAIT)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_WAIT)) -ne 0 ]; then
echo "Press enter."
- read
+ read enter
fi
return 1
fi
@@ -486,34 +486,32 @@ 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
done
if [ `uname` != "Linux" ]; then
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
echo "1..0 # Skipped: Only valid on Linux hosts"
else
echo "This script will only run on Linux."
@@ -521,21 +519,23 @@ function main() {
exit 1;
fi
- if [ $((flags & FLAG_TAP_TEST)) -ne 0 ]; then
+ if [ $(($flags & $FLAG_TAP_TEST)) -ne 0 ]; then
if [ "${LIBVIRT_URI}" != "qemu:///system" ]; then
echo "1..0 # Skipped: Only valid for Qemu system driver"
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,35 +550,34 @@ 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
done
fi
- if [ $((flags & FLAG_LIBVIRT_TEST)) -ne 0 ]; then
- pushd ${PWD} > /dev/null
+ if [ $(($flags & $FLAG_LIBVIRT_TEST)) -ne 0 ]; then
+ curdir="${PWD}"
. test-lib.sh
if [ $? -ne 0 ]; then
exit 1
fi
test_intro $this_test
- popd > /dev/null
+ cd "${curdir}"
+ [ $? -ne 0 ] && echo "cd failed" && exit 1
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)
+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)
+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
@@ -1,17 +1,17 @@
-#iptables -t nat -L -n | grep ' 10\\.1\\.2\\.'
+#iptables -t nat -L -n | grep ' 10\.1\.2\.'
MASQUERADE tcp -- 10.1.2.0/24 !10.1.2.0/24 masq ports: 1024-65535
MASQUERADE udp -- 10.1.2.0/24 !10.1.2.0/24 masq ports: 1024-65535
MASQUERADE all -- 10.1.2.0/24 !10.1.2.0/24
-#iptables -n -L FORWARD | grep ' 10\\.1\\.2\\.'
+#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[[:print:]*]\)|\1|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\\.'
+#route -n | grep '10\.1\.2\.'
10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
#brctl show | grep tck-testbr
tck-testbr 8000.000000000000 yes
-#ifconfig tck-testbr | grep ':10\\.1\\.2\\.'
+#ifconfig tck-testbr | grep ':10\.1\.2\.'
inet addr:10.1.2.1 Bcast:10.1.2.255 Mask:255.255.255.0
#virsh net-list | grep tck-testnet
tck-testnet active no
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
@@ -1,14 +1,14 @@
-#iptables -L FORWARD -n | grep ' 10\\.1\\.2\\.'
+#iptables -L FORWARD -n | grep ' 10\.1\.2\.'
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'
+#iptables -t nat -L -n | grep ' 10\.1\.2\.'
+#ps aux | sed -n '/dnsmasq .*10\.1\.2\./ s|.*\(dnsmasq[[:print:]*]\)|\1|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\\.'
+#route -n | grep '10\.1\.2\.'
10.1.2.0 0.0.0.0 255.255.255.0 U 0 0 0 tck-testbr
#brctl show | grep tck-testbr
tck-testbr 8000.000000000000 yes
-#ifconfig tck-testbr | grep ':10\\.1\\.2\\.'
+#ifconfig tck-testbr | grep ':10\.1\.2\.'
inet addr:10.1.2.1 Bcast:10.1.2.255 Mask:255.255.255.0
#virsh net-list | grep tck-testnet
tck-testnet active no
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.post.dat
===================================================================
--- libvirt-tck.orig/scripts/networks/networkxml2hostout/tck-testnet-1.post.dat
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-1.post.dat
@@ -1,7 +1,7 @@
-#iptables -t nat -L -n | grep ' 10\\.1\\.2\\.'
-#iptables -n -L FORWARD | grep ' 10\\.1\\.2\\.'
-#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*\\(dnsmasq[[:print:]*]\\)|\\1|p'
-#route -n | grep '10\\.1\\.2\\.'
+#iptables -t nat -L -n | grep ' 10\.1\.2\.'
+#iptables -n -L FORWARD | grep ' 10\.1\.2\.'
+#ps aux | sed -n '/dnsmasq .*10\.1\.2\./ s|.*\(dnsmasq[[:print:]*]\)|\1|p'
+#route -n | grep '10\.1\.2\.'
#brctl show | grep tck-testbr
-#ifconfig tck-testbr 2>/dev/null| grep ':10\\.1\\.2\\.'
+#ifconfig tck-testbr 2>/dev/null| grep ':10\.1\.2\.'
#virsh net-list | grep tck-testnet
Index: libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.post.dat
===================================================================
--- libvirt-tck.orig/scripts/networks/networkxml2hostout/tck-testnet-2.post.dat
+++ libvirt-tck/scripts/networks/networkxml2hostout/tck-testnet-2.post.dat
@@ -1,7 +1,7 @@
-#iptables -t nat -L -n | grep ' 10\\.1\\.2'
-#iptables -n -L FORWARD | grep ' 10\\.1\\.2'
-#ps aux | sed -n '/dnsmasq .*10\\.1\\.2\\./ s|.*\\(dnsmasq[[:print:]*]\\)|\\1|p'
-#route -n | grep '10\\.1\\.2\\.'
+#iptables -t nat -L -n | grep ' 10\.1\.2'
+#iptables -n -L FORWARD | grep ' 10\.1\.2'
+#ps aux | sed -n '/dnsmasq .*10\.1\.2\./ s|.*\(dnsmasq[[:print:]*]\)|\1|p'
+#route -n | grep '10\.1\.2\.'
#brctl show | grep tck-testbr
-#ifconfig tck-testbr 2>/dev/null | grep ':10\\.1\\.2\\.'
+#ifconfig tck-testbr 2>/dev/null | grep ':10\.1\.2\.'
#virsh net-list | grep tck-testnet
Index: libvirt-tck/scripts/nwfilter/nwfilterxml2fwallout/comment-test.fwall
===================================================================
--- libvirt-tck.orig/scripts/nwfilter/nwfilterxml2fwallout/comment-test.fwall
+++ libvirt-tck/scripts/nwfilter/nwfilterxml2fwallout/comment-test.fwall
@@ -33,21 +33,21 @@ Chain FI-vnet0 (1 references)
target prot opt source destination
RETURN tcp ::/0 a:b:c::/128 /* tcp/ipv6 rule */ tcp spts:256:4369 dpts:32:33 state ESTABLISHED ctdir ORIGINAL
RETURN udp ::/0 ::/0 /* `ls`;${COLUMNS};$(ls);"test";&'3 spaces' */ state ESTABLISHED ctdir ORIGINAL
-RETURN sctp ::/0 ::/0 /* comment with lone ', `, ", `, \\, $x, and two spaces */ state ESTABLISHED ctdir ORIGINAL
+RETURN sctp ::/0 ::/0 /* comment with lone ', `, ", `, \, $x, and two spaces */ state ESTABLISHED ctdir ORIGINAL
RETURN ah ::/0 ::/0 /* tmp=`mktemp`; echo ${RANDOM} > ${tmp} ; cat < ${tmp}; rm -f ${tmp} */ state ESTABLISHED ctdir ORIGINAL
#ip6tables -L FO-vnet0 -n
Chain FO-vnet0 (1 references)
target prot opt source destination
ACCEPT tcp a:b:c::/128 ::/0 MAC 01:02:03:04:05:06 /* tcp/ipv6 rule */ tcp spts:32:33 dpts:256:4369 state NEW,ESTABLISHED ctdir REPLY
ACCEPT udp ::/0 ::/0 /* `ls`;${COLUMNS};$(ls);"test";&'3 spaces' */ state NEW,ESTABLISHED ctdir REPLY
-ACCEPT sctp ::/0 ::/0 /* comment with lone ', `, ", `, \\, $x, and two spaces */ state NEW,ESTABLISHED ctdir REPLY
+ACCEPT sctp ::/0 ::/0 /* comment with lone ', `, ", `, \, $x, and two spaces */ state NEW,ESTABLISHED ctdir REPLY
ACCEPT ah ::/0 ::/0 /* tmp=`mktemp`; echo ${RANDOM} > ${tmp} ; cat < ${tmp}; rm -f ${tmp} */ state NEW,ESTABLISHED ctdir REPLY
#ip6tables -L HI-vnet0 -n
Chain HI-vnet0 (1 references)
target prot opt source destination
RETURN tcp ::/0 a:b:c::/128 /* tcp/ipv6 rule */ tcp spts:256:4369 dpts:32:33 state ESTABLISHED ctdir ORIGINAL
RETURN udp ::/0 ::/0 /* `ls`;${COLUMNS};$(ls);"test";&'3 spaces' */ state ESTABLISHED ctdir ORIGINAL
-RETURN sctp ::/0 ::/0 /* comment with lone ', `, ", `, \\, $x, and two spaces */ state ESTABLISHED ctdir ORIGINAL
+RETURN sctp ::/0 ::/0 /* comment with lone ', `, ", `, \, $x, and two spaces */ state ESTABLISHED ctdir ORIGINAL
RETURN ah ::/0 ::/0 /* tmp=`mktemp`; echo ${RANDOM} > ${tmp} ; cat < ${tmp}; rm -f ${tmp} */ state ESTABLISHED ctdir ORIGINAL
#ip6tables -L libvirt-host-in -n | grep vnet0 | tr -s " "
HI-vnet0 all ::/0 ::/0 [goto] PHYSDEV match --physdev-in vnet0
2
2
[libvirt] [PATCH v2] deprecate fclose() and introduce VIR_{FORCE_}FCLOSE()
by Stefan Berger 15 Nov '10
by Stefan Berger 15 Nov '10
15 Nov '10
V2:
- following Eric's suggestion, deprecating fdclose(), introducing VIR_FDCLOSE()
- following some other nits that Eric pointed out
- replaced some more fclose () I previously had missed (last 2 files in patch)
Similarly to deprecating close(), I am now deprecating fclose() and
introduce VIR_FORCE_FCLOSE() and VIR_FCLOSE(). Also, fdopen() is replaced with
VIR_FDOPEN().
Most of the files are opened in read-only mode, so usage of
VIR_FORCE_CLOSE() seemed appropriate. Others that are opened in write
mode already had the fclose() < 0 check and I converted those to
VIR_FCLOSE() < 0.
I did not find occurrences of possible double-closed files on the way.
Signed-off-by: Stefan Berger <stefanb(a)us.ibm.com>
---
HACKING | 33 +++++++++++++++++++++++++++------
daemon/libvirtd.c | 6 +++---
docs/hacking.html.in | 36 ++++++++++++++++++++++++++++--------
src/libvirt_private.syms | 2 ++
src/nodeinfo.c | 8 ++++----
src/openvz/openvz_conf.c | 12 ++++++------
src/openvz/openvz_driver.c | 4 ++--
src/qemu/qemu_driver.c | 4 ++--
src/storage/storage_backend.c | 18 +++++++-----------
src/storage/storage_backend_fs.c | 4 ++--
src/storage/storage_backend_iscsi.c | 9 +++------
src/storage/storage_backend_scsi.c | 2 +-
src/uml/uml_driver.c | 8 ++++----
src/util/cgroup.c | 10 +++++-----
src/util/dnsmasq.c | 5 +++--
src/util/files.c | 32 ++++++++++++++++++++++++++++++++
src/util/files.h | 6 ++++++
src/util/macvtap.c | 4 ++--
src/util/stats_linux.c | 3 ++-
src/util/util.c | 10 ++++------
src/xen/block_stats.c | 3 ++-
src/xen/xen_driver.c | 7 ++++---
src/xen/xen_hypervisor.c | 8 +++-----
tests/nodeinfotest.c | 5 +++--
tests/testutils.c | 8 ++++----
tests/xencapstest.c | 7 +++----
26 files changed, 164 insertions(+), 90 deletions(-)
Index: libvirt-acl/src/util/files.c
===================================================================
--- libvirt-acl.orig/src/util/files.c
+++ libvirt-acl/src/util/files.c
@@ -44,3 +44,35 @@ int virClose(int *fdptr, bool preserve_e
return rc;
}
+
+
+int virFclose(FILE **file, bool preserve_errno)
+{
+ int saved_errno;
+ int rc = 0;
+
+ if (*file) {
+ if (preserve_errno)
+ saved_errno = errno;
+ rc = fclose(*file);
+ *file = NULL;
+ if (preserve_errno)
+ errno = saved_errno;
+ }
+
+ return rc;
+}
+
+
+FILE *virFdopen(int *fdptr, const char *mode)
+{
+ FILE *file = NULL;
+
+ if (*fdptr >= 0) {
+ file = fdopen(*fdptr, mode);
+ if (file)
+ *fdptr = -1;
+ }
+
+ return file;
+}
Index: libvirt-acl/src/util/files.h
===================================================================
--- libvirt-acl.orig/src/util/files.h
+++ libvirt-acl/src/util/files.h
@@ -27,6 +27,7 @@
# define __VIR_FILES_H_
# include <stdbool.h>
+# include <stdio.h>
# include "internal.h"
# include "ignore-value.h"
@@ -34,13 +35,18 @@
/* Don't call this directly - use the macros below */
int virClose(int *fdptr, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+int virFclose(FILE **file, bool preserve_errno) ATTRIBUTE_RETURN_CHECK;
+FILE *virFdopen(int *fdptr, const char *mode);
/* For use on normal paths; caller must check return value,
and failure sets errno per close(). */
# define VIR_CLOSE(FD) virClose(&(FD), false)
+# define VIR_FCLOSE(FILE) virFclose(&(FILE), false)
+# define VIR_FDOPEN(FD, MODE) virFdopen(&(FD), MODE)
/* For use on cleanup paths; errno is unaffected by close,
and no return value to worry about. */
# define VIR_FORCE_CLOSE(FD) ignore_value(virClose(&(FD), true))
+# define VIR_FORCE_FCLOSE(FILE) ignore_value(virFclose(&(FILE), true))
#endif /* __VIR_FILES_H */
Index: libvirt-acl/src/libvirt_private.syms
===================================================================
--- libvirt-acl.orig/src/libvirt_private.syms
+++ libvirt-acl/src/libvirt_private.syms
@@ -344,6 +344,8 @@ virFDStreamCreateFile;
# files.h
virClose;
+virFclose;
+virFdopen;
# hash.h
Index: libvirt-acl/daemon/libvirtd.c
===================================================================
--- libvirt-acl.orig/daemon/libvirtd.c
+++ libvirt-acl/daemon/libvirtd.c
@@ -512,7 +512,7 @@ static int qemudWritePidFile(const char
return -1;
}
- if (!(fh = fdopen(fd, "w"))) {
+ if (!(fh = VIR_FDOPEN(fd, "w"))) {
VIR_ERROR(_("Failed to fdopen pid file '%s' : %s"),
pidFile, virStrerror(errno, ebuf, sizeof ebuf));
VIR_FORCE_CLOSE(fd);
@@ -522,11 +522,11 @@ static int qemudWritePidFile(const char
if (fprintf(fh, "%lu\n", (unsigned long)getpid()) < 0) {
VIR_ERROR(_("%s: Failed to write to pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
- fclose(fh);
+ VIR_FORCE_FCLOSE(fh);
return -1;
}
- if (fclose(fh) == EOF) {
+ if (VIR_FCLOSE(fh) == EOF) {
VIR_ERROR(_("%s: Failed to close pid file '%s' : %s"),
argv0, pidFile, virStrerror(errno, ebuf, sizeof ebuf));
return -1;
Index: libvirt-acl/src/nodeinfo.c
===================================================================
--- libvirt-acl.orig/src/nodeinfo.c
+++ libvirt-acl/src/nodeinfo.c
@@ -46,6 +46,7 @@
#include "virterror_internal.h"
#include "count-one-bits.h"
#include "intprops.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NONE
@@ -102,8 +103,7 @@ get_cpu_value(unsigned int cpu, const ch
}
cleanup:
- if (pathfp)
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return value;
@@ -155,7 +155,7 @@ static unsigned long count_thread_siblin
}
cleanup:
- fclose(pathfp);
+ VIR_FORCE_FCLOSE(pathfp);
VIR_FREE(path);
return ret;
@@ -329,7 +329,7 @@ int nodeGetInfo(virConnectPtr conn ATTRI
return -1;
}
ret = linuxNodeInfoCPUPopulate(cpuinfo, nodeinfo);
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
if (ret < 0)
return -1;
Index: libvirt-acl/src/openvz/openvz_conf.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_conf.c
+++ libvirt-acl/src/openvz/openvz_conf.c
@@ -528,7 +528,7 @@ int openvzLoadDomains(struct openvz_driv
dom = NULL;
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return 0;
@@ -536,7 +536,7 @@ int openvzLoadDomains(struct openvz_driv
virReportOOMError();
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (dom)
virDomainObjUnref(dom);
return -1;
@@ -906,10 +906,10 @@ openvzSetDefinedUUID(int vpsid, unsigned
virUUIDFormat(uuid, uuidstr);
- /* Record failure if fprintf or fclose fails,
+ /* Record failure if fprintf or VIR_FCLOSE fails,
and be careful always to close the stream. */
- if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0)
- + (fclose(fp) == EOF))
+ if ((fprintf(fp, "\n#UUID: %s\n", uuidstr) < 0) ||
+ (VIR_FCLOSE(fp) == EOF))
goto cleanup;
}
@@ -996,7 +996,7 @@ int openvzGetVEID(const char *name) {
}
ok = fscanf(fp, "%d\n", &veid ) == 1;
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (ok && veid >= 0)
return veid;
Index: libvirt-acl/src/openvz/openvz_driver.c
===================================================================
--- libvirt-acl.orig/src/openvz/openvz_driver.c
+++ libvirt-acl/src/openvz/openvz_driver.c
@@ -154,7 +154,7 @@ openvzDomainDefineCmd(const char *args[]
max_veid = veid;
}
}
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
if (max_veid == 0) {
max_veid = 100;
@@ -189,7 +189,7 @@ no_memory:
return -1;
cleanup:
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
#undef ADD_ARG
Index: libvirt-acl/src/qemu/qemu_driver.c
===================================================================
--- libvirt-acl.orig/src/qemu/qemu_driver.c
+++ libvirt-acl/src/qemu/qemu_driver.c
@@ -4588,7 +4588,7 @@ static int qemudGetProcessInfo(unsigned
/* startstack -> processor */
"%*u %*u %*u %*u %*u %*u %*u %*u %*u %*u %*d %d",
&usertime, &systime, &cpu) != 3) {
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
VIR_WARN0("cannot parse process status data");
errno = -EINVAL;
return -1;
@@ -4608,7 +4608,7 @@ static int qemudGetProcessInfo(unsigned
VIR_DEBUG("Got status for %d/%d user=%llu sys=%llu cpu=%d",
pid, tid, usertime, systime, cpu);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend.c
+++ libvirt-acl/src/storage/storage_backend.c
@@ -1398,7 +1398,7 @@ virStorageBackendRunProgRegex(virStorage
goto cleanup;
}
- if ((list = fdopen(fd, "r")) == NULL) {
+ if ((list = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("cannot read fd"));
goto cleanup;
@@ -1458,10 +1458,8 @@ virStorageBackendRunProgRegex(virStorage
VIR_FREE(reg);
- if (list)
- fclose(list);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(list);
+ VIR_FORCE_CLOSE(fd);
while ((err = waitpid(child, &exitstatus, 0) == -1) && errno == EINTR);
@@ -1531,9 +1529,9 @@ virStorageBackendRunProgNul(virStoragePo
goto cleanup;
}
- if ((fp = fdopen(fd, "r")) == NULL) {
+ if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("cannot read fd"));
+ "%s", _("cannot open file using fd"));
goto cleanup;
}
@@ -1573,10 +1571,8 @@ virStorageBackendRunProgNul(virStoragePo
VIR_FREE(v[i]);
VIR_FREE(v);
- if (fp)
- fclose (fp);
- else
- VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(fp);
+ VIR_FORCE_CLOSE(fd);
while ((w_err = waitpid (child, &exitstatus, 0) == -1) && errno == EINTR)
/* empty */ ;
Index: libvirt-acl/src/storage/storage_backend_fs.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_fs.c
+++ libvirt-acl/src/storage/storage_backend_fs.c
@@ -284,12 +284,12 @@ virStorageBackendFileSystemIsMounted(vir
while ((getmntent_r(mtab, &ent, buf, sizeof(buf))) != NULL) {
if (STREQ(ent.mnt_dir, pool->def->target.path)) {
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 1;
}
}
- fclose(mtab);
+ VIR_FORCE_FCLOSE(mtab);
return 0;
}
Index: libvirt-acl/src/storage/storage_backend_iscsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_iscsi.c
+++ libvirt-acl/src/storage/storage_backend_iscsi.c
@@ -188,7 +188,7 @@ virStorageBackendIQNFound(virStoragePool
goto out;
}
- if ((fp = fdopen(fd, "r")) == NULL) {
+ if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
_("Failed to open stream for file descriptor "
"when reading output from '%s': '%s'"),
@@ -235,11 +235,8 @@ out:
}
VIR_FREE(line);
- if (fp != NULL) {
- fclose(fp);
- } else {
- VIR_FORCE_CLOSE(fd);
- }
+ VIR_FORCE_FCLOSE(fp);
+ VIR_FORCE_CLOSE(fd);
return ret;
}
Index: libvirt-acl/src/storage/storage_backend_scsi.c
===================================================================
--- libvirt-acl.orig/src/storage/storage_backend_scsi.c
+++ libvirt-acl/src/storage/storage_backend_scsi.c
@@ -70,7 +70,7 @@ getDeviceType(uint32_t host,
}
gottype = fgets(typestr, 3, typefile);
- fclose(typefile);
+ VIR_FORCE_FCLOSE(typefile);
if (gottype == NULL) {
virReportSystemError(errno,
Index: libvirt-acl/src/uml/uml_driver.c
===================================================================
--- libvirt-acl.orig/src/uml/uml_driver.c
+++ libvirt-acl/src/uml/uml_driver.c
@@ -587,11 +587,11 @@ reopen:
if (fscanf(file, "%d", &vm->pid) != 1) {
errno = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0)
+ if (VIR_FCLOSE(file) < 0)
goto cleanup;
rc = 0;
@@ -1096,7 +1096,7 @@ static int umlGetProcessInfo(unsigned lo
if (fscanf(pidinfo, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %llu %llu", &usertime, &systime) != 2) {
umlDebug("not enough arg");
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return -1;
}
@@ -1109,7 +1109,7 @@ static int umlGetProcessInfo(unsigned lo
umlDebug("Got %llu %llu %llu", usertime, systime, *cpuTime);
- fclose(pidinfo);
+ VIR_FORCE_FCLOSE(pidinfo);
return 0;
}
Index: libvirt-acl/src/util/cgroup.c
===================================================================
--- libvirt-acl.orig/src/util/cgroup.c
+++ libvirt-acl/src/util/cgroup.c
@@ -31,6 +31,7 @@
#include "memory.h"
#include "cgroup.h"
#include "logging.h"
+#include "files.h"
#define CGROUP_MAX_VAL 512
@@ -127,13 +128,12 @@ static int virCgroupDetectMounts(virCgro
}
}
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return 0;
no_memory:
- if (mounts)
- fclose(mounts);
+ VIR_FORCE_FCLOSE(mounts);
return -ENOMEM;
}
@@ -192,12 +192,12 @@ static int virCgroupDetectPlacement(virC
}
}
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return 0;
no_memory:
- fclose(mapping);
+ VIR_FORCE_FCLOSE(mapping);
return -ENOMEM;
}
Index: libvirt-acl/src/util/dnsmasq.c
===================================================================
--- libvirt-acl.orig/src/util/dnsmasq.c
+++ libvirt-acl/src/util/dnsmasq.c
@@ -44,6 +44,7 @@
#include "memory.h"
#include "virterror_internal.h"
#include "logging.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_NETWORK
#define DNSMASQ_HOSTSFILE_SUFFIX "hostsfile"
@@ -171,7 +172,7 @@ hostsfileWrite(const char *path,
for (i = 0; i < nhosts; i++) {
if (fputs(hosts[i].host, f) == EOF || fputc('\n', f) == EOF) {
rc = errno;
- fclose(f);
+ VIR_FORCE_FCLOSE(f);
if (istmp)
unlink(tmp);
@@ -180,7 +181,7 @@ hostsfileWrite(const char *path,
}
}
- if (fclose(f) == EOF) {
+ if (VIR_FCLOSE(f) == EOF) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/util/macvtap.c
===================================================================
--- libvirt-acl.orig/src/util/macvtap.c
+++ libvirt-acl/src/util/macvtap.c
@@ -436,11 +436,11 @@ int openTap(const char *ifname,
virReportSystemError(errno,
"%s",_("cannot determine macvtap's tap device "
"interface index"));
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
return -1;
}
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
if (snprintf(tapname, sizeof(tapname),
"/dev/tap%d", ifindex) >= sizeof(tapname)) {
Index: libvirt-acl/src/util/util.c
===================================================================
--- libvirt-acl.orig/src/util/util.c
+++ libvirt-acl/src/util/util.c
@@ -1816,7 +1816,7 @@ int virFileWritePidPath(const char *pidf
goto cleanup;
}
- if (!(file = fdopen(fd, "w"))) {
+ if (!(file = VIR_FDOPEN(fd, "w"))) {
rc = errno;
VIR_FORCE_CLOSE(fd);
goto cleanup;
@@ -1830,10 +1830,8 @@ int virFileWritePidPath(const char *pidf
rc = 0;
cleanup:
- if (file &&
- fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0)
rc = errno;
- }
return rc;
}
@@ -1864,11 +1862,11 @@ int virFileReadPid(const char *dir,
if (fscanf(file, "%d", pid) != 1) {
rc = EINVAL;
- fclose(file);
+ VIR_FORCE_FCLOSE(file);
goto cleanup;
}
- if (fclose(file) < 0) {
+ if (VIR_FCLOSE(file) < 0) {
rc = errno;
goto cleanup;
}
Index: libvirt-acl/src/xen/xen_driver.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_driver.c
+++ libvirt-acl/src/xen/xen_driver.c
@@ -47,6 +47,7 @@
#include "pci.h"
#include "uuid.h"
#include "fdstream.h"
+#include "files.h"
#define VIR_FROM_THIS VIR_FROM_XEN
@@ -216,10 +217,10 @@ xenUnifiedProbe (void)
return 1;
#endif
#ifdef __sun
- FILE *fh;
+ int fd;
- if (fh = fopen("/dev/xen/domcaps", "r")) {
- fclose(fh);
+ if (fd = open("/dev/xen/domcaps", O_RDONLY)) {
+ VIR_FORCE_CLOSE(fd);
return 1;
}
#endif
Index: libvirt-acl/src/xen/xen_hypervisor.c
===================================================================
--- libvirt-acl.orig/src/xen/xen_hypervisor.c
+++ libvirt-acl/src/xen/xen_hypervisor.c
@@ -2641,7 +2641,7 @@ xenHypervisorMakeCapabilities(virConnect
capabilities = fopen ("/sys/hypervisor/properties/capabilities", "r");
if (capabilities == NULL) {
if (errno != ENOENT) {
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
virReportSystemError(errno,
_("cannot read file %s"),
"/sys/hypervisor/properties/capabilities");
@@ -2654,10 +2654,8 @@ xenHypervisorMakeCapabilities(virConnect
cpuinfo,
capabilities);
- if (cpuinfo)
- fclose(cpuinfo);
- if (capabilities)
- fclose(capabilities);
+ VIR_FORCE_FCLOSE(cpuinfo);
+ VIR_FORCE_FCLOSE(capabilities);
return caps;
#endif /* __sun */
Index: libvirt-acl/tests/nodeinfotest.c
===================================================================
--- libvirt-acl.orig/tests/nodeinfotest.c
+++ libvirt-acl/tests/nodeinfotest.c
@@ -9,6 +9,7 @@
#include "internal.h"
#include "nodeinfo.h"
#include "util.h"
+#include "files.h"
#ifndef __linux__
@@ -49,10 +50,10 @@ static int linuxTestCompareFiles(const c
fprintf(stderr, "\n%s\n", error->message);
virFreeError(error);
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
return -1;
}
- fclose(cpuinfo);
+ VIR_FORCE_FCLOSE(cpuinfo);
/* 'nodes' is filled using libnuma.so from current machine
* topology, which makes it unsuitable for the test suite
Index: libvirt-acl/tests/testutils.c
===================================================================
--- libvirt-acl.orig/tests/testutils.c
+++ libvirt-acl/tests/testutils.c
@@ -180,26 +180,26 @@ int virtTestLoadFile(const char *file,
if (fstat(fileno(fp), &st) < 0) {
fprintf (stderr, "%s: failed to fstat: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size > (buflen-1)) {
fprintf (stderr, "%s: larger than buffer (> %d)\n", file, buflen-1);
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
if (st.st_size) {
if (fread(*buf, st.st_size, 1, fp) != 1) {
fprintf (stderr, "%s: read failed: %s\n", file, strerror(errno));
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return -1;
}
}
(*buf)[st.st_size] = '\0';
- fclose(fp);
+ VIR_FORCE_FCLOSE(fp);
return st.st_size;
}
Index: libvirt-acl/tests/xencapstest.c
===================================================================
--- libvirt-acl.orig/tests/xencapstest.c
+++ libvirt-acl/tests/xencapstest.c
@@ -9,6 +9,7 @@
#include "xml.h"
#include "testutils.h"
#include "xen/xen_hypervisor.h"
+#include "files.h"
static char *progname;
static char *abs_srcdir;
@@ -63,10 +64,8 @@ static int testCompareFiles(const char *
fail:
free(actualxml);
- if (fp1)
- fclose(fp1);
- if (fp2)
- fclose(fp2);
+ VIR_FORCE_FCLOSE(fp1);
+ VIR_FORCE_FCLOSE(fp2);
virCapabilitiesFree(caps);
return ret;
Index: libvirt-acl/docs/hacking.html.in
===================================================================
--- libvirt-acl.orig/docs/hacking.html.in
+++ libvirt-acl/docs/hacking.html.in
@@ -414,25 +414,45 @@
<h2><a name="file_handling">File handling</a></h2>
<p>
- Use of the close() API is deprecated in libvirt code base to help
- avoiding double-closing of a file descriptor. Instead of this API,
- use the macro from files.h
+ Usage of the <code>fdopen()</code>, <code>close()</code>, <code>fclose()</code>
+ APIs is deprecated in libvirt code base to help avoiding double-closing of files
+ or file descriptors, which is particulary dangerous in a multi-threaded
+ applications. Instead of these APIs, use the macros from files.h
</p>
- <ul>
+ <ul>
+ <li><p>eg opening a file from a file descriptor</p>
+
+<pre>
+ if ((file = VIR_FDOPEN(fd, "r")) == NULL) {
+ virReportSystemError(errno, "%s",
+ _("failed to open file from file descriptor"));
+ return -1;
+ }
+ /* fd is now invalid; only access the file using file variable */
+</pre></li>
+
<li><p>e.g. close a file descriptor</p>
<pre>
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
-</pre>
- </li>
+</pre></li>
+
+ <li><p>eg close a file</p>
+
+<pre>
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+</pre></li>
- <li><p>eg close a file descriptor in an error path, without losing
+ <li><p>eg close a file or file descriptor in an error path, without losing
the previous <code>errno</code> value</p>
<pre>
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
</pre>
</li>
</ul>
Index: libvirt-acl/HACKING
===================================================================
--- libvirt-acl.orig/HACKING
+++ libvirt-acl/HACKING
@@ -339,22 +339,43 @@ routines, use the macros from memory.h
File handling
=============
-Use of the close() API is deprecated in libvirt code base to help avoiding
-double-closing of a file descriptor. Instead of this API, use the macro from
-files.h
+Usage of the "fdopen()", "close()", "fclose()" APIs is deprecated in libvirt
+code base to help avoiding double-closing of files or file descriptors, which
+is particulary dangerous in a multi-threaded applications. Instead of these
+APIs, use the macros from files.h
+
+- eg opening a file from a file descriptor
+
+ if ((file = VIR_FDOPEN(fd, "r")) == NULL) {
+ virReportSystemError(errno, "%s",
+ _("failed to open file from file descriptor"));
+ return -1;
+ }
+ /* fd is now invalid; only access the file using file variable */
+
+
- e.g. close a file descriptor
if (VIR_CLOSE(fd) < 0) {
- virReportSystemError(errno, _("failed to close file"));
+ virReportSystemError(errno, "%s", _("failed to close file"));
+ }
+
+
+
+- eg close a file
+
+ if (VIR_FCLOSE(file) < 0) {
+ virReportSystemError(errno, "%s", _("failed to close file"));
}
-- eg close a file descriptor in an error path, without losing the previous
-"errno" value
+- eg close a file or file descriptor in an error path, without losing the
+previous "errno" value
VIR_FORCE_CLOSE(fd);
+ VIR_FORCE_FCLOSE(file);
Index: libvirt-acl/src/util/stats_linux.c
===================================================================
--- libvirt-acl.orig/src/util/stats_linux.c
+++ libvirt-acl/src/util/stats_linux.c
@@ -25,6 +25,7 @@
# include "util.h"
# include "stats_linux.h"
# include "memory.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
@@ -103,7 +104,7 @@ linuxDomainInterfaceStats(const char *pa
return 0;
}
}
- fclose (fp);
+ VIR_FORCE_FCLOSE(fp);
virStatsError(VIR_ERR_INTERNAL_ERROR,
"/proc/net/dev: Interface not found");
Index: libvirt-acl/src/xen/block_stats.c
===================================================================
--- libvirt-acl.orig/src/xen/block_stats.c
+++ libvirt-acl/src/xen/block_stats.c
@@ -27,6 +27,7 @@
# include "util.h"
# include "block_stats.h"
# include "memory.h"
+# include "files.h"
# define VIR_FROM_THIS VIR_FROM_STATS_LINUX
@@ -100,7 +101,7 @@ read_stat (const char *path)
/* read, but don't bail out before closing */
i = fread (str, 1, sizeof str - 1, fp);
- if (fclose (fp) != 0 /* disk error */
+ if (VIR_FCLOSE(fp) != 0 /* disk error */
|| i < 1) /* ensure we read at least one byte */
return -1;
2
1
Eric Blake pointed out a deficiency in this regex when it was
copy-pasted into network.rng. This is just propogating the fix back to
its origin.
---
docs/schemas/interface.rng | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/docs/schemas/interface.rng b/docs/schemas/interface.rng
index a0df9ba..75893b5 100644
--- a/docs/schemas/interface.rng
+++ b/docs/schemas/interface.rng
@@ -439,7 +439,7 @@
<define name='ipv4-addr'>
<data type='string'>
- <param name="pattern">(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2}))\.){3}((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2}))</param>
+ <param name="pattern">(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([1-9][0-9])|([0-9]))</param>
</data>
</define>
--
1.7.2.3
2
2
[libvirt] [PATCH] interface.rng: Make miimon and arpmon optional for bond interfaces
by Laine Stump 15 Nov '10
by Laine Stump 15 Nov '10
15 Nov '10
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
2
2
15 Nov '10
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
3
8
15 Nov '10
-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_gf903c9ea089…
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;
2
2
[libvirt] [PATCH] RFC: Remove all object hashtable caches from virConnectPtr
by Daniel P. Berrange 15 Nov '10
by Daniel P. Berrange 15 Nov '10
15 Nov '10
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
3
6