summary refs log tree commit diff
diff options
context:
space:
mode:
authorDaniel Verkamp <dverkamp@chromium.org>2020-01-15 12:57:33 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-24 20:22:49 +0000
commit3c62aac88f829abd74cba7466e6a9e494af53b25 (patch)
tree758ee4bd798acd877e04385d92b74b2c6ec94b23
parent977f873a4140c29f838712e6f37137df4f0cd840 (diff)
downloadcrosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar.gz
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar.bz2
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar.lz
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar.xz
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.tar.zst
crosvm-3c62aac88f829abd74cba7466e6a9e494af53b25.zip
devices: virtio: block: keep disk allocated on resize
When a non-sparse disk is resized, we should allocate storage for the
newly-expanded space when the disk is grown to maintain the
non-sparseness.  To accomplish this, add a call to allocate in the
resize function in the block device.

BUG=chromium:858815
TEST=`crosvm disk resize ...` and verify disk image is fully allocated

Change-Id: If263aa2b5c9da11b8bfc0586e4ac1575f2bd7084
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2015829
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
-rw-r--r--devices/src/virtio/block.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs
index cc7a108..30cf4f7 100644
--- a/devices/src/virtio/block.rs
+++ b/devices/src/virtio/block.rs
@@ -344,6 +344,14 @@ impl Worker {
             return DiskControlResult::Err(SysError::new(libc::EIO));
         }
 
+        if !self.sparse {
+            // Allocate new space if the disk image is not sparse.
+            if let Err(e) = self.disk_image.allocate(0, new_size) {
+                error!("Allocating disk space after resize failed! {}", e);
+                return DiskControlResult::Err(SysError::new(libc::EIO));
+            }
+        }
+
         if let Ok(new_disk_size) = self.disk_image.get_len() {
             let mut disk_size = self.disk_size.lock();
             *disk_size = new_disk_size;