Content-Type: multipart/mixed; boundary="===============5073987885295427908==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH] accel-config: Refactor handling of cdev_minor at wq enable/disable Date: Tue, 18 May 2021 21:08:21 -0400 Message-ID: <20210519010821.875884-1-ramesh.thomas@intel.com> To: accel-config@lists.01.org List-ID: --===============5073987885295427908== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas cdev_minor depends on wq being enabled, of type "user" and in non uacce mode. Update the cached value of cdev_minor when wq state changes by reading sysfs. If the read fails, a negative value will be stored indicating it is not valid for the current state of the wq. Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 64 ++++++-------------------------------------- 1 file changed, 8 insertions(+), 56 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index 0796f08..1463a4d 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -1925,62 +1925,16 @@ ACCFG_EXPORT int accfg_wq_priority_boundary(struct = accfg_wq *wq) = static int accfg_wq_retrieve_cdev_minor(struct accfg_wq *wq) { + int dfd; struct accfg_ctx *ctx =3D accfg_wq_get_ctx(wq); - char *path =3D wq->wq_buf; - char buf[SYSFS_ATTR_SIZE]; - int rc; - - rc =3D sprintf(wq->wq_buf, "%s/%s", wq->wq_path, "cdev_minor"); - if (rc < 0) - return -errno; - - if (sysfs_read_attr(ctx, path, buf) < 0) { - err(ctx, "%s: retrieve cdev minor failed: '%s': %s\n", - __func__, wq->wq_path, strerror(errno)); - return -errno; - } - - wq->cdev_minor =3D atoi(buf); - return 0; -} = -static int accfg_wq_post_enable(struct accfg_wq *wq) -{ - enum accfg_wq_type type; - int rc; - - type =3D accfg_wq_get_type(wq); - - if (type =3D=3D ACCFG_WQT_USER) { - rc =3D accfg_wq_retrieve_cdev_minor(wq); - if (rc < 0) - return rc; - } - - return 0; -} - -static int accfg_wq_post_disable(struct accfg_wq *wq) -{ - enum accfg_wq_type type; - - type =3D accfg_wq_get_type(wq); - - if (type =3D=3D ACCFG_WQT_USER) - wq->cdev_minor =3D -1; + dfd =3D open(wq->wq_path, O_PATH); + if (dfd < 0) + return -ENXIO; = - return 0; -} + wq->cdev_minor =3D accfg_get_param_long(ctx, dfd, "cdev_minor"); = -static int accfg_wq_control_post_processing(struct accfg_wq *wq, - enum accfg_control_flag flag) -{ - if (flag =3D=3D ACCFG_WQ_ENABLE) - return accfg_wq_post_enable(wq); - else if (flag =3D=3D ACCFG_WQ_DISABLE) - return accfg_wq_post_disable(wq); - else - return -EINVAL; + close(dfd); = return 0; } @@ -2052,10 +2006,8 @@ static int accfg_wq_control(struct accfg_wq *wq, enu= m accfg_control_flag flag, return -ENXIO; } = - /* post processing */ - rc =3D accfg_wq_control_post_processing(wq, flag); - if (rc < 0) - return rc; + if (accfg_wq_retrieve_cdev_minor(wq)) + return -ENXIO; = return 0; } -- = 2.26.3 --===============5073987885295427908==--