예제 #1
0
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)
예제 #2
0
파일: lvm.py 프로젝트: zofuthan/vdsm
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)
예제 #3
0
파일: lvm.py 프로젝트: zofuthan/vdsm
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)
예제 #4
0
파일: lvm.py 프로젝트: zofuthan/vdsm
 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