2017-12-19 11:40:00 +01:00
|
|
|
From 0e1c896caaabdf0de38466951ea281f02fe8bb77 Mon Sep 17 00:00:00 2001
|
2017-07-04 14:31:34 +02:00
|
|
|
From: Eric Ren <zren@suse.com>
|
2017-07-07 07:24:39 +02:00
|
|
|
Date: Thu, 6 Jul 2017 17:42:58 +0800
|
2017-08-07 09:53:46 +02:00
|
|
|
Subject: [PATCH] fsadm: add support for btrfs
|
2015-04-09 10:27:21 +02:00
|
|
|
|
|
|
|
Check: mount the device first and then run`btrfs filesystem scrub start
|
|
|
|
-B` command
|
|
|
|
Reisze: find the mount point first and resize the filesystem after get
|
|
|
|
the device id since there are maybe several devices underneath btrfs
|
|
|
|
filesystem
|
|
|
|
---
|
2017-11-24 12:13:44 +01:00
|
|
|
scripts/fsadm.sh | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
|
|
|
|
1 file changed, 72 insertions(+), 3 deletions(-)
|
2015-04-09 10:27:21 +02:00
|
|
|
|
2017-07-04 14:31:34 +02:00
|
|
|
diff --git a/scripts/fsadm.sh b/scripts/fsadm.sh
|
2017-12-19 11:40:00 +01:00
|
|
|
index a09b91534..2a29d5ad5 100755
|
2017-07-04 14:31:34 +02:00
|
|
|
--- a/scripts/fsadm.sh
|
|
|
|
+++ b/scripts/fsadm.sh
|
2015-04-09 10:27:21 +02:00
|
|
|
@@ -22,6 +22,7 @@
|
|
|
|
# ext2/ext3/ext4: resize2fs, tune2fs
|
|
|
|
# reiserfs: resize_reiserfs, reiserfstune
|
|
|
|
# xfs: xfs_growfs, xfs_info
|
|
|
|
+# btrfs: btrfs
|
|
|
|
#
|
|
|
|
# Return values:
|
|
|
|
# 0 success
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -57,6 +58,7 @@ XFS_CHECK=xfs_check
|
2015-04-09 10:27:21 +02:00
|
|
|
# XFS_REPAIR -n is used when XFS_CHECK is not found
|
|
|
|
XFS_REPAIR=xfs_repair
|
2017-11-24 12:13:44 +01:00
|
|
|
CRYPTSETUP=cryptsetup
|
2015-04-09 10:27:21 +02:00
|
|
|
+BTRFS=btrfs
|
|
|
|
|
|
|
|
# user may override lvm location by setting LVM_BINARY
|
|
|
|
LVM=${LVM_BINARY:-lvm}
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -76,6 +78,9 @@ BLOCKCOUNT=
|
2015-04-09 10:27:21 +02:00
|
|
|
MOUNTPOINT=
|
|
|
|
MOUNTED=
|
|
|
|
REMOUNT=
|
|
|
|
+FINDMNT=
|
|
|
|
+UUID=
|
|
|
|
+BTRFS_DEVID=
|
2017-07-04 14:31:34 +02:00
|
|
|
PROCDIR="/proc"
|
|
|
|
PROCMOUNTS="$PROCDIR/mounts"
|
|
|
|
PROCSELFMOUNTINFO="$PROCDIR/self/mountinfo"
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -227,6 +232,33 @@ detect_fs() {
|
2017-07-04 14:31:34 +02:00
|
|
|
verbose "\"$FSTYPE\" filesystem found on \"$VOLUME\"."
|
2015-04-09 10:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+check_findmnt() {
|
|
|
|
+ FINDMNT=$(which findmnt 2>$NULL)
|
|
|
|
+ test -n "$FINDMNT"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+detect_fs_uuid() {
|
|
|
|
+ UUID=$($BLKID -o value -c $NULL -s UUID "$VOLUME" 2>$NULL)
|
|
|
|
+ test -n "$UUID"
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#find the mountpoint of this device
|
|
|
|
+detect_mounted_findmnt() {
|
|
|
|
+ local TMP
|
|
|
|
+ local STR_IFS=$IFS
|
|
|
|
+ IFS=" $(echo -n -e '\t')"
|
|
|
|
+
|
|
|
|
+ read -r TMP<<EOF
|
|
|
|
+$($FINDMNT -nuP -o TARGET,UUID 2>$NULL | $GREP "$UUID")
|
|
|
|
+EOF
|
|
|
|
+
|
|
|
|
+ TMP=${TMP##*TARGET=\"}
|
|
|
|
+ TMP=${TMP%%\"*}
|
|
|
|
+ MOUNTED=$TMP
|
|
|
|
+ test -n "$MOUNTED"
|
|
|
|
+
|
|
|
|
+ IFS=$STR_IFS
|
|
|
|
+}
|
2017-07-04 14:31:34 +02:00
|
|
|
|
|
|
|
# Check that passed mounted MAJOR:MINOR is not matching $MAJOR:MINOR of resized $VOLUME
|
|
|
|
validate_mounted_major_minor() {
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -354,8 +386,12 @@ detect_mounted_with_proc_mounts() {
|
2016-05-11 05:42:15 +02:00
|
|
|
|
2015-04-09 10:27:21 +02:00
|
|
|
# check if the given device is already mounted and where
|
|
|
|
# FIXME: resolve swap usage and device stacking
|
2017-07-04 14:31:34 +02:00
|
|
|
-detect_mounted() {
|
2016-05-11 05:42:15 +02:00
|
|
|
- if test -e "$PROCSELFMOUNTINFO"; then
|
2017-07-04 14:31:34 +02:00
|
|
|
+detect_mounted() {
|
2015-04-09 10:27:21 +02:00
|
|
|
+ if test "$FSTYPE" = "btrfs" ; then
|
|
|
|
+ check_findmnt || error "Need 'findmnt' utility to work with btrfs filesystem"
|
|
|
|
+ detect_fs_uuid || verbose "Can't get fs UUID from \"$VOLUME\" volume"
|
|
|
|
+ detect_mounted_findmnt
|
2016-05-11 05:42:15 +02:00
|
|
|
+ elif test -e "$PROCSELFMOUNTINFO"; then
|
|
|
|
detect_mounted_with_proc_self_mountinfo
|
|
|
|
elif test -e "$PROCMOUNTS"; then
|
|
|
|
detect_mounted_with_proc_mounts
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -654,6 +690,32 @@ resize_crypt() {
|
2017-12-19 11:40:00 +01:00
|
|
|
dry "$CRYPTSETUP" resize "$1" --size $CRYPT_RESIZE_BLOCKS || error "$CRYPTSETUP failed to resize device $1"
|
2015-04-09 10:27:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+########################
|
|
|
|
+# Resize btrfs filesystem
|
|
|
|
+# - mounted for upsize/downsize
|
2016-05-11 05:42:15 +02:00
|
|
|
+# - cannot resize when unmounted
|
2015-04-09 10:27:21 +02:00
|
|
|
+########################
|
|
|
|
+resize_btrfs() {
|
|
|
|
+ detect_mounted
|
|
|
|
+ MOUNTPOINT=$MOUNTED
|
|
|
|
+ if [ -z "$MOUNTED" ]; then
|
|
|
|
+ MOUNTPOINT=$TEMPDIR
|
|
|
|
+ temp_mount || error "Cannot mount Btrfs filesystem"
|
|
|
|
+ fi
|
|
|
|
+
|
|
|
|
+ verbose "Parsing $BTRFS filesystem show \"$MOUNTPOINT\""
|
|
|
|
+ for i in $(LC_ALL=C "$BTRFS" filesystem show "$MOUNTPOINT"); do
|
|
|
|
+ case "$i" in
|
|
|
|
+ *"$VOLUME"*) BTRFS_DEVID=${i##*devid};;
|
|
|
|
+ esac
|
|
|
|
+ done
|
|
|
|
+ BTRFS_DEVID=${BTRFS_DEVID%%size*}
|
|
|
|
+ BTRFS_DEVID=$(echo $BTRFS_DEVID|sed 's/^[ \t]*//g'|sed 's/[ \t]*$'//g)
|
|
|
|
+ decode_size $1 1
|
|
|
|
+ verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE bytes(btrfs devid: $BTRFS_DEVID) "
|
|
|
|
+ dry "$BTRFS" filesystem resize "$BTRFS_DEVID":"$NEWSIZE" "$MOUNTPOINT"
|
|
|
|
+}
|
2017-11-24 12:13:44 +01:00
|
|
|
+
|
2015-04-09 10:27:21 +02:00
|
|
|
####################
|
|
|
|
# Resize filesystem
|
|
|
|
####################
|
2017-11-24 12:13:44 +01:00
|
|
|
@@ -676,6 +738,7 @@ resize() {
|
|
|
|
"crypto_LUKS")
|
2017-12-19 11:40:00 +01:00
|
|
|
which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required to resize LUKS volume"
|
2017-11-24 12:13:44 +01:00
|
|
|
resize_luks $NEWSIZE ;;
|
2015-04-09 10:27:21 +02:00
|
|
|
+ "btrfs") resize_btrfs $NEWSIZE ;;
|
2017-07-04 14:31:34 +02:00
|
|
|
*) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
|
|
|
|
esac || error "Resize $FSTYPE failed."
|
2017-11-24 12:13:44 +01:00
|
|
|
test -z "$CRYPT_SHRINK" || resize_crypt "$VOLUME_ORIG"
|
|
|
|
@@ -748,6 +811,12 @@ check() {
|
|
|
|
"crypto_LUKS")
|
2017-12-19 11:40:00 +01:00
|
|
|
which "$CRYPTSETUP" > /dev/null 2>&1 || error "$CRYPTSETUP utility required."
|
2017-11-24 12:13:44 +01:00
|
|
|
check_luks ;;
|
2015-04-09 10:27:21 +02:00
|
|
|
+ "btrfs") #mount the device first and then run scrub
|
|
|
|
+ MOUNTPOINT=$TEMPDIR
|
|
|
|
+ temp_mount || error "Cannot mount btrfs filesystem"
|
|
|
|
+ dry "$BTRFS" scrub start -B "$VOLUME"
|
|
|
|
+ test "$MOUNTPOINT" = "$TEMPDIR" && MOUNTPOINT="" temp_umount
|
|
|
|
+ ;;
|
2017-11-24 12:13:44 +01:00
|
|
|
*)
|
|
|
|
error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool." ;;
|
|
|
|
esac
|
|
|
|
@@ -766,7 +835,7 @@ test -n "$FSADM_RUNNING" && exit 0
|
2015-04-09 10:27:21 +02:00
|
|
|
for i in "$TUNE_EXT" "$RESIZE_EXT" "$TUNE_REISER" "$RESIZE_REISER" \
|
|
|
|
"$TUNE_XFS" "$RESIZE_XFS" "$MOUNT" "$UMOUNT" "$MKDIR" \
|
|
|
|
"$RMDIR" "$BLOCKDEV" "$BLKID" "$GREP" "$READLINK" \
|
|
|
|
- "$DATE" "$FSCK" "$XFS_CHECK" "$XFS_REPAIR" "$LVM" ; do
|
2016-05-11 05:42:15 +02:00
|
|
|
+ "$DATE" "$FSCK" "$XFS_CHECK" "$XFS_REPAIR" "$LVM" "$BTRFS" ; do
|
2015-04-09 10:27:21 +02:00
|
|
|
test -n "$i" || error "Required command definitions in the script are missing!"
|
|
|
|
done
|
|
|
|
|
2017-07-04 14:31:34 +02:00
|
|
|
--
|
2017-12-19 11:40:00 +01:00
|
|
|
2.13.6
|
2017-07-04 14:31:34 +02:00
|
|
|
|