Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvmet: Introduce nvmet_req_transfer_len()

Add the new function nvmet_req_transfer_len() to parse a request command
to extract the transfer length of the command. This function
implementation relies on multiple helper functions for parsing I/O
commands (nvmet_io_cmd_transfer_len()), admin commands
(nvmet_admin_cmd_data_len()) and fabrics connect commands
(nvmet_connect_cmd_data_len).

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Tested-by: Rick Wertenbroek <rick.wertenbroek@gmail.com>
Tested-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Keith Busch <kbusch@kernel.org>

authored by

Damien Le Moal and committed by
Keith Busch
43043c9b 62027831

+135 -2
+21
drivers/nvme/target/admin-cmd.c
··· 1296 1296 nvmet_req_complete(req, status); 1297 1297 } 1298 1298 1299 + u32 nvmet_admin_cmd_data_len(struct nvmet_req *req) 1300 + { 1301 + struct nvme_command *cmd = req->cmd; 1302 + 1303 + if (nvme_is_fabrics(cmd)) 1304 + return nvmet_fabrics_admin_cmd_data_len(req); 1305 + if (nvmet_is_disc_subsys(nvmet_req_subsys(req))) 1306 + return nvmet_discovery_cmd_data_len(req); 1307 + 1308 + switch (cmd->common.opcode) { 1309 + case nvme_admin_get_log_page: 1310 + return nvmet_get_log_page_len(cmd); 1311 + case nvme_admin_identify: 1312 + return NVME_IDENTIFY_DATA_SIZE; 1313 + case nvme_admin_get_features: 1314 + return nvmet_feat_data_len(req, le32_to_cpu(cmd->common.cdw10)); 1315 + default: 1316 + return 0; 1317 + } 1318 + } 1319 + 1299 1320 u16 nvmet_parse_admin_cmd(struct nvmet_req *req) 1300 1321 { 1301 1322 struct nvme_command *cmd = req->cmd;
+37
drivers/nvme/target/core.c
··· 911 911 return 0; 912 912 } 913 913 914 + static u32 nvmet_io_cmd_transfer_len(struct nvmet_req *req) 915 + { 916 + struct nvme_command *cmd = req->cmd; 917 + u32 metadata_len = 0; 918 + 919 + if (nvme_is_fabrics(cmd)) 920 + return nvmet_fabrics_io_cmd_data_len(req); 921 + 922 + if (!req->ns) 923 + return 0; 924 + 925 + switch (req->cmd->common.opcode) { 926 + case nvme_cmd_read: 927 + case nvme_cmd_write: 928 + case nvme_cmd_zone_append: 929 + if (req->sq->ctrl->pi_support && nvmet_ns_has_pi(req->ns)) 930 + metadata_len = nvmet_rw_metadata_len(req); 931 + return nvmet_rw_data_len(req) + metadata_len; 932 + case nvme_cmd_dsm: 933 + return nvmet_dsm_len(req); 934 + case nvme_cmd_zone_mgmt_recv: 935 + return (le32_to_cpu(req->cmd->zmr.numd) + 1) << 2; 936 + default: 937 + return 0; 938 + } 939 + } 940 + 914 941 static u16 nvmet_parse_io_cmd(struct nvmet_req *req) 915 942 { 916 943 struct nvme_command *cmd = req->cmd; ··· 1085 1058 nvmet_put_namespace(req->ns); 1086 1059 } 1087 1060 EXPORT_SYMBOL_GPL(nvmet_req_uninit); 1061 + 1062 + size_t nvmet_req_transfer_len(struct nvmet_req *req) 1063 + { 1064 + if (likely(req->sq->qid != 0)) 1065 + return nvmet_io_cmd_transfer_len(req); 1066 + if (unlikely(!req->sq->ctrl)) 1067 + return nvmet_connect_cmd_data_len(req); 1068 + return nvmet_admin_cmd_data_len(req); 1069 + } 1070 + EXPORT_SYMBOL_GPL(nvmet_req_transfer_len); 1088 1071 1089 1072 bool nvmet_check_transfer_len(struct nvmet_req *req, size_t len) 1090 1073 {
+14
drivers/nvme/target/discovery.c
··· 355 355 nvmet_req_complete(req, stat); 356 356 } 357 357 358 + u32 nvmet_discovery_cmd_data_len(struct nvmet_req *req) 359 + { 360 + struct nvme_command *cmd = req->cmd; 361 + 362 + switch (cmd->common.opcode) { 363 + case nvme_admin_get_log_page: 364 + return nvmet_get_log_page_len(req->cmd); 365 + case nvme_admin_identify: 366 + return NVME_IDENTIFY_DATA_SIZE; 367 + default: 368 + return 0; 369 + } 370 + } 371 + 358 372 u16 nvmet_parse_discovery_cmd(struct nvmet_req *req) 359 373 { 360 374 struct nvme_command *cmd = req->cmd;
+12 -2
drivers/nvme/target/fabrics-cmd-auth.c
··· 179 179 return data->rescode_exp; 180 180 } 181 181 182 + u32 nvmet_auth_send_data_len(struct nvmet_req *req) 183 + { 184 + return le32_to_cpu(req->cmd->auth_send.tl); 185 + } 186 + 182 187 void nvmet_execute_auth_send(struct nvmet_req *req) 183 188 { 184 189 struct nvmet_ctrl *ctrl = req->sq->ctrl; ··· 211 206 offsetof(struct nvmf_auth_send_command, spsp1); 212 207 goto done; 213 208 } 214 - tl = le32_to_cpu(req->cmd->auth_send.tl); 209 + tl = nvmet_auth_send_data_len(req); 215 210 if (!tl) { 216 211 status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; 217 212 req->error_loc = ··· 434 429 data->rescode_exp = req->sq->dhchap_status; 435 430 } 436 431 432 + u32 nvmet_auth_receive_data_len(struct nvmet_req *req) 433 + { 434 + return le32_to_cpu(req->cmd->auth_receive.al); 435 + } 436 + 437 437 void nvmet_execute_auth_receive(struct nvmet_req *req) 438 438 { 439 439 struct nvmet_ctrl *ctrl = req->sq->ctrl; ··· 464 454 offsetof(struct nvmf_auth_receive_command, spsp1); 465 455 goto done; 466 456 } 467 - al = le32_to_cpu(req->cmd->auth_receive.al); 457 + al = nvmet_auth_receive_data_len(req); 468 458 if (!al) { 469 459 status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR; 470 460 req->error_loc =
+43
drivers/nvme/target/fabrics-cmd.c
··· 85 85 nvmet_req_complete(req, status); 86 86 } 87 87 88 + u32 nvmet_fabrics_admin_cmd_data_len(struct nvmet_req *req) 89 + { 90 + struct nvme_command *cmd = req->cmd; 91 + 92 + switch (cmd->fabrics.fctype) { 93 + #ifdef CONFIG_NVME_TARGET_AUTH 94 + case nvme_fabrics_type_auth_send: 95 + return nvmet_auth_send_data_len(req); 96 + case nvme_fabrics_type_auth_receive: 97 + return nvmet_auth_receive_data_len(req); 98 + #endif 99 + default: 100 + return 0; 101 + } 102 + } 103 + 88 104 u16 nvmet_parse_fabrics_admin_cmd(struct nvmet_req *req) 89 105 { 90 106 struct nvme_command *cmd = req->cmd; ··· 128 112 } 129 113 130 114 return 0; 115 + } 116 + 117 + u32 nvmet_fabrics_io_cmd_data_len(struct nvmet_req *req) 118 + { 119 + struct nvme_command *cmd = req->cmd; 120 + 121 + switch (cmd->fabrics.fctype) { 122 + #ifdef CONFIG_NVME_TARGET_AUTH 123 + case nvme_fabrics_type_auth_send: 124 + return nvmet_auth_send_data_len(req); 125 + case nvme_fabrics_type_auth_receive: 126 + return nvmet_auth_receive_data_len(req); 127 + #endif 128 + default: 129 + return 0; 130 + } 131 131 } 132 132 133 133 u16 nvmet_parse_fabrics_io_cmd(struct nvmet_req *req) ··· 367 335 out_ctrl_put: 368 336 nvmet_ctrl_put(ctrl); 369 337 goto out; 338 + } 339 + 340 + u32 nvmet_connect_cmd_data_len(struct nvmet_req *req) 341 + { 342 + struct nvme_command *cmd = req->cmd; 343 + 344 + if (!nvme_is_fabrics(cmd) || 345 + cmd->fabrics.fctype != nvme_fabrics_type_connect) 346 + return 0; 347 + 348 + return sizeof(struct nvmf_connect_data); 370 349 } 371 350 372 351 u16 nvmet_parse_connect_cmd(struct nvmet_req *req)
+8
drivers/nvme/target/nvmet.h
··· 517 517 void nvmet_stop_keep_alive_timer(struct nvmet_ctrl *ctrl); 518 518 519 519 u16 nvmet_parse_connect_cmd(struct nvmet_req *req); 520 + u32 nvmet_connect_cmd_data_len(struct nvmet_req *req); 520 521 void nvmet_bdev_set_limits(struct block_device *bdev, struct nvme_id_ns *id); 521 522 u16 nvmet_bdev_parse_io_cmd(struct nvmet_req *req); 522 523 u16 nvmet_file_parse_io_cmd(struct nvmet_req *req); 523 524 u16 nvmet_bdev_zns_parse_io_cmd(struct nvmet_req *req); 525 + u32 nvmet_admin_cmd_data_len(struct nvmet_req *req); 524 526 u16 nvmet_parse_admin_cmd(struct nvmet_req *req); 527 + u32 nvmet_discovery_cmd_data_len(struct nvmet_req *req); 525 528 u16 nvmet_parse_discovery_cmd(struct nvmet_req *req); 526 529 u16 nvmet_parse_fabrics_admin_cmd(struct nvmet_req *req); 530 + u32 nvmet_fabrics_admin_cmd_data_len(struct nvmet_req *req); 527 531 u16 nvmet_parse_fabrics_io_cmd(struct nvmet_req *req); 532 + u32 nvmet_fabrics_io_cmd_data_len(struct nvmet_req *req); 528 533 529 534 bool nvmet_req_init(struct nvmet_req *req, struct nvmet_cq *cq, 530 535 struct nvmet_sq *sq, const struct nvmet_fabrics_ops *ops); 531 536 void nvmet_req_uninit(struct nvmet_req *req); 537 + size_t nvmet_req_transfer_len(struct nvmet_req *req); 532 538 bool nvmet_check_transfer_len(struct nvmet_req *req, size_t len); 533 539 bool nvmet_check_data_len_lte(struct nvmet_req *req, size_t data_len); 534 540 void nvmet_req_complete(struct nvmet_req *req, u16 status); ··· 828 822 } 829 823 830 824 #ifdef CONFIG_NVME_TARGET_AUTH 825 + u32 nvmet_auth_send_data_len(struct nvmet_req *req); 831 826 void nvmet_execute_auth_send(struct nvmet_req *req); 827 + u32 nvmet_auth_receive_data_len(struct nvmet_req *req); 832 828 void nvmet_execute_auth_receive(struct nvmet_req *req); 833 829 int nvmet_auth_set_key(struct nvmet_host *host, const char *secret, 834 830 bool set_ctrl);