[pve-devel] [PATCH 1/2] move clone disk code to clone_disks sub
Alexandre Derumier
aderumier at odiso.com
Mon May 27 06:22:04 CEST 2013
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/API2/Qemu.pm | 103 +++++++++++++++++++++++++++++-------------------------
1 file changed, 55 insertions(+), 48 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 61282d5..4c5feb8 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -171,6 +171,59 @@ my $create_disks = sub {
return $vollist;
};
+my $clone_disks = sub {
+ my ($storecfg, $storage, $vollist, $newvollist, $drives, $snapname, $format, $vmid, $newid, $newconf, $running) = @_;
+
+ PVE::Storage::activate_volumes($storecfg, $vollist);
+
+ foreach my $opt (keys %$drives) {
+ my $drive = $drives->{$opt};
+
+ my $newvolid;
+ if (!$drive->{full}) {
+ print "create linked clone of drive $opt ($drive->{file})\n";
+ $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newid);
+ push @$newvollist, $newvolid;
+
+ } else {
+ my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
+ $storeid = $storage if $storage;
+
+ my $fmt = undef;
+ if($format){
+ $fmt = $format;
+ }else{
+ my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
+ $fmt = $drive->{format} || $defformat;
+ }
+
+ my ($size) = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 3);
+
+ print "create full clone of drive $opt ($drive->{file})\n";
+ $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newid, $fmt, undef, ($size/1024));
+ push @$newvollist, $newvolid;
+
+ if(!$running || $snapname){
+ PVE::QemuServer::qemu_img_convert($drive->{file}, $newvolid, $size, $snapname);
+ }else{
+ PVE::QemuServer::qemu_drive_mirror($vmid, $opt, $newvolid, $newid);
+ }
+ }
+
+ my ($size) = PVE::Storage::volume_size_info($storecfg, $newvolid, 3);
+ my $disk = $drive;
+ $disk->{full} = undef;
+ $disk->{format} = undef;
+ $disk->{file} = $newvolid;
+ $disk->{size} = $size;
+
+ $newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $disk);
+
+ PVE::QemuServer::update_config_nolock($newid, $newconf, 1);
+ }
+
+};
+
my $check_vm_modify_config_perm = sub {
my ($rpcenv, $authuser, $vmid, $pool, $key_list) = @_;
@@ -2001,6 +2054,7 @@ __PACKAGE__->register_method({
PVE::Tools::file_set_contents($conffile, "# qmclone temporary file\nlock: clone\n");
my $realcmd = sub {
+
my $upid = shift;
my $newvollist = [];
@@ -2008,54 +2062,7 @@ __PACKAGE__->register_method({
eval {
local $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub { die "interrupted by signal\n"; };
- PVE::Storage::activate_volumes($storecfg, $vollist);
-
- foreach my $opt (keys %$drives) {
- my $drive = $drives->{$opt};
-
- my $newvolid;
- if (!$drive->{full}) {
- print "create linked clone of drive $opt ($drive->{file})\n";
- $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newid);
- push @$newvollist, $newvolid;
-
- } else {
- my ($storeid, $volname) = PVE::Storage::parse_volume_id($drive->{file});
- $storeid = $storage if $storage;
-
- my $fmt = undef;
- if($format){
- $fmt = $format;
- }else{
- my $defformat = PVE::Storage::storage_default_format($storecfg, $storeid);
- $fmt = $drive->{format} || $defformat;
- }
-
- my ($size) = PVE::Storage::volume_size_info($storecfg, $drive->{file}, 3);
-
- print "create full clone of drive $opt ($drive->{file})\n";
- $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newid, $fmt, undef, ($size/1024));
- push @$newvollist, $newvolid;
-
- if(!$running || $snapname){
- PVE::QemuServer::qemu_img_convert($drive->{file}, $newvolid, $size, $snapname);
- }else{
- PVE::QemuServer::qemu_drive_mirror($vmid, $opt, $newvolid, $newid);
- }
-
- }
-
- my ($size) = PVE::Storage::volume_size_info($storecfg, $newvolid, 3);
- my $disk = $drive;
- $disk->{full} = undef;
- $disk->{format} = undef;
- $disk->{file} = $newvolid;
- $disk->{size} = $size;
-
- $newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $disk);
-
- PVE::QemuServer::update_config_nolock($newid, $newconf, 1);
- }
+ &$clone_disks($storecfg, $storage, $vollist, $newvollist, $drives, $snapname, $format, $vmid, $newid, $newconf, $running);
delete $newconf->{lock};
PVE::QemuServer::update_config_nolock($newid, $newconf, 1);
--
1.7.10.4
More information about the pve-devel
mailing list