Thu, May 23, 2019 at 07:57:03PM CEST, jakub.kicin...@netronome.com wrote: >On Thu, 23 May 2019 11:47:10 +0200, Jiri Pirko wrote: >> From: Jiri Pirko <j...@mellanox.com> >> >> Listen to status notifications coming from kernel during flashing and >> put them on stdout to inform user about the status. >> >> Signed-off-by: Jiri Pirko <j...@mellanox.com> > >> +static int cmd_dev_flash_status_cb(const struct nlmsghdr *nlh, void *data) >> +{ >> + struct cmd_dev_flash_status_ctx *ctx = data; >> + struct dl_opts *opts = &ctx->dl->opts; >> + struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); >> + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; >> + const char *component = NULL; >> + uint64_t done = 0, total = 0; >> + const char *msg = NULL; >> + const char *bus_name; >> + const char *dev_name; >> + >> + if (genl->cmd != DEVLINK_CMD_FLASH_UPDATE_STATUS && >> + genl->cmd != DEVLINK_CMD_FLASH_UPDATE_END) >> + return MNL_CB_STOP; >> + >> + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); >> + if (!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME]) >> + return MNL_CB_ERROR; >> + bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]); >> + dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]); >> + if (strcmp(bus_name, opts->bus_name) || >> + strcmp(dev_name, opts->dev_name)) >> + return MNL_CB_ERROR; >> + >> + if (genl->cmd == DEVLINK_CMD_FLASH_UPDATE_END && ctx->not_first) { >> + pr_out("\n"); >> + free(ctx->last_msg); >> + free(ctx->last_component); >> + ctx->received_end = 1; >> + return MNL_CB_STOP; >> + } > >> + pid = fork(); >> + if (pid == -1) { >> + close(pipe_r); >> + close(pipe_w); >> + return -errno; >> + } else if (!pid) { >> + /* In child, just execute the flash and pass returned >> + * value through pipe once it is done. >> + */ >> + close(pipe_r); >> + err = _mnlg_socket_send(dl->nlg, nlh); >> + write(pipe_w, &err, sizeof(err)); >> + close(pipe_w); >> + exit(0); >> + } >> + close(pipe_w); >> + >> + do { >> + err = cmd_dev_flash_fds_process(&ctx, nlg_ntf, pipe_r); >> + if (err) >> + goto out; >> + } while (!ctx.flash_done || !ctx.received_end); > >Won't this loop forever if driver never sends >DEVLINK_CMD_FLASH_UPDATE_END IOW doesn't implement status updates?
Hmm, right. Will look into this and fix.