From d6e69ea9cfe2f4cf9a360ae162c6dea74eb50ad1 Mon Sep 17 00:00:00 2001 From: Jaime Melis Date: Tue, 3 May 2016 11:20:25 +0200 Subject: [PATCH] Feature #2980: Recalculate VNC ports in fsck --- src/onedb/fsck.rb | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/onedb/fsck.rb b/src/onedb/fsck.rb index 6605bc7ed9..5be7986b72 100644 --- a/src/onedb/fsck.rb +++ b/src/onedb/fsck.rb @@ -800,6 +800,7 @@ EOT log_time() vms_fix = {} + cluster_vnc = {} # Aggregate information of the RUNNING vms @db.fetch("SELECT oid,body FROM vm_pool WHERE state<>6") do |row| @@ -808,6 +809,15 @@ EOT state = vm_doc.root.at_xpath('STATE').text.to_i lcm_state = vm_doc.root.at_xpath('LCM_STATE').text.to_i + # VNC ports per cluster + cid = doc.root.at_xpath("HISTORY_RECORDS/HISTORY[last()]/CID").text.to_i rescue nil + port = doc.root.at_xpath("TEMPLATE/GRAPHICS[TYPE='vnc']/PORT").text.to_i rescue nil + + if cid && port + cluster_vnc[cid] ||= Set.new + cluster_vnc[cid] << port + end + # Images used by this VM vm_doc.root.xpath("TEMPLATE/DISK/IMAGE_ID").each do |e| img_id = e.text.to_i @@ -946,6 +956,29 @@ EOT log_time() + # VNC Bitmap + + @db.run "DROP TABLE cluster_vnc_bitmap;" + @db.run "CREATE TABLE cluster_vnc_bitmap (id INTEGER, map LONGTEXT, PRIMARY KEY(id));" + + size = 65536 + + cluster_vnc.keys.sort.each do |cluster_id| + map = "" + size.times.each do |i| + map << (cluster_vnc[cluster_id].include?(size - 1 - i) ? "1" : "0") + end + + map_encoded = Base64::strict_encode64(Zlib::Deflate.deflate(map)) + + @db[:cluster_vnc_bitmap].insert( + :id => cluster_id, + :map => map_encoded + ) + end + + log_time() + # Bug #4000 may cause history records with etime=0 when they should # be closed. The last history can be fixed with the VM etime, but # previous history entries need to be fixed manually