+sub alloc_image {
+ my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
+
+ my $imagedir = $class->get_subdir($scfg, 'images');
+ $imagedir .= "/$vmid";
+
+ mkpath $imagedir;
+
+ $name = &$find_free_diskname($imagedir, $vmid, $fmt) if !$name;
+
+ my (undef, $tmpfmt) = parse_name_dir($name);
+
+ die "illegal name '$name' - wrong extension for format ('$tmpfmt != '$fmt')\n"
+ if $tmpfmt ne $fmt;
+
+ my $path = "$imagedir/$name";
+
+ die "disk image '$path' already exists\n" if -e $path;
+
+ my $server = $scfg->{server} ? $scfg->{server} : 'localhost';
+ my $glustervolume = $scfg->{volume};
+ my $volumepath = "gluster://$server/$glustervolume/images/$vmid/$name";
+
+ my $cmd = ['/usr/bin/qemu-img', 'create'];
+
+ push @$cmd, '-o', 'preallocation=metadata' if $fmt eq 'qcow2';
+
+ push @$cmd, '-f', $fmt, $volumepath, "${size}K";
+
+ run_command($cmd, errmsg => "unable to create image");
+
+ return "$vmid/$name";
+}
+