git: a265108447f9 - stable/13 - nfsd: Make Setxattr/Removexattr NFSv4.2 ops IO_SYNC

From: Rick Macklem <rmacklem_at_FreeBSD.org>
Date: Tue, 15 Nov 2022 21:36:49 UTC
The branch stable/13 has been updated by rmacklem:

URL: https://cgit.FreeBSD.org/src/commit/?id=a265108447f9db3e320c163c429c87b15ecbea0e

commit a265108447f9db3e320c163c429c87b15ecbea0e
Author:     Rick Macklem <rmacklem@FreeBSD.org>
AuthorDate: 2022-10-16 20:27:32 +0000
Commit:     Rick Macklem <rmacklem@FreeBSD.org>
CommitDate: 2022-11-15 21:35:00 +0000

    nfsd: Make Setxattr/Removexattr NFSv4.2 ops IO_SYNC
    
    When the NFS server does Setxattr or Removexattr, the
    operations must be done IO_SYNC. If a server
    crashes/reboots immediately after replying it must
    have the extended attribute changes.
    
    Since UFS does extended attributes asynchronously
    by default and there is no "ioflag" argument in
    the VOP calls, follow the VOP calls with VOP_FSYNC(),
    to ensure the operation has been done synchronously.
    
    This was found by inspection while investigating a
    bug discovered during a recent IETF NFSv4 testing
    event, where the Change attribute wasn't changed
    in the operation reply.
    
    This bug will take further work for ZFS and the
    pNFS server configuration, but is now fixed for
    a non-pNFS UFS exported file system.
    
    (cherry picked from commit 8063dc03202fad7d6bdf34976bc8556fa3f23fa1)
---
 sys/fs/nfsserver/nfs_nfsdport.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c
index d834c71041c8..258642bb1060 100644
--- a/sys/fs/nfsserver/nfs_nfsdport.c
+++ b/sys/fs/nfsserver/nfs_nfsdport.c
@@ -6568,6 +6568,8 @@ nfsvno_setxattr(struct vnode *vp, char *name, int len, struct mbuf *m,
 	if (error == 0) {
 		error = VOP_SETEXTATTR(vp, EXTATTR_NAMESPACE_USER, name, uiop,
 		    cred, p);
+		if (error == 0)
+			error = VOP_FSYNC(vp, MNT_WAIT, p);
 		free(iv, M_TEMP);
 	}
 
@@ -6603,6 +6605,8 @@ nfsvno_rmxattr(struct nfsrv_descript *nd, struct vnode *vp, char *name,
 	if (error == EOPNOTSUPP)
 		error = VOP_SETEXTATTR(vp, EXTATTR_NAMESPACE_USER, name, NULL,
 		    cred, p);
+	if (error == 0)
+		error = VOP_FSYNC(vp, MNT_WAIT, p);
 out:
 	NFSEXITCODE(error);
 	return (error);