From patchwork Tue Oct 17 04:32:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Cody X-Patchwork-Id: 10010743 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1ADA2601E7 for ; Tue, 17 Oct 2017 04:49:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 092A028732 for ; Tue, 17 Oct 2017 04:49:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EF1212875A; Tue, 17 Oct 2017 04:49:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D26B28732 for ; Tue, 17 Oct 2017 04:49:25 +0000 (UTC) Received: from localhost ([::1]:36480 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4Joi-0005zX-JU for patchwork-qemu-devel@patchwork.kernel.org; Tue, 17 Oct 2017 00:49:24 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53942) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1e4JZJ-00019N-R2 for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:33:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1e4JZI-0005MD-Hf for qemu-devel@nongnu.org; Tue, 17 Oct 2017 00:33:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44704) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1e4JZF-0005It-DA; Tue, 17 Oct 2017 00:33:25 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F762C049D42; Tue, 17 Oct 2017 04:33:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6F762C049D42 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jcody@redhat.com Received: from localhost (ovpn-117-62.phx2.redhat.com [10.3.117.62]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F237C61787; Tue, 17 Oct 2017 04:33:23 +0000 (UTC) From: Jeff Cody To: qemu-devel@nongnu.org Date: Tue, 17 Oct 2017 00:32:41 -0400 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 17 Oct 2017 04:33:24 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 05/10] qemu-iotests: change qemu pid and fd tracking / cleanup X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, jsnow@redhat.com, stefanha@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP So that later patches can cleanup running qemu processes called from different subshells, track resources to cleanup in pid and fd list files. In subsquent patches, ./check will kill all QEMU processes launched with the common.qemu framework, and the tests will not need to cleanup manually (unless they want to do so as part of the test, e.g. wait for a process to end such as migration). Signed-off-by: Jeff Cody --- tests/qemu-iotests/common.qemu | 65 +++++++++++++++++++++++++++++++----------- tests/qemu-iotests/common.rc | 2 +- 2 files changed, 49 insertions(+), 18 deletions(-) diff --git a/tests/qemu-iotests/common.qemu b/tests/qemu-iotests/common.qemu index 7b3052d..7bd21ea 100644 --- a/tests/qemu-iotests/common.qemu +++ b/tests/qemu-iotests/common.qemu @@ -193,6 +193,8 @@ function _launch_qemu() QEMU_OUT[${_QEMU_HANDLE}]=${_out_fd} QEMU_IN[${_QEMU_HANDLE}]=${_in_fd} QEMU_STATUS[${_QEMU_HANDLE}]=0 + echo ${_out_fd} >> "$QEMU_TEST_DIR/qemu-out-fd.lst" + echo ${_in_fd} >> "$QEMU_TEST_DIR/qemu-in-fd.lst" if [ "${qemu_comm_method}" == "qmp" ] then @@ -209,35 +211,64 @@ function _launch_qemu() # Silenty kills the QEMU process # +# This is able to kill and clean up after QEMU processes without the +# need for any subshell-specific variables, so long as the qemu-pidlist +# and qemu-out-fd.list and qemu-in-fd.list files are properly maintained. +# # If $wait is set to anything other than the empty string, the process will not # be killed but only waited for, and any output will be forwarded to stdout. If # $wait is empty, the process will be killed and all output will be suppressed. function _cleanup_qemu() { - # QEMU_PID[], QEMU_IN[], QEMU_OUT[] all use same indices - for i in "${!QEMU_OUT[@]}" + local PIDFILE="${QEMU_TEST_DIR}"/qemu-pidlist.pid + local OUT_FD_FILE="${QEMU_TEST_DIR}"/qemu-out-fd.lst + local IN_FD_FILE="${QEMU_TEST_DIR}"/qemu-in-fd.lst + + if [ ! -e "${PIDFILE}" ]; then + return + fi + + # get line count, and therefore number of processes to kill + numproc=$(wc -l "${PIDFILE}" | sed 's/\s.*//') + + for i in $(seq 1 $numproc) do local QEMU_PID - if [ -f "${QEMU_TEST_DIR}/qemu-${i}.pid" ]; then - read QEMU_PID < "${QEMU_TEST_DIR}/qemu-${i}.pid" - rm -f "${QEMU_TEST_DIR}/qemu-${i}.pid" - if [ -z "${wait}" ] && [ -n "${QEMU_PID}" ]; then - kill -KILL ${QEMU_PID} 2>/dev/null - fi - if [ -n "${QEMU_PID}" ]; then - wait ${QEMU_PID} 2>/dev/null # silent kill - fi + local OUT_FD + local IN_FD + + QEMU_PID=$(tail -n+${i} "${PIDFILE}" | head -n1) + OUT_FD=$(tail -n+${i} "${OUT_FD_FILE}" | head -n1) + IN_FD=$(tail -n+${i} "${IN_FD_FILE}" | head -n1) + + if [ -z "${wait}" ] && [ -n "${QEMU_PID}" ]; then + kill -KILL ${QEMU_PID} 2>/dev/null + fi + if [ -n "${QEMU_PID}" ]; then + wait ${QEMU_PID} 2>/dev/null # silent kill + fi + + if [ -n "${wait}" ] && [ -n "${OUT_FD}" ]; then + cat <&${OUT_FD} | _filter_testdir | _filter_qemu \ + | _filter_qemu_io | _filter_qmp | _filter_hmp fi - if [ -n "${wait}" ]; then - cat <&${QEMU_OUT[$i]} | _filter_testdir | _filter_qemu \ - | _filter_qemu_io | _filter_qmp | _filter_hmp + if [ -n "${IN_FD}" ]; then + eval "exec ${IN_FD}<&-" # close file descriptors + fi + if [ -n "${OUT_FD}" ]; then + eval "exec ${OUT_FD}<&-" + fi + if [ -n "${QEMU_FIFO_IN}" ]; then + rm -f "${QEMU_FIFO_IN}_${i}" + fi + if [ -n "${QEMU_FIFO_OUT}" ]; then + rm -f "${QEMU_FIFO_OUT}_${i}" fi - rm -f "${QEMU_FIFO_IN}_${i}" "${QEMU_FIFO_OUT}_${i}" - eval "exec ${QEMU_IN[$i]}<&-" # close file descriptors - eval "exec ${QEMU_OUT[$i]}<&-" unset QEMU_IN[$i] unset QEMU_OUT[$i] done + + rm -f "${PIDFILE}" "${OUT_FD_FILE}" "${IN_FD_FILE}" } diff --git a/tests/qemu-iotests/common.rc b/tests/qemu-iotests/common.rc index a345ffd..c81f712 100644 --- a/tests/qemu-iotests/common.rc +++ b/tests/qemu-iotests/common.rc @@ -51,7 +51,7 @@ _qemu_wrapper() { ( if [ -n "${QEMU_NEED_PID}" ]; then - echo $BASHPID > "${QEMU_TEST_DIR}/qemu-${_QEMU_HANDLE}.pid" + echo $BASHPID >> "${QEMU_TEST_DIR}/qemu-pidlist.pid" fi exec "$QEMU_PROG" $QEMU_OPTIONS "$@" )