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)