misc. cleanups
cover misc. cleanups
These patches are motivated by warnings from the clang static analyzer. They don't fix bugs, and shouldn't result in any changes in behavior. The one exception is the fix for building tags tables.
-Jeff
[ndctl patch 1/4] util/abspath: cleanup prefix_filename [ndctl patch 2/4] fix building of tags tables
[ndctl patch 3/4] query_fw_finish_status: get rid of redundant [ndctl patch 4/4] load-keys: get rid of duplicate assignment
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH 1/4 util/abspath: cleanup prefix_filename
Static checkers complain about the unused assignment to pfx_len. The code can obviously be simplified.
--- util/abspath.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
util/abspath.c +1 -5
@@ -9,11 +9,7 @@ char *prefix_filename(const char *pfx, const char *arg)struct strbuf path =STRBUF_INIT ;size_t pfx_len = pfx ?strlen (pfx) :0 ; -if (!pfx_len) - ; -else if (is_absolute_path (arg)) - pfx_len =0 ; -else +if (pfx_len && !is_absolute_path (arg))strbuf_add (&path, pfx, pfx_len);strbuf_addstr (&path, arg);
Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 1/4] util/abspath: cleanup prefix_filename
Quoted 4 lines · Jeff Moyer
Static checkers complain about the unused assignment to
pfx_len. The code can obviously be simplified.Signed-off-by Jeff Moyer <[email protected]>
Quoted 26 lines
--- util/abspath.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)util/abspath.c +1
-5@@ -9,11 +9,7 @@ char *prefix_filename(const char *pfx, const char *arg)struct strbuf path =STRBUF_INIT ;size_t pfx_len = pfx ?strlen (pfx) :0 ; -if (!pfx_len) - ; -else if (is_absolute_path (arg)) - pfx_len =0 ; -else +if (pfx_len && !is_absolute_path (arg))strbuf_add (&path, pfx, pfx_len);strbuf_addstr (&path, arg);Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH 2/4 fix building of tags tables
In reply to Jeff MoyerMake <tags-variant> currently fails with:
make[1]: *** No rule to make target 'libndctl.h', needed by 'tags-am'. Stop.
The path to libndctl.h is wrong in ndctl/lib/Makefile.am. Fix it.
--- ndctl/lib/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
ndctl/lib/Makefile.am +1 -1
@@ -7,7 +7,7 @@ pkginclude_HEADERS = ../libndctl.h ../ndctl.h lib_LTLIBRARIES = libndctl.la libndctl_la_SOURCES =\ - libndctl.h \ + ../libndctl.h \ private.h \ ../../util/log.c \ ../../util/log.h \
Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 2/4] fix building of tags tables
Quoted 7 lines · Jeff Moyer
Make <tags-variant> currently fails with:
make[1]: *** No rule to make target '
libndctl.h', needed by 'tags-am'. Stop.The path to
libndctl.his wrong in ndctl/lib/Makefile.am. Fix it.Signed-off-by Jeff Moyer <[email protected]>
Quoted 22 lines
--- ndctl/lib/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)ndctl/lib/Makefile.am +1
-1@@ -7,7 +7,7 @@ pkginclude_HEADERS = ../libndctl.h ../ndctl.h lib_LTLIBRARIES = libndctl.la libndctl_la_SOURCES =\ - libndctl.h \ + ../libndctl.h \ private.h \ ../../util/log.c \ ../../util/log.h \Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH 3/4 query_fw_finish_status: get rid of redundant variable
In reply to Jeff MoyerThe 'done' variable only adds confusion.
--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)
ndctl/dimm.c +1 -6
@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;
@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;break ;case FW_EBUSY :
@@ -753,7 +751,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));case FW_EINVAL_CTX :case FW_ESEQUENCE : - done = true; rc = -ENXIO ; goto out;case FW_ENORES :
@@ -761,17 +758,15 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,"Firmware update sequence timed out: %s\n" , ndctl_dimm_get_devname(dimm)); rc = -ETIMEDOUT ; - done = true; goto out;default :fprintf (stderr,"Unknown update status: %#x on DIMM %s\n" , status,ndctl_dimm_get_devname (dimm)); rc = -EINVAL ; - done = true; goto out; } - }while (!done); + }while (true); out:ndctl_cmd_unref (cmd);
Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 20 lines · Jeff Moyer
The 'done' variable only adds confusion.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)ndctl/dimm.c +0
-1@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 718
Quoted 5 lines
ndctl/dimm.c +0
-1@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;
Do we need "goto out" here?
Quoted 16 lines
ndctl/dimm.c +0
-2break ;case FW_EBUSY :@@ -753,7 +751,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));case FW_EINVAL_CTX :case FW_ESEQUENCE : - done = true; rc = -ENXIO ; goto out;case FW_ENORES :@@ -761,17 +758,15 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,"Firmware update sequence timed out: %s\n" , ndctl_dimm_get_devname(dimm)); rc = -ETIMEDOUT ; - done = true; goto out;
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 769
Quoted 10 lines
ndctl/dimm.c +1
-2default :fprintf (stderr,"Unknown update status: %#x on DIMM %s\n" , status,ndctl_dimm_get_devname (dimm)); rc = -EINVAL ; - done = true; goto out; } - }while (!done); + }while (true);
I'm not a fan of "while (true)". But I'm not the maintainer. The Logic seems fine otherwise.
Ira
Quoted 8 lines
ndctl/dimm.c +0
-0out:ndctl_cmd_unref (cmd);Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 20 lines · Ira Weiny
Quoted 19 lines · Jeff Moyer
The 'done' variable only adds confusion.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)ndctl/dimm.c +0
-1@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;
Quoted 8 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 718
Quoted 6 lines
ndctl/dimm.c +0
-1@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;Do we need "goto out" here?
Yes, I missed that one. Thanks.
Quoted 21 lines
Quoted 21 lines
ndctl/dimm.c +0
-2break ;case FW_EBUSY :@@ -753,7 +751,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));case FW_EINVAL_CTX :case FW_ESEQUENCE : - done = true; rc = -ENXIO ; goto out;case FW_ENORES :@@ -761,17 +758,15 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,"Firmware update sequence timed out: %s\n" , ndctl_dimm_get_devname(dimm)); rc = -ETIMEDOUT ; - done = true; goto out;default :fprintf (stderr,"Unknown update status: %#x on DIMM %s\n" , status,ndctl_dimm_get_devname (dimm)); rc = -EINVAL ;
Quoted 8 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 769
Quoted 5 lines
ndctl/dimm.c +1
-2- done = true; goto out; } - }while (!done); + }while (true);I'm not a fan of "while (true)". But I'm not the maintainer. The Logic seems fine otherwise.
The way things stand today is a mashup of goto vs. break. I'll follow-up with fixed up patch next week if there is consensus on the change. If you have a suggestion for a better way, that's welcome as well.
Thanks for looking, Ira!
-Jeff
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 13 lines · Jeff Moyer
Quoted 10 lines · Ira Weiny
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 769
Quoted 6 lines · Jeff Moyer
The 'done' variable only adds confusion.
ndctl/dimm.c +1
-1goto out; } - }while (!done); + }while (true);I'm not a fan of "while (true)". But I'm not the maintainer. The Logic seems fine otherwise.
Quoted 4 lines
The way things stand today is a mashup of goto vs. break. I'll follow-up with fixed up patch next week if there is consensus on the change. If you have a suggestion for a better way, that's welcome as well.
Yea that is the reason I did not object strongly. I don't have a good idea of how to clean the loop up without a pretty big refactoring. Which I'm not prepared to do. :-/ So if Vishal is ok with it, I am.
Ira
Quoted 4 lines
Thanks for looking, Ira!
-Jeff
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Verma, Vishal L
maintainerRe: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 14 lines · Ira Weiny
Quoted 13 lines · Jeff Moyer
Quoted 10 lines · Ira Weiny
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 769
Quoted 6 lines · Jeff Moyer
The 'done' variable only adds confusion.
ndctl/dimm.c +1
-1goto out; } - }while (!done); + }while (true);I'm not a fan of "while (true)". But I'm not the maintainer. The Logic seems fine otherwise.
Quoted 8 lines
Quoted 4 lines
The way things stand today is a mashup of goto vs. break. I'll follow-up with fixed up patch next week if there is consensus on the change. If you have a suggestion for a better way, that's welcome as well.
Yea that is the reason I did not object strongly. I don't have a good idea of how to clean the loop up without a pretty big refactoring. Which I'm not prepared to do. :-/ So if Vishal is ok with it, I am.
I looked into this - and I agree that while (true) isn't the greatest. I think we can refactor it to loop off the timeout value, and that keeps the loop always bounded. For other cases we break out as usual.
For now, we can go with the simpler fixup, and revisit the bigger refactoring later.
Thanks,
-Vishal
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Verma, Vishal L
maintainerRe: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
In reply to Jeff MoyerQuoted 30 lines · Jeff Moyer
Quoted 20 lines · Ira Weiny
Quoted 19 lines · Jeff Moyer
The 'done' variable only adds confusion.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)ndctl/dimm.c +0
-1@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;Quoted 8 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 718
Quoted 6 lines
ndctl/dimm.c +0
-1@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;Do we need "goto out" here?
Quoted 1 line
Yes, I missed that one. Thanks.
This actually looks fine, since there is a 'break' down below.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
ndctl/dimm.c +0
-0break ;case FW_EBUSY :
[..]
Quoted 11 lines
Quoted 5 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 769
Quoted 2 lines
ndctl/dimm.c +1
-1- }while (!done); + }while (true);I'm not a fan of "while (true)". But I'm not the maintainer. The Logic seems fine otherwise.
The way things stand today is a mashup of goto vs. break. I'll follow-up with fixed up patch next week if there is consensus on the change. If you have a suggestion for a better way, that's welcome as well.
I've applied this as is for v67, we can look at a refactoring for the while (true) later.
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Verma, Vishal L
maintainerRe: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 31 lines · Vishal L
Quoted 30 lines · Jeff Moyer
Quoted 28 lines · Ira Weiny
Quoted 20 lines · Jeff Moyer
The 'done' variable only adds confusion.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)ndctl/dimm.c +0
-1@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 718
Quoted 5 lines
ndctl/dimm.c +0
-1@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;Do we need "goto out" here?
Quoted 6 lines
Quoted 1 line
Yes, I missed that one. Thanks.
This actually looks fine, since there is a 'break' down below.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ndctl/dimm.c +0
-0break ;case FW_EBUSY :
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Yes this bit definitely needs to be refactored :)
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 36 lines · Vishal Verma
Quoted 35 lines · Vishal L
Quoted 30 lines · Jeff Moyer
Quoted 20 lines · Ira Weiny
Quoted 19 lines · Jeff Moyer
The 'done' variable only adds confusion.
Signed-off-by Jeff Moyer <[email protected]>--- ndctl/dimm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-)ndctl/dimm.c +0
-1@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;Quoted 8 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 718
Quoted 6 lines
ndctl/dimm.c +0
-1@@ -716,7 +715,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, ndctl_dimm_get_devname(dimm));printf ("Firmware version %#lx.\n" , ver);printf ("Cold reboot to activate.\n" ); - done = true; rc =0 ;Do we need "goto out" here?
Quoted 1 line
Yes, I missed that one. Thanks.
This actually looks fine, since there is a 'break' down below.
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 720
Quoted 2 lines
ndctl/dimm.c +0
-0break ;case FW_EBUSY :(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
Ira
From 24511b6a9f1b5e5c9e36c70ef6a03da5100cf4c7 Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Fri, 25 Oct 2019 15:16:13 -0700
Subject: [PATCH] ndctl: Clean up loop logic in query_fw_finish_status
This gets rid of a redundant variable as originally pointed out by Jeff Moyer[1]
Also, while we are here change the printf's to fprintf(stderr, ...)
[1] https://patchwork.kernel.org/patch/11199557/
--- ndctl/dimm.c | 142 +++++++++++++++++++++++++-------------------------- 1 file changed, 70 insertions(+), 72 deletions(-)
ndctl/dimm.c +70 -72
@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;
@@ -692,88 +691,87 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, rc =clock_gettime (CLOCK_MONOTONIC , &before);if (rc <0 ) - goto out; + goto unref; now.tv_nsec = fw->query_interval /1000 ; now.tv_sec =0 ; -do { - rc =ndctl_cmd_submit (cmd); -if (rc <0 ) -break ; +again: + rc =ndctl_cmd_submit (cmd); +if (rc <0 ) + goto unref; - status =ndctl_cmd_fw_xlat_firmware_status (cmd); -switch (status) { -case FW_SUCCESS : - ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); -if (ver ==0 ) { -fprintf (stderr,"No firmware updated.\n" ); - rc = -ENXIO ; - goto out; - } + status =ndctl_cmd_fw_xlat_firmware_status (cmd); +if (status ==FW_EBUSY ) { +/* Still on going, continue */ + rc =clock_gettime (CLOCK_MONOTONIC , &after); +if (rc <0 ) { + rc = -errno; + goto unref; + } -printf ("Image updated successfully to DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -printf ("Firmware version %#lx.\n" , ver); -printf ("Cold reboot to activate.\n" ); - done = true; - rc =0 ; -break ; -case FW_EBUSY : -/* Still on going, continue */ - rc =clock_gettime (CLOCK_MONOTONIC , &after); -if (rc <0 ) { - rc = -errno; - goto out; - } +/* +* If we expire max query time, +* we timed out +*/ +if (after.tv_sec - before.tv_sec > + fw->max_query /1000000 ) { + rc = -ETIMEDOUT ; + goto unref; + } -/* -* If we expire max query time, -* we timed out -*/ -if (after.tv_sec - before.tv_sec > - fw->max_query /1000000 ) { - rc = -ETIMEDOUT ; - goto out; - } +/* +* Sleep the interval dictated by firmware +* before query again. +*/ + rc =nanosleep (&now,NULL ); +if (rc <0 ) { + rc = -errno; + goto unref; + } + goto again; + } -/* -* Sleep the interval dictated by firmware -* before query again. -*/ - rc =nanosleep (&now,NULL ); -if (rc <0 ) { - rc = -errno; - goto out; - } -break ; -case FW_EBADFW : -fprintf (stderr, -"Firmware failed to verify by DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -case FW_EINVAL_CTX : -case FW_ESEQUENCE : - done = true; +/* We are done determine error code */ +switch (status) { +case FW_SUCCESS : + ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); +if (ver ==0 ) { +fprintf (stderr,"No firmware updated.\n" ); rc = -ENXIO ; - goto out; -case FW_ENORES : -fprintf (stderr, -"Firmware update sequence timed out: %s\n" , -ndctl_dimm_get_devname (dimm)); - rc = -ETIMEDOUT ; - done = true; - goto out; -default : -fprintf (stderr, -"Unknown update status: %#x on DIMM %s\n" , - status,ndctl_dimm_get_devname (dimm)); - rc = -EINVAL ; - done = true; - goto out; + goto unref; } - }while (!done); -out: +fprintf (stderr,"Image updated successfully to DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +fprintf (stderr,"Firmware version %#lx.\n" , ver); +fprintf (stderr,"Cold reboot to activate.\n" ); + rc =0 ; +break ; +case FW_EBADFW : +fprintf (stderr, +"Firmware failed to verify by DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +/* FALLTHROUGH */ +case FW_EINVAL_CTX : +case FW_ESEQUENCE : + rc = -ENXIO ; +break ; +case FW_ENORES : +fprintf (stderr, +"Firmware update sequence timed out: %s\n" , +ndctl_dimm_get_devname (dimm)); + rc = -ETIMEDOUT ; +break ; +default : +fprintf (stderr, +"Unknown update status: %#x on DIMM %s\n" , + status,ndctl_dimm_get_devname (dimm)); + rc = -EINVAL ; +break ; + } + +unref:ndctl_cmd_unref (cmd);return rc; }
Signature · 4 lines
2.20.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Verma, Vishal L
maintainerRe: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 3 lines · Ira Weiny
How about this patch instead? Untested.
Ira
Not a big deal, but just a quick note - if you include a scissors line here, I can easily apply it via git am --scissors
--8<--
Otherwise this looks good in principle.
I've already got Jeff's original (less intrusive) patch queued for v67 - maybe we can rebase this to be its own refactoring patch, and get some testing etc. for 68?
Quoted 180 lines
From
24511b6a9f1b5e5c9e36c70ef6a03da5100cf4c7Mon Sep 17 00:00:00 2001
From: Ira Weiny <[email protected]>
Date: Fri, 25 Oct 2019 15:16:13 -0700
Subject: [PATCH] ndctl: Clean up loop logic inquery_fw_finish_statusThis gets rid of a redundant variable as originally pointed out by Jeff Moyer[1]
Also, while we are here change the printf's to
fprintf(stderr, ...)[1] https://patchwork.kernel.org/patch/11199557/
Suggested-by Jeff Moyer <[email protected]>Signed-off-by Ira Weiny <[email protected]>--- ndctl/dimm.c | 142 +++++++++++++++++++++++++-------------------------- 1 file changed, 70 insertions(+), 72 deletions(-)ndctl/dimm.c +63
-72@@ -682,7 +682,6 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false;struct timespec now, before, after;uint64_t ver;@@ -692,88 +691,87 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm, rc =clock_gettime (CLOCK_MONOTONIC , &before);if (rc <0 ) - goto out; + goto unref; now.tv_nsec = fw->query_interval /1000 ; now.tv_sec =0 ; -do { - rc =ndctl_cmd_submit (cmd); -if (rc <0 ) -break ; +again: + rc =ndctl_cmd_submit (cmd); +if (rc <0 ) + goto unref; - status =ndctl_cmd_fw_xlat_firmware_status (cmd); -switch (status) { -case FW_SUCCESS : - ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); -if (ver ==0 ) { -fprintf (stderr,"No firmware updated.\n" ); - rc = -ENXIO ; - goto out; - } + status =ndctl_cmd_fw_xlat_firmware_status (cmd); +if (status ==FW_EBUSY ) { +/* Still on going, continue */ + rc =clock_gettime (CLOCK_MONOTONIC , &after); +if (rc <0 ) { + rc = -errno; + goto unref; + } -printf ("Image updated successfully to DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -printf ("Firmware version %#lx.\n" , ver); -printf ("Cold reboot to activate.\n" ); - done = true; - rc =0 ; -break ; -case FW_EBUSY : -/* Still on going, continue */ - rc =clock_gettime (CLOCK_MONOTONIC , &after); -if (rc <0 ) { - rc = -errno; - goto out; - } +/* +* If we expire max query time, +* we timed out +*/ +if (after.tv_sec - before.tv_sec > + fw->max_query /1000000 ) { + rc = -ETIMEDOUT ; + goto unref; + } -/* -* If we expire max query time, -* we timed out -*/ -if (after.tv_sec - before.tv_sec > - fw->max_query /1000000 ) { - rc = -ETIMEDOUT ; - goto out; - } +/* +* Sleep the interval dictated by firmware +* before query again. +*/ + rc =nanosleep (&now,NULL ); +if (rc <0 ) { + rc = -errno; + goto unref; + } + goto again; + } -/* -* Sleep the interval dictated by firmware -* before query again. -*/ - rc =nanosleep (&now,NULL ); -if (rc <0 ) { - rc = -errno; - goto out; - } -break ; -case FW_EBADFW : -fprintf (stderr, -"Firmware failed to verify by DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -case FW_EINVAL_CTX : -case FW_ESEQUENCE : - done = true; +/* We are done determine error code */ +switch (status) { +case FW_SUCCESS : + ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); +if (ver ==0 ) { +fprintf (stderr,"No firmware updated.\n" ); rc = -ENXIO ; - goto out; -case FW_ENORES : -fprintf (stderr, -"Firmware update sequence timed out: %s\n" , -ndctl_dimm_get_devname (dimm)); - rc = -ETIMEDOUT ; - done = true; - goto out; -default : -fprintf (stderr, -"Unknown update status: %#x on DIMM %s\n" , - status,ndctl_dimm_get_devname (dimm)); - rc = -EINVAL ; - done = true; - goto out; + goto unref; } - }while (!done); -out: +fprintf (stderr,"Image updated successfully to DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +fprintf (stderr,"Firmware version %#lx.\n" , ver); +fprintf (stderr,"Cold reboot to activate.\n" ); + rc =0 ; +break ; +case FW_EBADFW : +fprintf (stderr, +"Firmware failed to verify by DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +/* FALLTHROUGH */ +case FW_EINVAL_CTX : +case FW_ESEQUENCE : + rc = -ENXIO ; +break ; +case FW_ENORES : +fprintf (stderr, +"Firmware update sequence timed out: %s\n" , +ndctl_dimm_get_devname (dimm)); + rc = -ETIMEDOUT ; +break ; +default : + fprintf(stderr,
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 777
Quoted 10 lines
ndctl/dimm.c +7
-0+"Unknown update status: %#x on DIMM %s\n" , + status, ndctl_dimm_get_devname(dimm)); + rc = -EINVAL ; +break ; + } + +unref:ndctl_cmd_unref (cmd);return rc; }
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
In reply to Ira WeinyQuoted 6 lines · Ira Weiny
Quoted 4 lines
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
I'm not a fan of the looping with gotos. I think separating out the waiting for busy to its own function would make this more clear. Looking more closely, there are other issues. The timeout code looks at the seconds, but ignores the fractions, so you could be off by almost an entire second, there. It also doens't retry the sleep if interrupted. Finally, I find the variables names to be highly confusing.
I've decided not to fix those last two bugs just yet, but here's a patch that shows the dirction I think it should go. Compile-tested only for now. Let me know what you think.
Ira, I used the same base as you. If you updated ndctl, you'll have to revert 9e0391e057b36 to apply this patch.
Cheers,
Jeff
ndctl/dimm.c +81 -79
@@ -674,6 +674,41 @@ out:return rc; } +static void wait_for_cmd_completion (struct ndctl_cmd *cmd,struct fw_info *fw, +struct timespec *start) +{ +enum ND_FW_STATUS status; +struct timespec sleeptime, now; +int rc; + + sleeptime.tv_nsec = fw->query_interval /1000 ; + sleeptime.tv_sec =0 ; + +while ((status =ndctl_cmd_fw_xlat_firmware_status (cmd)) ==FW_EBUSY ) { + + rc =clock_gettime (CLOCK_MONOTONIC , &now); +if (rc <0 ) +break ; + +/* +* If we expire max query time, we timed out +*/ +if (now.tv_sec - start->tv_sec > fw->max_query /1000000 ) +break ; + +/* +* Sleep the interval dictated by firmware before +* query again. +*/ + rc =nanosleep (&sleeptime,NULL ); +if (rc <0 ) +break ; + + } + +return ; +} +static int query_fw_finish_status (struct ndctl_dimm *dimm,struct action_context *actx) {
@@ -682,98 +717,65 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false; -struct timespec now, before, after; +struct timespec start;uint64_t ver; cmd =ndctl_dimm_cmd_new_fw_finish_query (uctx->start);if (!cmd)return -ENXIO ; - rc =clock_gettime (CLOCK_MONOTONIC , &before); + rc =clock_gettime (CLOCK_MONOTONIC , &start);if (rc <0 ) - goto out; - - now.tv_nsec = fw->query_interval /1000 ; - now.tv_sec =0 ; - -do { - rc =ndctl_cmd_submit (cmd); -if (rc <0 ) -break ; + goto unref; - status =ndctl_cmd_fw_xlat_firmware_status (cmd); -switch (status) { -case FW_SUCCESS : - ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); -if (ver ==0 ) { -fprintf (stderr,"No firmware updated.\n" ); - rc = -ENXIO ; - goto out; - } - -printf ("Image updated successfully to DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -printf ("Firmware version %#lx.\n" , ver); -printf ("Cold reboot to activate.\n" ); - done = true; - rc =0 ; -break ; -case FW_EBUSY : -/* Still on going, continue */ - rc =clock_gettime (CLOCK_MONOTONIC , &after); -if (rc <0 ) { - rc = -errno; - goto out; - } + rc =ndctl_cmd_submit (cmd); +if (rc <0 ) + goto unref; -/* -* If we expire max query time, -* we timed out -*/ -if (after.tv_sec - before.tv_sec > - fw->max_query /1000000 ) { - rc = -ETIMEDOUT ; - goto out; - } +wait_for_cmd_completion (cmd, fw, &start); -/* -* Sleep the interval dictated by firmware -* before query again. -*/ - rc =nanosleep (&now,NULL ); -if (rc <0 ) { - rc = -errno; - goto out; - } -break ; -case FW_EBADFW : -fprintf (stderr, -"Firmware failed to verify by DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -case FW_EINVAL_CTX : -case FW_ESEQUENCE : - done = true; +/* We are done determine error code */ + status =ndctl_cmd_fw_xlat_firmware_status (cmd); +switch (status) { +case FW_SUCCESS : + ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); +if (ver ==0 ) { +fprintf (stderr,"No firmware updated.\n" ); rc = -ENXIO ; - goto out; -case FW_ENORES : -fprintf (stderr, -"Firmware update sequence timed out: %s\n" , -ndctl_dimm_get_devname (dimm)); - rc = -ETIMEDOUT ; - done = true; - goto out; -default : -fprintf (stderr, -"Unknown update status: %#x on DIMM %s\n" , - status,ndctl_dimm_get_devname (dimm)); - rc = -EINVAL ; - done = true; - goto out; +break ; } - }while (!done); -out: +fprintf (stderr,"Image updated successfully to DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +fprintf (stderr,"Firmware version %#lx.\n" , ver); +fprintf (stderr,"Cold reboot to activate.\n" ); + rc =0 ; +break ; +case FW_EBADFW : +fprintf (stderr, +"Firmware failed to verify by DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +/* FALLTHROUGH */ +case FW_EINVAL_CTX : +case FW_ESEQUENCE : + rc = -ENXIO ; +break ; +case FW_EBUSY : +case FW_ENORES : +fprintf (stderr, +"Firmware update sequence timed out: %s\n" , +ndctl_dimm_get_devname (dimm)); + rc = -ETIMEDOUT ; +break ; +default : +fprintf (stderr, +"Unknown update status: %#x on DIMM %s\n" , + status,ndctl_dimm_get_devname (dimm)); + rc = -EINVAL ; +break ; + } + +unref:ndctl_cmd_unref (cmd);return rc; }
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 10 lines · Jeff Moyer
Quoted 6 lines · Ira Weiny
Quoted 4 lines
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
I'm not a fan of the looping with gotos.
Me either... But... the logic here is not the same.
Quoted 6 lines
I think separating out the
waiting for busy to its own function would make this more clear. Looking more closely, there are other issues. The timeout code looks at the seconds, but ignores the fractions, so you could be off by almost an entire second, there.
For this operation that is probably not a big deal. We should be waiting much longer than the operation should take anyway.
Quoted 2 lines
It also doens't retry the sleep if interrupted.
This could be an issue.
Quoted 5 lines
Finally, I find the variables names to be highly confusing.
I've decided not to fix those last two bugs just yet, but here's a patch that shows the dirction I think it should go. Compile-tested only for now. Let me know what you think.
I thought about doing something similar but to make the logic the same it becomes a bit awkward.
Quoted 34 lines
Ira, I used the same base as you. If you updated ndctl, you'll have to revert
9e0391e057b36to apply this patch.Cheers,
Jeffndctl/dimm.c +19
-0@@ -674,6 +674,41 @@ out:return rc; } +static void wait_for_cmd_completion (struct ndctl_cmd *cmd,struct fw_info *fw, +struct timespec *start) +{ +enum ND_FW_STATUS status; +struct timespec sleeptime, now; +int rc; + + sleeptime.tv_nsec = fw->query_interval /1000 ; + sleeptime.tv_sec =0 ; + +while ((status =ndctl_cmd_fw_xlat_firmware_status (cmd)) ==FW_EBUSY ) { + + rc =clock_gettime (CLOCK_MONOTONIC , &now); +if (rc <0 ) +break ; + +/* +* If we expire max query time, we timed out +*/
ndctl/dimm.c out: · line 705
Quoted 10 lines
ndctl/dimm.c +10
-0+if (now.tv_sec - start->tv_sec > fw->max_query /1000000 ) +break ; + +/* +* Sleep the interval dictated by firmware before +* query again. +*/ + rc =nanosleep (&sleeptime,NULL ); +if (rc <0 ) +break ;
You need ndctl_cmd_submit() here to be the same logic.
Quoted 64 lines
ndctl/dimm.c +12
-36+ + } + +return ; +} +static int query_fw_finish_status (struct ndctl_dimm *dimm,struct action_context *actx) {@@ -682,98 +717,65 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -bool done = false; -struct timespec now, before, after; +struct timespec start;uint64_t ver; cmd =ndctl_dimm_cmd_new_fw_finish_query (uctx->start);if (!cmd)return -ENXIO ; - rc =clock_gettime (CLOCK_MONOTONIC , &before); + rc =clock_gettime (CLOCK_MONOTONIC , &start);if (rc <0 ) - goto out; - - now.tv_nsec = fw->query_interval /1000 ; - now.tv_sec =0 ; - - do { - rc = ndctl_cmd_submit(cmd); - if (rc < 0) - break; + goto unref; - status = ndctl_cmd_fw_xlat_firmware_status(cmd); - switch (status) { - case FW_SUCCESS: - ver = ndctl_cmd_fw_fquery_get_fw_rev(cmd); - if (ver == 0) { - fprintf(stderr, "No firmware updated.\n"); - rc = -ENXIO; - goto out; - } - - printf("Image updated successfully to DIMM %s.\n", - ndctl_dimm_get_devname(dimm)); - printf("Firmware version %#lx.\n", ver); - printf("Cold reboot to activate.\n"); - done = true; - rc = 0; - break; - case FW_EBUSY: - /* Still on going, continue */ - rc = clock_gettime(CLOCK_MONOTONIC, &after); - if (rc < 0) { - rc = -errno; - goto out; - } + rc =ndctl_cmd_submit (cmd); +if (rc <0 ) + goto unref;
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 735
Quoted 10 lines
ndctl/dimm.c +1
-9-/* -* If we expire max query time, -* we timed out -*/ -if (after.tv_sec - before.tv_sec > - fw->max_query /1000000 ) { - rc = -ETIMEDOUT ; - goto out; - } +wait_for_cmd_completion (cmd, fw, &start);
wait_for_cmd_completion() does not call ndctl_cmd_submit()
Now I find it odd that we need to resubmit the command but I assume the logic is correct. Therefore we need to go back and call ndctl_cmd_submit() again.
Or is this not required?
anyway that is why I went ahead and used the goto...
Ira
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 37 lines · Ira Weiny
Quoted 10 lines · Jeff Moyer
Quoted 6 lines · Ira Weiny
Quoted 4 lines
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
I'm not a fan of the looping with gotos.
Me either... But... the logic here is not the same.
Quoted 6 lines
I think separating out the
waiting for busy to its own function would make this more clear. Looking more closely, there are other issues. The timeout code looks at the seconds, but ignores the fractions, so you could be off by almost an entire second, there.For this operation that is probably not a big deal. We should be waiting much longer than the operation should take anyway.
Quoted 2 lines
It also doens't retry the sleep if interrupted.
This could be an issue.
Quoted 5 lines
Finally, I find the variables names to be highly confusing.
I've decided not to fix those last two bugs just yet, but here's a patch that shows the dirction I think it should go. Compile-tested only for now. Let me know what you think.
I thought about doing something similar but to make the logic the same it becomes a bit awkward.
[...]
Quoted 8 lines
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 735
Quoted 1 line
ndctl/dimm.c +1
-0+wait_for_cmd_completion (cmd, fw, &start);
wait_for_cmd_completion()does not callndctl_cmd_submit()Now I find it odd that we need to resubmit the command but I assume the logic is correct. Therefore we need to go back and call
ndctl_cmd_submit()again.Or is this not required?
Ah. Stupid mistake. Yes, it definitely looks like the status query command needs to be resubmitted, and that's the whole point of the timeout between calls. You can't ask too often. ;-)
Quoted 1 line
anyway that is why I went ahead and used the goto...
I'll take another look. Thanks for pointing out that obvious thinko.
-Jeff
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
In reply to Ira WeinyQuoted 6 lines · Ira Weiny
Quoted 5 lines · Jeff Moyer
Quoted 3 lines · Ira Weiny
Quoted 3 lines
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
I'm not a fan of the looping with gotos.
Me either... But... the logic here is not the same.
How about this one, then? Again, compile-tested only. I'll run it through testing only if you like it better than your approach. If you like your appraoch better, I'll go ahead and review and test that.
Cheers,
Jeff
ndctl/dimm.c +84 -77
@@ -674,6 +674,52 @@ out:return rc; } +/* +* Wait for a command to complete, up to the firmware-specified timeout. +* Returns -errno on error. On success, which means either the command +* completed (sucessfully or with an error), or we timed out waiting for +* it, return 0. The caller needs to check the status on its own if this +* function returns 0. +*/ +static int query_fw_finish_status_timeout (struct ndctl_cmd *cmd, +struct fw_info *fw) +{ +enum ND_FW_STATUS status; +struct timespec sleeptime, start, now; +int rc; + + rc =clock_gettime (CLOCK_MONOTONIC , &start); +if (rc <0 ) +return rc; + + sleeptime.tv_nsec = fw->query_interval /1000 ; + sleeptime.tv_sec =0 ; + +while ((rc =ndctl_cmd_submit (cmd)) ==0 && + (status =ndctl_cmd_fw_xlat_firmware_status (cmd)) ==FW_EBUSY ) { + + rc =clock_gettime (CLOCK_MONOTONIC , &now); +if (rc <0 ) +break ; + +/* +* If we expire max query time, we timed out +*/ +if (now.tv_sec - start.tv_sec > fw->max_query /1000000 ) +break ; + +/* +* Sleep the interval dictated by firmware before +* query again. +*/ + rc =nanosleep (&sleeptime,NULL ); +if (rc <0 ) +break ; + } + +return rc; +} +static int query_fw_finish_status (struct ndctl_dimm *dimm,struct action_context *actx) {
@@ -682,94 +728,55 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,struct ndctl_cmd *cmd;int rc;enum ND_FW_STATUS status; -struct timespec now, before, after;uint64_t ver; cmd =ndctl_dimm_cmd_new_fw_finish_query (uctx->start);if (!cmd)return -ENXIO ; - rc =clock_gettime (CLOCK_MONOTONIC , &before); + rc =query_fw_finish_status_timeout (cmd, fw);if (rc <0 ) - goto out; - - now.tv_nsec = fw->query_interval /1000 ; - now.tv_sec =0 ; - -do { - rc =ndctl_cmd_submit (cmd); -if (rc <0 ) -break ; - - status =ndctl_cmd_fw_xlat_firmware_status (cmd); -switch (status) { -case FW_SUCCESS : - ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); -if (ver ==0 ) { -fprintf (stderr,"No firmware updated.\n" ); - rc = -ENXIO ; - goto out; - } - -printf ("Image updated successfully to DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -printf ("Firmware version %#lx.\n" , ver); -printf ("Cold reboot to activate.\n" ); - rc =0 ; - goto out; -break ; -case FW_EBUSY : -/* Still on going, continue */ - rc =clock_gettime (CLOCK_MONOTONIC , &after); -if (rc <0 ) { - rc = -errno; - goto out; - } - -/* -* If we expire max query time, -* we timed out -*/ -if (after.tv_sec - before.tv_sec > - fw->max_query /1000000 ) { - rc = -ETIMEDOUT ; - goto out; - } + goto unref; -/* -* Sleep the interval dictated by firmware -* before query again. -*/ - rc =nanosleep (&now,NULL ); -if (rc <0 ) { - rc = -errno; - goto out; - } -break ; -case FW_EBADFW : -fprintf (stderr, -"Firmware failed to verify by DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -case FW_EINVAL_CTX : -case FW_ESEQUENCE : + status =ndctl_cmd_fw_xlat_firmware_status (cmd); +switch (status) { +case FW_SUCCESS : + ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); +if (ver ==0 ) { +fprintf (stderr,"No firmware updated.\n" ); rc = -ENXIO ; - goto out; -case FW_ENORES : -fprintf (stderr, -"Firmware update sequence timed out: %s\n" , -ndctl_dimm_get_devname (dimm)); - rc = -ETIMEDOUT ; - goto out; -default : -fprintf (stderr, -"Unknown update status: %#x on DIMM %s\n" , - status,ndctl_dimm_get_devname (dimm)); - rc = -EINVAL ; - goto out; +break ; } - }while (true); -out: +printf ("Image updated successfully to DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +printf ("Firmware version %#lx.\n" , ver); +printf ("Cold reboot to activate.\n" ); +break ; +case FW_EBADFW : +fprintf (stderr, +"Firmware failed to verify by DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +case FW_EINVAL_CTX : +case FW_ESEQUENCE : + rc = -ENXIO ; +break ; +case FW_EBUSY : +case FW_ENORES : +fprintf (stderr, +"Firmware update sequence timed out: %s\n" , +ndctl_dimm_get_devname (dimm)); + rc = -ETIMEDOUT ; +break ; +default : +fprintf (stderr, +"Unknown update status: %#x on DIMM %s\n" , + status,ndctl_dimm_get_devname (dimm)); + rc = -EINVAL ; +break ; + } + +unref:ndctl_cmd_unref (cmd);return rc; }
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 3/4] query_fw_finish_status: get rid of redundant variable
Quoted 43 lines · Jeff Moyer
Quoted 6 lines · Ira Weiny
Quoted 5 lines · Jeff Moyer
Quoted 3 lines · Ira Weiny
Quoted 3 lines
(Watching the unit test run fall into an infinite loop..) Nope, the break is in the switch scope, the while loop needs the 'goto out'.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
Yes this bit definitely needs to be refactored :)
How about this patch instead? Untested.
I'm not a fan of the looping with gotos.
Me either... But... the logic here is not the same.
How about this one, then? Again, compile-tested only. I'll run it through testing only if you like it better than your approach. If you like your appraoch better, I'll go ahead and review and test that.
Cheers,
Jeffndctl/dimm.c +12
-0@@ -674,6 +674,52 @@ out:return rc; } +/* +* Wait for a command to complete, up to the firmware-specified timeout. +* Returns -errno on error. On success, which means either the command +* completed (sucessfully or with an error), or we timed out waiting for +* it, return 0. The caller needs to check the status on its own if this +* function returns 0. +*/ +static int query_fw_finish_status_timeout (struct ndctl_cmd *cmd, +struct fw_info *fw) +{ +enum ND_FW_STATUS status; +struct timespec sleeptime, start, now;
ndctl/dimm.c out: · line 698
Quoted 10 lines
ndctl/dimm.c +10
-0+int rc; + + rc =clock_gettime (CLOCK_MONOTONIC , &start); +if (rc <0 ) +return rc; + + sleeptime.tv_nsec = fw->query_interval /1000 ; + sleeptime.tv_sec =0 ; + + while ((rc = ndctl_cmd_submit(cmd)) == 0 &&
This needs to check for >= 0 because ndctl_cmd_submit() can return a positive value on success. See do_cmd()
ndctl/dimm.c out: · line 699
Quoted 1 line
ndctl/dimm.c +1
-0+ (status = ndctl_cmd_fw_xlat_firmware_status(cmd)) == FW_EBUSY) {
Why not return this status rather than having to query for it again?
While I'm not a fan of the goto either I think it does actually work ok.
Why don't we go with that patch for now and if you want to pull the "again" loop into a separate function which fixes the signal handling of nanosleep we can do that as a follow on.
But I think we need to fix the above and just return the status from this loop...
Something like:
static int query_fw_finish_status_timeout(struct ndctl_cmd *cmd,
struct fw_info *fw, enum ND_FW_STATUS *status)
{
...
}[snip]
Quoted 14 lines
ndctl/dimm.c +0
-14- status =ndctl_cmd_fw_xlat_firmware_status (cmd); -switch (status) { -case FW_SUCCESS : - ver =ndctl_cmd_fw_fquery_get_fw_rev (cmd); -if (ver ==0 ) { -fprintf (stderr,"No firmware updated.\n" ); - rc = -ENXIO ; - goto out; - } - -printf ("Image updated successfully to DIMM %s.\n" , -ndctl_dimm_get_devname (dimm)); -printf ("Firmware version %#lx.\n" , ver); -printf ("Cold reboot to activate.\n" );
[snip]
ndctl/dimm.c static int query_fw_finish_status(struct ndctl_dimm *dimm, · line 754
Quoted 8 lines
ndctl/dimm.c +4
-2} - }while (true); -out: +printf ("Image updated successfully to DIMM %s.\n" , +ndctl_dimm_get_devname (dimm)); +printf ("Firmware version %#lx.\n" , ver); +printf ("Cold reboot to activate.\n" );
Final NIT I changed these to fprintf() as well.
Ira
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
PATCH 4/4 load-keys: get rid of duplicate assignment
In reply to Jeff Moyer--- ndctl/load-keys.c | 1 - 1 file changed, 1 deletion(-)
ndctl/load-keys.c +0 -1
@@ -185,7 +185,6 @@ static int load_keys(struct loadkeys *lk_ctx, const char *keypath, rc =chdir (keypath);if (rc <0 ) { - rc = -errno;fprintf (stderr,"Change current work dir to %s failed: %s\n" , param.key_path,strerror (errno)); rc = -errno;
Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
Re: [ndctl patch 4/4] load-keys: get rid of duplicate assignment
Quoted 1 line · Jeff Moyer
Signed-off-by Jeff Moyer <[email protected]>
Quoted 21 lines
--- ndctl/load-keys.c | 1 - 1 file changed, 1 deletion(-)ndctl/load-keys.c +0
-1@@ -185,7 +185,6 @@ static int load_keys(struct loadkeys *lk_ctx, const char *keypath, rc =chdir (keypath);if (rc <0 ) { - rc = -errno;fprintf (stderr,"Change current work dir to %s failed: %s\n" , param.key_path,strerror (errno)); rc = -errno;Signature · 4 lines
2.19.1 _______________________________________________ Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]
_______________________________________________
Linux-nvdimm mailing list -- [email protected] To unsubscribe send an email to [email protected]