def _run(self): self.log.info("Merging subchain %s", self.subchain) with guarded.context(self.subchain.locks): self.subchain.validate() with self.subchain.prepare(), self.subchain.volume_operation(): top_vol_path = self.subchain.top_vol.getVolumePath() base_vol_path = self.subchain.base_vol.getVolumePath() self.log.info("Committing data from %s to %s", top_vol_path, base_vol_path) self.operation = qemuimg.commit( top_vol_path, topFormat=sc.fmt2str(self.subchain.top_vol.getFormat()), base=base_vol_path) self.operation.run() if (self.subchain.base_vol.getFormat() == sc.COW_FORMAT and self.merge_bitmaps): self.log.info("Merging bitmaps from %s to %s", top_vol_path, base_vol_path) # Add and merge all the bitmaps from top_vol that don't # exist on the base_vol and not handled by block-commit. base_parent_vol = self.subchain.base_vol.getParentVolume() base_parent_path = (base_parent_vol.getVolumePath() if base_parent_vol else None) bitmaps.merge_bitmaps(base_vol_path, top_vol_path, base_parent_path=base_parent_path)
def _run(self): self.log.info("Merging subchain %s", self.subchain) with guarded.context(self.subchain.locks): self.subchain.validate() with self.subchain.prepare(), self.subchain.volume_operation(): self.operation = qemuimg.commit( self.subchain.top_vol.getVolumePath(), topFormat=sc.fmt2str(self.subchain.top_vol.getFormat()), base=self.subchain.base_vol.getVolumePath()) self.operation.run()
def test_commit_progress(self): with namedTemporaryDir() as tmpdir: size = 1048576 base = os.path.join(tmpdir, "base.img") make_image(base, size, qemuimg.FORMAT.RAW, 0, "1.1") top = os.path.join(tmpdir, "top.img") make_image(top, size, qemuimg.FORMAT.QCOW2, 1, "1.1", base) op = qemuimg.commit(top, topFormat=qemuimg.FORMAT.QCOW2) op.run() self.assertEqual(100, op.progress)
def test_commit_progress(self): with namedTemporaryDir() as tmpdir: size = 1048576 base = os.path.join(tmpdir, "base.img") make_image(base, size, qemuimg.FORMAT.RAW, 0, "1.1") top = os.path.join(tmpdir, "top.img") make_image(top, size, qemuimg.FORMAT.QCOW2, 1, "1.1", base) op = qemuimg.commit(top, topFormat=qemuimg.FORMAT.QCOW2) op.run() assert 100 == op.progress
def test_commit(self, qcow2_compat, base, top, use_base): size = 1048576 with namedTemporaryDir() as tmpdir: chain = [] parent = None # Create a chain of 4 volumes. for i in range(4): vol = os.path.join(tmpdir, "vol%d.img" % i) format = (qemuimg.FORMAT.RAW if i == 0 else qemuimg.FORMAT.QCOW2) make_image(vol, size, format, i, qcow2_compat, parent) orig_offset = qemuimg.check(vol)["offset"] if i > 0 else None chain.append((vol, orig_offset)) parent = vol base_vol = chain[base][0] top_vol = chain[top][0] op = qemuimg.commit(top_vol, topFormat=qemuimg.FORMAT.QCOW2, base=base_vol if use_base else None) op.run() base_fmt = (qemuimg.FORMAT.RAW if base == 0 else qemuimg.FORMAT.QCOW2) for i in range(base, top + 1): offset = i * 1024 pattern = 0xf0 + i # The base volume must have the data from all the volumes # merged into it. qemuio.verify_pattern( base_vol, base_fmt, offset=offset, len=1024, pattern=pattern) if i > base: # internal and top volumes should keep the data, we # may want to wipe this data when deleting the volumes # later. vol, orig_offset = chain[i] actual_offset = qemuimg.check(vol)["offset"] assert actual_offset == orig_offset