use PVE::INotify;
use PVE::JSONSchema qw(get_standard_option);
use PVE::Tools;
-use PVE::ReplicationTools;
use base qw(PVE::AbstractConfig);
description => 'Enable user quotas inside the container (not supported with zfs subvolumes)',
optional => 1,
},
- replica => {
+ replicate => {
type => 'boolean',
description => 'Will include this volume to a storage replica job.',
optional => 1,
type => 'integer',
minimum => 0,
},
- replica => {
- optional => 1,
- description => "Storage replica for local storage.",
- type => 'boolean',
- default => 0,
- },
- replica_rate_limit => {
- optional => 1,
- description => "Storage replica rate limit in KBytes/s.",
- type => 'integer',
- minimum => 1,
- },
- replica_target => {
- optional => 1,
- description => "Storage replica target node.",
- type => 'string',
- },
- replica_interval => {
- optional => 1,
- description => "Storage replica sync interval.",
- type => 'integer',
- minimum => 1,
- maximum => 1440,
- default => 15,
- },
cmode => {
optional => 1,
description => "Console mode. By default, the console command tries to open a connection to one of the available tty devices. By setting cmode to 'console' it tries to attach to /dev/console instead. If you set cmode to 'shell', it simply invokes a shell inside the container (no login).",
}
} elsif ($opt eq 'unprivileged') {
die "unable to delete read-only option: '$opt'\n";
- } elsif ($opt eq "replica" || $opt eq "replica_target") {
- delete $conf->{$opt};
- delete $conf->{replica} if $opt eq "replica_target";
-
- # job_remove required updated lxc conf
- PVE::LXC::Config->write_config($vmid, $conf);
- PVE::ReplicationTools::job_remove($vmid);
- next;
- } elsif ($opt eq "replica_interval" || $opt eq "replica_rate_limit") {
- delete $conf->{$opt};
- PVE::LXC::Config->write_config($vmid, $conf);
- PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt});
} else {
die "implement me (delete: $opt)"
}
PVE::LXC::Config->write_config($vmid, $conf) if $running;
}
+ my $storecfg = PVE::Storage::config();
+
my $used_volids = {};
my $check_content_type = sub {
my ($mp) = @_;
my $sid = PVE::Storage::parse_volume_id($mp->{volume});
- my $scfg = PVE::Storage::config();
- my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+ my $storage_config = PVE::Storage::storage_config($storecfg, $sid);
die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
if !$storage_config->{content}->{rootdir};
};
foreach my $opt (keys %$param) {
my $value = $param->{$opt};
my $check_protection_msg = "can't update CT $vmid drive '$opt'";
- my $update;
if ($opt eq 'hostname' || $opt eq 'arch') {
$conf->{$opt} = $value;
} elsif ($opt eq 'onboot') {
} elsif ($opt eq 'ostype') {
next if $hotplug_error->($opt);
$conf->{$opt} = $value;
- } elsif ($opt eq "replica") {
- die "Not all volumes are syncable, please check your config\n"
- if !PVE::ReplicationTools::check_guest_volumes_syncable($conf, 'lxc');
- $conf->{$opt} = $param->{$opt};
- die "replica_target is required\n" if !$conf->{replica_target}
- && !$param->{replica_target};
- $update = 1;
- } elsif ($opt eq "replica_interval" || $opt eq "replica_rate_limit") {
- $conf->{$opt} = $param->{$opt};
- PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt});
- $update = 1;
- } elsif ($opt eq "replica_target") {
- die "Node: $param->{$opt} does not exists in Cluster.\n"
- if !PVE::Cluster::check_node_exists($param->{$opt});
- $update = 1;
- PVE::ReplicationTools::update_conf($vmid, $opt, $param->{$opt})
- if defined($conf->{$opt});
- $conf->{$opt} = $param->{$opt};
} else {
die "implement me: $opt";
}
- PVE::LXC::Config->write_config($vmid, $conf) if $running || $update;
- }
- if (defined($param->{replica})) {
- if ($param->{replica}) {
- PVE::ReplicationTools::job_enable($vmid);
- } else {
- PVE::ReplicationTools::job_disable($vmid);
- }
+ PVE::LXC::Config->write_config($vmid, $conf) if $running;
}
# Apply deletions and creations of new volumes
return $vollist;
}
-return 1;
+sub get_replicatable_volumes {
+ my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
+
+ my $volhash = {};
+
+ my $test_volid = sub {
+ my ($volid, $mountpoint) = @_;
+
+ return if !$volid;
+
+ my $mptype = $mountpoint->{type};
+ die "unable to replicate mountpoint type '$mptype'\n"
+ if $mptype ne 'volume';
+
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($volid, $noerr);
+ return if !$storeid;
+
+ my $scfg = PVE::Storage::storage_config($storecfg, $storeid);
+ return if $scfg->{shared};
+
+ my ($path, $owner, $vtype) = PVE::Storage::path($storecfg, $volid);
+ return if !$owner || ($owner != $vmid);
+
+ die "unable to replicate volume '$volid', type '$vtype'\n" if $vtype ne 'images';
+
+ return if !$cleanup && defined($mountpoint->{replicate}) && !$mountpoint->{replicate};
+
+ if (!PVE::Storage::volume_has_feature($storecfg, 'replicate', $volid)) {
+ return if $cleanup || $noerr;
+ die "missing replicate feature on volume '$volid'\n";
+ }
+
+ $volhash->{$volid} = 1;
+ };
+
+ $class->foreach_mountpoint($conf, sub {
+ my ($ms, $mountpoint) = @_;
+ $test_volid->($mountpoint->{volume}, $mountpoint);
+ });
+
+ foreach my $snapname (keys %{$conf->{snapshots}}) {
+ my $snap = $conf->{snapshots}->{$snapname};
+ $class->foreach_mountpoint($snap, sub {
+ my ($ms, $mountpoint) = @_;
+ $test_volid->($mountpoint->{volume}, $mountpoint);
+ });
+ }
+
+ # add 'unusedX' volumes to volhash
+ foreach my $key (keys %$conf) {
+ if ($key =~ m/^unused/) {
+ $test_volid->($conf->{$key}, { type => 'volume', replicate => 1 });
+ }
+ }
+
+ return $volhash;
+}
+
+1;