/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright (c) 2011, Joyent, Inc. All rights reserved.
*/
#include <sys/sysmacros.h>
#include <sys/pathname.h>
#include <sys/vfs_opreg.h>
static int tmpfsfstype;
/*
* tmpfs vfs operations.
*/
static int tmpfsinit(int, char *);
/*
* Loadable module wrapper
*/
"tmpfs",
};
/*
* in-kernel mnttab options
*/
/* Option name Cancel Opt Arg Flags Data */
};
sizeof (tmpfs_options) / sizeof (mntopt_t),
};
/*
* Module linkage information
*/
};
};
int
_init()
{
return (mod_install(&modlinkage));
}
int
_fini()
{
int error;
if (error)
return (error);
/*
* Tear down the operations vectors
*/
(void) vfs_freevfsops_by_type(tmpfsfstype);
return (0);
}
int
{
}
/*
* The following are patchable variables limiting the amount of system
* resources tmpfs can use.
*
* tmpfs_maxkmem limits the amount of kernel kmem_alloc memory
* tmpfs can use for it's data structures (e.g. tmpnodes, directory entries)
* It is not determined by setting a hard limit but rather as a percentage of
* physical memory which is determined when tmpfs is first used in the system.
*
* tmpfs_minfree is the minimum amount of swap space that tmpfs leaves for
* the rest of the system. In other words, if the amount of free swap space
* in the system (i.e. anoninfo.ani_free) drops below tmpfs_minfree, tmpfs
* anon allocations will fail.
*
* There is also a per mount limit on the amount of swap space
* (tmount.tm_anonmax) settable via a mount option.
*/
/*
* initialize global tmpfs locks and such
* called when loading tmpfs module
*/
static int
{
};
int error;
extern void tmpfs_hash_init();
ASSERT(tmpfsfstype != 0);
if (error != 0) {
return (error);
}
if (error != 0) {
(void) vfs_freevfsops_by_type(fstype);
return (error);
}
/*
* tmpfs_minfree doesn't need to be some function of configured
* swap space since it really is an absolute limit of swap space
* which still allows other processes to execute.
*/
if (tmpfs_minfree == 0) {
/*
* Set if not patched
*/
}
/*
* The maximum amount of space tmpfs can allocate is
* TMPMAXPROCKMEM percent of kernel memory
*/
if (tmpfs_maxkmem == 0)
tmpfs_major = 0;
}
return (0);
}
static int
{
int error;
int got_attrs;
char *sizestr;
return (error);
return (ENOTDIR);
return (EBUSY);
}
/*
* Having the resource be anything but "swap" doesn't make sense.
*/
/*
* now look for options we understand...
*/
/* tmpfs doesn't support read-only mounts */
goto out;
}
/*
* tm_anonmax is set according to the mount arguments
* if any. Otherwise, it is set to a maximum value.
*/
goto out;
} else {
}
goto out;
/*
* If we change the size so its less than what is currently
* being used, we allow that. The file system will simply be
* full until enough files have been removed to get below the
* new max.
*/
goto out;
}
goto out;
}
/*
* find an available minor device number for this mount
*/
do {
/*
* Set but don't bother entering the mutex
* (tmount not on mount list yet)
*/
/*
* allocate and initialize root tmpnode structure
*/
/*
* Get the mode, uid, and gid from the underlying mount point.
*/
/*
* If the getattr succeeded, use its results. Otherwise allow
* the previously set hardwired defaults to prevail.
*/
if (got_attrs == 0) {
}
/*
* initialize linked list of tmpnodes so that the back pointer of
* the root tmpnode always points to the last one on the list
* and the forward pointer of the last node is null
*/
error = 0;
out:
if (error == 0)
return (error);
}
static int
{
int error;
return (error);
/*
* forced unmount is not supported by this file system
* and thus, ENOTSUP, is being returned.
*/
return (ENOTSUP);
/*
* If there are no open files, only the root node should have
* a reference count.
* With tm_contents held, nothing can be added or removed.
* There may be some dirty pages. To prevent fsflush from
* disrupting the unmount, put a hold on each node while scanning.
* If we find a previously referenced node, undo the holds we have
* placed and fail EBUSY.
*/
return (EBUSY);
}
}
return (EBUSY);
}
}
/*
* We can drop the mutex now because no one can find this mount
*/
/*
* Free all kmemalloc'd and anonalloc'd memory associated with
* this filesystem. To do this, we go through the file list twice,
* once to remove all the directory entries, and then to remove
* all the files. We do this because there is useful code in
* tmpnode_free which assumes that the directory entry has been
* removed before the file.
*/
/*
* Remove all directory entries
*/
/*
* Account for implicit attrdir reference.
*/
}
}
/*
* All links are gone, v_count is keeping nodes in place.
* VN_RELE should make the node disappear, unless somebody
* is holding pages against it. Nap and retry until it disappears.
*
* We re-acquire the lock to prevent others who have a HOLD on
* a tmpnode via its pages or anon slots from blowing it away
* (in tmp_inactive) while we're trying to get to it here. Once
* we have a HOLD on it we know it'll stick around.
*
*/
/*
* Remove all the files (except the rootnode) backwards.
*/
/*
* Inhibit tmp_inactive from touching attribute directory
* as all nodes will be released here.
* Note we handled the link count in pass 2 above.
*/
/*
* It's still there after the RELE. Someone else like pageout
* has a hold on it so wait a bit and then try again - we know
* they'll give it up soon.
*/
}
}
return (0);
}
/*
* return root tmpnode for given vnode
*/
static int
{
return (0);
}
static int
{
/*
* The file system may have been mounted by the global zone on
* behalf of the non-global zone. In that case, the tmount zone_id
* will be the global zone. We still want to show the swap cap inside
* the zone in this case, even though the file system was mounted by
* the global zone.
*/
else
else
/*
* Find the amount of available physical and memory swap
*/
/*
* If tm_anonmax for this mount is less than the available swap space
* (minus the amount tmpfs can't use), use that instead
*/
if (blocks > tmpfs_minfree)
else
/*
* Total number of blocks is what's available plus what's been used
*/
if (eff_zid != GLOBAL_ZONEUNIQID &&
/*
* If the fs is used by a non-global zone with a swap cap,
* then report the capped size.
*/
}
/*
* The maximum number of files available is approximately the number
* of tmpnodes we can allocate from the remaining kernel memory
* available to tmpfs. This is fairly inaccurate since it doesn't
* take into account the names stored in the directory entries.
*/
if (tmpfs_maxkmem > tmp_kmemspace)
else
/*
* ensure null termination
*/
return (0);
}
static int
{
/*
* If the gen numbers don't match we know the
* file won't be found since only one tmpnode
* can have this number at a time.
*/
return (0);
}
}
return (0);
}
}
return (0);
}