[pve-devel] [RFC cluster] switch to fuse3

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jul 15 09:47:42 CEST 2022


the new file info and flag parameters can be ignored (for now), except
for the rename flags, which must be handled.

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
since I had it lying around from the double auth key rotation
investigation.. there is some more things we could do like implementing
the rename flags, using fi->fh to correlate opens and other operations
on the opened file, or the big elephant, switching to low level fuse ;)

I gave this a rough spin while doing the auth key tests (but reverted to
stock when the invalidate cache via fuse3 approach turned out to be
infeasible), so this likely needs some more exposure.

 data/src/Makefile         |  4 ++--
 data/src/cfs-plug.h       |  2 +-
 data/src/loop.h           |  2 +-
 data/src/cfs-plug-memdb.c |  6 +++---
 data/src/cfs-plug.c       | 11 ++++++-----
 data/src/pmxcfs.c         | 39 +++++++++++++++++++++------------------
 6 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/data/src/Makefile b/data/src/Makefile
index 1f39f67..87fedf8 100644
--- a/data/src/Makefile
+++ b/data/src/Makefile
@@ -1,8 +1,8 @@
 
-DEPENDENCIES=libcpg libcmap libquorum libqb glib-2.0 fuse sqlite3 librrd
+DEPENDENCIES=libcpg libcmap libquorum libqb glib-2.0 fuse3 sqlite3 librrd
 
 CC = gcc
-CFLAGS += -std=gnu99
+CFLAGS += -std=gnu11
 CFLAGS += -Wall -Werror -Wno-unknown-pragmas -Wno-strict-aliasing
 CFLAGS += -Wpedantic
 CFLAGS += -g -O2 -Wl,-z,relro
diff --git a/data/src/cfs-plug.h b/data/src/cfs-plug.h
index 5837ca8..cf94122 100644
--- a/data/src/cfs-plug.h
+++ b/data/src/cfs-plug.h
@@ -23,7 +23,7 @@
 #ifndef _PVE_CFS_PLUG_H_
 #define _PVE_CFS_PLUG_H_
 
-#define FUSE_USE_VERSION 26
+#define FUSE_USE_VERSION 310
 
 #include <errno.h>
 #include <fuse.h>
diff --git a/data/src/loop.h b/data/src/loop.h
index 68b783c..b92da61 100644
--- a/data/src/loop.h
+++ b/data/src/loop.h
@@ -21,7 +21,7 @@
 #ifndef _PVE_LOOP_H_
 #define _PVE_LOOP_H_
 
-#define FUSE_USE_VERSION 26
+#define FUSE_USE_VERSION 310
 
 #include <glib.h>
 #include <fuse.h>
diff --git a/data/src/cfs-plug-memdb.c b/data/src/cfs-plug-memdb.c
index b7a5567..4e2ff7b 100644
--- a/data/src/cfs-plug-memdb.c
+++ b/data/src/cfs-plug-memdb.c
@@ -161,8 +161,8 @@ static int cfs_plug_memdb_readdir(
 
 	if (dirlist) {
 
-		filler(buf, ".", NULL, 0);
-		filler(buf, "..", NULL, 0);
+		filler(buf, ".", NULL, 0, 0);
+		filler(buf, "..", NULL, 0, 0);
 
 		struct stat stbuf;
 		memset(&stbuf, 0, sizeof(struct stat));
@@ -172,7 +172,7 @@ static int cfs_plug_memdb_readdir(
 			memdb_tree_entry_t *te = (memdb_tree_entry_t *)l->data;
 
 			tree_entry_stat(te, &stbuf, 0);
-			filler(buf, te->name, &stbuf, 0);
+			filler(buf, te->name, &stbuf, 0, 0);
 			l = g_list_next(l);
 		}
 
diff --git a/data/src/cfs-plug.c b/data/src/cfs-plug.c
index 108ed6b..2e6efab 100644
--- a/data/src/cfs-plug.c
+++ b/data/src/cfs-plug.c
@@ -115,7 +115,8 @@ static int tmp_hash_filler (
 	void *buf, 
 	const char *name,
 	const struct stat *stbuf, 
-	off_t off) {
+	off_t off,
+	enum fuse_fill_dir_flags flags) {
 
 	struct hash_filler *hf = (struct hash_filler *)buf;
 
@@ -125,7 +126,7 @@ static int tmp_hash_filler (
 	if (name[0] == '.' && (name[1] == 0 || (name[1] == '.' && name[2] ==  0)))
 		return 0;
 
-	hf->filler(hf->buf, name, stbuf, off);
+	hf->filler(hf->buf, name, stbuf, off, flags);
 
 	return 0;
 }
@@ -148,8 +149,8 @@ static int cfs_plug_base_readdir(cfs_plug_t *plug, const char *path, void *buf,
 
 	int ret = -EACCES;
 
-	filler(buf, ".", NULL, 0);
-	filler(buf, "..", NULL, 0);
+	filler(buf, ".", NULL, 0, 0);
+	filler(buf, "..", NULL, 0, 0);
 
 	if (!path[0]) {
 		GHashTableIter iter;
@@ -158,7 +159,7 @@ static int cfs_plug_base_readdir(cfs_plug_t *plug, const char *path, void *buf,
 		g_hash_table_iter_init (&iter, bplug->entries);
 
 		while (g_hash_table_iter_next (&iter, &key, &value)) {
-			filler(buf, key, NULL, 0);
+			filler(buf, key, NULL, 0, 0);
 		}
 	}
 
diff --git a/data/src/pmxcfs.c b/data/src/pmxcfs.c
index d78a248..cd9dda0 100644
--- a/data/src/pmxcfs.c
+++ b/data/src/pmxcfs.c
@@ -117,12 +117,12 @@ static cfs_plug_t *find_plug(const char *path, char **sub)
 	return plug;
 }
 
-void *cfs_fuse_init(struct fuse_conn_info *conn)
+void *cfs_fuse_init(struct fuse_conn_info *conn, struct fuse_config *config)
 {
 	return NULL;
 }
 
-static int cfs_fuse_getattr(const char *path, struct stat *stbuf)
+static int cfs_fuse_getattr(const char *path, struct stat *stbuf, struct fuse_file_info *file_info)
 {
 	cfs_debug("enter cfs_fuse_getattr %s", path);
 
@@ -157,7 +157,7 @@ static int cfs_fuse_getattr(const char *path, struct stat *stbuf)
 }
 
 static int cfs_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
-			    off_t offset, struct fuse_file_info *fi)
+			    off_t offset, struct fuse_file_info *fi, enum fuse_readdir_flags flags)
 {
 	(void) offset;
 	(void) fi;
@@ -183,7 +183,7 @@ ret:
 	return ret;
 }
 
-static int cfs_fuse_chmod(const char *path, mode_t mode)
+static int cfs_fuse_chmod(const char *path, mode_t mode, struct fuse_file_info *fi)
 {
 	int ret = -EPERM;
 
@@ -203,7 +203,7 @@ static int cfs_fuse_chmod(const char *path, mode_t mode)
 	return ret;
 }
 
-static int cfs_fuse_chown(const char *path, uid_t user, gid_t group)
+static int cfs_fuse_chown(const char *path, uid_t user, gid_t group, struct fuse_file_info *fi)
 {
 	int ret = -EPERM;
 
@@ -266,12 +266,17 @@ static int cfs_fuse_rmdir(const char *path)
 	return ret;
 }
 
-static int cfs_fuse_rename(const char *from, const char *to)
+static int cfs_fuse_rename(const char *from, const char *to, unsigned int flags)
 {
 	cfs_debug("enter cfs_fuse_rename from %s to %s", from, to);
 
 	int ret = -EACCES;
 
+	// TODO implement support for NOREPLACE and EXCHANGE?
+	if (flags) {
+		return -EINVAL;
+	}
+
 	char *sub_from = NULL;
 	cfs_plug_t *plug_from = find_plug(from, &sub_from);
 
@@ -373,7 +378,7 @@ static int cfs_fuse_write(const char *path, const char *buf, size_t size,
 	return ret;
 }
 
-static int cfs_fuse_truncate(const char *path, off_t size)
+static int cfs_fuse_truncate(const char *path, off_t size, struct fuse_file_info *fi)
 {
 	cfs_debug("enter cfs_fuse_truncate %s %jd", path, size);
 
@@ -467,7 +472,7 @@ ret:
 	return ret;
 }
 
-static int cfs_fuse_utimens(const char *path, const struct timespec tv[2])
+static int cfs_fuse_utimens(const char *path, const struct timespec tv[2], struct fuse_file_info *fi)
 {
 	cfs_debug("enter cfs_fuse_utimens %s", path);
 
@@ -938,19 +943,13 @@ int main(int argc, char *argv[])
 	char *fa[] = { "-f", "-odefault_permissions", "-oallow_other", NULL};
 
 	struct fuse_args fuse_args = FUSE_ARGS_INIT(sizeof (fa)/sizeof(gpointer) - 1, fa);
-
-	struct fuse_chan *fuse_chan = fuse_mount(CFSDIR, &fuse_args);
-	if (!fuse_chan) {
-		cfs_critical("fuse_mount error: %s", strerror(errno));
-		goto err;
-	}
-
-	if (!(fuse = fuse_new(fuse_chan, &fuse_args, &fuse_ops, sizeof(fuse_ops), NULL))) {
+	if (!(fuse = fuse_new(&fuse_args, &fuse_ops, sizeof(fuse_ops), NULL))) {
 		cfs_critical("fuse_new error: %s", strerror(errno));
 		goto err;
 	}
 
 	fuse_set_signal_handlers(fuse_get_session(fuse));
+	fuse_mount(fuse, CFSDIR);
 
 	if (!foreground) {
 		if (pipe(pipefd) == -1) {
@@ -1049,7 +1048,9 @@ int main(int argc, char *argv[])
 		close(pipefd[1]);
 	}
 
-	ret = fuse_loop_mt(fuse);
+	struct fuse_loop_config fuse_cfg;
+
+	ret = fuse_loop_mt(fuse, &fuse_cfg);
 
 	open(RESTART_FLAG_FILE, O_CREAT|O_NOCTTY|O_NONBLOCK, S_IRUSR | S_IRGRP);
 	chown(RESTART_FLAG_FILE, 0, cfs.gid);
@@ -1058,7 +1059,9 @@ int main(int argc, char *argv[])
 
 	server_stop();
 
-	fuse_unmount(CFSDIR, fuse_chan);
+	fuse_remove_signal_handlers(fuse_get_session(fuse));
+
+	fuse_unmount(fuse);
 
 	fuse_destroy(fuse);
 
-- 
2.30.2






More information about the pve-devel mailing list