]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
libhandle: add support for bulkstat v5
authorDarrick J. Wong <djwong@kernel.org>
Mon, 29 Jul 2024 23:22:59 +0000 (16:22 -0700)
committerDarrick J. Wong <djwong@kernel.org>
Tue, 30 Jul 2024 00:01:05 +0000 (17:01 -0700)
Add support to libhandle for generating file handles with bulkstat v5
structures.  xfs_fsr will need this to be able to interface with the new
vfs range swap ioctl, and other client programs will probably want this
over time.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
include/jdm.h
libhandle/jdm.c

index c57fcae7fcac4004ddaa2537f0ca5c4c553fce63..50c2296b45e99415ce04b71704a258c1cfa04188 100644 (file)
@@ -11,6 +11,7 @@ typedef void  jdm_fshandle_t;         /* filesystem handle */
 typedef void   jdm_filehandle_t;       /* filehandle */
 
 struct xfs_bstat;
+struct xfs_bulkstat;
 struct attrlist_cursor;
 struct parent;
 
@@ -23,6 +24,9 @@ jdm_new_filehandle( jdm_filehandle_t **handlep,       /* new filehandle */
                    jdm_fshandle_t *fshandlep,  /* filesystem filehandle */
                    struct xfs_bstat *sp);      /* bulkstat info */
 
+void jdm_new_filehandle_v5(jdm_filehandle_t **handlep, size_t *hlen,
+               jdm_fshandle_t *fshandlep, struct xfs_bulkstat *sp);
+
 extern void
 jdm_delete_filehandle( jdm_filehandle_t *handlep,/* filehandle to delete */
                       size_t hlen);            /* filehandle size */
@@ -32,35 +36,54 @@ jdm_open( jdm_fshandle_t *fshandlep,
          struct xfs_bstat *sp,
          intgen_t oflags);
 
+intgen_t jdm_open_v5(jdm_fshandle_t *fshandlep, struct xfs_bulkstat *sp,
+               intgen_t oflags);
+
 extern intgen_t
 jdm_readlink( jdm_fshandle_t *fshandlep,
              struct xfs_bstat *sp,
              char *bufp,
              size_t bufsz);
 
+intgen_t jdm_readlink_v5(jdm_fshandle_t *fshandlep, struct xfs_bulkstat *sp,
+               char *bufp, size_t bufsz);
+
 extern intgen_t
 jdm_attr_multi(        jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
                char *bufp, int rtrvcnt, int flags);
 
+intgen_t jdm_attr_multi_v5(jdm_fshandle_t *fshp, struct xfs_bulkstat *statp,
+               char *bufp, int rtrvcnt, int flags);
+
 extern intgen_t
 jdm_attr_list( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
                char *bufp, size_t bufsz, int flags,
                struct attrlist_cursor *cursor);
 
+intgen_t jdm_attr_list_v5(jdm_fshandle_t *fshp, struct xfs_bulkstat *statp,
+               char *bufp, size_t bufsz, int flags,
+               struct attrlist_cursor *cursor);
+
 extern int
 jdm_parents( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
                struct parent *bufp, size_t bufsz,
                unsigned int *count);
 
+int jdm_parents_v5(jdm_fshandle_t *fshp, struct xfs_bulkstat *statp,
+               struct parent *bufp, size_t bufsz, unsigned int *count);
+
 extern int
 jdm_parentpaths( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
                struct parent *bufp, size_t bufsz,
                unsigned int *count);
 
+int jdm_parentpaths_v5(jdm_fshandle_t *fshp, struct xfs_bulkstat *statp,
+               struct parent *bufp, size_t bufsz, unsigned int *count);
+
 /* macro for determining the size of a structure member */
 #define sizeofmember( t, m )   sizeof( ( ( t * )0 )->m )
 
index 07b0c60985ee9a749a019c12e1f8cbb59f43cf69..e21aff2b2c1972d854be6c8501b67097d8c40286 100644 (file)
@@ -41,6 +41,19 @@ jdm_fill_filehandle( filehandle_t *handlep,
        handlep->fh_ino = statp->bs_ino;
 }
 
+static void
+jdm_fill_filehandle_v5(
+       struct filehandle       *handlep,
+       struct fshandle         *fshandlep,
+       struct xfs_bulkstat     *statp)
+{
+       handlep->fh_fshandle = *fshandlep;
+       handlep->fh_sz_following = FILEHANDLE_SZ_FOLLOWING;
+       memset(handlep->fh_pad, 0, FILEHANDLE_SZ_PAD);
+       handlep->fh_gen = statp->bs_gen;
+       handlep->fh_ino = statp->bs_ino;
+}
+
 jdm_fshandle_t *
 jdm_getfshandle( char *mntpnt )
 {
@@ -90,6 +103,22 @@ jdm_new_filehandle( jdm_filehandle_t **handlep,
                jdm_fill_filehandle(*handlep, (fshandle_t *) fshandlep, statp);
 }
 
+void
+jdm_new_filehandle_v5(
+       jdm_filehandle_t        **handlep,
+       size_t                  *hlen,
+       jdm_fshandle_t          *fshandlep,
+       struct xfs_bulkstat     *statp)
+{
+       /* allocate and fill filehandle */
+       *hlen = sizeof(filehandle_t);
+       *handlep = (filehandle_t *) malloc(*hlen);
+       if (!*handlep)
+               return;
+
+       jdm_fill_filehandle_v5(*handlep, (struct fshandle *)fshandlep, statp);
+}
+
 /* ARGSUSED */
 void
 jdm_delete_filehandle( jdm_filehandle_t *handlep, size_t hlen )
@@ -111,6 +140,19 @@ jdm_open( jdm_fshandle_t *fshp, struct xfs_bstat *statp, intgen_t oflags )
        return fd;
 }
 
+intgen_t
+jdm_open_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       intgen_t                oflags)
+{
+       struct fshandle         *fshandlep = (struct fshandle *)fshp;
+       struct filehandle       filehandle;
+
+       jdm_fill_filehandle_v5(&filehandle, fshandlep, statp);
+       return open_by_fshandle(&filehandle, sizeof(filehandle), oflags);
+}
+
 intgen_t
 jdm_readlink( jdm_fshandle_t *fshp,
              struct xfs_bstat *statp,
@@ -128,6 +170,20 @@ jdm_readlink( jdm_fshandle_t *fshp,
        return rval;
 }
 
+intgen_t
+jdm_readlink_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       char                    *bufp,
+       size_t                  bufsz)
+{
+       struct fshandle         *fshandlep = (struct fshandle *)fshp;
+       struct filehandle       filehandle;
+
+       jdm_fill_filehandle_v5(&filehandle, fshandlep, statp);
+       return readlink_by_handle(&filehandle, sizeof(filehandle), bufp, bufsz);
+}
+
 int
 jdm_attr_multi(        jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
@@ -145,6 +201,22 @@ jdm_attr_multi(    jdm_fshandle_t *fshp,
        return rval;
 }
 
+int
+jdm_attr_multi_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       char                    *bufp,
+       int                     rtrvcnt,
+       int                     flags)
+{
+       struct fshandle         *fshandlep = (struct fshandle *)fshp;
+       struct filehandle       filehandle;
+
+       jdm_fill_filehandle_v5(&filehandle, fshandlep, statp);
+       return attr_multi_by_handle(&filehandle, sizeof(filehandle), bufp,
+                       rtrvcnt, flags);
+}
+
 int
 jdm_attr_list( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
@@ -166,6 +238,27 @@ jdm_attr_list(     jdm_fshandle_t *fshp,
        return rval;
 }
 
+int
+jdm_attr_list_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       char                    *bufp,
+       size_t                  bufsz,
+       int                     flags,
+       struct attrlist_cursor  *cursor)
+{
+       struct fshandle         *fshandlep = (struct fshandle *)fshp;
+       struct filehandle       filehandle;
+
+       /* prevent needless EINVAL from the kernel */
+       if (bufsz > XFS_XATTR_LIST_MAX)
+               bufsz = XFS_XATTR_LIST_MAX;
+
+       jdm_fill_filehandle_v5(&filehandle, fshandlep, statp);
+       return attr_list_by_handle(&filehandle, sizeof(filehandle), bufp,
+                       bufsz, flags, cursor);
+}
+
 int
 jdm_parents( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
@@ -176,6 +269,18 @@ jdm_parents( jdm_fshandle_t *fshp,
        return -1;
 }
 
+int
+jdm_parents_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       struct parent           *bufp,
+       size_t                  bufsz,
+       unsigned int            *count)
+{
+       errno = EOPNOTSUPP;
+       return -1;
+}
+
 int
 jdm_parentpaths( jdm_fshandle_t *fshp,
                struct xfs_bstat *statp,
@@ -185,3 +290,15 @@ jdm_parentpaths( jdm_fshandle_t *fshp,
        errno = EOPNOTSUPP;
        return -1;
 }
+
+int
+jdm_parentpaths_v5(
+       jdm_fshandle_t          *fshp,
+       struct xfs_bulkstat     *statp,
+       struct parent           *bufp,
+       size_t                  bufsz,
+       unsigned int            *count)
+{
+       errno = EOPNOTSUPP;
+       return -1;
+}