svn commit: r256589 - stable/9/sys/kern

Konstantin Belousov kib at FreeBSD.org
Wed Oct 16 06:07:04 UTC 2013


Author: kib
Date: Wed Oct 16 06:07:03 2013
New Revision: 256589
URL: http://svnweb.freebsd.org/changeset/base/256589

Log:
  MFC r256209:
  Reduce code duplication, introduce the getmaxfd() helper to calculate
  the max filedescriptor index.

Modified:
  stable/9/sys/kern/kern_descrip.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/kern/kern_descrip.c
==============================================================================
--- stable/9/sys/kern/kern_descrip.c	Wed Oct 16 05:43:03 2013	(r256588)
+++ stable/9/sys/kern/kern_descrip.c	Wed Oct 16 06:07:03 2013	(r256589)
@@ -133,6 +133,7 @@ static int	fill_procdesc_info(struct pro
     struct kinfo_file *kif);
 static int	fill_sem_info(struct file *fp, struct kinfo_file *kif);
 static int	fill_shm_info(struct file *fp, struct kinfo_file *kif);
+static int	getmaxfd(struct proc *p);
 
 /*
  * A process is initially started out with NDFILE descriptors stored within
@@ -808,6 +809,18 @@ readahead_vnlock_fail:
 	return (error);
 }
 
+static int
+getmaxfd(struct proc *p)
+{
+	int maxfd;
+
+	PROC_LOCK(p);
+	maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
+	PROC_UNLOCK(p);
+
+	return (maxfd);
+}
+
 /*
  * Common code for dup, dup2, fcntl(F_DUPFD) and fcntl(F_DUP2FD).
  */
@@ -833,9 +846,7 @@ do_dup(struct thread *td, int flags, int
 		return (EBADF);
 	if (new < 0)
 		return (flags & DUP_FCNTL ? EINVAL : EBADF);
-	PROC_LOCK(p);
-	maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
-	PROC_UNLOCK(p);
+	maxfd = getmaxfd(p);
 	if (new >= maxfd)
 		return (flags & DUP_FCNTL ? EINVAL : EBADF);
 
@@ -1547,9 +1558,7 @@ fdalloc(struct thread *td, int minfd, in
 	if (fdp->fd_freefile > minfd)
 		minfd = fdp->fd_freefile;
 
-	PROC_LOCK(p);
-	maxfd = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
-	PROC_UNLOCK(p);
+	maxfd = getmaxfd(p);
 
 	/*
 	 * Search the bitmap for a free descriptor.  If none is found, try
@@ -1634,9 +1643,7 @@ fdavail(struct thread *td, int n)
 	 *      call racct_add() from there instead of dealing with containers
 	 *      here.
 	 */
-	PROC_LOCK(p);
-	lim = min((int)lim_cur(p, RLIMIT_NOFILE), maxfilesperproc);
-	PROC_UNLOCK(p);
+	lim = getmaxfd(p);
 	if ((i = lim - fdp->fd_nfiles) > 0 && (n -= i) <= 0)
 		return (1);
 	last = min(fdp->fd_nfiles, lim);


More information about the svn-src-stable-9 mailing list