Skip to content

Commit 2019f03

Browse files
committed
src/main.rs: vsock with vmm-no-api
Due to the latest changes regarding the way vsock devices are actually attached, it was no longer possible to add one using the command line parameters. These changes re-enable that functionality, by invoking logic that is also used when the VMM interprets incoming API requests. Signed-off-by: Alexandru Agache <[email protected]>
1 parent 7b182db commit 2019f03

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/main.rs

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::sync::mpsc::channel;
1414
use std::sync::mpsc::Receiver;
1515

1616
use api_server::{ApiRequest, ApiServer};
17+
use api_server::request::sync::{DeviceState, NetworkInterfaceBody, VsockJsonBody};
1718
use sys_util::{syslog, EventFd, GuestAddress};
1819
use vmm::{CMDLINE_MAX_SIZE, CMDLINE_OFFSET, KERNEL_START_OFFSET};
1920
use vmm::{kernel_cmdline, KernelConfig};
@@ -186,9 +187,6 @@ fn vmm_no_api_handler(cmd_arguments: &clap::ArgMatches, from_api: Receiver<Box<A
186187
if let Some(value) = cmd_arguments.value_of("tap_dev_name") {
187188
let host_dev_name = String::from(value);
188189

189-
use api_server::request::sync::DeviceState;
190-
use api_server::request::sync::NetworkInterfaceBody;
191-
192190
let body = NetworkInterfaceBody {
193191
iface_id: String::from("0"),
194192
state: DeviceState::Attached,
@@ -199,6 +197,18 @@ fn vmm_no_api_handler(cmd_arguments: &clap::ArgMatches, from_api: Receiver<Box<A
199197
vmm.put_net_device(body).expect("failed adding net device.");
200198
}
201199

200+
if let Some(cid) = cmd_arguments.value_of("vsock_guest_cid") {
201+
let cid = cid.parse::<u32>().expect("unable to parse cid value.");
202+
let body = VsockJsonBody {
203+
vsock_id: String::from("1"),
204+
guest_cid: cid,
205+
state: DeviceState::Attached,
206+
};
207+
208+
vmm.put_vsock_device(body)
209+
.expect("cannot add vsock device.");
210+
}
211+
202212
// configure kernel from command line
203213
//we're using unwrap here because the kernel_path is mandatory for now
204214
let kernel_file = File::open(cmd_arguments.value_of("kernel_path").unwrap_or_default())
@@ -220,27 +230,17 @@ fn vmm_no_api_handler(cmd_arguments: &clap::ArgMatches, from_api: Receiver<Box<A
220230
}
221231

222232
fn parse_args(cmd_arguments: &clap::ArgMatches) -> MachineCfg {
233+
// TODO: this is also no longer necesssary, right?
223234
let root_blk_file = cmd_arguments
224235
.value_of("root_blk_file")
225236
.map(|s| PathBuf::from(s));
226237

227-
let vsock_guest_cid = match cmd_arguments.value_of("vsock_guest_cid") {
228-
Some(cid) => match cid.parse::<u64>() {
229-
Ok(value) => Some(value),
230-
Err(error) => {
231-
panic!(
232-
"Invalid parameter value for the vsock's guest CID! {:?}",
233-
error
234-
);
235-
}
236-
},
237-
None => None,
238-
};
239-
240-
// host_ip; no longer used; remove when refactoring MachineCfg
238+
// no longer used; remove when refactoring MachineCfg
241239
let host_ip: Option<Ipv4Addr> = Some("1.2.3.4".parse().unwrap());
242-
// subnet_mask; no longer used; remove when refactoring MachineCfg
240+
// no longer used; remove when refactoring MachineCfg
243241
let subnet_mask: Ipv4Addr = "255.255.255.0".parse().unwrap();
242+
// no longer used; remove when refactoring MachineCfg
243+
let vsock_guest_cid = None;
244244

245245
MachineCfg::new(root_blk_file, host_ip, subnet_mask, vsock_guest_cid)
246246
}

0 commit comments

Comments
 (0)