From patchwork Tue Jul 20 01:09:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12387191 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6BA7C07E9D for ; Tue, 20 Jul 2021 01:17:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 982376108B for ; Tue, 20 Jul 2021 01:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1354187AbhGTAb1 (ORCPT ); Mon, 19 Jul 2021 20:31:27 -0400 Received: from mail.kernel.org ([198.145.29.99]:41964 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381214AbhGTA3x (ORCPT ); Mon, 19 Jul 2021 20:29:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7959561165; Tue, 20 Jul 2021 01:09:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626743348; bh=HUiFOFRxHQEtwyrRshbFEsq3l4r5GCytFoaaC9NXMgI=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=U93NDz3E+QuRfjInFp75h5MSaEWVOJOeeCxKEDCTeM+4fWNpfugs2hcQt3QC4h1Qr Qms02eQ6NemmZMFEBmaVDU05b4WDfiA4aycPjQn8ZB8TK0N9tGDLEk/kW42VT7wseK 3uLYs+PyMOPQYS6McQMhoLscBOOWuyV7DH34O+1My52Lh+MJx3mN5qcf7nsmScVQ/f KOHVSA3CsTJflJ4ECescexb+hriDCcGAJRqLdSlaLrmciwWAkGcrupWKSLS9k+2EZc jihpL12h42EsltfAgFOa3EjxGNSHHTuyVdKzO5peF23y0odpJQDcaiMh82kDWIe2y4 r2NvErTJMugQA== Subject: [PATCH 1/3] dmflakey: support external log and realtime devices From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me, tytso@mit.edu Date: Mon, 19 Jul 2021 18:09:08 -0700 Message-ID: <162674334822.2651055.756804899535330518.stgit@magnolia> In-Reply-To: <162674334277.2651055.14927938006488444114.stgit@magnolia> References: <162674334277.2651055.14927938006488444114.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Upgrade the dmflakey code to coordinate making external scratch log and scratch realtime devices flakey along with the scratch device. Note that unlike SCRATCH_DEV, we save the old rt/log devices as separate variables and replace SCRATCH_{RT,LOG}DEV so that helper functions continue to work without modification. Signed-off-by: Darrick J. Wong --- common/dmflakey | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 3 deletions(-) diff --git a/common/dmflakey b/common/dmflakey index b4e11ae9..af4371a3 100644 --- a/common/dmflakey +++ b/common/dmflakey @@ -10,6 +10,7 @@ FLAKEY_ERROR_WRITES=2 _init_flakey() { + # Scratch device local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV` FLAKEY_DEV=/dev/mapper/flakey-test FLAKEY_TABLE="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 180 0" @@ -17,11 +18,50 @@ _init_flakey() FLAKEY_TABLE_ERROR="0 $BLK_DEV_SIZE flakey $SCRATCH_DEV 0 0 180 1 error_writes" _dmsetup_create flakey-test --table "$FLAKEY_TABLE" || \ _fatal "failed to create flakey device" + + # Realtime device + if [ -n "$SCRATCH_RTDEV" ]; then + if [ -z "$NON_FLAKEY_RTDEV" ]; then + # Set up the device switch + local backing_dev="$SCRATCH_RTDEV" + export NON_FLAKEY_RTDEV="$SCRATCH_RTDEV" + SCRATCH_RTDEV=/dev/mapper/flakey-rttest + else + # Already set up; recreate tables + local backing_dev="$NON_FLAKEY_RTDEV" + fi + local BLK_DEV_SIZE=`blockdev --getsz $backing_dev` + FLAKEY_RTTABLE="0 $BLK_DEV_SIZE flakey $backing_dev 0 180 0" + FLAKEY_RTTABLE_DROP="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 drop_writes" + FLAKEY_RTTABLE_ERROR="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 error_writes" + _dmsetup_create flakey-rttest --table "$FLAKEY_RTTABLE" || \ + _fatal "failed to create flakey rt device" + fi + + # External log device + if [ -n "$SCRATCH_LOGDEV" ]; then + if [ -z "$NON_FLAKEY_LOGDEV" ]; then + # Set up the device switch + local backing_dev="$SCRATCH_LOGDEV" + export NON_FLAKEY_LOGDEV="$SCRATCH_LOGDEV" + SCRATCH_LOGDEV=/dev/mapper/flakey-logtest + else + # Already set up; recreate tables + local backing_dev="$NON_FLAKEY_LOGDEV" + fi + local BLK_DEV_SIZE=`blockdev --getsz $backing_dev` + FLAKEY_LOGTABLE="0 $BLK_DEV_SIZE flakey $backing_dev 0 180 0" + FLAKEY_LOGTABLE_DROP="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 drop_writes" + FLAKEY_LOGTABLE_ERROR="0 $BLK_DEV_SIZE flakey $backing_dev 0 0 180 1 error_writes" + _dmsetup_create flakey-logtest --table "$FLAKEY_LOGTABLE" || \ + _fatal "failed to create flakey log device" + fi } _mount_flakey() { _scratch_options mount + mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $FLAKEY_DEV $SCRATCH_MNT } @@ -34,9 +74,21 @@ _cleanup_flakey() { # If dmsetup load fails then we need to make sure to do resume here # otherwise the umount will hang + test -n "$NON_FLAKEY_LOGDEV" && $DMSETUP_PROG resume flakey-logtest &> /dev/null + test -n "$NON_FLAKEY_RTDEV" && $DMSETUP_PROG resume flakey-rttest &> /dev/null $DMSETUP_PROG resume flakey-test > /dev/null 2>&1 + $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1 + _dmsetup_remove flakey-test + test -n "$NON_FLAKEY_LOGDEV" && _dmsetup_remove flakey-logtest + test -n "$NON_FLAKEY_RTDEV" && _dmsetup_remove flakey-rttest + + SCRATCH_LOGDEV="$NON_FLAKEY_LOGDEV" + unset NON_FLAKEY_LOGDEV + + SCRATCH_RTDEV="$NON_FLAKEY_RTDEV" + unset NON_FLAKEY_RTDEV } # _load_flakey_table [lockfs] @@ -45,22 +97,70 @@ _cleanup_flakey() # table, so it simulates power failure. _load_flakey_table() { - table="$FLAKEY_TABLE" - [ $1 -eq $FLAKEY_DROP_WRITES ] && table="$FLAKEY_TABLE_DROP" - [ $1 -eq $FLAKEY_ERROR_WRITES ] && table="$FLAKEY_TABLE_ERROR" + case "$1" in + "$FLAKEY_DROP_WRITES") + table="$FLAKEY_TABLE_DROP" + logtable="$FLAKEY_LOGTABLE_DROP" + rttable="$FLAKEY_RTTABLE_DROP" + ;; + "$FLAKEY_ERROR_WRITES") + table="$FLAKEY_TABLE_ERROR" + logtable="$FLAKEY_LOGTABLE_ERROR" + rttable="$FLAKEY_RTTABLE_ERROR" + ;; + *) + table="$FLAKEY_TABLE" + logtable="$FLAKEY_LOGTABLE" + rttable="$FLAKEY_RTTABLE" + ;; + esac suspend_opt="--nolockfs" [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt="" + # Suspend the scratch device before the log and realtime devices so + # that the kernel can freeze and flush the filesystem if the caller + # wanted a freeze. $DMSETUP_PROG suspend $suspend_opt flakey-test [ $? -ne 0 ] && _fatal "failed to suspend flakey-test" + if [ -n "$NON_FLAKEY_RTDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt flakey-rttest + [ $? -ne 0 ] && _fatal "failed to suspend flakey-rttest" + fi + + if [ -n "$NON_FLAKEY_LOGDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt flakey-logtest + [ $? -ne 0 ] && _fatal "failed to suspend flakey-logtest" + fi + # There may be multiple dm targets in the table, and these dm targets # will be joined by the newline ("\n"). Option --table can not cope with # the multiple-targets case, so get them by reading from standard input. echo -e "$table" | $DMSETUP_PROG load flakey-test [ $? -ne 0 ] && _fatal "failed to load table into flakey-test" + if [ -n "$NON_FLAKEY_RTDEV" ]; then + echo -e "$rttable" | $DMSETUP_PROG load flakey-rttest + [ $? -ne 0 ] && _fatal "failed to load table into flakey-rttest" + fi + + if [ -n "$NON_FLAKEY_LOGDEV" ]; then + echo -e "$logtable" | $DMSETUP_PROG load flakey-logtest + [ $? -ne 0 ] && _fatal "failed to load table into flakey-logtest" + fi + + # Resume devices in the opposite order that we suspended them. + if [ -n "$NON_FLAKEY_LOGDEV" ]; then + $DMSETUP_PROG resume flakey-logtest + [ $? -ne 0 ] && _fatal "failed to resume flakey-logtest" + fi + + if [ -n "$NON_FLAKEY_RTDEV" ]; then + $DMSETUP_PROG resume flakey-rttest + [ $? -ne 0 ] && _fatal "failed to resume flakey-rttest" + fi + $DMSETUP_PROG resume flakey-test [ $? -ne 0 ] && _fatal "failed to resume flakey-test" } From patchwork Tue Jul 20 01:09:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12387193 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6A2C07E9B for ; Tue, 20 Jul 2021 01:17:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B129161164 for ; Tue, 20 Jul 2021 01:17:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243232AbhGTAbg (ORCPT ); Mon, 19 Jul 2021 20:31:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:41960 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381233AbhGTA3x (ORCPT ); Mon, 19 Jul 2021 20:29:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EA3B461181; Tue, 20 Jul 2021 01:09:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626743354; bh=Zprt2tY43kp5tFNaM73vJU/jSBiiiXwPjoDNecZd1Ak=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=DhxCgOxBRWT8Zr/BfmwV+tpT6qZpVyAkxTgtE3Q5uHIuLtobYabaqTtB7hIqHt9C3 GhkmXoMKPt6J6o5Y4Bz1llxHM93WLxPn+cYBMVqsLHwrhQs1E5D1mxeo+mlkI2Fyyy 2zi1qcbwHO9H47/DIl31u5UA01v7DS5fT8f51QxWFka1bea8lhFbegGFLBf/AcPObd KiRtmjij2EkJGlCV7TRuuS/0n9XZP/lL+wnuv7ToBd4Qpt0Wh400YS/g1oKRD0HJ+D Z5NHujoYcbEG6z6ocivzY6cWINuXvwiy4JjIf+MsuHs5ZLEvoU7QkIPvvqboICaGJD jNK2/TxrHEMmw== Subject: [PATCH 2/3] dmerror: export configuration so that subprograms don't have to reinit From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me, tytso@mit.edu Date: Mon, 19 Jul 2021 18:09:13 -0700 Message-ID: <162674335368.2651055.3174851724980962325.stgit@magnolia> In-Reply-To: <162674334277.2651055.14927938006488444114.stgit@magnolia> References: <162674334277.2651055.14927938006488444114.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Export the dmerror configuration variables so that subprograms don't have to reinitialize the configuration in their own subprograms before calling the helpers. In the next patch (where we allow dmerror for log and rt devices) it will become important to avoid these reinitializations. Signed-off-by: Darrick J. Wong --- common/dmerror | 8 +++++--- src/dmerror | 13 +++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/common/dmerror b/common/dmerror index 6f1bef09..7f6800c0 100644 --- a/common/dmerror +++ b/common/dmerror @@ -10,11 +10,11 @@ _dmerror_setup() local blk_dev_size=`blockdev --getsz $dm_backing_dev` - DMERROR_DEV='/dev/mapper/error-test' + export DMERROR_DEV='/dev/mapper/error-test' - DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0" + export DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0" - DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0" + export DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0" } _dmerror_init() @@ -42,6 +42,8 @@ _dmerror_cleanup() $DMSETUP_PROG resume error-test > /dev/null 2>&1 $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1 _dmsetup_remove error-test + + unset DMERROR_DEV DMLINEAR_TABLE DMERROR_TABLE } _dmerror_load_error_table() diff --git a/src/dmerror b/src/dmerror index c34d1a9a..cde2b428 100755 --- a/src/dmerror +++ b/src/dmerror @@ -5,15 +5,12 @@ . ./common/config . ./common/dmerror -_dmerror_setup +if [ -z "$DMERROR_DEV" ]; then + echo "Caller should have run _dmerror_init." + exit 1 +fi case $1 in -cleanup) - _dmerror_cleanup - ;; -init) - _dmerror_init - ;; load_error_table) _dmerror_load_error_table ;; @@ -21,7 +18,7 @@ load_working_table) _dmerror_load_working_table ;; *) - echo "Usage: $0 {init|cleanup|load_error_table|load_working_table}" + echo "Usage: $0 {load_error_table|load_working_table}" exit 1 ;; esac From patchwork Tue Jul 20 01:09:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 12387155 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB900C07E95 for ; Tue, 20 Jul 2021 01:12:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B83BA6113B for ; Tue, 20 Jul 2021 01:12:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381487AbhGTAbO (ORCPT ); Mon, 19 Jul 2021 20:31:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:41966 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1381242AbhGTA3x (ORCPT ); Mon, 19 Jul 2021 20:29:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 69B0361175; Tue, 20 Jul 2021 01:09:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1626743359; bh=+s9/DuENmuXRY7J2ilXWdgs3s2ehFml9rnPwk5EmVr0=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=KFjtLHRTtEKrUlbpVU0gJz5ACNWTpgXrJEyTICTjWWXP1XOXFjygIRibeiB6toS2E WNf2sP/UXnVQOpxFHJP6Vz6IGBqnzkYzH/TDAse6p9EeD0c0XgklNCZTu9GfFMcHJ8 kg42mRLJnB7vyw+79boO0U/JsCjxJfQ1rsHJ8d3C0k7T35QAYpXegxYxnxiJd/nyV3 1N/qXQ4UyQgBdyDmTjK+Y/F++tovFvKsTEJ417C29ya/zlWF60buuRZg8Qoo2BGF1o q8MnG2/ua6BXKAcupy5Y8fmPR+4IMPcq2FuoTxTzqwEXy3Hw0/6uFRwxtu0xFF+VTU DctykUKVxYVvA== Subject: [PATCH 3/3] dmflakey: support external log and realtime devices From: "Darrick J. Wong" To: djwong@kernel.org, guaneryu@gmail.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org, guan@eryu.me, tytso@mit.edu Date: Mon, 19 Jul 2021 18:09:19 -0700 Message-ID: <162674335915.2651055.17005305530614106697.stgit@magnolia> In-Reply-To: <162674334277.2651055.14927938006488444114.stgit@magnolia> References: <162674334277.2651055.14927938006488444114.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org From: Darrick J. Wong Upgrade the dmerror code to coordinate making external scratch log and scratch realtime devices error out along with the scratch device. Note that unlike SCRATCH_DEV, we save the old rt/log devices in a separate variable and overwrite SCRATCH_{RT,LOG}DEV so that all the helper functions continue to work properly. Signed-off-by: Darrick J. Wong --- common/dmerror | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++--- tests/generic/441 | 2 - tests/generic/487 | 2 - 3 files changed, 178 insertions(+), 12 deletions(-) diff --git a/common/dmerror b/common/dmerror index 7f6800c0..03f3fd97 100644 --- a/common/dmerror +++ b/common/dmerror @@ -4,30 +4,94 @@ # # common functions for setting up and tearing down a dmerror device +_dmerror_setup_vars() +{ + local backing_dev="$1" + local tag="$2" + local target="$3" + + test -z "$target" && target=error + local blk_dev_size=$(blockdev --getsz "$backing_dev") + + eval export "DMLINEAR_${tag}TABLE=\"0 $blk_dev_size linear $backing_dev 0\"" + eval export "DMERROR_${tag}TABLE=\"0 $blk_dev_size $target $backing_dev 0\"" +} + _dmerror_setup() { - local dm_backing_dev=$SCRATCH_DEV + local rt_target= + local linear_target= - local blk_dev_size=`blockdev --getsz $dm_backing_dev` + for arg in "$@"; do + case "${arg}" in + no_rt) rt_target=linear;; + no_log) log_target=linear;; + *) echo "${arg}: Unknown _dmerror_setup arg.";; + esac + done + # Scratch device export DMERROR_DEV='/dev/mapper/error-test' + _dmerror_setup_vars $SCRATCH_DEV - export DMLINEAR_TABLE="0 $blk_dev_size linear $dm_backing_dev 0" + # Realtime device. We reassign SCRATCH_RTDEV so that all the scratch + # helpers continue to work unmodified. + if [ -n "$SCRATCH_RTDEV" ]; then + if [ -z "$NON_ERROR_RTDEV" ]; then + # Set up the device switch + local dm_backing_dev=$SCRATCH_RTDEV + export NON_ERROR_RTDEV="$SCRATCH_RTDEV" + SCRATCH_RTDEV='/dev/mapper/error-rttest' + else + # Already set up; recreate tables + local dm_backing_dev="$NON_ERROR_RTDEV" + fi - export DMERROR_TABLE="0 $blk_dev_size error $dm_backing_dev 0" + _dmerror_setup_vars $dm_backing_dev RT $rt_target + fi + + # External log device. We reassign SCRATCH_LOGDEV so that all the + # scratch helpers continue to work unmodified. + if [ -n "$SCRATCH_LOGDEV" ]; then + if [ -z "$NON_ERROR_LOGDEV" ]; then + # Set up the device switch + local dm_backing_dev=$SCRATCH_LOGDEV + export NON_ERROR_LOGDEV="$SCRATCH_LOGDEV" + SCRATCH_LOGDEV='/dev/mapper/error-logtest' + else + # Already set up; recreate tables + local dm_backing_dev="$NON_ERROR_LOGDEV" + fi + + _dmerror_setup_vars $dm_backing_dev LOG $log_target + fi } _dmerror_init() { - _dmerror_setup + _dmerror_setup "$@" + _dmsetup_remove error-test _dmsetup_create error-test --table "$DMLINEAR_TABLE" || \ _fatal "failed to create dm linear device" + + if [ -n "$NON_ERROR_RTDEV" ]; then + _dmsetup_remove error-rttest + _dmsetup_create error-rttest --table "$DMLINEAR_RTTABLE" || \ + _fatal "failed to create dm linear rt device" + fi + + if [ -n "$NON_ERROR_LOGDEV" ]; then + _dmsetup_remove error-logtest + _dmsetup_create error-logtest --table "$DMLINEAR_LOGTABLE" || \ + _fatal "failed to create dm linear log device" + fi } _dmerror_mount() { _scratch_options mount + $MOUNT_PROG -t $FSTYP `_common_dev_mount_options $*` $SCRATCH_OPTIONS \ $DMERROR_DEV $SCRATCH_MNT } @@ -39,11 +103,23 @@ _dmerror_unmount() _dmerror_cleanup() { + test -n "$NON_ERROR_LOGDEV" && $DMSETUP_PROG resume error-logtest &>/dev/null + test -n "$NON_ERROR_RTDEV" && $DMSETUP_PROG resume error-rttest &>/dev/null $DMSETUP_PROG resume error-test > /dev/null 2>&1 + $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1 + + test -n "$NON_ERROR_LOGDEV" && _dmsetup_remove error-logtest + test -n "$NON_ERROR_RTDEV" && _dmsetup_remove error-rttest _dmsetup_remove error-test unset DMERROR_DEV DMLINEAR_TABLE DMERROR_TABLE + + SCRATCH_LOGDEV="$NON_ERROR_LOGDEV" + unset NON_ERROR_LOGDEV DMLINEAR_LOGTABLE DMERROR_LOGTABLE + + SCRATCH_RTDEV="$NON_ERROR_RTDEV" + unset NON_ERROR_RTDEV DMLINEAR_RTTABLE DMERROR_RTTABLE } _dmerror_load_error_table() @@ -59,12 +135,47 @@ _dmerror_load_error_table() suspend_opt="$*" fi + # Suspend the scratch device before the log and realtime devices so + # that the kernel can freeze and flush the filesystem if the caller + # wanted a freeze. $DMSETUP_PROG suspend $suspend_opt error-test [ $? -ne 0 ] && _fail "dmsetup suspend failed" + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt error-rttest + [ $? -ne 0 ] && _fail "failed to suspend error-rttest" + fi + + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt error-logtest + [ $? -ne 0 ] && _fail "failed to suspend error-logtest" + fi + + # Load new table echo "$DMERROR_TABLE" | $DMSETUP_PROG load error-test load_res=$? + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG load error-rttest --table "$DMERROR_RTTABLE" + [ $? -ne 0 ] && _fail "failed to load error table into error-rttest" + fi + + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG load error-logtest --table "$DMERROR_LOGTABLE" + [ $? -ne 0 ] && _fail "failed to load error table into error-logtest" + fi + + # Resume devices in the opposite order that we suspended them. + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG resume error-logtest + [ $? -ne 0 ] && _fail "failed to resume error-logtest" + fi + + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG resume error-rttest + [ $? -ne 0 ] && _fail "failed to resume error-rttest" + fi + $DMSETUP_PROG resume error-test resume_res=$? @@ -85,12 +196,47 @@ _dmerror_load_working_table() suspend_opt="$*" fi + # Suspend the scratch device before the log and realtime devices so + # that the kernel can freeze and flush the filesystem if the caller + # wanted a freeze. $DMSETUP_PROG suspend $suspend_opt error-test [ $? -ne 0 ] && _fail "dmsetup suspend failed" + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt error-rttest + [ $? -ne 0 ] && _fail "failed to suspend error-rttest" + fi + + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG suspend $suspend_opt error-logtest + [ $? -ne 0 ] && _fail "failed to suspend error-logtest" + fi + + # Load new table $DMSETUP_PROG load error-test --table "$DMLINEAR_TABLE" load_res=$? + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG load error-rttest --table "$DMLINEAR_RTTABLE" + [ $? -ne 0 ] && _fail "failed to load working table into error-rttest" + fi + + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG load error-logtest --table "$DMLINEAR_LOGTABLE" + [ $? -ne 0 ] && _fail "failed to load working table into error-logtest" + fi + + # Resume devices in the opposite order that we suspended them. + if [ -n "$NON_ERROR_LOGDEV" ]; then + $DMSETUP_PROG resume error-logtest + [ $? -ne 0 ] && _fail "failed to resume error-logtest" + fi + + if [ -n "$NON_ERROR_RTDEV" ]; then + $DMSETUP_PROG resume error-rttest + [ $? -ne 0 ] && _fail "failed to resume error-rttest" + fi + $DMSETUP_PROG resume error-test resume_res=$? @@ -157,20 +303,36 @@ __dmerror_recreate_map() # Update the dm error table so that the range (start, len) maps to the # preferred dm target, overriding anything that maps to the implied dm target. # This assumes that the only desired targets for this dm device are the -# preferred and and implied targets. +# preferred and and implied targets. The fifth argument is the scratch device +# that we want to change the table for. __dmerror_change() { local start="$1" local len="$2" local preferred_tgt="$3" local implied_tgt="$4" + local whichdev="$5" + test -z "$whichdev" && whichdev="$SCRATCH_DEV" - DMERROR_TABLE="$( (echo "$DMERROR_TABLE"; echo "$start $len $preferred_tgt") | \ + case "$whichdev" in + "$SCRATCH_DEV") old_table="$DMERROR_TABLE";; + "$NON_ERROR_LOGDEV") old_table="$DMERROR_LOGTABLE";; + "$NON_ERROR_RTDEV") old_table="$DMERROR_RTTABLE";; + *) echo "$whichdev: Unknown dmerror device."; return;; + esac + + new_table="$( (echo "$old_table"; echo "$start $len $preferred_tgt") | \ awk -v type="$preferred_tgt" '{if ($3 == type) print $0;}' | \ sort -g | \ __dmerror_combine_extents | \ - __dmerror_recreate_map "$SCRATCH_DEV" "$preferred_tgt" \ + __dmerror_recreate_map "$whichdev" "$preferred_tgt" \ "$implied_tgt" )" + + case "$whichdev" in + "$SCRATCH_DEV") DMERROR_TABLE="$new_table";; + "$NON_ERROR_LOGDEV") DMERROR_LOGTABLE="$new_table";; + "$NON_ERROR_RTDEV") DMERROR_RTTABLE="$new_table";; + esac } # Reset the dm error table to everything ok. The dm device itself must be @@ -178,6 +340,8 @@ __dmerror_change() _dmerror_reset_table() { DMERROR_TABLE="$DMLINEAR_TABLE" + DMERROR_LOGTABLE="$DMLINEAR_LOGTABLE" + DMERROR_RTTABLE="$DMLINEAR_RTTABLE" } # Update the dm error table so that IOs to the given range will return EIO. @@ -186,8 +350,9 @@ _dmerror_mark_range_bad() { local start="$1" local len="$2" + local dev="$3" - __dmerror_change "$start" "$len" error linear + __dmerror_change "$start" "$len" error linear "$dev" } # Update the dm error table so that IOs to the given range will succeed. @@ -196,6 +361,7 @@ _dmerror_mark_range_good() { local start="$1" local len="$2" + local dev="$3" - __dmerror_change "$start" "$len" linear error + __dmerror_change "$start" "$len" linear error "$dev" } diff --git a/tests/generic/441 b/tests/generic/441 index 0ec751da..85f29a3a 100755 --- a/tests/generic/441 +++ b/tests/generic/441 @@ -52,7 +52,7 @@ unset SCRATCH_RTDEV echo "Format and mount" _scratch_mkfs > $seqres.full 2>&1 -_dmerror_init +_dmerror_init no_log _dmerror_mount _require_fs_space $SCRATCH_MNT 65536 diff --git a/tests/generic/487 b/tests/generic/487 index fda8828d..3c9b2233 100755 --- a/tests/generic/487 +++ b/tests/generic/487 @@ -45,7 +45,7 @@ unset SCRATCH_RTDEV echo "Format and mount" _scratch_mkfs > $seqres.full 2>&1 -_dmerror_init +_dmerror_init no_log _dmerror_mount datalen=65536