@@ -2539,12 +2539,42 @@ bdev_nvme_no_pi_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
25392539 return rc ;
25402540}
25412541
2542+ static inline enum spdk_nvme_ns_cmd_ext_io_opts_mem_types
2543+ bdev_nvme_map_io_mkey_type (enum spdk_bdev_ext_io_opts_mem_types mem_type ) {
2544+
2545+ switch (mem_type )
2546+ {
2547+ case SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE_MEMORY_KEY :
2548+ return SPDK_NVME_NS_CMD_EXT_IO_OPTS_MEM_TYPE_MEMORY_KEY ;
2549+ default :
2550+ SPDK_ERRLOG ("Unknown get_mkey ctx type %d\n" , mem_type );
2551+ assert (0 );
2552+ }
2553+ }
2554+
2555+ static int bdev_nvme_ns_cmd_io_get_mkey (void * cb_arg , void * address , size_t length , void * pd ,
2556+ uint32_t * mkey )
2557+ {
2558+ struct nvme_bdev_io * bio = cb_arg ;
2559+ struct spdk_bdev_io * bdev_io = spdk_bdev_io_from_ctx (bio );
2560+ int rc ;
2561+
2562+ assert (bdev_io -> internal .ext_opts .mem_type -> type == SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE_MEMORY_KEY &&
2563+ bdev_io -> internal .ext_opts .mem_type -> u .mkey .get_mkey_cb != NULL );
2564+
2565+ rc = bdev_io -> internal .ext_opts .mem_type -> u .mkey .get_mkey_cb (
2566+ bdev_io -> internal .ext_opts .mem_type -> u .mkey .get_mkey_cb_arg , address , length , pd , mkey );
2567+
2568+ return rc ;
2569+ }
2570+
25422571static int
25432572bdev_nvme_readv (struct spdk_nvme_ns * ns , struct spdk_nvme_qpair * qpair ,
25442573 struct nvme_bdev_io * bio , struct iovec * iov , int iovcnt ,
25452574 void * md , uint64_t lba_count , uint64_t lba , uint32_t flags )
25462575{
25472576 int rc ;
2577+ struct spdk_bdev_io * bdev_io = spdk_bdev_io_from_ctx (bio );
25482578
25492579 SPDK_DEBUGLOG (bdev_nvme , "read %" PRIu64 " blocks with offset %#" PRIx64 "\n" ,
25502580 lba_count , lba );
@@ -2554,7 +2584,25 @@ bdev_nvme_readv(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
25542584 bio -> iovpos = 0 ;
25552585 bio -> iov_offset = 0 ;
25562586
2557- if (iovcnt == 1 ) {
2587+ if (bdev_io -> internal .ext_opts .flags ) {
2588+ struct spdk_nvme_ns_cmd_ext_io_opts opts ;
2589+ struct spdk_nvme_ns_cmd_ext_io_opts_mem_type mem_type ;
2590+
2591+ opts .flags = bdev_io -> internal .ext_opts .flags ;
2592+
2593+ if (bdev_io -> internal .ext_opts .flags & SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE ) {
2594+ opts .mem_type = & mem_type ;
2595+ mem_type .type = bdev_nvme_map_io_mkey_type (bdev_io -> internal .mem_type .type );
2596+ if (mem_type .type == SPDK_NVME_NS_CMD_EXT_IO_OPTS_MEM_TYPE_MEMORY_KEY ) {
2597+ mem_type .u .mkey .get_mkey_cb = bdev_nvme_ns_cmd_io_get_mkey ;
2598+ }
2599+ }
2600+
2601+ rc = spdk_nvme_ns_cmd_readv_with_md_ext (ns , qpair , lba , lba_count ,
2602+ bdev_nvme_readv_done , bio , flags ,
2603+ bdev_nvme_queued_reset_sgl , bdev_nvme_queued_next_sge ,
2604+ md , 0 , 0 , & opts );
2605+ } else if (iovcnt == 1 ) {
25582606 rc = spdk_nvme_ns_cmd_read_with_md (ns , qpair , iov [0 ].iov_base , md , lba ,
25592607 lba_count ,
25602608 bdev_nvme_readv_done , bio ,
@@ -2580,6 +2628,7 @@ bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
25802628 uint32_t flags )
25812629{
25822630 int rc ;
2631+ struct spdk_bdev_io * bdev_io = spdk_bdev_io_from_ctx (bio );
25832632
25842633 SPDK_DEBUGLOG (bdev_nvme , "write %" PRIu64 " blocks with offset %#" PRIx64 "\n" ,
25852634 lba_count , lba );
@@ -2589,7 +2638,25 @@ bdev_nvme_writev(struct spdk_nvme_ns *ns, struct spdk_nvme_qpair *qpair,
25892638 bio -> iovpos = 0 ;
25902639 bio -> iov_offset = 0 ;
25912640
2592- if (iovcnt == 1 ) {
2641+ if (bdev_io -> internal .ext_opts .flags ) {
2642+ struct spdk_nvme_ns_cmd_ext_io_opts opts ;
2643+ struct spdk_nvme_ns_cmd_ext_io_opts_mem_type mem_type ;
2644+
2645+ opts .flags = bdev_io -> internal .ext_opts .flags ;
2646+
2647+ if (bdev_io -> internal .ext_opts .flags & SPDK_BDEV_EXT_IO_OPTS_MEM_TYPE ) {
2648+ opts .mem_type = & mem_type ;
2649+ mem_type .type = bdev_nvme_map_io_mkey_type (bdev_io -> internal .mem_type .type );
2650+ if (mem_type .type == SPDK_NVME_NS_CMD_EXT_IO_OPTS_MEM_TYPE_MEMORY_KEY ) {
2651+ mem_type .u .mkey .get_mkey_cb = bdev_nvme_ns_cmd_io_get_mkey ;
2652+ }
2653+ }
2654+
2655+ rc = spdk_nvme_ns_cmd_writev_with_md_ext (ns , qpair , lba , lba_count ,
2656+ bdev_nvme_readv_done , bio , flags ,
2657+ bdev_nvme_queued_reset_sgl , bdev_nvme_queued_next_sge ,
2658+ md , 0 , 0 , & opts );
2659+ } else if (iovcnt == 1 ) {
25932660 rc = spdk_nvme_ns_cmd_write_with_md (ns , qpair , iov [0 ].iov_base , md , lba ,
25942661 lba_count ,
25952662 bdev_nvme_readv_done , bio ,
0 commit comments