diff options
author | Daniel Verkamp <dverkamp@chromium.org> | 2020-02-25 13:31:28 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-27 22:22:26 +0000 |
commit | 767333820014495f77b09f54de254e004bd8a5f9 (patch) | |
tree | 2cc5affe00d3dfc5a5211aabaf74f03375f727de /devices | |
parent | 1f9c1bb88b68961c2a0167993f6df401d49a2e9f (diff) | |
download | crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar.gz crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar.bz2 crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar.lz crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar.xz crosvm-767333820014495f77b09f54de254e004bd8a5f9.tar.zst crosvm-767333820014495f77b09f54de254e004bd8a5f9.zip |
devices: block: let resize convert to non-sparse
Change the behavior of the resize operation on virtio-block devices so that it causes a disk to become fully allocated (non-sparse) even if it had previously been sparse. This means that we could have a disk that was previously sparse and is now non-sparse, so treat discard requests for sparse disks as a no-op instead of an error. This is acceptable since discard is a hint and doing nothing is a valid implementation. BUG=chromium:858815 TEST=`crosvm disk resize` a sparse disk Change-Id: I8b79e460e5432cc71bed98172527fe1cd2e726ed Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2070846 Reviewed-by: David Munro <davidmunro@google.com> Reviewed-by: Dylan Reid <dgreid@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r-- | devices/src/virtio/block.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index 1e9c63e..094586f 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -343,14 +343,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)); - } + // 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)); } + self.sparse = false; + if let Ok(new_disk_size) = self.disk_image.get_len() { let mut disk_size = self.disk_size.lock(); *disk_size = new_disk_size; @@ -624,7 +624,8 @@ impl Block { } VIRTIO_BLK_T_DISCARD | VIRTIO_BLK_T_WRITE_ZEROES => { if req_type == VIRTIO_BLK_T_DISCARD && !sparse { - return Err(ExecuteError::Unsupported(req_type)); + // Discard is a hint; if this is a non-sparse disk, just ignore it. + return Ok(()); } while reader.available_bytes() >= size_of::<virtio_blk_discard_write_zeroes>() { |