From patchwork Mon Jul 1 21:23:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168228 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3397290ilk; Mon, 1 Jul 2019 14:23:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxSPNwkMEtg2XzgIxrCRVIEtwsG8HJdKbwCKmS0X1+ofIwB6vqeaW9/40/BRTtLjUdn0FgM X-Received: by 2002:a17:902:2be8:: with SMTP id l95mr29129454plb.231.1562016188116; Mon, 01 Jul 2019 14:23:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562016188; cv=none; d=google.com; s=arc-20160816; b=riAt6Lsmni256fx0NsAL/Z5bwcKuqmAHFzyAgby/F3OfYnwJ/aiSiaNWcNfJjD5E/s 5MZXYfHfvNf8ogdYzfOX4v5+3ULudPrCW78zfMBnXxi5t1lPOgD6E/0UXJIDk1dG+ZwS oDbZNtGG6iB19DIfbXayHoDv+8pybRPx6o2jlMRNBKSTChmOGdzo5YA9lQ1VZRziMi5K TpVt+5tjDw025ivIoAuYK/qTaQz9aJN0+wiPHYaNwNj1o4M6mLpGkcgFFzeyMZkd27Te 5ChXVop6Mqxc8Uq6Q5Us6gDFx7V8TXdyUs6JTESt0xYaEEEAJ5JMMnvVSRM6+vBeKsnJ gU8w== 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=jIp6mvp8h37E4zpDPxkNCd/7y5In34sswn2cpWkjzQI=; b=LwYoNZQU/5yHbmnsKGJ1x3n53aksLBqxGpxwKC44H8KPQY29AN0H0pLtmDE3gCbMDk nYDlb+qLPYD9w3CRtGiXqwN6AGEK3pZ7qZwdpGFMi5b+Huq/qZBNUZDBE0apuS4SArtO WV8F70ytC3hihw+apAshvBd1Rfm2ZecPV249x8A/xB5pXDmy/SOEAFUGOHqwgEi6ijd9 qLI1NBi0uqpdwcQvAFSP2KJBFT+Q4QkBlyBkS73V1nDjYGxZTDaZIjmj+XaTKAZwwHit an4oe+MQD8iV9xdIpqOINXaThwKbKsmzXspf7AuNqSn+U+u3I7CDX3qTxVZ2V34+C+a/ z9RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=APdDJeR3; 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 k1si11441889pfa.25.2019.07.01.14.23.07; Mon, 01 Jul 2019 14:23:08 -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=APdDJeR3; 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 8F1F47E807; Mon, 1 Jul 2019 21:23:05 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by mail.openembedded.org (Postfix) with ESMTP id 5D2B77E7D0 for ; Mon, 1 Jul 2019 21:23:04 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id o101so14683935ota.8 for ; Mon, 01 Jul 2019 14:23:05 -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=ByJSqe5Mc8tbY0a/Dr5mbuQgR+hIRCO4ewhQfk+Otig=; b=APdDJeR3nqB5vUq7ajHoJVY41OSpGGWHGCd98d5Csp+rpcbZO9WySBXBvQA9vTHdPD hIVExTNyfiDPLKuviBAUfibpNKoWACAGi974e1wTkG2OpEaMILel7EtOgjlhwlEZbMuP KcB3TjRmrKYP/E8ETkkWAVy3f1lq13Ags4SR2Z1gmuLDevHG7E3SNAtuxLML5ASNaNtm 5cy5r49sDAmUldqcmkh/sq3B2JxQ+TtAt3Y6zwgVnPS5Tx5ma13R4fXfLQCPI1dRza5P 505iM/ptgoyn4w2Asi5kLP69hDuY/L6B3BRqp+IpLWVGsmL5fBYcrsIS/ao9uPYEEAMl WEqQ== 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=ByJSqe5Mc8tbY0a/Dr5mbuQgR+hIRCO4ewhQfk+Otig=; b=iwkwsuB0R7C1jhXL4vPWdh3YRxZPtAMpDRO8zY+CC5xlD1KIZTGsDdChaTbl+gsrEZ fq9U+qXArZ2ndcyvPSxJf2SCb460sXhCZGHfFG2BFcntNfWJJp7vvbO411LfvL4axIcA cvfrCiVUz4LR6epY3oA5eUWNjXVtSggQBjI1IniOHDtSmjveVHw6T+LL0tHhli8gVPOk YjaC65OpvtsZJwne+iXIc5tgaZ3CH9vVLfd98Ks7vzpiWOpRA/HsJ1tBsjmAEyuwR7y3 ocWNZLASmMt6etqJsmtOtpbo2V8Z2v0humTeSuR5G3cwpCE3hYWR06TmmVA/HrF7Z9Tm cq7A== X-Gm-Message-State: APjAAAU4h6A5XRICN/iYs2NRKS+Yp9V0zkdavY7q5l/5WovLY7uul2ER g9gl/5TI/4FUbh3aeuoXO5r4Mksg9Ro= X-Received: by 2002:a9d:4d0b:: with SMTP id n11mr10346304otf.229.1562016185158; Mon, 01 Jul 2019 14:23:05 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id v203sm4569695oie.5.2019.07.01.14.23.03 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:23:04 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:23:48 -0500 Message-Id: <20190701212350.32503-1-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [OE-core] [PATCHv3 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 Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
--- scripts/runqemu | 50 +++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index 4079f2b17d..38dd1c30d9 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,32 @@ 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) + descriptor = None try: - self.lock_descriptor = open(self.lock, 'w') - fcntl.flock(self.lock_descriptor, fcntl.LOCK_EX|fcntl.LOCK_NB) + descriptor = open(lock, 'w') + fcntl.flock(descriptor, 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 descriptor: + descriptor.close() + descriptor = None return False + self.lock_descriptors[lock] = descriptor 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 +1017,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 +1036,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 +1269,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 +1292,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 Mon Jul 1 21:23:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168229 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3397342ilk; Mon, 1 Jul 2019 14:23:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxeRpOfITqx4JY70dA6j+D3/8XxnIMV6KENI0s9K2eKvjMn7pqayRoFd0mSob3+uVlCNjPp X-Received: by 2002:a17:902:6b07:: with SMTP id o7mr30374162plk.180.1562016192140; Mon, 01 Jul 2019 14:23:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562016192; cv=none; d=google.com; s=arc-20160816; b=CH3za7um5PZm4flj5+gcivwqqRft81Je8va1sUxfSkOf8PqEH0rGlgPpRYGWxzfSPz 26heZFfbgoQvQQ2o5olfNt+xtHVvuc9w9nAtxknumgXxwjoxNqLP26Jjo2WgbkynT2Dx UyIsfXA+P/GfQNYB97EJ+qcg9BKJVQCh4IGarinU+UKgXlA0Y0aIAhbhXGSx7EB+KlMt UTdDbrE3bGnV2ViO9Fuw2EloCPqWsIhCk3UW3pBoxU6ydmzeSbWw488UbblviZV2j9fo ktJ48bTvn9wTSA1d+7CgCBCgzGW96EZM8ks6j3l+wT9BbC4QiQS8iip4otpHWJTg5VXg Divw== 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=7EBkL3E0DcF6rM2UQN7JF+4GeRC0NgvygTFhaqdFUtc=; b=FdRuw3Lid2Oc6OHZVyVphjQZ1DEez9pPMcwTfxz4043wEUhG9LqLl3w1rSLZhoAuTU X2O4Kn6xLTwlFX8wOzzu3CVithfAtQ/byt3RKX7bIv0BK3S+zK2lH3nLdXxNtHGYh+kT Ppq42jasdGkOixXG/FnjzJNfb384PVE5rz3lxt0NhE5dJOC5fXcl+rZGBNvIDAukcg0V aGmoURBZqvz+zpHkF5XAXTRp5wdxjbXEfLlQRG7cyNdbpl0fZjdd6XovfNEaKuIFAkjz /Vu9yqvXm7iykuhQmZBu+u+ouajEDPybaF4gqLIFh8bzdD2U8yXCkn6EjcpErAbQrh47 walQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=JdNg+KMP; 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 p3si10477497plo.185.2019.07.01.14.23.11; Mon, 01 Jul 2019 14:23: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=JdNg+KMP; 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 45EEE7E959; Mon, 1 Jul 2019 21:23:08 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by mail.openembedded.org (Postfix) with ESMTP id 71BC97E7D0 for ; Mon, 1 Jul 2019 21:23:05 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id b7so14949384otl.11 for ; Mon, 01 Jul 2019 14:23:07 -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=23//2jW+dSpQktUrLt6wEsBNrPFr/UFeTd9Q8H4SwbI=; b=JdNg+KMPt0w3b1+BE4CuTat45L9NHJD0u1KrAfWQElvC+CNTXuYHqKCmW0huBbTXjr mYHdVYB9uNKD5P7MNvBdd72XpVUm3Cbl8JgNAaENahznj3kkFR9+3nDMh9vQo7Y0GcKl AckZ1L7wTX8GTVBqPnH2BotJrQ2TyLf7CrQkuFt3eA+jJKvtT6PysLFSQVnTk8j5GESG +9AmsJr/ZxwjEBzkB5xaxgE07sU2fA4K7fL1g5U/PSikVtm2cDzhxiJV1m4mpvIdUwAJ 9JgrNjq8thTR1HcITthcXX/sO1GlZqNzVCXBs96zu6OxeOGU53MLJj4pDcuAjqVN+kwT gtBQ== 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=23//2jW+dSpQktUrLt6wEsBNrPFr/UFeTd9Q8H4SwbI=; b=HqG6wclgMdLlmvxo4Tcp3Pi5fQuQbte/b12RbMbEtZRfnlDg+k8W1ruSfmOArc4qES 2joLRapATva/V5xcylrGG4irUOOYWXeJ8YXwxNIkx+L/j2N48hDdeRXKiGRDo5M9Vw3u 7ubqz+SqOPaJ01A6cRfvfp4EySMrO1zvBI47BTwGJdCMv9WMgKT+E7CBvGnGGA5Lms6m ydUXYkWGQX2NsPTNUD6izi1lp1cBkU7KbZSqxAE0UIeSkFhmtfS0smvzXbgN+4aExQC2 ESKLc5xZQhwGD/9CoDFpk6Li0mh9uDt5mcB4cZcaKCvaRpEwfZbRnNWzo48cQbuBttm7 E/+A== X-Gm-Message-State: APjAAAUEZdlfdX2HdaziY9DnTodeq7xZ3xLhLYVs2/52TJKYhd/JwAGB w0CQrWNGVE8mj35ORSwE2lxa5KREVCM= X-Received: by 2002:a9d:529:: with SMTP id 38mr18211951otw.145.1562016186396; Mon, 01 Jul 2019 14:23:06 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id v203sm4569695oie.5.2019.07.01.14.23.05 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:23:05 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:23:49 -0500 Message-Id: <20190701212350.32503-2-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701212350.32503-1-anibal.limon@linaro.org> References: <20190701212350.32503-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv3 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 38dd1c30d9..2f318e114d 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1006,64 +1006,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': @@ -1289,9 +1306,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 Mon Jul 1 21:23:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168230 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3397412ilk; Mon, 1 Jul 2019 14:23:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjARyEWJFuVSysMd68Cg2mcI8SNv6j9FmhUaPsnXhu+G8UKaCMXBkVX+A9XC2Dj8/9SXFo X-Received: by 2002:a17:902:7043:: with SMTP id h3mr32393002plt.10.1562016198728; Mon, 01 Jul 2019 14:23:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562016198; cv=none; d=google.com; s=arc-20160816; b=V1sIto86idlCrs5NaGLmp4j6eGa0GC7+8Y0sfDHteYsaWG+L8VPo1d9bAvRb7uyTIb kbrrAAj7r8WjjvStghwuPX3mgoCv23epkJNyg1rj8+XoAzpPPJfNN7rqJEhb9Se6sgPT KkDBwGWsEk66uIf+q7jSeLPMaBJ0GNkEo0FbnJoBauwcRWyU0jgS4AcyaZRCrBqlFUPl CCcYmQWYmQYMbJ6M3pJhTCxIU3Qp/Ci+uKUZq1Vp3hZekSU+e7cPvbf2fbEJEoRWBZAO CkxkKKJp+t2riTy6JDaizGzwwmxmmaVHQfy0ZPKlB5yH96cuu5MbIj2Mp/ckPzCM9/Cw vvFw== 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=duafR+Dv7Am+srn7or0D5JQwxlhsOG+M0bDJHcwPgAc=; b=tQL4a0irmP6LlVWH3L8/kzK1sFnbUxyVD0gopp4t+eJNmls6q/spJ/V0Ln2N6Sb18V Ij5zxdgJtvFAnIN17qc2qdkaHrfW83ZL/jbmYLZUBf1iIcph61P1JJgA/kzosxPl5jJa If7zuadVg9h59o5sg+o8bwQdTDDinG0kxImsmGhN2g/XQrwSouxYjxxcGfGv2qF5HpNx /jp3h4aw56pcON/nYZBmfnJDHYIhFeULDPe5odeJWcag4CCg8hMcHj88asSJfnceHLEK bqmYQAQs9vmp6yI6xCiZ1tBbXHvpkpozm5AdYDrM6f4CMtmaUZXybiXKHr4w+wTvz9Bz 3y2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Rpw6NEVe; 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 a6si479477pjo.91.2019.07.01.14.23.18; Mon, 01 Jul 2019 14:23:18 -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=Rpw6NEVe; 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 518AB7E9AD; Mon, 1 Jul 2019 21:23:10 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-oi1-f195.google.com (mail-oi1-f195.google.com [209.85.167.195]) by mail.openembedded.org (Postfix) with ESMTP id D83E97E830 for ; Mon, 1 Jul 2019 21:23:06 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id w196so11197933oie.7 for ; Mon, 01 Jul 2019 14:23:08 -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=sX3n5OlVTOC3e0EaTaApoiad6WeJorg8GqqVIIebXIo=; b=Rpw6NEVehEu4D3YCy1Ixj8Lp5mHLbgX8W1QUNIPw0T8E8yULrmqt6Vu3ByEJdj94mi mUeN/7UpN+WadkXQo8WnMXDCWvcVu0SXsFG/vfNY69RJOvGUnWdMvcSSuO/n/cgvKBOL TL3et/eJXJn/hwB3RNlPOEhf5kCa/Z/M9sJN4qZS/ecMZNAd2A3gUiJKheijnxreJN01 ZJzw5bK4w0BbMuVxNjQI8H1xRW186c8dGsxrbhwXffeUSP3Gx2md8WIKXQd5FlMzHHcf LDx9GJhoffmF0akznFsXjS06NBXtqzeFa12lOVhO4npQX2QK35mT2ZmkQLZzWsgOazoV LApQ== 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=sX3n5OlVTOC3e0EaTaApoiad6WeJorg8GqqVIIebXIo=; b=Rn3/puVMSympTebQi26lYD1S80YT3iaQntX+KkzomMrOukQhf6b+oX82DMonSVEXiY U+po9xUPnou/kZOowYA6kZNb/tRGPpt5BMFQkkVjA/Hiu2VK/DyD7MkKABfWBteQX50l GLqnTsOKBUo8/JKrS1WtNle+T2IYXGm3yr4BrS+AlV9hNu5epLELejq7QMBHrVV+nwQB WCx4IU0uX6hoWesmgD4kx4Bdwrptfjvsa1Z+oUTPtMKngd4KAMLVdheUUxJ6zZMbMUol NdqKmpyzMLYy36wl8pxamc4xvqkVZ9Om5/9WTLimHHht9oTVSe7X7zzTFgjydPZD+FxY /TEw== X-Gm-Message-State: APjAAAUHISuDYVp8qGVCT3Mve/FUmh+dfNXVO/5A8gN1rqptUSjHZsuT 93MNUGMYafE6auBYcltmoAX5t2FgM2Y= X-Received: by 2002:aca:5f03:: with SMTP id t3mr906451oib.18.1562016187600; Mon, 01 Jul 2019 14:23:07 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id v203sm4569695oie.5.2019.07.01.14.23.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:23:07 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:23:50 -0500 Message-Id: <20190701212350.32503-3-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701212350.32503-1-anibal.limon@linaro.org> References: <20190701212350.32503-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv3 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 2f318e114d..ec61edfc46 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1069,10 +1069,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)