[pve-devel] [PATCH qemu-server 2/4] add 'qm cleanup'

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Oct 17 12:23:00 CEST 2018


On Wed, Oct 17, 2018 at 12:00:19PM +0200, Dominik Csapak wrote:
> On 10/17/18 11:20 AM, Wolfgang Bumiller wrote:
> > On Tue, Oct 16, 2018 at 12:07:04PM +0200, Dominik Csapak wrote:
> > > this is intended to be used with qmeventd, to do
> > > the necessary cleanups when qemu crashes or is being
> > > shut down from within the guest
> > > 
> > > this can also be the point where we could introduce
> > > shutdown/stop/reboot hooks
> > > 
> > > Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> > > ---
> > >   PVE/CLI/qm.pm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> > >   1 file changed, 65 insertions(+)
> > > 
> > > diff --git a/PVE/CLI/qm.pm b/PVE/CLI/qm.pm
> > > index 46a7e2f..6a14c12 100755
> > > --- a/PVE/CLI/qm.pm
> > > +++ b/PVE/CLI/qm.pm
> > > @@ -18,6 +18,7 @@ use PVE::SafeSyslog;
> > >   use PVE::INotify;
> > >   use PVE::RPCEnvironment;
> > >   use PVE::Exception qw(raise_param_exc);
> > > +use PVE::Network;
> > >   use PVE::QemuServer;
> > >   use PVE::QemuServer::ImportDisk;
> > >   use PVE::QemuServer::OVF;
> > > @@ -722,6 +723,68 @@ __PACKAGE__->register_method({
> > >   	return { result => $res };
> > >       }});
> > > +__PACKAGE__->register_method({
> > > +    name => 'cleanup',
> > > +    path => 'cleanup',
> > > +    method => 'POST',
> > > +    protected => 1,
> > > +    description => "Cleans up resources like tap devices, vgpus, etc. Called after a vm shuts down, crashes, etc.",
> > > +    parameters => {
> > > +	additionalProperties => 0,
> > > +	properties => {
> > > +	    node => get_standard_option('pve-node'),
> > > +	    vmid => get_standard_option('pve-vmid', {
> > > +		    completion => \&PVE::QemuServer::complete_vmid_running }),
> > > +	    'clean-shutdown' => {
> > > +		type => 'boolean',
> > > +		description => "Indicates if qemu shutdown cleanly.",
> > > +	    },
> > > +	    'guest-requested' => {
> > > +		type => 'boolean',
> > > +		description => "Indicates if the shutdown was requested by the guest or via qmp.",
> > > +	    },
> > > +	    'was-reset' => {
> > > +		type => 'boolean',
> > > +		description => "Indicates if it was actually a reset, but -no-reboot was given to qemu.",
> > > +	    },
> > > +	},
> > > +    },
> > > +    returns => { type => 'null', },
> > > +    code => sub {
> > > +	my ($param) = @_;
> > > +
> > > +	my $vmid = $param->{vmid};
> > > +	my $clean = $param->{'clean-shutdown'};
> > > +	my $guest = $param->{'guest-requested'};
> > > +	my $reset = $param->{'was-reset'};
> > > +
> > > +	my $storecfg = PVE::Storage::config();
> > > +
> > > +	PVE::QemuConfig->lock_config($vmid, sub {
> > > +	    my $conf = PVE::QemuConfig->load_config ($vmid);
> > > +	    my $pid = PVE::QemuServer::check_running ($vmid);
> > > +	    die "vm still running\n" if $pid;
> > > +
> > > +
> > > +	    if (!$clean) {
> > > +		# we have to cleanup the tap devices after a crash
> > > +
> > > +		foreach my $opt (keys %$conf) {
> > > +		    next if $opt !~  m/^net(\d)+$/;
> > > +		    my $interface = $1;
> > > +		    PVE::Network::tap_unplug("tap${vmid}i${interface}");
> > 
> > I thought they disappear anyway and this was supposed to clean up
> > firewall bridges?
> > 
> 
> this is the same cleanup we call in the tap downscript
> it is a simple call which does all the necessary things :)

ah sorry, was too caught up in the naming, tap_unplug() does call
cleanup_firewall_bridge() indeed...
my bad




More information about the pve-devel mailing list