2016-10-05 09:33:37 -04:00
|
|
|
/*
|
|
|
|
|
FUSE: Filesystem in Userspace
|
|
|
|
|
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
|
|
|
|
|
|
|
|
|
This program can be distributed under the terms of the GNU LGPLv2.
|
|
|
|
|
See the file COPYING.LIB
|
|
|
|
|
*/
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
#ifndef _GNU_SOURCE
|
2016-10-05 09:33:37 -04:00
|
|
|
#define _GNU_SOURCE
|
2024-04-15 19:12:08 -05:00
|
|
|
#endif
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-08-05 00:39:52 -04:00
|
|
|
#include "syslog.hpp"
|
|
|
|
|
|
2021-09-30 23:28:54 -04:00
|
|
|
#include "crc32b.h"
|
2026-02-12 23:50:38 -05:00
|
|
|
#include "debug.hpp"
|
2026-04-18 01:00:11 -04:00
|
|
|
#include "fatal.hpp"
|
2021-08-30 07:59:21 -04:00
|
|
|
#include "kvec.h"
|
2025-05-26 00:44:39 -05:00
|
|
|
#include "mutex.hpp"
|
|
|
|
|
#include "node.hpp"
|
2026-04-18 01:00:11 -04:00
|
|
|
#include "xalloc.hpp"
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2025-10-24 08:20:29 -05:00
|
|
|
#include "fuse_cfg.hpp"
|
2026-02-13 20:26:26 -06:00
|
|
|
#include "fuse_req.hpp"
|
2025-09-24 00:51:21 -04:00
|
|
|
#include "fuse_dirents.hpp"
|
2026-03-20 11:03:54 -05:00
|
|
|
#include "fuse_i.hpp"
|
2021-10-11 22:47:59 -04:00
|
|
|
#include "fuse_kernel.h"
|
2016-10-05 09:33:37 -04:00
|
|
|
#include "fuse_lowlevel.h"
|
2021-10-11 22:47:59 -04:00
|
|
|
#include "fuse_opt.h"
|
2022-11-12 22:26:26 -05:00
|
|
|
#include "fuse_pollhandle.h"
|
2023-02-26 15:16:18 -05:00
|
|
|
#include "fuse_msgbuf.hpp"
|
2026-05-04 19:24:12 -05:00
|
|
|
#include "stat_utils.h"
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-07-05 17:05:53 -05:00
|
|
|
#include "maintenance_thread.hpp"
|
|
|
|
|
|
2025-01-09 20:10:35 -05:00
|
|
|
#include <string>
|
2025-07-05 17:05:53 -05:00
|
|
|
#include <vector>
|
2025-01-09 20:10:35 -05:00
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
#include <assert.h>
|
|
|
|
|
#include <errno.h>
|
2016-10-05 09:33:37 -04:00
|
|
|
#include <fcntl.h>
|
2022-12-08 22:04:15 -05:00
|
|
|
#include <inttypes.h>
|
2016-10-05 09:33:37 -04:00
|
|
|
#include <limits.h>
|
|
|
|
|
#include <poll.h>
|
2019-09-30 18:45:58 -04:00
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <sys/file.h>
|
2025-06-05 23:47:42 -05:00
|
|
|
#include <sys/ioctl.h>
|
2016-10-05 09:33:37 -04:00
|
|
|
#include <sys/param.h>
|
|
|
|
|
#include <sys/time.h>
|
2019-09-30 18:45:58 -04:00
|
|
|
#include <sys/uio.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
#include <unistd.h>
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-08-05 00:39:52 -04:00
|
|
|
#ifdef __GLIBC__
|
2021-08-30 07:59:21 -04:00
|
|
|
#include <malloc.h>
|
2016-10-05 09:33:37 -04:00
|
|
|
#endif
|
|
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
#define FUSE_UNKNOWN_INO UINT64_MAX
|
2016-10-05 09:33:37 -04:00
|
|
|
#define OFFSET_MAX 0x7fffffffffffffffLL
|
|
|
|
|
|
2026-02-24 22:22:20 -06:00
|
|
|
#define PATH_BUFSIZE_HALF_MAX 0x80000000u
|
|
|
|
|
#define PATH_BUFSIZE_MAX 0xffffffffu
|
|
|
|
|
|
|
|
|
|
#define INFO_FILE_MAX_SIZE (1024 * 1024)
|
|
|
|
|
|
2016-10-05 09:33:37 -04:00
|
|
|
#define NODE_TABLE_MIN_SIZE 8192
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
#define PARAM(inarg) ((void*)(((char*)(inarg)) + sizeof(*(inarg))))
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
struct lock_queue_element
|
|
|
|
|
{
|
|
|
|
|
struct lock_queue_element *next;
|
|
|
|
|
pthread_cond_t cond;
|
2021-09-30 23:28:54 -04:00
|
|
|
uint64_t nodeid1;
|
2020-07-31 23:50:47 -04:00
|
|
|
const char *name1;
|
|
|
|
|
char **path1;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **wnode1;
|
2021-09-30 23:28:54 -04:00
|
|
|
uint64_t nodeid2;
|
2020-07-31 23:50:47 -04:00
|
|
|
const char *name2;
|
|
|
|
|
char **path2;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **wnode2;
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
|
|
|
|
bool done : 1;
|
2016-10-05 09:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
struct node_table
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **array;
|
|
|
|
|
size_t use;
|
|
|
|
|
size_t size;
|
|
|
|
|
size_t split;
|
2016-10-05 09:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
struct list_head
|
|
|
|
|
{
|
|
|
|
|
struct list_head *next;
|
|
|
|
|
struct list_head *prev;
|
2016-10-05 09:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
2021-09-30 23:28:54 -04:00
|
|
|
typedef struct nodeid_gen_t nodeid_gen_t;
|
|
|
|
|
struct nodeid_gen_t
|
|
|
|
|
{
|
|
|
|
|
uint64_t nodeid;
|
|
|
|
|
uint64_t generation;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
struct fuse
|
|
|
|
|
{
|
|
|
|
|
struct fuse_session *se;
|
|
|
|
|
struct node_table name_table;
|
|
|
|
|
struct node_table id_table;
|
2021-09-30 23:28:54 -04:00
|
|
|
nodeid_gen_t nodeid_gen;
|
2019-09-30 18:45:58 -04:00
|
|
|
unsigned int hidectr;
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_t lock;
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_operations ops;
|
2019-09-30 18:45:58 -04:00
|
|
|
struct lock_queue_element *lockq;
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2016-10-05 09:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#define TREELOCK_WRITE -1
|
|
|
|
|
#define TREELOCK_WAIT_OFFSET INT_MIN
|
|
|
|
|
|
2019-06-14 08:59:04 -04:00
|
|
|
struct fuse_dh
|
|
|
|
|
{
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_t lock;
|
|
|
|
|
uint64_t fh;
|
|
|
|
|
fuse_dirents_t d;
|
2016-10-05 09:33:37 -04:00
|
|
|
};
|
|
|
|
|
|
2025-10-29 22:42:42 -05:00
|
|
|
static struct fuse f = {};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2021-09-30 23:28:54 -04:00
|
|
|
/*
|
|
|
|
|
Why was the nodeid:generation logic simplified?
|
|
|
|
|
|
|
|
|
|
nodeid is uint64_t: max value of 18446744073709551616
|
|
|
|
|
If nodes were created at a rate of 1048576 per second it would take
|
|
|
|
|
over 500 thousand years to roll over. I'm fine with risking that.
|
2025-10-13 00:21:36 -04:00
|
|
|
*/
|
2021-09-30 23:28:54 -04:00
|
|
|
static
|
|
|
|
|
uint64_t
|
|
|
|
|
generate_nodeid(nodeid_gen_t *ng_)
|
|
|
|
|
{
|
|
|
|
|
ng_->nodeid++;
|
|
|
|
|
|
|
|
|
|
return ng_->nodeid;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
static
|
|
|
|
|
void*
|
|
|
|
|
fuse_hdr_arg(const struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
return (void*)&hdr_[1];
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
static
|
|
|
|
|
size_t
|
2025-10-13 00:21:36 -04:00
|
|
|
id_hash(uint64_t ino)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
uint64_t hash = ((uint32_t)ino * 2654435761U) % f.id_table.size;
|
|
|
|
|
uint64_t oldhash = hash % (f.id_table.size / 2);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(oldhash >= f.id_table.split)
|
2020-07-31 23:50:47 -04:00
|
|
|
return oldhash;
|
|
|
|
|
else
|
|
|
|
|
return hash;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
static
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t*
|
2026-04-18 01:00:11 -04:00
|
|
|
get_node(const uint64_t nodeid)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
size_t hash = id_hash(nodeid);
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
for(node = f.id_table.array[hash]; node != NULL; node = node->id_next)
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node->nodeid == nodeid)
|
2020-07-31 23:50:47 -04:00
|
|
|
return node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return NULL;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2021-09-30 23:28:54 -04:00
|
|
|
static
|
|
|
|
|
uint32_t
|
|
|
|
|
stat_crc32b(const struct stat *st_)
|
|
|
|
|
{
|
|
|
|
|
uint32_t crc;
|
2026-05-04 19:24:12 -05:00
|
|
|
const auto mtimensec = ST_MTIM_NSEC(st_);
|
|
|
|
|
const auto ctimensec = ST_CTIM_NSEC(st_);
|
2021-09-30 23:28:54 -04:00
|
|
|
|
|
|
|
|
crc = crc32b_start();
|
2026-05-04 19:24:12 -05:00
|
|
|
/* st_dev is not exposed by FUSE attr replies, but the underlying value
|
|
|
|
|
is still useful as a proxy for whether the backing stat source changed. */
|
|
|
|
|
crc = crc32b_continue(&st_->st_dev,sizeof(st_->st_dev),crc);
|
2021-09-30 23:28:54 -04:00
|
|
|
crc = crc32b_continue(&st_->st_ino,sizeof(st_->st_ino),crc);
|
|
|
|
|
crc = crc32b_continue(&st_->st_size,sizeof(st_->st_size),crc);
|
2026-05-04 19:24:12 -05:00
|
|
|
crc = crc32b_continue(&st_->st_mtime,sizeof(st_->st_mtime),crc);
|
|
|
|
|
crc = crc32b_continue(&mtimensec,sizeof(mtimensec),crc);
|
|
|
|
|
crc = crc32b_continue(&st_->st_ctime,sizeof(st_->st_ctime),crc);
|
|
|
|
|
crc = crc32b_continue(&ctimensec,sizeof(ctimensec),crc);
|
2021-09-30 23:28:54 -04:00
|
|
|
crc = crc32b_finish(crc);
|
|
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
/* 0 is reserved to mean "no valid stat cache fingerprint". */
|
|
|
|
|
return (crc ? crc : UINT32_MAX);
|
2021-09-30 23:28:54 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-21 22:57:02 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
free_node(node_t *node_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
free(node_->name);
|
2019-05-21 22:57:02 -04:00
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
node_free(node_);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
node_table_reduce(struct node_table *t)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t newsize = t->size / 2;
|
|
|
|
|
void *newarray;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(newsize < NODE_TABLE_MIN_SIZE)
|
2020-07-31 23:50:47 -04:00
|
|
|
return;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
newarray = realloc(t->array,sizeof(node_t*) * newsize);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(newarray == NULL)
|
|
|
|
|
return;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
t->array = (node_t**)newarray;
|
|
|
|
|
t->size = newsize;
|
2020-07-31 23:50:47 -04:00
|
|
|
t->split = t->size / 2;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
remerge_id()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
struct node_table *t = &f.id_table;
|
2020-07-31 23:50:47 -04:00
|
|
|
int iter;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(t->split == 0)
|
2020-07-31 23:50:47 -04:00
|
|
|
node_table_reduce(t);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(iter = 8; t->split > 0 && iter; iter--)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **upper;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
t->split--;
|
|
|
|
|
upper = &t->array[t->split + t->size / 2];
|
|
|
|
|
if(*upper)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **nodep;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(nodep = &t->array[t->split]; *nodep;
|
|
|
|
|
nodep = &(*nodep)->id_next);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
*nodep = *upper;
|
|
|
|
|
*upper = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unhash_id(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
node_t **nodep = &f.id_table.array[id_hash(node->nodeid)];
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(; *nodep != NULL; nodep = &(*nodep)->id_next)
|
|
|
|
|
if(*nodep == node)
|
|
|
|
|
{
|
|
|
|
|
*nodep = node->id_next;
|
2025-10-13 00:21:36 -04:00
|
|
|
f.id_table.use--;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(f.id_table.use < (f.id_table.size / 4))
|
|
|
|
|
remerge_id();
|
2020-11-15 19:12:33 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
node_table_resize(struct node_table *t)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t newsize = t->size * 2;
|
|
|
|
|
void *newarray;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
newarray = realloc(t->array,sizeof(node_t*) * newsize);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(newarray == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
return -1;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
t->array = (node_t**)newarray;
|
2023-04-23 23:33:48 -04:00
|
|
|
memset(t->array + t->size,0,t->size * sizeof(node_t*));
|
2020-07-31 23:50:47 -04:00
|
|
|
t->size = newsize;
|
|
|
|
|
t->split = 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
rehash_id()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
struct node_table *t = &f.id_table;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **nodep;
|
|
|
|
|
node_t **next;
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t hash;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(t->split == t->size / 2)
|
2020-07-31 23:50:47 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
hash = t->split;
|
|
|
|
|
t->split++;
|
2020-11-15 19:12:33 -05:00
|
|
|
for(nodep = &t->array[hash]; *nodep != NULL; nodep = next)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node = *nodep;
|
2025-10-13 00:21:36 -04:00
|
|
|
size_t newhash = id_hash(node->nodeid);
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
if(newhash != hash)
|
|
|
|
|
{
|
|
|
|
|
next = nodep;
|
|
|
|
|
*nodep = node->id_next;
|
|
|
|
|
node->id_next = t->array[newhash];
|
|
|
|
|
t->array[newhash] = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next = &node->id_next;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
if(t->split == t->size / 2)
|
2020-07-31 23:50:47 -04:00
|
|
|
node_table_resize(t);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
hash_id(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
size_t hash;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
hash = id_hash(node->nodeid);
|
|
|
|
|
node->id_next = f.id_table.array[hash];
|
|
|
|
|
f.id_table.array[hash] = node;
|
|
|
|
|
f.id_table.use++;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(f.id_table.use >= (f.id_table.size / 2))
|
|
|
|
|
rehash_id();
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
size_t
|
2025-10-13 00:21:36 -04:00
|
|
|
name_hash(uint64_t parent,
|
|
|
|
|
const char *name)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
uint64_t hash = parent;
|
|
|
|
|
uint64_t oldhash;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(; *name; name++)
|
|
|
|
|
hash = hash * 31 + (unsigned char)*name;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
hash %= f.name_table.size;
|
|
|
|
|
oldhash = hash % (f.name_table.size / 2);
|
|
|
|
|
if(oldhash >= f.name_table.split)
|
2020-07-31 23:50:47 -04:00
|
|
|
return oldhash;
|
|
|
|
|
else
|
|
|
|
|
return hash;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unref_node(node_t *node);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
remerge_name()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int iter;
|
2025-10-13 00:21:36 -04:00
|
|
|
struct node_table *t = &f.name_table;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(t->split == 0)
|
2020-07-31 23:50:47 -04:00
|
|
|
node_table_reduce(t);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(iter = 8; t->split > 0 && iter; iter--)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **upper;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
t->split--;
|
|
|
|
|
upper = &t->array[t->split + t->size / 2];
|
|
|
|
|
if(*upper)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **nodep;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
for(nodep = &t->array[t->split]; *nodep; nodep = &(*nodep)->name_next);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
*nodep = *upper;
|
|
|
|
|
*upper = NULL;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unhash_name(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
if(not (node && node->name && node->parent))
|
|
|
|
|
return;
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
size_t hash = name_hash(node->parent->nodeid,node->name);
|
|
|
|
|
node_t **nodep = &f.name_table.array[hash];
|
|
|
|
|
|
|
|
|
|
for(; *nodep != NULL; nodep = &(*nodep)->name_next)
|
|
|
|
|
{
|
|
|
|
|
if(*nodep != node)
|
|
|
|
|
continue;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
*nodep = node->name_next;
|
|
|
|
|
node->name_next = NULL;
|
|
|
|
|
unref_node(node->parent);
|
|
|
|
|
free(node->name);
|
|
|
|
|
node->name = NULL;
|
|
|
|
|
node->parent = NULL;
|
|
|
|
|
f.name_table.use--;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
if(f.name_table.use < f.name_table.size / 4)
|
|
|
|
|
remerge_name();
|
|
|
|
|
return;
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2026-04-18 01:00:11 -04:00
|
|
|
|
|
|
|
|
fatal::abort("mergerfs: unable to unhash node: {}",
|
|
|
|
|
node->nodeid);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
rehash_name()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
struct node_table *t = &f.name_table;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t **nodep;
|
|
|
|
|
node_t **next;
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t hash;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(t->split == t->size / 2)
|
2020-07-31 23:50:47 -04:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
hash = t->split;
|
|
|
|
|
t->split++;
|
2020-11-15 19:12:33 -05:00
|
|
|
for(nodep = &t->array[hash]; *nodep != NULL; nodep = next)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node = *nodep;
|
2026-04-18 01:00:11 -04:00
|
|
|
if(node->parent == NULL)
|
|
|
|
|
{
|
|
|
|
|
next = &node->name_next;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
size_t newhash = name_hash(node->parent->nodeid,node->name);
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
if(newhash != hash)
|
|
|
|
|
{
|
|
|
|
|
next = nodep;
|
|
|
|
|
*nodep = node->name_next;
|
|
|
|
|
node->name_next = t->array[newhash];
|
|
|
|
|
t->array[newhash] = node;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
next = &node->name_next;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
if(t->split == t->size / 2)
|
2020-07-31 23:50:47 -04:00
|
|
|
node_table_resize(t);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
hash_name(node_t *node,
|
|
|
|
|
uint64_t parentid,
|
|
|
|
|
const char *name)
|
|
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
size_t hash;
|
|
|
|
|
node_t *parent;
|
|
|
|
|
|
|
|
|
|
hash = name_hash(parentid,name);
|
|
|
|
|
parent = get_node(parentid);
|
|
|
|
|
|
|
|
|
|
if(parent == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
node->name = strdup(name);
|
2021-10-28 23:01:47 -04:00
|
|
|
if(node->name == NULL)
|
|
|
|
|
return -1;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2021-08-30 07:59:21 -04:00
|
|
|
parent->refctr++;
|
2020-07-31 23:50:47 -04:00
|
|
|
node->parent = parent;
|
2025-10-13 00:21:36 -04:00
|
|
|
node->name_next = f.name_table.array[hash];
|
|
|
|
|
f.name_table.array[hash] = node;
|
|
|
|
|
f.name_table.use++;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(f.name_table.use >= f.name_table.size / 2)
|
|
|
|
|
rehash_name();
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2021-08-30 07:59:21 -04:00
|
|
|
static
|
|
|
|
|
inline
|
2026-05-05 16:01:55 -05:00
|
|
|
bool
|
2025-10-13 00:21:36 -04:00
|
|
|
remember_nodes()
|
2021-08-30 07:59:21 -04:00
|
|
|
{
|
2026-05-05 16:01:55 -05:00
|
|
|
return fuse_cfg.remember_nodes;
|
2021-08-30 07:59:21 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
delete_node(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
assert(node->treelock == 0);
|
2025-10-13 00:21:36 -04:00
|
|
|
unhash_name(node);
|
|
|
|
|
unhash_id(node);
|
2023-04-23 23:33:48 -04:00
|
|
|
node_free(node);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unref_node(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
assert(node->refctr > 0);
|
2020-11-15 19:12:33 -05:00
|
|
|
node->refctr--;
|
|
|
|
|
if(!node->refctr)
|
2025-10-13 00:21:36 -04:00
|
|
|
delete_node(node);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
static
|
|
|
|
|
uint64_t
|
|
|
|
|
rand64(void)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-09-30 18:45:58 -04:00
|
|
|
uint64_t rv;
|
|
|
|
|
|
|
|
|
|
rv = rand();
|
|
|
|
|
rv <<= 32;
|
|
|
|
|
rv |= rand();
|
|
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t*
|
2025-10-13 00:21:36 -04:00
|
|
|
lookup_node(uint64_t parent,
|
|
|
|
|
const char *name)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
size_t hash;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
hash = name_hash(parent,name);
|
|
|
|
|
for(node = f.name_table.array[hash]; node != NULL; node = node->name_next)
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node->parent->nodeid == parent && strcmp(node->name,name) == 0)
|
2020-07-31 23:50:47 -04:00
|
|
|
return node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return NULL;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2023-04-23 23:33:48 -04:00
|
|
|
inc_nlookup(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!node->nlookup)
|
2020-07-31 23:50:47 -04:00
|
|
|
node->refctr++;
|
|
|
|
|
node->nlookup++;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
remember_node(node_t *node)
|
|
|
|
|
{
|
|
|
|
|
if(node->remembered)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
inc_nlookup(node);
|
|
|
|
|
node->remembered = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
unref_node_if_unused(node_t *node)
|
|
|
|
|
{
|
|
|
|
|
if((node->nlookup == 0) &&
|
|
|
|
|
(node->open_count == 0) &&
|
|
|
|
|
(node->treelock == 0))
|
|
|
|
|
unref_node(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
unremember_node(node_t *node)
|
|
|
|
|
{
|
|
|
|
|
if(!node->remembered)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
assert(node->nlookup > 0);
|
|
|
|
|
node->remembered = false;
|
|
|
|
|
node->nlookup--;
|
|
|
|
|
unref_node_if_unused(node);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t*
|
2025-10-13 00:21:36 -04:00
|
|
|
find_node(uint64_t parent,
|
2026-05-05 16:01:55 -05:00
|
|
|
const char *name,
|
|
|
|
|
bool remember)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2026-04-18 01:00:11 -04:00
|
|
|
mutex_lockguard(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!name)
|
2026-04-18 01:00:11 -04:00
|
|
|
{
|
|
|
|
|
node = get_node(parent);
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
goto out_err;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2026-04-18 01:00:11 -04:00
|
|
|
{
|
|
|
|
|
node = lookup_node(parent,name);
|
|
|
|
|
}
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node == NULL)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node = node_alloc();
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node == NULL)
|
|
|
|
|
goto out_err;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
node->nodeid = generate_nodeid(&f.nodeid_gen);
|
2026-05-05 16:01:55 -05:00
|
|
|
if(remember && remember_nodes())
|
|
|
|
|
remember_node(node);
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(hash_name(node,parent,name) == -1)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
free_node(node);
|
2020-11-15 19:12:33 -05:00
|
|
|
node = NULL;
|
|
|
|
|
goto out_err;
|
|
|
|
|
}
|
2025-10-13 00:21:36 -04:00
|
|
|
hash_id(node);
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
|
|
|
|
inc_nlookup(node);
|
2026-04-18 01:00:11 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
out_err:
|
|
|
|
|
return node;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
char*
|
|
|
|
|
add_name(char **buf,
|
|
|
|
|
unsigned *bufsize,
|
|
|
|
|
char *s,
|
|
|
|
|
const char *name)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t len = strlen(name);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(s - len <= *buf)
|
|
|
|
|
{
|
|
|
|
|
unsigned pathlen = *bufsize - (s - *buf);
|
|
|
|
|
unsigned newbufsize = *bufsize;
|
|
|
|
|
char *newbuf;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
while(newbufsize < pathlen + len + 1)
|
|
|
|
|
{
|
2026-02-24 22:22:20 -06:00
|
|
|
if(newbufsize >= PATH_BUFSIZE_HALF_MAX)
|
|
|
|
|
newbufsize = PATH_BUFSIZE_MAX;
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
|
|
|
|
newbufsize *= 2;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
newbuf = (char*)realloc(*buf,newbufsize);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(newbuf == NULL)
|
|
|
|
|
return NULL;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
*buf = newbuf;
|
|
|
|
|
s = newbuf + newbufsize - pathlen;
|
|
|
|
|
memmove(s,newbuf + *bufsize - pathlen,pathlen);
|
|
|
|
|
*bufsize = newbufsize;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
s -= len;
|
2020-11-15 19:12:33 -05:00
|
|
|
strncpy(s,name,len);
|
2020-07-31 23:50:47 -04:00
|
|
|
s--;
|
|
|
|
|
*s = '/';
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return s;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unlock_path(uint64_t nodeid,
|
|
|
|
|
node_t *wnode,
|
|
|
|
|
node_t *end)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(wnode)
|
|
|
|
|
{
|
|
|
|
|
assert(wnode->treelock == TREELOCK_WRITE);
|
|
|
|
|
wnode->treelock = 0;
|
2026-05-05 16:01:55 -05:00
|
|
|
/* unlink_node() can drop the retained lookup while the node is locked. */
|
|
|
|
|
unref_node_if_unused(wnode);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
node = get_node(nodeid);
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for(;node != end && node->nodeid != FUSE_ROOT_ID;
|
2025-10-13 00:21:36 -04:00
|
|
|
node = node->parent)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
assert(node->treelock != 0);
|
|
|
|
|
assert(node->treelock != TREELOCK_WAIT_OFFSET);
|
|
|
|
|
assert(node->treelock != TREELOCK_WRITE);
|
|
|
|
|
node->treelock--;
|
|
|
|
|
if(node->treelock == TREELOCK_WAIT_OFFSET)
|
|
|
|
|
node->treelock = 0;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
/*
|
|
|
|
|
Throughout this file all calls to the op.func() callbacks will be
|
|
|
|
|
'&fusepath[1]' because the current path generation always prefixes a
|
|
|
|
|
'/' for each path but we need a relative path for usage with
|
|
|
|
|
`openat()` functions and would rather do that here than in the
|
|
|
|
|
called function.
|
2025-10-13 00:21:36 -04:00
|
|
|
*/
|
2025-09-17 23:51:16 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
try_get_path(uint64_t nodeid,
|
2020-11-15 19:12:33 -05:00
|
|
|
const char *name,
|
|
|
|
|
char **path,
|
2025-09-17 23:51:16 -04:00
|
|
|
node_t **wnodep,
|
2020-11-15 19:12:33 -05:00
|
|
|
bool need_lock)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
unsigned bufsize = 256;
|
|
|
|
|
char *buf;
|
|
|
|
|
char *s;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
|
|
|
|
node_t *wnode = NULL;
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
|
|
|
|
|
|
|
|
|
*path = NULL;
|
|
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
2024-04-15 19:12:08 -05:00
|
|
|
buf = (char*)malloc(bufsize);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(buf == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_err;
|
|
|
|
|
|
|
|
|
|
s = buf + bufsize - 1;
|
|
|
|
|
*s = '\0';
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(name != NULL)
|
|
|
|
|
{
|
|
|
|
|
s = add_name(&buf,&bufsize,s,name);
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
if(s == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(wnodep)
|
|
|
|
|
{
|
|
|
|
|
assert(need_lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
wnode = lookup_node(nodeid,name);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(wnode)
|
|
|
|
|
{
|
|
|
|
|
if(wnode->treelock != 0)
|
|
|
|
|
{
|
|
|
|
|
if(wnode->treelock > 0)
|
|
|
|
|
wnode->treelock += TREELOCK_WAIT_OFFSET;
|
|
|
|
|
err = -EAGAIN;
|
|
|
|
|
goto out_free;
|
|
|
|
|
}
|
|
|
|
|
wnode->treelock = TREELOCK_WRITE;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
node = get_node(nodeid);
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
{
|
|
|
|
|
err = -ESTALE;
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(; node->nodeid != FUSE_ROOT_ID; node = node->parent)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2022-03-20 12:09:22 -04:00
|
|
|
err = -ESTALE;
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node->name == NULL || node->parent == NULL)
|
|
|
|
|
goto out_unlock;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
err = -ENOMEM;
|
|
|
|
|
s = add_name(&buf,&bufsize,s,node->name);
|
|
|
|
|
if(s == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_unlock;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(need_lock)
|
|
|
|
|
{
|
|
|
|
|
err = -EAGAIN;
|
|
|
|
|
if(node->treelock < 0)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
|
|
|
|
|
node->treelock++;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(s[0])
|
|
|
|
|
memmove(buf,s,bufsize - (s - buf));
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2020-11-15 19:12:33 -05:00
|
|
|
strcpy(buf,"/");
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
*path = buf;
|
2020-11-15 19:12:33 -05:00
|
|
|
if(wnodep)
|
2020-07-31 23:50:47 -04:00
|
|
|
*wnodep = wnode;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
|
|
|
|
out_unlock:
|
2020-11-15 19:12:33 -05:00
|
|
|
if(need_lock)
|
2025-10-13 00:21:36 -04:00
|
|
|
unlock_path(nodeid,wnode,node);
|
2016-10-05 09:33:37 -04:00
|
|
|
out_free:
|
2020-07-31 23:50:47 -04:00
|
|
|
free(buf);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
|
|
|
|
out_err:
|
2020-07-31 23:50:47 -04:00
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
2023-01-28 01:17:07 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
try_get_path2(uint64_t nodeid1,
|
|
|
|
|
const char *name1,
|
|
|
|
|
uint64_t nodeid2,
|
|
|
|
|
const char *name2,
|
|
|
|
|
char **path1,
|
|
|
|
|
char **path2,
|
|
|
|
|
node_t **wnode1,
|
|
|
|
|
node_t **wnode2)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-01-28 01:17:07 -05:00
|
|
|
int err;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path(nodeid1,name1,path1,wnode1,true);
|
2023-01-28 01:17:07 -05:00
|
|
|
if(!err)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path(nodeid2,name2,path2,wnode2,true);
|
2023-01-28 01:17:07 -05:00
|
|
|
if(err)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *wn1 = wnode1 ? *wnode1 : NULL;
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
unlock_path(nodeid1,wn1,NULL);
|
2023-01-28 01:17:07 -05:00
|
|
|
free(*path1);
|
|
|
|
|
}
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2023-01-28 01:17:07 -05:00
|
|
|
|
|
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
queue_element_wakeup(struct lock_queue_element *qe)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!qe->path1)
|
|
|
|
|
{
|
|
|
|
|
/* Just waiting for it to be unlocked */
|
2026-04-18 01:00:11 -04:00
|
|
|
node_t *qnode = get_node(qe->nodeid1);
|
|
|
|
|
if(qnode && (qnode->treelock == 0))
|
2020-11-15 19:12:33 -05:00
|
|
|
pthread_cond_signal(&qe->cond);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2023-01-28 01:17:07 -05:00
|
|
|
if(qe->done)
|
|
|
|
|
return;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2023-01-28 01:17:07 -05:00
|
|
|
if(!qe->path2)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path(qe->nodeid1,
|
2023-01-28 01:17:07 -05:00
|
|
|
qe->name1,
|
|
|
|
|
qe->path1,
|
|
|
|
|
qe->wnode1,
|
|
|
|
|
true);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2023-01-28 01:17:07 -05:00
|
|
|
else
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path2(qe->nodeid1,
|
2023-01-28 01:17:07 -05:00
|
|
|
qe->name1,
|
|
|
|
|
qe->nodeid2,
|
|
|
|
|
qe->name2,
|
|
|
|
|
qe->path1,
|
|
|
|
|
qe->path2,
|
|
|
|
|
qe->wnode1,
|
|
|
|
|
qe->wnode2);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2023-01-28 01:17:07 -05:00
|
|
|
if(err == -EAGAIN)
|
|
|
|
|
return;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
qe->err = err;
|
|
|
|
|
qe->done = true;
|
|
|
|
|
pthread_cond_signal(&qe->cond);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
wake_up_queued()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
struct lock_queue_element *qe;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
for(qe = f.lockq; qe != NULL; qe = qe->next)
|
|
|
|
|
queue_element_wakeup(qe);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
queue_path(struct lock_queue_element *qe)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
struct lock_queue_element **qp;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
qe->done = false;
|
2020-11-15 19:12:33 -05:00
|
|
|
pthread_cond_init(&qe->cond,NULL);
|
2020-07-31 23:50:47 -04:00
|
|
|
qe->next = NULL;
|
2025-10-13 00:21:36 -04:00
|
|
|
for(qp = &f.lockq; *qp != NULL; qp = &(*qp)->next);
|
2020-07-31 23:50:47 -04:00
|
|
|
*qp = qe;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
dequeue_path(struct lock_queue_element *qe)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
struct lock_queue_element **qp;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
pthread_cond_destroy(&qe->cond);
|
2025-10-13 00:21:36 -04:00
|
|
|
for(qp = &f.lockq; *qp != qe; qp = &(*qp)->next);
|
2020-07-31 23:50:47 -04:00
|
|
|
*qp = qe->next;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
wait_path(struct lock_queue_element *qe)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
queue_path(qe);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
do
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
pthread_cond_wait(&qe->cond,&f.lock);
|
2020-11-15 19:12:33 -05:00
|
|
|
} while(!qe->done);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
dequeue_path(qe);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return qe->err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
get_path_common(uint64_t nodeid,
|
|
|
|
|
const char *name,
|
|
|
|
|
char **path,
|
|
|
|
|
node_t **wnode)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path(nodeid,name,path,wnode,true);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(err == -EAGAIN)
|
|
|
|
|
{
|
2025-10-29 22:42:42 -05:00
|
|
|
struct lock_queue_element qe = {};
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
qe.nodeid1 = nodeid;
|
|
|
|
|
qe.name1 = name;
|
|
|
|
|
qe.path1 = path;
|
|
|
|
|
qe.wnode1 = wnode;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = wait_path(&qe);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
get_path(uint64_t nodeid,
|
|
|
|
|
char **path)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
return get_path_common(nodeid,NULL,path,NULL);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
get_path_name(uint64_t nodeid,
|
|
|
|
|
const char *name,
|
|
|
|
|
char **path)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
return get_path_common(nodeid,name,path,NULL);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
get_path_wrlock(uint64_t nodeid,
|
|
|
|
|
const char *name,
|
|
|
|
|
char **path,
|
|
|
|
|
node_t **wnode)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
return get_path_common(nodeid,name,path,wnode);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
get_path2(uint64_t nodeid1,
|
|
|
|
|
const char *name1,
|
|
|
|
|
uint64_t nodeid2,
|
|
|
|
|
const char *name2,
|
|
|
|
|
char **path1,
|
|
|
|
|
char **path2,
|
|
|
|
|
node_t **wnode1,
|
|
|
|
|
node_t **wnode2)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
|
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
err = try_get_path2(nodeid1,name1,nodeid2,name2,
|
2020-11-15 19:12:33 -05:00
|
|
|
path1,path2,wnode1,wnode2);
|
|
|
|
|
if(err == -EAGAIN)
|
|
|
|
|
{
|
2025-10-29 22:42:42 -05:00
|
|
|
struct lock_queue_element qe = {};
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
qe.nodeid1 = nodeid1;
|
|
|
|
|
qe.name1 = name1;
|
|
|
|
|
qe.path1 = path1;
|
|
|
|
|
qe.wnode1 = wnode1;
|
|
|
|
|
qe.nodeid2 = nodeid2;
|
|
|
|
|
qe.name2 = name2;
|
|
|
|
|
qe.path2 = path2;
|
|
|
|
|
qe.wnode2 = wnode2;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = wait_path(&qe);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path_wrlock(uint64_t nodeid,
|
|
|
|
|
node_t *wnode,
|
|
|
|
|
char *path)
|
|
|
|
|
{
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
unlock_path(nodeid,wnode,NULL);
|
|
|
|
|
if(f.lockq)
|
|
|
|
|
wake_up_queued();
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
free(path);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
update_stat(node_t *node_,
|
|
|
|
|
const struct stat *stnew_)
|
|
|
|
|
{
|
|
|
|
|
uint32_t crc32b;
|
|
|
|
|
|
|
|
|
|
// This function can only invalidate an existing fingerprint; it
|
|
|
|
|
// never arms a new one. Arming (writing a non-zero CRC into
|
|
|
|
|
// state_crc32b) happens exclusively in open_auto_cache(), which is
|
|
|
|
|
// the single point that decides a file's page cache is worth
|
|
|
|
|
// retaining across opens. If stat_crc32b is 0 here the cache is
|
|
|
|
|
// already considered invalid and we have nothing to compare
|
|
|
|
|
// against.
|
|
|
|
|
if(node_->stat_crc32b == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
crc32b = stat_crc32b(stnew_);
|
|
|
|
|
|
|
|
|
|
if(crc32b != node_->stat_crc32b)
|
|
|
|
|
node_->stat_crc32b = 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(uint64_t nodeid,
|
|
|
|
|
char *path)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
if(path)
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path_wrlock(nodeid,NULL,path);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
static
|
|
|
|
|
node_t*
|
|
|
|
|
free_path_and_inc_open(u64 free_nodeid_,
|
|
|
|
|
char *path_,
|
|
|
|
|
u64 inc_open_ino_,
|
|
|
|
|
bool remember_too_)
|
|
|
|
|
{
|
|
|
|
|
node_t *node;
|
|
|
|
|
|
|
|
|
|
mutex_lock(f.lock);
|
|
|
|
|
|
|
|
|
|
unlock_path(free_nodeid_,NULL,NULL);
|
|
|
|
|
node = get_node(inc_open_ino_);
|
|
|
|
|
if(node)
|
|
|
|
|
{
|
|
|
|
|
if(remember_too_ && remember_nodes())
|
|
|
|
|
remember_node(node);
|
|
|
|
|
node->open_count++;
|
|
|
|
|
}
|
|
|
|
|
if(f.lockq)
|
|
|
|
|
wake_up_queued();
|
|
|
|
|
|
|
|
|
|
mutex_unlock(f.lock);
|
|
|
|
|
free(path_);
|
|
|
|
|
|
|
|
|
|
return node;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
bool
|
|
|
|
|
free_path_and_update_stat(u64 nodeid_,
|
|
|
|
|
char *path_,
|
|
|
|
|
const struct stat *stnew_)
|
|
|
|
|
{
|
|
|
|
|
bool ok;
|
|
|
|
|
node_t *node;
|
|
|
|
|
|
|
|
|
|
mutex_lock(f.lock);
|
|
|
|
|
|
|
|
|
|
unlock_path(nodeid_,NULL,NULL);
|
|
|
|
|
node = get_node(nodeid_);
|
|
|
|
|
ok = (node != NULL);
|
|
|
|
|
if(ok)
|
|
|
|
|
update_stat(node,stnew_);
|
|
|
|
|
if(f.lockq)
|
|
|
|
|
wake_up_queued();
|
|
|
|
|
|
|
|
|
|
mutex_unlock(f.lock);
|
|
|
|
|
free(path_);
|
|
|
|
|
|
|
|
|
|
return ok;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path2(uint64_t nodeid1,
|
|
|
|
|
uint64_t nodeid2,
|
|
|
|
|
node_t *wnode1,
|
|
|
|
|
node_t *wnode2,
|
|
|
|
|
char *path1,
|
|
|
|
|
char *path2)
|
|
|
|
|
{
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
unlock_path(nodeid1,wnode1,NULL);
|
|
|
|
|
unlock_path(nodeid2,wnode2,NULL);
|
|
|
|
|
wake_up_queued();
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
free(path1);
|
|
|
|
|
free(path2);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
forget_node(const uint64_t nodeid,
|
|
|
|
|
const uint64_t nlookup)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
if(nodeid == FUSE_ROOT_ID)
|
|
|
|
|
return;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
mutex_lockguard(f.lock);
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
node = get_node(nodeid);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(node == NULL)
|
|
|
|
|
return;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
/*
|
|
|
|
|
* Node may still be locked due to interrupt idiocy in open,
|
|
|
|
|
* create and opendir
|
|
|
|
|
*/
|
|
|
|
|
while(node->nlookup == nlookup && node->treelock)
|
|
|
|
|
{
|
2025-10-29 22:42:42 -05:00
|
|
|
struct lock_queue_element qe = {};
|
2020-11-15 19:12:33 -05:00
|
|
|
|
|
|
|
|
qe.nodeid1 = nodeid;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
queue_path(&qe);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
do
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
pthread_cond_wait(&qe.cond,&f.lock);
|
2019-09-30 18:45:58 -04:00
|
|
|
}
|
|
|
|
|
while((node->nlookup == nlookup) && node->treelock);
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
dequeue_path(&qe);
|
2019-09-30 18:45:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
assert(node->nlookup >= nlookup);
|
|
|
|
|
node->nlookup -= nlookup;
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
unref_node_if_unused(node);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
unlink_node(node_t *node)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
unhash_name(node);
|
2026-05-05 16:01:55 -05:00
|
|
|
unremember_node(node);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
remove_node(uint64_t dir,
|
|
|
|
|
const char *name)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
node = lookup_node(dir,name);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node != NULL)
|
2025-10-13 00:21:36 -04:00
|
|
|
unlink_node(node);
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
rename_node(uint64_t olddir,
|
|
|
|
|
const char *oldname,
|
|
|
|
|
uint64_t newdir,
|
|
|
|
|
const char *newname)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
int err = 0;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
|
|
|
|
node_t *newnode;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
node = lookup_node(olddir,oldname);
|
|
|
|
|
newnode = lookup_node(newdir,newname);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(node == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
if((newnode != NULL) && (newnode != node))
|
2025-10-13 00:21:36 -04:00
|
|
|
unlink_node(newnode);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
unhash_name(node);
|
|
|
|
|
if(hash_name(node,newdir,newname) == -1)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
|
goto out;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
out:
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
set_stat(uint64_t nodeid,
|
2020-11-15 19:12:33 -05:00
|
|
|
struct stat *stbuf)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-24 08:20:29 -05:00
|
|
|
if(fuse_cfg.valid_uid())
|
|
|
|
|
stbuf->st_uid = fuse_cfg.uid;
|
|
|
|
|
if(fuse_cfg.valid_gid())
|
|
|
|
|
stbuf->st_gid = fuse_cfg.gid;
|
|
|
|
|
if(fuse_cfg.valid_umask())
|
|
|
|
|
stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~fuse_cfg.umask);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
2019-03-03 23:26:20 -05:00
|
|
|
int
|
2023-04-23 23:33:48 -04:00
|
|
|
node_open(const node_t *node_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
return ((node_ != NULL) && (node_->open_count > 0));
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
static
|
2026-05-13 08:24:03 -05:00
|
|
|
int
|
|
|
|
|
set_path_info(uint64_t nodeid_,
|
|
|
|
|
const char *name_,
|
|
|
|
|
struct fuse_entry_param *e_,
|
|
|
|
|
bool remember_ = true)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2026-05-13 08:24:03 -05:00
|
|
|
node_t *node;
|
2021-09-30 23:28:54 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
mutex_lock(f.lock);
|
2021-09-30 23:28:54 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
if(!name_)
|
|
|
|
|
{
|
|
|
|
|
node = get_node(nodeid_);
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node = lookup_node(nodeid_,name_);
|
|
|
|
|
}
|
2019-05-23 23:22:36 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
if(node == NULL)
|
|
|
|
|
{
|
|
|
|
|
node = node_alloc();
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
goto out_unlock;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
node->nodeid = generate_nodeid(&f.nodeid_gen);
|
|
|
|
|
if(remember_ && remember_nodes())
|
|
|
|
|
remember_node(node);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
if(hash_name(node,nodeid_,name_) == -1)
|
|
|
|
|
{
|
|
|
|
|
free_node(node);
|
|
|
|
|
node = NULL;
|
|
|
|
|
goto out_unlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hash_id(node);
|
|
|
|
|
}
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
inc_nlookup(node);
|
|
|
|
|
|
|
|
|
|
e_->ino = node->nodeid;
|
|
|
|
|
e_->generation = ((e_->ino == FUSE_ROOT_ID) ? 0 : f.nodeid_gen.generation);
|
|
|
|
|
|
|
|
|
|
update_stat(node,&e_->attr);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
set_stat(e_->ino,&e_->attr);
|
2020-06-21 14:45:14 -04:00
|
|
|
|
|
|
|
|
return 0;
|
2026-05-13 08:24:03 -05:00
|
|
|
|
|
|
|
|
out_unlock:
|
|
|
|
|
mutex_unlock(f.lock);
|
|
|
|
|
|
|
|
|
|
return -ENOMEM;
|
2020-06-21 14:45:14 -04:00
|
|
|
}
|
|
|
|
|
|
2024-02-25 17:03:47 -06:00
|
|
|
/*
|
|
|
|
|
lookup requests only come in for FUSE_ROOT_ID when a "parent of
|
|
|
|
|
child of root node" request is made. This can happen when using
|
|
|
|
|
EXPORT_SUPPORT=true and a file handle is used to keep a reference to
|
|
|
|
|
a node which has been forgotten. Mostly a NFS concern but not
|
|
|
|
|
excluslively. Root node always has a nodeid of 1 and generation of
|
|
|
|
|
0. To ensure this set_path_info() explicitly ensures the root id has
|
|
|
|
|
a generation of 0.
|
2025-10-13 00:21:36 -04:00
|
|
|
*/
|
2019-09-24 10:27:46 -04:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
lookup_path(fuse_req_t *req_,
|
2021-09-30 23:28:54 -04:00
|
|
|
uint64_t nodeid,
|
2019-09-24 10:27:46 -04:00
|
|
|
const char *name,
|
2025-09-17 23:51:16 -04:00
|
|
|
const char *fusepath,
|
2019-09-24 10:27:46 -04:00
|
|
|
struct fuse_entry_param *e,
|
2026-05-05 16:01:55 -05:00
|
|
|
fuse_file_info_t *fi,
|
|
|
|
|
bool remember = true)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
int rv;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
assert(req_ != NULL);
|
|
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
memset(e,0,sizeof(struct fuse_entry_param));
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-06-21 14:45:14 -04:00
|
|
|
rv = ((fi == NULL) ?
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.getattr(&req_->ctx,&fusepath[1],&e->attr,&e->timeout) :
|
|
|
|
|
f.ops.fgetattr(&req_->ctx,fi->fh,&e->attr,&e->timeout));
|
2019-09-24 10:27:46 -04:00
|
|
|
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv)
|
|
|
|
|
return rv;
|
2019-09-24 10:27:46 -04:00
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
return set_path_info(nodeid,name,e,remember);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(fuse_req_t *req_,
|
2020-11-15 19:12:33 -05:00
|
|
|
const struct fuse_entry_param *e,
|
|
|
|
|
int err)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
if(fuse_reply_entry(req_,e) == -ENOENT)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
/* Skip forget for negative result */
|
|
|
|
|
if(e->ino != 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
forget_node(e->ino,1);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2026-04-18 00:59:52 -04:00
|
|
|
fuse_lib_init(fuse_conn_info_t *conn)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.init(conn);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2026-04-18 00:59:52 -04:00
|
|
|
fuse_lib_destroy()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.destroy();
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_lookup(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-09-24 10:27:46 -04:00
|
|
|
int err;
|
2022-11-12 22:26:26 -05:00
|
|
|
uint64_t nodeid;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *dot = NULL;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct fuse_entry_param e = {};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
nodeid = hdr_->nodeid;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(name[0] == '.')
|
|
|
|
|
{
|
2021-08-30 07:59:21 -04:00
|
|
|
if(name[1] == '\0')
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2021-08-30 07:59:21 -04:00
|
|
|
name = NULL;
|
2026-04-18 01:00:11 -04:00
|
|
|
mutex_lockguard(f.lock);
|
|
|
|
|
dot = get_node(nodeid);
|
2021-08-30 07:59:21 -04:00
|
|
|
if(dot == NULL)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,-ESTALE);
|
2021-08-30 07:59:21 -04:00
|
|
|
return;
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2021-08-30 07:59:21 -04:00
|
|
|
dot->refctr++;
|
|
|
|
|
}
|
|
|
|
|
else if((name[1] == '.') && (name[2] == '\0'))
|
|
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
if(nodeid == FUSE_ROOT_ID)
|
2022-04-07 13:39:20 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,-ENOENT);
|
2022-04-07 13:39:20 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
name = NULL;
|
2026-04-18 01:00:11 -04:00
|
|
|
mutex_lockguard(f.lock);
|
|
|
|
|
{
|
|
|
|
|
node_t *pnode = get_node(nodeid);
|
|
|
|
|
if((pnode == NULL) || (pnode->parent == NULL))
|
|
|
|
|
{
|
|
|
|
|
reply_entry(req_,&e,-ESTALE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
nodeid = pnode->parent->nodeid;
|
|
|
|
|
}
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_name(nodeid,name,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = lookup_path(req_,nodeid,name,fusepath,&e,NULL);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(err == -ENOENT)
|
|
|
|
|
{
|
|
|
|
|
e.ino = 0;
|
|
|
|
|
err = 0;
|
|
|
|
|
}
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(nodeid,fusepath);
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(dot)
|
|
|
|
|
{
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
unref_node(dot);
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2021-08-30 07:59:21 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-08 00:00:53 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_lseek(fuse_req_t *req_,
|
2025-05-08 00:00:53 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOSYS);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-30 18:45:58 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_forget(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_forget_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_forget_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
forget_node(hdr_->nodeid,arg->nlookup);
|
2022-11-27 22:23:38 -06:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_none(req_);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_forget_multi(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_batch_forget_in *arg;
|
|
|
|
|
struct fuse_forget_one *entry;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_batch_forget_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
entry = (fuse_forget_one*)PARAM(arg);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
for(uint32_t i = 0; i < arg->count; i++)
|
2023-04-23 23:33:48 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
forget_node(entry[i].nodeid,
|
|
|
|
|
entry[i].nlookup);
|
2023-04-23 23:33:48 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_none(req_);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_getattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-09-24 10:27:46 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2025-06-05 23:47:42 -05:00
|
|
|
uint64_t fh;
|
2019-09-24 10:27:46 -04:00
|
|
|
struct stat buf;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2026-03-10 19:29:13 -05:00
|
|
|
fuse_timeouts_t timeouts{};
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_getattr_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_getattr_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-06-05 23:47:42 -05:00
|
|
|
fh = 0;
|
2022-11-12 22:26:26 -05:00
|
|
|
if(arg->getattr_flags & FUSE_GETATTR_FH)
|
2025-06-05 23:47:42 -05:00
|
|
|
fh = arg->fh;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
memset(&buf,0,sizeof(buf));
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2020-07-08 19:25:23 -04:00
|
|
|
err = 0;
|
2025-09-17 23:51:16 -04:00
|
|
|
fusepath = NULL;
|
2025-06-05 23:47:42 -05:00
|
|
|
if(fh == 0)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2025-06-05 23:47:42 -05:00
|
|
|
if(err == -ESTALE) // unlinked but open
|
|
|
|
|
err = 0;
|
|
|
|
|
}
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2019-09-24 10:27:46 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-13 08:24:03 -05:00
|
|
|
bool node_ok = true;
|
2026-04-18 01:00:11 -04:00
|
|
|
if(fusepath != NULL)
|
2026-05-13 08:24:03 -05:00
|
|
|
{
|
|
|
|
|
err = f.ops.getattr(&req_->ctx,&fusepath[1],&buf,&timeouts);
|
|
|
|
|
if(!err)
|
|
|
|
|
node_ok = free_path_and_update_stat(hdr_->nodeid,fusepath,&buf);
|
|
|
|
|
else
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
|
|
|
|
}
|
2026-04-18 01:00:11 -04:00
|
|
|
else
|
2026-05-13 08:24:03 -05:00
|
|
|
{
|
|
|
|
|
err = f.ops.fgetattr(&req_->ctx,fh,&buf,&timeouts);
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
|
|
|
|
mutex_lockguard(f.lock);
|
|
|
|
|
node = get_node(hdr_->nodeid);
|
|
|
|
|
node_ok = (node != NULL);
|
|
|
|
|
if(node_ok)
|
|
|
|
|
update_stat(node,&buf);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-09-24 10:27:46 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
if(!err && !node_ok)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ESTALE);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
set_stat(hdr_->nodeid,&buf);
|
2026-03-10 19:29:13 -05:00
|
|
|
fuse_reply_attr(req_,&buf,timeouts.attr);
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2019-09-24 10:27:46 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2025-03-30 18:06:30 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statx_path(fuse_req_t *req_,
|
2025-03-30 18:06:30 -05:00
|
|
|
struct fuse_in_header *hdr_,
|
|
|
|
|
fuse_statx_in *inarg_)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
char *fusepath;
|
|
|
|
|
struct fuse_statx st{};
|
|
|
|
|
fuse_timeouts_t timeouts{};
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2026-04-28 09:07:27 -05:00
|
|
|
if(err == -ESTALE)
|
|
|
|
|
err = 0;
|
2025-03-30 18:06:30 -05:00
|
|
|
if(err)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-28 09:07:27 -05:00
|
|
|
if(fusepath != NULL)
|
|
|
|
|
err = f.ops.statx(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
inarg_->sx_flags,
|
|
|
|
|
inarg_->sx_mask,
|
|
|
|
|
&st,
|
|
|
|
|
&timeouts);
|
|
|
|
|
else
|
|
|
|
|
err = f.ops.statx_fh(&req_->ctx,
|
|
|
|
|
0,
|
|
|
|
|
inarg_->sx_flags,
|
|
|
|
|
inarg_->sx_mask,
|
|
|
|
|
&st,
|
|
|
|
|
&timeouts);
|
2025-03-30 18:06:30 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2025-03-30 18:06:30 -05:00
|
|
|
|
|
|
|
|
if(err)
|
|
|
|
|
fuse_reply_err(req_,err);
|
|
|
|
|
else
|
|
|
|
|
fuse_reply_statx(req_,0,&st,timeouts.attr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statx_fh(fuse_req_t *req_,
|
2025-03-30 18:06:30 -05:00
|
|
|
struct fuse_in_header *hdr_,
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_statx_in *inarg_)
|
2025-03-30 18:06:30 -05:00
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
struct fuse_statx st{};
|
|
|
|
|
fuse_timeouts_t timeouts{};
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.statx_fh(&req_->ctx,
|
|
|
|
|
inarg_->fh,
|
|
|
|
|
inarg_->sx_flags,
|
|
|
|
|
inarg_->sx_mask,
|
|
|
|
|
&st,
|
|
|
|
|
&timeouts);
|
2025-03-30 18:06:30 -05:00
|
|
|
|
|
|
|
|
if(err)
|
|
|
|
|
fuse_reply_err(req_,err);
|
|
|
|
|
else
|
|
|
|
|
fuse_reply_statx(req_,0,&st,timeouts.attr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statx(fuse_req_t *req_,
|
2025-03-30 18:06:30 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_statx_in *inarg;
|
|
|
|
|
|
|
|
|
|
inarg = (fuse_statx_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
|
|
|
|
|
if(inarg->getattr_flags & FUSE_GETATTR_FH)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statx_fh(req_,hdr_,inarg);
|
2025-03-30 18:06:30 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statx_path(req_,hdr_,inarg);
|
2025-03-30 18:06:30 -05:00
|
|
|
}
|
|
|
|
|
|
2020-02-10 18:39:15 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_setattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2020-02-10 18:39:15 -05:00
|
|
|
{
|
2025-06-05 23:47:42 -05:00
|
|
|
uint64_t fh;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct stat stbuf = {};
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2020-02-10 18:39:15 -05:00
|
|
|
int err;
|
2026-03-10 19:29:13 -05:00
|
|
|
fuse_timeouts_t timeouts{};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_setattr_in *arg;
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_setattr_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-06-05 23:47:42 -05:00
|
|
|
fh = 0;
|
2022-11-12 22:26:26 -05:00
|
|
|
if(arg->valid & FATTR_FH)
|
2025-06-05 23:47:42 -05:00
|
|
|
fh = arg->fh;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-08 19:25:23 -04:00
|
|
|
err = 0;
|
2025-09-17 23:51:16 -04:00
|
|
|
fusepath = NULL;
|
2025-06-05 23:47:42 -05:00
|
|
|
if(fh == 0)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2025-06-05 23:47:42 -05:00
|
|
|
if(err == -ESTALE)
|
|
|
|
|
err = 0;
|
|
|
|
|
}
|
2020-02-10 18:39:15 -05:00
|
|
|
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
|
|
|
|
err = 0;
|
2022-11-12 22:26:26 -05:00
|
|
|
if(!err && (arg->valid & FATTR_MODE))
|
2025-09-17 23:51:16 -04:00
|
|
|
err = ((fusepath != NULL) ?
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.chmod(&req_->ctx,&fusepath[1],arg->mode) :
|
|
|
|
|
f.ops.fchmod(&req_->ctx,fh,arg->mode));
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(!err && (arg->valid & (FATTR_UID | FATTR_GID)))
|
2020-02-10 18:39:15 -05:00
|
|
|
{
|
2022-11-12 22:26:26 -05:00
|
|
|
uid_t uid = ((arg->valid & FATTR_UID) ? arg->uid : (uid_t)-1);
|
|
|
|
|
gid_t gid = ((arg->valid & FATTR_GID) ? arg->gid : (gid_t)-1);
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
err = ((fusepath != NULL) ?
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.chown(&req_->ctx,&fusepath[1],uid,gid) :
|
|
|
|
|
f.ops.fchown(&req_->ctx,fh,uid,gid));
|
2020-02-10 18:39:15 -05:00
|
|
|
}
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(!err && (arg->valid & FATTR_SIZE))
|
2025-09-17 23:51:16 -04:00
|
|
|
err = ((fusepath != NULL) ?
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.truncate(&req_->ctx,&fusepath[1],arg->size) :
|
|
|
|
|
f.ops.ftruncate(&req_->ctx,fh,arg->size));
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(!err && (arg->valid & (FATTR_ATIME | FATTR_MTIME)))
|
2020-02-10 18:39:15 -05:00
|
|
|
{
|
|
|
|
|
struct timespec tv[2];
|
|
|
|
|
|
|
|
|
|
tv[0].tv_sec = 0;
|
|
|
|
|
tv[1].tv_sec = 0;
|
|
|
|
|
tv[0].tv_nsec = UTIME_OMIT;
|
|
|
|
|
tv[1].tv_nsec = UTIME_OMIT;
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(arg->valid & FATTR_ATIME_NOW)
|
2020-02-10 18:39:15 -05:00
|
|
|
tv[0].tv_nsec = UTIME_NOW;
|
2022-11-12 22:26:26 -05:00
|
|
|
else if(arg->valid & FATTR_ATIME)
|
2025-11-29 17:45:20 +01:00
|
|
|
tv[0] = (struct timespec){ static_cast<time_t>(arg->atime), static_cast<long>(arg->atimensec) };
|
2020-02-10 18:39:15 -05:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(arg->valid & FATTR_MTIME_NOW)
|
2020-02-10 18:39:15 -05:00
|
|
|
tv[1].tv_nsec = UTIME_NOW;
|
2022-11-12 22:26:26 -05:00
|
|
|
else if(arg->valid & FATTR_MTIME)
|
2025-11-29 17:45:20 +01:00
|
|
|
tv[1] = (struct timespec){ static_cast<time_t>(arg->mtime), static_cast<long>(arg->mtimensec) };
|
2020-02-10 18:39:15 -05:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
err = ((fusepath != NULL) ?
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.utimens(&req_->ctx,&fusepath[1],tv) :
|
|
|
|
|
f.ops.futimens(&req_->ctx,fh,tv));
|
2020-02-10 18:39:15 -05:00
|
|
|
}
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-09-17 23:51:16 -04:00
|
|
|
err = ((fusepath != NULL) ?
|
2026-03-10 19:29:13 -05:00
|
|
|
f.ops.getattr(&req_->ctx,&fusepath[1],&stbuf,&timeouts) :
|
|
|
|
|
f.ops.fgetattr(&req_->ctx,fh,&stbuf,&timeouts));
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
bool stat_updated = false;
|
|
|
|
|
if(!err && (fusepath != NULL))
|
|
|
|
|
{
|
2026-11-29 23:10:57 -05:00
|
|
|
// Unlike getattr a vanished node is not turned into ESTALE
|
|
|
|
|
// here, so the helper's result is deliberately ignored.
|
|
|
|
|
free_path_and_update_stat(hdr_->nodeid,fusepath,&stbuf);
|
2026-05-13 08:24:03 -05:00
|
|
|
stat_updated = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
|
|
|
|
}
|
2026-04-18 01:00:11 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
|
|
|
|
if(!stat_updated)
|
|
|
|
|
{
|
|
|
|
|
node_t *node;
|
|
|
|
|
mutex_lockguard(f.lock);
|
|
|
|
|
node = get_node(hdr_->nodeid);
|
|
|
|
|
if(node)
|
|
|
|
|
update_stat(node,&stbuf);
|
|
|
|
|
}
|
2026-04-18 01:00:11 -04:00
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
set_stat(hdr_->nodeid,&stbuf);
|
|
|
|
|
fuse_reply_attr(req_,&stbuf,timeouts.attr);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,err);
|
|
|
|
|
}
|
|
|
|
|
return;
|
2020-02-10 18:39:15 -05:00
|
|
|
}
|
2026-05-13 08:24:03 -05:00
|
|
|
|
|
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2026-05-13 08:24:03 -05:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_access(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_access_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_access_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.access(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mask);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_readlink(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2026-04-24 17:35:47 -05:00
|
|
|
ssize_t rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
char linkname[PATH_MAX + 1];
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-24 17:35:47 -05:00
|
|
|
rv = get_path(hdr_->nodeid,&fusepath);
|
|
|
|
|
if(!rv)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2026-04-24 17:35:47 -05:00
|
|
|
rv = f.ops.readlink(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
linkname,
|
|
|
|
|
sizeof(linkname));
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2026-04-24 17:35:47 -05:00
|
|
|
if(rv >= 0)
|
|
|
|
|
fuse_reply_readlink(req_,linkname,rv);
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
2026-04-24 17:35:47 -05:00
|
|
|
fuse_reply_err(req_,rv);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_mknod(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char* name;
|
|
|
|
|
struct fuse_entry_param e;
|
|
|
|
|
struct fuse_mknod_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_mknod_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
name = (const char*)PARAM(arg);
|
2025-10-13 00:21:36 -04:00
|
|
|
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 12)
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ctx.umask = arg->umask;
|
2022-11-12 22:26:26 -05:00
|
|
|
else
|
|
|
|
|
name = (char*)arg + FUSE_COMPAT_MKNOD_IN_SIZE;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_name(hdr_->nodeid,name,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
|
|
|
|
err = -ENOSYS;
|
2022-11-12 22:26:26 -05:00
|
|
|
if(S_ISREG(arg->mode))
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_file_info_t ffi = {};
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
ffi.flags = O_CREAT | O_EXCL | O_WRONLY;
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.create(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mode,
|
2026-04-18 01:00:11 -04:00
|
|
|
&ffi);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&ffi);
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(&req_->ctx,
|
2026-04-18 01:00:11 -04:00
|
|
|
&ffi);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(err == -ENOSYS)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.mknod(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mode,
|
|
|
|
|
arg->rdev);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,NULL);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_mkdir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
|
|
|
|
struct fuse_entry_param e;
|
|
|
|
|
struct fuse_mkdir_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_mkdir_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
name = (const char*)PARAM(arg);
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 12)
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ctx.umask = arg->umask;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_name(hdr_->nodeid,name,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.mkdir(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mode);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,NULL);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-19 23:25:46 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_unlink(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2019-05-19 23:25:46 -04:00
|
|
|
{
|
|
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *wnode;
|
2019-05-19 23:25:46 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)PARAM(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_wrlock(hdr_->nodeid,name,&fusepath,&wnode);
|
2019-05-19 23:25:46 -04:00
|
|
|
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
2019-05-21 22:57:02 -04:00
|
|
|
if(node_open(wnode))
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ctx.nodeid = wnode->nodeid;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.unlink(&req_->ctx,
|
|
|
|
|
&fusepath[1]);
|
2019-05-21 22:57:02 -04:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
remove_node(hdr_->nodeid,name);
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path_wrlock(hdr_->nodeid,wnode,fusepath);
|
2019-05-19 23:25:46 -04:00
|
|
|
}
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_rmdir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *wnode;
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)PARAM(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_wrlock(hdr_->nodeid,name,&fusepath,&wnode);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.rmdir(&req_->ctx,
|
|
|
|
|
&fusepath[1]);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
remove_node(hdr_->nodeid,name);
|
|
|
|
|
free_path_wrlock(hdr_->nodeid,wnode,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_symlink(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
int rv;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
|
|
|
|
const char *linkname;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct fuse_entry_param e = {};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
linkname = (name + strlen(name) + 1);
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = get_path_name(hdr_->nodeid,name,&fusepath);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = f.ops.symlink(&req_->ctx,
|
|
|
|
|
linkname,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
&e.attr,
|
|
|
|
|
&e.timeout);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = set_path_info(hdr_->nodeid,name,&e);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-06-21 14:45:14 -04:00
|
|
|
reply_entry(req_,&e,rv);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-19 23:25:46 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_rename(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2019-05-19 23:25:46 -04:00
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
char *oldpath;
|
|
|
|
|
char *newpath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *oldname;
|
|
|
|
|
const char *newname;
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *wnode1;
|
|
|
|
|
node_t *wnode2;
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_rename_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_rename_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
oldname = (const char*)PARAM(arg);
|
2022-11-12 22:26:26 -05:00
|
|
|
newname = (oldname + strlen(oldname) + 1);
|
2019-05-19 23:25:46 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path2(hdr_->nodeid,
|
2025-09-17 23:51:16 -04:00
|
|
|
oldname,
|
|
|
|
|
arg->newdir,
|
|
|
|
|
newname,
|
|
|
|
|
&oldpath,
|
|
|
|
|
&newpath,
|
|
|
|
|
&wnode1,
|
|
|
|
|
&wnode2);
|
2019-05-19 23:25:46 -04:00
|
|
|
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.rename(&req_->ctx,
|
|
|
|
|
&oldpath[1],
|
|
|
|
|
&newpath[1]);
|
2019-05-19 23:25:46 -04:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
err = rename_node(hdr_->nodeid,oldname,arg->newdir,newname);
|
2019-05-16 14:38:07 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path2(hdr_->nodeid,arg->newdir,wnode1,wnode2,oldpath,newpath);
|
2019-05-19 23:25:46 -04:00
|
|
|
}
|
2019-05-16 14:38:07 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2025-05-08 00:00:53 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_rename2(fuse_req_t *req_,
|
2025-05-08 00:00:53 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOSYS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_retrieve_reply(fuse_req_t *req_,
|
2025-05-08 00:00:53 -05:00
|
|
|
void *cookie_,
|
|
|
|
|
uint64_t ino_,
|
|
|
|
|
off_t offset_)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-21 14:45:14 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_link(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-06-21 14:45:14 -04:00
|
|
|
int rv;
|
2020-07-31 23:50:47 -04:00
|
|
|
char *oldpath;
|
|
|
|
|
char *newpath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *newname;
|
|
|
|
|
struct fuse_link_in *arg;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct fuse_entry_param e = {};
|
2020-06-21 14:45:14 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_link_in*)fuse_hdr_arg(hdr_);
|
2024-04-15 19:12:08 -05:00
|
|
|
newname = (const char*)PARAM(arg);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = get_path2(arg->oldnodeid,
|
2025-09-17 23:51:16 -04:00
|
|
|
NULL,
|
|
|
|
|
hdr_->nodeid,
|
|
|
|
|
newname,
|
|
|
|
|
&oldpath,
|
|
|
|
|
&newpath,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(!rv)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = f.ops.link(&req_->ctx,
|
|
|
|
|
&oldpath[1],
|
|
|
|
|
&newpath[1],
|
|
|
|
|
&e.attr,
|
|
|
|
|
&e.timeout);
|
2020-06-21 14:45:14 -04:00
|
|
|
if(rv == 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = set_path_info(hdr_->nodeid,newname,&e);
|
|
|
|
|
free_path2(arg->oldnodeid,hdr_->nodeid,NULL,NULL,oldpath,newpath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
reply_entry(req_,&e,rv);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_do_release(fuse_req_ctx_t *req_ctx_,
|
|
|
|
|
uint64_t ino_,
|
|
|
|
|
fuse_file_info_t *ffi_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(req_ctx_,
|
|
|
|
|
ffi_);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
mutex_lockguard(f.lock);
|
2023-04-05 00:28:34 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
node_t *node;
|
|
|
|
|
|
|
|
|
|
node = get_node(ino_);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(node)
|
|
|
|
|
{
|
|
|
|
|
assert(node->open_count > 0);
|
|
|
|
|
node->open_count--;
|
2026-05-05 16:01:55 -05:00
|
|
|
unref_node_if_unused(node);
|
2026-04-18 01:00:11 -04:00
|
|
|
}
|
2023-04-05 00:28:34 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_create(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-05-23 23:22:36 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
2025-06-05 23:47:42 -05:00
|
|
|
uint64_t new_nodeid;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2019-05-23 23:22:36 -04:00
|
|
|
struct fuse_entry_param e;
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_create_in *arg;
|
|
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
arg = (fuse_create_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
name = (const char*)PARAM(arg);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
|
|
|
|
ffi.flags = arg->flags;
|
|
|
|
|
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 12)
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ctx.umask = arg->umask;
|
2022-11-12 22:26:26 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
name = ((char*)arg + sizeof(struct fuse_open_in));
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
// Opportunistically allocate a provisional node so passthrough create has
|
|
|
|
|
// a nodeid. It is remembered only after create fully succeeds.
|
2025-06-05 23:47:42 -05:00
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
node_t *node;
|
|
|
|
|
|
2026-05-05 16:01:55 -05:00
|
|
|
node = find_node(hdr_->nodeid,name,false);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(node == NULL)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOMEM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-05 23:47:42 -05:00
|
|
|
new_nodeid = node->nodeid;
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ctx.nodeid = new_nodeid;
|
2025-06-05 23:47:42 -05:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path_name(hdr_->nodeid,name,&fusepath);
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.create(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mode,
|
|
|
|
|
&ffi);
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-05 16:01:55 -05:00
|
|
|
err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&ffi,false);
|
2019-05-23 23:22:36 -04:00
|
|
|
if(err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(&req_->ctx,&ffi);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
|
|
|
|
else if(!S_ISREG(e.attr.st_mode))
|
|
|
|
|
{
|
|
|
|
|
err = -EIO;
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(&req_->ctx,&ffi);
|
|
|
|
|
forget_node(e.ino,1);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-13 08:24:03 -05:00
|
|
|
free_path_and_inc_open(hdr_->nodeid,fusepath,e.ino,true);
|
|
|
|
|
fusepath = NULL;
|
2019-03-03 23:26:20 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(fuse_reply_create(req_,&e,&ffi) == -ENOENT)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
/* The open syscall was interrupted,so it
|
|
|
|
|
must be cancelled */
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_do_release(&req_->ctx,e.ino,&ffi);
|
|
|
|
|
forget_node(e.ino,1);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
forget_node(new_nodeid,1);
|
|
|
|
|
fuse_reply_err(req_,err);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
open_auto_cache(fuse_req_ctx_t *req_ctx_,
|
2021-09-30 23:28:54 -04:00
|
|
|
uint64_t ino,
|
2020-11-15 19:12:33 -05:00
|
|
|
const char *path,
|
|
|
|
|
fuse_file_info_t *fi)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
2026-03-10 19:29:13 -05:00
|
|
|
fuse_timeouts_t timeouts{};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
node = get_node(ino);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(not node)
|
|
|
|
|
{
|
|
|
|
|
mutex_unlock(f.lock);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
struct stat stbuf;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
mutex_unlock(f.lock);
|
|
|
|
|
err = f.ops.fgetattr(req_ctx_,
|
|
|
|
|
fi->fh,
|
|
|
|
|
&stbuf,
|
|
|
|
|
&timeouts);
|
|
|
|
|
mutex_lock(f.lock);
|
2019-05-23 23:22:36 -04:00
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
|
|
|
|
uint32_t old_crc32b;
|
|
|
|
|
uint32_t new_crc32b;
|
2019-05-23 23:22:36 -04:00
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
old_crc32b = node->stat_crc32b;
|
|
|
|
|
new_crc32b = stat_crc32b(&stbuf);
|
|
|
|
|
if((old_crc32b != 0) && (old_crc32b == new_crc32b))
|
|
|
|
|
fi->keep_cache = 1;
|
2019-05-23 23:22:36 -04:00
|
|
|
|
2026-05-04 19:24:12 -05:00
|
|
|
node->stat_crc32b = new_crc32b;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
node->stat_crc32b = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-05-23 23:22:36 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_open(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-05-23 23:22:36 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_open_in *arg;
|
|
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
arg = (fuse_open_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
|
|
|
|
ffi.flags = arg->flags;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.open(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
&ffi);
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-07-06 18:31:47 -05:00
|
|
|
if(ffi.auto_cache && (ffi.passthrough == false))
|
2025-10-13 00:21:36 -04:00
|
|
|
open_auto_cache(&req_->ctx,hdr_->nodeid,fusepath,&ffi);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2019-05-23 23:22:36 -04:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-13 08:24:03 -05:00
|
|
|
free_path_and_inc_open(hdr_->nodeid,fusepath,hdr_->nodeid,false);
|
|
|
|
|
fusepath = NULL;
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
/* The open syscall was interrupted,so it must be cancelled */
|
2025-10-13 00:21:36 -04:00
|
|
|
if(fuse_reply_open(req_,&ffi) == -ENOENT)
|
|
|
|
|
fuse_do_release(&req_->ctx,hdr_->nodeid,&ffi);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2019-05-23 23:22:36 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_read(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int res;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_read_in *arg;
|
2023-02-26 15:16:18 -05:00
|
|
|
fuse_msgbuf_t *msgbuf;
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi.fh = arg->fh;
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 9)
|
2022-11-12 22:26:26 -05:00
|
|
|
{
|
|
|
|
|
ffi.flags = arg->flags;
|
|
|
|
|
ffi.lock_owner = arg->lock_owner;
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-09 02:04:32 -05:00
|
|
|
msgbuf = msgbuf_alloc_page_aligned();
|
2026-04-18 01:00:11 -04:00
|
|
|
if(msgbuf == NULL)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOMEM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-02-26 15:16:18 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
res = f.ops.read(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
msgbuf->mem,
|
|
|
|
|
arg->size,
|
|
|
|
|
arg->offset);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(res >= 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_data(req_,msgbuf->mem,res);
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2023-02-26 15:16:18 -05:00
|
|
|
msgbuf_free(msgbuf);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_write(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int res;
|
2022-11-12 22:26:26 -05:00
|
|
|
char *data;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_write_in *arg;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_write_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
ffi.fh = arg->fh;
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi.writepage = !!(arg->write_flags & 1);
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor < 9)
|
2022-11-12 22:26:26 -05:00
|
|
|
{
|
|
|
|
|
data = ((char*)arg) + FUSE_COMPAT_WRITE_IN_SIZE;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffi.flags = arg->flags;
|
|
|
|
|
ffi.lock_owner = arg->lock_owner;
|
2024-04-15 19:12:08 -05:00
|
|
|
data = (char*)PARAM(arg);
|
2022-11-12 22:26:26 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
res = f.ops.write(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
data,
|
|
|
|
|
arg->size,
|
|
|
|
|
arg->offset);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(res >= 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_write(req_,res);
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_fsync(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-10-13 00:21:36 -04:00
|
|
|
int is_datasync;
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_fsync_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
is_datasync = !!(arg->fsync_flags & FUSE_FSYNC_FDATASYNC);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.fsync(&req_->ctx,
|
|
|
|
|
arg->fh,
|
|
|
|
|
is_datasync);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
struct fuse_dh*
|
|
|
|
|
get_dirhandle(const fuse_file_info_t *llfi,
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_file_info_t *ffi)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
struct fuse_dh *dh = (struct fuse_dh *)(uintptr_t)llfi->fh;
|
2026-04-18 01:00:11 -04:00
|
|
|
|
|
|
|
|
if(dh == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
*ffi = {};
|
|
|
|
|
|
|
|
|
|
ffi->fh = dh->fh;
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return dh;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_opendir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2020-11-15 19:12:33 -05:00
|
|
|
struct fuse_dh *dh;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t llffi = {};
|
|
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_open_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_open_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
llffi.flags = arg->flags;
|
|
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
dh = (fuse_dh*)calloc(1,sizeof(fuse_dh));
|
2020-11-15 19:12:33 -05:00
|
|
|
if(dh == NULL)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,ENOMEM);
|
2020-11-15 19:12:33 -05:00
|
|
|
return;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
err = fuse_dirents_init(&dh->d);
|
|
|
|
|
if(err)
|
|
|
|
|
{
|
|
|
|
|
free(dh);
|
|
|
|
|
fuse_reply_err(req_,ENOMEM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_init(dh->lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
llffi.fh = (uintptr_t)dh;
|
|
|
|
|
ffi.flags = llffi.flags;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.opendir(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
&ffi);
|
2022-11-12 22:26:26 -05:00
|
|
|
dh->fh = ffi.fh;
|
|
|
|
|
llffi.keep_cache = ffi.keep_cache;
|
|
|
|
|
llffi.cache_readdir = ffi.cache_readdir;
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
if(fuse_reply_open(req_,&llffi) == -ENOENT)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
/* The opendir syscall was interrupted,so it
|
|
|
|
|
must be cancelled */
|
2026-04-18 01:00:11 -04:00
|
|
|
f.ops.releasedir(&req_->ctx,&ffi);
|
|
|
|
|
|
|
|
|
|
fuse_dirents_free(&dh->d);
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_destroy(dh->lock);
|
2020-11-15 19:12:33 -05:00
|
|
|
free(dh);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_dirents_free(&dh->d);
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_destroy(dh->lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
free(dh);
|
|
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-14 08:59:04 -04:00
|
|
|
static
|
2020-07-10 13:50:14 -04:00
|
|
|
size_t
|
|
|
|
|
readdir_buf_size(fuse_dirents_t *d_,
|
|
|
|
|
size_t size_,
|
|
|
|
|
off_t off_)
|
2019-06-14 08:59:04 -04:00
|
|
|
{
|
2025-09-17 23:51:16 -04:00
|
|
|
if((size_t)off_ >= kv_size(d_->offs))
|
2020-07-10 13:50:14 -04:00
|
|
|
return 0;
|
2021-09-18 22:22:47 -04:00
|
|
|
if((kv_A(d_->offs,off_) + size_) > kv_size(d_->data))
|
|
|
|
|
return (kv_size(d_->data) - kv_A(d_->offs,off_));
|
2020-07-10 13:50:14 -04:00
|
|
|
return size_;
|
|
|
|
|
}
|
2019-06-14 08:59:04 -04:00
|
|
|
|
2020-07-10 13:50:14 -04:00
|
|
|
static
|
|
|
|
|
char*
|
|
|
|
|
readdir_buf(fuse_dirents_t *d_,
|
|
|
|
|
off_t off_)
|
|
|
|
|
{
|
2021-09-18 22:22:47 -04:00
|
|
|
size_t i;
|
|
|
|
|
|
|
|
|
|
i = kv_A(d_->offs,off_);
|
|
|
|
|
|
|
|
|
|
return &kv_A(d_->data,i);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-14 08:59:04 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_readdir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-06-14 08:59:04 -04:00
|
|
|
int rv;
|
2022-11-12 22:26:26 -05:00
|
|
|
size_t size;
|
2019-06-14 08:59:04 -04:00
|
|
|
fuse_dirents_t *d;
|
|
|
|
|
struct fuse_dh *dh;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
|
|
|
|
fuse_file_info_t llffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_read_in *arg;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
size = arg->size;
|
2022-11-12 22:26:26 -05:00
|
|
|
llffi.fh = arg->fh;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
dh = get_dirhandle(&llffi,&ffi);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(not dh)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,EBADF);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
d = &dh->d;
|
|
|
|
|
|
|
|
|
|
mutex_lockguard(dh->lock);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
|
|
|
|
rv = 0;
|
2022-11-12 22:26:26 -05:00
|
|
|
if((arg->offset == 0) || (kv_size(d->data) == 0))
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = f.ops.readdir(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
d);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
|
|
|
|
if(rv)
|
|
|
|
|
{
|
fix: keep readdir listings stable under fill errors
- func.readdir=cor appended entries in whichever order branch workers
finished. Directory offsets are positions in that list, so a reader
reopening an unchanged directory and seeking to a previously issued
cookie (NFS does this) could see a duplicate and miss a later entry.
Read branches concurrently into their own buffers, then merge and
deduplicate them in configured branch order. The merge mutex is gone.
- Growing a dirents buffer overwrote the only pointer with realloc's
result while recording the new capacity, so an allocation failure
leaked the buffer and the next fill wrote through NULL. Grow both
vectors without changing pointer, length or capacity until the
allocation succeeds, and return ENOMEM.
- seq and cosr ignored that failure and served a listing with entries
missing. Every policy now returns the error, and libfuse resets the
handle's buffer whenever a fill fails, so a later request at a
nonzero offset re-enumerates instead of serving a partial or stale
listing as success. cosr closes the directories its workers opened
when it gives up early.
- Document the fill-error contract, which doesn't promise that every
branch was read: seq and cosr can treat a branch read error as the
end of the directory. Document cor's memory use, and refer to
func.getattr, not fuse.getattr.
- TEST_readdir_cor_cookie_replay compares cor listings, offsets and
inodes with seq and replays cookies on fresh handles.
TEST_dirents_allocation injects allocation failures into the dirents
code. TEST_readdir_cor_enomem fails one allocation in a mounted
daemon for cor and seq and checks the same handle then serves the
exact suffix.
Performance: cor copies each entry twice and merges serially after the
parallel reads. Listing 100,000 entries over 4 tmpfs branches took
the same time before and after (81-83 ms per listing for cor:4 and
seq). Peak daemon memory for cor:4 dropped from 27.4 MB to 18.7 MB.
2026-05-13 10:58:01 -05:00
|
|
|
// A failed fill must not leave a partial or stale listing
|
|
|
|
|
// cached: a later nonzero-offset request would otherwise be
|
|
|
|
|
// served from a truncated enumeration of a different fill.
|
|
|
|
|
// Reset so the next request re-enumerates from scratch.
|
|
|
|
|
fuse_dirents_reset(d);
|
2023-02-26 15:16:18 -05:00
|
|
|
fuse_reply_err(req_,rv);
|
2026-04-18 01:00:11 -04:00
|
|
|
return;
|
2019-06-14 08:59:04 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
size = readdir_buf_size(d,size,arg->offset);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
if(size == 0)
|
|
|
|
|
fuse_reply_buf(req_,NULL,0);
|
|
|
|
|
else
|
|
|
|
|
fuse_reply_buf(req_,
|
|
|
|
|
readdir_buf(d,arg->offset),
|
|
|
|
|
size);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-14 08:59:04 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_readdir_plus(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-06-14 08:59:04 -04:00
|
|
|
int rv;
|
2022-11-12 22:26:26 -05:00
|
|
|
size_t size;
|
2019-06-14 08:59:04 -04:00
|
|
|
fuse_dirents_t *d;
|
|
|
|
|
struct fuse_dh *dh;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
|
|
|
|
fuse_file_info_t llffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_read_in *arg;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_read_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
size = arg->size;
|
2022-11-12 22:26:26 -05:00
|
|
|
llffi.fh = arg->fh;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
dh = get_dirhandle(&llffi,&ffi);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(not dh)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,EBADF);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
d = &dh->d;
|
|
|
|
|
|
|
|
|
|
mutex_lockguard(dh->lock);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
|
|
|
|
rv = 0;
|
2022-11-12 22:26:26 -05:00
|
|
|
if((arg->offset == 0) || (kv_size(d->data) == 0))
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = f.ops.readdir_plus(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
d);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
|
|
|
|
if(rv)
|
|
|
|
|
{
|
fix: keep readdir listings stable under fill errors
- func.readdir=cor appended entries in whichever order branch workers
finished. Directory offsets are positions in that list, so a reader
reopening an unchanged directory and seeking to a previously issued
cookie (NFS does this) could see a duplicate and miss a later entry.
Read branches concurrently into their own buffers, then merge and
deduplicate them in configured branch order. The merge mutex is gone.
- Growing a dirents buffer overwrote the only pointer with realloc's
result while recording the new capacity, so an allocation failure
leaked the buffer and the next fill wrote through NULL. Grow both
vectors without changing pointer, length or capacity until the
allocation succeeds, and return ENOMEM.
- seq and cosr ignored that failure and served a listing with entries
missing. Every policy now returns the error, and libfuse resets the
handle's buffer whenever a fill fails, so a later request at a
nonzero offset re-enumerates instead of serving a partial or stale
listing as success. cosr closes the directories its workers opened
when it gives up early.
- Document the fill-error contract, which doesn't promise that every
branch was read: seq and cosr can treat a branch read error as the
end of the directory. Document cor's memory use, and refer to
func.getattr, not fuse.getattr.
- TEST_readdir_cor_cookie_replay compares cor listings, offsets and
inodes with seq and replays cookies on fresh handles.
TEST_dirents_allocation injects allocation failures into the dirents
code. TEST_readdir_cor_enomem fails one allocation in a mounted
daemon for cor and seq and checks the same handle then serves the
exact suffix.
Performance: cor copies each entry twice and merges serially after the
parallel reads. Listing 100,000 entries over 4 tmpfs branches took
the same time before and after (81-83 ms per listing for cor:4 and
seq). Peak daemon memory for cor:4 dropped from 27.4 MB to 18.7 MB.
2026-05-13 10:58:01 -05:00
|
|
|
// A failed fill must not leave a partial or stale listing
|
|
|
|
|
// cached: a later nonzero-offset request would otherwise be
|
|
|
|
|
// served from a truncated enumeration of a different fill.
|
|
|
|
|
// Reset so the next request re-enumerates from scratch.
|
|
|
|
|
fuse_dirents_reset(d);
|
2023-02-26 15:16:18 -05:00
|
|
|
fuse_reply_err(req_,rv);
|
2026-04-18 01:00:11 -04:00
|
|
|
return;
|
2019-06-14 08:59:04 -04:00
|
|
|
}
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
size = readdir_buf_size(d,size,arg->offset);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
if(size == 0)
|
|
|
|
|
fuse_reply_buf(req_,NULL,0);
|
|
|
|
|
else
|
|
|
|
|
fuse_reply_buf(req_,
|
|
|
|
|
readdir_buf(d,arg->offset),
|
|
|
|
|
size);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-06-14 08:59:04 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_releasedir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2019-06-14 08:59:04 -04:00
|
|
|
struct fuse_dh *dh;
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_file_info_t ffi = {};
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t llffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_release_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_release_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
llffi.fh = arg->fh;
|
|
|
|
|
llffi.flags = arg->flags;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
dh = get_dirhandle(&llffi,&ffi);
|
2026-04-18 01:00:11 -04:00
|
|
|
if(not dh)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,EBADF);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.releasedir(&req_->ctx,
|
|
|
|
|
&ffi);
|
2019-06-14 08:59:04 -04:00
|
|
|
|
2026-05-13 07:59:07 -05:00
|
|
|
// Acquire/release barrier: not a real critical section. A
|
|
|
|
|
// concurrent readdir may still hold dh->lock at this point. This
|
|
|
|
|
// lock+unlock pair blocks until the last readdir drops the lock
|
|
|
|
|
// guaranteeing that the subsequent destroy/free sees no in-flight
|
|
|
|
|
// readdir accessing dh->d. Do NOT remove.
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(dh->lock);
|
|
|
|
|
mutex_unlock(dh->lock);
|
|
|
|
|
mutex_destroy(dh->lock);
|
2019-06-14 08:59:04 -04:00
|
|
|
fuse_dirents_free(&dh->d);
|
|
|
|
|
free(dh);
|
2023-02-26 15:16:18 -05:00
|
|
|
fuse_reply_err(req_,0);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_fsyncdir(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-10-13 00:21:36 -04:00
|
|
|
int is_datasync;
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_dh *dh;
|
|
|
|
|
fuse_file_info_t ffi = {};
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t llffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_fsync_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
is_datasync = !!(arg->fsync_flags & FUSE_FSYNC_FDATASYNC);
|
|
|
|
|
llffi.fh = arg->fh;
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
dh = get_dirhandle(&llffi,&ffi);
|
|
|
|
|
if(not dh)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,EBADF);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.fsyncdir(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
is_datasync);
|
2020-07-08 19:25:23 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_statfs(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err = 0;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct statvfs buf = {};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-09-17 23:51:16 -04:00
|
|
|
fusepath = NULL;
|
2022-11-12 22:26:26 -05:00
|
|
|
if(hdr_->nodeid)
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.statfs(&req_->ctx,
|
|
|
|
|
fusepath ? &fusepath[1] : "",
|
|
|
|
|
&buf);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_statfs(req_,&buf);
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_setxattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
|
|
|
|
const char *value;
|
|
|
|
|
struct fuse_setxattr_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
arg = (fuse_setxattr_in*)fuse_hdr_arg(hdr_);
|
2026-02-13 20:26:26 -06:00
|
|
|
if((req_->conn.capable & FUSE_SETXATTR_EXT) &&
|
|
|
|
|
(req_->conn.want & FUSE_SETXATTR_EXT))
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)PARAM(arg);
|
2022-12-06 23:26:08 -05:00
|
|
|
else
|
|
|
|
|
name = (((char*)arg) + FUSE_COMPAT_SETXATTR_IN_SIZE);
|
|
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
value = (name + strlen(name) + 1);
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.setxattr(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
arg->size,
|
|
|
|
|
arg->flags);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
common_getxattr(fuse_req_t *req_,
|
|
|
|
|
uint64_t ino,
|
|
|
|
|
const char *name,
|
|
|
|
|
char *value,
|
|
|
|
|
size_t size)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(ino,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.getxattr(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
name,
|
|
|
|
|
value,
|
|
|
|
|
size);
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(ino,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_getxattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int res;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char* name;
|
|
|
|
|
struct fuse_getxattr_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
name = (const char*)PARAM(arg);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
|
|
|
|
if(arg->size)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2022-11-12 22:26:26 -05:00
|
|
|
char *value = (char*)malloc(arg->size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(value == NULL)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,ENOMEM);
|
2020-11-15 19:12:33 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
res = common_getxattr(req_,hdr_->nodeid,name,value,arg->size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(res > 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_buf(req_,value,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
free(value);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
res = common_getxattr(req_,hdr_->nodeid,name,NULL,0);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(res >= 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_xattr(req_,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
common_listxattr(fuse_req_t *req_,
|
|
|
|
|
uint64_t ino,
|
|
|
|
|
char *list,
|
|
|
|
|
size_t size)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(ino,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.listxattr(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
list,
|
|
|
|
|
size);
|
|
|
|
|
free_path(ino,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return err;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_listxattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int res;
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_getxattr_in *arg;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_getxattr_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
|
|
|
|
if(arg->size)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2022-11-12 22:26:26 -05:00
|
|
|
char *list = (char*)malloc(arg->size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(list == NULL)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,ENOMEM);
|
2020-11-15 19:12:33 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
res = common_listxattr(req_,hdr_->nodeid,list,arg->size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(res > 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_buf(req_,list,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
free(list);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
res = common_listxattr(req_,hdr_->nodeid,NULL,0);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(res >= 0)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_xattr(req_,res);
|
2020-11-15 19:12:33 -05:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,res);
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_removexattr(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
const char *name;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
name = (const char*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.removexattr(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
name);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2019-05-25 14:25:57 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_copy_file_range(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2019-05-25 14:25:57 -04:00
|
|
|
{
|
|
|
|
|
ssize_t rv;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi_in = {};
|
|
|
|
|
fuse_file_info_t ffi_out = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_copy_file_range_in *arg;
|
2026-04-01 09:48:12 -05:00
|
|
|
struct fuse_copy_file_range_in arg_tmp;
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_copy_file_range_in*)fuse_hdr_arg(hdr_);
|
2026-04-01 09:48:12 -05:00
|
|
|
if(((hdr_->opcode == FUSE_COPY_FILE_RANGE) || (sizeof(size_t) == 4)) &&
|
|
|
|
|
(arg->len > 0xfffff000ULL))
|
|
|
|
|
{
|
|
|
|
|
/* Avoid truncation in the old reply format or 32-bit size_t conversion. */
|
|
|
|
|
arg_tmp = *arg;
|
|
|
|
|
arg_tmp.len = 0xfffff000ULL;
|
|
|
|
|
arg = &arg_tmp;
|
|
|
|
|
}
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi_in.fh = arg->fh_in;
|
|
|
|
|
ffi_out.fh = arg->fh_out;
|
2019-05-25 14:25:57 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
rv = f.ops.copy_file_range(&req_->ctx,
|
|
|
|
|
&ffi_in,
|
|
|
|
|
arg->off_in,
|
|
|
|
|
&ffi_out,
|
|
|
|
|
arg->off_out,
|
|
|
|
|
arg->len,
|
|
|
|
|
arg->flags);
|
2019-05-25 14:25:57 -04:00
|
|
|
|
|
|
|
|
if(rv >= 0)
|
2026-04-01 09:48:12 -05:00
|
|
|
{
|
|
|
|
|
if(hdr_->opcode == FUSE_COPY_FILE_RANGE_64)
|
|
|
|
|
fuse_reply_copy_file_range_64(req_,rv);
|
|
|
|
|
else
|
|
|
|
|
fuse_reply_write(req_,rv);
|
|
|
|
|
}
|
2019-05-25 14:25:57 -04:00
|
|
|
else
|
2023-02-26 15:16:18 -05:00
|
|
|
fuse_reply_err(req_,rv);
|
2019-05-25 14:25:57 -04:00
|
|
|
}
|
|
|
|
|
|
2023-08-12 01:50:37 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_setupmapping(fuse_req_t *req_,
|
2023-08-12 01:50:37 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOSYS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_removemapping(fuse_req_t *req_,
|
2023-08-12 01:50:37 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOSYS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_syncfs(fuse_req_t *req_,
|
2023-08-12 01:50:37 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOSYS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// name is always '/'
|
|
|
|
|
// nodeid is the base directory
|
|
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_tmpfile(fuse_req_t *req_,
|
2023-08-12 01:50:37 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2023-08-12 01:50:37 -05:00
|
|
|
const char *name;
|
2026-05-06 18:34:28 -05:00
|
|
|
uint64_t new_nodeid;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2023-08-12 01:50:37 -05:00
|
|
|
struct fuse_entry_param e;
|
|
|
|
|
struct fuse_create_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_create_in*)fuse_hdr_arg(hdr_);
|
|
|
|
|
name = (const char*)PARAM(arg);
|
2023-08-12 01:50:37 -05:00
|
|
|
|
|
|
|
|
ffi.flags = arg->flags;
|
|
|
|
|
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 12)
|
2023-08-12 01:50:37 -05:00
|
|
|
req_->ctx.umask = arg->umask;
|
|
|
|
|
else
|
|
|
|
|
name = (char*)arg + sizeof(struct fuse_open_in);
|
|
|
|
|
|
2026-05-06 18:34:28 -05:00
|
|
|
// Opportunistically allocate a provisional node so passthrough tmpfile has
|
|
|
|
|
// a nodeid. It is remembered only after tmpfile fully succeeds.
|
|
|
|
|
{
|
|
|
|
|
node_t *node;
|
|
|
|
|
|
|
|
|
|
node = find_node(hdr_->nodeid,name,false);
|
|
|
|
|
if(node == NULL)
|
|
|
|
|
{
|
|
|
|
|
fuse_reply_err(req_,ENOMEM);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new_nodeid = node->nodeid;
|
|
|
|
|
req_->ctx.nodeid = new_nodeid;
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-28 12:12:43 -05:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2023-08-12 01:50:37 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.tmpfile(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->mode,
|
|
|
|
|
&ffi);
|
2023-08-12 01:50:37 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-06 18:34:28 -05:00
|
|
|
err = lookup_path(req_,hdr_->nodeid,name,fusepath,&e,&ffi,false);
|
2023-08-12 01:50:37 -05:00
|
|
|
if(err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(&req_->ctx,
|
|
|
|
|
&ffi);
|
2023-08-12 01:50:37 -05:00
|
|
|
}
|
|
|
|
|
else if(!S_ISREG(e.attr.st_mode))
|
|
|
|
|
{
|
|
|
|
|
err = -EIO;
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.release(&req_->ctx,
|
|
|
|
|
&ffi);
|
|
|
|
|
forget_node(e.ino,1);
|
2023-08-12 01:50:37 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!err)
|
|
|
|
|
{
|
2026-05-13 08:24:03 -05:00
|
|
|
free_path_and_inc_open(hdr_->nodeid,fusepath,e.ino,true);
|
|
|
|
|
fusepath = NULL;
|
2023-08-12 01:50:37 -05:00
|
|
|
|
|
|
|
|
if(fuse_reply_create(req_,&e,&ffi) == -ENOENT)
|
|
|
|
|
{
|
|
|
|
|
/* The open syscall was interrupted,so it
|
|
|
|
|
must be cancelled */
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_do_release(&req_->ctx,e.ino,&ffi);
|
|
|
|
|
forget_node(e.ino,1);
|
2023-08-12 01:50:37 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2026-05-06 18:34:28 -05:00
|
|
|
forget_node(new_nodeid,1);
|
2023-08-12 01:50:37 -05:00
|
|
|
fuse_reply_err(req_,err);
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2023-08-12 01:50:37 -05:00
|
|
|
}
|
|
|
|
|
|
2026-05-04 23:50:45 -05:00
|
|
|
static
|
2020-11-15 19:12:33 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_flush_common(fuse_req_t *req_,
|
|
|
|
|
fuse_file_info_t *ffi_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2026-05-04 23:50:45 -05:00
|
|
|
return f.ops.flush(&req_->ctx,
|
|
|
|
|
ffi_);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_release(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err = 0;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_release_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_release_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi.fh = arg->fh;
|
|
|
|
|
ffi.flags = arg->flags;
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 8)
|
2022-11-12 22:26:26 -05:00
|
|
|
{
|
|
|
|
|
ffi.flush = !!(arg->release_flags & FUSE_RELEASE_FLUSH);
|
|
|
|
|
ffi.lock_owner = arg->lock_owner;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ffi.flock_release = 1;
|
|
|
|
|
ffi.lock_owner = arg->lock_owner;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(ffi.flush)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2026-05-04 23:20:48 -05:00
|
|
|
err = fuse_flush_common(req_,&ffi);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(err == -ENOSYS)
|
|
|
|
|
err = 0;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_do_release(&req_->ctx,
|
|
|
|
|
hdr_->nodeid,
|
|
|
|
|
&ffi);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_flush(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
struct fuse_flush_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_flush_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
|
|
|
|
ffi.fh = arg->fh;
|
|
|
|
|
ffi.flush = 1;
|
2026-02-13 20:26:26 -06:00
|
|
|
if(req_->conn.proto_minor >= 7)
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi.lock_owner = arg->lock_owner;
|
|
|
|
|
|
2026-05-04 23:20:48 -05:00
|
|
|
err = fuse_flush_common(req_,&ffi);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_bmap(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2025-09-17 23:51:16 -04:00
|
|
|
char *fusepath;
|
2022-11-12 22:26:26 -05:00
|
|
|
uint64_t block;
|
|
|
|
|
const struct fuse_bmap_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_bmap_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
block = arg->block;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = get_path(hdr_->nodeid,&fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.bmap(&req_->ctx,
|
|
|
|
|
&fusepath[1],
|
|
|
|
|
arg->blocksize,
|
|
|
|
|
&block);
|
|
|
|
|
free_path(hdr_->nodeid,fusepath);
|
2020-11-15 19:12:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_bmap(req_,block);
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_ioctl(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2020-11-15 19:12:33 -05:00
|
|
|
char *out_buf = NULL;
|
2026-04-18 01:00:11 -04:00
|
|
|
fuse_dh *dh;
|
|
|
|
|
fuse_file_info_t ffi = {};
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t llffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
const void *in_buf;
|
|
|
|
|
uint32_t out_size;
|
|
|
|
|
const struct fuse_ioctl_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_ioctl_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
err = -EPERM;
|
|
|
|
|
if(arg->flags & FUSE_IOCTL_UNRESTRICTED)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
if((sizeof(void*) == 4) &&
|
2026-02-13 20:26:26 -06:00
|
|
|
(req_->conn.proto_minor >= 16) &&
|
2022-11-12 22:26:26 -05:00
|
|
|
!(arg->flags & FUSE_IOCTL_32BIT))
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
req_->ioctl_64bit = 1;
|
2022-11-12 22:26:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
llffi.fh = arg->fh;
|
|
|
|
|
out_size = arg->out_size;
|
|
|
|
|
in_buf = (arg->in_size ? PARAM(arg) : NULL);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(arg->flags & FUSE_IOCTL_DIR)
|
2026-04-18 01:00:11 -04:00
|
|
|
{
|
|
|
|
|
dh = get_dirhandle(&llffi,&ffi);
|
|
|
|
|
if(not dh)
|
|
|
|
|
{
|
|
|
|
|
err = -EBADF;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2026-04-18 01:00:11 -04:00
|
|
|
{
|
|
|
|
|
ffi = llffi;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((arg->in_size > 0) &&
|
|
|
|
|
(out_size > 0) &&
|
|
|
|
|
(arg->in_size != out_size))
|
|
|
|
|
{
|
|
|
|
|
err = -EINVAL;
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2022-11-12 22:26:26 -05:00
|
|
|
if(out_size)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
|
|
|
|
err = -ENOMEM;
|
2024-04-15 19:12:08 -05:00
|
|
|
out_buf = (char*)malloc(out_size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!out_buf)
|
|
|
|
|
goto err;
|
|
|
|
|
}
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
if(in_buf && out_buf)
|
|
|
|
|
memcpy(out_buf,in_buf,out_size);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.ioctl(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
arg->cmd,
|
|
|
|
|
(void*)(uintptr_t)arg->arg,
|
|
|
|
|
arg->flags,
|
2026-04-18 01:00:11 -04:00
|
|
|
out_buf ? out_buf : (void*)in_buf,
|
2025-10-13 00:21:36 -04:00
|
|
|
&out_size);
|
2023-01-28 01:17:07 -05:00
|
|
|
if(err < 0)
|
|
|
|
|
goto err;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_ioctl(req_,err,out_buf,out_size);
|
2026-04-30 12:11:01 -05:00
|
|
|
goto out;
|
2020-07-31 23:50:47 -04:00
|
|
|
err:
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2026-04-30 12:11:01 -05:00
|
|
|
out:
|
|
|
|
|
free(out_buf);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_poll(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
|
|
|
|
unsigned revents = 0;
|
2025-10-29 22:42:42 -05:00
|
|
|
fuse_file_info_t ffi = {};
|
2022-11-12 22:26:26 -05:00
|
|
|
fuse_pollhandle_t *ph = NULL;
|
|
|
|
|
const struct fuse_poll_in *arg;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_poll_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
ffi.fh = arg->fh;
|
|
|
|
|
|
|
|
|
|
if(arg->flags & FUSE_POLL_SCHEDULE_NOTIFY)
|
|
|
|
|
{
|
|
|
|
|
ph = (fuse_pollhandle_t*)malloc(sizeof(fuse_pollhandle_t));
|
|
|
|
|
if(ph == NULL)
|
|
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,ENOMEM);
|
2022-11-12 22:26:26 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ph->kh = arg->kh;
|
2026-02-16 20:55:18 -06:00
|
|
|
ph->se = req_->se;
|
2022-11-12 22:26:26 -05:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.poll(&req_->ctx,
|
|
|
|
|
&ffi,
|
|
|
|
|
ph,
|
|
|
|
|
&revents);
|
2020-07-08 19:25:23 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
if(!err)
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_poll(req_,revents);
|
2020-07-31 23:50:47 -04:00
|
|
|
else
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_lib_fallocate(fuse_req_t *req_,
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_in_header *hdr_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
int err;
|
2022-11-12 22:26:26 -05:00
|
|
|
const struct fuse_fallocate_in *arg;
|
|
|
|
|
|
2024-04-15 19:12:08 -05:00
|
|
|
arg = (fuse_fallocate_in*)fuse_hdr_arg(hdr_);
|
2022-11-12 22:26:26 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
err = f.ops.fallocate(&req_->ctx,
|
|
|
|
|
arg->fh,
|
|
|
|
|
arg->mode,
|
|
|
|
|
arg->offset,
|
|
|
|
|
arg->length);
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_reply_err(req_,err);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static struct fuse_lowlevel_ops fuse_path_ops =
|
|
|
|
|
{
|
2025-05-08 00:00:53 -05:00
|
|
|
.access = fuse_lib_access,
|
|
|
|
|
.bmap = fuse_lib_bmap,
|
|
|
|
|
.copy_file_range = fuse_lib_copy_file_range,
|
|
|
|
|
.create = fuse_lib_create,
|
|
|
|
|
.destroy = fuse_lib_destroy,
|
|
|
|
|
.fallocate = fuse_lib_fallocate,
|
|
|
|
|
.flush = fuse_lib_flush,
|
|
|
|
|
.forget = fuse_lib_forget,
|
|
|
|
|
.forget_multi = fuse_lib_forget_multi,
|
|
|
|
|
.fsync = fuse_lib_fsync,
|
|
|
|
|
.fsyncdir = fuse_lib_fsyncdir,
|
|
|
|
|
.getattr = fuse_lib_getattr,
|
|
|
|
|
.getxattr = fuse_lib_getxattr,
|
|
|
|
|
.init = fuse_lib_init,
|
|
|
|
|
.ioctl = fuse_lib_ioctl,
|
|
|
|
|
.link = fuse_lib_link,
|
|
|
|
|
.listxattr = fuse_lib_listxattr,
|
|
|
|
|
.lookup = fuse_lib_lookup,
|
|
|
|
|
.lseek = fuse_lib_lseek,
|
|
|
|
|
.mkdir = fuse_lib_mkdir,
|
|
|
|
|
.mknod = fuse_lib_mknod,
|
|
|
|
|
.open = fuse_lib_open,
|
|
|
|
|
.opendir = fuse_lib_opendir,
|
|
|
|
|
.poll = fuse_lib_poll,
|
|
|
|
|
.read = fuse_lib_read,
|
|
|
|
|
.readdir = fuse_lib_readdir,
|
|
|
|
|
.readdir_plus = fuse_lib_readdir_plus,
|
|
|
|
|
.readlink = fuse_lib_readlink,
|
|
|
|
|
.release = fuse_lib_release,
|
|
|
|
|
.releasedir = fuse_lib_releasedir,
|
|
|
|
|
.removemapping = fuse_lib_removemapping,
|
|
|
|
|
.removexattr = fuse_lib_removexattr,
|
|
|
|
|
.rename = fuse_lib_rename,
|
|
|
|
|
.rename2 = fuse_lib_rename2,
|
|
|
|
|
.retrieve_reply = fuse_lib_retrieve_reply,
|
|
|
|
|
.rmdir = fuse_lib_rmdir,
|
|
|
|
|
.setattr = fuse_lib_setattr,
|
|
|
|
|
.setupmapping = fuse_lib_setupmapping,
|
|
|
|
|
.setxattr = fuse_lib_setxattr,
|
|
|
|
|
.statfs = fuse_lib_statfs,
|
|
|
|
|
.statx = fuse_lib_statx,
|
|
|
|
|
.symlink = fuse_lib_symlink,
|
|
|
|
|
.syncfs = fuse_lib_syncfs,
|
|
|
|
|
.tmpfile = fuse_lib_tmpfile,
|
|
|
|
|
.unlink = fuse_lib_unlink,
|
|
|
|
|
.write = fuse_lib_write,
|
2020-11-15 19:12:33 -05:00
|
|
|
};
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
int
|
|
|
|
|
fuse_notify_poll(fuse_pollhandle_t *ph)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
return fuse_lowlevel_notify_poll(ph);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_exited()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
return fuse_session_exited(f.se);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
struct fuse_session*
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_get_session()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
return f.se;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_exit()
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2025-10-13 00:21:36 -04:00
|
|
|
f.se->exited = 1;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
static
|
|
|
|
|
int
|
|
|
|
|
node_table_init(struct node_table *t)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
t->size = NODE_TABLE_MIN_SIZE;
|
2023-04-23 23:33:48 -04:00
|
|
|
t->array = (node_t **)calloc(1,sizeof(node_t *) * t->size);
|
2020-11-15 19:12:33 -05:00
|
|
|
if(t->array == NULL)
|
|
|
|
|
{
|
|
|
|
|
fprintf(stderr,"fuse: memory allocation failed\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
t->use = 0;
|
|
|
|
|
t->split = 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2020-07-31 23:50:47 -04:00
|
|
|
return 0;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2021-10-10 18:37:14 -04:00
|
|
|
static
|
|
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
metrics_log_nodes_info(FILE *file_)
|
2021-10-10 18:37:14 -04:00
|
|
|
{
|
2022-03-07 18:47:28 -05:00
|
|
|
char buf[1024];
|
2023-04-23 23:33:48 -04:00
|
|
|
char time_str[64];
|
|
|
|
|
struct tm tm;
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
uint64_t sizeof_node;
|
|
|
|
|
|
|
|
|
|
gettimeofday(&tv,NULL);
|
|
|
|
|
localtime_r(&tv.tv_sec,&tm);
|
|
|
|
|
strftime(time_str,sizeof(time_str),"%Y-%m-%dT%H:%M:%S.000%z",&tm);
|
|
|
|
|
|
|
|
|
|
sizeof_node = sizeof(node_t);
|
|
|
|
|
|
2022-03-07 18:47:28 -05:00
|
|
|
snprintf(buf,sizeof(buf),
|
2023-04-23 23:33:48 -04:00
|
|
|
"time: %s\n"
|
2024-04-15 19:12:08 -05:00
|
|
|
"sizeof(node): %" PRIu64 "\n"
|
|
|
|
|
"node id_table size: %" PRIu64 "\n"
|
|
|
|
|
"node id_table usage: %" PRIu64 "\n"
|
|
|
|
|
"node id_table total allocated memory: %" PRIu64 "\n"
|
|
|
|
|
"node name_table size: %" PRIu64 "\n"
|
|
|
|
|
"node name_table usage: %" PRIu64 "\n"
|
|
|
|
|
"node name_table total allocated memory: %" PRIu64 "\n"
|
|
|
|
|
"msgbuf bufsize: %" PRIu64 "\n"
|
|
|
|
|
"msgbuf allocation count: %" PRIu64 "\n"
|
|
|
|
|
"msgbuf total allocated memory: %" PRIu64 "\n"
|
2022-03-07 18:47:28 -05:00
|
|
|
"\n"
|
|
|
|
|
,
|
2023-04-23 23:33:48 -04:00
|
|
|
time_str,
|
|
|
|
|
sizeof_node,
|
2025-10-13 00:21:36 -04:00
|
|
|
(uint64_t)f.id_table.size,
|
|
|
|
|
(uint64_t)f.id_table.use,
|
|
|
|
|
(uint64_t)(f.id_table.size * sizeof(node_t*)),
|
|
|
|
|
(uint64_t)f.name_table.size,
|
|
|
|
|
(uint64_t)f.name_table.use,
|
|
|
|
|
(uint64_t)(f.name_table.size * sizeof(node_t*)),
|
2023-04-23 23:33:48 -04:00
|
|
|
msgbuf_get_bufsize(),
|
|
|
|
|
msgbuf_alloc_count(),
|
|
|
|
|
msgbuf_alloc_count() * msgbuf_get_bufsize()
|
2022-03-07 18:47:28 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
fputs(buf,file_);
|
2021-10-10 18:37:14 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
metrics_log_nodes_info_to_tmp_dir(struct fuse *f_)
|
|
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
int rv;
|
2021-10-10 18:37:14 -04:00
|
|
|
FILE *file;
|
|
|
|
|
char filepath[256];
|
2023-04-23 23:33:48 -04:00
|
|
|
struct stat st;
|
|
|
|
|
char const *mode = "a";
|
2021-10-10 18:37:14 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
snprintf(filepath,
|
|
|
|
|
sizeof(filepath),
|
|
|
|
|
"/tmp/mergerfs.%d.info",
|
|
|
|
|
getpid());
|
2021-10-10 18:37:14 -04:00
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
rv = lstat(filepath,&st);
|
2026-02-24 22:22:20 -06:00
|
|
|
if((rv == 0) && (st.st_size > INFO_FILE_MAX_SIZE))
|
2023-04-23 23:33:48 -04:00
|
|
|
mode = "w";
|
|
|
|
|
|
|
|
|
|
file = fopen(filepath,mode);
|
2021-10-10 18:37:14 -04:00
|
|
|
if(file == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
metrics_log_nodes_info(file);
|
2021-10-10 18:37:14 -04:00
|
|
|
|
|
|
|
|
fclose(file);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-30 07:59:21 -04:00
|
|
|
static
|
|
|
|
|
void
|
|
|
|
|
fuse_malloc_trim(void)
|
|
|
|
|
{
|
2025-08-05 00:39:52 -04:00
|
|
|
#ifdef __GLIBC__
|
2021-08-30 07:59:21 -04:00
|
|
|
malloc_trim(1024 * 1024);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
void
|
|
|
|
|
fuse_invalidate_all_nodes()
|
|
|
|
|
{
|
2025-01-09 20:10:35 -05:00
|
|
|
std::vector<std::string> names;
|
2023-04-23 23:33:48 -04:00
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_lock(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
for(size_t i = 0; i < f.id_table.size; i++)
|
2023-04-23 23:33:48 -04:00
|
|
|
{
|
|
|
|
|
node_t *node;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
for(node = f.id_table.array[i]; node != NULL; node = node->id_next)
|
2023-04-23 23:33:48 -04:00
|
|
|
{
|
|
|
|
|
if(node->nodeid == FUSE_ROOT_ID)
|
|
|
|
|
continue;
|
2025-01-09 20:10:35 -05:00
|
|
|
if(node->name == NULL)
|
|
|
|
|
continue;
|
|
|
|
|
if(node->parent == NULL)
|
|
|
|
|
continue;
|
2023-04-23 23:33:48 -04:00
|
|
|
if(node->parent->nodeid != FUSE_ROOT_ID)
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-01-09 20:10:35 -05:00
|
|
|
names.emplace_back(node->name);
|
2023-04-23 23:33:48 -04:00
|
|
|
}
|
|
|
|
|
}
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_unlock(f.lock);
|
2025-01-09 20:10:35 -05:00
|
|
|
|
2025-08-05 00:39:52 -04:00
|
|
|
SysLog::info("invalidating {} file entries",
|
|
|
|
|
names.size());
|
2025-01-09 20:10:35 -05:00
|
|
|
for(auto &name : names)
|
|
|
|
|
{
|
2026-02-16 20:55:18 -06:00
|
|
|
fuse_lowlevel_notify_inval_entry(f.se,
|
2025-01-09 20:10:35 -05:00
|
|
|
FUSE_ROOT_ID,
|
|
|
|
|
name.c_str(),
|
|
|
|
|
name.size());
|
|
|
|
|
}
|
2023-04-23 23:33:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fuse_gc()
|
|
|
|
|
{
|
2025-08-05 00:39:52 -04:00
|
|
|
SysLog::info("running thorough garbage collection");
|
2026-02-17 19:09:01 -06:00
|
|
|
node_clear();
|
2026-02-20 22:27:55 -06:00
|
|
|
msgbuf_clear();
|
2023-04-23 23:33:48 -04:00
|
|
|
fuse_malloc_trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
fuse_gc1()
|
|
|
|
|
{
|
2025-08-05 00:39:52 -04:00
|
|
|
SysLog::info("running basic garbage collection");
|
2026-02-17 19:09:01 -06:00
|
|
|
node_gc();
|
2026-02-20 22:27:55 -06:00
|
|
|
msgbuf_gc();
|
2023-04-23 23:33:48 -04:00
|
|
|
fuse_malloc_trim();
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-05 17:05:53 -05:00
|
|
|
void
|
|
|
|
|
fuse_populate_maintenance_thread(struct fuse *f_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2026-03-20 15:48:10 -05:00
|
|
|
MaintenanceThread::push_job([](u64 count_)
|
2025-07-05 17:05:53 -05:00
|
|
|
{
|
|
|
|
|
if((count_ % 15) == 0)
|
|
|
|
|
fuse_gc1();
|
|
|
|
|
});
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2026-03-20 15:48:10 -05:00
|
|
|
MaintenanceThread::push_job([=](u64 count_)
|
2025-07-05 17:05:53 -05:00
|
|
|
{
|
2026-02-12 23:50:38 -05:00
|
|
|
if(fuse_cfg.debug)
|
2025-07-05 17:05:53 -05:00
|
|
|
metrics_log_nodes_info_to_tmp_dir(f_);
|
|
|
|
|
});
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
struct fuse*
|
2026-02-16 20:55:18 -06:00
|
|
|
fuse_new(int fd_,
|
|
|
|
|
size_t bufsize_,
|
2025-10-13 00:21:36 -04:00
|
|
|
struct fuse_args *args,
|
|
|
|
|
const struct fuse_operations *ops_)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *root;
|
2020-07-31 23:50:47 -04:00
|
|
|
struct fuse_lowlevel_ops llop = fuse_path_ops;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops = *ops_;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
f.se = fuse_lowlevel_new_common(args,&llop,sizeof(llop));
|
2025-10-13 00:21:36 -04:00
|
|
|
if(f.se == NULL)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_free_fs;
|
|
|
|
|
|
2026-02-16 20:55:18 -06:00
|
|
|
/* Inlined channel fields - direct assignment */
|
|
|
|
|
f.se->fd = fd_;
|
|
|
|
|
f.se->bufsize = bufsize_;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
/* Trace topmost layer by default */
|
|
|
|
|
srand(time(NULL));
|
2025-10-13 00:21:36 -04:00
|
|
|
f.nodeid_gen.nodeid = FUSE_ROOT_ID;
|
|
|
|
|
f.nodeid_gen.generation = rand64();
|
|
|
|
|
if(node_table_init(&f.name_table) == -1)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_free_session;
|
|
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
if(node_table_init(&f.id_table) == -1)
|
2020-07-31 23:50:47 -04:00
|
|
|
goto out_free_name_table;
|
|
|
|
|
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_init(f.lock);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2023-04-23 23:33:48 -04:00
|
|
|
root = node_alloc();
|
2020-11-15 19:12:33 -05:00
|
|
|
if(root == NULL)
|
|
|
|
|
{
|
2026-04-18 01:00:11 -04:00
|
|
|
fprintf(stderr,"mergerfs: root node alloc failed\n");
|
2020-11-15 19:12:33 -05:00
|
|
|
goto out_free_id_table;
|
|
|
|
|
}
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2026-04-18 01:00:11 -04:00
|
|
|
root->name = xstrdup("/");
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
root->parent = NULL;
|
|
|
|
|
root->nodeid = FUSE_ROOT_ID;
|
|
|
|
|
inc_nlookup(root);
|
2025-10-13 00:21:36 -04:00
|
|
|
hash_id(root);
|
2020-07-31 23:50:47 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
return &f;
|
2020-07-31 23:50:47 -04:00
|
|
|
|
|
|
|
|
out_free_id_table:
|
2025-10-13 00:21:36 -04:00
|
|
|
free(f.id_table.array);
|
2020-07-31 23:50:47 -04:00
|
|
|
out_free_name_table:
|
2025-10-13 00:21:36 -04:00
|
|
|
free(f.name_table.array);
|
2020-07-31 23:50:47 -04:00
|
|
|
out_free_session:
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_session_destroy(f.se);
|
2020-07-31 23:50:47 -04:00
|
|
|
out_free_fs:
|
|
|
|
|
/* Horrible compatibility hack to stop the destructor from being
|
|
|
|
|
called on the filesystem without init being called first */
|
2025-10-13 00:21:36 -04:00
|
|
|
f.ops.destroy = NULL;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
return NULL;
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2020-11-15 19:12:33 -05:00
|
|
|
void
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_destroy(struct fuse *)
|
2016-10-05 09:33:37 -04:00
|
|
|
{
|
2020-07-31 23:50:47 -04:00
|
|
|
size_t i;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
for(i = 0; i < f.id_table.size; i++)
|
2020-11-15 19:12:33 -05:00
|
|
|
{
|
2023-04-23 23:33:48 -04:00
|
|
|
node_t *node;
|
|
|
|
|
node_t *next;
|
2016-10-05 09:33:37 -04:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
for(node = f.id_table.array[i]; node != NULL; node = next)
|
2020-07-31 23:50:47 -04:00
|
|
|
{
|
2020-11-15 19:12:33 -05:00
|
|
|
next = node->id_next;
|
2025-10-13 00:21:36 -04:00
|
|
|
free_node(node);
|
|
|
|
|
f.id_table.use--;
|
2020-07-31 23:50:47 -04:00
|
|
|
}
|
|
|
|
|
}
|
2020-11-15 19:12:33 -05:00
|
|
|
|
2025-10-13 00:21:36 -04:00
|
|
|
free(f.id_table.array);
|
|
|
|
|
free(f.name_table.array);
|
2026-02-20 22:27:55 -06:00
|
|
|
mutex_destroy(f.lock);
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_session_destroy(f.se);
|
2016-10-05 09:33:37 -04:00
|
|
|
}
|
|
|
|
|
|
2025-06-05 23:47:42 -05:00
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_passthrough_open(const int fd_)
|
2025-06-05 23:47:42 -05:00
|
|
|
{
|
|
|
|
|
int rv;
|
|
|
|
|
int dev_fuse_fd;
|
2025-10-29 22:42:42 -05:00
|
|
|
struct fuse_backing_map bm = {};
|
2025-06-05 23:47:42 -05:00
|
|
|
|
2026-02-16 20:55:18 -06:00
|
|
|
dev_fuse_fd = f.se->fd;
|
2025-06-05 23:47:42 -05:00
|
|
|
bm.fd = fd_;
|
|
|
|
|
|
|
|
|
|
rv = ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_OPEN,&bm);
|
|
|
|
|
|
2026-01-19 15:16:01 -06:00
|
|
|
return ((rv < 0) ? INVALID_BACKING_ID : rv);
|
2025-06-05 23:47:42 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-10-13 00:21:36 -04:00
|
|
|
fuse_passthrough_close(const int backing_id_)
|
2025-06-05 23:47:42 -05:00
|
|
|
{
|
|
|
|
|
int dev_fuse_fd;
|
|
|
|
|
|
2026-01-19 15:16:01 -06:00
|
|
|
if(!fuse_backing_id_is_valid(backing_id_))
|
|
|
|
|
return 0;
|
|
|
|
|
|
2026-02-16 20:55:18 -06:00
|
|
|
dev_fuse_fd = f.se->fd;
|
2025-06-05 23:47:42 -05:00
|
|
|
|
|
|
|
|
return ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_CLOSE,&backing_id_);
|
|
|
|
|
}
|