From patchwork Thu Aug 20 04:01:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ouyang Changchun X-Patchwork-Id: 6782 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 9812B8D39; Thu, 20 Aug 2015 06:01:24 +0200 (CEST) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 1A7898D35 for ; Thu, 20 Aug 2015 06:01:22 +0200 (CEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga102.jf.intel.com with ESMTP; 19 Aug 2015 21:01:21 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,713,1432623600"; d="scan'208";a="787248154" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 19 Aug 2015 21:01:18 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t7K41GMA002039; Thu, 20 Aug 2015 12:01:16 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t7K41CCo029003; Thu, 20 Aug 2015 12:01:14 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t7K41CnM028999; Thu, 20 Aug 2015 12:01:12 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Thu, 20 Aug 2015 12:01:10 +0800 Message-Id: <1440043270-28970-1-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.12.2 Cc: claire.k.murphy@intel.com Subject: [dpdk-dev] [PATCH] vhost: fix qemu shutdown issue 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch originates from the patch: [dpdk-dev] [PATCH 1/2] Patch for Qemu wrapper for US-VHost to ensure Qemu process ends when VM is shutdown http://dpdk.org/ml/archives/dev/2014-June/003606.html Aslo update the vhost sample guide doc. Signed-off-by: Claire Murphy Signed-off-by: Changchun Ouyang --- doc/guides/sample_app_ug/vhost.rst | 9 --------- lib/librte_vhost/libvirt/qemu-wrap.py | 29 +++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/doc/guides/sample_app_ug/vhost.rst b/doc/guides/sample_app_ug/vhost.rst index 730b9da..743908d 100644 --- a/doc/guides/sample_app_ug/vhost.rst +++ b/doc/guides/sample_app_ug/vhost.rst @@ -717,15 +717,6 @@ Common Issues needs access to the shared memory from the guest to receive and transmit packets. It is important to make sure the QEMU version supports shared memory mapping. -* Issues with ``virsh destroy`` not destroying the VM: - - Using libvirt ``virsh create`` the ``qemu-wrap.py`` spawns a new process to run ``qemu-kvm``. This impacts the behavior - of ``virsh destroy`` which kills the process running ``qemu-wrap.py`` without actually destroying the VM (it leaves - the ``qemu-kvm`` process running): - - This following patch should fix this issue: - http://dpdk.org/ml/archives/dev/2014-June/003607.html - * In an Ubuntu environment, QEMU fails to start a new guest normally with user space VHOST due to not being able to allocate huge pages for the new guest: diff --git a/lib/librte_vhost/libvirt/qemu-wrap.py b/lib/librte_vhost/libvirt/qemu-wrap.py index 5096011..30a0d50 100755 --- a/lib/librte_vhost/libvirt/qemu-wrap.py +++ b/lib/librte_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. @@ -280,7 +295,7 @@ def main(): 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,14 +367,21 @@ 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__": main()