[PATCH] fio: file vs bdev size fixes
authorJens Axboe <axboe@suse.de>
Wed, 30 Nov 2005 09:05:59 +0000 (10:05 +0100)
committerJens Axboe <axboe@suse.de>
Wed, 30 Nov 2005 09:05:59 +0000 (10:05 +0100)
fio-ini.c
fio.c

index 803b10a51ae4a202aefd6f4cb030ea259103aed4..6fb4415f50a97e82ba39370f9c39b2d331f68c9f 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -30,6 +30,7 @@
 #define DEF_NUMJOBS    (1)
 #define DEF_USE_THREAD (0)
 #define DEF_USE_MMAP   (0)
+#define DEF_FILE_SIZE  (1024 * 1024 * 1024UL)
 
 static int repeatable = DEF_RAND_REPEAT;
 static char *ini_file;
diff --git a/fio.c b/fio.c
index 52b3aaeba33b527e7ac7012ef5e56de902bcc5fc..3529d025920eb175122e2429292401ace72b1b50 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1322,13 +1322,8 @@ static int file_size(struct thread_data *td)
                return 1;
        }
 
-       if (td_read(td)) {
-               if (!td->file_size || (st.st_size > td->file_size))
-                       td->file_size = st.st_size;
-       } else {
-               if (!td->file_size)
-                       td->file_size = 1024 * 1024 * 1024;
-       }
+       if (!td->file_size)
+               td->file_size = st.st_size;
 
        return 0;
 }
@@ -1342,7 +1337,10 @@ static int bdev_size(struct thread_data *td)
                return 1;
        }
 
-       if (!td->file_size || (bytes > td->file_size))
+       /*
+        * no extend possibilities, so limit size to device size if too large
+        */
+       if (!td->file_size || td->file_size > bytes)
                td->file_size = bytes;
 
        return 0;
@@ -1457,9 +1455,11 @@ static int setup_file(struct thread_data *td)
                }
                if (create_file(td, td->file_size, 0))
                        return 1;
-       } else if (st.st_size < td->file_size) {
-               if (create_file(td, td->file_size - st.st_size, 1))
-                       return 1;
+       } else if (td->filetype == FIO_TYPE_FILE) {
+               if (st.st_size < td->file_size) {
+                       if (create_file(td, td->file_size - st.st_size, 1))
+                               return 1;
+               }
        }
 
        if (td->odirect)
@@ -1468,14 +1468,18 @@ static int setup_file(struct thread_data *td)
        if (td_read(td))
                td->fd = open(td->file_name, flags | O_RDONLY);
        else {
-               if (!td->overwrite)
-                       flags |= O_TRUNC;
+               if (td->filetype == FIO_TYPE_FILE) {
+                       if (!td->overwrite)
+                               flags |= O_TRUNC;
+
+                       flags |= O_CREAT;
+               }
                if (td->sync_io)
                        flags |= O_SYNC;
 
                flags |= O_RDWR;
 
-               td->fd = open(td->file_name, flags | O_CREAT, 0600);
+               td->fd = open(td->file_name, flags, 0600);
        }
 
        if (td->fd == -1) {
@@ -1486,11 +1490,6 @@ static int setup_file(struct thread_data *td)
        if (get_file_size(td))
                return 1;
 
-       if (td_write(td) && ftruncate(td->fd, td->file_size) == -1) {
-               td->error = errno;
-               return 1;
-       }
-
        if (!td->use_mmap)
                return setup_file_plain(td);
        else