[Accel-config] [PATCH v4 2/3] accel-config: Print details of error at exit using new last_error API
ramesh.thomas at intel.com
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
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 <ramesh.thomas(a)intel.com>
---
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 = main_handle_internal_command(argc, argv, ctx, commands,
ARRAY_SIZE(commands));
+
+ last_error = 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 = accfg_ctx_get_last_error_device(ctx);
+ g = accfg_ctx_get_last_error_group(ctx);
+ w = accfg_ctx_get_last_error_wq(ctx);
+ e = 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 = 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 = 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 == DEV_ACTION_DISABLE)))
rc = ENXIO;
}
- if (rc == 0) {
+ if (rc == 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, const char *usage,
}
rc = wq_action_switch(wq, action, argv[i]);
- if (rc == 0) {
+ if (rc == 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