diff options
author | helg <helg@cvs.openbsd.org> | 2018-07-16 13:10:54 +0000 |
---|---|---|
committer | helg <helg@cvs.openbsd.org> | 2018-07-16 13:10:54 +0000 |
commit | 1517307726c832675acce4bc5b463699b82f8afa (patch) | |
tree | 75fb5501a700b30f47e59a0c4a268cede339c3bc /sys/miscfs/fuse | |
parent | 0da7d4bc120fe64fdbbc90778507243b903301a6 (diff) |
Implement FBT_FSYNC, which is called on fsync(2) and fdatasync(2).
Currently ignores the a_waitfor argument and always invokes the file
system's fsync implementation synchronously.
ok mpi@
Diffstat (limited to 'sys/miscfs/fuse')
-rw-r--r-- | sys/miscfs/fuse/fuse_vnops.c | 61 | ||||
-rw-r--r-- | sys/miscfs/fuse/fusefs.h | 3 |
2 files changed, 61 insertions, 3 deletions
diff --git a/sys/miscfs/fuse/fuse_vnops.c b/sys/miscfs/fuse/fuse_vnops.c index 051c6335f26..b20f532ce25 100644 --- a/sys/miscfs/fuse/fuse_vnops.c +++ b/sys/miscfs/fuse/fuse_vnops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_vnops.c,v 1.49 2018/06/21 14:17:23 visa Exp $ */ +/* $OpenBSD: fuse_vnops.c,v 1.50 2018/07/16 13:10:53 helg Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com> * @@ -66,6 +66,7 @@ int fusefs_lock(void *); int fusefs_unlock(void *); int fusefs_islocked(void *); int fusefs_advlock(void *); +int fusefs_fsync(void *); /* Prototypes for fusefs kqfilter */ int filt_fusefsread(struct knote *, long); @@ -87,7 +88,7 @@ struct vops fusefs_vops = { .vop_ioctl = fusefs_ioctl, .vop_poll = fusefs_poll, .vop_kqfilter = fusefs_kqfilter, - .vop_fsync = nullop, + .vop_fsync = fusefs_fsync, .vop_remove = fusefs_remove, .vop_link = fusefs_link, .vop_rename = fusefs_rename, @@ -1526,3 +1527,59 @@ fusefs_advlock(void *v) return (lf_advlock(&ip->ufs_ino.i_lockf, ip->filesize, ap->a_id, ap->a_op, ap->a_fl, ap->a_flags)); } + +int +fusefs_fsync(void *v) +{ + struct vop_fsync_args *ap = v; + struct vnode *vp = ap->a_vp; + struct proc *p = ap->a_p; + struct fusefs_node *ip; + struct fusefs_mnt *fmp; + struct fusefs_filehandle *fufh; + struct fusebuf *fbuf; + int type, error = 0; + + /* + * Can't write to directory file handles so no need to fsync. + * FUSE has fsyncdir but it doesn't make sense on OpenBSD. + */ + if (vp->v_type == VDIR) + return (0); + + ip = VTOI(vp); + fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump; + + if (!fmp->sess_init) + return (ENXIO); + + /* Implementing fsync is optional so don't error. */ + if (fmp->undef_op & UNDEF_FSYNC) + return (0); + + /* Sync all writeable file descriptors. */ + for (type = 0; type < FUFH_MAXTYPE; type++) { + fufh = &(ip->fufh[type]); + if (fufh->fh_type == FUFH_WRONLY || + fufh->fh_type == FUFH_RDWR) { + + fbuf = fb_setup(0, ip->ufs_ino.i_number, FBT_FSYNC, p); + fbuf->fb_io_fd = fufh->fh_id; + + /* Always behave as if ap->a_waitfor = MNT_WAIT. */ + error = fb_queue(fmp->dev, fbuf); + fb_delete(fbuf); + if (error) + break; + } + } + + if (error == ENOSYS) { + fmp->undef_op |= UNDEF_FSYNC; + + /* Implementing fsync is optional so don't error. */ + return (0); + } + + return (error); +} diff --git a/sys/miscfs/fuse/fusefs.h b/sys/miscfs/fuse/fusefs.h index c0b3fb89126..237ef0578f2 100644 --- a/sys/miscfs/fuse/fusefs.h +++ b/sys/miscfs/fuse/fusefs.h @@ -1,4 +1,4 @@ -/* $OpenBSD: fusefs.h,v 1.12 2018/06/25 12:03:53 helg Exp $ */ +/* $OpenBSD: fusefs.h,v 1.13 2018/07/16 13:10:53 helg Exp $ */ /* * Copyright (c) 2012-2013 Sylvestre Gallon <ccna.syl@gmail.com> * @@ -68,6 +68,7 @@ struct fusefs_mnt { #define UNDEF_SYMLINK 1<<9 #define UNDEF_MKNOD 1<<10 #define UNDEF_FLUSH 1<<11 +#define UNDEF_FSYNC 1<<12 extern struct vops fusefs_vops; extern struct pool fusefs_fbuf_pool; |