#!/bin/sh
#
# Free up a disk - detach the plexes, subdisks and kill them,
# then remove the physical disk completely from VxVM.
#

[ $# -ne 1 ] && {
  echo "
	USAGE: $0 VXDISK_NAME

		VXDISK_NAME   -  vx disk to free up
  "
  exit 1
}

TRGDISK=$1

vxprint -g rootdg

vxprint -s | grep "^sd ${TRGDISK}-" | sort -u |\
 while read TYPE SUBDISK PLEX STATE LEN REST ; do
  vxplex -o force dis $PLEX
  vxsd   dis $SUBDISK
  vxedit rm $SUBDISK
  vxedit rm $PLEX
done

vxedit rm rootdiskPriv 2>&-
vxdg rmdisk $TRGDISK

echo
vxprint -g rootdg
