Skip to contentSkip to conversation

Block script unsafe when starting multiple devices in parallel

PATCH Nathan March 2 participants 2 messages Aug 30, 2011

lore
Share & tools
lore
#0 lore raw

Hi Guys,

Ran into an issue where losetup was failing, added some logging to it's executions to see (first #'s are parent pid / pid):

32435 / 32438 - losetup -f
32436 / 32439 - losetup -f

32435 / 32438 -  Exit code: 0
32435 / 32438 -  Output: /dev/loop/10
32436 / 32439 -  Exit code: 0
32436 / 32439 -  Output: /dev/loop/10

32128 / 32451 - losetup /dev/loop/10 /mnt/xenDisks2/nathanxen2/backup_tmp 31934 / 32452 - losetup /dev/loop/10 /mnt/xenDisks1/nathanxen2/swap

Sometime's losetup seems to be stuck waiting on something else and since multiple block devices are brought up in parallel, the block script tries to use the same name for multiple loopback devices.

Fix for this is pretty straightforward - should just be letting losetup figure out the device names itself, patch is attached.

- Nathan

Signature · 3 lines
Nathan March<[email protected]>
Gossamer Threads Inc. http://www.gossamer-threads.com/
Tel: (604) 687-5804 Fax: (604) 687-5806
block renamed from block.orig +12 -7
@@ -292,12 +292,12 @@
           done
         fi
 
-        loopdev=$(losetup -f 2>/dev/null || find_free_loopback_dev)
-        if [ "$loopdev" = '' ]
-        then
-          release_lock "block"
-          fatal 'Failed to find an unused loop device'
-        fi
+        #loopdev=$(losetup -f 2>/dev/null || find_free_loopback_dev)
+        #if [ "$loopdev" = '' ]
+        #then
+        #  release_lock "block"
+        #  fatal 'Failed to find an unused loop device'
+        #fi
 
         if LANG=C losetup -h 2>&1 | grep read-only >/dev/null
         then
@@ -305,7 +305,12 @@
         else
           roflag=''
         fi
-        do_or_die losetup $roflag "$loopdev" "$file"
+
+        loopdev=$(losetup -f "$file" --show)
+        if [[ $? -ne 0 ]]; then
+            fatal "Unable to bring up $file - $loopdev"
+        fi;
+        #do_or_die losetup $roflag "$loopdev" "$file"
         xenstore_write "$XENBUS_PATH/node" "$loopdev"
         write_dev "$loopdev"
         release_lock "block"

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw
Quoted 11 lines · Nathan March

Hi Guys,

Ran into an issue where losetup was failing, added some logging to it's executions to see (first #'s are parent pid / pid):

32435 / 32438 - losetup -f
32436 / 32439 - losetup -f

32435 / 32438 -  Exit code: 0
32435 / 32438 -  Output: /dev/loop/10
32436 / 32439 -  Exit code: 0
32436 / 32439 -  Output: /dev/loop/10
Quoted 6 lines

32128 / 32451 - losetup /dev/loop/10 /mnt/xenDisks2/nathanxen2/backup_tmp 31934 / 32452 - losetup /dev/loop/10 /mnt/xenDisks1/nathanxen2/swap

Sometime's losetup seems to be stuck waiting on something else and since multiple block devices are brought up in parallel, the block script tries to use the same name for multiple loopback devices.

This should be prevented by locking mechanism (claim_lock / release_lock), but it isn't working in some cases
(http://lists.xensource.com/archives/html/xen-devel/2011-07/msg00182.html).

I've workarounded it with wrapping this script with flock (in udev rules).

Perhaps it can be done in tools/hotplug/Linux/xen-backend.rules instead of using claim_lock/release_lock? This is much simpler than restructuring all hotplug scripts...

Signature · 3 lines
Pozdrawiam / Best Regards,
Marek Marczykowski         | RLU #390519
marmarek at mimuw edu pl   | xmpp:marmarek at staszic waw pl

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel