aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-01-27 14:53:02 +0000
committerMark Johnston <markj@FreeBSD.org>2022-02-10 13:46:12 +0000
commit14c0cde468e136a007a5a7e1bcb7b3a50a2a8b57 (patch)
tree014db6e836abc80c7974444706fc4bed7fc8d917
parent7fbdc1e3d421d4c2612933a5fe292541e9611aae (diff)
downloadsrc-14c0cde468e136a007a5a7e1bcb7b3a50a2a8b57.tar.gz
src-14c0cde468e136a007a5a7e1bcb7b3a50a2a8b57.zip
shsec: Allocate data blocks only for BIO_READ/WRITE requests
In particular, there is no need to allocate a data block when passing BIO_FLUSH requests to child providers, and g_io_request() asserts that bp->bio_data == NULL for such requests. PR: 255131 Reported and tested by: nvass@gmx.com Sponsored by: The FreeBSD Foundation (cherry picked from commit a2dfffb98917a57bfacb155b9d7d423c3e8ff792)
-rw-r--r--sys/geom/shsec/g_shsec.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/sys/geom/shsec/g_shsec.c b/sys/geom/shsec/g_shsec.c
index a3b2f59d0555..2b9e127ce350 100644
--- a/sys/geom/shsec/g_shsec.c
+++ b/sys/geom/shsec/g_shsec.c
@@ -272,8 +272,10 @@ g_shsec_done(struct bio *bp)
(ssize_t)pbp->bio_length);
}
}
- explicit_bzero(bp->bio_data, bp->bio_length);
- uma_zfree(g_shsec_zone, bp->bio_data);
+ if (bp->bio_data != NULL) {
+ explicit_bzero(bp->bio_data, bp->bio_length);
+ uma_zfree(g_shsec_zone, bp->bio_data);
+ }
g_destroy_bio(bp);
pbp->bio_inbed++;
if (pbp->bio_children == pbp->bio_inbed) {
@@ -351,20 +353,22 @@ g_shsec_start(struct bio *bp)
* Fill in the component buf structure.
*/
cbp->bio_done = g_shsec_done;
- cbp->bio_data = uma_zalloc(g_shsec_zone, M_NOWAIT);
- if (cbp->bio_data == NULL) {
- g_shsec_alloc_failed++;
- error = ENOMEM;
- goto failure;
- }
cbp->bio_caller2 = sc->sc_disks[no];
- if (bp->bio_cmd == BIO_WRITE) {
- if (no == 0) {
- dst = (uint32_t *)cbp->bio_data;
- bcopy(bp->bio_data, dst, len);
- } else {
- g_shsec_xor2((uint32_t *)cbp->bio_data, dst,
- len);
+ if (bp->bio_cmd == BIO_READ || bp->bio_cmd == BIO_WRITE) {
+ cbp->bio_data = uma_zalloc(g_shsec_zone, M_NOWAIT);
+ if (cbp->bio_data == NULL) {
+ g_shsec_alloc_failed++;
+ error = ENOMEM;
+ goto failure;
+ }
+ if (bp->bio_cmd == BIO_WRITE) {
+ if (no == 0) {
+ dst = (uint32_t *)cbp->bio_data;
+ bcopy(bp->bio_data, dst, len);
+ } else {
+ g_shsec_xor2((uint32_t *)cbp->bio_data,
+ dst, len);
+ }
}
}
}