From patchwork Thu Jun 30 12:49:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brian Foster X-Patchwork-Id: 9207433 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA53C6075A for ; Thu, 30 Jun 2016 12:49:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CC1D327FAB for ; Thu, 30 Jun 2016 12:49:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0FEA2867D; Thu, 30 Jun 2016 12:49:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D10D27FAB for ; Thu, 30 Jun 2016 12:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752219AbcF3Mti (ORCPT ); Thu, 30 Jun 2016 08:49:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43627 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752205AbcF3Mtg (ORCPT ); Thu, 30 Jun 2016 08:49:36 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02A35C049D5C for ; Thu, 30 Jun 2016 12:49:36 +0000 (UTC) Received: from bfoster.bfoster (dhcp-41-180.bos.redhat.com [10.18.41.180]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5UCnZvx019399 for ; Thu, 30 Jun 2016 08:49:35 -0400 Received: by bfoster.bfoster (Postfix, from userid 1000) id 659EB1200DA; Thu, 30 Jun 2016 08:49:34 -0400 (EDT) From: Brian Foster To: fstests@vger.kernel.org Subject: [PATCH 1/2] xfstests: support dm-delay to introduce I/O delays Date: Thu, 30 Jun 2016 08:49:33 -0400 Message-Id: <1467290974-13203-2-git-send-email-bfoster@redhat.com> In-Reply-To: <1467290974-13203-1-git-send-email-bfoster@redhat.com> References: <1467290974-13203-1-git-send-email-bfoster@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 30 Jun 2016 12:49:36 +0000 (UTC) Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add some infrastructure in common/dmdelay to support use of the dm-delay device-mapper module within tests. This is effectively copied from the existing infrastructure in common/dmflakey. This provides the ability to delay I/O. It only supports delaying read I/O as that is all that is required at this point in time. Signed-off-by: Brian Foster --- common/dmdelay | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 common/dmdelay diff --git a/common/dmdelay b/common/dmdelay new file mode 100644 index 0000000..c53e2dd --- /dev/null +++ b/common/dmdelay @@ -0,0 +1,89 @@ +##/bin/bash +# +# Copyright (c) 2016 Red Hat, Inc. All Rights Reserved. +# +# 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. +# +# 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 +# +# +# common functions for setting up and tearing down a dmdelay device + +DELAY_NONE=0 +DELAY_READ=1 + +echo $MOUNT_OPTIONS | grep -q dax +if [ $? -eq 0 ]; then + _notrun "Cannot run tests with DAX on dmdelay devices" +fi + +_init_delay() +{ + local BLK_DEV_SIZE=`blockdev --getsz $SCRATCH_DEV` + DELAY_DEV=/dev/mapper/delay-test + DELAY_TABLE="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 0" + DELAY_TABLE_RDELAY="0 $BLK_DEV_SIZE delay $SCRATCH_DEV 0 10000 $SCRATCH_DEV 0 0" + $DMSETUP_PROG create delay-test --table "$DELAY_TABLE" || \ + _fatal "failed to create delay device" + $DMSETUP_PROG mknodes > /dev/null 2>&1 +} + +_mount_delay() +{ + _scratch_options mount + mount -t $FSTYP $SCRATCH_OPTIONS $MOUNT_OPTIONS $DELAY_DEV $SCRATCH_MNT +} + +_unmount_delay() +{ + $UMOUNT_PROG $SCRATCH_MNT +} + +_cleanup_delay() +{ + # If dmsetup load fails then we need to make sure to do resume here + # otherwise the umount will hang + $DMSETUP_PROG resume delay-test > /dev/null 2>&1 + $UMOUNT_PROG $SCRATCH_MNT > /dev/null 2>&1 + # wait for device to be fully settled so that 'dmsetup remove' doesn't + # fail due to EBUSY + $UDEV_SETTLE_PROG >/dev/null 2>&1 + $DMSETUP_PROG remove delay-test > /dev/null 2>&1 + $DMSETUP_PROG mknodes > /dev/null 2>&1 +} + +# _load_delay_table [lockfs] +# +# This defaults to --nolockfs, which doesn't freeze_fs() before loading the new +# table, so it simulates power failure. +_load_delay_table() +{ + table="$DELAY_TABLE" + [ $1 -eq $DELAY_READ ] && table="$DELAY_TABLE_RDELAY" + + suspend_opt="--nolockfs" + [ $# -gt 1 ] && [ $2 -eq 1 ] && suspend_opt="" + + # run a suspend/resume cycle to avoid excessive resume delays once a + # delay is introduced below + $DMSETUP_PROG suspend $suspend_opt delay-test + $DMSETUP_PROG resume $suspend_opt delay-test + + $DMSETUP_PROG suspend $suspend_opt delay-test + [ $? -ne 0 ] && _fatal "failed to suspend delay-test" + + $DMSETUP_PROG load delay-test --table "$table" + [ $? -ne 0 ] && _fatal "failed to load table into delay-test" + + $DMSETUP_PROG resume delay-test + [ $? -ne 0 ] && _fatal "failed to resume delay-test" +}