Content-Type: multipart/mixed; boundary="===============8216482782317145391==" MIME-Version: 1.0 From: Dave Jiang Subject: [Accel-config] Re: [PATCH v2] accel-config: Add API to return uacce device path Date: Mon, 05 Apr 2021 21:13:12 -0700 Message-ID: In-Reply-To: 20210406013856.463845-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============8216482782317145391== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable On 4/5/2021 6:38 PM, ramesh.thomas(a)intel.com wrote: > From: Ramesh Thomas > > Return path to uacce device path for user wqs. This includes support for > legacy mode device names. > > Signed-off-by: Ramesh Thomas Reviewed-by: Dave Jiang > --- > V2: > Change name of API to a gneric name instead of uacce specific > > accfg/lib/libaccel-config.sym | 5 ++++ > accfg/lib/libaccfg.c | 55 +++++++++++++++++++++++++++++++++++ > accfg/libaccel_config.h | 1 + > 3 files changed, 61 insertions(+) > > diff --git a/accfg/lib/libaccel-config.sym b/accfg/lib/libaccel-config.sym > index 4de2a49..87b53f5 100644 > --- a/accfg/lib/libaccel-config.sym > +++ b/accfg/lib/libaccel-config.sym > @@ -141,3 +141,8 @@ global: > accfg_remove_mdev; > accfg_device_get_mdev_enabled; > } LIBACCFG_6; > + > +LIBACCFG_8 { > +global: > + accfg_wq_get_user_dev_path; > +} LIBACCFG_7; > diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c > index 1d89d4c..a8d18ff 100644 > --- a/accfg/lib/libaccfg.c > +++ b/accfg/lib/libaccfg.c > @@ -25,6 +25,7 @@ > #include > #include > #include > +#include > #include "private.h" > = > #define MDEV_POSTFIX "mdev_supported_types" > @@ -2099,6 +2100,60 @@ ACCFG_EXPORT int accfg_wq_size_boundary(struct acc= fg_device *device, > return 0; > } > = > +ACCFG_EXPORT int accfg_wq_get_user_dev_path(struct accfg_wq *wq, char *b= uf, > + size_t size) > +{ > + struct dirent **d; > + int n, n1; > + char *f; > + char p[PATH_MAX]; > + struct accfg_ctx *ctx; > + int rc =3D 0; > + > + ctx =3D accfg_device_get_ctx(wq->device); > + > + sprintf(p, "/dev/%s", wq->device->bus_type_str); > + n1 =3D n =3D scandir(p, &d, NULL, alphasort); > + if (n < 0) { > + err(ctx, "Device path not found %s\n", p); > + return -ENOENT; > + } > + > + sprintf(p, "%s-*", accfg_wq_get_devname(wq)); > + > + while (n--) { > + f =3D &d[n]->d_name[0]; > + > + if (!fnmatch(p, f, 0) || !strcmp(accfg_wq_get_devname(wq), f)) > + break; > + } > + > + if (n < 0) { > + err(ctx, "Device for %s not found at /dev/%s\n", > + accfg_wq_get_devname(wq), > + wq->device->bus_type_str); > + rc =3D -ENOENT; > + goto ext_uacce; > + } > + > + n =3D sprintf(p, "/dev/%s/%s", wq->device->bus_type_str, f); > + > + if ((size_t)n >=3D size) { > + err(ctx, "Buffer size too small. Need %d bytes\n", n + 1); > + rc =3D -ERANGE; > + goto ext_uacce; > + } > + > + strcpy(buf, p); > + > +ext_uacce: > + while (n1--) > + free(d[n1]); > + free(d); > + > + return rc; > +} > + > #define accfg_wq_set_field(wq, val, field) \ > ACCFG_EXPORT int accfg_wq_set_##field( \ > struct accfg_wq *wq, int val) \ > diff --git a/accfg/libaccel_config.h b/accfg/libaccel_config.h > index 94aef80..238ca1a 100644 > --- a/accfg/libaccel_config.h > +++ b/accfg/libaccel_config.h > @@ -276,6 +276,7 @@ int accfg_wq_enable(struct accfg_wq *wq); > int accfg_wq_disable(struct accfg_wq *wq, bool force); > int accfg_wq_priority_boundary(struct accfg_wq *wq); > int accfg_wq_size_boundary(struct accfg_device *device, int wq_num); > +int accfg_wq_get_user_dev_path(struct accfg_wq *wq, char *buf, size_t si= ze); > = > /* libaccfg function for engine */ > struct accfg_engine; --===============8216482782317145391==--