]> git.proxmox.com Git - pve-container.git/commitdiff
Start a worker in lxc resize.
authorWolfgang Link <w.link@proxmox.com>
Wed, 28 Oct 2015 08:40:41 +0000 (09:40 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Wed, 28 Oct 2015 10:23:36 +0000 (11:23 +0100)
It is necessary because if we resize a disk it can take longer. so to prevent long waiting time fork a worker process.

src/PVE/API2/LXC.pm

index 972f6282ca7ac743ffc008b924622c00ea8a820a..ffa3f4c1e9d5284fc4be69987e9969c8258d9ce1 100644 (file)
@@ -941,7 +941,10 @@ __PACKAGE__->register_method({
                }
            }),
     },
-    returns => { type => 'null'},
+    returns => {
+       type => 'string',
+       description => "the task ID.",
+    },
     code => sub {
        my ($param) = @_;
 
@@ -1015,42 +1018,43 @@ __PACKAGE__->register_method({
            return if $size == $newsize;
 
            PVE::Cluster::log_msg('info', $authuser, "update CT $vmid: resize --disk $disk --size $sizestr");
-
-           # FIXME: volume_resize doesn't do anything if $running=1?
-           PVE::Storage::volume_resize($storage_cfg, $volid, $newsize, 0);
-
-           $mp->{size} = $newsize;
-           $conf->{$disk} = PVE::LXC::print_ct_mountpoint($mp, $disk eq 'rootfs');
-
-           PVE::LXC::write_config($vmid, $conf);
-
-           if ($format eq 'raw') {
-               my $path = PVE::Storage::path($storage_cfg, $volid, undef);
-               if ($running) {
-                   $path = &$query_loopdev($path);
-                   die "internal error: CT running but mountpoint not attached to a loop device"
-                       if !$path; # fixme: zvols and other storages?
-                   PVE::Tools::run_command(['losetup', '--set-capacity', $path]);
-
-                   # In order for resize2fs to know that we need online-resizing a mountpoint needs
-                   # to be visible to it in its namespace.
-                   # To not interfere with the rest of the system we unshare the current mount namespace,
-                   # mount over /tmp and then run resize2fs.
-
-                   # interestingly we don't need to e2fsck on mounted systems...
-                   my $quoted = PVE::Tools::shellquote($path);
-                   my $cmd = "mount --make-rprivate / && mount $quoted /tmp && resize2fs $quoted";
-                   PVE::Tools::run_command(['unshare', '-m', '--', 'sh', '-c', $cmd]);
-               } else {
-                   PVE::Tools::run_command(['e2fsck', '-f', '-y', $path]);
-                   PVE::Tools::run_command(['resize2fs', $path]);
+           my $realcmd = sub {
+               # FIXME: volume_resize doesn't do anything if $running=1?
+               PVE::Storage::volume_resize($storage_cfg, $volid, $newsize, 0);
+
+               $mp->{size} = $newsize;
+               $conf->{$disk} = PVE::LXC::print_ct_mountpoint($mp, $disk eq 'rootfs');
+
+               PVE::LXC::write_config($vmid, $conf);
+
+               if ($format eq 'raw') {
+                   my $path = PVE::Storage::path($storage_cfg, $volid, undef);
+                   if ($running) {
+                       $path = &$query_loopdev($path);
+                       die "internal error: CT running but mountpoint not attached to a loop device"
+                           if !$path; # fixme: zvols and other storages?
+                       PVE::Tools::run_command(['losetup', '--set-capacity', $path]);
+
+                       # In order for resize2fs to know that we need online-resizing a mountpoint needs
+                       # to be visible to it in its namespace.
+                       # To not interfere with the rest of the system we unshare the current mount namespace,
+                       # mount over /tmp and then run resize2fs.
+
+                       # interestingly we don't need to e2fsck on mounted systems...
+                       my $quoted = PVE::Tools::shellquote($path);
+                       my $cmd = "mount --make-rprivate / && mount $quoted /tmp && resize2fs $quoted";
+                       PVE::Tools::run_command(['unshare', '-m', '--', 'sh', '-c', $cmd]);
+                   } else {
+                       PVE::Tools::run_command(['e2fsck', '-f', '-y', $path]);
+                       PVE::Tools::run_command(['resize2fs', $path]);
+                   }
                }
-           }
-       };
+           };
 
-       PVE::LXC::lock_container($vmid, undef, $code);
+           return $rpcenv->fork_worker('resize', $vmid, $authuser, $realcmd);
+       };
 
-       return undef;
+       return PVE::LXC::lock_container($vmid, undef, $code);;
     }});
 
 1;