summaryrefslogtreecommitdiffstats
path: root/sys/fs/tmpfs/tmpfs_vfsops.c
diff options
context:
space:
mode:
authorjh <jh@FreeBSD.org>2010-01-29 12:09:14 +0000
committerjh <jh@FreeBSD.org>2010-01-29 12:09:14 +0000
commitcf482307807918efe12edbfee94740f0069fc33b (patch)
treed8a53985962bf414ab0d94bf298c03d965014b62 /sys/fs/tmpfs/tmpfs_vfsops.c
parentf403000d3914d84750322e39d1292d2420d88026 (diff)
downloadFreeBSD-src-cf482307807918efe12edbfee94740f0069fc33b.zip
FreeBSD-src-cf482307807918efe12edbfee94740f0069fc33b.tar.gz
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)
Diffstat (limited to 'sys/fs/tmpfs/tmpfs_vfsops.c')
-rw-r--r--sys/fs/tmpfs/tmpfs_vfsops.c65
1 files changed, 8 insertions, 57 deletions
diff --git a/sys/fs/tmpfs/tmpfs_vfsops.c b/sys/fs/tmpfs/tmpfs_vfsops.c
index 7d60849..356be5e 100644
--- a/sys/fs/tmpfs/tmpfs_vfsops.c
+++ b/sys/fs/tmpfs/tmpfs_vfsops.c
@@ -77,62 +77,12 @@ static int tmpfs_statfs(struct mount *, struct statfs *);
/* --------------------------------------------------------------------- */
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;
OpenPOWER on IntegriCloud