erofs-utils: introduce fuse implementation
Subsystems (2)
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover erofs-utils: introduce fuse implementation
From: Gao Xiang <[email protected]>
changes since v1:
- fix off-by-one error of namebuf in erofs_fill_dentries();
- drop unused "struct erofs_super_block super;" in lib/super.c;
- fix clang/32-bit build errors founded by travis CI.
Hi all,
I've finished cleaning up erofsfuse - a fuse implementation of erofs just now. It's now considered as multithread safe since it's currently stateless by killing useless caches and using high-level libfuse APIs(also libfuse itself is MT-safe). Therefore, I don't need to release another liberofs MT-safe version for now as well.
As I said eariler, the main usage of erofsfuse is to support handling erofs images on older kernels without kernel modification, which was requested by real vendors (thanks to folks from OPPO to pick it up).
And to summarize the benefits of erofsfuse, I think it would be:
- erofs images can be supported on various platforms;
- an independent unpack tool can be developed based on this;
- new on-disk feature can be iterated, verified effectively.
erofsfuse will be included in the upcoming erofs-utils v1.2, but disabled by default for now. Since it still needs sometime to stablize and also notice LZ4_decompress_safe_partial() was broken in lz4-1.9.2, which just fixed in lz4-1.9.3 days ago [1].
BTW, recently some other people get in touch with me in private to ask for some latest micro-benchmark among compression fses, so I spared some extra time on this as well, see:
https://github.com/erofs/erofs-openbenchmark/wiki/linux_5.10_rc4-compression-FSes-benchmark
I might test on hikey960 board as well yet need to seek more extra time but I think no much difference on relative relationship (but yeah, CPU-storage combination is vital for seqread uplimit).
Thanks,
Gao Xiang
[1] https://github.com/lz4/lz4/issues/783
Huang Jianan (2):
erofs-utils: fuse: support symlink & special inode
erofs-utils: fuse: add compressed file support
Li Guifu (1):
erofs-utils: introduce fuse implementation
Makefile.am | 4 + configure.ac | 22 +- fuse/Makefile.am | 10 + fuse/dir.c | 103 +++++++++ fuse/main.c | 240 +++++++++++++++++++++ include/erofs/decompress.h | 35 ++++ include/erofs/defs.h | 5 + include/erofs/internal.h | 94 ++++++++- include/erofs/io.h | 1 + include/erofs/trace.h | 14 ++ include/erofs_fs.h | 4 + lib/Makefile.am | 4 +- lib/data.c | 204 ++++++++++++++++++ lib/decompress.c | 87 ++++++++ lib/io.c | 16 ++ lib/namei.c | 264 +++++++++++++++++++++++ lib/super.c | 78 +++++++ lib/zmap.c | 415 +++++++++++++++++++++++++++++++++++++ 18 files changed, 1596 insertions(+), 4 deletions(-) create mode 100644 fuse/Makefile.am create mode 100644 fuse/dir.c create mode 100644 fuse/main.c create mode 100644 include/erofs/decompress.h create mode 100644 include/erofs/trace.h create mode 100644 lib/data.c create mode 100644 lib/decompress.c create mode 100644 lib/namei.c create mode 100644 lib/super.c create mode 100644 lib/zmap.c
Signature · 1 line
2.24.0
PATCH v2 1/3 erofs-utils: introduce fuse implementation
From: Gao Xiang <[email protected]>
From: Li Guifu <[email protected]>
Let's add a simple erofsfuse approach, and benefits are:
- images can be supported on various platforms;
- new unpack tool can be developed based on this;
- new on-disk features can be iterated, verified effectively.
This commit only addresses reading uncompressed regular files. Other file (e.g. compressed file) support is out of scope here.
Note that erofsfuse is an unstable feature for now (also notice LZ4_decompress_safe_partial() was broken in lz4-1.9.2, which just fixed in lz4-1.9.3), let's disable it by default for a while.
--- Makefile.am | 4 + configure.ac | 22 +++- fuse/Makefile.am | 10 ++ fuse/dir.c | 103 ++++++++++++++++ fuse/main.c | 230 ++++++++++++++++++++++++++++++++++++ include/erofs/internal.h | 86 +++++++++++++- include/erofs/io.h | 1 + include/erofs/trace.h | 14 +++ include/erofs_fs.h | 4 + lib/Makefile.am | 4 +- lib/data.c | 134 +++++++++++++++++++++ lib/io.c | 16 +++ lib/namei.c | 246 +++++++++++++++++++++++++++++++++++++++ lib/super.c | 78 +++++++++++++ 14 files changed, 948 insertions(+), 4 deletions(-) create mode 100644 fuse/Makefile.am create mode 100644 fuse/dir.c create mode 100644 fuse/main.c create mode 100644 include/erofs/trace.h create mode 100644 lib/data.c create mode 100644 lib/namei.c create mode 100644 lib/super.c
Makefile.am +4 -0
@@ -4,3 +4,7 @@ ACLOCAL_AMFLAGS = -I m4 SUBDIRS = man lib mkfs +if ENABLE_FUSE +SUBDIRS += fuse +endif +
configure.ac +21 -1
@@ -63,6 +63,10 @@ AC_ARG_ENABLE(lz4, [AS_HELP_STRING([--disable-lz4], [disable LZ4 compression support @<:@default=enabled@:>@])], [enable_lz4="$enableval"], [enable_lz4="yes"]) +AC_ARG_ENABLE(fuse, + [AS_HELP_STRING([--enable-fuse], [enable erofsfuse @<:@default=no@:>@])], + [enable_fuse="$enableval"], [enable_fuse="no"]) + AC_ARG_WITH(uuid, [AS_HELP_STRING([--without-uuid], [Ignore presence of libuuid and disable uuid support @<:@default=enabled@:>@])])
@@ -183,6 +187,20 @@ AS_IF([test "x$with_selinux" != "xno"], [ LIBS="${saved_LIBS}" CPPFLAGS="${saved_CPPFLAGS}"], [have_selinux="no"]) +# Configure fuse +AS_IF([test "x$enable_fuse" != "xno"], [ + PKG_CHECK_MODULES([libfuse], [fuse >= 2.6]) + # Paranoia: don't trust the result reported by pkgconfig before trying out + saved_LIBS="$LIBS" + saved_CPPFLAGS=${CPPFLAGS} + CPPFLAGS="${libfuse_CFLAGS} ${CPPFLAGS}" + LIBS="${libfuse_LIBS} $LIBS" + AC_CHECK_LIB(fuse, fuse_main, [ + have_fuse="yes" ], [ + AC_MSG_ERROR([libfuse (>= 2.6) doesn't work properly])]) + LIBS="${saved_LIBS}" + CPPFLAGS="${saved_CPPFLAGS}"], [have_fuse="no"]) + # Configure lz4 test -z $LZ4_LIBS && LZ4_LIBS='-llz4'
@@ -218,6 +236,7 @@ fi # Set up needed symbols, conditionals and compiler/linker flags AM_CONDITIONAL([ENABLE_LZ4], [test "x${have_lz4}" = "xyes"]) AM_CONDITIONAL([ENABLE_LZ4HC], [test "x${have_lz4hc}" = "xyes"]) +AM_CONDITIONAL([ENABLE_FUSE], [test "x${have_fuse}" = "xyes"]) if test "x$have_uuid" = "xyes"; then AC_DEFINE([HAVE_LIBUUID], 1, [Define to 1 if libuuid is found])
@@ -247,6 +266,7 @@ AC_SUBST([liblz4_LIBS]) AC_CONFIG_FILES([Makefile man/Makefile lib/Makefile - mkfs/Makefile]) + mkfs/Makefile + fuse/Makefile]) AC_OUTPUT
fuse/Makefile.am new file +10 -0
@@ -0,0 +1,10 @@ +# SPDX-License-Identifier: GPL-2.0+ +# Makefile.am + +AUTOMAKE_OPTIONS = foreign +bin_PROGRAMS = erofsfuse +erofsfuse_SOURCES = dir.c main.c +erofsfuse_CFLAGS = -Wall -Werror -I$(top_srcdir)/include +erofsfuse_CFLAGS += -DFUSE_USE_VERSION=26 ${libfuse_CFLAGS} +erofsfuse_LDADD = $(top_builddir)/lib/liberofs.la ${libfuse_LIBS} ${LZ4_LIBS} +
fuse/dir.c new file +103 -0
103 lines not on this page · raw message
fuse/main.c new file +230 -0
230 lines not on this page · raw message
include/erofs/internal.h +85 -1
127 lines not on this page · raw message
include/erofs/io.h +1 -0
@@ -17,6 +17,7 @@#endif int dev_open (const char *devname); +int dev_open_ro (const char *dev);void dev_close (void );int dev_write (const void *buf,u64 offset,size_t len);int dev_read (void *buf,u64 offset,size_t len);
include/erofs/trace.h new file +14 -0
@@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* erofs-utils/include/erofs/trace.h +* +* Copyright (C) 2020 Gao Xiang <[email protected]> +*/ +#ifndef __EROFS_TRACE_H +#define __EROFS_TRACE_H + +#define trace_erofs_map_blocks_flatmode_enter (inode, map, flags) ((void)0) +#define trace_erofs_map_blocks_flatmode_exit (inode, map, flags, ret) ((void)0) + +#endif +
include/erofs_fs.h +4 -0
@@ -279,6 +279,10 @@ struct z_erofs_vle_decompressed_index { } di_u; }; +#define Z_EROFS_VLE_LEGACY_INDEX_ALIGN (size) \ + (round_up(size, sizeof(struct z_erofs_vle_decompressed_index)) + \ + sizeof(struct z_erofs_map_header) + Z_EROFS_VLE_LEGACY_HEADER_PADDING) +#define Z_EROFS_VLE_EXTENT_ALIGN (size) round_up(size, \ sizeof(struct z_erofs_vle_decompressed_index))
lib/Makefile.am +2 -2
@@ -2,8 +2,8 @@ # Makefile.am noinst_LTLIBRARIES = liberofs.la -liberofs_la_SOURCES = config.c io.c cache.c inode.c xattr.c \ - compress.c compressor.c exclude.c +liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ + namei.c data.c compress.c compressor.c liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include if ENABLE_LZ4 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/data.c new file +134 -0
134 lines not on this page · raw message
lib/io.c +16 -0
@@ -108,6 +108,22 @@ int dev_open(const char *dev)return 0 ; } +/* XXX: temporary soluation. Disk I/O implementation needs to be refactored. */ +int dev_open_ro (const char *dev) +{ +int fd =open (dev,O_RDONLY |O_BINARY ); + +if (fd <0 ) { +erofs_err ("failed to open(%s)." , dev); +return -errno; + } + + erofs_devfd = fd; + erofs_devname = dev; + erofs_devsz =INT64_MAX ; +return 0 ; +} +u64 dev_length (void ) {return erofs_devsz;
lib/namei.c new file +246 -0
246 lines not on this page · raw message
lib/super.c new file +78 -0
78 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v2 2/3 erofs-utils: fuse: support symlink & special inode
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
From: Huang Jianan <[email protected]>
This patch adds symlink and special inode (e.g. block dev, char, socket, pipe inode) support.
--- fuse/main.c | 10 ++++++++++ lib/namei.c | 22 ++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-)
fuse/main.c +10 -0
@@ -78,7 +78,17 @@ static int erofsfuse_read(const char *path, char *buffer,return size; } +static int erofsfuse_readlink (const char *path,char *buffer,size_t size) +{ +int ret =erofsfuse_read (path, buffer, size,0 ,NULL ); + +if (ret <0 ) +return ret; +return 0 ; +} +static struct fuse_operations erofs_ops = { + .readlink = erofsfuse_readlink, .getattr = erofsfuse_getattr, .readdir = erofsfuse_readdir, .open = erofsfuse_open,
lib/namei.c +18 -4
@@ -15,6 +15,14 @@#include "erofs/print.h" #include "erofs/io.h" +static dev_t erofs_new_decode_dev (u32 dev) +{ +const unsigned int major = (dev &0xfff00 ) >>8 ; +const unsigned int minor = (dev &0xff ) | ((dev >>12 ) &0xfff00 ); + +return makedev (major, minor); +} +static int erofs_read_inode_from_disk (struct erofs_inode *vi) {int ret, ifmt;
@@ -57,10 +65,13 @@ static int erofs_read_inode_from_disk(struct erofs_inode *vi)break ;case S_IFCHR :case S_IFBLK : -return -EOPNOTSUPP ; + vi->u.i_rdev = +erofs_new_decode_dev (le32_to_cpu (die->i_u.rdev)); +break ;case S_IFIFO :case S_IFSOCK : -return -EOPNOTSUPP ; + vi->u.i_rdev =0 ; +break ;default : goto bogusimode; }
@@ -86,10 +97,13 @@ static int erofs_read_inode_from_disk(struct erofs_inode *vi)break ;case S_IFCHR :case S_IFBLK : -return -EOPNOTSUPP ; + vi->u.i_rdev = +erofs_new_decode_dev (le32_to_cpu (dic->i_u.rdev)); +break ;case S_IFIFO :case S_IFSOCK : -return -EOPNOTSUPP ; + vi->u.i_rdev =0 ; +break ;default : goto bogusimode; }
Signature · 1 line
2.24.0
PATCH v2 3/3 erofs-utils: fuse: add compressed file support
In reply to Gao Xiang via Linux-erofsFrom: Gao Xiang <[email protected]>
From: Huang Jianan <[email protected]>
This patch adds a simple approach (~ 700 LOC) to EROFS fixed-sized output decompression without inplace I/O or decompression inplace so it's easy to be ported everywhere with less constraint.
However, the on-disk compressed index parser (aka. zmap) is largely kept in line with the kernel side, therefore new on-disk features under development can be verified effectively first here.
--- include/erofs/decompress.h | 35 ++++ include/erofs/defs.h | 5 + include/erofs/internal.h | 8 + lib/Makefile.am | 2 +- lib/data.c | 72 ++++++- lib/decompress.c | 87 ++++++++ lib/namei.c | 4 + lib/zmap.c | 415 +++++++++++++++++++++++++++++++++++++ 8 files changed, 626 insertions(+), 2 deletions(-) create mode 100644 include/erofs/decompress.h create mode 100644 lib/decompress.c create mode 100644 lib/zmap.c
include/erofs/decompress.h new file +35 -0
@@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* erofs-utils/include/erofs/decompress.h +* +* Copyright (C), 2008-2020, OPPO Mobile Comm Corp., Ltd. +* Created by Huang Jianan <[email protected]> +*/ +#ifndef __EROFS_DECOMPRESS_H +#define __EROFS_DECOMPRESS_H + +#include "internal.h" + +enum { +Z_EROFS_COMPRESSION_SHIFTED =Z_EROFS_COMPRESSION_MAX , +Z_EROFS_COMPRESSION_RUNTIME_MAX +}; + +struct z_erofs_decompress_req { +char *in, *out; + +/* +* initial decompressed bytes that need to be skipped +* when finally copying to output buffer +*/ +unsigned int decodedskip; +unsigned int inputsize, decodedlength; + +/* indicate the algorithm will be used for decompression */ +unsigned int alg; +bool partial_decoding; +}; + +int z_erofs_decompress (struct z_erofs_decompress_req *rq); + +#endif
include/erofs/defs.h +5 -0
@@ -170,5 +170,10 @@ typedef int64_t s64;#define __maybe_unused __attribute__((__unused__))#endif +static inline u32 get_unaligned_le32 (const u8 *p) +{ +return p[0 ] | p[1 ] <<8 | p[2 ] <<16 | p[3 ] <<24 ; +} +#endif
include/erofs/internal.h +8 -0
@@ -106,9 +106,13 @@ static inline void erofs_sb_clear_##name(void) \ EROFS_FEATURE_FUNCS(lz4_0padding, incompat, INCOMPAT_LZ4_0PADDING) EROFS_FEATURE_FUNCS(sb_chksum, compat, COMPAT_SB_CHKSUM) +#define EROFS_I_EA_INITED (1 << 0) +#define EROFS_I_Z_INITED (1 << 1) +struct erofs_inode {struct list_head i_hash, i_subdirs, i_xattrs; +unsigned int flags;unsigned int i_count;struct erofs_inode *i_parent;
@@ -250,6 +254,10 @@ int erofs_ilookup(const char *path, struct erofs_inode *vi);/* data.c */ int erofs_pread (struct erofs_inode *inode,char *buf,erofs_off_t count,erofs_off_t offset); +/* zmap.c */ +int z_erofs_fill_inode (struct erofs_inode *vi); +int z_erofs_map_blocks_iter (struct erofs_inode *vi, +struct erofs_map_blocks *map);#define EFSCORRUPTED EUCLEAN/* Filesystem is corrupted */
lib/Makefile.am +1 -1
@@ -3,7 +3,7 @@ noinst_LTLIBRARIES = liberofs.la liberofs_la_SOURCES = config.c io.c cache.c super.c inode.c xattr.c exclude.c \ - namei.c data.c compress.c compressor.c + namei.c data.c compress.c compressor.c zmap.c decompress.c liberofs_la_CFLAGS = -Wall -Werror -I$(top_srcdir)/include if ENABLE_LZ4 liberofs_la_CFLAGS += ${LZ4_CFLAGS}
lib/data.c +71 -1
90 lines not on this page · raw message
lib/decompress.c new file +87 -0
87 lines not on this page · raw message
lib/namei.c +4 -0
@@ -122,6 +122,10 @@ static int erofs_read_inode_from_disk(struct erofs_inode *vi) erofs_inode_version(ifmt), vi->nid | 0ULL);return -EOPNOTSUPP ; } + + vi->flags =0 ; +if (erofs_inode_is_data_compressed (vi->datalayout)) +z_erofs_fill_inode (vi);return 0 ; bogusimode:erofs_err ("bogus i_mode (%o) @ nid %llu" , vi->i_mode, vi->nid |0ULL );
lib/zmap.c new file +415 -0
415 lines not on this page · raw message
Signature · 1 line
2.24.0