/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 2007-2009 Google Inc.4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions are8* met:9*10* * Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* * Redistributions in binary form must reproduce the above13* copyright notice, this list of conditions and the following disclaimer14* in the documentation and/or other materials provided with the15* distribution.16* * Neither the name of Google Inc. nor the names of its17* contributors may be used to endorse or promote products derived from18* this software without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS21* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT22* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR23* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT24* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,25* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT26* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,27* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY28* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT29* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE30* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.31*32* Copyright (C) 2005 Csaba Henk.33* All rights reserved.34*35* Copyright (c) 2019 The FreeBSD Foundation36*37* Portions of this software were developed by BFF Storage Systems, LLC under38* sponsorship from the FreeBSD Foundation.39*40* Redistribution and use in source and binary forms, with or without41* modification, are permitted provided that the following conditions42* are met:43* 1. Redistributions of source code must retain the above copyright44* notice, this list of conditions and the following disclaimer.45* 2. Redistributions in binary form must reproduce the above copyright46* notice, this list of conditions and the following disclaimer in the47* documentation and/or other materials provided with the distribution.48*49* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND50* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE51* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE52* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE53* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL54* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS55* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)56* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT57* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY58* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF59* SUCH DAMAGE.60*/6162#include <sys/types.h>63#include <sys/param.h>64#include <sys/module.h>65#include <sys/systm.h>66#include <sys/errno.h>67#include <sys/param.h>68#include <sys/kernel.h>69#include <sys/conf.h>70#include <sys/mutex.h>71#include <sys/proc.h>72#include <sys/queue.h>73#include <sys/mount.h>74#include <sys/vnode.h>75#include <sys/stat.h>76#include <sys/file.h>77#include <sys/buf.h>78#include <sys/sdt.h>79#include <sys/sysctl.h>8081#include "fuse.h"82#include "fuse_file.h"83#include "fuse_ipc.h"84#include "fuse_internal.h"85#include "fuse_node.h"8687static void fuse_bringdown(eventhandler_tag eh_tag);88static int fuse_loader(struct module *m, int what, void *arg);8990struct mtx fuse_mtx;9192extern struct vfsops fuse_vfsops;93extern struct cdevsw fuse_cdevsw;94extern struct vop_vector fuse_fifonops;9596static struct vfsconf fuse_vfsconf = {97.vfc_version = VFS_VERSION,98.vfc_name = "fusefs",99.vfc_vfsops = &fuse_vfsops,100.vfc_typenum = -1,101.vfc_flags = VFCF_JAIL | VFCF_SYNTHETIC102};103104SYSCTL_NODE(_vfs, OID_AUTO, fusefs, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,105"FUSE tunables");106SYSCTL_NODE(_vfs_fusefs, OID_AUTO, stats, CTLFLAG_RW | CTLFLAG_MPSAFE, 0,107"FUSE statistics");108SYSCTL_INT(_vfs_fusefs, OID_AUTO, kernelabi_major, CTLFLAG_RD,109SYSCTL_NULL_INT_PTR, FUSE_KERNEL_VERSION, "FUSE kernel abi major version");110SYSCTL_INT(_vfs_fusefs, OID_AUTO, kernelabi_minor, CTLFLAG_RD,111SYSCTL_NULL_INT_PTR, FUSE_KERNEL_MINOR_VERSION, "FUSE kernel abi minor version");112SDT_PROVIDER_DEFINE(fusefs);113114/******************************115*116* >>> Module management stuff117*118******************************/119120static void121fuse_bringdown(eventhandler_tag eh_tag)122{123fuse_node_destroy();124fuse_internal_destroy();125fuse_file_destroy();126fuse_ipc_destroy();127fuse_device_destroy();128mtx_destroy(&fuse_mtx);129}130131static int132fuse_loader(struct module *m, int what, void *arg)133{134static eventhandler_tag eh_tag = NULL;135int err = 0;136137switch (what) {138case MOD_LOAD: /* kldload */139mtx_init(&fuse_mtx, "fuse_mtx", NULL, MTX_DEF);140err = fuse_device_init();141if (err) {142mtx_destroy(&fuse_mtx);143return (err);144}145fuse_ipc_init();146fuse_file_init();147fuse_internal_init();148fuse_node_init();149150/* vfs_modevent ignores its first arg */151if ((err = vfs_modevent(NULL, what, &fuse_vfsconf)))152fuse_bringdown(eh_tag);153break;154case MOD_UNLOAD:155if ((err = vfs_modevent(NULL, what, &fuse_vfsconf)))156return (err);157fuse_bringdown(eh_tag);158break;159default:160return (EINVAL);161}162163return (err);164}165166/* Registering the module */167168static moduledata_t fuse_moddata = {169"fusefs",170fuse_loader,171&fuse_vfsconf172};173174DECLARE_MODULE(fusefs, fuse_moddata, SI_SUB_VFS, SI_ORDER_MIDDLE);175MODULE_VERSION(fusefs, 1);176177178