Content-Type: multipart/mixed; boundary="===============2892780667159961645==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH v1 5/8] accel-config: Rewrite device selection using new filter functions Date: Wed, 05 May 2021 13:44:19 -0400 Message-ID: <20210505174422.837248-6-ramesh.thomas@intel.com> In-Reply-To: 20210505174422.837248-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============2892780667159961645== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Rewrite code that parses and locates devices, wqs, groups and engines using the new filter and parse functions. Signed-off-by: Ramesh Thomas --- 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, vo= id *ctx) } = for (i =3D 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 =3D accel_config_parse_device_attribs(device, - &dev_param); - if (rc !=3D 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 =3D accel_config_parse_device_attribs(device, &dev_param); + if (rc !=3D 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 =3D 0; - unsigned int dev_id, group_id; = const struct option options[] =3D { OPT_UINTEGER('r', "tokens-reserved", @@ -373,43 +370,17 @@ int cmd_config_group(int argc, const char **argv, voi= d *ctx) } = for (i =3D 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") =3D=3D 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) - !=3D 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 =3D sprintf(group_name, "group%u.%u", dev_id, group_id); + rc =3D 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 =3D 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 =3D 0; - unsigned int dev_id =3D 0, wq_id =3D 0; = const struct option options[] =3D { 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 =3D 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") !=3D NULL) { - if (sscanf(argv[i], "%[^/]/wq%u.%u", - dev_name, &dev_id, &wq_id) !=3D 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 =3D sprintf(wq_name, "wq%u.%u", dev_id, wq_id); + rc =3D 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 =3D 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 *ct= x) int cmd_config_engine(int argc, const char **argv, void *ctx) { int i, rc =3D 0; - unsigned int dev_id =3D 0, engine_id =3D 0; = const struct option options[] =3D { OPT_INTEGER('g', "group-id", &engine_param.group_id, @@ -538,41 +483,19 @@ int cmd_config_engine(int argc, const char **argv, vo= id *ctx) for (i =3D 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") !=3D NULL) { - if (sscanf(argv[i], "%[^/]/engine%u.%u", dev_name, &dev_id, - &engine_id) !=3D 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 =3D sprintf(engine_name, "engine%u.%u", dev_id, engine_id); - if (rc < 0) + rc =3D accel_config_parse_engine_attribs(device, + engine, &engine_param); + if (rc !=3D 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 =3D accel_config_parse_engine_attribs(device, - engine, &engine_param); - if (rc !=3D 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 =3D 0; i < argc; i++) { - int found =3D 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 =3D dev_action_switch(device, action); - if (rc =3D=3D 0) { - /* - * Double check if the state of the device - * matches with the enable/disable - */ - state =3D accfg_device_get_state(device); - if (((state !=3D ACCFG_DEVICE_ENABLED) && - (action =3D=3D DEV_ACTION_ENABLE)) || - ((state !=3D ACCFG_DEVICE_DISABLED) && - (action =3D=3D DEV_ACTION_DISABLE))) - rc =3D ENXIO; - } - if (rc =3D=3D 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 =3D dev_action_switch(device, action); + if (rc =3D=3D 0) { + /* + * Double check if the state of the device + * matches with the enable/disable + */ + state =3D accfg_device_get_state(device); + if (((state !=3D ACCFG_DEVICE_ENABLED) && + (action =3D=3D DEV_ACTION_ENABLE)) || + ((state !=3D ACCFG_DEVICE_DISABLED) && + (action =3D=3D DEV_ACTION_DISABLE))) + rc =3D ENXIO; } + if (rc =3D=3D 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 =3D -EINVAL, success =3D 0; const char *all =3D "all"; = @@ -249,43 +241,21 @@ static int wq_action(int argc, const char **argv, con= st char *usage, for (i =3D 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 =3D 0; - - if (sscanf(argv[i], "%[^/]/wq%" SCNu64 ".%" SCNu64, - dev_name, &dev_id, &wq_id) !=3D 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 =3D 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 =3D wq_action_switch(wq, action, wq_name); - if (rc =3D=3D 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 =3D wq_action_switch(wq, action, argv[i]); + if (rc =3D=3D 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 --===============2892780667159961645==--