def __init__(self, **config): self.config = Config.copy() self.config.update(config) self.drive = self.build_service() self.data_dir = self.get_data_dir() self.uuid = hashlib.sha1(self.data_dir).hexdigest() self.load_data_dir() self.block_size = self.bd_attr['block_size'] self.block_count = self.bd_attr['block_count'] self.total_size = self.block_size * self.block_count self.mapping = [None] * self.block_count self.que = TimedPriorityQueue() self.lock = Lock() self.running = True self.workers = [] for i in xrange(self.config.get('workers', 8)): worker = GBDWorker(self, self.build_service()) worker.daemon = True worker.start() self.workers.append(worker)
def __init__(self, cache_file, dirty=False, *args, **kargs): if 'workers' not in kargs: kargs['workers'] = 16 self.done = False self.gbd = GBD(*args, **kargs) self.uuid = self.gbd.uuid self.block_size = self.gbd.block_size self.block_count = self.gbd.block_count self.total_size = self.gbd.total_size self.cache = open(cache_file, 'r+b') self.cache_lock = Lock() self.entry_count = self.calc_entry_count() self.clean_que = RLUQueue(self.entry_count) self.dirty_que = RLUQueue(self.entry_count) self.last_modify = [0] * self.entry_count self.map = {} self.rmap = [self.EMPTY] * self.entry_count self.map_lock = Lock() self.load_cache(dirty) self.wb_sem = Semaphore(8) self.wb_daemon = Thread(target=self.do_writeback) self.wb_daemon.daemon = True self.wb_daemon.start() self.pull_que = TimedPriorityQueue() self.dque_lock = Lock() self.pull_delay_que = {} self.pull_daemon = Thread(target=self.do_pull) self.pull_daemon.daemon = True self.pull_daemon.start() self.done = True