def _getAllEntries(self, readFile = True): lvList = self.lvmCache.getTagged(self.LV_TAG) entries = dict() for lvName in lvList: parts = lvName.split(self.SEPARATOR, 2) if len(parts) != 3: raise JournalerException("Bad LV name: %s" % lvName) type, id, val = parts if readFile: # For clone and leaf journals, additional # data is written inside file # TODO: Remove dependency on journal type if type == self.JRN_CLONE or type == self.JRN_LEAF: fullPath = self.lvmCache._getPath(lvName) self.lvmCache.activateNoRefcount(lvName,False) fd = open_file(fullPath) try: try: min_block_size = get_min_blk_size_wrapper(fd) data = file_read_wrapper(fd, 0, min_block_size, min_block_size) length, val = data.split(" ", 1) val = val[:int(length)] except: raise JournalerException("Failed to read from journal %s" \ % lvName) finally: close(fd) self.lvmCache.deactivateNoRefcount(lvName) if not entries.get(type): entries[type] = dict() entries[type][id] = val return entries
def _getAllEntries(self): lvList = self.lvmCache.getTagged(self.LV_TAG) entries = dict() for lvName in lvList: parts = lvName.split(self.SEPARATOR, 2) if len(parts) != 3: raise JournalerException("Bad LV name: %s" % lvName) type, id, val = parts # For clone and leaf journals, additional # data is written inside file # TODO: Remove dependency on journal type if type == self.JRN_CLONE or type == self.JRN_LEAF: fullPath = self.lvmCache._getPath(lvName) self.lvmCache.activateNoRefcount(lvName,False) fd = open_file(fullPath) try: try: min_block_size = get_min_blk_size_wrapper(fd) data = xs_file_read_wrapper(fd, 0, min_block_size, min_block_size) length, val = data.split(" ", 1) val = val[:int(length)] except: raise JournalerException("Failed to read from journal %s" \ % lvName) finally: close(fd) self.lvmCache.deactivateNoRefcount(lvName) if not entries.get(type): entries[type] = dict() entries[type][id] = val return entries
def create(self, type, id, val): """Create an entry of type "type" for "id" with the value "val". Error if such an entry already exists.""" valExisting = self.get(type, id) writeData = False if valExisting: raise JournalerException("Journal already exists for '%s:%s': %s" \ % (type, id, valExisting)) lvName = self._getNameLV(type, id, val) mapperDevice = self._getLVMapperName(lvName) if len(mapperDevice) > LVM_MAX_NAME_LEN: lvName = self._getNameLV(type, id) writeData = True mapperDevice = self._getLVMapperName(lvName) assert len(mapperDevice) <= LVM_MAX_NAME_LEN self.lvmCache.create(lvName, self.LV_SIZE, self.LV_TAG) if writeData: fullPath = self.lvmCache._getPath(lvName) fd = open_file(fullPath, True) try: e = None try: min_block_size = get_min_blk_size_wrapper(fd) data = "%d %s" % (len(val), val) file_write_wrapper(fd, 0, min_block_size, data, len(data)) except Exception as e: raise finally: try: close(fd) self.lvmCache.deactivateNoRefcount(lvName) except Exception as e2: msg = 'failed to close/deactivate %s: %s' \ % (lvName, e2) if not e: util.SMlog(msg) raise e2 else: util.SMlog('WARNING: %s (error ignored)' % msg) except: util.logException("journaler.create") try: self.lvmCache.remove(lvName) except Exception as e: util.SMlog('WARNING: failed to clean up failed journal ' \ ' creation: %s (error ignored)' % e) raise JournalerException("Failed to write to journal %s" \ % lvName)
def create(self, type, id, val): """Create an entry of type "type" for "id" with the value "val". Error if such an entry already exists.""" valExisting = self.get(type, id) writeData = False if valExisting: raise JournalerException("Journal already exists for '%s:%s': %s" \ % (type, id, valExisting)) lvName = self._getNameLV(type, id, val) mapperDevice = self._getLVMapperName(lvName) if len(mapperDevice) > LVM_MAX_NAME_LEN: lvName = self._getNameLV(type, id) writeData = True mapperDevice = self._getLVMapperName(lvName) assert len(mapperDevice) <= LVM_MAX_NAME_LEN self.lvmCache.create(lvName, self.LV_SIZE, self.LV_TAG) if writeData: fullPath = self.lvmCache._getPath(lvName) fd = open_file(fullPath, True) try: e = None try: min_block_size = get_min_blk_size_wrapper(fd) data = "%d %s" % (len(val), val) xs_file_write_wrapper(fd, 0, min_block_size, data, len(data)) except Exception, e: raise finally: try: close(fd) self.lvmCache.deactivateNoRefcount(lvName) except Exception, e2: msg = 'failed to close/deactivate %s: %s' \ % (lvName, e2) if not e: util.SMlog(msg) raise e2 else: util.SMlog('WARNING: %s (error ignored)' % msg)