t/zbd: avoid test case 31 failure with small devices
[fio.git] / engines / e4defrag.c
index c599c9868ee6f40baaa61422e4daad60a6c4751e..37cc2ada817dad98faa6968c9d3c8b2e8d0a8af9 100644 (file)
@@ -9,11 +9,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/uio.h>
 #include <errno.h>
-#include <assert.h>
 #include <fcntl.h>
 
 #include "../fio.h"
@@ -45,6 +41,7 @@ struct e4defrag_options {
 static struct fio_option options[] = {
        {
                .name   = "donorname",
+               .lname  = "Donor Name",
                .type   = FIO_OPT_STR_STORE,
                .off1   = offsetof(struct e4defrag_options, donor_name),
                .help   = "File used as a block donor",
@@ -53,6 +50,7 @@ static struct fio_option options[] = {
        },
        {
                .name   = "inplace",
+               .lname  = "In Place",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct e4defrag_options, inplace),
                .minval = 0,
@@ -74,17 +72,16 @@ static int fio_e4defrag_init(struct thread_data *td)
        struct stat stub;
        char donor_name[PATH_MAX];
 
-       if (!strlen(o->donor_name)) {
+       if (!o->donor_name || !strlen(o->donor_name)) {
                log_err("'donorname' options required\n");
                return 1;
        }
 
-       ed = malloc(sizeof(*ed));
+       ed = calloc(1, sizeof(*ed));
        if (!ed) {
                td_verror(td, ENOMEM, "io_queue_init");
                return 1;
        }
-       memset(ed, 0 ,sizeof(*ed));
 
        if (td->o.directory)
                len = sprintf(donor_name, "%s/", td->o.directory);
@@ -93,7 +90,7 @@ static int fio_e4defrag_init(struct thread_data *td)
        ed->donor_fd = open(donor_name, O_CREAT|O_WRONLY, 0644);
        if (ed->donor_fd < 0) {
                td_verror(td, errno, "io_queue_init");
-               log_err("Can't open donor file %s err:%d", donor_name, ed->donor_fd);
+               log_err("Can't open donor file %s err:%d\n", donor_name, ed->donor_fd);
                free(ed);
                return 1;
        }
@@ -129,7 +126,8 @@ static void fio_e4defrag_cleanup(struct thread_data *td)
 }
 
 
-static int fio_e4defrag_queue(struct thread_data *td, struct io_u *io_u)
+static enum fio_q_status fio_e4defrag_queue(struct thread_data *td,
+                                           struct io_u *io_u)
 {
 
        int ret;
@@ -170,8 +168,13 @@ static int fio_e4defrag_queue(struct thread_data *td, struct io_u *io_u)
                len = io_u->xfer_buflen;
 
        if (len != io_u->xfer_buflen) {
-               io_u->resid = io_u->xfer_buflen - len;
-               io_u->error = 0;
+               if (len) {
+                       io_u->resid = io_u->xfer_buflen - len;
+                       io_u->error = 0;
+               } else {
+                       /* access beyond i_size */
+                       io_u->error = EINVAL;
+               }
        }
        if (ret)
                io_u->error = errno;