Skip to content

Commit 84faf42

Browse files
ChaitanayaKulkarniChristoph Hellwig
authored andcommitted
nvmet: add error log support for fabrics-cmd
This patch adds the support to maintain error log page for the fabrics prop get, prop set, and admin connect commands. Here we also update the discovery.c and add update set/get features and parse functions to support error log page. Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com> Reviewed-by: Sagi Grimberg <sagi@grimberg.me> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent e81446a commit 84faf42

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

drivers/nvme/target/discovery.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ static void nvmet_execute_disc_set_features(struct nvmet_req *req)
259259
NVMET_DISC_AEN_CFG_OPTIONAL);
260260
break;
261261
default:
262+
req->error_loc =
263+
offsetof(struct nvme_common_command, cdw10);
262264
stat = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
263265
break;
264266
}
@@ -279,6 +281,8 @@ static void nvmet_execute_disc_get_features(struct nvmet_req *req)
279281
nvmet_get_feat_async_event(req);
280282
break;
281283
default:
284+
req->error_loc =
285+
offsetof(struct nvme_common_command, cdw10);
282286
stat = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
283287
break;
284288
}
@@ -293,6 +297,8 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
293297
if (unlikely(!(req->sq->ctrl->csts & NVME_CSTS_RDY))) {
294298
pr_err("got cmd %d while not ready\n",
295299
cmd->common.opcode);
300+
req->error_loc =
301+
offsetof(struct nvme_common_command, opcode);
296302
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
297303
}
298304

@@ -323,6 +329,8 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
323329
default:
324330
pr_err("unsupported get_log_page lid %d\n",
325331
cmd->get_log_page.lid);
332+
req->error_loc =
333+
offsetof(struct nvme_get_log_page_command, lid);
326334
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
327335
}
328336
case nvme_admin_identify:
@@ -335,10 +343,12 @@ u16 nvmet_parse_discovery_cmd(struct nvmet_req *req)
335343
default:
336344
pr_err("unsupported identify cns %d\n",
337345
cmd->identify.cns);
346+
req->error_loc = offsetof(struct nvme_identify, cns);
338347
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
339348
}
340349
default:
341350
pr_err("unhandled cmd %d\n", cmd->common.opcode);
351+
req->error_loc = offsetof(struct nvme_common_command, opcode);
342352
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
343353
}
344354

drivers/nvme/target/fabrics-cmd.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,26 @@
1717

1818
static void nvmet_execute_prop_set(struct nvmet_req *req)
1919
{
20+
u64 val = le64_to_cpu(req->cmd->prop_set.value);
2021
u16 status = 0;
2122

22-
if (!(req->cmd->prop_set.attrib & 1)) {
23-
u64 val = le64_to_cpu(req->cmd->prop_set.value);
24-
25-
switch (le32_to_cpu(req->cmd->prop_set.offset)) {
26-
case NVME_REG_CC:
27-
nvmet_update_cc(req->sq->ctrl, val);
28-
break;
29-
default:
30-
status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
31-
break;
32-
}
33-
} else {
23+
if (req->cmd->prop_set.attrib & 1) {
24+
req->error_loc =
25+
offsetof(struct nvmf_property_set_command, attrib);
3426
status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
27+
goto out;
3528
}
3629

30+
switch (le32_to_cpu(req->cmd->prop_set.offset)) {
31+
case NVME_REG_CC:
32+
nvmet_update_cc(req->sq->ctrl, val);
33+
break;
34+
default:
35+
req->error_loc =
36+
offsetof(struct nvmf_property_set_command, offset);
37+
status = NVME_SC_INVALID_FIELD | NVME_SC_DNR;
38+
}
39+
out:
3740
nvmet_req_complete(req, status);
3841
}
3942

@@ -69,6 +72,14 @@ static void nvmet_execute_prop_get(struct nvmet_req *req)
6972
}
7073
}
7174

75+
if (status && req->cmd->prop_get.attrib & 1) {
76+
req->error_loc =
77+
offsetof(struct nvmf_property_get_command, offset);
78+
} else {
79+
req->error_loc =
80+
offsetof(struct nvmf_property_get_command, attrib);
81+
}
82+
7283
req->rsp->result.u64 = cpu_to_le64(val);
7384
nvmet_req_complete(req, status);
7485
}
@@ -89,6 +100,7 @@ u16 nvmet_parse_fabrics_cmd(struct nvmet_req *req)
89100
default:
90101
pr_err("received unknown capsule type 0x%x\n",
91102
cmd->fabrics.fctype);
103+
req->error_loc = offsetof(struct nvmf_common_command, fctype);
92104
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
93105
}
94106

@@ -105,10 +117,12 @@ static u16 nvmet_install_queue(struct nvmet_ctrl *ctrl, struct nvmet_req *req)
105117
old = cmpxchg(&req->sq->ctrl, NULL, ctrl);
106118
if (old) {
107119
pr_warn("queue already connected!\n");
120+
req->error_loc = offsetof(struct nvmf_connect_command, opcode);
108121
return NVME_SC_CONNECT_CTRL_BUSY | NVME_SC_DNR;
109122
}
110123
if (!sqsize) {
111124
pr_warn("queue size zero!\n");
125+
req->error_loc = offsetof(struct nvmf_connect_command, sqsize);
112126
return NVME_SC_CONNECT_INVALID_PARAM | NVME_SC_DNR;
113127
}
114128

@@ -157,6 +171,7 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
157171
if (c->recfmt != 0) {
158172
pr_warn("invalid connect version (%d).\n",
159173
le16_to_cpu(c->recfmt));
174+
req->error_loc = offsetof(struct nvmf_connect_command, recfmt);
160175
status = NVME_SC_CONNECT_FORMAT | NVME_SC_DNR;
161176
goto out;
162177
}
@@ -171,8 +186,13 @@ static void nvmet_execute_admin_connect(struct nvmet_req *req)
171186

172187
status = nvmet_alloc_ctrl(d->subsysnqn, d->hostnqn, req,
173188
le32_to_cpu(c->kato), &ctrl);
174-
if (status)
189+
if (status) {
190+
if (status == (NVME_SC_INVALID_FIELD | NVME_SC_DNR))
191+
req->error_loc =
192+
offsetof(struct nvme_common_command, opcode);
175193
goto out;
194+
}
195+
176196
uuid_copy(&ctrl->hostid, &d->hostid);
177197

178198
status = nvmet_install_queue(ctrl, req);
@@ -259,11 +279,13 @@ u16 nvmet_parse_connect_cmd(struct nvmet_req *req)
259279
if (cmd->common.opcode != nvme_fabrics_command) {
260280
pr_err("invalid command 0x%x on unconnected queue.\n",
261281
cmd->fabrics.opcode);
282+
req->error_loc = offsetof(struct nvme_common_command, opcode);
262283
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
263284
}
264285
if (cmd->fabrics.fctype != nvme_fabrics_type_connect) {
265286
pr_err("invalid capsule type 0x%x on unconnected queue.\n",
266287
cmd->fabrics.fctype);
288+
req->error_loc = offsetof(struct nvmf_common_command, fctype);
267289
return NVME_SC_INVALID_OPCODE | NVME_SC_DNR;
268290
}
269291

0 commit comments

Comments
 (0)