Skip to contentSkip to conversation

virtio-balloon: fix dynamic properties.

PATCH Superseded [email protected] 2 participants 6 messages Apr 11, 2013 – Apr 12, 2013

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio-balloon: fix dynamic properties.

From: KONRAD Frederic <[email protected]>

To keep compatibility with the old virtio-balloon-x, add the dynamic properties to virtio-balloon-pci and virtio-balloon-ccw.

---
 hw/s390x/virtio-ccw.c              |  8 ++++++++
 hw/virtio/virtio-balloon.c         | 16 ++++++++--------
 hw/virtio/virtio-pci.c             |  8 ++++++++
 include/hw/virtio/virtio-balloon.h |  9 +++++++++
 4 files changed, 33 insertions(+), 8 deletions(-)
hw/s390x/virtio-ccw.c +8 -0
index 4dec0cd..ea5ed6d 100644
@@ -626,6 +626,14 @@ static void virtio_ccw_balloon_instance_init(Object *obj)
     VirtIOBalloonCcw *dev = VIRTIO_BALLOON_CCW(obj);
     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON);
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+
+    object_property_add(obj, "guest-stats", "guest statistics",
+                        balloon_stats_get_all, NULL, NULL, &dev->vdev, NULL);
+
+    object_property_add(obj, "guest-stats-polling-interval", "int",
+                        balloon_stats_get_poll_interval,
+                        balloon_stats_set_poll_interval,
+                        NULL, &dev->vdev, NULL);
 }
 
 static int virtio_ccw_scsi_init(VirtioCcwDevice *ccw_dev)
hw/virtio/virtio-balloon.c +8 -8
index c2c446e..2e2ea30 100644
@@ -105,8 +105,8 @@ static void balloon_stats_poll_cb(void *opaque)
     virtio_notify(vdev, s->svq);
 }
 
-static void balloon_stats_get_all(Object *obj, struct Visitor *v,
-                                  void *opaque, const char *name, Error **errp)
+void balloon_stats_get_all(Object *obj, struct Visitor *v, void *opaque,
+                           const char *name, Error **errp)
 {
     VirtIOBalloon *s = opaque;
     int i;
@@ -129,17 +129,17 @@ static void balloon_stats_get_all(Object *obj, struct Visitor *v,
     visit_end_struct(v, errp);
 }
 
-static void balloon_stats_get_poll_interval(Object *obj, struct Visitor *v,
-                                            void *opaque, const char *name,
-                                            Error **errp)
+void balloon_stats_get_poll_interval(Object *obj, struct Visitor *v,
+                                     void *opaque, const char *name,
+                                     Error **errp)
 {
     VirtIOBalloon *s = opaque;
     visit_type_int(v, &s->stats_poll_interval, name, errp);
 }
 
-static void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
-                                            void *opaque, const char *name,
-                                            Error **errp)
+void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
+                                     void *opaque, const char *name,
+                                     Error **errp)
 {
     VirtIOBalloon *s = opaque;
     int64_t value;
hw/virtio/virtio-pci.c +8 -0
index 2b22588..9a3d291 100644
@@ -1450,6 +1450,14 @@ static void virtio_balloon_pci_instance_init(Object *obj)
     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
     object_initialize(OBJECT(&dev->vdev), TYPE_VIRTIO_BALLOON);
     object_property_add_child(obj, "virtio-backend", OBJECT(&dev->vdev), NULL);
+
+    object_property_add(obj, "guest-stats", "guest statistics",
+                        balloon_stats_get_all, NULL, NULL, &dev->vdev, NULL);
+
+    object_property_add(obj, "guest-stats-polling-interval", "int",
+                        balloon_stats_get_poll_interval,
+                        balloon_stats_set_poll_interval,
+                        NULL, &dev->vdev, NULL);
 }
 
 static const TypeInfo virtio_balloon_pci_info = {
include/hw/virtio/virtio-balloon.h +9 -0
index 3b459bb..023d0f0 100644
@@ -69,4 +69,13 @@ typedef struct VirtIOBalloon {
     int64_t stats_poll_interval;
 } VirtIOBalloon;
 
+void balloon_stats_get_all(Object *obj, struct Visitor *v, void *opaque,
+                           const char *name, Error **errp);
+void balloon_stats_get_poll_interval(Object *obj, struct Visitor *v,
+                                     void *opaque, const char *name,
+                                     Error **errp);
+void balloon_stats_set_poll_interval(Object *obj, struct Visitor *v,
+                                     void *opaque, const char *name,
+                                     Error **errp);
+
 #endif
Signature · 1 line
1.8.1.4
#1 lore raw
Quoted 4 lines · On 11 April 2013 23:38, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

To keep compatibility with the old virtio-balloon-x, add the dynamic properties to virtio-balloon-pci and virtio-balloon-ccw.

Does the approach I suggested on IRC where virtio-balloon-pci's property set/get callbacks just set/get the property on virtio-balloon via the public interface not work? Having to expose virtio-balloon's callback functions seems a bit of an encapsulation violation...

thanks
-- PMM

#2 lore raw
Quoted 5 lines · Peter Maydell
Quoted 4 lines · On 11 April 2013 23:38, <[email protected]> wrote:

From: KONRAD Frederic <[email protected]>

To keep compatibility with the old virtio-balloon-x, add the dynamic properties to virtio-balloon-pci and virtio-balloon-ccw.

Quoted 8 lines

Does the approach I suggested on IRC where virtio-balloon-pci's property set/get callbacks just set/get the property on virtio-balloon via the public interface not work? Having to expose virtio-balloon's callback functions seems a bit of an encapsulation violation...

thanks
-- PMM

Oh, I didn't understand that like that.

What do you mean by the public interface?

I thought you wanted two set/get callbacks which call directly virtio-balloon callbacks.

Thanks,
Fred

#3 lore raw
Quoted 10 lines · KONRAD Frédéric
Quoted 5 lines · Peter Maydell

Does the approach I suggested on IRC where virtio-balloon-pci's property set/get callbacks just set/get the property on virtio-balloon via the public interface not work? Having to expose virtio-balloon's callback functions seems a bit of an encapsulation violation...

Oh, I didn't understand that like that.

What do you mean by the public interface?

I mean the interface that any user of an object should use to access properties, ie object_property_set() and object_property_get(). Something like:

static void balloon_pci_fwd_get(Object *obj,
struct Visitor *v, void *opaque, const char *name, Error **errp)

{
    VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
    object_property_get(OBJECT(&dev->vdev), v, name, errp);
}

Ditto for fwd_set; note that you can use the same accessors for any property you need to forward to the underlying virtio-balloon-device. Untested :-)

-- PMM

#4 lore raw
Quoted 21 lines · Peter Maydell
Quoted 9 lines · KONRAD Frédéric
Quoted 5 lines · Peter Maydell

Does the approach I suggested on IRC where virtio-balloon-pci's property set/get callbacks just set/get the property on virtio-balloon via the public interface not work? Having to expose virtio-balloon's callback functions seems a bit of an encapsulation violation...

Oh, I didn't understand that like that.

What do you mean by the public interface?

I mean the interface that any user of an object should use to access properties, ie object_property_set() and object_property_get(). Something like:

static void balloon_pci_fwd_get(Object *obj,
struct Visitor *v, void *opaque, const char *name, Error **errp)

{
     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
     object_property_get(OBJECT(&dev->vdev), v, name, errp);
}
Quoted 5 lines

Ditto for fwd_set; note that you can use the same accessors for any property you need to forward to the underlying virtio-balloon-device. Untested :-)

-- PMM

Ok understood,
will fix that.

Thanks,
Fred

#5 lore raw
In reply to Peter Maydell
Quoted 21 lines · Peter Maydell
Quoted 9 lines · KONRAD Frédéric
Quoted 5 lines · Peter Maydell

Does the approach I suggested on IRC where virtio-balloon-pci's property set/get callbacks just set/get the property on virtio-balloon via the public interface not work? Having to expose virtio-balloon's callback functions seems a bit of an encapsulation violation...

Oh, I didn't understand that like that.

What do you mean by the public interface?

I mean the interface that any user of an object should use to access properties, ie object_property_set() and object_property_get(). Something like:

static void balloon_pci_fwd_get(Object *obj,
struct Visitor *v, void *opaque, const char *name, Error **errp)

{
     VirtIOBalloonPCI *dev = VIRTIO_BALLOON_PCI(obj);
     object_property_get(OBJECT(&dev->vdev), v, name, errp);
}
Quoted 5 lines

Ditto for fwd_set; note that you can use the same accessors for any property you need to forward to the underlying virtio-balloon-device. Untested :-)

-- PMM

Note, I'm having a kind of similar issue with virtio-rng:

virtio-rng-pci have actually a child device named "default-backend".

The logic wants that default-backend is a child of virtio-rng-device but as we want to keep compatibility.

And it's not possible to have this default-backend be a child of virtio-rng-pci and virtio-rng-device at the same time.