Content-Type: multipart/mixed; boundary="===============4935683103029117527==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v3 2/3] accel-config: Print details of error at exit using new last_error API Date: Wed, 14 Jul 2021 13:17:46 -0400 Message-ID: <20210714171747.1089140-3-ramesh.thomas@intel.com> In-Reply-To: 20210714171747.1089140-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============4935683103029117527== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas On error exit, if cmd_status was set get the details of the error using new last_error APIs and print. Do this at a common place at exit and remove from other places to avoid duplication. Signed-off-by: Ramesh Thomas --- accfg/accel-config.c | 25 ++++++++++++++++++++++++- accfg/enable.c | 25 ++++--------------------- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/accfg/accel-config.c b/accfg/accel-config.c index d373f88..0840e0b 100644 --- a/accfg/accel-config.c +++ b/accfg/accel-config.c @@ -103,6 +103,7 @@ int main(int argc, const char **argv) struct accfg_ctx *ctx; struct kmod_ctx *kmod_ctx; struct kmod_module *mod; + unsigned int last_error; int rc; = /* Look for flags.. */ @@ -136,6 +137,29 @@ int main(int argc, const char **argv) = rc =3D main_handle_internal_command(argc, argv, ctx, commands, ARRAY_SIZE(commands)); + + last_error =3D accfg_ctx_get_last_error(ctx); + if (rc && last_error) { + struct accfg_device *d; + struct accfg_group *g; + struct accfg_wq *w; + struct accfg_engine *e; + + printf("Error[%#10x] ", last_error); + d =3D accfg_ctx_get_last_error_device(ctx); + g =3D accfg_ctx_get_last_error_group(ctx); + w =3D accfg_ctx_get_last_error_wq(ctx); + e =3D accfg_ctx_get_last_error_engine(ctx); + if (d) + printf("%s", accfg_device_get_devname(d)); + if (g) + printf("/%s", accfg_group_get_devname(g)); + if (w) + printf("/%s", accfg_wq_get_devname(w)); + if (e) + printf("/%s", accfg_engine_get_devname(e)); + printf(": %s\n", accfg_ctx_get_last_error_str(ctx)); + } accfg_unref(ctx); kmod_module_unref(mod); kmod_unref(kmod_ctx); @@ -144,7 +168,6 @@ int main(int argc, const char **argv) return EXIT_SUCCESS; error_exit: errno =3D abs(rc); - perror("Error"); = return EXIT_FAILURE; } diff --git a/accfg/enable.c b/accfg/enable.c index 90d899c..973f0b8 100644 --- a/accfg/enable.c +++ b/accfg/enable.c @@ -81,17 +81,6 @@ static int dev_action_switch(struct accfg_device *device, } } = -static void print_device_cmd_status(struct accfg_device *device) -{ - const char *status; - - if (accfg_device_get_cmd_status(device) > 0) { - status =3D accfg_device_get_cmd_status_str(device); - if (status) - fprintf(stderr, "device command status: %s\n", status); - } -} - static int device_action(int argc, const char **argv, const char *usage, const struct option *options, enum dev_action action, struct accfg_ctx *ctx) @@ -143,13 +132,10 @@ static int device_action(int argc, const char **argv,= const char *usage, (action =3D=3D DEV_ACTION_DISABLE))) rc =3D ENXIO; } - if (rc =3D=3D 0) { + if (rc =3D=3D 0) success++; - } else { + else fprintf(stderr, "failed in %s\n", argv[i]); - - print_device_cmd_status(device); - } } = fprintf(stderr, "%s %d device(s) out of %d\n", @@ -249,13 +235,10 @@ static int wq_action(int argc, const char **argv, con= st char *usage, } = rc =3D wq_action_switch(wq, action, argv[i]); - if (rc =3D=3D 0) { + if (rc =3D=3D 0) success++; - } else { + else fprintf(stderr, "failed in %s\n", argv[i]); - - print_device_cmd_status(device); - } } = fprintf(stderr, "%s %d wq(s) out of %d\n", -- = 2.26.3 --===============4935683103029117527==--