On 08/21/2015 05:10 PM, Alexandre Derumier wrote:
Signed-off-by: Alexandre Derumier <aderum...@odiso.com>
---
src/PVE/LXC/Create.pm | 131 +++++++++++---------------------------------------
1 file changed, 29 insertions(+), 102 deletions(-)
@@ -279,30 +199,37 @@ sub create_rootfs {
PVE::LXC::create_config($vmid, $conf);
}
- my ($vtype, undef, undef, undef, undef, $isBase, $format) =
- PVE::Storage::parse_volname($storage_cfg, $volid);
-
- die "got strange vtype '$vtype'\n" if $vtype ne 'images';
-
- die "unable to install into base volume" if $isBase;
-
- if ($format eq 'subvol') {
- create_rootfs_subvol($storage_cfg, $storage, $volid, $vmid, $conf,
$archive, $password, $restore);
- } elsif ($format eq 'raw') {
- my $scfg = PVE::Storage::storage_config($storage_cfg, $storage);
- PVE::Storage::activate_storage($storage_cfg, $storage);
- PVE::Storage::activate_volumes($storage_cfg, [$volid]);
- if ($scfg->{path}) {
- create_rootfs_dir_loop($storage_cfg, $storage, $volid, $vmid,
$conf, $archive, $password, $restore);
- } elsif ($scfg->{type} eq 'drbd' || $scfg->{type} eq 'rbd') {
- create_rootfs_dev($storage_cfg, $storage, $volid, $vmid, $conf,
$archive, $password, $restore);
- } else {
- die "unable to create containers on storage type '$scfg->{type}'\n";
+ my $image_path = PVE::Storage::path($storage_cfg, $volid);
+ my $mountpoint_path = "/var/lib/lxc/$vmid/rootfs";
+ my $mountpoint = { volume => $volid, mp => "/" };
+ my $ms = "rootfs";
+
+ eval {
+ PVE::Storage::activate_volumes($storage_cfg, [$volid]);
+ my $loopdevs = PVE::LXC::attach_loops($storage_cfg, [$volid]);
+
+ if (!-d $image_path) {
+ my $cmd = ['mkfs.ext4', $image_path];
+ PVE::Tools::run_command($cmd);
}
- PVE::Storage::deactivate_volumes($storage_cfg, [$volid]);
- } else {
- die "unsupported image format '$format'\n";
+
+ PVE::LXC::mountpoint_mount($ms, $mountpoint, $mountpoint_path,
$storage_cfg, $loopdevs);
+
+ restore_and_configure($vmid, $archive, $mountpoint_path, $conf,
$password, $restore);
+ };
+ if (my $err = $@) {
+ eval {
+ PVE::LXC::dettach_loops($storage_cfg, [$volid]);
+ PVE::Storage::deactivate_volumes($storage_cfg, [$volid]);
+ };
+ warn $@ if $@;
+ die $err;
}
+
+ PVE::Tools::run_command(['umount', '-l', '-d', $mountpoint_path]);
I wonder if that unmount everything (mountpoints below /)?
_______________________________________________
pve-devel mailing list
pve-devel@pve.proxmox.com
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel