linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] nvme: Export fast_io_fail_tmo to sysfs
@ 2021-03-31 13:12 Daniel Wagner
  2021-03-31 18:01 ` Ewan D. Milne
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Daniel Wagner @ 2021-03-31 13:12 UTC (permalink / raw)
  To: linux-nvme
  Cc: linux-kernel, Keith Busch, Jens Axboe, Christoph Hellwig,
	Sagi Grimberg, Chaitanya Kulkarni, Hannes Reinecke, Chao Leng,
	Daniel Wagner, Victor Gladkov

Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device")
introduced fast_io_fail_tmo but didn't export the value to sysfs. That
means the value is hard coded during compile time. Export the timeout
value to user space via sysfs to allow runtime configuration.

Cc: Victor Gladkov <Victor.Gladkov@kioxia.com>
Signed-off-by: Daniel Wagner <dwagner@suse.de>
---

This patch is against nvme-5.13

BTW, checkpatch complains with

  WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not preferred. Consider using octal permissions '0644'.

Is this something we want to adapt to?

 drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index 40215a0246e4..c8de0e37c7d9 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3696,6 +3696,36 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev,
 static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
 	nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store);
 
+static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
+		struct device_attribute *attr, char *buf)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+
+	if (ctrl->opts->fast_io_fail_tmo == -1)
+		return sprintf(buf, "off\n");
+	return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);
+}
+
+static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
+		struct device_attribute *attr, const char *buf, size_t count)
+{
+	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
+	struct nvmf_ctrl_options *opts = ctrl->opts;
+	int fast_io_fail_tmo, err;
+
+	err = kstrtoint(buf, 10, &fast_io_fail_tmo);
+	if (err)
+		return -EINVAL;
+
+	else if (fast_io_fail_tmo < 0)
+		opts->fast_io_fail_tmo = -1;
+	else
+		opts->fast_io_fail_tmo = fast_io_fail_tmo;
+	return count;
+}
+static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
+	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
+
 static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_reset_controller.attr,
 	&dev_attr_rescan_controller.attr,
@@ -3715,6 +3745,7 @@ static struct attribute *nvme_dev_attrs[] = {
 	&dev_attr_hostid.attr,
 	&dev_attr_ctrl_loss_tmo.attr,
 	&dev_attr_reconnect_delay.attr,
+	&dev_attr_fast_io_fail_tmo.attr,
 	NULL
 };
 
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs
  2021-03-31 13:12 [PATCH] nvme: Export fast_io_fail_tmo to sysfs Daniel Wagner
@ 2021-03-31 18:01 ` Ewan D. Milne
  2021-03-31 19:36 ` Sagi Grimberg
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Ewan D. Milne @ 2021-03-31 18:01 UTC (permalink / raw)
  To: Daniel Wagner, linux-nvme; +Cc: linux-kernel

On Wed, 2021-03-31 at 15:12 +0200, Daniel Wagner wrote:
> Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device")
> introduced fast_io_fail_tmo but didn't export the value to sysfs.
> That
> means the value is hard coded during compile time. Export the timeout
> value to user space via sysfs to allow runtime configuration.
> 
> Cc: Victor Gladkov <Victor.Gladkov@kioxia.com>
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
> 
> This patch is against nvme-5.13
> 
> BTW, checkpatch complains with
> 
>   WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not
> preferred. Consider using octal permissions '0644'.
> 
> Is this something we want to adapt to?
> 
>  drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 40215a0246e4..c8de0e37c7d9 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3696,6 +3696,36 @@ static ssize_t
> nvme_ctrl_reconnect_delay_store(struct device *dev,
>  static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
>  	nvme_ctrl_reconnect_delay_show,
> nvme_ctrl_reconnect_delay_store);
>  
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> +	if (ctrl->opts->fast_io_fail_tmo == -1)
> +		return sprintf(buf, "off\n");
> +	return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);
> +}
> +
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf, size_t
> count)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	struct nvmf_ctrl_options *opts = ctrl->opts;
> +	int fast_io_fail_tmo, err;
> +
> +	err = kstrtoint(buf, 10, &fast_io_fail_tmo);
> +	if (err)
> +		return -EINVAL;
> +
> +	else if (fast_io_fail_tmo < 0)
> +		opts->fast_io_fail_tmo = -1;
> +	else
> +		opts->fast_io_fail_tmo = fast_io_fail_tmo;
> +	return count;
> +}
> +static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
> +	nvme_ctrl_fast_io_fail_tmo_show,
> nvme_ctrl_fast_io_fail_tmo_store);
> +
>  static struct attribute *nvme_dev_attrs[] = {
>  	&dev_attr_reset_controller.attr,
>  	&dev_attr_rescan_controller.attr,
> @@ -3715,6 +3745,7 @@ static struct attribute *nvme_dev_attrs[] = {
>  	&dev_attr_hostid.attr,
>  	&dev_attr_ctrl_loss_tmo.attr,
>  	&dev_attr_reconnect_delay.attr,
> +	&dev_attr_fast_io_fail_tmo.attr,
>  	NULL
>  };
>  

Thanks.
Reviewed-by: Ewan D. Milne <emilne@redhat.com>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs
  2021-03-31 13:12 [PATCH] nvme: Export fast_io_fail_tmo to sysfs Daniel Wagner
  2021-03-31 18:01 ` Ewan D. Milne
@ 2021-03-31 19:36 ` Sagi Grimberg
  2021-03-31 19:54 ` Himanshu Madhani
  2021-03-31 20:34 ` Chaitanya Kulkarni
  3 siblings, 0 replies; 6+ messages in thread
From: Sagi Grimberg @ 2021-03-31 19:36 UTC (permalink / raw)
  To: Daniel Wagner, linux-nvme
  Cc: linux-kernel, Keith Busch, Jens Axboe, Christoph Hellwig,
	Chaitanya Kulkarni, Hannes Reinecke, Chao Leng, Victor Gladkov

Reviewed-by: Sagi Grimberg <sagi@grimberg.me>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs
  2021-03-31 13:12 [PATCH] nvme: Export fast_io_fail_tmo to sysfs Daniel Wagner
  2021-03-31 18:01 ` Ewan D. Milne
  2021-03-31 19:36 ` Sagi Grimberg
@ 2021-03-31 19:54 ` Himanshu Madhani
  2021-03-31 20:34 ` Chaitanya Kulkarni
  3 siblings, 0 replies; 6+ messages in thread
From: Himanshu Madhani @ 2021-03-31 19:54 UTC (permalink / raw)
  To: Daniel Wagner
  Cc: linux-nvme, Linux Kernel Mailing List, Keith Busch, Jens Axboe,
	Christoph Hellwig, Sagi Grimberg, Chaitanya Kulkarni,
	Hannes Reinecke, Chao Leng, Victor Gladkov



> On Mar 31, 2021, at 8:12 AM, Daniel Wagner <dwagner@suse.de> wrote:
> 
> Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device")
> introduced fast_io_fail_tmo but didn't export the value to sysfs. That
> means the value is hard coded during compile time. Export the timeout
> value to user space via sysfs to allow runtime configuration.
> 
> Cc: Victor Gladkov <Victor.Gladkov@kioxia.com>
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
> 
> This patch is against nvme-5.13
> 
> BTW, checkpatch complains with
> 
>  WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not preferred. Consider using octal permissions '0644'.
> 
> Is this something we want to adapt to?
> 
> drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
> 
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 40215a0246e4..c8de0e37c7d9 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3696,6 +3696,36 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev,
> static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
> 	nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store);
> 
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> +	if (ctrl->opts->fast_io_fail_tmo == -1)
> +		return sprintf(buf, "off\n");
> +	return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);
> +}
> +
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf, size_t count)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	struct nvmf_ctrl_options *opts = ctrl->opts;
> +	int fast_io_fail_tmo, err;
> +
> +	err = kstrtoint(buf, 10, &fast_io_fail_tmo);
> +	if (err)
> +		return -EINVAL;
> +
> +	else if (fast_io_fail_tmo < 0)
> +		opts->fast_io_fail_tmo = -1;
> +	else
> +		opts->fast_io_fail_tmo = fast_io_fail_tmo;
> +	return count;
> +}
> +static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
> +	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
> +
> static struct attribute *nvme_dev_attrs[] = {
> 	&dev_attr_reset_controller.attr,
> 	&dev_attr_rescan_controller.attr,
> @@ -3715,6 +3745,7 @@ static struct attribute *nvme_dev_attrs[] = {
> 	&dev_attr_hostid.attr,
> 	&dev_attr_ctrl_loss_tmo.attr,
> 	&dev_attr_reconnect_delay.attr,
> +	&dev_attr_fast_io_fail_tmo.attr,
> 	NULL
> };
> 
> -- 
> 2.29.2
> 


Reviewed-by: Himanshu Madhani <himanshu.madhaani@oracle.com>

--
Himanshu Madhani	 Oracle Linux Engineering


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs
  2021-03-31 13:12 [PATCH] nvme: Export fast_io_fail_tmo to sysfs Daniel Wagner
                   ` (2 preceding siblings ...)
  2021-03-31 19:54 ` Himanshu Madhani
@ 2021-03-31 20:34 ` Chaitanya Kulkarni
  2021-04-01  7:35   ` Daniel Wagner
  3 siblings, 1 reply; 6+ messages in thread
From: Chaitanya Kulkarni @ 2021-03-31 20:34 UTC (permalink / raw)
  To: Daniel Wagner
  Cc: linux-nvme, linux-kernel, Keith Busch, Jens Axboe,
	Christoph Hellwig, Sagi Grimberg, Hannes Reinecke, Chao Leng,
	Victor Gladkov

Daniel,

On 3/31/21 06:12, Daniel Wagner wrote:
> Commit 8c4dfea97f15 ("nvme-fabrics: reject I/O to offline device")
> introduced fast_io_fail_tmo but didn't export the value to sysfs. That
> means the value is hard coded during compile time. Export the timeout
> value to user space via sysfs to allow runtime configuration.
>
> Cc: Victor Gladkov <Victor.Gladkov@kioxia.com>
> Signed-off-by: Daniel Wagner <dwagner@suse.de>
> ---
>
> This patch is against nvme-5.13
>
> BTW, checkpatch complains with
>
>   WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not preferred. Consider using octal permissions '0644'.

For now keep the current style.

>
> Is this something we want to adapt to?
>
>  drivers/nvme/host/core.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
>
> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 40215a0246e4..c8de0e37c7d9 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -3696,6 +3696,36 @@ static ssize_t nvme_ctrl_reconnect_delay_store(struct device *dev,
>  static DEVICE_ATTR(reconnect_delay, S_IRUGO | S_IWUSR,
>  	nvme_ctrl_reconnect_delay_show, nvme_ctrl_reconnect_delay_store);
>  
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
> +		struct device_attribute *attr, char *buf)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +
> +	if (ctrl->opts->fast_io_fail_tmo == -1)
> +		return sprintf(buf, "off\n");
> +	return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);

do we need snprintf() for 2nd ?

> +}
> +
> +static ssize_t nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
> +		struct device_attribute *attr, const char *buf, size_t count)
> +{
> +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> +	struct nvmf_ctrl_options *opts = ctrl->opts;
> +	int fast_io_fail_tmo, err;
> +
> +	err = kstrtoint(buf, 10, &fast_io_fail_tmo);
> +	if (err)
> +		return -EINVAL;
> +

since you are returning an error, you can remove next else if, this also
removes the extra line after above return. Something like this on the top
of yours totally untested :-

diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index c8de0e37c7d9..afa0a6790b52 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -3717,7 +3717,7 @@ static ssize_t
nvme_ctrl_fast_io_fail_tmo_store(struct device *dev,
        if (err)
                return -EINVAL;
 
-       else if (fast_io_fail_tmo < 0)
+       if (fast_io_fail_tmo < 0)
                opts->fast_io_fail_tmo = -1;
        else
                opts->fast_io_fail_tmo = fast_io_fail_tmo;

> +	else if (fast_io_fail_tmo < 0)
> +		opts->fast_io_fail_tmo = -1;
> +	else
> +		opts->fast_io_fail_tmo = fast_io_fail_tmo;
> +	return count;
> +}
> +static DEVICE_ATTR(fast_io_fail_tmo, S_IRUGO | S_IWUSR,
> +	nvme_ctrl_fast_io_fail_tmo_show, nvme_ctrl_fast_io_fail_tmo_store);
> +
>  static struct attribute *nvme_dev_attrs[] = {
>  	&dev_attr_reset_controller.attr,
>  	&dev_attr_rescan_controller.attr,
> @@ -3715,6 +3745,7 @@ static struct attribute *nvme_dev_attrs[] = {
>  	&dev_attr_hostid.attr,
>  	&dev_attr_ctrl_loss_tmo.attr,
>  	&dev_attr_reconnect_delay.attr,
> +	&dev_attr_fast_io_fail_tmo.attr,
>  	NULL
>  };
>  
> -- 2.29.2



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] nvme: Export fast_io_fail_tmo to sysfs
  2021-03-31 20:34 ` Chaitanya Kulkarni
@ 2021-04-01  7:35   ` Daniel Wagner
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Wagner @ 2021-04-01  7:35 UTC (permalink / raw)
  To: Chaitanya Kulkarni
  Cc: linux-nvme, linux-kernel, Keith Busch, Jens Axboe,
	Christoph Hellwig, Sagi Grimberg, Hannes Reinecke, Chao Leng,
	Victor Gladkov

Hi Chaitanya,

On Wed, Mar 31, 2021 at 08:34:31PM +0000, Chaitanya Kulkarni wrote:
> >   WARNING: Symbolic permissions 'S_IRUGO | S_IWUSR' are not preferred. Consider using octal permissions '0644'.
> 
> For now keep the current style.

Okay, I thought so too. I am just wondering if a patch for changing all
the permission sets is acceptable. I prefer the the octal permissions ;)

> > +static ssize_t nvme_ctrl_fast_io_fail_tmo_show(struct device *dev,
> > +		struct device_attribute *attr, char *buf)
> > +{
> > +	struct nvme_ctrl *ctrl = dev_get_drvdata(dev);
> > +
> > +	if (ctrl->opts->fast_io_fail_tmo == -1)
> > +		return sprintf(buf, "off\n");
> > +	return sprintf(buf, "%d\n", ctrl->opts->fast_io_fail_tmo);
> 
> do we need snprintf() for 2nd ?

Sure thing can do. Also here I followed the existing style. The other
store functions tend to use sprintf().

> > +	err = kstrtoint(buf, 10, &fast_io_fail_tmo);
> > +	if (err)
> > +		return -EINVAL;
> > +
> 
> since you are returning an error, you can remove next else if, this also
> removes the extra line after above return. Something like this on the top
> of yours totally untested :-

Right, same here, followed the existing style. I prepare a patch which
addresses your comments for the existing code as well.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-04-01  7:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-31 13:12 [PATCH] nvme: Export fast_io_fail_tmo to sysfs Daniel Wagner
2021-03-31 18:01 ` Ewan D. Milne
2021-03-31 19:36 ` Sagi Grimberg
2021-03-31 19:54 ` Himanshu Madhani
2021-03-31 20:34 ` Chaitanya Kulkarni
2021-04-01  7:35   ` Daniel Wagner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).