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. and Amit Singh
|
|
|
|
* 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/uio.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/lock.h>
|
|
|
|
#include <sys/sx.h>
|
|
|
|
#include <sys/mutex.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/namei.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/fnv_hash.h>
|
|
|
|
#include <sys/priv.h>
|
|
|
|
#include <security/mac/mac_framework.h>
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_extern.h>
|
|
|
|
|
|
|
|
#include "fuse.h"
|
|
|
|
#include "fuse_node.h"
|
|
|
|
#include "fuse_internal.h"
|
|
|
|
#include "fuse_io.h"
|
|
|
|
#include "fuse_ipc.h"
|
|
|
|
|
2019-02-28 19:27:54 +00:00
|
|
|
SDT_PROVIDER_DECLARE(fuse);
|
|
|
|
/*
|
|
|
|
* Fuse trace probe:
|
|
|
|
* arg0: verbosity. Higher numbers give more verbose messages
|
|
|
|
* arg1: Textual message
|
|
|
|
*/
|
|
|
|
SDT_PROBE_DEFINE2(fuse, , node, trace, "int", "char*");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
MALLOC_DEFINE(M_FUSEVN, "fuse_vnode", "fuse vnode private data");
|
|
|
|
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
static int sysctl_fuse_cache_mode(SYSCTL_HANDLER_ARGS);
|
|
|
|
|
2012-10-13 23:54:26 +00:00
|
|
|
static int fuse_node_count = 0;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, node_count, CTLFLAG_RD,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_node_count, 0, "Count of FUSE vnodes");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
int fuse_data_cache_mode = FUSE_CACHE_WT;
|
2012-10-13 23:54:26 +00:00
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_PROC(_vfs_fusefs, OID_AUTO, data_cache_mode, CTLTYPE_INT|CTLFLAG_RW,
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
&fuse_data_cache_mode, 0, sysctl_fuse_cache_mode, "I",
|
|
|
|
"Zero: disable caching of FUSE file data; One: write-through caching "
|
|
|
|
"(default); Two: write-back caching (generally unsafe)");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
int fuse_data_cache_invalidate = 0;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, data_cache_invalidate, CTLFLAG_RW,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_data_cache_invalidate, 0,
|
|
|
|
"If non-zero, discard cached clean file data when there are no active file"
|
|
|
|
" users");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
int fuse_mmap_enable = 1;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, mmap_enable, CTLFLAG_RW,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_mmap_enable, 0,
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
"If non-zero, and data_cache_mode is also non-zero, enable mmap(2) of "
|
2018-08-15 17:41:19 +00:00
|
|
|
"FUSE files");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
int fuse_refresh_size = 0;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, refresh_size, CTLFLAG_RW,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_refresh_size, 0,
|
|
|
|
"If non-zero, and no dirty file extension data is buffered, fetch file "
|
|
|
|
"size before write operations");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
int fuse_sync_resize = 1;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, sync_resize, CTLFLAG_RW,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_sync_resize, 0,
|
|
|
|
"If a cached write extended a file, inform FUSE filesystem of the changed"
|
|
|
|
"size immediately subsequent to the issued writes");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
int fuse_fix_broken_io = 0;
|
|
|
|
|
2019-03-20 21:48:43 +00:00
|
|
|
SYSCTL_INT(_vfs_fusefs, OID_AUTO, fix_broken_io, CTLFLAG_RW,
|
2018-08-15 17:41:19 +00:00
|
|
|
&fuse_fix_broken_io, 0,
|
|
|
|
"If non-zero, print a diagnostic warning if a userspace filesystem returns"
|
|
|
|
" EIO on reads of recently extended portions of files");
|
2012-10-13 23:54:26 +00:00
|
|
|
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
static int
|
|
|
|
sysctl_fuse_cache_mode(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
int val, error;
|
|
|
|
|
|
|
|
val = *(int *)arg1;
|
|
|
|
error = sysctl_handle_int(oidp, &val, 0, req);
|
|
|
|
if (error || !req->newptr)
|
|
|
|
return (error);
|
|
|
|
|
|
|
|
switch (val) {
|
|
|
|
case FUSE_CACHE_UC:
|
|
|
|
case FUSE_CACHE_WT:
|
|
|
|
case FUSE_CACHE_WB:
|
|
|
|
*(int *)arg1 = val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return (EDOM);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2012-10-13 23:54:26 +00:00
|
|
|
static void
|
|
|
|
fuse_vnode_init(struct vnode *vp, struct fuse_vnode_data *fvdat,
|
|
|
|
uint64_t nodeid, enum vtype vtyp)
|
|
|
|
{
|
|
|
|
fvdat->nid = nodeid;
|
2019-03-31 03:19:10 +00:00
|
|
|
LIST_INIT(&fvdat->handles);
|
FUSE: Respect userspace FS "do-not-cache" of file attributes
The FUSE protocol demands that kernel implementations cache user filesystem
file attributes (vattr data) for a maximum period of time in the range of
[0, ULONG_MAX] seconds. In practice, typical requests are for 0, 1, or 10
seconds; or "a long time" to represent indefinite caching.
Historically, FreeBSD FUSE has ignored this client directive entirely. This
works fine for local-only filesystems, but causes consistency issues with
multi-writer network filesystems.
For now, respect 0 second cache TTLs and do not cache such metadata.
Non-zero metadata caching TTLs in the range [0.000000001, ULONG_MAX] seconds
are still cached indefinitely, because it is unclear how a userspace
filesystem could do anything sensible with those semantics even if
implemented.
In the future, as an optimization, we should implement notify_inval_entry,
etc, which provide userspace filesystems a way of evicting the kernel cache.
One potentially bogus access to invalid cached attribute data was left in
fuse_io_strategy. It is restricted behind the undocumented and non-default
"vfs.fuse.fix_broken_io" sysctl or "brokenio" mount option; maybe these are
deadcode and can be eliminated?
Some minor APIs changed to facilitate this:
1. Attribute cache validity is tracked in FUSE inodes ("fuse_vnode_data").
2. cache_attrs() respects the provided TTL and only caches in the FUSE
inode if TTL > 0. It also grows an "out" argument, which, if non-NULL,
stores the translated fuse_attr (even if not suitable for caching).
3. FUSE VTOVA(vp) returns NULL if the vnode's cache is invalid, to help
avoid programming mistakes.
4. A VOP_LINK check for potential nlink overflow prior to invoking the FUSE
link op was weakened (only performed when we have a valid attr cache). The
check is racy in a multi-writer network filesystem anyway -- classic TOCTOU.
We have to trust any userspace filesystem that rejects local caching to
account for it correctly.
PR: 230258 (inspired by; does not fix)
2019-02-15 22:49:15 +00:00
|
|
|
vattr_null(&fvdat->cached_attrs);
|
2012-10-13 23:54:26 +00:00
|
|
|
if (nodeid == FUSE_ROOT_ID) {
|
|
|
|
vp->v_vflag |= VV_ROOT;
|
|
|
|
}
|
|
|
|
vp->v_type = vtyp;
|
|
|
|
vp->v_data = fvdat;
|
|
|
|
|
|
|
|
atomic_add_acq_int(&fuse_node_count, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fuse_vnode_destroy(struct vnode *vp)
|
|
|
|
{
|
|
|
|
struct fuse_vnode_data *fvdat = vp->v_data;
|
|
|
|
|
|
|
|
vp->v_data = NULL;
|
2019-03-31 03:19:10 +00:00
|
|
|
KASSERT(LIST_EMPTY(&fvdat->handles),
|
|
|
|
("Destroying fuse vnode with open files!"));
|
2012-10-13 23:54:26 +00:00
|
|
|
free(fvdat, M_FUSEVN);
|
|
|
|
|
|
|
|
atomic_subtract_acq_int(&fuse_node_count, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fuse_vnode_cmp(struct vnode *vp, void *nidp)
|
|
|
|
{
|
|
|
|
return (VTOI(vp) != *((uint64_t *)nidp));
|
|
|
|
}
|
|
|
|
|
2019-02-20 02:49:26 +00:00
|
|
|
static uint32_t inline
|
2012-10-13 23:54:26 +00:00
|
|
|
fuse_vnode_hash(uint64_t id)
|
|
|
|
{
|
|
|
|
return (fnv_32_buf(&id, sizeof(id), FNV1_32_INIT));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
fuse_vnode_alloc(struct mount *mp,
|
|
|
|
struct thread *td,
|
|
|
|
uint64_t nodeid,
|
|
|
|
enum vtype vtyp,
|
|
|
|
struct vnode **vpp)
|
|
|
|
{
|
|
|
|
struct fuse_vnode_data *fvdat;
|
|
|
|
struct vnode *vp2;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
if (vtyp == VNON) {
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
*vpp = NULL;
|
|
|
|
err = vfs_hash_get(mp, fuse_vnode_hash(nodeid), LK_EXCLUSIVE, td, vpp,
|
|
|
|
fuse_vnode_cmp, &nodeid);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
|
|
|
|
if (*vpp) {
|
|
|
|
MPASS((*vpp)->v_type == vtyp && (*vpp)->v_data != NULL);
|
2019-02-28 19:27:54 +00:00
|
|
|
SDT_PROBE2(fuse, , node, trace, 1, "vnode taken from hash");
|
2012-10-13 23:54:26 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
fvdat = malloc(sizeof(*fvdat), M_FUSEVN, M_WAITOK | M_ZERO);
|
|
|
|
err = getnewvnode("fuse", mp, &fuse_vnops, vpp);
|
|
|
|
if (err) {
|
|
|
|
free(fvdat, M_FUSEVN);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
lockmgr((*vpp)->v_vnlock, LK_EXCLUSIVE, NULL);
|
|
|
|
fuse_vnode_init(*vpp, fvdat, nodeid, vtyp);
|
|
|
|
err = insmntque(*vpp, mp);
|
|
|
|
ASSERT_VOP_ELOCKED(*vpp, "fuse_vnode_alloc");
|
|
|
|
if (err) {
|
|
|
|
free(fvdat, M_FUSEVN);
|
|
|
|
*vpp = NULL;
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
err = vfs_hash_insert(*vpp, fuse_vnode_hash(nodeid), LK_EXCLUSIVE,
|
|
|
|
td, &vp2, fuse_vnode_cmp, &nodeid);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
if (vp2 != NULL) {
|
|
|
|
*vpp = vp2;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(*vpp, "fuse_vnode_alloc");
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fuse_vnode_get(struct mount *mp,
|
2019-02-15 22:50:31 +00:00
|
|
|
struct fuse_entry_out *feo,
|
2012-10-13 23:54:26 +00:00
|
|
|
uint64_t nodeid,
|
|
|
|
struct vnode *dvp,
|
|
|
|
struct vnode **vpp,
|
|
|
|
struct componentname *cnp,
|
|
|
|
enum vtype vtyp)
|
|
|
|
{
|
|
|
|
struct thread *td = (cnp != NULL ? cnp->cn_thread : curthread);
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
err = fuse_vnode_alloc(mp, td, nodeid, vtyp, vpp);
|
|
|
|
if (err) {
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (dvp != NULL) {
|
2019-03-27 14:15:35 +00:00
|
|
|
MPASS(cnp && (cnp->cn_flags & ISDOTDOT) == 0);
|
|
|
|
MPASS(cnp &&
|
|
|
|
!(cnp->cn_namelen == 1 && cnp->cn_nameptr[0] == '.'));
|
2012-10-13 23:54:26 +00:00
|
|
|
fuse_vnode_setparent(*vpp, dvp);
|
|
|
|
}
|
2019-02-15 22:50:31 +00:00
|
|
|
if (dvp != NULL && cnp != NULL && (cnp->cn_flags & MAKEENTRY) != 0 &&
|
|
|
|
feo != NULL &&
|
|
|
|
(feo->entry_valid != 0 || feo->entry_valid_nsec != 0)) {
|
2012-10-13 23:54:26 +00:00
|
|
|
ASSERT_VOP_LOCKED(*vpp, "fuse_vnode_get");
|
|
|
|
ASSERT_VOP_LOCKED(dvp, "fuse_vnode_get");
|
|
|
|
cache_enter(dvp, *vpp, cnp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In userland, libfuse uses cached lookups for dot and dotdot entries,
|
|
|
|
* thus it does not really bump the nlookup counter for forget.
|
|
|
|
* Follow the same semantic and avoid tu bump it in order to keep
|
|
|
|
* nlookup counters consistent.
|
|
|
|
*/
|
|
|
|
if (cnp == NULL || ((cnp->cn_flags & ISDOTDOT) == 0 &&
|
|
|
|
(cnp->cn_namelen != 1 || cnp->cn_nameptr[0] != '.')))
|
|
|
|
VTOFUD(*vpp)->nlookup++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fuse_vnode_open(struct vnode *vp, int32_t fuse_open_flags, struct thread *td)
|
|
|
|
{
|
|
|
|
/*
|
2019-03-31 03:19:10 +00:00
|
|
|
* Function is called for every vnode open.
|
2015-03-02 19:14:58 +00:00
|
|
|
* Merge fuse_open_flags it may be 0
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Ideally speaking, direct io should be enabled on
|
|
|
|
* fd's but do not see of any way of providing that
|
|
|
|
* this implementation.
|
|
|
|
*
|
|
|
|
* Also cannot think of a reason why would two
|
|
|
|
* different fd's on same vnode would like
|
|
|
|
* have DIRECT_IO turned on and off. But linux
|
|
|
|
* based implementation works on an fd not an
|
|
|
|
* inode and provides such a feature.
|
|
|
|
*
|
|
|
|
* XXXIP: Handle fd based DIRECT_IO
|
|
|
|
*/
|
2015-03-02 19:04:27 +00:00
|
|
|
if (fuse_open_flags & FOPEN_DIRECT_IO) {
|
2016-05-15 00:45:17 +00:00
|
|
|
ASSERT_VOP_ELOCKED(vp, __func__);
|
2015-03-02 19:04:27 +00:00
|
|
|
VTOFUD(vp)->flag |= FN_DIRECTIO;
|
2016-05-15 00:45:17 +00:00
|
|
|
fuse_io_invalbuf(vp, td);
|
2015-03-02 19:04:27 +00:00
|
|
|
} else {
|
2017-04-21 22:00:22 +00:00
|
|
|
if ((fuse_open_flags & FOPEN_KEEP_CACHE) == 0)
|
|
|
|
fuse_io_invalbuf(vp, td);
|
2015-03-02 19:04:27 +00:00
|
|
|
VTOFUD(vp)->flag &= ~FN_DIRECTIO;
|
|
|
|
}
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
if (vnode_vtype(vp) == VREG) {
|
|
|
|
/* XXXIP prevent getattr, by using cached node size */
|
|
|
|
vnode_create_vobject(vp, 0, td);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fuse_vnode_savesize(struct vnode *vp, struct ucred *cred)
|
|
|
|
{
|
|
|
|
struct fuse_vnode_data *fvdat = VTOFUD(vp);
|
|
|
|
struct thread *td = curthread;
|
|
|
|
struct fuse_filehandle *fufh = NULL;
|
|
|
|
struct fuse_dispatcher fdi;
|
|
|
|
struct fuse_setattr_in *fsai;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(vp, "fuse_io_extend");
|
|
|
|
|
|
|
|
if (fuse_isdeadfs(vp)) {
|
|
|
|
return EBADF;
|
|
|
|
}
|
|
|
|
if (vnode_vtype(vp) == VDIR) {
|
|
|
|
return EISDIR;
|
|
|
|
}
|
|
|
|
if (vfs_isrdonly(vnode_mount(vp))) {
|
|
|
|
return EROFS;
|
|
|
|
}
|
|
|
|
if (cred == NULL) {
|
|
|
|
cred = td->td_ucred;
|
|
|
|
}
|
|
|
|
fdisp_init(&fdi, sizeof(*fsai));
|
|
|
|
fdisp_make_vp(&fdi, FUSE_SETATTR, vp, td, cred);
|
|
|
|
fsai = fdi.indata;
|
|
|
|
fsai->valid = 0;
|
|
|
|
|
|
|
|
/* Truncate to a new value. */
|
2018-08-15 17:41:19 +00:00
|
|
|
fsai->size = fvdat->filesize;
|
2012-10-13 23:54:26 +00:00
|
|
|
fsai->valid |= FATTR_SIZE;
|
|
|
|
|
|
|
|
fuse_filehandle_getrw(vp, FUFH_WRONLY, &fufh);
|
|
|
|
if (fufh) {
|
|
|
|
fsai->fh = fufh->fh_id;
|
|
|
|
fsai->valid |= FATTR_FH;
|
|
|
|
}
|
|
|
|
err = fdisp_wait_answ(&fdi);
|
|
|
|
fdisp_destroy(&fdi);
|
|
|
|
if (err == 0)
|
|
|
|
fvdat->flag &= ~FN_SIZECHANGE;
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-03-27 16:45:30 +00:00
|
|
|
int
|
2012-10-13 23:54:26 +00:00
|
|
|
fuse_vnode_refreshsize(struct vnode *vp, struct ucred *cred)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct fuse_vnode_data *fvdat = VTOFUD(vp);
|
|
|
|
struct vattr va;
|
2019-03-27 16:45:30 +00:00
|
|
|
int err;
|
2012-10-13 23:54:26 +00:00
|
|
|
|
|
|
|
if ((fvdat->flag & FN_SIZECHANGE) != 0 ||
|
FUSE: The FUSE design expects writethrough caching
At least prior to 7.23 (which adds FUSE_WRITEBACK_CACHE), the FUSE protocol
specifies only clean data to be cached.
Prior to this change, we implement and default to writeback caching. This
is ok enough for local only filesystems without hardlinks, but violates the
general design contract with FUSE and breaks distributed filesystems or
concurrent access to hardlinks of the same inode.
In this change, add cache mode as an extension of cache enable/disable. The
new modes are UC (was: cache disabled), WT (default), and WB (was: cache
enabled).
For now, WT caching is implemented as write-around, which meets the goal of
only caching clean data. WT can be better than WA for workloads that
frequently read data that was recently written, but WA is trivial to
implement. Note that this has no effect on O_WRONLY-opened files, which
were already coerced to write-around.
Refs:
* https://sourceforge.net/p/fuse/mailman/message/8902254/
* https://github.com/vgough/encfs/issues/315
PR: 230258 (inspired by)
2019-02-15 22:52:49 +00:00
|
|
|
fuse_data_cache_mode == FUSE_CACHE_UC ||
|
2012-11-08 00:32:49 +00:00
|
|
|
(fuse_refresh_size == 0 && fvdat->filesize != 0))
|
2019-03-27 16:45:30 +00:00
|
|
|
return 0;
|
2012-10-13 23:54:26 +00:00
|
|
|
|
2019-03-27 16:45:30 +00:00
|
|
|
err = VOP_GETATTR(vp, &va, cred);
|
2019-02-28 19:27:54 +00:00
|
|
|
SDT_PROBE2(fuse, , node, trace, 1, "refreshed file size");
|
2019-03-27 16:45:30 +00:00
|
|
|
return err;
|
2012-10-13 23:54:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
fuse_vnode_setsize(struct vnode *vp, struct ucred *cred, off_t newsize)
|
|
|
|
{
|
|
|
|
struct fuse_vnode_data *fvdat = VTOFUD(vp);
|
|
|
|
off_t oldsize;
|
|
|
|
int err = 0;
|
|
|
|
|
|
|
|
ASSERT_VOP_ELOCKED(vp, "fuse_vnode_setsize");
|
|
|
|
|
|
|
|
oldsize = fvdat->filesize;
|
|
|
|
fvdat->filesize = newsize;
|
|
|
|
fvdat->flag |= FN_SIZECHANGE;
|
|
|
|
|
|
|
|
if (newsize < oldsize) {
|
|
|
|
err = vtruncbuf(vp, cred, newsize, fuse_iosize(vp));
|
|
|
|
}
|
|
|
|
vnode_pager_setsize(vp, newsize);
|
|
|
|
return err;
|
|
|
|
}
|