svn commit: r367358 - head/sys/kern

Mateusz Guzik mjg at FreeBSD.org
Thu Nov 5 02:12:34 UTC 2020


Author: mjg
Date: Thu Nov  5 02:12:33 2020
New Revision: 367358
URL: https://svnweb.freebsd.org/changeset/base/367358

Log:
  fd: make all f_count uses go through refcount_*

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/uipc_usrreq.c

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Thu Nov  5 02:12:08 2020	(r367357)
+++ head/sys/kern/kern_descrip.c	Thu Nov  5 02:12:33 2020	(r367358)
@@ -2863,7 +2863,7 @@ fget_unlocked_seq(struct filedesc *fdp, int fd, cap_ri
 			 * This re-read is not any more racy than using the
 			 * return value from fcmpset.
 			 */
-			if (fp->f_count != 0)
+			if (refcount_load(&fp->f_count) != 0)
 				return (EBADF);
 			/*
 			 * Force a reload. Other thread could reallocate the
@@ -3833,7 +3833,7 @@ sysctl_kern_file(SYSCTL_HANDLER_ARGS)
 			xf.xf_data = (uintptr_t)fp->f_data;
 			xf.xf_vnode = (uintptr_t)fp->f_vnode;
 			xf.xf_type = (uintptr_t)fp->f_type;
-			xf.xf_count = fp->f_count;
+			xf.xf_count = refcount_load(&fp->f_count);
 			xf.xf_msgcount = 0;
 			xf.xf_offset = foffset_get(fp);
 			xf.xf_flag = fp->f_flag;
@@ -3916,7 +3916,7 @@ export_file_to_kinfo(struct file *fp, int fd, cap_righ
 	else
 		cap_rights_init_zero(&kif->kf_cap_rights);
 	kif->kf_fd = fd;
-	kif->kf_ref_count = fp->f_count;
+	kif->kf_ref_count = refcount_load(&fp->f_count);
 	kif->kf_offset = foffset_get(fp);
 
 	/*
@@ -4446,7 +4446,7 @@ db_print_file(struct file *fp, int header)
 	p = file_to_first_proc(fp);
 	db_printf("%*p %6s %*p %08x %04x %5d %6d %*p %5d %s\n", XPTRWIDTH,
 	    fp, file_type_to_name(fp->f_type), XPTRWIDTH, fp->f_data,
-	    fp->f_flag, 0, fp->f_count, 0, XPTRWIDTH, fp->f_vnode,
+	    fp->f_flag, 0, refcount_load(&fp->f_count), 0, XPTRWIDTH, fp->f_vnode,
 	    p != NULL ? p->p_pid : -1, p != NULL ? p->p_comm : "-");
 
 #undef XPTRWIDTH

Modified: head/sys/kern/uipc_usrreq.c
==============================================================================
--- head/sys/kern/uipc_usrreq.c	Thu Nov  5 02:12:08 2020	(r367357)
+++ head/sys/kern/uipc_usrreq.c	Thu Nov  5 02:12:33 2020	(r367358)
@@ -2651,7 +2651,7 @@ unp_gc(__unused void *arg, int pending)
 			 * NULL.
 			 */
 			if (f != NULL && unp->unp_msgcount != 0 &&
-			    f->f_count == unp->unp_msgcount) {
+			    refcount_load(&f->f_count) == unp->unp_msgcount) {
 				LIST_INSERT_HEAD(&unp_deadhead, unp, unp_dead);
 				unp->unp_gcflag |= UNPGC_DEAD;
 				unp->unp_gcrefs = unp->unp_msgcount;
@@ -2714,7 +2714,7 @@ unp_gc(__unused void *arg, int pending)
 		unp->unp_gcflag &= ~UNPGC_DEAD;
 		f = unp->unp_file;
 		if (unp->unp_msgcount == 0 || f == NULL ||
-		    f->f_count != unp->unp_msgcount ||
+		    refcount_load(&f->f_count) != unp->unp_msgcount ||
 		    !fhold(f))
 			continue;
 		unref[total++] = f;


More information about the svn-src-all mailing list