Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/uzip/g_uzip_zlib.c
Show All 27 Lines | |||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include <sys/types.h> | #include <sys/types.h> | ||||
#include <sys/systm.h> | #include <sys/systm.h> | ||||
#include <sys/malloc.h> | #include <sys/malloc.h> | ||||
#include <sys/zlib.h> | #include <contrib/zlib/zlib.h> | ||||
#include <dev/zlib/zcalloc.h> | |||||
#include <geom/uzip/g_uzip.h> | #include <geom/uzip/g_uzip.h> | ||||
#include <geom/uzip/g_uzip_dapi.h> | #include <geom/uzip/g_uzip_dapi.h> | ||||
#include <geom/uzip/g_uzip_zlib.h> | #include <geom/uzip/g_uzip_zlib.h> | ||||
struct g_uzip_zlib { | struct g_uzip_zlib { | ||||
uint32_t blksz; | uint32_t blksz; | ||||
struct g_uzip_dapi pub; | struct g_uzip_dapi pub; | ||||
/* Zlib decoder structs */ | /* Zlib decoder structs */ | ||||
z_stream zs; | z_stream zs; | ||||
}; | }; | ||||
static void *z_alloc(void *, u_int, u_int); | |||||
static void z_free(void *, void *); | |||||
static int g_uzip_zlib_rewind(struct g_uzip_dapi *, const char *); | static int g_uzip_zlib_rewind(struct g_uzip_dapi *, const char *); | ||||
static void | static void | ||||
g_uzip_zlib_free(struct g_uzip_dapi *zpp) | g_uzip_zlib_free(struct g_uzip_dapi *zpp) | ||||
{ | { | ||||
struct g_uzip_zlib *zp; | struct g_uzip_zlib *zp; | ||||
zp = (struct g_uzip_zlib *)zpp->pvt; | zp = (struct g_uzip_zlib *)zpp->pvt; | ||||
Show All 33 Lines | g_uzip_zlib_rewind(struct g_uzip_dapi *zpp, const char *gp_name) | ||||
err = 0; | err = 0; | ||||
if (inflateReset(&zp->zs) != Z_OK) { | if (inflateReset(&zp->zs) != Z_OK) { | ||||
printf("%s: UZIP(zlib) decoder reset failed\n", gp_name); | printf("%s: UZIP(zlib) decoder reset failed\n", gp_name); | ||||
err = 1; | err = 1; | ||||
} | } | ||||
return (err); | return (err); | ||||
} | } | ||||
static int | |||||
z_compressBound(int len) | |||||
{ | |||||
return (len + (len >> 12) + (len >> 14) + 11); | |||||
} | |||||
struct g_uzip_dapi * | struct g_uzip_dapi * | ||||
g_uzip_zlib_ctor(uint32_t blksz) | g_uzip_zlib_ctor(uint32_t blksz) | ||||
{ | { | ||||
struct g_uzip_zlib *zp; | struct g_uzip_zlib *zp; | ||||
zp = malloc(sizeof(struct g_uzip_zlib), M_GEOM_UZIP, M_WAITOK); | zp = malloc(sizeof(struct g_uzip_zlib), M_GEOM_UZIP, M_WAITOK); | ||||
zp->zs.zalloc = z_alloc; | zp->zs.zalloc = zcalloc_nowait; | ||||
ota_j.email.ne.jp: Given geom_uzip uses nowait kmalloc,
zp->zs.zalloc = zcalloc_nowait;
is the equivalent choice. | |||||
Done Inline ActionsMy version of zcalloc was the nowait variant :) delphij: My version of zcalloc was the nowait variant :) | |||||
Not Done Inline ActionsYes, that was the case. ota_j.email.ne.jp: Yes, that was the case.
I somehow got confused and mixed up. | |||||
zp->zs.zfree = z_free; | |||||
delphijAuthorUnsubmitted Not Done Inline ActionsI think inflateInit() still expects zfree be set? delphij: I think inflateInit() still expects zfree be set? | |||||
ota_j.email.ne.jpUnsubmitted Done Inline ActionsI will check. Using -DZ_SOLO changes implementation and don't recall. ota_j.email.ne.jp: I will check. Using -DZ_SOLO changes implementation and don't recall. | |||||
if (inflateInit(&zp->zs) != Z_OK) { | if (inflateInit(&zp->zs) != Z_OK) { | ||||
goto e1; | goto e1; | ||||
} | } | ||||
zp->blksz = blksz; | zp->blksz = blksz; | ||||
zp->pub.max_blen = z_compressBound(blksz); | zp->pub.max_blen = compressBound(blksz); | ||||
ota_j.email.ne.jpUnsubmitted Done Inline ActionscompressBounce is taken out by -DZ_SOLO. ota_j.email.ne.jp: compressBounce is taken out by -DZ_SOLO.
We will need to adjust zlib side to expose with… | |||||
zp->pub.decompress = &g_uzip_zlib_decompress; | zp->pub.decompress = &g_uzip_zlib_decompress; | ||||
zp->pub.free = &g_uzip_zlib_free; | zp->pub.free = &g_uzip_zlib_free; | ||||
zp->pub.rewind = &g_uzip_zlib_rewind; | zp->pub.rewind = &g_uzip_zlib_rewind; | ||||
zp->pub.pvt = (void *)zp; | zp->pub.pvt = (void *)zp; | ||||
return (&zp->pub); | return (&zp->pub); | ||||
e1: | e1: | ||||
free(zp, M_GEOM_UZIP); | free(zp, M_GEOM_UZIP); | ||||
return (NULL); | return (NULL); | ||||
} | |||||
static void * | |||||
z_alloc(void *nil, u_int type, u_int size) | |||||
{ | |||||
void *ptr; | |||||
ptr = malloc(type * size, M_GEOM_UZIP, M_NOWAIT); | |||||
Done Inline Actionsgeom_uzip uses M_NOWAIT option. ota_j.email.ne.jp: geom_uzip uses M_NOWAIT option. | |||||
return (ptr); | |||||
} | |||||
static void | |||||
z_free(void *nil, void *ptr) | |||||
{ | |||||
free(ptr, M_GEOM_UZIP); | |||||
} | } |
Given geom_uzip uses nowait kmalloc,
is the equivalent choice.
I am not sure which one provides better system handling and user experiences, though.
It will be nice if we can get file-system and kernel memory experts inputs.