Bug 1379579

Summary: guestfish mistakely parse nbd exportname
Product: [Community] Virtualization Tools Reporter: Han Han <hhan>
Component: libguestfsAssignee: Richard W.M. Jones <rjones>
Status: CLOSED DUPLICATE QA Contact: Virtualization Bugs <virt-bugs>
Severity: medium Docs Contact:
Priority: unspecified    
Version: unspecifiedCC: dyuan, mxie, ptoscano, rbalakri, tzheng, xchen, xuzhang
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1379585 (view as bug list) Environment:
Last Closed: 2017-02-16 14:57:32 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Bug Depends On: 1379585    
Bug Blocks:    

Comment 2 Han Han 2016-09-27 07:53:41 UTC
Sorry for exposing some internal info in comment0, so I make it private. Here is the bug report without the info:

Description of problem:
As subject

Version-Release number of selected component (if applicable):
libguestfs-tools-c-1.32.7-3.el7.x86_64
libvirt-2.0.0-10.el7.x86_64
qemu-kvm-rhev-2.6.0-27.el7.x86_64


How reproducible:
100%

Steps to Reproduce:
1. Using nbdkit to setup a nbd server with exportname 'image':
# nbdkit file -n -e image file=V.qcow2

2. Try to read the image via guestfish
# qemu-img info nbd://xx.xx.xx.xx:10809/image            
image: nbd://xx.xx.xx.xx:10809/image
file format: qcow2
virtual size: 3.0G (3221225472 bytes)
disk size: unavailable
cluster_size: 65536
Format specific information:
    compat: 1.1
    lazy refcounts: false
    refcount bits: 16
    corrupt: false
# guestfish --ro --format=qcow2 -a nbd://xx.xx.xx.xx:10809/image
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: create: flags = 0, handle = 0x7fb2bc712fc0, program = guestfish
libguestfs: trace: set_pgroup true
libguestfs: trace: set_pgroup = 0
libguestfs: trace: add_drive "/image" "readonly:true" "format:qcow2" "protocol:nbd" "server:tcp:xx.xx.xx.xx:10809"
libguestfs: creating COW overlay to protect original drive content
libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"
libguestfs: trace: disk_create "/tmp/libguestfsPImcnO/overlay1" "qcow2" -1 "backingfile:nbd:xx.xx.xx.xx:10809:exportname=/image" "backingformat:qcow2"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=nbd:xx.xx.xx.xx:10809:exportname=/image,backing_fmt=qcow2
libguestfs: command: run: \ /tmp/libguestfsPImcnO/overlay1
qemu-img: /tmp/libguestfsPImcnO/overlay1: No export with name '/image' available
libguestfs: error: qemu-img: /tmp/libguestfsPImcnO/overlay1: qemu-img exited with error status 1, see debug messages above
libguestfs: trace: disk_create = -1 (error)
libguestfs: trace: add_drive = -1 (error)
libguestfs: trace: close
libguestfs: closing guestfs handle 0x7fb2bc712fc0 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsPImcnO


Actual results:
As above

Expected results:
Parse exportname as 'image', not '/image'.

Comment 3 Han Han 2016-09-27 08:10:55 UTC
The bug can also reproduced with unix socket form:
# guestfish --ro --format=qcow2 -a 'nbd:///image?socket=/tmp/qemu.socket'
libguestfs: trace: set_verbose true
libguestfs: trace: set_verbose = 0
libguestfs: create: flags = 0, handle = 0x5618c0c3c440, program = guestfish
libguestfs: trace: set_pgroup true
libguestfs: trace: set_pgroup = 0
libguestfs: trace: add_drive "/image" "readonly:true" "format:qcow2" "protocol:nbd" "server:unix:/tmp/qemu.socket"
libguestfs: creating COW overlay to protect original drive content
libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"
libguestfs: trace: disk_create "/tmp/libguestfsdG3oKh/overlay1" "qcow2" -1 "backingfile:nbd:unix:/tmp/qemu.socket:exportname=/image" "backingformat:qcow2"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=nbd:unix:/tmp/qemu.socket:exportname=/image,backing_fmt=qcow2
libguestfs: command: run: \ /tmp/libguestfsdG3oKh/overlay1
qemu-img: /tmp/libguestfsdG3oKh/overlay1: No export with name '/image' available
libguestfs: error: qemu-img: /tmp/libguestfsdG3oKh/overlay1: qemu-img exited with error status 1, see debug messages above
libguestfs: trace: disk_create = -1 (error)
libguestfs: trace: add_drive = -1 (error)
libguestfs: trace: close
libguestfs: closing guestfs handle 0x5618c0c3c440 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsdG3oKh

Comment 5 Xianghua Chen 2016-12-26 07:34:26 UTC
Can reproduce it with following package:
libguestfs-1.32.7-3.el7.x86_64

Steps:
1. Install nbdkit:
# yum install -y https://kojipkgs.fedoraproject.org//packages/nbdkit/1.1.12/4.fc26/x86_64/nbdkit-1.1.12-4.fc26.x86_64.rpm  https://kojipkgs.fedoraproject.org//packages/nbdkit/1.1.12/4.fc26/x86_64/nbdkit-plugin-file-1.1.12-4.fc26.x86_64.rpm

2. Prepare a guest image, then set nbd server and share the guest image:
# nbdkit file -n -e rhel7.2 file=RHEL-Server-7.2-64-hvm.raw
# qemu-img info nbd://10.66.10.107/rhel7.2
image: nbd://10.66.10.107/rhel7.2
file format: raw
virtual size: 8.0G (8589934592 bytes)
disk size: unavailable

3. Use guestfish to access it:
# guestfish --format=raw -a nbd://10.66.10.107/rhel7.2 -i -v -x
libguestfs: trace: set_pgroup true
libguestfs: trace: set_pgroup = 0
libguestfs: trace: add_drive "/rhel7.2" "format:raw" "protocol:nbd" "server:tcp:10.66.10.107"
libguestfs: trace: add_drive = 0
libguestfs: trace: is_config
libguestfs: trace: is_config = 1
libguestfs: trace: launch
libguestfs: trace: get_tmpdir
libguestfs: trace: get_tmpdir = "/tmp"
libguestfs: trace: version
libguestfs: trace: version = <struct guestfs_version = major: 1, minor: 32, release: 7, extra: rhel=7,release=3.el7,libvirt, >
libguestfs: trace: get_backend
libguestfs: trace: get_backend = "libvirt"
libguestfs: launch: program=guestfish
libguestfs: launch: version=1.32.7rhel=7,release=3.el7,libvirt
libguestfs: launch: backend registered: unix
libguestfs: launch: backend registered: uml
libguestfs: launch: backend registered: libvirt
libguestfs: launch: backend registered: direct
libguestfs: launch: backend=libvirt
libguestfs: launch: tmpdir=/tmp/libguestfsBuhhmG
libguestfs: launch: umask=0022
libguestfs: launch: euid=0
libguestfs: libvirt version = 2000000 (2.0.0)
libguestfs: guest random name = guestfs-ns9g4xm266jcszxb
libguestfs: connect to libvirt
libguestfs: opening libvirt handle: URI = qemu:///system, auth = default+wrapper, flags = 0
libguestfs: successfully opened libvirt handle: conn = 0x7fe9c6f11c60
libguestfs: qemu version (reported by libvirt) = 2006000 (2.6.0)
libguestfs: get libvirt capabilities
libguestfs: parsing capabilities XML
libguestfs: trace: get_backend_setting "force_tcg"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_label"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_imagelabel"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: trace: get_backend_setting "internal_libvirt_norelabel_disks"
libguestfs: trace: get_backend_setting = NULL (error)
libguestfs: build appliance
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: begin building supermin appliance
libguestfs: run supermin
libguestfs: command: run: /usr/bin/supermin5
libguestfs: command: run: \ --build
libguestfs: command: run: \ --verbose
libguestfs: command: run: \ --if-newer
libguestfs: command: run: \ --lock /var/tmp/.guestfs-0/lock
libguestfs: command: run: \ --copy-kernel
libguestfs: command: run: \ -f ext2
libguestfs: command: run: \ --host-cpu x86_64
libguestfs: command: run: \ /usr/lib64/guestfs/supermin.d
libguestfs: command: run: \ -o /var/tmp/.guestfs-0/appliance.d
supermin: version: 5.1.16
supermin: rpm: detected RPM version 4.11
supermin: package handler: fedora/rpm
supermin: acquiring lock on /var/tmp/.guestfs-0/lock
supermin: build: /usr/lib64/guestfs/supermin.d
supermin: reading the supermin appliance
supermin: build: visiting /usr/lib64/guestfs/supermin.d/base.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/daemon.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/excludefiles type uncompressed excludefiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/hostfiles type uncompressed hostfiles
supermin: build: visiting /usr/lib64/guestfs/supermin.d/init.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/packages type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/udev-rules.tar.gz type gzip base image (tar)
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-packages-dib type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-packages-gfs2 type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-packages-rescue type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-packages-rsync type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-packages-xfs type uncompressed packages
supermin: build: visiting /usr/lib64/guestfs/supermin.d/zz-winsupport.tar.gz type gzip base image (tar)
supermin: mapping package names to installed packages
supermin: resolving full list of package dependencies
supermin: build: 218 packages, including dependencies
supermin: build: 31607 files
supermin: build: 8427 files, after matching excludefiles
supermin: build: 8437 files, after adding hostfiles
supermin: build: 8431 files, after removing unreadable files
supermin: build: 8472 files, after munging
supermin: kernel: picked kernel vmlinuz-3.10.0-327.el7.x86_64
supermin: kernel: picked modules path /lib/modules/3.10.0-327.el7.x86_64
supermin: kernel: kernel_version 3.10.0-327.el7.x86_64
supermin: kernel: modules /lib/modules/3.10.0-327.el7.x86_64
supermin: ext2: creating empty ext2 filesystem '/var/tmp/.guestfs-0/appliance.d.tme7bn1z/root'
supermin: ext2: populating from base image
supermin: ext2: copying files from host filesystem
supermin: ext2: copying kernel modules
supermin: ext2: creating minimal initrd '/var/tmp/.guestfs-0/appliance.d.tme7bn1z/initrd'
supermin: ext2: wrote 27 modules to minimal initrd
supermin: renaming /var/tmp/.guestfs-0/appliance.d.tme7bn1z to /var/tmp/.guestfs-0/appliance.d
libguestfs: finished building supermin appliance
libguestfs: trace: disk_create "/tmp/libguestfsBuhhmG/overlay1" "qcow2" -1 "backingfile:/var/tmp/.guestfs-0/appliance.d/root" "backingformat:raw"
libguestfs: command: run: qemu-img
libguestfs: command: run: \ create
libguestfs: command: run: \ -f qcow2
libguestfs: command: run: \ -o backing_file=/var/tmp/.guestfs-0/appliance.d/root,backing_fmt=raw
libguestfs: command: run: \ /tmp/libguestfsBuhhmG/overlay1
Formatting '/tmp/libguestfsBuhhmG/overlay1', fmt=qcow2 size=4294967296 backing_file=/var/tmp/.guestfs-0/appliance.d/root backing_fmt=raw encryption=off cluster_size=65536 lazy_refcounts=off refcount_bits=16
libguestfs: trace: disk_create = 0
libguestfs: set_socket_create_context: getcon failed: (none): Invalid argument [you can ignore this message if you are not using SELinux + sVirt]
libguestfs: clear_socket_create_context: setsockcreatecon failed: NULL: Invalid argument [you can ignore this message if you are not using SELinux + sVirt]
libguestfs: create libvirt XML
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: libvirt XML:\n<?xml version="1.0"?>\n<domain type="kvm" xmlns:qemu="http://libvirt.org/schemas/domain/qemu/1.0">\n  <name>guestfs-ns9g4xm266jcszxb</name>\n  <memory unit="MiB">500</memory>\n  <currentMemory unit="MiB">500</currentMemory>\n  <cpu mode="host-passthrough">\n    <model fallback="allow"/>\n  </cpu>\n  <vcpu>1</vcpu>\n  <clock offset="utc">\n    <timer name="rtc" tickpolicy="catchup"/>\n    <timer name="pit" tickpolicy="delay"/>\n    <timer name="hpet" present="no"/>\n  </clock>\n  <os>\n    <type>hvm</type>\n    <kernel>/var/tmp/.guestfs-0/appliance.d/kernel</kernel>\n    <initrd>/var/tmp/.guestfs-0/appliance.d/initrd</initrd>\n    <cmdline>panic=1 console=ttyS0 udevtimeout=6000 udev.event-timeout=6000 no_timer_check printk.time=1 cgroup_disable=memory usbcore.nousb cryptomgr.notests 8250.nr_uarts=1 root=/dev/sdb selinux=0 guestfs_verbose=1 TERM=xterm-256color</cmdline>\n    <bios useserial="yes"/>\n  </os>\n  <on_reboot>destroy</on_reboot>\n  <devices>\n    <rng model="virtio">\n      <backend model="random">/dev/urandom</backend>\n    </rng>\n    <controller type="scsi" index="0" model="virtio-scsi"/>\n    <disk device="disk" type="network">\n      <source protocol="nbd" name="/rhel7.2">\n        <host name="10.66.10.107" port="10809"/>\n      </source>\n      <target dev="sda" bus="scsi"/>\n      <driver name="qemu" type="raw" cache="writeback"/>\n      <address type="drive" controller="0" bus="0" target="0" unit="0"/>\n    </disk>\n    <disk type="file" device="disk">\n      <source file="/tmp/libguestfsBuhhmG/overlay1"/>\n      <target dev="sdb" bus="scsi"/>\n      <driver name="qemu" type="qcow2" cache="unsafe"/>\n      <address type="drive" controller="0" bus="0" target="1" unit="0"/>\n      <shareable/>\n    </disk>\n    <serial type="unix">\n      <source mode="connect" path="/tmp/libguestfsBuhhmG/console.sock"/>\n      <target port="0"/>\n    </serial>\n    <channel type="unix">\n      <source mode="connect" path="/tmp/libguestfsBuhhmG/guestfsd.sock"/>\n      <target type="virtio" name="org.libguestfs.channel.0"/>\n    </channel>\n  </devices>\n  <qemu:commandline>\n    <qemu:env name="TMPDIR" value="/var/tmp"/>\n  </qemu:commandline>\n</domain>\n
libguestfs: trace: get_cachedir
libguestfs: trace: get_cachedir = "/var/tmp"
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -R
libguestfs: command: run: \ -Z /var/tmp/.guestfs-0
libguestfs: /var/tmp/.guestfs-0:
libguestfs: drwxr-xr-x  root root ?                                .
libguestfs: drwxrwxrwt. root root system_u:object_r:tmp_t:s0       ..
libguestfs: drwxr-xr-x  root root ?                                appliance.d
libguestfs: -rw-r--r--  root root ?                                lock
libguestfs: 
libguestfs: /var/tmp/.guestfs-0/appliance.d:
libguestfs: drwxr-xr-x root root ?                                .
libguestfs: drwxr-xr-x root root ?                                ..
libguestfs: -rw-r--r-- root root ?                                initrd
libguestfs: -rwxr-xr-x root root ?                                kernel
libguestfs: -rw-r--r-- root root ?                                root
libguestfs: command: run: ls
libguestfs: command: run: \ -a
libguestfs: command: run: \ -l
libguestfs: command: run: \ -Z /tmp/libguestfsBuhhmG
libguestfs: drwxr-xr-x  root root ?                                .
libguestfs: drwxrwxrwt. root root system_u:object_r:tmp_t:s0       ..
libguestfs: srw-rw----  root qemu ?                                console.sock
libguestfs: srw-rw----  root qemu ?                                guestfsd.sock
libguestfs: -rw-r--r--  root root ?                                overlay1
libguestfs: launch libvirt guest
libguestfs: error: could not create appliance through libvirt.

Try running qemu directly without libvirt using this environment variable:
export LIBGUESTFS_BACKEND=direct

Original error from libvirt: internal error: process exited while connecting to monitor: 2016-12-26T05:42:41.130679Z qemu-kvm: -drive file=nbd:10.66.10.107:10809:exportname=/rhel7.2,format=raw,if=none,id=drive-scsi0-0-0-0,cache=writeback: No export with name '/rhel7.2' available [code=1 int1=-1]
libguestfs: clear_socket_create_context: setsockcreatecon failed: NULL: Invalid argument [you can ignore this message if you are not using SELinux + sVirt]
libguestfs: trace: launch = -1 (error)
libguestfs: trace: close
libguestfs: closing guestfs handle 0x7fe9c6f0fda0 (state 0)
libguestfs: command: run: rm
libguestfs: command: run: \ -rf /tmp/libguestfsBuhhmG

Comment 6 Richard W.M. Jones 2017-02-16 14:13:37 UTC
This isn't a bug that affects customers, and in any case we don't
support nbdkit in RHEL.  Therefore moving to the upstream bug tracker.

Comment 7 Richard W.M. Jones 2017-02-16 14:57:32 UTC

*** This bug has been marked as a duplicate of bug 1379585 ***