From patchwork Thu Feb 16 21:03:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143900 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 907FBC636CC for ; Thu, 16 Feb 2023 21:03:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230071AbjBPVD0 (ORCPT ); Thu, 16 Feb 2023 16:03:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVD0 (ORCPT ); Thu, 16 Feb 2023 16:03:26 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE0C2A16F for ; Thu, 16 Feb 2023 13:03:25 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2A49360C48 for ; Thu, 16 Feb 2023 21:03:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B727C433EF; Thu, 16 Feb 2023 21:03:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581404; bh=qhLAtemkiBieV3oHDZAz6hz/UkZoYPJBiKbNhVFRGvA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=X7zOwelgGccVGbN+hu8O5S9AoSniI/NlW4T3QWQuDam/ODFi8H5rwTvcmjpkqrgsj FeYgEZwARtEHLr2VWZuKi9efod+m7wNXVtw+Dn1abmn1Q7cVr5BLtJqUG5806jF2+Y qO0Sb6vnW0U61tEiG/1mqH9LIOWFfBxfWdptTRpgmmebM0y/uoAxTCvCP0ZsAnTaUo VxEcTQHKr9i1dTnC+wZN5hmU45ifdLt5qB5orErTEjMHDuCcenF8ouRdNKLzglJpqI /szcz0AvTEJJYF5a9WFnwZQmT+ftWon0GeOvyRZfpzRI8DXwAMyE9BouHm8sk36VZG 1OwzcWM4mxq2A== Date: Thu, 16 Feb 2023 13:03:24 -0800 Subject: [PATCH 01/10] xfs_scrub: revert unnecessary code from "implement the upper half of parent pointers" From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880272.3477097.18280720624008495400.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Revert this piece which is no longer necessary. Signed-off-by: Darrick J. Wong --- scrub/inodes.c | 26 -------------------------- scrub/inodes.h | 2 -- 2 files changed, 28 deletions(-) diff --git a/scrub/inodes.c b/scrub/inodes.c index 245dd713..78f0914b 100644 --- a/scrub/inodes.c +++ b/scrub/inodes.c @@ -19,7 +19,6 @@ #include "descr.h" #include "libfrog/fsgeom.h" #include "libfrog/bulkstat.h" -#include "parent.h" /* * Iterate a range of inodes. @@ -450,28 +449,3 @@ scrub_open_handle( return open_by_fshandle(handle, sizeof(*handle), O_RDONLY | O_NOATIME | O_NOFOLLOW | O_NOCTTY); } - -/* Construct a description for an inode. */ -void -xfs_scrub_ino_descr( - struct scrub_ctx *ctx, - struct xfs_handle *handle, - char *buf, - size_t buflen) -{ - uint64_t ino; - xfs_agnumber_t agno; - xfs_agino_t agino; - int ret; - - ret = handle_to_path(handle, sizeof(struct xfs_handle), buf, buflen); - if (ret >= 0) - return; - - ino = handle->ha_fid.fid_ino; - agno = ino / (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); - agino = ino % (1ULL << (ctx->mnt.inopblog + ctx->mnt.agblklog)); - snprintf(buf, buflen, _("inode %"PRIu64" (%u/%u)"), ino, agno, - agino); -} - diff --git a/scrub/inodes.h b/scrub/inodes.h index 189fa282..f0318045 100644 --- a/scrub/inodes.h +++ b/scrub/inodes.h @@ -21,7 +21,5 @@ int scrub_scan_all_inodes(struct scrub_ctx *ctx, scrub_inode_iter_fn fn, void *arg); int scrub_open_handle(struct xfs_handle *handle); -void xfs_scrub_ino_descr(struct scrub_ctx *ctx, struct xfs_handle *handle, - char *buf, size_t buflen); #endif /* XFS_SCRUB_INODES_H_ */ From patchwork Thu Feb 16 21:03:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143901 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C95F0C636CC for ; Thu, 16 Feb 2023 21:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230073AbjBPVDp (ORCPT ); Thu, 16 Feb 2023 16:03:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230063AbjBPVDo (ORCPT ); Thu, 16 Feb 2023 16:03:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E22232A16F for ; Thu, 16 Feb 2023 13:03:42 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 95A20B8217A for ; Thu, 16 Feb 2023 21:03:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 271CFC433EF; Thu, 16 Feb 2023 21:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581420; bh=ZQizVFdLDlCT9exkEmiE2JxrgLN23LNtWEBpmVX7HpY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KrnDVX6rdHmnrxhXjW1GII4TTrxNqIXEIvTy1/bvY/eXSo9tdfUXAl+VHjIydyeIQ 7dx0/gpbSIuUhVW98IHJyK7f9R/ITu6pU1xLC3Ia/lqhAELW0NQWIB3xb7dNNSKZG2 QLHVoeowZxOJVlJmM8rX7YlteF/8gkB2l6ei7dJ6uSmYNLh3mJfnM4VjvF77U4JCD6 TP2XcKjhjr6gdG3RjPGRI+dPOzU/PAqTLn6Z1btuEaGxeGNagN4kake1g/EaaLHObM SpgN9/EIEqlYbblE/gYuWzl5lVLFJW7q7FQzGYRFpx3+ru7XmSHDJ8iiaeVVerbXZ9 uZDJ4mwF8AAyA== Date: Thu, 16 Feb 2023 13:03:39 -0800 Subject: [PATCH 02/10] xfs_io: print path in path_print From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880284.3477097.17451710627088149390.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Actually print the path string once we've bothered to construct it into a string buffer. Signed-off-by: Darrick J. Wong --- io/parent.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/io/parent.c b/io/parent.c index a6f3fa0c..b18e02c4 100644 --- a/io/parent.c +++ b/io/parent.c @@ -87,6 +87,8 @@ path_print( ret = path_list_to_string(path, buf + ret, len - ret); if (ret < 0) return ret; + + printf("%s\n", buf); return 0; } From patchwork Thu Feb 16 21:03:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143902 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CFB1C636CC for ; Thu, 16 Feb 2023 21:04:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbjBPVEB (ORCPT ); Thu, 16 Feb 2023 16:04:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39760 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230076AbjBPVEA (ORCPT ); Thu, 16 Feb 2023 16:04:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7303E505D3 for ; Thu, 16 Feb 2023 13:03:58 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0B2F2B8217A for ; Thu, 16 Feb 2023 21:03:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF15BC433D2; Thu, 16 Feb 2023 21:03:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581435; bh=wuGp2iFG4mhXj3AmqXMDMUqAzy9gzCSQ2VZAyiCqB8k=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=RIBRs31OLv1fmTM7VtupPAVjsX8RAFlyrDvLoFzzaMY4GiH979cm/DpwVdFSyIBK8 QR8ms1IYMXWEBWCeyYOpYfAF1eZ/mJKtDvRm60jJPHxbKCBxnPeM8xWMnFR5BSg3n5 Cw4e7CZIe4mJQQKOZo68FPSTel40XCKZp/o+UBJxvYNXn1qw29Phkw7grIZL8GSpiN k7a0FZSFXOBzqZ+pZrRXYN9nyTY8h4LSMm/tGfurfXPmMTXyCMiKbeVnD9heZI2kAU k8fqg4wZTGFuofpqzWV17nbn9j2XprDwuP/VSpylpIy4rZ1dNuSDrzQYozik0/XpLJ XYZb1za8JvcdA== Date: Thu, 16 Feb 2023 13:03:55 -0800 Subject: [PATCH 03/10] xfs_io: move parent pointer filtering and formatting flags out of libhandle From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880297.3477097.85390825696047054.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong All this filtering and presentation stuff originates in xfs_io and should stay there. The added arguments seriously complicate the basic iterator interface and there are no other users. While we're at it, fix a bug in path_print where it doesn't actually print the path. Signed-off-by: Darrick J. Wong --- include/parent.h | 17 +++------ io/parent.c | 99 ++++++++++++++++++++++++++++++++-------------------- libfrog/paths.c | 28 ++++++++++++++- libfrog/paths.h | 8 +++- libhandle/parent.c | 77 ++++++++++++---------------------------- 5 files changed, 119 insertions(+), 110 deletions(-) diff --git a/include/parent.h b/include/parent.h index 2e136724..fb900041 100644 --- a/include/parent.h +++ b/include/parent.h @@ -17,27 +17,20 @@ typedef struct parent_cursor { __u32 opaque[4]; /* an opaque cookie */ } parent_cursor_t; -/* Print parent pointer option flags */ -#define XFS_PPPTR_OFLAG_SHORT (1<<0) /* Print in short format */ - struct path_list; typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, struct xfs_parent_ptr *pptr, - void *arg, int flags); + void *arg); typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, void *arg); #define WALK_PPTRS_ABORT 1 -int fd_walk_pptrs(int fd, uint64_t pino, char *pname, walk_pptr_fn fn, - void *arg, int flags); -int handle_walk_pptrs(void *hanp, size_t hanlen, uint64_t pino, char *pname, - walk_pptr_fn fn, void *arg, int flags); +int fd_walk_pptrs(int fd, walk_pptr_fn fn, void *arg); +int handle_walk_pptrs(void *hanp, size_t hanlen, walk_pptr_fn fn, void *arg); #define WALK_PPATHS_ABORT 1 -int fd_walk_ppaths(int fd, uint64_t pino, char *pname, walk_ppath_fn fn, - void *arg, int flags); -int handle_walk_ppaths(void *hanp, size_t hanlen, uint64_t pino, char *pname, - walk_ppath_fn fn, void *arg, int flags); +int fd_walk_ppaths(int fd, walk_ppath_fn fn, void *arg); +int handle_walk_ppaths(void *hanp, size_t hanlen, walk_ppath_fn fn, void *arg); int fd_to_path(int fd, char *path, size_t pathlen); int handle_to_path(void *hanp, size_t hlen, char *path, size_t pathlen); diff --git a/io/parent.c b/io/parent.c index b18e02c4..66bb0fae 100644 --- a/io/parent.c +++ b/io/parent.c @@ -15,34 +15,41 @@ static cmdinfo_t parent_cmd; static char *mntpt; +struct pptr_args { + uint64_t filter_ino; + char *filter_name; + bool shortformat; +}; + static int pptr_print( struct xfs_pptr_info *pi, struct xfs_parent_ptr *pptr, - void *arg, - int flags) + void *arg) { - char buf[XFS_PPTR_MAXNAMELEN + 1]; - unsigned int namelen = strlen((char *)pptr->xpp_name); + struct pptr_args *args = arg; + unsigned int namelen; if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) { printf(_("Root directory.\n")); return 0; } - memcpy(buf, pptr->xpp_name, namelen); - buf[namelen] = 0; + if (args->filter_ino && pptr->xpp_ino != args->filter_ino) + return 0; + if (args->filter_name && strcmp(args->filter_name, pptr->xpp_name)) + return 0; - if (flags & XFS_PPPTR_OFLAG_SHORT) { + namelen = strlen(pptr->xpp_name); + if (args->shortformat) { printf("%llu/%u/%u/%s\n", (unsigned long long)pptr->xpp_ino, - (unsigned int)pptr->xpp_gen, namelen, buf); - } - else { + (unsigned int)pptr->xpp_gen, namelen, pptr->xpp_name); + } else { printf(_("p_ino = %llu\n"), (unsigned long long)pptr->xpp_ino); printf(_("p_gen = %u\n"), (unsigned int)pptr->xpp_gen); printf(_("p_reclen = %u\n"), namelen); - printf(_("p_name = \"%s\"\n\n"), buf); + printf(_("p_name = \"%s\"\n\n"), pptr->xpp_name); } return 0; } @@ -50,34 +57,53 @@ pptr_print( static int print_parents( struct xfs_handle *handle, - uint64_t pino, - char *pname, - int flags) + struct pptr_args *args) { int ret; if (handle) - ret = handle_walk_pptrs(handle, sizeof(*handle), pino, - pname, pptr_print, NULL, flags); + ret = handle_walk_pptrs(handle, sizeof(*handle), pptr_print, + args); else - ret = fd_walk_pptrs(file->fd, pino, pname, pptr_print, - NULL, flags); + ret = fd_walk_pptrs(file->fd, pptr_print, args); if (ret) perror(file->name); return 0; } +static int +filter_path_components( + const char *name, + uint64_t ino, + void *arg) +{ + struct pptr_args *args = arg; + + if (args->filter_ino && ino == args->filter_ino) + return ECANCELED; + if (args->filter_name && !strcmp(args->filter_name, name)) + return ECANCELED; + return 0; +} + static int path_print( const char *mntpt, struct path_list *path, - void *arg) { - + void *arg) +{ + struct pptr_args *args = arg; char buf[PATH_MAX]; size_t len = PATH_MAX; int ret; + if (args->filter_ino || args->filter_name) { + ret = path_walk_components(path, filter_path_components, args); + if (ret != ECANCELED) + return 0; + } + ret = snprintf(buf, len, "%s", mntpt); if (ret != strlen(mntpt)) { errno = ENOMEM; @@ -95,18 +121,15 @@ path_print( static int print_paths( struct xfs_handle *handle, - uint64_t pino, - char *pname, - int flags) + struct pptr_args *args) { int ret; if (handle) - ret = handle_walk_ppaths(handle, sizeof(*handle), pino, - pname, path_print, NULL, flags); + ret = handle_walk_ppaths(handle, sizeof(*handle), path_print, + args); else - ret = fd_walk_ppaths(file->fd, pino, pname, path_print, - NULL, flags); + ret = fd_walk_ppaths(file->fd, path_print, args); if (ret) perror(file->name); return 0; @@ -118,6 +141,7 @@ parent_f( char **argv) { struct xfs_handle handle; + struct pptr_args args = { 0 }; void *hanp = NULL; size_t hlen; struct fs_path *fs; @@ -128,9 +152,6 @@ parent_f( int listpath_flag = 0; int ret; static int tab_init; - uint64_t pino = 0; - char *pname = NULL; - int ppptr_flags = 0; if (!tab_init) { tab_init = 1; @@ -151,8 +172,8 @@ parent_f( listpath_flag = 1; break; case 'i': - pino = strtoull(optarg, &p, 0); - if (*p != '\0' || pino == 0) { + args.filter_ino = strtoull(optarg, &p, 0); + if (*p != '\0' || args.filter_ino == 0) { fprintf(stderr, _("Bad inode number '%s'.\n"), optarg); @@ -161,10 +182,10 @@ parent_f( break; case 'n': - pname = optarg; + args.filter_name = optarg; break; case 'f': - ppptr_flags |= XFS_PPPTR_OFLAG_SHORT; + args.shortformat = true; break; default: return command_usage(&parent_cmd); @@ -204,14 +225,14 @@ parent_f( handle.ha_fid.fid_ino = ino; handle.ha_fid.fid_gen = gen; + } else if (optind != argc) { + return command_usage(&parent_cmd); } if (listpath_flag) - exitcode = print_paths(ino ? &handle : NULL, - pino, pname, ppptr_flags); + exitcode = print_paths(ino ? &handle : NULL, &args); else - exitcode = print_parents(ino ? &handle : NULL, - pino, pname, ppptr_flags); + exitcode = print_parents(ino ? &handle : NULL, &args); if (hanp) free_handle(hanp, hlen); @@ -245,7 +266,7 @@ parent_init(void) parent_cmd.cfunc = parent_f; parent_cmd.argmin = 0; parent_cmd.argmax = -1; - parent_cmd.args = _("[-p] [ino gen] [-i] [ino] [-n] [name] [-f]"); + parent_cmd.args = _("[-p] [ino gen] [-i ino] [-n name] [-f]"); parent_cmd.flags = CMD_NOMAP_OK; parent_cmd.oneline = _("print parent inodes"); parent_cmd.help = parent_help; diff --git a/libfrog/paths.c b/libfrog/paths.c index a86ae07c..e541e200 100644 --- a/libfrog/paths.c +++ b/libfrog/paths.c @@ -574,13 +574,15 @@ struct path_list { struct path_component { struct list_head pc_list; + uint64_t pc_ino; char *pc_fname; }; /* Initialize a path component with a given name. */ struct path_component * path_component_init( - const char *name) + const char *name, + uint64_t ino) { struct path_component *pc; @@ -593,6 +595,7 @@ path_component_init( free(pc); return NULL; } + pc->pc_ino = ino; return pc; } @@ -610,7 +613,8 @@ int path_component_change( struct path_component *pc, void *name, - size_t namelen) + size_t namelen, + uint64_t ino) { void *p; @@ -620,6 +624,7 @@ path_component_change( pc->pc_fname = p; memcpy(pc->pc_fname, name, namelen); pc->pc_fname[namelen] = 0; + pc->pc_ino = ino; return 0; } @@ -699,3 +704,22 @@ path_list_to_string( } return bytes; } + +/* Walk each component of a path. */ +int +path_walk_components( + struct path_list *path, + path_walk_fn_t fn, + void *arg) +{ + struct path_component *pos; + int ret; + + list_for_each_entry(pos, &path->p_head, pc_list) { + ret = fn(pos->pc_fname, pos->pc_ino, arg); + if (ret) + return ret; + } + + return 0; +} diff --git a/libfrog/paths.h b/libfrog/paths.h index 52538fb5..eb66df0c 100644 --- a/libfrog/paths.h +++ b/libfrog/paths.h @@ -63,10 +63,10 @@ extern fs_path_t *fs_cursor_next_entry(fs_cursor_t *__cp); struct path_list; struct path_component; -struct path_component *path_component_init(const char *name); +struct path_component *path_component_init(const char *name, uint64_t ino); void path_component_free(struct path_component *pc); int path_component_change(struct path_component *pc, void *name, - size_t namelen); + size_t namelen, uint64_t ino); struct path_list *path_list_init(void); void path_list_free(struct path_list *path); @@ -77,4 +77,8 @@ void path_list_del_component(struct path_list *path, struct path_component *pc); ssize_t path_list_to_string(struct path_list *path, char *buf, size_t buflen); +typedef int (*path_walk_fn_t)(const char *name, uint64_t ino, void *arg); + +int path_walk_components(struct path_list *path, path_walk_fn_t fn, void *arg); + #endif /* __PATH_H__ */ diff --git a/libhandle/parent.c b/libhandle/parent.c index 3de8742c..c10a55ac 100644 --- a/libhandle/parent.c +++ b/libhandle/parent.c @@ -40,21 +40,13 @@ xfs_pptr_alloc( return pi; } -/* - * Walk all parents of the given file handle. - * If pino is set, print only the parent pointer - * of that inode. If pname is set, print only the - * parent pointer of that filename - */ +/* Walk all parents of the given file handle. */ static int handle_walk_parents( int fd, struct xfs_handle *handle, - uint64_t pino, - char *pname, walk_pptr_fn fn, - void *arg, - int flags) + void *arg) { struct xfs_pptr_info *pi; struct xfs_parent_ptr *p; @@ -73,20 +65,13 @@ handle_walk_parents( ret = ioctl(fd, XFS_IOC_GETPARENTS, pi); while (!ret) { if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) { - ret = fn(pi, NULL, arg, flags); + ret = fn(pi, NULL, arg); break; } for (i = 0; i < pi->pi_ptrs_used; i++) { p = xfs_ppinfo_to_pp(pi, i); - if ((pino != 0) && (pino != p->xpp_ino)) - continue; - - if ((pname != NULL) && (strcmp(pname, - (char *)p->xpp_name) != 0)) - continue; - - ret = fn(pi, p, arg, flags); + ret = fn(pi, p, arg); if (ret) goto out_pi; } @@ -107,11 +92,8 @@ int handle_walk_pptrs( void *hanp, size_t hlen, - uint64_t pino, - char *pname, walk_pptr_fn fn, - void *arg, - int flags) + void *arg) { char *mntpt; int fd; @@ -125,20 +107,17 @@ handle_walk_pptrs( if (fd < 0) return -1; - return handle_walk_parents(fd, hanp, pino, pname, fn, arg, flags); + return handle_walk_parents(fd, hanp, fn, arg); } /* Walk all parent pointers of this fd. */ int fd_walk_pptrs( int fd, - uint64_t pino, - char *pname, walk_pptr_fn fn, - void *arg, - int flags) + void *arg) { - return handle_walk_parents(fd, NULL, pino, pname, fn, arg, flags); + return handle_walk_parents(fd, NULL, fn, arg); } struct walk_ppaths_info { @@ -156,15 +135,13 @@ struct walk_ppath_level_info { }; static int handle_walk_parent_paths(struct walk_ppaths_info *wpi, - struct xfs_handle *handle, uint64_t pino, char *pname, - int flags); + struct xfs_handle *handle); static int handle_walk_parent_path_ptr( struct xfs_pptr_info *pi, struct xfs_parent_ptr *p, - void *arg, - int flags) + void *arg) { struct walk_ppath_level_info *wpli = arg; struct walk_ppaths_info *wpi = wpli->wpi; @@ -177,13 +154,13 @@ handle_walk_parent_path_ptr( for (i = 0; i < pi->pi_ptrs_used; i++) { p = xfs_ppinfo_to_pp(pi, i); ret = path_component_change(wpli->pc, p->xpp_name, - strlen((char *)p->xpp_name)); + strlen((char *)p->xpp_name), p->xpp_ino); if (ret) break; wpli->newhandle.ha_fid.fid_ino = p->xpp_ino; wpli->newhandle.ha_fid.fid_gen = p->xpp_gen; path_list_add_parent_component(wpi->path, wpli->pc); - ret = handle_walk_parent_paths(wpi, &wpli->newhandle, 0, NULL, 0); + ret = handle_walk_parent_paths(wpi, &wpli->newhandle); path_list_del_component(wpi->path, wpli->pc); if (ret) break; @@ -199,10 +176,7 @@ handle_walk_parent_path_ptr( static int handle_walk_parent_paths( struct walk_ppaths_info *wpi, - struct xfs_handle *handle, - uint64_t pino, - char *pname, - int flags) + struct xfs_handle *handle) { struct walk_ppath_level_info *wpli; int ret; @@ -210,7 +184,7 @@ handle_walk_parent_paths( wpli = malloc(sizeof(struct walk_ppath_level_info)); if (!wpli) return -1; - wpli->pc = path_component_init(""); + wpli->pc = path_component_init("", 0); if (!wpli->pc) { free(wpli); return -1; @@ -218,8 +192,8 @@ handle_walk_parent_paths( wpli->wpi = wpi; memcpy(&wpli->newhandle, handle, sizeof(struct xfs_handle)); - ret = handle_walk_parents(wpi->fd, handle, pino, pname, - handle_walk_parent_path_ptr, wpli, flags); + ret = handle_walk_parents(wpi->fd, handle, handle_walk_parent_path_ptr, + wpli); path_component_free(wpli->pc); free(wpli); @@ -234,11 +208,8 @@ int handle_walk_ppaths( void *hanp, size_t hlen, - uint64_t pino, - char *pname, walk_ppath_fn fn, - void *arg, - int flags) + void *arg) { struct walk_ppaths_info wpi; ssize_t ret; @@ -257,7 +228,7 @@ handle_walk_ppaths( wpi.fn = fn; wpi.arg = arg; - ret = handle_walk_parent_paths(&wpi, hanp, pino, pname, flags); + ret = handle_walk_parent_paths(&wpi, hanp); path_list_free(wpi.path); return ret; @@ -270,11 +241,8 @@ handle_walk_ppaths( int fd_walk_ppaths( int fd, - uint64_t pino, - char *pname, walk_ppath_fn fn, - void *arg, - int flags) + void *arg) { struct walk_ppaths_info wpi; void *hanp; @@ -296,7 +264,7 @@ fd_walk_ppaths( wpi.fn = fn; wpi.arg = arg; - ret = handle_walk_parent_paths(&wpi, hanp, pino, pname, flags); + ret = handle_walk_parent_paths(&wpi, hanp); path_list_free(wpi.path); return ret; @@ -342,8 +310,7 @@ handle_to_path( pwi.buf = path; pwi.len = pathlen; - return handle_walk_ppaths(hanp, hlen, 0, NULL, handle_to_path_walk, - &pwi, 0); + return handle_walk_ppaths(hanp, hlen, handle_to_path_walk, &pwi); } /* Return any eligible path to this file description. */ @@ -357,5 +324,5 @@ fd_to_path( pwi.buf = path; pwi.len = pathlen; - return fd_walk_ppaths(fd, 0, NULL, handle_to_path_walk, &pwi, 0); + return fd_walk_ppaths(fd, handle_to_path_walk, &pwi); } From patchwork Thu Feb 16 21:04:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143906 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D77EC636CC for ; Thu, 16 Feb 2023 21:04:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjBPVEO (ORCPT ); Thu, 16 Feb 2023 16:04:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230077AbjBPVEN (ORCPT ); Thu, 16 Feb 2023 16:04:13 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 60CF5505D3 for ; Thu, 16 Feb 2023 13:04:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F057460C1A for ; Thu, 16 Feb 2023 21:04:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5AF08C433D2; Thu, 16 Feb 2023 21:04:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581451; bh=Yk7tXYVf86isRM7zlOUZZLrhWjaowRzxvfQxZCH0EQY=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=iFkRDMHiWcfMXywq/vE2Gor3lMRRbRe3t5zRdz1e4h3PO8/GxLUW/UgvpvWZpnfJ4 Wyh09EyXG9rgndt4Jg4fxMGB6tXuPZZ8COeffhjeC6XHjdT6wu18agFXs6yWkpkZkv ToFS0L9Wt6DAY+dWVrJNAi0PkP5N9euVCQdRBYK9VOmdxxrgI0O0R4gHtBDdggUq35 sqNua8jVxDrNN8CxtuY4FZmzoYoD+gDZx8dVUIGuC+PbJ3jS+dyIXlTaJGh0a5RIP9 djn8g6O1uRA7nhvxL1IjRDA/d0FOS6NcDGpC1wwkUWuMbqaAkKkbzkWqHawaXdTok8 z3Y+dhgA//7iA== Date: Thu, 16 Feb 2023 13:04:10 -0800 Subject: [PATCH 04/10] libfrog: remove all the parent pointer code from libhandle From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880311.3477097.14103004780435007800.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Move this code out of libhandle and into libfrog. We don't want to expose this stuff to a userspace library until customers actually demand it. While we're here, fix the copyright statements and licensing tags. Signed-off-by: Darrick J. Wong --- include/parent.h | 18 ------------------ io/parent.c | 1 + libfrog/Makefile | 2 ++ libfrog/pptrs.c | 22 ++++------------------ libfrog/pptrs.h | 27 +++++++++++++++++++++++++++ libhandle/Makefile | 2 +- 6 files changed, 35 insertions(+), 37 deletions(-) rename libhandle/parent.c => libfrog/pptrs.c (87%) create mode 100644 libfrog/pptrs.h diff --git a/include/parent.h b/include/parent.h index fb900041..4d3ad51b 100644 --- a/include/parent.h +++ b/include/parent.h @@ -17,22 +17,4 @@ typedef struct parent_cursor { __u32 opaque[4]; /* an opaque cookie */ } parent_cursor_t; -struct path_list; - -typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, struct xfs_parent_ptr *pptr, - void *arg); -typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, - void *arg); - -#define WALK_PPTRS_ABORT 1 -int fd_walk_pptrs(int fd, walk_pptr_fn fn, void *arg); -int handle_walk_pptrs(void *hanp, size_t hanlen, walk_pptr_fn fn, void *arg); - -#define WALK_PPATHS_ABORT 1 -int fd_walk_ppaths(int fd, walk_ppath_fn fn, void *arg); -int handle_walk_ppaths(void *hanp, size_t hanlen, walk_ppath_fn fn, void *arg); - -int fd_to_path(int fd, char *path, size_t pathlen); -int handle_to_path(void *hanp, size_t hlen, char *path, size_t pathlen); - #endif diff --git a/io/parent.c b/io/parent.c index 66bb0fae..ceb62a43 100644 --- a/io/parent.c +++ b/io/parent.c @@ -8,6 +8,7 @@ #include "input.h" #include "libfrog/paths.h" #include "parent.h" +#include "libfrog/pptrs.h" #include "handle.h" #include "init.h" #include "io.h" diff --git a/libfrog/Makefile b/libfrog/Makefile index 01107082..5622ab9b 100644 --- a/libfrog/Makefile +++ b/libfrog/Makefile @@ -23,6 +23,7 @@ list_sort.c \ linux.c \ logging.c \ paths.c \ +pptrs.c \ projects.c \ ptvar.c \ radix-tree.c \ @@ -42,6 +43,7 @@ crc32table.h \ fsgeom.h \ logging.h \ paths.h \ +pptrs.h \ projects.h \ ptvar.h \ radix-tree.h \ diff --git a/libhandle/parent.c b/libfrog/pptrs.c similarity index 87% rename from libhandle/parent.c rename to libfrog/pptrs.c index c10a55ac..66a34246 100644 --- a/libhandle/parent.c +++ b/libfrog/pptrs.c @@ -1,21 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (C) 2017 Oracle. All Rights Reserved. - * - * Author: Darrick J. Wong - * - * 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; either version 2 - * of the License, or (at your option) any later version. - * - * 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. + * Copyright (C) 2023 Oracle. All Rights Reserved. + * Author: Darrick J. Wong */ #include "platform_defs.h" #include "xfs.h" @@ -23,7 +9,7 @@ #include "list.h" #include "libfrog/paths.h" #include "handle.h" -#include "parent.h" +#include "libfrog/pptrs.h" /* Allocate a buffer large enough for some parent pointer records. */ static inline struct xfs_pptr_info * diff --git a/libfrog/pptrs.h b/libfrog/pptrs.h new file mode 100644 index 00000000..d174aa2a --- /dev/null +++ b/libfrog/pptrs.h @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2023 Oracle. All Rights Reserved. + * Author: Darrick J. Wong + */ +#ifndef __LIBFROG_PPTRS_H_ +#define __LIBFROG_PPTRS_H_ + +struct path_list; + +typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, struct xfs_parent_ptr *pptr, + void *arg); +typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, + void *arg); + +#define WALK_PPTRS_ABORT 1 +int fd_walk_pptrs(int fd, walk_pptr_fn fn, void *arg); +int handle_walk_pptrs(void *hanp, size_t hanlen, walk_pptr_fn fn, void *arg); + +#define WALK_PPATHS_ABORT 1 +int fd_walk_ppaths(int fd, walk_ppath_fn fn, void *arg); +int handle_walk_ppaths(void *hanp, size_t hanlen, walk_ppath_fn fn, void *arg); + +int fd_to_path(int fd, char *path, size_t pathlen); +int handle_to_path(void *hanp, size_t hlen, char *path, size_t pathlen); + +#endif /* __LIBFROG_PPTRS_H_ */ diff --git a/libhandle/Makefile b/libhandle/Makefile index cf7df67c..f297a59e 100644 --- a/libhandle/Makefile +++ b/libhandle/Makefile @@ -12,7 +12,7 @@ LT_AGE = 0 LTLDFLAGS += -Wl,--version-script,libhandle.sym -CFILES = handle.c jdm.c parent.c +CFILES = handle.c jdm.c LSRCFILES = libhandle.sym default: ltdepend $(LTLIBRARY) From patchwork Thu Feb 16 21:04:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CE55C61DA4 for ; Thu, 16 Feb 2023 21:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbjBPVEb (ORCPT ); Thu, 16 Feb 2023 16:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjBPVEb (ORCPT ); Thu, 16 Feb 2023 16:04:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4C663505E5 for ; Thu, 16 Feb 2023 13:04:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B1ED560C48 for ; Thu, 16 Feb 2023 21:04:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C0FDC433D2; Thu, 16 Feb 2023 21:04:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581469; bh=5SWiYleLjl/Ndx+8NVKipwN9A6CL7ESRIEpDgJu0MX8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=QmmYQjs3jR86CRQ5EaLt9nFsQ5PEpkI++pAOjvM2hDEr/OIqyaGwuOvxQEwbJOzmQ flAsUPRc//C3Ubgc/eMTt5ds9a4VtH97TGTLnmTiBpGq69y4cBebZFCE83wxfKJ9AC H1CIIyLqAngOg2K3vyf8vVv893QuSLS0sYC/4sGU3m1d2p4sJh55KjrVIsQEAsyYre of6BqPwojYaOSZuWMnBWe2pEPI3S1QGdjjU5OhHt9mN6XAnu/80IE7pG8sTpDf4Hk7 14+ULCTGcdzGnWoZdOYWexR1ViiFFZjLuarsOt8NAS3eaFxiKGfriunAutUtyBLUH+ 3WsjRWsczEVig== Date: Thu, 16 Feb 2023 13:04:26 -0800 Subject: [PATCH 05/10] libfrog: fix indenting errors in xfss_pptr_alloc From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880324.3477097.4962218122860520315.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Fix some indenting problems, and get rid of the xfs_ prefix. Signed-off-by: Darrick J. Wong --- libfrog/pptrs.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 66a34246..5a3a7e2b 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -13,17 +13,17 @@ /* Allocate a buffer large enough for some parent pointer records. */ static inline struct xfs_pptr_info * -xfs_pptr_alloc( - size_t nr_ptrs) +alloc_pptr_buf( + size_t nr_ptrs) { - struct xfs_pptr_info *pi; + struct xfs_pptr_info *pi; - pi = malloc(xfs_pptr_info_sizeof(nr_ptrs)); - if (!pi) - return NULL; - memset(pi, 0, sizeof(struct xfs_pptr_info)); - pi->pi_ptrs_size = nr_ptrs; - return pi; + pi = malloc(xfs_pptr_info_sizeof(nr_ptrs)); + if (!pi) + return NULL; + memset(pi, 0, sizeof(struct xfs_pptr_info)); + pi->pi_ptrs_size = nr_ptrs; + return pi; } /* Walk all parents of the given file handle. */ @@ -39,7 +39,7 @@ handle_walk_parents( unsigned int i; ssize_t ret = -1; - pi = xfs_pptr_alloc(4); + pi = alloc_pptr_buf(4); if (!pi) return -1; From patchwork Thu Feb 16 21:04:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4B570C636CC for ; Thu, 16 Feb 2023 21:04:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230082AbjBPVEy (ORCPT ); Thu, 16 Feb 2023 16:04:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230109AbjBPVEs (ORCPT ); Thu, 16 Feb 2023 16:04:48 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 600D02B632 for ; Thu, 16 Feb 2023 13:04:47 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id ECCD6B8217A for ; Thu, 16 Feb 2023 21:04:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8969C433D2; Thu, 16 Feb 2023 21:04:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581484; bh=n1YAAIYrvV7Ft+r5eO7KXcc7ydAFK4MBbg4r3ccjOII=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=illw3zfYeV7YIMF3PhmhH2hv4G0OXnvMfCqVDs7WFNoKCiIcG02cb82ag2HwwdXeM H/x9a5orAgaAwKbjhIPnmafiWSiM13adjHFxlqSTUK+l4JRkmkn1z9/GCinq6KR01g 7WpxfywwW/7ndpFiIr7QiSxywoZWKY5GiGLnSqSlsu9tHPX+nBInYmY3oc2zUsIhvN Uas++O193UBuFvmh+ob4ozp90+r60E0+nt8Tu48N/mSqIfrrHhgZ77MvVuIq/Shvz6 k6QJrdi3AMGA/2e3jpejKvzapqxnTWx8pDkIEOBl2M120bINhBswemExD5QDtuhms8 phYch+YHakbyA== Date: Thu, 16 Feb 2023 13:04:44 -0800 Subject: [PATCH 06/10] libfrog: return positive errno in pptrs.c From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880337.3477097.2597122428206999325.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Make all the functions in here return 0 for success or positive errno. Signed-off-by: Darrick J. Wong --- io/parent.c | 12 +++----- libfrog/paths.c | 11 +++++-- libfrog/pptrs.c | 81 +++++++++++++++++++++++++++++++++---------------------- libfrog/pptrs.h | 6 +--- 4 files changed, 62 insertions(+), 48 deletions(-) diff --git a/io/parent.c b/io/parent.c index ceb62a43..25d835a3 100644 --- a/io/parent.c +++ b/io/parent.c @@ -68,7 +68,7 @@ print_parents( else ret = fd_walk_pptrs(file->fd, pptr_print, args); if (ret) - perror(file->name); + fprintf(stderr, "%s: %s\n", file->name, strerror(ret)); return 0; } @@ -106,14 +106,12 @@ path_print( } ret = snprintf(buf, len, "%s", mntpt); - if (ret != strlen(mntpt)) { - errno = ENOMEM; - return -1; - } + if (ret != strlen(mntpt)) + return ENAMETOOLONG; ret = path_list_to_string(path, buf + ret, len - ret); if (ret < 0) - return ret; + return ENAMETOOLONG; printf("%s\n", buf); return 0; @@ -132,7 +130,7 @@ print_paths( else ret = fd_walk_ppaths(file->fd, path_print, args); if (ret) - perror(file->name); + fprintf(stderr, "%s: %s\n", file->name, strerror(ret)); return 0; } diff --git a/libfrog/paths.c b/libfrog/paths.c index e541e200..cc43b02c 100644 --- a/libfrog/paths.c +++ b/libfrog/paths.c @@ -608,7 +608,7 @@ path_component_free( free(pc); } -/* Change a path component's filename. */ +/* Change a path component's filename or returns positive errno. */ int path_component_change( struct path_component *pc, @@ -620,7 +620,7 @@ path_component_change( p = realloc(pc->pc_fname, namelen + 1); if (!p) - return -1; + return errno; pc->pc_fname = p; memcpy(pc->pc_fname, name, namelen); pc->pc_fname[namelen] = 0; @@ -628,7 +628,7 @@ path_component_change( return 0; } -/* Initialize a pathname. */ +/* Initialize a pathname or returns positive errno. */ struct path_list * path_list_init(void) { @@ -683,7 +683,10 @@ path_list_del_component( list_del_init(&pc->pc_list); } -/* Convert a pathname into a string. */ +/* + * Convert a pathname into a string or returns -1 if the buffer isn't long + * enough. + */ ssize_t path_list_to_string( struct path_list *path, diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 5a3a7e2b..ef91a919 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -26,7 +26,10 @@ alloc_pptr_buf( return pi; } -/* Walk all parents of the given file handle. */ +/* + * Walk all parents of the given file handle. Returns 0 on success or positive + * errno. + */ static int handle_walk_parents( int fd, @@ -41,7 +44,7 @@ handle_walk_parents( pi = alloc_pptr_buf(4); if (!pi) - return -1; + return errno; if (handle) { memcpy(&pi->pi_handle, handle, sizeof(struct xfs_handle)); @@ -52,7 +55,7 @@ handle_walk_parents( while (!ret) { if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) { ret = fn(pi, NULL, arg); - break; + goto out_pi; } for (i = 0; i < pi->pi_ptrs_used; i++) { @@ -67,13 +70,15 @@ handle_walk_parents( ret = ioctl(fd, XFS_IOC_GETPARENTS, pi); } + if (ret) + ret = errno; out_pi: free(pi); return ret; } -/* Walk all parent pointers of this handle. */ +/* Walk all parent pointers of this handle. Returns 0 or positive errno. */ int handle_walk_pptrs( void *hanp, @@ -84,19 +89,17 @@ handle_walk_pptrs( char *mntpt; int fd; - if (hlen != sizeof(struct xfs_handle)) { - errno = EINVAL; - return -1; - } + if (hlen != sizeof(struct xfs_handle)) + return EINVAL; fd = handle_to_fsfd(hanp, &mntpt); if (fd < 0) - return -1; + return errno; return handle_walk_parents(fd, hanp, fn, arg); } -/* Walk all parent pointers of this fd. */ +/* Walk all parent pointers of this fd. Returns 0 or positive errno. */ int fd_walk_pptrs( int fd, @@ -158,6 +161,7 @@ handle_walk_parent_path_ptr( /* * Recursively walk all parents of the given file handle; if we hit the * fs root then we call the associated function with the constructed path. + * Returns 0 for success or positive errno. */ static int handle_walk_parent_paths( @@ -169,11 +173,12 @@ handle_walk_parent_paths( wpli = malloc(sizeof(struct walk_ppath_level_info)); if (!wpli) - return -1; + return errno; wpli->pc = path_component_init("", 0); if (!wpli->pc) { + ret = errno; free(wpli); - return -1; + return ret; } wpli->wpi = wpi; memcpy(&wpli->newhandle, handle, sizeof(struct xfs_handle)); @@ -188,7 +193,7 @@ handle_walk_parent_paths( /* * Call the given function on all known paths from the vfs root to the inode - * described in the handle. + * described in the handle. Returns 0 for success or positive errno. */ int handle_walk_ppaths( @@ -200,17 +205,15 @@ handle_walk_ppaths( struct walk_ppaths_info wpi; ssize_t ret; - if (hlen != sizeof(struct xfs_handle)) { - errno = EINVAL; - return -1; - } + if (hlen != sizeof(struct xfs_handle)) + return EINVAL; wpi.fd = handle_to_fsfd(hanp, &wpi.mntpt); if (wpi.fd < 0) - return -1; + return errno; wpi.path = path_list_init(); if (!wpi.path) - return -1; + return errno; wpi.fn = fn; wpi.arg = arg; @@ -222,7 +225,7 @@ handle_walk_ppaths( /* * Call the given function on all known paths from the vfs root to the inode - * referred to by the file description. + * referred to by the file description. Returns 0 or positive errno. */ int fd_walk_ppaths( @@ -238,15 +241,15 @@ fd_walk_ppaths( ret = fd_to_handle(fd, &hanp, &hlen); if (ret) - return ret; + return errno; fsfd = handle_to_fsfd(hanp, &wpi.mntpt); if (fsfd < 0) - return -1; + return errno; wpi.fd = fd; wpi.path = path_list_init(); if (!wpi.path) - return -1; + return errno; wpi.fn = fn; wpi.arg = arg; @@ -272,19 +275,20 @@ handle_to_path_walk( int ret; ret = snprintf(pwi->buf, pwi->len, "%s", mntpt); - if (ret != strlen(mntpt)) { - errno = ENOMEM; - return -1; - } + if (ret != strlen(mntpt)) + return ENAMETOOLONG; ret = path_list_to_string(path, pwi->buf + ret, pwi->len - ret); if (ret < 0) - return ret; + return ENAMETOOLONG; - return WALK_PPATHS_ABORT; + return ECANCELED; } -/* Return any eligible path to this file handle. */ +/* + * Return any eligible path to this file handle. Returns 0 for success or + * positive errno. + */ int handle_to_path( void *hanp, @@ -293,13 +297,20 @@ handle_to_path( size_t pathlen) { struct path_walk_info pwi; + int ret; pwi.buf = path; pwi.len = pathlen; - return handle_walk_ppaths(hanp, hlen, handle_to_path_walk, &pwi); + ret = handle_walk_ppaths(hanp, hlen, handle_to_path_walk, &pwi); + if (ret == ECANCELED) + return 0; + return ret; } -/* Return any eligible path to this file description. */ +/* + * Return any eligible path to this file description. Returns 0 for success + * or positive errno. + */ int fd_to_path( int fd, @@ -307,8 +318,12 @@ fd_to_path( size_t pathlen) { struct path_walk_info pwi; + int ret; pwi.buf = path; pwi.len = pathlen; - return fd_walk_ppaths(fd, handle_to_path_walk, &pwi); + ret = fd_walk_ppaths(fd, handle_to_path_walk, &pwi); + if (ret == ECANCELED) + return 0; + return ret; } diff --git a/libfrog/pptrs.h b/libfrog/pptrs.h index d174aa2a..1666de06 100644 --- a/libfrog/pptrs.h +++ b/libfrog/pptrs.h @@ -8,16 +8,14 @@ struct path_list; -typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, struct xfs_parent_ptr *pptr, - void *arg); +typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, + struct xfs_parent_ptr *pptr, void *arg); typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, void *arg); -#define WALK_PPTRS_ABORT 1 int fd_walk_pptrs(int fd, walk_pptr_fn fn, void *arg); int handle_walk_pptrs(void *hanp, size_t hanlen, walk_pptr_fn fn, void *arg); -#define WALK_PPATHS_ABORT 1 int fd_walk_ppaths(int fd, walk_ppath_fn fn, void *arg); int handle_walk_ppaths(void *hanp, size_t hanlen, walk_ppath_fn fn, void *arg); From patchwork Thu Feb 16 21:04:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D4B0C636CC for ; Thu, 16 Feb 2023 21:05:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230083AbjBPVFF (ORCPT ); Thu, 16 Feb 2023 16:05:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230079AbjBPVFE (ORCPT ); Thu, 16 Feb 2023 16:05:04 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B285F505D3 for ; Thu, 16 Feb 2023 13:05:03 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 11D2ACE2D78 for ; Thu, 16 Feb 2023 21:05:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3E5ABC433EF; Thu, 16 Feb 2023 21:05:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581500; bh=QV1IyaaqkGuQNVpfSet+j6EQKRL8H/mVL5G1Nw79xXk=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=aT+m7HTnn1ei7JL1/DOSQvzD0TKXIXFG9/NsAKRJRcs9ubcdfq/Mxez7JC7Nqy/V7 7UuoDVR2fUOiSk2sktteADp0jLxUVfE3Wp45oSrWhLe6QaTrclmGPLiPsVpvFxaJVV ZGR3h6EmRmijcwe45whMxvAa4pGSXzU4J4x5yko5Rva/HEkT4hD78uHTpJMpC4Z4kg hnQxxMPIgTvX+Khs/YyW+dyWEF1CATRWJfkLPhXW52VOzazkCNNL6mOjebrND7bhTc +ksR8j0nfmNvKs06ablExcrWHmnNPdKFOEUBiGleGJ+bH1eMJSb1tT1sDZtWb6weju 27h7mddoaEHjw== Date: Thu, 16 Feb 2023 13:04:59 -0800 Subject: [PATCH 07/10] libfrog: only walk one parent pointer at a time in handle_walk_parent_path_ptr From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880350.3477097.7538603843264282258.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong handle_walk_parents already walks each returned parent pointer record, so we don't need a loop in handle_walk_parent_path_ptr. Signed-off-by: Darrick J. Wong --- libfrog/pptrs.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index ef91a919..8d9e62a2 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -134,26 +134,22 @@ handle_walk_parent_path_ptr( { struct walk_ppath_level_info *wpli = arg; struct walk_ppaths_info *wpi = wpli->wpi; - unsigned int i; int ret = 0; if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) return wpi->fn(wpi->mntpt, wpi->path, wpi->arg); - for (i = 0; i < pi->pi_ptrs_used; i++) { - p = xfs_ppinfo_to_pp(pi, i); - ret = path_component_change(wpli->pc, p->xpp_name, + ret = path_component_change(wpli->pc, p->xpp_name, strlen((char *)p->xpp_name), p->xpp_ino); - if (ret) - break; - wpli->newhandle.ha_fid.fid_ino = p->xpp_ino; - wpli->newhandle.ha_fid.fid_gen = p->xpp_gen; - path_list_add_parent_component(wpi->path, wpli->pc); - ret = handle_walk_parent_paths(wpi, &wpli->newhandle); - path_list_del_component(wpi->path, wpli->pc); - if (ret) - break; - } + if (ret) + return ret; + + wpli->newhandle.ha_fid.fid_ino = p->xpp_ino; + wpli->newhandle.ha_fid.fid_gen = p->xpp_gen; + + path_list_add_parent_component(wpi->path, wpli->pc); + ret = handle_walk_parent_paths(wpi, &wpli->newhandle); + path_list_del_component(wpi->path, wpli->pc); return ret; } From patchwork Thu Feb 16 21:05:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A036EC61DA4 for ; Thu, 16 Feb 2023 21:05:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230079AbjBPVFT (ORCPT ); Thu, 16 Feb 2023 16:05:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230084AbjBPVFT (ORCPT ); Thu, 16 Feb 2023 16:05:19 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E010505D3 for ; Thu, 16 Feb 2023 13:05:18 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1815EB826BA for ; Thu, 16 Feb 2023 21:05:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9DBEC433D2; Thu, 16 Feb 2023 21:05:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581515; bh=V3qfY/0jz7ZA+ArWQMcJJ5mQocu4dVWeZwdjE0/qRac=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=ifks/CDY2Vk2iaEX1amG96iC827vhFzV/7Y7Vh2jZBXeSttPYXM1+TGlzlGzT1tRU U2ddno0qu7QaTawiwzGfAXgxSW+rc/cJpgdeedJmUrGQNVYgdwm40agn3oGsZ2GnSq LwotZ3Gam93sjNHpexLNNfBqETChtq7WurPOElG1RcOS6O2oQXCuvrc2CEJs8RCzeF qFeNhfX7zugXThefrryF2Tf+tKiVLAa40CNtF9fehXxfHCG3dYaHcJaojJgiB2kTGH 11IZNojDz5rf/TXMw/HYpoNLnYVg7oijsIaaQAhSABiqGkMObvtxwgvjIeE2mzn+li GVp4kx8BD9s8w== Date: Thu, 16 Feb 2023 13:05:15 -0800 Subject: [PATCH 08/10] libfrog: trim trailing slashes when printing pptr paths From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880363.3477097.15991358215180868688.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong Trim the trailing slashes in the mountpoint string when we're printing parent pointer paths. Signed-off-by: Darrick J. Wong --- io/parent.c | 9 +++++++-- libfrog/pptrs.c | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/io/parent.c b/io/parent.c index 25d835a3..694c0839 100644 --- a/io/parent.c +++ b/io/parent.c @@ -97,6 +97,7 @@ path_print( struct pptr_args *args = arg; char buf[PATH_MAX]; size_t len = PATH_MAX; + int mntpt_len = strlen(mntpt); int ret; if (args->filter_ino || args->filter_name) { @@ -105,8 +106,12 @@ path_print( return 0; } - ret = snprintf(buf, len, "%s", mntpt); - if (ret != strlen(mntpt)) + /* Trim trailing slashes from the mountpoint */ + while (mntpt_len > 0 && mntpt[mntpt_len - 1] == '/') + mntpt_len--; + + ret = snprintf(buf, len, "%.*s", mntpt_len, mntpt); + if (ret != mntpt_len) return ENAMETOOLONG; ret = path_list_to_string(path, buf + ret, len - ret); diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 8d9e62a2..61fd1fb9 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -268,10 +268,15 @@ handle_to_path_walk( void *arg) { struct path_walk_info *pwi = arg; + int mntpt_len = strlen(mntpt); int ret; - ret = snprintf(pwi->buf, pwi->len, "%s", mntpt); - if (ret != strlen(mntpt)) + /* Trim trailing slashes from the mountpoint */ + while (mntpt_len > 0 && mntpt[mntpt_len - 1] == '/') + mntpt_len--; + + ret = snprintf(pwi->buf, pwi->len, "%.*s", mntpt_len, mntpt); + if (ret != mntpt_len) return ENAMETOOLONG; ret = path_list_to_string(path, pwi->buf + ret, pwi->len - ret); From patchwork Thu Feb 16 21:05:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143911 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27C11C636CC for ; Thu, 16 Feb 2023 21:05:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbjBPVFg (ORCPT ); Thu, 16 Feb 2023 16:05:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230097AbjBPVFe (ORCPT ); Thu, 16 Feb 2023 16:05:34 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A0382B632 for ; Thu, 16 Feb 2023 13:05:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id BE547B8217A for ; Thu, 16 Feb 2023 21:05:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5FBA6C433EF; Thu, 16 Feb 2023 21:05:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581531; bh=jeQTcEnLwNtEyVnstGH88DzGARpu5kuAm98IrTfeDgg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=sSIHdNtRQU5IHgz+Ca0qYKMaZNnJFod5IX5T6x4Oto0lEKf2NT9WqtYhdsRp/24vo EplLmpu3Ro8vYwXskQ6NYb0gZhmVGglmKAA3GNGm9GLD60WQh3321Rc/W6chcWCVP3 N1eO3yznroDSIFBCWEumWmO2E/8jy5m7B1YYoG6rfwrbrmDZamwo91kgLb5uPECFiK oijatS3ZxPFwMWr2AUjql6jcR/1F1g325zDpndw69NHbMJkPTbxTvxsCxR9p4dudZU W67TxVDKjLmcWpMxCSvtBZF2J1eUcQAf+WXCCH60iG2g0LTx0bWehAoUfGyDQHMVUQ w+dawelakOzIA== Date: Thu, 16 Feb 2023 13:05:30 -0800 Subject: [PATCH 09/10] xfs_io: parent command is not experts-only From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880376.3477097.9371089403493745661.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong This command isn't dangerous, so don't make it experts-only. Signed-off-by: Darrick J. Wong --- io/parent.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/io/parent.c b/io/parent.c index 694c0839..36522f26 100644 --- a/io/parent.c +++ b/io/parent.c @@ -275,6 +275,5 @@ parent_init(void) parent_cmd.oneline = _("print parent inodes"); parent_cmd.help = parent_help; - if (expert) - add_command(&parent_cmd); + add_command(&parent_cmd); } From patchwork Thu Feb 16 21:05:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Darrick J. Wong" X-Patchwork-Id: 13143912 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9BF92C61DA4 for ; Thu, 16 Feb 2023 21:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230094AbjBPVFv (ORCPT ); Thu, 16 Feb 2023 16:05:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230092AbjBPVFu (ORCPT ); Thu, 16 Feb 2023 16:05:50 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6CFF5505D3 for ; Thu, 16 Feb 2023 13:05:49 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2203BB8217A for ; Thu, 16 Feb 2023 21:05:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D5A53C433D2; Thu, 16 Feb 2023 21:05:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581546; bh=6cOgyUW9y6GN5eP5G8D80u6r5GILEMLNN7CpNCsLgJg=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=OMUi739qzljWx7TzA0tNuoBKRt/HaYU3a7QcJbtpj46v5ZzCU9Wk7er0tuQvp97WJ 8DtIkfuZJiHqGXnmcVYuvqYQjfTSNtraWbZmqzokvaemzqOGnwviBEFhRRD+YepN92 jdnIuPANnlt/8sTrN5Aks/bXi2o6bLc7mDB+3lhisL5sISMjcstqgXnDuc/rFMUHld OUOJ5BLQ07bjqGXh9XY6q8hufXT34F298xaQcr4ad5VYzMo6e0BQ98j0dxful5Wc9O akmF1DUthtK6DxV2sq1sC6SxgneAuT+ixUQbUFuxt/qCTRUbgQSem51sKQA6FcVCwM hXwL0l2sYRN9A== Date: Thu, 16 Feb 2023 13:05:46 -0800 Subject: [PATCH 10/10] xfs_scrub: use parent pointers when possible to report file operations From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657880389.3477097.12099364278909899946.stgit@magnolia> In-Reply-To: <167657880257.3477097.11495108667073036392.stgit@magnolia> References: <167657880257.3477097.11495108667073036392.stgit@magnolia> User-Agent: StGit/0.19 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org From: Darrick J. Wong If parent pointers are available, use them to supply file paths when doing things to files, instead of merely printing the inode number. Signed-off-by: Darrick J. Wong --- scrub/common.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/scrub/common.c b/scrub/common.c index 49a87f41..9f3cde9b 100644 --- a/scrub/common.c +++ b/scrub/common.c @@ -12,6 +12,7 @@ #include "xfs_scrub.h" #include "common.h" #include "progress.h" +#include "libfrog/pptrs.h" extern char *progname; @@ -407,6 +408,26 @@ scrub_render_ino_descr( uint32_t agino; int ret; + if (ctx->mnt.fsgeom.flags & XFS_FSOP_GEOM_FLAGS_PARENT) { + struct xfs_handle handle; + + memcpy(&handle.ha_fsid, ctx->fshandle, sizeof(handle.ha_fsid)); + handle.ha_fid.fid_len = sizeof(xfs_fid_t) - + sizeof(handle.ha_fid.fid_len); + handle.ha_fid.fid_pad = 0; + handle.ha_fid.fid_ino = ino; + handle.ha_fid.fid_gen = gen; + + ret = handle_to_path(&handle, sizeof(struct xfs_handle), buf, + buflen); + /* + * If successful, return any positive integer to use the + * formatted error string. + */ + if (ret == 0) + return 1; + } + agno = cvt_ino_to_agno(&ctx->mnt, ino); agino = cvt_ino_to_agino(&ctx->mnt, ino); ret = snprintf(buf, buflen, _("inode %"PRIu64" (%"PRIu32"/%"PRIu32")%s"),