Bug 1230071

Summary: autostart --disable doesn't work well for lxc
Product: [Community] Virtualization Tools Reporter: yisun
Component: libvirtAssignee: Libvirt Maintainers <libvirt-maint>
Status: CLOSED NEXTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: unspecifiedCC: pkrempa, rbalakri
Target Milestone: ---   
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2015-07-28 17:02:48 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:
Embargoed:

Description yisun 2015-06-10 08:26:43 UTC
please note, this is a regression issue and not reproducible with libvirt 1.2.8-16

description:
cannot "autostart --disable" a lxc vm in shutoff status, if the lxc vm experienced a "running" state between the "autostart --disable" and previous "autostart"

versions:
libvirt-1.2.16-1.el7.x86_64
qemu-kvm-rhev-2.3.0-2.el7.x86_64
kernel-3.10.0-254.el7.x86_64

How reproduced:
100%

steps:
1. # virsh -c lxc://
    # virsh # list --all
 Id    Name                           State
----------------------------------------------------
 -     lxc                            shut off

2. make sure lxc in shutoff state
2.1 virsh # destroy lxc
Domain lxc destroyed

2.2 check the lxc autostart files
# ll /etc/libvirt/lxc/autostart/
total 0


3. set lxc to autostart
3.1 virsh # autostart lxc
Domain lxc marked as autostarted


3.2 check the lxc autostart files, it appears
# ll /etc/libvirt/lxc/autostart/
total 0
lrwxrwxrwx. 1 root root 24 Jun 10 14:59 lxc.xml -> /etc/libvirt/lxc/lxc.xml


4. start lxc and check the autostart file
virsh # start lxc
Domain lxc started

# ll /etc/libvirt/lxc/autostart/
total 0
lrwxrwxrwx. 1 root root 24 Jun 10 14:59 lxc.xml -> /etc/libvirt/lxc/lxc.xml




5. destroy lxc and check the autostart file
virsh # destroy lxc
Domain lxc destroyed

# ll /etc/libvirt/lxc/autostart/
total 0
lrwxrwxrwx. 1 root root 24 Jun 10 14:59 lxc.xml -> /etc/libvirt/lxc/lxc.xml

6. disable the autostart for lxc (in shutoff state)
6.1 disable autostart 
virsh # autostart lxc --disable
Domain lxc unmarked as autostarted

6.2 check the autostart file
# ll /etc/libvirt/lxc/autostart/
total 0
lrwxrwxrwx. 1 root root 24 Jun 10 14:59 lxc.xml -> /etc/libvirt/lxc/lxc.xml     <==== it's still exist, and when service libvirtd restart, lxc will be running. 


additional info:
During the test, this issue can reproduced with following 2 conditions:
1. when run autostart --disable, lxc is in shutoff state.
2. between autostart and autostart --disable, the lxc should have experienced a running state.

So following situations also reproduced the bug
1. start lxc; autostart lxc; destroy lxc; autostart --disable lxc
2. autostart lxc; start lxc; destroy lxc; autostart --disable lxc

Following situations cannnot reproduce this issue,
1. start lxc; autostart lxc; autostart --disable lxc; destroy lxc
2. destroy lxc; autostart lxc; autostart --disable lxc; start lxc

Comment 1 Peter Krempa 2015-07-28 17:02:48 UTC
Fixed upstream:

commit dbb0baa5a74cecdac332f3d9d82f33cf517af8dd
Author: Peter Krempa <pkrempa>
Date:   Tue Jul 28 18:25:59 2015 +0200

    lxc: Don't accidentaly reset autostart flag in virLXCProcessCleanup
    
    virDomainDeleteConfig is meant to delete the persistent config and thus
    it resets vm->autostart. Copy parts of qemuProcessRemoveDomainStatus to
    a new helper to avoid using the incorrect function.

Upcomming resease will fix this problem