Module Name:    src
Committed By:   pooka
Date:           Wed May 15 15:57:01 UTC 2013

Modified Files:
        src/lib/librumpuser: rumpuser.3 rumpuser.c
        src/sys/rump/include/rump: rumpuser.h

Log Message:
Add a generalized rumpuser_syncfd() call which allows the caller
to request a sync or a barrier for fd.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/librumpuser/rumpuser.3
cvs rdiff -u -r1.52 -r1.53 src/lib/librumpuser/rumpuser.c
cvs rdiff -u -r1.106 -r1.107 src/sys/rump/include/rump/rumpuser.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/librumpuser/rumpuser.3
diff -u src/lib/librumpuser/rumpuser.3:1.12 src/lib/librumpuser/rumpuser.3:1.13
--- src/lib/librumpuser/rumpuser.3:1.12	Wed May 15 14:58:24 2013
+++ src/lib/librumpuser/rumpuser.3	Wed May 15 15:57:01 2013
@@ -1,4 +1,4 @@
-.\"     $NetBSD: rumpuser.3,v 1.12 2013/05/15 14:58:24 pooka Exp $
+.\"     $NetBSD: rumpuser.3,v 1.13 2013/05/15 15:57:01 pooka Exp $
 .\"
 .\" Copyright (c) 2013 Antti Kantee.  All rights reserved.
 .\"
@@ -280,6 +280,51 @@ results in undefined behavior.
 .It Fa retv
 number of bytes successfully transferred is returned here
 .El
+.Pp
+.Ft int
+.Fo rumpuser_syncfd
+.Fa "int fd" "int flags" "uint64_t start" "uint64_t len"
+.Fc
+.Pp
+Synchronizes
+.Fa fd
+with respect to backing storage.
+The other arguments are:
+.Pp
+.Bl -tag -width "xenum_rumpclock"
+.It Fa flags
+controls how syncronization happens.
+It must contain one of the following:
+.Bl -tag -width "XRUMPUSER_SYNCFD_BARRIER"
+.It Dv RUMPUSER_SYNCFD_READ
+Make sure that the next read sees writes from all other parties.
+This is useful for example in the case that
+.Fa fd
+represents memory to write a DMA read is being performed.
+.It Dv RUMPUSER_SYNCFD_WRITE
+Flush cached writes.
+.El
+.Pp
+The following additional parameters may be passed in
+.Fa flags :
+.Pp
+.Bl -tag -width "XRUMPUSER_SYNCFD_BARRIER"
+.It Dv RUMPUSER_SYNCFD_BARRIER
+Issue a barrier.
+Outstanding I/O operations which were started before the barrier
+complete before any operations after the barrier are performed.
+.It Dv RUMPUSER_SYNCFD_SYNC
+Wait for the synchronization operation to fully complete before
+returning.
+For example, this could mean that the data to be written to a disk
+has hit either the disk or non-volatile memory.
+.El
+.It Fa start
+offset into the object.
+.It Fa len
+the number of bytes to synchronize.
+The value 0 denotes until the end of the object.
+.El
 .Ss Clocks
 The hypervisor should support two clocks, one for wall time and one
 for monotonically increasing time, the latter of which may be based

Index: src/lib/librumpuser/rumpuser.c
diff -u src/lib/librumpuser/rumpuser.c:1.52 src/lib/librumpuser/rumpuser.c:1.53
--- src/lib/librumpuser/rumpuser.c:1.52	Wed May 15 14:58:24 2013
+++ src/lib/librumpuser/rumpuser.c	Wed May 15 15:57:01 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.c,v 1.52 2013/05/15 14:58:24 pooka Exp $	*/
+/*	$NetBSD: rumpuser.c,v 1.53 2013/05/15 15:57:01 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
 #include "rumpuser_port.h"
 
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.52 2013/05/15 14:58:24 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.53 2013/05/15 15:57:01 pooka Exp $");
 #endif /* !lint */
 
 #include <sys/ioctl.h>
@@ -397,6 +397,43 @@ rumpuser_iovwrite(int fd, const struct r
 }
 
 int
+rumpuser_syncfd(int fd, int flags, uint64_t start, uint64_t len)
+{
+	int rv = 0;
+	
+	/*
+	 * For now, assume fd is regular file and does not care
+	 * about read syncing
+	 */
+	if ((flags & RUMPUSER_SYNCFD_BOTH) == 0) {
+		rv = EINVAL;
+		goto out;
+	}
+	if ((flags & RUMPUSER_SYNCFD_WRITE) == 0) {
+		rv = 0;
+		goto out;
+	}
+
+#ifdef __NetBSD__
+	{
+	int fsflags = FDATASYNC;
+
+	if (fsflags & RUMPUSER_SYNCFD_SYNC)
+		fsflags |= FDISKSYNC;
+	if (fsync_range(fd, fsflags, start, len) == -1)
+		rv = errno;
+	}
+#else
+	/* el-simplo */
+	if (fsync(fd) == -1)
+		rv = errno;
+#endif
+
+ out:
+	ET(rv);
+}
+
+int
 rumpuser_clock_gettime(int enum_rumpclock, int64_t *sec, long *nsec)
 {
 	enum rumpclock rclk = enum_rumpclock;

Index: src/sys/rump/include/rump/rumpuser.h
diff -u src/sys/rump/include/rump/rumpuser.h:1.106 src/sys/rump/include/rump/rumpuser.h:1.107
--- src/sys/rump/include/rump/rumpuser.h:1.106	Wed May 15 14:58:24 2013
+++ src/sys/rump/include/rump/rumpuser.h	Wed May 15 15:57:01 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.h,v 1.106 2013/05/15 14:58:24 pooka Exp $	*/
+/*	$NetBSD: rumpuser.h,v 1.107 2013/05/15 15:57:01 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007-2013 Antti Kantee.  All Rights Reserved.
@@ -109,6 +109,13 @@ int rumpuser_iovread(int, struct rumpuse
 int rumpuser_iovwrite(int, const struct rumpuser_iovec *, size_t,
 		      int64_t, size_t *);
 
+#define RUMPUSER_SYNCFD_READ	0x01
+#define RUMPUSER_SYNCFD_WRITE	0x02
+#define RUMPUSER_SYNCFD_BOTH	(RUMPUSER_SYNCFD_READ | RUMPUSER_SYNCFD_WRITE)
+#define RUMPUSER_SYNCFD_BARRIER	0x04
+#define RUMPUSER_SYNCFD_SYNC	0x08
+int rumpuser_syncfd(int, int, uint64_t, uint64_t);
+
 /*
  * clock and zzz
  */

Reply via email to