Пример #1
0
def deactivate():
    util.SMlog("MPATH: multipath deactivate called")
    cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
    if os.path.exists(iscsi_default_file):
        # Only do this if using our customized open-iscsi package
        util.pread2(cmd)

    # Stop the updatempppathd daemon
    if _is_mpp_daemon_running():
        cmd = ["service", "updatempppathd", "stop"]
        util.pread2(cmd)

    if _is_mpath_daemon_running():
        # Flush the multipath nodes
        for sid in mpath_cli.list_maps():
            reset(sid, True)

    # Disable any active MPP LUN maps (except the root dev)
    systemroot = os.path.realpath(util.getrootdev())
    for dev in glob.glob(DEVBYMPPPATH + "/*"):
        if os.path.realpath(dev) != systemroot:
            sid = os.path.basename(dev).split('-')[0]
            reset(sid)
        else:
            util.SMlog("MPP: Found root dev node, not resetting")

    # Check the ISCSI daemon doesn't have any active sessions, if not,
    # restart in the new mode
    if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
        iscsilib.restart_daemon()

    util.SMlog("MPATH: multipath deactivated.")
Пример #2
0
def createVG(root, vgname):
    systemroot = util.getrootdev()
    rootdev = root.split(',')[0]

    # Create PVs for each device
    for dev in root.split(','):
        if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
            raise xs_errors.XenError('Rootdev', \
                  opterr=('Device %s contains core system files, ' \
                          + 'please use another device') % dev)
        if not os.path.exists(dev):
            raise xs_errors.XenError('InvalidDev', \
                  opterr=('Device %s does not exist') % dev)

        f = _openExclusive(dev, True)
        os.close(f)
        try:
            # Overwrite the disk header, try direct IO first
            cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M",
                    "count=10", "oflag=direct"]
            util.pread2(cmd)
        except util.CommandException, inst:
            if inst.code == errno.EPERM:
                try:
                    # Overwrite the disk header, try normal IO
                    cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev,
                            "bs=1M", "count=10"]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
            else:
                raise xs_errors.XenError('LVMWrite', \
                      opterr='device %s' % dev)
Пример #3
0
def deactivate():
    util.SMlog("MPATH: multipath deactivate called")
    cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
    if os.path.exists(iscsi_default_file):
        # Only do this if using our customized open-iscsi package
        util.pread2(cmd)

    # Stop the updatempppathd daemon
    if _is_mpp_daemon_running():
        cmd = ["service", "updatempppathd", "stop"]
        util.pread2(cmd)

    if _is_mpath_daemon_running():
        # Flush the multipath nodes
        for sid in mpath_cli.list_maps():
            reset(sid,True)
        
    # Disable any active MPP LUN maps (except the root dev)
    systemroot = os.path.realpath(util.getrootdev())
    for dev in glob.glob(DEVBYMPPPATH + "/*"):
        if os.path.realpath(dev) != systemroot:
            sid = os.path.basename(dev).split('-')[0]
            reset(sid)
        else:
            util.SMlog("MPP: Found root dev node, not resetting")

    # Check the ISCSI daemon doesn't have any active sessions, if not,
    # restart in the new mode
    if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
        iscsilib.restart_daemon()
        
    util.SMlog("MPATH: multipath deactivated.")
Пример #4
0
def deactivate():
    util.SMlog("MPATH: multipath deactivate called")
    # Adjust any HBAs on the host
    cmd = [hba_script, "disable"]
    util.SMlog(util.pread2(cmd))
    cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
    util.pread2(cmd)

    # Stop the updatempppathd daemon
    if _is_mpp_daemon_running():
        cmd = ["/etc/init.d/updatempppathd", "stop"]
        util.pread2(cmd)

    if _is_mpath_daemon_running():
        # Flush the multipath nodes
        for sid in mpath_cli.list_maps():
            reset(sid, True)

    # Disable any active MPP LUN maps (except the root dev)
    systemroot = os.path.realpath(util.getrootdev())
    for dev in glob.glob(DEVBYMPPPATH + "/*"):
        if os.path.realpath(dev) != systemroot:
            sid = os.path.basename(dev).split('-')[0]
            reset(sid)
        else:
            util.SMlog("MPP: Found root dev node, not resetting")

    # Check the ISCSI daemon doesn't have any active sessions, if not,
    # restart in the new mode
    if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
        iscsilib.restart_daemon()

    util.SMlog("MPATH: multipath deactivated.")
Пример #5
0
def deactivate():
    util.SMlog("MPATH: multipath deactivate called")
    # Adjust any HBAs on the host
    cmd = [hba_script, "disable"]
    util.SMlog(util.pread2(cmd))
    cmd = ['ln', '-sf', iscsi_default_file, iscsi_file]
    util.pread2(cmd)

    # Stop the updatempppathd daemon
    if _is_mpp_daemon_running():
        cmd = ["/etc/init.d/updatempppathd", "stop"]
        util.pread2(cmd)

    if _is_mpath_daemon_running():
        # Flush the multipath nodes
        for sid in mpath_cli.list_maps():
            reset(sid,True)
        
    # Disable any active MPP LUN maps (except the root dev)
    systemroot = os.path.realpath(util.getrootdev())
    for dev in glob.glob(DEVBYMPPPATH + "/*"):
        if os.path.realpath(dev) != systemroot:
            sid = os.path.basename(dev).split('-')[0]
            reset(sid)
        else:
            util.SMlog("MPP: Found root dev node, not resetting")

    # Check the ISCSI daemon doesn't have any active sessions, if not,
    # restart in the new mode
    if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
        iscsilib.restart_daemon()
        
    util.SMlog("MPATH: multipath deactivated.")
Пример #6
0
def createVG(root, vgname):
    systemroot = util.getrootdev()
    rootdev = root.split(',')[0]

    # Create PVs for each device
    for dev in root.split(','):
        if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
            raise xs_errors.XenError('Rootdev', \
                  opterr=('Device %s contains core system files, ' \
                          + 'please use another device') % dev)
        if not os.path.exists(dev):
            raise xs_errors.XenError('InvalidDev', \
                  opterr=('Device %s does not exist') % dev)

        f = _openExclusive(dev, True)
        os.close(f)
        try:
            # Overwrite the disk header, try direct IO first
            cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M",
                    "count=10", "oflag=direct"]
            util.pread2(cmd)
        except util.CommandException, inst:
            if inst.code == errno.EPERM:
                try:
                    # Overwrite the disk header, try normal IO
                    cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev,
                            "bs=1M", "count=10"]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
            else:
                raise xs_errors.XenError('LVMWrite', \
                      opterr='device %s' % dev)
Пример #7
0
    def create(self, sr_uuid, size):
        if self._checkmount():
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')

        if not lvutil._checkVG(self.vgname):
            systemroot = util.getrootdev()
            rootdev = self.root.split(',')[0]
            # Create PVs for each device
            for dev in self.root.split(','):
                if dev in [systemroot, '%s1'%systemroot, '%s2'%systemroot]:
                    raise xs_errors.XenError('Rootdev', \
                        opterr=('Device %s contains core system files, ' \
                            + 'please use another device') % dev)

                if not os.path.exists(dev):
                    raise xs_errors.XenError('InvalidDev', \
                        opterr=('Device %s does not exist') % dev)

                try:
                    f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL)
                except:
                    raise xs_errors.XenError('SRInUse')
                os.close(f)
                try:
                    # Overwrite the disk header, try direct IO first
                    cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \
                           "count=100","oflag=direct"]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    if inst.code == errno.EPERM:
                        try:
                            cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \
                                   "count=100"]
                            util.pread2(cmd)
                        except util.CommandException, inst:
                            raise xs_errors.XenError('LVMWrite', 
                                  opterr='disk %s, error %d' % (dev, inst.code))
                    else:
                        raise xs_errors.XenError('LVMWrite', 
                              opterr='disk %s, error %d' % (dev, inst.code))
                if not lvutil._checkPV(dev):
                    try:                        
                        cmd = ["pvcreate", "--metadatasize", "10M", dev]
                        util.pread2(cmd)
                    except util.CommandException, inst:
                        raise xs_errors.XenError('LVMPartCreate', 
                              opterr='disk %s, error %d' % (dev, inst.code))
Пример #8
0
    def create(self, sr_uuid, size):
        if self._checkmount():
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')

        if not lvutil._checkVG(self.vgname):
            systemroot = util.getrootdev()
            rootdev = self.root.split(',')[0]
            # Create PVs for each device
            for dev in self.root.split(','):
                if dev in [systemroot, '%s1'%systemroot, '%s2'%systemroot]:
                    raise xs_errors.XenError('Rootdev', \
                        opterr=('Device %s contains core system files, ' \
                            + 'please use another device') % dev)

                if not os.path.exists(dev):
                    raise xs_errors.XenError('InvalidDev', \
                        opterr=('Device %s does not exist') % dev)

                try:
                    f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL)
                except:
                    raise xs_errors.XenError('SRInUse')
                os.close(f)
                try:
                    # Overwrite the disk header, try direct IO first
                    cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \
                           "count=100","oflag=direct"]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    if inst.code == errno.EPERM:
                        try:
                            cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \
                                   "count=100"]
                            util.pread2(cmd)
                        except util.CommandException, inst:
                            raise xs_errors.XenError('LVMWrite', 
                                  opterr='disk %s, error %d' % (dev, inst.code))
                    else:
                        raise xs_errors.XenError('LVMWrite', 
                              opterr='disk %s, error %d' % (dev, inst.code))
                if not lvutil._checkPV(dev):
                    try:                        
                        cmd = ["pvcreate", "--metadatasize", "10M", dev]
                        util.pread2(cmd)
                    except util.CommandException, inst:
                        raise xs_errors.XenError('LVMPartCreate', 
                              opterr='disk %s, error %d' % (dev, inst.code))
Пример #9
0
    def create(self, sr_uuid, size):
        if not self.isMaster:
            util.SMlog('sr_create blocked for non-master')
            raise xs_errors.XenError('LVMMaster')

        if lvutil._checkVG(self.vgname):
            raise xs_errors.XenError('SRExists')

        # Check none of the devices already in use by other PBDs
        if util.test_hostPBD_devs(self.session, self.root):
            raise xs_errors.XenError('SRInUse')

        # Check serial number entry in SR records
        for dev in self.root.split(','):
            if util.test_scsiserial(self.session, dev):
                raise xs_errors.XenError('SRInUse')
        
        systemroot = util.getrootdev()
        rootdev = self.root.split(',')[0]
        # Create PVs for each device
        for dev in self.root.split(','):
            if dev in [systemroot, '%s1'%systemroot, '%s2'%systemroot]:
                raise xs_errors.XenError('Rootdev', \
                      opterr=('Device %s contains core system files, ' \
                              + 'please use another device') % dev)
            if not os.path.exists(dev):
                raise xs_errors.XenError('InvalidDev', \
                      opterr=('Device %s does not exist') % dev)

            try:
                f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL)
            except:
                raise xs_errors.XenError('SRInUse', \
                      opterr=('Device %s in use, please check your existing ' \
                      + 'SRs for an instance of this device') % dev)
            os.close(f)
            try:
                # Overwrite the disk header, try direct IO first
                cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M","count=100", \
                       "oflag=direct"]
                util.pread2(cmd)
            except util.CommandException, inst:
                if inst.code == errno.EPERM:
                    try:
                        # Overwrite the disk header, try normal IO
                        cmd = ["dd","if=/dev/zero","of=%s" % dev,"bs=1M", \
                               "count=100"]
                        util.pread2(cmd)
                    except util.CommandException, inst:
                        raise xs_errors.XenError('LVMWrite', \
                              opterr='device %s' % dev)
                else:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
Пример #10
0
def createVG(root, vgname, sr_alloc='thick'):
    systemroot = util.getrootdev()
    rootdev = root.split(',')[0]

    # Create PVs for each device
    for dev in root.split(','):
        if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
            raise xs_errors.XenError('Rootdev', \
                  opterr=('Device %s contains core system files, ' \
                          + 'please use another device') % dev)
        if not os.path.exists(dev):
            raise xs_errors.XenError('InvalidDev', \
                  opterr=('Device %s does not exist') % dev)

        try:
            f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL)
        except:
            raise xs_errors.XenError('SRInUse', \
                  opterr=('Device %s in use, please check your existing ' \
                  + 'SRs for an instance of this device') % dev)
        os.close(f)
        try:
            # Overwrite the disk header, try direct IO first
            cmd = [
                util.CMD_DD, "if=/dev/zero",
                "of=%s" % dev, "bs=1M", "count=10", "oflag=direct"
            ]
            util.pread2(cmd)
        except util.CommandException, inst:
            if inst.code == errno.EPERM:
                try:
                    # Overwrite the disk header, try normal IO
                    cmd = [
                        util.CMD_DD, "if=/dev/zero",
                        "of=%s" % dev, "bs=1M", "count=10"
                    ]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
            else:
                raise xs_errors.XenError('LVMWrite', \
                      opterr='device %s' % dev)
Пример #11
0
def createVG(root, vgname, sr_alloc='thick'):
    systemroot = util.getrootdev()
    rootdev = root.split(',')[0]

    # Create PVs for each device
    for dev in root.split(','):
        if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
            raise xs_errors.XenError('Rootdev', \
                  opterr=('Device %s contains core system files, ' \
                          + 'please use another device') % dev)
        if not os.path.exists(dev):
            raise xs_errors.XenError('InvalidDev', \
                  opterr=('Device %s does not exist') % dev)

        try:
            f = os.open("%s" % dev, os.O_RDWR | os.O_EXCL)
        except:
            raise xs_errors.XenError('SRInUse', \
                  opterr=('Device %s in use, please check your existing ' \
                  + 'SRs for an instance of this device') % dev)
        os.close(f)
        try:
            # Overwrite the disk header, try direct IO first
            cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev, "bs=1M",
                    "count=10", "oflag=direct"]
            util.pread2(cmd)
        except util.CommandException, inst:
            if inst.code == errno.EPERM:
                try:
                    # Overwrite the disk header, try normal IO
                    cmd = [util.CMD_DD, "if=/dev/zero", "of=%s" % dev,
                            "bs=1M", "count=10"]
                    util.pread2(cmd)
                except util.CommandException, inst:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
            else:
                raise xs_errors.XenError('LVMWrite', \
                      opterr='device %s' % dev)
Пример #12
0
def deactivate():
    util.SMlog("MPATH: multipath deactivate called")

    if _is_mpath_daemon_running():
        # Flush the multipath nodes
        for sid in mpath_cli.list_maps():
            reset(sid, True)

    # Disable any active MPP LUN maps (except the root dev)
    systemroot = os.path.realpath(util.getrootdev())
    for dev in glob.glob(DEVBYMPPPATH + "/*"):
        if os.path.realpath(dev) != systemroot:
            sid = os.path.basename(dev).split('-')[0]
            reset(sid)
        else:
            util.SMlog("MPP: Found root dev node, not resetting")

    # Check the ISCSI daemon doesn't have any active sessions, if not,
    # restart in the new mode
    if iscsilib.is_iscsi_daemon_running() and not iscsilib._checkAnyTGT():
        iscsilib.restart_daemon()

    util.SMlog("MPATH: multipath deactivated.")
Пример #13
0
def scan(srobj):
    systemroot = util.getrootdev()
    hbadict = srobj.hbadict
    hbas = srobj.hbas
    dom = xml.dom.minidom.Document()
    e = dom.createElement("Devlist")
    dom.appendChild(e)

    if not os.path.exists(DEVPATH):
        return dom.toprettyxml()
    
    devs = srobj.devs
    vdis = {}

    for key in hbadict:
        hba = hbadict[key]
        path = os.path.join("/dev",key)
        realpath = path

        obj = srobj.vdi("")
        try:
            obj._query(realpath, devs[realpath][4])
        except:
            continue
        
        # Test for root dev or existing PBD
        if realpath == systemroot:
            continue
        elif util.test_SCSIid(srobj.session, obj.SCSIid):
            util.SMlog("SCSIid in use, ignoring (%s)" % obj.SCSIid)
            continue
        elif not devs.has_key(realpath):
            continue
        
        ids = devs[realpath]
        obj.adapter = ids[1]
        obj.channel = ids[2]
        obj.id = ids[3]
        obj.lun = ids[4]
        obj.hba = hba['procname']
        obj.numpaths = 1
        if vdis.has_key(obj.SCSIid):
            vdis[obj.SCSIid].numpaths += 1
            vdis[obj.SCSIid].path += " [%s]" % key
        elif obj.hba == 'mpp':
            mppdict = _genMPPHBA(obj.adapter)
            if mppdict.has_key(key):
                item = mppdict[key]
                adapters = ''
                for i in item:
                    if len(adapters):
                        adapters += ', '
                        obj.numpaths += 1
                    adapters += i
                if len(adapters):
                    obj.mpp = adapters
            vdis[obj.SCSIid] = obj
        else:    
            vdis[obj.SCSIid] = obj
                    
    for key in vdis:
        obj = vdis[key]
        d = dom.createElement("BlockDevice")
        e.appendChild(d)

        for attr in ['path','numpaths','SCSIid','vendor','serial','size','adapter','channel','id','lun','hba','mpp']:
            try:
                aval = getattr(obj, attr)
            except AttributeError:
                if attr in ['mpp']:
                    continue
                raise xs_errors.XenError('InvalidArg', \
                      opterr='Missing required field [%s]' % attr)
            entry = dom.createElement(attr)
            d.appendChild(entry)
            textnode = dom.createTextNode(str(aval))
            entry.appendChild(textnode)

    for key in hbas.iterkeys():
        a = dom.createElement("Adapter")
        e.appendChild(a)
        entry = dom.createElement('host')
        a.appendChild(entry)
        textnode = dom.createTextNode(key)
        entry.appendChild(textnode)

        entry = dom.createElement('name')
        a.appendChild(entry)
        textnode = dom.createTextNode(hbas[key])
        entry.appendChild(textnode)

        entry = dom.createElement('manufacturer')
        a.appendChild(entry)
        textnode = dom.createTextNode(getManufacturer(hbas[key]))
        entry.appendChild(textnode)

        id = key.replace("host","")
        entry = dom.createElement('id')
        a.appendChild(entry)
        textnode = dom.createTextNode(id)
        entry.appendChild(textnode)       
        
    return dom.toprettyxml()
Пример #14
0
def createVG(root, vgname):
    systemroot = util.getrootdev()
    rootdev = root.split(',')[0]

    # Create PVs for each device
    for dev in root.split(','):
        if dev in [systemroot, '%s1' % systemroot, '%s2' % systemroot]:
            raise xs_errors.XenError('Rootdev', \
                  opterr=('Device %s contains core system files, ' \
                          + 'please use another device') % dev)
        if not os.path.exists(dev):
            raise xs_errors.XenError('InvalidDev', \
                  opterr=('Device %s does not exist') % dev)

        f = _openExclusive(dev, True)
        os.close(f)
        try:
            # Overwrite the disk header, try direct IO first
            cmd = [
                util.CMD_DD, "if=/dev/zero",
                "of=%s" % dev, "bs=1M", "count=10", "oflag=direct"
            ]
            util.pread2(cmd)
        except util.CommandException as inst:
            if inst.code == errno.EPERM:
                try:
                    # Overwrite the disk header, try normal IO
                    cmd = [
                        util.CMD_DD, "if=/dev/zero",
                        "of=%s" % dev, "bs=1M", "count=10"
                    ]
                    util.pread2(cmd)
                except util.CommandException as inst:
                    raise xs_errors.XenError('LVMWrite', \
                          opterr='device %s' % dev)
            else:
                raise xs_errors.XenError('LVMWrite', \
                      opterr='device %s' % dev)

        if not (dev == rootdev):
            try:
                cmd_lvm(
                    [CMD_PVCREATE, "-ff", "-y", "--metadatasize", "10M", dev])
            except util.CommandException as inst:
                raise xs_errors.XenError('LVMPartCreate',
                                         opterr='error is %d' % inst.code)

    # Create VG on first device
    try:
        cmd_lvm([CMD_VGCREATE, "--metadatasize", "10M", vgname, rootdev])
    except:
        raise xs_errors.XenError('LVMGroupCreate')

    # Then add any additional devs into the VG
    for dev in root.split(',')[1:]:
        try:
            cmd_lvm([CMD_VGEXTEND, vgname, dev])
        except util.CommandException as inst:
            # One of the PV args failed, delete SR
            try:
                cmd_lvm([CMD_VGREMOVE, vgname])
            except:
                pass
            raise xs_errors.XenError('LVMGroupCreate')

    try:
        cmd_lvm([CMD_VGCHANGE, "-an", vgname])
    except util.CommandException as inst:
        raise xs_errors.XenError('LVMUnMount',
                                 opterr='errno is %d' % inst.code)