FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu Masters Of The Universe

 
 
LinkBack Thread Tools
 
Old 02-11-2009, 11:54 PM
David Cantrell
 
Default Use parted.Disk.getPartitionByPath()

Removed the parted.getPartitionByName() function. There is now
a method on parted.Disk called getPartitionByPath() which provides
the same functionality, but only works on a single Disk.
---
autopart.py | 35 ++++++++++-----
bootloader.py | 9 ----
fsset.py | 12 ++++-
iscsi.py | 7 ++-
packages.py | 2 +-
partIntfHelpers.py | 128 +++++++++++++++++++++++++++++++---------------------
partRequests.py | 17 +++++--
7 files changed, 127 insertions(+), 83 deletions(-)

diff --git a/autopart.py b/autopart.py
index 648a1bb..a42cff6 100644
--- a/autopart.py
+++ b/autopart.py
@@ -70,7 +70,12 @@ else:
def bootRequestCheck(req, diskset):
if not req.device or req.ignoreBootConstraints:
return PARTITION_SUCCESS
- part = parted.getPartitionByName(req.device)
+
+ for drive in req.drive:
+ part = diskset.disks[drive].getPartitionByPath(req.device)
+ if part:
+ break
+
if not part:
return PARTITION_SUCCESS

@@ -85,10 +90,11 @@ def bootRequestCheck(req, diskset):
return bootAlphaCheckRequirements(part)
elif (iutil.getPPCMachine() == "pSeries" or
iutil.getPPCMachine() == "iSeries"):
- part = parted.getPartitionByName(req.device)
- if part and ((part.geometry.end * part.geometry.device.sectorSize /
- (1024.0 * 1024)) > 4096):
- return BOOTIPSERIES_TOO_HIGH
+ for drive in req.drive:
+ part = diskset.disks[drive].getPartitionByPath(req.device)
+ if part and ((part.geometry.end * part.geometry.device.sectorSize /
+ (1024.0 * 1024)) > 4096):
+ return BOOTIPSERIES_TOO_HIGH

return PARTITION_SUCCESS

@@ -124,15 +130,15 @@ def bootAlphaCheckRequirements(part):

return PARTITION_SUCCESS

-
def printNewRequestsCyl(diskset, newRequest):
for req in newRequest.requests:
if req.type != REQUEST_NEW:
continue

- part = parted.getPartitionByName(req.device)
-## print(req)
-## print("Start Cyl:%s End Cyl: %s" % (part.geometry.device.startSectorToCylinder(part.g eometry.start),
+ for drive in req.drive:
+ part = diskset.disks[drive].getPartitionByPath(req.device)
+## print(req)
+## print("Start Cyl:%s End Cyl: %s" % (part.geometry.device.startSectorToCylinder(part.g eometry.start),
## part.geometry.device.endSectorToCylinder(part.geom etry.end),))

def printFreespaceitem(part):
@@ -749,7 +755,11 @@ def growParts(diskset, requests, newParts):
donegrowing = 0

# get amount of space actually used by current allocation
- part = parted.getPartitionByName(request.device)
+ for drive in request.drive:
+ part = diskset.disks[drive].getPartitionByPath(request.device)
+ if part:
+ break
+
startSize = part.geometry.length

# compute fraction of freespace which to give to this
@@ -1033,7 +1043,10 @@ def processPartitioning(diskset, requests, newParts):
elif request.preexist:
# we need to keep track of the max size of preexisting partitions
# FIXME: we should also get the max size for LVs at some point
- part = parted.getPartitionByName(request.device)
+ for drive in request.drive:
+ part = diskset.disks[drive].getPartitionByPath(request.device)
+ if part:
+ break
request.maxResizeSize = part.getMaxAvailableSize(unit="MB")

## print("disk layout after everything is done")
diff --git a/bootloader.py b/bootloader.py
index 58d20b3..b78cfd7 100644
--- a/bootloader.py
+++ b/bootloader.py
@@ -121,15 +121,6 @@ def bootloaderSetupChoices(anaconda):
elif choices and choices.has_key("boot"):
anaconda.id.bootloader.setDevice(choices["boot"][0])

-
- bootDev = anaconda.id.fsset.getEntryByMountPoint("/")
- if not bootDev:
- bootDev = anaconda.id.fsset.getEntryByMountPoint("/boot")
- part = parted.getPartitionByName(bootDev.device.getDevice ())
- if part and part.geometry.device.endSectorToCylinder(part.geom etry.end) >= 1024:
- anaconda.id.bootloader.above1024 = 1
-
-
def writeBootloader(anaconda):
def dosync():
isys.sync()
diff --git a/fsset.py b/fsset.py
index 862ef24..085dba3 100644
--- a/fsset.py
+++ b/fsset.py
@@ -1637,7 +1637,7 @@ MAILADDR root
# set active partition on disks
# if an active partition is set, leave it alone; if none set
# set either our boot partition or the first partition on the drive active
- def setActive(self, diskset):
+ def setActive(self, diskset, requests):
dev = self.getBootDev()

if dev is None:
@@ -1646,8 +1646,14 @@ MAILADDR root
bootDev = dev.device

if dev.getName() != "RAIDDevice":
- part = parted.getPartitionByName(bootDev)
- drive = part.geometry.device.path[5:]
+ for request in requests:
+ if request.mountpoint = bootDev.mountpoint:
+ break
+
+ for drive in request.drive:
+ part = diskset.disks[drive].getPartitionByPath(bootDev)
+ if part:
+ break

# on EFI systems, *only* /boot/efi should be marked bootable
# similarly, on pseries, we really only want the PReP partition
diff --git a/iscsi.py b/iscsi.py
index 2886279..c9cbd08 100644
--- a/iscsi.py
+++ b/iscsi.py
@@ -578,11 +578,12 @@ class iscsi(object):
req = anaconda.id.partitions.getRequestByMountPoint("/")
root_requests = anaconda.id.partitions.getUnderlyingRequests(req)
for req in root_requests:
- # req.drive is unreliable <sigh> so figure it out ourselves
- part = parted.getPartitionByName(req.device)
+ for drive in req.drive:
+ part = anaconda.id.diskset.disks[drive].getPartitionByPath(req.device)
+ if part:
+ break
if not part:
continue
- drive = part.geometry.device.path[5:]
if drive not in root_drives:
root_drives.append(drive)

diff --git a/packages.py b/packages.py
index 7478c10..f871c49 100644
--- a/packages.py
+++ b/packages.py
@@ -134,7 +134,7 @@ def turnOnFilesystems(anaconda):
stdout = "/dev/tty5", stderr="/dev/tty5",
searchPath = 1)
anaconda.id.partitions.doMetaDeletes(anaconda.id.d iskset)
- anaconda.id.fsset.setActive(anaconda.id.diskset)
+ anaconda.id.fsset.setActive(anaconda.id.diskset, anaconda.id.partitions.requests)
try:
anaconda.id.fsset.shrinkFilesystems(anaconda.id.di skset, anaconda.rootPath)
except fsset.ResizeError, (e, dev):
diff --git a/partIntfHelpers.py b/partIntfHelpers.py
index 285264c..659da89 100644
--- a/partIntfHelpers.py
+++ b/partIntfHelpers.py
@@ -253,43 +253,65 @@ def doDeletePartitionsByDevice(intf, requestlist, diskset, device,
return

# get list of unique IDs of these requests
- reqIDs = []
+ reqIDs = set()
+ reqparts = {}
+
for req in requests:
- part = parted.getPartitionByName(req.device)
- if part.type & parted.PARTITION_FREESPACE or part.type & parted.PARTITION_METADATA or part.type & parted.PARTITION_PROTECTED:
- continue
- reqIDs.append(req.uniqueID)
+ for drive in req.drive:
+ part = diskset.disks[drive].getPartitionByPath(req.device)
+
+ if part.type & parted.PARTITION_FREESPACE or
+ part.type & parted.PARTITION_METADATA or
+ part.type & parted.PARTITION_PROTECTED:
+ continue
+
+ reqIDs.add(req.uniqueID)
+
+ if reqparts.has_key(req.uniqueID):
+ reqparts[req.uniqueID].append(part)
+ else:
+ reqparts[req.uniqueID] = [ part ]
+
+ reqIDs = list(reqIDs)

# now go thru and try to delete the unique IDs
for id in reqIDs:
try:
- req = requestlist.getRequestByID(id)
- if req is None:
- continue
- part = parted.getPartitionByName(req.device)
- rc = doDeletePartitionByRequest(intf, requestlist, part,
- confirm=0, quiet=1)
- if not rc:
- pass
+ req = requestlist.getRequestByID(id)
+ if req is None:
+ continue
+ for partlist in reqparts[id]:
+ for part in partlist:
+ rc = doDeletePartitionByRequest(intf, requestlist, part,
+ confirm=0, quiet=1)
+ if not rc:
+ pass
except:
- pass
+ pass

# see which partitions are left
notdeleted = []
left_requests = requestlist.getRequestsByDevice(diskset, device)
if left_requests:
- # get list of unique IDs of these requests
- leftIDs = []
- for req in left_requests:
- part = parted.getPartitionByName(req.device)
- if part.type & parted.PARTITION_FREESPACE or part.type & parted.PARTITION_METADATA or part.type & parted.PARTITION_PROTECTED:
- continue
- leftIDs.append(req.uniqueID)
-
- for id in leftIDs:
- req = requestlist.getRequestByID(id)
- notdeleted.append(req)
-
+ # get list of unique IDs of these requests
+ leftIDs = set()
+
+ for req in left_requests:
+ for drive in req.drive:
+ part = diskset.disks[drive].getPartitionByPath(req.device)
+
+ if part.type & parted.PARTITION_FREESPACE or
+ part.type & parted.PARTITION_METADATA or
+ part.type & parted.PARTITION_PROTECTED:
+ continue
+
+ leftIDs.add(req.uniqueID)
+
+ leftIDs = list(leftIDs)
+
+ for id in leftIDs:
+ req = requestlist.getRequestByID(id)
+ notdeleted.append(req)

# see if we need to report any failures - some were because we removed
# an extended partition which contained other members of our delete list
@@ -377,34 +399,38 @@ def doEditPartitionByRequest(intf, requestlist, part):

def checkForSwapNoMatch(anaconda):
"""Check for any partitions of type 0x82 which don't have a swap fs."""
+ diskset = anaconda.id.diskset
+
for request in anaconda.id.partitions.requests:
if not request.device or not request.fstype:
continue
-
- part = parted.getPartitionByName(request.device)
- if (part and (not part.type & parted.PARTITION_FREESPACE)
- and (part.getFlag(parted.PARTITION_SWAP))
- and (request.fstype and request.fstype.getName() != "swap")
- and (not request.format)):
- rc = anaconda.intf.messageWindow(_("Format as Swap?"),
- _("/dev/%s has a partition type of 0x82 "
- "(Linux swap) but does not appear to "
- "be formatted as a Linux swap "
- "partition.

"
- "Would you like to format this "
- "partition as a swap partition?")
- % (request.device), type = "yesno",
- custom_icon="question")
- if rc == 1:
- request.format = 1
- request.fstype = fsset.fileSystemTypeGet("swap")
- if request.fstype.getName() == "software RAID":
- part.setFlag(parted.PARTITION_RAID)
- else:
- part.unsetFlag(parted.PARTITION_RAID)
-
- partedUtils.set_partition_file_system_type(part,
- request.fstype)
+
+ for drive in request.drive:
+ part = diskset.disks[drive].getPartitionByPath(request.device)
+
+ if (part and (not part.type & parted.PARTITION_FREESPACE)
+ and (part.getFlag(parted.PARTITION_SWAP))
+ and (request.fstype and request.fstype.getName() != "swap")
+ and (not request.format)):
+ rc = anaconda.intf.messageWindow(_("Format as Swap?"),
+ _("/dev/%s has a partition type of 0x82 "
+ "(Linux swap) but does not appear to "
+ "be formatted as a Linux swap "
+ "partition.

"
+ "Would you like to format this "
+ "partition as a swap partition?")
+ % (request.device), type = "yesno",
+ custom_icon="question")
+ if rc == 1:
+ request.format = 1
+ request.fstype = fsset.fileSystemTypeGet("swap")
+ if request.fstype.getName() == "software RAID":
+ part.setFlag(parted.PARTITION_RAID)
+ else:
+ part.unsetFlag(parted.PARTITION_RAID)
+
+ partedUtils.set_partition_file_system_type(part,
+ request.fstype)

def mustHaveSelectedDrive(intf):
txt =_("You need to select at least one hard drive to install %s.") % (productName,)
diff --git a/partRequests.py b/partRequests.py
index d768bd3..d8de5e6 100644
--- a/partRequests.py
+++ b/partRequests.py
@@ -517,11 +517,18 @@ class PartitionSpec(RequestSpec):

def getActualSize(self, partitions, diskset):
"""Return the actual size allocated for the request in megabytes."""
- part = parted.getPartitionByName(self.device)
- if not part:
- # XXX kickstart might still call this before allocating the partitions
- raise RuntimeError, "Checking the size of a partition which hasn't been allocated yet"
- return part.getSize(unit="MB")
+ size = 0
+
+ for drive in self.drive:
+ part = diskset.disks[drive].getPartitionByPath(self.device)
+
+ if not part:
+ # XXX kickstart might still call this before allocating the partitions
+ raise RuntimeError, "Checking the size of a partition which hasn't been allocated yet"
+
+ size += part.getSize(unit="MB")
+
+ return size

def doSizeSanityCheck(self):
"""Sanity check that the size of the partition is sane."""
--
1.6.1.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 

Thread Tools




All times are GMT. The time now is 03:04 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org