summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Cantrell <dcantrell@redhat.com>2008-12-03 20:15:07 (GMT)
committerDavid Cantrell <dcantrell@redhat.com>2008-12-03 20:15:07 (GMT)
commit0b41f2deb4e22172c6219338d5c33aed033c3133 (patch)
tree49510f948418cfa8f42ebb79f21dd044228109a0
parente1048bb9968246021fbca15f2345e17365a4c775 (diff)
downloadanaconda-0b41f2deb4e22172c6219338d5c33aed033c3133.zip
anaconda-0b41f2deb4e22172c6219338d5c33aed033c3133.tar.gz
anaconda-0b41f2deb4e22172c6219338d5c33aed033c3133.tar.xz
Better naming for LVM volume groups and logical volumes (#461682)
Try to name volume groups as vg_HOSTNAME and logical volumes as lv_MOUNTPOINT, if we can. Swap partitions will be lv_swapNN where NN is a unique number in the instance where more than one swap partition in use. The / partition will get the name lv_root. Fall back on the old naming system (VolGroupNN for volume groups and LogVolNN for logical volumes) for people doing custom setup or where the hostname is localhost. For swap partition naming, tack on an NN designation when there are more than 1 swap partitions requested. If only one is requested, it will be "lv_swap".
-rw-r--r--autopart.py41
-rw-r--r--fsset.py5
-rw-r--r--lvm.py57
3 files changed, 74 insertions, 29 deletions
diff --git a/autopart.py b/autopart.py
index ff62f37..716fb12 100644
--- a/autopart.py
+++ b/autopart.py
@@ -1463,7 +1463,7 @@ def doAutoPartition(anaconda):
# FIXME: this is a hack so that autopartition'd vgs
# can have a unique name
if req.autoname == 1 and req.volumeGroupName == "lvm":
- n = lvm.createSuggestedVGName(partitions)
+ n = lvm.createSuggestedVGName(partitions, anaconda.id.network)
req.volumeGroupName = n
if (isinstance(req, partRequests.LogicalVolumeRequestSpec)):
@@ -1649,11 +1649,15 @@ def autoCreateLVMPartitionRequests(autoreq):
requests.append(nr)
volnum = 0
+ swapvol = 0
+ totalswaps = 0
+
for (mntpt, fstype, minsize, maxsize, grow, format, asvol) in autoreq:
- if fstype:
- ptype = fsset.fileSystemTypeGet(fstype)
- else:
- ptype = fsset.fileSystemTypeGetDefault()
+ if fsset.fileSystemTypeGet(fstype) == fsset.fileSystemTypeGet("swap"):
+ totalswaps += 1
+
+ for (mntpt, fstype, minsize, maxsize, grow, format, asvol) in autoreq:
+ ptype = fsset.fileSystemTypeGet(fstype)
if not asvol:
newrequest = partRequests.PartitionSpec(ptype,
@@ -1663,17 +1667,38 @@ def autoCreateLVMPartitionRequests(autoreq):
grow = grow,
format = format)
else:
+ # try to incorporate the mount point in to the logical volume name
+ if mntpt is not None and mntpt != '':
+ if mntpt == '/':
+ lvtemplate = 'lv_root'
+ else:
+ tmp = string.strip(mntpt)
+ tmp = tmp.replace('/', '_')
+
+ while tmp.startswith('_'):
+ tmp = tmp[1:]
+
+ lvtemplate = "lv_%s" % (tmp,)
+ else:
+ if ptype == fsset.fileSystemTypeGet("swap"):
+ if totalswaps > 1:
+ lvtemplate = "lv_swap%02d" % (swapvol,)
+ swapvol += 1
+ else:
+ lvtemplate = "lv_swap"
+ else:
+ lvtemplate = "LogVol%02d" % (volnum,)
+ volnum += 1
+
newrequest = partRequests.LogicalVolumeRequestSpec(ptype,
mountpoint = mntpt,
size = minsize,
maxSizeMB = maxsize,
grow = grow,
format = format,
- lvname = "LogVol%02d" %(volnum,),
+ lvname = "%s" % (lvtemplate,),
volgroup = "lvm")
- volnum += 1
-
requests.append(newrequest)
return requests
diff --git a/fsset.py b/fsset.py
index b726985..a4b3cd4 100644
--- a/fsset.py
+++ b/fsset.py
@@ -78,7 +78,10 @@ def fileSystemTypeGetDefault():
def fileSystemTypeGet(key):
- return fileSystemTypes[key]
+ if fileSystemTypes.has_key(key):
+ return fileSystemTypes[key]
+ else:
+ return fileSystemTypeGetDefault()
def fileSystemTypeRegister(klass):
fileSystemTypes[klass.getName()] = klass
diff --git a/lvm.py b/lvm.py
index 00f7c02..0e07a1f 100644
--- a/lvm.py
+++ b/lvm.py
@@ -528,45 +528,62 @@ def getMaxLVSize(pe):
else:
return (16*1024*1024) #Max is 16TiB
-def createSuggestedVGName(partitions):
+def createSuggestedVGName(partitions, network):
"""Given list of partition requests, come up with a reasonable VG name
partitions - list of requests
"""
- i = 0
- while 1:
- tmpname = "VolGroup%02d" % (i,)
- if not partitions.isVolumeGroupNameInUse(tmpname):
- break
- i = i + 1
- if i>99:
- tmpname = ""
+ # try to create a volume group name incorporating the hostname
+ hn = network.hostname
+ if hn is not None and hn != '':
+ if hn == 'localhost' or hn == 'localhost.localdomain':
+ vgtemplate = "VolGroup"
+ elif hn.find('.') != -1:
+ vgtemplate = "vg_%s" % (hn.split('.')[0].lower(),)
+ else:
+ vgtemplate = "vg_%s" % (hn.lower(),)
+ else:
+ vgtemplate = "VolGroup"
+
+ if not partitions.isVolumeGroupNameInUse(vgtemplate):
+ return vgtemplate
+ else:
+ i = 0
+ while 1:
+ tmpname = "%s%02d" % (vgtemplate, i,)
+ if not partitions.isVolumeGroupNameInUse(tmpname):
+ break
+
+ i += 1
+ if i > 99:
+ tmpname = ""
+
+ return tmpname
- return tmpname
-
def createSuggestedLVName(logreqs):
"""Given list of LV requests, come up with a reasonable LV name
partitions - list of LV requests for this VG
"""
+
i = 0
lnames = []
for lv in logreqs:
- lnames.append(lv.logicalVolumeName)
-
+ lnames.append(lv.logicalVolumeName)
+
while 1:
- tmpname = "LogVol%02d" % (i,)
- if (logreqs is None) or (tmpname not in lnames):
- break
+ tmpname = "LogVol%02d" % (i,)
+ if (logreqs is None) or (tmpname not in lnames):
+ break
- i = i + 1
- if i>99:
- tmpname = ""
+ i += 1
+ if i > 99:
+ tmpname = ""
return tmpname
-
+
def getVGUsedSpace(vgreq, requests, diskset):
vgused = 0
for request in requests.requests: