Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vsock cli param #8

Merged
merged 1 commit into from
Nov 15, 2022
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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ Create a vsock console (communication with sock file)
--serial-path "/tmp/dbs" ;
```

Create a virtio-vsock tunnel for Guest-to-Host communication.

> When the parameter `vsock` is not given, `dbs-cli` will not add a virtio-vsock device.
>
> Otherwise, `dbs-cli` will create a unix socket on the host using the argument
> specified with the `--vsock` parameter.

```
./dbs-cli \
--log-file dbs-cli.log --log-level ERROR \
--kernel-path ~/path/to/kernel/vmlinux.bin \
--rootfs ~/path/to/rootfs/bionic.rootfs.ext4 \
--boot-args "console=ttyS0 tty0 reboot=k debug panic=1 pci=off root=/dev/vda1" \
--vsock /tmp/vsock.sock;
```

# 2. Usage

## 1. Exit vm
Expand Down Expand Up @@ -90,4 +106,4 @@ make build

# License

`DBS-CLI` is licensed under [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0.
`DBS-CLI` is licensed under [Apache License](http://www.apache.org/licenses/LICENSE-2.0), Version 2.0.
24 changes: 23 additions & 1 deletion src/cli_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use vmm_sys_util::eventfd::EventFd;
use dragonball::{
api::v1::{
BlockDeviceConfigInfo, BootSourceConfig, InstanceInfo, VmmAction, VmmActionError, VmmData,
VmmRequest, VmmResponse,
VmmRequest, VmmResponse, VsockDeviceConfigInfo,
},
vm::{CpuTopology, VmConfigInfo},
};
Expand Down Expand Up @@ -117,6 +117,20 @@ impl CliInstance {
self.insert_block_device(block_device_config_info)
.expect("failed to set block device");

if !args.create_args.vsock.is_empty() {
// VSOCK config
let mut vsock_config_info = VsockDeviceConfigInfo::default();
vsock_config_info = VsockDeviceConfigInfo {
guest_cid: 42, // dummy value
uds_path: Some(args.create_args.vsock.to_string()),
..vsock_config_info
};

// set vsock
self.insert_vsock(vsock_config_info)
.expect("failed to set vsock socket path");
}

// start micro-vm
self.instance_start().expect("failed to start micro-vm");

Expand Down Expand Up @@ -153,6 +167,14 @@ impl CliInstance {
Ok(())
}

pub fn insert_vsock(&self, vsock_cfg: VsockDeviceConfigInfo) -> Result<()> {
self.handle_request(Request::Sync(VmmAction::InsertVsockDevice(
vsock_cfg.clone(),
)))
.with_context(|| format!("Failed to insert vsock device {:?}", vsock_cfg))?;
Ok(())
}

fn send_request(&self, vmm_action: VmmAction) -> Result<VmmResponse> {
if let Some(ref to_vmm) = self.to_vmm {
to_vmm
Expand Down
13 changes: 13 additions & 0 deletions src/parser/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,19 @@ pub struct CreateArgs {
display_order = 2
)]
pub serial_path: String,

// The path to a vsock socket file
// FIXME: add more params:
// cid="contextid",socket_path="somepath",gid="guest_id"
#[clap(
short,
long,
value_parser,
default_value = "",
help = "Virtio VSOCK socket path",
display_order = 2
)]
pub vsock: String,
}

/// Config boot source including rootfs file path
Expand Down