From patchwork Thu Mar 21 20:25:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Theodore Ts'o X-Patchwork-Id: 1060445 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=none (p=none dis=none) header.from=mit.edu Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44QJFR5QBJz9sRj for ; Fri, 22 Mar 2019 07:25:31 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728904AbfCUUZb (ORCPT ); Thu, 21 Mar 2019 16:25:31 -0400 Received: from outgoing-auth-1.mit.edu ([18.9.28.11]:52567 "EHLO outgoing.mit.edu" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728093AbfCUUZa (ORCPT ); Thu, 21 Mar 2019 16:25:30 -0400 Received: from callcc.thunk.org (guestnat-104-133-0-99.corp.google.com [104.133.0.99] (may be forged)) (authenticated bits=0) (User authenticated as tytso@ATHENA.MIT.EDU) by outgoing.mit.edu (8.14.7/8.12.4) with ESMTP id x2LKPJs9017000 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Mar 2019 16:25:19 -0400 Received: by callcc.thunk.org (Postfix, from userid 15806) id E4083420AA9; Thu, 21 Mar 2019 16:25:18 -0400 (EDT) From: "Theodore Ts'o" To: Ext4 Developers List Cc: darrick.wong@oracle.com, lczerner@redhat.com, "Theodore Ts'o" Subject: [PATCH 1/9] e2scrub: check to make sure lvm2 is installed Date: Thu, 21 Mar 2019 16:25:05 -0400 Message-Id: <20190321202513.1969-2-tytso@mit.edu> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190321202513.1969-1-tytso@mit.edu> References: <20190321202513.1969-1-tytso@mit.edu> MIME-Version: 1.0 Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org Not all systems will have the lvm2 package installed, so check for that. Pretty much all systems should have util-linux installed, but check for that as well. Of course, if lvm2 is installed we shouldn't find any LVM devices --- but eventually the Demon Murphy will find a way to make it happen. :-) Also, set the PATH so we don't have to worry about the script failing due to /sbin not being in the path. Signed-off-by: Theodore Ts'o --- scrub/e2scrub.in | 12 ++++++++++++ scrub/e2scrub_all.in | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/scrub/e2scrub.in b/scrub/e2scrub.in index e1965db4e..51a909373 100644 --- a/scrub/e2scrub.in +++ b/scrub/e2scrub.in @@ -23,6 +23,8 @@ # check filesystems in VGs that have at least 256MB (or so) of # free space. +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + snap_size_mb=256 fstrim=0 reap=0 @@ -82,6 +84,16 @@ if [ -z "${arg}" ]; then exitcode 1 fi +if ! type lsblk >& /dev/null ; then + echo "e2scrub: can't find lsblk --- is util-linux installed?" + exitcode 1 +fi + +if ! type lvcreate >& /dev/null ; then + echo "e2scrub: can't find lvcreate --- is lvm2 installed?" + exitcode 1 +fi + # Find the device for a given mountpoint dev_from_mount() { local mountpt="$(realpath "$1")" diff --git a/scrub/e2scrub_all.in b/scrub/e2scrub_all.in index 23d122d25..d725a7f2e 100644 --- a/scrub/e2scrub_all.in +++ b/scrub/e2scrub_all.in @@ -18,6 +18,8 @@ # along with this program; if not, write the Free Software Foundation, # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. +PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin + scrub_all=0 conffile="@root_sysconfdir@/e2scrub.conf" @@ -68,6 +70,20 @@ while getopts "ArV" opt; do done shift "$((OPTIND - 1))" +# If some prerequisite packages are not installed, exit with a code +# indicating success to avoid spamming the sysadmin with fail messages +# when e2scrub_all is run out of cron or a systemd timer. + +if ! type lsblk >& /dev/null ; then + echo "e2scrub_all: can't find lsblk --- is util-linux installed?" + exitcode 0 +fi + +if ! type lvcreate >& /dev/null ; then + echo "e2scrub_all: can't find lvcreate --- is lvm2 installed?" + exitcode 0 +fi + # 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