]> git.proxmox.com Git - pve-storage.git/commitdiff
use qemu gluster blockdriver for linked clone creation
authorDominik Csapak <d.csapak@proxmox.com>
Mon, 28 Nov 2016 12:34:19 +0000 (13:34 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Tue, 29 Nov 2016 08:40:10 +0000 (09:40 +0100)
this works around a bug, where qemu does not align the qcow2 file
when using the filesystem directly, and the gluster blockdriver
refuses to read from it

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/Storage/GlusterfsPlugin.pm

index 1e63e24ae6783e4dd86238bed20eb73362bf1079..d8b7c8c9ae6c83e245da31a2d91fc6591bc318ab 100644 (file)
@@ -213,6 +213,47 @@ sub path {
     return wantarray ? ($path, $vmid, $vtype) : $path;
 }
 
+sub clone_image {
+    my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
+
+    die "storage definintion has no path\n" if !$scfg->{path};
+
+    my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
+       $class->parse_volname($volname);
+
+    die "clone_image on wrong vtype '$vtype'\n" if $vtype ne 'images';
+
+    die "this storage type does not support clone_image on snapshot\n" if $snap;
+
+    die "this storage type does not support clone_image on subvolumes\n" if $format eq 'subvol';
+
+    die "clone_image only works on base images\n" if !$isBase;
+
+    my $imagedir = $class->get_subdir($scfg, 'images');
+    $imagedir .= "/$vmid";
+
+    mkpath $imagedir;
+
+    my $name = &$find_free_diskname($imagedir, $vmid, "qcow2");
+
+    warn "clone $volname: $vtype, $name, $vmid to $name (base=../$basevmid/$basename)\n";
+
+    my $path = "$imagedir/$name";
+
+    die "disk image '$path' already exists\n" if -e $path;
+
+    my $server = &$get_active_server($scfg, 1);
+    my $glustervolume = $scfg->{volume};
+    my $volumepath = "gluster://$server/$glustervolume/images/$vmid/$name";
+
+    my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
+              '-f', 'qcow2', $volumepath];
+
+    run_command($cmd, errmsg => "unable to create image");
+
+    return "$basevmid/$basename/$vmid/$name";
+}
+
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;