diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index 15e0e7301d..ae212c3cf1 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -13,6 +13,7 @@ use std::thread; use std::time::Duration; use std::u32; +use sync::Mutex; use sys_util::Error as SysError; use sys_util::Result as SysResult; use sys_util::{ @@ -618,7 +619,7 @@ impl Worker { pub struct Block { kill_evt: Option, disk_image: Option, - disk_size: u64, + disk_size: Arc>, avail_features: u64, read_only: bool, } @@ -664,7 +665,7 @@ impl Block { Ok(Block { kill_evt: None, disk_image: Some(disk_image), - disk_size, + disk_size: Arc::new(Mutex::new(disk_size)), avail_features, read_only, }) @@ -704,7 +705,10 @@ impl VirtioDevice for Block { } fn read_config(&self, offset: u64, mut data: &mut [u8]) { - let config_space = build_config_space(self.disk_size); + let config_space = { + let disk_size = self.disk_size.lock(); + build_config_space(*disk_size) + }; let config_len = size_of_val(&config_space) as u64; if offset >= config_len { return;