nvmet: add nvmet_req_bio put helper for backends
authorChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Thu, 10 Jun 2021 01:32:50 +0000 (18:32 -0700)
committerChristoph Hellwig <hch@lst.de>
Thu, 17 Jun 2021 13:51:20 +0000 (15:51 +0200)
In current code there exists two backends which are using inline bio
optimization, that adds a duplicate code for freeing the bio.

For Zoned Block Device backend we also use the same optimzation and it
will lead to having duplicate code in the three backends: generic
bdev, passsthru, and generic zns.

Add a helper function to avoid duplicate code and update the respective
backends.

Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
drivers/nvme/target/io-cmd-bdev.c
drivers/nvme/target/nvmet.h
drivers/nvme/target/passthru.c

index 5d998e5873d3f7f6e98ef90fde2d9d8451217e95..019cc994efcd4cb438ba28282fbdca8b38f42cf0 100644 (file)
@@ -164,8 +164,7 @@ static void nvmet_bio_done(struct bio *bio)
        struct nvmet_req *req = bio->bi_private;
 
        nvmet_req_complete(req, blk_to_nvme_status(req, bio->bi_status));
-       if (bio != &req->b.inline_bio)
-               bio_put(bio);
+       nvmet_req_bio_put(req, bio);
 }
 
 #ifdef CONFIG_BLK_DEV_INTEGRITY
index 002651f34c5e1b39f1245495fc22e6672a4105d6..29b386de1d07d2892af6c4a8ad59dede9d7a6345 100644 (file)
@@ -632,4 +632,10 @@ static inline void nvmet_req_cns_error_complete(struct nvmet_req *req)
        nvmet_req_complete(req, NVME_SC_INVALID_FIELD | NVME_SC_DNR);
 }
 
+static inline void nvmet_req_bio_put(struct nvmet_req *req, struct bio *bio)
+{
+       if (bio != &req->b.inline_bio)
+               bio_put(bio);
+}
+
 #endif /* _NVMET_H */
index 39b1473f7204eb78cc17f7988233ccbd05f37791..fced52de33ce9331e4f6d2c76b7abb193cdc5b06 100644 (file)
@@ -206,8 +206,7 @@ static int nvmet_passthru_map_sg(struct nvmet_req *req, struct request *rq)
        for_each_sg(req->sg, sg, req->sg_cnt, i) {
                if (bio_add_pc_page(rq->q, bio, sg_page(sg), sg->length,
                                    sg->offset) < sg->length) {
-                       if (bio != &req->p.inline_bio)
-                               bio_put(bio);
+                       nvmet_req_bio_put(req, bio);
                        return -EINVAL;
                }
        }