convert println logs to logging macros

TEST=build_test
BUG=None

Change-Id: Ia184e994e996eef427e1b50ce019403f4521f008
Reviewed-on: https://chromium-review.googlesource.com/693138
Commit-Ready: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
This commit is contained in:
Zach Reizner 2017-09-29 11:17:53 -07:00 committed by chrome-bot
parent 26e1aef84f
commit bb493dd02b
10 changed files with 67 additions and 94 deletions

View file

@ -6,6 +6,7 @@
extern crate libc;
extern crate kvm_sys;
#[macro_use]
extern crate sys_util;
mod cap;
@ -99,7 +100,7 @@ impl Kvm {
0 => 4, // according to api.txt
x if x > 0 => x as u32,
_ => {
println!("warning: kernel returned invalid number of VCPUs");
warn!("kernel returned invalid number of VCPUs");
4
},
}

View file

@ -28,7 +28,7 @@ impl BusDevice for I8042Device {
fn write(&mut self, offset: u64, data: &[u8]) {
if data.len() == 1 && data[0] == 0xfe && offset == 3 {
if let Err(e) = self.reset_evt.write(1) {
println!("failed to trigger i8042 reset event: {:?}", e);
error!("failed to trigger i8042 reset event: {:?}", e);
}
}
}

View file

@ -31,13 +31,13 @@ fn child_proc(sock: UnixDatagram, device: &mut BusDevice) {
let mut buf = [0; MSG_SIZE];
match handle_eintr!(sock.recv(&mut buf)) {
Ok(c) if c != buf.len() => {
println!("error: child device process incorrect recv size: got {}, expected {}",
c,
buf.len());
error!("child device process incorrect recv size: got {}, expected {}",
c,
buf.len());
break;
}
Err(e) => {
println!("error: child device process failed recv: {}", e);
error!("child device process failed recv: {}", e);
break;
}
_ => {}
@ -57,12 +57,12 @@ fn child_proc(sock: UnixDatagram, device: &mut BusDevice) {
running = false;
handle_eintr!(sock.send(&buf))
} else {
println!("child device process unknown command: {}", cmd);
error!("child device process unknown command: {}", cmd);
break;
};
if let Err(e) = res {
println!("error: child device process failed send: {}", e);
error!("error: child device process failed send: {}", e);
break;
}
}
@ -102,7 +102,10 @@ impl ProxyDevice {
.set_write_timeout(Some(Duration::from_millis(SOCKET_TIMEOUT_MS)))?;
parent_sock
.set_read_timeout(Some(Duration::from_millis(SOCKET_TIMEOUT_MS)))?;
Ok(ProxyDevice { sock: parent_sock, pid: pid })
Ok(ProxyDevice {
sock: parent_sock,
pid: pid,
})
}
pub fn pid(&self) -> pid_t {
@ -137,7 +140,7 @@ impl BusDevice for ProxyDevice {
let res = self.send_cmd(Command::Read, offset, data.len() as u32, &[])
.and_then(|_| self.recv_resp(data));
if let Err(e) = res {
println!("error: failed read from child device process: {}", e);
error!("failed read from child device process: {}", e);
}
}
@ -145,7 +148,7 @@ impl BusDevice for ProxyDevice {
let res = self.send_cmd(Command::Write, offset, data.len() as u32, data)
.and_then(|_| self.wait());
if let Err(e) = res {
println!("error: failed write to child device process: {}", e);
error!("failed write to child device process: {}", e);
}
}
}
@ -154,7 +157,7 @@ impl Drop for ProxyDevice {
fn drop(&mut self) {
let res = self.send_cmd(Command::Shutdown, 0, 0, &[]);
if let Err(e) = res {
println!("error: failed to shutdown child device process: {}", e);
error!("failed to shutdown child device process: {}", e);
}
}
}

View file

@ -191,7 +191,7 @@ impl BusDevice for Serial {
}
if let Err(e) = self.handle_write(offset as u8, data[0]) {
println!("serial failed write: {:?}", e);
error!("serial failed write: {:?}", e);
}
}

View file

@ -197,7 +197,7 @@ impl Worker {
VIRTIO_BLK_S_OK
}
Err(e) => {
println!("block: error executing disk request: {:?}", e);
error!("failed executing disk request: {:?}", e);
len = 1; // 1 byte for the status
e.status()
}
@ -209,8 +209,7 @@ impl Worker {
.unwrap();
}
Err(e) => {
println!("block: error processing available descriptor chain: {:?}",
e);
error!("failed processing available descriptor chain: {:?}", e);
len = 0;
}
}
@ -239,7 +238,7 @@ impl Worker {
let tokens = match poller.poll(&[(Q_AVAIL, &queue_evt), (KILL, &kill_evt)]) {
Ok(v) => v,
Err(e) => {
println!("block: error polling for events: {:?}", e);
error!("failed polling for events: {:?}", e);
break;
}
};
@ -249,7 +248,7 @@ impl Worker {
match token {
Q_AVAIL => {
if let Err(e) = queue_evt.read() {
println!("block: error reading queue EventFd: {:?}", e);
error!("failed reading queue EventFd: {:?}", e);
break 'poll;
}
needs_interrupt |= self.process_queue(0);
@ -291,10 +290,10 @@ impl Block {
pub fn new(mut disk_image: File) -> SysResult<Block> {
let disk_size = disk_image.seek(SeekFrom::End(0))? as u64;
if disk_size % SECTOR_SIZE != 0 {
println!("block: Disk size {} is not a multiple of sector size {}; \
warn!("Disk size {} is not a multiple of sector size {}; \
the remainder will not be visible to the guest.",
disk_size,
SECTOR_SIZE);
disk_size,
SECTOR_SIZE);
}
Ok(Block {
kill_evt: None,
@ -358,7 +357,7 @@ impl VirtioDevice for Block {
match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) {
Ok(v) => v,
Err(e) => {
println!("block: error creating kill EventFd pair: {:?}", e);
error!("failed creating kill EventFd pair: {:?}", e);
return;
}
};

View file

@ -195,7 +195,7 @@ impl BusDevice for MmioDevice {
0x70 => self.driver_status,
0xfc => self.config_generation,
_ => {
println!("unknown virtio mmio register read: 0x{:x}", offset);
warn!("unknown virtio mmio register read: 0x{:x}", offset);
return;
}
};
@ -203,9 +203,7 @@ impl BusDevice for MmioDevice {
}
0x100...0xfff => self.device.read_config(offset - 0x100, data),
_ => {
println!("invalid virtio mmio read: 0x{:x}:0x{:x}",
offset,
data.len());
warn!("invalid virtio mmio read: 0x{:x}:0x{:x}", offset, data.len());
}
};
@ -243,22 +241,20 @@ impl BusDevice for MmioDevice {
0xa0 => mut_q = self.with_queue_mut(|q| lo(&mut q.used_ring, v)),
0xa4 => mut_q = self.with_queue_mut(|q| hi(&mut q.used_ring, v)),
_ => {
println!("unknown virtio mmio register write: 0x{:x}", offset);
warn!("unknown virtio mmio register write: 0x{:x}", offset);
return;
}
}
}
0x100...0xfff => return self.device.write_config(offset - 0x100, data),
_ => {
println!("invalid virtio mmio write: 0x{:x}:0x{:x}",
offset,
data.len());
warn!("invalid virtio mmio write: 0x{:x}:0x{:x}", offset, data.len());
return;
}
}
if self.device_activated && mut_q {
println!("warning: virtio queue was changed after device was activated");
warn!("virtio queue was changed after device was activated");
}
if !self.device_activated && self.is_driver_ready() && self.are_queues_valid() {

View file

@ -212,32 +212,32 @@ impl Queue {
let used_ring = self.used_ring;
let used_ring_size = 6 + 8 * queue_size;
if !self.ready {
println!("error: attempt to use virtio queue that is not marked ready");
error!("attempt to use virtio queue that is not marked ready");
false
} else if self.size > self.max_size || self.size == 0 ||
(self.size & (self.size - 1)) != 0 {
println!("error: virtio queue with invalid size: {}", self.size);
error!("virtio queue with invalid size: {}", self.size);
false
} else if desc_table
.checked_add(desc_table_size)
.map_or(true, |v| !mem.address_in_range(v)) {
println!("error: virtio queue descriptor table goes out of bounds: start:0x{:08x} size:0x{:08x}",
desc_table.offset(),
desc_table_size);
error!("virtio queue descriptor table goes out of bounds: start:0x{:08x} size:0x{:08x}",
desc_table.offset(),
desc_table_size);
false
} else if avail_ring
.checked_add(avail_ring_size)
.map_or(true, |v| !mem.address_in_range(v)) {
println!("error: virtio queue available ring goes out of bounds: start:0x{:08x} size:0x{:08x}",
avail_ring.offset(),
avail_ring_size);
error!("virtio queue available ring goes out of bounds: start:0x{:08x} size:0x{:08x}",
avail_ring.offset(),
avail_ring_size);
false
} else if used_ring
.checked_add(used_ring_size)
.map_or(true, |v| !mem.address_in_range(v)) {
println!("error: virtio queue used ring goes out of bounds: start:0x{:08x} size:0x{:08x}",
used_ring.offset(),
used_ring_size);
error!("virtio queue used ring goes out of bounds: start:0x{:08x} size:0x{:08x}",
used_ring.offset(),
used_ring_size);
false
} else {
true
@ -279,8 +279,8 @@ impl Queue {
/// Puts an available descriptor head into the used ring for use by the guest.
pub fn add_used(&mut self, mem: &GuestMemory, desc_index: u16, len: u32) {
if desc_index >= self.actual_size() {
println!("error: attempted to add out of bounds descriptor to used ring: {}",
desc_index);
error!("attempted to add out of bounds descriptor to used ring: {}",
desc_index);
return;
}

View file

@ -77,7 +77,7 @@ impl Worker {
let tokens = match poller.poll(&[(Q_AVAIL, &queue_evt), (KILL, &kill_evt)]) {
Ok(v) => v,
Err(e) => {
println!("rng: error polling for events: {:?}", e);
error!("failed polling for events: {:?}", e);
break;
}
};
@ -87,7 +87,7 @@ impl Worker {
match token {
Q_AVAIL => {
if let Err(e) = queue_evt.read() {
println!("rng: error reading queue EventFd: {:?}", e);
error!("failed reading queue EventFd: {:?}", e);
break 'poll;
}
needs_interrupt |= self.process_queue();
@ -163,7 +163,7 @@ impl VirtioDevice for Rng {
match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) {
Ok(v) => v,
Err(e) => {
println!("rng: error creating kill EventFd pair: {:?}", e);
error!("failed to create kill EventFd pair: {:?}", e);
return;
}
};

View file

@ -900,15 +900,12 @@ impl Worker {
self.out_queue.add_used(&self.mem, index, len);
}
}
KILL => {
println!("crosvm Wl worker killed");
break 'poll;
}
KILL => break 'poll,
v => {
if let Some(&id) = token_vfd_id_map.get(&v) {
let res = self.state.recv(id);
if let Err(e) = res {
println!("recv vfd {} error: {:?}", id, e);
error!("failed to receive vfd {}: {:?}", id, e);
}
}
}
@ -932,7 +929,7 @@ impl Worker {
len
}
Err(e) => {
println!("failed to encode response to descriptor chain: {:?}", e);
error!("failed to encode response to descriptor chain: {:?}", e);
0
}
};
@ -1013,7 +1010,7 @@ impl VirtioDevice for Wl {
match EventFd::new().and_then(|e| Ok((e.try_clone()?, e))) {
Ok(v) => v,
Err(e) => {
println!("wl: error creating kill EventFd pair: {:?}", e);
error!("failed creating kill EventFd pair: {:?}", e);
return;
}
};

View file

@ -197,7 +197,6 @@ struct Config {
disable_wayland: bool,
socket_path: Option<PathBuf>,
multiprocess: bool,
warn_unknown_ports: bool,
cid: Option<u64>,
}
@ -422,8 +421,7 @@ fn run_config(cfg: Config) -> Result<()> {
cfg.vcpu_count.unwrap_or(1),
guest_mem,
&device_manager.bus,
control_sockets,
cfg.warn_unknown_ports)
control_sockets)
}
fn run_kvm(requests: Vec<VmRequest>,
@ -432,8 +430,7 @@ fn run_kvm(requests: Vec<VmRequest>,
vcpu_count: u32,
guest_mem: GuestMemory,
mmio_bus: &hw::Bus,
control_sockets: Vec<UnlinkUnixDatagram>,
warn_unknown_ports: bool)
control_sockets: Vec<UnlinkUnixDatagram>)
-> Result<()> {
let kvm = Kvm::new().map_err(Error::Kvm)?;
let kernel_start_addr = GuestAddress(KERNEL_START_OFFSET);
@ -455,7 +452,7 @@ fn run_kvm(requests: Vec<VmRequest>,
return Err(Error::Vm(e));
}
if !running {
println!("configuration requested exit");
info!("configuration requested exit");
return Ok(());
}
}
@ -562,40 +559,20 @@ fn run_kvm(requests: Vec<VmRequest>,
Ok(run) => {
match run {
VcpuExit::IoIn(addr, data) => {
if !io_bus.read(addr as u64, data) && warn_unknown_ports {
println!("warning: unhandled I/O port {}-bit read at 0x{:03x}",
data.len() << 3,
addr);
}
io_bus.read(addr as u64, data);
}
VcpuExit::IoOut(addr, data) => {
if !io_bus.write(addr as u64, data) && warn_unknown_ports {
println!("warning: unhandled I/O port {}-bit write at 0x{:03x}",
data.len() << 3,
addr);
}
io_bus.write(addr as u64, data);
}
VcpuExit::MmioRead(addr, data) => {
if !mmio_bus.read(addr, data) && warn_unknown_ports {
println!("warning: unhandled mmio {}-bit read at 0x{:08x}",
data.len() << 3,
addr);
}
mmio_bus.read(addr, data);
}
VcpuExit::MmioWrite(addr, data) => {
if !mmio_bus.write(addr, data) && warn_unknown_ports {
println!("warning: unhandled mmio {}-bit write at 0x{:08x}",
data.len() << 3,
addr);
}
mmio_bus.write(addr, data);
}
VcpuExit::Hlt => break,
VcpuExit::Shutdown => break,
r => println!("unexpected vcpu exit: {:?}", r),
r => warn!("unexpected vcpu exit: {:?}", r),
}
}
Err(e) => {
@ -664,7 +641,7 @@ fn run_control(mut vm: Vm,
match poller.poll(&pollables[..]) {
Ok(v) => v,
Err(e) => {
println!("failed to poll: {:?}", e);
error!("failed to poll: {:?}", e);
break;
}
}
@ -672,7 +649,7 @@ fn run_control(mut vm: Vm,
for &token in tokens {
match token {
EXIT => {
println!("vcpu requested shutdown");
info!("vcpu requested shutdown");
break 'poll;
}
STDIN => {
@ -708,14 +685,14 @@ fn run_control(mut vm: Vm,
let response =
request.execute(&mut vm, &mut next_dev_pfn, &mut running);
if let Err(e) = response.send(&mut scm, socket.as_ref()) {
println!("failed to send VmResponse: {:?}", e);
error!("failed to send VmResponse: {:?}", e);
}
if !running {
println!("control socket requested exit");
info!("control socket requested exit");
break 'poll;
}
}
Err(e) => println!("failed to recv VmRequest: {:?}", e),
Err(e) => error!("failed to recv VmRequest: {:?}", e),
}
}
_ => {}
@ -730,10 +707,10 @@ fn run_control(mut vm: Vm,
match handle.kill(0) {
Ok(_) => {
if let Err(e) = handle.join() {
println!("failed to join vcpu thread: {:?}", e);
error!("failed to join vcpu thread: {:?}", e);
}
}
Err(e) => println!("failed to kill vcpu thread: {:?}", e),
Err(e) => error!("failed to kill vcpu thread: {:?}", e),
}
}
@ -955,8 +932,8 @@ fn run_vm(args: std::env::Args) {
match match_res {
Ok(_) => {
match run_config(cfg) {
Ok(_) => println!("crosvm has exited normally"),
Err(e) => println!("{}", e),
Ok(_) => info!("crosvm has exited normally"),
Err(e) => error!("{}", e),
}
}
Err(argument::Error::PrintHelp) => print_help("crosvm run", "KERNEL", &arguments[..]),