diff mbox series

[2/7] e2scrub: create a script to scrub all ext* filesystems

Message ID 151992862237.32479.3320641920090240561.stgit@magnolia
State Superseded, archived
Headers show
Series e2fprogs: online scrub & compiler fun | expand

Commit Message

Darrick Wong March 1, 2018, 6:23 p.m. UTC
From: Darrick J. Wong <darrick.wong@oracle.com>

Create an e2scrub_all command to find all ext* filesystems
and run an online scrub against them all.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 scrub/Makefile.in      |    9 ++++++--
 scrub/e2scrub_all.8.in |   14 ++++++++++++
 scrub/e2scrub_all.in   |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 78 insertions(+), 2 deletions(-)
 create mode 100644 scrub/e2scrub_all.8.in
 create mode 100644 scrub/e2scrub_all.in

Comments

Andreas Dilger March 1, 2018, 10:42 p.m. UTC | #1
On Mar 1, 2018, at 11:23 AM, Darrick J. Wong <darrick.wong@oracle.com> wrote:
> 
> From: Darrick J. Wong <darrick.wong@oracle.com>
> 
> Create an e2scrub_all command to find all ext* filesystems
> and run an online scrub against them all.

Is fstrim a no-op on HDD and SSD devices that don't support it?

> diff --git a/scrub/e2scrub_all.8.in b/scrub/e2scrub_all.8.in
> new file mode 100644
> index 0000000..a57d4aa
> --- /dev/null
> +++ b/scrub/e2scrub_all.8.in
> @@ -0,0 +1,14 @@
> +.TH E2SCRUB 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
> +.SH NAME
> +e2scrub_all - Check all mounted btrfs/ext4/XFS LVM file systems for errors.

Does it actually check btrfs/XFS filesystems?  I'd guess not.

> diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
> new file mode 100644
> index 0000000..ff9eb8f
> --- /dev/null
> +++ b/scrub/e2scrub_all.in
> @@ -0,0 +1,57 @@
> +#!/bin/bash
> +
> +#  Copyright (C) 2018 Oracle.  All Rights Reserved.
> +#
> +#  Author: Darrick J. Wong <darrick.wong@oracle.com>
> +#
> +#  This program is free software; you can redistribute it and/or
> +#  modify it under the terms of the GNU General Public License
> +#  as published by the Free Software Foundation; either version 2
> +#  of the License, or (at your option) any later version.
> +#
> +#  This program is distributed in the hope that it would be useful,
> +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#  GNU General Public License for more details.
> +#
> +#  You should have received a copy of the GNU General Public License
> +#  along with this program; if not, write the Free Software Foundation,
> +#  Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> +
> +# Check all ext[234] filesystems mounted on LVM
> +types="ext2,ext3,ext4"
> +
> +exitcode() {
> +	ret="$1"
> +
> +	exit "${ret}"
> +}

I don't understand the benefit of this at all...  Why not "exit" directly?

> +prog_path() {
> +	path="$1"
> +	displayname="$2"
> +
> +	if ! type -P "${path}" && [ -n "${displayname}" ]; then
> +		echo "${displayname}: Command not found."
> +		exitcode 8
> +	fi
> +}
> +
> +LVS_PROG="$(prog_path "@root_sbindir@/lvs" "lvs")"
> +BLKID_PROG="$(prog_path "@root_sbindir@/blkid" "blkid")"

This is confusing.  You are forcing the path to be one thing, then failing if
the command is not at the fully-specified path.  Why not just use:

PATH=/bin:/sbin:/usr/bin:/usr/sbin

lvs ...
blkid ...

and then no need to make the script ugly by using $LVS_PROG and $BLKID_PROG
everywhere, secondly it will work regardless of where the programs are installed
(for any sane system), and finally no need to subst every one of your scripts.

Cheers, Andreas

> +
> +# Scrub any fs on lvm by creating a snapshot and fscking that.
> +"${LVS_PROG}" -o vg_name,lv_name,lv_role --noheadings 2> /dev/null | while read vg lv role extra; do
> +	# parsing error?
> +	test -n "${extra}" && continue
> +	# Skip snapshots
> +	echo "${role}" | grep -q "snapshot" && continue
> +
> +	dev="/dev/${vg}/${lv}"
> +	# Skip non-ext[234]
> +	"${BLKID_PROG}" -p -n "${types}" "${dev}" > /dev/null 2>&1 || continue
> +
> +	${DBG} "@root_sbindir@/e2scrub" "${dev}"
> +done
> +
> +exitcode 0
> 


Cheers, Andreas
Darrick Wong March 2, 2018, 8:01 p.m. UTC | #2
On Thu, Mar 01, 2018 at 03:42:52PM -0700, Andreas Dilger wrote:
> On Mar 1, 2018, at 11:23 AM, Darrick J. Wong <darrick.wong@oracle.com> wrote:
> > 
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> > 
> > Create an e2scrub_all command to find all ext* filesystems
> > and run an online scrub against them all.
> 
> Is fstrim a no-op on HDD and SSD devices that don't support it?

fstrim will report that it failed on unsupported devices, but e2scrub
doesn't factor that into the exit code.

> > diff --git a/scrub/e2scrub_all.8.in b/scrub/e2scrub_all.8.in
> > new file mode 100644
> > index 0000000..a57d4aa
> > --- /dev/null
> > +++ b/scrub/e2scrub_all.8.in
> > @@ -0,0 +1,14 @@
> > +.TH E2SCRUB 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
> > +.SH NAME
> > +e2scrub_all - Check all mounted btrfs/ext4/XFS LVM file systems for errors.
> 
> Does it actually check btrfs/XFS filesystems?  I'd guess not.

Oops, fixed. :)

> 
> > diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
> > new file mode 100644
> > index 0000000..ff9eb8f
> > --- /dev/null
> > +++ b/scrub/e2scrub_all.in
> > @@ -0,0 +1,57 @@
> > +#!/bin/bash
> > +
> > +#  Copyright (C) 2018 Oracle.  All Rights Reserved.
> > +#
> > +#  Author: Darrick J. Wong <darrick.wong@oracle.com>
> > +#
> > +#  This program is free software; you can redistribute it and/or
> > +#  modify it under the terms of the GNU General Public License
> > +#  as published by the Free Software Foundation; either version 2
> > +#  of the License, or (at your option) any later version.
> > +#
> > +#  This program is distributed in the hope that it would be useful,
> > +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
> > +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> > +#  GNU General Public License for more details.
> > +#
> > +#  You should have received a copy of the GNU General Public License
> > +#  along with this program; if not, write the Free Software Foundation,
> > +#  Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
> > +
> > +# Check all ext[234] filesystems mounted on LVM
> > +types="ext2,ext3,ext4"
> > +
> > +exitcode() {
> > +	ret="$1"
> > +
> > +	exit "${ret}"
> > +}
> 
> I don't understand the benefit of this at all...  Why not "exit" directly?

Done.

> > +prog_path() {
> > +	path="$1"
> > +	displayname="$2"
> > +
> > +	if ! type -P "${path}" && [ -n "${displayname}" ]; then
> > +		echo "${displayname}: Command not found."
> > +		exitcode 8
> > +	fi
> > +}
> > +
> > +LVS_PROG="$(prog_path "@root_sbindir@/lvs" "lvs")"
> > +BLKID_PROG="$(prog_path "@root_sbindir@/blkid" "blkid")"
> 
> This is confusing.  You are forcing the path to be one thing, then failing if
> the command is not at the fully-specified path.  Why not just use:
> 
> PATH=/bin:/sbin:/usr/bin:/usr/sbin
> 
> lvs ...
> blkid ...
> 
> and then no need to make the script ugly by using $LVS_PROG and $BLKID_PROG
> everywhere, secondly it will work regardless of where the programs are installed
> (for any sane system), and finally no need to subst every one of your scripts.

Fixed up in e2scrub and e2scrub_all.

--D

> Cheers, Andreas
> 
> > +
> > +# Scrub any fs on lvm by creating a snapshot and fscking that.
> > +"${LVS_PROG}" -o vg_name,lv_name,lv_role --noheadings 2> /dev/null | while read vg lv role extra; do
> > +	# parsing error?
> > +	test -n "${extra}" && continue
> > +	# Skip snapshots
> > +	echo "${role}" | grep -q "snapshot" && continue
> > +
> > +	dev="/dev/${vg}/${lv}"
> > +	# Skip non-ext[234]
> > +	"${BLKID_PROG}" -p -n "${types}" "${dev}" > /dev/null 2>&1 || continue
> > +
> > +	${DBG} "@root_sbindir@/e2scrub" "${dev}"
> > +done
> > +
> > +exitcode 0
> > 
> 
> 
> Cheers, Andreas
> 
> 
> 
> 
>
diff mbox series

Patch

diff --git a/scrub/Makefile.in b/scrub/Makefile.in
index a8bb06b..1744941 100644
--- a/scrub/Makefile.in
+++ b/scrub/Makefile.in
@@ -11,8 +11,8 @@  INSTALL = @INSTALL@
 
 @MCONFIG@
 
-PROGS=		e2scrub
-MANPAGES=	e2scrub.8
+PROGS=		e2scrub e2scrub_all
+MANPAGES=	e2scrub.8 e2scrub_all.8
 CONFFILES=	e2scrub.conf
 
 ifeq ($(HAVE_UDEV),yes)
@@ -29,6 +29,11 @@  e2scrub: $(DEP_SUBSTITUTE) e2scrub.in
 	$(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/e2scrub.in $@
 	$(Q) chmod a+x $@
 
+e2scrub_all: e2scrub_all.in
+	$(E) "	SUBST $@"
+	$(Q) $(SUBSTITUTE_UPTIME) $(srcdir)/e2scrub_all.in $@
+	$(Q) chmod a+x $@
+
 %.8: %.8.in $(DEP_SUBSTITUTE)
 	$(E) "	SUBST $@"
 	$(Q) $(SUBSTITUTE_UPTIME) $< $@
diff --git a/scrub/e2scrub_all.8.in b/scrub/e2scrub_all.8.in
new file mode 100644
index 0000000..a57d4aa
--- /dev/null
+++ b/scrub/e2scrub_all.8.in
@@ -0,0 +1,14 @@ 
+.TH E2SCRUB 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@"
+.SH NAME
+e2scrub_all - Check all mounted btrfs/ext4/XFS LVM file systems for errors.
+.SH SYNOPSYS
+.B
+e2scrub_all
+.SH DESCRIPTION
+Searches the system for all LVM volumes containing an ext2, ext3, or
+ext4 file system, and checks them all for errors.
+If the file system has no errors, it will be fstrim'd.
+.SH AUTHOR
+Darrick J. Wong <darrick.wong@oracle.com>
+.SH COPYRIGHT
+Copyright ©2018 Darrick J. Wong.  License is GPLv2+. <http://www.gnu.org/licenses/gpl-2.0.html>
diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in
new file mode 100644
index 0000000..ff9eb8f
--- /dev/null
+++ b/scrub/e2scrub_all.in
@@ -0,0 +1,57 @@ 
+#!/bin/bash
+
+#  Copyright (C) 2018 Oracle.  All Rights Reserved.
+#
+#  Author: Darrick J. Wong <darrick.wong@oracle.com>
+#
+#  This program is free software; you can redistribute it and/or
+#  modify it under the terms of the GNU General Public License
+#  as published by the Free Software Foundation; either version 2
+#  of the License, or (at your option) any later version.
+#
+#  This program is distributed in the hope that it would be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, write the Free Software Foundation,
+#  Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
+
+# Check all ext[234] filesystems mounted on LVM
+types="ext2,ext3,ext4"
+
+exitcode() {
+	ret="$1"
+
+	exit "${ret}"
+}
+
+prog_path() {
+	path="$1"
+	displayname="$2"
+
+	if ! type -P "${path}" && [ -n "${displayname}" ]; then
+		echo "${displayname}: Command not found."
+		exitcode 8
+	fi
+}
+
+LVS_PROG="$(prog_path "@root_sbindir@/lvs" "lvs")"
+BLKID_PROG="$(prog_path "@root_sbindir@/blkid" "blkid")"
+
+# Scrub any fs on lvm by creating a snapshot and fscking that.
+"${LVS_PROG}" -o vg_name,lv_name,lv_role --noheadings 2> /dev/null | while read vg lv role extra; do
+	# parsing error?
+	test -n "${extra}" && continue
+	# Skip snapshots
+	echo "${role}" | grep -q "snapshot" && continue
+
+	dev="/dev/${vg}/${lv}"
+	# Skip non-ext[234]
+	"${BLKID_PROG}" -p -n "${types}" "${dev}" > /dev/null 2>&1 || continue
+
+	${DBG} "@root_sbindir@/e2scrub" "${dev}"
+done
+
+exitcode 0