[Accel-config] [PATCH v1 5/8] accel-config: Rewrite device selection using new filter functions
ramesh.thomas at intel.com
| Newsgroups | dev.linux.lists.accel-config |
|---|---|
| Message-ID | <[email protected]> |
From: Ramesh Thomas <ramesh.thomas(a)intel.com>
Rewrite code that parses and locates devices, wqs, groups and engines
using the new filter and parse functions.
Signed-off-by: Ramesh Thomas <ramesh.thomas(a)intel.com>
---
accfg/config_attr.c | 139 ++++++++++----------------------------------
accfg/enable.c | 102 ++++++++++++--------------------
2 files changed, 67 insertions(+), 174 deletions(-)
diff --git a/accfg/config_attr.c b/accfg/config_attr.c
index a893f08..e09b9b6 100644
--- a/accfg/config_attr.c
+++ b/accfg/config_attr.c
@@ -310,19 +310,17 @@ int cmd_config_device(int argc, const char **argv, void *ctx)
}
for (i = 0; i < argc; i++) {
- if (accfg_device_type_validate(argv[i])) {
- /* walkthrough device */
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, argv[i]))
- continue;
- rc = accel_config_parse_device_attribs(device,
- &dev_param);
- if (rc != 0) {
- fprintf(stderr,
- "accel_config_parse_device_attribs failed\n");
- return rc;
- }
- }
+ if (parse_device_name(ctx, argv[i], &device)) {
+ fprintf(stderr,
+ "%s is not a valid device name\n", argv[i]);
+ continue;
+ }
+
+ rc = accel_config_parse_device_attribs(device, &dev_param);
+ if (rc != 0) {
+ fprintf(stderr,
+ "accel_config_parse_device_attribs failed\n");
+ return rc;
}
}
@@ -332,7 +330,6 @@ int cmd_config_device(int argc, const char **argv, void *ctx)
int cmd_config_group(int argc, const char **argv, void *ctx)
{
int i, rc = 0;
- unsigned int dev_id, group_id;
const struct option options[] = {
OPT_UINTEGER('r', "tokens-reserved",
@@ -373,43 +370,17 @@ int cmd_config_group(int argc, const char **argv, void *ctx)
}
for (i = 0; i < argc; i++) {
- struct accfg_device *device;
struct accfg_group *group;
- char dev_name[MAX_DEV_LEN], group_name[MAX_DEV_LEN];
-
- if (strstr(argv[i], "group") == NULL) {
- fprintf(stderr, "need to provide group name\n");
- return -EINVAL;
- }
- /* walk through group */
- if (sscanf(argv[i], "%[^/]/group%u.%u", dev_name, &dev_id, &group_id)
- != 3) {
+ if (parse_group_name(ctx, argv[i], NULL, &group)) {
fprintf(stderr,
- "'%s' is not a valid group name\n", argv[i]);
- return -EINVAL;
+ "%s is not a valid group name\n", argv[i]);
+ continue;
}
- if (!accfg_device_type_validate(dev_name))
- return -EINVAL;
- rc = sprintf(group_name, "group%u.%u", dev_id, group_id);
+ rc = accel_config_parse_group_attribs(group, &group_param);
if (rc < 0)
return rc;
-
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, dev_name))
- continue;
-
- accfg_group_foreach(device, group) {
- if (!util_group_filter(group, group_name))
- continue;
-
- rc = accel_config_parse_group_attribs(group,
- &group_param);
- if (rc < 0)
- return rc;
- }
- }
}
return 0;
@@ -418,7 +389,6 @@ int cmd_config_group(int argc, const char **argv, void *ctx)
int cmd_config_wq(int argc, const char **argv, void *ctx)
{
int i, rc = 0;
- unsigned int dev_id = 0, wq_id = 0;
const struct option options[] = {
OPT_INTEGER('g', "group-id", &wq_param.group_id,
@@ -466,40 +436,16 @@ int cmd_config_wq(int argc, const char **argv, void *ctx)
for (i = 0; i < argc; i++) {
struct accfg_device *device;
struct accfg_wq *wq;
- char dev_name[MAX_DEV_LEN], wq_name[MAX_DEV_LEN];
-
- /* walk through wq */
- if (strstr(argv[i], "wq") != NULL) {
- if (sscanf(argv[i], "%[^/]/wq%u.%u",
- dev_name, &dev_id, &wq_id) != 3) {
- fprintf(stderr,
- "'%s' is not a valid wq name\n",
- argv[i]);
- return -EINVAL;
- }
- }
- if (!accfg_device_type_validate(dev_name))
- return -EINVAL;
+ if (parse_wq_name(ctx, argv[i], &device, &wq)) {
+ fprintf(stderr,
+ "%s is not a valid workqueue name\n", argv[i]);
+ continue;
+ }
- rc = sprintf(wq_name, "wq%u.%u", dev_id, wq_id);
+ rc = accel_config_parse_wq_attribs(device, wq, &wq_param);
if (rc < 0)
return rc;
-
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, dev_name))
- continue;
-
- accfg_wq_foreach(device, wq) {
- if (!util_wq_filter(wq, wq_name))
- continue;
-
- rc = accel_config_parse_wq_attribs(device, wq,
- &wq_param);
- if (rc < 0)
- return rc;
- }
- }
}
return 0;
@@ -508,7 +454,6 @@ int cmd_config_wq(int argc, const char **argv, void *ctx)
int cmd_config_engine(int argc, const char **argv, void *ctx)
{
int i, rc = 0;
- unsigned int dev_id = 0, engine_id = 0;
const struct option options[] = {
OPT_INTEGER('g', "group-id", &engine_param.group_id,
@@ -538,41 +483,19 @@ int cmd_config_engine(int argc, const char **argv, void *ctx)
for (i = 0; i < argc; i++) {
struct accfg_device *device;
struct accfg_engine *engine;
- char dev_name[MAX_DEV_LEN], engine_name[MAX_DEV_LEN];
-
- if (strstr(argv[i], "engine") != NULL) {
- if (sscanf(argv[i], "%[^/]/engine%u.%u", dev_name, &dev_id,
- &engine_id) != 3) {
- fprintf(stderr,
- "'%s' is not a valid engine name\n",
- argv[i]);
- return -EINVAL;
- }
- }
- /* walk through engine */
- if (!accfg_device_type_validate(dev_name))
- return -EINVAL;
+ if (parse_engine_name(ctx, argv[i], &device, &engine)) {
+ fprintf(stderr,
+ "%s is not a valid engine name\n", argv[i]);
+ continue;
+ }
- rc = sprintf(engine_name, "engine%u.%u", dev_id, engine_id);
- if (rc < 0)
+ rc = accel_config_parse_engine_attribs(device,
+ engine, &engine_param);
+ if (rc != 0) {
+ fprintf(stderr,
+ "accel_config_parse_engine_attribs failed\n");
return rc;
-
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, dev_name))
- continue;
-
- accfg_engine_foreach(device, engine) {
- if (!util_engine_filter(engine, engine_name))
- continue;
- rc = accel_config_parse_engine_attribs(device,
- engine, &engine_param);
- if (rc != 0) {
- fprintf(stderr,
- "accel_config_parse_engine_attribs failed\n");
- return rc;
- }
- }
}
}
diff --git a/accfg/enable.c b/accfg/enable.c
index f65f8e2..90d899c 100644
--- a/accfg/enable.c
+++ b/accfg/enable.c
@@ -121,42 +121,35 @@ static int device_action(int argc, const char **argv, const char *usage,
}
for (i = 0; i < argc; i++) {
- int found = 0;
struct accfg_device *device;
- if (!accfg_device_type_validate(argv[i]))
- return -EINVAL;
-
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, argv[i]))
- continue;
- found++;
-
- rc = dev_action_switch(device, action);
- if (rc == 0) {
- /*
- * Double check if the state of the device
- * matches with the enable/disable
- */
- state = accfg_device_get_state(device);
- if (((state != ACCFG_DEVICE_ENABLED) &&
- (action == DEV_ACTION_ENABLE)) ||
- ((state != ACCFG_DEVICE_DISABLED) &&
- (action == DEV_ACTION_DISABLE)))
- rc = ENXIO;
- }
- if (rc == 0) {
- success++;
- } else {
- fprintf(stderr, "failed in %s\n", argv[i]);
+ if (parse_device_name(ctx, argv[i], &device)) {
+ if (param.verbose)
+ fprintf(stderr,
+ "%s device not found\n", argv[i]);
+ continue;
+ }
- print_device_cmd_status(device);
- }
+ rc = dev_action_switch(device, action);
+ if (rc == 0) {
+ /*
+ * Double check if the state of the device
+ * matches with the enable/disable
+ */
+ state = accfg_device_get_state(device);
+ if (((state != ACCFG_DEVICE_ENABLED) &&
+ (action == DEV_ACTION_ENABLE)) ||
+ ((state != ACCFG_DEVICE_DISABLED) &&
+ (action == DEV_ACTION_DISABLE)))
+ rc = ENXIO;
}
+ if (rc == 0) {
+ success++;
+ } else {
+ fprintf(stderr, "failed in %s\n", argv[i]);
- if (!found && param.verbose)
- fprintf(stderr, "no device matches with the name: %s\n",
- argv[i]);
+ print_device_cmd_status(device);
+ }
}
fprintf(stderr, "%s %d device(s) out of %d\n",
@@ -226,7 +219,6 @@ static int wq_action(int argc, const char **argv, const char *usage,
usage,
NULL
};
- uint64_t dev_id, wq_id;
int i, rc = -EINVAL, success = 0;
const char *all = "all";
@@ -249,43 +241,21 @@ static int wq_action(int argc, const char **argv, const char *usage,
for (i = 0; i < argc; i++) {
struct accfg_device *device;
struct accfg_wq *wq;
- char dev_name[MAX_DEV_LEN], wq_name[MAX_DEV_LEN];
- int found = 0;
-
- if (sscanf(argv[i], "%[^/]/wq%" SCNu64 ".%" SCNu64,
- dev_name, &dev_id, &wq_id) != 3) {
- fprintf(stderr, "'%s' is not a valid wq name\n",
- argv[i]);
- return -EINVAL;
- }
- if (!accfg_device_type_validate(dev_name))
- return -EINVAL;
-
- rc = sprintf(wq_name, "wq%" PRIu64 ".%" PRIu64, dev_id, wq_id);
- if (rc < 0)
- return rc;
-
- accfg_device_foreach(ctx, device) {
- if (!util_device_filter(device, dev_name))
- continue;
- accfg_wq_foreach(device, wq) {
- if (!util_wq_filter(wq, wq_name))
- continue;
- found++;
- rc = wq_action_switch(wq, action, wq_name);
- if (rc == 0) {
- success++;
- } else {
- fprintf(stderr, "failed in %s\n", wq_name);
-
- print_device_cmd_status(device);
- }
- }
+ if (parse_wq_name(ctx, argv[i], &device, &wq)) {
+ if (param.verbose)
+ fprintf(stderr, "%s wq not found\n", argv[i]);
+ continue;
}
- if (!found && param.verbose)
- fprintf(stderr, "no wq matches id: %s\n", wq_name);
+ rc = wq_action_switch(wq, action, argv[i]);
+ if (rc == 0) {
+ success++;
+ } 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