cinder/cinder
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
..
api Remove multiatttach request parameter 2023-03-17 14:14:36 +00:00
backup Restore into sparse volumes 2023-03-17 10:24:44 -04:00
brick LVM: Retry lvextend commands on code 139 2021-08-18 12:29:01 -04:00
cmd Merge "mypy: cmd/manage.py" 2022-11-18 17:00:55 +00:00
common Add additional transport type constants 2022-07-27 11:46:33 -04:00
compute Reject unsafe delete attachment calls 2023-05-10 19:52:39 +02:00
db Improve resource listing efficiency 2023-03-06 14:04:57 +00:00
group db: Remove 'db_driver' option 2021-08-27 15:13:21 +01:00
image Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
interface Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
keymgr Add support for transferring encrypted volumes 2022-08-26 06:32:41 -07:00
locale Imported Translations from Zanata 2022-11-17 03:58:44 +00:00
message Add image_conversion_disable config 2022-06-01 03:56:02 +08:00
objects Objects: Make OPTIONAL_FIELDS a tuple 2023-02-09 12:08:59 -05:00
policies Support volume re-image 2022-02-24 15:23:38 +05:30
privsep LVM nvmet: Add support for shared subsystems 2023-02-03 14:56:19 +01:00
scheduler Remove multiatttach request parameter 2023-03-17 14:14:36 +00:00
tests Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
transfer remove six from cinder.transfer 2023-01-18 10:20:39 -05:00
volume Skip sparse copy during volume reimage 2024-02-13 05:31:06 +00:00
wsgi Introduce flake8-import-order extension 2020-01-06 09:59:35 -06:00
zonemanager Brocade: Fix lookup UnboundLocalError 2020-08-07 15:24:44 +02:00
__init__.py
context.py Add default to read_deleted in context's from_dict 2023-09-09 14:42:32 +00:00
coordination.py Address G004 in flake8-logging-format 0.7.4 2022-08-08 13:09:49 -04:00
exception.py Make paramiko import optional 2023-06-01 14:42:07 +00:00
flow_utils.py Use modern type annotation format for collections 2022-05-18 10:01:18 -04:00
i18n.py
manager.py db: Drop support for MySQL 5.5 2022-04-12 11:03:50 +01:00
opts.py Hitachi: add GAD volume support 2023-02-20 05:56:27 +00:00
policy.py mypy: policy.py 2022-02-02 09:19:17 -05:00
quota.py Merge "Remove six from quota.py" 2021-04-20 07:49:02 +00:00
quota_utils.py Modify/Move project validation methods to api_utils 2021-04-05 08:00:40 -04:00
rpc.py Use new get_rpc_client API from oslo.messaging 2023-01-19 20:28:36 +00:00
service.py mypy: service.py 2022-05-23 11:08:25 -04:00
service_auth.py backup/swift: Add support sending service user token 2022-05-04 07:29:54 +00:00
ssh_utils.py Make paramiko import optional 2023-06-01 14:42:07 +00:00
utils.py Fix and unify capacity calculations 2022-09-09 16:13:12 -04:00
version.py