From patchwork Wed Jul 3 17:02:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168432 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1149322ilk; Wed, 3 Jul 2019 10:01:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMaE16zCWCqDYx4UANEukpo4hCz0S1BGj3ZVhuYTWe4DKWivyDzuuZWQYOzwMKI/PlR8OO X-Received: by 2002:a17:90b:d82:: with SMTP id bg2mr14109835pjb.87.1562173302179; Wed, 03 Jul 2019 10:01:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173302; cv=none; d=google.com; s=arc-20160816; b=nDX3PTkLq3eRhTZDpfW9Tgxya2DSuOsO9+3kLRxUxWGZEYnl04wUo1zqrgx/HtCSbl ovbClvGKlvMjb43B0YBZtgovdH+D3fwhkWNbw1UaWfyj+gg3wY4U5b3opFk4xK0bBWZv kjcrOD+tmNzzRIlqk4Re+r5Y6kDtT0sUIA14hMk6UqfHR8rIXjzZnUPhAGICHDEcgQbq /rBmsjaE2gDm41N5V/6yLKvWEp01RoXDcyTmbmNN66+GLdIHZLem17l/Mj1m0HxdqZbN yE7kQySXtk3Tt7Rr3rRvQIKmRJVQiO4ZqXb3os39RyRKcovM/Cv6NPLOXTf0xVtVDeAw Cxbg== 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=pOTpjK1HZaeS0FrEcEHfnuu4ahULypktG9Uk/++oAvudM7AKi4jSxzk/LhzzMOHtZL OnS15UAsopY3/JuvTIJK74WPgAcDT8unu/f1CXvxbMifoQNOqSAFj87UhWQreqfW4z8H 4AxVSSVjH6lTtxvEdY3Q5QEDsaFOTcIA+5L78uIJc3VMEWTzHze9TxnsgISQBYESM01J Sywu8oPEAcckBWuOSVZdxHpjTwqDEjpwDxfDDowL9w4Eb8bVodZWzAFwIk3Mz2ERzcdt /VNSLdU/9Ioczx6hSkYotfkk9gPNVrJcbhGqgYM17ZGlGkvAwuKfs98VXr0X42yampRr 9/vA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=S6KaxAwO; 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 z10si2574978pgv.233.2019.07.03.10.01.41; Wed, 03 Jul 2019 10:01:42 -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=S6KaxAwO; 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 9C66D7E726; Wed, 3 Jul 2019 17:01:39 +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 44F7A7E18C for ; Wed, 3 Jul 2019 17:01:38 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id a93so1568204pla.7 for ; Wed, 03 Jul 2019 10:01:39 -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=S6KaxAwOJbArlIQe2+5aXr+D24ct+ojiGKBuUKLCcnjrS9OlJc6i5GpcPJ4ZiGnxMN FW5s9nd9ewjCKwSteAhPzXfNElfkLYyB51lhd95aSOnW3yNuZ4RmE1rnYl/GVTCJff8N FzwMFmlaF5oeYyWnz5BIooxwOvCUNxjw7UkL8ZlIVOcVZfdtHZ2K79ql1HtRwkIhuxEV qTMfIPUdMJngWqLsYm8pUN5ledC2jwACn4YIZvv3gHbOi+CCnIyrcroQ8QLXPpACCQC2 JIocfLMbf/65WUPPXGRLLT6CgJ9qixsoi4B+VKhZhH9g+RdVt68B6TncS71YFdbsKJVZ nVOQ== 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=n3d8A5WxCB39QtdQpwnVEkPOxW0UrJ5wLchsAMUmuStUzVk90X4Zurj15i23eBUqHV ndWoJLYJDLiYHPzPlqhXhI8OSZvlzgPp28UKtWyqUfXwpy3heYh+jFG4iSmBgtxKg9IG 0GDQBSlUqzjKrIwMro2mokD8GDvvs7YEJQQ1iB5G8CDJrllROhPBAqyFl/5lZyEDHswv BAsFs2Hz9ryVZyB97h/TXuOV4xLyHsJFUjlufhBuLSXp8S2Wn1LIWvxCETgrcGZDaOLb +Dut15rmlcFmL5ONVOpaftSvka4P0bRFcBPxFNHoM38q21lpkv9ihYDnIQ9NMS+HHFY+ Tpzg== X-Gm-Message-State: APjAAAUlEQA8us4Lb8mmcQBXEmReqBbnQQQh2qM5yeQe8Nm5Q1fna5Gm n9V/xj+AZowCFA1qKCgP3jlCFDPvJJSq+A== X-Received: by 2002:a17:902:a411:: with SMTP id p17mr44061222plq.104.1562173299151; Wed, 03 Jul 2019 10:01:39 -0700 (PDT) Received: from blackbox.Home ([200.68.141.206]) by smtp.gmail.com with ESMTPSA id o16sm8417666pgi.36.2019.07.03.10.01.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 10:01:38 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Wed, 3 Jul 2019 12:02:21 -0500 Message-Id: <20190703170223.6228-1-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [OE-core] [PATCHv4 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 | 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 Wed Jul 3 17:02:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168433 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1149485ilk; Wed, 3 Jul 2019 10:01:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqxP5MXAh45+LI9FvBOkAtTLLbF5RN9csb6GgFsQudezwpj/U9euKf+WraMCaidG5fez6Oab X-Received: by 2002:a17:90a:5887:: with SMTP id j7mr13785245pji.136.1562173310974; Wed, 03 Jul 2019 10:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173310; cv=none; d=google.com; s=arc-20160816; b=Rn8uuVEhoziBJ7QYUxo65UD9oni78jxCxtA7C6uuFpw2fF50oIVfQQW9jRR5HV3mCo fspugyiJz9tw9/MMIKmdYJ+B0+KJM3OZcwLqIbEFPb0WBOS3/tEFkOELA+tadKHrdap/ cR8efYMYmXdTBvBzkymdA5uvZjOa/dyXl0XU/3iro+AJj6YDHlgG9TZIqvSHGR7cTr3c fsHIauo29KxUB/hc9Gd91RUClnEfZTbkT6DbeHiRlH2zyBNXhiVURaBZJHd0R/3lEG3n IsN/UMUZPW7uPPpNjeSsmyV5j/marKALCJAO6qpi8r6/cVo/wP8wuWil90WpSl1d1nwU Mccg== 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=9p5P38NhryZx8AsifN7Te/YEMpPAam+EdiqAcj7SA4I=; b=GBjv1eW+oBGkuF2lvpG/52CqSz/BnzVW8TUh/P3gZZg56D/HPhO9eMCwFZYC+Pb4UU 82jrpjBBfa4xjtS+9gPWQZAY7b1vWuE4zg0PFjWDDlC3ndElu7fXCPMEtz2HIlMFYWfE BToKvPFpfPKZLScfLGhQ+qVpcAf0zJtsbZtcGSTKnSpnM8T+H1rITC50ZuUi/IfOFHBC h7dUsxON6UkZ17YklXUf2aczEi5xqrBKS0D3OHgOBzOtq5NBtF9yxxfOoqUudZFTJLWb wc7bZmVBV6H89D+DFpwFYRG7uKZRGf+JyhLRwVZjj6pefMD+xuif2QneQq1dBfqtkXx+ romg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=QOTXdFcg; 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 e7si2908727pfi.130.2019.07.03.10.01.50; Wed, 03 Jul 2019 10:01:50 -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=QOTXdFcg; 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 945357E85B; Wed, 3 Jul 2019 17:01:47 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-pg1-f196.google.com (mail-pg1-f196.google.com [209.85.215.196]) by mail.openembedded.org (Postfix) with ESMTP id ACC747E731 for ; Wed, 3 Jul 2019 17:01:39 +0000 (UTC) Received: by mail-pg1-f196.google.com with SMTP id q4so1543168pgj.8 for ; Wed, 03 Jul 2019 10:01:41 -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=rJG896kltnjF75TKlYg4EvFodN7bcBWcrR6g1+xtyMA=; b=QOTXdFcgB1o9BMYc2Il28gjZnc+lhzX0eMMByB4EstxVTvRU1ZM+RMcmlgVSJz0WDu zhQL2t6xL3ewYnssUppyGaJvs+ERDX0hrLyzwt4yC+ETXFWmnW2nlhxgXOFwI3d5LC8X lMLDCYYDcDOegTyjNfOBAxcCFVlsYidU+fJly7eVS4c0l+4yo4qvwtULdqFYmr6O+2N1 ME97rBKFl8DDaSqeHqzMRZuCij7GQJJLBbi1sSvoT6QOhz9UEuk3v/EWW4qRmcQLiW3W AD1SM/q8BnJCb3pRH+gq/Nk9swmLDbgpZfN+vmXPNs+yHUKMiBF5TLjnSplL/Bxi1e7O 8Wqw== 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=rJG896kltnjF75TKlYg4EvFodN7bcBWcrR6g1+xtyMA=; b=jBT9X57BiNnWzdGjDmGONE0cu09JbSK+CkDHRf4lCFqqqhxmlWJl7LYY3Fh9c2G+1z BGOvGtA7iBhIR/LD6YR9p3y59nx0r0HYAqD+47Q7SYrY851uovIx3z3HtKZzOROMgTws pmchrr+pjq4msWef43BZoqTxr71WC1gXclJPh4IrfLUHkwBV1OdR0qzHiSRHXhRDnK59 +Z3xXEyB5gSWvE/xeTRyaKSW5J+2anFHhuk65olSZptBbQrL/54C3M9EEuRKTajz8kLZ XbqI+klWah2xEYudLoejhR8JDXdn6/U8CY9tGZOiaTnjhGTL9Dd9tEO2qdfCXY7V1i3P Nkkw== X-Gm-Message-State: APjAAAWEf2ppplTPxlWEOVzRVwXmJyhy8IAiSSebXLD3dhHUxpVtxR2G K69sCu6Pt1ORh3b3w8cojMmRCJNLhk7oRQ== X-Received: by 2002:a17:90a:1aa4:: with SMTP id p33mr14085932pjp.27.1562173300625; Wed, 03 Jul 2019 10:01:40 -0700 (PDT) Received: from blackbox.Home ([200.68.141.206]) by smtp.gmail.com with ESMTPSA id o16sm8417666pgi.36.2019.07.03.10.01.39 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 10:01:40 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Wed, 3 Jul 2019 12:02:22 -0500 Message-Id: <20190703170223.6228-2-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703170223.6228-1-anibal.limon@linaro.org> References: <20190703170223.6228-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv4 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 Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
--- scripts/runqemu | 141 ++++++++++++++++++++++++++++-------------------- 1 file changed, 83 insertions(+), 58 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index 38dd1c30d9..0134f86b4c 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1006,64 +1006,88 @@ 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 + + # XXX: Linux qemuarm and qemuppc dosen't configure the interface + # if device is specified in ip (ethN), so if only one tap device is + # requested don't specify ethN. + if tap_no == 1: + 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 + elif 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 +1313,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 Wed Jul 3 17:02:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168434 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp1149602ilk; Wed, 3 Jul 2019 10:01:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqy+CErOQfUhQHOgTdHlCgB3OgzqoPmvtit7mdW+vWQSOwxRib8RGmB03PYoWplaWVVnYvnH X-Received: by 2002:a17:90a:35e6:: with SMTP id r93mr14054572pjb.20.1562173316951; Wed, 03 Jul 2019 10:01:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562173316; cv=none; d=google.com; s=arc-20160816; b=L3+e6EiFHHnevT/mH2pm6vj2DChWBpSKJerK/hn4Mh5NzP3SZvwbuxqquewIkN6ack fIfRQ+b7lwOO9SwyEtB5YOw1LgdM6ChBI5Abxf9C/i9af5MtCtR2Zisi2aSG7uyBXv3r loIqtcVz9OEo/zAQsZORCflvWS2Pv/EUzMv4LHyAUAsNZXf3WdJEXamc+97KO/0U8mxF wlfx9m33beQsk9MhzbcIiYIJp9SrIRudSr+qBtOgNPjw+01VsYopU8WvdbZqy+FbXpqL JgIQS10WkX61sYISisVMU35CwsqH0+traD/3DP5DF6VJ+/GotV4uxSlKV1iUO5H46x5S zpJQ== 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=4BRqVgbaAxNfBe39Tm67bXE/7+dRZKqYtDS4i74V4l0=; b=Kd4mAdx/e5VU8b4TfscQkpLTZ2TewY5vU6wFR6yXh9kReLc96vzGWLPOMspqiRCp0h DkrjzJ3C+6RVFNhAjbw/Xiwuulm77641CHvgXAG68wv1QVVUlFiGMa5KEsypowlb04mK 3JQmcBq3S+bXiRm/cEIBH+3EO0SqVwwIN4fi1vXY2dF0Lfn9oaaxp8cpRnS3+pi/YYt+ mIBbcXeQtls6tCWQ2fUoL/HtNa8P4td+P9hxpqlhq6/UAYPxsP4u1LrmuBgI3VtDvN3s RSr0d5lOEtVRB5Gup8/OzpJKvaAzgt9cCTRrmV5K1EoXCY1UDpZIdj8c2p6Cw3A0X6gB l8Pw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Psswu6Ov; 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 f17si2327758pjq.14.2019.07.03.10.01.56; Wed, 03 Jul 2019 10:01: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=Psswu6Ov; 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 C192A7E951; Wed, 3 Jul 2019 17:01:48 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by mail.openembedded.org (Postfix) with ESMTP id 2C8697E7BF for ; Wed, 3 Jul 2019 17:01:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id c13so1555817pgg.3 for ; Wed, 03 Jul 2019 10:01:42 -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=n3Sf3uxt+HVkwYjGYPFKZ+tUCFFCpaw2GHwQqGsPFPs=; b=Psswu6OvPEqGTZAmIgvCyHvyzN9UoagI2dinuvZAyf5WglNFiXeEGUggRb3cqqbmn/ HJYWfnCvjUiRvXEu3CLMis6sWWxjGWyNMozal2wrLR/zvjEkXJH5aIExvo+EoUO9gk/m p+la7UuCwDbAC1XaGHrlbKQcLOFSe7a+DYDiE/Bk/2Kd4uEVWKyNh9S1qiqk9EMQLQ79 nIKM84UDs6JetkIgIagBFX9qNA/OP4IiUkPDnHMjXnfzRDEIIbyi+zSJUyGF5V/dqUkl oshNJwKbwuyOw7UaxEJiCenNb50t0Tqi7c5Cc5R92q7uhr2quQovLNWcNIi9PMIe/aXr FOLw== 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=n3Sf3uxt+HVkwYjGYPFKZ+tUCFFCpaw2GHwQqGsPFPs=; b=RHcJI1QF7qvpJbnlmd0q77hE+rRTKbJUhNpHHCMpbx2EMhC35mSfDw8s3xbk57BUUM up2VUBAsQOAn0yX2qWn8e/fChnrpag1pvfR+Tpe1eyKPRn0QeoVdo0chWymyePP89h6Y qigtsIV377/tEH0dALBcDdVuTx43psKS3yNfoGxJ7DuJhcZQIFuc3shZsxveOoCvmjyr nLzgZE6K0/CvKv44XjFssSrAthgzpUymYlR49Nase4jEYGTkB0T5Te8LQybrOGHql3m1 lWAv2zysZ8be8ivSj4Bwt7K7iYFdy4uYxD1XgCinkZWoVqwgYkYhKka3+BLz0cgB5lfV +Rcw== X-Gm-Message-State: APjAAAXf/qfdS40++PU+yRRV3I0e5AuZIZoxLReH8kDhWcsDUdFH9xAr ZIqlvR8qk4WekhSzlVZBIEyQ0Pu9LLEHLw== X-Received: by 2002:a17:90a:a410:: with SMTP id y16mr14094019pjp.62.1562173302220; Wed, 03 Jul 2019 10:01:42 -0700 (PDT) Received: from blackbox.Home ([200.68.141.206]) by smtp.gmail.com with ESMTPSA id o16sm8417666pgi.36.2019.07.03.10.01.40 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Wed, 03 Jul 2019 10:01:41 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Wed, 3 Jul 2019 12:02:23 -0500 Message-Id: <20190703170223.6228-3-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190703170223.6228-1-anibal.limon@linaro.org> References: <20190703170223.6228-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv4 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 | 24 +++++++++++++----------- 2 files changed, 16 insertions(+), 11 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 0134f86b4c..10f7296c91 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -1069,17 +1069,19 @@ class BaseConfig(object): gateway = tapnum * 2 + 1 client = gateway + 1 - # XXX: Linux qemuarm and qemuppc dosen't configure the interface - # if device is specified in ip (ethN), so if only one tap device is - # requested don't specify ethN. - if tap_no == 1: - 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 - elif 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': + # XXX: Linux qemuarm and qemuppc dosen't configure the interface + # if device is specified in ip (ethN), so if only one tap device is + # requested don't specify ethN. + if tap_no == 1: + 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 + elif 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)