On 7/15/25 11:25, Mark Cave-Ayland wrote:
> Use QOM casts to convert between VFIOUserContainer and VFIOContainerBase instead
> of accessing bcontainer directly.
>
> Signed-off-by: Mark Cave-Ayland <mark.caveayland@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Thanks,
C.
> ---
> hw/vfio-user/container.c | 26 +++++++++++---------------
> 1 file changed, 11 insertions(+), 15 deletions(-)
>
> diff --git a/hw/vfio-user/container.c b/hw/vfio-user/container.c
> index d318e6a339..025db93ff3 100644
> --- a/hw/vfio-user/container.c
> +++ b/hw/vfio-user/container.c
> @@ -24,16 +24,14 @@
> */
> static void vfio_user_listener_begin(VFIOContainerBase *bcontainer)
> {
> - VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> - bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>
> container->proxy->async_ops = true;
> }
>
> static void vfio_user_listener_commit(VFIOContainerBase *bcontainer)
> {
> - VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> - bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>
> /* wait here for any async requests sent during the transaction */
> container->proxy->async_ops = false;
> @@ -44,8 +42,8 @@ static int vfio_user_dma_unmap(const VFIOContainerBase *bcontainer,
> hwaddr iova, ram_addr_t size,
> IOMMUTLBEntry *iotlb, bool unmap_all)
> {
> - VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> - bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
> Error *local_err = NULL;
> int ret = 0;
>
> @@ -88,8 +86,8 @@ static int vfio_user_dma_map(const VFIOContainerBase *bcontainer, hwaddr iova,
> ram_addr_t size, void *vaddr, bool readonly,
> MemoryRegion *mrp)
> {
> - VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> - bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
> +
> int fd = memory_region_get_fd(mrp);
> Error *local_err = NULL;
> int ret;
> @@ -177,8 +175,7 @@ static int vfio_user_query_dirty_bitmap(const VFIOContainerBase *bcontainer,
>
> static bool vfio_user_setup(VFIOContainerBase *bcontainer, Error **errp)
> {
> - VFIOUserContainer *container = container_of(bcontainer, VFIOUserContainer,
> - bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(bcontainer);
>
> assert(container->proxy->dma_pgsizes != 0);
> bcontainer->pgsizes = container->proxy->dma_pgsizes;
> @@ -222,7 +219,7 @@ vfio_user_container_connect(AddressSpace *as, VFIODevice *vbasedev,
> goto put_space_exit;
> }
>
> - bcontainer = &container->bcontainer;
> + bcontainer = VFIO_IOMMU(container);
>
> ret = ram_block_uncoordinated_discard_disable(true);
> if (ret) {
> @@ -267,7 +264,7 @@ put_space_exit:
>
> static void vfio_user_container_disconnect(VFIOUserContainer *container)
> {
> - VFIOContainerBase *bcontainer = &container->bcontainer;
> + VFIOContainerBase *bcontainer = VFIO_IOMMU(container);
> VFIOIOMMUClass *vioc = VFIO_IOMMU_GET_CLASS(bcontainer);
> VFIOAddressSpace *space = bcontainer->space;
>
> @@ -295,7 +292,7 @@ static bool vfio_user_device_get(VFIOUserContainer *container,
>
> vbasedev->fd = -1;
>
> - vfio_device_prepare(vbasedev, &container->bcontainer, &info);
> + vfio_device_prepare(vbasedev, VFIO_IOMMU(container), &info);
>
> return true;
> }
> @@ -319,8 +316,7 @@ static bool vfio_user_device_attach(const char *name, VFIODevice *vbasedev,
>
> static void vfio_user_device_detach(VFIODevice *vbasedev)
> {
> - VFIOUserContainer *container = container_of(vbasedev->bcontainer,
> - VFIOUserContainer, bcontainer);
> + VFIOUserContainer *container = VFIO_IOMMU_USER(vbasedev->bcontainer);
>
> vfio_device_unprepare(vbasedev);
>