Handle end_fsync if a file is closed
authorJens Axboe <axboe@kernel.dk>
Mon, 11 Feb 2013 10:26:55 +0000 (11:26 +0100)
committerJens Axboe <axboe@kernel.dk>
Mon, 11 Feb 2013 10:26:55 +0000 (11:26 +0100)
Should not happen, but better be careful since it could have
an impact on data integrity.

Additionally, add a log_err() error if we do fail it.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
backend.c

index 6461fff70c21aa37192d3c2dd40a1831543b7a05..d1fe9641d88ebaa47489fc10a8f039e9443bbc10 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -322,6 +322,21 @@ requeue:
        return 0;
 }
 
        return 0;
 }
 
+static int fio_file_fsync(struct thread_data *td, struct fio_file *f)
+{
+       int ret;
+
+       if (fio_file_open(f))
+               return fio_io_sync(td, f);
+
+       if (td_io_open_file(td, f))
+               return 1;
+
+       ret = fio_io_sync(td, f);
+       td_io_close_file(td, f);
+       return ret;
+}
+
 static inline void __update_tv_cache(struct thread_data *td)
 {
        fio_gettime(&td->tv_cache, NULL);
 static inline void __update_tv_cache(struct thread_data *td)
 {
        fio_gettime(&td->tv_cache, NULL);
@@ -822,9 +837,11 @@ sync_done:
                        td_set_runstate(td, TD_FSYNCING);
 
                        for_each_file(td, f, i) {
                        td_set_runstate(td, TD_FSYNCING);
 
                        for_each_file(td, f, i) {
-                               if (!fio_file_open(f))
+                               if (!fio_file_fsync(td, f))
                                        continue;
                                        continue;
-                               fio_io_sync(td, f);
+
+                               log_err("fio: end_fsync failed for file %s\n",
+                                                               f->file_name);
                        }
                }
        } else
                        }
                }
        } else