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)
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.")
def _getLvmInfo(self, vg_name): """ Parses the LVM volume and returns a config dict :param vg_name: Name of the VG :return: lvm config dict """ _fd, temp_file = tempfile.mkstemp() util.pread2(['vgcfgbackup', '-f', temp_file, vg_name]) # parse old config lvm_config = lvmconfigparser.LvmConfigParser() lvm_config.parse(temp_file) lvm_config_dict = lvm_config.toDict() os.remove(temp_file) assert vg_name in lvm_config_dict, "No volume group found" assert 'physical_volumes' in lvm_config_dict[ vg_name], "No physical volumes found" assert len(lvm_config_dict[vg_name]['physical_volumes'] ) == 1, "LUN should container only 1 physical volume" assert 'logical_volumes' in lvm_config_dict[ vg_name], "No logical volumes found" return lvm_config_dict
def _resetDMP(sid,explicit_unmap=False,delete_nodes=False): # If mpath has been turned on since the sr/vdi was attached, we # might be trying to unmap it before the daemon has been started # This is unnecessary (and will fail) so just return. deactivate_MPdev(sid) if not _is_mpath_daemon_running(): util.SMlog("Warning: Trying to unmap mpath device when multipathd not running") return # If the multipath daemon is running, but we were initially plugged # with multipathing set to no, there may be no map for us in the multipath # tables. In that case, list_paths will return [], but remove_map might # throw an exception. Catch it and ignore it. if explicit_unmap: util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-f', sid]), maxretry = 3, period = 4) util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-W']), maxretry = 3, period = 4) else: mpath_cli.ensure_map_gone(sid) path = "/dev/mapper/%s" % sid if not util.wait_for_nopath(path, 10): util.SMlog("MPATH: WARNING - path did not disappear [%s]" % path) else: util.SMlog("MPATH: path disappeared [%s]" % path)
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.")
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.")
def _rollback_snapshot(self, base_uuid, snap_uuid): vdi_name = "%s%s" % (VDI_PREFIX, base_uuid) snapshot_name = "%s@%s%s" % (vdi_name, SNAPSHOT_PREFIX, snap_uuid) util.pread2([ "rbd", "snap", "rollback", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER ])
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.")
def create(self, sr_uuid, vdi_uuid, size): if not self.sr.isMaster: util.SMlog('vdi_create blocked for non-master') raise xs_errors.XenError('LVMMaster') try: mb = 1024L * 1024L size_mb = (long(size) + mb - 1L) / mb # round up # Rather than bailing out for small sizes, just round up to 1 MiB. The # LVM code will round up to the nearest PE size anyway (probably 4 MiB) if size_mb == 0: size_mb = 1 if lvutil._checkLV(self.path): raise xs_errors.XenError('VDIExists') # Verify there's sufficient space for the VDI stats = lvutil._getVGstats(self.sr.vgname) freespace = stats['physical_size'] - stats['physical_utilisation'] if freespace < long(size): raise xs_errors.XenError('SRNoSpace') cmd = ["lvcreate", "-n", self.lvname, "-L", str(size_mb), \ self.sr.vgname] text = util.pread2(cmd) cmd = ["lvchange", "-an", self.path] text = util.pread2(cmd) self.size = lvutil._getLVsize(self.path) self.utilisation = self.size except util.CommandException, inst: raise xs_errors.XenError('LVMCreate', \ opterr='lv operation failed error is %d' % inst.code)
def _do_snapshot(self, vdi_uuid, snap_uuid): util.SMlog( "Calling cephutils.VDI._do_snapshot: vdi_uuid=%s, snap_uuid=%s" % (vdi_uuid, snap_uuid)) vdi_name = "%s%s" % (VDI_PREFIX, vdi_uuid) snapshot_name = "%s@%s%s" % (vdi_name, SNAPSHOT_PREFIX, snap_uuid) vdi_ref = self.session.xenapi.VDI.get_by_uuid(vdi_uuid) sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref) if sm_config.has_key('attached') and not sm_config.has_key('paused'): if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, vdi_uuid): raise util.SMException("failed to pause VDI %s" % vdi_uuid) self.__unmap_VHD(vdi_uuid) #--- util.pread2([ "rbd", "snap", "create", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER ]) util.pread2([ "rbd", "snap", "protect", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER ]) #--- if sm_config.has_key('attached') and not sm_config.has_key('paused'): self.__map_VHD(vdi_uuid) blktap2.VDI.tap_unpause(self.session, self.sr.uuid, vdi_uuid, None)
def __map(session, arg_dict): mode = arg_dict['mode'] _dev_name = arg_dict['_dev_name'] _dmdev_name = arg_dict['_dmdev_name'] _dm_name = arg_dict['_dm_name'] CEPH_POOL_NAME = arg_dict['CEPH_POOL_NAME'] CEPH_USER = arg_dict['CEPH_USER'] NBDS_MAX = arg_dict['NBDS_MAX'] sharable = arg_dict['sharable'] dm = arg_dict['dm'] _vdi_name = arg_dict['_vdi_name'] if mode == "kernel": dev = util.pread2(["rbd", "map", _vdi_name, "--pool", CEPH_POOL_NAME, "--name", CEPH_USER]) elif mode == "fuse": pass elif mode == "nbd": dev = "%s%s" % ("/dev/nbd", arg_dict['dev']) if sharable == "true": _disable_rbd_caching() dev = util.pread2(["rbd", "nbd", "map", "--device", dev, "--nbds_max", NBDS_MAX, "-c", "/etc/ceph/ceph.conf.nocaching", "%s/%s" % (CEPH_POOL_NAME, _vdi_name), "--name", CEPH_USER]).rstrip('\n') else: dev = util.pread2(["rbd", "nbd", "map", "--device", dev, "--nbds_max", NBDS_MAX, "%s/%s" % (CEPH_POOL_NAME, _vdi_name), "--name", CEPH_USER]).rstrip('\n') if dm != "none": util.pread2(["dmsetup", "resume", _dm_name]) return "mapped"
def _checkPV(pvname): try: cmd = [CMD_PVS, pvname] util.pread2(cmd) return True except: return False
def _checkLV(path): try: cmd = [CMD_LVDISPLAY, path] util.pread2(cmd) return True except: return False
def _map(session, arg_dict): mode = arg_dict['mode'] dev_name = arg_dict['dev_name'] CEPH_POOL_NAME = arg_dict['CEPH_POOL_NAME'] CEPH_USER = arg_dict['CEPH_USER'] NBDS_MAX = arg_dict['NBDS_MAX'] if arg_dict.has_key("snap_name"): vdi_name = arg_dict["snap_name"] else: vdi_name = arg_dict['vdi_name'] if mode == "kernel": util.pread2([ "rbd", "map", vdi_name, "--pool", CEPH_POOL_NAME, "--name", CEPH_USER ]) elif mode == "fuse": pass elif mode == "nbd": cmdout = util.pread2([ "rbd-nbd", "--nbds_max", NBDS_MAX, "map", "%s/%s" % (CEPH_POOL_NAME, vdi_name), "--name", CEPH_USER ]).rstrip('\n') util.pread2(["ln", "-s", cmdout, dev_name]) return "mapped"
def _LUNprint(self, sr_uuid): if self.iscsi.attached: # Force a rescan on the bus. self.iscsi.refresh() # time.sleep(5) # Now call attach (handles the refcounting + session activa) self.iscsi.attach(sr_uuid) util.SMlog("LUNprint: waiting for path: %s" % self.iscsi.path) if util.wait_for_path("%s/LUN*" % self.iscsi.path, ISCSISR.MAX_TIMEOUT): try: adapter = self.iscsi.adapter[self.iscsi.address] util.SMlog("adapter=%s" % adapter) # find a scsi device on which to issue a report luns command: devs = glob.glob("%s/LUN*" % self.iscsi.path) sgdevs = [] for i in devs: sgdevs.append(int(i.split("LUN")[1])) sgdevs.sort() sgdev = "%s/LUN%d" % (self.iscsi.path, sgdevs[0]) # issue a report luns: luns = util.pread2(["/usr/bin/sg_luns", "-q", sgdev]).split('\n') nluns = len( luns) - 1 # remove the line relating to the final \n # check if the LUNs are MPP-RDAC Luns scsi_id = scsiutil.getSCSIid(sgdev) mpp_lun = False if (mpp_luncheck.is_RdacLun(scsi_id)): mpp_lun = True link = glob.glob('/dev/disk/by-scsibus/%s-*' % scsi_id) mpp_adapter = link[0].split('/')[-1].split('-')[-1].split( ':')[0] # make sure we've got that many sg devices present for i in range(0, 30): luns = scsiutil._dosgscan() sgdevs = filter(lambda r: r[1] == adapter, luns) if mpp_lun: sgdevs.extend( filter(lambda r: r[1] == mpp_adapter, luns)) if len(sgdevs) >= nluns: util.SMlog("Got all %d sg devices" % nluns) break else: util.SMlog("Got %d sg devices - expecting %d" % (len(sgdevs), nluns)) time.sleep(1) util.pread2(["/sbin/udevsettle"]) except: pass # Make sure we don't break the probe... self.iscsi.print_LUNs() self.iscsi.detach(sr_uuid)
def _resetDMP(sid, explicit_unmap=False): # If mpath has been turned on since the sr/vdi was attached, we # might be trying to unmap it before the daemon has been started # This is unnecessary (and will fail) so just return. deactivate_MPdev(sid) if not _is_mpath_daemon_running(): util.SMlog("Warning: Trying to unmap mpath device when multipathd not running") return # If the multipath daemon is running, but we were initially plugged # with multipathing set to no, there may be no map for us in the multipath # tables. In that case, list_paths will return [], but remove_map might # throw an exception. Catch it and ignore it. if explicit_unmap: util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-f', sid]), maxretry=3, period=4) util.retry(lambda: util.pread2(['/usr/sbin/multipath', '-W']), maxretry=3, period=4) else: mpath_cli.ensure_map_gone(sid) path = "/dev/mapper/%s" % sid if not util.wait_for_nopath(path, 10): util.SMlog("MPATH: WARNING - path did not disappear [%s]" % path) else: util.SMlog("MPATH: path disappeared [%s]" % path)
def _checkVG(vgname): try: cmd = [CMD_VGS, vgname] util.pread2(cmd) return True except: return False
def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("RBDVDI.attach_from_config") self.sr.attach(sr_uuid) try: vdi_name = "%s%s" % (cephutils.VDI_PREFIX, vdi_uuid) dev_name = "%s/%s" % (self.sr.SR_ROOT, vdi_name) self.path = self.sr._get_path(vdi_uuid) if self.mode == "kernel": util.pread2([ "rbd", "map", vdi_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER ]) elif self.mode == "fuse": pass elif self.mode == "nbd": cmdout = util.pread2([ "rbd-nbd", "--nbds_max", str(cephutils.NBDS_MAX), "map", "%s/%s" % (self.sr.CEPH_POOL_NAME, vdi_name), "--name", self.sr.CEPH_USER ]).rstrip('\n') util.pread2(["ln", "-s", cmdout, dev_name]) return VDI.VDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("RBDVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk')
def _rename_image(self, orig_uuid, new_uuid): util.SMlog( "Calling cephutils.VDI._rename_image: orig_uuid=%s, new_uuid=%s" % (orig_uuid, new_uuid)) orig_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, VDI_PREFIX, orig_uuid) new_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, VDI_PREFIX, new_uuid) util.pread2( ["rbd", "mv", orig_name, new_name, "--name", self.sr.CEPH_USER])
def _change_image_prefix_to_VHD(self, vdi_uuid): util.SMlog( "Calling cephutils.VDI._change_image_prefix_to_VHD: vdi_uuid=%s" % vdi_uuid) orig_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, SXM_PREFIX, vdi_uuid) new_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, VDI_PREFIX, vdi_uuid) util.pread2( ["rbd", "mv", orig_name, new_name, "--name", self.sr.CEPH_USER])
def activate(): util.SMlog("MPATH: multipath activate called") cmd = ['ln', '-sf', iscsi_mpath_file, iscsi_file] try: util.pread2(cmd) except util.CommandException, ce: if not ce.reason.endswith(': File exists'): raise
def create(name, size, vgname, tag = None, activate = True): size_mb = size / 1024 / 1024 cmd = [CMD_LVCREATE, "-n", name, "-L", str(size_mb), vgname] if tag: cmd.extend(["--addtag", tag]) if not activate: cmd.extend(["--inactive", "--zero=n"]) util.pread2(cmd)
def detach(self, sr_uuid): super(EXTSR, self).detach(sr_uuid) try: # deactivate SR cmd = ["lvchange", "-an", self.remotepath] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMUnMount', \ opterr='lvm -an failed errno is %d' % inst.code)
def create(name, size, vgname, tag=None, size_in_percentage=None): if size_in_percentage: cmd = [CMD_LVCREATE, "-n", name, "-l", size_in_percentage, vgname] else: size_mb = size / 1024 / 1024 cmd = [CMD_LVCREATE, "-n", name, "-L", str(size_mb), vgname] if tag: cmd.extend(["--addtag", tag]) util.pread2(cmd)
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, sr_uuid, 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): lvutil.createVG(self.root, self.vgname) if lvutil._checkLV(self.remotepath): raise xs_errors.XenError('SRExists') try: numdevs = len(self.root.split(',')) cmd = ["lvcreate", "-n", sr_uuid] if numdevs > 1: lowest = -1 for dev in self.root.split(','): stats = lvutil._getPVstats(dev) if lowest < 0 or stats['freespace'] < lowest: lowest = stats['freespace'] size_mb = (lowest / (1024 * 1024)) * numdevs # Add stripe parameter to command cmd += ["-i", str(numdevs), "-I", "2048"] else: stats = lvutil._getVGstats(self.vgname) size_mb = stats['freespace'] / (1024 * 1024) assert (size_mb > 0) cmd += ["-L", str(size_mb), self.vgname] text = util.pread(cmd) cmd = ["lvchange", "-ay", self.remotepath] text = util.pread(cmd) except util.CommandException as inst: raise xs_errors.XenError('LVMCreate', \ opterr='lv operation, error %d' % inst.code) except AssertionError: raise xs_errors.XenError('SRNoSpace', \ opterr='Insufficient space in VG %s' % self.vgname) try: util.pread2(["mkfs.ext4", "-F", self.remotepath]) except util.CommandException as inst: raise xs_errors.XenError('LVMFilesystem', \ opterr='mkfs failed error %d' % inst.code) #Update serial number string scsiutil.add_serial_record(self.session, self.sr_ref, \ scsiutil.devlist_to_serialstring(self.root.split(',')))
def detach(self, sr_uuid): super(EXTSR, self).detach(sr_uuid) try: # deactivate SR cmd = ["lvchange", "-an", self.remotepath] util.pread2(cmd) except util.CommandException as inst: raise xs_errors.XenError('LVMUnMount', \ opterr='lvm -an failed errno is %d' % inst.code)
def _lvmBugCleanup(path): # the device should not exist at this point. If it does, this was an LVM # bug, and we manually clean up after LVM here mapperDevice = path[5:].replace("-", "--").replace("/", "-") mapperPath = "/dev/mapper/" + mapperDevice nodeExists = False cmd_st = [CMD_DMSETUP, "status", mapperDevice] cmd_rm = [CMD_DMSETUP, "remove", mapperDevice] cmd_rf = [CMD_DMSETUP, "remove", mapperDevice, "--force"] try: util.pread(cmd_st, expect_rc=1) except util.CommandException as e: if e.code == 0: nodeExists = True if not util.pathexists(mapperPath) and not nodeExists: return util.SMlog("_lvmBugCleanup: seeing dm file %s" % mapperPath) # destroy the dm device if nodeExists: util.SMlog("_lvmBugCleanup: removing dm device %s" % mapperDevice) for i in range(LVM_FAIL_RETRIES): try: util.pread2(cmd_rm) break except util.CommandException as e: if i < LVM_FAIL_RETRIES - 1: util.SMlog("Failed on try %d, retrying" % i) try: util.pread(cmd_st, expect_rc=1) util.SMlog("_lvmBugCleanup: dm device {}" " removed".format(mapperDevice)) break except: cmd_rm = cmd_rf time.sleep(1) else: # make sure the symlink is still there for consistency if not os.path.lexists(path): os.symlink(mapperPath, path) util.SMlog("_lvmBugCleanup: restored symlink %s" % path) raise e if util.pathexists(mapperPath): os.unlink(mapperPath) util.SMlog("_lvmBugCleanup: deleted devmapper file %s" % mapperPath) # delete the symlink if os.path.lexists(path): os.unlink(path) util.SMlog("_lvmBugCleanup: deleted symlink %s" % path)
def _LUNprint(self, sr_uuid): if self.iscsi.attached: # Force a rescan on the bus. self.iscsi.refresh() # time.sleep(5) # Now call attach (handles the refcounting + session activa) self.iscsi.attach(sr_uuid) util.SMlog("LUNprint: waiting for path: %s" % self.iscsi.path) if util.wait_for_path("%s/LUN*" % self.iscsi.path, ISCSISR.MAX_TIMEOUT): try: adapter=self.iscsi.adapter[self.iscsi.address] util.SMlog("adapter=%s" % adapter) # find a scsi device on which to issue a report luns command: devs=glob.glob("%s/LUN*" % self.iscsi.path) sgdevs = [] for i in devs: sgdevs.append(int(i.split("LUN")[1])) sgdevs.sort() sgdev = "%s/LUN%d" % (self.iscsi.path,sgdevs[0]) # issue a report luns: luns=util.pread2(["/usr/bin/sg_luns","-q",sgdev]).split('\n') nluns=len(luns)-1 # remove the line relating to the final \n # check if the LUNs are MPP-RDAC Luns scsi_id = scsiutil.getSCSIid(sgdev) mpp_lun = False if (mpp_luncheck.is_RdacLun(scsi_id)): mpp_lun = True link=glob.glob('/dev/disk/by-scsibus/%s-*' % scsi_id) mpp_adapter = link[0].split('/')[-1].split('-')[-1].split(':')[0] # make sure we've got that many sg devices present for i in range(0,30): luns=scsiutil._dosgscan() sgdevs=filter(lambda r: r[1]==adapter, luns) if mpp_lun: sgdevs.extend(filter(lambda r: r[1]==mpp_adapter, luns)) if len(sgdevs)>=nluns: util.SMlog("Got all %d sg devices" % nluns) break else: util.SMlog("Got %d sg devices - expecting %d" % (len(sgdevs),nluns)) time.sleep(1) if os.path.exists("/sbin/udevsettle"): util.pread2(["/sbin/udevsettle"]) else: util.pread2(["/sbin/udevadm","settle"]) except: util.SMlog("Generic exception caught. Pass") pass # Make sure we don't break the probe... self.iscsi.print_LUNs() self.iscsi.detach(sr_uuid)
def _map_VHD(self, vdi_uuid): vdi_name = "%s%s" % (VDI_PREFIX, vdi_uuid) dev_name = "%s/%s" % (self.sr.SR_ROOT, vdi_name) if self.mode == "kernel": util.pread2(["rbd", "map", vdi_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER]) elif self.mode == "fuse": pass elif self.mode == "nbd": cmdout = util.pread2(["rbd-nbd", "--nbds_max", str(NBDS_MAX), "map", "%s/%s" % (self.sr.CEPH_POOL_NAME, vdi_name), "--name", self.sr.CEPH_USER]).rstrip('\n') util.pread2(["ln", "-s", cmdout, dev_name])
def _flatten_clone(self, clone_uuid): if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, clone_uuid): raise util.SMException("failed to pause VDI %s" % clone_uuid) self._unmap_VHD(clone_uuid) #--- ?????? CHECK For running VM. What if flattening takes a long time and vdi is paused during this process clone_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, CLONE_PREFIX, clone_uuid) util.pread2(["rbd", "flatten", clone_name, "--name", self.sr.CEPH_USER]) #--- ?????? self._map_VHD(clone_uuid) blktap2.VDI.tap_unpause(self.session, self.sr.uuid, clone_uuid, None)
def resize(self, sr_uuid, vdi_uuid, size): if not blktap2.VDI.tap_pause(self.session, self,sr.uuid, vdi_uuid): raise util.SMException("failed to pause VDI %s" % vdi_uuid) self._unmap_VHD(vdi_uuid) #--- image_size = size / 1024 / 1024 util.pread2(["rbd", "resize", "--size", str(image_size), "--allow-shrink", self.CEPH_VDI_NAME, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER]) #--- self._map_VHD(vdi_uuid) blktap2.VDI.tap_unpause(self.session, self.sr.uuid, vdi_uuid, None)
def _rollback_snapshot(self, base_uuid, snap_uuid): util.SMlog( "Calling cephutils.VDI._rollback_snapshot: base_uuid=%s, snap_uuid=%s" % (base_uuid, snap_uuid)) vdi_name = "%s%s" % (VDI_PREFIX, base_uuid) snapshot_name = "%s@%s%s" % (vdi_name, SNAPSHOT_PREFIX, snap_uuid) util.pread2([ "rbd", "snap", "rollback", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER ])
def activate(): util.SMlog("MPATH: multipath activate called") cmd = ['ln', '-sf', iscsi_mpath_file, iscsi_file] try: if os.path.exists(iscsi_mpath_file): # Only do this if using our customized open-iscsi package util.pread2(cmd) except util.CommandException, ce: if not ce.reason.endswith(': File exists'): raise
def removeDevMapperEntry(path): try: # remove devmapper entry using dmsetup cmd = [CMD_DMSETUP, "remove", path] util.pread2(cmd) return True except Exception, e: util.SMlog("removeDevMapperEntry: dmsetup remove failed for file %s " \ "with error %s." % (path, str(e))) return False
class EXTSR(FileSR.FileSR): """EXT3 Local file storage repository""" def handles(srtype): return srtype == 'ext' handles = staticmethod(handles) def load(self, sr_uuid): self.ops_exclusive = FileSR.OPS_EXCLUSIVE self.lock = Lock(vhdutil.LOCK_TYPE_SR, self.uuid) self.sr_vditype = SR.DEFAULT_TAP if not self.dconf.has_key('device') or not self.dconf['device']: raise xs_errors.XenError('ConfigDeviceMissing') self.root = self.dconf['device'] for dev in self.root.split(','): if not self._isvalidpathstring(dev): raise xs_errors.XenError('ConfigDeviceInvalid', \ opterr='path is %s' % dev) self.path = os.path.join(SR.MOUNT_BASE, sr_uuid) self.vgname = EXT_PREFIX + sr_uuid self.remotepath = os.path.join("/dev",self.vgname,sr_uuid) self.attached = self._checkmount() self.driver_config = DRIVER_CONFIG self._check_o_direct() def delete(self, sr_uuid): super(EXTSR, self).delete(sr_uuid) # Check PVs match VG try: for dev in self.root.split(','): cmd = ["pvs", dev] txt = util.pread2(cmd) if txt.find(self.vgname) == -1: raise xs_errors.XenError('VolNotFound', \ opterr='volume is %s' % self.vgname) except util.CommandException, inst: raise xs_errors.XenError('PVSfailed', \ opterr='error is %d' % inst.code) # Remove LV, VG and pv try: cmd = ["lvremove", "-f", self.remotepath] util.pread2(cmd) cmd = ["vgremove", self.vgname] util.pread2(cmd) for dev in self.root.split(','): cmd = ["pvremove", dev] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMDelete', \ opterr='errno is %d' % inst.code)
def __init__(self, sr_uuid, cephx_id="client.%s" % DEFAULT_CEPH_USER): util.SMlog("rbdsr_lock.Lock.__int__: sr_uuid = %s, cephx_id = %s" % (sr_uuid, cephx_id)) self.sr_uuid = sr_uuid self._pool = "%s%s" % (RBDPOOL_PREFIX, sr_uuid) self._cephx_id = cephx_id self._srlock_image = SRLOCK_IMAGE if not self._if_rbd_exist(self._srlock_image): util.pread2(["rbd", "create", self._srlock_image, "--size", "0", "--pool", self._pool, "--name", self._cephx_id])
def _setMultipathableFlag(self, SCSIid=''): try: sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) sm_config['multipathable'] = 'true' self.session.xenapi.SR.set_sm_config(self.sr_ref, sm_config) if self.mpath == "true" and len(SCSIid): cmd = ['/opt/xensource/sm/mpathcount.py',SCSIid] util.pread2(cmd) except: pass
def detach(self, sr_uuid): if not lvutil._checkVG(self.vgname): return # Deactivate any active LVs try: cmd = ["vgchange", "-an", self.SRmaster, self.vgname] util.pread2(cmd) except util.CommandException, inst: raise xs_errors.XenError('LVMUnMount', \ opterr='deactivating VG failed, VDIs in use?')
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)
def detach(self, sr_uuid): if self.mode == "kernel": pass elif self.mode == "fuse": util.pread2(["fusermount", "-u", self.SR_ROOT]) elif self.mode == "nbd": pass if self.mode != "kernel": util.pread2(["rm", "-rf", self.SR_ROOT])
def _setMultipathableFlag(self, SCSIid=''): try: sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) sm_config['multipathable'] = 'true' self.session.xenapi.SR.set_sm_config(self.sr_ref, sm_config) if self.mpath == "true" and len(SCSIid): cmd = [os.path.join(constants.SM_DEST, 'mpathcount.py'),SCSIid] util.pread2(cmd) except: pass
def activate(): util.SMlog("MPATH: multipath activate called") # Adjust any HBAs on the host cmd = [hba_script, "enable"] util.SMlog(util.pread2(cmd)) cmd = ['ln', '-sf', iscsi_mpath_file, iscsi_file] try: util.pread2(cmd) except util.CommandException, ce: if not ce.reason.endswith(': File exists'): raise
def activate_MPdev(sid, dst): if not os.path.exists(MP_INUSEDIR): os.mkdir(MP_INUSEDIR) if (mpp_luncheck.is_RdacLun(sid)): suffix = get_TargetID_LunNUM(sid) sid_with_suffix = sid + "-" + suffix path = os.path.join(MP_INUSEDIR, sid_with_suffix) else: path = os.path.join(MP_INUSEDIR, sid) cmd = ['ln', '-sf', dst, path] util.pread2(cmd)
def _setMultipathableFlag(self, SCSIid=''): try: sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) sm_config['multipathable'] = 'true' self.session.xenapi.SR.set_sm_config(self.sr_ref, sm_config) if self.mpath == "true" and len(SCSIid): cmd = ['/opt/xensource/sm/mpathcount.py', SCSIid] util.pread2(cmd) except: pass
def activateNoRefcount(path, refresh): cmd = [CMD_LVCHANGE, "-ay", path] text = util.pread2(cmd) if not _checkActive(path): raise util.CommandException(-1, str(cmd), "LV not activated") if refresh: cmd = [CMD_LVCHANGE, "--refresh", path] text = util.pread2(cmd) mapperDevice = path[5:].replace("-", "--").replace("/", "-") cmd = [CMD_DMSETUP, "table", mapperDevice] ret = util.pread(cmd) util.SMlog("DM table for %s: %s" % (path, ret.strip()))
def _do_snapshot(self, vdi_uuid, snap_uuid): vdi_name = "%s%s" % (VDI_PREFIX, vdi_uuid) snapshot_name = "%s@%s%s" % (vdi_name, SNAPSHOT_PREFIX, snap_uuid) if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, vdi_uuid): raise util.SMException("failed to pause VDI %s" % vdi_uuid) self._unmap_VHD(vdi_uuid) #--- util.pread2(["rbd", "snap", "create", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER]) util.pread2(["rbd", "snap", "protect", snapshot_name, "--pool", self.sr.CEPH_POOL_NAME, "--name", self.sr.CEPH_USER]) #--- self._map_VHD(vdi_uuid) blktap2.VDI.tap_unpause(self.session, self.sr.uuid, vdi_uuid, None)
def compose(self, sr_uuid, vdi1, vdi2): if self.vdi_type != vhdutil.VDI_TYPE_VHD: raise xs_errors.XenError("Unimplemented") parent_fn = vdi1 + vhdutil.FILE_EXTN[vhdutil.VDI_TYPE_VHD] parent_path = os.path.join(self.sr.path, parent_fn) assert util.pathexists(parent_path) vhdutil.setParent(self.path, parent_path, False) vhdutil.setHidden(parent_path) util.pread2([vhdutil.VHD_UTIL, "modify", "-p", parent_path, "-n", self.path]) # Tell tapdisk the chain has changed if not blktap2.VDI.tap_refresh(self.session, sr_uuid, vdi2): raise util.SMException("failed to refresh VDI %s" % self.uuid) util.SMlog("VDI.compose: relinked %s->%s" % (vdi2, vdi1))
def attach(self, sr_uuid): #self.RBDVDIs = self._get_vdilist(self.CEPH_POOL_NAME) self.load(sr_uuid) if self.mode != "kernel": util.pread2(["mkdir", "-p", self.SR_ROOT]) if self.mode == "kernel": pass elif self.mode == "fuse": util.pread2(["rbd-fuse", "-p", self.CEPH_POOL_NAME, self.SR_ROOT, "--name", self.CEPH_USER]) elif self.mode == "nbd": pass
def _flatten_clone(self, clone_uuid): vdi_ref = self.session.xenapi.VDI.get_by_uuid(vdi_uuid) sm_config = self.session.xenapi.VDI.get_sm_config(vdi_ref) if sm_config.has_key('attached'): if not blktap2.VDI.tap_pause(self.session, self.sr.uuid, clone_uuid): raise util.SMException("failed to pause VDI %s" % clone_uuid) self._unmap_VHD(clone_uuid) #--- ?????? CHECK For running VM. What if flattening takes a long time and vdi is paused during this process clone_name = "%s/%s%s" % (self.sr.CEPH_POOL_NAME, CLONE_PREFIX, clone_uuid) util.pread2(["rbd", "flatten", clone_name, "--name", self.sr.CEPH_USER]) #--- ?????? if sm_config.has_key('attached'): self._map_VHD(clone_uuid) blktap2.VDI.tap_unpause(self.session, self.sr.uuid, clone_uuid, None)