From b9c3c7a2f462febcbfdc6d8c0bc19be6ac6350c0 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 21 Jul 2009 16:17:54 -0700 Subject: [PATCH] The losetup -f option is unavailable for SLES10 use unused_loop_device() SLES10 ships util-linux-2.12r-35.30 which does not support the -f option to losetup. To avoid this problem the unused_loop_device() function was added which attempts to find an unused loop device by checking each /dev/loop* device with losetup to see if it is configured. --- scripts/common.sh | 12 ++++++++++++ scripts/zpool-config/lo-raid0.sh | 2 +- scripts/zpool-config/lo-raid10.sh | 2 +- scripts/zpool-config/lo-raidz.sh | 2 +- scripts/zpool-config/lo-raidz2.sh | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/scripts/common.sh b/scripts/common.sh index fdb9b947c5..6e19bbf83d 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -143,3 +143,15 @@ unload_modules() { return 0 } + +unused_loop_device() { + for DEVICE in `ls -1 /dev/loop*`; do + losetup $DEVICE &>/dev/null + if [ $? -ne 0 ]; then + echo $DEVICE + return + fi + done + + die "Error: Unable to find unused loopback device" +} diff --git a/scripts/zpool-config/lo-raid0.sh b/scripts/zpool-config/lo-raid0.sh index 84c355266c..36b3c4d62f 100644 --- a/scripts/zpool-config/lo-raid0.sh +++ b/scripts/zpool-config/lo-raid0.sh @@ -11,7 +11,7 @@ DEVICES="" zpool_create() { for FILE in ${FILES}; do - DEVICE=`/sbin/losetup -f` + DEVICE=`unused_loop_device` msg "Creating ${FILE} using loopback device ${DEVICE}" rm -f ${FILE} || exit 1 dd if=/dev/zero of=${FILE} bs=1024k count=256 &>/dev/null || diff --git a/scripts/zpool-config/lo-raid10.sh b/scripts/zpool-config/lo-raid10.sh index 78004cc545..ce528004c7 100644 --- a/scripts/zpool-config/lo-raid10.sh +++ b/scripts/zpool-config/lo-raid10.sh @@ -13,7 +13,7 @@ DEVICES_M2="" zpool_create() { for FILE in ${FILES_M1}; do - DEVICE=`/sbin/losetup -f` + DEVICE=`unused_loop_device` msg "Creating ${FILE} using loopback device ${DEVICE}" rm -f ${FILE} || exit 1 dd if=/dev/zero of=${FILE} bs=1024k count=256 &>/dev/null || diff --git a/scripts/zpool-config/lo-raidz.sh b/scripts/zpool-config/lo-raidz.sh index cac9036464..616c364bed 100644 --- a/scripts/zpool-config/lo-raidz.sh +++ b/scripts/zpool-config/lo-raidz.sh @@ -11,7 +11,7 @@ DEVICES="" zpool_create() { for FILE in ${FILES}; do - DEVICE=`/sbin/losetup -f` + DEVICE=`unused_loop_device` msg "Creating ${FILE} using loopback device ${DEVICE}" rm -f ${FILE} || exit 1 dd if=/dev/zero of=${FILE} bs=1024k count=256 &>/dev/null || diff --git a/scripts/zpool-config/lo-raidz2.sh b/scripts/zpool-config/lo-raidz2.sh index bd9a40ce58..dbd7d815eb 100644 --- a/scripts/zpool-config/lo-raidz2.sh +++ b/scripts/zpool-config/lo-raidz2.sh @@ -11,7 +11,7 @@ DEVICES="" zpool_create() { for FILE in ${FILES}; do - DEVICE=`/sbin/losetup -f` + DEVICE=`unused_loop_device` msg "Creating ${FILE} using loopback device ${DEVICE}" rm -f ${FILE} || exit 1 dd if=/dev/zero of=${FILE} bs=1024k count=256 &>/dev/null ||