From: Christoph Hellwig <hch@lst.de>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Christoph Hellwig <hch@lst.de>, Jan Kara <jack@suse.cz>,
linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
akpm@linux-foundation.org, viro@zeniv.linux.org.uk,
kyle@mcmartin.ca, sct@redhat.com
Subject: Re: [PATCH] implement posix O_SYNC and O_DSYNC semantics
Date: Thu, 17 Sep 2009 19:16:17 +0200 [thread overview]
Message-ID: <20090917171617.GB858@lst.de> (raw)
In-Reply-To: <4AAFA9BC.1000409@redhat.com>
Btw, a little update on O_RSYNC: I have a patch that should work,
but surprisingly enough it doesn't. Seem like the O_ flags grew too
large and somewhere in the middle they get truncated off. Here's what I
have so far:
Index: linux-2.6/fs/splice.c
===================================================================
--- linux-2.6.orig/fs/splice.c 2009-09-15 00:06:09.737003454 -0300
+++ linux-2.6/fs/splice.c 2009-09-15 00:08:23.669254032 -0300
@@ -501,6 +501,10 @@ ssize_t generic_file_splice_read(struct
if (unlikely(left < len))
len = left;
+ ret = generic_read_sync(in, *ppos, len);
+ if (ret)
+ return ret;
+
ret = __generic_file_splice_read(in, ppos, pipe, len, flags);
if (ret > 0) {
*ppos += ret;
Index: linux-2.6/fs/sync.c
===================================================================
--- linux-2.6.orig/fs/sync.c 2009-09-15 00:08:23.180271144 -0300
+++ linux-2.6/fs/sync.c 2009-09-15 00:28:41.359031442 -0300
@@ -295,6 +295,33 @@ int generic_write_sync(struct file *file
}
EXPORT_SYMBOL(generic_write_sync);
+/**
+ * generic_read_sync - perform syncing befor
+ * @file: file to which the read happens
+ * @pos: offset where the read starts
+ * @count: length of the read
+ *
+ * This implements the O_RSYNC semantics:
+ * O_RSYNC on its own just means the data is successfully transferred to
+ * the calling process (always the case).
+ *
+ * O_RSYNC|O_DSYNC means that if a read request hits data that is currently
+ * in a cache and not yet on the medium, then the write to medium is
+ * successful before the read succeeds.
+ *
+ * O_RSYNC|O_SYNC means the same plus the integrity of file meta information
+ * (access time etc).
+ */
+int generic_read_sync(struct file *file, loff_t pos, loff_t count)
+{
+ if (((file->f_flags & (O_RSYNC|O_DSYNC)) != (O_RSYNC|O_DSYNC)))
+ return 0;
+ return vfs_fsync_range(file, file->f_path.dentry, pos,
+ pos + count - 1,
+ (file->f_flags & __O_SYNC) ? 0 : 1);
+}
+EXPORT_SYMBOL(generic_read_sync);
+
/*
* sys_sync_file_range() permits finely controlled syncing over a segment of
* a file in the range offset .. (offset+nbytes-1) inclusive. If nbytes is
Index: linux-2.6/include/asm-generic/fcntl.h
===================================================================
--- linux-2.6.orig/include/asm-generic/fcntl.h 2009-09-15 00:08:23.162254189 -0300
+++ linux-2.6/include/asm-generic/fcntl.h 2009-09-15 00:08:23.672254134 -0300
@@ -68,6 +68,10 @@
#define O_SYNC (__O_SYNC|O_DSYNC)
#endif
+#ifndef O_RSYNC
+#define O_RSYNC 010000000
+#endif
+
#ifndef O_NDELAY
#define O_NDELAY O_NONBLOCK
#endif
Index: linux-2.6/include/linux/fs.h
===================================================================
--- linux-2.6.orig/include/linux/fs.h 2009-09-15 00:06:09.758004312 -0300
+++ linux-2.6/include/linux/fs.h 2009-09-15 00:08:23.673254191 -0300
@@ -2097,6 +2097,7 @@ extern int vfs_fsync_range(struct file *
loff_t start, loff_t end, int datasync);
extern int vfs_fsync(struct file *file, struct dentry *dentry, int datasync);
extern int generic_write_sync(struct file *file, loff_t pos, loff_t count);
+extern int generic_read_sync(struct file *file, loff_t pos, loff_t count);
extern void sync_supers(void);
extern void emergency_sync(void);
extern void emergency_remount(void);
Index: linux-2.6/mm/filemap.c
===================================================================
--- linux-2.6.orig/mm/filemap.c 2009-09-15 00:06:09.764004377 -0300
+++ linux-2.6/mm/filemap.c 2009-09-15 00:08:23.676300248 -0300
@@ -1285,6 +1285,10 @@ generic_file_aio_read(struct kiocb *iocb
if (retval)
return retval;
+ retval = generic_read_sync(filp, pos, count);
+ if (retval)
+ return retval;
+
/* coalesce the iovecs and go direct-to-BIO for O_DIRECT */
if (filp->f_flags & O_DIRECT) {
loff_t size;
Index: linux-2.6/arch/alpha/include/asm/fcntl.h
===================================================================
--- linux-2.6.orig/arch/alpha/include/asm/fcntl.h 2009-09-15 00:08:23.169254241 -0300
+++ linux-2.6/arch/alpha/include/asm/fcntl.h 2009-09-15 00:08:23.678253988 -0300
@@ -30,6 +30,7 @@
*/
#define __O_SYNC 020000000
#define O_SYNC (__O_SYNC|O_DSYNC)
+#define O_RSYNC 040000000
#define F_GETLK 7
#define F_SETLK 8
Index: linux-2.6/arch/mips/include/asm/fcntl.h
===================================================================
--- linux-2.6.orig/arch/mips/include/asm/fcntl.h 2009-09-15 00:08:23.172253854 -0300
+++ linux-2.6/arch/mips/include/asm/fcntl.h 2009-09-15 00:08:23.678253988 -0300
@@ -34,6 +34,7 @@
#define __O_SYNC 0x4000
#define O_SYNC (__O_SYNC|O_DSYNC)
#define O_DIRECT 0x8000 /* direct disk access hint */
+#define O_DSYNC 0x10000
#define F_GETLK 14
#define F_SETLK 6
Index: linux-2.6/arch/parisc/include/asm/fcntl.h
===================================================================
--- linux-2.6.orig/arch/parisc/include/asm/fcntl.h 2009-09-15 00:08:23.178298896 -0300
+++ linux-2.6/arch/parisc/include/asm/fcntl.h 2009-09-15 00:08:23.680301735 -0300
@@ -14,6 +14,7 @@
#define O_RSYNC 002000000 /* HPUX only */
#define O_NOATIME 004000000
#define O_CLOEXEC 010000000 /* set close_on_exec */
+#define O_RSYNC 020000000
#define O_DIRECTORY 000010000 /* must be a directory */
#define O_NOFOLLOW 000000200 /* don't follow links */
Index: linux-2.6/arch/sparc/include/asm/fcntl.h
===================================================================
--- linux-2.6.orig/arch/sparc/include/asm/fcntl.h 2009-09-15 00:08:23.179254674 -0300
+++ linux-2.6/arch/sparc/include/asm/fcntl.h 2009-09-15 00:08:23.681254370 -0300
@@ -33,6 +33,7 @@
*/
#define __O_SYNC 0x800000
#define O_SYNC (__O_SYNC|O_DSYNC)
+#define O_RSYNC 0x1000000
#define F_GETOWN 5 /* for sockets. */
#define F_SETOWN 6 /* for sockets. */
next prev parent reply other threads:[~2009-09-17 17:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20090914165419.GD25549@duck.suse.cz>
2009-09-15 13:12 ` [PATCH] implement posix O_SYNC and O_DSYNC semantics Christoph Hellwig
2009-09-15 14:10 ` Jan Kara
2009-09-15 14:50 ` Ulrich Drepper
2009-09-17 17:16 ` Christoph Hellwig [this message]
2009-09-17 21:03 ` Kyle McMartin
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=20090917171617.GB858@lst.de \
--to=hch@lst.de \
--cc=akpm@linux-foundation.org \
--cc=drepper@redhat.com \
--cc=jack@suse.cz \
--cc=kyle@mcmartin.ca \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sct@redhat.com \
--cc=viro@zeniv.linux.org.uk \
/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;
as well as URLs for NNTP newsgroup(s).