Bug 676908

Summary: libvirt can't snapshot guest with space in name
Product: Red Hat Enterprise Linux 6 Reporter: Eric Blake <eblake>
Component: libvirtAssignee: Eric Blake <eblake>
Status: CLOSED ERRATA QA Contact: Virtualization Bugs <virt-bugs>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 6.1CC: berrange, dallan, dyuan, eblake, mjenner, nzhang, pmatouse, vbian, vdanen, xen-maint
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.8.7-7.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-05-19 13:27:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Eric Blake 2011-02-11 19:30:24 UTC
Description of problem:
As part of the rebase to libvirt 0.8.7 in RHEL 6.1, libvirt gained the ability to have better support for guests with spaces in their names.  However, this support is incomplete, and an attempt to snapshot such a domain causes a shell syntax error.

Version-Release number of selected component (if applicable):
v0.8.7-6.el6

How reproducible:
100%

Steps to Reproduce:
1. create and run a guest named "a b" (note: virt-manager might not allow this, so it may require manual creation of an xml file and 'virsh define file.xml')
2. try 'virsh managedsave "a b"
  
Actual results:
/var/log/libvirt/qemu/a\ b.log:
  sh: -c: line 0: syntax error near unexpected token `b'
  sh: -c: line 0: `cat | { dd bs=4096 seek=1 if=/dev/null && dd bs=1048576; }

Expected results:
should work

Additional info:
Reported and patched upstream:
https://www.redhat.com/archives/libvir-list/2011-February/msg00360.html
commit f370fc37f964984ba40584dab1de340ce7e44bac
Author: Philipp Hahn <hahn>
Date:   Fri Feb 11 13:59:11 2011 +0100

    qemu: Fix escape_monitor(escape_shell(command))
    
    Suspending a VM which contains shell meta characters doesn't work with
    libvirt-0.8.7:
    /var/log/libvirt/qemu/andreas_231-ne\ doch\ nicht.log:
      sh: -c: line 0: syntax error near unexpected token `doch'
      sh: -c: line 0: `cat | { dd bs=4096 seek=1 if=/dev/null && dd bs=1048576; }
    
    Although target="andreas_231-ne doch nicht" contains shell meta
    characters (here: blanks), they are not properly escaped by
    src/qemu/qemu_monitor_{json,text}.c#qemuMonitor{JSON,Text}MigrateToFile()
    
    First, the filename needs to be properly escaped for the shell, than
    this command line has to be properly escaped for qemu again.
    
    For this to work, remove the old qemuMonitorEscapeArg() wrapper, rename
    qemuMonitorEscape() to it removing the handling for shell=TRUE, and
    implement a new qemuMonitorEscapeShell() returning strings using single
    quotes.
    
    Using double quotes or escaping special shell characters with backslashes
    would also be possible, but the set of special characters heavily
    depends on the concrete shell (dsh, bash, zsh) and its setting (history
    expansion, interactive use, ...)
    
    Signed-off-by: Philipp Hahn <hahn>

Comment 9 Eric Blake 2011-02-11 23:39:56 UTC
In POST for 6.1; also recommend cloning this for z-stream, as well as back-porting to RHEL 5.6.z and 5.7.
http://post-office.corp.redhat.com/archives/rhvirt-patches/2011-February/msg00923.html

Comment 17 Vivian Bian 2011-02-21 09:16:54 UTC
checked with libvirt-0.8.7-7.el6.x86_64  FAILED

libvirt-0.8.7-7.el6.x86_64

#virsh start test
Domain test started

# virsh managedsave test
Domain test state saved by libvirt


# virsh start 'a b'
Domain a b started

# virsh managedsave 'a b'
error: Failed to save domain a b state
error: cannot send monitor command '{"execute":"query-migrate"}': Connection reset by peer


set bug status to ASSIGNED

Comment 18 Vivian Bian 2011-03-11 10:38:14 UTC
retested with libvirt-0.8.7-7.el6.x86_64


#virsh start test
Domain test started

# virsh managedsave test
Domain test state saved by libvirt


# virsh start 'a b'
Domain a b started

# virsh managedsave 'a b'
Domain a b state saved by libvirt

Addtional info : 
this result is from the scratch installed libvirt . And the result from Comment 17 is the libvirt updated from old packages . 
Can't reproduce this bug with the new installed libvirt . So set bug status to VERIFIED for now. Once meet this bug again . Will reopen this for further investigation .

Comment 21 errata-xmlrpc 2011-05-19 13:27:07 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2011-0596.html