]> git.proxmox.com Git - pve-container.git/commitdiff
Check content type when adding/updating volumes
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 16 Mar 2016 09:14:00 +0000 (10:14 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 16 Mar 2016 09:29:07 +0000 (10:29 +0100)
the non-'rootdir' storages are filtered out in the web
interface already, but using the API/CLI it was still
possible to add volumes on storages without the 'rootdir'
content type.

this check is only used for mountpoints using our storage
backends, bind/dev mounts still work like before.

src/PVE/LXC/Config.pm

index 7c451ba851dcfffa02ed736f05a47fc278e5e6be..6519852a79bdd381683f2ec7ff16d88559791291 100644 (file)
@@ -848,6 +848,15 @@ sub update_pct_config {
            next if $hotplug_error->($opt);
            PVE::LXC::Config->check_protection($conf, $check_protection_msg);
            my $old = $conf->{$opt};
+           my $mp = PVE::LXC::Config->parse_ct_mountpoint($value);
+           if ($mp->{type} eq 'volume') {
+               my $sid = PVE::Storage::parse_volume_id($mp->{volume});
+               my $scfg = PVE::Storage::config();
+               my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+               die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
+                   if !$storage_config->{content}->{rootdir};
+               $used_volids->{$mp->{volume}} = 1;
+           }
            $conf->{$opt} = $value;
            if (defined($old)) {
                my $mp = PVE::LXC::Config->parse_ct_mountpoint($old);
@@ -856,21 +865,26 @@ sub update_pct_config {
                }
            }
            $new_disks = 1;
-           my $mp = PVE::LXC::Config->parse_ct_mountpoint($value);
-           $used_volids->{$mp->{volume}} = 1;
        } elsif ($opt eq 'rootfs') {
            next if $hotplug_error->($opt);
            PVE::LXC::Config->check_protection($conf, $check_protection_msg);
            my $old = $conf->{$opt};
            $conf->{$opt} = $value;
+           my $mp = PVE::LXC::Config->parse_ct_rootfs($value);
+           if ($mp->{type} eq 'volume') {
+               my $sid = PVE::Storage::parse_volume_id($mp->{volume});
+               my $scfg = PVE::Storage::config();
+               my $storage_config = PVE::Storage::storage_config($scfg, $sid);
+               die "storage '$sid' does not allow content type 'rootdir' (Container)\n"
+                   if !$storage_config->{content}->{rootdir};
+               $used_volids->{$mp->{volume}} = 1;
+           }
            if (defined($old)) {
                my $mp = PVE::LXC::Config->parse_ct_rootfs($old);
                if ($mp->{type} eq 'volume') {
                    PVE::LXC::Config->add_unused_volume($conf, $mp->{volume});
                }
            }
-           my $mp = PVE::LXC::Config->parse_ct_rootfs($value);
-           $used_volids->{$mp->{volume}} = 1;
        } elsif ($opt eq 'unprivileged') {
            die "unable to modify read-only option: '$opt'\n";
        } elsif ($opt eq 'ostype') {