Bug 1702868 - 'qemu-img measure' supports luks format please
Summary: 'qemu-img measure' supports luks format please
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: qemu-kvm
Version: 8.0
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: 8.0
Assignee: Stefan Hajnoczi
QA Contact: Xueqiang Wei
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-04-25 02:59 UTC by Tingting Mao
Modified: 2020-11-17 17:45 UTC (History)
8 users (show)

Fixed In Version: qemu-kvm-5.0.0-2.module+el8.3.0+7379+0505d6ca
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-11-17 17:44:46 UTC
Type: Feature Request
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Tingting Mao 2019-04-25 02:59:12 UTC
Description of problem:
'qemu-img measure' now supports raw, qcow2 and luks-inside-qcow2, but not luks. After a discussion with Stefan, we could support luks in rhel 8.x. Thanks.


Version-Release number of selected component (if applicable):
qemu-kvm-3.1.0-22.module+el8.0.1+3032+a09688b9
kernel-4.18.0-80.el8


How reproducible:
100%


Steps to Reproduce:

Scenario 1(Measure for a new created luks image)
# qemu-img measure -O luks --size 4G
qemu-img: Block driver 'luks' does not support size measurement


Scenario 2(Measure for a new converted luks image)
# qemu-img info base.qcow2 
image: base.qcow2
file format: qcow2
virtual size: 5.0G (5368709120 bytes)
disk size: 1.0G
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

# qemu-img measure -f qcow2 -O luks base.qcow2 
qemu-img: Block driver 'luks' does not support size measurement


Actual results:
As above.


Expected results:
Given the required sizes for luks images.


Additional info:

Comment 1 Stefan Hajnoczi 2020-01-08 11:41:57 UTC
Patches posted upstream:
https://lists.gnu.org/archive/html/qemu-devel/2020-01/msg01337.html

Comment 2 Ademar Reis 2020-02-05 22:56:34 UTC
QEMU has been recently split into sub-components and as a one-time operation to avoid breakage of tools, we are setting the QEMU sub-component of this BZ to "General". Please review and change the sub-component if necessary the next time you review this BZ. Thanks

Comment 3 Xueqiang Wei 2020-05-27 09:38:00 UTC
Hi Stefan,

I tested this bug on qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420. It works well, it should has been fixed already. 

Please help check it. If I was wrong, please correct me. Many thanks.


Versions:
kernel-4.18.0-202.el8.x86_64
qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420


Scenario 1(Measure for a new created luks image)

# qemu-img measure --object secret,id=sec0,data=base -O luks -o key-secret=sec0 --size 4G
required size: 4297035776
fully allocated size: 4297035776

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0 -f luks test1.luks 4G
Formatting 'test1.luks', fmt=luks size=4294967296 key-secret=sec0

# ls -als test1.luks
256 -rw-r--r--. 1 root root 4297035776 May 27 04:22 test1.luks

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0,preallocation=full -f luks test1.luks 4G
Formatting 'test1.luks', fmt=luks size=4294967296 key-secret=sec0 preallocation=full

# ls -als test1.luks
4196324 -rw-r--r--. 1 root root 4297035776 May 27 04:25 test1.luks



Scenario 2(Measure for a new converted luks image)

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0 -f luks original.img 4G
Formatting 'original.img', fmt=luks size=4294967296 key-secret=sec0

# qemu-io -c 'write 0 1G' --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
wrote 1073741824/1073741824 bytes at offset 0
1 GiB, 1 ops; 0:00:09.27 (110.510 MiB/sec and 0.1079 ops/sec)

# qemu-img info original.img
image: original.img
file format: luks
virtual size: 4 GiB (4294967296 bytes)
disk size: 1 GiB
encrypted: yes
Format specific information:
    ivgen alg: plain64
    hash alg: sha256
    cipher alg: aes-256
    uuid: 0925e6b8-dcac-4258-b90e-56234db4814c
    cipher mode: xts
    slots:
        [0]:
            active: true
            iters: 1108900
            key offset: 4096
            stripes: 4000
        [1]:
            active: false
            key offset: 262144
        [2]:
            active: false
            key offset: 520192
        [3]:
            active: false
            key offset: 778240
        [4]:
            active: false
            key offset: 1036288
        [5]:
            active: false
            key offset: 1294336
        [6]:
            active: false
            key offset: 1552384
        [7]:
            active: false
            key offset: 1810432
    payload offset: 2068480
    master key iters: 277033


Calculate the file size for convert luks to luks
# qemu-img measure --object secret,id=sec1,data=base -O luks -o key-secret=sec1 --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4297035776
fully allocated size: 4297035776


# qemu-img convert -p --object secret,id=sec0,data=base  --object secret,id=sec1,data=base  --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O luks -o key-secret=sec1 convert.luks
    (100.00/100%)
# ls -als convert.luks 
4194560 -rw-r--r--. 1 root root 4297035776 May 27 05:01 convert.luks



Calculate the file size for convert luks to qcow2
# qemu-img measure -O qcow2  --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4295884800
fully allocated size: 4295884800


# qemu-img convert -p --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O qcow2  convert.qcow2
    (100.00/100%)
# ls -als convert.qcow2 
4195140 -rw-r--r--. 1 root root 4295884800 May 27 05:10 convert.qcow2



Calculate the file size for convert luks to raw
# qemu-img measure -O raw  --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4294967296
fully allocated size: 4294967296

# qemu-img convert -p --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O raw  convert.raw
    (100.00/100%)
# ls -als convert.raw 
4194304 -rw-r--r--. 1 root root 4294967296 May 27 05:13 convert.raw

Comment 4 Stefan Hajnoczi 2020-06-05 12:40:28 UTC
(In reply to Xueqiang Wei from comment #3)
> I tested this bug on qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420. It works
> well, it should has been fixed already. 
> 
> Please help check it. If I was wrong, please correct me. Many thanks.

Excellent! The output looks as expected.

QEMU 5.0 contains the patches so qemu-kvm-5.0.0-0.module+el8.3.0+6620+5d5e1420 should indeed have the patches.

There is also an automated test for this feature: cd tests/qemu-iotests && ./check -luks 288

Comment 5 Danilo de Paula 2020-07-16 14:11:06 UTC
Based on Stefan's comment, moving this BZ to MODIFIED.

Comment 8 Xueqiang Wei 2020-07-17 07:09:19 UTC
According to Comment 3, retested with qemu-kvm-5.0.0-2.module+el8.3.0+7379+0505d6ca, all work as expected. So set status to VERIFIED.

Versions:
kernel-4.18.0-222.el8.x86_64
qemu-kvm-5.0.0-2.module+el8.3.0+7379+0505d6ca


Scenario 1(Measure for a new created luks image)

# qemu-img measure --object secret,id=sec0,data=base -O luks -o key-secret=sec0 --size 4G
required size: 4297035776
fully allocated size: 4297035776

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0 -f luks test1.luks 4G
Formatting 'test1.luks', fmt=luks size=4294967296 key-secret=sec0

# ls -als test1.luks
256 -rw-r--r--. 1 root root 4297035776 Jul 17 03:00 test1.luks

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0,preallocation=full -f luks test1.luks 4G
Formatting 'test1.luks', fmt=luks size=4294967296 key-secret=sec0 preallocation=full

# ls -als test1.luks
4196324 -rw-r--r--. 1 root root 4297035776 Jul 17 03:01 test1.luks


Scenario 2(Measure for a new converted luks image)

# qemu-img create --object secret,id=sec0,data=base -o key-secret=sec0 -f luks original.img 4G
Formatting 'original.img', fmt=luks size=4294967296 key-secret=sec0

# qemu-io -c 'write 0 1G' --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
wrote 1073741824/1073741824 bytes at offset 0
1 GiB, 1 ops; 0:00:01.23 (834.046 MiB/sec and 0.8145 ops/sec)

# qemu-img info original.img
image: original.img
file format: luks
virtual size: 4 GiB (4294967296 bytes)
disk size: 1 GiB
encrypted: yes
Format specific information:
    ivgen alg: plain64
    hash alg: sha256
    cipher alg: aes-256
    uuid: 2faec40c-d530-46f0-85b9-a19a0678a1a4
    cipher mode: xts
    slots:
        [0]:
            active: true
            iters: 1779088
            key offset: 4096
            stripes: 4000
        [1]:
            active: false
            key offset: 262144
        [2]:
            active: false
            key offset: 520192
        [3]:
            active: false
            key offset: 778240
        [4]:
            active: false
            key offset: 1036288
        [5]:
            active: false
            key offset: 1294336
        [6]:
            active: false
            key offset: 1552384
        [7]:
            active: false
            key offset: 1810432
    payload offset: 2068480
    master key iters: 444589


Calculate the file size for convert luks to luks
# qemu-img measure --object secret,id=sec1,data=base -O luks -o key-secret=sec1 --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4297035776
fully allocated size: 4297035776


# qemu-img convert -p --object secret,id=sec0,data=base  --object secret,id=sec1,data=base  --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O luks -o key-secret=sec1 convert.luks
    (100.00/100%)
# ls -als convert.luks 
4194560 -rw-r--r--. 1 root root 4297035776 Jul 17 03:05 convert.luks


Calculate the file size for convert luks to qcow2
# qemu-img measure -O qcow2  --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4295884800
fully allocated size: 4295884800


# qemu-img convert -p --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O qcow2  convert.qcow2
    (100.00/100%)
# ls -als convert.qcow2 
4195140 -rw-r--r--. 1 root root 4295884800 Jul 17 03:06 convert.qcow2


Calculate the file size for convert luks to raw
# qemu-img measure -O raw  --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0
required size: 4294967296
fully allocated size: 4294967296

# qemu-img convert -p --object secret,id=sec0,data=base --image-opts driver=luks,file.filename=original.img,key-secret=sec0  -O raw  convert.raw
    (100.00/100%)
# ls -als convert.raw 
4194304 -rw-r--r--. 1 root root 4294967296 Jul 17 03:07 convert.raw

Comment 11 errata-xmlrpc 2020-11-17 17:44:46 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (virt:8.3 bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:5137


Note You need to log in before you can comment on or make changes to this bug.