From: Hallvard Breien Furuseth <h.b.furuseth@usit.uio.no>
To: linux-kernel@vger.kernel.org
Subject: PROBLEM: Failed open() with O_DIRECT creates file
Date: Wed, 07 Sep 2016 17:10:49 +0200 [thread overview]
Message-ID: <hbf.20160907dj4u@bombur.uio.no> (raw)
If the filesystem does not support O_DIRECT, then
open(...O_CREAT|O_DIRECT..) fails but creates the file anyway.
Eric Sandeen@RedHat thought a fix would need a lot of vfs restructuring.
(I reported this in 2013 to RedHat (bug#1008073), but just realized he
was talking about "upstream" so maybe the report didn't get further.)
Linux 3.10.0-327.28.3.el7.x86_64, RHEL 7.2 (Maipo).
The bug existed at least since 2.6.18-348.6.1.el5.
To reproduce, run this as:
./a.out /dev/test-direct.dat
(Originally I wrote to /dev/shm/, but tmpfs now accepts O_DIRECT.)
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
char *fname = argc > 1 ? argv[1] : "test-direct.dat";
int fd = open(fname, O_WRONLY|O_CREAT|O_EXCL|O_DIRECT, 0666);
int e = fd < 0 ? errno : 0;
if (fd >= 0)
puts("open() succeeded");
else
perror("open() error");
if ((access(fname, F_OK) == 0) != (fd >= 0 || e == EEXIST))
puts(fd < 0 ? "Created file anyway!" : "File disappeared!");
if (e != EEXIST)
unlink(fname);
return 0;
}
--
Hallvard
next reply other threads:[~2016-09-07 15:19 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-07 15:10 Hallvard Breien Furuseth [this message]
2016-09-07 15:15 ` PROBLEM: Failed open() with O_DIRECT creates file Hallvard Breien Furuseth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=hbf.20160907dj4u@bombur.uio.no \
--to=h.b.furuseth@usit.uio.no \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox