def _io(new_io, queue, address, size, data, offset, direction): io = new_io(queue, address, size, direction, 0, 0) if direction == IoDir.READ: _data = Data.from_bytes(bytes(size)) else: _data = Data.from_bytes(data, offset, size) ret = __io(io, queue, address, size, _data, direction) if not ret and direction == IoDir.READ: memmove(cast(data, c_void_p).value + offset, _data.handle, size) return ret
def io_to_exp_obj(vol, queue, address, size, data, offset, direction, target_ioclass, flags): io = vol.new_io(queue, address, size, direction, target_ioclass, flags) if direction == IoDir.READ: _data = Data.from_bytes(bytes(size)) else: _data = Data.from_bytes(data, offset, size) ret = __io(io, queue, address, size, _data, direction) if not ret and direction == IoDir.READ: memmove(cast(data, c_void_p).value + offset, _data.handle, size) return ret
def io_to_exp_obj(core, address, size, data, offset, direction, flags): vol = core.get_front_volume() queue = core.cache.get_default_queue() io = vol.new_io(queue, address, size, direction, 0, flags) if direction == IoDir.READ: _data = Data.from_bytes(bytes(size)) else: _data = Data.from_bytes(data, offset, size) ret = __io(io, queue, address, size, _data, direction) if not ret and direction == IoDir.READ: memmove(cast(data, c_void_p).value + offset, _data.handle, size) return ret
def ocf_write(vol, queue, val, offset): data = Data.from_bytes(bytes([val] * 512)) comp = OcfCompletion([("error", c_int)]) io = vol.new_io(queue, offset, 512, IoDir.WRITE, 0, 0) io.set_data(data) io.callback = comp.callback io.submit() comp.wait()
def _read(self, offset=0, size=0): if size == 0: size = self.get_length().B - offset exp_obj_io = self.__alloc_io(offset, size, IoDir.READ, 0, 0) completion = OcfCompletion([("err", c_int)]) exp_obj_io.callback = completion data = Data.from_bytes(bytes(size)) exp_obj_io.set_data(data) exp_obj_io.submit() completion.wait() error = completion.results["err"] if error: raise Exception("error reading exported object for dump") return data