blob: b976f6f9edfd0d8c7f2ef5172a3e74ef86b6001a [file] [log] [blame]
Andrew Walbrand0ef4002022-05-16 16:14:10 +00001// Copyright 2022, The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::fmt::{self, Debug, Display, Formatter};
16use android_system_virtualizationservice::{
17 aidl::android::system::virtualizationservice::{
18 DeathReason::DeathReason as AidlDeathReason}};
19
20/// The reason why a VM died.
21#[derive(Clone, Copy, Debug, Eq, PartialEq)]
22pub enum DeathReason {
23 /// VirtualizationService died.
24 VirtualizationServiceDied,
25 /// There was an error waiting for the VM.
26 InfrastructureError,
27 /// The VM was killed.
28 Killed,
29 /// The VM died for an unknown reason.
30 Unknown,
31 /// The VM requested to shut down.
32 Shutdown,
33 /// crosvm had an error starting the VM.
34 Error,
35 /// The VM requested to reboot, possibly as the result of a kernel panic.
36 Reboot,
37 /// The VM or crosvm crashed.
38 Crash,
39 /// The pVM firmware failed to verify the VM because the public key doesn't match.
40 PvmFirmwarePublicKeyMismatch,
41 /// The pVM firmware failed to verify the VM because the instance image changed.
42 PvmFirmwareInstanceImageChanged,
43 /// The bootloader failed to verify the VM because the public key doesn't match.
44 BootloaderPublicKeyMismatch,
45 /// The bootloader failed to verify the VM because the instance image changed.
46 BootloaderInstanceImageChanged,
Jiyong Parke6ed0f92022-06-22 00:13:00 +090047 /// The microdroid failed to connect to VirtualizationService's RPC server.
48 MicrodroidFailedToConnectToVirtualizationService,
49 /// The payload for microdroid is changed.
50 MicrodroidPayloadHasChanged,
51 /// The microdroid failed to verify given payload APK.
52 MicrodroidPayloadVerificationFailed,
53 /// The VM config for microdroid is invalid (e.g. missing tasks).
54 MicrodroidInvalidPayloadConfig,
55 /// There was a runtime error while running microdroid manager.
56 MicrodroidUnknownRuntimeError,
57 /// The VM was killed due to hangup.
58 Hangup,
Andrew Walbrand0ef4002022-05-16 16:14:10 +000059 /// VirtualizationService sent a death reason which was not recognised by the client library.
60 Unrecognised(AidlDeathReason),
61}
62
63impl From<AidlDeathReason> for DeathReason {
64 fn from(reason: AidlDeathReason) -> Self {
65 match reason {
66 AidlDeathReason::INFRASTRUCTURE_ERROR => Self::InfrastructureError,
67 AidlDeathReason::KILLED => Self::Killed,
68 AidlDeathReason::UNKNOWN => Self::Unknown,
69 AidlDeathReason::SHUTDOWN => Self::Shutdown,
70 AidlDeathReason::ERROR => Self::Error,
71 AidlDeathReason::REBOOT => Self::Reboot,
72 AidlDeathReason::CRASH => Self::Crash,
73 AidlDeathReason::PVM_FIRMWARE_PUBLIC_KEY_MISMATCH => Self::PvmFirmwarePublicKeyMismatch,
74 AidlDeathReason::PVM_FIRMWARE_INSTANCE_IMAGE_CHANGED => {
75 Self::PvmFirmwareInstanceImageChanged
76 }
77 AidlDeathReason::BOOTLOADER_PUBLIC_KEY_MISMATCH => Self::BootloaderPublicKeyMismatch,
78 AidlDeathReason::BOOTLOADER_INSTANCE_IMAGE_CHANGED => {
79 Self::BootloaderInstanceImageChanged
80 }
Jiyong Parke6ed0f92022-06-22 00:13:00 +090081 AidlDeathReason::MICRODROID_FAILED_TO_CONNECT_TO_VIRTUALIZATION_SERVICE => {
82 Self::MicrodroidFailedToConnectToVirtualizationService
83 }
84 AidlDeathReason::MICRODROID_PAYLOAD_HAS_CHANGED => Self::MicrodroidPayloadHasChanged,
85 AidlDeathReason::MICRODROID_PAYLOAD_VERIFICATION_FAILED => {
86 Self::MicrodroidPayloadVerificationFailed
87 }
88 AidlDeathReason::MICRODROID_INVALID_PAYLOAD_CONFIG => {
89 Self::MicrodroidInvalidPayloadConfig
90 }
91 AidlDeathReason::MICRODROID_UNKNOWN_RUNTIME_ERROR => {
92 Self::MicrodroidUnknownRuntimeError
93 }
94 AidlDeathReason::HANGUP => Self::Hangup,
Andrew Walbrand0ef4002022-05-16 16:14:10 +000095 _ => Self::Unrecognised(reason),
96 }
97 }
98}
99
100impl Display for DeathReason {
101 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
102 let s = match self {
103 Self::VirtualizationServiceDied => "VirtualizationService died.",
104 Self::InfrastructureError => "Error waiting for VM to finish.",
105 Self::Killed => "VM was killed.",
106 Self::Unknown => "VM died for an unknown reason.",
107 Self::Shutdown => "VM shutdown cleanly.",
108 Self::Error => "Error starting VM.",
109 Self::Reboot => "VM tried to reboot, possibly due to a kernel panic.",
110 Self::Crash => "VM crashed.",
111 Self::PvmFirmwarePublicKeyMismatch => {
112 "pVM firmware failed to verify the VM because the public key doesn't match."
113 }
114 Self::PvmFirmwareInstanceImageChanged => {
115 "pVM firmware failed to verify the VM because the instance image changed."
116 }
117 Self::BootloaderPublicKeyMismatch => {
118 "Bootloader failed to verify the VM because the public key doesn't match."
119 }
120 Self::BootloaderInstanceImageChanged => {
121 "Bootloader failed to verify the VM because the instance image changed."
122 }
Jiyong Parke6ed0f92022-06-22 00:13:00 +0900123 Self::MicrodroidFailedToConnectToVirtualizationService => {
124 "The microdroid failed to connect to VirtualizationService's RPC server."
125 }
126 Self::MicrodroidPayloadHasChanged => "The payload for microdroid is changed.",
127 Self::MicrodroidPayloadVerificationFailed => {
128 "The microdroid failed to verify given payload APK."
129 }
130 Self::MicrodroidInvalidPayloadConfig => {
131 "The VM config for microdroid is invalid (e.g. missing tasks)."
132 }
133 Self::MicrodroidUnknownRuntimeError => {
134 "There was a runtime error while running microdroid manager."
135 }
136 Self::Hangup => "VM hangup.",
Andrew Walbrand0ef4002022-05-16 16:14:10 +0000137 Self::Unrecognised(reason) => {
138 return write!(f, "Unrecognised death reason {:?}.", reason);
139 }
140 };
141 f.write_str(s)
142 }
143}