2019-04-17 15:30:51 +03:00
|
|
|
/* $NetBSD: perfuse.c,v 1.42 2019/04/17 12:30:51 maya Exp $ */
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
/*-
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
* Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
|
2010-08-25 11:16:00 +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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <puffs.h>
|
2016-10-18 20:56:31 +03:00
|
|
|
#include <inttypes.h>
|
2010-08-25 11:16:00 +04:00
|
|
|
#include <sys/types.h>
|
2011-09-09 19:35:22 +04:00
|
|
|
#include <sys/mman.h>
|
2011-10-23 09:01:00 +04:00
|
|
|
#include <sys/resource.h>
|
2010-08-25 11:16:00 +04:00
|
|
|
#include <sys/socket.h>
|
2011-06-28 20:19:16 +04:00
|
|
|
#include <sys/extattr.h>
|
2012-07-21 09:49:42 +04:00
|
|
|
#include <sys/hash.h>
|
2010-08-25 11:16:00 +04:00
|
|
|
#include <sys/un.h>
|
2010-09-15 05:51:43 +04:00
|
|
|
#include <machine/vmparam.h>
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
#define LIBPERFUSE
|
|
|
|
#include "perfuse.h"
|
|
|
|
#include "perfuse_if.h"
|
|
|
|
#include "perfuse_priv.h"
|
|
|
|
|
|
|
|
int perfuse_diagflags = 0; /* global used only in DPRINTF/DERR/DWARN */
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
extern char **environ;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
static struct perfuse_state *init_state(void);
|
|
|
|
static int get_fd(const char *);
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
static struct perfuse_state *
|
|
|
|
init_state(void)
|
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
2012-07-21 09:49:42 +04:00
|
|
|
size_t len;
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
char opts[1024];
|
2012-07-21 09:49:42 +04:00
|
|
|
int i;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
if ((ps = malloc(sizeof(*ps))) == NULL)
|
2012-07-21 09:49:42 +04:00
|
|
|
DERR(EX_OSERR, "%s:%d malloc failed", __func__, __LINE__);
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
(void)memset(ps, 0, sizeof(*ps));
|
|
|
|
ps->ps_max_write = UINT_MAX;
|
|
|
|
ps->ps_max_readahead = UINT_MAX;
|
2011-12-28 21:33:52 +04:00
|
|
|
TAILQ_INIT(&ps->ps_trace);
|
2012-07-21 09:49:42 +04:00
|
|
|
|
|
|
|
ps->ps_nnidhash = PUFFS_PNODEBUCKETS;
|
|
|
|
len = sizeof(*ps->ps_nidhash) * ps->ps_nnidhash;
|
|
|
|
if ((ps->ps_nidhash = malloc(len)) == NULL)
|
|
|
|
DERR(EX_OSERR, "%s:%d malloc failed", __func__, __LINE__);
|
|
|
|
for (i = 0; i < ps->ps_nnidhash; i++)
|
|
|
|
LIST_INIT(&ps->ps_nidhash[i]);
|
2010-08-25 11:16:00 +04:00
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
/*
|
|
|
|
* Most of the time, access() is broken because the filesystem
|
|
|
|
* performs the check with root privileges. glusterfs will do that
|
|
|
|
* if the Linux-specific setfsuid() is missing, for instance.
|
|
|
|
*/
|
|
|
|
ps->ps_flags |= PS_NO_ACCESS;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This is a temporary way to toggle access and creat usage.
|
|
|
|
* It would be nice if that could be provided as mount options,
|
|
|
|
* but that will not be obvious to do.
|
|
|
|
*/
|
|
|
|
if (getenv_r("PERFUSE_OPTIONS", opts, sizeof(opts)) != -1) {
|
|
|
|
char *optname;
|
|
|
|
char *last;
|
|
|
|
|
|
|
|
for ((optname = strtok_r(opts, ",", &last));
|
|
|
|
optname != NULL;
|
|
|
|
(optname = strtok_r(NULL, ",", &last))) {
|
|
|
|
if (strcmp(optname, "enable_access") == 0)
|
|
|
|
ps->ps_flags &= ~PS_NO_ACCESS;
|
|
|
|
|
|
|
|
if (strcmp(optname, "disable_access") == 0)
|
|
|
|
ps->ps_flags |= PS_NO_ACCESS;
|
|
|
|
|
|
|
|
if (strcmp(optname, "enable_creat") == 0)
|
|
|
|
ps->ps_flags &= ~PS_NO_CREAT;
|
|
|
|
|
|
|
|
if (strcmp(optname, "disable_creat") == 0)
|
|
|
|
ps->ps_flags |= PS_NO_CREAT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2012-03-21 14:10:36 +04:00
|
|
|
get_fd(const char *data)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
char *string;
|
|
|
|
const char fdopt[] = "fd=";
|
|
|
|
char *lastp;
|
|
|
|
char *opt;
|
|
|
|
int fd = -1;
|
|
|
|
|
|
|
|
if ((string = strdup(data)) == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
for (opt = strtok_r(string, ",", &lastp);
|
|
|
|
opt != NULL;
|
|
|
|
opt = strtok_r(NULL, ",", &lastp)) {
|
|
|
|
if (strncmp(opt, fdopt, strlen(fdopt)) == 0) {
|
|
|
|
fd = atoi(opt + strlen(fdopt));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No file descriptor found
|
|
|
|
*/
|
|
|
|
if (fd == -1)
|
|
|
|
errno = EINVAL;
|
|
|
|
|
|
|
|
free(string);
|
|
|
|
return fd;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-19 04:30:35 +03:00
|
|
|
uint32_t
|
|
|
|
perfuse_bufvar_from_env(const char *name, uint32_t defval)
|
2016-10-18 18:06:17 +03:00
|
|
|
{
|
|
|
|
char valstr[1024];
|
2016-10-18 20:56:31 +03:00
|
|
|
int e;
|
|
|
|
uint32_t retval;
|
|
|
|
|
|
|
|
if (getenv_r(name, valstr, sizeof(valstr)) == -1)
|
|
|
|
return defval;
|
|
|
|
|
|
|
|
retval = (uint32_t)strtoi(valstr, NULL, 0, 0, UINT32_MAX, &e);
|
|
|
|
if (!e)
|
|
|
|
return retval;
|
2016-10-18 18:06:17 +03:00
|
|
|
|
2016-10-18 20:56:31 +03:00
|
|
|
DWARNC(e, "conversion from `%s' to uint32_t failed, using %u",
|
|
|
|
valstr, defval);
|
|
|
|
return defval;
|
2016-10-18 18:06:17 +03:00
|
|
|
}
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
int
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_open(const char *path, int flags, mode_t mode)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
2010-08-27 13:58:17 +04:00
|
|
|
int sv[2];
|
2010-08-25 11:16:00 +04:00
|
|
|
struct sockaddr_un sun;
|
|
|
|
struct sockaddr *sa;
|
2010-08-27 13:58:17 +04:00
|
|
|
char progname[] = _PATH_PERFUSED;
|
|
|
|
char minus_i[] = "-i";
|
|
|
|
char fdstr[16];
|
|
|
|
char *const argv[] = { progname, minus_i, fdstr, NULL};
|
2010-09-15 05:51:43 +04:00
|
|
|
uint32_t opt;
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
uint32_t optlen;
|
2011-05-30 18:50:08 +04:00
|
|
|
int sock_type = SOCK_SEQPACKET;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
if (strcmp(path, _PATH_FUSE) != 0)
|
|
|
|
return open(path, flags, mode);
|
|
|
|
|
2011-05-30 18:50:08 +04:00
|
|
|
/*
|
|
|
|
* Try SOCK_SEQPACKET then SOCK_DGRAM if unavailable
|
|
|
|
*/
|
|
|
|
if ((sv[0] = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) == -1) {
|
|
|
|
sock_type = SOCK_DGRAM;
|
|
|
|
DWARNX("SEQPACKET local sockets unavailable, using less "
|
|
|
|
"reliable DGRAM sockets. Expect file operation hangs.");
|
|
|
|
|
|
|
|
if ((sv[0] = socket(PF_LOCAL, SOCK_DGRAM, 0)) == -1) {
|
2010-08-25 11:16:00 +04:00
|
|
|
#ifdef PERFUSE_DEBUG
|
2011-08-14 03:12:15 +04:00
|
|
|
DWARN("%s: %d socket failed", __func__, __LINE__);
|
2010-08-25 11:16:00 +04:00
|
|
|
#endif
|
2011-05-30 18:50:08 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
2010-09-15 05:51:43 +04:00
|
|
|
/*
|
2019-04-17 15:30:51 +03:00
|
|
|
* Set a buffer length large enough so that enough FUSE packets
|
2010-09-15 05:51:43 +04:00
|
|
|
* will fit.
|
|
|
|
*/
|
2016-10-19 04:30:35 +03:00
|
|
|
opt = perfuse_bufvar_from_env("PERFUSE_BUFSIZE",
|
|
|
|
(uint32_t)(16 * FUSE_BUFSIZE));
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
optlen = sizeof(opt);
|
|
|
|
if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
|
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
if (setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_RCVBUF to %d failed", __func__, opt);
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
sa = (struct sockaddr *)(void *)&sun;
|
|
|
|
sun.sun_len = sizeof(sun);
|
|
|
|
sun.sun_family = AF_LOCAL;
|
|
|
|
(void)strcpy(sun.sun_path, path);
|
|
|
|
|
2011-05-30 18:50:08 +04:00
|
|
|
if (connect(sv[0], sa, (socklen_t)sun.sun_len) == 0)
|
2010-08-27 13:58:17 +04:00
|
|
|
return sv[0];
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attempt to run perfused on our own
|
|
|
|
* if it does not run yet; In that case
|
|
|
|
* we will talk using a socketpair
|
|
|
|
* instead of /dev/fuse.
|
|
|
|
*/
|
2011-05-30 18:50:08 +04:00
|
|
|
if (socketpair(PF_LOCAL, sock_type, 0, sv) != 0) {
|
2010-09-07 06:11:04 +04:00
|
|
|
DWARN("%s:%d: socketpair failed", __func__, __LINE__);
|
2010-08-25 11:16:00 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-09-15 05:51:43 +04:00
|
|
|
/*
|
2019-04-17 15:30:51 +03:00
|
|
|
* Set a buffer length large enough so that enough FUSE packets
|
2010-09-15 05:51:43 +04:00
|
|
|
* will fit.
|
|
|
|
*/
|
2016-10-19 04:30:35 +03:00
|
|
|
opt = perfuse_bufvar_from_env("PERFUSE_BUFSIZE",
|
|
|
|
(uint32_t)(16 * FUSE_BUFSIZE));
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
optlen = sizeof(opt);
|
|
|
|
if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
|
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
if (setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_RCVBUF to %d failed", __func__, opt);
|
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
if (setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
|
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
if (setsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt SO_RCVBUF to %d failed", __func__, opt);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Request peer credentials. This musr be done before first
|
|
|
|
* frame is sent.
|
|
|
|
*/
|
|
|
|
opt = 1;
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
optlen = sizeof(opt);
|
|
|
|
if (setsockopt(sv[1], 0, LOCAL_CREDS, &opt, optlen) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s: setsockopt LOCAL_CREDS failed", __func__);
|
|
|
|
|
2010-08-27 13:58:17 +04:00
|
|
|
(void)sprintf(fdstr, "%d", sv[1]);
|
|
|
|
|
|
|
|
switch(fork()) {
|
|
|
|
case -1:
|
|
|
|
#ifdef PERFUSE_DEBUG
|
2010-09-07 06:11:04 +04:00
|
|
|
DWARN("%s:%d: fork failed", __func__, __LINE__);
|
2010-08-27 13:58:17 +04:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
|
|
|
case 0:
|
2012-02-03 19:54:15 +04:00
|
|
|
(void)close(sv[0]);
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
(void)execve(argv[0], argv, environ);
|
2010-08-27 13:58:17 +04:00
|
|
|
#ifdef PERFUSE_DEBUG
|
2010-09-07 06:11:04 +04:00
|
|
|
DWARN("%s:%d: execve failed", __func__, __LINE__);
|
2010-08-27 13:58:17 +04:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-02-03 19:54:15 +04:00
|
|
|
(void)close(sv[1]);
|
2010-08-27 13:58:17 +04:00
|
|
|
return sv[0];
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_mount(const char *source, const char *target,
|
|
|
|
const char *filesystemtype, long mountflags, const void *data)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
int s;
|
|
|
|
size_t len;
|
2010-09-15 05:51:43 +04:00
|
|
|
struct perfuse_mount_out *pmo;
|
|
|
|
struct sockaddr_storage ss;
|
2010-09-20 11:00:21 +04:00
|
|
|
struct sockaddr_un *sun;
|
2010-09-15 05:51:43 +04:00
|
|
|
struct sockaddr *sa;
|
|
|
|
socklen_t sa_len;
|
|
|
|
size_t sock_len;
|
|
|
|
char *frame;
|
|
|
|
char *cp;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
#ifdef PERFUSE_DEBUG
|
2010-09-07 06:11:04 +04:00
|
|
|
if (perfuse_diagflags & PDF_MISC)
|
|
|
|
DPRINTF("%s(\"%s\", \"%s\", \"%s\", 0x%lx, \"%s\")\n",
|
|
|
|
__func__, source, target, filesystemtype,
|
|
|
|
mountflags, (const char *)data);
|
2010-08-25 11:16:00 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if ((s = get_fd(data)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
2010-09-15 05:51:43 +04:00
|
|
|
/*
|
|
|
|
* If we are connected to /dev/fuse, we need a second
|
|
|
|
* socket to get replies from perfused.
|
|
|
|
* XXX This socket is not removed at exit time yet
|
|
|
|
*/
|
|
|
|
sock_len = 0;
|
|
|
|
sa = (struct sockaddr *)(void *)&ss;
|
2010-09-20 11:00:21 +04:00
|
|
|
sun = (struct sockaddr_un *)(void *)&ss;
|
2010-09-15 05:51:43 +04:00
|
|
|
sa_len = sizeof(ss);
|
|
|
|
if ((getpeername(s, sa, &sa_len) == 0) &&
|
|
|
|
(sa->sa_family = AF_LOCAL) &&
|
2010-09-20 11:00:21 +04:00
|
|
|
(strcmp(sun->sun_path, _PATH_FUSE) == 0)) {
|
2010-09-15 05:51:43 +04:00
|
|
|
|
2010-09-20 11:00:21 +04:00
|
|
|
sun->sun_len = sizeof(*sun);
|
|
|
|
sun->sun_family = AF_LOCAL;
|
|
|
|
(void)sprintf(sun->sun_path, "%s/%s-%d",
|
2010-09-15 05:51:43 +04:00
|
|
|
_PATH_TMP, getprogname(), getpid());
|
|
|
|
|
2010-09-20 11:00:21 +04:00
|
|
|
if (bind(s, sa, (socklen_t)sa->sa_len) != 0)
|
2010-09-15 05:51:43 +04:00
|
|
|
DERR(EX_OSERR, "%s:%d bind to \"%s\" failed",
|
2010-09-20 11:00:21 +04:00
|
|
|
__func__, __LINE__, sun->sun_path);
|
2010-09-15 05:51:43 +04:00
|
|
|
|
2010-09-20 11:00:21 +04:00
|
|
|
sock_len = strlen(sun->sun_path) + 1;
|
2010-09-15 05:51:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
len = sizeof(*pmo);
|
|
|
|
len += source ? (uint32_t)strlen(source) + 1 : 0;
|
|
|
|
len += target ? (uint32_t)strlen(target) + 1 : 0;
|
|
|
|
len += filesystemtype ? (uint32_t)strlen(filesystemtype) + 1 : 0;
|
|
|
|
len += data ? (uint32_t)strlen(data) + 1 : 0;
|
|
|
|
len += sock_len;
|
|
|
|
|
|
|
|
if ((frame = malloc(len)) == NULL) {
|
2010-08-25 11:16:00 +04:00
|
|
|
#ifdef PERFUSE_DEBUG
|
2010-09-07 06:11:04 +04:00
|
|
|
if (perfuse_diagflags & PDF_MISC)
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s:%d malloc failed", __func__, __LINE__);
|
2010-08-25 11:16:00 +04:00
|
|
|
#endif
|
|
|
|
return -1;
|
|
|
|
}
|
2010-09-15 05:51:43 +04:00
|
|
|
|
|
|
|
pmo = (struct perfuse_mount_out *)(void *)frame;
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
pmo->pmo_len = (uint32_t)len;
|
2010-09-15 05:51:43 +04:00
|
|
|
pmo->pmo_error = 0;
|
|
|
|
pmo->pmo_unique = (uint64_t)-1;
|
|
|
|
(void)strcpy(pmo->pmo_magic, PERFUSE_MOUNT_MAGIC);
|
|
|
|
|
|
|
|
pmo->pmo_source_len = source ? (uint32_t)strlen(source) + 1 : 0;
|
|
|
|
pmo->pmo_target_len = target ? (uint32_t)strlen(target) + 1: 0;
|
|
|
|
pmo->pmo_filesystemtype_len =
|
|
|
|
filesystemtype ? (uint32_t)strlen(filesystemtype) + 1 : 0;
|
|
|
|
pmo->pmo_mountflags = (uint32_t)mountflags;
|
|
|
|
pmo->pmo_data_len = data ? (uint32_t)strlen(data) + 1 : 0;
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
pmo->pmo_sock_len = (uint32_t)sock_len;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2010-09-15 05:51:43 +04:00
|
|
|
cp = (char *)(void *)(pmo + 1);
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
if (source) {
|
2010-09-15 05:51:43 +04:00
|
|
|
(void)strcpy(cp, source);
|
|
|
|
cp += pmo->pmo_source_len;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (target) {
|
2010-09-15 05:51:43 +04:00
|
|
|
(void)strcpy(cp, target);
|
|
|
|
cp += pmo->pmo_target_len;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
2010-09-15 05:51:43 +04:00
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
if (filesystemtype) {
|
2010-09-15 05:51:43 +04:00
|
|
|
(void)strcpy(cp, filesystemtype);
|
|
|
|
cp += pmo->pmo_filesystemtype_len;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data) {
|
2010-09-15 05:51:43 +04:00
|
|
|
(void)strcpy(cp, data);
|
|
|
|
cp += pmo->pmo_data_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sock_len != 0) {
|
2010-09-20 11:00:21 +04:00
|
|
|
(void)strcpy(cp, sun->sun_path);
|
2010-09-15 05:51:43 +04:00
|
|
|
cp += pmo->pmo_sock_len;
|
|
|
|
}
|
|
|
|
|
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.
- Set full fsidx in vftstat method
- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build
- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.
- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.
- Update puffs_node cached file size in write method
- Remove unused argument to perfuse_destroy_pn()
2011-04-25 08:54:53 +04:00
|
|
|
if (send(s, frame, len, MSG_NOSIGNAL) != (ssize_t)len) {
|
2010-08-25 11:16:00 +04:00
|
|
|
#ifdef PERFUSE_DEBUG
|
2010-09-15 05:51:43 +04:00
|
|
|
DWARN("%s:%d sendto failed", __func__, __LINE__);
|
2010-08-25 11:16:00 +04:00
|
|
|
#endif
|
2010-09-15 05:51:43 +04:00
|
|
|
return -1;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uint64_t
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_next_unique(struct puffs_usermount *pu)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
|
|
|
|
return ps->ps_unique++;
|
|
|
|
}
|
|
|
|
|
2015-06-19 20:33:20 +03:00
|
|
|
static void
|
|
|
|
updatelimit(const char *func, int lim, const char *name)
|
|
|
|
{
|
|
|
|
struct rlimit rl;
|
|
|
|
|
|
|
|
/* Try infinity but that will fail unless we are root */
|
|
|
|
rl.rlim_cur = RLIM_INFINITY;
|
|
|
|
rl.rlim_max = RLIM_INFINITY;
|
|
|
|
if (setrlimit(lim, &rl) != -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get and set to the maximum allowed */
|
|
|
|
if (getrlimit(lim, &rl) == -1)
|
|
|
|
DERR(EX_OSERR, "%s: getrlimit %s failed", func, name);
|
|
|
|
|
|
|
|
rl.rlim_cur = rl.rlim_max;
|
|
|
|
if (setrlimit(lim, &rl) == -1)
|
|
|
|
DERR(EX_OSERR, "%s: setrlimit %s to %ju failed", func,
|
|
|
|
name, (uintmax_t)rl.rlim_cur);
|
|
|
|
}
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
struct puffs_usermount *
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_init(struct perfuse_callbacks *pc, struct perfuse_mount_info *pmi)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
struct puffs_usermount *pu;
|
|
|
|
struct puffs_ops *pops;
|
2011-05-12 14:32:41 +04:00
|
|
|
const char *source = _PATH_PUFFS;
|
|
|
|
char *fstype;
|
2010-08-25 11:16:00 +04:00
|
|
|
unsigned int puffs_flags;
|
|
|
|
struct puffs_node *pn_root;
|
|
|
|
struct puffs_pathobj *po_root;
|
2011-10-23 09:01:00 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* perfused can grow quite large, let assume there's enough ram ...
|
|
|
|
*/
|
2015-06-19 20:33:20 +03:00
|
|
|
updatelimit(__func__, RLIMIT_DATA, "RLIMIT_DATA");
|
|
|
|
updatelimit(__func__, RLIMIT_AS, "RLIMIT_AS");
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
ps = init_state();
|
2010-08-27 13:58:17 +04:00
|
|
|
ps->ps_owner_uid = pmi->pmi_uid;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2011-05-12 14:32:41 +04:00
|
|
|
if (pmi->pmi_source) {
|
|
|
|
if ((ps->ps_source = strdup(pmi->pmi_source)) == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: strdup failed", __func__);
|
2011-05-12 14:32:41 +04:00
|
|
|
|
|
|
|
source = ps->ps_source;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pmi->pmi_filesystemtype) {
|
|
|
|
size_t len;
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
ps->ps_filesystemtype = strdup(pmi->pmi_filesystemtype);
|
2011-05-12 14:32:41 +04:00
|
|
|
if (ps->ps_filesystemtype == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: strdup failed", __func__);
|
2011-05-12 14:32:41 +04:00
|
|
|
|
|
|
|
len = sizeof("perfuse|") + strlen(ps->ps_filesystemtype) + 1;
|
|
|
|
if ((fstype = malloc(len)) == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: malloc failed", __func__);
|
2011-05-12 14:32:41 +04:00
|
|
|
|
|
|
|
(void)sprintf(fstype, "perfuse|%s", ps->ps_filesystemtype);
|
|
|
|
} else {
|
|
|
|
if ((fstype = strdup("perfuse")) == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: strdup failed", __func__);
|
2011-05-12 14:32:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ps->ps_target = strdup(pmi->pmi_target)) == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: strdup failed", __func__);
|
2011-05-12 14:32:41 +04:00
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
ps->ps_mountflags = pmi->pmi_mountflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some options are forbidden for non root users
|
|
|
|
*/
|
2010-08-27 13:58:17 +04:00
|
|
|
if (ps->ps_owner_uid != 0)
|
2010-08-25 11:16:00 +04:00
|
|
|
ps->ps_mountflags |= MNT_NOSUID|MNT_NODEV;
|
|
|
|
|
|
|
|
PUFFSOP_INIT(pops);
|
|
|
|
PUFFSOP_SET(pops, perfuse, fs, unmount);
|
|
|
|
PUFFSOP_SET(pops, perfuse, fs, statvfs);
|
|
|
|
PUFFSOP_SET(pops, perfuse, fs, sync);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, lookup);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, create);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, mknod);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, open);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, close);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, access);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, getattr);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, setattr);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, poll);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, fsync);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, remove);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, link);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, rename);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, mkdir);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, rmdir);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, symlink);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, readdir);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, readlink);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, reclaim);
|
2018-11-16 05:39:02 +03:00
|
|
|
PUFFSOP_SET(pops, perfuse, node, reclaim2);
|
2010-08-25 11:16:00 +04:00
|
|
|
PUFFSOP_SET(pops, perfuse, node, inactive);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, print);
|
2014-09-03 20:01:45 +04:00
|
|
|
PUFFSOP_SET(pops, perfuse, node, pathconf);
|
2010-08-25 11:16:00 +04:00
|
|
|
PUFFSOP_SET(pops, perfuse, node, advlock);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, read);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, write);
|
2011-06-28 20:19:16 +04:00
|
|
|
#ifdef PUFFS_EXTNAMELEN
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, getextattr);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, setextattr);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, listextattr);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, deleteextattr);
|
|
|
|
#endif /* PUFFS_EXTNAMELEN */
|
2012-04-18 04:57:21 +04:00
|
|
|
#ifdef PUFFS_KFLAG_CACHE_FS_TTL
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, getattr_ttl);
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, setattr_ttl);
|
|
|
|
#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
|
2012-07-21 09:49:42 +04:00
|
|
|
#ifdef PUFFS_SETATTR_FAF
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, write2);
|
|
|
|
#endif /* PUFFS_SETATTR_FAF */
|
2014-08-16 20:28:43 +04:00
|
|
|
#ifdef PUFFS_OPEN_IO_DIRECT
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, open2);
|
|
|
|
#endif /* PUFFS_OPEN_IO_DIRECT */
|
2014-10-31 18:12:15 +03:00
|
|
|
#ifdef PUFFS_HAVE_FALLOCATE
|
|
|
|
PUFFSOP_SET(pops, perfuse, node, fallocate);
|
|
|
|
#endif /* PUFFS_HAVE_FALLOCATE */
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2011-08-09 10:58:33 +04:00
|
|
|
/*
|
2011-10-30 09:11:37 +04:00
|
|
|
* PUFFS_KFLAG_NOCACHE_NAME is required so that we can see changes
|
2012-04-08 19:13:06 +04:00
|
|
|
* done by other machines in networked filesystems. In later
|
|
|
|
* NetBSD releases we use the alternative PUFFS_KFLAG_CACHE_FS_TTL,
|
|
|
|
* which implement name cache with a filesystem-provided TTL.
|
2011-08-09 10:58:33 +04:00
|
|
|
*/
|
2012-04-08 19:13:06 +04:00
|
|
|
#ifdef PUFFS_KFLAG_CACHE_FS_TTL
|
|
|
|
puffs_flags = PUFFS_KFLAG_CACHE_FS_TTL;
|
|
|
|
#else
|
2011-10-30 09:11:37 +04:00
|
|
|
puffs_flags = PUFFS_KFLAG_NOCACHE_NAME;
|
2012-04-08 19:13:06 +04:00
|
|
|
#endif
|
2012-08-10 20:49:35 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not lookuo ..
|
|
|
|
* That means we keep all parent vnode active
|
|
|
|
*/
|
|
|
|
#ifdef PUFFS_KFLAG_CACHE_DOTDOT
|
|
|
|
puffs_flags |= PUFFS_KFLAG_CACHE_DOTDOT;
|
|
|
|
#endif
|
2012-04-08 19:13:06 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* It would be nice to avoid useless inactive, and only
|
|
|
|
* get them on file open for writing (PUFFS does
|
|
|
|
* CLOSE/WRITE/INACTIVE, therefore actual close must be
|
|
|
|
* done at INACTIVE time). Unfortunatley, puffs_setback
|
|
|
|
* crashes when called on OPEN, therefore leave it for
|
|
|
|
* another day.
|
|
|
|
*/
|
|
|
|
#ifdef notyet
|
|
|
|
puffs_flags |= PUFFS_FLAG_IAONDEMAND;
|
|
|
|
#endif
|
2010-09-29 12:01:10 +04:00
|
|
|
|
2015-02-15 23:21:29 +03:00
|
|
|
/*
|
|
|
|
* FUSE filesystem do not expect [amc]time and size
|
|
|
|
* updates to be sent by the kernel, they do the
|
|
|
|
* updates on their own after other operations.
|
|
|
|
*/
|
|
|
|
#ifdef PUFFS_KFLAG_NOFLUSH_META
|
|
|
|
puffs_flags |= PUFFS_KFLAG_NOFLUSH_META;
|
|
|
|
#endif
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
if (perfuse_diagflags & PDF_PUFFS)
|
|
|
|
puffs_flags |= PUFFS_FLAG_OPDUMP;
|
|
|
|
|
2011-05-12 14:32:41 +04:00
|
|
|
if ((pu = puffs_init(pops, source, fstype, ps, puffs_flags)) == NULL)
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: puffs_init failed", __func__);
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2012-07-21 09:49:42 +04:00
|
|
|
puffs_setncookiehash(pu, PUFFS_PNODEBUCKETS);
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
ps->ps_pu = pu;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup filesystem root
|
|
|
|
*/
|
2010-10-03 09:46:47 +04:00
|
|
|
pn_root = perfuse_new_pn(pu, "", NULL);
|
2011-10-30 09:11:37 +04:00
|
|
|
PERFUSE_NODE_DATA(pn_root)->pnd_nodeid = FUSE_ROOT_ID;
|
2012-07-21 09:49:42 +04:00
|
|
|
PERFUSE_NODE_DATA(pn_root)->pnd_parent_nodeid = FUSE_ROOT_ID;
|
|
|
|
perfuse_node_cache(ps, pn_root);
|
2010-08-25 11:16:00 +04:00
|
|
|
puffs_setroot(pu, pn_root);
|
|
|
|
ps->ps_fsid = pn_root->pn_va.va_fsid;
|
|
|
|
|
|
|
|
po_root = puffs_getrootpathobj(pu);
|
|
|
|
if ((po_root->po_path = strdup("/")) == NULL)
|
|
|
|
DERRX(EX_OSERR, "perfuse_mount_start() failed");
|
|
|
|
|
|
|
|
po_root->po_len = 1;
|
|
|
|
puffs_path_buildhash(pu, po_root);
|
|
|
|
|
|
|
|
puffs_vattr_null(&pn_root->pn_va);
|
|
|
|
pn_root->pn_va.va_type = VDIR;
|
|
|
|
pn_root->pn_va.va_mode = 0755;
|
2011-10-30 09:11:37 +04:00
|
|
|
pn_root->pn_va.va_fileid = FUSE_ROOT_ID;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
|
|
|
ps->ps_root = pn_root;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Callbacks
|
|
|
|
*/
|
|
|
|
ps->ps_new_msg = pc->pc_new_msg;
|
|
|
|
ps->ps_xchg_msg = pc->pc_xchg_msg;
|
|
|
|
ps->ps_destroy_msg = pc->pc_destroy_msg;
|
|
|
|
ps->ps_get_inhdr = pc->pc_get_inhdr;
|
|
|
|
ps->ps_get_inpayload = pc->pc_get_inpayload;
|
|
|
|
ps->ps_get_outhdr = pc->pc_get_outhdr;
|
|
|
|
ps->ps_get_outpayload = pc->pc_get_outpayload;
|
2011-05-30 18:50:08 +04:00
|
|
|
ps->ps_umount = pc->pc_umount;
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2012-07-21 09:49:42 +04:00
|
|
|
pc->pc_fsreq = *perfuse_fsreq;
|
|
|
|
|
2010-08-25 11:16:00 +04:00
|
|
|
return pu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_setspecific(struct puffs_usermount *pu, void *priv)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
ps->ps_private = priv;
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_getspecific(struct puffs_usermount *pu)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
|
|
|
|
return ps->ps_private;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_inloop(struct puffs_usermount *pu)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
|
|
|
|
return ps->ps_flags & PS_INLOOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_mainloop(struct puffs_usermount *pu)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
|
|
|
|
ps->ps_flags |= PS_INLOOP;
|
2011-05-30 18:50:08 +04:00
|
|
|
if (puffs_mainloop(ps->ps_pu) != 0) {
|
2011-08-14 03:12:15 +04:00
|
|
|
DERR(EX_OSERR, "%s: failed", __func__);
|
2011-05-30 18:50:08 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2010-08-25 11:16:00 +04:00
|
|
|
|
2011-05-30 18:50:08 +04:00
|
|
|
/*
|
|
|
|
* Normal exit after unmount
|
|
|
|
*/
|
|
|
|
return 0;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED0 */
|
|
|
|
uint64_t
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_get_nodeid(struct puffs_usermount *pu, puffs_cookie_t opc)
|
2010-08-25 11:16:00 +04:00
|
|
|
{
|
2011-10-30 09:11:37 +04:00
|
|
|
return PERFUSE_NODE_DATA(opc)->pnd_nodeid;
|
2010-08-25 11:16:00 +04:00
|
|
|
}
|
2010-08-27 13:58:17 +04:00
|
|
|
|
|
|
|
int
|
2012-03-21 14:10:36 +04:00
|
|
|
perfuse_unmount(struct puffs_usermount *pu)
|
2010-08-27 13:58:17 +04:00
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
|
|
|
|
return unmount(ps->ps_target, MNT_FORCE);
|
|
|
|
}
|
2012-07-21 09:49:42 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
perfuse_fsreq(struct puffs_usermount *pu, perfuse_msg_t *pm)
|
|
|
|
{
|
|
|
|
struct perfuse_state *ps;
|
|
|
|
struct fuse_out_header *foh;
|
|
|
|
|
|
|
|
ps = puffs_getspecific(pu);
|
|
|
|
foh = GET_OUTHDR(ps, pm);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There are some operations we may use in a Fire and Forget wey,
|
|
|
|
* because the kernel does not await a reply, but FUSE still
|
|
|
|
* sends a reply. This happens for fsyc, setattr (for metadata
|
|
|
|
* associated with a fsync) and write (for VOP_PUTPAGES). Ignore
|
|
|
|
* if it was fine, warn or abort otherwise.
|
|
|
|
*/
|
|
|
|
switch (foh->error) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case -ENOENT:
|
|
|
|
/* File disapeared during a FAF operation */
|
|
|
|
break;
|
|
|
|
case -ENOTCONN: /* FALLTHROUGH */
|
|
|
|
case -EAGAIN: /* FALLTHROUGH */
|
|
|
|
case -EMSGSIZE:
|
|
|
|
DWARN("operation unique = %"PRId64" failed", foh->unique);
|
|
|
|
break;
|
|
|
|
default:
|
2012-09-10 17:56:18 +04:00
|
|
|
DWARNX("Unexpected frame: unique = %"PRId64", error = %d",
|
|
|
|
foh->unique, foh->error);
|
2012-07-21 09:49:42 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
ps->ps_destroy_msg(pm);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|