2017-11-20 19:43:44 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*
|
2012-10-13 23:54:26 +00:00
|
|
|
* Copyright (c) 2007-2009 Google Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * 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.
|
|
|
|
* * Neither the name of Google Inc. nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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 COPYRIGHT
|
|
|
|
* OWNER 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.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Csaba Henk.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 AUTHOR 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 AUTHOR 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
2019-02-28 19:27:54 +00:00
|
|
|
#include <sys/queue.h>
|
2012-10-13 23:54:26 +00:00
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/file.h>
|
|
|
|
#include <sys/buf.h>
|
2019-02-28 19:27:54 +00:00
|
|
|
#include <sys/sdt.h>
|
2012-10-13 23:54:26 +00:00
|
|
|
#include <sys/sysctl.h>
|
|
|
|
|
|
|
|
#include "fuse.h"
|
|
|
|
|
|
|
|
static void fuse_bringdown(eventhandler_tag eh_tag);
|
|
|
|
static int fuse_loader(struct module *m, int what, void *arg);
|
|
|
|
|
|
|
|
struct mtx fuse_mtx;
|
|
|
|
|
|
|
|
extern struct vfsops fuse_vfsops;
|
|
|
|
extern struct cdevsw fuse_cdevsw;
|
2019-04-29 01:40:35 +00:00
|
|
|
extern struct vop_vector fuse_fifonops;
|
2012-10-13 23:54:26 +00:00
|
|
|
extern struct vop_vector fuse_vnops;
|
Allocate pager bufs from UMA instead of 80-ish mutex protected linked list.
o In vm_pager_bufferinit() create pbuf_zone and start accounting on how many
pbufs are we going to have set.
In various subsystems that are going to utilize pbufs create private zones
via call to pbuf_zsecond_create(). The latter calls uma_zsecond_create(),
and sets a limit on created zone. After startup preallocate pbufs according
to requirements of all pbuf zones.
Subsystems that used to have a private limit with old allocator now have
private pbuf zones: md(4), fusefs, NFS client, smbfs, VFS cluster, FFS,
swap, vnode pager.
The following subsystems use shared pbuf zone: cam(4), nvme(4), physio(9),
aio(4). They should have their private limits, but changing that is out of
scope of this commit.
o Fetch tunable value of kern.nswbuf from init_param2() and while here move
NSWBUF_MIN to opt_param.h and eliminate opt_swap.h, that was holding only
this option.
Default values aren't touched by this commit, but they probably should be
reviewed wrt to modern hardware.
This change removes a tight bottleneck from sendfile(2) operation, that
uses pbufs in vnode pager. Other pagers also would benefit from faster
allocation.
Together with: gallatin
Tested by: pho
2019-01-15 01:02:16 +00:00
|
|
|
extern uma_zone_t fuse_pbuf_zone;
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
static struct vfsconf fuse_vfsconf = {
|
|
|
|
.vfc_version = VFS_VERSION,
|
|
|
|
.vfc_name = "fusefs",
|
|
|
|
.vfc_vfsops = &fuse_vfsops,
|
|
|
|
.vfc_typenum = -1,
|
2018-07-20 21:35:31 +00:00
|
|
|
.vfc_flags = VFCF_JAIL | VFCF_SYNTHETIC
|
2012-10-13 23:54:26 +00:00
|
|
|
};
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, kernelabi_major, CTLFLAG_RD,
|
2014-10-21 07:31:21 +00:00
|
|
|
SYSCTL_NULL_INT_PTR, FUSE_KERNEL_VERSION, "FUSE kernel abi major version");
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, kernelabi_minor, CTLFLAG_RD,
|
2014-10-21 07:31:21 +00:00
|
|
|
SYSCTL_NULL_INT_PTR, FUSE_KERNEL_MINOR_VERSION, "FUSE kernel abi minor version");
|
2019-04-20 00:04:31 +00:00
|
|
|
SDT_PROVIDER_DEFINE(fusefs);
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
/******************************
|
|
|
|
*
|
|
|
|
* >>> Module management stuff
|
|
|
|
*
|
|
|
|
******************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
fuse_bringdown(eventhandler_tag eh_tag)
|
|
|
|
{
|
|
|
|
|
|
|
|
fuse_ipc_destroy();
|
|
|
|
fuse_device_destroy();
|
|
|
|
mtx_destroy(&fuse_mtx);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fuse_loader(struct module *m, int what, void *arg)
|
|
|
|
{
|
|
|
|
static eventhandler_tag eh_tag = NULL;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
switch (what) {
|
|
|
|
case MOD_LOAD: /* kldload */
|
|
|
|
mtx_init(&fuse_mtx, "fuse_mtx", NULL, MTX_DEF);
|
|
|
|
err = fuse_device_init();
|
|
|
|
if (err) {
|
|
|
|
mtx_destroy(&fuse_mtx);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
fuse_ipc_init();
|
Allocate pager bufs from UMA instead of 80-ish mutex protected linked list.
o In vm_pager_bufferinit() create pbuf_zone and start accounting on how many
pbufs are we going to have set.
In various subsystems that are going to utilize pbufs create private zones
via call to pbuf_zsecond_create(). The latter calls uma_zsecond_create(),
and sets a limit on created zone. After startup preallocate pbufs according
to requirements of all pbuf zones.
Subsystems that used to have a private limit with old allocator now have
private pbuf zones: md(4), fusefs, NFS client, smbfs, VFS cluster, FFS,
swap, vnode pager.
The following subsystems use shared pbuf zone: cam(4), nvme(4), physio(9),
aio(4). They should have their private limits, but changing that is out of
scope of this commit.
o Fetch tunable value of kern.nswbuf from init_param2() and while here move
NSWBUF_MIN to opt_param.h and eliminate opt_swap.h, that was holding only
this option.
Default values aren't touched by this commit, but they probably should be
reviewed wrt to modern hardware.
This change removes a tight bottleneck from sendfile(2) operation, that
uses pbufs in vnode pager. Other pagers also would benefit from faster
allocation.
Together with: gallatin
Tested by: pho
2019-01-15 01:02:16 +00:00
|
|
|
fuse_pbuf_zone = pbuf_zsecond_create("fusepbuf", nswbuf / 2);
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
/* vfs_modevent ignores its first arg */
|
|
|
|
if ((err = vfs_modevent(NULL, what, &fuse_vfsconf)))
|
|
|
|
fuse_bringdown(eh_tag);
|
|
|
|
break;
|
|
|
|
case MOD_UNLOAD:
|
|
|
|
if ((err = vfs_modevent(NULL, what, &fuse_vfsconf)))
|
|
|
|
return (err);
|
|
|
|
fuse_bringdown(eh_tag);
|
Allocate pager bufs from UMA instead of 80-ish mutex protected linked list.
o In vm_pager_bufferinit() create pbuf_zone and start accounting on how many
pbufs are we going to have set.
In various subsystems that are going to utilize pbufs create private zones
via call to pbuf_zsecond_create(). The latter calls uma_zsecond_create(),
and sets a limit on created zone. After startup preallocate pbufs according
to requirements of all pbuf zones.
Subsystems that used to have a private limit with old allocator now have
private pbuf zones: md(4), fusefs, NFS client, smbfs, VFS cluster, FFS,
swap, vnode pager.
The following subsystems use shared pbuf zone: cam(4), nvme(4), physio(9),
aio(4). They should have their private limits, but changing that is out of
scope of this commit.
o Fetch tunable value of kern.nswbuf from init_param2() and while here move
NSWBUF_MIN to opt_param.h and eliminate opt_swap.h, that was holding only
this option.
Default values aren't touched by this commit, but they probably should be
reviewed wrt to modern hardware.
This change removes a tight bottleneck from sendfile(2) operation, that
uses pbufs in vnode pager. Other pagers also would benefit from faster
allocation.
Together with: gallatin
Tested by: pho
2019-01-15 01:02:16 +00:00
|
|
|
uma_zdestroy(fuse_pbuf_zone);
|
2012-10-13 23:54:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Registering the module */
|
|
|
|
|
|
|
|
static moduledata_t fuse_moddata = {
|
2019-03-20 21:48:43 +00:00
|
|
|
"fusefs",
|
2012-10-13 23:54:26 +00:00
|
|
|
fuse_loader,
|
|
|
|
&fuse_vfsconf
|
|
|
|
};
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
DECLARE_MODULE(fusefs, fuse_moddata, SI_SUB_VFS, SI_ORDER_MIDDLE);
|
|
|
|
MODULE_VERSION(fusefs, 1);
|