summaryrefslogtreecommitdiffstats
path: root/sys/geom/uncompress/g_uncompress.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/geom/uncompress/g_uncompress.c')
-rw-r--r--sys/geom/uncompress/g_uncompress.c42
1 files changed, 16 insertions, 26 deletions
diff --git a/sys/geom/uncompress/g_uncompress.c b/sys/geom/uncompress/g_uncompress.c
index 629e9d5..5bc8d30 100644
--- a/sys/geom/uncompress/g_uncompress.c
+++ b/sys/geom/uncompress/g_uncompress.c
@@ -116,7 +116,7 @@ g_uncompress_softc_free(struct g_uncompress_softc *sc, struct g_geom *gp)
}
if (sc->offsets != NULL) {
free(sc->offsets, M_GEOM_UNCOMPRESS);
- sc->offsets = 0;
+ sc->offsets = NULL;
}
switch (sc->type) {
@@ -150,6 +150,7 @@ z_alloc(void *nil, u_int type, u_int size)
void *ptr;
ptr = malloc(type * size, M_GEOM_UNCOMPRESS, M_NOWAIT);
+
return (ptr);
}
@@ -221,11 +222,11 @@ g_uncompress_done(struct bio *bp)
(intmax_t)bp2->bio_offset, sc->blksz, bsize));
for (i = start_blk; upos < bp2->bio_length; i++) {
- off_t len, dlen, ulen, uoff;
+ off_t len, ulen, uoff;
uoff = i == start_blk ? bp2->bio_offset % sc->blksz : 0;
ulen = MIN(sc->blksz - uoff, bp2->bio_length - upos);
- dlen = len = sc->offsets[i + 1] - sc->offsets[i];
+ len = sc->offsets[i + 1] - sc->offsets[i];
DPRINTF((
"%s: done: inflate block %d, start %ju, end %ju len %jd\n",
@@ -239,19 +240,17 @@ g_uncompress_done(struct bio *bp)
bp2->bio_completed += ulen;
continue;
}
-
if (len > iolen) {
DPRINTF(("%s: done: early termination: len (%jd) > "
"iolen (%jd)\n",
gp->name, (intmax_t)len, (intmax_t)iolen));
break;
}
-
mtx_lock(&sc->last_mtx);
#ifdef GEOM_UNCOMPRESS_DEBUG
if (g_debugflags & 32)
- hexdump(bp->bio_data + pos, dlen, 0, 0);
+ hexdump(bp->bio_data + pos, len, 0, 0);
#endif
switch (sc->type) {
@@ -259,7 +258,7 @@ g_uncompress_done(struct bio *bp)
sc->b->in = bp->bio_data + pos;
sc->b->out = sc->last_buf;
sc->b->in_pos = sc->b->out_pos = 0;
- sc->b->in_size = dlen;
+ sc->b->in_size = len;
sc->b->out_size = (size_t)-1;
err = (xz_dec_run(sc->s, sc->b) != XZ_STREAM_END) ?
@@ -268,7 +267,7 @@ g_uncompress_done(struct bio *bp)
break;
case GEOM_UZIP:
sc->zs->next_in = bp->bio_data + pos;
- sc->zs->avail_in = dlen;
+ sc->zs->avail_in = len;
sc->zs->next_out = sc->last_buf;
sc->zs->avail_out = sc->blksz;
@@ -328,7 +327,6 @@ g_uncompress_start(struct bio *bp)
uint32_t start_blk, end_blk;
size_t bsize;
-
pp = bp->bio_to;
gp = pp->geom;
DPRINTF(("%s: start (%d:%s) to %s off=%jd len=%jd\n",
@@ -347,10 +345,8 @@ g_uncompress_start(struct bio *bp)
start_blk = bp->bio_offset / sc->blksz;
end_blk = howmany(bp->bio_offset + bp->bio_length, sc->blksz);
- KASSERT(start_blk < sc->nblocks,
- ("start_blk out of range"));
- KASSERT(end_blk <= sc->nblocks,
- ("end_blk out of range"));
+ KASSERT(start_blk < sc->nblocks, ("start_blk out of range"));
+ KASSERT(end_blk <= sc->nblocks, ("end_blk out of range"));
sc->req_total++;
if (start_blk + 1 == end_blk) {
@@ -385,9 +381,7 @@ g_uncompress_start(struct bio *bp)
gp->name, start_blk, end_blk,
pp->name, pp->sectorsize, (intmax_t)pp->mediasize,
pp2->name, pp2->sectorsize, (intmax_t)pp2->mediasize));
-
bsize = pp2->sectorsize;
-
bp2->bio_done = g_uncompress_done;
bp2->bio_offset = rounddown(sc->offsets[start_blk], bsize);
while (1) {
@@ -401,14 +395,12 @@ g_uncompress_start(struct bio *bp)
"%s: bio_length (%jd) > MAXPHYS: lowering end_blk to %u\n",
gp->name, (intmax_t)bp2->bio_length, end_blk));
}
-
DPRINTF(("%s: start %jd + %jd -> %ju + %ju -> %jd + %jd\n",
gp->name,
(intmax_t)bp->bio_offset, (intmax_t)bp->bio_length,
(uintmax_t)sc->offsets[start_blk],
(uintmax_t)sc->offsets[end_blk] - sc->offsets[start_blk],
(intmax_t)bp2->bio_offset, (intmax_t)bp2->bio_length));
-
bp2->bio_data = malloc(bp2->bio_length, M_GEOM_UNCOMPRESS, M_NOWAIT);
if (bp2->bio_data == NULL) {
g_destroy_bio(bp2);
@@ -425,8 +417,7 @@ g_uncompress_orphan(struct g_consumer *cp)
{
struct g_geom *gp;
- g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp,
- cp->provider->name);
+ g_trace(G_T_TOPOLOGY, "%s(%p/%s)", __func__, cp, cp->provider->name);
g_topology_assert();
gp = cp->geom;
@@ -508,15 +499,13 @@ g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
*/
DPRINTF(("%s: media sectorsize %u, mediasize %jd\n",
gp->name, pp->sectorsize, (intmax_t)pp->mediasize));
-
i = roundup(sizeof(struct cloop_header), pp->sectorsize);
buf = g_read_data(cp, 0, i, NULL);
if (buf == NULL)
goto err;
-
header = (struct cloop_header *) buf;
if (strncmp(header->magic, CLOOP_MAGIC_START,
- sizeof(CLOOP_MAGIC_START) - 1) != 0) {
+ sizeof(CLOOP_MAGIC_START) - 1) != 0) {
DPRINTF(("%s: no CLOOP magic\n", gp->name));
goto err;
}
@@ -571,7 +560,7 @@ g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
free(buf, M_GEOM);
i = roundup((sizeof(struct cloop_header) +
- total_offsets * sizeof(uint64_t)),pp->sectorsize);
+ total_offsets * sizeof(uint64_t)), pp->sectorsize);
buf = g_read_data(cp, 0, i, NULL);
if (buf == NULL)
goto err;
@@ -581,6 +570,7 @@ g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
sc->offsets[i] = be64toh(((uint64_t *)
(buf+sizeof(struct cloop_header)))[i]);
}
+ free(buf, M_GEOM);
DPRINTF(("%s: done reading offsets\n", gp->name));
mtx_init(&sc->last_mtx, "geom_uncompress cache", NULL, MTX_DEF);
sc->last_blk = -1;
@@ -615,15 +605,13 @@ g_uncompress_taste(struct g_class *mp, struct g_provider *pp, int flags)
pp2->stripeoffset = pp->stripeoffset;
}
g_error_provider(pp2, 0);
- free(buf, M_GEOM);
g_access(cp, -1, 0, 0);
DPRINTF(("%s: taste ok (%d, %jd), (%d, %d), %x\n",
gp->name,
pp2->sectorsize, (intmax_t)pp2->mediasize,
pp2->stripeoffset, pp2->stripesize, pp2->flags));
- printf("%s: %u x %u blocks\n",
- gp->name, sc->nblocks, sc->blksz);
+ printf("%s: %u x %u blocks\n", gp->name, sc->nblocks, sc->blksz);
return (gp);
err:
@@ -638,6 +626,7 @@ err:
g_detach(cp);
g_destroy_consumer(cp);
g_destroy_geom(gp);
+
return (NULL);
}
@@ -664,6 +653,7 @@ g_uncompress_destroy_geom(struct gctl_req *req, struct g_class *mp,
g_uncompress_softc_free(gp->softc, gp);
gp->softc = NULL;
g_wither_geom(gp, ENXIO);
+
return (0);
}
OpenPOWER on IntegriCloud