[libvirt] [libvirt-glib 1/2] gobject: Handle PMSUSPENDED state from libvirt

Emit a signal when switching to the PMSUSPENDED state, and add an enum entry to describe this state. This avoids runtime warnings with newer libvirt. --- libvirt-gobject/libvirt-gobject-connection.c | 7 +++++++ libvirt-gobject/libvirt-gobject-domain.c | 11 +++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 19 +++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index 428ae38..ad7aa07 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -389,6 +389,13 @@ static int domain_event_cb(virConnectPtr conn G_GNUC_UNUSED, case VIR_DOMAIN_EVENT_SHUTDOWN: break; + case VIR_DOMAIN_EVENT_PMSUSPENDED: + if (detail == VIR_DOMAIN_EVENT_PMSUSPENDED_MEMORY) + g_signal_emit_by_name(gdom, "pmsuspended::memory"); + else + g_warn_if_reached(); + break; + default: g_warn_if_reached(); } diff --git a/libvirt-gobject/libvirt-gobject-domain.c b/libvirt-gobject/libvirt-gobject-domain.c index bcfad2a..f8ad493 100644 --- a/libvirt-gobject/libvirt-gobject-domain.c +++ b/libvirt-gobject/libvirt-gobject-domain.c @@ -55,6 +55,7 @@ enum { VIR_RESUMED, VIR_STOPPED, VIR_UPDATED, + VIR_PMSUSPENDED, LAST_SIGNAL }; @@ -225,6 +226,16 @@ static void gvir_domain_class_init(GVirDomainClass *klass) G_TYPE_NONE, 0); + signals[VIR_PMSUSPENDED] = g_signal_new("pmsuspended", + G_OBJECT_CLASS_TYPE(object_class), + G_SIGNAL_RUN_LAST | G_SIGNAL_NO_RECURSE | + G_SIGNAL_NO_HOOKS | G_SIGNAL_DETAILED, + G_STRUCT_OFFSET(GVirDomainClass, pmsuspended), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); + g_type_class_add_private(klass, sizeof(GVirDomainPrivate)); } diff --git a/libvirt-gobject/libvirt-gobject-domain.h b/libvirt-gobject/libvirt-gobject-domain.h index 7810d1b..fc2db7c 100644 --- a/libvirt-gobject/libvirt-gobject-domain.h +++ b/libvirt-gobject/libvirt-gobject-domain.h @@ -66,19 +66,22 @@ struct _GVirDomainClass void (*resumed)(GVirDomain *dom); void (*updated)(GVirDomain *dom); void (*suspended)(GVirDomain *dom); + void (*pmsuspended)(GVirDomain *dom); - gpointer padding[20]; + gpointer padding[19]; }; typedef enum { - GVIR_DOMAIN_STATE_NONE = 0, /* no state */ - GVIR_DOMAIN_STATE_RUNNING = 1, /* the domain is running */ - GVIR_DOMAIN_STATE_BLOCKED = 2, /* the domain is blocked on resource */ - GVIR_DOMAIN_STATE_PAUSED = 3, /* the domain is paused by user */ - GVIR_DOMAIN_STATE_SHUTDOWN= 4, /* the domain is being shut down */ - GVIR_DOMAIN_STATE_SHUTOFF = 5, /* the domain is shut off */ - GVIR_DOMAIN_STATE_CRASHED = 6 /* the domain is crashed */ + GVIR_DOMAIN_STATE_NONE = 0, /* no state */ + GVIR_DOMAIN_STATE_RUNNING = 1, /* the domain is running */ + GVIR_DOMAIN_STATE_BLOCKED = 2, /* the domain is blocked on resource */ + GVIR_DOMAIN_STATE_PAUSED = 3, /* the domain is paused by user */ + GVIR_DOMAIN_STATE_SHUTDOWN= 4, /* the domain is being shut down */ + GVIR_DOMAIN_STATE_SHUTOFF = 5, /* the domain is shut off */ + GVIR_DOMAIN_STATE_CRASHED = 6, /* the domain is crashed */ + GVIR_DOMAIN_STATE_PMSUSPENDED = 7 /* the domain is suspended by guest + power management */ } GVirDomainState; -- 1.7.11.4

This avoids a runtime warning about this kind of event not being handled. --- libvirt-gobject/libvirt-gobject-connection.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libvirt-gobject/libvirt-gobject-connection.c b/libvirt-gobject/libvirt-gobject-connection.c index ad7aa07..9628989 100644 --- a/libvirt-gobject/libvirt-gobject-connection.c +++ b/libvirt-gobject/libvirt-gobject-connection.c @@ -327,6 +327,8 @@ static int domain_event_cb(virConnectPtr conn G_GNUC_UNUSED, g_signal_emit_by_name(gdom, "started::restored"); else if (detail == VIR_DOMAIN_EVENT_STARTED_FROM_SNAPSHOT) g_signal_emit_by_name(gdom, "started::from-snapshot"); + else if (detail == VIR_DOMAIN_EVENT_STARTED_WAKEUP) + g_signal_emit_by_name(gdom, "started::wakeup"); else g_warn_if_reached(); break; -- 1.7.11.4

On 28.09.2012 19:01, Christophe Fergeau wrote:
This avoids a runtime warning about this kind of event not being handled. --- libvirt-gobject/libvirt-gobject-connection.c | 2 ++ 1 file changed, 2 insertions(+)
ACK Michal

On 28.09.2012 19:01, Christophe Fergeau wrote:
Emit a signal when switching to the PMSUSPENDED state, and add an enum entry to describe this state. This avoids runtime warnings with newer libvirt. --- libvirt-gobject/libvirt-gobject-connection.c | 7 +++++++ libvirt-gobject/libvirt-gobject-domain.c | 11 +++++++++++ libvirt-gobject/libvirt-gobject-domain.h | 19 +++++++++++-------- 3 files changed, 29 insertions(+), 8 deletions(-)
ACK Michal

On Fri, Sep 28, 2012 at 07:01:23PM +0200, Christophe Fergeau wrote:
Emit a signal when switching to the PMSUSPENDED state, and add an enum entry to describe this state. This avoids runtime warnings with newer libvirt.
This also breaks compilation with older libvirt, so we need to either bump our libvirt requirement to 0.10.2 or to add conditional compilation of this code. I'd go for the former, especially as 0.10.2 has various mainloop/event fixes compared to 0.9.10 we are currently depending on, but before sending a patch I wanted to check if people prefer the latter to be done. Christophe
participants (2)
-
Christophe Fergeau
-
Michal Privoznik