Introduce VIR_DOMAIN_PAUSED_API_ERROR

Some APIs (migration, save/restore, snapshot, ...) require a domain to
be suspended temporarily. In case resuming the domain fails, the domain
will be unexpectedly left paused when the API finishes. This situation
is reported via VIR_DOMAIN_EVENT_SUSPENDED event with
VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR detail. But we do not have a
corresponding reason for VIR_DOMAIN_PAUSED state and the reason would
remain set to the value used when the domain was paused. So the state
reason would suggest the operation is still running.

This patch changes the state reason to a new VIR_DOMAIN_PAUSED_API_ERROR
to make it clear the API that paused the domain already finished, but
failed to resume the domain.

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Jiri Denemark 2023-02-28 16:53:29 +01:00
parent 6414046e9c
commit b1b037fa5b
6 changed files with 22 additions and 0 deletions

View File

@ -148,6 +148,7 @@ typedef enum {
VIR_DOMAIN_PAUSED_STARTING_UP = 11, /* the domain is being started (Since: 1.2.14) */ VIR_DOMAIN_PAUSED_STARTING_UP = 11, /* the domain is being started (Since: 1.2.14) */
VIR_DOMAIN_PAUSED_POSTCOPY = 12, /* paused for post-copy migration (Since: 1.3.3) */ VIR_DOMAIN_PAUSED_POSTCOPY = 12, /* paused for post-copy migration (Since: 1.3.3) */
VIR_DOMAIN_PAUSED_POSTCOPY_FAILED = 13, /* paused after failed post-copy (Since: 1.3.3) */ VIR_DOMAIN_PAUSED_POSTCOPY_FAILED = 13, /* paused after failed post-copy (Since: 1.3.3) */
VIR_DOMAIN_PAUSED_API_ERROR = 14, /* Some APIs (e.g., migration, snapshot) internally need to suspend a domain. This paused state reason is used when resume operation at the end of such API fails. (Since: 9.2.0) */
# ifdef VIR_ENUM_SENTINELS # ifdef VIR_ENUM_SENTINELS
VIR_DOMAIN_PAUSED_LAST /* (Since: 0.9.10) */ VIR_DOMAIN_PAUSED_LAST /* (Since: 0.9.10) */

View File

@ -1163,6 +1163,7 @@ VIR_ENUM_IMPL(virDomainPausedReason,
"starting up", "starting up",
"post-copy", "post-copy",
"post-copy failed", "post-copy failed",
"api error",
); );
VIR_ENUM_IMPL(virDomainShutdownReason, VIR_ENUM_IMPL(virDomainShutdownReason,

View File

@ -11376,6 +11376,9 @@ qemuDomainPausedReasonToSuspendedEvent(virDomainPausedReason reason)
case VIR_DOMAIN_PAUSED_POSTCOPY: case VIR_DOMAIN_PAUSED_POSTCOPY:
return VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY; return VIR_DOMAIN_EVENT_SUSPENDED_POSTCOPY;
case VIR_DOMAIN_PAUSED_API_ERROR:
return VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR;
case VIR_DOMAIN_PAUSED_UNKNOWN: case VIR_DOMAIN_PAUSED_UNKNOWN:
case VIR_DOMAIN_PAUSED_USER: case VIR_DOMAIN_PAUSED_USER:
case VIR_DOMAIN_PAUSED_SAVE: case VIR_DOMAIN_PAUSED_SAVE:

View File

@ -2727,6 +2727,10 @@ qemuDomainSaveInternal(virQEMUDriver *driver,
virDomainEventLifecycleNewFromObj(vm, virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR)); VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR));
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_API_ERROR);
}
} }
virErrorRestore(&save_err); virErrorRestore(&save_err);
} }
@ -3254,6 +3258,10 @@ qemuDomainCoreDumpWithFormat(virDomainPtr dom,
event = virDomainEventLifecycleNewFromObj(vm, event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR); VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_API_ERROR);
}
if (virGetLastErrorCode() == VIR_ERR_OK) if (virGetLastErrorCode() == VIR_ERR_OK)
virReportError(VIR_ERR_OPERATION_FAILED, virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("resuming after dump failed")); "%s", _("resuming after dump failed"));

View File

@ -326,6 +326,10 @@ qemuSnapshotCreateActiveInternal(virQEMUDriver *driver,
event = virDomainEventLifecycleNewFromObj(vm, event = virDomainEventLifecycleNewFromObj(vm,
VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR); VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_API_ERROR);
}
if (virGetLastErrorCode() == VIR_ERR_OK) { if (virGetLastErrorCode() == VIR_ERR_OK) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("resuming after snapshot failed")); _("resuming after snapshot failed"));
@ -1398,6 +1402,10 @@ qemuSnapshotCreateActiveExternal(virQEMUDriver *driver,
VIR_DOMAIN_EVENT_SUSPENDED, VIR_DOMAIN_EVENT_SUSPENDED,
VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR); VIR_DOMAIN_EVENT_SUSPENDED_API_ERROR);
virObjectEventStateQueue(driver->domainEventState, event); virObjectEventStateQueue(driver->domainEventState, event);
if (virDomainObjGetState(vm, NULL) == VIR_DOMAIN_PAUSED) {
virDomainObjSetState(vm, VIR_DOMAIN_PAUSED,
VIR_DOMAIN_PAUSED_API_ERROR);
}
if (virGetLastErrorCode() == VIR_ERR_OK) { if (virGetLastErrorCode() == VIR_ERR_OK) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("resuming after snapshot failed")); _("resuming after snapshot failed"));

View File

@ -192,6 +192,7 @@ VIR_ENUM_IMPL(virshDomainPausedReason,
N_("starting up"), N_("starting up"),
N_("post-copy"), N_("post-copy"),
N_("post-copy failed"), N_("post-copy failed"),
N_("api error"),
); );
VIR_ENUM_DECL(virshDomainShutdownReason); VIR_ENUM_DECL(virshDomainShutdownReason);