Commit 1334e47e authored by Yi Liu's avatar Yi Liu Committed by Jason Gunthorpe

vfio: Wrap vfio group module init/clean code into helpers

This wraps the init/clean code of vfio group global variable to be
helpers, and prepares for further moving vfio group specific code into
separate file.

As container is used by group, so vfio_container_init/cleanup() is moved
into vfio_group_init/cleanup().

Link: https://lore.kernel.org/r/20221201145535.589687-9-yi.l.liu@intel.comReviewed-by: default avatarKevin Tian <kevin.tian@intel.com>
Reviewed-by: default avatarJason Gunthorpe <jgg@nvidia.com>
Reviewed-by: default avatarAlex Williamson <alex.williamson@redhat.com>
Tested-by: default avatarLixiao Yang <lixiao.yang@intel.com>
Tested-by: default avatarYu He <yu.he@intel.com>
Signed-off-by: default avatarYi Liu <yi.l.liu@intel.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 5c8d3d93
......@@ -2066,12 +2066,11 @@ static char *vfio_devnode(struct device *dev, umode_t *mode)
return kasprintf(GFP_KERNEL, "vfio/%s", dev_name(dev));
}
static int __init vfio_init(void)
static int __init vfio_group_init(void)
{
int ret;
ida_init(&vfio.group_ida);
ida_init(&vfio.device_ida);
mutex_init(&vfio.group_lock);
INIT_LIST_HEAD(&vfio.group_list);
......@@ -2088,24 +2087,12 @@ static int __init vfio_init(void)
vfio.class->devnode = vfio_devnode;
/* /sys/class/vfio-dev/vfioX */
vfio.device_class = class_create(THIS_MODULE, "vfio-dev");
if (IS_ERR(vfio.device_class)) {
ret = PTR_ERR(vfio.device_class);
goto err_dev_class;
}
ret = alloc_chrdev_region(&vfio.group_devt, 0, MINORMASK + 1, "vfio");
if (ret)
goto err_alloc_chrdev;
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
return 0;
err_alloc_chrdev:
class_destroy(vfio.device_class);
vfio.device_class = NULL;
err_dev_class:
class_destroy(vfio.class);
vfio.class = NULL;
err_group_class:
......@@ -2113,18 +2100,47 @@ static int __init vfio_init(void)
return ret;
}
static void __exit vfio_cleanup(void)
static void vfio_group_cleanup(void)
{
WARN_ON(!list_empty(&vfio.group_list));
ida_destroy(&vfio.device_ida);
ida_destroy(&vfio.group_ida);
unregister_chrdev_region(vfio.group_devt, MINORMASK + 1);
class_destroy(vfio.device_class);
vfio.device_class = NULL;
class_destroy(vfio.class);
vfio_container_cleanup();
vfio.class = NULL;
vfio_container_cleanup();
}
static int __init vfio_init(void)
{
int ret;
ida_init(&vfio.device_ida);
ret = vfio_group_init();
if (ret)
return ret;
/* /sys/class/vfio-dev/vfioX */
vfio.device_class = class_create(THIS_MODULE, "vfio-dev");
if (IS_ERR(vfio.device_class)) {
ret = PTR_ERR(vfio.device_class);
goto err_dev_class;
}
pr_info(DRIVER_DESC " version: " DRIVER_VERSION "\n");
return 0;
err_dev_class:
vfio_group_cleanup();
return ret;
}
static void __exit vfio_cleanup(void)
{
ida_destroy(&vfio.device_ida);
class_destroy(vfio.device_class);
vfio.device_class = NULL;
vfio_group_cleanup();
xa_destroy(&vfio_device_set_xa);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment