def initRaidFromConf(self,fd): ''' Initializes a RAID device from a json config file. @param fd An already opened file descriptor for the config file. ''' decoded = json.load(fd) if "devices" in decoded and "raidlevel" in decoded and "type" in decoded: self.__type = decoded["type"] if self.__type == "sw_mdadm": self.__raidTec = Mdadm(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) if self.__type == "hw_lsi": # If no readpolicy is specified, use nora (no read ahead) as default readpolicy = "nora" # If no writepolicy is specified, use wt (write through) as default writepolicy = "wt" # If no stripsize is specified, use 256 (KB) as default stripsize = "strip=256" if "readpolicy" in decoded: readpolicy = decoded["readpolicy"] if "writepolicy" in decoded: writepolicy = decoded["writepolicy"] if "stripsize" in decoded: stripsize = decoded["stripsize"] self.__raidTec = Storcli(self.getDevPath(), decoded["raidlevel"], decoded["devices"], readpolicy, writepolicy, stripsize) self.__raidTec.initialize()
def initRaidFromConf(self, fd): ''' Initializes a RAID device from a json config file. @param fd An already opened file descriptor for the config file. ''' decoded = json.load(fd) if "devices" in decoded and "raidlevel" in decoded and "type" in decoded: self.__type = decoded["type"] if self.__type == "sw_mdadm": self.__raidTec = Mdadm(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) if self.__type == "hw_lsi": # If no readpolicy is specified, use nora (no read ahead) as default readpolicy = "nora" # If no writepolicy is specified, use wt (write through) as default writepolicy = "wt" # If no stripsize is specified, use 256 (KB) as default stripsize = "strip=256" if "readpolicy" in decoded: readpolicy = decoded["readpolicy"] if "writepolicy" in decoded: writepolicy = decoded["writepolicy"] if "stripsize" in decoded: stripsize = decoded["stripsize"] self.__raidTec = Storcli(self.getDevPath(), decoded["raidlevel"], decoded["devices"], readpolicy, writepolicy, stripsize) self.__raidTec.initialize()
def initRaidFromConf(self,fd): ''' Initializes a RAID device from a json config file. @param fd An already opened file descriptor for the config file. ''' decoded = json.load(fd) if "devices" in decoded and "raidlevel" in decoded and "type" in decoded: self.__type = decoded["type"] if self.__type == "sw_mdadm": self.__raidTec = Mdadm(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) if self.__type == "hw_lsi": self.__raidTec = Storcli(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) self.__raidTec.initialize()
class RAID(Device): ''' Representing a RAID device. ''' raidLevels = [0, 1, 5, 6, 10] def __init__(self, devtype, path, devname, config=None, vendor=None): ''' Constructor @param config The config file describing the RAID set ''' super(RAID, self).__init__(devtype, path, devname, vendor) ## Type of raid, read from config, e.g. sw_mdadm, hw_lsi self.__type = None ## The config file describing the RAID device self.__config = config ## The used RAID technology, linux sw RAID, lsi hw RAID self.__raidTec = None def getType(self): return self.__type def getConfig(self): return self.__config def setConfig(self,cfg): self.__config = cfg def initialize(self): ''' Run size and devinfo methods for the current device. If a raid doesn't exist, create it. ''' try: # Init from config if not done yet if self.__raidTec == None: self.initRaidFromConf(self.__config) # Create raid if it doesn't exist if not self.__raidTec.checkRaidPath(): self.__raidTec.createVD() self.setDevSizeB(self.calcDevSizeB()) self.setDevSizeKB(self.calcDevSizeKB()) self.setDevIsMounted(self.checkDevIsMounted()) self.setDevIsAvailable(self.checkDevIsAvbl()) self.readDevInfo() except RuntimeError: logging.error("# Could not fetch initial information for " + self.getDevPath()) raise def initRaidFromConf(self,fd): ''' Initializes a RAID device from a json config file. @param fd An already opened file descriptor for the config file. ''' decoded = json.load(fd) if "devices" in decoded and "raidlevel" in decoded and "type" in decoded: self.__type = decoded["type"] if self.__type == "sw_mdadm": self.__raidTec = Mdadm(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) if self.__type == "hw_lsi": # If no readpolicy is specified, use nora (no read ahead) as default readpolicy = "nora" # If no writepolicy is specified, use wt (write through) as default writepolicy = "wt" # If no stripsize is specified, use 256 (KB) as default stripsize = "strip=256" if "readpolicy" in decoded: readpolicy = decoded["readpolicy"] if "writepolicy" in decoded: writepolicy = decoded["writepolicy"] if "stripsize" in decoded: stripsize = decoded["stripsize"] self.__raidTec = Storcli(self.getDevPath(), decoded["raidlevel"], decoded["devices"], readpolicy, writepolicy, stripsize) self.__raidTec.initialize() def readDevInfo(self): devInfo = "" devInfo += "RAID type: " + self.__type + "\n" devInfo += "RAID devices: " devInfo += ', '.join(self.__raidTec.getDevices()) + "\n" devInfo += "RAID level: " devInfo += str(self.__raidTec.getLevel()) + "\n" if self.__type == "hw_lsi": devInfo += "Controller read policy: " devInfo += str(self.__raidTec.getREADPOLICY()) + "\n" devInfo += "Controller write policy: " devInfo += str(self.__raidTec.getWRITEPOLICY()) + "\n" devInfo += "Controller strip size: " devInfo += str(self.__raidTec.getSTRIPSIZE()) + "\n" self.setDevInfo(devInfo) def createRaid(self): # Check if there is already a device, if yes delete it if self.__raidTec.checkRaidPath() == True: logging.info("# Found raid device "+self.getDevPath()+", deleting it!") self.__raidTec.deleteVD() # Create the raid device self.__raidTec.createVD() while not self.__raidTec.isReady(): sleep(30) def secureErase(self): ''' Carries out the secure erase for a RAID device. ''' if self.getType() == 'sw_mdadm': import multiprocessing m = multiprocessing.Manager() exc = m.Queue() ps = [] for d in self.__raidTec.getDevices(): p = multiprocessing.Process(target=self.operator,args=(d,'erase',None, None, exc)) ps.append(p) p.start() for p in ps: p.join() if exc.empty(): pass else: logging.error("# Error: Could not secure erase " + self.getDevPath()) raise RuntimeError, "secure erase error" if self.getType() == 'hw_lsi': logging.info("# Secure Erase not implemented on LSI controllers, skipping...") return # After secure erase create the raid device logging.info("# Creating raid device "+self.getDevPath()+" after secure erase!") self.createRaid() def precondition(self,nj=1,iod=1): ''' Carries out the preconditioning for a RAID device. ''' if self.getType() == 'sw_mdadm': import multiprocessing m = multiprocessing.Manager() exc = m.Queue() ps = [] for d in self.__raidTec.getDevices(): p = multiprocessing.Process(target=self.operator,args=(d,'condition',nj, iod, exc)) ps.append(p) p.start() for p in ps: p.join() if exc.empty(): pass else: logging.error("# Error: Could not precondition " + self.getDevPath()) raise RuntimeError, "precondition error" if self.getType() == 'hw_lsi': tmpSSD = SSD('ssd', self.getDevPath(), self.getDevName()) tmpSSD.precondition(nj, iod) # After preconditioning create the raid device logging.info("# Creating raid device "+self.getDevPath()+" after workload independet preconditioning!") self.createRaid() def operator(self, path, op, nj, iod, exc): try: tmpSSD = SSD('ssd', path, self.getDevName()) if op == 'erase': tmpSSD.secureErase() if op == 'condition': tmpSSD.precondition(nj, iod) except RuntimeError: exc.put('Error')
class RAID(Device): ''' Representing a RAID device. ''' raidLevels = [0, 1, 5, 6, 10] def __init__(self, devtype, path, devname, config=None, vendor=None): ''' Constructor @param config The config file describing the RAID set ''' super(RAID, self).__init__(devtype, path, devname, vendor) ## Type of raid, read from config, e.g. sw_mdadm, hw_lsi self.__type = None ## The config file describing the RAID device self.__config = config ## The used RAID technology, linux sw RAID, lsi hw RAID self.__raidTec = None def getType(self): return self.__type def getConfig(self): return self.__config def setConfig(self, cfg): self.__config = cfg def initialize(self): ''' Run size and devinfo methods for the current device. If a raid doesn't exist, create it. ''' try: # Init from config if not done yet if self.__raidTec == None: self.initRaidFromConf(self.__config) # Create raid if it doesn't exist if not self.__raidTec.checkRaidPath(): self.__raidTec.createVD() self.setDevSizeB(self.calcDevSizeB()) self.setDevSizeKB(self.calcDevSizeKB()) self.setDevIsMounted(self.checkDevIsMounted()) self.setDevIsAvailable(self.checkDevIsAvbl()) self.readDevInfo() except RuntimeError: logging.error("# Could not fetch initial information for " + self.getDevPath()) raise def initRaidFromConf(self, fd): ''' Initializes a RAID device from a json config file. @param fd An already opened file descriptor for the config file. ''' decoded = json.load(fd) if "devices" in decoded and "raidlevel" in decoded and "type" in decoded: self.__type = decoded["type"] if self.__type == "sw_mdadm": self.__raidTec = Mdadm(self.getDevPath(), decoded["raidlevel"], decoded["devices"]) if self.__type == "hw_lsi": # If no readpolicy is specified, use nora (no read ahead) as default readpolicy = "nora" # If no writepolicy is specified, use wt (write through) as default writepolicy = "wt" # If no stripsize is specified, use 256 (KB) as default stripsize = "strip=256" if "readpolicy" in decoded: readpolicy = decoded["readpolicy"] if "writepolicy" in decoded: writepolicy = decoded["writepolicy"] if "stripsize" in decoded: stripsize = decoded["stripsize"] self.__raidTec = Storcli(self.getDevPath(), decoded["raidlevel"], decoded["devices"], readpolicy, writepolicy, stripsize) self.__raidTec.initialize() def readDevInfo(self): devInfo = "" devInfo += "RAID type: " + self.__type + "\n" devInfo += "RAID devices: " devInfo += ', '.join(self.__raidTec.getDevices()) + "\n" devInfo += "RAID level: " devInfo += str(self.__raidTec.getLevel()) + "\n" if self.__type == "hw_lsi": devInfo += "Controller read policy: " devInfo += str(self.__raidTec.getREADPOLICY()) + "\n" devInfo += "Controller write policy: " devInfo += str(self.__raidTec.getWRITEPOLICY()) + "\n" devInfo += "Controller strip size: " devInfo += str(self.__raidTec.getSTRIPSIZE()) + "\n" self.setDevInfo(devInfo) def createRaid(self): # Check if there is already a device, if yes delete it if self.__raidTec.checkRaidPath() == True: logging.info("# Found raid device " + self.getDevPath() + ", deleting it!") self.__raidTec.deleteVD() # Create the raid device self.__raidTec.createVD() while not self.__raidTec.isReady(): sleep(30) def secureErase(self): ''' Carries out the secure erase for a RAID device. ''' if self.getType() == 'sw_mdadm': import multiprocessing m = multiprocessing.Manager() exc = m.Queue() ps = [] for d in self.__raidTec.getDevices(): p = multiprocessing.Process(target=self.operator, args=(d, 'erase', None, None, exc)) ps.append(p) p.start() for p in ps: p.join() if exc.empty(): pass else: logging.error("# Error: Could not secure erase " + self.getDevPath()) raise RuntimeError, "secure erase error" if self.getType() == 'hw_lsi': logging.info( "# Secure Erase not implemented on LSI controllers, skipping..." ) return # After secure erase create the raid device logging.info("# Creating raid device " + self.getDevPath() + " after secure erase!") self.createRaid() def precondition(self, nj=1, iod=1): ''' Carries out the preconditioning for a RAID device. ''' if self.getType() == 'sw_mdadm': import multiprocessing m = multiprocessing.Manager() exc = m.Queue() ps = [] for d in self.__raidTec.getDevices(): p = multiprocessing.Process(target=self.operator, args=(d, 'condition', nj, iod, exc)) ps.append(p) p.start() for p in ps: p.join() if exc.empty(): pass else: logging.error("# Error: Could not precondition " + self.getDevPath()) raise RuntimeError, "precondition error" if self.getType() == 'hw_lsi': tmpSSD = SSD('ssd', self.getDevPath(), self.getDevName()) tmpSSD.precondition(nj, iod) # After preconditioning create the raid device logging.info("# Creating raid device " + self.getDevPath() + " after workload independet preconditioning!") self.createRaid() def operator(self, path, op, nj, iod, exc): try: tmpSSD = SSD('ssd', path, self.getDevName()) tmpSSD.setInterface(self.getIntfce()) if op == 'erase': tmpSSD.secureErase() if op == 'condition': tmpSSD.precondition(nj, iod) except RuntimeError: exc.put('Error')