From patchwork Sat Mar 24 01:57:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Darrick Wong X-Patchwork-Id: 890367 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="WtdvWBzl"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 407Nnv2nXPz9s08 for ; Sat, 24 Mar 2018 12:57:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751811AbeCXB5W (ORCPT ); Fri, 23 Mar 2018 21:57:22 -0400 Received: from userp2120.oracle.com ([156.151.31.85]:51320 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751675AbeCXB5W (ORCPT ); Fri, 23 Mar 2018 21:57:22 -0400 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2O1sPW2110663; Sat, 24 Mar 2018 01:57:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=corp-2017-10-26; bh=/lkzVX7hks2IUKIqlyNBCpvFJul7LuqneZzRjNrNNyk=; b=WtdvWBzlOs0KXWFrqKVEmuCnMzJrGVSJFySybgrl7VS1lynbdXGowGE4LWzdPXH7SI4/ dNScg0NaMPIeczK3N5LMMZRt39y21ZID9SgKVFb7oYafHTbcnKxyIXcMOXrMDsh167Pz znerL/Q7D+6BKrO6Yg8q34p9doc99Pu3OHznwZUeuUa8kWl0PmlQl+3yhO+QkjpOJAEA 5BQNffREBPpPd3hELhaxlS6RGTDhPk2VpmLsUqVyhdbJN64LS0XZj/g2C8l7MR0U8PUd cmliuA+3LNNMFW0XcfEvMiXh0BH0ioUAEK4I/VZw6DrVtdt201zDoERa61HCXpYU3u4i fQ== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2gwdder046-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Mar 2018 01:57:17 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2O1vHnZ005491 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 24 Mar 2018 01:57:17 GMT Received: from abhmp0017.oracle.com (abhmp0017.oracle.com [141.146.116.23]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2O1vHHW023874; Sat, 24 Mar 2018 01:57:17 GMT Received: from localhost (/10.159.132.121) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 23 Mar 2018 18:57:16 -0700 Subject: [PATCH 3/4] e2scrub: create a script to scrub all ext* filesystems From: "Darrick J. Wong" To: tytso@mit.edu, darrick.wong@oracle.com Cc: Andreas Dilger , linux-ext4@vger.kernel.org Date: Fri, 23 Mar 2018 18:57:15 -0700 Message-ID: <152185663566.10434.10842263720369617262.stgit@magnolia> In-Reply-To: <152185661631.10434.3295057734679624788.stgit@magnolia> References: <152185661631.10434.3295057734679624788.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8841 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=9 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1803240010 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Darrick J. Wong Create an e2scrub_all command to find all ext* filesystems and run an online scrub against them all. Signed-off-by: Darrick J. Wong Reviewed-by: Andreas Dilger --- scrub/Makefile.in | 9 ++++- scrub/e2scrub.conf.in | 3 ++ scrub/e2scrub_all.8.in | 36 ++++++++++++++++++++ scrub/e2scrub_all.in | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 scrub/e2scrub_all.8.in create mode 100644 scrub/e2scrub_all.in 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.conf.in b/scrub/e2scrub.conf.in index d578cc7..69f997f 100644 --- a/scrub/e2scrub.conf.in +++ b/scrub/e2scrub.conf.in @@ -8,3 +8,6 @@ # Arguments passed into e2fsck. # e2fsck_opts="-vtt" + +# Set this to 1 to have e2scrub_all scrub all LVs, not just the mounted ones. +# scrub_all=0 diff --git a/scrub/e2scrub_all.8.in b/scrub/e2scrub_all.8.in new file mode 100644 index 0000000..ba3b873 --- /dev/null +++ b/scrub/e2scrub_all.8.in @@ -0,0 +1,36 @@ +.TH E2SCRUB 8 "@E2FSPROGS_MONTH@ @E2FSPROGS_YEAR@" "E2fsprogs version @E2FSPROGS_VERSION@" +.SH NAME +e2scrub_all - check all mounted ext[234] filesystems for errors. +.SH SYNOPSYS +.B +e2scrub_all [OPTION] +.SH DESCRIPTION +Searches the system for all LVM logical volumes containing an ext2, ext3, or +ext4 file system, and checks them for problems. +The checking is performed by invoking the +.B e2scrub +tool, which will look for corruptions. +Corrupt filesystems will be tagged as having errors so that fsck will be +invoked before the next mount. +If no errors are encountered, +.B fstrim +will be called on the filesystem if it is mounted. +See the +.B e2scrub +manual page for more information about how the checking is performed. +.SH OPTIONS +.TP +\fB-A\fR +Scrub all ext[234] filesystems even if they are not mounted. +.TP +\fB-r\fR +Remove e2scrub snapshots but do not check anything. +.TP +\fB-V\fR +Print version information and exit. +.SH SEE ALSO +.BR e2scrub "(8)" +.SH AUTHOR +Darrick J. Wong +.SH COPYRIGHT +Copyright ©2018 Oracle. License is GPLv2+. diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in new file mode 100644 index 0000000..b9e5dea --- /dev/null +++ b/scrub/e2scrub_all.in @@ -0,0 +1,85 @@ +#!/bin/bash + +# Copyright (C) 2018 Oracle. All Rights Reserved. +# +# Author: Darrick J. Wong +# +# 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. + +scrub_all=0 +conffile="@root_sysconfdir@/e2scrub.conf" + +test -f "${conffile}" && . "${conffile}" + +scrub_args="" + +print_help() { + echo "Usage: $0 [OPTIONS]" + echo " -A: Scrub all ext[234] filesystems even if not mounted." + echo " -r: Remove e2scrub snapshots." + echo " -V: Print version information and exit." +} + +print_version() { + echo "e2scrub_all @E2FSPROGS_VERSION@ (@E2FSPROGS_DATE@)" +} + +while getopts "ArV" opt; do + case "${opt}" in + "A") scrub_all=1;; + "r") scrub_args="${scrub_args} -r";; + "V") print_version; exit 0;; + *) print_help; exit 2;; + esac +done +shift "$((OPTIND - 1))" + +# Find scrub targets, make sure we only do this once. +ls_scrub_targets() { + lsblk -o NAME,FSTYPE,MOUNTPOINT -p -P -n | while read vars; do + eval "${vars}" + + # Skip non-ext[234] + case "${FSTYPE}" in + ext[234]) ;; + *) continue;; + esac + + # Skip unmounted filesystems unless -A + if [ "${scrub_all}" -eq 0 ] && [ -z "${MOUNTPOINT}" ]; then + continue; + fi + + # Skip non-lvm devices and lvm snapshots + lvm_vars="$(lvs --nameprefixes -o vg_name,lv_name,lv_role --noheadings "${NAME}" 2> /dev/null)" + test $? -ne 0 && continue + eval "${lvm_vars}" + echo "${LVM2_LV_ROLE}" | grep -q "snapshot" && continue + + if [ -n "${MOUNTPOINT}" ]; then + echo "${MOUNTPOINT}" + else + echo "${NAME}" + fi + done | sort | uniq +} + +# Scrub any mounted fs on lvm by creating a snapshot and fscking that. +stdin="$(realpath /dev/stdin)" +ls_scrub_targets | while read tgt; do + ${DBG} "@root_sbindir@/e2scrub" ${scrub_args} "${tgt}" < "${stdin}" +done + +exit 0