linux-nvdimm.lists.01.org archive mirror
 help / color / mirror / Atom feed
* [ndctl PATCH] util: distinguish error codes for sysfs_{read, write}_attr()
@ 2017-06-09  5:27 Dan Williams
  2017-06-09 20:09 ` Linda Knippers
  0 siblings, 1 reply; 3+ messages in thread
From: Dan Williams @ 2017-06-09  5:27 UTC (permalink / raw)
  To: linux-nvdimm

There are occasions where it would be good to know the difference
between a sysfs attribute failing to be accessed because we could not
open versus could not read/write.

Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 util/sysfs.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/util/sysfs.c b/util/sysfs.c
index 31d1a898eba2..7905455890dc 100644
--- a/util/sysfs.c
+++ b/util/sysfs.c
@@ -34,13 +34,13 @@ int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf)
 
 	if (fd < 0) {
 		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
-		return -1;
+		return -ENOENT;
 	}
 	n = read(fd, buf, SYSFS_ATTR_SIZE);
 	close(fd);
 	if (n < 0 || n >= SYSFS_ATTR_SIZE) {
 		log_dbg(ctx, "failed to read %s: %s\n", path, strerror(errno));
-		return -1;
+		return -EIO;
 	}
 	buf[n] = 0;
 	if (n && buf[n-1] == '\n')
@@ -56,7 +56,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
 
 	if (fd < 0) {
 		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
-		return -1;
+		return -ENOENT;
 	}
 	n = write(fd, buf, len);
 	close(fd);
@@ -64,7 +64,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
 		if (!quiet)
 			log_dbg(ctx, "failed to write %s to %s: %s\n", buf, path,
 					strerror(errno));
-		return -1;
+		return -EIO;
 	}
 	return 0;
 }

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [ndctl PATCH] util: distinguish error codes for sysfs_{read, write}_attr()
  2017-06-09  5:27 [ndctl PATCH] util: distinguish error codes for sysfs_{read, write}_attr() Dan Williams
@ 2017-06-09 20:09 ` Linda Knippers
  2017-06-09 20:53   ` Dan Williams
  0 siblings, 1 reply; 3+ messages in thread
From: Linda Knippers @ 2017-06-09 20:09 UTC (permalink / raw)
  To: Dan Williams, linux-nvdimm

On 06/09/2017 01:27 AM, Dan Williams wrote:
> There are occasions where it would be good to know the difference
> between a sysfs attribute failing to be accessed because we could not
> open versus could not read/write.

I think it would be really helpful if you returned the actual errno value
rather than something hard coded.  The most common reason for not being able to write
something is that it requires running as root, in which case you should
get an EPERM. I think an accurate errno will help users figure out what's
gone wrong.

-- ljk

> 
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
>  util/sysfs.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/util/sysfs.c b/util/sysfs.c
> index 31d1a898eba2..7905455890dc 100644
> --- a/util/sysfs.c
> +++ b/util/sysfs.c
> @@ -34,13 +34,13 @@ int __sysfs_read_attr(struct log_ctx *ctx, const char *path, char *buf)
>  
>  	if (fd < 0) {
>  		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
> -		return -1;
> +		return -ENOENT;
>  	}
>  	n = read(fd, buf, SYSFS_ATTR_SIZE);
>  	close(fd);
>  	if (n < 0 || n >= SYSFS_ATTR_SIZE) {
>  		log_dbg(ctx, "failed to read %s: %s\n", path, strerror(errno));
> -		return -1;
> +		return -EIO;
>  	}
>  	buf[n] = 0;
>  	if (n && buf[n-1] == '\n')
> @@ -56,7 +56,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
>  
>  	if (fd < 0) {
>  		log_dbg(ctx, "failed to open %s: %s\n", path, strerror(errno));
> -		return -1;
> +		return -ENOENT;
>  	}
>  	n = write(fd, buf, len);
>  	close(fd);
> @@ -64,7 +64,7 @@ static int write_attr(struct log_ctx *ctx, const char *path,
>  		if (!quiet)
>  			log_dbg(ctx, "failed to write %s to %s: %s\n", buf, path,
>  					strerror(errno));
> -		return -1;
> +		return -EIO;
>  	}
>  	return 0;
>  }
> 
> _______________________________________________
> Linux-nvdimm mailing list
> Linux-nvdimm@lists.01.org
> https://lists.01.org/mailman/listinfo/linux-nvdimm
> 

_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

* Re: [ndctl PATCH] util: distinguish error codes for sysfs_{read, write}_attr()
  2017-06-09 20:09 ` Linda Knippers
@ 2017-06-09 20:53   ` Dan Williams
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Williams @ 2017-06-09 20:53 UTC (permalink / raw)
  To: Linda Knippers; +Cc: linux-nvdimm

On Fri, Jun 9, 2017 at 1:09 PM, Linda Knippers <linda.knippers@hpe.com> wrote:
> On 06/09/2017 01:27 AM, Dan Williams wrote:
>> There are occasions where it would be good to know the difference
>> between a sysfs attribute failing to be accessed because we could not
>> open versus could not read/write.
>
> I think it would be really helpful if you returned the actual errno value
> rather than something hard coded.  The most common reason for not being able to write
> something is that it requires running as root, in which case you should
> get an EPERM. I think an accurate errno will help users figure out what's
> gone wrong.

Will do.
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

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

end of thread, other threads:[~2017-06-09 20:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-09  5:27 [ndctl PATCH] util: distinguish error codes for sysfs_{read, write}_attr() Dan Williams
2017-06-09 20:09 ` Linda Knippers
2017-06-09 20:53   ` Dan Williams

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).