flexnbd: Move building the allocation map to before server socket bind()

Building the allocation map takes time, which scales with the size of the disc
being presented. By building that map in the space between bind() and accept(),
we leave the process in a useless state after the only good signal we have for
"we are ready" and the state where it is actually ready. This was breaking
migrations of large files.
This commit is contained in:
nick
2012-09-25 11:47:44 +01:00
parent ccbfce1075
commit 32cae67a75
3 changed files with 43 additions and 8 deletions

View File

@@ -8,16 +8,35 @@ module FlexNBD
class FakeSource
def initialize( addr, port, err_msg, source_addr=nil, source_port=0 )
timing_out( 2, err_msg ) do
@sock = if source_addr
TCPSocket.new( addr, port, source_addr, source_port )
else
TCPSocket.new( addr, port )
end
timing_out( 10, err_msg ) {
@sock = wait_for_server_socket( addr, port, source_addr, source_port )
}
end
def wait_for_server_socket(addr, port, saddr = nil, sport = 0)
sock = nil
loop do
sock = try_get_server_socket( addr, port, saddr, sport )
break if sock
sleep 0.1
end
sock
end
def try_get_server_socket(addr, port, saddr = nil, sport = 0)
if saddr
TCPSocket.new( addr, port, saddr, sport ) rescue nil
else
TCPSocket.new( addr, port ) rescue nil
end
end
def close
@sock.close
end
@@ -137,3 +156,4 @@ module FlexNBD
end # class FakeSource
end # module FlexNBD