From patchwork Mon Apr 22 15:45:02 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: 10911205 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 59EFE14DB for ; Mon, 22 Apr 2019 15:45:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47104280CF for ; Mon, 22 Apr 2019 15:45:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3B58C283CF; Mon, 22 Apr 2019 15:45:06 +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=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 D04DF280CF for ; Mon, 22 Apr 2019 15:45:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727309AbfDVPpF (ORCPT ); Mon, 22 Apr 2019 11:45:05 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:43820 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726132AbfDVPpF (ORCPT ); Mon, 22 Apr 2019 11:45:05 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3MFi2jc042696; Mon, 22 Apr 2019 15:45:02 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=iGTJ517+wtiIvbARchgrY79V/Wv8aSvg3NuSoII9z+0=; b=ogppEaN6skipRXVQv42XFj/OhHY1pucN3dNeILszX/NqfqH4+ibXw/iNR2Lzy/QeeNP2 8iKhCnfHcAh4IlZbssvGuWmPKdsiwzkHTRi+eeK8yPIeTeKb84co1AFzHGFXL88UNVnI 8bEo4kSpfK4icfAng4fC+rtrAKewir03x+IWgUvN/ljix4DvLHgFTALehYDPKjjCGmRG jYhYorNZW+IFwQtLGUjRgWC7IdscV80kr4NykfrqQdRs4yAEi2IJ8igF6WlKt8T6cVDR KDMpK9xW2v14kim56AcYoPd7hcjL3somY6A3PPIrmYHcf2GslTP5jd2MAGvg7fuJ+VM1 wQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 2rytusq07u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Apr 2019 15:45:02 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x3MFijka157748; Mon, 22 Apr 2019 15:45:02 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3020.oracle.com with ESMTP id 2s0dwds0p4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Apr 2019 15:45:02 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x3MFj1tO030094; Mon, 22 Apr 2019 15:45:01 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 22 Apr 2019 08:45:01 -0700 Subject: [PATCH 02/10] xfs_info: use findmnt to handle mounted block devices From: "Darrick J. Wong" To: sandeen@sandeen.net, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Mon, 22 Apr 2019 08:45:02 -0700 Message-ID: <155594790268.115924.87682432738525436.stgit@magnolia> In-Reply-To: <155594788997.115924.16224143537288136652.stgit@magnolia> References: <155594788997.115924.16224143537288136652.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9235 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 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-1810050000 definitions=main-1904220118 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9235 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-1904220119 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 Use findmnt to determine if the passed-in argument is associated with a mount point, and if so, use spaceman to query the mounted filesystem. If the user passed in a file, try to find out if it's a loop mounted live filesystem and if so query the live filesystem. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen Reviewed-by: Bill O'Donnell --- debian/control | 2 +- spaceman/xfs_info.sh | 22 +++++++++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/debian/control b/debian/control index f4f807b0..0b3205f5 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Standards-Version: 4.0.0 Homepage: https://xfs.wiki.kernel.org/ Package: xfsprogs -Depends: ${shlibs:Depends}, ${misc:Depends}, python3:any +Depends: ${shlibs:Depends}, ${misc:Depends}, python3:any, util-linux Provides: fsck-backend Suggests: xfsdump, acl, attr, quota Breaks: xfsdump (<< 3.0.0) diff --git a/spaceman/xfs_info.sh b/spaceman/xfs_info.sh index ecf17f61..1bf6d2c3 100755 --- a/spaceman/xfs_info.sh +++ b/spaceman/xfs_info.sh @@ -7,6 +7,14 @@ OPTS="" USAGE="Usage: xfs_info [-V] [-t mtab] [mountpoint|device|file]" +# Try to find a loop device associated with a file. We only want to return +# one loopdev (multiple loop devices can attach to a single file) so we grab +# the last line and return it if it's actually a block device. +try_find_loop_dev_for_file() { + local x="$(losetup -O NAME -j "$1" 2> /dev/null | tail -n 1)" + test -b "$x" && echo "$x" +} + while getopts "t:V" c do case $c in @@ -24,11 +32,19 @@ set -- extra "$@" shift $OPTIND case $# in 1) - if [ -b "$1" ] || [ -f "$1" ]; then - xfs_db -p xfs_info -c "info" $OPTS "$1" + arg="$1" + + # See if we can map the arg to a loop device + loopdev="$(try_find_loop_dev_for_file "${arg}")" + test -n "${loopdev}" && arg="${loopdev}" + + # If we find a mountpoint for the device, do a live query; + # otherwise try reading the fs with xfs_db. + if mountpt="$(findmnt -f -n -o TARGET "${arg}" 2> /dev/null)"; then + xfs_spaceman -p xfs_info -c "info" $OPTS "${mountpt}" status=$? else - xfs_spaceman -p xfs_info -c "info" $OPTS "$1" + xfs_db -p xfs_info -c "info" $OPTS "${arg}" status=$? fi ;;