Skip to content

Commit

Permalink
vm: Simplify extend_volume()
Browse files Browse the repository at this point in the history
Previously we accepted the current and maximum size of the volume, and
computed the next volume size, including one chunk of free space, and
ensuring that the size is limited by the volume capacity and qcow2
overhead.

This works for auto extending thin volume and for pre extend during
replication, but it does not work correctly for internal live merge,
when we don't want to add one chunk of free space. It also ugly that in
active layer merge we have to lie and call with the maximum required
size as the "current" size.

Change extend_volume() to accept the new size, moving the responsibility
to the caller. The 3 callers were update to compute the size using
drive.getNextVolumeSize().

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
  • Loading branch information
nirs authored and erav committed Jun 21, 2022
1 parent e47f4e6 commit f801083
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
5 changes: 3 additions & 2 deletions lib/vdsm/virt/livemerge.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,9 @@ def _start_extend(self, drive, job):
job_id=job.id,
attempt=job.extend["attempt"])

self._vm.extend_volume(
drive, job.base, max_alloc, capacity, callback=callback)
# New size includes one chunk of free space.
new_size = drive.getNextVolumeSize(max_alloc, capacity)
self._vm.extend_volume(drive, job.base, new_size, callback=callback)

def _retry_extend(self, job):
"""
Expand Down
18 changes: 8 additions & 10 deletions lib/vdsm/virt/thinp.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,11 @@ def _handle_exceeded(self, drive, urgent=False):
"Requesting an extension for volume %s on domain %s block_info %s",
drive.volumeID, drive.domainID, drive.block_info)

self.extend_volume(
drive,
drive.volumeID,
drive.block_info.physical,
drive.block_info.capacity)
# New size includes one chunk of free space.
new_size = drive.getNextVolumeSize(
drive.block_info.physical, drive.block_info.capacity)

self.extend_volume(drive, drive.volumeID, new_size)

def _can_extend_drive(self, drive):
# NOTE: Physical may be larger than maximum volume size since it is
Expand Down Expand Up @@ -521,10 +521,10 @@ def _amend_block_info(self, drive, block_info):

# Extending volumes.

def extend_volume(self, vmDrive, volumeID, curSize, capacity,
callback=None):
def extend_volume(self, vmDrive, volumeID, newSize, callback=None):
"""
Extend drive volume and its replica volume during replication.
Extend drive volume and its replica volume during replication to
newSize.
Must be called only when the drive or its replica are chunked.
Expand All @@ -535,8 +535,6 @@ def extend_volume(self, vmDrive, volumeID, curSize, capacity,
def callback(error=None):
"""
newSize = vmDrive.getNextVolumeSize(curSize, capacity)

# If drive is replicated to a block device, we extend first the
# replica, and handle drive later in _extend_replica_completed.

Expand Down
19 changes: 10 additions & 9 deletions lib/vdsm/virt/vm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,10 +1305,13 @@ def query_block_stats(self):
_, raw_stats = res[0]
return raw_stats

def extend_volume(self, vmDrive, volumeID, curSize, capacity,
callback=None):
def extend_volume(self, vmDrive, volumeID, new_size, callback=None):
"""
Extend drive volume and its replica volume during replication.
Extend drive volume and its replica volume during replication to
new_size.
The new size of the volume may be bigger than the requested value
because the actual volume size is always aligned to lvm extent size.
Must be called only when the drive or its replica are chunked.
Expand All @@ -1322,7 +1325,7 @@ def callback(error=None):
called.
"""
self.volume_monitor.extend_volume(
vmDrive, volumeID, curSize, capacity, callback=callback)
vmDrive, volumeID, new_size, callback=callback)

def should_refresh_destination_volume(self):
"""
Expand Down Expand Up @@ -4373,11 +4376,9 @@ def diskReplicateStart(self, srcDisk, dstDisk, need_extend=True):
try:
block_info = self.volume_monitor.query_block_info(
drive, drive.volumeID)
self.extend_volume(
drive,
drive.volumeID,
block_info.physical,
block_info.capacity)
new_size = drive.getNextVolumeSize(
block_info.physical, block_info.capacity)
self.extend_volume(drive, drive.volumeID, new_size)
except Exception:
self.log.exception("Initial extension request failed for %s",
drive.name)
Expand Down

0 comments on commit f801083

Please sign in to comment.