fuse2fs: prepare for kernel driver replacement
PATCH 2/5 fuse2fs: prepare for kernel driver replacement
Hi all,
This series creates a new "kernel" mount option that signals to the fuse2fs driver that it's being used as a containerizable replacement for the kernel driver. This has the effect of delegating quite a lot of decisionmaking to the kernel, and opening access to users other than whoever's running the fuse2fs server.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
Comments and questions are, as always, welcome.
e2fsprogs git tree:
https://git.kernel.org/cgit/linux/kernel/git/djwong/e2fsprogs.git/log/?h=fuse2fs-kernel
---
Commits in this patchset:
* fuse2fs: add dummy acl/user_xattr mount options
* fuse2fs: set fuse subtype via argv[0] if possible
* fuse2fs: make "ro" behavior consistent with the kernel
--- misc/fuse2fs.c | 56 ++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 18 deletions(-)
PATCH 1/3 fuse2fs: add dummy acl/user_xattr mount options
From: Darrick J. Wong <[email protected]>
ACLs and user xattrs are always supported, so add these mount options and do nothing.
--- misc/fuse2fs.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
misc/fuse2fs.c +7 -1
@@ -3728,6 +3728,7 @@ static int get_random_bytes(void *p, size_t sz) }enum { +FUSE2FS_IGNORED ,FUSE2FS_VERSION ,FUSE2FS_HELP ,FUSE2FS_HELPFULL ,
@@ -3743,7 +3744,10 @@ static struct fuse_opt fuse2fs_opts[] = {FUSE2FS_OPT ("fuse2fs_debug" , debug,1 ),FUSE2FS_OPT ("no_default_opts" , no_default_opts,1 ),FUSE2FS_OPT ("norecovery" , norecovery,1 ), -FUSE2FS_OPT ("offset=%lu" , offset,0 ), +FUSE2FS_OPT ("offset=%lu" , offset,0 ), + +FUSE_OPT_KEY ("acl" ,FUSE2FS_IGNORED ), +FUSE_OPT_KEY ("user_xattr" ,FUSE2FS_IGNORED ),FUSE_OPT_KEY ("-V" ,FUSE2FS_VERSION ), FUSE_OPT_KEY("--version", FUSE2FS_VERSION),
@@ -3766,6 +3770,8 @@ static int fuse2fs_opt_proc(void *data, const char *arg,return 0 ; }return 1 ; +case FUSE2FS_IGNORED : +return 0 ;case FUSE2FS_HELP :case FUSE2FS_HELPFULL : fprintf(stderr,
PATCH 2/3 fuse2fs: set fuse subtype via argv[0] if possible
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
If argv[0] ends in "ext[0-9]", set the fuse subtype string to this value. This enables us to place fuse2fs at some place in the filesystem like /sbin/mount.ext2 and have /proc/mounts report the filesystem type as "fuse.ext2". This is fairly boring, but it'll make it easier to test things in fstests.
--- misc/fuse2fs.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
misc/fuse2fs.c +20 -1
@@ -26,6 +26,7 @@#endif #include <sys/ioctl.h> #include <unistd.h> +#include <ctype.h> #ifdef __SET_FOB_FOR_FUSE# error Do not set magic value __SET_FOB_FOR_FUSE!!!!#endif
@@ -3812,6 +3813,23 @@ static int fuse2fs_opt_proc(void *data, const char *arg,return 1 ; } +static const char *get_subtype (const char *argv0) +{ +size_t argvlen =strlen (argv0); + +if (argvlen <4 ) + goto out_default; + +if (argv0[argvlen -4 ] =='e' && + argv0[argvlen -3 ] =='x' && + argv0[argvlen -2 ] =='t' && +isdigit (argv0[argvlen -1 ])) +return &argv0[argvlen -4 ]; + +out_default: +return "ext4" ; +} +int main (int argc,char *argv[]) {struct fuse_args args =FUSE_ARGS_INIT (argc, argv);
@@ -3954,8 +3972,9 @@ int main(int argc, char *argv[])get_random_bytes (&fctx.next_generation,sizeof (unsigned int ));/* Set up default fuse parameters */ -snprintf (extra_args,BUFSIZ ,"-okernel_cache,subtype=ext4," +snprintf (extra_args,BUFSIZ ,"-okernel_cache,subtype=%s," "fsname=%s,attr_timeout=0" FUSE_PLATFORM_OPTS , +get_subtype (argv[0 ]), fctx.device);if (fctx.no_default_opts ==0 )fuse_opt_add_arg (&args, extra_args);
PATCH 3/3 fuse2fs: make "ro" behavior consistent with the kernel
In reply to Darrick J. WongFrom: Darrick J. Wong <[email protected]>
Make the behavior of the "ro" mount option consistent with the kernel:
User programs cannot change the files in the filesystem, but the driver itself is allowed to update the filesystem metadata. This means that ro mounts can recover the journal.
--- misc/fuse2fs.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
misc/fuse2fs.c +11 -16
@@ -3739,6 +3739,7 @@ enum {static struct fuse_opt fuse2fs_opts[] = {FUSE2FS_OPT ("ro" , ro,1 ), +FUSE2FS_OPT ("rw" , ro,0 ),FUSE2FS_OPT ("errors=panic" , panic_on_error,1 ),FUSE2FS_OPT ("minixdf" , minixdf,1 ),FUSE2FS_OPT ("fakeroot" , fakeroot,1 ),
@@ -3784,13 +3785,12 @@ static int fuse2fs_opt_proc(void *data, const char *arg," -V --version print version\n" "\n" "fuse2fs options:\n" -" -o ro read-only mount\n" " -o errors=panic dump core on error\n" " -o minixdf minix-style df\n" " -o fakeroot pretend to be root for permission checks\n" " -o no_default_opts do not include default fuse options\n" " -o offset=<bytes> similar to mount -o offset=<bytes>, mount the partition starting at <bytes>\n" -" -o norecovery don't replay the journal (implies ro)\n" +" -o norecovery don't replay the journal\n" " -o fuse2fs_debug enable fuse2fs debugging\n" "\n" , outargs->argv[0]);
@@ -3838,7 +3838,8 @@ int main(int argc, char *argv[])char *logfile;char extra_args[BUFSIZ ];int ret =0 ; -int flags =EXT2_FLAG_64BITS |EXT2_FLAG_THREADS |EXT2_FLAG_EXCLUSIVE ; +int flags =EXT2_FLAG_64BITS |EXT2_FLAG_THREADS |EXT2_FLAG_EXCLUSIVE | +EXT2_FLAG_RW ;memset (&fctx,0 ,sizeof (fctx)); fctx.magic =FUSE2FS_MAGIC ;
@@ -3857,11 +3858,6 @@ int main(int argc, char *argv[])else fctx.shortdev = fctx.device; -if (fctx.norecovery) - fctx.ro =1 ; -if (fctx.ro) -log_printf (&fctx,"%s\n" ,_ ("Mounting read-only." )); -#ifdef ENABLE_NLS setlocale (LC_MESSAGES ,"" );setlocale (LC_CTYPE ,"" );
@@ -3892,8 +3888,6 @@ int main(int argc, char *argv[])/* Start up the fs (while we still can use stdout) */ ret =2 ; -if (!fctx.ro) - flags |=EXT2_FLAG_RW ;char options[50 ];sprintf (options,"offset=%lu" , fctx.offset); err = ext2fs_open2(fctx.device, options, flags, 0, 0, unix_io_manager,
@@ -3912,7 +3906,9 @@ int main(int argc, char *argv[])if (fctx.norecovery) {log_printf (&fctx,"%s\n" ,_ ("Mounting read-only without recovering journal." )); - }else if (!fctx.ro) { + fctx.ro =1 ; + global_fs->flags &= ~EXT2_FLAG_RW ; + }else {log_printf (&fctx,"%s\n" ,_ ("Recovering journal." )); err =ext2fs_run_ext3_journal (&global_fs);if (err) {
@@ -3923,14 +3919,10 @@ int main(int argc, char *argv[]) }ext2fs_clear_feature_journal_needs_recovery (global_fs->super);ext2fs_mark_super_dirty (global_fs); - }else { -err_printf (&fctx,"%s\n" , -_ ("Journal needs recovery; running `e2fsck -E journal_only' is required." )); - goto out; } } -if (!fctx.ro) { +if (global_fs->flags &EXT2_FLAG_RW ) {if (ext2fs_has_feature_journal (global_fs->super))log_printf (&fctx,"%s\n" ,_ ("Writing to the journal is not supported." ));
@@ -3979,6 +3971,9 @@ int main(int argc, char *argv[])if (fctx.no_default_opts ==0 )fuse_opt_add_arg (&args, extra_args); +if (fctx.ro) +fuse_opt_add_arg (&args,"-oro" ); +if (fctx.fakeroot) {#ifdef HAVE_MOUNT_NODEV fuse_opt_add_arg (&args,"-onodev" );
Theodore Ts'o
AppliedQuoted 10 lines · Darrick J. Wong
This series creates a new "kernel" mount option that signals to the fuse2fs driver that it's being used as a containerizable replacement for the kernel driver. This has the effect of delegating quite a lot of decisionmaking to the kernel, and opening access to users other than whoever's running the fuse2fs server.
If you're going to start using this code, I strongly recommend pulling from my git trees, which are linked below.
[...]
Applied, thanks!
[1/3] fuse2fs: add dummy acl/user_xattr mount options
commit: 5776fc59fb26ecf7a9d4f4ee4cf139ba52bc27a9
[2/3] fuse2fs: set fuse subtype via argv[0] if possible
commit: 13e365bbfdd97cc086ee9e33cb42f514d8a415ac
[3/3] fuse2fs: make "ro" behavior consistent with the kernel
commit: 3875380971d3b63d08fd97c37dd86bf99e898ac8Best regards,
Signature · 1 line
Theodore Ts'o <[email protected]>