[PATCH 02/35] fsadm: Add "destroy" command

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This commit adds new command "destroy" which provides the functionality
of removing logical volumes or volume group.

Several fixes for filesystem creation are also involved including fix
for creating extn file system on striped logical volume.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
---
 scripts/fsadm.sh |   67 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 62 insertions(+), 5 deletions(-)

diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
index 42c7da4..2895371 100755
--- a/scripts/fsadm.sh
+++ b/scripts/fsadm.sh
@@ -385,10 +385,14 @@ make_ext() {
 	if [ "$YES" ]; then
 		force="-F"
 	fi
-	stride=$(($stripesize/$bsize))
-	stripewidth=$(($stride*$stripe))
 
-	dry mkfs.$fstyp $force -b$(($bsize*1024)) -E stride=${stride},stripe-width=${stripewidth} $device
+	if [ ! -z $stripesize ]; then
+		stride=$(($stripesize/$bsize))
+		stripewidth=$(($stride*$stripe))
+		extended="-E stride=${stride},stripe-width=${stripewidth}"
+	fi
+
+	dry mkfs.$fstyp $force -b$(($bsize*1024)) $extended $device
 }
 
 generic_make_fs() {
@@ -452,7 +456,7 @@ create() {
 		case $i in
 			"stripesize"* | "chunksize"*) stripesize=${i##*=} ;;
 			"name"*) name="--name ${i##*=}" ;;
-			"fstyp"*) fstyp=${i##*=} ;;
+			"fstyp"* | "fs"*) fstyp=${i##*=} ;;
 			"size"*) size="-L ${i##*=}" ;;
 			*) error "Wrong option $i. (see: $TOOL --help)"
 		esac
@@ -491,7 +495,6 @@ create() {
 	device="/dev/${vgname}/${name}"
 
 	guess=0
-	echo "$fstyp"
 	if [ -z $fstyp ]; then
 		fstyp=$(echo $TOOL | sed 's/^.*\.//g')
 		guess=1
@@ -509,6 +512,59 @@ create() {
 	esac
 }
 
+#############################
+# Remove the logical volume
+# of the whole volume group
+#############################
+destroy() {
+	if [ $# -gt 2 ]; then
+		error "Wrong option for destroy. (see: $TOOL --help)"
+	fi
+
+	# help
+	if [ "$1" == "help" ]; then
+		echo "Usage: $TOOL destroy [mount point | dm device | voulume group]"
+		exit 0
+	fi
+
+	# Block device has been given
+	if [ -b $1 ]; then
+		device=$1
+	fi
+
+	# Mount point has been given
+	if [ -z $device ] && [ -d $1 ]; then
+		mp=$(echo $1 | sed -e 's/\/$//')
+
+		count=$($GREP " $mp " $PROCMOUNTS | wc -l)
+
+		if [ $count -eq 1 ]; then
+			device=$($GREP " $mp " $PROCMOUNTS | cut -d' ' -f1)
+		else
+			count=$(LANG=C $MOUNT | $GREP " $mp " | wc -l)
+			[ $count -ne 1 ] && error "Could not find device mounted at $mp"
+			device=$(LANG=C $MOUNT | $GREP " $mp " | cut -d' ' -f1)
+		fi
+		MOUNTED=$device
+	fi
+
+	if [ -z $device ]; then
+		$LVM vgs $1
+		# Volume group has been given
+		if [ $? -eq 0 ]; then
+			dry $LVM vgremove $FORCE $1
+			return 0
+		fi
+	fi
+
+	[ -z $device ] && error "$1 is not a valid mount point, dm device nor volume group name."
+
+	if [ $MOUNTED ]; then
+		try_umount
+	fi
+	dry $LVM lvremove $FORCE $device
+}
+
 ####################################
 # Calclulate diff between two dates
 #  LANG=C input is expected the
@@ -603,6 +659,7 @@ do
 	  "check") COMMAND=$1; shift; ARGS=$@; break ;;
 	  "resize") COMMAND=$1; shift; ARGS=$@; break ;;
 	  "create") COMMAND=$1; shift; ARGS=$@; break ;;
+	  "destroy") COMMAND=$1; shift; ARGS=$@; break ;;
 	  *) error "Wrong argument \"$1\". (see: $TOOL --help)"
 	esac
 	shift
-- 
1.7.4.4

_______________________________________________
linux-lvm mailing list
linux-lvm@redhat.com
https://www.redhat.com/mailman/listinfo/linux-lvm
read the LVM HOW-TO at http://tldp.org/HOWTO/LVM-HOWTO/


[Index of Archives]     [Gluster Users]     [Kernel Development]     [Linux Clusters]     [Device Mapper]     [Security]     [Bugtraq]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]

  Powered by Linux