Skip to content

Commit

Permalink
vmm-task:individually specify task.debug to enable debug_console
Browse files Browse the repository at this point in the history
Before this we reuse "task.log_level" to determine whether listening debug
console port, which is not so good, individually specifying task.debug to
enable debug_console is needed.

Signed-off-by: Vanient <xiadanni1@huawei.com>
  • Loading branch information
Vanient committed Aug 28, 2023
1 parent d5eca4c commit 17ef9bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
38 changes: 27 additions & 11 deletions docs/vmm/how-to-run-kuasar-with-isulad-and-stratovirt.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ After installation, you will find the required files in the specified path
## Build and configure iSulad

[iSulad](https://gitee.com/openeuler/iSulad) supports Kuasar with its dev-sandbox branch at the moment. For building iSulad from scratch, please refer to [iSulad build guide](https://gitee.com/openeuler/iSulad/blob/master/docs/build_docs/guide/build_guide.md). Here we only emphasize the difference of the building steps.

### Build LCR

```bash
Expand Down Expand Up @@ -260,6 +260,32 @@ POD ID CREATED STATE NAME
5cbcf744949d8 About a minute ago Ready busybox-sandbox2 default 1
```
### Set up a debug console
Kuasar vmm supports setting up a shell debug console by adding `task.debug` to kernel_params in config file, this requires the guest image to include /bin/bash.
```toml
[hypervisor]
kernel_params = "task.debug"
```

After starting pod, get the `vsock guest-cid` from stratovirt vm process:

```bash
$ ps -ef | grep stratovirt | grep 5cbcf744949d8
/usr/bin/stratovirt -name sandbox-5cbcf744949d8500e7159d6bd1e3894211f475549c0be15d9c60d3c502c7ede3 ...
-device vhost-vsock-pci,id=vsock-395568061,guest-cid=395568061,bus=pcie.0,addr=0x3,vhostfd=3
...
```

Then developers could enter the guest os debug console shell environment by:

```bash
# ncat --vsock <guest-cid> <debug-console>
# enter the guest os debug console shell
$ ncat --vsock 395568061 1025
```

### Create and start container in the pod sandbox with config file

Create a container in the podsandbox
Expand Down Expand Up @@ -296,17 +322,7 @@ c11df540f913e docker.io/library/busybox:latest 2 minutes ago Runni

### Test Network Connectivity

Get the `vsock guest-cid` from stratovirt vm process
```bash
$ ps -ef | grep stratovirt | grep 5cbcf744949d8
/usr/bin/stratovirt -name sandbox-5cbcf744949d8500e7159d6bd1e3894211f475549c0be15d9c60d3c502c7ede3 ...
-device vhost-vsock-pci,id=vsock-395568061,guest-cid=395568061,bus=pcie.0,addr=0x3,vhostfd=3
...
```
Enter the guest os debug console shell environment:
```bash
# ncat --vsock <guest-cid> <debug-console>
# enter the guest os debug console shell
$ ncat --vsock 395568061 1025

Expand Down
4 changes: 4 additions & 0 deletions vmm/task/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use tokio::fs::read_to_string;

const SHAREFS_TYPE: &str = "task.sharefs_type";
const LOG_LEVEL: &str = "task.log_level";
const TASK_DEBUG: &str = "task.debug";

macro_rules! parse_cmdline {
($param:ident, $key:ident, $field:expr) => {
Expand All @@ -40,13 +41,15 @@ macro_rules! parse_cmdline {
pub struct TaskConfig {
pub(crate) sharefs_type: String,
pub(crate) log_level: String,
pub(crate) debug: bool,
}

impl Default for TaskConfig {
fn default() -> Self {
TaskConfig {
sharefs_type: "9p".to_string(),
log_level: "info".to_string(),
debug: false,
}
}
}
Expand All @@ -62,6 +65,7 @@ impl TaskConfig {
let param: Vec<&str> = p.split('=').collect();
parse_cmdline!(param, SHAREFS_TYPE, config.sharefs_type, String::from);
parse_cmdline!(param, LOG_LEVEL, config.log_level, String::from);
parse_cmdline!(param, TASK_DEBUG, config.debug);
}
Ok(config)
}
Expand Down
3 changes: 1 addition & 2 deletions vmm/task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ async fn main() {
warn!("sharefs_type should be either 9p or virtiofs");
}
}
// TODO reuse log_level temporarily, maybe we should have a config named by "task.debug"
if config.log_level == "debug" {
if config.debug {
debug!("listen vsock port 1025 for debug console");
if let Err(e) = listen_debug_console("vsock://-1:1025").await {
error!("failed to listen debug console port, {:?}", e);
Expand Down

0 comments on commit 17ef9bc

Please sign in to comment.