mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-18 10:53:13 +09:00
Feature #2858: Remove leases fixes from fsck
This commit is contained in:
1 parent
c12cb2d6ba
commit
c0aaec92f1
1 file changed
+12
-166
+12
-166
@@ -23,7 +23,7 @@ require 'nokogiri'
|
||||
|
||||
module OneDBFsck
|
||||
VERSION = "4.6.0"
|
||||
LOCAL_VERSION = "4.5.80"
|
||||
LOCAL_VERSION = "4.7.80"
|
||||
|
||||
def check_db_version()
|
||||
db_version = read_db_version()
|
||||
@@ -768,8 +768,7 @@ EOT
|
||||
|
||||
counters[:vnet][row[:oid]] = {
|
||||
:type => doc.root.get_text('TYPE').to_s.to_i,
|
||||
:total_leases => 0,
|
||||
:leases => {}
|
||||
:ar_leases => {}
|
||||
}
|
||||
end
|
||||
|
||||
@@ -808,12 +807,20 @@ EOT
|
||||
log_error("VM #{row[:oid]} is using VNet #{net_id}, "<<
|
||||
"but it does not exist")
|
||||
else
|
||||
counters[:vnet][net_id][:leases][e.at_xpath('IP').text] =
|
||||
=begin
|
||||
ar_id_e = e.at_xpath('AR_ID')
|
||||
ar_id = ar_id_e.nil? ? -1 : ar_id_e.text.to_i
|
||||
|
||||
if counters[:vnet][net_id][:ar_leases][ar_id].nil?
|
||||
counters[:vnet][net_id][:ar_leases][ar_id] = []
|
||||
end
|
||||
|
||||
counters[:vnet][net_id][:ar_leases][ar_id] <<
|
||||
[
|
||||
e.at_xpath('MAC').text, # MAC
|
||||
"1", # USED
|
||||
vm_doc.root.at_xpath('ID').text.to_i # VID
|
||||
]
|
||||
=end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1104,167 +1111,6 @@ EOT
|
||||
|
||||
log_time()
|
||||
|
||||
########################################################################
|
||||
# VNet
|
||||
#
|
||||
# LEASES
|
||||
########################################################################
|
||||
|
||||
@db.run "CREATE TABLE leases_new (oid INTEGER, ip BIGINT, body MEDIUMTEXT, PRIMARY KEY(oid,ip));"
|
||||
|
||||
@db.transaction do
|
||||
@db[:leases].each do |row|
|
||||
doc = Nokogiri::XML(row[:body]){|c| c.default_xml.noblanks}
|
||||
|
||||
used = (doc.root.at_xpath('USED').text == "1")
|
||||
vid = doc.root.at_xpath('VID').text.to_i
|
||||
|
||||
ip_str = IPAddr.new(row[:ip], Socket::AF_INET).to_s
|
||||
|
||||
vnet_structure = counters[:vnet][row[:oid]]
|
||||
|
||||
if vnet_structure.nil?
|
||||
log_error("Table leases contains the lease #{ip_str} "<<
|
||||
"for VNet #{row[:oid]}, but it does not exit")
|
||||
|
||||
next
|
||||
end
|
||||
|
||||
ranged = vnet_structure[:type] == 0
|
||||
|
||||
counter_mac, counter_used, counter_vid =
|
||||
vnet_structure[:leases][ip_str]
|
||||
|
||||
vnet_structure[:leases].delete(ip_str)
|
||||
|
||||
insert = true
|
||||
|
||||
if used && (vid != -1) # Lease used by a VM
|
||||
if counter_mac.nil?
|
||||
log_error(
|
||||
"VNet #{row[:oid]} has used lease #{ip_str} "<<
|
||||
"(VM #{vid}) \tbut it is free")
|
||||
|
||||
if ranged
|
||||
insert = false
|
||||
end
|
||||
|
||||
doc.root.at_xpath("USED").content = "0"
|
||||
|
||||
doc.root.at_xpath("VID").content = "-1"
|
||||
|
||||
row[:body] = doc.root.to_s
|
||||
|
||||
elsif vid != counter_vid
|
||||
log_error(
|
||||
"VNet #{row[:oid]} has used lease #{ip_str} "<<
|
||||
"(VM #{vid}) \tbut it used by VM #{counter_vid}")
|
||||
|
||||
doc.root.at_xpath("VID").content = counter_vid.to_s
|
||||
|
||||
row[:body] = doc.root.to_s
|
||||
end
|
||||
else # Lease is free or on hold (used=1, vid=-1)
|
||||
if !counter_mac.nil?
|
||||
if used
|
||||
log_error(
|
||||
"VNet #{row[:oid]} has lease on hold #{ip_str} "<<
|
||||
"\tbut it is used by VM #{counter_vid}")
|
||||
else
|
||||
log_error(
|
||||
"VNet #{row[:oid]} has free lease #{ip_str} "<<
|
||||
"\tbut it is used by VM #{counter_vid}")
|
||||
end
|
||||
|
||||
doc.root.at_xpath("USED").content = "1"
|
||||
|
||||
doc.root.at_xpath("VID").content = counter_vid.to_s
|
||||
|
||||
row[:body] = doc.root.to_s
|
||||
end
|
||||
end
|
||||
|
||||
if (doc.root.at_xpath('USED').text == "1")
|
||||
vnet_structure[:total_leases] += 1
|
||||
end
|
||||
|
||||
# commit
|
||||
@db[:leases_new].insert(row) if insert
|
||||
end
|
||||
end
|
||||
|
||||
log_time()
|
||||
|
||||
# Now insert all the leases left in the hash, i.e. used by a VM in
|
||||
# vm_pool, but not in the leases table. This will only happen in
|
||||
# ranged networks
|
||||
@db.transaction do
|
||||
counters[:vnet].each do |net_id,vnet_structure|
|
||||
vnet_structure[:leases].each do |ip,array|
|
||||
mac,used,vid = array
|
||||
|
||||
ip_i = IPAddr.new(ip, Socket::AF_INET).to_i
|
||||
|
||||
# TODO: MAC_PREFIX is now hardcoded to "02:00"
|
||||
body = "<LEASE><IP>#{ip_i}</IP><MAC_PREFIX>512</MAC_PREFIX><MAC_SUFFIX>#{ip_i}</MAC_SUFFIX><USED>#{used}</USED><VID>#{vid}</VID></LEASE>"
|
||||
|
||||
log_error("VNet #{net_id} has free lease #{ip} \tbut it is used by VM #{vid}")
|
||||
|
||||
vnet_structure[:total_leases] += 1
|
||||
|
||||
@db[:leases_new].insert(
|
||||
:oid => net_id,
|
||||
:ip => ip_i,
|
||||
:body => body)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Rename table
|
||||
@db.run("DROP TABLE leases")
|
||||
@db.run("ALTER TABLE leases_new RENAME TO leases")
|
||||
|
||||
log_time()
|
||||
|
||||
########################################################################
|
||||
# VNet
|
||||
#
|
||||
# VNET/TOTAL_LEASES
|
||||
########################################################################
|
||||
|
||||
# Create a new empty table where we will store the new calculated values
|
||||
@db.run "CREATE TABLE network_pool_new (oid INTEGER PRIMARY KEY, name VARCHAR(128), body MEDIUMTEXT, uid INTEGER, gid INTEGER, owner_u INTEGER, group_u INTEGER, other_u INTEGER, cid INTEGER, UNIQUE(name,uid));"
|
||||
|
||||
@db.transaction do
|
||||
@db[:network_pool].each do |row|
|
||||
doc = Document.new(row[:body])
|
||||
|
||||
oid = row[:oid]
|
||||
|
||||
total_leases = counters[:vnet][oid][:total_leases]
|
||||
|
||||
# rewrite running_vms
|
||||
doc.root.each_element("TOTAL_LEASES") {|e|
|
||||
if e.text != total_leases.to_s
|
||||
log_error("VNet #{oid} TOTAL_LEASES has #{e.text} \tis\t#{total_leases}")
|
||||
e.text = total_leases
|
||||
end
|
||||
}
|
||||
|
||||
row[:body] = doc.to_s
|
||||
|
||||
# commit
|
||||
@db[:network_pool_new].insert(row)
|
||||
end
|
||||
end
|
||||
|
||||
# Rename table
|
||||
@db.run("DROP TABLE network_pool")
|
||||
@db.run("ALTER TABLE network_pool_new RENAME TO network_pool")
|
||||
|
||||
log_time()
|
||||
|
||||
########################################################################
|
||||
# Users
|
||||
#
|
||||
|
||||
Reference in new issue
Block a user