Skip to content

Commit a364645

Browse files
mitaChristoph Hellwig
authored andcommitted
nvme: prepare for fault injection into admin commands
Currenlty fault injection support for nvme only enables to inject errors into the commands submitted to I/O queues. In preparation for fault injection into the admin commands, this makes the helper functions independent of struct nvme_ns. Signed-off-by: Akinobu Mita <[email protected]> Reviewed-by: Minwoo Im <[email protected]> Reviewed-by: Sagi Grimberg <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Signed-off-by: Christoph Hellwig <[email protected]>
1 parent a5448fd commit a364645

File tree

3 files changed

+41
-33
lines changed

3 files changed

+41
-33
lines changed

drivers/nvme/host/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3336,7 +3336,7 @@ static int nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid)
33363336
device_add_disk(ctrl->device, ns->disk, nvme_ns_id_attr_groups);
33373337

33383338
nvme_mpath_add_disk(ns, id);
3339-
nvme_fault_inject_init(ns);
3339+
nvme_fault_inject_init(&ns->fault_inject, ns->disk->disk_name);
33403340
kfree(id);
33413341

33423342
return 0;
@@ -3361,7 +3361,7 @@ static void nvme_ns_remove(struct nvme_ns *ns)
33613361
if (test_and_set_bit(NVME_NS_REMOVING, &ns->flags))
33623362
return;
33633363

3364-
nvme_fault_inject_fini(ns);
3364+
nvme_fault_inject_fini(&ns->fault_inject);
33653365

33663366
mutex_lock(&ns->ctrl->subsys->lock);
33673367
list_del_rcu(&ns->siblings);

drivers/nvme/host/fault_inject.c

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,31 @@ static DECLARE_FAULT_ATTR(fail_default_attr);
1515
static char *fail_request;
1616
module_param(fail_request, charp, 0000);
1717

18-
void nvme_fault_inject_init(struct nvme_ns *ns)
18+
void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
19+
const char *dev_name)
1920
{
2021
struct dentry *dir, *parent;
21-
char *name = ns->disk->disk_name;
22-
struct nvme_fault_inject *fault_inj = &ns->fault_inject;
2322
struct fault_attr *attr = &fault_inj->attr;
2423

2524
/* set default fault injection attribute */
2625
if (fail_request)
2726
setup_fault_attr(&fail_default_attr, fail_request);
2827

2928
/* create debugfs directory and attribute */
30-
parent = debugfs_create_dir(name, NULL);
29+
parent = debugfs_create_dir(dev_name, NULL);
3130
if (!parent) {
32-
pr_warn("%s: failed to create debugfs directory\n", name);
31+
pr_warn("%s: failed to create debugfs directory\n", dev_name);
3332
return;
3433
}
3534

3635
*attr = fail_default_attr;
3736
dir = fault_create_debugfs_attr("fault_inject", parent, attr);
3837
if (IS_ERR(dir)) {
39-
pr_warn("%s: failed to create debugfs attr\n", name);
38+
pr_warn("%s: failed to create debugfs attr\n", dev_name);
4039
debugfs_remove_recursive(parent);
4140
return;
4241
}
43-
ns->fault_inject.parent = parent;
42+
fault_inj->parent = parent;
4443

4544
/* create debugfs for status code and dont_retry */
4645
fault_inj->status = NVME_SC_INVALID_OPCODE;
@@ -49,29 +48,34 @@ void nvme_fault_inject_init(struct nvme_ns *ns)
4948
debugfs_create_bool("dont_retry", 0600, dir, &fault_inj->dont_retry);
5049
}
5150

52-
void nvme_fault_inject_fini(struct nvme_ns *ns)
51+
void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject)
5352
{
5453
/* remove debugfs directories */
55-
debugfs_remove_recursive(ns->fault_inject.parent);
54+
debugfs_remove_recursive(fault_inject->parent);
5655
}
5756

5857
void nvme_should_fail(struct request *req)
5958
{
6059
struct gendisk *disk = req->rq_disk;
61-
struct nvme_ns *ns = NULL;
60+
struct nvme_fault_inject *fault_inject = NULL;
6261
u16 status;
6362

6463
/*
6564
* make sure this request is coming from a valid namespace
6665
*/
67-
if (!disk)
68-
return;
66+
if (disk) {
67+
struct nvme_ns *ns = disk->private_data;
68+
69+
if (ns)
70+
fault_inject = &ns->fault_inject;
71+
else
72+
WARN_ONCE(1, "No namespace found for request\n");
73+
}
6974

70-
ns = disk->private_data;
71-
if (ns && should_fail(&ns->fault_inject.attr, 1)) {
75+
if (fault_inject && should_fail(&fault_inject->attr, 1)) {
7276
/* inject status code and DNR bit */
73-
status = ns->fault_inject.status;
74-
if (ns->fault_inject.dont_retry)
77+
status = fault_inject->status;
78+
if (fault_inject->dont_retry)
7579
status |= NVME_SC_DNR;
7680
nvme_req(req)->status = status;
7781
}

drivers/nvme/host/nvme.h

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,15 @@ enum nvme_ctrl_state {
146146
NVME_CTRL_DEAD,
147147
};
148148

149+
struct nvme_fault_inject {
150+
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
151+
struct fault_attr attr;
152+
struct dentry *parent;
153+
bool dont_retry; /* DNR, do not retry */
154+
u16 status; /* status code */
155+
#endif
156+
};
157+
149158
struct nvme_ctrl {
150159
bool comp_seen;
151160
enum nvme_ctrl_state state;
@@ -313,15 +322,6 @@ struct nvme_ns_head {
313322
#endif
314323
};
315324

316-
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
317-
struct nvme_fault_inject {
318-
struct fault_attr attr;
319-
struct dentry *parent;
320-
bool dont_retry; /* DNR, do not retry */
321-
u16 status; /* status code */
322-
};
323-
#endif
324-
325325
struct nvme_ns {
326326
struct list_head list;
327327

@@ -349,9 +349,7 @@ struct nvme_ns {
349349
#define NVME_NS_ANA_PENDING 2
350350
u16 noiob;
351351

352-
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
353352
struct nvme_fault_inject fault_inject;
354-
#endif
355353

356354
};
357355

@@ -372,12 +370,18 @@ struct nvme_ctrl_ops {
372370
};
373371

374372
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
375-
void nvme_fault_inject_init(struct nvme_ns *ns);
376-
void nvme_fault_inject_fini(struct nvme_ns *ns);
373+
void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
374+
const char *dev_name);
375+
void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inject);
377376
void nvme_should_fail(struct request *req);
378377
#else
379-
static inline void nvme_fault_inject_init(struct nvme_ns *ns) {}
380-
static inline void nvme_fault_inject_fini(struct nvme_ns *ns) {}
378+
static inline void nvme_fault_inject_init(struct nvme_fault_inject *fault_inj,
379+
const char *dev_name)
380+
{
381+
}
382+
static inline void nvme_fault_inject_fini(struct nvme_fault_inject *fault_inj)
383+
{
384+
}
381385
static inline void nvme_should_fail(struct request *req) {}
382386
#endif
383387

0 commit comments

Comments
 (0)