sys/kern: Don't implement .vfs_sync unless sync is supported
authorTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Tue, 24 May 2016 15:09:48 +0000 (00:09 +0900)
committerTomohiro Kusumi <kusumi.tomohiro@gmail.com>
Thu, 2 Jun 2016 23:34:59 +0000 (08:34 +0900)
The only reason filesystems without requirement of syncing
(e.g. no backing storage) need to implement .vfs_sync is because
those fs need a sync with a return value of 0 on unmount.

If unmount allows sync with return value of EOPNOTSUPP for fs
that do not support sync, those fs no longer have to implement
.vfs_sync with vfs_stdsync() only to pass dounmount().

The drawback is when there is a sync (other than vfs_stdnosync)
that returns EOPNOTSUPP for real errors. The existing fs in
DragonFly don't do this (and shouldn't either).

Also see https://bugs.dragonflybsd.org/issues/2912.

 # grep "\.vfs_sync" sys/vfs sys/gnu/vfs -rI | grep vfs_stdsync
 sys/vfs/udf/udf_vfsops.c:       .vfs_sync =             vfs_stdsync,
 sys/vfs/portal/portal_vfsops.c: .vfs_sync =             vfs_stdsync
 sys/vfs/devfs/devfs_vfsops.c:   .vfs_sync       = vfs_stdsync,
 sys/vfs/isofs/cd9660/cd9660_vfsops.c:   .vfs_sync =             vfs_stdsync,
 sys/vfs/autofs/autofs_vfsops.c: .vfs_sync =             vfs_stdsync,    /* for unmount(2) */
 sys/vfs/tmpfs/tmpfs_vfsops.c:   .vfs_sync =                     vfs_stdsync,
 sys/vfs/dirfs/dirfs_vfsops.c:   .vfs_sync =                     vfs_stdsync,
 sys/vfs/ntfs/ntfs_vfsops.c:     .vfs_sync =             vfs_stdsync,
 sys/vfs/procfs/procfs_vfsops.c: .vfs_sync =             vfs_stdsync
 sys/vfs/hpfs/hpfs_vfsops.c:     .vfs_sync =             vfs_stdsync,
 sys/vfs/nullfs/null_vfsops.c:   .vfs_sync =             vfs_stdsync,

sys/kern/vfs_syscalls.c
sys/vfs/devfs/devfs_vfsops.c
sys/vfs/dirfs/dirfs_vfsops.c
sys/vfs/hpfs/hpfs_vfsops.c
sys/vfs/isofs/cd9660/cd9660_vfsops.c
sys/vfs/ntfs/ntfs_vfsops.c
sys/vfs/nullfs/null_vfsops.c
sys/vfs/portal/portal_vfsops.c
sys/vfs/procfs/procfs_vfsops.c
sys/vfs/tmpfs/tmpfs_vfsops.c
sys/vfs/udf/udf_vfsops.c

index 24f963f..c3bc0e1 100644 (file)
@@ -777,17 +777,17 @@ dounmount(struct mount *mp, int flags)
        /*
         * So far so good, sync the filesystem once more and
         * call the VFS unmount code if the sync succeeds.
-        *
-        * A filesystem without explicitly initialzed .vfs_sync
-        * fails here since vfs_stdnosync() returns EOPNOTSUPP.
-        * A filesystem needs to implement vfs_stdsync() which
-        * returns 0 even if there is no backing storage.
         */
        if (error == 0) {
-               if (((mp->mnt_flag & MNT_RDONLY) ||
-                    (error = VFS_SYNC(mp, MNT_WAIT)) == 0) ||
-                   (flags & MNT_FORCE)) {
+               if (mp->mnt_flag & MNT_RDONLY) {
                        error = VFS_UNMOUNT(mp, flags);
+               } else {
+                       error = VFS_SYNC(mp, MNT_WAIT);
+                       if ((error == 0) ||
+                           (error == EOPNOTSUPP) || /* No sync */
+                           (flags & MNT_FORCE)) {
+                               error = VFS_UNMOUNT(mp, flags);
+                       }
                }
        }
 
index 8d9e012..0e26409 100644 (file)
@@ -270,7 +270,6 @@ static struct vfsops devfs_vfsops = {
        .vfs_unmount    = devfs_vfs_unmount,
        .vfs_root       = devfs_vfs_root,
        .vfs_statfs     = devfs_vfs_statfs,
-       .vfs_sync       = vfs_stdsync,
        .vfs_vget       = devfs_vfs_vget,
        .vfs_vptofh     = devfs_vfs_vptofh,
        .vfs_fhtovp     = devfs_vfs_fhtovp,
index b77737f..ca874d0 100644 (file)
@@ -352,7 +352,6 @@ static struct vfsops dirfs_vfsops = {
        .vfs_statvfs =                  dirfs_statvfs,
        .vfs_fhtovp =                   dirfs_fhtovp,
        .vfs_vptofh =                   dirfs_vptofh,
-       .vfs_sync =                     vfs_stdsync,
        .vfs_checkexp =                 dirfs_checkexp
 };
 
index af65891..aa51e6f 100644 (file)
@@ -557,7 +557,6 @@ static struct vfsops hpfs_vfsops = {
        .vfs_unmount =          hpfs_unmount,
        .vfs_root =             hpfs_root,
        .vfs_statfs =           hpfs_statfs,
-       .vfs_sync =             vfs_stdsync,
        .vfs_vget =             hpfs_vget,
        .vfs_fhtovp =           hpfs_fhtovp,
        .vfs_checkexp =         hpfs_checkexp,
index 7b7a8f2..4c738be 100644 (file)
@@ -86,7 +86,6 @@ static struct vfsops cd9660_vfsops = {
        .vfs_unmount =          cd9660_unmount,
        .vfs_root =             cd9660_root,
        .vfs_statfs =           cd9660_statfs,
-       .vfs_sync =             vfs_stdsync,
        .vfs_vget =             cd9660_vget,
        .vfs_fhtovp =           cd9660_fhtovp,
        .vfs_checkexp =         cd9660_checkexp,
index 2e37daf..97b845f 100644 (file)
@@ -802,7 +802,6 @@ static struct vfsops ntfs_vfsops = {
        .vfs_root =             ntfs_root,
        .vfs_statfs =           ntfs_statfs,
        .vfs_statvfs =          ntfs_statvfs,
-       .vfs_sync =             vfs_stdsync,
        .vfs_vget =             ntfs_vget,
        .vfs_fhtovp =           ntfs_fhtovp,
        .vfs_checkexp =         ntfs_checkexp,
index 78352c1..00e0ac7 100644 (file)
@@ -398,7 +398,6 @@ static struct vfsops null_vfsops = {
        .vfs_root =             nullfs_root,
        .vfs_quotactl =         nullfs_quotactl,
        .vfs_statfs =           nullfs_statfs,
-       .vfs_sync =             vfs_stdsync,
        .vfs_extattrctl =       nullfs_extattrctl,
        .vfs_fhtovp =           nullfs_fhtovp,
        .vfs_vptofh =           nullfs_vptofh,
index 1712478..73618a9 100644 (file)
@@ -227,7 +227,6 @@ static struct vfsops portal_vfsops = {
        .vfs_unmount =          portal_unmount,
        .vfs_root =             portal_root,
        .vfs_statfs =           portal_statfs,
-       .vfs_sync =             vfs_stdsync
 };
 
 VFS_SET(portal_vfsops, portal, VFCF_SYNTHETIC);
index 174fb3d..9737a7d 100644 (file)
@@ -148,7 +148,6 @@ static struct vfsops procfs_vfsops = {
        .vfs_unmount =          procfs_unmount,
        .vfs_root =             procfs_root,
        .vfs_statfs =           procfs_statfs,
-       .vfs_sync =             vfs_stdsync
 };
 
 VFS_SET(procfs_vfsops, procfs, VFCF_SYNTHETIC);
index 80e5a31..d81ebfa 100644 (file)
@@ -593,7 +593,6 @@ static struct vfsops tmpfs_vfsops = {
        .vfs_statfs =                   tmpfs_statfs,
        .vfs_fhtovp =                   tmpfs_fhtovp,
        .vfs_vptofh =                   tmpfs_vptofh, 
-       .vfs_sync =                     vfs_stdsync,
        .vfs_checkexp =                 tmpfs_checkexp,
 };
 
index f0615a8..e3bc22c 100644 (file)
@@ -116,7 +116,6 @@ static struct vfsops udf_vfsops = {
        .vfs_unmount =          udf_unmount,
        .vfs_root =             udf_root,
        .vfs_statfs =           udf_statfs,
-       .vfs_sync =             vfs_stdsync,
        .vfs_vget =             udf_vget,
        .vfs_fhtovp =           udf_fhtovp,
        .vfs_vptofh =           udf_vptofh