Modularize xz.

Embedded lzma decompression library becomes a module usable by other
consumers, in addition to geom_uzip.

Most important code changes are
- removal of XZ_DEC_SINGLE define, we need the code to work
  with XZ_DEC_DYNALLOC;
- xz_crc32_init() call is removed from geom_uzip, xz module handles
  initialization on its own.

xz is no longer embedded into geom_uzip, instead the depend line for
the module is provided, and corresponding kernel option is added to
each MIPS kernel config file using geom_uzip.

The commit also carries unrelated cleanup by removing excess "device geom_uzip"
in places which were missed in r344479.

Reviewed by:	cem, hselasky, ray, slavash (previous versions)
Sponsored by:	Mellanox Technologies
Differential revision:	https://reviews.freebsd.org/D19266
MFC after:	3 weeks
This commit is contained in:
kib 2019-02-26 19:55:03 +00:00
parent d6ebbcc6a2
commit 9ffa1db45e
51 changed files with 120 additions and 59 deletions

View File

@ -36,6 +36,7 @@ To compile this driver into the kernel,
place the following line in your
kernel configuration file:
.Bd -ragged -offset indent
.Cd "device xz"
.Cd "options GEOM_UZIP"
.Ed
.Pp

View File

@ -3004,3 +3004,5 @@ device n25q #
device spigen # Generic access to SPI devices from userland.
# Enable legacy /dev/spigenN name aliases for /dev/spigenX.Y devices.
options SPIGEN_LEGACY_CDEVNAME # legacy device names for spigen
device xz # xz_embedded LZMA de-compression library

View File

@ -636,6 +636,17 @@ contrib/ngatm/netnatm/sig/sig_unimsgcpy.c optional ngatm_uni \
compile-with "${NORMAL_C} -I$S/contrib/ngatm"
contrib/ngatm/netnatm/sig/sig_verify.c optional ngatm_uni \
compile-with "${NORMAL_C} -I$S/contrib/ngatm"
# xz
dev/xz/xz_mod.c optional xz \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_crc32.c optional xz \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c optional xz \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c optional xz \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c optional xz \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
# Zstd
contrib/zstd/lib/freebsd/zstd_kmalloc.c optional zstdio compile-with ${ZSTD_C}
contrib/zstd/lib/common/zstd_common.c optional zstdio compile-with ${ZSTD_C}
@ -3659,21 +3670,6 @@ geom/raid3/g_raid3.c optional geom_raid3
geom/raid3/g_raid3_ctl.c optional geom_raid3
geom/shsec/g_shsec.c optional geom_shsec
geom/stripe/g_stripe.c optional geom_stripe
contrib/xz-embedded/freebsd/xz_malloc.c \
optional xz_embedded | geom_uzip \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_crc32.c \
optional xz_embedded | geom_uzip \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_bcj.c \
optional xz_embedded | geom_uzip \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_lzma2.c \
optional xz_embedded | geom_uzip \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
contrib/xz-embedded/linux/lib/xz/xz_dec_stream.c \
optional xz_embedded | geom_uzip \
compile-with "${NORMAL_C} -I$S/contrib/xz-embedded/freebsd/ -I$S/contrib/xz-embedded/linux/lib/xz/ -I$S/contrib/xz-embedded/linux/include/linux/"
geom/uzip/g_uzip.c optional geom_uzip
geom/uzip/g_uzip_lzma.c optional geom_uzip
geom/uzip/g_uzip_wrkthr.c optional geom_uzip

View File

@ -35,7 +35,6 @@
#include <contrib/xz-embedded/linux/include/linux/xz.h>
#include "xz_malloc.h"
#define XZ_DEC_SINGLE 1
#define XZ_PREBOOT 1
#undef XZ_EXTERN

View File

@ -1,5 +1,6 @@
/*-
* Copyright (c) 2010-2012 Aleksandr Rybalko
* Copyright (c) 2019 Mellanox Technologies
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -24,11 +25,16 @@
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#include <sys/malloc.h>
#include <sys/kernel.h>
#include <sys/module.h>
#include "xz.h"
#include "xz_malloc.h"
/* Wraper for XZ decompressor memmory pool */
/* Wraper for XZ decompressor memory pool */
static MALLOC_DEFINE(XZ_DEC, "XZ_DEC", "XZ decompressor data");
@ -47,3 +53,38 @@ xz_free(void *addr)
free(addr, XZ_DEC);
}
static int
xz_module_event_handler(module_t mod, int what, void *arg)
{
int error;
switch (what) {
case MOD_LOAD:
#if XZ_INTERNAL_CRC32
xz_crc32_init();
#endif
#if XZ_INTERNAL_CRC64
xz_crc64_init();
#endif
error = 0;
break;
case MOD_UNLOAD:
error = 0;
break;
default:
error = EOPNOTSUPP;
break;
}
return (error);
}
static moduledata_t xz_moduledata = {
"xz",
xz_module_event_handler,
NULL
};
DECLARE_MODULE(xz, xz_moduledata, SI_SUB_INIT_IF, SI_ORDER_ANY);
MODULE_VERSION(xz, 1);

View File

@ -921,5 +921,6 @@ static struct g_class g_uzip_class = {
};
DECLARE_GEOM_CLASS(g_uzip_class, g_uzip);
MODULE_DEPEND(g_uzip, xz, 1, 1, 1);
MODULE_DEPEND(g_uzip, zlib, 1, 1, 1);
MODULE_VERSION(geom_uzip, 0);

View File

@ -103,7 +103,6 @@ g_uzip_lzma_ctor(uint32_t blksz)
struct g_uzip_lzma *lzp;
lzp = malloc(sizeof(struct g_uzip_lzma), M_GEOM_UZIP, M_WAITOK);
xz_crc32_init();
lzp->s = xz_dec_init(XZ_SINGLE, 0);
if (lzp->s == NULL) {
goto e1;

View File

@ -49,7 +49,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -43,7 +43,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -46,7 +46,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -43,7 +43,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -38,7 +38,7 @@ options NO_SWAPPING
# options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -26,7 +26,7 @@ options AR71XX_ENV_UBOOT
options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -21,6 +21,7 @@ hints "AP94.hints"
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:md0.uzip\"

View File

@ -27,7 +27,7 @@ options AR71XX_ENV_UBOOT
options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -39,7 +39,7 @@ options SOFTUPDATES #Enable FFS soft updates support
options UFS_ACL #Support for access control lists
options UFS_DIRHASH #Improve performance on big directories
device geom_uzip
device xz
options GEOM_UZIP
options GEOM_LABEL # Providers labelization.
options ROOTDEVNAME=\"ufs:ufs/FBSD\" # assumes FW built by

View File

@ -48,7 +48,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -38,7 +38,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -41,7 +41,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -47,6 +47,7 @@ nooptions INET6
# GEOM modules
device geom_map # to get access to the SPI flash partitions
device xz
options GEOM_UZIP
options GEOM_PART_GPT

View File

@ -26,7 +26,7 @@ options AR71XX_ENV_UBOOT
options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -26,7 +26,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -26,7 +26,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -26,7 +26,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -27,7 +27,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -45,7 +45,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -32,7 +32,7 @@ options AR71XX_REALMEM=64*1024*1024
options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -55,7 +55,7 @@ options FFS #Berkeley Fast Filesystem
#options UFS_DIRHASH #Improve performance on big directories
# Support uncompress lzma rootfs
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -38,7 +38,7 @@ options NO_SWAPPING
# options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -38,7 +38,7 @@ options NO_SWAPPING
# options MSDOSFS
# uncompress - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -14,7 +14,7 @@ hints "ROUTERSTATION.hints"
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device geom_uzip # compressed in-memory filesystem support
device xz
options GEOM_UZIP
# For DOS

View File

@ -12,6 +12,7 @@ hints "ROUTERSTATION.hints"
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:md0.uzip\"

View File

@ -15,7 +15,7 @@ device pcf2123_rtc
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device geom_uzip # compressed in-memory filesystem support
device xz
options GEOM_UZIP
# For DOS

View File

@ -15,6 +15,7 @@ device pcf2123_rtc
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device xz
options GEOM_UZIP
# Boot from the first MFS uzip

View File

@ -14,7 +14,7 @@ device pcf2123_rtc
# GEOM modules
device geom_redboot # to get access to the SPI flash partitions
device geom_uzip # compressed in-memory filesystem support
device xz
options GEOM_UZIP
# For DOS

View File

@ -27,7 +27,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -26,7 +26,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -27,7 +27,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -26,7 +26,7 @@ makeoptions MODULES_OVERRIDE=""
options ROOTDEVNAME=\"ufs:md0.uzip\"
# Support geom_uzip(4) compressed disk images
device geom_uzip
device xz
options GEOM_UZIP
# Support md(4) and md-based rootfs

View File

@ -46,7 +46,7 @@ options MSDOSFS
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -39,7 +39,7 @@ options MSDOSFS
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -34,7 +34,7 @@ options MSDOSFS
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -43,7 +43,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -48,7 +48,7 @@ device arswitch
options AR71XX_ENV_UBOOT
# uzip - to boot read-only lzma natively from flash
device geom_uzip
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -39,7 +39,7 @@ options MSDOSFS
options AR71XX_ENV_UBOOT
# uncompress - to boot natively from flash
device geom_uzip
device xz
options GEOM_UZIP
# Used for the static uboot partition map

View File

@ -26,6 +26,7 @@ options BOOTVERBOSE
# GEOM modules
device geom_map # to get access to the SPI flash partitions
device xz
options GEOM_UZIP
options ROOTDEVNAME=\"ufs:/dev/map/rootfs.uzip\"

View File

@ -25,6 +25,7 @@ options AR71XX_ENV_UBOOT
options BOOTVERBOSE
# GEOM modules
device xz
options GEOM_UZIP
device geom_map # to get access to the SPI flash partitions

View File

@ -56,6 +56,7 @@ options ALT_BREAK_TO_DEBUGGER
#options LOCK_DEBUG
#options LOCK_PROFILING
device xz
options GEOM_UZIP
# Device tree

View File

@ -404,6 +404,7 @@ SUBDIR= \
${_x86bios} \
${_xe} \
xl \
xz \
zlib
.if ${MK_AUTOFS} != "no" || defined(ALL_MODULES)

View File

@ -8,16 +8,10 @@ SRCS+= g_uzip.h g_uzip_dapi.h g_uzip_lzma.h g_uzip_zlib.h g_uzip_softc.h \
g_uzip_wrkthr.h
#CFLAGS= -g -DINVARIANT_SUPPORT -DINVARIANTS
.PATH: ${SRCTOP}/sys/contrib/xz-embedded/freebsd/ \
${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz/ \
${SRCTOP}/sys/contrib/xz-embedded/linux/include/linux/ \
${SRCTOP}/sys/net
.PATH: ${SRCTOP}/sys/net
CFLAGS+= -I${SRCTOP}/sys/contrib/xz-embedded/freebsd \
-I${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz/
SRCS+= xz_crc32.c xz_dec_bcj.c xz_dec_lzma2.c xz_dec_stream.c \
xz_malloc.c
SRCS+= xz.h xz_config.h xz_lzma2.h xz_malloc.h xz_private.h xz_stream.h
SRCS+= opt_geom.h
.include <bsd.kmod.mk>

20
sys/modules/xz/Makefile Normal file
View File

@ -0,0 +1,20 @@
# $FreeBSD$
.PATH: ${SRCTOP}/sys/dev/xz
.PATH: ${SRCTOP}/sys/contrib/xz-embedded/freebsd
.PATH: ${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz
KMOD= xz
SRCS= \
xz_crc32.c \
xz_dec_bcj.c \
xz_dec_lzma2.c \
xz_dec_stream.c \
xz_mod.c
CFLAGS+= \
-I${SRCTOP}/sys/contrib/xz-embedded/freebsd \
-I${SRCTOP}/sys/contrib/xz-embedded/linux/lib/xz \
-I${SRCTOP}/sys/contrib/xz-embedded/linux/include/linux
.include <bsd.kmod.mk>