[PATCH 1/2] nvmet: check sg_cnt for inline bio for bdev-ns

Chaitanya Kulkarni Chaitanya.Kulkarni at wdc.com
Tue May 4 23:03:27 BST 2021


On 4/29/21 11:44, Chaitanya Kulkarni wrote:
>  
>  	sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
>  
> -	if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
> +	if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN &&
> +	    req->sg_cnt <= NVMET_MAX_INLINE_BIOVEC) {
>  		bio = &req->b.inline_bio;
>  		bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
>  	} else {
> -- 2.22.1

One more thing, in the V2 to avoid open-coding in bdev and passthru (and
ZBD)
we should add a helper ?

something like following untested :-

diff --git a/drivers/nvme/target/io-cmd-bdev.c
b/drivers/nvme/target/io-cmd-bdev.c
index 9a8b3726a37c..429263ca9b97 100644
--- a/drivers/nvme/target/io-cmd-bdev.c
+++ b/drivers/nvme/target/io-cmd-bdev.c
@@ -258,7 +258,7 @@ static void nvmet_bdev_execute_rw(struct nvmet_req *req)
 
     sector = nvmet_lba_to_sect(req->ns, req->cmd->rw.slba);
 
-    if (req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN) {
+    if (nvmet_use_inline_bvec(req)) {
         bio = &req->b.inline_bio;
         bio_init(bio, req->inline_bvec, ARRAY_SIZE(req->inline_bvec));
     } else {
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 5566ed403576..d69a409515d6 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -616,4 +616,10 @@ static inline sector_t nvmet_lba_to_sect(struct
nvmet_ns *ns, __le64 lba)
     return le64_to_cpu(lba) << (ns->blksize_shift - SECTOR_SHIFT);
 }
 
+static inline bool nvmet_use_inline_bvec(struct nvmet_req *req)
+{
+    return req->transfer_len <= NVMET_MAX_INLINE_DATA_LEN &&
+           req->sg_cnt <= NVMET_MAX_INLINE_BIOVEC;
+}
+
 #endif /* _NVMET_H */





More information about the Linux-nvme mailing list