If the user changes the targetSize of a PartitionDevice, calculate a new geometry for the partition and mark the PartitionDevice for resizing. The new values are now in-memory and written to disk when resize() is called by the action's execute() method. --- storage/devices.py | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 47 insertions(+), 1 deletions(-) diff --git a/storage/devices.py b/storage/devices.py index de18113..f6880af 100644 --- a/storage/devices.py +++ b/storage/devices.py @@ -482,7 +482,17 @@ class StorageDevice(Device): self.format = format self.fstabComment = "" - self.targetSize = self._size + self._targetSize = self._size + + def _getTargetSize(self): + return self._targetSize + + def _setTargetSize(self, newsize): + self._targetSize = newsize + + targetSize = property(lambda s: s._getTargetSize(), + lambda s, v: s._setTargetSize(v), + doc="Target size of this device") def __str__(self): s = Device.__str__(self) @@ -889,6 +899,8 @@ class PartitionDevice(StorageDevice): self.bootable = False + self._resize = False + StorageDevice.__init__(self, name, format=format, size=size, major=major, minor=minor, exists=exists, sysfsPath=sysfsPath, parents=parents) @@ -947,6 +959,30 @@ class PartitionDevice(StorageDevice): "partedPart": self.partedPartition, "disk": self.disk}) return s + def _setTargetSize(self, newsize): + # a change in the target size means we need to resize the disk + # if targetSize is 0, it means we are initializing, so don't jump + # the gun and assume we're resizing + if newsize != self.targetSize and self.targetSize != 0: + self._resize = True + + self._targetSize = newsize + + if self._resize: + currentGeom = self.partedPartition.geometry + currentDev = currentGeom.device + newLen = long(self.targetSize * 1024 * 1024) / currentDev.sectorSize + geom = parted.Geometry(device=currentDev, + start=currentGeom.start, + length=newLen) + constraint = parted.Constraint(exactGeom=geom) + + partedDisk = self.disk.partedDisk + partedDisk.setPartitionGeometry(partition=self.partedPartition, + constraint=constraint, + start=geom.start, end=geom.end) + self.partedPartition = None + @property def partType(self): """ Get the partition's type (as parted constant). """ @@ -1102,6 +1138,16 @@ class PartitionDevice(StorageDevice): self.exists = True self.setup() + def resize(self, intf=None): + """ Resize the device. + + self.targetSize must be set to the new size. + """ + log_method_call(self, self.name, status=self.status) + + if self._resize: + self.disk.commit() + def destroy(self): """ Destroy the device. """ log_method_call(self, self.name, status=self.status) -- 1.6.2 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list