Re: svn commit: r304176 - in head: include lib/libc/sys sys/compat/freebsd32 sys/kern

2016-08-18 Thread Jilles Tjoelker
On Thu, Aug 18, 2016 at 10:53:16AM +0300, Konstantin Belousov wrote:
> On Wed, Aug 17, 2016 at 10:20:40PM +0200, Jilles Tjoelker wrote:
> > On Mon, Aug 15, 2016 at 07:08:51PM +, Konstantin Belousov wrote:
> > >  /* ISO/IEC 9945-1: 1996 */
> > >  #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE
> > >  int   fsync(int);
> > > +int   fdatasync(int);
> > >  
> > >  /*
> > >   * ftruncate() was in the POSIX Realtime Extension (it's used for shared

> > Apparently these functions were added closely enough in time that they
> > can stay together here :)

> Is this a form of suggestion to use other value for POSIX_VISIBLE ?

No, no change is necessary.

> > > +#if 0
> > > + if (!fullsync)
> > > + /* XXXKIB: compete outstanding aio writes */;

> > Under the _POSIX_SYNCHRONIZED_IO option, completing outstanding I/O
> > requests is in fact required for fsync() as well. The fdatasync()
> > function is completely under the _POSIX_SYNCHRONIZED_IO option.

> > We do not implement this option, but keeping fdatasync()'s guarantees a
> > subset of fsync()'s guarantees seems sensible.

> I will consider this if and when the AIO flush would be implemented.
> I looked at the AIO code to estimate the needed work, but did not started
> coding and quite possible it would be postponed.

OK.

> > > +%% fdatasync vp  L L L
> > > +
> > > +vop_fdatasync {
> > > + IN struct vnode *vp;
> > > + IN struct thread *td;
> > > +};
> > A waitfor parameter like in vop_fsync may be useful to implement
> > aio_fsync(O_DSYNC) later on.

> I really do not see how would it be. aio_fsync(O_DSYNC) is equivalent
> to fdatasync(2) in the async context. Completion of the aio request
> indicates that virtual fdatasync(2) execution did finished in that
> context. The use of waitfor in the VOP_FSYNC() is to allow syncer
> to initiate flush without waiting, or getting notification for the
> completion.

> Could you, please, elaborate ?  If the KPI change is needed there, it
> is obviously desirable to make it right before MFC to stable.

Oh, you're right. No change is needed. A MNT_NOWAIT fsync operation does
not provide any feedback when it is complete, so it is not useful for
AIO. In fact, aio_fsync() eventually calls VOP_FSYNC with MNT_WAIT on a
worker thread.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r304176 - in head: include lib/libc/sys sys/compat/freebsd32 sys/kern

2016-08-18 Thread Konstantin Belousov
On Wed, Aug 17, 2016 at 10:20:40PM +0200, Jilles Tjoelker wrote:
> On Mon, Aug 15, 2016 at 07:08:51PM +, Konstantin Belousov wrote:
> >  /* ISO/IEC 9945-1: 1996 */
> >  #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE
> >  int fsync(int);
> > +int fdatasync(int);
> >  
> >  /*
> >   * ftruncate() was in the POSIX Realtime Extension (it's used for shared
> 
> Apparently these functions were added closely enough in time that they
> can stay together here :)
Is this a form of suggestion to use other value for POSIX_VISIBLE ?

> > +#if 0
> > +   if (!fullsync)
> > +   /* XXXKIB: compete outstanding aio writes */;
> 
> Under the _POSIX_SYNCHRONIZED_IO option, completing outstanding I/O
> requests is in fact required for fsync() as well. The fdatasync()
> function is completely under the _POSIX_SYNCHRONIZED_IO option.
> 
> We do not implement this option, but keeping fdatasync()'s guarantees a
> subset of fsync()'s guarantees seems sensible.
I will consider this if and when the AIO flush would be implemented.
I looked at the AIO code to estimate the needed work, but did not started
coding and quite possible it would be postponed.

> > +%% fdatasync   vp  L L L
> > +
> > +vop_fdatasync {
> > +   IN struct vnode *vp;
> > +   IN struct thread *td;
> > +};
> A waitfor parameter like in vop_fsync may be useful to implement
> aio_fsync(O_DSYNC) later on.

I really do not see how would it be. aio_fsync(O_DSYNC) is equivalent
to fdatasync(2) in the async context. Completion of the aio request
indicates that virtual fdatasync(2) execution did finished in that
context. The use of waitfor in the VOP_FSYNC() is to allow syncer
to initiate flush without waiting, or getting notification for the
completion.

Could you, please, elaborate ?  If the KPI change is needed there, it
is obviously desirable to make it right before MFC to stable.
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


Re: svn commit: r304176 - in head: include lib/libc/sys sys/compat/freebsd32 sys/kern

2016-08-17 Thread Jilles Tjoelker
On Mon, Aug 15, 2016 at 07:08:51PM +, Konstantin Belousov wrote:
> Author: kib
> Date: Mon Aug 15 19:08:51 2016
> New Revision: 304176
> URL: https://svnweb.freebsd.org/changeset/base/304176

> Log:
>   Add an implementation of fdatasync(2).

>   The syscall is a trivial wrapper around new VOP_FDATASYNC(), sharing
>   code with fsync(2).  For all filesystems, this commit provides the
>   implementation which delegates the work of VOP_FDATASYNC() to
>   VOP_FSYNC().  This is functionally correct but not efficient.

>   This is not yet POSIX-compliant implementation, because it does not
>   ensure that queued AIO requests are completed before returning.

>   Reviewed by:mckusick
>   Discussed with: avg (ZFS), jhb (AIO part)
>   Tested by:  pho
>   Sponsored by:   The FreeBSD Foundation
>   MFC after:  2 weeks
>   Differential revision:  https://reviews.freebsd.org/D7471

> Modified:
>   head/include/unistd.h
>   head/lib/libc/sys/Symbol.map
>   head/sys/compat/freebsd32/syscalls.master
>   head/sys/kern/syscalls.master
>   head/sys/kern/vfs_default.c
>   head/sys/kern/vfs_syscalls.c
>   head/sys/kern/vnode_if.src

> Modified: head/include/unistd.h
> ==
> --- head/include/unistd.h Mon Aug 15 19:05:41 2016(r304175)
> +++ head/include/unistd.h Mon Aug 15 19:08:51 2016(r304176)
> @@ -384,6 +384,7 @@ extern int optind, opterr, optopt;
>  /* ISO/IEC 9945-1: 1996 */
>  #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE
>  int   fsync(int);
> +int   fdatasync(int);
>  
>  /*
>   * ftruncate() was in the POSIX Realtime Extension (it's used for shared

Apparently these functions were added closely enough in time that they
can stay together here :)

> [snip]
> Modified: head/sys/kern/vfs_syscalls.c
> ==
> --- head/sys/kern/vfs_syscalls.c  Mon Aug 15 19:05:41 2016
> (r304175)
> +++ head/sys/kern/vfs_syscalls.c  Mon Aug 15 19:08:51 2016
> (r304176)
> @@ -3354,20 +3354,8 @@ freebsd6_ftruncate(struct thread *td, st
>  }
>  #endif
>  
> -/*
> - * Sync an open file.
> - */
> -#ifndef _SYS_SYSPROTO_H_
> -struct fsync_args {
> - int fd;
> -};
> -#endif
> -int
> -sys_fsync(td, uap)
> - struct thread *td;
> - struct fsync_args /* {
> - int fd;
> - } */ *uap;
> +static int
> +kern_fsync(struct thread *td, int fd, bool fullsync)
>  {
>   struct vnode *vp;
>   struct mount *mp;
> @@ -3375,11 +3363,15 @@ sys_fsync(td, uap)
>   cap_rights_t rights;
>   int error, lock_flags;
>  
> - AUDIT_ARG_FD(uap->fd);
> - error = getvnode(td, uap->fd, cap_rights_init(, CAP_FSYNC), );
> + AUDIT_ARG_FD(fd);
> + error = getvnode(td, fd, cap_rights_init(, CAP_FSYNC), );
>   if (error != 0)
>   return (error);
>   vp = fp->f_vnode;
> +#if 0
> + if (!fullsync)
> + /* XXXKIB: compete outstanding aio writes */;

Under the _POSIX_SYNCHRONIZED_IO option, completing outstanding I/O
requests is in fact required for fsync() as well. The fdatasync()
function is completely under the _POSIX_SYNCHRONIZED_IO option.

We do not implement this option, but keeping fdatasync()'s guarantees a
subset of fsync()'s guarantees seems sensible.

> +#endif
>   error = vn_start_write(vp, , V_WAIT | PCATCH);
>   if (error != 0)
>   goto drop;
> [snip]
> Modified: head/sys/kern/vnode_if.src
> ==
> --- head/sys/kern/vnode_if.srcMon Aug 15 19:05:41 2016
> (r304175)
> +++ head/sys/kern/vnode_if.srcMon Aug 15 19:08:51 2016
> (r304176)
> @@ -703,6 +703,14 @@ vop_add_writecount {
>   IN int inc;
>  };
>  
> +%% fdatasync vp  L L L
> +
> +vop_fdatasync {
> + IN struct vnode *vp;
> + IN struct thread *td;
> +};
> +
> +
>  # The VOPs below are spares at the end of the table to allow new VOPs to be
>  # added in stable branches without breaking the KBI.  New VOPs in HEAD should
>  # be added above these spares.  When merging a new VOP to a stable branch,

A waitfor parameter like in vop_fsync may be useful to implement
aio_fsync(O_DSYNC) later on.

-- 
Jilles Tjoelker
___
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"


svn commit: r304176 - in head: include lib/libc/sys sys/compat/freebsd32 sys/kern

2016-08-15 Thread Konstantin Belousov
Author: kib
Date: Mon Aug 15 19:08:51 2016
New Revision: 304176
URL: https://svnweb.freebsd.org/changeset/base/304176

Log:
  Add an implementation of fdatasync(2).
  
  The syscall is a trivial wrapper around new VOP_FDATASYNC(), sharing
  code with fsync(2).  For all filesystems, this commit provides the
  implementation which delegates the work of VOP_FDATASYNC() to
  VOP_FSYNC().  This is functionally correct but not efficient.
  
  This is not yet POSIX-compliant implementation, because it does not
  ensure that queued AIO requests are completed before returning.
  
  Reviewed by:  mckusick
  Discussed with:   avg (ZFS), jhb (AIO part)
  Tested by:pho
  Sponsored by: The FreeBSD Foundation
  MFC after:2 weeks
  Differential revision:https://reviews.freebsd.org/D7471

Modified:
  head/include/unistd.h
  head/lib/libc/sys/Symbol.map
  head/sys/compat/freebsd32/syscalls.master
  head/sys/kern/syscalls.master
  head/sys/kern/vfs_default.c
  head/sys/kern/vfs_syscalls.c
  head/sys/kern/vnode_if.src

Modified: head/include/unistd.h
==
--- head/include/unistd.h   Mon Aug 15 19:05:41 2016(r304175)
+++ head/include/unistd.h   Mon Aug 15 19:08:51 2016(r304176)
@@ -384,6 +384,7 @@ extern int optind, opterr, optopt;
 /* ISO/IEC 9945-1: 1996 */
 #if __POSIX_VISIBLE >= 199506 || __XSI_VISIBLE
 int fsync(int);
+int fdatasync(int);
 
 /*
  * ftruncate() was in the POSIX Realtime Extension (it's used for shared

Modified: head/lib/libc/sys/Symbol.map
==
--- head/lib/libc/sys/Symbol.mapMon Aug 15 19:05:41 2016
(r304175)
+++ head/lib/libc/sys/Symbol.mapMon Aug 15 19:08:51 2016
(r304176)
@@ -400,6 +400,10 @@ FBSD_1.4 {
recvmmsg;
 };
 
+FBSD_1.5 {
+fdatasync;
+};
+
 FBSDprivate_1.0 {
___acl_aclcheck_fd;
__sys___acl_aclcheck_fd;
@@ -594,6 +598,8 @@ FBSDprivate_1.0 {
__sys_fstatfs;
_fsync;
__sys_fsync;
+   _fdatasync;
+   __sys_fdatasync;
_futimes;
__sys_futimes;
_getaudit;

Modified: head/sys/compat/freebsd32/syscalls.master
==
--- head/sys/compat/freebsd32/syscalls.master   Mon Aug 15 19:05:41 2016
(r304175)
+++ head/sys/compat/freebsd32/syscalls.master   Mon Aug 15 19:08:51 2016
(r304176)
@@ -1081,3 +1081,4 @@
 549AUE_NULLNOPROTO { int numa_setaffinity(cpuwhich_t which, \
id_t id, \
const struct vm_domain_policy *policy); }
+550AUE_FSYNC   NOPROTO { int fdatasync(int fd); }

Modified: head/sys/kern/syscalls.master
==
--- head/sys/kern/syscalls.master   Mon Aug 15 19:05:41 2016
(r304175)
+++ head/sys/kern/syscalls.master   Mon Aug 15 19:08:51 2016
(r304176)
@@ -993,8 +993,9 @@
id_t id, \
struct vm_domain_policy_entry *policy); }
 549AUE_NULLSTD { int numa_setaffinity(cpuwhich_t which, \
-   id_t id, \
-   const struct vm_domain_policy_entry 
*policy); }
+   id_t id, const struct \
+   vm_domain_policy_entry *policy); }
+550AUE_FSYNC   STD { int fdatasync(int fd); }
 
 ; Please copy any additions and changes to the following compatability tables:
 ; sys/compat/freebsd32/syscalls.master

Modified: head/sys/kern/vfs_default.c
==
--- head/sys/kern/vfs_default.c Mon Aug 15 19:05:41 2016(r304175)
+++ head/sys/kern/vfs_default.c Mon Aug 15 19:08:51 2016(r304176)
@@ -83,6 +83,7 @@ static int vop_stdset_text(struct vop_se
 static int vop_stdunset_text(struct vop_unset_text_args *ap);
 static int vop_stdget_writecount(struct vop_get_writecount_args *ap);
 static int vop_stdadd_writecount(struct vop_add_writecount_args *ap);
+static int vop_stdfdatasync(struct vop_fdatasync_args *ap);
 static int vop_stdgetpages_async(struct vop_getpages_async_args *ap);
 
 /*
@@ -111,6 +112,7 @@ struct vop_vector default_vnodeops = {
.vop_bmap = vop_stdbmap,
.vop_close =VOP_NULL,
.vop_fsync =VOP_NULL,
+   .vop_fdatasync =vop_stdfdatasync,
.vop_getpages = vop_stdgetpages,
.vop_getpages_async =   vop_stdgetpages_async,
.vop_getwritemount =vop_stdgetwritemount,
@@ -726,6 +728,13 @@ loop2:
return (error);
 }
 
+static int
+vop_stdfdatasync(struct vop_fdatasync_args *ap)
+{
+
+   return (VOP_FSYNC(ap->a_vp, MNT_WAIT,