From d486ee1ae40f0d5a6e3658647698d33f7a6fc563 Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Fri, 11 Oct 2024 14:01:45 +0200 Subject: [PATCH] F #-: Fix Ceph VM restore ignoring EC_POOL_NAME Signed-off-by: Guillermo Ramos (cherry picked from commit ad24f286169826c69f564d5b36801937b7b65077) --- src/tm_mad/ceph/restore | 4 ++-- src/tm_mad/lib/ceph.rb | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/tm_mad/ceph/restore b/src/tm_mad/ceph/restore index c378fd6592..2655386f18 100755 --- a/src/tm_mad/ceph/restore +++ b/src/tm_mad/ceph/restore @@ -130,7 +130,7 @@ begin if file $tmpimg | grep -q gzip; then cd $tmpdir tar zxf $tmpimg - #{ceph_disk.restore_sh(info[ceph_disk][:new], info[ceph_disk][:br])} + #{ceph_disk.restore_sh(info[ceph_disk][:new], ceph_ds, info[ceph_disk][:br])} cd - else qemu-img convert -m 4 -O raw $tmpimg $tmpimg.raw && \ @@ -184,7 +184,7 @@ begin :nostdout => false, :nostderr => false) - warn 'cannot restore disk backup' if rc.code != 0 + raise StandardError, 'cannot restore disk backup' if rc.code != 0 end rescue StandardError => e STDERR.puts "Error restoring VM disks: #{e.message}" diff --git a/src/tm_mad/lib/ceph.rb b/src/tm_mad/lib/ceph.rb index f5876cf4da..7f81916fb1 100644 --- a/src/tm_mad/lib/ceph.rb +++ b/src/tm_mad/lib/ceph.rb @@ -256,10 +256,23 @@ module TransferManager } end - def restore_sh(target, bridge = nil) + # @param target [String] the RBD image name where to import + # @param ds [TransferManager::Datastore] the target datastore + # @param bridge [Boolean, nil] host from where to execute this operation + # @return [String] the script + def restore_sh(target, ds, bridge = nil) + ec_pool_name = ds['TEMPLATE/EC_POOL_NAME'] + + # EC parameters (--data-pool) are only accepted in some `rbd` commands. It's not + # officially documented but at least the following ones require it: + # - create + # - import + rbdec_cmd = @rbd_cmd.clone + rbdec_cmd << " --data-pool #{ec_pool_name}" unless ec_pool_name.empty? + <<~EOF # Upload base image and snapshot - #{Disk.sshwrap(bridge, "#{@rbd_cmd} import --export-format 2 - #{target}")} < disk.*.rbd2 + #{Disk.sshwrap(bridge, "#{rbdec_cmd} import --export-format 2 - #{target}")} < disk.*.rbd2 # Apply increments for f in $(ls disk.*.*.rbdiff | sort -k3 -t.); do