From 2d70e6fd914a366329e7d417071a1ac308049520 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Tue, 27 Oct 2009 14:31:31 -0700 Subject: [PATCH] Update scripts to cleanup better when setup failures occur --- scripts/zpool-config/dm0-raid0.sh | 33 +++++++++++++++++------------- scripts/zpool-config/md0-raid10.sh | 22 ++++++++++++-------- scripts/zpool-config/md0-raid5.sh | 22 ++++++++++++-------- 3 files changed, 47 insertions(+), 30 deletions(-) diff --git a/scripts/zpool-config/dm0-raid0.sh b/scripts/zpool-config/dm0-raid0.sh index fa965ac019..89f66e73a8 100644 --- a/scripts/zpool-config/dm0-raid0.sh +++ b/scripts/zpool-config/dm0-raid0.sh @@ -15,10 +15,21 @@ LVCREATE=${LVCREATE:-/sbin/lvcreate} LVREMOVE=${LVREMOVE:-/sbin/lvremove} LVNAME=${LVNAME:-"lv_tank"} LVSTRIPES=${LVSTRIPES:-4} -LVSIZE=${LVSIZE:-4G} +LVSIZE=${LVSIZE:-32G} DEVICES="/dev/${VGNAME}/${LVNAME}" +zpool_dm_destroy() { + msg ${LVREMOVE} -f ${VGNAME}/${LVNAME} + ${LVREMOVE} -f ${VGNAME}/${LVNAME} >/dev/null + + msg ${VGREMOVE} -f ${VGNAME} + ${VGREMOVE} -f ${VGNAME} >/dev/null + + msg ${PVREMOVE} ${PVDEVICES} + ${PVREMOVE} ${PVDEVICES} >/dev/null +} + zpool_create() { # Remove EFI labels which cause pvcreate failure for DEVICE in ${PVDEVICES}; do @@ -26,30 +37,24 @@ zpool_create() { done msg ${PVCREATE} -f ${PVDEVICES} - ${PVCREATE} -f ${PVDEVICES} || exit 1 + ${PVCREATE} -f ${PVDEVICES} >/dev/null || exit 1 msg ${VGCREATE} ${VGNAME} ${PVDEVICES} - ${VGCREATE} ${VGNAME} ${PVDEVICES} || exit 2 + ${VGCREATE} ${VGNAME} ${PVDEVICES} >/dev/null || exit 2 msg ${LVCREATE} --size=${LVSIZE} --stripes=${LVSTRIPES} \ --name=${LVNAME} ${VGNAME} ${LVCREATE} --size=${LVSIZE} --stripes=${LVSTRIPES} \ - --name=${LVNAME} ${VGNAME} || exit 3 + --name=${LVNAME} ${VGNAME} >/dev/null || exit 3 msg ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} - ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} || exit 4 + ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} \ + ${DEVICES} || (zpool_dm_destroy && exit 4) } zpool_destroy() { msg ${ZPOOL} destroy ${ZPOOL_NAME} - ${ZPOOL} destroy ${ZPOOL_NAME} || exit 1 + ${ZPOOL} destroy ${ZPOOL_NAME} - msg ${LVREMOVE} -f ${VGNAME}/${LVNAME} - ${LVREMOVE} -f ${VGNAME}/${LVNAME} || exit 2 - - msg ${VGREMOVE} -f ${VGNAME} - ${VGREMOVE} -f ${VGNAME} || exit 3 - - msg ${PVREMOVE} ${PVDEVICES} - ${PVREMOVE} ${PVDEVICES} || exit 4 + zpool_dm_destroy } diff --git a/scripts/zpool-config/md0-raid10.sh b/scripts/zpool-config/md0-raid10.sh index 4b1a979041..ccc7170153 100644 --- a/scripts/zpool-config/md0-raid10.sh +++ b/scripts/zpool-config/md0-raid10.sh @@ -10,23 +10,29 @@ MDRAID=${MDRAID:-10} DEVICES="/dev/md0" +zpool_md_destroy() { + msg ${MDADM} --manage --stop ${DEVICES} + ${MDADM} --manage --stop ${DEVICES} &>/dev/null + + msg ${MDADM} --zero-superblock ${MDDEVICES} + ${MDADM} --zero-superblock ${MDDEVICES} >/dev/null +} + zpool_create() { msg ${MDADM} --create ${DEVICES} --level=${MDRAID} \ --raid-devices=${MDCOUNT} ${MDDEVICES} ${MDADM} --create ${DEVICES} --level=${MDRAID} \ - --raid-devices=${MDCOUNT} ${MDDEVICES} || exit 1 + --raid-devices=${MDCOUNT} ${MDDEVICES} \ + &>/dev/null || (zpool_md_destroy && exit 1) msg ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} - ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} || exit 2 + ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} \ + ${DEVICES} || (zpool_md_destroy && exit 2) } zpool_destroy() { msg ${ZPOOL} destroy ${ZPOOL_NAME} - ${ZPOOL} destroy ${ZPOOL_NAME} || exit 1 + ${ZPOOL} destroy ${ZPOOL_NAME} - msg ${MDADM} --manage --stop ${DEVICES} - ${MDADM} --manage --stop ${DEVICES} || exit 2 - - msg ${MDADM} --zero-superblock ${MDDEVICES} - ${MDADM} --zero-superblock ${MDDEVICES} || exit 3 + zpool_md_destroy } diff --git a/scripts/zpool-config/md0-raid5.sh b/scripts/zpool-config/md0-raid5.sh index 9bf17181b0..b5b22fe7a1 100644 --- a/scripts/zpool-config/md0-raid5.sh +++ b/scripts/zpool-config/md0-raid5.sh @@ -10,23 +10,29 @@ MDRAID=${MDRAID:-5} DEVICES="/dev/md0" +zpool_md_destroy() { + msg ${MDADM} --manage --stop ${DEVICES} + ${MDADM} --manage --stop ${DEVICES} &>/dev/null + + msg ${MDADM} --zero-superblock ${MDDEVICES} + ${MDADM} --zero-superblock ${MDDEVICES} >/dev/null +} + zpool_create() { msg ${MDADM} --create ${DEVICES} --level=${MDRAID} \ --raid-devices=${MDCOUNT} ${MDDEVICES} ${MDADM} --create ${DEVICES} --level=${MDRAID} \ - --raid-devices=${MDCOUNT} ${MDDEVICES} || exit 1 + --raid-devices=${MDCOUNT} ${MDDEVICES} \ + &>/dev/null || (zpool_md_destroy && exit 1) msg ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} - ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} ${DEVICES} || exit 2 + ${ZPOOL} create ${FORCE_FLAG} ${ZPOOL_NAME} \ + ${DEVICES} || (zpool_md_destroy && exit 2) } zpool_destroy() { msg ${ZPOOL} destroy ${ZPOOL_NAME} - ${ZPOOL} destroy ${ZPOOL_NAME} || exit 1 + ${ZPOOL} destroy ${ZPOOL_NAME} - msg ${MDADM} --manage --stop ${DEVICES} - ${MDADM} --manage --stop ${DEVICES} || exit 2 - - msg ${MDADM} --zero-superblock ${MDDEVICES} - ${MDADM} --zero-superblock ${MDDEVICES} || exit 3 + zpool_md_destroy }