[PATCH v3 1/2] libvirt: support memory failure event

Michal Privoznik mprivozn at redhat.com
Thu Oct 22 16:59:59 UTC 2020


On 10/14/20 12:37 PM, zhenwei pi wrote:
> Introduce memory failure event. Libvirt should monitor domain's
> event, then posts it to uplayer. According to the hardware memory
> corrupted message, a cloud scheduler could migrate domain to another
> health physical server.
> 
> Several changes in this patch:
> public API:
>      include/*
>      src/conf/*
>      src/remote/*
>      src/remote_protocol-structs
> 
> client:
>      examples/c/misc/event-test.c
>      tools/virsh-domain.c
> 
> With this patch, each driver could implement its own method to run
> this new event.
> 
> Signed-off-by: zhenwei pi <pizhenwei at bytedance.com>
> ---
>   include/libvirt/libvirt-domain.h    | 82 +++++++++++++++++++++++++++++++++++++
>   src/conf/domain_event.c             | 80 ++++++++++++++++++++++++++++++++++++
>   src/conf/domain_event.h             | 12 ++++++
>   src/libvirt_private.syms            |  2 +
>   src/remote/remote_daemon_dispatch.c | 32 +++++++++++++++
>   src/remote/remote_driver.c          | 32 +++++++++++++++
>   src/remote/remote_protocol.x        | 16 +++++++-
>   src/remote_protocol-structs         |  8 ++++
>   examples/c/misc/event-test.c        | 16 ++++++++
>   tools/virsh-domain.c                | 40 ++++++++++++++++++
>   10 files changed, 319 insertions(+), 1 deletion(-)
> 
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index 77f9116675..5138843a56 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -3196,6 +3196,64 @@ typedef enum {
>   } virDomainEventCrashedDetailType;
>   
>   /**
> + * virDomainMemoryFailureRecipientType:
> + *
> + * Recipient of a memory failure event.
> + */
> +typedef enum {
> +    /* memory failure at hypersivor memory address space */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_RECIPIENT_HYPERVISOR = 0,
> +
> +    /* memory failure at guest memory address space */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_RECIPIENT_GUEST = 1,
> +
> +# ifdef VIR_ENUM_SENTINELS
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_RECIPIENT_LAST
> +# endif
> +} virDomainMemoryFailureRecipientType;
> +
> +
> +/**
> + * virDomainMemoryFailureActionType:
> + *
> + * Action of a memory failure event.
> + */
> +typedef enum {
> +    /* the memory failure could be ignored. This will only be the case for
> +     * action-optional failures. */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_IGNORE = 0,
> +
> +    /* memory failure occurred in guest memory, the guest enabled MCE handling
> +     * mechanism, and hypervisor could inject the MCE into the guest
> +     * successfully. */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_INJECT = 1,
> +
> +    /* the failure is unrecoverable.  This occurs for action-required failures
> +     * if the recipient is the hypervisor; hypervisor will exit. */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_FATAL = 2,
> +
> +    /* the failure is unrecoverable but confined to the guest. This occurs if
> +     * the recipient is a guest which is not ready to handle memory failures. */
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_RESET = 3,
> +
> +# ifdef VIR_ENUM_SENTINELS
> +    VIR_DOMAIN_EVENT_MEMORY_FAILURE_ACTION_LAST
> +# endif
> +} virDomainMemoryFailureActionType;
> +
> +
> +typedef enum {
> +    /* whether a memory failure event is action-required or action-optional
> +     * (e.g. a failure during memory scrub). */
> +    VIR_DOMAIN_MEMORY_FAILURE_ACTION_REQUIRED = (1 << 0),
> +
> +    /* whether the failure occurred while the previous failure was still in
> +     * progress. */
> +    VIR_DOMAIN_MEMORY_FAILURE_RECURSIVE = (1 << 1),
> +} virDomainMemoryFailureFlags;
> +
> +
> +/**
>    * virConnectDomainEventCallback:
>    * @conn: virConnect connection
>    * @dom: The domain on which the event occurred
> @@ -4565,6 +4623,29 @@ typedef void (*virConnectDomainEventBlockThresholdCallback)(virConnectPtr conn,
>                                                               void *opaque);
>   
>   /**
> + * virConnectDomainEventMemoryFailureCallback:
> + * @conn: connection object
> + * @dom: domain on which the event occurred
> + * @recipient: the recipient of hardware memory failure
> + * @action: the action of hardware memory failure
> + * @flags: the flags of hardware memory failure
> + * @opaque: application specified data
> + *
> + * The callback occurs when the hypervisor handles the hardware memory
> + * corrupted event.
> + *
> + * The callback signature to use when registering for an event of type
> + * VIR_DOMAIN_EVENT_ID_MEMORY_FAILURE with virConnectDomainEventRegisterAny()
> + */
> +typedef void (*virConnectDomainEventMemoryFailureCallback)(virConnectPtr conn,
> +                                                           virDomainPtr dom,
> +                                                           virDomainMemoryFailureRecipientType recipient,
> +                                                           virDomainMemoryFailureActionType action,

While this works for now, it's not as future proof as it could be. We 
try to avoid enums in public APIs because if we ever add a new member 
into the enum its size might change and thus break the ABI. Use 'int' 
instead. That is also the reason why we use int on the RPC level. Then 
we merely document in the comment what enum to expect for each argument.

> +                                                           unsigned int flags,
> +                                                           void *opaque);


Therefore, I suggest this to be squashed in (no need to resend, I can 
fix locally, just want you to confirm you're okay with the change):

diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c
index 1651efe019..f164e825e1 100644
--- a/examples/c/misc/event-test.c
+++ b/examples/c/misc/event-test.c
@@ -966,8 +966,8 @@ myDomainEventBlockThresholdCallback(virConnectPtr 
conn G_GNUC_UNUSED,
  static int
  myDomainEventMemoryFailureCallback(virConnectPtr conn G_GNUC_UNUSED,
                                     virDomainPtr dom,
-                                   virDomainMemoryFailureRecipientType 
recipient,
-                                   virDomainMemoryFailureActionType action,
+                                   int recipient,
+                                   int action,
                                     unsigned int flags,
                                     void *opaque G_GNUC_UNUSED)
  {
diff --git a/include/libvirt/libvirt-domain.h 
b/include/libvirt/libvirt-domain.h
index 5138843a56..b3310729bf 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4627,7 +4627,9 @@ typedef void 
(*virConnectDomainEventBlockThresholdCallback)(virConnectPtr conn,
   * @conn: connection object
   * @dom: domain on which the event occurred
   * @recipient: the recipient of hardware memory failure
+ *             (virDomainMemoryFailureRecipientType)
   * @action: the action of hardware memory failure
+ *          (virDomainMemoryFailureActionType)
   * @flags: the flags of hardware memory failure
   * @opaque: application specified data
   *
@@ -4639,8 +4641,8 @@ typedef void 
(*virConnectDomainEventBlockThresholdCallback)(virConnectPtr conn,
   */
  typedef void 
(*virConnectDomainEventMemoryFailureCallback)(virConnectPtr conn,
 
virDomainPtr dom,
- 
virDomainMemoryFailureRecipientType recipient,
- 
virDomainMemoryFailureActionType action,
+                                                           int recipient,
+                                                           int action,
                                                             unsigned 
int flags,
                                                             void *opaque);

diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 4a6051a6ab..0fde3481ed 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -292,8 +292,8 @@ typedef virDomainEventBlockThreshold 
*virDomainEventBlockThresholdPtr;
  struct _virDomainEventMemoryFailure {
      virDomainEvent parent;

-    virDomainMemoryFailureRecipientType recipient;
-    virDomainMemoryFailureActionType action;
+    int recipient;
+    int action;
      unsigned int flags;
  };
  typedef struct _virDomainEventMemoryFailure virDomainEventMemoryFailure;
@@ -1644,8 +1644,8 @@ static virObjectEventPtr
  virDomainEventMemoryFailureNew(int id,
                                 const char *name,
                                 unsigned char *uuid,
-                               virDomainMemoryFailureRecipientType 
recipient,
-                               virDomainMemoryFailureActionType action,
+                               int recipient,
+                               int action,
                                 unsigned int flags)
  {
      virDomainEventMemoryFailurePtr ev;
@@ -1667,8 +1667,8 @@ virDomainEventMemoryFailureNew(int id,

  virObjectEventPtr
  virDomainEventMemoryFailureNewFromObj(virDomainObjPtr obj,
- 
virDomainMemoryFailureRecipientType recipient,
-                                      virDomainMemoryFailureActionType 
action,
+                                      int recipient,
+                                      int action,
                                        unsigned int flags)
  {
      return virDomainEventMemoryFailureNew(obj->def->id, obj->def->name,
@@ -1678,8 +1678,8 @@ 
virDomainEventMemoryFailureNewFromObj(virDomainObjPtr obj,

  virObjectEventPtr
  virDomainEventMemoryFailureNewFromDom(virDomainPtr dom,
- 
virDomainMemoryFailureRecipientType recipient,
-                                      virDomainMemoryFailureActionType 
action,
+                                      int recipient,
+                                      int action,
                                        unsigned int flags)
  {
      return virDomainEventMemoryFailureNew(dom->id, dom->name, dom->uuid,
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 1d001e164e..13a1c56ce1 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -257,14 +257,14 @@ 
virDomainEventBlockThresholdNewFromDom(virDomainPtr dom,

  virObjectEventPtr
  virDomainEventMemoryFailureNewFromObj(virDomainObjPtr obj,
- 
virDomainMemoryFailureRecipientType recipient,
-                                      virDomainMemoryFailureActionType 
action,
+                                      int recipient,
+                                      int action,
                                        unsigned int flags);

  virObjectEventPtr
  virDomainEventMemoryFailureNewFromDom(virDomainPtr dom,
- 
virDomainMemoryFailureRecipientType recipient,
-                                      virDomainMemoryFailureActionType 
action,
+                                      int recipient,
+                                      int action,
                                        unsigned int flags);

  int
diff --git a/src/remote/remote_daemon_dispatch.c 
b/src/remote/remote_daemon_dispatch.c
index 078467f8da..eb5f6ebb0c 100644
--- a/src/remote/remote_daemon_dispatch.c
+++ b/src/remote/remote_daemon_dispatch.c
@@ -1305,8 +1305,8 @@ remoteRelayDomainEventBlockThreshold(virConnectPtr 
conn,
  static int
  remoteRelayDomainEventMemoryFailure(virConnectPtr conn,
                                      virDomainPtr dom,
-                                    virDomainMemoryFailureRecipientType 
recipient,
-                                    virDomainMemoryFailureActionType 
action,
+                                    int recipient,
+                                    int action,
                                      unsigned int flags,
                                      void *opaque)
  {
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4040f0d1e7..ef347585e8 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -13608,8 +13608,8 @@ VIR_ENUM_IMPL(virshEventMemoryFailureActionType,
  static void
  virshEventMemoryFailurePrint(virConnectPtr conn G_GNUC_UNUSED,
                               virDomainPtr dom,
-                             virDomainMemoryFailureRecipientType recipient,
-                             virDomainMemoryFailureActionType action,
+                             int recipient,
+                             int action,
                               unsigned int flags,
                               void *opaque)
  {



Michal




More information about the libvir-list mailing list