def bytes_to_bitmap(buf, maxitems, bitmap=None): """Convert string of bytes back into bitmap This is the inverse of bytes_to_bitmap(), and is used to recover the bitmap from its representation as string of bytes. Parameters ---------- buf : bytes (str in Python 2) [Compact] representation of bitmap as bytes. Result of bitmap_to_bytes(). maxitems : int Number of entries; number of bits in bitmap. bitmap : BitMap, optional Bitmap object to set. If provided, the bitmap must be empty (all zeros), and have at least `maxitems` bits. This can be used to avoid commit creation costs. Returns ------- BitMap Bitmap / bitset with given representation. """ if not bitmap: bitmap = BitMap(maxitems) bitmap.bitmap = array.array('B', buf) return bitmap
def test_reorganize_hash_file(): nbd.init(128) logicService._g = logicService._logic_service() # for i in BitMapIter(iter(bytearray([1, 0, 0, 2, 3, 4, 5]))): # print(i) with open('/tmp/test.bitmap', 'rb') as f: _bit_map = f.read() bit_map = BitMap() bit_map.bitmap = bytearray(_bit_map) snapshots = [{ "path": "/home/mnt/nodes/ffccc08f7d5e40119e0440fd5845259c/images/c152ad459f4c4b39897bf0127c760f66/d3632a55450d4692a5d3021727975edf.qcow", "ident": 'a3a1debbbe6f4c969fb0fe630d111199' }] disk_bytes = 105066964992 hash_name = '/tmp/hash.new' # import os # os.system('echo 3 > /proc/sys/vm/drop_caches;echo 3 > /proc/sys/vm/drop_caches') ReorganizeHashFile(bit_map, snapshots, hash_name, hash_name + '.tmp', disk_bytes).work() MergeHash(disk_bytes).merge(hash_name + '.reg', [hash_name])