To avoid having to use the ^/ and ^/dev/ regexes which are
easy to forget about there's now a 'type' property on
mountpoints which classify them via names, for now including
"volume", "bind" and "device".
+sub classify_mountpoint {
+ my ($vol) = @_;
+ if ($vol =~ m!^/!) {
+ return 'device' if $vol =~ m!^/dev/!;
+ return 'bind';
+ }
+ return 'volume';
+}
+
sub parse_ct_mountpoint {
my ($data, $noerr) = @_;
sub parse_ct_mountpoint {
my ($data, $noerr) = @_;
+ $res->{type} = classify_mountpoint($res->{volume});
+
return $res;
}
sub print_ct_mountpoint {
my ($info, $nomp) = @_;
return $res;
}
sub print_ct_mountpoint {
my ($info, $nomp) = @_;
- my $skip = $nomp ? ['mp'] : [];
+ my $skip = [ 'type' ];
+ push @$skip, 'mp' if $nomp;
return PVE::JSONSchema::print_property_string($info, $mp_desc, $skip);
}
return PVE::JSONSchema::print_property_string($info, $mp_desc, $skip);
}
sub add_unused_volume {
my ($config, $volid) = @_;
sub add_unused_volume {
my ($config, $volid) = @_;
- # skip bind mounts and block devices
- return if $volid =~ m|^/|;
-
my $key;
for (my $ind = $MAX_UNUSED_DISKS - 1; $ind >= 0; $ind--) {
my $test = "unused$ind";
my $key;
for (my $ind = $MAX_UNUSED_DISKS - 1; $ind >= 0; $ind--) {
my $test = "unused$ind";
next if $hotplug_error->($opt);
check_protection($conf, "can't remove CT $vmid drive '$opt'");
my $mountpoint = parse_ct_mountpoint($conf->{$opt});
next if $hotplug_error->($opt);
check_protection($conf, "can't remove CT $vmid drive '$opt'");
my $mountpoint = parse_ct_mountpoint($conf->{$opt});
- add_unused_volume($conf, $mountpoint->{volume});
+ if ($mountpoint->{type} eq 'volume') {
+ add_unused_volume($conf, $mountpoint->{volume})
+ }
delete $conf->{$opt};
} elsif ($opt eq 'unprivileged') {
die "unable to delete read-only option: '$opt'\n";
delete $conf->{$opt};
} elsif ($opt eq 'unprivileged') {
die "unable to delete read-only option: '$opt'\n";
sub delete_mountpoint_volume {
my ($storage_cfg, $vmid, $volume) = @_;
sub delete_mountpoint_volume {
my ($storage_cfg, $vmid, $volume) = @_;
- # skip bind mounts and block devices
- if ($volume =~ m|^/|) {
- return;
- }
+ return if classify_mountpoint($volume) ne 'volume';
my ($vtype, $name, $owner) = PVE::Storage::parse_volname($storage_cfg, $volume);
PVE::Storage::vdisk_free($storage_cfg, $volume) if $vmid == $owner;
my ($vtype, $name, $owner) = PVE::Storage::parse_volname($storage_cfg, $volume);
PVE::Storage::vdisk_free($storage_cfg, $volume) if $vmid == $owner;
my $volid = $mountpoint->{volume};
my $mount = $mountpoint->{mp};
my $volid = $mountpoint->{volume};
my $mount = $mountpoint->{mp};
+ my $type = $mountpoint->{type};
return if !$volid || !$mount;
return if !$volid || !$mount;
} else {
die "unsupported image format '$format'\n";
}
} else {
die "unsupported image format '$format'\n";
}
- } elsif ($volid =~ m|^/dev/.+|) {
+ } elsif ($type eq 'device') {
PVE::Tools::run_command(['mount', $volid, $mount_path]) if $mount_path;
return wantarray ? ($volid, 0) : $volid;
PVE::Tools::run_command(['mount', $volid, $mount_path]) if $mount_path;
return wantarray ? ($volid, 0) : $volid;
- } elsif ($volid !~ m|^/dev/.+| && $volid =~ m|^/.+| && -d $volid) {
+ } elsif ($type eq 'bind' && -d $volid) {
&$check_mount_path($volid);
PVE::Tools::run_command(['mount', '-o', 'bind', $volid, $mount_path]) if $mount_path;
return wantarray ? ($volid, 0) : $volid;
&$check_mount_path($volid);
PVE::Tools::run_command(['mount', '-o', 'bind', $volid, $mount_path]) if $mount_path;
return wantarray ? ($volid, 0) : $volid;
my $volid = $mountpoint->{volume};
my $volid = $mountpoint->{volume};
- return if !$volid || $volid =~ m|^/|;
+ return if !$volid || $mountpoint->{type} ne 'volume';
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
return if !$sid;
my ($sid, $volname) = PVE::Storage::parse_volume_id($volid, 1);
return if !$sid;
my ($name, $data) = @_;
my $volid = $data->{volume};
my $mount = $data->{mp};
my ($name, $data) = @_;
my $volid = $data->{volume};
my $mount = $data->{mp};
+ my $type = $data->{type};
- return if !$volid || !$mount || $volid =~ m|^/|;
+ return if !$volid || !$mount || $type ne 'volume';
if ($name ne 'rootfs' && !$data->{backup}) {
push @$exclude_dirs, $mount;
if ($name ne 'rootfs' && !$data->{backup}) {
push @$exclude_dirs, $mount;