On Mon, Oct 28, 2019 at 06:12:23PM -0400, Jeff Moyer wrote:
> Ira Weiny <ira.we...@intel.com> writes:
> 
> > On Mon, Oct 28, 2019 at 03:37:48PM -0400, Jeff Moyer wrote:
> >> Ira Weiny <ira.we...@intel.com> writes:
> >> 
> >> >> (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.
> 
> 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
> 
> diff --git a/ndctl/dimm.c b/ndctl/dimm.c
> index b1b84c2..63d4d4a 100644
> --- a/ndctl/dimm.c
> +++ b/ndctl/dimm.c
> @@ -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 &&

This needs to check for >= 0 because ndctl_cmd_submit() can return a positive
value on success.  See do_cmd()

> +            (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]

> -             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]

>               }
> -     } 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 -- linux-nvdimm@lists.01.org
To unsubscribe send an email to linux-nvdimm-le...@lists.01.org

Reply via email to