Bug 1733044 - Fail to parse ':' nbd exportname in before blockdev-add
Summary: Fail to parse ':' nbd exportname in before blockdev-add
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: 8.1
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: 8.0
Assignee: Peter Krempa
QA Contact: Han Han
Peter Krempa
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-07-25 05:50 UTC by Han Han
Modified: 2020-05-05 09:46 UTC (History)
4 users (show)

Fixed In Version: libvirt-5.9.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-05-05 09:46:33 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Han Han 2019-07-25 05:50:15 UTC
Description of problem:
As subject

Version-Release number of selected component (if applicable):
libvirt-5.5.0-1.module+el8.1.0+3580+d7f6488d.x86_64
qemu-kvm-4.0.0-6.module+el8.1.0+3736+a2aefea3.x86_64

How reproducible:
100%

Steps to Reproduce:
1. Start a nbd server with exportname ':'
# qemu-nbd -t -x ":" /tmp/a

2. Start a vm with -blockdev enabled:
VM xml:

<domain type='kvm' xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
…
  <qemu:capabilities>
    <qemu:add capability='blockdev'/>
    <qemu:del capability='drive'/>
  </qemu:capabilities>
</domain>

3. Create a backing image for the nbd
# qemu-img create -b nbd:10.66.4.183:10809:exportname=":" -o backing_fmt=raw /tmp/nbd -f qcow2

4. Attach the backing image to vm:
# virsh attach-disk copy /tmp/nbd vdd --subdriver qcow2                                                                                                                 
error: Failed to attach disk
error: internal error: unable to execute QEMU command 'blockdev-add': Requested export not available 

The qmp log shows the export name is empty string:
Jul 25 13:43:33 lab libvirtd[16437]: 16437: info : qemuMonitorIOWrite:546 : QEMU_MONITOR_IO_WRITE: mon=0x7f47b0001f40 buf={"execute":"blockdev-add","arguments":{"driver":"nbd","server":{"type":"inet","host":"10.66.4.183","port":"10809"},"export":"","node-name":"libvirt-14-storage","read-only":true,"discard":"unmap"},"id":"libvirt-15"}#015#012 len=216 ret=216 errno=0

So I guess libvirt failed to parse char ':' before blockdev-add.

Actual results:
As above

Expected results:
Libvirt could attach disk backing with nbd export ':'

Additional info:
It works well without -blockdev.
To test full chars, you can start a nbd server whose exportname is combined with all acsii printable chars and some unicode chars:

# qemu-nbd -x nbd:10.66.4.183:10809:exportname="$(for ((i=32;i<127;i++)) do printf "\\$(printf %03o "$i")"; done)呵呵哒" /tmp/a

Comment 1 Peter Krempa 2019-08-16 12:14:52 UTC
Fixed upstream:

commit 96f0a17ead829b9b8ae185660b412635642edf85
Author: Peter Krempa <pkrempa>
Date:   Wed Jul 31 17:17:30 2019 +0200

    util: storage: Fix parsing of 'exportname' from legacy NBD strings
    
    If the nbd export name contains a colon, our parser would not parse it
    properly as we split the string by colons. Modify the code to look up
    the exportname and copy any trailing characters as the export name is
    supposed to be at the end of the string.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1733044
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Jiri Denemark <jdenemar>

v5.6.0-197-g96f0a17ead

Comment 3 Han Han 2020-01-19 09:16:37 UTC
Vefified on libvirt-6.0.0-1.module+el8.2.0+5453+31b2b136.x86_64 qemu-kvm-4.2.0-6.module+el8.2.0+5453+31b2b136.x86_64:
1. Create a nbd server with exportname in various character:
# qemu-nbd -f raw /var/lib/libvirt/images/nbd.qcow2 -x "$(for ((i=32;i<127;i++)) do printf "\\$(printf %03o "$i")"; done)是魔鬼的步伐" -t -e 10

2. Create a qcow2 based on the exportname:
# qemu-img create -b nbd:localhost:10809:exportname="$(awk 'BEGIN{for(i=32;i<127;i++)printf "%c",i; print}')是魔鬼的步伐"  -o backing_fmt=qcow2 -f qcow2 /tmp/new.qcow2                                        
Formatting '/tmp/new.qcow2', fmt=qcow2 size=10737418240 backing_file=nbd:localhost:10809:exportname= !"#$%&'()*+,,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~是魔鬼的步伐 backing_fmt=qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16

3. Start an VM with the overlay image:
# virsh dumpxml pc|xmllint --xpath //disk -                                                                                                                                                                    
<disk type="file" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source file="/tmp/new.qcow2" index="1"/>
      <backingStore type="network" index="2">
        <format type="qcow2"/>
        <source protocol="nbd" name=" !&quot;#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#x662F;&#x9B54;&#x9B3C;&#x7684;&#x6B65;&#x4F10;" tls="no">
          <host name="localhost" port="10809"/>
        </source>
      </backingStore>
      <target dev="vda" bus="virtio"/>
      <alias name="virtio-disk0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x09" function="0x0"/>
    </disk>

4. Blockcommit to the nbd disk:
# virsh blockcommit pc vda --active --wait --verbose --pivot                                                                                                           
Block commit: [100 %]
Successfully pivoted

# virsh dumpxml pc|xmllint --xpath //disk -                 
<disk type="network" device="disk">
      <driver name="qemu" type="qcow2"/>
      <source protocol="nbd" name=" !&quot;#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~&#x662F;&#x9B54;&#x9B3C;&#x7684;&#x6B65;&#x4F10;" tls="no" index="2">
        <host name="localhost" port="10809"/>
      </source>
      <target dev="vda" bus="virtio"/>
      <alias name="virtio-disk0"/>
      <address type="pci" domain="0x0000" bus="0x00" slot="0x09" function="0x0"/>
    </disk>

Comment 4 Han Han 2020-04-22 09:37:47 UTC
Covered by unit test virstoragetest

Comment 6 errata-xmlrpc 2020-05-05 09:46:33 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, 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:2017


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