virtio-console: Have a static instance of virtconsole
PATCH 1/1 virtio-console: Have a static instance of virtconsole
Currently the VirtIOConsole struct is allocated from the call to virtio_common_init, also doing an UP_CAST implicitly.
The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
--- hw/virtio-console.c | 37 +++++++++++++++++++++---------------- 1 files changed, 21 insertions(+), 16 deletions(-)
hw/virtio-console.c +21 -16
@@ -19,11 +19,13 @@typedef struct VirtIOConsole { -VirtIODevice vdev; +VirtIODevice *vdev;VirtQueue *ivq, *ovq;CharDriverState *chr; }VirtIOConsole ; +VirtIOConsole virtconsole; +static VirtIOConsole *to_virtio_console (VirtIODevice *vdev) {return (VirtIOConsole *)vdev;
@@ -61,7 +63,7 @@ static int vcon_can_read(void *opaque)VirtIOConsole *s = (VirtIOConsole *) opaque;if (!virtio_queue_ready (s->ivq) || - !(s->vdev.status &VIRTIO_CONFIG_S_DRIVER_OK ) || + !(s->vdev->status &VIRTIO_CONFIG_S_DRIVER_OK ) ||virtio_queue_empty (s->ivq))return 0 ;
@@ -97,7 +99,7 @@ static void vcon_read(void *opaque, const uint8_t *buf, int size) }virtqueue_push (s->ivq, &elem, size); } -virtio_notify (&s->vdev, s->ivq); +virtio_notify (s->vdev, s->ivq); }static void vcon_event (void *opaque,int event)
@@ -109,7 +111,7 @@ static void virtio_console_save(QEMUFile *f, void *opaque) {VirtIOConsole *s = opaque; -virtio_save (&s->vdev, f); +virtio_save (s->vdev, f); }static int virtio_console_load (QEMUFile *f,void *opaque,int version_id)
@@ -119,25 +121,28 @@ static int virtio_console_load(QEMUFile *f, void *opaque, int version_id)if (version_id !=1 )return -EINVAL ; -virtio_load (&s->vdev, f); +virtio_load (s->vdev, f);return 0 ; }VirtIODevice *virtio_console_init (DeviceState *dev) { -VirtIOConsole *s; - s = (VirtIOConsole *)virtio_common_init ("virtio-console" , -VIRTIO_ID_CONSOLE , -0 ,sizeof (VirtIOConsole)); - s->vdev.get_features = virtio_console_get_features; + virtconsole.vdev =virtio_common_init ("virtio-console" , +VIRTIO_ID_CONSOLE , +0 ,sizeof (VirtIODevice)); + virtconsole.vdev->get_features = virtio_console_get_features; - s->ivq =virtio_add_queue (&s->vdev,128 , virtio_console_handle_input); - s->ovq =virtio_add_queue (&s->vdev,128 , virtio_console_handle_output); + virtconsole.ivq =virtio_add_queue (virtconsole.vdev,128 , + virtio_console_handle_input); + virtconsole.ovq =virtio_add_queue (virtconsole.vdev,128 , + virtio_console_handle_output); - s->chr =qdev_init_chardev (dev); -qemu_chr_add_handlers (s->chr, vcon_can_read, vcon_read, vcon_event, s); + virtconsole.chr =qdev_init_chardev (dev); +qemu_chr_add_handlers (virtconsole.chr, vcon_can_read, vcon_read, vcon_event, + &virtconsole); -register_savevm ("virtio-console" ,-1 ,1 , virtio_console_save, virtio_console_load, s); +register_savevm ("virtio-console" ,-1 ,1 , virtio_console_save, + virtio_console_load, &virtconsole); -return &s->vdev; +return virtconsole.vdev; }
Signature · 1 line
1.6.2.5
Quoted 8 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
+VirtIOConsole virtconsole;
IMHO this is going to wrong direction. What kind of code would need a static instance?
Quoted 4 lines · Blue Swirl
Quoted 3 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.
Quoted 8 lines
Quoted 5 lines
The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
+VirtIOConsole virtconsole;
IMHO this is going to wrong direction. What kind of code would need a static instance?
Adding multiple ports to the console device, we'll have to store an array of ports here as well as config space. Both of these are device-specific.
Amit
Quoted 9 lines · Amit Shah
Quoted 8 lines · Blue Swirl
Quoted 6 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+VirtIOConsole virtconsole;
IMHO this is going to wrong direction. What kind of code would need a static instance?
Adding multiple ports to the console device, we'll have to store an array of ports here as well as config space. Both of these are device-specific.
There could be a master device which managed all ports.
Quoted 12 lines · Blue Swirl
Quoted 11 lines · Amit Shah
Quoted 10 lines · Blue Swirl
Quoted 8 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
+VirtIOConsole virtconsole;
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
IMHO this is going to wrong direction. What kind of code would need a static instance?
Adding multiple ports to the console device, we'll have to store an array of ports here as well as config space. Both of these are device-specific.
There could be a master device which managed all ports.
There's only one instance of a virtio device created, and this device hosts multiple ports. And VirIOConsole is the master structure.
Or did I miss what it is you're saying?
Amit
Quoted 16 lines · Amit Shah
Quoted 15 lines · Blue Swirl
Quoted 14 lines · Amit Shah
Quoted 12 lines · Blue Swirl
Quoted 8 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
+VirtIOConsole virtconsole;
IMHO this is going to wrong direction. What kind of code would need a static instance?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Adding multiple ports to the console device, we'll have to store an array of ports here as well as config space. Both of these are device-specific.
There could be a master device which managed all ports.
There's only one instance of a virtio device created, and this device hosts multiple ports. And VirIOConsole is the master structure.
But instead of this, you should have a separate structure for the master one, if that way you can avoid the static instance.
Quoted 17 lines · Blue Swirl
Quoted 16 lines · Amit Shah
Quoted 16 lines
Quoted 15 lines
Quoted 11 lines
Quoted 8 lines
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
+VirtIOConsole virtconsole;
IMHO this is going to wrong direction. What kind of code would need a static instance?
Adding multiple ports to the console device, we'll have to store an array of ports here as well as config space. Both of these are device-specific.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
There could be a master device which managed all ports.
There's only one instance of a virtio device created, and this device hosts multiple ports. And VirIOConsole is the master structure.
But instead of this, you should have a separate structure for the master one, if that way you can avoid the static instance.
The problem with that is that the config space and the ports array have to be made static anyway (because they get used at command-line parsing time, before the virtio-console init function is called). So there's no net gain for doing it that way and we're just keeping things outside of the struct. And that doesn't fit well with the new proposed VMState handlers.
Amit
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 14 lines · Juan Quintela
Quoted 7 lines
Quoted 6 lines
Quoted 3 lines
There's only one instance of a virtio device created, and this device hosts multiple ports. And VirIOConsole is the master structure.
But instead of this, you should have a separate structure for the master one, if that way you can avoid the static instance.
Quoted 6 lines
The problem with that is that the config space and the ports array have to be made static anyway (because they get used at command-line parsing time, before the virtio-console init function is called). So there's no net gain for doing it that way and we're just keeping things outside of the struct. And that doesn't fit well with the new proposed VMState handlers.
Quoted 3 lines
I haven't looked at that, but qdev should help here.
There has to be a way to create multiple devices from the command line, or qdev is doomed :)
We don't want multiple devices; just one virtio-console device with several ports.
Quoted 2 lines
What I haven't looked is at what part of how virt-console share the ports.
Share the ports in what sense?
Amit
Quoted 9 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
Signed-off-by Amit Shah <[email protected]>
This seems bad. Even though the device is multiport capable, we should still supporting having multiple devices per guest.
I think Gerd would suggest this is a use-case for capabilities. I'm not sure we have a similar device that can take multiple char drivers.
Maybe we ought to treat virtio-console like a bus? Do you have any suggestions Gerd?
Regards,
Anthony Liguori
Quoted 5 lines · Anthony Liguori
Quoted 2 lines
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.Maybe we ought to treat virtio-console like a bus? Do you have any suggestions Gerd?
i.e. the virtio-console pci devices provides some virtual qdev bus (say vmch), then each port is modeled as separate qdev device for that bus? I think that handles it pretty nicely.
cheers,
Gerd
Quoted 8 lines · Anthony Liguori
Quoted 7 lines · Amit Shah
Currently the VirtIOConsole struct is allocated from the call to
virtio_common_init, also doing anUP_CASTimplicitly.The new multiport functionality will need a few arrays and it's easier to move to the new VMState infrastructure by keeping it all within one struct.
Quoted 5 lines
Quoted 2 lines
Signed-off-by Amit Shah <[email protected]>This seems bad. Even though the device is multiport capable, we should still supporting having multiple devices per guest.
OK; so I'll drop this for now. I'd much rather we get the multiple ports patch in first and then add support for multiple devices.
Amit