aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2009-01-20 14:10:30 -0800
committerBrian Behlendorf <[email protected]>2009-01-20 14:10:30 -0800
commitdb210bf236c14b2b013c1fe115a5c357b1b1743b (patch)
treef40a786c5d4c348098fbd9db345a65a6a686d648 /scripts
parent5bf49743a6e0f1c79606da6af3ed00bc7629b8f3 (diff)
Add destroy functionality to zpool create, needed for generic use by zpios.sh
Diffstat (limited to 'scripts')
-rw-r--r--scripts/zpool-config/hda-raid0.cfg8
-rw-r--r--scripts/zpool-config/hda-raid0.sh16
-rw-r--r--scripts/zpool-config/lo-raid0.cfg21
-rw-r--r--scripts/zpool-config/lo-raid0.sh35
-rw-r--r--scripts/zpool-config/sda-raid0.sh16
-rw-r--r--scripts/zpool-config/x4550-raid0.sh (renamed from scripts/zpool-config/x4550-raid0.cfg)10
-rwxr-xr-xscripts/zpool-create.sh17
7 files changed, 90 insertions, 33 deletions
diff --git a/scripts/zpool-config/hda-raid0.cfg b/scripts/zpool-config/hda-raid0.cfg
deleted file mode 100644
index 13a55e194..000000000
--- 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 000000000..9ddfdb362
--- /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 75a411c9b..000000000
--- 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 000000000..fb40b1586
--- /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 000000000..aa43b5651
--- /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
index 05bbfdf77..32e608fce 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 4b8e3a8bf..e613e671c 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"