diff mbox series

[1/3] runqemu: Allow to store more than one lock for network interfaces

Message ID 20190628033830.27713-1-anibal.limon@linaro.org
State Superseded
Headers show
Series [1/3] runqemu: Allow to store more than one lock for network interfaces | expand

Commit Message

Anibal Limon June 28, 2019, 3:38 a.m. UTC
In order to support multiple tap devices in the same qemu virtual
machine.

Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
---
 scripts/runqemu | 48 ++++++++++++++++++++++++------------------------
 1 file changed, 24 insertions(+), 24 deletions(-)

Comments

Richard Purdie June 30, 2019, 11:41 a.m. UTC | #1
On Thu, 2019-06-27 at 22:38 -0500, Aníbal Limón wrote:
> In order to support multiple tap devices in the same qemu virtual
> machine.
> 
> Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>
> ---

With this change included tests failed on the autobuilder. I think it
breaks usage of tap devices after the first one. E.g.:

https://autobuilder.yoctoproject.org/typhoon/#/builders/59/builds/756

(but testimage failed all over)

Cheers,

Richard
Anibal Limon July 1, 2019, 8:38 p.m. UTC | #2
On Sun, 30 Jun 2019 at 06:41, <richard.purdie@linuxfoundation.org> wrote:

> On Thu, 2019-06-27 at 22:38 -0500, Aníbal Limón wrote:

> > In order to support multiple tap devices in the same qemu virtual

> > machine.

> >

> > Signed-off-by: Aníbal Limón <anibal.limon@linaro.org>

> > ---

>

> With this change included tests failed on the autobuilder. I think it

> breaks usage of tap devices after the first one. E.g.:

>

> https://autobuilder.yoctoproject.org/typhoon/#/builders/59/builds/756

>

> (but testimage failed all over)

>


Ok, I will review the issue and send a v2.

Thanks,
Anibal


>

> Cheers,

>

> Richard

>

>
<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 30 Jun 2019 at 06:41, &lt;<a href="mailto:richard.purdie@linuxfoundation.org">richard.purdie@linuxfoundation.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Thu, 2019-06-27 at 22:38 -0500, Aníbal Limón wrote:<br>
&gt; In order to support multiple tap devices in the same qemu virtual<br>
&gt; machine.<br>
&gt; <br>
&gt; Signed-off-by: Aníbal Limón &lt;<a href="mailto:anibal.limon@linaro.org" target="_blank">anibal.limon@linaro.org</a>&gt;<br>
&gt; ---<br>
<br>
With this change included tests failed on the autobuilder. I think it<br>
breaks usage of tap devices after the first one. E.g.:<br>
<br>
<a href="https://autobuilder.yoctoproject.org/typhoon/#/builders/59/builds/756" rel="noreferrer" target="_blank">https://autobuilder.yoctoproject.org/typhoon/#/builders/59/builds/756</a><br>
<br>
(but testimage failed all over)<br></blockquote><div><br></div><div>Ok, I will review the issue and send a v2.</div><div><br></div><div>Thanks,</div><div>Anibal</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
Cheers,<br>
<br>
Richard<br>
<br>
</blockquote></div></div>
-- 
_______________________________________________
Openembedded-core mailing list
Openembedded-core@lists.openembedded.org
http://lists.openembedded.org/mailman/listinfo/openembedded-core
diff mbox series

Patch

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