Browse Source

Move fuse_session to C++ and make exit flag atomic

fixes
Antonio SJ Musumeci 2 days ago
parent
commit
793ce78f8a
  1. 1
      vendored/libfuse/Makefile
  2. 2
      vendored/libfuse/lib/fuse.cpp
  3. 11
      vendored/libfuse/lib/fuse_i.hpp
  4. 2
      vendored/libfuse/lib/fuse_loop.cpp
  5. 2
      vendored/libfuse/lib/fuse_lowlevel.cpp
  6. 68
      vendored/libfuse/lib/fuse_session.cpp
  7. 9
      vendored/libfuse/lib/helper.c
  8. 1
      vendored/libfuse/lib/mount_bsd.c
  9. 2
      vendored/libfuse/lib/mount_generic.c

1
vendored/libfuse/Makefile

@ -79,7 +79,6 @@ BUILDDIR := build
SRC_C = \
lib/crc32b.c \
lib/fuse_opt.c \
lib/fuse_session.c \
lib/fuse_signals.c \
lib/helper.c \
lib/mount.c

2
vendored/libfuse/lib/fuse.cpp

@ -22,7 +22,7 @@
#include "fuse_cfg.hpp"
#include "fuse_req.hpp"
#include "fuse_dirents.hpp"
#include "fuse_i.h"
#include "fuse_i.hpp"
#include "fuse_kernel.h"
#include "fuse_lowlevel.h"
#include "fuse_opt.h"

11
vendored/libfuse/lib/fuse_i.h → vendored/libfuse/lib/fuse_i.hpp

@ -14,7 +14,7 @@
#include "extern_c.h"
#include <signal.h>
#include <atomic>
/* Simplified fuse_session - fields inlined from former fuse_chan
* Since mergerfs only supports one mount, we collapse the hierarchy:
@ -32,7 +32,7 @@ struct fuse_session
void (*destroy)(void *data);
struct fuse_ll *f;
volatile sig_atomic_t exited;
std::atomic<int> exited;
/* Formerly in fuse_chan - inlined for single-mount simplicity */
int fd; /* /dev/fuse file descriptor */
@ -58,11 +58,4 @@ struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args,
const struct fuse_lowlevel_ops *op,
size_t op_size, void *userdata);
void fuse_kern_unmount(const char *mountpoint, int fd);
int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
EXTERN_C_END

2
vendored/libfuse/lib/fuse_loop.cpp

@ -10,7 +10,7 @@
#include "syslog.hpp"
#include "maintenance_thread.hpp"
#include "fuse_i.h"
#include "fuse_i.hpp"
#include "fuse_kernel.h"
#include "fuse_lowlevel.h"

2
vendored/libfuse/lib/fuse_lowlevel.cpp

@ -16,7 +16,7 @@
#include "fatal.hpp"
#include "fmt/core.h"
#include "fuse_cfg.hpp"
#include "fuse_i.h"
#include "fuse_i.hpp"
#include "fuse_kernel.h"
#include "fuse_msgbuf.hpp"
#include "fuse_opt.h"

68
vendored/libfuse/lib/fuse_session.c → vendored/libfuse/lib/fuse_session.cpp

@ -4,16 +4,16 @@
This program can be distributed under the terms of the GNU LGPLv2.
See the file COPYING.LIB
*/
*/
#include "fuse_i.h"
#include "fuse_i.hpp"
#include "fuse_kernel.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <cassert>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unistd.h>
#include <sys/uio.h>
@ -30,19 +30,19 @@ fuse_session_new(void *data,
void *process_buf,
void *destroy)
{
struct fuse_session *se = (struct fuse_session *) malloc(sizeof(*se));
if (se == NULL) {
fprintf(stderr, "fuse: failed to allocate session\n");
return NULL;
}
memset(se, 0, sizeof(*se));
se->f = data;
se->receive_buf = receive_buf;
se->process_buf = process_buf;
se->destroy = destroy;
se->fd = -1; /* Not yet mounted */
//se->bufsize = 0;
auto *se = new(std::nothrow) fuse_session();
if(se == nullptr)
{
fprintf(stderr, "fuse: failed to allocate session\n");
return nullptr;
}
se->f = static_cast<struct fuse_ll*>(data);
se->receive_buf = reinterpret_cast<int(*)(struct fuse_session*, fuse_msgbuf_t*)>(receive_buf);
se->process_buf = reinterpret_cast<void(*)(struct fuse_session*, const fuse_msgbuf_t*)>(process_buf);
se->destroy = reinterpret_cast<void(*)(void*)>(destroy);
se->fd = -1;
return se;
}
@ -50,12 +50,16 @@ fuse_session_new(void *data,
void
fuse_session_destroy(struct fuse_session *se)
{
se->destroy(se->f);
if(se->fd != -1) {
close(se->fd);
se->fd = -1;
}
free(se);
if(se->destroy)
se->destroy(se->f);
if(se->fd != -1)
{
close(se->fd);
se->fd = -1;
}
delete se;
}
void
@ -103,3 +107,15 @@ fuse_session_setbufsize(struct fuse_session *se,
{
se->bufsize = bufsize;
}
int
fuse_session_fd(struct fuse_session *se)
{
return se->fd;
}
size_t
fuse_session_bufsize(struct fuse_session *se)
{
return se->bufsize;
}

9
vendored/libfuse/lib/helper.c

@ -6,7 +6,7 @@
See the file COPYING.LIB.
*/
#include "fuse_i.h"
#include "fuse.h"
#include "fuse_opt.h"
#include "fuse_lowlevel.h"
@ -19,6 +19,9 @@
#include <errno.h>
#include <sys/param.h>
int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
void fuse_kern_unmount(const char *mountpoint, int fd);
enum {
KEY_HELP,
KEY_HELP_NOHEADER,
@ -312,10 +315,10 @@ struct fuse *fuse_setup(int argc,
static void fuse_teardown_common(char *mountpoint)
{
struct fuse_session *se = fuse_get_session();
int fd = se ? se->fd : -1;
int fd = se ? fuse_session_fd(se) : -1;
fuse_remove_signal_handlers(se);
if (mountpoint && fd != -1) {
se->fd = -1;
fuse_session_clearfd(se);
fuse_kern_unmount(mountpoint, fd);
}
free(mountpoint);

1
vendored/libfuse/lib/mount_bsd.c

@ -6,7 +6,6 @@
See the file COPYING.LIB.
*/
#include "fuse_i.h"
#include "fuse_opt.h"
#include <sys/stat.h>

2
vendored/libfuse/lib/mount_generic.c

@ -6,7 +6,6 @@
See the file COPYING.LIB.
*/
#include "fuse_i.h"
#include "fuse_opt.h"
#include "mount_util.h"
@ -19,6 +18,7 @@
#include <errno.h>
#include <poll.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <sys/wait.h>
#include <sys/mount.h>

Loading…
Cancel
Save