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