fix #2120: use hosts initiator name with qemu-img

qemu-img uses the qemu default initiator name 'iqn.2008-11.org.linux-kvm'
since we use the one of the host (/etc/iscsi/initiatorname.iscsi) when
using it with a running vm, we want to using it also when moving a disk
with qemu-img

to do that we have give qemu-img the image in as a full option string

this fixes the issue that we could not move an zfs-over-iscsi disk
without allowing the default qemu initiator

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2019-03-07 13:43:11 +01:00 committed by Thomas Lamprecht
parent cb702ebe0f
commit 92bdc3f0e3

View File

@ -6540,6 +6540,23 @@ sub template_create {
}); });
} }
sub convert_iscsi_path {
my ($path) = @_;
if ($path =~ m|^iscsi://([^/]+)/([^/]+)/(.+)$|) {
my $portal = $1;
my $target = $2;
my $lun = $3;
my $initiator_name = get_initiator_name();
return "file.driver=iscsi,file.transport=tcp,file.initiator-name=$initiator_name,".
"file.portal=$portal,file.target=$target,file.lun=$lun,driver=raw";
}
die "cannot convert iscsi path '$path', unkown format\n";
}
sub qemu_img_convert { sub qemu_img_convert {
my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized) = @_; my ($src_volid, $dst_volid, $size, $snapname, $is_zero_initialized) = @_;
@ -6560,13 +6577,32 @@ sub qemu_img_convert {
my $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname); my $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
my $dst_path = PVE::Storage::path($storecfg, $dst_volid); my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
my $src_is_iscsi = ($src_path =~ m|^iscsi://|);
my $dst_is_iscsi = ($dst_path =~ m|^iscsi://|);
my $cmd = []; my $cmd = [];
push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n'; push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n';
push @$cmd, '-l', "snapshot.name=$snapname" if($snapname && $src_format eq "qcow2"); push @$cmd, '-l', "snapshot.name=$snapname" if($snapname && $src_format eq "qcow2");
push @$cmd, '-t', 'none' if $dst_scfg->{type} eq 'zfspool'; push @$cmd, '-t', 'none' if $dst_scfg->{type} eq 'zfspool';
push @$cmd, '-T', 'none' if $src_scfg->{type} eq 'zfspool'; push @$cmd, '-T', 'none' if $src_scfg->{type} eq 'zfspool';
push @$cmd, '-f', $src_format, '-O', $dst_format, $src_path;
if ($is_zero_initialized) { if ($src_is_iscsi) {
push @$cmd, '--image-opts';
$src_path = convert_iscsi_path($src_path);
} else {
push @$cmd, '-f', $src_format;
}
if ($dst_is_iscsi) {
push @$cmd, '--target-image-opts';
$dst_path = convert_iscsi_path($dst_path);
} else {
push @$cmd, '-O', $dst_format;
}
push @$cmd, $src_path;
if (!$dst_is_iscsi && $is_zero_initialized) {
push @$cmd, "zeroinit:$dst_path"; push @$cmd, "zeroinit:$dst_path";
} else { } else {
push @$cmd, $dst_path; push @$cmd, $dst_path;