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...")