[PATCH V13 2/4] nvmet: add ZBD over ZNS backend support

Chaitanya Kulkarni Chaitanya.Kulkarni at wdc.com
Fri Apr 9 08:09:12 BST 2021


On 4/8/21 00:24, Christoph Hellwig wrote:
>> @@ -448,6 +456,15 @@ u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req)
>>  	case nvme_cmd_write_zeroes:
>>  		req->execute = nvmet_bdev_execute_write_zeroes;
>>  		return 0;
>> +	case nvme_cmd_zone_append:
>> +		req->execute = nvmet_bdev_execute_zone_append;
>> +		return 0;
>> +	case nvme_cmd_zone_mgmt_recv:
>> +		req->execute = nvmet_bdev_execute_zone_mgmt_recv;
>> +		return 0;
>> +	case nvme_cmd_zone_mgmt_send:
>> +		req->execute = nvmet_bdev_execute_zone_mgmt_send;
> I think we need a separate _parse for just ZNS.  That way we can
> do the ns.csi and IS_ENABLED check in one single place, and we
> also don't need stubs for any of these functions as they are all
> under the IS_ENABLED check and thus the compiler will never generate
> a call to them for !CONFIG_BLK_DEV_ZONED.
>

Do you prefer something like this ? (partially tested with and without
CONFIG_BLK_DEV_ZONED) :-

# git diff
diff --git a/drivers/nvme/target/admin-cmd.c
b/drivers/nvme/target/admin-cmd.c
index fc5f64a38661..da6d5225f25a 100644
--- a/drivers/nvme/target/admin-cmd.c
+++ b/drivers/nvme/target/admin-cmd.c
@@ -685,6 +685,14 @@ static void nvmet_execute_identify(struct nvmet_req
*req)
        if (!nvmet_check_transfer_len(req, NVME_IDENTIFY_DATA_SIZE))
                return;
 
+       switch (req->cmd->identify.csi) {
+       case NVME_CSI_NVM:
+       case NVME_CSI_ZNS:
+               break;
+       default:
+               goto out;
+       }
+
        switch (req->cmd->identify.cns) {
        case NVME_ID_CNS_NS:
                return nvmet_execute_identify_ns(req);
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index d33ba4c3c3f4..a0bdd39de23b 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -892,7 +892,16 @@ static u16 nvmet_parse_io_cmd(struct nvmet_req *req)
        if (req->ns->file)
                return nvmet_file_parse_io_cmd(req);
 
-       return nvmet_bdev_parse_io_cmd(req);
+       switch (req->ns->csi) {
+       case NVME_CSI_NVM:
+               return nvmet_bdev_parse_io_cmd(req);
+       case NVME_CSI_ZNS:
+               if (IS_ENABLED(CONFIG_BLK_DEV_ZONED))
+                       return nvmet_bdev_zns_parse_io_cmd(req);
+               /* fallthrough */
+       default:
+               return NVME_SC_INVALID_IO_CMD_SET;
+       }
 }
 
 bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq,
diff --git a/drivers/nvme/target/nvmet.h b/drivers/nvme/target/nvmet.h
index 8333701e4154..fcd01e303e19 100644
--- a/drivers/nvme/target/nvmet.h
+++ b/drivers/nvme/target/nvmet.h
@@ -404,6 +404,7 @@ void nvmet_stop_keep_alive_timer(struct nvmet_ctrl
*ctrl);
 u16 nvmet_parse_connect_cmd(struct nvmet_req *req);
 void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns
*id);
 u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req);
+u16 nvmet_bdev_zns_parse_io_cmd(struct nvmet_req *req);
 u16 nvmet_file_parse_io_cmd(struct nvmet_req *req);
 u16 nvmet_parse_admin_cmd(struct nvmet_req *req);
 u16 nvmet_parse_discovery_cmd(struct nvmet_req *req);
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index b62925eb49ab..c65ac53d9b0b 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -445,3 +445,22 @@ void nvmet_bdev_execute_zone_append(struct
nvmet_req *req)
                bio_put(bio);
        nvmet_req_complete(req, ret < 0 ? NVME_SC_INTERNAL : status);
 }
+
+u16 nvmet_bdev_zns_parse_io_cmd(struct nvmet_req *req)
+{
+       struct nvme_command *cmd = req->cmd;
+
+       switch (cmd->common.opcode) {
+       case nvme_cmd_zone_append:
+               req->execute = nvmet_bdev_execute_zone_append;
+               return 0;
+       case nvme_cmd_zone_mgmt_recv:
+               req->execute = nvmet_bdev_execute_zone_mgmt_recv;
+               return 0;
+       case nvme_cmd_zone_mgmt_send:
+               req->execute = nvmet_bdev_execute_zone_mgmt_send;
+               return 0;
+       default:
+               return nvmet_bdev_parse_io_cmd(req);
+       }
+}
roo



More information about the Linux-nvme mailing list