From patchwork Thu Mar 16 19:29:01 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: 13178242 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 DFC5BC6FD1F for ; Thu, 16 Mar 2023 19:29:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230147AbjCPT3G (ORCPT ); Thu, 16 Mar 2023 15:29:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjCPT3F (ORCPT ); Thu, 16 Mar 2023 15:29:05 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D53922795 for ; Thu, 16 Mar 2023 12:29:03 -0700 (PDT) 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 C1C32620F8 for ; Thu, 16 Mar 2023 19:29:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30127C433D2; Thu, 16 Mar 2023 19:29:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678994942; bh=KkYwuwKgUJrx+Jcb1Wq9oc2aPiv+rEtDOOKyPLAUs2U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=PlZRXil0q6YeJl9MxiTLO6MGotg+0Z9rij1dC2NR97xBxoqdzy9+uK5gvkPJFVe9+ YZkQNRurlsgMVDh1G5XVlt7260z9ptWcNHyoY9i9NV9ihyaXyE7DM3H9DKywmBQqHv 5k6EYrj87V5HekJRk6UKOIjaIxx+neFRyos5ulmt5fxXD/5qaPYVQ/Xzdktortv046 LDwHtKQVOK8Jj9NeGJ45M40TAuPpAx4OQkTrH01ms/VW6J1NpzHascBRRawZJEIe4C 2gtYZgBCe1LfCbAbPEwvDuTt3PWM5bNODLmfjz6ufb7WrzrBuvTlNPAWX9NayOBeqM s1u9gplbwP+3A== Date: Thu, 16 Mar 2023 12:29:01 -0700 Subject: [PATCH 1/7] 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: <167899416082.16628.16791646099642475394.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 2e136724b..fb9000419 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 6af342820..8c822cdeb 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 a86ae07c1..e541e2007 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 52538fb56..eb66df0c1 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 966ed74d5..b511f5b64 100644 --- a/libhandle/parent.c +++ b/libhandle/parent.c @@ -39,21 +39,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; @@ -72,20 +64,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_count; 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; } @@ -106,11 +91,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; @@ -124,20 +106,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 { @@ -155,15 +134,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; @@ -176,13 +153,13 @@ handle_walk_parent_path_ptr( for (i = 0; i < pi->pi_count; 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; @@ -198,10 +175,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; @@ -209,7 +183,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; @@ -217,8 +191,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); @@ -233,11 +207,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; @@ -256,7 +227,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; @@ -269,11 +240,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; @@ -295,7 +263,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; @@ -341,8 +309,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. */ @@ -356,5 +323,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 Mar 16 19:29:17 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: 13178243 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 30E09C6FD1F for ; Thu, 16 Mar 2023 19:29:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229755AbjCPT3X (ORCPT ); Thu, 16 Mar 2023 15:29:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjCPT3W (ORCPT ); Thu, 16 Mar 2023 15:29:22 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FECC3B0F5 for ; Thu, 16 Mar 2023 12:29:21 -0700 (PDT) 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 69729CE1E5A for ; Thu, 16 Mar 2023 19:29:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D8CADC433EF; Thu, 16 Mar 2023 19:29:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678994957; bh=x5WDhtF1UJx98WwrvTZDyBfJSxWWBTWL9jr4KIqVFHE=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=DKUZJmyYJpVz35LB0Ppir/xtXOLx+MOgXrrasmgy62SgdkN7G9LUD4XKP7n1RsxpL Patn4LQNXjNXJVonMXD+73FW3ZsCiC7Mr07QErJviZjQJteL2RcyehBfmLqqs6gw0H GQ81DLZXeCsiW6XbRdaORfkFeFSfenGFWxF4nuPiLe7kCxfYHQOzSfhTHESOmpodmR oQ5kOBmmIaV+hlkMZr/f4fZy0D3/xdwMTqH9WEAM/YM6ogKyHpefrZnFHkb3WSXc5K p6/Y6Kma0JSBXYVrqtMw51Z/qH5hKcRd6Dm35MME80yQn6F1DLN8BIBfFnbuvj9xP3 DnQdgNyAsCc5g== Date: Thu, 16 Mar 2023 12:29:17 -0700 Subject: [PATCH 2/7] 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: <167899416096.16628.7558790734995602619.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 fb9000419..4d3ad51b4 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 8c822cdeb..f5ebb40e4 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 011070823..5622ab9b0 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 b511f5b64..96de47b89 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) 2017-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 000000000..d174aa2a5 --- /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 cf7df67c8..f297a59e4 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 Mar 16 19:29:33 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: 13178244 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 C8ED7C6FD1F for ; Thu, 16 Mar 2023 19:29:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229589AbjCPT3k (ORCPT ); Thu, 16 Mar 2023 15:29:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229547AbjCPT3i (ORCPT ); Thu, 16 Mar 2023 15:29:38 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D74A7FD6D for ; Thu, 16 Mar 2023 12:29:36 -0700 (PDT) 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 C6DB9B82302 for ; Thu, 16 Mar 2023 19:29:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B206C433D2; Thu, 16 Mar 2023 19:29:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678994973; bh=VmiZ+G/Lhs1LAkZJEfgh8lDUqQJzMiD0ER68EqVMlf8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=KaaRk5UZQ55EbbPLZHcu+sDThLmvpyU7FtHUp0cakrfL5wJ0xU8s9PRk0MwLN+9vr khJAYkZBos4QoEYKGVzY1Aylg9TcwwGhEVy11ZRPa6LyI8s3FsL9yccPVCpXauVJDI BYHFRKf1plnoV5UzqOMVNwpx9qu7YP/LQt08zI9uKJ9rX2QIJSwatFitaKNKRBmDBe tLx5boem7n0mdgxc71Pw3wxZ0PDghJLA6Fz0riI+eVUqhArPoxQ+LC8L3D41pmH+vu EgoC2a8OGVbvskM+KgWXK0AvljS7lgjckG+JQd79DbZt3zhGw5PFh18C7TKgjeN1En H6skFsUcqLRtw== Date: Thu, 16 Mar 2023 12:29:33 -0700 Subject: [PATCH 3/7] 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: <167899416109.16628.17876653587515001968.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 96de47b89..6a4f60cf6 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -13,16 +13,16 @@ /* Allocate a buffer large enough for some parent pointer records. */ static inline struct xfs_pptr_info * -xfs_pptr_alloc( - size_t bufsize) +alloc_pptr_buf( + size_t bufsize) { - struct xfs_pptr_info *pi; + struct xfs_pptr_info *pi; - pi = calloc(bufsize, 1); - if (!pi) - return NULL; - pi->pi_ptrs_size = bufsize; - return pi; + pi = calloc(bufsize, 1); + if (!pi) + return NULL; + pi->pi_ptrs_size = bufsize; + return pi; } /* Walk all parents of the given file handle. */ @@ -38,7 +38,7 @@ handle_walk_parents( unsigned int i; ssize_t ret = -1; - pi = xfs_pptr_alloc(XFS_XATTR_LIST_MAX); + pi = alloc_pptr_buf(XFS_XATTR_LIST_MAX); if (!pi) return -1; From patchwork Thu Mar 16 19:29:48 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: 13178245 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 75273C6FD1F for ; Thu, 16 Mar 2023 19:30:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbjCPTaE (ORCPT ); Thu, 16 Mar 2023 15:30:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230214AbjCPT3x (ORCPT ); Thu, 16 Mar 2023 15:29:53 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F183273385 for ; Thu, 16 Mar 2023 12:29:51 -0700 (PDT) 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 5F135B8228E for ; Thu, 16 Mar 2023 19:29:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15C7FC433EF; Thu, 16 Mar 2023 19:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678994989; bh=8zWcXdhWdFj7ddmVXQhqBMSsORvaDpb+1KMdxyHAatA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=NagIanjb3iwi7w68RZQgmkId7A/SXnZSpNIJvY06P4Yl/u/lEubF7mTwL3BM9lEbc 30PP8bAY1mYsSMtTbBBiJNx8r6XwDIheGOiMKn6rEeVnhN31qSlErnefhmXp6FEZgG Ephqz+0atzkWaMclTx+8ZnI2MUyr67vw7kxypx667Y378UhA2b4YmfWFHtHhr87sN2 Pmt9b8+krie0Soum7WxOMymnILQXAL0cmFlpzKNEWEPKhp2KLIT+HYq9Yyc5ZBEaU+ gnciVm51TfgubCsGqk3ko+SBhrvkDnwZ1LB27QzK7gj4/JvB/cUmLtxcbeHOi++Vim 5Zrz3RXdpK7UA== Date: Thu, 16 Mar 2023 12:29:48 -0700 Subject: [PATCH 4/7] 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: <167899416122.16628.10916393155125095333.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 f5ebb40e4..6c0d81c12 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 e541e2007..cc43b02c4 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 6a4f60cf6..ac7fcea28 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -25,7 +25,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, @@ -40,7 +43,7 @@ handle_walk_parents( pi = alloc_pptr_buf(XFS_XATTR_LIST_MAX); if (!pi) - return -1; + return errno; if (handle) { memcpy(&pi->pi_handle, handle, sizeof(struct xfs_handle)); @@ -51,7 +54,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_count; i++) { @@ -66,13 +69,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, @@ -83,19 +88,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, @@ -157,6 +160,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( @@ -168,11 +172,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)); @@ -187,7 +192,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( @@ -199,17 +204,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; @@ -221,7 +224,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( @@ -237,15 +240,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; @@ -271,19 +274,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, @@ -292,13 +296,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, @@ -306,8 +317,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 d174aa2a5..1666de060 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 Mar 16 19:30:04 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: 13178246 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 1367CC6FD1F for ; Thu, 16 Mar 2023 19:30:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230235AbjCPTaK (ORCPT ); Thu, 16 Mar 2023 15:30:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbjCPTaJ (ORCPT ); Thu, 16 Mar 2023 15:30:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1638E77E00 for ; Thu, 16 Mar 2023 12:30:05 -0700 (PDT) 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 4DA28620EB for ; Thu, 16 Mar 2023 19:30:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA017C4339E; Thu, 16 Mar 2023 19:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678995004; bh=FgP25QasVGi1HXwOnRihELZ5cgFmJw7oQXQ2X2+/DwI=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=nvVANrxUGfuRFDDQmijTpxhKO22DJy7rp0TruQTP2im1mxVFYK+m9TWUp/TQ25kpP 2yy7dkGHD1CSIEfWeRIltLnldVWvxsOisuN6ANlda0Yj4uYLkhaGZw6/zaMCMnbhM+ jiZx4OlmtaqEJ3QtsQK2RMNyvKuMcuWnyLcJfgFOpBkmYGyjHdJ9k4c55hDozRSobK 78G/sGQFI3Bq3FckKhRcvBL9eAJSdAMVXagQlgNlVeC9LGCl/kNh3U4Duhu1jZVXWB Xx9J7QSuOFMN5lmjY+ZysLQs6TcrWSDVNQGJyRUCuig26Erwaby2YIXCmGdFptKh53 oTN5+rVrn98Jg== Date: Thu, 16 Mar 2023 12:30:04 -0700 Subject: [PATCH 5/7] 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: <167899416135.16628.9821897460513031802.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 ac7fcea28..b61a4e005 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -133,26 +133,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_count; 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 Mar 16 19:30:19 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: 13178247 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 3C3F4C6FD1F for ; Thu, 16 Mar 2023 19:30:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229597AbjCPTa1 (ORCPT ); Thu, 16 Mar 2023 15:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58390 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230305AbjCPTa0 (ORCPT ); Thu, 16 Mar 2023 15:30:26 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1A82685A55 for ; Thu, 16 Mar 2023 12:30:23 -0700 (PDT) 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 8B9FCB82302 for ; Thu, 16 Mar 2023 19:30:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44D7AC4339C; Thu, 16 Mar 2023 19:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678995020; bh=3GjQrUq7tVwIC8k/B8voSnlgNxrNNFjdDwApY/XUtb8=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=onpbzE/8P4u2op9MP65PrPHA/GTujtJaEUpUD/pcUu7VCOrwRxQMYPf+AycpgMpVi y2jresOXdXp5ouFr39JABGC0Chvh9KJJUDPEwdabCCyBhwHo32aXEL3Rii/sjUg3Ch 73APhEtzpNxLatc2oZ/VQqWshMD+Pex4Z/LrmpA5VpnNYJqAM3TaaFDvRznoqKGOOf y0ZAq++APF0VRXnXpwJbpIFl2mwfIOvArV02o7Y97bh19qWEdQoGPOdGcQfkONhdv4 mYXBZYs6yXB/XsVMa+NCWSPRH+XFizgRoilVY+W8jSjaiG2q7LuHuHIHr8BMddQhrv 50nV331quG2SQ== Date: Thu, 16 Mar 2023 12:30:19 -0700 Subject: [PATCH 6/7] 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: <167899416148.16628.3062260277371930152.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 6c0d81c12..36522f262 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 b61a4e005..488682738 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -267,10 +267,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 Mar 16 19:30:35 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: 13178248 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 1702BC6FD19 for ; Thu, 16 Mar 2023 19:30:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229489AbjCPTam (ORCPT ); Thu, 16 Mar 2023 15:30:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230260AbjCPTam (ORCPT ); Thu, 16 Mar 2023 15:30:42 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1CA26DC0A1 for ; Thu, 16 Mar 2023 12:30:37 -0700 (PDT) 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 6E17A620F1 for ; Thu, 16 Mar 2023 19:30:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0054C433D2; Thu, 16 Mar 2023 19:30:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678995035; bh=iCviZiQltjTcy+vt/iOvo/WHRVOCyTvk2x368hJOPLA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=lQMSWVbVQMPz4cpjZqnaR8qTjdYWMr5KkRJ9NRYPtY+p5x5jtASPhanUo0cAdkEoh EJRtWnZJ+xO9+/T+kAR+NlRQwLPQc7tnphlF3AHE22siLKicZIAde6bn83nKUlkC8Y e9m7ePm/edixMcg0vjx2biO6AliZoqB+SF5U+CFk7xsvbUqJ20ATHJHsImtmEFjUFZ z2NniN5j6/jzn66J2m3GbSx1OhyL0B6F9gv8vbo59QoWeltGbmXH5XI9vnu+jRk5Vt PXJoBkA0OSFalmQ8TzehlkVASJTPWo29/s8BJbHV8/baRO4K8EnMxg2+ZRBEIMTA0n q6FhqbIsRwRbQ== Date: Thu, 16 Mar 2023 12:30:35 -0700 Subject: [PATCH 7/7] libfrog: fix a buffer overrun in path_list_to_string From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167899416161.16628.955548688434298492.stgit@frogsfrogsfrogs> In-Reply-To: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> References: <167899416068.16628.8907331389138892555.stgit@frogsfrogsfrogs> 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 a buffer overrun when converting a path list to a string. Signed-off-by: Darrick J. Wong --- libfrog/paths.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libfrog/paths.c b/libfrog/paths.c index cc43b02c4..42e000295 100644 --- a/libfrog/paths.c +++ b/libfrog/paths.c @@ -694,13 +694,18 @@ path_list_to_string( size_t buflen) { struct path_component *pos; + char *buf_end = buf + buflen; ssize_t bytes = 0; int ret; list_for_each_entry(pos, &path->p_head, pc_list) { + if (buf >= buf_end) + return -1; + ret = snprintf(buf, buflen, "/%s", pos->pc_fname); - if (ret != 1 + strlen(pos->pc_fname)) + if (ret < 0 || ret >= buflen) return -1; + bytes += ret; buf += ret; buflen -= ret;