Commit 87ed476f authored by David Munro's avatar David Munro Committed by Commit Bot

crostini: Handle the disk resizing case where we are overprovisioned.

In some cases the user could end up with a disk larger than we allow
them to have. When that happens they can still go up to their current
size instead of us erroring out.

Bug: chromium:1083847
Test: Unit
Change-Id: If55591bfbf8d7c81c1aea27db9dc06a54ea0988f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208157
Auto-Submit: David Munro <davidmunro@google.com>
Commit-Queue: Nicholas Verne <nverne@chromium.org>
Reviewed-by: default avatarNicholas Verne <nverne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#770018}
parent efdb33f8
...@@ -124,8 +124,6 @@ void OnListVmDisks( ...@@ -124,8 +124,6 @@ void OnListVmDisks(
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
// User has to leave at least kDiskHeadroomBytes for the host system.
int64_t max_size = free_space - kDiskHeadroomBytes;
auto disk_info = std::make_unique<CrostiniDiskInfo>(); auto disk_info = std::make_unique<CrostiniDiskInfo>();
auto image = auto image =
std::find_if(response->images().begin(), response->images().end(), std::find_if(response->images().begin(), response->images().end(),
...@@ -152,6 +150,12 @@ void OnListVmDisks( ...@@ -152,6 +150,12 @@ void OnListVmDisks(
if (image->min_size() == 0) { if (image->min_size() == 0) {
VLOG(1) << "Unable to get minimum disk size. VM not running yet?"; VLOG(1) << "Unable to get minimum disk size. VM not running yet?";
} }
// User has to leave at least kDiskHeadroomBytes for the host system.
// In some cases we can be over-provisioned (e.g. we increased the headroom
// required), when that happens the user can still go up to their currently
// allocated size.
int64_t max_size =
std::max(free_space - kDiskHeadroomBytes + image->size(), image->size());
disk_info->is_user_chosen_size = image->user_chosen_size(); disk_info->is_user_chosen_size = image->user_chosen_size();
disk_info->can_resize = disk_info->can_resize =
image->image_type() == vm_tools::concierge::DiskImageType::DISK_IMAGE_RAW; image->image_type() == vm_tools::concierge::DiskImageType::DISK_IMAGE_RAW;
...@@ -160,12 +164,11 @@ void OnListVmDisks( ...@@ -160,12 +164,11 @@ void OnListVmDisks(
const int64_t min_size = const int64_t min_size =
std::max(static_cast<int64_t>(image->min_size()), kMinimumDiskSizeBytes); std::max(static_cast<int64_t>(image->min_size()), kMinimumDiskSizeBytes);
std::vector<crostini::mojom::DiskSliderTickPtr> ticks = std::vector<crostini::mojom::DiskSliderTickPtr> ticks =
GetTicks(min_size, image->size(), max_size + image->size(), GetTicks(min_size, image->size(), max_size, &(disk_info->default_index));
&(disk_info->default_index));
if (ticks.size() == 0) { if (ticks.size() == 0) {
LOG(ERROR) << "Unable to calculate the number of ticks for min: " LOG(ERROR) << "Unable to calculate the number of ticks for min: "
<< min_size << " current: " << image->size() << min_size << " current: " << image->size()
<< " max: " << max_size + image->size(); << " max: " << max_size;
std::move(callback).Run(nullptr); std::move(callback).Run(nullptr);
return; return;
} }
......
...@@ -263,5 +263,21 @@ TEST_F(CrostiniDiskTestDbus, DiskResizeEventualSuccessReportsSuccess) { ...@@ -263,5 +263,21 @@ TEST_F(CrostiniDiskTestDbus, DiskResizeEventualSuccessReportsSuccess) {
EXPECT_EQ(result, true); EXPECT_EQ(result, true);
} }
TEST_F(CrostiniDiskTestDbus, DiskResizeNegativeHeadroom) {
vm_tools::concierge::ListVmDisksResponse response;
auto* image = response.add_images();
response.set_success(true);
image->set_name("vm_name");
image->set_image_type(vm_tools::concierge::DiskImageType::DISK_IMAGE_RAW);
image->set_min_size(1000);
image->set_size(3 * kGiB);
auto disk_info =
OnListVmDisksWithResult("vm_name", kDiskHeadroomBytes - 1, response);
ASSERT_TRUE(disk_info);
ASSERT_TRUE(disk_info->ticks.size() > 0);
ASSERT_EQ(disk_info->ticks.at(disk_info->ticks.size() - 1)->value, 3 * kGiB);
}
} // namespace disk } // namespace disk
} // namespace crostini } // namespace crostini
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment