Skip to content

Switch from syslog to some hostfile-backed mechanism #214

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ devices = { path = "devices" }
net_util = { path = "net_util" }
sys_util = { path = "sys_util" }
vmm = { path = "vmm" }
logger = { path = "logger" }

[workspace]
1 change: 1 addition & 0 deletions devices/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ sys_util = { path = "../sys_util" }
virtio_sys = { path = "../virtio_sys" }
vhost_sys = { path = "../vhost_sys" }
vhost_backend = { path = "../vhost_backend" }
logger = {path = "../logger"}

[dev-dependencies]
data_model = { path = "../data_model"}
5 changes: 2 additions & 3 deletions devices/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
// found in the LICENSE file.

//! Emulates virtual and hardware devices.

extern crate byteorder;
extern crate epoll;
extern crate libc;

#[macro_use]
extern crate logger;
extern crate net_sys;
extern crate net_util;
#[macro_use]
extern crate sys_util;
extern crate vhost_backend;
extern crate vhost_sys;
Expand Down
7 changes: 1 addition & 6 deletions kvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ extern crate libc;

extern crate byteorder;
extern crate kvm_sys;
#[macro_use]
extern crate sys_util;

mod cap;
Expand Down Expand Up @@ -79,12 +78,8 @@ impl Kvm {
/// Gets the recommended maximum number of VCPUs per VM.
pub fn get_nr_vcpus(&self) -> usize {
match self.check_extension_int(Cap::NrVcpus) {
0 => 4, // according to api.txt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this line also go away?

Copy link
Contributor Author

@dianpopa dianpopa Apr 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, the logic before:

  • In case of 0, return 4
  • In case of a positive number return the number
  • In case of anything else, warning and return 4

The logic now:

  • In case of positive number, return the number
  • Anything else, return 4 ( no warning is necessary in case kvm return negative, see api.txt and qemu code); this is why the line with 0 went away

x if x > 0 => x as usize,
_ => {
warn!("kernel returned invalid number of VCPUs");
4
}
_ => 4,
}
}

Expand Down
9 changes: 9 additions & 0 deletions logger/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[package]
name = "logger"
version = "0.1.0"
authors = ["Amazon firecracker team <[email protected]>"]

[dependencies]
libc = ">=0.2.39"
log = { version = "0.4", features = ["std"] }

75 changes: 75 additions & 0 deletions logger/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! Errors returned by the logger.

use std;
use std::error::Error;
use std::fmt;

#[derive(Debug)]
pub enum LoggerError {
/// First attempt at initialization failed.
NeverInitialized(String),
/// Initialization has previously failed and can not be retried.
Poisoned(String),
/// Creating log file fails.
CreateLogFile(std::io::Error),
/// Writing to log file fails.
FileLogWrite(std::io::Error),
/// Flushing to disk fails.
FileLogFlush(std::io::Error),
/// Error obtaining lock on mutex.
FileLogLock(String),
}

impl fmt::Display for LoggerError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let printable = match *self {
LoggerError::NeverInitialized(ref e) => e,
LoggerError::Poisoned(ref e) => e,
LoggerError::CreateLogFile(ref e) => e.description(),
LoggerError::FileLogWrite(ref e) => e.description(),
LoggerError::FileLogFlush(ref e) => e.description(),
LoggerError::FileLogLock(ref e) => e,
};
write!(f, "{}", printable)
}
}

#[cfg(test)]
mod tests {
use super::*;
use std::io::ErrorKind;

#[test]
fn test_formatting() {
assert!(
format!(
"{:?}",
LoggerError::NeverInitialized(String::from("Bad Log Path Provided"))
).contains("NeverInitialized")
);
assert!(
format!(
"{:?}",
LoggerError::Poisoned(String::from("Never Initialized"))
).contains("Poisoned")
);
assert!(
format!(
"{:?}",
LoggerError::FileLogWrite(std::io::Error::new(ErrorKind::Interrupted, "write"))
).contains("FileLogWrite")
);
assert!(
format!(
"{:?}",
LoggerError::FileLogFlush(std::io::Error::new(ErrorKind::Interrupted, "flush"))
).contains("FileLogFlush")
);
assert!(
format!(
"{:?}",
LoggerError::FileLogLock(String::from("File log lock"))
).contains("FileLogLock")
);
}
}
Loading