From patchwork Wed Mar 21 03:40:42 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: 10298505 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 9A4D260349 for ; Wed, 21 Mar 2018 03:40:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 881AE295F9 for ; Wed, 21 Mar 2018 03:40:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C1E02963F; Wed, 21 Mar 2018 03:40: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.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 AA22029621 for ; Wed, 21 Mar 2018 03:40:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751828AbeCUDkr (ORCPT ); Tue, 20 Mar 2018 23:40:47 -0400 Received: from aserp2130.oracle.com ([141.146.126.79]:41204 "EHLO aserp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751687AbeCUDkq (ORCPT ); Tue, 20 Mar 2018 23:40:46 -0400 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w2L3W1FL027235; Wed, 21 Mar 2018 03:40:44 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=rjLrPpv9WqaRYFzTd8/b6aPlzNkjGRVwDsd9027kteo=; b=OxAicMoNO9cS7ZqYTcFbS09MxSBYcWQr2gnIe5c/KSulV/BWQU0SVpxIH33pvExQmqMf FHa3L+QLTfczdaXs8I8T4hvKTZdcg+7slAixxpSnvDnKfsEijrhDnhsdFN2Y5iAX/y7U OTwMl+aBq5kuavfUMCPwDQeYNeckhjOzzRpIkJ7vIG4Sw+D7+i7oR8YMCjN90w2bszYU TpHbCDPoxy03Lk9KD7PkTAipXPGkuQfomvIDS4ur6fWGx7U89ah3DBcckW9Qp7wTPJry FQQzRFAhpwl+mvexzBqyejQF9i0XUmAlj8tZY5E7b8fYYRVjCCwTUrJjA9djXGib3S2o 2A== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by aserp2130.oracle.com with ESMTP id 2gufjqr0hu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 03:40:44 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id w2L3eh0m007326 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 21 Mar 2018 03:40:43 GMT Received: from abhmp0014.oracle.com (abhmp0014.oracle.com [141.146.116.20]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id w2L3ehfu025151; Wed, 21 Mar 2018 03:40:43 GMT Received: from localhost (/10.159.242.221) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 20 Mar 2018 20:40:42 -0700 Subject: [PATCH 10/14] xfs_scrub: refactor mountpoint finding code to use libfrog path code From: "Darrick J. Wong" To: sandeen@redhat.com, darrick.wong@oracle.com Cc: linux-xfs@vger.kernel.org Date: Tue, 20 Mar 2018 20:40:42 -0700 Message-ID: <152160364198.8288.1222538238075511907.stgit@magnolia> In-Reply-To: <152160358015.8288.2700156777231657519.stgit@magnolia> References: <152160358015.8288.2700156777231657519.stgit@magnolia> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8838 signatures=668695 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=2 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-1803200127 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 the libfrog path finding code to determine if the argument being passed in is a mountpoint, remove all mention of taking a block device (we have never supported that) from the documentation, and fix some potential memory leaks. Signed-off-by: Darrick J. Wong Reviewed-by: Eric Sandeen --- man/man8/xfs_scrub.8 | 2 + scrub/common.c | 69 -------------------------------------------------- scrub/common.h | 1 - scrub/phase1.c | 12 --------- scrub/xfs_scrub.c | 19 +++++++------- scrub/xfs_scrub.h | 1 - 6 files changed, 10 insertions(+), 94 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/man/man8/xfs_scrub.8 b/man/man8/xfs_scrub.8 index 77fed92..680ef72 100644 --- a/man/man8/xfs_scrub.8 +++ b/man/man8/xfs_scrub.8 @@ -6,7 +6,7 @@ xfs_scrub \- check the contents of a mounted XFS filesystem [ .B \-abCemnTvx ] -.RI "[" mount-point " | " block-device "]" +.I mount-point .br .B xfs_scrub \-V .SH DESCRIPTION diff --git a/scrub/common.c b/scrub/common.c index 5a37a98..722bf36 100644 --- a/scrub/common.c +++ b/scrub/common.c @@ -267,75 +267,6 @@ scrub_nproc_workqueue( } /* - * Check if the argument is either the device name or mountpoint of a mounted - * filesystem. - */ -#define MNTTYPE_XFS "xfs" -static bool -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 false; - if (sb->st_ino != ms.st_ino) - return false; - if (sb->st_dev != ms.st_dev) - return false; - if (strcmp(t->mnt_type, MNTTYPE_XFS) != 0) - return NULL; - } else { /* device */ - if (stat(t->mnt_fsname, &ms) < 0) - return false; - if (sb->st_rdev != ms.st_rdev) - return false; - 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 false; - } - - return true; -} - -/* Check that our alleged mountpoint is in mtab */ -bool -find_mountpoint( - char *mtab, - struct scrub_ctx *ctx) -{ - struct mntent_cursor cursor; - struct mntent *t = NULL; - bool found = false; - - 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) { - /* - * Keep jotting down matching mount details; newer mounts are - * towards the end of the file (hopefully). - */ - if (find_mountpoint_check(&ctx->mnt_sb, t)) { - ctx->mntpoint = strdup(t->mnt_dir); - ctx->blkdev = strdup(t->mnt_fsname); - found = true; - } - } - platform_mntent_close(&cursor); - return found; -} - -/* * Sleep for 100ms * however many -b we got past the initial one. * This is an (albeit clumsy) way to throttle scrub activity. */ diff --git a/scrub/common.h b/scrub/common.h index 4f1f0cd..bc83971 100644 --- a/scrub/common.h +++ b/scrub/common.h @@ -88,7 +88,6 @@ static inline int syncfs(int fd) } #endif -bool find_mountpoint(char *mtab, struct scrub_ctx *ctx); void background_sleep(void); char *string_escape(const char *in); diff --git a/scrub/phase1.c b/scrub/phase1.c index 9926770..c2b9067 100644 --- a/scrub/phase1.c +++ b/scrub/phase1.c @@ -83,7 +83,6 @@ bool xfs_setup_fs( struct scrub_ctx *ctx) { - struct fs_path *fsp; int error; /* @@ -178,17 +177,6 @@ _("Kernel metadata repair facility is not available. Use -n to scrub.")); return false; } - /* Go find the XFS devices if we have a usable fsmap. */ - fs_table_initialise(0, NULL, 0, NULL); - errno = 0; - fsp = fs_table_lookup(ctx->mntpoint, FS_MOUNT_POINT); - if (!fsp) { - str_info(ctx, ctx->mntpoint, -_("Unable to find XFS information.")); - return false; - } - memcpy(&ctx->fsinfo, fsp, sizeof(struct fs_path)); - /* Did we find the log and rt devices, if they're present? */ if (ctx->geo.logstart == 0 && ctx->fsinfo.fs_log == NULL) { str_info(ctx, ctx->mntpoint, diff --git a/scrub/xfs_scrub.c b/scrub/xfs_scrub.c index 2d55283..a5b5cf2 100644 --- a/scrub/xfs_scrub.c +++ b/scrub/xfs_scrub.c @@ -170,7 +170,7 @@ bool is_service; static void __attribute__((noreturn)) usage(void) { - fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint | device\n"), progname); + fprintf(stderr, _("Usage: %s [OPTIONS] mountpoint\n"), progname); fprintf(stderr, "\n"); fprintf(stderr, _("Options:\n")); fprintf(stderr, _(" -a count Stop after this many errors are found.\n")); @@ -538,8 +538,8 @@ main( struct phase_rusage all_pi; char *mtab = NULL; FILE *progress_fp = NULL; + struct fs_path *fsp; bool moveon = true; - bool ismnt; int c; int fd; int ret = SCRUB_RET_SUCCESS; @@ -640,7 +640,7 @@ main( if (optind != argc - 1) usage(); - ctx.mntpoint = strdup(argv[optind]); + ctx.mntpoint = argv[optind]; stdout_isatty = isatty(STDOUT_FILENO); stderr_isatty = isatty(STDERR_FILENO); @@ -680,14 +680,15 @@ main( mtab = _PATH_MOUNTED; } - ismnt = find_mountpoint(mtab, &ctx); - if (!ismnt) { - fprintf(stderr, -_("%s: Not a XFS mount point or block device.\n"), - ctx.mntpoint); + fs_table_initialise(0, NULL, 0, NULL); + fsp = fs_table_lookup_mount(ctx.mntpoint); + if (!fsp) { + fprintf(stderr, _("%s: Not a XFS mount point.\n"), + ctx.mntpoint); ret |= SCRUB_RET_SYNTAX; goto out; } + memcpy(&ctx.fsinfo, fsp, sizeof(struct fs_path)); /* How many CPUs? */ nproc = sysconf(_SC_NPROCESSORS_ONLN); @@ -740,8 +741,6 @@ _("%s: Not a XFS mount point or block device.\n"), phase_end(&all_pi, 0); if (progress_fp) fclose(progress_fp); - free(ctx.blkdev); - free(ctx.mntpoint); /* * If we're being run as a service, the return code must fit the LSB diff --git a/scrub/xfs_scrub.h b/scrub/xfs_scrub.h index aa130a7..c9dbe8e 100644 --- a/scrub/xfs_scrub.h +++ b/scrub/xfs_scrub.h @@ -48,7 +48,6 @@ struct scrub_ctx { /* Strings we need for presentation */ char *mntpoint; - char *blkdev; /* Mountpoint info */ struct stat mnt_sb;