Skip to contentSkip to conversation

Substitute O_SYNC with O_FSYNC in block/raw-posix.c

PATCH In review G 3 2 participants 4 messages Jun 26, 2009 – Jul 2, 2009 2 messages not in the archive Block layer

lore
Share & tools
lore

G 3

author
#0 lore raw

PATCH 1/1 Substitute O_SYNC with O_FSYNC in block/raw-posix.c

This patch will allow the file block/raw-posix.c to compile on gcc 3.3 on Mac OS 10.3. Since the O_SYNC symbol is missing on this version of the Mac OS, O_FSYNC will be used in its place.

---
 block/raw-posix.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
block/raw-posix.c +9 -0
index fa1a394..baff82d 100644
@@ -79,6 +79,15 @@
 #define DEBUG_BLOCK_PRINT(formatCstr, ...)
 #endif
 
+/* Mac OS less than 10.4 doesn't have O_SYNC */
+#ifndef O_SYNC
+#ifdef O_FSYNC
+#define O_SYNC O_FSYNC
+#else
+#define O_SYNC 0
+#endif
+#endif
+
 /* OS X does not have O_DSYNC */
 #ifndef O_DSYNC
 #define O_DSYNC O_SYNC
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 3 lines · On Thu, Jun 25, 2009 at 08:59:35PM -0400, G 3 wrote:

This patch will allow the file block/raw-posix.c to compile on gcc 3.3 on Mac OS 10.3. Since the O_SYNC symbol is missing on this version of the Mac OS, O_FSYNC will be used in its place.

Same comment about the zero as last time still applies. Also the look of this is really ugly as you just deinfe O_SYNC only for it to substitute for O_DSYNC a littler later, with two comments that together are rather confusing about macos..

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

author
#4 lore raw

PATCH 1/1 Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.

Quoted 18 lines · Christoph Hellwig
Quoted 4 lines · On Fri, Jun 26, 2009 at 03:02:47PM -0400, G 3 wrote:

/* OS X does not have O_DSYNC */
#ifndef O_DSYNC
#ifdef O_SYNC /* Works on Mac OS 10.4 and
greater */

Quoted 8 lines

#define O_DSYNC O_SYNC
#elif defined(O_FSYNC) /* Works on Mac OS 10.3 and under */
#define O_DSYNC O_FSYNC
#else /* If no substitute is
available */
#define O_DSYNC 0
#endif
#endif

This still does the NULL sync which can cause silent data loss if no O_*SYNC is available. If you want to be safe and support either O_SYNC or O_FSYNC as O_DSYNC replacement the following should be enough:

Quoted 13 lines

/*
* MacOS X does not have O_DSYNC, and in earlier version no O_SYNC
either.
*/
#ifndef O_DSYNC
#ifdef O_SYNC
#define O_DSYNC O_SYNC
#else
#define O_DSYNC O_FSYNC
#endif
#endif

This patch should be what you want.

commit b32354139556d1a807d04aa54ed82610e0f4507a

Author: John Arbuckle <[email protected]>
Date:   Wed Jul 1 13:24:37 2009 -0400

Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.

block/raw-posix.c +4 -0
index 8b1e67c..17338ee 100644
@@ -81,7 +81,11 @@
 
 /* OS X does not have O_DSYNC */
 #ifndef O_DSYNC
+#ifdef O_SYNC
 #define O_DSYNC O_SYNC
+#elif defined(O_FSYNC)
+#define O_DSYNC O_FSYNC
+#endif
 #endif
Reviewed-by on v1 1/1
#5 lore raw

[Qemu-devel] Re: [PATCH] Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.

Quoted 9 lines · On Wed, Jul 01, 2009 at 01:28:32PM -0400, G 3 wrote:

This patch should be what you want.

commit b32354139556d1a807d04aa54ed82610e0f4507a

Author: John Arbuckle <[email protected]>
Date:   Wed Jul 1 13:24:37 2009 -0400

Substitute O_DSYNC with O_SYNC or O_FSYNC when needed.

Thanks, looks good to me,

Quoted 5 lines
block/raw-posix.c +0 -0
index 8b1e67c..17338ee 100644

block/raw-posix.c line 89

Quoted 9 lines
block/raw-posix.c +4 -0
@@ -81,7 +81,11 @@
 
 /* OS X does not have O_DSYNC */
 #ifndef O_DSYNC
+#ifdef O_SYNC
 #define O_DSYNC O_SYNC
+#elif defined(O_FSYNC)
+#define O_DSYNC O_FSYNC
+#endif
 #endif

---end quoted text---