summary refs log tree commit diff
path: root/src/main.rs
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2019-12-06 17:26:55 +1100
committerCommit Bot <commit-bot@chromium.org>2019-12-10 23:33:56 +0000
commit2767223fdbcf189ccebbffbec8b3a0f254d9d40e (patch)
treec0e02d927d76f1a8a85c19d69e1117ac65c47bd9 /src/main.rs
parent84be74727c7510d48d516de89c88374db78e71b3 (diff)
downloadcrosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar.gz
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar.bz2
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar.lz
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar.xz
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.tar.zst
crosvm-2767223fdbcf189ccebbffbec8b3a0f254d9d40e.zip
devices: block: add block_size option for disks
This allows overriding the default logical block size (512 bytes) with
other values, such as 4096 for 4K block size disks.

BUG=chromium:942700
TEST=crosvm run -r vm_rootfs,block_size=4096 vm_kernel
TEST=verify block size with lsblk --output-all

Change-Id: Ia6db05f369a76557a2afb8b48b5cc2b66cf84b01
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/1954220
Reviewed-by: Zach Reizner <zachr@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 8d9c890..9c97c4d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -378,6 +378,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 path: disk_path,
                 read_only,
                 sparse: true,
+                block_size: 512,
             };
 
             for opt in components {
@@ -399,6 +400,14 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                         })?;
                         disk.sparse = sparse;
                     }
+                    "block_size" => {
+                        let block_size =
+                            value.parse().map_err(|_| argument::Error::InvalidValue {
+                                value: value.to_owned(),
+                                expected: "`block_size` must be an integer",
+                            })?;
+                        disk.block_size = block_size;
+                    }
                     _ => {
                         return Err(argument::Error::InvalidValue {
                             value: kind.to_owned(),
@@ -423,6 +432,7 @@ fn set_argument(cfg: &mut Config, name: &str, value: Option<&str>) -> argument::
                 path: disk_path,
                 read_only: !name.starts_with("rw"),
                 sparse: false,
+                block_size: sys_util::pagesize() as u32,
             });
         }
         "host_ip" => {
@@ -893,7 +903,8 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
                               See --disk for valid options."),
           Argument::short_value('d', "disk", "PATH[,key=value[,key=value[,...]]", "Path to a disk image followed by optional comma-separated options.
                               Valid keys:
-                              sparse=BOOL - Indicates whether the disk should support the discard operation (default: true)"),
+                              sparse=BOOL - Indicates whether the disk should support the discard operation (default: true)
+                              block_size=BYTES - Set the reported block size of the disk (default: 512)"),
           Argument::value("qcow", "PATH", "Path to a qcow2 disk image. (Deprecated; use --disk instead.)"),
           Argument::value("rwdisk", "PATH[,key=value[,key=value[,...]]", "Path to a writable disk image followed by optional comma-separated options.
                               See --disk for valid options."),