Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Add a generalized rumpuser_syncfd() call which allows the ca...



details:   https://anonhg.NetBSD.org/src/rev/639106bb8881
branches:  trunk
changeset: 786847:639106bb8881
user:      pooka <pooka%NetBSD.org@localhost>
date:      Wed May 15 15:57:01 2013 +0000

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

diffstat:

 lib/librumpuser/rumpuser.3       |  47 +++++++++++++++++++++++++++++++++++++++-
 lib/librumpuser/rumpuser.c       |  41 +++++++++++++++++++++++++++++++++-
 sys/rump/include/rump/rumpuser.h |   9 ++++++-
 3 files changed, 93 insertions(+), 4 deletions(-)

diffs (146 lines):

diff -r b7513cb9ec61 -r 639106bb8881 lib/librumpuser/rumpuser.3
--- a/lib/librumpuser/rumpuser.3        Wed May 15 14:58:24 2013 +0000
+++ b/lib/librumpuser/rumpuser.3        Wed May 15 15:57:01 2013 +0000
@@ -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 @@
 .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
diff -r b7513cb9ec61 -r 639106bb8881 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c        Wed May 15 14:58:24 2013 +0000
+++ b/lib/librumpuser/rumpuser.c        Wed May 15 15:57:01 2013 +0000
@@ -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 @@
 }
 
 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;
diff -r b7513cb9ec61 -r 639106bb8881 sys/rump/include/rump/rumpuser.h
--- a/sys/rump/include/rump/rumpuser.h  Wed May 15 14:58:24 2013 +0000
+++ b/sys/rump/include/rump/rumpuser.h  Wed May 15 15:57:01 2013 +0000
@@ -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_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
  */



Home | Main Index | Thread Index | Old Index