Source-Changes-HG archive

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

[src/trunk]: src Userland portion of fsync_range(2), written by Bill Studenmu...



details:   https://anonhg.NetBSD.org/src/rev/af0ee2d67ee8
branches:  trunk
changeset: 555450:af0ee2d67ee8
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Nov 18 00:56:56 2003 +0000

description:
Userland portion of fsync_range(2), written by Bill Studenmund, and
contributed by Wasabi Systems, Inc.

diffstat:

 distrib/sets/lists/comp/mi          |   4 +-
 include/unistd.h                    |   3 +-
 lib/libc/sys/Makefile.inc           |   7 +-
 lib/libc/sys/fsync.2                |  77 ++++++++++++++++++++++++++++++++++--
 lib/libpthread/pthread_cancelstub.c |  26 +++++++++++-
 lib/libpthread/pthread_testcancel.3 |   3 +-
 6 files changed, 106 insertions(+), 14 deletions(-)

diffs (271 lines):

diff -r adde0007dfcd -r af0ee2d67ee8 distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi        Mon Nov 17 22:59:00 2003 +0000
+++ b/distrib/sets/lists/comp/mi        Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: mi,v 1.640 2003/11/16 15:10:46 yamt Exp $
+#      $NetBSD: mi,v 1.641 2003/11/18 00:56:57 thorpej Exp $
 ./usr/bin/addr2line            comp-debug-bin
 ./usr/bin/ar                   comp-util-bin
 ./usr/bin/as                   comp-util-bin
@@ -1210,6 +1210,7 @@
 ./usr/share/man/cat2/fstat.0           comp-c-catman
 ./usr/share/man/cat2/fstatfs.0         comp-c-catman
 ./usr/share/man/cat2/fsync.0           comp-c-catman
+./usr/share/man/cat2/fsync_range.0     comp-c-catman
 ./usr/share/man/cat2/ftruncate.0       comp-c-catman
 ./usr/share/man/cat2/futimes.0         comp-c-catman
 ./usr/share/man/cat2/getcontext.0      comp-c-catman
@@ -4675,6 +4676,7 @@
 ./usr/share/man/man2/fstat.2           comp-c-man
 ./usr/share/man/man2/fstatfs.2         comp-c-man
 ./usr/share/man/man2/fsync.2           comp-c-man
+./usr/share/man/man2/fsync_range.2     comp-c-man
 ./usr/share/man/man2/ftruncate.2               comp-c-man
 ./usr/share/man/man2/futimes.2         comp-c-man
 ./usr/share/man/man2/getcontext.2      comp-c-man
diff -r adde0007dfcd -r af0ee2d67ee8 include/unistd.h
--- a/include/unistd.h  Mon Nov 17 22:59:00 2003 +0000
+++ b/include/unistd.h  Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: unistd.h,v 1.94 2003/08/07 09:44:11 agc Exp $  */
+/*     $NetBSD: unistd.h,v 1.95 2003/11/18 00:56:56 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -307,6 +307,7 @@
 void    endusershell __P((void));
 int     exect __P((const char *, char * const *, char * const *));
 int     fchroot __P((int));
+int     fsync_range __P((int, int, off_t, off_t));
 int     getdomainname __P((char *, size_t));
 int     getgrouplist __P((const char *, gid_t, gid_t *, int *));
 mode_t  getmode __P((const void *, mode_t));
diff -r adde0007dfcd -r af0ee2d67ee8 lib/libc/sys/Makefile.inc
--- a/lib/libc/sys/Makefile.inc Mon Nov 17 22:59:00 2003 +0000
+++ b/lib/libc/sys/Makefile.inc Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile.inc,v 1.144 2003/09/16 13:51:34 cl Exp $
+#      $NetBSD: Makefile.inc,v 1.145 2003/11/18 00:56:56 thorpej Exp $
 #      @(#)Makefile.inc        8.3 (Berkeley) 10/24/94
 
 # sys sources
@@ -83,8 +83,8 @@
        timer_create.S timer_delete.S timer_gettime.S timer_getoverrun.S \
        timer_settime.S
 
-WEAKASM= accept.S close.S connect.S execve.S fcntl.S fsync.S kill.S \
-       msgrcv.S msgsnd.S __msync13.S \
+WEAKASM= accept.S close.S connect.S execve.S fcntl.S fsync.S fsync_range.S \
+       kill.S msgrcv.S msgsnd.S __msync13.S \
        nanosleep.S open.S poll.S read.S readv.S \
        select.S __sigsuspend14.S sysarch.S wait4.S write.S writev.S
 
@@ -167,6 +167,7 @@
 MLINKS+=clock_settime.2 clock_gettime.2
 MLINKS+=clock_settime.2 clock_getres.2
 MLINKS+=fhopen.2 fhstat.2 fhopen.2 fhstatfs.2
+MLINKS+=fsync.2 fsync_range.2
 MLINKS+=getcontext.2 setcontext.2
 MLINKS+=getgid.2 getegid.2
 MLINKS+=getitimer.2 setitimer.2
diff -r adde0007dfcd -r af0ee2d67ee8 lib/libc/sys/fsync.2
--- a/lib/libc/sys/fsync.2      Mon Nov 17 22:59:00 2003 +0000
+++ b/lib/libc/sys/fsync.2      Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: fsync.2,v 1.13 2003/08/07 16:43:57 agc Exp $
+.\"    $NetBSD: fsync.2,v 1.14 2003/11/18 00:56:57 thorpej Exp $
 .\"
 .\" Copyright (c) 1983, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,11 +29,12 @@
 .\"
 .\"     @(#)fsync.2    8.1 (Berkeley) 6/4/93
 .\"
-.Dd June 4, 1993
+.Dd November 14, 2003
 .Dt FSYNC 2
 .Os
 .Sh NAME
-.Nm fsync
+.Nm fsync ,
+.Nm fsync_range
 .Nd "synchronize a file's in-core state with that on disk"
 .Sh LIBRARY
 .Lb libc
@@ -41,6 +42,8 @@
 .In unistd.h
 .Ft int
 .Fn fsync "int fd"
+.Ft int
+.Fn fsync_range "int fd" "int how" "off_t start" "off_t length"
 .Sh DESCRIPTION
 .Fn fsync
 causes all modified data and attributes of
@@ -53,13 +56,44 @@
 should be used by programs that require a file to be
 in a known state, for example, in building a simple transaction
 facility.
+.Pp
+.Fn fsync_range
+causes all modified data starting at
+.Fa start
+for length
+.Fa length
+of
+.Fa fd
+to be written to permanent storage.
+Note that
+.Fn fsync_range
+requires that the file
+.Fa fd
+must be open for writing.
+.Pp
+.Fn fsync_range
+may flush the file data in one of two manners:
+.Bl -tag -width FDATASYNC
+.It Dv FDATASYNC
+Synchronize the file data and sufficient meta-data to retrieve the
+data for te specified range.
+.It Dv FFILESYNC
+Synchronize all modified file data and meta-data for the specified range.
+.El
+.Pp
+If the
+.Fa length
+parameter is zero,
+.Fn fsync_range
+will synchronize all of the file data.
 .Sh RETURN VALUES
 A 0 value is returned on success.
-A -1 value indicates an error.
+A \-1 value indicates an error.
 .Sh ERRORS
-The
 .Fn fsync
-fails if:
+or
+.Fn fsync_range
+fail if:
 .Bl -tag -width Er
 .It Bq Er EBADF
 .Fa fd
@@ -70,6 +104,31 @@
 .It Bq Er EIO
 An I/O error occurred while reading from or writing to the file system.
 .El
+.Pp
+Additionally,
+.Fn fsync_range
+fails if:
+.Bl -tag -width Er
+.It Bq Er EBADF
+.Fa fd
+is not open for writing.
+.It Bq Er EINVAL
+.Fa start
++
+.Fa length
+is less than
+.Fa start .
+.El
+.Sh NOTES
+For optimal efficiency, the
+.Fn fsync_range
+call requires that the file system containing the file referenced by
+.Fa fd
+support partial synchronization of file data.
+For file systems which do
+not support partial synchronization, the entire file will be synchronized
+and the call will be the equivalent of calling
+.Fn fsync .
 .Sh SEE ALSO
 .Xr sync 2 ,
 .Xr sync 8
@@ -78,3 +137,9 @@
 .Fn fsync
 function call appeared in
 .Bx 4.2 .
+.Pp
+The
+.Fn fsync_range
+function call first appeared in
+.Nx 2.0
+and is modeled after the function available in AIX.
diff -r adde0007dfcd -r af0ee2d67ee8 lib/libpthread/pthread_cancelstub.c
--- a/lib/libpthread/pthread_cancelstub.c       Mon Nov 17 22:59:00 2003 +0000
+++ b/lib/libpthread/pthread_cancelstub.c       Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pthread_cancelstub.c,v 1.5 2003/03/08 08:03:35 lukem Exp $     */
+/*     $NetBSD: pthread_cancelstub.c,v 1.6 2003/11/18 00:56:57 thorpej Exp $   */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -37,7 +37,13 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pthread_cancelstub.c,v 1.5 2003/03/08 08:03:35 lukem Exp $");
+__RCSID("$NetBSD: pthread_cancelstub.c,v 1.6 2003/11/18 00:56:57 thorpej Exp $");
+
+/*
+ * This is necessary because the fsync_range() name is always weak (it is
+ * not a POSIX function).
+ */
+#define        fsync_range     _fsync_range
 
 #include <sys/msg.h>
 #include <sys/types.h>
@@ -69,6 +75,7 @@
 int    _sys_connect(int, const struct sockaddr *, socklen_t);
 int    _sys_fcntl(int, int, ...);
 int    _sys_fsync(int);
+int    _sys_fsync_range(int, int, off_t, off_t);
 ssize_t        _sys_msgrcv(int, void *, size_t, long, int);
 int    _sys_msgsnd(int, const void *, size_t, int);
 int    _sys___msync13(void *, size_t, int);
@@ -157,6 +164,20 @@
        return retval;
 }
 
+int
+fsync_range(int d, int f, off_t s, off_t e)
+{
+       int retval;
+       pthread_t self;
+
+       self = pthread__self();
+       pthread__testcancel(self);
+       retval = _sys_fsync_range(d, f, s, e);
+       pthread__testcancel(self);
+
+       return retval;
+}
+
 ssize_t
 msgrcv(int msgid, void *msgp, size_t msgsz, long msgtyp, int msgflg)
 {
@@ -347,6 +368,7 @@
 __strong_alias(_close, close)
 __strong_alias(_fcntl, fcntl)
 __strong_alias(_fsync, fsync)
+__weak_alias(fsync_range, _fsync_range)
 __strong_alias(_msgrcv, msgrcv)
 __strong_alias(_msgsnd, msgsnd)
 __strong_alias(___msync13, __msync13)
diff -r adde0007dfcd -r af0ee2d67ee8 lib/libpthread/pthread_testcancel.3
--- a/lib/libpthread/pthread_testcancel.3       Mon Nov 17 22:59:00 2003 +0000
+++ b/lib/libpthread/pthread_testcancel.3       Tue Nov 18 00:56:56 2003 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pthread_testcancel.3,v 1.2 2003/07/04 08:42:20 wiz Exp $
+.\" $NetBSD: pthread_testcancel.3,v 1.3 2003/11/18 00:56:57 thorpej Exp $
 .\"
 .\" Copyright (c) 2002 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -134,6 +134,7 @@
 .Fn creat ,
 .Fn fcntl ,
 .Fn fsync ,
+.Fn fsync_range ,
 .\".Fn getmsg ,
 .\".Fn getpmsg ,
 .\".Fn lockf ,



Home | Main Index | Thread Index | Old Index