]> git.proxmox.com Git - pve-storage.git/blobdiff - PVE/Storage/GlusterfsPlugin.pm
plugin: change name, separator and error message for dir overrides
[pve-storage.git] / PVE / Storage / GlusterfsPlugin.pm
index d8b7c8c9ae6c83e245da31a2d91fc6591bc318ab..ad386d2f3606c2ad315753621ac464783ad1c1fc 100644 (file)
@@ -39,9 +39,8 @@ my $get_active_server = sub {
        my $status = 0;
 
        if ($server && $server ne 'localhost' && $server ne '127.0.0.1' && $server ne '::1') {
-
-           # ping the echo port (7) without service check
-           $status = PVE::Network::tcp_ping($server, undef, 2);
+           # ping the gluster daemon default port (24007) as heuristic
+           $status = PVE::Network::tcp_ping($server, 24007, 2);
 
        } else {
 
@@ -98,7 +97,7 @@ sub type {
 
 sub plugindata {
     return {
-       content => [ { images => 1, vztmpl => 1, iso => 1, backup => 1},
+       content => [ { images => 1, vztmpl => 1, iso => 1, backup => 1, snippets => 1},
                     { images => 1 }],
        format => [ { raw => 1, qcow2 => 1, vmdk => 1 } , 'raw' ],
     };
@@ -130,12 +129,16 @@ sub options {
        server2 => { optional => 1 },
        volume => { fixed => 1 },
        transport => { optional => 1 },
-        nodes => { optional => 1 },
+       nodes => { optional => 1 },
        disable => { optional => 1 },
-        maxfiles => { optional => 1 },
+       maxfiles => { optional => 1 },
+       'prune-backups' => { optional => 1 },
+       'max-protected-backups' => { optional => 1 },
        content => { optional => 1 },
        format => { optional => 1 },
        mkdir => { optional => 1 },
+       bwlimit => { optional => 1 },
+       preallocation => { optional => 1 },
     };
 }
 
@@ -160,26 +163,6 @@ sub parse_name_dir {
     die "unable to parse volume filename '$name'\n";
 }
 
-my $find_free_diskname = sub {
-    my ($imgdir, $vmid, $fmt) = @_;
-
-    my $disk_ids = {};
-    PVE::Tools::dir_glob_foreach($imgdir,
-                                 qr!(vm|base)-$vmid-disk-(\d+)\..*!,
-                                 sub {
-                                     my ($fn, $type, $disk) = @_;
-                                     $disk_ids->{$disk} = 1;
-                                 });
-
-    for (my $i = 1; $i < 100; $i++) {
-        if (!$disk_ids->{$i}) {
-            return "vm-$vmid-disk-$i.$fmt";
-        }
-    }
-
-    die "unable to allocate a new image name for VM $vmid in '$imgdir'\n";
-};
-
 sub path {
     my ($class, $scfg, $volname, $storeid, $snapname) = @_;
 
@@ -216,7 +199,7 @@ sub path {
 sub clone_image {
     my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
 
-    die "storage definintion has no path\n" if !$scfg->{path};
+    die "storage definition has no path\n" if !$scfg->{path};
 
     my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
        $class->parse_volname($volname);
@@ -234,7 +217,7 @@ sub clone_image {
 
     mkpath $imagedir;
 
-    my $name = &$find_free_diskname($imagedir, $vmid, "qcow2");
+    my $name = $class->find_free_diskname($storeid, $scfg, $vmid, "qcow2", 1);
 
     warn "clone $volname: $vtype, $name, $vmid to $name (base=../$basevmid/$basename)\n";
 
@@ -247,7 +230,7 @@ sub clone_image {
     my $volumepath = "gluster://$server/$glustervolume/images/$vmid/$name";
 
     my $cmd = ['/usr/bin/qemu-img', 'create', '-b', "../$basevmid/$basename",
-              '-f', 'qcow2', $volumepath];
+              '-F', $format, '-f', 'qcow2', $volumepath];
 
     run_command($cmd, errmsg => "unable to create image");
 
@@ -262,7 +245,7 @@ sub alloc_image {
 
     mkpath $imagedir;
 
-    $name = &$find_free_diskname($imagedir, $vmid, $fmt) if !$name;
+    $name = $class->find_free_diskname($storeid, $scfg, $vmid, $fmt, 1) if !$name;
 
     my (undef, $tmpfmt) = parse_name_dir($name);
 
@@ -279,11 +262,17 @@ sub alloc_image {
 
     my $cmd = ['/usr/bin/qemu-img', 'create'];
 
-    push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
+    my $prealloc_opt = PVE::Storage::Plugin::preallocation_cmd_option($scfg, $fmt);
+    push @$cmd, '-o', $prealloc_opt if defined($prealloc_opt);
 
     push @$cmd, '-f', $fmt, $volumepath, "${size}K";
 
-    run_command($cmd, errmsg => "unable to create image");
+    eval { run_command($cmd, errmsg => "unable to create image"); };
+    if ($@) {
+       unlink $path;
+       rmdir $imagedir;
+       die "$@";
+    }
 
     return "$vmid/$name";
 }