mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-21 15:36:31 -05:00
node.cpp
This commit is contained in:
parent
c33ef49cdf
commit
95e62e6a98
14 changed files with 44 additions and 85 deletions
|
|
@ -62,11 +62,7 @@ BUILDDIR := build
|
|||
SRC_C = \
|
||||
lib/buffer.c \
|
||||
lib/crc32b.c \
|
||||
lib/fuse_opt.c \
|
||||
lib/fuse_session.c \
|
||||
lib/fuse_signals.c \
|
||||
lib/helper.c \
|
||||
lib/mount.c
|
||||
lib/fuse_opt.c
|
||||
SRC_CXX = $(wildcard lib/*.cpp)
|
||||
|
||||
OBJS := $(SRC_C:lib/%.c=$(BUILDDIR)/.objs/%.c.o)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
#include "extern_c.h"
|
||||
#include "fuse_common.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_req.h"
|
||||
#include "fuse_req.hpp"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
|
|
@ -13,3 +13,6 @@ struct fuse_req_t
|
|||
struct fuse_chan *ch;
|
||||
unsigned int ioctl_64bit : 1;
|
||||
};
|
||||
|
||||
fuse_req_t* fuse_req_alloc();
|
||||
void fuse_req_free(fuse_req_t *);
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
#define _GNU_SOURCE
|
||||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
|
|
|||
|
|
@ -20,11 +20,11 @@
|
|||
#include "node.hpp"
|
||||
|
||||
#include "fuse_cfg.hpp"
|
||||
#include "fuse_req.h"
|
||||
#include "fuse_req.hpp"
|
||||
#include "fuse_dirents.hpp"
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
#include "fuse_opt.h"
|
||||
#include "fuse_pollhandle.h"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
|
|
@ -3638,15 +3638,6 @@ metrics_log_nodes_info(FILE *file_)
|
|||
|
||||
sizeof_node = sizeof(node_t);
|
||||
|
||||
lfmp_t *lfmp;
|
||||
lfmp = node_lfmp();
|
||||
lfmp_lock(lfmp);
|
||||
node_slab_count = fmp_slab_count(&lfmp->fmp);
|
||||
node_usage_ratio = fmp_slab_usage_ratio(&lfmp->fmp);
|
||||
node_avail_objs = fmp_avail_objs(&lfmp->fmp);
|
||||
node_total_alloc_mem = fmp_total_allocated_memory(&lfmp->fmp);
|
||||
lfmp_unlock(lfmp);
|
||||
|
||||
snprintf(buf,sizeof(buf),
|
||||
"time: %s\n"
|
||||
"sizeof(node): %" PRIu64 "\n"
|
||||
|
|
@ -3763,7 +3754,6 @@ void
|
|||
fuse_gc()
|
||||
{
|
||||
SysLog::info("running thorough garbage collection");
|
||||
node_gc();
|
||||
msgbuf_gc();
|
||||
fuse_malloc_trim();
|
||||
}
|
||||
|
|
@ -3772,7 +3762,6 @@ void
|
|||
fuse_gc1()
|
||||
{
|
||||
SysLog::info("running basic garbage collection");
|
||||
node_gc1();
|
||||
msgbuf_gc_10percent();
|
||||
fuse_malloc_trim();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "fuse.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
#include "fuse_msgbuf_t.h"
|
||||
|
||||
#include "extern_c.h"
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
|
||||
#include "fuse_cfg.hpp"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
|
|
|
|||
|
|
@ -38,10 +38,10 @@ fuse_session_new(void *data,
|
|||
}
|
||||
|
||||
memset(se, 0, sizeof(*se));
|
||||
se->f = data;
|
||||
se->receive_buf = receive_buf;
|
||||
se->process_buf = process_buf;
|
||||
se->destroy = destroy;
|
||||
se->f = (fuse_ll*)data;
|
||||
se->receive_buf = (int(*)(fuse_session*,fuse_msgbuf_t*))receive_buf;
|
||||
se->process_buf = (void(*)(fuse_session*,const fuse_msgbuf_t*))process_buf;
|
||||
se->destroy = (void(*)(void*))destroy;
|
||||
|
||||
return se;
|
||||
}
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
See the file COPYING.LIB
|
||||
*/
|
||||
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_opt.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
#include "fuse_lowlevel.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -53,7 +53,7 @@ fuse_helper_opt_proc(void *data,
|
|||
int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
struct helper_opts *hopts = data;
|
||||
struct helper_opts *hopts = (helper_opts*)data;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
|
|
@ -282,7 +282,7 @@ fuse_setup_common(int argc,
|
|||
if (res == -1)
|
||||
goto err_unmount;
|
||||
|
||||
res = fuse_set_signal_handlers(fuse_get_session(fuse));
|
||||
res = fuse_set_signal_handlers(fuse_get_session());
|
||||
if (res == -1)
|
||||
goto err_unmount;
|
||||
|
||||
|
|
@ -188,7 +188,7 @@ set_mount_flag(const char *s,
|
|||
static int fuse_mount_opt_proc(void *data, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
struct mount_opts *mo = data;
|
||||
struct mount_opts *mo = (mount_opts*)data;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
|
|
@ -426,11 +426,11 @@ static int fuse_mount_sys(const char *mnt, struct mount_opts *mo,
|
|||
if (res == -1)
|
||||
goto out_close;
|
||||
|
||||
source = malloc((mo->fsname ? strlen(mo->fsname) : 0) +
|
||||
(mo->subtype ? strlen(mo->subtype) : 0) +
|
||||
strlen(devname) + 32);
|
||||
source = (char*)malloc((mo->fsname ? strlen(mo->fsname) : 0) +
|
||||
(mo->subtype ? strlen(mo->subtype) : 0) +
|
||||
strlen(devname) + 32);
|
||||
|
||||
type = malloc((mo->subtype ? strlen(mo->subtype) : 0) + 32);
|
||||
type = (char*)malloc((mo->subtype ? strlen(mo->subtype) : 0) + 32);
|
||||
if (!type || !source) {
|
||||
fprintf(stderr, "fuse: failed to allocate memory\n");
|
||||
goto out_close;
|
||||
|
|
|
|||
|
|
@ -1,60 +1,35 @@
|
|||
#include "node.hpp"
|
||||
|
||||
#include "lfmp.h"
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
|
||||
static lfmp_t g_NODE_FMP;
|
||||
|
||||
static
|
||||
__attribute__((constructor))
|
||||
void
|
||||
node_constructor()
|
||||
struct stack_t
|
||||
{
|
||||
lfmp_init(&g_NODE_FMP,sizeof(node_t),256);
|
||||
}
|
||||
stack_t *next;
|
||||
};
|
||||
|
||||
static
|
||||
__attribute__((destructor))
|
||||
void
|
||||
node_destructor()
|
||||
{
|
||||
lfmp_destroy(&g_NODE_FMP);
|
||||
}
|
||||
thread_local static stack_t *g_stack = NULL;
|
||||
|
||||
node_t*
|
||||
node_alloc()
|
||||
{
|
||||
return (node_t*)lfmp_calloc(&g_NODE_FMP);
|
||||
if(g_stack == NULL)
|
||||
return (node_t*)calloc(1,sizeof(node_t));
|
||||
|
||||
node_t *node;
|
||||
|
||||
node = (node_t*)g_stack;
|
||||
g_stack = g_stack->next;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
void
|
||||
node_free(node_t *node_)
|
||||
{
|
||||
lfmp_free(&g_NODE_FMP,node_);
|
||||
}
|
||||
stack_t *stack;
|
||||
|
||||
int
|
||||
node_gc1()
|
||||
{
|
||||
return lfmp_gc(&g_NODE_FMP);
|
||||
}
|
||||
|
||||
void
|
||||
node_gc()
|
||||
{
|
||||
int rv;
|
||||
int fails;
|
||||
|
||||
fails = 0;
|
||||
do
|
||||
{
|
||||
rv = node_gc1();
|
||||
if(rv == 0)
|
||||
fails++;
|
||||
} while(rv || (fails < 3));
|
||||
}
|
||||
|
||||
lfmp_t*
|
||||
node_lfmp()
|
||||
{
|
||||
return &g_NODE_FMP;
|
||||
stack = (stack_t*)node_;
|
||||
stack->next = g_stack;
|
||||
g_stack = stack;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "lock.h"
|
||||
#include "lfmp.h"
|
||||
|
||||
typedef struct node_s node_t;
|
||||
struct node_s
|
||||
typedef struct node_t node_t;
|
||||
struct node_t
|
||||
{
|
||||
node_t *name_next;
|
||||
node_t *id_next;
|
||||
|
|
@ -26,6 +25,3 @@ struct node_s
|
|||
|
||||
node_t *node_alloc();
|
||||
void node_free(node_t*);
|
||||
int node_gc1();
|
||||
void node_gc();
|
||||
lfmp_t *node_lfmp();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue