Skip to contentSkip to conversation

common: cleanups after common/rc split

PATCH Superseded Eryu Guan 2 participants 5 messages Dec 1, 2016 – Dec 2, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eryu Guan

author
#0 lore raw

PATCH 1/1 common: cleanups after common/rc split

Fix code style issues after the common/rc split, e.g. use tab indention, fix if-then-else format, fix while-do and for-do format and various whitespace issues. No functional changes.

---

This is a follow-up patch to Dave's "make common/rc easier to manage" patchset.

 common/btrfs |  87 ++++++-------
 common/xfs   | 404 +++++++++++++++++++++++++++++------------------------------
 2 files changed, 239 insertions(+), 252 deletions(-)
common/btrfs +41 -46
index 7cc4f5d..ab6497d 100644
@@ -68,53 +68,49 @@ _require_btrfs_fs_feature()
 
 _check_btrfs_filesystem()
 {
-    device=$1
-
-    # If type is set, we're mounted
-    type=`_fs_type $device`
-    ok=1
-
-    if [ "$type" = "$FSTYP" ]
-    then
-        # mounted ...
-        mountpoint=`_umount_or_remount_ro $device`
-    fi
-
-    btrfsck $device >$tmp.fsck 2>&1
-    if [ $? -ne 0 ]
-    then
-        echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
-
-        echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
-        echo "*** fsck.$FSTYP output ***"	>>$seqres.full
-        cat $tmp.fsck				>>$seqres.full
-        echo "*** end fsck.$FSTYP output"	>>$seqres.full
-
-        ok=0
-    fi
-    rm -f $tmp.fsck
-
-    if [ $ok -eq 0 ]
-    then
-        echo "*** mount output ***"		>>$seqres.full
-        _mount					>>$seqres.full
-        echo "*** end mount output"		>>$seqres.full
-    elif [ "$type" = "$FSTYP" ]
-    then
-	# was mounted ...
-	_mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
-	ok=$?
-    fi
-
-    if [ $ok -eq 0 ]; then
-	status=1
-	if [ "$iam" != "check" ]; then
-		exit 1
+	device=$1
+
+	# If type is set, we're mounted
+	type=`_fs_type $device`
+	ok=1
+
+	if [ "$type" = "$FSTYP" ]; then
+		# mounted ...
+		mountpoint=`_umount_or_remount_ro $device`
 	fi
-	return 1
-    fi
 
-    return 0
+	btrfsck $device >$tmp.fsck 2>&1
+	if [ $? -ne 0 ]; then
+		echo "_check_btrfs_filesystem: filesystem on $device is inconsistent (see $seqres.full)"
+
+		echo "_check_btrfs_filesystem: filesystem on $device is inconsistent" >>$seqres.full
+		echo "*** fsck.$FSTYP output ***"	>>$seqres.full
+		cat $tmp.fsck				>>$seqres.full
+		echo "*** end fsck.$FSTYP output"	>>$seqres.full
+
+		ok=0
+	fi
+	rm -f $tmp.fsck
+
+	if [ $ok -eq 0 ]; then
+		echo "*** mount output ***"		>>$seqres.full
+		_mount					>>$seqres.full
+		echo "*** end mount output"		>>$seqres.full
+	elif [ "$type" = "$FSTYP" ]; then
+		# was mounted ...
+		_mount_or_remount_rw "$MOUNT_OPTIONS" $device $mountpoint
+		ok=$?
+	fi
+
+	if [ $ok -eq 0 ]; then
+		status=1
+		if [ "$iam" != "check" ]; then
+			exit 1
+		fi
+		return 1
+	fi
+
+	return 0
 }
 
 _require_btrfs_dev_del_by_devid()
@@ -332,4 +328,3 @@ _reload_btrfs_ko()
 	modprobe -r btrfs || _fail "btrfs unload failed"
 	modprobe btrfs || _fail "btrfs load failed"
 }
-
common/xfs +198 -206

461 lines not on this page · raw message

Signature · 1 line
2.9.3
#1 lore raw
Quoted 3 lines · Eryu Guan

Fix code style issues after the common/rc split, e.g. use tab indention, fix if-then-else format, fix while-do and for-do format and various whitespace issues. No functional changes.

Couple of quick things....

Quoted 7 lines
common/xfs +7 -0
+	OPTS=" "
+	DBOPTS=" "
+	USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
+
+	while getopts "b:fi:l:stvV" c; do
+		case $c in
+			s) OPTS=$OPTS"-s ";;

common/xfs _scratch_mkfs_xfs() · line 154

Quoted 10 lines
common/xfs +10 -0
+			t) OPTS=$OPTS"-t ";;
+			v) OPTS=$OPTS"-v ";;
+			i) OPTS=$OPTS"-i "$OPTARG" ";;
+			b) OPTS=$OPTS"-b "$OPTARG" ";;
+			f) DBOPTS=$DBOPTS" -f";;
+			l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
+			V) $XFS_DB_PROG -p xfs_check -V
+			   return $?
+			   ;;
+		esac

It saves space and makes it easier to read if you don't indent the individual cases but do indent the code so multi-line operations don't end up with weird space indenting:

		case $c in
		s)	OPTS=$OPTS"-s ";;
		t)	OPTS=$OPTS"-t ";;
		v)	OPTS=$OPTS"-v ";;
		....
		V)	$XFS_DB_PROG -p xfs_check -V
			return $?
			;;
Quoted 5 lines
common/xfs +0 -1
@@ -198,23 +197,23 @@ _test_xfs_logprint()
 
 _scratch_xfs_check()
 {
-    SCRATCH_OPTIONS=""

common/xfs _test_xfs_logprint() · line 204

Quoted 10 lines
common/xfs +5 -5
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
-        SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
-    [ "$LARGE_SCRATCH_DEV" = yes ] && \
-        SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
-    _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
+	SCRATCH_OPTIONS=""
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+		SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
+	[ "$LARGE_SCRATCH_DEV" = yes ] && \
+		SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"

If it's a multi-line construct, just use if [...]; then.

Quoted 7 lines
common/xfs +1 -2
+	_xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
 }
 
 _scratch_xfs_repair()
 {
-    SCRATCH_OPTIONS=""
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \

common/xfs _test_xfs_logprint() · line 214

Quoted 10 lines
common/xfs +5 -5
-        SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
-        SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
-    [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
-    $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
+	SCRATCH_OPTIONS=""
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+		SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+		SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"

And this can become:

	if [ "$USE_EXTERNAL" = yes ]; then
		[ -n "$SCRATCH_LOGDEV" ] && SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV" 
		[ -n "$SCRATCH_RTDEV" ] && SCRATCH_OPTIONS="-l$SCRATCH_RTDEV" 
	fi

common/xfs _require_xfs_db_command() · line 373

Quoted 10 lines
common/xfs +10 -0
+
+	$XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
+		| tee $tmp.logprint | grep -q "<CLEAN>"
+	if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]; then
+		echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
+
+		echo "_check_xfs_filesystem: filesystem on $device has dirty log"   >>$seqres.full
+		echo "*** xfs_logprint -t output ***"	>>$seqres.full
+		cat $tmp.logprint			>>$seqres.full
+		echo "*** end xfs_logprint output"	>>$seqres.full

Better, I think, with these multi-line file dumps is something like:

		(
		echo ....
		echo ....
		cat ...
		echo
		) >> $seqres.full
Quoted 5 lines
common/xfs +5 -0
+	if [ $ok -eq 0 ]; then
+		echo "*** mount output ***"		>>$seqres.full
+		_mount					>>$seqres.full
+		echo "*** end mount output"		>>$seqres.full
+	elif [ "$type" = "xfs" ]; then

common/xfs _require_xfs_db_command() · line 452

Quoted 10 lines
common/xfs +10 -0
+		_mount_or_remount_rw "$extra_mount_options" $device $mountpoint
+	fi
+
+	if [ $ok -eq 0 ]; then
+		status=1
+		if [ "$iam" != "check" ]; then
+			exit 1
+		fi
+		return 1
+	fi

THese $ok -eq 0 cases can be combined.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#2 lore raw
Quoted 29 lines · Dave Chinner
Quoted 3 lines · Eryu Guan

Fix code style issues after the common/rc split, e.g. use tab indention, fix if-then-else format, fix while-do and for-do format and various whitespace issues. No functional changes.

Couple of quick things....

Quoted 7 lines
common/xfs +7 -0
+	OPTS=" "
+	DBOPTS=" "
+	USAGE="Usage: xfs_check [-fsvV] [-l logdev] [-i ino]... [-b bno]... special"
+
+	while getopts "b:fi:l:stvV" c; do
+		case $c in
+			s) OPTS=$OPTS"-s ";;

common/xfs _scratch_mkfs_xfs() · line 154

Quoted 10 lines
common/xfs +10 -0
+			t) OPTS=$OPTS"-t ";;
+			v) OPTS=$OPTS"-v ";;
+			i) OPTS=$OPTS"-i "$OPTARG" ";;
+			b) OPTS=$OPTS"-b "$OPTARG" ";;
+			f) DBOPTS=$DBOPTS" -f";;
+			l) DBOPTS=$DBOPTS" -l "$OPTARG" ";;
+			V) $XFS_DB_PROG -p xfs_check -V
+			   return $?
+			   ;;
+		esac

It saves space and makes it easier to read if you don't indent the individual cases but do indent the code so multi-line operations don't end up with weird space indenting:

Quoted 9 lines
		case $c in
		s)	OPTS=$OPTS"-s ";;
		t)	OPTS=$OPTS"-t ";;
		v)	OPTS=$OPTS"-v ";;
		....
		V)	$XFS_DB_PROG -p xfs_check -V
			return $?
			;;

Yes, this looks better.

Quoted 17 lines
Quoted 5 lines
common/xfs +0 -1
@@ -198,23 +197,23 @@ _test_xfs_logprint()
 
 _scratch_xfs_check()
 {
-    SCRATCH_OPTIONS=""

common/xfs _test_xfs_logprint() · line 204

Quoted 10 lines
common/xfs +5 -5
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
-        SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
-    [ "$LARGE_SCRATCH_DEV" = yes ] && \
-        SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
-    _xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
+	SCRATCH_OPTIONS=""
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+		SCRATCH_OPTIONS="-l $SCRATCH_LOGDEV"
+	[ "$LARGE_SCRATCH_DEV" = yes ] && \
+		SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"

If it's a multi-line construct, just use if [...]; then.

I didn't pay attention to the actual code, just fixed the indention issue. I'll fix them in v2.

Thanks for the review!

Eryu

Quoted 69 lines
Quoted 8 lines
common/xfs +1 -2
+	_xfs_check $SCRATCH_OPTIONS $* $SCRATCH_DEV
 }
 
 _scratch_xfs_repair()
 {
-    SCRATCH_OPTIONS=""
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \

common/xfs _test_xfs_logprint() · line 214

Quoted 10 lines
common/xfs +5 -5
-        SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
-    [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
-        SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"
-    [ "$LARGE_SCRATCH_DEV" = yes ] && SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -t"
-    $XFS_REPAIR_PROG $SCRATCH_OPTIONS $* $SCRATCH_DEV
+	SCRATCH_OPTIONS=""
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
+		SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV"
+	[ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_RTDEV" ] && \
+		SCRATCH_OPTIONS=$SCRATCH_OPTIONS" -r$SCRATCH_RTDEV"

And this can become:

	if [ "$USE_EXTERNAL" = yes ]; then
		[ -n "$SCRATCH_LOGDEV" ] && SCRATCH_OPTIONS="-l$SCRATCH_LOGDEV" 
		[ -n "$SCRATCH_RTDEV" ] && SCRATCH_OPTIONS="-l$SCRATCH_RTDEV" 
	fi

common/xfs _require_xfs_db_command() · line 373

Quoted 10 lines
common/xfs +10 -0
+
+	$XFS_LOGPRINT_PROG -t $extra_log_options $device 2>&1 \
+		| tee $tmp.logprint | grep -q "<CLEAN>"
+	if [ $? -ne 0 -a "$HOSTOS" = "Linux" ]; then
+		echo "_check_xfs_filesystem: filesystem on $device has dirty log (see $seqres.full)"
+
+		echo "_check_xfs_filesystem: filesystem on $device has dirty log"   >>$seqres.full
+		echo "*** xfs_logprint -t output ***"	>>$seqres.full
+		cat $tmp.logprint			>>$seqres.full
+		echo "*** end xfs_logprint output"	>>$seqres.full

Better, I think, with these multi-line file dumps is something like:

		(
		echo ....
		echo ....
		cat ...
		echo
		) >> $seqres.full
Quoted 5 lines
common/xfs +5 -0
+	if [ $ok -eq 0 ]; then
+		echo "*** mount output ***"		>>$seqres.full
+		_mount					>>$seqres.full
+		echo "*** end mount output"		>>$seqres.full
+	elif [ "$type" = "xfs" ]; then

common/xfs _require_xfs_db_command() · line 452

Quoted 10 lines
common/xfs +10 -0
+		_mount_or_remount_rw "$extra_mount_options" $device $mountpoint
+	fi
+
+	if [ $ok -eq 0 ]; then
+		status=1
+		if [ "$iam" != "check" ]; then
+			exit 1
+		fi
+		return 1
+	fi

THese $ok -eq 0 cases can be combined.

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]
author
#3 lore raw

On Fri, Dec 02, 2016 at 11:35:04AM +0800, Eryu Guan wrote:
...

Quoted 6 lines
Quoted 6 lines

common/xfs _require_xfs_db_command() · line 443

Quoted 6 lines
common/xfs +6 -0
+	if [ $ok -eq 0 ]; then
+		echo "*** mount output ***"		>>$seqres.full
+		_mount					>>$seqres.full
+		echo "*** end mount output"		>>$seqres.full
+	elif [ "$type" = "xfs" ]; then
+		_mount_or_remount_rw "$extra_mount_options" $device $mountpoint

I looked at this more and I think that a "ok=$?" is missed here (_mount_or_remount_rw return 1 as success), both _check_generic_filesystem and _check_btrfs_filesystem do this. So if it passes the first $ok check then does this rw mount and sets $ok based on the mount result. I'll just add a "ok=$?" here.

Thanks,
Eryu

Quoted 22 lines
Quoted 12 lines

common/btrfs _require_btrfs_fs_feature() · line 111

Quoted 9 lines
common/btrfs +9 -0
+	fi
+
+	if [ $ok -eq 0 ]; then
+		status=1
+		if [ "$iam" != "check" ]; then
+			exit 1
+		fi
+		return 1
+	fi

THese $ok -eq 0 cases can be combined.

Quoted 6 lines

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]

--
To unsubscribe from this list: send the line "unsubscribe fstests" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#4 lore raw
Quoted 14 lines · Eryu Guan

On Fri, Dec 02, 2016 at 11:35:04AM +0800, Eryu Guan wrote:
...

Quoted 6 lines
Quoted 6 lines

common/xfs _require_xfs_db_command() · line 443

Quoted 6 lines
common/xfs +6 -0
+	if [ $ok -eq 0 ]; then
+		echo "*** mount output ***"		>>$seqres.full
+		_mount					>>$seqres.full
+		echo "*** end mount output"		>>$seqres.full
+	elif [ "$type" = "xfs" ]; then
+		_mount_or_remount_rw "$extra_mount_options" $device $mountpoint

I looked at this more and I think that a "ok=$?" is missed here (_mount_or_remount_rw return 1 as success), both _check_generic_filesystem and _check_btrfs_filesystem do this. So if it passes the first $ok check then does this rw mount and sets $ok based on the mount result. I'll just add a "ok=$?" here.

Sounds good. :P

Cheers,

Dave.

Signature · 2 lines
Dave Chinner
[email protected]