vm_tools: Fix concierge's disk-size location

Recent changes have been made to where vm disk storage locations are
mounted. As such the previous lookup location stopped working. This
would cause new VM disks to be created with the minimum size (1GB).

This change uses the desired disk's path to work out the mount, which is
more robust to changes in the storage locations going forward.

BUG=b:162539437
TEST=borealis start brand_new_vm

Change-Id: I6913f4e2e0115bb10736366340ff30a7b537058a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/2335617
Tested-by: Nic Hollingum <hollingum@google.com>
Reviewed-by: Fergus Dall <sidereal@google.com>
Reviewed-by: Nic Hollingum <hollingum@google.com>
Reviewed-by: Nicholas Verne <nverne@chromium.org>
Commit-Queue: Nic Hollingum <hollingum@google.com>
diff --git a/vm_tools/concierge/service.cc b/vm_tools/concierge/service.cc
index f4f5a69..4fdab11 100644
--- a/vm_tools/concierge/service.cc
+++ b/vm_tools/concierge/service.cc
@@ -388,11 +388,12 @@
   return false;
 }
 
-uint64_t CalculateDesiredDiskSize(uint64_t current_usage) {
-  // If no disk size was specified, use 90% of free space.
-  // Free space is calculated as if the disk image did not consume any space.
+// Returns the desired size of VM disks, which is 90% of the available space
+// (excluding the space already taken up by the disk).
+uint64_t CalculateDesiredDiskSize(base::FilePath disk_location,
+                                  uint64_t current_usage) {
   uint64_t free_space =
-      base::SysInfo::AmountOfFreeDiskSpace(base::FilePath("/home"));
+      base::SysInfo::AmountOfFreeDiskSpace(disk_location.DirName());
   free_space += current_usage;
   uint64_t disk_size = ((free_space * 9) / 10) & kDiskSizeMask;
 
@@ -647,8 +648,7 @@
     : next_seneschal_server_port_(kFirstSeneschalServerPort),
       quit_closure_(std::move(quit_closure)),
       host_kernel_version_(GetKernelVersion()),
-      weak_ptr_factory_(this) {
-}
+      weak_ptr_factory_(this) {}
 
 Service::~Service() {
   if (grpc_server_vm_) {
@@ -1788,7 +1788,7 @@
         LOG(INFO) << "Disk image has " << kDiskImageUserChosenSizeXattr
                   << " xattr - keeping existing size " << current_size;
       } else {
-        uint64_t disk_size = CalculateDesiredDiskSize(current_usage);
+        uint64_t disk_size = CalculateDesiredDiskSize(disk_path, current_usage);
         if (disk_size > current_size) {
           LOG(INFO) << "Expanding disk image from " << current_size << " to "
                     << disk_size;
@@ -1870,8 +1870,9 @@
     return dbus_response;
   }
 
-  uint64_t disk_size =
-      request.disk_size() ? request.disk_size() : CalculateDesiredDiskSize(0);
+  uint64_t disk_size = request.disk_size()
+                           ? request.disk_size()
+                           : CalculateDesiredDiskSize(disk_path, 0);
 
   if (request.image_type() == DISK_IMAGE_RAW ||
       request.image_type() == DISK_IMAGE_AUTO) {