Replace the status messages at the end of 'ndctl update-firmware' with a
json representation of the dimm-firmware state.

Signed-off-by: Dan Williams <[email protected]>
---
 ndctl/dimm.c            |   23 ++++++++++++++++-------
 ndctl/firmware-update.h |    1 +
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/ndctl/dimm.c b/ndctl/dimm.c
index 5ecee033cd63..e02f5dfdb889 100644
--- a/ndctl/dimm.c
+++ b/ndctl/dimm.c
@@ -701,8 +701,10 @@ static int query_fw_finish_status(struct ndctl_dimm *dimm,
        struct update_context *uctx = &actx->update;
        struct fw_info *fw = &uctx->dimm_fw;
        struct timespec now, before, after;
+       struct json_object *jobj;
        enum ND_FW_STATUS status;
        struct ndctl_cmd *cmd;
+       unsigned long flags;
        uint64_t ver;
        int rc;
 
@@ -763,10 +765,12 @@ again:
                        goto unref;
                }
 
-               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");
+               flags = UTIL_JSON_FIRMWARE;
+               if (isatty(1))
+                       flags |= UTIL_JSON_HUMAN;
+               jobj = util_dimm_to_json(dimm, flags);
+               if (jobj)
+                       json_object_array_add(actx->jdimms, jobj);
                rc = 0;
                break;
        case FW_EBADFW:
@@ -1202,7 +1206,7 @@ static int dimm_action(int argc, const char **argv, 
struct ndctl_ctx *ctx,
                return -EINVAL;
        }
 
-       json = param.json || param.human;
+       json = param.json || param.human || action == action_update;
        if (action == action_read && json && (param.len || param.offset)) {
                fprintf(stderr, "--size and --offset are incompatible with 
--json\n");
                usage_with_options(u, options);
@@ -1308,8 +1312,13 @@ static int dimm_action(int argc, const char **argv, 
struct ndctl_ctx *ctx,
                        rc = action(single, &actx);
        }
 
-       if (actx.jdimms)
-               util_display_json_array(actx.f_out, actx.jdimms, 0);
+       if (actx.jdimms && json_object_array_length(actx.jdimms) > 0) {
+               unsigned long flags = 0;
+
+               if (actx.f_out == stdout && isatty(1))
+                       flags |= UTIL_JSON_HUMAN;
+               util_display_json_array(actx.f_out, actx.jdimms, flags);
+       }
 
        if (actx.f_out != stdout)
                fclose(actx.f_out);
diff --git a/ndctl/firmware-update.h b/ndctl/firmware-update.h
index a7576889f739..a4386d6089d2 100644
--- a/ndctl/firmware-update.h
+++ b/ndctl/firmware-update.h
@@ -40,6 +40,7 @@ struct update_context {
        size_t fw_size;
        struct fw_info dimm_fw;
        struct ndctl_cmd *start;
+       struct json_object *jdimms;
 };
 
 #endif
_______________________________________________
Linux-nvdimm mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to