From patchwork Fri Jun 28 03:38:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 167998 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3156976ilk; Thu, 27 Jun 2019 20:37:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqxrvDb95N96e8LpruQKzD19jCijtHTfdO67ZtvCK09s5pP6i3BJS/cl6/bDFSYcaqzfSZdO X-Received: by 2002:a63:2326:: with SMTP id j38mr7316304pgj.134.1561693076569; Thu, 27 Jun 2019 20:37:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561693076; cv=none; d=google.com; s=arc-20160816; b=vKwYit4KcyJUJXNGfB/xN3GNQ8gGi0USS+7GzHkyVMXPJAMwfaw08wePa0AtSK0s2D UBjY7WMATYiSxhtDo5eerAQdbhL8iSNuIvex65mgGPJSvbUJCGdXlmj6kIiJ/Eetg7Hr Eh9xURgEhMneaNwkbdFlZdHiPgSWAd6xc+UNRI3wfhnyweOTRFjx4b4MxO9EG5go5tpo V0TftCUD6GgdIu2abhsLFAtEEvAarxutlJubF91s80K/P/CXZBW6EtQBdlxfFQzqXzIz M+xnITX5p92EJBqztRjLedMBko2JSOgseKuUAJPHbEH9rIOFmk4lVGxg51oLD6LLFMRb p8Bw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:delivered-to; bh=1rIP+Ga9TK4DqdmUmyRMNUrNqYBCovcAU8G37waHde8=; b=ScR5nY6Aiqe+VMV0Od0B+LmzbR9TXHjIiDGce13lJ5CgmR6f3UIIEAGu9pWM10NT+Y AI17GOmWg/BfOQGweqLRAPfu1o+1GI4akbrOn1wzuQuXg7jKlBOmciACGWZRzmZb7uRi dZmPCYQqPh6TD12dti1OmkiW/2sTmYW1Jp96+lMGkrvQCqCXUqkWuhcNFTR/ClR0lO7m P0D7CVjybcb5rHRVhHjGF9GZQs8BhNXNd6E8W9THUEpKtioj+AcGMr8rwznpnap1ysXY lhJh+2obQez2+65/osH0xPDzaS4s4J3N6zNBEMUGV5LLzsBWBZMEXfJb0NdxZiWGi29n ZSgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=mC+j9GQO; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id l13si1027903pjq.69.2019.06.27.20.37.55; Thu, 27 Jun 2019 20:37:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=mC+j9GQO; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ec2-34-214-78-129.us-west-2.compute.amazonaws.com (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id A6BC47E9A2; Fri, 28 Jun 2019 03:37:52 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by mail.openembedded.org (Postfix) with ESMTP id BD2397E71D for ; Fri, 28 Jun 2019 03:37:51 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id k8so2427129plt.3 for ; Thu, 27 Jun 2019 20:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hmeKpZsM5UFB/SVPkYcwh/IiH6jl+9WHQTT+pVcUicM=; b=mC+j9GQOysUT4arn2pxzjywkLDf4bXV4YObmrGkz/T0ystV0yMZQ1XVB6PmSaUbjtT aTiwNLLj8K2U8BGmixDO7U0ROAKmZVMJNEJKCJJOls3qQUyY/bOdjnOmuc62AfNABI4y XIlR+kgGAvVRQyakxaB5q3f3TNy2neVmDMOkXy+eJdUMSvo1iZZSA738UbyuQLemARuM s7/O2Y2iBjL7yzl/SRwKqyDnNwLVfjwdmAAwCn+fb/Y7buvIE2jmmq37+P4aTq0PIkqb us05u7WjMqxH/ylCtcWDC/WLYswkVnYZb5M2mt0Na2Lebh/nqQV1HBbOnOZ3D9cpY6zz zvow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=hmeKpZsM5UFB/SVPkYcwh/IiH6jl+9WHQTT+pVcUicM=; b=PCXZoNkv9/1zK88bEOhi+7Pbts8U0zx30U0269XeMykGMDg/RD6Q2ld/G/M+FtOSGG 2NS56YFQLpdq78Pv/OKTyH+CA+ZLXaKzI2hEaTjtVCvvdL+QtyxLFeDh0FEJ7wK8jdvp /+C2LVf1BWgf69Tiis8VkDHjtKDAL900BqlfcM5QnRmFpyLRcx3Vs+H3b82KQ5K4pqAe mHLti1WoFTAhAVUkN4o3c/2VMACVzwkX0UX4dysZWXw6ffiTlXOPCIFqkTvAjRW7zhuW 8nm+GKhYYOjurKzsTQm4VWf7QKYbr/L73gf59lrMsoCm8d9ItTr8BoDlEF9vfEv8RKT5 ubdA== X-Gm-Message-State: APjAAAXDeMxmu//JU1UTHNtSIxBc+V4C6oztC9jvw72J9xTTgXN80MkE nvTAcFYHYn+o97ihIxnXM8JwNW+Va1NjHzt4 X-Received: by 2002:a17:902:15c5:: with SMTP id a5mr8929427plh.39.1561693072635; Thu, 27 Jun 2019 20:37:52 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id e184sm566027pfa.169.2019.06.27.20.37.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 20:37:52 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Thu, 27 Jun 2019 22:38:28 -0500 Message-Id: <20190628033830.27713-1-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [OE-core] [PATCH 1/3] runqemu: Allow to store more than one lock for network interfaces X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org In order to support multiple tap devices in the same qemu virtual machine. Signed-off-by: Aníbal Limón --- scripts/runqemu | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index 4079f2b17d..8a54c9ef9a 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -181,8 +181,7 @@ class BaseConfig(object): self.audio_enabled = False self.tcpserial_portnum = '' self.custombiosdir = '' - self.lock = '' - self.lock_descriptor = None + self.lock_descriptors = {} self.bitbake_e = '' self.snapshot = False self.wictypes = ('wic', 'wic.vmdk', 'wic.qcow2', 'wic.vdi') @@ -204,30 +203,30 @@ class BaseConfig(object): # avoid cleanup twice self.cleaned = False - def acquire_lock(self, error=True): - logger.debug("Acquiring lockfile %s..." % self.lock) + def acquire_lock(self, lock, error=True): + logger.debug("Acquiring lockfile %s..." % lock) try: - self.lock_descriptor = open(self.lock, 'w') - fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB) + self.lock_descriptors[lock] = open(lock, 'w') + fcntl.flock(self.lock_descriptors[lock], fcntl.LOCK_EX|fcntl.LOCK_NB) except Exception as e: - msg = "Acquiring lockfile %s failed: %s" % (self.lock, e) + msg = "Acquiring lockfile %s failed: %s" % (lock, e) if error: logger.error(msg) else: logger.info(msg) - if self.lock_descriptor: - self.lock_descriptor.close() - self.lock_descriptor = None + if self.lock_descriptors[lock]: + self.lock_descriptor[lock].close() + self.lock_descriptor[lock] = None return False return True - def release_lock(self): - if self.lock_descriptor: - logger.debug("Releasing lockfile for tap device '%s'" % self.tap) - fcntl.flock(self.lock_descriptor, fcntl.LOCK_UN) - self.lock_descriptor.close() - os.remove(self.lock) - self.lock_descriptor = None + def release_lock(self, lock): + if self.lock_descriptors[lock]: + logger.debug("Releasing lockfile for tap device '%s'" % lock) + fcntl.flock(self.lock_descriptors[lock], fcntl.LOCK_UN) + self.lock_descriptors[lock].close() + os.remove(lock) + self.lock_descriptors[lock] = None def get(self, key): if key in self.d: @@ -1016,8 +1015,8 @@ class BaseConfig(object): if os.path.exists('%s.skip' % lockfile): logger.info('Found %s.skip, skipping %s' % (lockfile, p)) continue - self.lock = lockfile + '.lock' - if self.acquire_lock(error=False): + lock = lockfile + '.lock' + if self.acquire_lock(lock, error=False): tap = p logger.info("Using preconfigured tap device %s" % tap) logger.info("If this is not intended, touch %s.skip to make runqemu skip %s." %(lockfile, tap)) @@ -1035,8 +1034,8 @@ class BaseConfig(object): cmd = ('sudo', self.qemuifup, str(uid), str(gid), self.bindir_native) tap = subprocess.check_output(cmd).decode('utf-8').strip() lockfile = os.path.join(lockdir, tap) - self.lock = lockfile + '.lock' - self.acquire_lock() + lock = lockfile + '.lock' + self.acquire_lock(lock) self.cleantap = True logger.debug('Created tap: %s' % tap) @@ -1268,8 +1267,8 @@ class BaseConfig(object): cmds = shlex.split(cmd) logger.info('Running %s\n' % cmd) pass_fds = [] - if self.lock_descriptor: - pass_fds = [self.lock_descriptor.fileno()] + if self.lock_descriptors.keys(): + pass_fds = [self.lock_descriptors[lock].fileno() for lock in self.lock_descriptors.keys()] process = subprocess.Popen(cmds, stderr=subprocess.PIPE, pass_fds=pass_fds) self.qemupid = process.pid retcode = process.wait() @@ -1291,7 +1290,8 @@ class BaseConfig(object): cmd = ('sudo', self.qemuifdown, self.tap, self.bindir_native) logger.debug('Running %s' % str(cmd)) subprocess.check_call(cmd) - self.release_lock() + for lock in self.lock_descriptors.keys(): + self.release_lock(lock) if self.nfs_running: logger.info("Shutting down the userspace NFS server...") From patchwork Fri Jun 28 03:38:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 167999 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3157099ilk; Thu, 27 Jun 2019 20:38:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4bjtmj+91TZVGljdcH9o/fvNYLMuKS/IlEC2Nb9LQ4k7b4rO7IhGlT9JbtaAMxrMqVC5B X-Received: by 2002:a17:902:d887:: with SMTP id b7mr8806859plz.28.1561693086565; Thu, 27 Jun 2019 20:38:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561693086; cv=none; d=google.com; s=arc-20160816; b=WXpDUfQstNxqCzHPbfTm6giW8ne3LvPCPWXYKBbVN4yeNo4jgLDkxBVJoroEr6aWqR OPTjUfRdbkXdlTac5/3Ms2778k7e+5pjOJDoT3TY99wwkopu64tUEej7amh5gZz99UIT dqSJb0rdbRFuKIGy9//K2ws1z4PmS1VEdVojztkwXrifmGApp7Y5Jp9Z8ei5Z6WZoaEL jHpyrU3GP6e2gzsiTkjYISoILUOYowZkKSqzIPlFmfx0m7xMMWK8pkfrud/c/c5Eh3pQ yD5NaT7ks4C2mPnnB2VApxyjlkH5d6QjKKnINTDBMssOuXHMOcCwvYvJpvOY8hxyq9mo KYfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=nEMM14ufRBuU6ahvW0AU9hZ7slpMLSftNOVd0tvFJeM=; b=MM0qUKaEsPmcw2DdU9cofREKQJeT4LJ8tRovKTZyz0bYk2DWyRrTPSwKDyfUe8CtVj Pd0p2GqgjhobIiFr/21DD18Q6quDxm/CKQys7hrEpZHajsfTD0jVm1ATlMzs+6UdUp71 jBlq+f/dvM/kAGe3UikEIfiMF/ry1JlXq5GougdKVAEHdU1S2jlC6/O0r1iavpsp4zec We9XRGBFdxVYpcm2XPyVA2Uu77jBr+wduVhms2nbswLNuBIkVXi8HO47sivKyMBUstTS JvSJ3e2prAsyieFrrWTCmNwjMfu3JDeid0gFQZi9gSFoQEK3tcrJb5iJ0rU+EZqRn9AR 0KGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=g2zncgl6; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id e96si935478plb.123.2019.06.27.20.38.06; Thu, 27 Jun 2019 20:38:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=g2zncgl6; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ec2-34-214-78-129.us-west-2.compute.amazonaws.com (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 459D57EA5E; Fri, 28 Jun 2019 03:38:03 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by mail.openembedded.org (Postfix) with ESMTP id 9A22D7EA5F for ; Fri, 28 Jun 2019 03:37:56 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id bi6so2411013plb.12 for ; Thu, 27 Jun 2019 20:37:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wAkmMDly0bZ8LiPueFeslg8jzXm3MB4NJxjNlm+XwoE=; b=g2zncgl6CY1mEA32gTBYoBs1siJyLD4JRrhQ+B1iIgSCdBobEAU08q4qx+ZF5eAeO4 ya4+Y6ab2TtsSX6NzP2qkT02RuMuiM27PggNaZN1LZrRFRaUoAT3U22Hl/yCSiYOcUX/ FibZf7mPA7qdGy50xFrDyIzIlP8/xP492aEYMzIFjebu4y9yMYz9M2ZLg+UgfceHh3KG UJzwwdKCyibQc3IPMy1qH2zjzI6fvpbZPNYOshYn164/LMbC82CayPk1aP5TGn6N8NfW Q8Myr20hzVr4ehPLBnKZJC4B4d4EtryCVthVFCK5jyCSuWAaQe/elcMexyjewZDtXP3I bFuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wAkmMDly0bZ8LiPueFeslg8jzXm3MB4NJxjNlm+XwoE=; b=TtdGWZhpT1QcemXEu7oofNlC9RE7F29nUZGc8bvS3McHDGWyIrN7Jw0q2kF3Gz0dOB s51Edd2GwoC6ZRgFipxJnxetS8e6CnmjgNU8Wh6FLwzJXfTnTWdByEjk/bC4RF+vxL/E kNthsuNcN0Pdq9PnboK6iw2Sq8WMJm3pv1zgSxJ6E59rf3b/p2H1UVpaNl6BuRc7aLNM Oob4XuhKV3s3mp73y8FVX7gqqGU3gZNwFE8oJXm4i1fLvrD4lz5Sq9FSTSDLjDE6vyB6 6SNmSKhcPP/vBOOBABAY3Fj/Z3Ta/CMU+H9Z9PUD7pj9KvsriOtovPlP1Zc0R/3/92cv RD0g== X-Gm-Message-State: APjAAAWPsvqTbFqlglDMBIA2x1KEjlLtwN1qN2t3gNEW4S3Hid3dLZe4 tjsuEu9fl7MnyACcgg8Ijp9WIn0aP0JCVlno X-Received: by 2002:a17:902:bf08:: with SMTP id bi8mr9052756plb.189.1561693077572; Thu, 27 Jun 2019 20:37:57 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id e184sm566027pfa.169.2019.06.27.20.37.55 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 20:37:57 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Thu, 27 Jun 2019 22:38:29 -0500 Message-Id: <20190628033830.27713-2-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190628033830.27713-1-anibal.limon@linaro.org> References: <20190628033830.27713-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCH 2/3] runqemu: Add support for multiple tap devices X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org Add the ability to set more than one tap devices into the same qemu instance, The code was modified to detect multiple @TAP@ and @MAC@ in the QA_TAP_OPT and QA_NETWORK_DEVICE respectively, it handles the attach/creation of multiple tap devices and stores into a list for lock/unlock. Configure the first interface because Kernel IP Configuration only takes care of the first device. This patch was tested using qemux86, kvm-vhost and NFS rootfs. Example of the configuration: QB_TAP_OPT = "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no \ -netdev tap,id=net1,ifname=@TAP@,script=no,downscript=no" QB_NETWORK_DEVICE = "-device virtio-net-pci,netdev=net0,mac=@MAC@ \ -device virtio-net-pci,netdev=net1,mac=@MAC@" Signed-off-by: Aníbal Limón --- scripts/runqemu | 134 +++++++++++++++++++++++++++--------------------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index 8a54c9ef9a..e1a78c8910 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1004,64 +1004,81 @@ class BaseConfig(object): except FileExistsError: pass - cmd = (ip, 'link') - logger.debug('Running %s...' % str(cmd)) - ip_link = subprocess.check_output(cmd).decode('utf-8') - # Matches line like: 6: tap0: - possibles = re.findall('^[0-9]+: +(tap[0-9]+): <.*', ip_link, re.M) - tap = "" - for p in possibles: - lockfile = os.path.join(lockdir, p) - if os.path.exists('%s.skip' % lockfile): - logger.info('Found %s.skip, skipping %s' % (lockfile, p)) - continue - lock = lockfile + '.lock' - if self.acquire_lock(lock, error=False): - tap = p - logger.info("Using preconfigured tap device %s" % tap) - logger.info("If this is not intended, touch %s.skip to make runqemu skip %s." %(lockfile, tap)) - break - - if not tap: - if os.path.exists(nosudo_flag): - logger.error("Error: There are no available tap devices to use for networking,") - logger.error("and I see %s exists, so I am not going to try creating" % nosudo_flag) - raise RunQemuError("a new one with sudo.") - - gid = os.getgid() - uid = os.getuid() - logger.info("Setting up tap interface under sudo") - cmd = ('sudo', self.qemuifup, str(uid), str(gid), self.bindir_native) - tap = subprocess.check_output(cmd).decode('utf-8').strip() - lockfile = os.path.join(lockdir, tap) - lock = lockfile + '.lock' - self.acquire_lock(lock) - self.cleantap = True - logger.debug('Created tap: %s' % tap) - - if not tap: - logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") - return 1 - self.tap = tap - tapnum = int(tap[3:]) - gateway = tapnum * 2 + 1 - client = gateway + 1 - if self.fstype == 'nfs': - self.setup_nfs() - netconf = "192.168.7.%s::192.168.7.%s:255.255.255.0" % (client, gateway) - logger.info("Network configuration: %s", netconf) - self.kernel_cmdline_script += " ip=%s" % netconf - mac = "%s%02x" % (self.mac_tap, client) - qb_tap_opt = self.get('QB_TAP_OPT') - if qb_tap_opt: - qemu_tap_opt = qb_tap_opt.replace('@TAP@', tap) - else: - qemu_tap_opt = "-netdev tap,id=net0,ifname=%s,script=no,downscript=no" % (self.tap) + self.taps = [] + qemu_tap_opt = self.get('QB_TAP_OPT') + if not qemu_tap_opt: + qemu_tap_opt = '-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no' if self.vhost_enabled: - qemu_tap_opt += ',vhost=on' + opts = [] + for tap_opt in qemu_tap_opt.split(): + if 'tap' in tap_opt: + tap_opt += ',vhost=on' + opts.append(tap_opt) + else: + opts.append(tap_opt) + qemu_tap_opt = ' '.join(opts) + + tap_no = qemu_tap_opt.count('@TAP@') + for tap_idx in range(tap_no): + cmd = (ip, 'link') + logger.debug('Running %s...' % str(cmd)) + ip_link = subprocess.check_output(cmd).decode('utf-8') + # Matches line like: 6: tap0: + possibles = re.findall('^[0-9]+: +(tap[0-9]+): <.*', ip_link, re.M) + tap = "" + for p in possibles: + if p in self.taps: + continue + + lockfile = os.path.join(lockdir, p) + if os.path.exists('%s.skip' % lockfile): + logger.info('Found %s.skip, skipping %s' % (lockfile, p)) + continue + lock = lockfile + '.lock' + if self.acquire_lock(lock, error=False): + tap = p + logger.info("Using preconfigured tap device %s" % tap) + logger.info("If this is not intended, touch %s.skip to make runqemu skip %s." %(lockfile, tap)) + break - self.set('NETWORK_CMD', '%s %s' % (self.network_device.replace('@MAC@', mac), qemu_tap_opt)) + if not tap: + if os.path.exists(nosudo_flag): + logger.error("Error: There are no available tap devices to use for networking,") + logger.error("and I see %s exists, so I am not going to try creating" % nosudo_flag) + raise RunQemuError("a new one with sudo.") + + gid = os.getgid() + uid = os.getuid() + logger.info("Setting up tap interface under sudo") + cmd = ('sudo', self.qemuifup, str(uid), str(gid), self.bindir_native) + tap = subprocess.check_output(cmd).decode('utf-8').strip() + lockfile = os.path.join(lockdir, tap) + lock = lockfile + '.lock' + self.acquire_lock(lock) + self.cleantap = True + logger.info('Created tap: %s' % tap) + + if not tap: + logger.error("Failed to setup tap device. Run runqemu-gen-tapdevs to manually create.") + return 1 + self.taps.append(tap) + tapnum = int(tap[3:]) + gateway = tapnum * 2 + 1 + client = gateway + 1 + + if tap_idx == 0: + netconf = "192.168.7.%s::192.168.7.%s:255.255.255.0::eth%d" % (client, gateway, tap_idx) + logger.info("Network configuration: %s", netconf) + self.kernel_cmdline_script += " ip=%s" % netconf + + mac = "%s%02x" % (self.mac_tap, client) + qemu_tap_opt = qemu_tap_opt.replace('@TAP@', tap, 1) + self.network_device = self.network_device.replace('@MAC@', mac, 1) + + self.set('NETWORK_CMD', '%s %s' % (self.network_device, qemu_tap_opt)) + if self.fstype == 'nfs': + self.setup_nfs() def setup_network(self): if self.get('QB_NET') == 'none': @@ -1287,9 +1304,10 @@ class BaseConfig(object): logger.info("Cleaning up") if self.cleantap: - cmd = ('sudo', self.qemuifdown, self.tap, self.bindir_native) - logger.debug('Running %s' % str(cmd)) - subprocess.check_call(cmd) + for tap in self.taps: + cmd = ('sudo', self.qemuifdown, tap, self.bindir_native) + logger.debug('Running %s' % str(cmd)) + subprocess.check_call(cmd) for lock in self.lock_descriptors.keys(): self.release_lock(lock) From patchwork Fri Jun 28 03:38:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168000 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3157188ilk; Thu, 27 Jun 2019 20:38:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqw067WOfh3pUniDQnBtg4yTsroTAdVCkaeAPjFKTBZTjL1NuYMIUYNsdnTddFBZStsZ3zVx X-Received: by 2002:a17:90a:3210:: with SMTP id k16mr9979178pjb.13.1561693092829; Thu, 27 Jun 2019 20:38:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561693092; cv=none; d=google.com; s=arc-20160816; b=cS54t/PXec1oHZRCNF5r/Vbhi3uxf0he5XPc7+6PVjXBNyIxW8KJ6YqbtofROGqcXt LB/cLmGiK7XqAaSy1L11ZinZJYRxt4UkgcY8QClEfjeZgEnJRHqkFnIxwMMjNW3cFsFy a6en2P0r3XP87NUcBWMiGCmn4rURMJKNYHbmmbP0BwJzsr5Ouz5hlvS4PgydlBPQ5CVN 6WERWgUULEvsPsF4nE/kOWf6f2+KJHicyePqUVPebJ2V5u4sNiMjt5ZnMS5poULbqwwu 0JRYbEGybrhKxYhUHpne0BrEFjVd5uUTiBrA4CZxQs1CTqPLVK9UA17mMk0rbH3g4vP5 OuRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:sender:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:delivered-to; bh=gruW3mu96HU1dEsl4zE8oAYAkWgs+kYpA22/xVRJib0=; b=YVSHCEQakdGoc3munUGU2Gy0wnz9F0AC1OFygCjDdQn7eU56AExgCnaUyjPFWCaBVy 71BQDV4UKhKmfCZfdqp64SBBMxf2tNqRhr8dBCIqW5tcMRLHD6HE0XmIQcpSbvAhy3AX WqQ44pqsMyL/Gqm67RR+QXZIpRlVmdPLWGozZFrZzzO1fLV0y/ycrQYEiosuJrFNlzMY b8QzQPz8m5eriZ7B6cTersBwbjaArZVeiULNWAt3tZFZSviCbZ+30B0sKuZlSF7uLdpF huA3JqS/i864HaBd2ozSVPFcDhK7okKnyDKBFbLhum362x/6JCN12yCDRiLvAWoMo9D1 LHog== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EMOFORpN; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail.openembedded.org (mail.openembedded.org. [140.211.169.62]) by mx.google.com with ESMTP id h13si906338pgp.296.2019.06.27.20.38.12; Thu, 27 Jun 2019 20:38:12 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) client-ip=140.211.169.62; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=EMOFORpN; spf=pass (google.com: best guess record for domain of openembedded-core-bounces@lists.openembedded.org designates 140.211.169.62 as permitted sender) smtp.mailfrom=openembedded-core-bounces@lists.openembedded.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from ec2-34-214-78-129.us-west-2.compute.amazonaws.com (localhost [127.0.0.1]) by mail.openembedded.org (Postfix) with ESMTP id 6A6727EA6D; Fri, 28 Jun 2019 03:38:04 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-pl1-f196.google.com (mail-pl1-f196.google.com [209.85.214.196]) by mail.openembedded.org (Postfix) with ESMTP id 0DF4C7EA5F for ; Fri, 28 Jun 2019 03:37:58 +0000 (UTC) Received: by mail-pl1-f196.google.com with SMTP id 9so1648403ple.5 for ; Thu, 27 Jun 2019 20:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7Vfg9h33wB7wYrWh5CS3qJmltO09MmuyBAYOIuEZJec=; b=EMOFORpNA/TWQegB0oArQ+ZFhdP0T5w2eiwIrkmUrJjhmXv6b12KTPib7PcmfLeWKS RsPGz+qdpLcQ8vpYfycl+bquhlye0Zebuj85i2zLsuepczhqunDzUEVc3YrQzOwcogG3 v61H3FELog6+3eD7KBrhdn6a+lGOaDCcPBQ1eaWhzMe8ofoBZjtmudnofifEf8P74LQK 4Yx4DWIjqdCZnGkTi6rY+xbsvH4dK0rBEgWWnugH0BqZIBiJpN3GTHV7iG6hWNbVTRa9 joRUZ6G2YQ6K63xFhEKqpT2X6ij4642QHOsGSVcIsU2qwMAakPCz+5zvCfcoocSOC2zP OsOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7Vfg9h33wB7wYrWh5CS3qJmltO09MmuyBAYOIuEZJec=; b=RFT0W52IDKNS7e5QVUEpTc9uZelO6sCm9CqrLFGKKaesEJUWxsb+58OX2cuuKkxakH lapEQiDOzh5Cv8XrRZqjG0RHUMYMq8B4ofMSHRjWx1bA+G13jiEjsQnF4yvQfyRZvcQo i9DE+4LU2NSI2H2H/8vlYOlj9CBTiZwPYl0fINZps2k2bfG8LFKKKvKpw46qPR00R79l nMXPqmHDeSDCpTp6YMUHZmKXs5Ep9s/ugUDIjzEDch6wTbzfyt95EBEI4XEEIz2muy0T pz7Sf+j2mH+k0at33tDpTuWcA0S1CgWoeluDrFSsZKqwf+A/D39QQm3xsD7aAIn8yKHk +G9w== X-Gm-Message-State: APjAAAVXrX0tONRw1MM/axjbrY2KjK9VBr9/Qswx5tYaLJAmrvnX0Ltg 04baogw2T1hzW45oaK2/6S0mCK9+VAj5W44B X-Received: by 2002:a17:902:8c98:: with SMTP id t24mr9026952plo.320.1561693079203; Thu, 27 Jun 2019 20:37:59 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id e184sm566027pfa.169.2019.06.27.20.37.57 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 27 Jun 2019 20:37:58 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Thu, 27 Jun 2019 22:38:30 -0500 Message-Id: <20190628033830.27713-3-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190628033830.27713-1-anibal.limon@linaro.org> References: <20190628033830.27713-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCH 3/3] runqemu: Add QB_KERNEL_NO_NETWORK_CONFIG variable X-BeenThere: openembedded-core@lists.openembedded.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: Patches and discussions about the oe-core layer List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openembedded-core-bounces@lists.openembedded.org Errors-To: openembedded-core-bounces@lists.openembedded.org To let user choice if wants to have network configured via Kernel cmdline. Signed-off-by: Aníbal Limón --- meta/classes/qemuboot.bbclass | 3 +++ scripts/runqemu | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/meta/classes/qemuboot.bbclass b/meta/classes/qemuboot.bbclass index 15a9e63f2b..5df63a6a61 100644 --- a/meta/classes/qemuboot.bbclass +++ b/meta/classes/qemuboot.bbclass @@ -41,6 +41,8 @@ # "-netdev tap,id=net0,ifname=@TAP@,script=no,downscript=no" # Note, runqemu will replace "@TAP@" with the one which is used, such as tap0, tap1 ... # +# QB_KERNEL_NO_NETWORK_CONFIG: disable auto network configuration via kernel cmdline possible values 'True' and 'False' +# # QB_SLIRP_OPT: network option for SLIRP mode, e.g., -netdev user,id=net0" # # QB_ROOTFS_OPT: used as rootfs, e.g., @@ -63,6 +65,7 @@ QB_DEFAULT_KERNEL ?= "${KERNEL_IMAGETYPE}" QB_DEFAULT_FSTYPE ?= "ext4" QB_OPT_APPEND ?= "-show-cursor" QB_NETWORK_DEVICE ?= "-device virtio-net-pci,netdev=net0,mac=@MAC@" +QB_KERNEL_NO_NETWORK_CONFIG ?= "False" # This should be kept align with ROOT_VM QB_DRIVE_TYPE ?= "/dev/sd" diff --git a/scripts/runqemu b/scripts/runqemu index e1a78c8910..5d6804233f 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1067,10 +1067,12 @@ class BaseConfig(object): gateway = tapnum * 2 + 1 client = gateway + 1 - if tap_idx == 0: - netconf = "192.168.7.%s::192.168.7.%s:255.255.255.0::eth%d" % (client, gateway, tap_idx) - logger.info("Network configuration: %s", netconf) - self.kernel_cmdline_script += " ip=%s" % netconf + no_network = self.get('QB_KERNEL_NO_NETWORK_CONFIG') + if no_network and not no_network.lower() == 'true': + if tap_idx == 0: + netconf = "192.168.7.%s::192.168.7.%s:255.255.255.0::eth%d" % (client, gateway, tap_idx) + logger.info("Network configuration: %s", netconf) + self.kernel_cmdline_script += " ip=%s" % netconf mac = "%s%02x" % (self.mac_tap, client) qemu_tap_opt = qemu_tap_opt.replace('@TAP@', tap, 1)