On 03/20/2009 05:36 PM, David Lehman wrote:
On Fri, 2009-03-20 at 17:05 -1000, David Cantrell wrote:
Resizing existing filesystems on PartitionDevice objects now works
properly. I have resized ext3 and ntfs on existing partitions and
autopart takes over after that.
I have some concern about the self._resizePartition business, but if it
works I say we can hammer out the details later. Ack.
New patch attached.
LVM resizing is not done yet, but this patch takes care of the major
case: resizing existing Windows installations.
---
storage/devices.py | 69 ++++++++++++++++++++++++++++++++++-----------------
1 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/storage/devices.py b/storage/devices.py
index e1f08d3..1b33145 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -939,28 +939,25 @@ class PartitionDevice(StorageDevice):
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
+ if newsize != self.currentSize:
+ # change this partition's geometry in-memory so that other
+ # partitioning operations can complete (e.g., autopart)
+ self._targetSize = newsize
+ disk = self.disk.partedDisk
+
+ # keep a pointer to this partition in _origPartedDisk
+ i = 0
+ for partition in disk.partitions:
+ if partition == self.partedPartition:
+ break
+ i += 1
+ self._resizePartition = self.disk._origPartedDisk.partitions[i]
+
+ # resize the partition's geometry in memory
+ (constraint, geometry) = self._computeResize(self.partedPartition)
+ disk.setPartitionGeometry(partition=self.partedPartition,
+ constraint=constraint,
+ start=geometry.start, end=geometry.end)
@property
def path(self):
@@ -1146,6 +1143,20 @@ class PartitionDevice(StorageDevice):
self.exists = True
self.setup()
+ def _computeResize(self, partition):
+ log_method_call(self, self.name, status=self.status)
+
+ # compute new size for partition
+ currentGeom = partition.geometry
+ currentDev = currentGeom.device
+ newLen = long(self.targetSize * 1024 * 1024) / currentDev.sectorSize
+ newGeometry = parted.Geometry(device=currentDev,
+ start=currentGeom.start,
+ length=newLen)
+ constraint = parted.Constraint(exactGeom=newGeometry)
+
+ return (constraint, newGeometry)
+
def resize(self, intf=None):
""" Resize the device.
@@ -1153,8 +1164,20 @@ class PartitionDevice(StorageDevice):
"""
log_method_call(self, self.name, status=self.status)
- if self._resize:
+ if self.targetSize != self.currentSize:
+ # partedDisk has been restored to _origPartedDisk, so
+ # recalculate resize geometry because we may have new
+ # partitions on the disk, which could change constraints
+ partition = self._resizePartition
+ (constraint, geometry) = self._computeResize(partition)
+
+ self.disk.partedDisk.setPartitionGeometry(partition=partition,
+ constraint=constraint,
+ start=geometry.start,
+ end=geometry.end)
+
self.disk.commit()
+ self.notifyKernel()
def destroy(self):
""" Destroy the device. """
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
--
David Cantrell <dcantrell@xxxxxxxxxx>
Red Hat / Honolulu, HI
>From 49bc0ee23e0e827b79f141575fe1bddc1a50926f Mon Sep 17 00:00:00 2001
From: David Cantrell <dcantrell@xxxxxxxxxx>
Date: Wed, 18 Mar 2009 11:57:03 -1000
Subject: [anaconda-storage-branch PATCH 1/2] Make PartitionDevice resize work.
Resizing existing filesystems on PartitionDevice objects now works
properly. I have resized ext3 and ntfs on existing partitions and
autopart takes over after that.
LVM resizing is not done yet, but this patch takes care of the major
case: resizing existing Windows installations.
---
storage/devices.py | 61 ++++++++++++++++++++++++++++++++-------------------
1 files changed, 38 insertions(+), 23 deletions(-)
diff --git a/storage/devices.py b/storage/devices.py
index e1f08d3..ca32462 100644
--- a/storage/devices.py
+++ b/storage/devices.py
@@ -939,28 +939,17 @@ class PartitionDevice(StorageDevice):
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
+ if newsize != self.currentSize:
+ # change this partition's geometry in-memory so that other
+ # partitioning operations can complete (e.g., autopart)
+ self._targetSize = newsize
+ disk = self.disk.partedDisk
+
+ # resize the partition's geometry in memory
+ (constraint, geometry) = self._computeResize(self.partedPartition)
+ disk.setPartitionGeometry(partition=self.partedPartition,
+ constraint=constraint,
+ start=geometry.start, end=geometry.end)
@property
def path(self):
@@ -1146,6 +1135,20 @@ class PartitionDevice(StorageDevice):
self.exists = True
self.setup()
+ def _computeResize(self, partition):
+ log_method_call(self, self.name, status=self.status)
+
+ # compute new size for partition
+ currentGeom = partition.geometry
+ currentDev = currentGeom.device
+ newLen = long(self.targetSize * 1024 * 1024) / currentDev.sectorSize
+ newGeometry = parted.Geometry(device=currentDev,
+ start=currentGeom.start,
+ length=newLen)
+ constraint = parted.Constraint(exactGeom=newGeometry)
+
+ return (constraint, newGeometry)
+
def resize(self, intf=None):
""" Resize the device.
@@ -1153,8 +1156,20 @@ class PartitionDevice(StorageDevice):
"""
log_method_call(self, self.name, status=self.status)
- if self._resize:
+ if self.targetSize != self.currentSize:
+ # partedDisk has been restored to _origPartedDisk, so
+ # recalculate resize geometry because we may have new
+ # partitions on the disk, which could change constraints
+ partition = self.disk.partedDisk.getPartitionByPath(self.path)
+ (constraint, geometry) = self._computeResize(partition)
+
+ self.disk.partedDisk.setPartitionGeometry(partition=partition,
+ constraint=constraint,
+ start=geometry.start,
+ end=geometry.end)
+
self.disk.commit()
+ self.notifyKernel()
def destroy(self):
""" Destroy the device. """
--
1.6.2
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list