> typedef struct QVirtioDevice { > const QVirtioBus *bus; > + QTestState *qts; > /* Device type */ > uint16_t device_type; > } QVirtioDevice; > @@ -35,12 +36,14 @@ typedef struct QVirtQueue { > uint16_t last_used_idx; > bool indirect; > bool event; > + QTestState *qts; > } QVirtQueue; > > typedef struct QVRingIndirectDesc { > uint64_t desc; /* This points to an array fo struct vring_desc */ > uint16_t index; > uint16_t elem; > + QTestState *qts; > } QVRingIndirectDesc;
Adding QTestState to QVRingIndirectDesc and QVirtQueue sounds somewhat ugly to me. I think they should either rather have a pointer to the associated QVirtioDevice, or the functions where this is needed (qvring_init() for example) should get a "QTestState *" parameter instead. I agree with Thomas and even extend it to QVirtioDevice. If there is a has-a hierarchy between libqos objects, only the topmost one (such as the virtio mmio bus device, and the PCI host bridge---or possibly even the machine object exclusively) should have a QTestState. Everyone else can access it implicitly through operations on its bus. Test code on the other hand can use global_qtest implicitly when they prepare/read buffers that the devices do DMA from/to. Paolo Just my 0.02 €. Thomas