Nfs – Mounting NFS with sync option but without noac option

nfsnfs4

When I mount using the sync option:

sudo mount -o vers=4,soft,sync,sec=none -t nfs 192.168.1.198:/js.js /mnt/self

the sync option doesn't seem to get applied:

$ cat /proc/mounts | grep nfs
192.168.1.198:/js.js /mnt/self nfs4 rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,soft,proto=tcp,port=0,timeo=600,retrans=2,sec=null,clientaddr=192.168.1.198,local_lock=none,addr=192.168.1.198 0 0

However, if I use the noac option, which implies sync:

sudo mount -o vers=4,soft,noac,sec=none -t nfs 192.168.1.198:/js.js /mnt/self

then I do see it being applied:

$ cat /proc/mounts | grep nfs
192.168.1.198:/js.js /mnt/self nfs4 rw,sync,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,acregmin=0,acregmax=0,acdirmin=0,acdirmax=0,soft,noac,proto=tcp,port=0,timeo=600,retrans=2,sec=null,clientaddr=192.168.1.198,local_lock=none,addr=192.168.1.198 0 0

Also, if I mount the root of the server instead of a subdirectory:

sudo mount -o vers=4,sync,sec=none -t nfs 192.168.1.198:/ /mnt/self

then I also see the sync option being applied:

$ cat /proc/mounts | grep nfs
192.168.1.198:/ /mnt/self nfs4 rw,sync,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=null,clientaddr=192.168.1.198,local_lock=none,addr=192.168.1.198 0 0

This is with kernel 3.8.0-28-generic on Ubuntu. When I try the same thing using 2.6.32 on CentOS, the sync option is applied in all cases.

How do I enable sync mode without noac mode in newer versions of the kernel and when mounting a subdirectory?

Best Answer

This commit will solve this issue.

commit e890db0104826742818cbfb8fdb3000a38a9b97c

NFSv4: Fix the sync mount option for nfs4 mounts

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 71fdc0d..f6db66d 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -2478,6 +2478,10 @@ struct dentry *nfs_fs_mount_common(struct nfs_server *server,
    if (server->flags & NFS_MOUNT_NOAC)
        sb_mntdata.mntflags |= MS_SYNCHRONOUS;

+   if (mount_info->cloned != NULL && mount_info->cloned->sb != NULL)
+       if (mount_info->cloned->sb->s_flags & MS_SYNCHRONOUS)
+           sb_mntdata.mntflags |= MS_SYNCHRONOUS;
+
    /* Get a superblock - note that we may end up sharing one that already exists */
    s = sget(nfs_mod->nfs_fs, compare_super, nfs_set_super, flags, &sb_mntdata);
    if (IS_ERR(s)) {