F #4985: Create recovery snaphots in new thread (#682)

This commit is contained in:
Jan Orel authored and GitHub committed 2021-01-21 10:30:45 +01:00
1 parent e9e19f36fd
commit 3202a252d1
4 files changed
+112 -2

No files matched your search

+5
View File
@@ -339,6 +339,7 @@ VAR_DIRS="$VAR_LOCATION/remotes \
$VAR_LOCATION/remotes/im/kvm-probes.d/host/system \
$VAR_LOCATION/remotes/im/kvm-probes.d/vm/monitor \
$VAR_LOCATION/remotes/im/kvm-probes.d/vm/status \
$VAR_LOCATION/remotes/im/kvm-probes.d/vm/snapshot \
$VAR_LOCATION/remotes/im/dummy.d \
$VAR_LOCATION/remotes/im/dummy-probes.d/host/beacon \
$VAR_LOCATION/remotes/im/dummy-probes.d/host/monitor \
@@ -571,6 +572,7 @@ INSTALL_FILES=(
IM_PROBES_KVM_HOST_SYSTEM_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/host/system
IM_PROBES_KVM_VM_MONITOR_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/vm/monitor
IM_PROBES_KVM_VM_STATUS_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/vm/status
IM_PROBES_KVM_VM_SNAPSHOT_FILES:$VAR_LOCATION/remotes/im/kvm-probes.d/vm/snapshot
IM_PROBES_ETC_KVM_PROBES_FILES:$VAR_LOCATION/remotes/etc/im/kvm-probes.d
IM_PROBES_DUMMY_HOST_BEACON_FILES:$VAR_LOCATION/remotes/im/dummy-probes.d/host/beacon
IM_PROBES_DUMMY_HOST_MONITOR_FILES:$VAR_LOCATION/remotes/im/dummy-probes.d/host/monitor
@@ -1315,6 +1317,9 @@ IM_PROBES_KVM_VM_MONITOR_FILES="\
IM_PROBES_KVM_VM_STATUS_FILES="\
src/im_mad/remotes/kvm-probes.d/vm/status/state.rb"
IM_PROBES_KVM_VM_SNAPSHOT_FILES="\
src/im_mad/remotes/kvm-probes.d/vm/snapshot/recovery.rb"
IM_PROBES_ETC_KVM_PROBES_FILES="\
src/im_mad/remotes/kvm-probes.d/pci.conf \
src/im_mad/remotes/lib/probe_db.conf"
@@ -213,6 +213,12 @@ begin
:path => 'vm/monitor'
},
:snapshot_vm_udp => {
:period => 60,
:elem_name => 'MONITOR_VM',
:path => 'vm/snapshot'
},
:beacon_host_udp => {
:period => config.elements['PROBES_PERIOD/BEACON_HOST'].text.to_s,
:path => 'host/beacon'
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2020, OpenNebula Project, OpenNebula Systems #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
require 'rexml/document'
require 'fileutils'
require 'open3'
require 'base64'
def xml_elem(xml, xpath)
rexml = REXML::Document.new(xml).root
rexml.elements[xpath].text.to_s
rescue StandardError
nil
end
ds_loc = xml_elem(STDIN.read, 'DATASTORE_LOCATION')
ds_loc ||= '/var/lib/one/datastores'
Dir.chdir ds_loc
datastores = Dir.glob('*').select do |f|
File.directory?(f) && f.match(/^\d+$/)
end
monitor_data = []
datastores.each do |ds|
# Skip if datastore is not ssh
mark = "#{ds_loc}/#{ds}/.monitor"
next unless File.exist? mark
driver = File.read mark
driver.chomp!
next unless driver == 'ssh'
# for all VMs
Dir.entries("#{ds_loc}/#{ds}").each do |vm_id|
vm_dir = "#{ds_loc}/#{ds}/#{vm_id}"
next if vm_id !~ /^\d+$/
next unless File.directory?(vm_dir)
disk_data = []
# for all disks
Dir.entries(vm_dir).each do |disk|
next if disk !~ /^disk.\d+$/
next unless File.file?("#{vm_dir}/#{disk}.snap/base.1")
next unless File.file?("#{vm_dir}/vm.xml")
next unless File.file?("#{vm_dir}/ds.xml")
disk_id = disk.split('.')[1]
replica = xml_elem(File.read("#{vm_dir}/ds.xml"),
'/DATASTORE/TEMPLATE/REPLICA_HOST')
freq = xml_elem(File.read("#{vm_dir}/vm.xml"),
"/VM/TEMPLATE/DISK[DISK_ID=#{disk_id}]/" <<
'RECOVERY_SNAPSHOT_FREQ')
rs_script = '/var/tmp/one/tm/ssh/recovery_snap_create_live'
next if freq.empty? || replica.empty? || !File.exist?(rs_script)
o, _e, s = Open3.capture3("#{rs_script} #{vm_id} " <<
"#{vm_dir}/#{disk} " <<
"#{freq} #{replica}")
o.chomp!
if s.exitstatus == 0
disk_data << \
'DISK_RECOVERY_SNAPSHOT = ' \
"[ ID=#{disk_id}, TIMESTAMP=#{o}]"
else
disk_data << \
'DISK_RECOVERY_SNAPSHOT = ' \
"[ ID=#{disk_id}, MSG=\"ERROR #{o}\"]"
end
end
next if disk_data.empty?
enc_data = Base64.strict_encode64(disk_data.join("\n"))
monitor_data << \
"VM = [ ID=\"#{vm_id}\" MONITOR = \"#{enc_data}\" ]"
end
end
puts monitor_data.join("\n")
+2 -2
View File
@@ -70,7 +70,7 @@ EOF
)
# try with quiesce first (needs guest agent)
$SNAP_CMD --quiesce || $SNAP_CMD
$SNAP_CMD --quiesce >/dev/null || $SNAP_CMD >/dev/null
# copy base.1 to the replica
ssh $REPLICA_HOST "mkdir -p $REPLICA_RECOVERY_SNAPS_DIR/$VMID/$DISK_NAME.snap"
@@ -83,6 +83,6 @@ rsync -q $DISK_PATH.snap/base.1 \
virsh -c ${LIBVIRT_URI} blockcommit one-${VMID} $SNAP_PATH \
--base $DISK_PATH.snap/base.1 \
--top $SNAP_PATH \
--active --pivot --wait
--active --pivot --wait >/dev/null
stat -c "%Y" $SNAP_PATH