Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ the arguments.

- `sharedDir`: Path to the host directory that will be shared with the guest.
- `mountTag`: Tag to be used to mount the shared directory in the guest.
- `permissionSemantics`: (Optional) Permission semantics to be used in the virtio-fs device. Supported values: `complete`, `simplified`. Default value is `simplified`.

#### Example

Expand All @@ -224,6 +225,12 @@ This will share `/Users/user/shared-dir` with the guest:
--device virtio-fs,sharedDir=/Users/user/shared-dir,mountTag=MOUNT_TAG
```

To use complete permission semantics:

```
--device virtio-fs,sharedDir=/Users/user/shared-dir,mountTag=MOUNT_TAG,permissionSemantics=complete
```

## Restful Service

Recall that the RESTful service is started at the address specified in the `--restful-uri` argument (or
Expand Down
44 changes: 42 additions & 2 deletions src/virtio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ extern "C" {
) -> i32;
fn krun_add_vsock_port2(ctx_id: u32, port: u32, c_filepath: *const c_char, listen: bool)
-> i32;
fn krun_add_virtiofs(ctx_id: u32, c_tag: *const c_char, c_path: *const c_char) -> i32;
fn krun_add_virtiofs4(
ctx_id: u32,
c_tag: *const c_char,
c_path: *const c_char,
shm_size: u64,
read_only: bool,
semantics: u32,
) -> i32;
fn krun_set_console_output(ctx_id: u32, c_filepath: *const c_char) -> i32;
fn krun_add_net_unixgram(
ctx_id: u32,
Expand Down Expand Up @@ -92,6 +99,25 @@ impl FromStr for DiskImageFormat {
}
}

#[derive(Clone, Debug, Default, PartialEq)]
pub enum FsPermissions {
Complete = 0,
#[default]
Simplified = 1,
}

impl FromStr for FsPermissions {
type Err = anyhow::Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_lowercase().as_str() {
"complete" => Ok(FsPermissions::Complete),
"simplified" => Ok(FsPermissions::Simplified),
_ => Err(anyhow!("unsupported permission semantics")),
}
}
}

/// Each virito device configures itself with krun differently. This is used by each virtio device
/// to set their respective configurations with libkrun.
pub trait KrunContextSet {
Expand Down Expand Up @@ -584,6 +610,8 @@ pub struct FsConfig {

/// Guest mount tag for shared directory.
pub mount_tag: PathBuf,

pub permission_semantics: FsPermissions,
}

impl FromStr for FsConfig {
Expand All @@ -602,6 +630,10 @@ impl FromStr for FsConfig {
fs_config.mount_tag =
PathBuf::from_str(mount_tag.as_str()).context("mountTag argument not a valid path")?;

if let Some(p) = args.remove("permissionSemantics") {
fs_config.permission_semantics = FsPermissions::from_str(p.as_str())?;
}

check_unknown_args(args, "virtio-fs")?;

Ok(fs_config)
Expand All @@ -614,7 +646,15 @@ impl KrunContextSet for FsConfig {
let shared_dir_cstr = path_to_cstring(&self.shared_dir)?;
let mount_tag_cstr = path_to_cstring(&self.mount_tag)?;

if krun_add_virtiofs(id, mount_tag_cstr.as_ptr(), shared_dir_cstr.as_ptr()) < 0 {
if krun_add_virtiofs4(
id,
mount_tag_cstr.as_ptr(),
shared_dir_cstr.as_ptr(),
0,
false,
self.permission_semantics.clone() as u32,
) < 0
{
return Err(anyhow!(format!(
"unable to add virtiofs shared directory {} with mount tag {}",
&self.shared_dir.display(),
Expand Down
Loading