summary refs log tree commit diff
path: root/src/crosvm.rs
diff options
context:
space:
mode:
authorChirantan Ekbote <chirantan@chromium.org>2019-07-17 10:50:30 +0900
committerCommit Bot <commit-bot@chromium.org>2019-11-19 17:59:47 +0000
commitbd4723b218fab426f575e70df5c0e437bd40669f (patch)
tree664bb62dafef8831331520541c0eff467ef1b555 /src/crosvm.rs
parent9093c002fefeb403bffd1b29deca2e7d680b2f2f (diff)
downloadcrosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar.gz
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar.bz2
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar.lz
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar.xz
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.tar.zst
crosvm-bd4723b218fab426f575e70df5c0e437bd40669f.zip
Add fs device to --shared-dir
Expand the `--shared-dir` option to allow callers to select between 9p
and virtio-fs for sharing directories.

BUG=b:136128319
TEST=start a VM with a virtio-fs based shared directory

Change-Id: Ie8afc1965b693805dd6000f0157786317aab060d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1705656
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Chirantan Ekbote <chirantan@chromium.org>
Diffstat (limited to 'src/crosvm.rs')
-rw-r--r--src/crosvm.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/crosvm.rs b/src/crosvm.rs
index c8b67bb..9e015b9 100644
--- a/src/crosvm.rs
+++ b/src/crosvm.rs
@@ -14,8 +14,11 @@ use std::collections::BTreeMap;
 use std::net;
 use std::os::unix::io::RawFd;
 use std::path::PathBuf;
+use std::str::FromStr;
 
+use devices::virtio::fs::passthrough;
 use devices::SerialParameters;
+use libc::{getegid, geteuid};
 
 static SECCOMP_POLICY_DIR: &str = "/usr/share/policy/crosvm";
 
@@ -69,6 +72,52 @@ impl TouchDeviceOption {
     }
 }
 
+pub enum SharedDirKind {
+    FS,
+    P9,
+}
+
+impl FromStr for SharedDirKind {
+    type Err = &'static str;
+
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        use SharedDirKind::*;
+        match s {
+            "fs" | "FS" => Ok(FS),
+            "9p" | "9P" | "p9" | "P9" => Ok(P9),
+            _ => Err("invalid file system type"),
+        }
+    }
+}
+
+impl Default for SharedDirKind {
+    fn default() -> SharedDirKind {
+        SharedDirKind::P9
+    }
+}
+
+pub struct SharedDir {
+    pub src: PathBuf,
+    pub tag: String,
+    pub kind: SharedDirKind,
+    pub uid_map: String,
+    pub gid_map: String,
+    pub cfg: passthrough::Config,
+}
+
+impl Default for SharedDir {
+    fn default() -> SharedDir {
+        SharedDir {
+            src: Default::default(),
+            tag: Default::default(),
+            kind: Default::default(),
+            uid_map: format!("0 {} 1", unsafe { geteuid() }),
+            gid_map: format!("0 {} 1", unsafe { getegid() }),
+            cfg: Default::default(),
+        }
+    }
+}
+
 /// Aggregate of all configurable options for a running VM.
 pub struct Config {
     pub vcpu_count: Option<u32>,
@@ -93,7 +142,7 @@ pub struct Config {
     pub wayland_socket_path: Option<PathBuf>,
     pub wayland_dmabuf: bool,
     pub x_display: Option<String>,
-    pub shared_dirs: Vec<(PathBuf, String)>,
+    pub shared_dirs: Vec<SharedDir>,
     pub sandbox: bool,
     pub seccomp_policy_dir: PathBuf,
     pub seccomp_log_failures: bool,