diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2018-12-04 13:17:46 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-01-16 01:46:54 -0800 |
commit | 92f73d73d04bdc973fe89e2c1682a1c3cc03fe49 (patch) | |
tree | 8b9b52835951bb982ad3e5cc240b91f0dcacea3f /src/main.rs | |
parent | 53429509833a8f1a227d977778069df93a4edd44 (diff) | |
download | crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar.gz crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar.bz2 crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar.lz crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar.xz crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.tar.zst crosvm-92f73d73d04bdc973fe89e2c1682a1c3cc03fe49.zip |
devices: block: add resize VmControl request
This allows manual resizing of block devices at runtime via the command line ('crosvm disk resize <index> <size>'). The virtio config interrupt is asserted when the disk size changes so that the guest driver can update the block device to the updated size. Currently, there is no automatic policy for resizing disks - that will be implemented in another change. Additionally, this resize operation just changes the size of the block device; the filesystem will need to be resized by the guest (e.g. via the 'btrfs filesystem resize' command) as a separate step either before (shrinking) or after (expanding) the disk resize operation. BUG=chromium:858815 TEST=Start crosvm with a control socket (-s) and resize the disk with 'crosvm disk resize' from another shell. Change-Id: I01633a7af04bfbaffbd27b9227274406d2a2b9cb Signed-off-by: Daniel Verkamp <dverkamp@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/1394152 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index 79d0432..9cb7b3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -691,12 +691,76 @@ fn create_qcow2(mut args: std::env::Args) -> std::result::Result<(), ()> { Ok(()) } +fn disk_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> { + if args.len() < 2 { + print_help("crosvm disk", "SUBCOMMAND VM_SOCKET...", &[]); + println!("Manage attached virtual disk devices."); + println!("Subcommands:"); + println!(" resize DISK_INDEX NEW_SIZE VM_SOCKET"); + } + let subcommand: &str = &args.nth(0).unwrap(); + + let request = match subcommand { + "resize" => { + let disk_index = match args.nth(0).unwrap().parse::<usize>() { + Ok(n) => n, + Err(_) => { + error!("Failed to parse disk index"); + return Err(()); + } + }; + + let new_size = match args.nth(0).unwrap().parse::<u64>() { + Ok(n) => n, + Err(_) => { + error!("Failed to parse disk size"); + return Err(()); + } + }; + + VmRequest::DiskResize { + disk_index, + new_size, + } + } + _ => { + error!("Unknown disk subcommand '{}'", subcommand); + return Err(()); + } + }; + + let mut return_result = Ok(()); + for socket_path in args { + match UnixDatagram::unbound().and_then(|s| { + s.connect(&socket_path)?; + Ok(s) + }) { + Ok(s) => { + let sender = Sender::<VmRequest>::new(s); + if let Err(e) = sender.send(&request) { + error!( + "failed to send disk request to socket at '{}': {:?}", + socket_path, e + ); + } + } + Err(e) => { + error!("failed to connect to socket at '{}': {}", socket_path, e); + return_result = Err(()); + } + } + } + + return_result +} + fn print_usage() { print_help("crosvm", "[stop|run]", &[]); println!("Commands:"); println!(" stop - Stops crosvm instances via their control sockets."); println!(" run - Start a new crosvm instance."); println!(" create_qcow2 - Create a new qcow2 disk image file."); + println!(" disk - Manage attached virtual disk devices.") } fn crosvm_main() -> std::result::Result<(), ()> { @@ -721,6 +785,7 @@ fn crosvm_main() -> std::result::Result<(), ()> { Some("run") => run_vm(args), Some("balloon") => balloon_vms(args), Some("create_qcow2") => create_qcow2(args), + Some("disk") => disk_cmd(args), Some(c) => { println!("invalid subcommand: {:?}", c); print_usage(); |