From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id BA32CB149 for ; Wed, 18 Jun 2014 17:35:30 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP; 18 Jun 2014 08:29:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.01,501,1400050800"; d="scan'208";a="549885235" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga001.fm.intel.com with ESMTP; 18 Jun 2014 08:34:59 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s5IFYwS1013167; Wed, 18 Jun 2014 16:34:58 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s5IFYwGo023955; Wed, 18 Jun 2014 16:34:58 +0100 Received: (from cmurph2@localhost) by sivswdev02.ir.intel.com with id s5IFYw5C023951; Wed, 18 Jun 2014 16:34:58 +0100 From: Claire Murphy To: dev@dpdk.org Date: Wed, 18 Jun 2014 16:34:53 +0100 Message-Id: <1403105694-23736-2-git-send-email-claire.k.murphy@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1403105694-23736-1-git-send-email-claire.k.murphy@intel.com> References: <1403105694-23736-1-git-send-email-claire.k.murphy@intel.com> Subject: [dpdk-dev] [PATCH 1/2] Patch for Qemu wrapper for US-VHost to ensure Qemu process ends when VM is shutdown. X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 18 Jun 2014 15:35:31 -0000 Signed-off-by: Claire Murphy --- examples/vhost/libvirt/qemu-wrap.py | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-) diff --git a/examples/vhost/libvirt/qemu-wrap.py b/examples/vhost/libvirt/qemu-wrap.py index e2d68a0..bfe668a 100755 --- a/examples/vhost/libvirt/qemu-wrap.py +++ b/examples/vhost/libvirt/qemu-wrap.py @@ -76,6 +76,7 @@ # "/dev/ptmx", "/dev/kvm", "/dev/kqemu", # "/dev/rtc", "/dev/hpet", "/dev/net/tun", # "/dev/-", +# "/dev/hugepages" # ] # # 4.b) Disable SELinux or set to permissive mode @@ -161,6 +162,8 @@ hugetlbfs_dir = "" ############################################# import sys, os, subprocess +import time +import signal #List of open userspace vhost file descriptors @@ -174,6 +177,18 @@ vhost_flags = [ "csum=off", "guest_ecn=off" ] +#String of the path to the Qemu process pid +qemu_pid = "/tmp/%d-qemu.pid" % os.getpid() + +############################################# +# Signal haldler to kill Qemu subprocess +############################################# +def kill_qemu_process(signum, stack): + pidfile = open(qemu_pid, 'r') + pid = int(pidfile.read()) + os.killpg(pid, signal.SIGTERM) + pidfile.close() + ############################################# # Find the system hugefile mount point. @@ -274,13 +289,13 @@ def main(): emul_call = '' mem_prealloc_set = 0 mem_path_set = 0 - num = 0; + num = 0 #parse the parameters while (num < num_cmd_args): arg = sys.argv[num] - #Check netdev +1 parameter for vhostfd + #Check netdev +1 parameter for vhostfd if arg == '-netdev': num_vhost_devs = len(fd_list) new_args.append(arg) @@ -333,7 +348,6 @@ def main(): emul_call += mp emul_call += " " - #add user options for opt in emul_opts_user: emul_call += opt @@ -353,13 +367,22 @@ def main(): emul_call+=str(arg) emul_call+= " " + emul_call += "-pidfile %s " % qemu_pid #Call QEMU - subprocess.call(emul_call, shell=True) + process = subprocess.Popen(emul_call, shell=True, preexec_fn=os.setsid) + + for sig in [signal.SIGTERM, signal.SIGINT, signal.SIGHUP, signal.SIGQUIT]: + signal.signal(sig, kill_qemu_process) + process.wait() #Close usvhost files for fd in fd_list: os.close(fd) + #Cleanup temporary files + if os.access(qemu_pid, os.F_OK): + os.remove(qemu_pid) + if __name__ == "__main__": -- 1.7.0.7