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] #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 rc, out, err = _lvminfo.cmd(cmd) if rc != 0: raise se.PhysDevInitializationError(device)
def createVG(vgName, devices, initialTag, metadataSize, extentsize="128m", force=False): pvs = [_fqpvname(pdev) for pdev in _normalizeargs(devices)] _checkpvsblksize(pvs) _initpvs(pvs, metadataSize, force) # Activate the 1st PV metadata areas cmd = ["pvchange", "--metadataignore", "n"] cmd.append(pvs[0]) rc, out, err = _lvminfo.cmd(cmd, tuple(pvs)) if rc != 0: raise se.PhysDevInitializationError(pvs[0]) options = ["--physicalextentsize", extentsize] if initialTag: options.extend(("--addtag", initialTag)) cmd = ["vgcreate"] + options + [vgName] + pvs rc, out, err = _lvminfo.cmd(cmd, tuple(pvs)) if rc == 0: _lvminfo._invalidatepvs(pvs) _lvminfo._invalidatevgs(vgName) log.debug("Cache after createvg %s", _lvminfo._vgs) else: raise se.VolumeGroupCreateError(vgName, pvs)
def _initpvs(devices, metadataSize, force=False): def _initpvs_removeHolders(): """Remove holders for all devices.""" for device in devices: try: devicemapper.removeMappingsHoldingDevice( os.path.basename(device)) except OSError as e: if e.errno == errno.ENODEV: raise se.PhysDevInitializationError("%s: %s" % (device, str(e))) else: raise if force is True: options = ("-y", "-ff") _initpvs_removeHolders() else: options = tuple() rc, out, err = _createpv(devices, metadataSize, options) _lvminfo._invalidatepvs(devices) if rc != 0: log.error("pvcreate failed with rc=%s", rc) log.error("%s, %s", out, err) raise se.PhysDevInitializationError(str(devices)) return (set(devices), set(), rc, out, err)
def _initpvs_removeHolders(): """Remove holders for all devices.""" for device in devices: try: devicemapper.removeMappingsHoldingDevice( os.path.basename(device)) except OSError as e: if e.errno == errno.ENODEV: raise se.PhysDevInitializationError("%s: %s" % (device, str(e))) else: raise