File pre-read lseek error check
authorJens Axboe <axboe@fb.com>
Tue, 1 Apr 2014 23:01:30 +0000 (17:01 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 1 Apr 2014 23:01:30 +0000 (17:01 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
filesetup.c

index 12da0e60579c025ce751b242e54238c522c65234..fa09219f62a2e2b93f0e001b2e7254da72e04e99 100644 (file)
@@ -194,7 +194,7 @@ err:
 
 static int pre_read_file(struct thread_data *td, struct fio_file *f)
 {
-       int r, did_open = 0, old_runstate;
+       int ret = 0, r, did_open = 0, old_runstate;
        unsigned long long left;
        unsigned int bs;
        char *b;
@@ -216,7 +216,13 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
        b = malloc(bs);
        memset(b, 0, bs);
 
-       lseek(f->fd, f->file_offset, SEEK_SET);
+       if (lseek(f->fd, f->file_offset, SEEK_SET) < 0) {
+               td_verror(td, errno, "lseek");
+               log_err("fio: failed to lseek pre-read file\n");
+               ret = 1;
+               goto error;
+       }
+
        left = f->io_size;
 
        while (left && !td->terminate) {
@@ -234,12 +240,14 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f)
                }
        }
 
+error:
        td_restore_runstate(td, old_runstate);
 
        if (did_open)
                td->io_ops->close_file(td, f);
+
        free(b);
-       return 0;
+       return ret;
 }
 
 static unsigned long long get_rand_file_size(struct thread_data *td)