engines/filestat: change "lstat" bool option to "stat_type" str option
[fio.git] / engines / filestat.c
index 795259341b7e33a320a6d848a64c1f3b6d85bf01..68a340bd0619907e7cca9f91373d808cb1bf4cef 100644 (file)
 #include <sys/stat.h>
 #include <unistd.h>
 #include "../fio.h"
+#include "../optgroup.h"
 
 struct fc_data {
        enum fio_ddir stat_ddir;
 };
 
+struct filestat_options {
+       void *pad;
+       unsigned int stat_type;
+};
+
+enum {
+       FIO_FILESTAT_STAT       = 1,
+       FIO_FILESTAT_LSTAT      = 2,
+       /*FIO_FILESTAT_STATX    = 3,*/
+};
+
+static struct fio_option options[] = {
+       {
+               .name   = "stat_type",
+               .lname  = "stat_type",
+               .type   = FIO_OPT_STR,
+               .off1   = offsetof(struct filestat_options, stat_type),
+               .help   = "Specify stat system call type to measure lookup/getattr performance",
+               .def    = "stat",
+               .posval = {
+                         { .ival = "stat",
+                           .oval = FIO_FILESTAT_STAT,
+                           .help = "Use stat(2)",
+                         },
+                         { .ival = "lstat",
+                           .oval = FIO_FILESTAT_LSTAT,
+                           .help = "Use lstat(2)",
+                         },
+                         /*
+                         { .ival = "statx",
+                           .oval = FIO_FILESTAT_STATX,
+                           .help = "Use statx(2)",
+                         },
+                         */
+               },
+               .category = FIO_OPT_C_ENGINE,
+               .group  = FIO_OPT_G_FILESTAT,
+       },
+       {
+               .name   = NULL,
+       },
+};
+
 static int stat_file(struct thread_data *td, struct fio_file *f)
 {
+       struct filestat_options *o = td->eo;
        struct timespec start;
        int do_lat = !td->o.disable_lat;
        struct stat statbuf;
@@ -37,13 +82,24 @@ static int stat_file(struct thread_data *td, struct fio_file *f)
        if (do_lat)
                fio_gettime(&start, NULL);
 
-       ret = stat(f->file_name, &statbuf);
+       switch (o->stat_type){
+       case FIO_FILESTAT_STAT:
+               ret = stat(f->file_name, &statbuf);
+               break;
+       case FIO_FILESTAT_LSTAT:
+               ret = lstat(f->file_name, &statbuf);
+               break;
+       default:
+               ret = -1;
+               break;
+       }
 
        if (ret == -1) {
                char buf[FIO_VERROR_SIZE];
                int e = errno;
 
-               snprintf(buf, sizeof(buf), "stat(%s)", f->file_name);
+               snprintf(buf, sizeof(buf), "stat(%s) type=%u", f->file_name,
+                       o->stat_type);
                td_verror(td, e, buf);
                return 1;
        }
@@ -103,6 +159,8 @@ static struct ioengine_ops ioengine = {
        .open_file      = stat_file,
        .flags          =  FIO_SYNCIO | FIO_FAKEIO |
                                FIO_NOSTATS | FIO_NOFILEHASH,
+       .options        = options,
+       .option_struct_size = sizeof(struct filestat_options),
 };
 
 static void fio_init fio_filestat_register(void)