[PATCH] fio: various fixes for using a bdev directly
authorJens Axboe <axboe@suse.de>
Thu, 17 Nov 2005 12:53:36 +0000 (13:53 +0100)
committerJens Axboe <axboe@suse.de>
Thu, 17 Nov 2005 12:53:36 +0000 (13:53 +0100)
fio-ini.c
fio.c
fio.h

index 3018fc10f7444406399e059101c3a79ba5e0951e..97f3807a05849f5a6f2bc732575dca1631efeebf 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -153,12 +153,21 @@ static void put_job(struct thread_data *td)
 static int add_job(struct thread_data *td, const char *jobname, int prioclass,
                   int prio)
 {
+       struct stat sb;
        int numjobs;
 
        if (td == &def_thread)
                return 0;
 
-       sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->thread_number);
+       td->filetype = FIO_TYPE_FILE;
+       if (!stat(jobname, &sb) && S_ISBLK(sb.st_mode))
+               td->filetype = FIO_TYPE_BD;
+
+       if (td->filetype == FIO_TYPE_FILE)
+               sprintf(td->file_name, "%s/%s.%d", td->directory, jobname, td->thread_number);
+       else
+               strcpy(td->file_name, jobname);
+
        sem_init(&td->mutex, 1, 0);
        td->ioprio = (prioclass << IOPRIO_CLASS_SHIFT) | prio;
 
diff --git a/fio.c b/fio.c
index 22db6fc232e0df7e392bc6b7627f184647c86f53..d6e40d522a9c906d6d3f2b27d12f9313be920993 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1188,9 +1188,8 @@ static int file_exists(struct thread_data *td)
        return errno != ENOENT;
 }
 
-static int get_file_size(struct thread_data *td)
+static int file_size(struct thread_data *td)
 {
-       size_t bytes = 0;
        struct stat st;
 
        if (fstat(td->fd, &st) == -1) {
@@ -1198,39 +1197,50 @@ static int get_file_size(struct thread_data *td)
                return 1;
        }
 
-       /*
-        * if block device, get size via BLKGETSIZE64 ioctl. try that as well
-        * if this is a link, fall back to st.st_size if it fails
-        */
-       if (S_ISBLK(st.st_mode) || S_ISLNK(st.st_mode)) {
-               if (ioctl(td->fd, BLKGETSIZE64, &bytes)) {
-                       if (S_ISBLK(st.st_mode)) {
-                               td->error = errno;
-                               return 1;
-                       } else
-                               bytes = st.st_size;
-               }
-       } else
-               bytes = st.st_size;
-
        if (td_read(td)) {
-               if (!td->file_size)
-                       td->file_size = bytes;
-               else if (td->file_size > bytes)
-                       bytes = td->file_size;
+               if (!td->file_size || td->file_size > st.st_size)
+                       td->file_size = st.st_size;
        } else {
                if (!td->file_size)
                        td->file_size = 1024 * 1024 * 1024;
+       }
+
+       return 0;
+}
+
+static int bdev_size(struct thread_data *td)
+{
+       size_t bytes;
 
-               bytes = td->file_size;
+       if (ioctl(td->fd, BLKGETSIZE64, &bytes) < 0) {
+               td->error = errno;
+               return 1;
        }
 
-       if (td->file_offset > bytes) {
+       if (!td->file_size || (td->file_size > bytes))
+               td->file_size = bytes;
+
+       return 0;
+}
+
+static int get_file_size(struct thread_data *td)
+{
+       int ret;
+
+       if (td->filetype == FIO_TYPE_FILE)
+               ret = file_size(td);
+       else
+               ret = bdev_size(td);
+
+       if (ret)
+               return ret;
+
+       if (td->file_offset > td->file_size) {
                fprintf(stderr, "Client%d: offset larger than length\n", td->thread_number);
                return 1;
        }
 
-       td->io_size = bytes - td->file_offset;
+       td->io_size = td->file_size - td->file_offset;
        if (td->io_size == 0) {
                fprintf(stderr, "Client%d: no io blocks\n", td->thread_number);
                td->error = EINVAL;
@@ -1772,8 +1782,7 @@ static void show_run_stats(void)
                td = &threads[i];
                rs = &runstats[td->groupid];
 
-               if (!td->error)
-                       show_thread_status(td, rs);
+               show_thread_status(td, rs);
        }
 
        for (i = 0; i < groupid + 1; i++)
diff --git a/fio.h b/fio.h
index 1cdf0492f7e4d91cee5ddef9b2e485dd35f10333..81969d3527e072e6586caaf1372196d02c92e988 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -58,6 +58,7 @@ struct thread_data {
        pthread_t thread;
        int thread_number;
        int groupid;
+       int filetype;
        int error;
        int fd;
        pid_t pid;
@@ -181,6 +182,11 @@ enum {
        MEM_SHM,
 };
 
+enum {
+       FIO_TYPE_FILE = 1,
+       FIO_TYPE_BD,
+};
+
 #define td_read(td)            ((td)->ddir == DDIR_READ)
 #define td_write(td)           ((td)->ddir == DDIR_WRITE)