From patchwork Tue Mar 20 03:08:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 10296163 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 9F77B605B4 for ; Tue, 20 Mar 2018 03:08:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8DFF5290E0 for ; Tue, 20 Mar 2018 03:08:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8266B290F9; Tue, 20 Mar 2018 03:08:45 +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.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, 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 B6A50290E0 for ; Tue, 20 Mar 2018 03:08:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751249AbeCTDIo (ORCPT ); Mon, 19 Mar 2018 23:08:44 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:38740 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750921AbeCTDIn (ORCPT ); Mon, 19 Mar 2018 23:08:43 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2K2ldM0146702; Tue, 20 Mar 2018 03:08:40 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-2017-10-26; bh=cmy+gDTyWaJGqDR5vr92awNb/fS1i6d9f7bxNCGjQGE=; b=PeBE44O5/J7jwG/NgO43iUrIEftUnqF1zUNk9CEKyN9zJuBvzUxIsmwvrWX8pzcK93Q5 EbOsDe7kNBc1bTLEKRZZxs/XKJZc7qdIt9voyhw9Y2ixfKzoi5qyDIhsfqgpUxCOd7Mt 8JtgjnPINn2bVi1Fgcdu0z9HSXmHapBiwqpFrlD3IXytQjQoXFuXSkJLOsBHVnsHOGNJ D0qBQwDDhKylSeDA2HUKTQYi672ymZ+hhTGh5+Pjn3jEE/HDL4qWPAM2B6Xc+FVkYKZK GieY0Pr7+0TWUbIyHT3YksX6oPB1dxY+9hFgMiVEQO2tJD2BFMtlkoQ1/lPv9+8spV+g EA== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2120.oracle.com with ESMTP id 2gtstsr1cj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Mar 2018 03:08:40 +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 w2K38eXh008658 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 20 Mar 2018 03:08:40 GMT Received: from abhmp0016.oracle.com (abhmp0016.oracle.com [141.146.116.22]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w2K38d8N030143; Tue, 20 Mar 2018 03:08:39 GMT Received: from localhost (/67.169.218.210) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 19 Mar 2018 20:08:39 -0700 Subject: [PATCH 3/4] xfs_fsr: refactor mountpoint finding to use libfrog paths functions From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Mon, 19 Mar 2018 20:08:38 -0700 Message-ID: <152151531831.18312.9201377632555740636.stgit@magnolia> In-Reply-To: <152151529988.18312.2660325658864402943.stgit@magnolia> References: <152151529988.18312.2660325658864402943.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8837 signatures=668693 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-1711220000 definitions=main-1803200006 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 the mount-point finding code in fsr to use the libfrog helpers instead of open-coding yet another routine. Signed-off-by: Darrick J. Wong --- fsr/Makefile | 4 ++- fsr/xfs_fsr.c | 71 +++++-------------------------------------------------- include/path.h | 1 + libfrog/paths.c | 47 ++++++++++++++++++++++++++++-------- 4 files changed, 47 insertions(+), 76 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fsr/Makefile b/fsr/Makefile index d3521b2..fc1c33b 100644 --- a/fsr/Makefile +++ b/fsr/Makefile @@ -7,7 +7,9 @@ include $(TOPDIR)/include/builddefs LTCOMMAND = xfs_fsr CFILES = xfs_fsr.c -LLDLIBS = $(LIBHANDLE) +LLDLIBS = $(LIBHANDLE) $(LIBFROG) +LTDEPENDENCIES = $(LIBFROG) +LLDFLAGS = -static-libtool-libs ifeq ($(HAVE_GETMNTENT),yes) LCFLAGS += -DHAVE_GETMNTENT diff --git a/fsr/xfs_fsr.c b/fsr/xfs_fsr.c index 2a18ce0..ef6a68f 100644 --- a/fsr/xfs_fsr.c +++ b/fsr/xfs_fsr.c @@ -22,6 +22,7 @@ #include "jdm.h" #include "xfs_bmap_btree.h" #include "xfs_attr_sf.h" +#include "path.h" #include #include @@ -167,73 +168,13 @@ aborter(int unused) exit(1); } -/* - * Check if the argument is either the device name or mountpoint of an XFS - * filesystem. Note that we do not care about bind mounted regular files - * here - the code that handles defragmentation of invidual files takes care - * of that. - */ -static char * -find_mountpoint_check(struct stat *sb, struct mntent *t) -{ - struct stat ms; - - if (S_ISDIR(sb->st_mode)) { /* mount point */ - if (stat(t->mnt_dir, &ms) < 0) - return NULL; - if (sb->st_ino != ms.st_ino) - return NULL; - if (sb->st_dev != ms.st_dev) - return NULL; - if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0) - return NULL; - } else { /* device */ - if (stat(t->mnt_fsname, &ms) < 0) - return NULL; - if (sb->st_rdev != ms.st_rdev) - return NULL; - if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0) - return NULL; - /* - * Make sure the mountpoint given by mtab is accessible - * before using it. - */ - if (stat(t->mnt_dir, &ms) < 0) - return NULL; - } - - return t->mnt_dir; -} - -static char * -find_mountpoint(char *mtab, char *argname, struct stat *sb) -{ - struct mntent_cursor cursor; - struct mntent *t = NULL; - char *mntp = NULL; - - if (platform_mntent_open(&cursor, mtab) != 0){ - fprintf(stderr, "Error: can't get mntent entries.\n"); - exit(1); - } - - while ((t = platform_mntent_next(&cursor)) != NULL) { - mntp = find_mountpoint_check(sb, t); - if (mntp == NULL) - continue; - break; - } - platform_mntent_close(&cursor); - return mntp; -} - int main(int argc, char **argv) { struct stat sb; char *argname; int c; - char *mntp; + struct fs_path *fsp; char *mtab = NULL; setlinebuf(stdout); @@ -343,9 +284,11 @@ main(int argc, char **argv) sb = sb2; } - mntp = find_mountpoint(mtab, argname, &sb); - if (mntp != NULL) { - fsrfs(mntp, 0, 100); + fsp = fs_table_lookup_mount(argname); + if (!fsp) + fsp = fs_table_lookup_blkdev(argname); + if (fsp != NULL) { + fsrfs(fsp->fs_dir, 0, 100); } else if (S_ISCHR(sb.st_mode)) { fprintf(stderr, _( "%s: char special not supported: %s\n"), diff --git a/include/path.h b/include/path.h index 1d3a902..88dc44b 100644 --- a/include/path.h +++ b/include/path.h @@ -57,6 +57,7 @@ extern void fs_table_insert_project_path(char *__dir, uint __projid); extern fs_path_t *fs_table_lookup(const char *__dir, uint __flags); extern fs_path_t *fs_table_lookup_mount(const char *__dir); +extern fs_path_t *fs_table_lookup_blkdev(const char *bdev); typedef struct fs_cursor { uint count; /* total count of mount entries */ diff --git a/libfrog/paths.c b/libfrog/paths.c index 19ee1ea..a80a30b 100644 --- a/libfrog/paths.c +++ b/libfrog/paths.c @@ -89,15 +89,10 @@ fs_table_lookup( return NULL; } -/* - * Find the FS table entry describing an actual mount for the given path. - * Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" - * argument to actual mount point entries in the table. Accordingly, it - * will find matches only if the "dir" argument is indeed mounted. - */ -struct fs_path * -fs_table_lookup_mount( - const char *dir) +static struct fs_path * +__fs_table_lookup_mount( + const char *dir, + const char *blkdev) { uint i; dev_t dev = 0; @@ -106,13 +101,17 @@ fs_table_lookup_mount( if (fs_device_number(dir, &dev)) return NULL; - if (!realpath(dir, dpath)) + if (dir && !realpath(dir, dpath)) + return NULL; + if (blkdev && !realpath(blkdev, dpath)) return NULL; for (i = 0; i < fs_count; i++) { if (fs_table[i].fs_flags != FS_MOUNT_POINT) continue; - if (!realpath(fs_table[i].fs_dir, rpath)) + if (dir && !realpath(fs_table[i].fs_dir, rpath)) + continue; + if (blkdev && !realpath(fs_table[i].fs_name, rpath)) continue; if (strcmp(rpath, dpath) == 0) return &fs_table[i]; @@ -120,6 +119,32 @@ fs_table_lookup_mount( return NULL; } +/* + * Find the FS table entry describing an actual mount for the given path. + * Unlike fs_table_lookup(), fs_table_lookup_mount() compares the "dir" + * argument to actual mount point entries in the table. Accordingly, it + * will find matches only if the "dir" argument is indeed mounted. + */ +struct fs_path * +fs_table_lookup_mount( + const char *dir) +{ + return __fs_table_lookup_mount(dir, NULL); +} + +/* + * Find the FS table entry describing an actual mount for the block device. + * Unlike fs_table_lookup(), fs_table_lookup_blkdev() compares the "bdev" + * argument to actual mount point names in the table. Accordingly, it + * will find matches only if the "bdev" argument is indeed mounted. + */ +struct fs_path * +fs_table_lookup_blkdev( + const char *bdev) +{ + return __fs_table_lookup_mount(NULL, bdev); +} + static int fs_table_insert( char *dir,