Merge "Enrich logs"
diff --git a/virtualizationservice/src/crosvm.rs b/virtualizationservice/src/crosvm.rs
index 13e5c70..00c33ef 100644
--- a/virtualizationservice/src/crosvm.rs
+++ b/virtualizationservice/src/crosvm.rs
@@ -22,12 +22,13 @@
use libc::{sysconf, _SC_CLK_TCK};
use log::{debug, error, info};
use semver::{Version, VersionReq};
-use nix::{fcntl::OFlag, unistd::pipe2};
+use nix::{fcntl::OFlag, unistd::pipe2, unistd::Uid, unistd::User};
use regex::{Captures, Regex};
use rustutils::system_properties;
use shared_child::SharedChild;
use std::borrow::Cow;
use std::cmp::max;
+use std::fmt;
use std::fs::{read_to_string, remove_dir_all, File};
use std::io::{self, Read};
use std::mem;
@@ -249,6 +250,19 @@
payload_state: Mutex<PayloadState>,
/// Represents the condition that payload_state was updated
payload_state_updated: Condvar,
+ /// The human readable name of requester_uid
+ requester_uid_name: String,
+}
+
+impl fmt::Display for VmInstance {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let adj = if self.protected { "Protected" } else { "Non-protected" };
+ write!(
+ f,
+ "{} virtual machine \"{}\" (owner: {}, cid: {})",
+ adj, self.name, self.requester_uid_name, self.cid
+ )
+ }
}
impl VmInstance {
@@ -264,7 +278,11 @@
let cid = config.cid;
let name = config.name.clone();
let protected = config.protected;
- Ok(VmInstance {
+ let requester_uid_name = User::from_uid(Uid::from_raw(requester_uid))
+ .ok()
+ .flatten()
+ .map_or_else(|| format!("{}", requester_uid), |u| u.name);
+ let instance = VmInstance {
vm_state: Mutex::new(VmState::NotStarted { config }),
vm_context,
cid,
@@ -278,7 +296,10 @@
vm_metric: Mutex::new(Default::default()),
payload_state: Mutex::new(PayloadState::Starting),
payload_state_updated: Condvar::new(),
- })
+ requester_uid_name,
+ };
+ info!("{} created", &instance);
+ Ok(instance)
}
/// Starts an instance of `crosvm` to manage the VM. The `crosvm` instance will be killed when
@@ -286,7 +307,11 @@
pub fn start(self: &Arc<Self>) -> Result<(), Error> {
let mut vm_metric = self.vm_metric.lock().unwrap();
vm_metric.start_timestamp = Some(SystemTime::now());
- self.vm_state.lock().unwrap().start(self.clone())
+ let ret = self.vm_state.lock().unwrap().start(self.clone());
+ if ret.is_ok() {
+ info!("{} started", &self);
+ }
+ ret.with_context(|| format!("{} failed to start", &self))
}
/// Monitors the exit of the VM (i.e. termination of the `child` process). When that happens,
@@ -310,6 +335,7 @@
*vm_state = VmState::Dead;
// Ensure that the mutex is released before calling the callbacks.
drop(vm_state);
+ info!("{} exited", &self);
// Read the pipe to see if any failure reason is written
let mut failure_reason = String::new();