From patchwork Wed Mar 20 00:45:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10860631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 047831669 for ; Wed, 20 Mar 2019 00:45:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6B9329987 for ; Wed, 20 Mar 2019 00:45:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DAC4A2998C; Wed, 20 Mar 2019 00:45:33 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 81E002998B for ; Wed, 20 Mar 2019 00:45:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727406AbfCTApd (ORCPT ); Tue, 19 Mar 2019 20:45:33 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:57502 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726801AbfCTApc (ORCPT ); Tue, 19 Mar 2019 20:45:32 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x2K0cZXw008238; Wed, 20 Mar 2019 00:45:30 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-2018-07-02; bh=NJUDaziGzizIgoo3DtBlDSMt5SGjPsgwp5P2meRz59M=; b=r7YZ8PM0ce9D/2sGah3nPdzoPGxrgUFOi/8pxJO35KQcK/+F78JerQheYN/aj9rfiIPV hS9eLQgSy8tSHneUaBray1tnszv7WOAud5yF9BGoWkSeYP+RJkxEO/ymufe6zocWkp/N bWIe8L4jzkheCSAx6NOcFCH0DlbtyD3ZAT4sg+ZhqBuYAXJl5r7GT7Pu4IJnLJOHnLBG WRoBbgLxclixbfpEXKmFD8sVkDnbj4GcsFfQpky+ygIQW8POKsPSB2AneCsr51SE/Ctx 4x9FLYoCPyKtbJlaBZKH+lHY6+cxWDbphx81x91mBTGsVnmlQRDiSithNJN/5AgpXS/T uw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2r8pner3yr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Mar 2019 00:45:29 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x2K0jTxd016701 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Mar 2019 00:45:29 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x2K0jShD027305; Wed, 20 Mar 2019 00:45:28 GMT Received: from localhost (/10.159.245.168) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 19 Mar 2019 17:45:28 -0700 Subject: [PATCH 07/12] common/populate: refactor _scratch_populate_cached From: "Darrick J. Wong" To: guaneryu@gmail.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org, fstests@vger.kernel.org Date: Tue, 19 Mar 2019 17:45:28 -0700 Message-ID: <155304272879.31707.4358538241141797662.stgit@magnolia> In-Reply-To: <155304267647.31707.14180452399822113095.stgit@magnolia> References: <155304267647.31707.14180452399822113095.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9200 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1903200003 Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Darrick J. Wong Refactor _scratch_populate_cached into smaller helper functions. Signed-off-by: Darrick J. Wong --- common/populate | 69 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 26 deletions(-) diff --git a/common/populate b/common/populate index 95953476..1f921ac5 100644 --- a/common/populate +++ b/common/populate @@ -765,20 +765,14 @@ _fill_fs() done } -# Populate a scratch FS from scratch or from a cached image. -_scratch_populate_cached() { - POPULATE_METADUMP="${TEST_DIR}/__populate.${FSTYP}" - POPULATE_METADUMP_DESCR="${TEST_DIR}/__populate.${FSTYP}.txt" - - # Don't keep metadata images cached for more 48 hours... - rm -rf "$(find "${POPULATE_METADUMP}" -mtime +2 2>/dev/null)" +# Compute the fs geometry description of a populated filesystem +_scratch_populate_cache_tag() { + local extra_descr="" + local size="$(blockdev --getsz "${SCRATCH_DEV}")" - # Throw away cached image if it doesn't match our spec. case "${FSTYP}" in "ext4") extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL}" - # ext4 cannot e2image external logs, so we cannot restore - test -n "${SCRATCH_LOGDEV}" && rm -f "${POPULATE_METADUMP}" ;; "xfs") extra_descr="LOGDEV ${SCRATCH_LOGDEV} USE_EXTERNAL ${USE_EXTERNAL} RTDEV ${SCRATCH_RTDEV}" @@ -787,23 +781,46 @@ _scratch_populate_cached() { extra_descr="${extra_descr} QUOTAS" fi ;; - *) - extra_descr="";; esac - meta_descr="FSTYP ${FSTYP} MKFS_OPTIONS ${MKFS_OPTIONS} SIZE $(blockdev --getsz "${SCRATCH_DEV}") ${extra_descr} ARGS $@" - cmp -s "${POPULATE_METADUMP_DESCR}" <(echo "${meta_descr}") || rm -rf "${POPULATE_METADUMP}" - - # Do we have a cached image? - if [ -r "${POPULATE_METADUMP}" ]; then - case "${FSTYP}" in - "xfs") - xfs_mdrestore "${POPULATE_METADUMP}" "${SCRATCH_DEV}" && return - ;; - "ext2"|"ext3"|"ext4") - e2image -r "${POPULATE_METADUMP}" "${SCRATCH_DEV}" && return - ;; - esac - fi + echo "FSTYP ${FSTYP} MKFS_OPTIONS ${MKFS_OPTIONS} SIZE ${size} ${extra_descr} ARGS $@" +} + +# Restore a cached populated fs from a metadata dump +_scratch_populate_restore_cached() { + local metadump="$1" + + case "${FSTYP}" in + "xfs") + xfs_mdrestore "${metadump}" "${SCRATCH_DEV}" && return 0 + ;; + "ext2"|"ext3"|"ext4") + # ext4 cannot e2image external logs, so we cannot restore + test -n "${SCRATCH_LOGDEV}" && return 1 + e2image -r "${metadump}" "${SCRATCH_DEV}" && return 0 + ;; + esac + return 1 +} + +# Populate a scratch FS from scratch or from a cached image. +_scratch_populate_cached() { + local meta_descr="$(_scratch_populate_cache_tag "$@")" + + # These variables are shared outside this function + POPULATE_METADUMP="${TEST_DIR}/__populate.${FSTYP}" + POPULATE_METADUMP_DESCR="${TEST_DIR}/__populate.${FSTYP}.txt" + + # Don't keep metadata images cached for more 48 hours... + rm -rf "$(find "${POPULATE_METADUMP}" -mtime +2 2>/dev/null)" + + # Throw away cached image if it doesn't match our spec. + cmp -s "${POPULATE_METADUMP_DESCR}" <(echo "${meta_descr}") || \ + rm -rf "${POPULATE_METADUMP}" + + # Try to restore from the metadump + test -r "${POPULATE_METADUMP}" && \ + _scratch_populate_restore_cached "${POPULATE_METADUMP}" && \ + return # Oh well, just create one from scratch _scratch_mkfs