def do_stop(self): if not self.is_up(): self.log.info("%s is already down" % self.label) return self.remove_holders() udevadm_settle() self.deactivate_lv()
def scanscsi(self, hba=None, target=None, lun=None, log=None): if not os.path.exists('/sys') or not os.path.ismount('/sys'): print("scanscsi is not supported without /sys mounted", file=sys.stderr) return 1 disks_before = glob.glob('/sys/block/sd*') disks_before += glob.glob('/sys/block/vd*') hba_num = self.hba_num(hba) if hba_num is not None: hosts = glob.glob('/sys/class/scsi_host/host' + str(hba_num)) target_num = self.target_num(hba_num, target) else: hosts = glob.glob('/sys/class/scsi_host/host*') target_num = None if target_num is None: target_num = '-' if lun is None: lun = '-' for host in hosts: scan_f = host + '/scan' if not os.path.exists(scan_f): continue if log: log.info("scan %s target%s lun%s", os.path.basename(host), target_num, lun) os.system('echo - ' + target_num + ' ' + lun + ' >' + scan_f) udevadm_settle() disks_after = glob.glob('/sys/block/sd*') disks_after += glob.glob('/sys/block/vd*') new_disks = set(disks_after) - set(disks_before) if len(new_disks) == 0: if log: log.info("scsi scan found no new disk") return 0 if log: log.info(self.diskinfo_header()) for disk in new_disks: if log: log.info(self.diskinfo_str(disk)) self.wait_devpath("/dev/" + disk.replace("/sys/block/", "")) return 0
def scanscsi(self, hba=None, target=None, lun=None): if not os.path.exists('/sys') or not os.path.ismount('/sys'): print("scanscsi is not supported without /sys mounted", file=sys.stderr) return 1 disks_before = glob.glob('/sys/block/sd*') disks_before += glob.glob('/sys/block/vd*') hba_num = self.hba_num(hba) if hba_num is not None: hosts = glob.glob('/sys/class/scsi_host/host' + str(hba_num)) target_num = self.target_num(hba_num, target) else: hosts = glob.glob('/sys/class/scsi_host/host*') target_num = None if target_num is None: target_num = '-' if lun is None: lun = '-' for host in hosts: scan_f = host + '/scan' if not os.path.exists(scan_f): continue print("scan", os.path.basename(host), "target" + target_num, "lun" + lun) os.system('echo - ' + target_num + ' ' + lun + ' >' + scan_f) udevadm_settle() disks_after = glob.glob('/sys/block/sd*') disks_after += glob.glob('/sys/block/vd*') new_disks = set(disks_after) - set(disks_before) if len(new_disks) == 0: print("no new disk found") return 0 self.print_diskinfo_header() #for disk in disks_before: for disk in new_disks: self.print_diskinfo(disk) return 0
def snapdestroykey(self, s): if protected_mount(self.snaps[s]['snap_mnt']): self.log.error("the snapshot is no longer mounted in %s. panic."%self.snaps[s]['snap_mnt']) raise ex.excError cmd = ['fuser', '-kmv', self.snaps[s]['snap_mnt']] (ret, out, err) = self.vcall(cmd, err_to_info=True) cmd = [rcEnv.syspaths.umount, self.snaps[s]['snap_mnt']] (ret, out, err) = self.vcall(cmd) udevadm_settle() cmd = ['lvremove', '-A', 'n', '-f', self.snaps[s]['snap_dev']] self.log.info(' '.join(cmd)) for i in range(1, 30): out, err, ret = justcall(cmd) if ret == 0: break err_l1 = err.split('\n') err_l2 = [] out_l = out.split('\n') for e in err_l1: if 'This metadata update is NOT backed up' in e: pass elif 'Falling back to direct link removal.' in e: out_l.append(e) elif 'Falling back to direct node removal.' in e: out_l.append(e) else: err_l2.append(e) err = '\n'.join(err_l2) out = '\n'.join(out_l) if len(out) > 0: self.log.info(out) if len(err) > 0: self.log.error(err) if ret != 0: self.log.error("failed to remove snapshot %s (attempts: %d)"%(self.snaps[s]['snap_dev'], i)) elif i > 1: self.log.info("successfully removed snapshot %s (attempts: %d)"%(self.snaps[s]['snap_dev'], i)) del(self.snaps[s])