Skip to content

Commit

Permalink
Add vsock cli param
Browse files Browse the repository at this point in the history
Using an extra CLI parameter, we are able to specify a unix socket
to be used as a VSOCK endpoint for Guest-to-Host communication.

For now, the argument is just the socket path, with a hardcoded
Guest ID. The default value is empty so that the VSOCK endpoint
is not added by default.

Example invocation:

./dbs-cli --kernel-path ./vmlinux \
	  --rootfs ./rootfs.img \
	  --boot-args 'console=ttyS0 tty0 pci=off root=/dev/vda' \
	  --vsock vsock.sock

Signed-off-by: Anastassios Nanos <ananos@nubificus.co.uk>
  • Loading branch information
ananos committed Nov 11, 2022
1 parent 7b17be9 commit aa86c0a
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
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

0 comments on commit aa86c0a

Please sign in to comment.