Bug 1826652 - Fail to parse nbd socket path with colon
Summary: Fail to parse nbd socket path with colon
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux Advanced Virtualization
Classification: Red Hat
Component: libvirt
Version: ---
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: rc
: 8.3
Assignee: Peter Krempa
QA Contact: gaojianan
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-04-22 08:56 UTC by Han Han
Modified: 2020-11-25 07:44 UTC (History)
7 users (show)

Fixed In Version: libvirt-6.3.0-1.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-11-17 17:48:27 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Han Han 2020-04-22 08:56:17 UTC
Description of problem:
As subject

Version-Release number of selected component (if applicable):
libvirt-6.2.0-1.el8.x86_64


How reproducible:
100%

Steps to Reproduce:
1. Create a nbd server with a colon in its unix socket:
~ qemu-nbd -k /tmp/nbd: /tmp/nbd -x : -t -e 10

Allow qemu to access the socket
~ chown qemu:qemu /tmp/nbd:

~ setenforce 0

2. Rebase a qcow2 file to the nbd address
~ qemu-img rebase -b 'nbd:unix:/tmp/nbd::exportname=:' -F raw /var/lib/libvirt/images/nbd -f qcow2

~ qemu-img info /var/lib/libvirt/images/nbd
image: /var/lib/libvirt/images/nbd
file format: qcow2
virtual size: 100 MiB (104857600 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: nbd:unix:/tmp/nbd::exportname=:
backing file format: raw
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

Attach the overlay file as qcow2 to a live VM:
~ virsh attach-disk pc /var/lib/libvirt/images/nbd vdc --subdriver qcow2
error: Failed to attach disk
error: internal error: unable to execute QEMU command 'blockdev-add': Failed to connect socket /tmp/nbd: No such file or directory

Libvirtd qmp log:
2020-04-22 08:50:20.454+0000: 1732421: info : qemuMonitorIOWrite:431 : QEMU_MONITOR_IO_WRITE: mon=0x7f37e8039910 buf={"execute":"blockdev-add","arguments":{"driver":"nbd","server":{"type":"unix","path":"/tmp/nbd"},"export":":","node-name":"libvirt-29-storage","auto-read-only":true,"discard":"unmap"},"id":"libvirt-389"}

So libvirt regards the colon of socket path as separator.
See also: https://bugzilla.redhat.com/show_bug.cgi?id=1733044


Actual results:
As above


Expected results:
Correctly parse the unix socket path with a colon

Additional info:

Comment 1 Peter Krempa 2020-04-22 09:30:20 UTC
Suggested workaround is not to use colons in your socket names.

Comment 2 Peter Krempa 2020-04-22 09:40:32 UTC
Fixing title. The socket path is not in the json:{} pseudo uri format but rather the old colon separated format. The json:{} version would work properly.

Comment 3 Peter Krempa 2020-04-27 06:10:06 UTC
Fixed upstream:

commit f8d6b319a6f033fea951a33fe069b573b2ed5b60 (HEAD -> master, origin/master, origin/HEAD)
Author: Peter Krempa <pkrempa>
Date:   Fri Apr 24 13:59:21 2020 +0200

    virStorageSourceParseNBDColonString: Rewrite to match what qemu does
    
    Our implementation wasn't quite able to parse everything that qemu does.
    This patch rewrites the parser to a code that semantically resembles the
    combination of 'nbd_parse_filename' and 'inet_parse' methods in qemu to
    be able to parse the strings in an equivalent manner.
    
    The only thing that libvirt doesn't do is to check the lengths of
    various components in the nbd string in places where qemu uses constant
    size buffers.
    
    The test cases validate that some of the corner cases involving colons
    are parsed properly.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=1826652
    
    Signed-off-by: Peter Krempa <pkrempa>
    Reviewed-by: Eric Blake <eblake>

Comment 6 gaojianan 2020-05-25 08:47:54 UTC
Verified on :
libvirt-6.3.0-1.module+el8.3.0+6478+69f490bb.x86_64

Sc1:Have colon in export name field:
1. Create a nbd server with a colon in export name field:
# qemu-nbd  -b 127.0.0.1 /tmp/nbd -x :test: -t  -f raw -p 10001

Allow qemu to access the socket
~ chown qemu:qemu /tmp/nbd:

~ setenforce 0

2. Rebase a qcow2 file to the nbd address
# qemu-img rebase -b 'nbd://127.0.0.1:10001/:test:' -F raw /var/lib/libvirt/images/nbd2 -f qcow2
# qemu-img info /var/lib/libvirt/images/nbd2 
image: /var/lib/libvirt/images/nbd2
file format: qcow2
virtual size: 100 MiB (104857600 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: nbd://127.0.0.1:10001/:test:
backing file format: raw
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false


3.Attach/detach the overlay file as qcow2 to a live VM:
# virsh attach-disk test1 /var/lib/libvirt/images/nbd2 sdc
Disk attached successfully

# virsh detach-disk test1 sdc 
Disk detached successfully


Sc2:Have colon in unix socket field:
1.# qemu-nbd -k /tmp/nbd: /tmp/nbd -x : -t -e 10 -f raw

2.# qemu-img rebase -b 'nbd:unix:/tmp/nbd::exportname=:' -F raw /var/lib/libvirt/images/nbd3 -f qcow2
# qemu-img info /var/lib/libvirt/images/nbd3 
image: /var/lib/libvirt/images/nbd3
file format: qcow2
virtual size: 100 MiB (104857600 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: nbd:unix:/tmp/nbd::exportname=:
backing file format: raw
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

3.Attach/detach the overlay file as qcow2 to a live VM:
# virsh attach-disk test1 /var/lib/libvirt/images/nbd3 sdc
Disk attached successfully

# virsh detach-disk test1 sdc 
Disk detached successfully


Sc3:Have colon in inet6 field with colon in exportname:
1.qemu-nbd  -b 2620:52:0:4224:4dfa:e2:e7af:6034 /tmp/nbd -x :test: -t  -f raw -p 10001

2.# qemu-img rebase -b 'nbd:[2620:52:0:4224:4dfa:e2:e7af:6034]:10001:exportname=:test:' -F raw /var/lib/libvirt/images/nbd4 -f qcow2
# qemu-img info /var/lib/libvirt/images/nbd4 
image: /var/lib/libvirt/images/nbd4
file format: qcow2
virtual size: 100 MiB (104857600 bytes)
disk size: 196 KiB
cluster_size: 65536
backing file: nbd:[2620:52:0:4224:4dfa:e2:e7af:6034]:10001:exportname=:test:
backing file format: raw
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false

3.Attach/detach the overlay file as qcow2 to a live VM:
# virsh attach-disk test1 /var/lib/libvirt/images/nbd4 sdc
Disk attached successfully

# virsh detach-disk test1 sdc 
Disk detached successfully


Work as expected,so verified.

Comment 9 errata-xmlrpc 2020-11-17 17:48:27 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.