[pve-devel] renaming of disks at cloning VM (patch)

pve at spichka.info pve at spichka.info
Thu Jul 21 14:26:16 CEST 2016


Hello!

Testing:
qemu-server: 4.0-85

Problem:
#qm clone 106 117 -storage local -full
create full clone of drive ide1 (iso:106/vm-106-disk-1.qcow2)
Formatting '/var/lib/vz/images/117/vm-117-disk-2.qcow2', fmt=qcow2 size=1073664 encryption=off cluster_size=65536 preallocation=metadata lazy_refcounts=off refcount_bits=16
transferred: 0 bytes remaining: 1073664 bytes total: 1073664 bytes progression: 0.00 %
transferred: 1073664 bytes remaining: 0 bytes total: 1073664 bytes progression: 100.00 %
transferred: 1073664 bytes remaining: 0 bytes total: 1073664 bytes progression: 100.00 %


was:disk-1 -> became:disk-2

I use VM with an identical configuration. There is a wish 
to have identical names of disks.

Patch sketch:

added parameter: -oldnamedisk (qm clone 106 117 -storage local -full -oldnamedisk)

--- /usr/share/perl5/PVE/API2/Qemu.pm.bak       2016-07-20 22:13:00.851780111 +0300
+++ /usr/share/perl5/PVE/API2/Qemu.pm   2016-07-20 22:07:27.626444295 +0300
@@ -2203,6 +2203,12 @@
                    "you clone a normal VM. For VM templates, we try to create a linked clone by default.",
                default => 0,
            },
+           oldnamedisk => {
+               optional => 1,
+               type => 'boolean',
+               description => "Old name disk",
+               default => 0,
+           },
            target => get_standard_option('pve-node', {
                description => "Target node. Only allowed if the original VM is on shared storage.",
                optional => 1,
@@ -2378,7 +2384,8 @@
                        my $drive = $drives->{$opt};
 
                        my $newdrive = PVE::QemuServer::clone_disk($storecfg, $vmid, $running, $opt, $drive, $snapname,
-                                                                  $newid, $storage, $format, $fullclone->{$opt}, $newvollist);
+                                                                  $newid, $storage, $format, $fullclone->{$opt}, 
+                                                                  $param->{oldnamedisk}, $newvollist);
 
                        $newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $newdrive);
 
@@ -2547,7 +2554,7 @@
                        if $snapshotted;
 
                    my $newdrive = PVE::QemuServer::clone_disk($storecfg, $vmid, $running, $disk, $drive, undef,
-                                                              $vmid, $storeid, $format, 1, $newvollist);
+                                                              $vmid, $storeid, $format, 1, 0, $newvollist);
 
                    $conf->{$disk} = PVE::QemuServer::print_drive($vmid, $newdrive);


--- /usr/share/perl5/PVE/QemuServer.pm.bak      2016-07-20 21:16:30.858244179 +0300
+++ /usr/share/perl5/PVE/QemuServer.pm  2016-07-20 22:18:10.961023340 +0300
@@ -5722,7 +5722,7 @@
 
 sub clone_disk {
     my ($storecfg, $vmid, $running, $drivename, $drive, $snapname,
-       $newvmid, $storage, $format, $full, $newvollist) = @_;
+       $newvmid, $storage, $format, $full, $oldnamedisk, $newvollist) = @_;
 
     my $newvolid;
 
@@ -5748,7 +5748,12 @@
 
        print "create full clone of drive $drivename ($drive->{file})\n";
 
-       $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $format, undef, ($size/1024));
+       my $name = undef;
+       if ($oldnamedisk && $drive->{file} =~ /(vm|base)-\d+-disk-(\d+)/){
+               $name = "$1-$newvmid-disk-$2.$format";
+       }
+
+       $newvolid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $newvmid, $format, $name, ($size/1024));
        push @$newvollist, $newvolid;
 
        PVE::Storage::activate_volumes($storecfg, $newvollist);


It is possible to consider this patch?
Excuse my poor English.

-- 
Чт. июля 21 20:16:32 IRKT 2016
------------------------
С уважением, Vladimir Galaichuk



More information about the pve-devel mailing list