cinder/cinder/tests/unit/volume
whoami-rajat 8d7e292bcd Skip sparse copy during volume reimage
When rebuilding a volume backed instance, while copying the new
image to the existing volume, we preserve sparseness.
This could be problematic since we don't write the zero blocks of
the new image and the data in the old image can still persist
leading to a data leak scenario.

To prevent this, we are using `-S 0`[1][2] option with the `qemu-img convert`
command to write all the zero bytes into the volume.

In the testing done, this doesn't seem to be a problem with known 'raw'
images but good to handle the case anyway.

Following is the testing performed with 3 images:

1. CIRROS QCOW2 to RAW
======================

Volume size: 1 GiB
Image size (raw): 112 MiB

CREATE VOLUME FROM IMAGE (without -S 0)

LVS (10.94% allocated)
  volume-91ea43ef-684c-402f-896e-63e45e5f4fff stack-volumes-lvmdriver-1 Vwi-a-tz-- 1.00g stack-volumes-lvmdriver-1-pool 10.94

REBUILD (with -S 0)

LVS (10.94% allocated)
  volume-91ea43ef-684c-402f-896e-63e45e5f4fff stack-volumes-lvmdriver-1 Vwi-aotz-- 1.00g stack-volumes-lvmdriver-1-pool 10.94

Conclusion:
Same space is consumed on the disk with and without preserving sparseness.

2. DEBIAN QCOW2 to RAW
======================

Volume size: 3 GiB
Image size (raw): 2 GiB

CREATE VOLUME FROM IMAGE (without -S 0)

LVS (66.67% allocated)
  volume-edc42b6a-df5d-420e-85d3-b3e52bcb735e stack-volumes-lvmdriver-1 Vwi-a-tz-- 3.00g stack-volumes-lvmdriver-1-pool 66.67

REBUILD (with -S 0)

LVS (66.67% allocated)
  volume-edc42b6a-df5d-420e-85d3-b3e52bcb735e stack-volumes-lvmdriver-1 Vwi-aotz-- 3.00g stack-volumes-lvmdriver-1-pool 66.67

Conclusion:
Same space is consumed on the disk with and without preserving sparseness.

3. FEDORA QCOW2 TO RAW
======================

CREATE VOLUME FROM IMAGE (without -S 0)

Volume size: 6 GiB
Image size (raw): 5 GiB

LVS (83.33% allocated)
  volume-efa1a227-a30d-4385-867a-db22a3e80ad7 stack-volumes-lvmdriver-1 Vwi-a-tz-- 6.00g stack-volumes-lvmdriver-1-pool 83.33

REBUILD (with -S 0)

LVS (83.33% allocated)
  volume-efa1a227-a30d-4385-867a-db22a3e80ad7 stack-volumes-lvmdriver-1 Vwi-aotz-- 6.00g stack-volumes-lvmdriver-1-pool 83.33

Conclusion:
Same space is consumed on the disk with and without preserving sparseness.

Another testing was done to check if the `-S 0` option actually
works in OpenStack setup.
Note that we are converting qcow2 to qcow2 image which won't
happen in a real world deployment and only for test purposes.

DEBIAN QCOW2 TO QCOW2
=====================

CREATE VOLUME FROM IMAGE (without -S 0)

LVS (52.61% allocated)
  volume-de581f84-e722-4f4a-94fb-10f767069f50 stack-volumes-lvmdriver-1 Vwi-a-tz-- 3.00g stack-volumes-lvmdriver-1-pool 52.61

REBUILD (with -S 0)

LVS (66.68% allocated)
  volume-de581f84-e722-4f4a-94fb-10f767069f50 stack-volumes-lvmdriver-1 Vwi-aotz-- 3.00g stack-volumes-lvmdriver-1-pool 66.68

Conclusion:
We can see that the space allocation increased hence we are not preserving sparseness when using the -S 0 option.

[1] https://qemu-project.gitlab.io/qemu/tools/qemu-img.html#cmdoption-qemu-img-common-opts-S
[2] abf635ddfe/qemu-img.c (L182-L186)

Closes-Bug: #2045431

Change-Id: I5be7eaba68a5b8e1c43f0d95486b5c79c14e1b95
(cherry picked from commit 1a8ea0eac4)
(cherry picked from commit 85857a19ab)
2024-02-13 05:31:06 +00:00
..
drivers Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
flows Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
__init__.py Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
test_availability_zone.py Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
test_capabilities.py Fix extra_capabilities 2021-07-29 20:06:18 +00:00
test_connection.py Reject unsafe delete attachment calls 2023-05-10 19:52:39 +02:00
test_driver.py Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
test_image.py Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
test_init_host.py Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
test_manage_volume.py Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
test_replication_manager.py Move require_driver_initialized / log_unsupp to volume_utils 2021-06-11 11:13:34 -04:00
test_rpcapi.py Support volume re-image 2022-02-24 15:23:38 +05:30
test_snapshot.py Snapshot in-use volumes without force flag 2021-08-31 14:48:32 -04:00
test_volume.py Remove multiatttach request parameter 2023-03-17 14:14:36 +00:00
test_volume_manager.py Send the correct location URI to the Glance v2 API 2023-01-16 16:34:21 +02:00
test_volume_migration.py Revert "Driver assisted migration on retype when it's safe" 2024-01-18 15:56:20 +00:00
test_volume_reimage.py Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
test_volume_retype.py Fix volume retype with AZ 2020-09-04 12:21:58 +00:00
test_volume_usage_audit.py Improve resource listing efficiency 2023-03-06 14:04:57 +00:00