Merge branch 'regrow_agg_logs' of https://github.com/pmoust/fio
[fio.git] / oslib / linux-blkzoned.c
index 6fe78b9ce79dc24abe24af38b7784f34e1029648..0a8a577a59e9d0f8488d34454af15f2c220ea034 100644 (file)
@@ -222,9 +222,21 @@ int blkzoned_reset_wp(struct thread_data *td, struct fio_file *f,
                .sector         = offset >> 9,
                .nr_sectors     = length >> 9,
        };
+       int fd, ret = 0;
+
+       /* If the file is not yet opened, open it for this function. */
+       fd = f->fd;
+       if (fd < 0) {
+               fd = open(f->file_name, O_RDWR | O_LARGEFILE);
+               if (fd < 0)
+                       return -errno;
+       }
 
-       if (ioctl(f->fd, BLKRESETZONE, &zr) < 0)
-               return -errno;
+       if (ioctl(fd, BLKRESETZONE, &zr) < 0)
+               ret = -errno;
 
-       return 0;
+       if (f->fd < 0)
+               close(fd);
+
+       return ret;
 }