]> git.proxmox.com Git - pve-container.git/commitdiff
Use parse_volume instead of parse_ct-variants
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 8 Apr 2020 09:24:58 +0000 (11:24 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 8 Apr 2020 20:44:12 +0000 (22:44 +0200)
Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
src/PVE/API2/LXC.pm
src/PVE/CLI/pct.pm
src/PVE/LXC.pm
src/PVE/LXC/Config.pm

index 58f38f88cbb801fb5a6c59fc2756c4359aadf490..3a8694a0e744a9b3882ccdcaa52b30dfc8b9f3ea 100644 (file)
@@ -1391,9 +1391,7 @@ __PACKAGE__->register_method({
                    my $value = $src_conf->{$opt};
 
                    if (($opt eq 'rootfs') || ($opt =~ m/^mp\d+$/)) {
-                       my $mp = $opt eq 'rootfs' ?
-                           PVE::LXC::Config->parse_ct_rootfs($value) :
-                           PVE::LXC::Config->parse_ct_mountpoint($value);
+                       my $mp = PVE::LXC::Config->parse_volume($opt, $value);
 
                        if ($mp->{type} eq 'volume') {
                            my $volid = $mp->{volume};
@@ -1623,8 +1621,7 @@ __PACKAGE__->register_method({
            my $running = PVE::LXC::check_running($vmid);
 
            my $disk = $param->{disk};
-           my $mp = $disk eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($conf->{$disk}) :
-               PVE::LXC::Config->parse_ct_mountpoint($conf->{$disk});
+           my $mp = PVE::LXC::Config->parse_volume($disk, $conf->{$disk});
 
            my $volid = $mp->{volume};
 
@@ -1786,13 +1783,7 @@ __PACKAGE__->register_method({
 
            die "cannot move volumes of a running container\n" if PVE::LXC::check_running($vmid);
 
-           if ($mpkey eq 'rootfs') {
-               $mpdata = PVE::LXC::Config->parse_ct_rootfs($conf->{$mpkey});
-           } elsif ($mpkey =~ m/mp\d+/) {
-               $mpdata = PVE::LXC::Config->parse_ct_mountpoint($conf->{$mpkey});
-           } else {
-               die "Can't parse $mpkey\n";
-           }
+           PVE::LXC::Config->parse_volume($mpkey, $conf->{$mpkey});
            $old_volid = $mpdata->{volume};
 
            die "you can't move a volume with snapshots and delete the source\n"
index 33f564fd0ffb71c1a77c81808eae235ac7d4c199..54bd7a7bc222be376ac47912034fa2fc45686ee2 100755 (executable)
@@ -233,8 +233,7 @@ __PACKAGE__->register_method ({
 
            defined($conf->{$device}) || die "cannot run command on non-existing mount point $device\n";
 
-           my $mount_point = $device eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($conf->{$device}) :
-               PVE::LXC::Config->parse_ct_mountpoint($conf->{$device});
+           my $mount_point = PVE::LXC::Config->parse_volume($device, $conf->{$device});
 
            die "cannot run fsck when container is running\n"
                if PVE::LXC::check_running($vmid);
index 06524ef6547af357404074aa3947cc956695db05..9adb36649f21b26b2d11a0d0a56ba3d4ac5857d7 100644 (file)
@@ -206,7 +206,7 @@ sub vmstatus {
            $d->{disk} = 0;
            # use 4GB by default ??
            if (my $rootfs = $conf->{rootfs}) {
-               my $rootinfo = PVE::LXC::Config->parse_ct_rootfs($rootfs);
+               my $rootinfo = PVE::LXC::Config->parse_volume('rootfs', $rootfs);
                $d->{maxdisk} = $rootinfo->{size} || (4*1024*1024*1024);
            } else {
                $d->{maxdisk} = 4*1024*1024*1024;
@@ -687,7 +687,7 @@ sub update_lxc_config {
     die "missing 'rootfs' configuration\n"
        if !defined($conf->{rootfs});
 
-    my $mountpoint = PVE::LXC::Config->parse_ct_rootfs($conf->{rootfs});
+    my $mountpoint = PVE::LXC::Config->parse_volume('rootfs', $conf->{rootfs});
 
     $raw .= "lxc.rootfs.path = $dir/rootfs\n";
 
@@ -1199,8 +1199,7 @@ sub check_ct_modify_config_perm {
        } elsif ($opt eq 'rootfs' || $opt =~ /^mp\d+$/) {
            $rpcenv->check_vm_perm($authuser, $vmid, $pool, ['VM.Config.Disk']);
            return if $delete;
-           my $data = $opt eq 'rootfs' ? PVE::LXC::Config->parse_ct_rootfs($newconf->{$opt})
-                                       : PVE::LXC::Config->parse_ct_mountpoint($newconf->{$opt});
+           my $data = PVE::LXC::Config->parse_volume($opt, $newconf->{$opt});
            raise_perm_exc("mount point type $data->{type} is only allowed for root\@pam")
                if $data->{type} ne 'volume';
        } elsif ($opt eq 'memory' || $opt eq 'swap') {
index e613e78e0a3a6cdbc68855f965ad4f3bd7f1eccc..e7fe99b57a2063292eb0dd79ef0a63351cb585d2 100644 (file)
@@ -129,7 +129,7 @@ sub __snapshot_delete_remove_drive {
        die "implement me - saving vmstate\n";
     } else {
        my $value = $snap->{$remove_drive};
-       my $mountpoint = $remove_drive eq 'rootfs' ? $class->parse_ct_rootfs($value, 1) : $class->parse_ct_mountpoint($value, 1);
+       my $mountpoint = $class->parse_volume($remove_drive, $value, 1);
        delete $snap->{$remove_drive};
 
        $class->add_unused_volume($snap, $mountpoint->{volume})
@@ -956,7 +956,7 @@ sub update_pct_config {
        my $value = $param->{$opt};
        if ($opt =~ m/^mp(\d+)$/ || $opt eq 'rootfs') {
            $class->check_protection($conf, "can't update CT $vmid drive '$opt'");
-           my $mp = $opt eq 'rootfs' ? $class->parse_ct_rootfs($value) : $class->parse_ct_mountpoint($value);
+           my $mp = $class->parse_volume($opt, $value);
            $check_content_type->($mp) if ($mp->{type} eq 'volume');
        } elsif ($opt eq 'hookscript') {
            PVE::GuestHelpers::check_hookscript($value);
@@ -1059,22 +1059,6 @@ sub __parse_ct_mountpoint_full {
     return $res;
 };
 
-sub parse_ct_rootfs {
-    my ($class, $data, $noerr) = @_;
-
-    my $res =  $class->__parse_ct_mountpoint_full($rootfs_desc, $data, $noerr);
-
-    $res->{mp} = '/' if defined($res);
-
-    return $res;
-}
-
-sub parse_ct_mountpoint {
-    my ($class, $data, $noerr) = @_;
-
-    return $class->__parse_ct_mountpoint_full($mp_desc, $data, $noerr);
-}
-
 sub print_ct_mountpoint {
     my ($class, $info, $nomp) = @_;
     my $skip = [ 'type' ];
@@ -1086,9 +1070,11 @@ sub parse_volume {
     my ($class, $key, $volume_string, $noerr) = @_;
 
     if ($key eq 'rootfs') {
-       return $class->parse_ct_rootfs($volume_string, $noerr);
+       my $res =  $class->__parse_ct_mountpoint_full($rootfs_desc, $volume_string, $noerr);
+       $res->{mp} = '/' if defined($res);
+       return $res;
     } elsif ($key =~ m/^mp\d+$/ || $key =~ m/^unused\d+$/) {
-       return $class->parse_ct_mountpoint($volume_string, $noerr);
+       return $class->__parse_ct_mountpoint_full($mp_desc, $volume_string, $noerr);
     }
 
     die "parse_volume - unknown type: $key\n";
@@ -1282,7 +1268,7 @@ sub vmconfig_apply_pending {
        next if $selection && !$selection->{$opt};
        eval {
            if ($opt =~ m/^mp(\d+)$/) {
-               my $mp = $class->parse_ct_mountpoint($conf->{$opt});
+               my $mp = $class->parse_volume($opt, $conf->{$opt});
                if ($mp->{type} eq 'volume') {
                    $class->add_unused_volume($conf, $mp->{volume})
                        if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
@@ -1335,7 +1321,7 @@ my $rescan_volume = sub {
 sub apply_pending_mountpoint {
     my ($class, $vmid, $conf, $opt, $storecfg, $running) = @_;
 
-    my $mp = $class->parse_ct_mountpoint($conf->{pending}->{$opt});
+    my $mp = $class->parse_volume($opt, $conf->{pending}->{$opt});
     my $old = $conf->{$opt};
     if ($mp->{type} eq 'volume') {
        if ($mp->{volume} =~ $PVE::LXC::NEW_DISK_RE) {
@@ -1349,7 +1335,7 @@ sub apply_pending_mountpoint {
            );
            if ($running) {
                # Re-parse mount point:
-               my $mp = $class->parse_ct_mountpoint($conf->{pending}->{$opt});
+               my $mp = $class->parse_volume($opt, $conf->{pending}->{$opt});
                eval {
                    PVE::LXC::mountpoint_hotplug($vmid, $conf, $opt, $mp, $storecfg);
                };
@@ -1374,7 +1360,7 @@ sub apply_pending_mountpoint {
     }
 
     if (defined($old)) {
-       my $mp = $class->parse_ct_mountpoint($old);
+       my $mp = $class->parse_volume($opt, $old);
        if ($mp->{type} eq 'volume') {
            $class->add_unused_volume($conf, $mp->{volume})
                if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);