sub lock_vm {
my ($self, $vmid, $code, @param) = @_;
- return PVE::LXC::lock_container($vmid, undef, $code, @param);
+ return PVE::LXC::Config->lock_config($vmid, $code, @param);
}
sub prepare {
$self->{storecfg} = PVE::Storage::config();
- # test is VM exist
- my $conf = $self->{vmconf} = PVE::LXC::load_config($vmid);
+ # test if CT exists
+ my $conf = $self->{vmconf} = PVE::LXC::Config->load_config($vmid);
- PVE::LXC::check_lock($conf);
+ PVE::LXC::Config->check_lock($conf);
my $running = 0;
if (PVE::LXC::check_running($vmid)) {
die "lxc live migration is currently not implemented\n";
- die "cant migrate running container without --online\n" if !$online;
+ die "can't migrate running container without --online\n" if !$online;
$running = 1;
}
- PVE::LXC::foreach_mountpoint($conf, sub {
+ my $force = $self->{opts}->{force} // 0;
+ my $need_activate = [];
+
+ PVE::LXC::Config->foreach_mountpoint($conf, sub {
my ($ms, $mountpoint) = @_;
my $volid = $mountpoint->{volume};
+
+ # skip dev/bind mps when forced
+ if ($mountpoint->{type} ne 'volume' && $force) {
+ return;
+ }
my ($storage, $volname) = PVE::Storage::parse_volume_id($volid, 1) if $volid;
die "can't determine assigned storage for mountpoint '$ms'\n" if !$storage;
my $scfg = PVE::Storage::storage_check_node($self->{storecfg}, $storage);
PVE::Storage::storage_check_node($self->{storecfg}, $storage, $self->{node});
- die "unable to migrate local mountpoint '$volid' while CT is running"
- if !$scfg->{shared} && $running;
+
+ if ($scfg->{shared}) {
+ # PVE::Storage::activate_storage checks this for non-shared storages
+ my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+ warn "Used shared storage '$storage' is not online on source node!\n"
+ if !$plugin->check_connection($storage, $scfg);
+ } else {
+ # only activate if not shared
+ push @$need_activate, $volid;
+
+ die "unable to migrate local mountpoint '$volid' while CT is running"
+ if $running;
+ }
});
- my $volid_list = PVE::LXC::get_vm_volumes($conf);
- PVE::Storage::activate_volumes($self->{storecfg}, $volid_list);
+ PVE::Storage::activate_volumes($self->{storecfg}, $need_activate);
# todo: test if VM uses local resources
my $conf = $self->{vmconf};
$conf->{lock} = 'migrate';
- PVE::LXC::write_config($vmid, $conf);
+ PVE::LXC::Config->write_config($vmid, $conf);
if ($self->{running}) {
$self->log('info', "container is running - using online migration");
$self->{volumes} = [];
- PVE::LXC::foreach_mountpoint($conf, sub {
+ PVE::LXC::Config->foreach_mountpoint($conf, sub {
my ($ms, $mountpoint) = @_;
my $volid = $mountpoint->{volume};
+
+ # already checked in prepare
+ if ($mountpoint->{type} ne 'volume') {
+ $self->log('info', "ignoring mountpoint '$ms' ('$volid') of type " .
+ "'$mountpoint->{type}', migration is forced.");
+ return;
+ }
+
my ($storage, $volname) = PVE::Storage::parse_volume_id($volid);
my $scfg = PVE::Storage::storage_check_node($self->{storecfg}, $storage);
if (!$scfg->{shared}) {
- $self->log('info', "copy mointpoint '$ms' ($volid) to node ' $self->{node}'");
+ $self->log('info', "copy mountpoint '$ms' ($volid) to node ' $self->{node}'");
PVE::Storage::storage_migrate($self->{storecfg}, $volid, $self->{nodeip}, $storage);
push @{$self->{volumes}}, $volid;
} else {
- $self->log('info', "mointpoint '$ms' is on shared storage '$storage'");
+ $self->log('info', "mountpoint '$ms' is on shared storage '$storage'");
}
});
- my $conffile = PVE::LXC::config_file($vmid);
- my $newconffile = PVE::LXC::config_file($vmid, $self->{node});
+ my $conffile = PVE::LXC::Config->config_file($vmid);
+ my $newconffile = PVE::LXC::Config->config_file($vmid, $self->{node});
if ($self->{running}) {
die "implement me";
PVE::LXC::umount_all($vmid, $self->{storecfg}, $conf);
#to be sure there are no active volumes
- my $vollist = PVE::LXC::get_vm_volumes($conf);
+ my $vollist = PVE::LXC::Config->get_vm_volumes($conf);
PVE::Storage::deactivate_volumes($self->{storecfg}, $vollist);
# move config
my $conf = $self->{vmconf};
delete $conf->{lock};
- eval { PVE::LXC::write_config($vmid, $conf); };
+ eval { PVE::LXC::Config->write_config($vmid, $conf); };
if (my $err = $@) {
$self->log('err', $err);
}