From owner-svn-src-all@FreeBSD.ORG Wed Jan 20 16:56:21 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 37C611065695; Wed, 20 Jan 2010 16:56:21 +0000 (UTC) (envelope-from jh@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0D7D08FC1F; Wed, 20 Jan 2010 16:56:21 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o0KGuKDi061600; Wed, 20 Jan 2010 16:56:20 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0KGuKKG061597; Wed, 20 Jan 2010 16:56:20 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201001201656.o0KGuKKG061597@svn.freebsd.org> From: Jaakko Heinonen Date: Wed, 20 Jan 2010 16:56:20 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r202708 - head/sys/fs/tmpfs X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jan 2010 16:56:21 -0000 Author: jh Date: Wed Jan 20 16:56:20 2010 New Revision: 202708 URL: http://svn.freebsd.org/changeset/base/202708 Log: - Change the type of nodes_max to u_int and use "%u" format string to convert its value. [1] - Set default tm_nodes_max to min(pages + 3, UINT32_MAX). It's more reasonable than the old four nodes per page (with page size 4096) because non-empty regular files always use at least one page. This fixes possible overflow in the calculation. [2] - Don't allow more than tm_nodes_max nodes allocated in tmpfs_alloc_node(). PR: kern/138367 Suggested by: bde [1], Gleb Kurtsou [2] Approved by: trasz (mentor) Modified: head/sys/fs/tmpfs/tmpfs_subr.c head/sys/fs/tmpfs/tmpfs_vfsops.c Modified: head/sys/fs/tmpfs/tmpfs_subr.c ============================================================================== --- head/sys/fs/tmpfs/tmpfs_subr.c Wed Jan 20 16:50:13 2010 (r202707) +++ head/sys/fs/tmpfs/tmpfs_subr.c Wed Jan 20 16:56:20 2010 (r202708) @@ -93,7 +93,7 @@ tmpfs_alloc_node(struct tmpfs_mount *tmp MPASS(IFF(type == VLNK, target != NULL)); MPASS(IFF(type == VBLK || type == VCHR, rdev != VNOVAL)); - if (tmp->tm_nodes_inuse > tmp->tm_nodes_max) + if (tmp->tm_nodes_inuse >= tmp->tm_nodes_max) return (ENOSPC); nnode = (struct tmpfs_node *)uma_zalloc_arg( Modified: head/sys/fs/tmpfs/tmpfs_vfsops.c ============================================================================== --- head/sys/fs/tmpfs/tmpfs_vfsops.c Wed Jan 20 16:50:13 2010 (r202707) +++ head/sys/fs/tmpfs/tmpfs_vfsops.c Wed Jan 20 16:56:20 2010 (r202708) @@ -182,10 +182,10 @@ tmpfs_mount(struct mount *mp) struct tmpfs_mount *tmp; struct tmpfs_node *root; size_t pages, mem_size; - ino_t nodes; + uint32_t nodes; int error; /* Size counters. */ - ino_t nodes_max; + u_int nodes_max; u_quad_t size_max; /* Root node attributes. */ @@ -223,7 +223,7 @@ tmpfs_mount(struct mount *mp) if (mp->mnt_cred->cr_ruid != 0 || vfs_scanopt(mp->mnt_optnew, "mode", "%ho", &root_mode) != 1) root_mode = va.va_mode; - if (vfs_scanopt(mp->mnt_optnew, "inodes", "%d", &nodes_max) != 1) + if (vfs_scanopt(mp->mnt_optnew, "inodes", "%u", &nodes_max) != 1) nodes_max = 0; if (vfs_scanopt(mp->mnt_optnew, "size", "%qu", &size_max) != 1) size_max = 0; @@ -245,9 +245,12 @@ tmpfs_mount(struct mount *mp) pages = howmany(size_max, PAGE_SIZE); MPASS(pages > 0); - if (nodes_max <= 3) - nodes = 3 + pages * PAGE_SIZE / 1024; - else + if (nodes_max <= 3) { + if (pages > UINT32_MAX - 3) + nodes = UINT32_MAX; + else + nodes = pages + 3; + } else nodes = nodes_max; MPASS(nodes >= 3);