From owner-svn-src-stable-9@FreeBSD.ORG Wed Oct 16 06:07:04 2013 Return-Path: Delivered-To: svn-src-stable-9@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 618B1F94; Wed, 16 Oct 2013 06:07:04 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 34C332328; Wed, 16 Oct 2013 06:07:04 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9G674O0099250; Wed, 16 Oct 2013 06:07:04 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9G673Lm099248; Wed, 16 Oct 2013 06:07:03 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201310160607.r9G673Lm099248@svn.freebsd.org> From: Konstantin Belousov Date: Wed, 16 Oct 2013 06:07:03 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r256589 - stable/9/sys/kern X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-9@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for only the 9-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 06:07:04 -0000 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);