Changeset View
Changeset View
Standalone View
Standalone View
sys/geom/eli/g_eli_privacy.c
Show First 20 Lines • Show All 255 Lines • ▼ Show 20 Lines | |||||
* g_eli_start -> g_eli_crypto_read -> g_io_request -> g_eli_read_done -> G_ELI_CRYPTO_RUN -> g_eli_crypto_read_done -> g_io_deliver | * g_eli_start -> g_eli_crypto_read -> g_io_request -> g_eli_read_done -> G_ELI_CRYPTO_RUN -> g_eli_crypto_read_done -> g_io_deliver | ||||
* BIO_WRITE: | * BIO_WRITE: | ||||
* g_eli_start -> G_ELI_CRYPTO_RUN -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver | * g_eli_start -> G_ELI_CRYPTO_RUN -> g_eli_crypto_write_done -> g_io_request -> g_eli_write_done -> g_io_deliver | ||||
*/ | */ | ||||
void | void | ||||
g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp) | g_eli_crypto_run(struct g_eli_worker *wr, struct bio *bp) | ||||
{ | { | ||||
struct g_eli_softc *sc; | struct g_eli_softc *sc; | ||||
struct cryptopq crpq; | |||||
struct cryptop *crp; | struct cryptop *crp; | ||||
vm_page_t *pages; | vm_page_t *pages; | ||||
u_int i, nsec, secsize; | u_int i, nsec, secsize; | ||||
off_t dstoff; | off_t dstoff; | ||||
u_char *data = NULL; | u_char *data = NULL; | ||||
int error; | int error, pages_offset; | ||||
int pages_offset; | bool batch; | ||||
G_ELI_LOGREQ(3, bp, "%s", __func__); | G_ELI_LOGREQ(3, bp, "%s", __func__); | ||||
bp->bio_pflags = wr->w_number; | bp->bio_pflags = wr->w_number; | ||||
sc = wr->w_softc; | sc = wr->w_softc; | ||||
secsize = LIST_FIRST(&sc->sc_geom->provider)->sectorsize; | secsize = LIST_FIRST(&sc->sc_geom->provider)->sectorsize; | ||||
nsec = bp->bio_length / secsize; | nsec = bp->bio_length / secsize; | ||||
Show All 19 Lines | if (bp->bio_cmd == BIO_WRITE) { | ||||
if ((bp->bio_flags & BIO_UNMAPPED) != 0) { | if ((bp->bio_flags & BIO_UNMAPPED) != 0) { | ||||
pages = bp->bio_ma; | pages = bp->bio_ma; | ||||
pages_offset = bp->bio_ma_offset; | pages_offset = bp->bio_ma_offset; | ||||
} else { | } else { | ||||
data = bp->bio_data; | data = bp->bio_data; | ||||
} | } | ||||
} | } | ||||
TAILQ_INIT(&crpq); | |||||
batch = atomic_load_int(&g_eli_batch) != 0; | |||||
for (i = 0, dstoff = bp->bio_offset; i < nsec; i++, dstoff += secsize) { | for (i = 0, dstoff = bp->bio_offset; i < nsec; i++, dstoff += secsize) { | ||||
crp = crypto_getreq(wr->w_sid, M_WAITOK); | crp = crypto_getreq(wr->w_sid, M_WAITOK); | ||||
if (data) { | if (data) { | ||||
crypto_use_buf(crp, data, secsize); | crypto_use_buf(crp, data, secsize); | ||||
data += secsize; | data += secsize; | ||||
} else { | } else { | ||||
MPASS(pages != NULL); | MPASS(pages != NULL); | ||||
crypto_use_vmpage(crp, pages, secsize, pages_offset); | crypto_use_vmpage(crp, pages, secsize, pages_offset); | ||||
pages_offset += secsize; | pages_offset += secsize; | ||||
pages += pages_offset >> PAGE_SHIFT; | pages += pages_offset >> PAGE_SHIFT; | ||||
pages_offset &= PAGE_MASK; | pages_offset &= PAGE_MASK; | ||||
} | } | ||||
crp->crp_opaque = (void *)bp; | crp->crp_opaque = (void *)bp; | ||||
if (bp->bio_cmd == BIO_WRITE) { | if (bp->bio_cmd == BIO_WRITE) { | ||||
crp->crp_op = CRYPTO_OP_ENCRYPT; | crp->crp_op = CRYPTO_OP_ENCRYPT; | ||||
crp->crp_callback = g_eli_crypto_write_done; | crp->crp_callback = g_eli_crypto_write_done; | ||||
} else /* if (bp->bio_cmd == BIO_READ) */ { | } else /* if (bp->bio_cmd == BIO_READ) */ { | ||||
crp->crp_op = CRYPTO_OP_DECRYPT; | crp->crp_op = CRYPTO_OP_DECRYPT; | ||||
crp->crp_callback = g_eli_crypto_read_done; | crp->crp_callback = g_eli_crypto_read_done; | ||||
} | } | ||||
crp->crp_flags = CRYPTO_F_CBIFSYNC; | crp->crp_flags = CRYPTO_F_CBIFSYNC; | ||||
if (g_eli_batch) | |||||
crp->crp_flags |= CRYPTO_F_BATCH; | |||||
crp->crp_payload_start = 0; | crp->crp_payload_start = 0; | ||||
crp->crp_payload_length = secsize; | crp->crp_payload_length = secsize; | ||||
if ((sc->sc_flags & G_ELI_FLAG_SINGLE_KEY) == 0) { | if ((sc->sc_flags & G_ELI_FLAG_SINGLE_KEY) == 0) { | ||||
crp->crp_cipher_key = g_eli_key_hold(sc, dstoff, | crp->crp_cipher_key = g_eli_key_hold(sc, dstoff, | ||||
secsize); | secsize); | ||||
} | } | ||||
if (g_eli_ivlen(sc->sc_ealgo) != 0) { | if (g_eli_ivlen(sc->sc_ealgo) != 0) { | ||||
crp->crp_flags |= CRYPTO_F_IV_SEPARATE; | crp->crp_flags |= CRYPTO_F_IV_SEPARATE; | ||||
g_eli_crypto_ivgen(sc, dstoff, crp->crp_iv, | g_eli_crypto_ivgen(sc, dstoff, crp->crp_iv, | ||||
sizeof(crp->crp_iv)); | sizeof(crp->crp_iv)); | ||||
} | } | ||||
if (batch) { | |||||
TAILQ_INSERT_TAIL(&crpq, crp, crp_next); | |||||
} else { | |||||
error = crypto_dispatch(crp); | error = crypto_dispatch(crp); | ||||
KASSERT(error == 0, ("crypto_dispatch() failed (error=%d)", | KASSERT(error == 0, | ||||
error)); | ("crypto_dispatch() failed (error=%d)", error)); | ||||
} | } | ||||
} | |||||
if (batch) | |||||
crypto_dispatch_batch(&crpq, 0); | |||||
} | } |