From mboxrd@z Thu Jan 1 00:00:00 1970 Content-Type: multipart/mixed; boundary="===============0771486256113884472==" MIME-Version: 1.0 From: ramesh.thomas at intel.com Subject: [Accel-config] [PATCH 1/5] accel-config: Update for driver deferred mdev registration Date: Mon, 05 Apr 2021 23:34:07 -0400 Message-ID: <20210406033411.464362-2-ramesh.thomas@intel.com> In-Reply-To: 20210406033411.464362-1-ramesh.thomas@intel.com To: accel-config@lists.01.org List-ID: --===============0771486256113884472== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ramesh Thomas Mdev is now registered when the first mdev wq is created. It will be deregistered when the last mdev wq is removed. Change will check for presence of /sys/class/mdev_bus at the point of mdev use instead of initializing context at start. Signed-off-by: Ramesh Thomas --- accfg/lib/libaccfg.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/accfg/lib/libaccfg.c b/accfg/lib/libaccfg.c index a8d18ff..24ae65c 100644 --- a/accfg/lib/libaccfg.c +++ b/accfg/lib/libaccfg.c @@ -108,6 +108,11 @@ const char *accfg_device_cmd_status[] =3D { [ACCFG_CMD_STATUS_MAX] =3D "", }; = +static inline bool is_mdev_registered(struct accfg_device *device) +{ + return device->mdev_path && !access(device->mdev_path, R_OK); +} + static long accfg_get_param_long(struct accfg_ctx *ctx, int dfd, char *nam= e) { int fd =3D openat(dfd, name, O_RDONLY); @@ -593,11 +598,7 @@ static void *add_device(void *parent, int id, const ch= ar *ctl_base, goto err_dev_path; } free(device->mdev_path); - if (access(p, R_OK)) { - free(p); - device->mdev_path =3D NULL; - } else - device->mdev_path =3D p; + device->mdev_path =3D p; = device->device_buf =3D calloc(1, strlen(device->device_path) + MAX_PARAM_LEN); @@ -614,7 +615,7 @@ static void *add_device(void *parent, int id, const cha= r *ctl_base, = device->bus_type_str =3D bus_type; = - if (device->mdev_path && add_device_mdevs(ctx, device)) + if (is_mdev_registered(device) && add_device_mdevs(ctx, device)) goto err_dev_path; = list_add_tail(&ctx->devices, &device->list); @@ -1050,7 +1051,7 @@ ACCFG_EXPORT int accfg_create_mdev(struct accfg_devic= e *device, unsigned int version; int rc; = - if (!device->mdev_path) + if (!is_mdev_registered(device)) return -ENOENT; = if (type >=3D ACCFG_MDEV_TYPE_UNKNOWN || type < 0) @@ -1110,7 +1111,7 @@ ACCFG_EXPORT int accfg_remove_mdev(struct accfg_devic= e *device, uuid_t uuid) struct accfg_device_mdev *entry, *next; int rc, all; = - if (!device->mdev_path) + if (!is_mdev_registered(device)) return -ENOENT; = /* remove all mdevs if null uuid is passed */ @@ -1266,7 +1267,7 @@ ACCFG_EXPORT bool accfg_device_get_pasid_enabled( ACCFG_EXPORT bool accfg_device_get_mdev_enabled( struct accfg_device *device) { - return device->mdev_path !=3D NULL; + return is_mdev_registered(device); } = ACCFG_EXPORT int accfg_device_get_errors(struct accfg_device *device, -- = 2.26.3 --===============0771486256113884472==--