From patchwork Thu Feb 16 21:12:16 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: 13143938 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 7DC50C61DA4 for ; Thu, 16 Feb 2023 21:12:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230176AbjBPVMT (ORCPT ); Thu, 16 Feb 2023 16:12:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjBPVMT (ORCPT ); Thu, 16 Feb 2023 16:12:19 -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 E71292BF17 for ; Thu, 16 Feb 2023 13:12:17 -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 848EA60A65 for ; Thu, 16 Feb 2023 21:12:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3908C433D2; Thu, 16 Feb 2023 21:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581936; bh=KBLlmPl1kyYmza4O1Amh/NzzWPgoYW+hdJsWmlaEIOA=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=putqZglIMJFSjvRq6X+ZxXiqwKg+CBIqfhtrXCATwVbeb8Y1vUIkCxVbW8Tab3jBb Tjzbh5SaG7FAzw5auiM8eyXQIx0PmEF8SOM5d1mu5z7RcWlcZay6OgsrdQOvo0F+fY x2IsesrRwcvjUPjExu5q+lJudCRY/wOJkl1cl49Q5TM9sbt3Jos5MgkcmKdsaueSUs ASOUdxanWcyBRbOh5amUeBN2lDR002TYfrczvbxxBBUpi+y6kteWVfWD1tzmo8tvA5 vElpTlaAWPXQtxdOH5CWam9PvKXBMpHbVacH5duJtZIf8bY8WoikZvw9zcVVrlmk18 jzdQA0x0p1KGg== Date: Thu, 16 Feb 2023 13:12:16 -0800 Subject: [PATCH 1/3] xfs: rename xfs_pptr_info to xfs_getparents From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657882759.3478223.9534389676327770055.stgit@magnolia> In-Reply-To: <167657882746.3478223.17677270918788774260.stgit@magnolia> References: <167657882746.3478223.17677270918788774260.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 Rename the head structure of the parent pointer ioctl to match the name of the ioctl (XFS_IOC_GETPARENTS). Signed-off-by: Darrick J. Wong --- io/parent.c | 4 ++-- libfrog/pptrs.c | 28 ++++++++++++++-------------- libfrog/pptrs.h | 2 +- libxfs/xfs_fs.h | 51 ++++++++++++++++++++++++++------------------------- man/man3/xfsctl.3 | 16 ++++++++-------- 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/io/parent.c b/io/parent.c index 36522f26..1c1453f2 100644 --- a/io/parent.c +++ b/io/parent.c @@ -24,14 +24,14 @@ struct pptr_args { static int pptr_print( - struct xfs_pptr_info *pi, + struct xfs_getparents *pi, struct xfs_parent_ptr *pptr, void *arg) { struct pptr_args *args = arg; unsigned int namelen; - if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) { + if (pi->gp_flags & XFS_GETPARENTS_OFLAG_ROOT) { printf(_("Root directory.\n")); return 0; } diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 61fd1fb9..3bb441f0 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -12,17 +12,17 @@ #include "libfrog/pptrs.h" /* Allocate a buffer large enough for some parent pointer records. */ -static inline struct xfs_pptr_info * +static inline struct xfs_getparents * alloc_pptr_buf( size_t nr_ptrs) { - struct xfs_pptr_info *pi; + struct xfs_getparents *pi; - pi = malloc(xfs_pptr_info_sizeof(nr_ptrs)); + pi = malloc(xfs_getparents_sizeof(nr_ptrs)); if (!pi) return NULL; - memset(pi, 0, sizeof(struct xfs_pptr_info)); - pi->pi_ptrs_size = nr_ptrs; + memset(pi, 0, sizeof(struct xfs_getparents)); + pi->gp_ptrs_size = nr_ptrs; return pi; } @@ -37,7 +37,7 @@ handle_walk_parents( walk_pptr_fn fn, void *arg) { - struct xfs_pptr_info *pi; + struct xfs_getparents *pi; struct xfs_parent_ptr *p; unsigned int i; ssize_t ret = -1; @@ -47,25 +47,25 @@ handle_walk_parents( return errno; if (handle) { - memcpy(&pi->pi_handle, handle, sizeof(struct xfs_handle)); - pi->pi_flags = XFS_PPTR_IFLAG_HANDLE; + memcpy(&pi->gp_handle, handle, sizeof(struct xfs_handle)); + pi->gp_flags = XFS_GETPARENTS_IFLAG_HANDLE; } ret = ioctl(fd, XFS_IOC_GETPARENTS, pi); while (!ret) { - if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) { + if (pi->gp_flags & XFS_GETPARENTS_OFLAG_ROOT) { ret = fn(pi, NULL, arg); goto out_pi; } - for (i = 0; i < pi->pi_ptrs_used; i++) { - p = xfs_ppinfo_to_pp(pi, i); + for (i = 0; i < pi->gp_ptrs_used; i++) { + p = xfs_getparents_rec(pi, i); ret = fn(pi, p, arg); if (ret) goto out_pi; } - if (pi->pi_flags & XFS_PPTR_OFLAG_DONE) + if (pi->gp_flags & XFS_GETPARENTS_OFLAG_DONE) break; ret = ioctl(fd, XFS_IOC_GETPARENTS, pi); @@ -128,7 +128,7 @@ static int handle_walk_parent_paths(struct walk_ppaths_info *wpi, static int handle_walk_parent_path_ptr( - struct xfs_pptr_info *pi, + struct xfs_getparents *pi, struct xfs_parent_ptr *p, void *arg) { @@ -136,7 +136,7 @@ handle_walk_parent_path_ptr( struct walk_ppaths_info *wpi = wpli->wpi; int ret = 0; - if (pi->pi_flags & XFS_PPTR_OFLAG_ROOT) + if (pi->gp_flags & XFS_GETPARENTS_OFLAG_ROOT) return wpi->fn(wpi->mntpt, wpi->path, wpi->arg); ret = path_component_change(wpli->pc, p->xpp_name, diff --git a/libfrog/pptrs.h b/libfrog/pptrs.h index 1666de06..ab1d0f2f 100644 --- a/libfrog/pptrs.h +++ b/libfrog/pptrs.h @@ -8,7 +8,7 @@ struct path_list; -typedef int (*walk_pptr_fn)(struct xfs_pptr_info *pi, +typedef int (*walk_pptr_fn)(struct xfs_getparents *pi, struct xfs_parent_ptr *pptr, void *arg); typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, void *arg); diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index c65345d2..2a23c010 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -752,19 +752,20 @@ struct xfs_scrub_metadata { XFS_SCRUB_OFLAG_NO_REPAIR_NEEDED) #define XFS_SCRUB_FLAGS_ALL (XFS_SCRUB_FLAGS_IN | XFS_SCRUB_FLAGS_OUT) -#define XFS_PPTR_MAXNAMELEN 256 +#define XFS_GETPARENTS_MAXNAMELEN 256 /* return parents of the handle, not the open fd */ -#define XFS_PPTR_IFLAG_HANDLE (1U << 0) +#define XFS_GETPARENTS_IFLAG_HANDLE (1U << 0) /* target was the root directory */ -#define XFS_PPTR_OFLAG_ROOT (1U << 1) +#define XFS_GETPARENTS_OFLAG_ROOT (1U << 1) /* Cursor is done iterating pptrs */ -#define XFS_PPTR_OFLAG_DONE (1U << 2) +#define XFS_GETPARENTS_OFLAG_DONE (1U << 2) - #define XFS_PPTR_FLAG_ALL (XFS_PPTR_IFLAG_HANDLE | XFS_PPTR_OFLAG_ROOT | \ - XFS_PPTR_OFLAG_DONE) +#define XFS_GETPARENTS_FLAG_ALL (XFS_GETPARENTS_IFLAG_HANDLE | \ + XFS_GETPARENTS_OFLAG_ROOT | \ + XFS_GETPARENTS_OFLAG_DONE) /* Get an inode parent pointer through ioctl */ struct xfs_parent_ptr { @@ -772,57 +773,57 @@ struct xfs_parent_ptr { __u32 xpp_gen; /* Inode generation */ __u32 xpp_rsvd; /* Reserved */ __u64 xpp_rsvd2; /* Reserved */ - __u8 xpp_name[XFS_PPTR_MAXNAMELEN]; /* File name */ + __u8 xpp_name[XFS_GETPARENTS_MAXNAMELEN]; /* File name */ }; /* Iterate through an inodes parent pointers */ -struct xfs_pptr_info { - /* File handle, if XFS_PPTR_IFLAG_HANDLE is set */ - struct xfs_handle pi_handle; +struct xfs_getparents { + /* File handle, if XFS_GETPARENTS_IFLAG_HANDLE is set */ + struct xfs_handle gp_handle; /* * Structure to track progress in iterating the parent pointers. * Must be initialized to zeroes before the first ioctl call, and * not touched by callers after that. */ - struct xfs_attrlist_cursor pi_cursor; + struct xfs_attrlist_cursor gp_cursor; - /* Operational flags: XFS_PPTR_*FLAG* */ - __u32 pi_flags; + /* Operational flags: XFS_GETPARENTS_*FLAG* */ + __u32 gp_flags; /* Must be set to zero */ - __u32 pi_reserved; + __u32 gp_reserved; /* # of entries in array */ - __u32 pi_ptrs_size; + __u32 gp_ptrs_size; /* # of entries filled in (output) */ - __u32 pi_ptrs_used; + __u32 gp_ptrs_used; /* Must be set to zero */ - __u64 pi_reserved2[6]; + __u64 gp_reserved2[6]; /* * An array of struct xfs_parent_ptr follows the header - * information. Use xfs_ppinfo_to_pp() to access the + * information. Use xfs_getparents_rec() to access the * parent pointer array entries. */ - struct xfs_parent_ptr pi_parents[]; + struct xfs_parent_ptr gp_parents[]; }; static inline size_t -xfs_pptr_info_sizeof(int nr_ptrs) +xfs_getparents_sizeof(int nr_ptrs) { - return sizeof(struct xfs_pptr_info) + + return sizeof(struct xfs_getparents) + (nr_ptrs * sizeof(struct xfs_parent_ptr)); } static inline struct xfs_parent_ptr* -xfs_ppinfo_to_pp( - struct xfs_pptr_info *info, - int idx) +xfs_getparents_rec( + struct xfs_getparents *info, + unsigned int idx) { - return &info->pi_parents[idx]; + return &info->gp_parents[idx]; } /* diff --git a/man/man3/xfsctl.3 b/man/man3/xfsctl.3 index 42ba3bba..0bcf8886 100644 --- a/man/man3/xfsctl.3 +++ b/man/man3/xfsctl.3 @@ -326,12 +326,12 @@ XFS_IOC_FSSETDM_BY_HANDLE is not supported as of Linux 5.5. .B XFS_IOC_GETPARENTS This command is used to get a files parent pointers. Parent pointers are file attributes used to store meta data information about an inodes parent. -This command takes a xfs_pptr_info structure with trailing array of +This command takes a xfs_getparents structure with trailing array of struct xfs_parent_ptr as an input to store an inodes parents. The -xfs_pptr_info_sizeof() and xfs_ppinfo_to_pp() routines are provided to +xfs_getparents_sizeof() and xfs_getparents_rec() routines are provided to create and iterate through these structures. The number of pointers stored -in the array is indicated by the xfs_pptr_info.used field, and the -XFS_PPTR_OFLAG_DONE flag will be set in xfs_pptr_info.flags when there are +in the array is indicated by the xfs_getparents.used field, and the +XFS_PPTR_OFLAG_DONE flag will be set in xfs_getparents.flags when there are no more parent pointers to be read. The below code is an example of XFS_IOC_GETPARENTS usage: @@ -345,13 +345,13 @@ of XFS_IOC_GETPARENTS usage: #include int main() { - struct xfs_pptr_info *pi; + struct xfs_getparents *pi; struct xfs_parent_ptr *p; int i, error, fd, nr_ptrs = 4; - unsigned char buffer[xfs_pptr_info_sizeof(nr_ptrs)]; + unsigned char buffer[xfs_getparents_sizeof(nr_ptrs)]; memset(buffer, 0, sizeof(buffer)); - pi = (struct xfs_pptr_info *)&buffer; + pi = (struct xfs_getparents *)&buffer; pi->pi_ptrs_size = nr_ptrs; fd = open("/mnt/test/foo.txt", O_RDONLY | O_CREAT); @@ -364,7 +364,7 @@ int main() { return error; for (i = 0; i < pi->pi_ptrs_used; i++) { - p = xfs_ppinfo_to_pp(pi, i); + p = xfs_getparents_rec(pi, i); printf("inode = %llu\\n", (unsigned long long)p->xpp_ino); printf("generation = %u\\n", (unsigned int)p->xpp_gen); printf("name = \\"%s\\"\\n\\n", (char *)p->xpp_name); From patchwork Thu Feb 16 21:12:32 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: 13143939 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 C3D8EC636CC for ; Thu, 16 Feb 2023 21:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbjBPVMg (ORCPT ); Thu, 16 Feb 2023 16:12:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229866AbjBPVMg (ORCPT ); Thu, 16 Feb 2023 16:12:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BEB92BEC4 for ; Thu, 16 Feb 2023 13:12:35 -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 CF31DB82760 for ; Thu, 16 Feb 2023 21:12:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AFBAC433D2; Thu, 16 Feb 2023 21:12:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581952; bh=AONjIdRC3i/exYU/3MyWn29Ni+0cdznK6QGeQKKE3/U=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=vH9hmPmdH9ZPYlKdWgxYZByi+pER5OYt+MhlwH6CGBMz/CbpoArXGejmSuBDUUeLd v1bt+XZpDPpCrLdU7x1czS2ML7gLDS1gPHO8Z1xQI50b8y4RPFwGvVLmBY8rHX5hWK wAgVALfV7aiECEiWiwUkwILUVz/tQg7prlhzVa1SIMKvXFofmyPkER1G6quVn5kOoa ZJBLwpY8+GHXrrrd4uYbneUUv817luCvrXIXF1+9LUasdIRwHKtY8VarKcn3oIrVZh /cFe9sK6BeTAwZ+RvpfOXbGCQn9++Uwt82LnMT1AcgMKpvV3EX4BF4QF/prXRHDXar /KOIWPnE9lMfw== Date: Thu, 16 Feb 2023 13:12:32 -0800 Subject: [PATCH 2/3] xfs: rename xfs_parent_ptr From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657882772.3478223.7099237750506767525.stgit@magnolia> In-Reply-To: <167657882746.3478223.17677270918788774260.stgit@magnolia> References: <167657882746.3478223.17677270918788774260.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 Change the name to xfs_getparents_rec so that the name matches the head structure. Signed-off-by: Darrick J. Wong --- io/parent.c | 18 +++++++++--------- libfrog/pptrs.c | 12 ++++++------ libfrog/pptrs.h | 2 +- libxfs/xfs_fs.h | 22 +++++++++++----------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/io/parent.c b/io/parent.c index 1c1453f2..162c3169 100644 --- a/io/parent.c +++ b/io/parent.c @@ -25,7 +25,7 @@ struct pptr_args { static int pptr_print( struct xfs_getparents *pi, - struct xfs_parent_ptr *pptr, + struct xfs_getparents_rec *pptr, void *arg) { struct pptr_args *args = arg; @@ -36,21 +36,21 @@ pptr_print( return 0; } - if (args->filter_ino && pptr->xpp_ino != args->filter_ino) + if (args->filter_ino && pptr->gpr_ino != args->filter_ino) return 0; - if (args->filter_name && strcmp(args->filter_name, pptr->xpp_name)) + if (args->filter_name && strcmp(args->filter_name, pptr->gpr_name)) return 0; - namelen = strlen(pptr->xpp_name); + namelen = strlen(pptr->gpr_name); if (args->shortformat) { printf("%llu/%u/%u/%s\n", - (unsigned long long)pptr->xpp_ino, - (unsigned int)pptr->xpp_gen, namelen, pptr->xpp_name); + (unsigned long long)pptr->gpr_ino, + (unsigned int)pptr->gpr_gen, namelen, pptr->gpr_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_ino = %llu\n"), (unsigned long long)pptr->gpr_ino); + printf(_("p_gen = %u\n"), (unsigned int)pptr->gpr_gen); printf(_("p_reclen = %u\n"), namelen); - printf(_("p_name = \"%s\"\n\n"), pptr->xpp_name); + printf(_("p_name = \"%s\"\n\n"), pptr->gpr_name); } return 0; } diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 3bb441f0..48a09f69 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -38,7 +38,7 @@ handle_walk_parents( void *arg) { struct xfs_getparents *pi; - struct xfs_parent_ptr *p; + struct xfs_getparents_rec *p; unsigned int i; ssize_t ret = -1; @@ -129,7 +129,7 @@ static int handle_walk_parent_paths(struct walk_ppaths_info *wpi, static int handle_walk_parent_path_ptr( struct xfs_getparents *pi, - struct xfs_parent_ptr *p, + struct xfs_getparents_rec *p, void *arg) { struct walk_ppath_level_info *wpli = arg; @@ -139,13 +139,13 @@ handle_walk_parent_path_ptr( if (pi->gp_flags & XFS_GETPARENTS_OFLAG_ROOT) return wpi->fn(wpi->mntpt, wpi->path, wpi->arg); - ret = path_component_change(wpli->pc, p->xpp_name, - strlen((char *)p->xpp_name), p->xpp_ino); + ret = path_component_change(wpli->pc, p->gpr_name, + strlen((char *)p->gpr_name), p->gpr_ino); if (ret) return ret; - wpli->newhandle.ha_fid.fid_ino = p->xpp_ino; - wpli->newhandle.ha_fid.fid_gen = p->xpp_gen; + wpli->newhandle.ha_fid.fid_ino = p->gpr_ino; + wpli->newhandle.ha_fid.fid_gen = p->gpr_gen; path_list_add_parent_component(wpi->path, wpli->pc); ret = handle_walk_parent_paths(wpi, &wpli->newhandle); diff --git a/libfrog/pptrs.h b/libfrog/pptrs.h index ab1d0f2f..05aaea60 100644 --- a/libfrog/pptrs.h +++ b/libfrog/pptrs.h @@ -9,7 +9,7 @@ struct path_list; typedef int (*walk_pptr_fn)(struct xfs_getparents *pi, - struct xfs_parent_ptr *pptr, void *arg); + struct xfs_getparents_rec *pptr, void *arg); typedef int (*walk_ppath_fn)(const char *mntpt, struct path_list *path, void *arg); diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index 2a23c010..ec6fdf78 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -768,12 +768,12 @@ struct xfs_scrub_metadata { XFS_GETPARENTS_OFLAG_DONE) /* Get an inode parent pointer through ioctl */ -struct xfs_parent_ptr { - __u64 xpp_ino; /* Inode */ - __u32 xpp_gen; /* Inode generation */ - __u32 xpp_rsvd; /* Reserved */ - __u64 xpp_rsvd2; /* Reserved */ - __u8 xpp_name[XFS_GETPARENTS_MAXNAMELEN]; /* File name */ +struct xfs_getparents_rec { + __u64 gpr_ino; /* Inode */ + __u32 gpr_gen; /* Inode generation */ + __u32 gpr_rsvd; /* Reserved */ + __u64 gpr_rsvd2; /* Reserved */ + __u8 gpr_name[XFS_GETPARENTS_MAXNAMELEN]; /* File name */ }; /* Iterate through an inodes parent pointers */ @@ -804,21 +804,21 @@ struct xfs_getparents { __u64 gp_reserved2[6]; /* - * An array of struct xfs_parent_ptr follows the header + * An array of struct xfs_getparents_rec follows the header * information. Use xfs_getparents_rec() to access the * parent pointer array entries. */ - struct xfs_parent_ptr gp_parents[]; + struct xfs_getparents_rec gp_parents[]; }; static inline size_t xfs_getparents_sizeof(int nr_ptrs) { return sizeof(struct xfs_getparents) + - (nr_ptrs * sizeof(struct xfs_parent_ptr)); + (nr_ptrs * sizeof(struct xfs_getparents_rec)); } -static inline struct xfs_parent_ptr* +static inline struct xfs_getparents_rec* xfs_getparents_rec( struct xfs_getparents *info, unsigned int idx) @@ -871,7 +871,7 @@ xfs_getparents_rec( /* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) -#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_parent_ptr) +#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents_rec) /* * ioctl commands that replace IRIX syssgi()'s From patchwork Thu Feb 16 21:12:47 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: 13143940 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 0D69CC636CC for ; Thu, 16 Feb 2023 21:12:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbjBPVMy (ORCPT ); Thu, 16 Feb 2023 16:12:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229930AbjBPVMx (ORCPT ); Thu, 16 Feb 2023 16:12:53 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C4A26A57 for ; Thu, 16 Feb 2023 13:12:51 -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 EB75CCE2D79 for ; Thu, 16 Feb 2023 21:12:49 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3F81CC433D2; Thu, 16 Feb 2023 21:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1676581968; bh=o2MGK8frsrbTU8GIbCIrGm9G3NKiWA2O/9HdEF1eNoM=; h=Date:Subject:From:To:Cc:In-Reply-To:References:From; b=UmGgglSZHatjRw2TOQPVYhMjSi5YArUHoPRq2UZR61BaWS7m0H+yzrY6GuTOAxo/0 CMCz9b8a0QQJECPeb5UQe0LNLhX9WSYYySRyokHrqqsSMSwg2yHz5UNgVfSN9IA7Zl cnnOPY3AM78EfDVdMAx266GC/XM8F77eg+/ON6zD/Yc1muvBa0WI9Cz219WtlfLbq2 xXTAvWrywTm1R53Q+VQrQiTUNvEsGup9dWdWFR0l9uA0xdqHfyJ7VtTSzxDJauUGED FFtZAvLe38+c94S3iUmH63o4vcx/LKlLrxr0G3EfdMKyT93NSFmOUA7+YBaSigUt6z 1kuVsvbHKv2FA== Date: Thu, 16 Feb 2023 13:12:47 -0800 Subject: [PATCH 3/3] xfs: convert GETPARENTS structures to flex arrays From: "Darrick J. Wong" To: djwong@kernel.org Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org Message-ID: <167657882785.3478223.6288557795459574411.stgit@magnolia> In-Reply-To: <167657882746.3478223.17677270918788774260.stgit@magnolia> References: <167657882746.3478223.17677270918788774260.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 The current definition of the GETPARENTS ioctl doesn't use the buffer space terribly efficiently because each parent pointer record struct incorporates enough space to hold the maximally sized dirent name. Most dirent names are much less than 255 bytes long, which means we're wasting a lot of space. Convert the xfs_getparents_rec structure to use a flex array to store the dirent name as a null terminated string, which allows us to pack the information much more densely. For this to work, augment the xfs_getparents struct to end with a flex array of buffer offsets to each xfs_getparents_rec object, much as we do for the attrlist multi ioctl. Record objects are allocated from the end of the buffer towards the head. Reduce the amount of data that we copy to userspace to the head array containg the offsets, and however much of the buffer's end is used for the parent records. Signed-off-by: Darrick J. Wong --- libfrog/pptrs.c | 12 ++++++------ libxfs/xfs_fs.h | 38 ++++++++++++++------------------------ 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/libfrog/pptrs.c b/libfrog/pptrs.c index 48a09f69..67fd40c3 100644 --- a/libfrog/pptrs.c +++ b/libfrog/pptrs.c @@ -14,15 +14,15 @@ /* Allocate a buffer large enough for some parent pointer records. */ static inline struct xfs_getparents * alloc_pptr_buf( - size_t nr_ptrs) + size_t bufsize) { struct xfs_getparents *pi; - pi = malloc(xfs_getparents_sizeof(nr_ptrs)); + pi = calloc(bufsize, 1); if (!pi) return NULL; - memset(pi, 0, sizeof(struct xfs_getparents)); - pi->gp_ptrs_size = nr_ptrs; + + pi->gp_bufsize = bufsize; return pi; } @@ -42,7 +42,7 @@ handle_walk_parents( unsigned int i; ssize_t ret = -1; - pi = alloc_pptr_buf(4); + pi = alloc_pptr_buf(XFS_XATTR_LIST_MAX); if (!pi) return errno; @@ -58,7 +58,7 @@ handle_walk_parents( goto out_pi; } - for (i = 0; i < pi->gp_ptrs_used; i++) { + for (i = 0; i < pi->gp_count; i++) { p = xfs_getparents_rec(pi, i); ret = fn(pi, p, arg); if (ret) diff --git a/libxfs/xfs_fs.h b/libxfs/xfs_fs.h index ec6fdf78..c8be1493 100644 --- a/libxfs/xfs_fs.h +++ b/libxfs/xfs_fs.h @@ -769,11 +769,11 @@ struct xfs_scrub_metadata { /* Get an inode parent pointer through ioctl */ struct xfs_getparents_rec { - __u64 gpr_ino; /* Inode */ - __u32 gpr_gen; /* Inode generation */ - __u32 gpr_rsvd; /* Reserved */ - __u64 gpr_rsvd2; /* Reserved */ - __u8 gpr_name[XFS_GETPARENTS_MAXNAMELEN]; /* File name */ + __u64 gpr_ino; /* Inode */ + __u32 gpr_gen; /* Inode generation */ + __u32 gpr_rsvd; /* Reserved */ + __u64 gpr_rsvd2; /* Reserved */ + __u8 gpr_name[]; /* File name and null terminator */ }; /* Iterate through an inodes parent pointers */ @@ -794,36 +794,26 @@ struct xfs_getparents { /* Must be set to zero */ __u32 gp_reserved; - /* # of entries in array */ - __u32 gp_ptrs_size; + /* size of the memory buffer in bytes, including this header */ + __u32 gp_bufsize; /* # of entries filled in (output) */ - __u32 gp_ptrs_used; + __u32 gp_count; /* Must be set to zero */ - __u64 gp_reserved2[6]; + __u64 gp_reserved2[5]; - /* - * An array of struct xfs_getparents_rec follows the header - * information. Use xfs_getparents_rec() to access the - * parent pointer array entries. - */ - struct xfs_getparents_rec gp_parents[]; + /* Byte offset of each xfs_getparents_rec object within the buffer. */ + __u32 gp_offsets[]; }; -static inline size_t -xfs_getparents_sizeof(int nr_ptrs) -{ - return sizeof(struct xfs_getparents) + - (nr_ptrs * sizeof(struct xfs_getparents_rec)); -} - static inline struct xfs_getparents_rec* xfs_getparents_rec( struct xfs_getparents *info, unsigned int idx) { - return &info->gp_parents[idx]; + return (struct xfs_getparents_rec *)((char *)info + + info->gp_offsets[idx]); } /* @@ -871,7 +861,7 @@ xfs_getparents_rec( /* XFS_IOC_GETFSMAP ------ hoisted 59 */ #define XFS_IOC_SCRUB_METADATA _IOWR('X', 60, struct xfs_scrub_metadata) #define XFS_IOC_AG_GEOMETRY _IOWR('X', 61, struct xfs_ag_geometry) -#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents_rec) +#define XFS_IOC_GETPARENTS _IOWR('X', 62, struct xfs_getparents) /* * ioctl commands that replace IRIX syssgi()'s