From cc21d1ab7c157da459a33ddd6b30d862cd144eec Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 5 Dec 2023 19:18:31 +1100 Subject: [PATCH 1/3] Corrected the "-dump" report of fragment start position. --- fusefile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fusefile.c b/fusefile.c index f36bcfb..a1bf2bd 100644 --- a/fusefile.c +++ b/fusefile.c @@ -988,8 +988,8 @@ static int dump_fragments(int push) { if ( !push ) { fprintf( stdout, "%s/%ld:%ld\n", sources.array[ src ].filename, - sources.array[ src ].from, - //pos - sources.array[ src ].start, + sources.array[ src ].from + + pos - sources.array[ src ].start, x - sources.array[ src ].start + sources.array[ src ].from ); -- 2.47.2 From ef3677046ab6225bd167c6ffaf3d830b325d72cd Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 8 Oct 2024 10:48:53 +1100 Subject: [PATCH 2/3] Fully migrated to libfuse3 --- Makefile | 2 +- fusefile.c | 58 +++++++++++++++++++++++++++--------------------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index 9f02adc..1287fdc 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ ${BINS}: CFLAGS += -DDEBUG=1 -g endif ${BINS}: CFLAGS += -Wall -D_FILE_OFFSET_BITS=64 -fusefile: LDFLAGS = -lfuse -pthread +fusefile: LDFLAGS = -lfuse3 -pthread .INTERMEDIATE: fusefile.o fusefile.o: fusefile.c diff --git a/fusefile.c b/fusefile.c index a1bf2bd..2c7bc8d 100644 --- a/fusefile.c +++ b/fusefile.c @@ -25,8 +25,8 @@ #define FUSE_USE_VERSION 33 -#include -#include +#include +#include #include #include #include @@ -415,7 +415,9 @@ static int setup_sources(char **argv,int i,int n) { return 0; } -static int fusefile_getattr(const char *path,struct stat *stbuf) { +static int fusefile_getattr(const char *path, struct stat *stbuf, + struct fuse_file_info *ffi) +{ #if DEBUG fprintf( stderr, "fusefile_getattr( %s )\n", path ); #endif @@ -437,17 +439,19 @@ static int fusefile_getattr(const char *path,struct stat *stbuf) { return 0; } -static int fusefile_chmod(const char *path,mode_t m) { +static int fusefile_chmod(const char *path, mode_t m, + struct fuse_file_info *ffi) +{ #if DEBUG fprintf( stderr, "fusefile_chmod( %s, %d )\n", path, m ); #endif return -1; } -static int fusefile_open(const char *path,struct fuse_file_info *fi) { +static int fusefile_open(const char *path, struct fuse_file_info *ffi) { #if DEBUG - fprintf( stderr, "fusefile_open( %s, %d )\n", path, fi->flags ); - fprintf( stderr, "fixing( %d )\n", fi->flags | O_CLOEXEC ); + fprintf( stderr, "fusefile_open( %s, %d )\n", path, ffi->flags ); + fprintf( stderr, "fixing( %d )\n", ffi->flags | O_CLOEXEC ); #endif if ( strcmp( path, "/" ) != 0 ) { return -ENOENT; @@ -507,7 +511,7 @@ static int overlay_merge(char *buf,off_t beg,off_t end) { // Read bytes from in file static int fusefile_read(const char *path, char *buf, size_t size, - off_t off, struct fuse_file_info *fi) + off_t off, struct fuse_file_info *ffi) { if( strcmp( path, "/" ) != 0 ) { return -ENOENT; @@ -576,8 +580,8 @@ static int fusefile_read(const char *path, char *buf, size_t size, /** * Poll for IO readiness. */ -int fusefile_poll(const char *path, struct fuse_file_info *fi, - struct fuse_pollhandle *ph, unsigned *reventsp ) +int fusefile_poll(const char *path, struct fuse_file_info *ffi, + struct fuse_pollhandle *ph, unsigned *reventsp ) { #if DEBUG fprintf( stderr, "fusefile_poll( %s ) %p %d\n", path, ph, *reventsp ); @@ -798,7 +802,7 @@ static int write_block(off_t off,const char *buf,size_t size) { } static int fusefile_write_buf(const char *path, struct fuse_bufvec *buf, - off_t off, struct fuse_file_info *fi) { + off_t off, struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_write_buf( %s )\n", path ); #endif @@ -830,7 +834,7 @@ static int fusefile_write_buf(const char *path, struct fuse_bufvec *buf, * Write a fragment at . This overwrites files. */ static int fusefile_write(const char *path, const char *buf, size_t size, - off_t off, struct fuse_file_info *fi) + off_t off, struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_write( %s %ld )\n", path, size ); @@ -903,7 +907,7 @@ static void fsync_all_dirty() { } } -static int fusefile_flush(const char *path, struct fuse_file_info *info) { +static int fusefile_flush(const char *path, struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_flush( %s )\n", path ); #endif @@ -914,7 +918,7 @@ static int fusefile_flush(const char *path, struct fuse_file_info *info) { return 0; } -static int fusefile_release(const char *path, struct fuse_file_info *fi) { +static int fusefile_release(const char *path, struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_release( %s, %d )\n", path, fi->flags ); #endif @@ -924,7 +928,8 @@ static int fusefile_release(const char *path, struct fuse_file_info *fi) { return 0; } -static int fusefile_fsync(const char *path, int x, struct fuse_file_info *fi) { +static int fusefile_fsync(const char *path, int x, + struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_fsync( %s, %d )\n", path, x ); #endif @@ -938,7 +943,8 @@ static int fusefile_fsync(const char *path, int x, struct fuse_file_info *fi) { /** * */ -static int fusefile_truncate(const char *path, off_t len) { +static int fusefile_truncate(const char *path, off_t len, + struct fuse_file_info *ffi) { #if DEBUG fprintf( stderr, "fusefile_truncate( %s, %ld )\n", path, len ); #endif @@ -948,13 +954,12 @@ static int fusefile_truncate(const char *path, off_t len) { return -EIO; } -void *fusefile_init(struct fuse_conn_info *fci) { +void *fusefile_init(struct fuse_conn_info *fci, struct fuse_config *fc) { #if DEBUG fprintf( stderr, "fusefile_init( %d, %d )\n", fci->async_read, fci->want ); #endif - // Disable asynchronous reading - fci->async_read = 0; - fci->want &= ~FUSE_CAP_ASYNC_READ; + // Disable asynchronous operations, both reading and direct I/O + fci->want &= ~ ( FUSE_CAP_ASYNC_READ | FUSE_CAP_ASYNC_DIO ); #if DEBUG fprintf( stderr, "fusefile_init( %d, %d )\n", fci->async_read, fci->want ); #endif @@ -1031,7 +1036,6 @@ static struct fuse_operations fusefile_oper = { .fsync = fusefile_fsync, // NYI .ftruncate = fusefile_ftruncate, .truncate = fusefile_truncate, - //.truncate = fusefile_truncate, //.release = fusefile_release, .init = fusefile_init, }; @@ -1082,8 +1086,6 @@ static int setup_argv(int argc,char ***argv) { int main(int argc, char *argv[]) { char *mnt; - int mt; - int fg; int i; int fuseargc; struct stat stbuf; @@ -1153,13 +1155,11 @@ int main(int argc, char *argv[]) return dump_fragments( 1 ); } struct fuse_args args = FUSE_ARGS_INIT( fuseargc, argv ); - if ( fuse_parse_cmdline( &args, &mnt, &mt, &fg ) ) { + struct fuse_cmdline_opts opts = { 0 }; + if ( fuse_parse_cmdline( &args, &opts ) ) { return 1; } fuse_opt_free_args( &args ); - if ( ! mnt ) { - fprintf( stderr, "missing mountpoint parameter\n" ); - return 1; - } - return fuse_main( fuseargc, argv, &fusefile_oper, temporary? mnt : NULL ); + return fuse_main( fuseargc, argv, &fusefile_oper, + temporary? opts.mountpoint : NULL ); } -- 2.47.2 From ec342280389f14bf8e9aadc7947a41a726d06061 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 8 Oct 2024 14:02:47 +1100 Subject: [PATCH 3/3] test of asynchronous write/read --- asynctest.lsp | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100755 asynctest.lsp diff --git a/asynctest.lsp b/asynctest.lsp new file mode 100755 index 0000000..b9967e1 --- /dev/null +++ b/asynctest.lsp @@ -0,0 +1,70 @@ +#!/usr/bin/newlisp +# +# This is a test script for the overlay function of fusefile. +# +# 1) prepare a base image +# 2) set up a fusefile +# 3) run tests +# 4) dismantle the fusefile +# 5) remove test images + + +; ID is hour, minute and second values packed into a string +(constant + 'ID (apply string (3 3 (now))) + 'BASE (format "%s.raw" ID) 'SEGSZ 17000 'SEGN 40 + 'FILE (join (map (fn (R) (format "%s/%d:%d" (cons BASE R))) + (map (curry map (curry * SEGSZ) R) + '((14 22) (0 3) (22 40) (3 22)))) + " ") + 'LIBC6 "/lib/x86_64-linux-gnu/libc.so.6" + 'MINE "mine" + ) +(import LIBC6 "on_exit" "int" "void*" "void*") + +;; BASE is set up as a holes file with SEGN segments of size SEGSZ +(! (format "dd if=/dev/zero of=%s bs=%d seek=%d count=0 status=none" + BASE SEGSZ SEGN)) + +;; Set up the fusefile +(unless (= (! (format "fusefile %s %s %s" + "-ononempty -oallow_other" BASE FILE))) + (exit 1)) + +(println (list BASE FILE)) + +(define (writer CODE ADDR) + (println "writer " (char (CODE 0)) " " ADDR) + (let ((FD (open BASE "u"))) + (when (> FD) + (seek FD ADDR) + (write FD CODE) + (close FD)))) + +(define (reader CODE ADDR) + (println "reader " (char (CODE 0)) " " ADDR) + (let ((FD (open BASE "u")) (TODO (length CODE)) (BUFFER "") (B "")) + (if (when (> FD) + (seek FD ADDR) + (while (and (> TODO) (> (setf N (read FD B TODO)))) + (extend BUFFER B) + (dec TODO (length B))) + (close FD) + (and (= TODO) (= CODE BUFFER))) + (println "reader " (char (CODE 0)) " done") + (println "reader " (char (CODE 0)) " failed") + ))) + +(define (forking FN I) + (letex ((FN FN) (CODE (dup (char I) (/ SEGSZ 2))) (ADDR (* (- I 1) SEGSZ))) + (fork (FN CODE ADDR)))) + +(map wait-pid (map (curry forking writer) (sequence 1 SEGN))) +(map wait-pid (map (curry forking reader) (sequence 1 SEGN))) + +;; On exit: unmount the fusefile and delete the BASE +(! (format "fusermount -u %s" BASE)) +(delete-file BASE) + +(exit 0) + -- 2.47.2