From patchwork Mon Jul 1 21:18:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Anibal Limon X-Patchwork-Id: 168225 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3393334ilk; Mon, 1 Jul 2019 14:18:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcXaTtjxul2lnvLH9kB8fJW80KkOfMD9r3rSSL1DOTFM1PrqFBjEBgxvN2AUlU3Wapo/dO X-Received: by 2002:a17:90a:9289:: with SMTP id n9mr1446039pjo.35.1562015893114; Mon, 01 Jul 2019 14:18:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562015893; cv=none; d=google.com; s=arc-20160816; b=AaFxB6iXN6oFkAeqZrFCOwRql1WeUFUkjyE0PrINqNxDH6w2QBDJE2HszX4j6MI7I3 99G1a458byR6rVvebrNpQdnlmMywxh9IRLD2l1AzacjgWmHJVcOEzXXs2eCaQQpdVBYF Uzf+CBHOj5s8Sl8VFlzXKRKXd/+CsbxtYEW65f3jme0xRDhXWdo9IvtEdhgjEuHrhrU5 scF14hEb/v/ESo7irvvwBiqztGdmy8kKnPPvr45MSaaU3ADqtG/uCGXx7ggGNFBu2GkP 0pxS6hweERqnM6pzVcD2LJuYIc0whfxvDct3WZcXQMc698Qo4gh2yf3aznffu0mLgGIF x0zA== 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=gu662iZ/GLSxjA3BFb+XmP9ynptOTcIrKA3JTaJ9gy69T9mVvGHipiecN4X/MYDTpt Q7h2H7UYbybhu6G4HZY3FZDSLRQ3ih3motKtcb020qqmD+c3gzYzmSX8UGMSx9LINVII KzjujdnENarOjrVRlnKNNpG17C3n8H9GaIttDhb2eHRkrs6Un/dExnkDZuLwMuiZtlZR Ic3EZeFze9ANmh/qxiRucXwlcEvaQ/WZEmiZpsPqbrtBWBx1ALol8xIR9EWqSpVeNWhv hytZbmee1T+3+sJ2EU+HdBNVmQmUG4CBMhkjWpdDTjGi1JJCQ/Po1EcrZVX7PQ31gsql 1Wew== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=uXwSaZq9; 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 e13si11285987pfn.24.2019.07.01.14.18.12; Mon, 01 Jul 2019 14:18:13 -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=uXwSaZq9; 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 7E3597D265; Mon, 1 Jul 2019 21:18:08 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-ot1-f68.google.com (mail-ot1-f68.google.com [209.85.210.68]) by mail.openembedded.org (Postfix) with ESMTP id 86C096C149 for ; Mon, 1 Jul 2019 21:18:07 +0000 (UTC) Received: by mail-ot1-f68.google.com with SMTP id o101so14671412ota.8 for ; Mon, 01 Jul 2019 14:18: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:mime-version :content-transfer-encoding; bh=hmeKpZsM5UFB/SVPkYcwh/IiH6jl+9WHQTT+pVcUicM=; b=uXwSaZq9G7scokVTooEpKVk1pOUHc9gcegarj1xiJRFL+3C+AAzKT8kpr3X9+fLppT ea4/A4NAes6qfGe4MLd/muscSU2X9GRrDd+ioFxZjnzzA7vLMykzre82DjjKu+dsPFuZ IS+B/U/Qh7XNK89F+duwzknT6RJ/O1IGooZMl4LOHyUYuNB6XmxtJPWpIx6Fgvdjud9E 4xVsqzOQlPuDkWzeQo3h8jlwua8UMVbJdB4EFwN/0CX2Dpjkp3I+Sc27vGuIoNGPFir+ awNqaq4cSAIbF2raLOSHQQqlVrCTpFJB9bjQcQqcsO09+kEvtXVOza5UxMgNKd4D86nB 0ypA== 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=Z8qf1FqoZvfTTFtBcO3vzoxaIN/Dz74FwO0PpkG9OyEWE4pirf49582G7gE4qJiSBi n7zA6VBX3EVWCuKoOOikFg2xfEyOhqXdqq0MZVsOwNhqBvux/QXCwwiANzahr9o5LYNp 99KuUJBnzLa49PCWngf4a53VGmqeXX7otJrG+clsiIg9q1QRF28JEj/ZICWAYpBxg1+V akYIYxVz92zBPhcoNAnj9alz1Ugep3xGB0TITbAAwFYyHPfjh4jNJcKbNjhsPkbFrvXl zo4D9rvOB+ToeRuwZiriLDr6Y2ZfKFp1+6ymWufcr5Z9xrHPLw+bA4DvoN0+9fOebjT9 sSdg== X-Gm-Message-State: APjAAAX7fRcHy0jI+LBpiHFip9Wkm1IzstOSZifZ5R54j0gCn59Zrpfr aD+ldhR5tAhSRVw8Uyg6jmIIT4zfQSk= X-Received: by 2002:a9d:69ce:: with SMTP id v14mr2876934oto.39.1562015888174; Mon, 01 Jul 2019 14:18:08 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id l15sm4460040otr.38.2019.07.01.14.18.06 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:18:07 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:18:47 -0500 Message-Id: <20190701211849.31989-1-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [OE-core] [PATCHv2 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 Mon Jul 1 21:18: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: 168226 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3393557ilk; Mon, 1 Jul 2019 14:18:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqzMRCgZyOs2+dp2k3qcrpkuhzKN6SwcqNeGCieTYKmtGWPEkvdJ373ooMJGsRO+VFTckqyg X-Received: by 2002:a17:90a:db08:: with SMTP id g8mr1383054pjv.39.1562015910275; Mon, 01 Jul 2019 14:18:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562015910; cv=none; d=google.com; s=arc-20160816; b=rzC7Q9RDbHRWOOS8sgECvnTyk2ekzTXxx5dhYCe4TgzMOuWi9n5oULpdvh+R5y8Dfj EZ8UXF3wxeR0fxoi4jLz1CXBFVA5appPpmn+AtS+siSI0h7E3K4yqQ4voFmXfZsOmKmq Va6cREldN9IKQY+WSB/OIlsw2KpO030gEou47QUJgk5cabmPFWoeeC/ojq+4UxuMe32g dl1Yg89+e8FuXDqkpby4BIyBkX0+Yk61n7cmjrwV2SwA7dGGhZRkh49vPgw8ZaFrNJrq pzLE2MaLn2Wt3T5gt4orfbSYE98iBb8hylYpX/1xBNKMUfRUoRL51+Q2y3WA3mPo+jtZ i5bA== 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=qrEh7mpO2pXwhfFUOp9I4CWxbXO3uNVOtVEyDbFD3Dk=; b=Cz+ATjUKAmedAV5E8BUPGpBATotT7EKfPlcO0av5ydA6ALxZ1IeobUb5ocB5RVcTSo asCgJlc2bnyoKFTWMk0ETZ/IAGT1s9wa9a1LUXPx3hQgUpqyUagsJTPzdsMldlRkP9VN aDSOlAP8yke7xEOl8GAKTv6K+hBz4az1dd9qxvh1fWitrxmR4FKIwBSkgHTa5uzSWGxT WTLWz0zzwV+b+ZSTHEeiIkoldiFfbNIquAi969ynr9U9snvfC5HOWiSmR7imoojrMubx 0nWXX6PB2KDRxDfCqVkKHeG1Ir9zMTCybo+OfuWy5bka+VEMXcMvHpPu2ZUDM28NxR1b bLjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=s5xML8Ub; 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 60si11067561plf.143.2019.07.01.14.18.29; Mon, 01 Jul 2019 14:18:30 -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=s5xML8Ub; 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 40CF07E950; Mon, 1 Jul 2019 21:18:27 +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 14BC07E7BE for ; Mon, 1 Jul 2019 21:18:09 +0000 (UTC) Received: by mail-oi1-f195.google.com with SMTP id w7so11183819oic.3 for ; Mon, 01 Jul 2019 14:18:10 -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=Vf0gJMusTk2tbUWK0PELNxrpSzbGk4Opp3hV66pwCTc=; b=s5xML8UbATV9zux0N9jPKVsn1wRMzFP7HBsXIWOrN/+d0aIWy4Ij7U5OPftmkz0R4R 1RCryTw2Kzt/e6pDYLXNrzODOluj6sr2RjYHWVlq8SMFBHJNe8KIA4YQT0KtUMDMXOTp xGc8EgkvnnT3ecKx7W6FLgYvUyI1V3N4eFAtN8aDqqrXPnbXTbduBDFBBbKFijUGW+vY 0f06YMDTM70azu6qyO4LN+TMaWnhiTktsXW/DZDdvuWlmccV1WHHiXhgMmgoqr7TKKPq 68vMsWAGj2WuQX5eWLcoXJQQsut4MqtHQuhT3YgKpfudsoegfXMe9B1diyf/b5+b7u0m 2NQw== 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=Vf0gJMusTk2tbUWK0PELNxrpSzbGk4Opp3hV66pwCTc=; b=aNCiRSsTpFd4hnsvZJrFOlePQCymtJm3oe9FAXYndnIf2EjrbZahlhA3JbZmFV4Gjv 0Po8jasWIkquPqXazty8wx7M9ueXzs9xEyYwJea5PmF9R9TlwbpeRFRKnQGARwLfxJXV PGjhmHMb2F4DCJXRbTr47VE97/rJ3V0DuProG+lODKtIDYcVyfHRvx3GfLkygggAoHcq DgSW4vXYekOnceiTQbb7cScGgT3sLD4+LC84PZnrzhK4TtJGRnQ4aaENUqRySONzind8 u0okw2JNYWySWL7BzQ9Zh3KpybJMldN9uIc7NCKwcSM1RhLzc52Tcm5lr3AoUy4Px33q elUQ== X-Gm-Message-State: APjAAAXpbs//PmNf6U/U242gG3Br7O1TKSFg8qAzZZjcxibbqAOSY+Kl iOA5DLP2qEW/Au6atVzS1tf6ZaQ0HPM= X-Received: by 2002:aca:ed04:: with SMTP id l4mr931168oih.26.1562015889527; Mon, 01 Jul 2019 14:18:09 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id l15sm4460040otr.38.2019.07.01.14.18.08 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:18:09 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:18:48 -0500 Message-Id: <20190701211849.31989-2-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701211849.31989-1-anibal.limon@linaro.org> References: <20190701211849.31989-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv2 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 | 146 +++++++++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 63 deletions(-) diff --git a/scripts/runqemu b/scripts/runqemu index 8a54c9ef9a..2f318e114d 100755 --- a/scripts/runqemu +++ b/scripts/runqemu @@ -205,19 +205,21 @@ class BaseConfig(object): def acquire_lock(self, lock, error=True): logger.debug("Acquiring lockfile %s..." % lock) + descriptor = None try: - self.lock_descriptors[lock] = open(lock, 'w') - fcntl.flock(self.lock_descriptors[lock], 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" % (lock, e) if error: logger.error(msg) else: logger.info(msg) - if self.lock_descriptors[lock]: - self.lock_descriptor[lock].close() - self.lock_descriptor[lock] = None + if descriptor: + descriptor.close() + descriptor = None return False + self.lock_descriptors[lock] = descriptor return True def release_lock(self, lock): @@ -1004,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': @@ -1287,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:18: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: 168227 Delivered-To: patch@linaro.org Received: by 2002:a92:4782:0:0:0:0:0 with SMTP id e2csp3393634ilk; Mon, 1 Jul 2019 14:18:37 -0700 (PDT) X-Google-Smtp-Source: APXvYqytrMoYubidqMXpcXCsqWkoT6SZ7qyhxHMz3iV8ThA9Cuo2oB15Nhrs53XUrN4Hb6p08ssd X-Received: by 2002:a65:4cc4:: with SMTP id n4mr27746218pgt.307.1562015917067; Mon, 01 Jul 2019 14:18:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562015917; cv=none; d=google.com; s=arc-20160816; b=r+1UDnOCYJ0oFLQTHAxSq1EiZbTCtwa1JJquPWTYnOz2oYV1GYQjERDmWQ0cCG6LGO WJocwaK2Osrz1c29yERj00tP3x7BAuiO5ZTUkPE5GxVqKwzxq35zcZSNIGlz34FV+Bb1 uENLMqEqPpYRg3NCb7HCCDsU0ezGInGsG1HLf/mTL7sTBMdowpr+dKCZnyRdJShYITnD 500TZoVadW8GCBBvQChaOJDR5jd9BuCfQ7BXGHEEnoiwPSkmtQD6mIA0B6fDQhW4P8Th jGUPTIWjv1XlXiq0hJwQwlsCeQggBlUAAYukI314QXY0yWuePCZirVNVvjKueiHm4MUq jCPg== 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=e4rIEL/+yvGI/Y3qsuJn1gQ2JUqRtW11tX3LNWWxHgRGE+a+ezf+k13CulEgDGREs0 DVW0c2cuY/v3blEMyE2o+t1BG1CHGLFS89thgq3ZazTj26ezeCsxVMhhHOom+pSfAl+F xhi4fOSIwfAbenXTw5LISiOKnWJMWFig26illR776ysAMEoD8SFdTv6jMu/85AIk4CZJ rSCQ6cs3lHudBIbs0uEQg6fZHrmH1o/M+u0yo37BfDNMmu3IhTOvmrJQD3/Mwaqk3d3r N71ktBq1RlqXf8TQLTrP80jsoDdAUjwtZGzHYk9EpbV7R9ZMe3SgN+5aeJiGb0b9gdyZ iEPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KDMd+lcI; 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 m11si8049778pfa.0.2019.07.01.14.18.36; Mon, 01 Jul 2019 14:18:37 -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=KDMd+lcI; 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 CF1537E7DE; Mon, 1 Jul 2019 21:18:32 +0000 (UTC) X-Original-To: openembedded-core@lists.openembedded.org Delivered-To: openembedded-core@lists.openembedded.org Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by mail.openembedded.org (Postfix) with ESMTP id 0E9657E7BE for ; Mon, 1 Jul 2019 21:18:09 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id l12so11203122oil.1 for ; Mon, 01 Jul 2019 14:18:11 -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=KDMd+lcIHBJEpqsKHr64p21kT9To9GfB1nO8ecRWpeMXUDUSf+gGGudCyVcsDevFM3 qTMcoHhwER5SucqylTfSlpF9LGyBJCCW5K7/N05zTAalBD5SnHWzGq5RNHsAVRkurloj xkLJiAQ/aFLWd3h3TjA41zE+f2I3pJOQdV+Cp/+iYBp9il8fF2kq4BZbWa4AhP53L/a8 +00Ygg4wx5yoWZ0Z3z4pYT8sXCSmoknrKhsqnWjh66ZMhovAyi7T1zsY0z+iNH8jIqW/ o6kR2x6Za75lbR3/hWfXsecnjY1wzXyKCzb/466LuWTAgzHZU8Oqm2DWP2lN1954kOrM KE/Q== 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=X0faSsbriZ68THduohoGomQArqv0nbajfcHDnIJgkOXB/gW8+z8klU4z5vA0U7aOF4 Vvi+4XqNWiLcnQf2IA4LB28tYLFk0Rtt+TWJd8FEajfHIQ49JATwd/ma96ufy8VzL+hm m6zNL04Bx4DQPcilK7MrTmvyRZbdMs/QChrshfjVWwYe9od8RoF5voLtDWB85k9vQi5u bovKxluofN/+fxE8JvXhyrtY28eHWkob/s6b24eixfMzH9Q7XARBZaGoDJ2bu1/A4ARN JXllU/VszMii5XZE/O1L/vZhPBp4CGWgCaD5HGglOvjXWZMnxmYF5H9tJWR0KK01Gz4/ wQ9g== X-Gm-Message-State: APjAAAUbK/lbJhNl0eWxkvAqbEgSwvaUmxW7UdpHw+BR4Io6Gie2RzoY rMDfgH16jnwSIkntrN2gwkG6yJqw0Co= X-Received: by 2002:aca:4c16:: with SMTP id z22mr905917oia.57.1562015890839; Mon, 01 Jul 2019 14:18:10 -0700 (PDT) Received: from blackbox.Home ([200.68.140.5]) by smtp.gmail.com with ESMTPSA id l15sm4460040otr.38.2019.07.01.14.18.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 01 Jul 2019 14:18:10 -0700 (PDT) From: =?utf-8?b?QW7DrWJhbCBMaW3Ds24=?= To: openembedded-core@lists.openembedded.org Date: Mon, 1 Jul 2019 16:18:49 -0500 Message-Id: <20190701211849.31989-3-anibal.limon@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190701211849.31989-1-anibal.limon@linaro.org> References: <20190701211849.31989-1-anibal.limon@linaro.org> MIME-Version: 1.0 Subject: [OE-core] [PATCHv2 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)