Skip to content

Commit

Permalink
btrfs-progs: build: add option to disable LZO support for restore
Browse files Browse the repository at this point in the history
LZO as a compression format is pretty archaic these days, there are
better algorithms in all metrics for compression and decompression, and
lzo hasn't had a new release since 2017.

Add an option to disable LZO (defaulting to enabled), and respect it in
cmds/restore.c.

NOTE: disabling support for LZO will make make it impossible to restore
data from filesystems where the compression has ever been used. It's not
recommended to build without the support in general.

Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
rossburton authored and kdave committed May 24, 2022
1 parent a60afdc commit 73545c1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ endif
btrfs_convert_cflags = -DBTRFSCONVERT_EXT2=$(BTRFSCONVERT_EXT2)
btrfs_convert_cflags += -DBTRFSCONVERT_REISERFS=$(BTRFSCONVERT_REISERFS)
btrfs_fragments_libs = -lgd -lpng -ljpeg -lfreetype
cmds_restore_cflags = -DBTRFSRESTORE_ZSTD=$(BTRFSRESTORE_ZSTD)
cmds_restore_cflags = -DBTRFSRESTORE_LZO=$(BTRFSRESTORE_LZO) -DBTRFSRESTORE_ZSTD=$(BTRFSRESTORE_ZSTD)

ifeq ($(CRYPTOPROVIDER_BUILTIN),1)
CRYPTO_OBJECTS = crypto/sha224-256.o crypto/blake2b-ref.o
Expand Down
1 change: 1 addition & 0 deletions Makefile.inc.in
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ BUILD_PROGRAMS = @BUILD_PROGRAMS@
BUILD_SHARED_LIBRARIES = @BUILD_SHARED_LIBRARIES@
BUILD_STATIC_LIBRARIES = @BUILD_STATIC_LIBRARIES@
BTRFSCONVERT_EXT2 = @BTRFSCONVERT_EXT2@
BTRFSRESTORE_LZO = @BTRFSRESTORE_LZO@
BTRFSCONVERT_REISERFS = @BTRFSCONVERT_REISERFS@
BTRFSRESTORE_ZSTD = @BTRFSRESTORE_ZSTD@
PYTHON_BINDINGS = @PYTHON_BINDINGS@
Expand Down
7 changes: 7 additions & 0 deletions cmds/restore.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#if BTRFSRESTORE_LZO
#include <lzo/lzoconf.h>
#include <lzo/lzo1x.h>
#endif
#include <zlib.h>
#if BTRFSRESTORE_ZSTD
#include <zstd.h>
Expand Down Expand Up @@ -98,6 +100,10 @@ static inline size_t read_compress_length(unsigned char *buf)
static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf,
char *outbuf, u64 compress_len, u64 *decompress_len)
{
#if !BTRFSRESTORE_LZO
error("btrfs-restore not compiled with lzo support");
return -1;
#else
size_t new_len;
size_t in_len;
size_t out_len = 0;
Expand Down Expand Up @@ -156,6 +162,7 @@ static int decompress_lzo(struct btrfs_root *root, unsigned char *inbuf,
*decompress_len = out_len;

return 0;
#endif
}

static int decompress_zstd(const char *inbuf, char *outbuf, u64 compress_len,
Expand Down
30 changes: 20 additions & 10 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,26 @@ if ${PKG_CONFIG} udev --atleast-version 190; then
fi
AC_SUBST(UDEVDIR)

dnl lzo library does not provide pkg-config, let use classic way
AC_CHECK_LIB([lzo2], [lzo_version], [
LZO2_LIBS="-llzo2"
LZO2_CFLAGS=""
LZO2_LIBS_STATIC="-llzo2"],[
AC_MSG_ERROR([cannot find lzo2 library])
])
AC_SUBST([LZO2_LIBS])
AC_SUBST([LZO2_LIBS_STATIC])
AC_SUBST([LZO2_CFLAGS])
AC_ARG_ENABLE([lzo],
AS_HELP_STRING([--disable-lzo], [build without lzo support (default: enabled)]),
[], [enable_lzo=yes]
)

if test "x$enable_lzo" = xyes; then
dnl lzo library does not provide pkg-config, use classic way
AC_CHECK_LIB([lzo2], [lzo_version], [
LZO2_LIBS="-llzo2"
LZO2_CFLAGS=""
LZO2_LIBS_STATIC="-llzo2"],[
AC_MSG_ERROR([cannot find lzo2 library])
])
AC_SUBST([LZO2_LIBS])
AC_SUBST([LZO2_LIBS_STATIC])
AC_SUBST([LZO2_CFLAGS])
fi

AS_IF([test "x$enable_lzo" = xyes], [BTRFSRESTORE_LZO=1], [BTRFSRESTORE_LZO=0])
AC_SUBST(BTRFSRESTORE_LZO)

dnl call PKG_INSTALLDIR from pkg.m4 to set pkgconfigdir
m4_ifdef([PKG_INSTALLDIR], [PKG_INSTALLDIR], [AC_MSG_ERROR([please install pkgconf])])
Expand Down

0 comments on commit 73545c1

Please sign in to comment.