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 | |
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
-rw-r--r-- | devices/src/virtio/controller.rs | 21 | ||||
-rw-r--r-- | src/wl.rs | 8 |
2 files changed, 28 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, diff --git a/src/wl.rs b/src/wl.rs index 08d69f8..0a8bd0a 100644 --- a/src/wl.rs +++ b/src/wl.rs @@ -68,6 +68,14 @@ fn main() { Ok(MsgOnSocket(MsgOnSocketRequest::AckFeatures(value))) => wl.ack_features(value), + Ok(Bincode(BincodeRequest::ReadConfig { offset, len })) => { + let mut data = vec![0; len]; + wl.read_config(offset, &mut data); + if let Err(e) = msg_socket.send(BincodeResponse::ReadConfig(data)) { + panic!("replying to ReadConfig failed: {}", e); + } + } + Ok(Bincode(BincodeRequest::WriteConfig { offset, ref data })) => { wl.write_config(offset, data) } |