libndctl: set errno for routines that don't return an error status
Vishal Verma
maintainerPATCH 1/1 libndctl: set errno for routines that don't return an error status
For routines that return a UINT_MAX or UL{L}ONG_MAX, there isn't a way to get any information as to what went wrong. Set errno in such routines so that the callers can get some additional context about the error.
--- ndctl/lib/dimm.c | 8 +++-- ndctl/lib/hpe1.c | 79 +++++++++++++++++++++++++++++++++++++------- ndctl/lib/inject.c | 2 ++ ndctl/lib/intel.c | 45 +++++++++++++++++++++---- ndctl/lib/libndctl.c | 54 ++++++++++++++++++++++-------- ndctl/lib/msft.c | 27 ++++++++++++--- 6 files changed, 177 insertions(+), 38 deletions(-)
ndctl/lib/dimm.c +6 -2
@@ -565,17 +565,21 @@ NDCTL_EXPORT unsigned long ndctl_dimm_get_available_labels( {struct ndctl_ctx *ctx =ndctl_dimm_get_ctx (dimm);char *path = dimm->dimm_buf; -int len = dimm->buf_len; +int rc, len = dimm->buf_len;char buf[20 ];if (snprintf (path, len,"%s/available_slots" , dimm->dimm_path) >= len) {err (ctx,"%s: buffer too small!\n" ,ndctl_dimm_get_devname (dimm)); + errno =EOVERFLOW ;return ULONG_MAX ; } -if (sysfs_read_attr (ctx, path, buf) <0 ) + rc =sysfs_read_attr (ctx, path, buf); +if (rc <0 ) { + errno = -rc;return ULONG_MAX ; + }return strtoul (buf,NULL ,0 ); }
ndctl/lib/hpe1.c +67 -12
168 lines not on this page · raw message
ndctl/lib/inject.c +2 -0
@@ -498,6 +498,7 @@ NDCTL_EXPORT unsigned long long ndctl_bb_get_block(struct ndctl_bb *bb) {if (bb)return bb->block; + errno =EINVAL ;return ULLONG_MAX ; }
@@ -505,5 +506,6 @@ NDCTL_EXPORT unsigned long long ndctl_bb_get_count(struct ndctl_bb *bb) {if (bb)return bb->count; + errno =EINVAL ;return ULLONG_MAX ; }
ndctl/lib/intel.c +38 -7
94 lines not on this page · raw message
ndctl/lib/libndctl.c +41 -13
162 lines not on this page · raw message
ndctl/lib/msft.c +23 -4
@@ -77,8 +77,13 @@ static int msft_smart_valid(struct ndctl_cmd *cmd)static unsigned int msft_cmd_smart_get_flags (struct ndctl_cmd *cmd) { -if (msft_smart_valid (cmd) <0 ) +int rc; + + rc =msft_smart_valid (cmd); +if (rc <0 ) { + errno = -rc;return UINT_MAX ; + }/* below health data can be retrieved via MSFT _DSM function 11 */ return NDN_MSFT_SMART_HEALTH_VALID |
@@ -103,9 +108,13 @@ static unsigned int msft_cmd_smart_get_health(struct ndctl_cmd *cmd) {unsigned int health;unsigned int num; +int rc; -if (msft_smart_valid (cmd) <0 ) + rc =msft_smart_valid (cmd); +if (rc <0 ) { + errno = -rc;return UINT_MAX ; + } num =num_set_bit_health (CMD_MSFT_SMART (cmd)->health);if (num ==0 )
@@ -122,16 +131,26 @@ static unsigned int msft_cmd_smart_get_health(struct ndctl_cmd *cmd)static unsigned int msft_cmd_smart_get_media_temperature (struct ndctl_cmd *cmd) { -if (msft_smart_valid (cmd) <0 ) +int rc; + + rc =msft_smart_valid (cmd); +if (rc <0 ) { + errno = -rc;return UINT_MAX ; + }return CMD_MSFT_SMART (cmd)->temp *16 ; }static unsigned int msft_cmd_smart_get_life_used (struct ndctl_cmd *cmd) { -if (msft_smart_valid (cmd) <0 ) +int rc; + + rc =msft_smart_valid (cmd); +if (rc <0 ) { + errno = -rc;return UINT_MAX ; + }return 100 -CMD_MSFT_SMART (cmd)->nvm_lifetime; }
Signature · 6 lines
2.17.1 _______________________________________________ Linux-nvdimm mailing list [email protected] https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 5 lines · Vishal Verma
For routines that return a
UINT_MAXor UL{L}ONG_MAX, there isn't a way
to get any information as to what went wrong. Set errno in such routines
so that the callers can get some additional context about the error.
Looks ok, but why EOVERFLOW and not ENOMEM for the out of resource conditions?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 10 lines · Dan J
Quoted 6 lines · Vishal Verma
For routines that return a
UINT_MAXor UL{L}ONG_MAX, there isn't a way
to get any information as to what went wrong. Set errno in such routines
so that the callers can get some additional context about the error.Looks ok, but why EOVERFLOW and not ENOMEM for the out of resource conditions?
I debated between that and also ENOSPC, but nothing seemed like an exact fit for a buffer too small.. Mainly not ENOMEM because we aren't actually trying to allocate memory as a part of this?
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Quoted 10 lines · Vishal L
Quoted 9 lines · Dan J
Quoted 7 lines · Vishal Verma
For routines that return a
UINT_MAXor UL{L}ONG_MAX, there isn't a
way
to get any information as to what went wrong. Set errno in such routines
so that the callers can get some additional context about the error.
Quoted 7 lines
Quoted 2 lines
Looks ok, but why EOVERFLOW and not ENOMEM for the out of resource conditions?
I debated between that and also ENOSPC, but nothing seemed like an exact fit for a buffer too small.. Mainly not ENOMEM because we aren't
actually trying to allocate memory as a part of this?
That's true, but the effect is the same, couldn't get enough resource to complete the operation. I would expect EOVERFLOW for trying to store a 64-bit quantity in a 32-bit field.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm
Verma, Vishal L
maintainerQuoted 14 lines · Dan J
Quoted 13 lines · Vishal L
Quoted 11 lines · Dan J
Quoted 7 lines · Vishal Verma
For routines that return a
UINT_MAXor UL{L}ONG_MAX, there isn't a
way
to get any information as to what went wrong. Set errno in such routines
so that the callers can get some additional context about the error.Looks ok, but why EOVERFLOW and not ENOMEM for the out of resource conditions?
Quoted 9 lines
Quoted 4 lines
I debated between that and also ENOSPC, but nothing seemed like an exact fit for a buffer too small.. Mainly not ENOMEM because we aren't
actually trying to allocate memory as a part of this?That's true, but the effect is the same, couldn't get enough resource to complete the operation. I would expect EOVERFLOW for trying to store a 64-bit quantity in a 32-bit field.
Good point, I'll change to ENOMEM.
_______________________________________________
Linux-nvdimm mailing list
[email protected]
https://lists.01.org/mailman/listinfo/linux-nvdimm