mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 05:35:20 +00:00
vmm/api: Add vm.add-fs route
Currently unimplemented. Once implemented, this API will allow for creating virtio-fs devices in the VM after it has booted. Signed-off-by: Dean Sheather <dean@coder.com>
This commit is contained in:
parent
d35e775ed9
commit
bb2139a408
@ -93,8 +93,9 @@ Dump the VM information | `/vm.info` | N/A
|
||||
Add VFIO PCI device to the VM | `/vm.add-device` | `/schemas/VmAddDevice` | N/A | The VM is booted
|
||||
Remove VFIO PCI device from the VM | `/vm.remove-device` | `/schemas/VmRemoveDevice` | N/A | The VM is booted
|
||||
Add disk device to the VM | `/vm.add-disk` | `/schemas/DiskConfig` | N/A | The VM is booted
|
||||
Add fs device to the VM | `/vm.add-fs` | `/schemas/FsConfig` | N/A | The VM is booted
|
||||
Add pmem device to the VM | `/vm.add-pmem` | `/schemas/PmemConfig` | N/A | The VM is booted
|
||||
Add network device to the VM | `/vm.add-net` | `/schemas/NetConfig` | N/A | The VM is booted
|
||||
Add network device to the VM | `/vm.add-net` | `/schemas/NetConfig` | N/A | The VM is booted
|
||||
|
||||
### REST API Examples
|
||||
|
||||
|
@ -24,6 +24,7 @@ enum Error {
|
||||
InvalidMemorySize(std::num::ParseIntError),
|
||||
AddDeviceConfig(vmm::config::Error),
|
||||
AddDiskConfig(vmm::config::Error),
|
||||
AddFsConfig(vmm::config::Error),
|
||||
AddPmemConfig(vmm::config::Error),
|
||||
AddNetConfig(vmm::config::Error),
|
||||
Restore(vmm::config::Error),
|
||||
@ -228,6 +229,17 @@ fn add_disk_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Err
|
||||
)
|
||||
}
|
||||
|
||||
fn add_fs_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
||||
let fs_config = vmm::config::FsConfig::parse(config).map_err(Error::AddFsConfig)?;
|
||||
|
||||
simple_api_command(
|
||||
socket,
|
||||
"PUT",
|
||||
"add-fs",
|
||||
Some(&serde_json::to_string(&fs_config).unwrap()),
|
||||
)
|
||||
}
|
||||
|
||||
fn add_pmem_api_command(socket: &mut UnixStream, config: &str) -> Result<(), Error> {
|
||||
let pmem_config = vmm::config::PmemConfig::parse(config).map_err(Error::AddPmemConfig)?;
|
||||
|
||||
@ -315,6 +327,14 @@ fn do_command(matches: &ArgMatches) -> Result<(), Error> {
|
||||
.value_of("disk_config")
|
||||
.unwrap(),
|
||||
),
|
||||
Some("add-fs") => add_fs_api_command(
|
||||
&mut socket,
|
||||
matches
|
||||
.subcommand_matches("add-fs")
|
||||
.unwrap()
|
||||
.value_of("fs_config")
|
||||
.unwrap(),
|
||||
),
|
||||
Some("add-pmem") => add_pmem_api_command(
|
||||
&mut socket,
|
||||
matches
|
||||
@ -383,6 +403,15 @@ fn main() {
|
||||
.help(vmm::config::DiskConfig::SYNTAX),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("add-fs")
|
||||
.about("Add virtio-fs backed fs device")
|
||||
.arg(
|
||||
Arg::with_name("fs_config")
|
||||
.index(1)
|
||||
.help(vmm::config::FsConfig::SYNTAX),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("add-pmem")
|
||||
.about("Add persistent memory device")
|
||||
|
@ -155,12 +155,7 @@ fn create_app<'a, 'b>(
|
||||
.arg(
|
||||
Arg::with_name("fs")
|
||||
.long("fs")
|
||||
.help(
|
||||
"virtio-fs parameters \
|
||||
\"tag=<tag_name>,sock=<socket_path>,num_queues=<number_of_queues>,\
|
||||
queue_size=<size_of_each_queue>,dax=on|off,cache_size=<DAX cache size: \
|
||||
default 8Gib>\"",
|
||||
)
|
||||
.help(config::FsConfig::SYNTAX)
|
||||
.takes_value(true)
|
||||
.min_values(1)
|
||||
.group("vm-config"),
|
||||
|
@ -4,8 +4,8 @@
|
||||
//
|
||||
|
||||
use crate::api::http_endpoint::{
|
||||
VmActionHandler, VmAddDevice, VmAddDisk, VmAddNet, VmAddPmem, VmCreate, VmInfo, VmRemoveDevice,
|
||||
VmResize, VmRestore, VmSnapshot, VmmPing, VmmShutdown,
|
||||
VmActionHandler, VmAddDevice, VmAddDisk, VmAddFs, VmAddNet, VmAddPmem, VmCreate, VmInfo,
|
||||
VmRemoveDevice, VmResize, VmRestore, VmSnapshot, VmmPing, VmmShutdown,
|
||||
};
|
||||
use crate::api::{ApiRequest, VmAction};
|
||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||
@ -70,6 +70,7 @@ lazy_static! {
|
||||
r.routes.insert(endpoint!("/vm.add-device"), Box::new(VmAddDevice {}));
|
||||
r.routes.insert(endpoint!("/vm.remove-device"), Box::new(VmRemoveDevice {}));
|
||||
r.routes.insert(endpoint!("/vm.add-disk"), Box::new(VmAddDisk {}));
|
||||
r.routes.insert(endpoint!("/vm.add-fs"), Box::new(VmAddFs {}));
|
||||
r.routes.insert(endpoint!("/vm.add-pmem"), Box::new(VmAddPmem {}));
|
||||
r.routes.insert(endpoint!("/vm.add-net"), Box::new(VmAddNet {}));
|
||||
|
||||
|
@ -487,6 +487,24 @@ impl EndpointHandler for VmAddDisk {
|
||||
}
|
||||
}
|
||||
|
||||
// /api/v1/vm.add-fs handler
|
||||
pub struct VmAddFs {}
|
||||
|
||||
impl EndpointHandler for VmAddFs {
|
||||
fn handle_request(
|
||||
&self,
|
||||
req: &Request,
|
||||
_api_notifier: EventFd,
|
||||
_api_sender: Sender<ApiRequest>,
|
||||
) -> Response {
|
||||
match req.method() {
|
||||
// Not implemented.
|
||||
Method::Put => Response::new(Version::Http11, StatusCode::NotImplemented),
|
||||
_ => Response::new(Version::Http11, StatusCode::BadRequest),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// /api/v1/vm.add-pmem handler
|
||||
pub struct VmAddPmem {}
|
||||
|
||||
|
@ -187,6 +187,22 @@ paths:
|
||||
500:
|
||||
description: The new disk could not be added to the VM instance.
|
||||
|
||||
/vm.add-fs:
|
||||
put:
|
||||
summary: Add a new virtio-fs device to the VM
|
||||
requestBody:
|
||||
description: The details of the new virtio-fs
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/FsConfig'
|
||||
required: true
|
||||
responses:
|
||||
204:
|
||||
description: The new device was successfully added to the VM instance.
|
||||
500:
|
||||
description: The new device could not be added to the VM instance.
|
||||
|
||||
/vm.add-pmem:
|
||||
put:
|
||||
summary: Add a new pmem device to the VM
|
||||
|
@ -876,6 +876,11 @@ impl Default for FsConfig {
|
||||
}
|
||||
|
||||
impl FsConfig {
|
||||
pub const SYNTAX: &'static str = "virtio-fs parameters \
|
||||
\"tag=<tag_name>,sock=<socket_path>,num_queues=<number_of_queues>,\
|
||||
queue_size=<size_of_each_queue>,dax=on|off,cache_size=<DAX cache size: \
|
||||
default 8Gib>\"";
|
||||
|
||||
pub fn parse(fs: &str) -> Result<Self> {
|
||||
let mut parser = OptionParser::new();
|
||||
parser
|
||||
|
Loading…
Reference in New Issue
Block a user