Bug 684848

Summary: virsh connect URI mistakenly tries to open default connection
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: high Docs Contact:
Priority: high    
Version: 6.1CC: dallan, dyuan, eblake, iboverma, rwu, sgrubb, yoyzhang
Target Milestone: rc   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: libvirt-0.9.2-1.el6 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-12-06 10:57:51 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On: 605660, 684655    
Bug Blocks:    

Description Eric Blake 2011-03-14 16:22:06 UTC
Description of problem:
virsh is not supposed to open the default connection unless it encounters a command that requires a connection and does not already have one open.  Therefore, 'virsh connect test:///default' should succeed, and does so on F14 libvirt-client-0.8.3-4.fd14.x86_64.  However, a regression appeared where virsh now always tries to open the default connection.

Version-Release number of selected component (if applicable):
libvirt-client-0.8.7-11.el6.x86_64

How reproducible:
100%

Steps to Reproduce:
1. as non-root: virsh connect test:///default; echo $?
  
Actual results:
$ virsh connect test:///default; echo $?
error: cannot recv data: : Connection reset by peer
error: failed to connect to the hypervisor
1

Expected results:
$ virsh connect test:///default; echo $?
0

Additional info:
Originally reported by the Common Criteria list.

Comment 3 Eric Blake 2011-03-14 16:27:00 UTC
Possibly related: 'virsh -c ""' and 'virsh connect ""' should both work as a request to connect to the default URI.

Comment 4 Eric Blake 2011-03-14 18:46:33 UTC
Hmm, after further investigation, it looks like 'virsh connect URI' has _always_ first connected to the default connection, then disconnected and reconnected to the specified URI.  Of course, this is wasteful, so it is still worth patching.

The regression that I'm seeing on RHEL 6 appears to be that qemu:///session is no longer working out of the box, rather than any change in virsh itself.  I'm now trying to track down why qemu:///session is erroring out for RHEL but working for Fedora.

Comment 5 Eric Blake 2011-03-14 19:36:17 UTC
This appears to be the real regression - auto-starting the session daemon fails:

$ /usr/sbin/libvirtd --timeout=30
13:06:02.502: 24377: info : libvirt version: 0.8.7, package: 10.el6 (Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla>, 2011-03-07-14:14:56, x86-003.build.bos.redhat.com)
13:06:02.502: 24377: error : virStateInitialize:1022 : Initialization of udev state driver failed
13:06:02.520: 24377: warning : qemudStartup:1733 : Unable to create cgroup for driver: Permission denied
13:06:02.771: 24377: error : main:3305 : Driver state initialization failed
13:06:02.771: 24379: warning : qemudDispatchSignalEvent:403 : Shutting down on signal 3

Comment 6 Eric Blake 2011-03-14 20:42:19 UTC
comment 5 is a duplicate of bug 684655; however, comment 4 regarding making 'virsh' smarter about default connections is worth independently fixing.

Comment 7 Eric Blake 2011-03-14 21:11:39 UTC
Upstream patch posted:
https://www.redhat.com/archives/libvir-list/2011-March/msg00633.html

Comment 11 Dave Allan 2011-06-09 14:58:09 UTC
commit d218344e6c1afce5788d7f72b78859219c50a3de
Author: Eric Blake <eblake>
Date:   Mon Mar 14 14:30:24 2011 -0600

    virsh: optimize creation of default connection
    
    Ramon de Carvalho Valle reported a problem with:
    virsh connect qemu:///system
    as a non-root user.  The real root problem appears to be a regression
    in libvirtd being auto-started on the default qemu:///session URI;
    however, the symptom points to an independent flaw in virsh - we
    shouldn't be wasting efforts on making a connection if we aren't going
    to be using that connection.  Fixing virsh avoids Ramon's issue, while
    I work in the meantime to fix the real libvirtd regression.
    
    This patch looks big, but that's because 'gcc -Wmissing-field-initializers'
    gets triggered by './autobuild.sh --enable-compile-warnings=error', so I
    had to add 0 initialization to everyone (rather than my preference of
    just adding the non-zero flags to virshCmds and to cmdConnect).
    
    Meanwhile, if you use 'virsh -c URI', the connection must succeed; this
    patch _only_ optimizes the default connection to be deferred to a later
    point where we know if a particular command to be run needs a connection.
    
    * tools/virsh.c (VSH_CMD_FLAG_NOCONNECT): New flag.
    (vshCmdDef): Add new flags field.
    (vshCommandRun): Honor new flag.
    (domManagementCmds, domMonitoringCmds, storagePoolCmds)
    (storageVolCmds, networkCmds, nodedevCmds, ifaceCmds)
    (nwfilterCmds, secretCmds, virshCmds, snapshotCmds)
    (hostAndHypervisorCmds): Populate new field.
    (vshReconnect): Don't warn on initial connection.

Comment 12 Daniel Veillard 2011-06-23 02:51:37 UTC
This should be fixed by the libvirt-0.9.2-1.el6 rebase

Comment 13 zhanghaiyan 2011-06-24 06:42:52 UTC
Reproduced this bug with old package libvirt-0.8.7-11.el6.x86_64.rpm
- 2.6.32-156.el6.x86_64
- qemu-kvm-0.12.1.2-2.165.el6.x86_64

$ virsh connect test:///default
error: cannot recv data: : Connection reset by peer
error: failed to connect to the hypervisor

Verified this bug pass with new package libvirt-0.9.2-1.el6.x86_64
- 2.6.32-156.el6.x86_64
- qemu-kvm-0.12.1.2-2.165.el6.x86_64

[yoyo@localhost ~]$ virsh connect test:///default

[yoyo@localhost ~]$ virsh -c test:///default
Welcome to virsh, the virtualization interactive terminal.

Type:  'help' for help with commands
       'quit' to quit

virsh #

Comment 15 Rita Wu 2011-07-06 10:25:21 UTC
Set it as VERIFIED per comment13

Comment 16 errata-xmlrpc 2011-12-06 10:57:51 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.

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