Adam Litke has uploaded a new change for review. Change subject: storage: Refactor workarounds.detect_format ......................................................................
storage: Refactor workarounds.detect_format The function workarounds.detect_format accepts two volumes, checks for a special case, then returns the qemuimg formats that should be used for each volume. To make this logic more sharable, change detect_format to just detect if the problem exists and let the calling code decide which format to use. This will allow the sdm.copy_data code to use this function with a single volume and still apply the proper logic. Change-Id: Id7b2be176c474f9049d067f0a0c169644ac39899 Signed-off-by: Adam Litke <ali...@redhat.com> --- M tests/storage_workarounds_test.py M vdsm/storage/image.py M vdsm/storage/workarounds.py 3 files changed, 28 insertions(+), 34 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/30/64230/1 diff --git a/tests/storage_workarounds_test.py b/tests/storage_workarounds_test.py index 900b512..f0d01b8 100644 --- a/tests/storage_workarounds_test.py +++ b/tests/storage_workarounds_test.py @@ -32,17 +32,13 @@ class DetectFormatTest(VdsmTestCase): - def make_volumes(self, env, size, src_md_fmt, src_qemu_fmt, dst_md_fmt): - src_img_id = str(uuid.uuid4()) - src_vol_id = str(uuid.uuid4()) - dst_img_id = str(uuid.uuid4()) - dst_vol_id = str(uuid.uuid4()) - env.make_volume(size, src_img_id, src_vol_id, vol_format=src_md_fmt) - env.make_volume(size, dst_img_id, dst_vol_id, vol_format=dst_md_fmt) - src_vol = env.sd_manifest.produceVolume(src_img_id, src_vol_id) - dst_vol = env.sd_manifest.produceVolume(dst_img_id, dst_vol_id) - qemuimg.create(src_vol.getVolumePath(), size, src_qemu_fmt) - return src_vol, dst_vol + def make_volume(self, env, size, src_md_fmt, src_qemu_fmt): + img_id = str(uuid.uuid4()) + vol_id = str(uuid.uuid4()) + env.make_volume(size, img_id, vol_id, vol_format=src_md_fmt) + vol = env.sd_manifest.produceVolume(img_id, vol_id) + qemuimg.create(vol.getVolumePath(), size, src_qemu_fmt) + return vol def test_bad_format_vm_conf_disk(self): """ @@ -52,10 +48,9 @@ """ size = workarounds.VM_CONF_SIZE_BLK * sc.BLOCK_SIZE with fake_file_env() as env: - src, dst = self.make_volumes(env, size, sc.COW_FORMAT, - qemuimg.FORMAT.RAW, sc.RAW_FORMAT) - self.assertEqual((qemuimg.FORMAT.RAW, qemuimg.FORMAT.RAW), - workarounds.detect_format(src, dst)) + vol = self.make_volume(env, size, sc.COW_FORMAT, + qemuimg.FORMAT.RAW) + self.assertTrue(workarounds.mismatched_vm_conf_disk(vol)) def test_bad_format_other_size(self): """ @@ -64,10 +59,9 @@ """ size = 2 * workarounds.VM_CONF_SIZE_BLK * sc.BLOCK_SIZE with fake_file_env() as env: - src, dst = self.make_volumes(env, size, sc.COW_FORMAT, - qemuimg.FORMAT.RAW, sc.RAW_FORMAT) - self.assertEqual((qemuimg.FORMAT.QCOW2, qemuimg.FORMAT.RAW), - workarounds.detect_format(src, dst)) + vol = self.make_volume(env, size, sc.COW_FORMAT, + qemuimg.FORMAT.RAW) + self.assertFalse(workarounds.mismatched_vm_conf_disk(vol)) def test_cow_vm_conf_disk(self): """ @@ -75,7 +69,6 @@ """ size = workarounds.VM_CONF_SIZE_BLK * sc.BLOCK_SIZE with fake_file_env() as env: - src, dst = self.make_volumes(env, size, sc.COW_FORMAT, - qemuimg.FORMAT.QCOW2, sc.COW_FORMAT) - self.assertEqual((qemuimg.FORMAT.QCOW2, qemuimg.FORMAT.QCOW2), - workarounds.detect_format(src, dst)) + vol = self.make_volume(env, size, sc.COW_FORMAT, + qemuimg.FORMAT.QCOW2) + self.assertFalse(workarounds.mismatched_vm_conf_disk(vol)) diff --git a/vdsm/storage/image.py b/vdsm/storage/image.py index 37619d9..7adc199 100644 --- a/vdsm/storage/image.py +++ b/vdsm/storage/image.py @@ -455,8 +455,12 @@ try: dstVol = destDom.produceVolume(imgUUID=imgUUID, volUUID=srcVol.volUUID) - srcFormat, dstFormat = workarounds.detect_format(srcVol, - dstVol) + + if workarounds.mismatched_vm_conf_disk(srcVol): + srcFormat = dstFormat = qemuimg.FORMAT.RAW + else: + srcFormat = sc.fmt2str(srcVol.getFormat()) + dstFormat = sc.fmt2str(dstVol.getFormat()) parentVol = dstVol.getParentVolume() diff --git a/vdsm/storage/workarounds.py b/vdsm/storage/workarounds.py index 7cea63d..b0c5cea 100644 --- a/vdsm/storage/workarounds.py +++ b/vdsm/storage/workarounds.py @@ -29,7 +29,7 @@ VM_CONF_SIZE_BLK = 20 -def detect_format(srcVol, dstVol): +def mismatched_vm_conf_disk(vol): """ set VM metadata images format to RAW @@ -46,18 +46,15 @@ Since VM metadata volumes with this problem may still exist in storage we must keep using this workaround to avoid problems with copying VM disks. """ - src_format = srcVol.getFormat() - size_in_blk = srcVol.getSize() - if src_format == sc.COW_FORMAT and size_in_blk == VM_CONF_SIZE_BLK: - info = qemuimg.info(srcVol.getVolumePath()) + if vol.getFormat() == sc.COW_FORMAT and vol.getSize() == VM_CONF_SIZE_BLK: + info = qemuimg.info(vol.getVolumePath()) actual_format = info['format'] if actual_format == qemuimg.FORMAT.RAW: log.warning("Incorrect volume format %r has been detected" " for volume %r, using the actual format %r.", qemuimg.FORMAT.QCOW2, - srcVol.volUUID, + vol.volUUID, qemuimg.FORMAT.RAW) - return qemuimg.FORMAT.RAW, qemuimg.FORMAT.RAW - - return sc.fmt2str(src_format), sc.fmt2str(dstVol.getFormat()) + return True + return False -- To view, visit https://gerrit.ovirt.org/64230 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Id7b2be176c474f9049d067f0a0c169644ac39899 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Adam Litke <ali...@redhat.com> _______________________________________________ vdsm-patches mailing list -- vdsm-patches@lists.fedorahosted.org To unsubscribe send an email to vdsm-patches-le...@lists.fedorahosted.org