svn commit: r361441 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Mon May 25 04:57:58 UTC 2020


Author: mjg
Date: Mon May 25 04:57:57 2020
New Revision: 361441
URL: https://svnweb.freebsd.org/changeset/base/361441

Log:
  vfs: use atomic_{store,load}_long to manage f_offset
  
  ... instead of depending on the compiler not to mess them up

Modified:
  head/sys/kern/vfs_vnops.c

Modified: head/sys/kern/vfs_vnops.c
==============================================================================
--- head/sys/kern/vfs_vnops.c	Mon May 25 04:56:41 2020	(r361440)
+++ head/sys/kern/vfs_vnops.c	Mon May 25 04:57:57 2020	(r361441)
@@ -682,12 +682,8 @@ foffset_lock(struct file *fp, int flags)
 
 	KASSERT((flags & FOF_OFFSET) == 0, ("FOF_OFFSET passed"));
 
-	/*
-	 * Caller only wants the current f_offset value.  Assume that
-	 * the long and shorter integer types reads are atomic.
-	 */
 	if ((flags & FOF_NOLOCK) != 0)
-		return (fp->f_offset);
+		return (atomic_load_long(&fp->f_offset));
 
 	/*
 	 * According to McKusick the vn lock was protecting f_offset here.
@@ -695,7 +691,7 @@ foffset_lock(struct file *fp, int flags)
 	 */
 	flagsp = &fp->f_vnread_flags;
 	if (atomic_cmpset_acq_16(flagsp, 0, FOFFSET_LOCKED))
-		return (fp->f_offset);
+		return (atomic_load_long(&fp->f_offset));
 
 	sleepq_lock(&fp->f_vnread_flags);
 	state = atomic_load_16(flagsp);
@@ -718,7 +714,7 @@ foffset_lock(struct file *fp, int flags)
 		sleepq_lock(&fp->f_vnread_flags);
 		state = atomic_load_16(flagsp);
 	}
-	res = fp->f_offset;
+	res = atomic_load_long(&fp->f_offset);
 	sleepq_release(&fp->f_vnread_flags);
 	return (res);
 }
@@ -732,7 +728,7 @@ foffset_unlock(struct file *fp, off_t val, int flags)
 	KASSERT((flags & FOF_OFFSET) == 0, ("FOF_OFFSET passed"));
 
 	if ((flags & FOF_NOUPDATE) == 0)
-		fp->f_offset = val;
+		atomic_store_long(&fp->f_offset, val);
 	if ((flags & FOF_NEXTOFF) != 0)
 		fp->f_nextoff = val;
 


More information about the svn-src-head mailing list