fsadm: add support for btrfs
PATCH 1/1 fsadm: add support for btrfs
Run btrfs check to check filesystem
Run btrfs filesystem show to get the filesystem size and btrfs filesystem resize to resize.
--- scripts/fsadm.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-)
scripts/fsadm.sh +47 -13
@@ -22,6 +22,7 @@ # ext2/ext3/ext4: resize2fs, tune2fs # reiserfs: resize_reiserfs, reiserfstune # xfs: xfs_growfs, xfs_info +# btrfs: btrfs # # Return values: # 0 success
@@ -56,6 +57,7 @@ FSCK=fsck XFS_CHECK=xfs_check # XFS_REPAIR -n is used when XFS_CHECK is not found XFS_REPAIR=xfs_repair +BTRFS=btrfs # user may override lvm location by setting LVM_BINARY LVM=${LVM_BINARY:-lvm}
@@ -72,6 +74,7 @@ TEMPDIR="${TMPDIR:-/tmp}/${TOOL}_${RANDOM}$$/m" DM_DEV_DIR="${DM_DEV_DIR:-/dev}" BLOCKSIZE= BLOCKCOUNT= +OLDSIZE= MOUNTPOINT= MOUNTED= REMOUNT=
@@ -157,18 +160,20 @@ cleanup() { # convert parameter from Exa/Peta/Tera/Giga/Mega/Kilo/Bytes and blocks # (2^(60/50/40/30/20/10/0)) decode_size() { - case "$1" in - *[eE]) NEWSIZE=$(( ${1%[eE]} * 1152921504606846976 )) ;; - *[pP]) NEWSIZE=$(( ${1%[pP]} * 1125899906842624 )) ;; - *[tT]) NEWSIZE=$(( ${1%[tT]} * 1099511627776 )) ;; - *[gG]) NEWSIZE=$(( ${1%[gG]} * 1073741824 )) ;; - *[mM]) NEWSIZE=$(( ${1%[mM]} * 1048576 )) ;; - *[kK]) NEWSIZE=$(( ${1%[kK]} * 1024 )) ;; - *[bB]) NEWSIZE=${1%[bB]} ;; - *) NEWSIZE=$(( $1 * $2 )) ;; - esac - #NEWBLOCKCOUNT=$(round_block_size $NEWSIZE $2) - NEWBLOCKCOUNT=$(( $NEWSIZE / $2 )) + if [ -n "$1" -a -n "$2" ]; then + case "$1" in + *[eE]) NEWSIZE=$(( ${1%[eE]} * 1152921504606846976 )) ;; + *[pP]) NEWSIZE=$(( ${1%[pP]} * 1125899906842624 )) ;; + *[tT]) NEWSIZE=$(( ${1%[tT]} * 1099511627776 )) ;; + *[gG]) NEWSIZE=$(( ${1%[gG]} * 1073741824 )) ;; + *[mM]) NEWSIZE=$(( ${1%[mM]} * 1048576 )) ;; + *[kK]) NEWSIZE=$(( ${1%[kK]} * 1024 )) ;; + *[bB]) NEWSIZE=${1%[bB]} ;; + *) NEWSIZE=$(( $1 * $2 )) ;; + esac + #NEWBLOCKCOUNT=$(round_block_size $NEWSIZE $2) + NEWBLOCKCOUNT=$(( $NEWSIZE / $2 )) + fi if [ $DO_LVRESIZE -eq 1 ]; then # start lvresize, but first cleanup mounted dirs
@@ -368,6 +373,30 @@ resize_xfs() { fi } +######################## +# Resize btrfs filesystem +# - mounted for upsize/downsize +# - cannot resize when unmounted +######################## +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 + *"size"*) OLDSIZE=${i##*size};; + esac + done + OLDSIZE=${OLDSIZE%%used*} + decode_size $1 + verbose "Resizing filesystem on device \"$VOLUME\" to $NEWSIZE bytes from $OLDSIZE bytes" + dry "$BTRFS" filesystem resize $NEWSIZE "$MOUNTPOINT" +} #################### # Resize filesystem ####################
@@ -384,6 +413,7 @@ resize() { "ext3"|"ext2"|"ext4") resize_ext $NEWSIZE ;; "reiserfs") resize_reiser $NEWSIZE ;; "xfs") resize_xfs $NEWSIZE ;; + "btrfs") resize_btrfs $NEWSIZE ;; *) error "Filesystem \"$FSTYPE\" on device \"$VOLUME\" is not supported by this tool" ;; esac || error "Resize $FSTYPE failed" cleanup 0
@@ -441,6 +471,10 @@ check() { # Think about better way.... dry "$XFS_REPAIR" -n -o force_geometry "$VOLUME" fi ;; + "btrfs") if which "$BTRFS" > "$NULL" 2>&1 ; then + dry "$BTRFS" check "$VOLUME" + fi + ;; *) # check if executed from interactive shell environment case "$-" in *i*) dry "$FSCK" $YES $FORCE "$VOLUME" ;;
@@ -462,7 +496,7 @@ test -n "$FSADM_RUNNING" && exit 0 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 + "$DATE" "$FSCK" "$XFS_CHECK" "$XFS_REPAIR" "$LVM" "$BTRFS"; do test -n "$i" || error "Required command definitions in the script are missing!" done
Signature · 1 line
1.8.1.4
PATCH 1/1 fsadm: add support for btrfs
Quoted 4 lines · Lidong Zhong
Run
btrfs checkto check filesystem
Runbtrfs filesystem showto get the filesystem size andbtrfs filesystem resizeto resize.
Hi,
thank you for the patch but I'm afraid it is not correct. For example it doesn't seem to deal with the possibility of btrfs volume spanning across multiple block devices. You have to resize (meant with btrfs tools) specific subvolume to not to break the filesystem on LV about to get resized with lvresize.
I proposed similar patch before
(http://www.redhat.com/archives/lvm-devel/2012-November/msg00052.html)
but in the end came to conclusion it was not worth the pain considering the btrfs-check couldn't detect even elemental fs breakage. Is the state of btrfs-check tool better than what I described earlier in my patch header?
Kind regards
Ondrej
PS: The original patch is from 2012 so perhaps some of the magic I used to extract proper btrfs device id is useless as of now. At least I hope so...
PATCH 1/1 fsadm: add support for btrfs
Hi Ondrej,
Thank you for your reply.
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 3/9/2015 at 04:31 PM, in message <[email protected]>, Ondrej Kozina
Quoted 6 lines · <[email protected]> wrote:
Quoted 4 lines · Lidong Zhong
Run
btrfs checkto check filesystem
Runbtrfs filesystem showto get the filesystem size andbtrfs filesystem resizeto resize.
Quoted 7 lines
Hi,
thank you for the patch but I'm afraid it is not correct. For example it doesn't seem to deal with the possibility of btrfs volume spanning across multiple block devices. You have to resize (meant with btrfs tools) specific subvolume to not to break the filesystem on LV about to get resized with lvresize.
Yeah, I didn't think of that. But the solution is already in your patch. I guess this is not a problem. right?
Quoted 6 lines
I proposed similar patch before
(http://www.redhat.com/archives/lvm-devel/2012-November/msg00052.html)
but in the end came to conclusion it was not worth the pain considering the btrfs-check couldn't detect even elemental fs breakage. Is the state of btrfs-check tool better than what I described earlier in my patch header?
How about mount the device on a tmp place(as temp_mount()) first and then run
btrfs scrub start -B device
and check if the error is zero in the output?
(or the return value of the command is not zero)
Regards,
Lidong
Quoted 14 lines
Kind regards
OndrejPS: The original patch is from 2012 so perhaps some of the magic I used to extract proper btrfs device id is useless as of now. At least I hope so...
Signature · 3 lines
lvm-devel mailing list lvm-devel at redhat.com https://www.redhat.com/mailman/listinfo/lvm-devel