[elbe-devel] [PATCH] fstab: Fix issue #254

Olivier Dion dion at linutronix.de
Tue Mar 24 00:35:06 CET 2020


See <https://github.com/Linutronix/elbe/issues/254>.

Before setting up a loop device, poll it to see if it's busy and wait
until it's not.

Signed-off-by: Olivier Dion <dion at linutronix.de>
---
 elbepack/fstab.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/elbepack/fstab.py b/elbepack/fstab.py
index 94f11d2f..3d9fd112 100644
--- a/elbepack/fstab.py
+++ b/elbepack/fstab.py
@@ -6,8 +6,10 @@
 # SPDX-License-Identifier: GPL-3.0-or-later
 
 import os
+import time
+import logging
 
-from elbepack.shellhelper import do
+from elbepack.shellhelper import do, get_command_out
 
 
 def get_mtdnum(xml, label):
@@ -141,6 +143,16 @@ class fstabentry(object):
         self.number = '{}{}'.format(disk.type, ppart.number)
 
     def losetup(self, loopdev):
+        while True:
+            is_busy = get_command_out("losetup -l /dev/%s -n --raw | "
+                                      "cut -d' ' -f6" % loopdev)
+
+            if is_busy == "\n" or is_busy == "":
+                break
+
+            time.sleep(0.1)
+            logging.warning("Device /dev/%s is busy .. retrying", loopdev)
+
         do('losetup -o%d --sizelimit %d /dev/%s "%s"' %
            (self.offset, self.size, loopdev, self.filename))
 
-- 
2.25.1




More information about the elbe-devel mailing list