>-----Original Message----- >From: Joel Granados <j.grana...@samsung.com> >Sent: Friday, July 14, 2023 5:23 PM >Subject: Re: [RFC PATCH v4 20/24] vfio/iommufd: Implement the iommufd >backend > >On Wed, Jul 12, 2023 at 03:25:24PM +0800, Zhenzhong Duan wrote: >> From: Yi Liu <yi.l....@intel.com> ... >> +static int vfio_get_devicefd(const char *sysfs_path, Error **errp) >> +{ >> + long int ret = -ENOTTY; >> + char *path, *vfio_dev_path = NULL, *vfio_path = NULL; >> + DIR *dir = NULL; >> + struct dirent *dent; >> + gchar *contents; >> + struct stat st; >> + gsize length; >> + int major, minor; >> + dev_t vfio_devt; >> + >> + path = g_strdup_printf("%s/vfio-dev", sysfs_path); >> + if (stat(path, &st) < 0) { >> + error_setg_errno(errp, errno, "no such host device"); >> + goto out_free_path; >> + } >> + >> + dir = opendir(path); >> + if (!dir) { >> + error_setg_errno(errp, errno, "couldn't open dirrectory %s", path); >> + goto out_free_path; >> + } >> + >> + while ((dent = readdir(dir))) { >> + if (!strncmp(dent->d_name, "vfio", 4)) { >> + vfio_dev_path = g_strdup_printf("%s/%s/dev", path, >> dent->d_name); >> + break; >> + } >> + } >> + >> + if (!vfio_dev_path) { >> + error_setg(errp, "failed to find vfio-dev/vfioX/dev"); >> + goto out_free_path; >> + } >> + >> + if (!g_file_get_contents(vfio_dev_path, &contents, &length, NULL)) { >> + error_setg(errp, "failed to load \"%s\"", vfio_dev_path); >> + goto out_free_dev_path; >> + } >> + >> + if (sscanf(contents, "%d:%d", &major, &minor) != 2) { >> + error_setg(errp, "failed to get major:mino for \"%s\"", >> vfio_dev_path); >Very small nit: Should be "minor" here. Good catch, will fix.
Thanks Zhenzhong