ltp/fsx: drop caches if we're doing closeopen
[xfstests-dev.git] / ltp / iogen.c
index fadd5e1ed58a7c1550dc49b7698aab776c78e009..2b6644d5219219746e5707f89af4a57f12e8f91e 100644 (file)
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * 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.
- *
- * 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
  */
 /*
  * iogen - a tool for generating file/sds io for a doio process
@@ -132,7 +120,7 @@ int Fileio = 0;             /* flag indicating that a file              */
 int    Naio_Strat_Types = 0;   /* # async io completion types              */
 struct strmap *Aio_Strat_List[128]; /* Async io completion types           */
 
-void   startup_info();
+void   startup_info(FILE *stream, int seed);
 
 /*
  * Map async io completion modes (-a args) names to values.  Macros are
@@ -182,12 +170,10 @@ struct strmap     Syscall_Map[] = {
        { "write",              WRITE,          SY_WRITE                },
        { "pread",              PREAD                                   },
        { "pwrite",             PWRITE,         SY_WRITE                },
-#ifndef NO_XFS
        { "resvsp",             RESVSP,         SY_WRITE                },
        { "unresvsp",           UNRESVSP,       SY_WRITE                },
        { "reserve",            RESVSP,         SY_WRITE                },
        { "unreserve",          UNRESVSP,       SY_WRITE                },
-#endif
        { "readv",              READV                                   },
        { "writev",             WRITEV,         SY_WRITE                },
        { "mmread",             MMAPR                                   },
@@ -301,7 +287,7 @@ char        **argv;
 void
 startup_info(FILE *stream, int seed)
 {
-    char       *value_to_string(), *type;
+    char       *value_to_string(struct strmap *map, int val), *type;
     int                i;
 
     fprintf(stream, "\n");
@@ -744,10 +730,8 @@ get_file_info(rec)
 struct file_info    *rec;
 {
     struct stat                        sbuf;
-#ifndef NO_XFS
     int                                fd;
     struct dioattr             finfo;
-#endif
 
     /*
      * Figure out if the files is regular, block or character special.  Any
@@ -784,8 +768,8 @@ struct file_info    *rec;
        }
 
        rec->f_riou = BSIZE;
-#ifndef NO_XFS
        if( (fd = open(rec->f_path, O_RDWR|O_DIRECT, 0)) != -1 ) {
+           char *dio_env;
 #ifdef XFS_IOC_DIOINFO
            if(xfsctl(rec->f_path, fd, XFS_IOC_DIOINFO, &finfo) != -1) {
 #else
@@ -795,6 +779,10 @@ struct file_info    *rec;
 bozo!
 #endif
 #endif
+               dio_env = getenv("XFS_DIO_MIN");
+               if (dio_env)
+                   finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
+
                rec->f_riou = finfo.d_miniosz;
            } else {
                fprintf(stderr,
@@ -805,7 +793,6 @@ bozo!
        } else {
            rec->f_riou = BBSIZE;
        }
-#endif
     } else {
 
        rec->f_riou = BSIZE;
@@ -829,13 +816,11 @@ int       nbytes;
     int                fd, rval;
     char       c;
     struct stat        sbuf;
-#ifndef NO_XFS
     int                nb;
     struct flock64 f;
     struct fsxattr xattr;
     struct dioattr finfo;
     char       *b, *buf;
-#endif
 
     errno = 0;
     rval = stat(path, &sbuf);
@@ -883,7 +868,6 @@ int         nbytes;
        }
     } else {
 
-#ifndef NO_XFS
        /*
         *  The file must be designated as Real-Time before any data
         *  is allocated to it.
@@ -926,7 +910,6 @@ bozo!
                fprintf(stderr, "get: fsx_xflags = 0x%x\n", 
                        xattr.fsx_xflags);
            }
-#endif
        }
 
        /*
@@ -1008,10 +991,10 @@ bozo!
         * file size.
         */
 
-#ifndef NO_XFS
        if(Owrite == 2) {
            close(fd);
            if( (fd = open(path, O_CREAT|O_RDWR|O_DIRECT, 0)) != -1 ) {
+               char *dio_env;
 #ifdef XFS_IOC_DIOINFO
                if(xfsctl(path, fd, XFS_IOC_DIOINFO, &finfo) == -1) {
 #else
@@ -1029,6 +1012,10 @@ bozo!
                    /*fprintf(stderr, "%s: miniosz=%d\n", 
                            path, finfo.d_miniosz);*/
                }
+
+               dio_env = getenv("XFS_DIO_MIN");
+               if (dio_env)
+                       finfo.d_mem = finfo.d_miniosz = atoi(dio_env);
            } else {
                fprintf(stderr, "iogen%s: Error %s (%d) opening file %s with flags O_CREAT|O_RDWR|O_DIRECT\n",
                        TagName, SYSERR, errno, path);
@@ -1081,7 +1068,6 @@ bozo!
            }
            free(b);
        } else
-#endif
            if(Owrite) {
            /*fprintf(stderr,
                    "create_file_Owrite: lseek(%d, %d {%d}, SEEK_SET)\n",
@@ -1276,7 +1262,7 @@ char      *opts;
            break;
 
        case 'N':
-           sprintf( TagName, "(%.39s)", optarg );
+           sprintf( TagName, "(%.37s)", optarg );
            break;
 
        case 'o':
@@ -1286,7 +1272,6 @@ char      *opts;
        case 'O':
 
            nopenargs = string_to_tokens(optarg, openargs, 4, ":/");
-#ifndef NO_XFS
            if(!strcmp(openargs[0], "realtime")) {
                /*
                 * -O realtime:extsize
@@ -1323,14 +1308,6 @@ char     *opts;
                        TagName, openargs[0]);
                exit(1);
            }
-#else
-           Oflags = parse_open_flags(openargs[0], &errmsg);
-           if(Oflags == -1) {
-               fprintf(stderr, "iogen%s: -O %s error: %s\n", TagName, optarg, errmsg);
-               exit(1);
-           }
-#endif
-
            O_opt++;
            break;
 
@@ -1629,13 +1606,8 @@ FILE     *stream;
     fprintf(stream, "\t-a               (Not used on Linux).\n");
 #endif /* !linux */
     fprintf(stream, "\t-f flag,...      Flags to use for file IO.  Supported flags are\n");
-#ifndef NO_XFS
     fprintf(stream, "\t                 buffered, direct, sync.\n");
     fprintf(stream, "\t                 Default is 'buffered,sync'.\n");
-#else
-    fprintf(stream, "\t                 buffered, sync.\n");
-    fprintf(stream, "\t                 Default is 'buffered,sync'.\n");
-#endif /* sgi */
     fprintf(stream, "\t-h               This help.\n");
     fprintf(stream, "\t-i iterations[s] # of requests to generate.  0 means causes iogen\n");
     fprintf(stream, "\t                 to run until it's killed.  If iterations is suffixed\n");
@@ -1650,15 +1622,11 @@ FILE    *stream;
     fprintf(stream, "\t-N tagname       Tag name, for Monster.\n");
     fprintf(stream, "\t-o               Form overlapping consecutive requests.\n");
     fprintf(stream, "\t-O               Open flags for creating files\n");
-#ifndef NO_XFS
     fprintf(stream, "\t                 realtime:extsize - put file on real-time volume\n");
     fprintf(stream, "\t                 allocate - allocate space with F_ALLOCSP\n");
     fprintf(stream, "\t                 reserve - reserve space with F_RESVSP (default)\n");
     fprintf(stream, "\t                 noreserve - do not reserve with F_RESVSP\n");
     fprintf(stream, "\t                 direct - use O_DIRECT I/O to write to the file\n");
-#else
-    fprintf(stream, "\t                 {O_SYNC,etc}\n");
-#endif
     fprintf(stream, "\t-p               Output pipe.  Default is stdout.\n");
     fprintf(stream, "\t-q               Quiet mode.  Normally iogen spits out info\n");
     fprintf(stream, "\t                 about test files, options, etc. before starting.\n");