From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754227AbcIGPTA (ORCPT ); Wed, 7 Sep 2016 11:19:00 -0400 Received: from mail-out4.uio.no ([129.240.10.15]:39174 "EHLO mail-out4.uio.no" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750877AbcIGPS5 (ORCPT ); Wed, 7 Sep 2016 11:18:57 -0400 From: Hallvard Breien Furuseth To: linux-kernel@vger.kernel.org Subject: PROBLEM: Failed open() with O_DIRECT creates file Date: Wed, 07 Sep 2016 17:10:49 +0200 Message-ID: MIME-Version: 1.0 Content-Type: text/plain X-UiO-Ratelimit-Test: rcpts/h 2 msgs/h 1 sum rcpts/h 4 sum msgs/h 2 total rcpts 2586 max rcpts/h 16 ratelimit 0 X-UiO-Spam-info: not spam, SpamAssassin (score=-6.1, required=5.0, autolearn=disabled, RP_MATCHES_RCVD=-1.096,UIO_MAIL_IS_INTERNAL=-5, uiobl=NO, uiouri=NO) X-UiO-Scanned: 40E3CEB97F034AFBD20BB134DD89C1836446BC98 X-UiO-SPAM-Test: remote_host: 129.240.203.105 spam_score: -60 maxlevel 80 minaction 1 bait 0 mail/h: 1 total 1190 max/h 9 blacklist 0 greylist 1 ratelimit 0 X-UiOonly: 3FCC160F634CF16F0C9832DBCA8321B9E6333D15 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 #include #include #include #include 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