[pve-devel] [PATCH 1/4] Add CT suspend/resume support via PVE2 API

Daniel Hunsaker danhunsaker at gmail.com
Sun Oct 5 11:50:13 CEST 2014


I know I'd like to try it.  The potential issue is when migrating between
nodes with different kernel versions/modules/configurations.  It would
probably be useful to detect those cases (as best we can), and either issue
a warning, or automatically switch to an offline migration, shutting down
and starting up before and after migration, respectively.  If such
detection isn't feasible, perhaps online migrations of CTs are something we
shouldn't worry about.  We can only control the environment to a certain
extent.

On the other hand, a failed online migration ought to lead sysadmins to
attempt offline migration before giving up, so maybe we just let the
migration fail and let the sysadmin adapt their course of action
accordingly.  Just some thoughts on it.
On Oct 4, 2014 1:11 AM, "Dietmar Maurer" <dietmar at proxmox.com> wrote:

> Thank for that patch, looks good.
>
> I wonder if we should migrate the saved state when we migrate the
> container?
>
> > -----Original Message-----
> > From: pve-devel [mailto:pve-devel-bounces at pve.proxmox.com] On Behalf Of
> > Daniel Hunsaker
> > Sent: Freitag, 03. Oktober 2014 20:59
> > To: pve-devel at pve.proxmox.com
> > Subject: [pve-devel] [PATCH 1/4] Add CT suspend/resume support via PVE2
> API
> >
> > From: Dan Hunsaker <danhunsaker at gmail.com>
> >
> > Suspend/resume support for VMs has been in the PVE2 API for some time,
> but
> > even though vzctl supports suspend/resume (what they call checkpoint/
> restore),
> > the API doesn't yet support suspend/resume for CTs.  This patch adds that
> > support.
> >
> > Signed-off-by: Dan Hunsaker <danhunsaker at gmail.com>
> > ---
> >  PVE/API2/OpenVZ.pm | 96
> > ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  PVE/OpenVZ.pm      | 26 ++++++++++++++-
> >  2 files changed, 121 insertions(+), 1 deletion(-)
> >
> > diff --git a/PVE/API2/OpenVZ.pm b/PVE/API2/OpenVZ.pm index
> > 184ebdf..5d8c0c6 100644
> > --- a/PVE/API2/OpenVZ.pm
> > +++ b/PVE/API2/OpenVZ.pm
> > @@ -1459,6 +1459,102 @@ __PACKAGE__->register_method({
> >      }});
> >
> >  __PACKAGE__->register_method({
> > +       name => 'vm_suspend',
> > +       path => '{vmid}/status/suspend',
> > +       method => 'POST',
> > +       protected => 1,
> > +       proxyto => 'node',
> > +       description => "Suspend the container.",
> > +       permissions => {
> > +               check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
> > +       },
> > +       parameters => {
> > +               additionalProperties => 0,
> > +               properties => {
> > +                       node => get_standard_option('pve-node'),
> > +                       vmid => get_standard_option('pve-vmid'),
> > +               },
> > +       },
> > +       returns => {
> > +               type => 'string',
> > +       },
> > +       code => sub {
> > +               my ($param) = @_;
> > +
> > +               my $rpcenv = PVE::RPCEnvironment::get();
> > +
> > +               my $authuser = $rpcenv->get_user();
> > +
> > +               my $node = extract_param($param, 'node');
> > +
> > +               my $vmid = extract_param($param, 'vmid');
> > +
> > +               die "CT $vmid not running\n" if
> > + !PVE::OpenVZ::check_running($vmid);
> > +
> > +               my $realcmd = sub {
> > +                       my $upid = shift;
> > +
> > +                       syslog('info', "suspend CT $vmid: $upid\n");
> > +
> > +                       PVE::OpenVZ::vm_suspend($vmid);
> > +
> > +                       return;
> > +               };
> > +
> > +               my $upid = $rpcenv->fork_worker('vzsuspend', $vmid,
> > + $authuser, $realcmd);
> > +
> > +               return $upid;
> > +       }});
> > +
> > +__PACKAGE__->register_method({
> > +       name => 'vm_resume',
> > +       path => '{vmid}/status/resume',
> > +       method => 'POST',
> > +       protected => 1,
> > +       proxyto => 'node',
> > +       description => "Resume the container.",
> > +       permissions => {
> > +               check => ['perm', '/vms/{vmid}', [ 'VM.PowerMgmt' ]],
> > +       },
> > +       parameters => {
> > +               additionalProperties => 0,
> > +               properties => {
> > +                       node => get_standard_option('pve-node'),
> > +                       vmid => get_standard_option('pve-vmid'),
> > +               },
> > +       },
> > +       returns => {
> > +               type => 'string',
> > +       },
> > +       code => sub {
> > +               my ($param) = @_;
> > +
> > +               my $rpcenv = PVE::RPCEnvironment::get();
> > +
> > +               my $authuser = $rpcenv->get_user();
> > +
> > +               my $node = extract_param($param, 'node');
> > +
> > +               my $vmid = extract_param($param, 'vmid');
> > +
> > +               die "CT $vmid already running\n" if
> > + PVE::OpenVZ::check_running($vmid);
> > +
> > +               my $realcmd = sub {
> > +                       my $upid = shift;
> > +
> > +                       syslog('info', "resume CT $vmid: $upid\n");
> > +
> > +                       PVE::OpenVZ::vm_resume($vmid);
> > +
> > +                       return;
> > +               };
> > +
> > +               my $upid = $rpcenv->fork_worker('vzresume', $vmid,
> > + $authuser, $realcmd);
> > +
> > +               return $upid;
> > +       }});
> > +
> > +__PACKAGE__->register_method({
> >      name => 'migrate_vm',
> >      path => '{vmid}/migrate',
> >      method => 'POST',
> > diff --git a/PVE/OpenVZ.pm b/PVE/OpenVZ.pm index aa6f502..fcfb0c2 100644
> > --- a/PVE/OpenVZ.pm
> > +++ b/PVE/OpenVZ.pm
> > @@ -6,7 +6,7 @@ use File::stat qw();
> >  use POSIX qw (LONG_MAX);
> >  use IO::Dir;
> >  use IO::File;
> > -use PVE::Tools qw(extract_param $IPV6RE $IPV4RE);
> > +use PVE::Tools qw(run_command extract_param $IPV6RE $IPV4RE);
> >  use PVE::ProcFSTools;
> >  use PVE::Cluster qw(cfs_register_file cfs_read_file);  use
> PVE::SafeSyslog; @@ -
> > 1220,6 +1220,30 @@ sub lock_container {
> >      return $res;
> >  }
> >
> > +sub vm_suspend {
> > +    my ($vmid) = @_;
> > +
> > +    my $cmd = ['vzctl', 'chkpnt', $vmid];
> > +
> > +    eval { run_command($cmd); };
> > +    if (my $err = $@) {
> > +        syslog("err", "CT $vmid suspend failed - $err");
> > +        die $err;
> > +    }
> > +}
> > +
> > +sub vm_resume {
> > +    my ($vmid) = @_;
> > +
> > +    my $cmd = ['vzctl', 'restore', $vmid];
> > +
> > +    eval { run_command($cmd); };
> > +    if (my $err = $@) {
> > +        syslog("err", "CT $vmid resume failed - $err");
> > +        die $err;
> > +    }
> > +}
> > +
> >  sub replacepw {
> >      my ($file, $epw) = @_;
> >
> > --
> > 1.9.1
> >
> > _______________________________________________
> > pve-devel mailing list
> > pve-devel at pve.proxmox.com
> > http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.proxmox.com/pipermail/pve-devel/attachments/20141005/0583b8e4/attachment.htm>


More information about the pve-devel mailing list