QemuServer.patch 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. --- QemuServer.orig.pm 2019-02-01 13:04:19.000000000 +0100
  2. +++ QemuServer.patched.pm 2019-02-12 16:47:56.000000000 +0100
  3. @@ -6461,6 +6461,46 @@
  4. my $src_path = PVE::Storage::path($storecfg, $src_volid, $snapname);
  5. my $dst_path = PVE::Storage::path($storecfg, $dst_volid);
  6. + #BEGIN addition
  7. + my $src_storage_plugin = PVE::Storage::Plugin->lookup($src_scfg->{type});
  8. + my $dst_storage_plugin = PVE::Storage::Plugin->lookup($dst_scfg->{type});
  9. +
  10. + # in many cases the storage may have a better idea how to convert:
  11. + # if src and dst format is the same
  12. + # and src_storeid is dst_storeid
  13. + # and the storage has the feature
  14. + # and the feature is implemented as volume_copy / volume_snapshot_copy
  15. + # let the storage do the work as it quite sure is faster
  16. + if ( $src_format eq $dst_format ) {
  17. + if( $src_storeid eq $dst_storeid ) {
  18. + # this is the same storage
  19. + # and storage is capable of materializing snaps
  20. + if( $snapname ) {
  21. + my $canCopySnap = PVE::Storage::volume_has_feature($storecfg, 'copy', $src_volid, $snapname, undef) && $src_storage_plugin->can('volume_snapshot_copy');
  22. + if( $canCopySnap ) {
  23. + print "delegate to storage plugin volume_snapshot_copy (snap $snapname)\n";
  24. + $src_storage_plugin->volume_snapshot_copy($src_scfg, $src_volname, $snapname, $dst_volname);
  25. +
  26. + $src_storage_plugin->deactivate_volume($src_storeid, $src_scfg, $src_volname, $snapname);
  27. +
  28. + return 1;
  29. + }
  30. + }
  31. +
  32. + my $canCopyVolume = PVE::Storage::volume_has_feature($storecfg, 'copy', $src_volid, undef, undef) && $src_storage_plugin->can('volume_copy');
  33. + if ( $canCopyVolume ) {
  34. + print "delegate to storage plugin: volume_copy (base)\n";
  35. + $src_storage_plugin->volume_copy($src_scfg, $src_volname, $dst_volname);
  36. +
  37. + $src_storage_plugin->deactivate_volume($src_storeid, $src_scfg, $src_volname, $snapname);
  38. +
  39. + return 1;
  40. + }
  41. + }
  42. + # @todo: two zfs-storages might be able to receive stream from each other
  43. + }
  44. + #END addition
  45. +
  46. my $cmd = [];
  47. push @$cmd, '/usr/bin/qemu-img', 'convert', '-p', '-n';
  48. push @$cmd, '-l', "snapshot.name=$snapname" if($snapname && $src_format eq "qcow2");
  49. @@ -6487,6 +6527,11 @@
  50. eval { run_command($cmd, timeout => undef, outfunc => $parser); };
  51. my $err = $@;
  52. +
  53. + # added: deactivate the src-volume, even on failure
  54. + # this can be safely called as qemu_img_convert is never called on a running volume (that is not a snap)
  55. + $src_storage_plugin->deactivate_volume($src_storeid, $src_scfg, $src_volname, $snapname);
  56. +
  57. die "copy failed: $err" if $err;
  58. }
  59. }