From db210bf236c14b2b013c1fe115a5c357b1b1743b Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 20 Jan 2009 14:10:30 -0800 Subject: [PATCH] Add destroy functionality to zpool create, needed for generic use by zpios.sh --- scripts/zpool-config/hda-raid0.cfg | 8 ----- scripts/zpool-config/hda-raid0.sh | 16 +++++++++ scripts/zpool-config/lo-raid0.cfg | 21 ----------- scripts/zpool-config/lo-raid0.sh | 35 +++++++++++++++++++ scripts/zpool-config/sda-raid0.sh | 16 +++++++++ .../{x4550-raid0.cfg => x4550-raid0.sh} | 10 +++++- scripts/zpool-create.sh | 17 +++++++-- 7 files changed, 90 insertions(+), 33 deletions(-) delete mode 100644 scripts/zpool-config/hda-raid0.cfg create mode 100644 scripts/zpool-config/hda-raid0.sh delete mode 100644 scripts/zpool-config/lo-raid0.cfg create mode 100644 scripts/zpool-config/lo-raid0.sh create mode 100644 scripts/zpool-config/sda-raid0.sh rename scripts/zpool-config/{x4550-raid0.cfg => x4550-raid0.sh} (70%) diff --git a/scripts/zpool-config/hda-raid0.cfg b/scripts/zpool-config/hda-raid0.cfg deleted file mode 100644 index 13a55e194c..0000000000 --- a/scripts/zpool-config/hda-raid0.cfg +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# -# Single disk /dev/hda Raid-0 Configuration -# - -DEVICES="/dev/hda" - -${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 diff --git a/scripts/zpool-config/hda-raid0.sh b/scripts/zpool-config/hda-raid0.sh new file mode 100644 index 0000000000..9ddfdb3629 --- /dev/null +++ b/scripts/zpool-config/hda-raid0.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Single disk /dev/hda Raid-0 Configuration +# + +DEVICES="/dev/hda" + +zpool_create() { + msg "${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES}" + ${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 +} + +zpool_destroy() { + msg "${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME}" + ${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME} || exit 1 +} diff --git a/scripts/zpool-config/lo-raid0.cfg b/scripts/zpool-config/lo-raid0.cfg deleted file mode 100644 index 75a411c9b5..0000000000 --- a/scripts/zpool-config/lo-raid0.cfg +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -# -# 5 Device Loopback Raid-0 Configuration -# - -DEVICES="/tmp/zpool-vdev0 \ - /tmp/zpool-vdev1 \ - /tmp/zpool-vdev2 \ - /tmp/zpool-vdev3 \ - /tmp/zpool-vdev4" -DEVICE_SIZE=512 - -for DEV in ${DEVICES}; do - msg "Creating ${DEV} loopback device (${DEVICE_SIZE} Mib)" - rm -f ${DEV} || exit 1 - dd if=/dev/zero of=${DEV} bs=1024k count=${DEVICE_SIZE} &>/dev/null || exit 1 - losetup `/sbin/losetup -f` ${DEV} || exit 1 -done - -${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 - diff --git a/scripts/zpool-config/lo-raid0.sh b/scripts/zpool-config/lo-raid0.sh new file mode 100644 index 0000000000..fb40b15868 --- /dev/null +++ b/scripts/zpool-config/lo-raid0.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# 5 Device Loopback Raid-0 Configuration +# + +DEVICES="/tmp/zpool-vdev0 \ + /tmp/zpool-vdev1 \ + /tmp/zpool-vdev2 \ + /tmp/zpool-vdev3 \ + /tmp/zpool-vdev4" +DEVICE_SIZE=512 + +zpool_create() { + for DEV in ${DEVICES}; do + LO=`/sbin/losetup -f` + msg "Creating ${DEV} using loopback device ${LO}" + rm -f ${DEV} || exit 1 + dd if=/dev/zero of=${DEV} bs=1024k count=${DEVICE_SIZE} &>/dev/null || exit 1 + losetup ${LO} ${DEV} || exit 1 + done + + msg "${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES}" + ${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 +} + +zpool_destroy() { + msg "${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME}" + ${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME} + + for DEV in ${DEVICES}; do + LO=`/sbin/losetup -a | grep ${DEV} | head -n1 | cut -f1 -d:` + msg "Removing ${DEV} using loopback device ${LO}" + rm -f ${DEV} || exit 1 + done +} diff --git a/scripts/zpool-config/sda-raid0.sh b/scripts/zpool-config/sda-raid0.sh new file mode 100644 index 0000000000..aa43b56517 --- /dev/null +++ b/scripts/zpool-config/sda-raid0.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Single disk /dev/sda Raid-0 Configuration +# + +DEVICES="/dev/sda" + +zpool_create() { + msg "${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES}" + ${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 +} + +zpool_destroy() { + msg "${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME}" + ${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME} || exit 1 +} diff --git a/scripts/zpool-config/x4550-raid0.cfg b/scripts/zpool-config/x4550-raid0.sh similarity index 70% rename from scripts/zpool-config/x4550-raid0.cfg rename to scripts/zpool-config/x4550-raid0.sh index 05bbfdf77f..32e608fcef 100644 --- a/scripts/zpool-config/x4550-raid0.cfg +++ b/scripts/zpool-config/x4550-raid0.sh @@ -12,4 +12,12 @@ DEVICES="/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde /dev/sdf \ /dev/sdak /dev/sdal /dev/sdam /dev/sdan /dev/sdao /dev/sdap \ /dev/sdaq /dev/sdar /dev/sdas /dev/sdat /dev/sdau /dev/sdav" -${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 +zpool_create() { + msg "${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES}" + ${CMDDIR}/zpool/zpool create -f ${ZPOOL_NAME} ${DEVICES} || exit 1 +} + +zpool_destroy() { + msg "${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME}" + ${CMDDIR}/zpool/zpool destroy ${ZPOOL_NAME} +} diff --git a/scripts/zpool-create.sh b/scripts/zpool-create.sh index 4b8e3a8bf2..e613e671c8 100755 --- a/scripts/zpool-create.sh +++ b/scripts/zpool-create.sh @@ -14,8 +14,9 @@ DESCRIPTION: OPTIONS: -h Show this message -v Verbose - -c Zpool configuration - -p Zpool name + -c Configuration for zpool + -p Name for zpool + -d Destroy zpool (default create) EOF } @@ -39,8 +40,9 @@ check_config() { ZPOOL_CONFIG=zpool_config.cfg ZPOOL_NAME=tank +ZPOOL_DESTROY= -while getopts 'hvc:p:' OPTION; do +while getopts 'hvc:p:d' OPTION; do case $OPTION in h) usage @@ -55,6 +57,9 @@ while getopts 'hvc:p:' OPTION; do p) ZPOOL_NAME=${OPTARG} ;; + d) + ZPOOL_DESTROY=1 + ;; ?) usage exit @@ -69,6 +74,12 @@ fi check_config || die "${ERROR}" . ${ZPOOL_CONFIG} +if [ ${ZPOOL_DESTROY} ]; then + zpool_destroy +else + zpool_create +fi + if [ ${VERBOSE} ]; then echo echo "zpool list"