Skip to content

Commit 1f4137e

Browse files
committed
nvme: move passthrough logging attribute to head
The namespace does not have attributes, but the head does. Move the new logging attribute to that structure instead of dereferencing the wrong type. And while we're here, fix the reverse-tree coding style. Fixes: 9f079dd ("nvme: allow passthru cmd error logging") Reported-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com> Tested-by: Tasmiya Nalatwad <tasmiya@linux.vnet.ibm.com> Reviewed-by: Chaitanya Kulkarni <kch@nvidia.com> Reviewed-by: Alan Adamson <alan.adamson@oracle.com> Signed-off-by: Keith Busch <kbusch@kernel.org>
1 parent f0377ff commit 1f4137e

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

drivers/nvme/host/core.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ void nvme_init_request(struct request *req, struct nvme_command *cmd)
713713
if (req->q->queuedata) {
714714
struct nvme_ns *ns = req->q->disk->private_data;
715715

716-
logging_enabled = ns->passthru_err_log_enabled;
716+
logging_enabled = ns->head->passthru_err_log_enabled;
717717
req->timeout = NVME_IO_TIMEOUT;
718718
} else { /* no queuedata implies admin queue */
719719
logging_enabled = nr->ctrl->passthru_err_log_enabled;
@@ -3696,7 +3696,6 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, struct nvme_ns_info *info)
36963696

36973697
ns->disk = disk;
36983698
ns->queue = disk->queue;
3699-
ns->passthru_err_log_enabled = false;
37003699

37013700
if (ctrl->opts && ctrl->opts->data_digest)
37023701
blk_queue_flag_set(QUEUE_FLAG_STABLE_WRITES, ns->queue);

drivers/nvme/host/nvme.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ struct nvme_ns_head {
455455
struct list_head entry;
456456
struct kref ref;
457457
bool shared;
458+
bool passthru_err_log_enabled;
458459
int instance;
459460
struct nvme_effects_log *effects;
460461
u64 nuse;
@@ -523,7 +524,6 @@ struct nvme_ns {
523524
struct device cdev_device;
524525

525526
struct nvme_fault_inject fault_inject;
526-
bool passthru_err_log_enabled;
527527
};
528528

529529
/* NVMe ns supports metadata actions by the controller (generate/strip) */

drivers/nvme/host/sysfs.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static ssize_t nvme_adm_passthru_err_log_enabled_store(struct device *dev,
4848
struct device_attribute *attr, const char *buf, size_t count)
4949
{
5050
struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
51-
int err;
5251
bool passthru_err_log_enabled;
52+
int err;
5353

5454
err = kstrtobool(buf, &passthru_err_log_enabled);
5555
if (err)
@@ -60,25 +60,34 @@ static ssize_t nvme_adm_passthru_err_log_enabled_store(struct device *dev,
6060
return count;
6161
}
6262

63+
static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev)
64+
{
65+
struct gendisk *disk = dev_to_disk(dev);
66+
67+
if (nvme_disk_is_ns_head(disk))
68+
return disk->private_data;
69+
return nvme_get_ns_from_dev(dev)->head;
70+
}
71+
6372
static ssize_t nvme_io_passthru_err_log_enabled_show(struct device *dev,
6473
struct device_attribute *attr, char *buf)
6574
{
66-
struct nvme_ns *n = dev_get_drvdata(dev);
75+
struct nvme_ns_head *head = dev_to_ns_head(dev);
6776

68-
return sysfs_emit(buf, n->passthru_err_log_enabled ? "on\n" : "off\n");
77+
return sysfs_emit(buf, head->passthru_err_log_enabled ? "on\n" : "off\n");
6978
}
7079

7180
static ssize_t nvme_io_passthru_err_log_enabled_store(struct device *dev,
7281
struct device_attribute *attr, const char *buf, size_t count)
7382
{
74-
struct nvme_ns *ns = dev_get_drvdata(dev);
75-
int err;
83+
struct nvme_ns_head *head = dev_to_ns_head(dev);
7684
bool passthru_err_log_enabled;
85+
int err;
7786

7887
err = kstrtobool(buf, &passthru_err_log_enabled);
7988
if (err)
8089
return -EINVAL;
81-
ns->passthru_err_log_enabled = passthru_err_log_enabled;
90+
head->passthru_err_log_enabled = passthru_err_log_enabled;
8291

8392
return count;
8493
}
@@ -91,15 +100,6 @@ static struct device_attribute dev_attr_io_passthru_err_log_enabled = \
91100
__ATTR(passthru_err_log_enabled, S_IRUGO | S_IWUSR, \
92101
nvme_io_passthru_err_log_enabled_show, nvme_io_passthru_err_log_enabled_store);
93102

94-
static inline struct nvme_ns_head *dev_to_ns_head(struct device *dev)
95-
{
96-
struct gendisk *disk = dev_to_disk(dev);
97-
98-
if (nvme_disk_is_ns_head(disk))
99-
return disk->private_data;
100-
return nvme_get_ns_from_dev(dev)->head;
101-
}
102-
103103
static ssize_t wwid_show(struct device *dev, struct device_attribute *attr,
104104
char *buf)
105105
{

0 commit comments

Comments
 (0)