[pve-devel] ceph: clone vm
Alexandre DERUMIER
aderumier at odiso.com
Thu Feb 6 06:20:16 CET 2014
>>it adds snapshot support but not linked clones? or do i miss something.
this add support to clone from a snapshot from a vm. (at not the default __base__ snapshot, from base-xxx templates ).
I don't have tested it, but this is almost all we need. (maybe some checks to add in qemuserver.pm, but nothing too big)
----- Mail original -----
De: "Stefan Priebe" <s.priebe at profihost.ag>
À: "Alexandre DERUMIER" <aderumier at odiso.com>, "Michael Rasmussen" <mir at datanom.net>
Cc: pve-devel at pve.proxmox.com
Envoyé: Mercredi 5 Février 2014 20:50:34
Objet: Re: [pve-devel] ceph: clone vm
it adds snapshot support but not linked clones? or do i miss something.
Stefan
Am 05.02.2014 16:06, schrieb Alexandre DERUMIER:
>>> Cloning from snapshot is also an opportunity with ZFS.
>
> yes, sure, for any storage which support snasphot.
>
> It's not a big work, as we have already almost all subroutines in storage plugins
>
>
>
> something like this should work (don't have tested it ;)
>
>
> qemuserver.pm
> --------------
>>> sub clone_disk {
>>> my ($storecfg, $vmid, $running, $drivename, $drive, $snapname,
>>> $newvmid, $storage, $format, $full, $newvollist) = @_;
>>>
>>> my $newvolid;
>>>
>>> if (!$full) {
>>> print "create linked clone of drive $drivename ($drive->{file})\n";
>>> $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid);
>
> sub clone_disk {
> my ($storecfg, $vmid, $running, $drivename, $drive, $snapname,
> $newvmid, $storage, $format, $full, $newvollist) = @_;
>
> my $newvolid;
>
> if (!$full) {
> print "create linked clone of drive $drivename ($drive->{file})\n";
> $newvolid = PVE::Storage::vdisk_clone($storecfg, $drive->{file}, $newvmid, $snapname);
>
>
> storage.pm
> ----------
>>> sub vdisk_clone {
>>> my ($cfg, $volid, $vmid) = @_;
>>>
>>> my ($storeid, $volname) = parse_volume_id($volid);
>>>
>>> my $scfg = storage_config($cfg, $storeid);
>>>
>>> my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
>>>
>>> activate_storage($cfg, $storeid);
>>>
>>> # lock shared storage
>>> return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
>>> my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid);
>>> return "$storeid:$volname";
>>> });
>>> }
>
>
> sub vdisk_clone {
> my ($cfg, $volid, $vmid, $snap) = @_;
>
> my ($storeid, $volname) = parse_volume_id($volid);
>
> my $scfg = storage_config($cfg, $storeid);
>
> my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
>
> activate_storage($cfg, $storeid);
>
> # lock shared storage
> return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
> my $volname = $plugin->clone_image($scfg, $storeid, $volname, $vmid, $snap);
> return "$storeid:$volname";
> });
> }
>
>
> storage plugin
> --------------
>>> sub clone_image {
>>> my ($class, $scfg, $storeid, $volname, $vmid) = @_;
>>>
>>> my $snap = '__base__';
>>>
>>> my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
>>> $class->parse_volname($volname);
>>>
>>> die "clone_image onyl works on base images\n" if !$isBase;
>>>
>>> my $name = &$find_free_diskname($storeid, $scfg, $vmid);
>>>
>>> warn "clone $volname: $basename to $name\n";
>>>
>>> my $newvol = "$basename/$name";
>>>
>>> my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name));
>>> run_command($cmd, errmsg => "rbd clone $basename' error");
>>>
>>> return $newvol;
>>> }
>
> sub clone_image {
> my ($class, $scfg, $storeid, $volname, $vmid, $snapshot) = @_;
>
> my $snap = '__base__';
> $snap = $snapshot if $snapshot;
>
> my ($vtype, $basename, $basevmid, undef, undef, $isBase) =
> $class->parse_volname($volname);
>
> die "clone_image onyl works on base images\n" if !$isBase && !$snapshot;
>
> my $name = &$find_free_diskname($storeid, $scfg, $vmid);
>
> warn "clone $volname: $basename to $name\n";
>
> my $newvol = "$basename/$name"; # Maybe find a way to reference snasphot like "$basename@$snasphot/$name"
>
> my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', &$add_pool_to_disk($scfg, $basename), '--snap', $snap, &$add_pool_to_disk($scfg, $name));
> run_command($cmd, errmsg => "rbd clone $basename' error");
>
> return $newvol;
> }
>
>
>
> ----- Mail original -----
>
> De: "Michael Rasmussen" <mir at datanom.net>
> À: pve-devel at pve.proxmox.com
> Envoyé: Mercredi 5 Février 2014 15:39:23
> Objet: Re: [pve-devel] ceph: clone vm
>
> On 02-05-2014 14:50, Alexandre DERUMIER wrote:
>>
>> Maybe could we introduce this feature (for ceph,sheepdog,..), cloning
>> from a snapshot.
>>
> Cloning from snapshot is also an opportunity with ZFS.
>
More information about the pve-devel
mailing list