]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_spaceman: embed struct xfs_fd in struct fileio
authorDarrick J. Wong <darrick.wong@oracle.com>
Mon, 9 Sep 2019 19:37:07 +0000 (15:37 -0400)
committerEric Sandeen <sandeen@redhat.com>
Mon, 9 Sep 2019 19:37:07 +0000 (15:37 -0400)
Replace the open-coded fd and geometry fields of struct fileio with a
single xfs_fd, which will enable us to use it natively throughout
xfs_spaceman in upcoming patches.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
spaceman/file.c
spaceman/freesp.c
spaceman/info.c
spaceman/init.c
spaceman/prealloc.c
spaceman/space.h
spaceman/trim.c

index 29b7d9ce584bd11fc1464353e8588f75a028db4a..43b87e14af347db28e1d2a929ad8ffc691a39b54 100644 (file)
@@ -11,8 +11,8 @@
 #include "input.h"
 #include "init.h"
 #include "libfrog/paths.h"
-#include "space.h"
 #include "libfrog/fsgeom.h"
+#include "space.h"
 
 static cmdinfo_t print_cmd;
 
@@ -45,19 +45,13 @@ print_f(
 int
 openfile(
        char            *path,
-       struct xfs_fsop_geom *geom,
+       struct xfs_fd   *xfd,
        struct fs_path  *fs_path)
 {
        struct fs_path  *fsp;
-       int             fd, ret;
-
-       fd = open(path, 0);
-       if (fd < 0) {
-               perror(path);
-               return -1;
-       }
+       int             ret;
 
-       ret = xfrog_geometry(fd, geom);
+       ret = xfd_open(xfd, path, O_RDONLY);
        if (ret) {
                if (ret == ENOTTY)
                        fprintf(stderr,
@@ -65,9 +59,8 @@ _("%s: Not on a mounted XFS filesystem.\n"),
                                        path);
                else {
                        errno = ret;
-                       perror("XFS_IOC_FSGEOMETRY");
+                       perror(path);
                }
-               close(fd);
                return -1;
        }
 
@@ -75,19 +68,18 @@ _("%s: Not on a mounted XFS filesystem.\n"),
        if (!fsp) {
                fprintf(stderr, _("%s: cannot find mount point."),
                        path);
-               close(fd);
+               xfd_close(xfd);
                return -1;
        }
        memcpy(fs_path, fsp, sizeof(struct fs_path));
 
-       return fd;
+       return xfd->fd;
 }
 
 int
 addfile(
        char            *name,
-       int             fd,
-       struct xfs_fsop_geom *geometry,
+       struct xfs_fd   *xfd,
        struct fs_path  *fs_path)
 {
        char            *filename;
@@ -95,7 +87,7 @@ addfile(
        filename = strdup(name);
        if (!filename) {
                perror("strdup");
-               close(fd);
+               xfd_close(xfd);
                return -1;
        }
 
@@ -106,15 +98,14 @@ addfile(
                perror("realloc");
                filecount = 0;
                free(filename);
-               close(fd);
+               xfd_close(xfd);
                return -1;
        }
 
        /* Finally, make this the new active open file */
        file = &filetable[filecount - 1];
-       file->fd = fd;
        file->name = filename;
-       file->geom = *geometry;
+       memcpy(&file->xfd, xfd, sizeof(struct xfs_fd));
        memcpy(&file->fs_path, fs_path, sizeof(file->fs_path));
        return 0;
 }
index 527ecb520993d50b0d2e978bae9102dcb5cc4673..f30171f03ff2b9ef09418dcd35e064568b7c602b 100644 (file)
@@ -8,6 +8,7 @@
 
 #include "libxfs.h"
 #include <linux/fiemap.h>
+#include "libfrog/fsgeom.h"
 #include "command.h"
 #include "init.h"
 #include "libfrog/paths.h"
@@ -149,7 +150,8 @@ scan_ag(
        struct fsmap            *extent;
        struct fsmap            *l, *h;
        struct fsmap            *p;
-       off64_t                 blocksize = file->geom.blocksize;
+       struct xfs_fsop_geom    *fsgeom = &file->xfd.fsgeom;
+       off64_t                 blocksize = fsgeom->blocksize;
        off64_t                 bperag;
        off64_t                 aglen;
        xfs_agblock_t           agbno;
@@ -158,7 +160,7 @@ scan_ag(
        int                     ret;
        int                     i;
 
-       bperag = (off64_t)file->geom.agblocks * blocksize;
+       bperag = (off64_t)fsgeom->agblocks * blocksize;
 
        fsmap = malloc(fsmap_sizeof(NR_EXTENTS));
        if (!fsmap) {
@@ -185,7 +187,7 @@ scan_ag(
        h->fmr_offset = ULLONG_MAX;
 
        while (true) {
-               ret = ioctl(file->fd, FS_IOC_GETFSMAP, fsmap);
+               ret = ioctl(file->xfd.fd, FS_IOC_GETFSMAP, fsmap);
                if (ret < 0) {
                        fprintf(stderr, _("%s: FS_IOC_GETFSMAP [\"%s\"]: %s\n"),
                                progname, file->name, strerror(errno));
@@ -248,12 +250,13 @@ aglistadd(
 
 static int
 init(
-       int             argc,
-       char            **argv)
+       int                     argc,
+       char                    **argv)
 {
-       long long       x;
-       int             c;
-       int             speced = 0;     /* only one of -b -e -h or -m */
+       struct xfs_fsop_geom    *fsgeom = &file->xfd.fsgeom;
+       long long               x;
+       int                     c;
+       int                     speced = 0;     /* only one of -b -e -h or -m */
 
        agcount = dumpflag = equalsize = multsize = optind = gflag = 0;
        histcount = seen1 = summaryflag = 0;
@@ -321,7 +324,7 @@ init(
                return 0;
        if (!speced)
                multsize = 2;
-       histinit(file->geom.agblocks);
+       histinit(fsgeom->agblocks);
        return 1;
 many_spec:
        return command_usage(&freesp_cmd);
@@ -332,10 +335,11 @@ many_spec:
  */
 static int
 freesp_f(
-       int             argc,
-       char            **argv)
+       int                     argc,
+       char                    **argv)
 {
-       xfs_agnumber_t  agno;
+       struct xfs_fsop_geom    *fsgeom = &file->xfd.fsgeom;
+       xfs_agnumber_t          agno;
 
        if (!init(argc, argv))
                return 0;
@@ -343,7 +347,7 @@ freesp_f(
                printf(_("        AG    extents     blocks\n"));
        if (rtflag)
                scan_ag(NULLAGNUMBER);
-       for (agno = 0; !rtflag && agno < file->geom.agcount; agno++)  {
+       for (agno = 0; !rtflag && agno < fsgeom->agcount; agno++) {
                if (inaglist(agno))
                        scan_ag(agno);
        }
index f563cf1edde148941d20c471ef4aceaf4d9ce164..f6234c4c67aa19f8b9582487d502ddf80306a9a0 100644 (file)
@@ -7,8 +7,8 @@
 #include "command.h"
 #include "init.h"
 #include "libfrog/paths.h"
-#include "space.h"
 #include "libfrog/fsgeom.h"
+#include "space.h"
 
 static void
 info_help(void)
@@ -28,26 +28,13 @@ info_f(
        int                     argc,
        char                    **argv)
 {
-       struct xfs_fsop_geom    geo;
-       int                     error;
-
        if (fs_table_lookup_mount(file->name) == NULL) {
                fprintf(stderr, _("%s: Not a XFS mount point.\n"), file->name);
                return 1;
        }
 
-       /* get the current filesystem size & geometry */
-       error = xfrog_geometry(file->fd, &geo);
-       if (error) {
-               fprintf(stderr,
-       _("%s: cannot determine geometry of filesystem mounted at %s: %s\n"),
-                       progname, file->name, strerror(error));
-               exitcode = 1;
-               return 0;
-       }
-
-       xfs_report_geom(&geo, file->fs_path.fs_name, file->fs_path.fs_log,
-                       file->fs_path.fs_rt);
+       xfs_report_geom(&file->xfd.fsgeom, file->fs_path.fs_name,
+                       file->fs_path.fs_log, file->fs_path.fs_rt);
        return 0;
 }
 
index fa0397abf1481773da6d4a466833d693459b65fa..4afdb3866c35f93fd62d18b83cd57de63851961a 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "libxfs.h"
+#include "libfrog/fsgeom.h"
 #include "command.h"
 #include "input.h"
 #include "init.h"
@@ -60,7 +61,7 @@ init(
        char            **argv)
 {
        int             c;
-       struct xfs_fsop_geom geometry = { 0 };
+       struct xfs_fd   xfd = XFS_FD_INIT_EMPTY;
        struct fs_path  fsp;
 
        progname = basename(argv[0]);
@@ -88,11 +89,13 @@ init(
        if (optind != argc - 1)
                usage();
 
-       if ((c = openfile(argv[optind], &geometry, &fsp)) < 0)
+       c = openfile(argv[optind], &xfd, &fsp);
+       if (c < 0)
                exit(1);
-       if (!platform_test_xfs_fd(c))
+       if (!platform_test_xfs_fd(xfd.fd))
                printf(_("Not an XFS filesystem!\n"));
-       if (addfile(argv[optind], c, &geometry, &fsp) < 0)
+       c = addfile(argv[optind], &xfd, &fsp);
+       if (c < 0)
                exit(1);
 
        init_commands();
index b223010c654d70a9cf9b3c818bd6951fc884c795..e5d857bdd3345d54ee5efa7f23ba778935e43f0c 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "libxfs.h"
+#include "libfrog/fsgeom.h"
 #include "command.h"
 #include "input.h"
 #include "init.h"
@@ -18,11 +19,12 @@ static cmdinfo_t prealloc_cmd;
  */
 static int
 prealloc_f(
-       int     argc,
-       char    **argv)
+       int                     argc,
+       char                    **argv)
 {
        struct xfs_fs_eofblocks eofb = {0};
-       int     c;
+       struct xfs_fsop_geom    *fsgeom = &file->xfd.fsgeom;
+       int                     c;
 
        eofb.eof_version = XFS_EOFBLOCKS_VERSION;
 
@@ -51,9 +53,8 @@ prealloc_f(
                        break;
                case 'm':
                        eofb.eof_flags |= XFS_EOF_FLAGS_MINFILESIZE;
-                       eofb.eof_min_file_size = cvtnum(file->geom.blocksize,
-                                                       file->geom.sectsize,
-                                                       optarg);
+                       eofb.eof_min_file_size = cvtnum(fsgeom->blocksize,
+                                       fsgeom->sectsize, optarg);
                        break;
                case '?':
                default:
@@ -63,7 +64,7 @@ prealloc_f(
        if (optind != argc)
                return command_usage(&prealloc_cmd);
 
-       if (ioctl(file->fd, XFS_IOC_FREE_EOFBLOCKS, &eofb) < 0) {
+       if (ioctl(file->xfd.fd, XFS_IOC_FREE_EOFBLOCKS, &eofb) < 0) {
                fprintf(stderr, _("%s: XFS_IOC_FREE_EOFBLOCKS on %s: %s\n"),
                        progname, file->name, strerror(errno));
        }
index 8b224acabfc020784250be3165156633123914d2..2c26884a024825f4e52a7bdda105da99cdf76bb1 100644 (file)
@@ -7,18 +7,19 @@
 #define XFS_SPACEMAN_SPACE_H_
 
 struct fileio {
-       struct xfs_fsop_geom geom;              /* XFS filesystem geometry */
+       struct xfs_fd   xfd;            /* XFS runtime support context */
        struct fs_path  fs_path;        /* XFS path information */
        char            *name;          /* file name at time of open */
-       int             fd;             /* open file descriptor */
 };
 
 extern struct fileio   *filetable;     /* open file table */
 extern int             filecount;      /* number of open files */
 extern struct fileio   *file;          /* active file in file table */
 
-extern int     openfile(char *, struct xfs_fsop_geom *, struct fs_path *);
-extern int     addfile(char *, int , struct xfs_fsop_geom *, struct fs_path *);
+extern int     openfile(char *path, struct xfs_fd *xfd,
+                        struct fs_path *fs_path);
+extern int     addfile(char *path, struct xfs_fd *xfd,
+                       struct fs_path *fs_path);
 
 extern void    print_init(void);
 extern void    help_init(void);
index b23e2bf9a407073fff690b7094d57e6b34dd0794..daf4e4273eb7988021b9fa17ec4f4b3061ecae68 100644 (file)
@@ -5,6 +5,7 @@
  */
 
 #include "libxfs.h"
+#include "libfrog/fsgeom.h"
 #include "command.h"
 #include "init.h"
 #include "libfrog/paths.h"
@@ -18,18 +19,19 @@ static cmdinfo_t trim_cmd;
  */
 static int
 trim_f(
-       int             argc,
-       char            **argv)
+       int                     argc,
+       char                    **argv)
 {
-       struct fstrim_range trim = {0};
-       xfs_agnumber_t  agno = 0;
-       off64_t         offset = 0;
-       ssize_t         length = 0;
-       ssize_t         minlen = 0;
-       int             aflag = 0;
-       int             fflag = 0;
-       int             ret;
-       int             c;
+       struct fstrim_range     trim = {0};
+       struct xfs_fsop_geom    *fsgeom = &file->xfd.fsgeom;
+       xfs_agnumber_t          agno = 0;
+       off64_t                 offset = 0;
+       ssize_t                 length = 0;
+       ssize_t                 minlen = 0;
+       int                     aflag = 0;
+       int                     fflag = 0;
+       int                     ret;
+       int                     c;
 
        while ((c = getopt(argc, argv, "a:fm:")) != EOF) {
                switch (c) {
@@ -45,8 +47,8 @@ trim_f(
                        fflag = 1;
                        break;
                case 'm':
-                       minlen = cvtnum(file->geom.blocksize,
-                                       file->geom.sectsize, optarg);
+                       minlen = cvtnum(fsgeom->blocksize, fsgeom->sectsize,
+                                       optarg);
                        break;
                default:
                        return command_usage(&trim_cmd);
@@ -59,23 +61,23 @@ trim_f(
        if (optind != argc - 2 && !(aflag || fflag))
                return command_usage(&trim_cmd);
        if (optind != argc) {
-               offset = cvtnum(file->geom.blocksize, file->geom.sectsize,
+               offset = cvtnum(fsgeom->blocksize, fsgeom->sectsize,
                                argv[optind]);
-               length = cvtnum(file->geom.blocksize, file->geom.sectsize,
+               length = cvtnum(fsgeom->blocksize, fsgeom->sectsize,
                                argv[optind + 1]);
        } else if (agno) {
-               offset = (off64_t)agno * file->geom.agblocks * file->geom.blocksize;
-               length = file->geom.agblocks * file->geom.blocksize;
+               offset = (off64_t)agno * fsgeom->agblocks * fsgeom->blocksize;
+               length = fsgeom->agblocks * fsgeom->blocksize;
        } else {
                offset = 0;
-               length = file->geom.datablocks * file->geom.blocksize;
+               length = fsgeom->datablocks * fsgeom->blocksize;
        }
 
        trim.start = offset;
        trim.len = length;
        trim.minlen = minlen;
 
-       ret = ioctl(file->fd, FITRIM, (unsigned long)&trim);
+       ret = ioctl(file->xfd.fd, FITRIM, (unsigned long)&trim);
        if (ret < 0) {
                fprintf(stderr, "%s: ioctl(FITRIM) [\"%s\"]: %s\n",
                        progname, file->name, strerror(errno));