From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============8713227564573923683==" MIME-Version: 1.0 From: Ramesh Thomas Subject: [Accel-config] [PATCH 2/4] accel-config: Fix issues in skipping active configurations Date: Tue, 07 Dec 2021 19:51:50 -0500 Message-ID: <20211208005152.220518-3-ramesh.thomas@intel.com> In-Reply-To: 20211208005152.220518-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8713227564573923683== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Skipping of active configurations was not being handled correctly. If device is active or encounters an error, all configurations related to that device are skipped. Removed redundant code paths. Signed-off-by: Ramesh Thomas --- accfg/config.c | 60 ++++++++++++++++++++------------------------------ 1 file changed, 24 insertions(+), 36 deletions(-) diff --git a/accfg/config.c b/accfg/config.c index 91a71e3..9fb8874 100644 --- a/accfg/config.c +++ b/accfg/config.c @@ -486,8 +486,7 @@ static int configure_json_value(struct accfg_ctx *ctx, char *parsed_string; char dev_type[MAX_DEV_LEN]; char *accel_type =3D NULL; - static char *dev_name; - static struct accfg_device *dev; + static struct accfg_device *dev, *parent; static struct accfg_wq *wq; static struct accfg_engine *engine; static struct accfg_group *group; @@ -501,6 +500,10 @@ static int configure_json_value(struct accfg_ctx *ctx, parsed_string =3D (char *)json_object_get_string(jobj); if (!parsed_string) return -EINVAL; + dev =3D NULL; + group =3D NULL; + wq =3D NULL; + engine =3D NULL; for (accel_type =3D accfg_basenames[0]; accel_type !=3D NULL; i++) { memset(dev_type, 0, MAX_DEV_LEN); if (strstr(parsed_string, accel_type) !=3D NULL) { @@ -514,6 +517,7 @@ static int configure_json_value(struct accfg_ctx *ctx, } = if (!strcmp(dev_type, accel_type)) { + parent =3D NULL; dev =3D accfg_ctx_device_get_by_name(ctx, parsed_string); if (!dev) { @@ -524,48 +528,43 @@ static int configure_json_value(struct accfg_ctx *ctx, if (dev_state =3D=3D ACCFG_DEVICE_ENABLED) { fprintf(stderr, "%s is active, will skip...\n", parsed_string); + dev =3D NULL; return 0; } - dev_name =3D parsed_string; - wq =3D NULL; - engine =3D NULL; - group =3D NULL; = if (enable) { rc =3D add_to_activation_list(&activate_dev_list, dev); if (rc) return rc; } + + parent =3D dev; + break; } accel_type =3D accfg_basenames[i]; } = + /* Skip if device configuration was skipped */ + if (!parent) + return 0; + if (strstr(parsed_string, "wq") !=3D NULL) { rc =3D sscanf(&parsed_string[strlen("wq")], "%d.%d", &dev_id, &id); if (rc !=3D 2) return -EINVAL; = - if (dev_name) - dev =3D accfg_ctx_device_get_by_name(ctx, dev_name); - - if (!dev) - return -ENOENT; - - wq =3D accfg_device_wq_get_by_id(dev, id); + wq =3D accfg_device_wq_get_by_id(parent, id); if (!wq) return -ENOENT; wq_state =3D accfg_wq_get_state(wq); if (wq_state =3D=3D ACCFG_WQ_ENABLED || wq_state =3D=3D ACCFG_WQ_LOCKED= ) { fprintf(stderr, "%s is active, will skip...\n", parsed_string); + wq =3D NULL; return 0; } = - dev =3D NULL; - engine =3D NULL; - group =3D NULL; - if (enable) { rc =3D add_to_activation_list(&activate_wq_list, wq); if (rc) @@ -579,19 +578,10 @@ static int configure_json_value(struct accfg_ctx *ctx, if (rc !=3D 2) return -EINVAL; = - if (dev_name) - dev =3D accfg_ctx_device_get_by_name(ctx, dev_name); - - if (!dev) - return -ENOENT; - - engine =3D accfg_device_engine_get_by_id(dev, id); + engine =3D accfg_device_engine_get_by_id(parent, id); if (!engine) return -ENOENT; = - dev =3D NULL; - wq =3D NULL; - group =3D NULL; } = if (strstr(parsed_string, "group") !=3D NULL) { @@ -600,20 +590,18 @@ static int configure_json_value(struct accfg_ctx *ctx, if (rc !=3D 2) return -EINVAL; = - if (dev_name) - dev =3D accfg_ctx_device_get_by_name(ctx, dev_name); - - if (!dev) - return -ENOENT; - group =3D accfg_device_group_get_by_id(dev, id); + group =3D accfg_device_group_get_by_id(parent, id); if (!group) return -ENOENT; - dev =3D NULL; - wq =3D NULL; - engine =3D NULL; } + + return 0; } = + /* Skip if device configuration was skipped */ + if (!parent) + return 0; + if (dev && dev_state !=3D ACCFG_DEVICE_ENABLED) { rc =3D device_json_set_val(dev, jobj, key); if (rc < 0) { -- = 2.26.3 --===============8713227564573923683==--