mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
crosvm: {WlDriverRequest, WlDriverResponse} --> {VmMemoryRequest, VmMemoryResponse}
These type of requests are not necessarily specific to the virtio-wl, and other devices (virtio-gpu) may want to use them. BUG=chromium:924405 TEST=compile Change-Id: Iad0889da8ab3d23bb2378448fc05e3c840a93d93 Reviewed-on: https://chromium-review.googlesource.com/1626791 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: kokoro <noreply+kokoro@google.com> Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
parent
56ebd12380
commit
53edb817da
3 changed files with 45 additions and 45 deletions
|
@ -73,7 +73,7 @@ use super::resource_bridge::*;
|
|||
use super::{
|
||||
DescriptorChain, Queue, VirtioDevice, INTERRUPT_STATUS_USED_RING, TYPE_WL, VIRTIO_F_VERSION_1,
|
||||
};
|
||||
use vm_control::{MaybeOwnedFd, WlControlRequestSocket, WlDriverRequest, WlDriverResponse};
|
||||
use vm_control::{MaybeOwnedFd, VmMemoryControlRequestSocket, VmMemoryRequest, VmMemoryResponse};
|
||||
|
||||
const VIRTWL_SEND_MAX_ALLOCS: usize = 28;
|
||||
const VIRTIO_WL_CMD_VFD_NEW: u32 = 256;
|
||||
|
@ -489,17 +489,17 @@ impl From<VolatileMemoryError> for WlError {
|
|||
|
||||
#[derive(Clone)]
|
||||
struct VmRequester {
|
||||
inner: Rc<RefCell<WlControlRequestSocket>>,
|
||||
inner: Rc<RefCell<VmMemoryControlRequestSocket>>,
|
||||
}
|
||||
|
||||
impl VmRequester {
|
||||
fn new(vm_socket: WlControlRequestSocket) -> VmRequester {
|
||||
fn new(vm_socket: VmMemoryControlRequestSocket) -> VmRequester {
|
||||
VmRequester {
|
||||
inner: Rc::new(RefCell::new(vm_socket)),
|
||||
}
|
||||
}
|
||||
|
||||
fn request(&self, request: WlDriverRequest) -> WlResult<WlDriverResponse> {
|
||||
fn request(&self, request: VmMemoryRequest) -> WlResult<VmMemoryResponse> {
|
||||
let mut inner = self.inner.borrow_mut();
|
||||
let vm_socket = &mut *inner;
|
||||
vm_socket.send(&request).map_err(WlError::VmControl)?;
|
||||
|
@ -730,12 +730,12 @@ impl WlVfd {
|
|||
vfd_shm
|
||||
.set_size(size_page_aligned)
|
||||
.map_err(WlError::AllocSetSize)?;
|
||||
let register_response = vm.request(WlDriverRequest::RegisterMemory(
|
||||
let register_response = vm.request(VmMemoryRequest::RegisterMemory(
|
||||
MaybeOwnedFd::Borrowed(vfd_shm.as_raw_fd()),
|
||||
vfd_shm.size() as usize,
|
||||
))?;
|
||||
match register_response {
|
||||
WlDriverResponse::RegisterMemory { pfn, slot } => {
|
||||
VmMemoryResponse::RegisterMemory { pfn, slot } => {
|
||||
let mut vfd = WlVfd::default();
|
||||
vfd.guest_shared_memory = Some((vfd_shm.size(), vfd_shm.into()));
|
||||
vfd.slot = Some((slot, pfn, vm));
|
||||
|
@ -753,13 +753,13 @@ impl WlVfd {
|
|||
format: u32,
|
||||
) -> WlResult<(WlVfd, GpuMemoryDesc)> {
|
||||
let allocate_and_register_gpu_memory_response =
|
||||
vm.request(WlDriverRequest::AllocateAndRegisterGpuMemory {
|
||||
vm.request(VmMemoryRequest::AllocateAndRegisterGpuMemory {
|
||||
width,
|
||||
height,
|
||||
format,
|
||||
})?;
|
||||
match allocate_and_register_gpu_memory_response {
|
||||
WlDriverResponse::AllocateAndRegisterGpuMemory {
|
||||
VmMemoryResponse::AllocateAndRegisterGpuMemory {
|
||||
fd,
|
||||
pfn,
|
||||
slot,
|
||||
|
@ -825,13 +825,13 @@ impl WlVfd {
|
|||
match fd.seek(SeekFrom::End(0)) {
|
||||
Ok(fd_size) => {
|
||||
let size = round_up_to_page_size(fd_size as usize) as u64;
|
||||
let register_response = vm.request(WlDriverRequest::RegisterMemory(
|
||||
let register_response = vm.request(VmMemoryRequest::RegisterMemory(
|
||||
MaybeOwnedFd::Borrowed(fd.as_raw_fd()),
|
||||
size as usize,
|
||||
))?;
|
||||
|
||||
match register_response {
|
||||
WlDriverResponse::RegisterMemory { pfn, slot } => {
|
||||
VmMemoryResponse::RegisterMemory { pfn, slot } => {
|
||||
let mut vfd = WlVfd::default();
|
||||
vfd.guest_shared_memory = Some((size, fd));
|
||||
vfd.slot = Some((slot, pfn, vm));
|
||||
|
@ -966,7 +966,7 @@ impl WlVfd {
|
|||
|
||||
fn close(&mut self) -> WlResult<()> {
|
||||
if let Some((slot, _, vm)) = self.slot.take() {
|
||||
vm.request(WlDriverRequest::UnregisterMemory(slot))?;
|
||||
vm.request(VmMemoryRequest::UnregisterMemory(slot))?;
|
||||
}
|
||||
self.socket = None;
|
||||
self.remote_pipe = None;
|
||||
|
@ -1005,7 +1005,7 @@ struct WlState {
|
|||
impl WlState {
|
||||
fn new(
|
||||
wayland_path: PathBuf,
|
||||
vm_socket: WlControlRequestSocket,
|
||||
vm_socket: VmMemoryControlRequestSocket,
|
||||
use_transition_flags: bool,
|
||||
resource_bridge: Option<ResourceRequestSocket>,
|
||||
) -> WlState {
|
||||
|
@ -1489,7 +1489,7 @@ impl Worker {
|
|||
in_queue: Queue,
|
||||
out_queue: Queue,
|
||||
wayland_path: PathBuf,
|
||||
vm_socket: WlControlRequestSocket,
|
||||
vm_socket: VmMemoryControlRequestSocket,
|
||||
use_transition_flags: bool,
|
||||
resource_bridge: Option<ResourceRequestSocket>,
|
||||
) -> Worker {
|
||||
|
@ -1672,7 +1672,7 @@ impl Worker {
|
|||
pub struct Wl {
|
||||
kill_evt: Option<EventFd>,
|
||||
wayland_path: PathBuf,
|
||||
vm_socket: Option<WlControlRequestSocket>,
|
||||
vm_socket: Option<VmMemoryControlRequestSocket>,
|
||||
resource_bridge: Option<ResourceRequestSocket>,
|
||||
use_transition_flags: bool,
|
||||
}
|
||||
|
@ -1680,7 +1680,7 @@ pub struct Wl {
|
|||
impl Wl {
|
||||
pub fn new<P: AsRef<Path>>(
|
||||
wayland_path: P,
|
||||
vm_socket: WlControlRequestSocket,
|
||||
vm_socket: VmMemoryControlRequestSocket,
|
||||
resource_bridge: Option<ResourceRequestSocket>,
|
||||
) -> Result<Wl> {
|
||||
Ok(Wl {
|
||||
|
|
24
src/linux.rs
24
src/linux.rs
|
@ -48,8 +48,8 @@ use vhost;
|
|||
use vm_control::{
|
||||
BalloonControlCommand, BalloonControlRequestSocket, BalloonControlResponseSocket,
|
||||
DiskControlCommand, DiskControlRequestSocket, DiskControlResponseSocket, DiskControlResult,
|
||||
UsbControlSocket, VmControlResponseSocket, VmRunMode, WlControlRequestSocket,
|
||||
WlControlResponseSocket, WlDriverRequest, WlDriverResponse,
|
||||
UsbControlSocket, VmControlResponseSocket, VmMemoryControlRequestSocket,
|
||||
VmMemoryControlResponseSocket, VmMemoryRequest, VmMemoryResponse, VmRunMode,
|
||||
};
|
||||
|
||||
use crate::{Config, DiskOption, TouchDeviceOption};
|
||||
|
@ -235,7 +235,7 @@ type Result<T> = std::result::Result<T, Error>;
|
|||
|
||||
enum TaggedControlSocket {
|
||||
Vm(VmControlResponseSocket),
|
||||
Wayland(WlControlResponseSocket),
|
||||
VmMemory(VmMemoryControlResponseSocket),
|
||||
}
|
||||
|
||||
impl AsRef<UnixSeqpacket> for TaggedControlSocket {
|
||||
|
@ -243,7 +243,7 @@ impl AsRef<UnixSeqpacket> for TaggedControlSocket {
|
|||
use self::TaggedControlSocket::*;
|
||||
match &self {
|
||||
Vm(ref socket) => socket,
|
||||
Wayland(ref socket) => socket,
|
||||
VmMemory(ref socket) => socket,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -596,7 +596,7 @@ fn create_gpu_device(
|
|||
fn create_wayland_device(
|
||||
cfg: &Config,
|
||||
socket_path: &Path,
|
||||
socket: WlControlRequestSocket,
|
||||
socket: VmMemoryControlRequestSocket,
|
||||
resource_bridge: Option<virtio::resource_bridge::ResourceRequestSocket>,
|
||||
) -> DeviceResult {
|
||||
let wayland_socket_dir = socket_path.parent().ok_or(Error::InvalidWaylandPath)?;
|
||||
|
@ -692,7 +692,7 @@ fn create_virtio_devices(
|
|||
cfg: &Config,
|
||||
mem: &GuestMemory,
|
||||
_exit_evt: &EventFd,
|
||||
wayland_device_socket: WlControlRequestSocket,
|
||||
wayland_device_socket: VmMemoryControlRequestSocket,
|
||||
balloon_device_socket: BalloonControlResponseSocket,
|
||||
disk_device_sockets: &mut Vec<DiskControlResponseSocket>,
|
||||
) -> DeviceResult<Vec<VirtioDeviceStub>> {
|
||||
|
@ -792,7 +792,7 @@ fn create_devices(
|
|||
cfg: &Config,
|
||||
mem: &GuestMemory,
|
||||
exit_evt: &EventFd,
|
||||
wayland_device_socket: WlControlRequestSocket,
|
||||
wayland_device_socket: VmMemoryControlRequestSocket,
|
||||
balloon_device_socket: BalloonControlResponseSocket,
|
||||
disk_device_sockets: &mut Vec<DiskControlResponseSocket>,
|
||||
usb_provider: HostBackendDeviceProvider,
|
||||
|
@ -1161,8 +1161,8 @@ pub fn run_config(cfg: Config) -> Result<()> {
|
|||
|
||||
let mut control_sockets = Vec::new();
|
||||
let (wayland_host_socket, wayland_device_socket) =
|
||||
msg_socket::pair::<WlDriverResponse, WlDriverRequest>().map_err(Error::CreateSocket)?;
|
||||
control_sockets.push(TaggedControlSocket::Wayland(wayland_host_socket));
|
||||
msg_socket::pair::<VmMemoryResponse, VmMemoryRequest>().map_err(Error::CreateSocket)?;
|
||||
control_sockets.push(TaggedControlSocket::VmMemory(wayland_host_socket));
|
||||
// Balloon gets a special socket so balloon requests can be forwarded from the main process.
|
||||
let (balloon_host_socket, balloon_device_socket) =
|
||||
msg_socket::pair::<BalloonControlCommand, ()>().map_err(Error::CreateSocket)?;
|
||||
|
@ -1569,19 +1569,19 @@ fn run_control(
|
|||
}
|
||||
}
|
||||
},
|
||||
TaggedControlSocket::Wayland(socket) => match socket.recv() {
|
||||
TaggedControlSocket::VmMemory(socket) => match socket.recv() {
|
||||
Ok(request) => {
|
||||
let response =
|
||||
request.execute(&mut linux.vm, &mut linux.resources);
|
||||
if let Err(e) = socket.send(&response) {
|
||||
error!("failed to send WlControlResponse: {}", e);
|
||||
error!("failed to send VmMemoryControlResponse: {}", e);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
if let MsgError::BadRecvSize { actual: 0, .. } = e {
|
||||
vm_control_indices_to_remove.push(index);
|
||||
} else {
|
||||
error!("failed to recv WlControlRequest: {}", e);
|
||||
error!("failed to recv VmMemoryControlRequest: {}", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -185,7 +185,7 @@ impl Display for UsbControlResult {
|
|||
}
|
||||
|
||||
#[derive(MsgOnSocket, Debug)]
|
||||
pub enum WlDriverRequest {
|
||||
pub enum VmMemoryRequest {
|
||||
/// Register shared memory represented by the given fd into guest address space. The response
|
||||
/// variant is `VmResponse::RegisterMemory`.
|
||||
RegisterMemory(MaybeOwnedFd, usize),
|
||||
|
@ -200,7 +200,7 @@ pub enum WlDriverRequest {
|
|||
},
|
||||
}
|
||||
|
||||
impl WlDriverRequest {
|
||||
impl VmMemoryRequest {
|
||||
/// Executes this request on the given Vm.
|
||||
///
|
||||
/// # Arguments
|
||||
|
@ -208,18 +208,18 @@ impl WlDriverRequest {
|
|||
/// * `allocator` - Used to allocate addresses.
|
||||
///
|
||||
/// This does not return a result, instead encapsulating the success or failure in a
|
||||
/// `WlDriverResponse` with the intended purpose of sending the response back over the socket
|
||||
/// that received this `WlDriverResponse`.
|
||||
pub fn execute(&self, vm: &mut Vm, sys_allocator: &mut SystemAllocator) -> WlDriverResponse {
|
||||
use self::WlDriverRequest::*;
|
||||
/// `VmMemoryResponse` with the intended purpose of sending the response back over the socket
|
||||
/// that received this `VmMemoryResponse`.
|
||||
pub fn execute(&self, vm: &mut Vm, sys_allocator: &mut SystemAllocator) -> VmMemoryResponse {
|
||||
use self::VmMemoryRequest::*;
|
||||
match *self {
|
||||
RegisterMemory(ref fd, size) => match register_memory(vm, sys_allocator, fd, size) {
|
||||
Ok((pfn, slot)) => WlDriverResponse::RegisterMemory { pfn, slot },
|
||||
Err(e) => WlDriverResponse::Err(e),
|
||||
Ok((pfn, slot)) => VmMemoryResponse::RegisterMemory { pfn, slot },
|
||||
Err(e) => VmMemoryResponse::Err(e),
|
||||
},
|
||||
UnregisterMemory(slot) => match vm.remove_device_memory(slot) {
|
||||
Ok(_) => WlDriverResponse::Ok,
|
||||
Err(e) => WlDriverResponse::Err(e),
|
||||
Ok(_) => VmMemoryResponse::Ok,
|
||||
Err(e) => VmMemoryResponse::Err(e),
|
||||
},
|
||||
AllocateAndRegisterGpuMemory {
|
||||
width,
|
||||
|
@ -229,24 +229,24 @@ impl WlDriverRequest {
|
|||
let (mut fd, desc) = match sys_allocator.gpu_memory_allocator() {
|
||||
Some(gpu_allocator) => match gpu_allocator.allocate(width, height, format) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return WlDriverResponse::Err(e),
|
||||
Err(e) => return VmMemoryResponse::Err(e),
|
||||
},
|
||||
None => return WlDriverResponse::Err(SysError::new(ENODEV)),
|
||||
None => return VmMemoryResponse::Err(SysError::new(ENODEV)),
|
||||
};
|
||||
// Determine size of buffer using 0 byte seek from end. This is preferred over
|
||||
// `stride * height` as it's not limited to packed pixel formats.
|
||||
let size = match fd.seek(SeekFrom::End(0)) {
|
||||
Ok(v) => v,
|
||||
Err(e) => return WlDriverResponse::Err(SysError::from(e)),
|
||||
Err(e) => return VmMemoryResponse::Err(SysError::from(e)),
|
||||
};
|
||||
match register_memory(vm, sys_allocator, &fd, size as usize) {
|
||||
Ok((pfn, slot)) => WlDriverResponse::AllocateAndRegisterGpuMemory {
|
||||
Ok((pfn, slot)) => VmMemoryResponse::AllocateAndRegisterGpuMemory {
|
||||
fd: MaybeOwnedFd::Owned(fd),
|
||||
pfn,
|
||||
slot,
|
||||
desc,
|
||||
},
|
||||
Err(e) => WlDriverResponse::Err(e),
|
||||
Err(e) => VmMemoryResponse::Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ impl WlDriverRequest {
|
|||
}
|
||||
|
||||
#[derive(MsgOnSocket, Debug)]
|
||||
pub enum WlDriverResponse {
|
||||
pub enum VmMemoryResponse {
|
||||
/// The request to register memory into guest address space was successfully done at page frame
|
||||
/// number `pfn` and memory slot number `slot`.
|
||||
RegisterMemory {
|
||||
|
@ -281,8 +281,8 @@ pub type DiskControlResponseSocket = MsgSocket<DiskControlResult, DiskControlCom
|
|||
|
||||
pub type UsbControlSocket = MsgSocket<UsbControlCommand, UsbControlResult>;
|
||||
|
||||
pub type WlControlRequestSocket = MsgSocket<WlDriverRequest, WlDriverResponse>;
|
||||
pub type WlControlResponseSocket = MsgSocket<WlDriverResponse, WlDriverRequest>;
|
||||
pub type VmMemoryControlRequestSocket = MsgSocket<VmMemoryRequest, VmMemoryResponse>;
|
||||
pub type VmMemoryControlResponseSocket = MsgSocket<VmMemoryResponse, VmMemoryRequest>;
|
||||
|
||||
pub type VmControlRequestSocket = MsgSocket<VmRequest, VmResponse>;
|
||||
pub type VmControlResponseSocket = MsgSocket<VmResponse, VmRequest>;
|
||||
|
|
Loading…
Reference in a new issue