nvmet: handle bio allocation failure
Subsystems (2)
Sagi Grimberg
maintainerPATCH 1/2 nvmet: handle bio allocation failure
We cannot rely on bio_alloc to succeed, so we first allocate the needed bios in a list, and only then submit all of them so we can cleanup if something fails in the process of building the chained bios.
Signed-off-by Sagi Grimberg <sagi at grimberg.me>
--- drivers/nvme/target/io-cmd-bdev.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/nvme/target/io-cmd-bdev.c +16 -3
@@ -59,9 +59,10 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) {int sg_cnt = req->sg_cnt;struct bio *bio = &req->b.inline_bio; +struct bio_list list;struct scatterlist *sg;sector_t sector; -blk_qc_t cookie; +blk_qc_t cookie =BLK_QC_T_NONE ;int op, op_flags =0 , i;if (!req->sg_cnt) {
@@ -88,27 +89,39 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req) bio->bi_end_io = nvmet_bio_done;bio_set_op_attrs (bio, op, op_flags); +bio_list_init (&list);for_each_sg (req->sg, sg, req->sg_cnt, i) {while (bio_add_page (bio,sg_page (sg), sg->length, sg->offset) != sg->length) {struct bio *prev = bio; bio =bio_alloc (GFP_KERNEL ,min (sg_cnt,BIO_MAX_PAGES )); +if (unlikely (!bio)) + goto err; +bio_set_dev (bio, req->ns->bdev); bio->bi_iter.bi_sector = sector;bio_set_op_attrs (bio, op, op_flags);bio_chain (bio, prev); -submit_bio (prev); +bio_list_add (&list, bio); } sector += sg->length >>9 ; sg_cnt--; } - cookie =submit_bio (bio); +bio_list_add (&list, bio); +while ((bio =bio_list_pop (&list))) + cookie =submit_bio (bio);blk_poll (bdev_get_queue (req->ns->bdev), cookie); +return ; +err: +while ((bio =bio_list_pop (&list))) +if (bio != &req->b.inline_bio) +bio_put (bio); +nvmet_req_complete (req,NVME_SC_INTERNAL ); }static void nvmet_bdev_execute_flush (struct nvmet_req *req)
Signature · 1 line
2.17.1
Christoph Hellwig
maintainerPATCH 1/2 nvmet: handle bio allocation failure
Quoted 1 line · Sagi Grimberg
We cannot rely on
bio_allocto succeed,
Yes, we can (unless it is an atomic allocation or it exceeds BIO_MAX_PAGES, neither of which we do here).
Sagi Grimberg
maintainerPATCH 1/2 nvmet: handle bio allocation failure
Quoted 5 lines
Quoted 2 lines
We cannot rely on
bio_allocto succeed,Yes, we can (unless it is an atomic allocation or it exceeds
BIO_MAX_PAGES, neither of which we do here).
Yea I see that now... lets drop this one...