Fix failure in opening files with O_NOATIME
authorAaron Carroll <aaronc@gelato.unsw.edu.au>
Mon, 26 Nov 2007 08:08:53 +0000 (09:08 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Mon, 26 Nov 2007 08:08:53 +0000 (09:08 +0100)
If we try to open a file with O_NOATIME and it fails, turn off
O_NOATIME and try again.  This occurs if the user does not own
the file and is unprivileged.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
filesetup.c

index 5134fdbb8af5a52e08e5ad8b60ea820e0caeab9f..6c241516ff9424f526e587b9acd620b817c9cdfb 100644 (file)
@@ -234,6 +234,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
        if (f->filetype != FIO_TYPE_FILE)
                flags |= O_NOATIME;
 
        if (f->filetype != FIO_TYPE_FILE)
                flags |= O_NOATIME;
 
+open_again:
        if (td_write(td)) {
                assert(!read_only);
 
        if (td_write(td)) {
                assert(!read_only);
 
@@ -262,6 +263,11 @@ int generic_open_file(struct thread_data *td, struct fio_file *f)
                char buf[FIO_VERROR_SIZE];
                int __e = errno;
 
                char buf[FIO_VERROR_SIZE];
                int __e = errno;
 
+               if (errno == EPERM && (flags & O_NOATIME)) {
+                       flags &= ~O_NOATIME;
+                       goto open_again;
+               }
+
                snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name);
 
                td_verror(td, __e, buf);
                snprintf(buf, sizeof(buf) - 1, "open(%s)", f->file_name);
 
                td_verror(td, __e, buf);