From owner-svn-src-all@FreeBSD.ORG Fri Jan 29 12:09:15 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 DD9C01065692; Fri, 29 Jan 2010 12:09:14 +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 CC5C58FC17; Fri, 29 Jan 2010 12:09:14 +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 o0TC9EWM056246; Fri, 29 Jan 2010 12:09:14 GMT (envelope-from jh@svn.freebsd.org) Received: (from jh@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o0TC9Ed1056243; Fri, 29 Jan 2010 12:09:14 GMT (envelope-from jh@svn.freebsd.org) Message-Id: <201001291209.o0TC9Ed1056243@svn.freebsd.org> From: Jaakko Heinonen Date: Fri, 29 Jan 2010 12:09:14 +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: r203164 - in head: share/man/man5 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: Fri, 29 Jan 2010 12:09:15 -0000 Author: jh Date: Fri Jan 29 12:09:14 2010 New Revision: 203164 URL: http://svn.freebsd.org/changeset/base/203164 Log: Add "maxfilesize" mount option for tmpfs to allow specifying the maximum file size limit. Default is UINT64_MAX when the option is not specified. It was useless to set the limit to the total amount of memory and swap in the system. Use tmpfs_mem_info() rather than get_swpgtotal() in tmpfs_mount() to check if there is enough memory available. Remove now unused get_swpgtotal(). Reviewed by: Gleb Kurtsou Approved by: trasz (mentor) Modified: head/share/man/man5/tmpfs.5 head/sys/fs/tmpfs/tmpfs_vfsops.c Modified: head/share/man/man5/tmpfs.5 ============================================================================== --- head/share/man/man5/tmpfs.5 Fri Jan 29 11:30:40 2010 (r203163) +++ head/share/man/man5/tmpfs.5 Fri Jan 29 12:09:14 2010 (r203164) @@ -70,6 +70,8 @@ permissions in octal format. maximum number of inodes. .It Cm size maximum size (in bytes) for the file system. +.It Cm maxfilesize +maximum file size (in bytes). .El .Sh EXAMPLES To mount a Modified: head/sys/fs/tmpfs/tmpfs_vfsops.c ============================================================================== --- head/sys/fs/tmpfs/tmpfs_vfsops.c Fri Jan 29 11:30:40 2010 (r203163) +++ head/sys/fs/tmpfs/tmpfs_vfsops.c Fri Jan 29 12:09:14 2010 (r203164) @@ -77,62 +77,12 @@ static int tmpfs_statfs(struct mount *, /* --------------------------------------------------------------------- */ static const char *tmpfs_opts[] = { - "from", "size", "inodes", "uid", "gid", "mode", "export", + "from", "size", "maxfilesize", "inodes", "uid", "gid", "mode", "export", NULL }; /* --------------------------------------------------------------------- */ -#define SWI_MAXMIB 3 - -static u_int -get_swpgtotal(void) -{ - struct xswdev xsd; - char *sname = "vm.swap_info"; - int soid[SWI_MAXMIB], oid[2]; - u_int unswdev, total, dmmax, nswapdev; - size_t mibi, len; - - total = 0; - - len = sizeof(dmmax); - if (kernel_sysctlbyname(curthread, "vm.dmmax", &dmmax, &len, - NULL, 0, NULL, 0) != 0) - return total; - - len = sizeof(nswapdev); - if (kernel_sysctlbyname(curthread, "vm.nswapdev", - &nswapdev, &len, - NULL, 0, NULL, 0) != 0) - return total; - - mibi = (SWI_MAXMIB - 1) * sizeof(int); - oid[0] = 0; - oid[1] = 3; - - if (kernel_sysctl(curthread, oid, 2, - soid, &mibi, (void *)sname, strlen(sname), - NULL, 0) != 0) - return total; - - mibi = (SWI_MAXMIB - 1); - for (unswdev = 0; unswdev < nswapdev; ++unswdev) { - soid[mibi] = unswdev; - len = sizeof(struct xswdev); - if (kernel_sysctl(curthread, - soid, mibi + 1, &xsd, &len, NULL, 0, - NULL, 0) != 0) - return total; - if (len == sizeof(struct xswdev)) - total += (xsd.xsw_nblks - dmmax); - } - - /* Not Reached */ - return total; -} - -/* --------------------------------------------------------------------- */ static int tmpfs_node_ctor(void *mem, int size, void *arg, int flags) { @@ -181,12 +131,12 @@ tmpfs_mount(struct mount *mp) { struct tmpfs_mount *tmp; struct tmpfs_node *root; - size_t pages, mem_size; + size_t pages; uint32_t nodes; int error; /* Size counters. */ u_int nodes_max; - u_quad_t size_max; + u_quad_t size_max, maxfilesize; /* Root node attributes. */ uid_t root_uid; @@ -227,12 +177,13 @@ tmpfs_mount(struct mount *mp) nodes_max = 0; if (vfs_scanopt(mp->mnt_optnew, "size", "%qu", &size_max) != 1) size_max = 0; + if (vfs_scanopt(mp->mnt_optnew, "maxfilesize", "%qu", + &maxfilesize) != 1) + maxfilesize = 0; /* Do not allow mounts if we do not have enough memory to preserve * the minimum reserved pages. */ - mem_size = cnt.v_free_count + cnt.v_inactive_count + get_swpgtotal(); - mem_size -= mem_size > cnt.v_wire_count ? cnt.v_wire_count : mem_size; - if (mem_size < TMPFS_PAGES_RESERVED) + if (tmpfs_mem_info() < TMPFS_PAGES_RESERVED) return ENOSPC; /* Get the maximum number of memory pages this file system is @@ -261,7 +212,7 @@ tmpfs_mount(struct mount *mp) mtx_init(&tmp->allnode_lock, "tmpfs allnode lock", NULL, MTX_DEF); tmp->tm_nodes_max = nodes; tmp->tm_nodes_inuse = 0; - tmp->tm_maxfilesize = (u_int64_t)(cnt.v_page_count + get_swpgtotal()) * PAGE_SIZE; + tmp->tm_maxfilesize = maxfilesize > 0 ? maxfilesize : UINT64_MAX; LIST_INIT(&tmp->tm_nodes_used); tmp->tm_pages_max = pages;