2020-04-04 23:49:30 +03:00
|
|
|
/* $NetBSD: tmpfs_vfsops.c,v 1.77 2020/04/04 20:49:30 ad Exp $ */
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/*
|
2008-01-02 14:48:20 +03:00
|
|
|
* Copyright (c) 2005, 2006, 2007 The NetBSD Foundation, Inc.
|
2005-09-10 23:20:48 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2005-09-23 19:36:15 +04:00
|
|
|
* by Julio M. Merino Vidal, developed as part of Google's Summer of Code
|
|
|
|
* 2005 program.
|
2005-09-10 23:20:48 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2005-09-11 02:28:57 +04:00
|
|
|
* Efficient memory file system.
|
2005-09-23 19:36:15 +04:00
|
|
|
*
|
|
|
|
* tmpfs is a file system that uses NetBSD's virtual memory sub-system
|
|
|
|
* (the well-known UVM) to store file data and metadata in an efficient
|
|
|
|
* way. This means that it does not follow the structure of an on-disk
|
|
|
|
* file system because it simply does not need to. Instead, it uses
|
|
|
|
* memory-specific data structures and algorithms to automatically
|
|
|
|
* allocate and release resources.
|
2005-09-10 23:20:48 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2020-04-04 23:49:30 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: tmpfs_vfsops.c,v 1.77 2020/04/04 20:49:30 ad Exp $");
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2015-07-06 13:07:12 +03:00
|
|
|
#include <sys/atomic.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
#include <sys/types.h>
|
2008-01-02 14:48:20 +03:00
|
|
|
#include <sys/kmem.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
#include <sys/mount.h>
|
2005-09-25 20:34:42 +04:00
|
|
|
#include <sys/stat.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/vnode.h>
|
2015-07-06 13:07:12 +03:00
|
|
|
#include <sys/kauth.h>
|
2008-05-10 06:26:09 +04:00
|
|
|
#include <sys/module.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-01-28 17:31:15 +03:00
|
|
|
#include <miscfs/genfs/genfs.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
#include <fs/tmpfs/tmpfs.h>
|
2008-07-29 13:10:09 +04:00
|
|
|
#include <fs/tmpfs/tmpfs_args.h>
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2008-05-10 06:26:09 +04:00
|
|
|
MODULE(MODULE_CLASS_VFS, tmpfs, NULL);
|
|
|
|
|
2011-05-19 07:21:23 +04:00
|
|
|
struct pool tmpfs_dirent_pool;
|
|
|
|
struct pool tmpfs_node_pool;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
void
|
2011-05-19 07:21:23 +04:00
|
|
|
tmpfs_init(void)
|
|
|
|
{
|
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
pool_init(&tmpfs_dirent_pool, sizeof(tmpfs_dirent_t), 0, 0, 0,
|
2011-05-19 07:21:23 +04:00
|
|
|
"tmpfs_dirent", &pool_allocator_nointr, IPL_NONE);
|
2011-05-25 00:17:49 +04:00
|
|
|
pool_init(&tmpfs_node_pool, sizeof(tmpfs_node_t), 0, 0, 0,
|
2011-05-19 07:21:23 +04:00
|
|
|
"tmpfs_node", &pool_allocator_nointr, IPL_NONE);
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
void
|
2011-05-19 07:21:23 +04:00
|
|
|
tmpfs_done(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
pool_destroy(&tmpfs_dirent_pool);
|
|
|
|
pool_destroy(&tmpfs_node_pool);
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
tmpfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2007-07-12 23:35:32 +04:00
|
|
|
struct tmpfs_args *args = data;
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_mount_t *tmp;
|
|
|
|
tmpfs_node_t *root;
|
2015-07-06 13:07:12 +03:00
|
|
|
struct vattr va;
|
|
|
|
struct vnode *vp;
|
2010-06-22 22:32:07 +04:00
|
|
|
uint64_t memlimit;
|
|
|
|
ino_t nodes;
|
2017-01-27 13:47:54 +03:00
|
|
|
int error, flags;
|
2016-03-12 11:45:23 +03:00
|
|
|
bool set_memlimit;
|
|
|
|
bool set_nodes;
|
2007-07-12 23:35:32 +04:00
|
|
|
|
2014-04-16 22:55:17 +04:00
|
|
|
if (args == NULL)
|
|
|
|
return EINVAL;
|
|
|
|
|
2011-05-24 05:09:47 +04:00
|
|
|
/* Validate the version. */
|
|
|
|
if (*data_len < sizeof(*args) ||
|
|
|
|
args->ta_version != TMPFS_ARGS_VERSION)
|
2007-07-12 23:35:32 +04:00
|
|
|
return EINVAL;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Handle retrieval of mount point arguments. */
|
|
|
|
if (mp->mnt_flag & MNT_GETARGS) {
|
|
|
|
if (mp->mnt_data == NULL)
|
|
|
|
return EIO;
|
|
|
|
tmp = VFS_TO_TMPFS(mp);
|
|
|
|
|
2007-07-12 23:35:32 +04:00
|
|
|
args->ta_version = TMPFS_ARGS_VERSION;
|
|
|
|
args->ta_nodes_max = tmp->tm_nodes_max;
|
2010-06-22 22:32:07 +04:00
|
|
|
args->ta_size_max = tmp->tm_mem_limit;
|
2007-11-06 22:50:55 +03:00
|
|
|
|
2007-11-10 06:36:16 +03:00
|
|
|
root = tmp->tm_root;
|
2007-07-12 23:35:32 +04:00
|
|
|
args->ta_root_uid = root->tn_uid;
|
|
|
|
args->ta_root_gid = root->tn_gid;
|
|
|
|
args->ta_root_mode = root->tn_mode;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2010-06-22 22:32:07 +04:00
|
|
|
*data_len = sizeof(*args);
|
2007-07-12 23:35:32 +04:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-24 05:09:47 +04:00
|
|
|
/* Prohibit mounts if there is not enough memory. */
|
2014-06-07 13:54:34 +04:00
|
|
|
if (tmpfs_mem_info(true) < uvmexp.freetarg)
|
2005-09-10 23:20:48 +04:00
|
|
|
return EINVAL;
|
|
|
|
|
2014-06-10 20:10:59 +04:00
|
|
|
/* Check for invalid uid and gid arguments */
|
|
|
|
if (args->ta_root_uid == VNOVAL || args->ta_root_gid == VNOVAL)
|
|
|
|
return EINVAL;
|
|
|
|
|
2010-06-22 22:32:07 +04:00
|
|
|
/* Get the memory usage limit for this file-system. */
|
|
|
|
if (args->ta_size_max < PAGE_SIZE) {
|
|
|
|
memlimit = UINT64_MAX;
|
2016-03-12 11:45:23 +03:00
|
|
|
set_memlimit = false;
|
2010-06-22 22:32:07 +04:00
|
|
|
} else {
|
|
|
|
memlimit = args->ta_size_max;
|
2016-03-12 11:45:23 +03:00
|
|
|
set_memlimit = true;
|
2010-06-22 22:32:07 +04:00
|
|
|
}
|
|
|
|
KASSERT(memlimit > 0);
|
|
|
|
|
|
|
|
if (args->ta_nodes_max <= 3) {
|
|
|
|
nodes = 3 + (memlimit / 1024);
|
2016-03-12 11:45:23 +03:00
|
|
|
set_nodes = false;
|
2010-06-22 22:32:07 +04:00
|
|
|
} else {
|
2007-07-12 23:35:32 +04:00
|
|
|
nodes = args->ta_nodes_max;
|
2016-03-12 11:45:23 +03:00
|
|
|
set_nodes = true;
|
2010-06-22 22:32:07 +04:00
|
|
|
}
|
|
|
|
nodes = MIN(nodes, INT_MAX);
|
2005-09-25 20:28:43 +04:00
|
|
|
KASSERT(nodes >= 3);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2014-04-30 05:33:51 +04:00
|
|
|
if (mp->mnt_flag & MNT_UPDATE) {
|
|
|
|
tmp = VFS_TO_TMPFS(mp);
|
2016-03-12 11:45:23 +03:00
|
|
|
if (set_nodes && nodes < tmp->tm_nodes_cnt)
|
2014-04-30 05:33:51 +04:00
|
|
|
return EBUSY;
|
2017-03-01 13:44:47 +03:00
|
|
|
if ((mp->mnt_iflag & IMNT_WANTRDONLY)) {
|
2017-01-27 13:47:54 +03:00
|
|
|
/* Changing from read/write to read-only. */
|
|
|
|
flags = WRITECLOSE;
|
|
|
|
if ((mp->mnt_flag & MNT_FORCE))
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
error = vflush(mp, NULL, flags);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
}
|
2016-03-12 11:45:23 +03:00
|
|
|
if (set_memlimit) {
|
|
|
|
if ((error = tmpfs_mntmem_set(tmp, memlimit)) != 0)
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
if (set_nodes)
|
|
|
|
tmp->tm_nodes_max = nodes;
|
2014-04-30 05:59:30 +04:00
|
|
|
root = tmp->tm_root;
|
2014-04-30 05:33:51 +04:00
|
|
|
root->tn_uid = args->ta_root_uid;
|
|
|
|
root->tn_gid = args->ta_root_gid;
|
|
|
|
root->tn_mode = args->ta_root_mode;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-09 11:43:56 +03:00
|
|
|
mp->mnt_flag |= MNT_LOCAL;
|
|
|
|
mp->mnt_stat.f_namemax = TMPFS_MAXNAMLEN;
|
|
|
|
mp->mnt_fs_bshift = PAGE_SHIFT;
|
|
|
|
mp->mnt_dev_bshift = DEV_BSHIFT;
|
2020-04-04 23:49:30 +03:00
|
|
|
mp->mnt_iflag |= IMNT_MPSAFE | IMNT_CAN_RWTORO | IMNT_SHRLOOKUP |
|
|
|
|
IMNT_NCLOOKUP;
|
2018-08-09 11:43:56 +03:00
|
|
|
vfs_getnewfsid(mp);
|
|
|
|
|
2005-09-10 23:20:48 +04:00
|
|
|
/* Allocate the tmpfs mount structure and fill it. */
|
2011-05-25 00:17:49 +04:00
|
|
|
tmp = kmem_zalloc(sizeof(tmpfs_mount_t), KM_SLEEP);
|
2005-09-10 23:20:48 +04:00
|
|
|
tmp->tm_nodes_max = nodes;
|
2008-01-02 14:48:20 +03:00
|
|
|
tmp->tm_nodes_cnt = 0;
|
|
|
|
LIST_INIT(&tmp->tm_nodes);
|
|
|
|
|
|
|
|
mutex_init(&tmp->tm_lock, MUTEX_DEFAULT, IPL_NONE);
|
2010-06-22 22:32:07 +04:00
|
|
|
tmpfs_mntmem_init(tmp, memlimit);
|
2015-07-06 13:07:12 +03:00
|
|
|
mp->mnt_data = tmp;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Allocate the root node. */
|
2015-07-06 13:07:12 +03:00
|
|
|
vattr_null(&va);
|
|
|
|
va.va_type = VDIR;
|
|
|
|
va.va_mode = args->ta_root_mode & ALLPERMS;
|
|
|
|
va.va_uid = args->ta_root_uid;
|
|
|
|
va.va_gid = args->ta_root_gid;
|
2019-01-01 13:06:54 +03:00
|
|
|
error = vcache_new(mp, NULL, &va, NOCRED, NULL, &vp);
|
2016-08-27 00:44:24 +03:00
|
|
|
if (error) {
|
|
|
|
mp->mnt_data = NULL;
|
|
|
|
tmpfs_mntmem_destroy(tmp);
|
|
|
|
mutex_destroy(&tmp->tm_lock);
|
|
|
|
kmem_free(tmp, sizeof(*tmp));
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
KASSERT(vp != NULL);
|
2015-07-06 13:07:12 +03:00
|
|
|
root = VP_TO_TMPFS_NODE(vp);
|
2016-08-27 00:44:24 +03:00
|
|
|
KASSERT(root != NULL);
|
2011-05-30 02:29:06 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Parent of the root inode is itself. Also, root inode has no
|
|
|
|
* directory entry (i.e. is never attached), thus hold an extra
|
|
|
|
* reference (link) for it.
|
|
|
|
*/
|
2008-01-02 14:48:20 +03:00
|
|
|
root->tn_links++;
|
2011-05-30 02:29:06 +04:00
|
|
|
root->tn_spec.tn_dir.tn_parent = root;
|
2005-09-10 23:20:48 +04:00
|
|
|
tmp->tm_root = root;
|
2015-07-06 13:07:12 +03:00
|
|
|
vrele(vp);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-19 07:21:23 +04:00
|
|
|
error = set_statvfs_info(path, UIO_USERSPACE, "tmpfs", UIO_SYSSPACE,
|
2010-06-22 22:32:07 +04:00
|
|
|
mp->mnt_op->vfs_name, mp, curlwp);
|
2011-05-19 07:21:23 +04:00
|
|
|
if (error) {
|
|
|
|
(void)tmpfs_unmount(mp, MNT_FORCE);
|
|
|
|
}
|
|
|
|
return error;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
tmpfs_start(struct mount *mp, int flags)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
tmpfs_unmount(struct mount *mp, int mntflags)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2013-11-08 19:44:23 +04:00
|
|
|
tmpfs_mount_t *tmp = VFS_TO_TMPFS(mp);
|
|
|
|
tmpfs_node_t *node, *cnode;
|
2011-05-19 07:21:23 +04:00
|
|
|
int error, flags = 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Handle forced unmounts. */
|
|
|
|
if (mntflags & MNT_FORCE)
|
|
|
|
flags |= FORCECLOSE;
|
|
|
|
|
|
|
|
/* Finalize all pending I/O. */
|
|
|
|
error = vflush(mp, NULL, flags);
|
|
|
|
if (error != 0)
|
|
|
|
return error;
|
|
|
|
|
2013-11-08 19:44:23 +04:00
|
|
|
/*
|
|
|
|
* First round, detach and destroy all directory entries.
|
|
|
|
* Also, clear the pointers to the vnodes - they are gone.
|
|
|
|
*/
|
|
|
|
LIST_FOREACH(node, &tmp->tm_nodes, tn_entries) {
|
|
|
|
tmpfs_dirent_t *de;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2013-11-08 19:44:23 +04:00
|
|
|
node->tn_vnode = NULL;
|
|
|
|
if (node->tn_type != VDIR) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
while ((de = TAILQ_FIRST(&node->tn_spec.tn_dir.tn_dir)) != NULL) {
|
2013-11-10 16:46:19 +04:00
|
|
|
cnode = de->td_node;
|
|
|
|
if (cnode && cnode != TMPFS_NODE_WHITEOUT) {
|
2013-11-08 19:44:23 +04:00
|
|
|
cnode->tn_vnode = NULL;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2013-11-08 19:44:23 +04:00
|
|
|
tmpfs_dir_detach(node, de);
|
|
|
|
tmpfs_free_dirent(tmp, de);
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
2013-11-23 20:35:32 +04:00
|
|
|
/* Extra virtual entry (itself for the root). */
|
|
|
|
node->tn_links--;
|
2013-11-08 19:44:23 +04:00
|
|
|
}
|
|
|
|
|
2013-11-23 20:35:32 +04:00
|
|
|
/* Release the reference on root (diagnostic). */
|
|
|
|
node = tmp->tm_root;
|
|
|
|
node->tn_links--;
|
|
|
|
|
2013-11-08 19:44:23 +04:00
|
|
|
/* Second round, destroy all inodes. */
|
|
|
|
while ((node = LIST_FIRST(&tmp->tm_nodes)) != NULL) {
|
2005-09-10 23:20:48 +04:00
|
|
|
tmpfs_free_node(tmp, node);
|
2007-11-10 06:36:16 +03:00
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
/* Throw away the tmpfs_mount structure. */
|
2010-06-22 22:32:07 +04:00
|
|
|
tmpfs_mntmem_destroy(tmp);
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_destroy(&tmp->tm_lock);
|
|
|
|
kmem_free(tmp, sizeof(*tmp));
|
2005-09-10 23:20:48 +04:00
|
|
|
mp->mnt_data = NULL;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2020-01-17 23:08:06 +03:00
|
|
|
tmpfs_root(struct mount *mp, int lktype, vnode_t **vpp)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_node_t *node = VFS_TO_TMPFS(mp)->tm_root;
|
2015-07-06 13:07:12 +03:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = vcache_get(mp, &node, sizeof(node), vpp);
|
|
|
|
if (error)
|
|
|
|
return error;
|
2020-01-17 23:08:06 +03:00
|
|
|
error = vn_lock(*vpp, lktype);
|
2015-07-06 13:07:12 +03:00
|
|
|
if (error) {
|
|
|
|
vrele(*vpp);
|
|
|
|
*vpp = NULL;
|
|
|
|
return error;
|
|
|
|
}
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2015-07-06 13:07:12 +03:00
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2020-01-17 23:08:06 +03:00
|
|
|
tmpfs_vget(struct mount *mp, ino_t ino, int lktype, vnode_t **vpp)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2020-01-17 23:08:06 +03:00
|
|
|
tmpfs_fhtovp(struct mount *mp, struct fid *fhp, int lktype, vnode_t **vpp)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2011-05-30 02:29:06 +04:00
|
|
|
tmpfs_mount_t *tmp = VFS_TO_TMPFS(mp);
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_node_t *node;
|
|
|
|
tmpfs_fid_t tfh;
|
2014-01-04 16:36:49 +04:00
|
|
|
int error;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-30 02:29:06 +04:00
|
|
|
if (fhp->fid_len != sizeof(tmpfs_fid_t)) {
|
2005-09-10 23:20:48 +04:00
|
|
|
return EINVAL;
|
2011-05-30 02:29:06 +04:00
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
memcpy(&tfh, fhp, sizeof(tmpfs_fid_t));
|
2006-07-13 16:00:24 +04:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_enter(&tmp->tm_lock);
|
2020-01-17 23:08:06 +03:00
|
|
|
/* XXX big oof .. use a better data structure */
|
2008-01-02 14:48:20 +03:00
|
|
|
LIST_FOREACH(node, &tmp->tm_nodes, tn_entries) {
|
2014-01-04 16:36:49 +04:00
|
|
|
if (node->tn_id == tfh.tf_id) {
|
2015-07-06 13:07:12 +03:00
|
|
|
/* Prevent this node from disappearing. */
|
|
|
|
atomic_inc_32(&node->tn_holdcount);
|
2014-01-04 16:36:49 +04:00
|
|
|
break;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
}
|
2008-01-02 14:48:20 +03:00
|
|
|
mutex_exit(&tmp->tm_lock);
|
2014-01-04 16:36:49 +04:00
|
|
|
if (node == NULL)
|
|
|
|
return ESTALE;
|
2015-07-06 13:07:12 +03:00
|
|
|
|
|
|
|
error = vcache_get(mp, &node, sizeof(node), vpp);
|
|
|
|
/* If this node has been reclaimed free it now. */
|
|
|
|
if (atomic_dec_32_nv(&node->tn_holdcount) == TMPFS_NODE_RECLAIMED) {
|
|
|
|
KASSERT(error != 0);
|
|
|
|
tmpfs_free_node(tmp, node);
|
|
|
|
}
|
|
|
|
if (error)
|
|
|
|
return (error == ENOENT ? ESTALE : error);
|
2020-01-17 23:08:06 +03:00
|
|
|
error = vn_lock(*vpp, lktype);
|
2015-07-06 13:07:12 +03:00
|
|
|
if (error) {
|
|
|
|
vrele(*vpp);
|
|
|
|
*vpp = NULL;
|
2014-01-04 16:36:49 +04:00
|
|
|
return error;
|
2015-07-06 13:07:12 +03:00
|
|
|
}
|
2014-01-04 16:36:49 +04:00
|
|
|
if (TMPFS_NODE_GEN(node) != tfh.tf_gen) {
|
|
|
|
vput(*vpp);
|
|
|
|
*vpp = NULL;
|
|
|
|
return ESTALE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2005-09-10 23:20:48 +04:00
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_vptofh(vnode_t *vp, struct fid *fhp, size_t *fh_size)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_fid_t tfh;
|
|
|
|
tmpfs_node_t *node;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
2011-05-25 00:17:49 +04:00
|
|
|
if (*fh_size < sizeof(tmpfs_fid_t)) {
|
|
|
|
*fh_size = sizeof(tmpfs_fid_t);
|
2006-07-13 16:00:24 +04:00
|
|
|
return E2BIG;
|
|
|
|
}
|
2011-05-25 00:17:49 +04:00
|
|
|
*fh_size = sizeof(tmpfs_fid_t);
|
2005-09-10 23:20:48 +04:00
|
|
|
node = VP_TO_TMPFS_NODE(vp);
|
|
|
|
|
2006-07-13 16:00:24 +04:00
|
|
|
memset(&tfh, 0, sizeof(tfh));
|
2011-05-25 00:17:49 +04:00
|
|
|
tfh.tf_len = sizeof(tmpfs_fid_t);
|
2011-05-30 02:29:06 +04:00
|
|
|
tfh.tf_gen = TMPFS_NODE_GEN(node);
|
2006-07-13 16:00:24 +04:00
|
|
|
tfh.tf_id = node->tn_id;
|
|
|
|
memcpy(fhp, &tfh, sizeof(tfh));
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2007-11-26 22:01:26 +03:00
|
|
|
tmpfs_statvfs(struct mount *mp, struct statvfs *sbp)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_mount_t *tmp;
|
2010-06-26 07:38:14 +04:00
|
|
|
fsfilcnt_t freenodes;
|
|
|
|
size_t avail;
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
tmp = VFS_TO_TMPFS(mp);
|
|
|
|
|
|
|
|
sbp->f_iosize = sbp->f_frsize = sbp->f_bsize = PAGE_SIZE;
|
|
|
|
|
2010-06-26 07:38:14 +04:00
|
|
|
mutex_enter(&tmp->tm_acc_lock);
|
|
|
|
avail = tmpfs_pages_avail(tmp);
|
2010-06-22 22:32:07 +04:00
|
|
|
sbp->f_blocks = (tmpfs_bytes_max(tmp) >> PAGE_SHIFT);
|
2010-06-26 07:38:14 +04:00
|
|
|
sbp->f_bavail = sbp->f_bfree = avail;
|
2005-09-10 23:20:48 +04:00
|
|
|
sbp->f_bresvd = 0;
|
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
freenodes = MIN(tmp->tm_nodes_max - tmp->tm_nodes_cnt,
|
2011-05-25 00:17:49 +04:00
|
|
|
avail * PAGE_SIZE / sizeof(tmpfs_node_t));
|
2007-11-10 06:36:16 +03:00
|
|
|
|
2008-01-02 14:48:20 +03:00
|
|
|
sbp->f_files = tmp->tm_nodes_cnt + freenodes;
|
2005-09-10 23:20:48 +04:00
|
|
|
sbp->f_favail = sbp->f_ffree = freenodes;
|
|
|
|
sbp->f_fresvd = 0;
|
2010-06-26 07:38:14 +04:00
|
|
|
mutex_exit(&tmp->tm_acc_lock);
|
2005-09-10 23:20:48 +04:00
|
|
|
|
|
|
|
copy_statvfs_info(sbp, mp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_sync(struct mount *mp, int waitfor, kauth_cred_t uc)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-07-06 13:05:50 +03:00
|
|
|
int
|
2011-05-25 00:17:49 +04:00
|
|
|
tmpfs_snapshot(struct mount *mp, vnode_t *vp, struct timespec *ctime)
|
2005-09-10 23:20:48 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
return EOPNOTSUPP;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* tmpfs vfs operations.
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern const struct vnodeopv_desc tmpfs_fifoop_opv_desc;
|
|
|
|
extern const struct vnodeopv_desc tmpfs_specop_opv_desc;
|
|
|
|
extern const struct vnodeopv_desc tmpfs_vnodeop_opv_desc;
|
|
|
|
|
|
|
|
const struct vnodeopv_desc * const tmpfs_vnodeopv_descs[] = {
|
|
|
|
&tmpfs_fifoop_opv_desc,
|
|
|
|
&tmpfs_specop_opv_desc,
|
|
|
|
&tmpfs_vnodeop_opv_desc,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct vfsops tmpfs_vfsops = {
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_name = MOUNT_TMPFS,
|
|
|
|
.vfs_min_mount_data = sizeof (struct tmpfs_args),
|
|
|
|
.vfs_mount = tmpfs_mount,
|
|
|
|
.vfs_start = tmpfs_start,
|
|
|
|
.vfs_unmount = tmpfs_unmount,
|
|
|
|
.vfs_root = tmpfs_root,
|
|
|
|
.vfs_quotactl = (void *)eopnotsupp,
|
|
|
|
.vfs_statvfs = tmpfs_statvfs,
|
|
|
|
.vfs_sync = tmpfs_sync,
|
|
|
|
.vfs_vget = tmpfs_vget,
|
2015-07-06 13:07:12 +03:00
|
|
|
.vfs_loadvnode = tmpfs_loadvnode,
|
|
|
|
.vfs_newvnode = tmpfs_newvnode,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_fhtovp = tmpfs_fhtovp,
|
|
|
|
.vfs_vptofh = tmpfs_vptofh,
|
|
|
|
.vfs_init = tmpfs_init,
|
|
|
|
.vfs_done = tmpfs_done,
|
|
|
|
.vfs_snapshot = tmpfs_snapshot,
|
|
|
|
.vfs_extattrctl = vfs_stdextattrctl,
|
2017-02-17 11:31:23 +03:00
|
|
|
.vfs_suspendctl = genfs_suspendctl,
|
2014-03-23 19:21:15 +04:00
|
|
|
.vfs_renamelock_enter = genfs_renamelock_enter,
|
|
|
|
.vfs_renamelock_exit = genfs_renamelock_exit,
|
|
|
|
.vfs_fsync = (void *)eopnotsupp,
|
|
|
|
.vfs_opv_descs = tmpfs_vnodeopv_descs
|
2005-09-10 23:20:48 +04:00
|
|
|
};
|
2008-05-10 06:26:09 +04:00
|
|
|
|
|
|
|
static int
|
|
|
|
tmpfs_modcmd(modcmd_t cmd, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case MODULE_CMD_INIT:
|
|
|
|
return vfs_attach(&tmpfs_vfsops);
|
|
|
|
case MODULE_CMD_FINI:
|
|
|
|
return vfs_detach(&tmpfs_vfsops);
|
|
|
|
default:
|
|
|
|
return ENOTTY;
|
|
|
|
}
|
|
|
|
}
|