summary refs log tree commit diff
path: root/src/linux.rs
diff options
context:
space:
mode:
authorZach Reizner <zachr@google.com>2019-06-19 17:46:03 -0700
committerCommit Bot <commit-bot@chromium.org>2019-08-08 03:19:58 +0000
commit0f2cfb095dc2d49bfe22cb2d560b7777a19901e8 (patch)
tree366bf094ea0194b21f5d7415259281717cb32d3d /src/linux.rs
parent7f855be1f96905c44599b944a0d8449ae528ac39 (diff)
downloadcrosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar.gz
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar.bz2
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar.lz
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar.xz
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.tar.zst
crosvm-0f2cfb095dc2d49bfe22cb2d560b7777a19901e8.zip
crosvm: add x-display argument for choosing the X11 gpu display
TEST=cargo run -- run --gpu --x-display :0
BUG=None

Change-Id: I76b4b33a6b14cb6fad322ffa95f00cce976f81a3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1670550
Reviewed-by: Zach Reizner <zachr@chromium.org>
Commit-Queue: Zach Reizner <zachr@chromium.org>
Tested-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Diffstat (limited to 'src/linux.rs')
-rw-r--r--src/linux.rs48
1 files changed, 32 insertions, 16 deletions
diff --git a/src/linux.rs b/src/linux.rs
index 56750ae..b579e8a 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -11,6 +11,7 @@ use std::fmt::{self, Display};
 use std::fs::{File, OpenOptions};
 use std::io::{self, stdin, Read};
 use std::net::Ipv4Addr;
+use std::num::NonZeroU8;
 use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
 use std::os::unix::net::UnixStream;
 use std::path::{Path, PathBuf};
@@ -562,19 +563,33 @@ fn create_gpu_device(
     exit_evt: &EventFd,
     gpu_device_socket: VmMemoryControlRequestSocket,
     gpu_sockets: Vec<virtio::resource_bridge::ResourceResponseSocket>,
-    wayland_socket_path: &Path,
+    wayland_socket_path: Option<PathBuf>,
+    x_display: Option<String>,
 ) -> DeviceResult {
     let jailed_wayland_path = Path::new("/wayland-0");
 
+    let mut display_backends = vec![
+        virtio::DisplayBackend::X(x_display),
+        virtio::DisplayBackend::Null,
+    ];
+
+    if let Some(socket_path) = wayland_socket_path.as_ref() {
+        display_backends.insert(
+            0,
+            virtio::DisplayBackend::Wayland(if cfg.sandbox {
+                Some(jailed_wayland_path.to_owned())
+            } else {
+                Some(socket_path.to_owned())
+            }),
+        );
+    }
+
     let dev = virtio::Gpu::new(
         exit_evt.try_clone().map_err(Error::CloneEventFd)?,
         Some(gpu_device_socket),
+        NonZeroU8::new(1).unwrap(), // number of scanouts
         gpu_sockets,
-        if cfg.sandbox {
-            &jailed_wayland_path
-        } else {
-            wayland_socket_path
-        },
+        display_backends,
     );
 
     let jail = match simple_jail(&cfg, "gpu_device.policy")? {
@@ -619,7 +634,9 @@ fn create_gpu_device(
 
             // Bind mount the wayland socket into jail's root. This is necessary since each
             // new wayland context must open() the socket.
-            jail.mount_bind(wayland_socket_path, jailed_wayland_path, true)?;
+            if let Some(path) = wayland_socket_path {
+                jail.mount_bind(path.as_ref(), jailed_wayland_path, true)?;
+            }
 
             add_crosvm_user_to_jail(&mut jail, "gpu")?;
 
@@ -894,15 +911,14 @@ fn create_virtio_devices(
     #[cfg(feature = "gpu")]
     {
         if cfg.gpu {
-            if let Some(wayland_socket_path) = &cfg.wayland_socket_path {
-                devs.push(create_gpu_device(
-                    cfg,
-                    _exit_evt,
-                    gpu_device_socket,
-                    resource_bridges,
-                    wayland_socket_path,
-                )?);
-            }
+            devs.push(create_gpu_device(
+                cfg,
+                _exit_evt,
+                gpu_device_socket,
+                resource_bridges,
+                cfg.wayland_socket_path.clone(),
+                cfg.x_display.clone(),
+            )?);
         }
     }