[NEW PATCH] BZ#736034 - Add metadataignore switch to pvcreate. (via gerrit-bot)
Eduardo Warszawski
ewarszaw at redhat.com
Sun Sep 11 07:27:05 UTC 2011
New patch submitted by Eduardo Warszawski (ewarszaw at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/908
commit 0bf8e1562f88dd3ff6888aaa429c308a7ce0026c
Author: Eduardo Warszawski <ewarszaw at redhat.com>
Date: Wed Sep 7 14:00:04 2011 +0300
BZ#736034 - Add metadataignore switch to pvcreate.
Change-Id: Ib040902610fd2c5b0de04de95b57f0bfbdd1e11e
diff --git a/vdsm/storage/lvm.py b/vdsm/storage/lvm.py
index 921cf3b..5ba5f6c 100644
--- a/vdsm/storage/lvm.py
+++ b/vdsm/storage/lvm.py
@@ -701,47 +701,59 @@ def _fqpvname(pv):
pv = os.path.join(PV_PREFIX, pv)
return pv
-def _initpv(device, metadataSize=0):
- if metadataSize > 0:
- # Size for pvcreate should be with units k|m|g
- metadatasize = str(metadataSize) + 'm'
- cmd = ["pvcreate", "--metadatasize", metadatasize, device]
- else:
- cmd = ["pvcreate", "--pvmetadatacopies", "0", device]
+def _initpvs(devices, metadataSize):
+ devices = _normalizeargs(devices)
+ # Size for pvcreate should be with units k|m|g
+ metadatasize = str(metadataSize) + 'm'
+ cmd = ["pvcreate", "--metadatasize", metadatasize, "metadacopies", "2", "--metadataignore"]
+ cmd.extend(devices)
#pvcreate on a dev that is already a PV but not in a VG returns rc = 0.
#The device is created with the new parameters.
rc, out, err = _lvminfo.cmd(cmd)
if rc != 0:
- # This could have failed because a VG
- # was removed on another host. Let us
- # check with lvm
- if isPvPartOfVg(device):
- raise se.PhysDevInitializationError(device)
-
- try:
- devicemapper.removeMappingsHoldingDevice(os.path.basename(device))
- except OSError, e:
- if e.errno == errno.ENODEV:
- raise se.PhysDevInitializationError("%s: %s" % (device, str(e)))
- else:
- raise
+ # This could have failed because a VG was removed on another host.
+ #Let us check with lvm
+ found, notFound = arePartOfVg(devices)
+ #If returned not found devices or any device is in a VG
+ if notFound or any(found.itervalues()):
+ raise se.PhysDevInitializationError("found: %s notFound: %s", found, notFound)
+ #All devices are free and reachable, calling the ghostbusters!
+ for device in devices:
+ try:
+ devicemapper.removeMappingsHoldingDevice(os.path.basename(device))
+ except OSError, e:
+ if e.errno == errno.ENODEV:
+ raise se.PhysDevInitializationError("%s: %s" % (device, str(e)))
+ else:
+ raise
+ #Retry pvcreate
rc, out, err = _lvminfo.cmd(cmd)
if rc != 0:
raise se.PhysDevInitializationError(device)
- _lvminfo._invalidatepvs(device)
+ _lvminfo._invalidatepvs(devices)
def getLvDmName(vgName, lvName):
return "%s-%s" % (vgName.replace("-", "--"), lvName)
-def isPvPartOfVg(pvName):
- cmd = ["pvs", "-o", "vg_name", "--noheading", pvName]
+def arePartOfVg(pvNames):
+ pvNames = _normalizeargs(pvNames)
+ cmd = ["pvs", "-o", "vg_name,pv_name", "--noheading"]
+ cmd.extend(pvNames)
rc, out, err = _lvminfo.cmd(cmd)
- if rc != 0:
- return False
+ found = {} #{pvName, vgName}
+ for line in out:
+ try:
+ #Safe: volume group name containg spaces is invalid
+ vgName, pvName = line.strip().split()
+ except ValueError:
+ found[pvName] = None #Free PV
+ else:
+ found[pvName] = vgName
+ notFound = (pvName for pvName in pvNames if pvName not in found.iterkeys())
- return ("".join(out).strip() != "")
+ return found, notFound
def removeVgMapping(vgName):
"""
@@ -845,9 +857,12 @@ def getLV(vgName, lvName=None):
def createVG(vgName, devices, initialTag, metadataSize, extentsize="128m"):
pvs = [_fqpvname(pdev) for pdev in _normalizeargs(devices)]
- _initpv(pvs[0], metadataSize)
- for dev in pvs[1:]:
- _initpv(dev)
+ _initpvs(pvs, metadataSize)
+ #Activate the 1st PV metadata areas
+ cmd = ["pvchange", "--metadataignore", "n"] + pvs[0]
+ rc, out, err = _lvminfo.cmd(cmd)
+ if rc == 0:
+ raise se.PhysDevInitializationError(pvs[0])
options = ["--physicalextentsize", extentsize]
if initialTag:
@@ -899,21 +914,20 @@ def renameVG(oldvg, newvg):
raise se.VolumeGroupRenameError()
-def extendVG(vg, devices):
+def extendVG(vgName, devices):
pvs = [_fqpvname(pdev) for pdev in _normalizeargs(devices)]
- for dev in pvs:
- pv = _lvminfo.getPv(dev)
- if not pv or pv.mda_count != 0:
- _initpv(dev)
+ vg = _lvminfo.getVg(vgName)
+ #Format extension PVs as all the other already in the VG
+ _initpvs(pvs, vg.vg_mda_size)
- cmd = ["vgextend", vg] + pvs
+ cmd = ["vgextend", vgName] + pvs
rc, out, err = _lvminfo.cmd(cmd)
if rc == 0:
_lvminfo._invalidatepvs(pvs)
- _lvminfo._invalidatevgs(vg)
+ _lvminfo._invalidatevgs(vgName)
log.debug("Cache after extending vg %s", _lvminfo._vgs)
else:
- raise se.VolumeGroupExtendError(vg, pvs)
+ raise se.VolumeGroupExtendError(vgName, pvs)
def chkVG(vgName):
More information about the vdsm-patches
mailing list