diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-03-13 23:44:04 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-06-15 09:36:45 +0000 |
commit | f97762597454c90a9671a3e5eb8d8a59b466e659 (patch) | |
tree | 0bf98ef31d624af9c78290e7aa72879b53a7fa8a /devices | |
parent | 812263927a9fbcca6cf94563685efa310a734dbe (diff) | |
download | crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar.gz crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar.bz2 crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar.lz crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar.xz crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.tar.zst crosvm-f97762597454c90a9671a3e5eb8d8a59b466e659.zip |
read_config
Diffstat (limited to 'devices')
-rw-r--r-- | devices/src/virtio/controller.rs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/devices/src/virtio/controller.rs b/devices/src/virtio/controller.rs index 374d11c..4a770cc 100644 --- a/devices/src/virtio/controller.rs +++ b/devices/src/virtio/controller.rs @@ -70,6 +70,7 @@ pub enum MsgOnSocketRequest { #[derive(Debug, Serialize, Deserialize)] pub enum BincodeRequest { + ReadConfig { offset: u64, len: usize }, WriteConfig { offset: u64, data: Vec<u8> }, } @@ -93,7 +94,9 @@ pub enum MsgOnSocketResponse { } #[derive(Debug, Deserialize, Serialize)] -pub struct BincodeResponse; +pub enum BincodeResponse { + ReadConfig(Vec<u8>), +} pub type Response = poly_msg_socket::Value<MsgOnSocketResponse, BincodeResponse>; @@ -291,6 +294,22 @@ impl VirtioDevice for Controller { } } + fn read_config(&self, offset: u64, data: &mut [u8]) { + let len = data.len(); + + if let Err(e) = self.socket.send(BincodeRequest::ReadConfig { offset, len }) { + error!("failed to send ReadConfig: {}", e); + return; + } + + match self.socket.recv_bincode() { + Ok(BincodeResponse::ReadConfig(response)) => { + data.copy_from_slice(&response[..len]); // TODO: test no panic + } + response => error!("bad response to ReadConfig: {:?}", response), + } + } + fn write_config(&mut self, offset: u64, data: &[u8]) { if let Err(e) = self.socket.send(BincodeRequest::WriteConfig { offset, |