Added test for FUA acceptance.
Although I think this might be a bit useless as servers normally just ingore flags.
This commit is contained in:
@@ -483,6 +483,7 @@ void client_reply_to_write( struct client* client, struct nbd_request request )
|
|||||||
/* multiple of 4K page size */
|
/* multiple of 4K page size */
|
||||||
uint64_t from_rounded = request.from & (!0xfff);
|
uint64_t from_rounded = request.from & (!0xfff);
|
||||||
uint64_t len_rounded = request.len + (request.from - from_rounded);
|
uint64_t len_rounded = request.len + (request.from - from_rounded);
|
||||||
|
debug("Calling msync from=%"PRIu64", len=%"PRIu64"",from_rounded, len_rounded);
|
||||||
|
|
||||||
FATAL_IF_NEGATIVE(
|
FATAL_IF_NEGATIVE(
|
||||||
msync( client->mapped + from_rounded,
|
msync( client->mapped + from_rounded,
|
||||||
|
@@ -195,6 +195,7 @@ module FlexNBD
|
|||||||
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
|
@ctrl = "/tmp/.flexnbd.ctrl.#{Time.now.to_i}.#{rand}"
|
||||||
@ip = ip
|
@ip = ip
|
||||||
@port = port
|
@port = port
|
||||||
|
@pid = @wait_thread = nil
|
||||||
@kill = []
|
@kill = []
|
||||||
@prefetch_proxy = false
|
@prefetch_proxy = false
|
||||||
end
|
end
|
||||||
|
@@ -40,11 +40,12 @@ module FlexNBD
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_request(type, handle = 'myhandle', from = 0, len = 0, magic = REQUEST_MAGIC)
|
def send_request(type, handle = 'myhandle', from = 0, len = 0, magic = REQUEST_MAGIC, flags = 0)
|
||||||
raise 'Bad handle' unless handle.length == 8
|
raise 'Bad handle' unless handle.length == 8
|
||||||
|
|
||||||
@sock.write(magic)
|
@sock.write(magic)
|
||||||
@sock.write([type].pack('N'))
|
@sock.write([flags].pack('n'))
|
||||||
|
@sock.write([type].pack('n'))
|
||||||
@sock.write(handle)
|
@sock.write(handle)
|
||||||
@sock.write([n64(from)].pack('q'))
|
@sock.write([n64(from)].pack('q'))
|
||||||
@sock.write([len].pack('N'))
|
@sock.write([len].pack('N'))
|
||||||
@@ -53,7 +54,11 @@ module FlexNBD
|
|||||||
def write_write_request(from, len, handle = 'myhandle')
|
def write_write_request(from, len, handle = 'myhandle')
|
||||||
send_request(1, handle, from, len)
|
send_request(1, handle, from, len)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_write_request_with_fua(from, len, handle = 'myhandle')
|
||||||
|
send_request(1, handle, from, len, REQUEST_MAGIC, 1)
|
||||||
|
end
|
||||||
|
|
||||||
def write_flush_request(handle = 'myhandle')
|
def write_flush_request(handle = 'myhandle')
|
||||||
send_request(3, handle, 0, 0)
|
send_request(3, handle, 0, 0)
|
||||||
end
|
end
|
||||||
@@ -99,6 +104,11 @@ module FlexNBD
|
|||||||
write_data(data)
|
write_data(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def write_with_fua(from, data)
|
||||||
|
write_write_request_with_fua(from, data.length)
|
||||||
|
write_data(data)
|
||||||
|
end
|
||||||
|
|
||||||
def flush
|
def flush
|
||||||
write_flush_request
|
write_flush_request
|
||||||
end
|
end
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
require 'test/unit'
|
require 'test/unit'
|
||||||
require 'environment'
|
require 'environment'
|
||||||
require 'flexnbd/fake_source'
|
require 'flexnbd/fake_source'
|
||||||
require 'pp'
|
|
||||||
|
|
||||||
class TestServeMode < Test::Unit::TestCase
|
class TestServeMode < Test::Unit::TestCase
|
||||||
def setup
|
def setup
|
||||||
@@ -118,4 +117,14 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
assert_equal 0, rsp[:error]
|
assert_equal 0, rsp[:error]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_write_with_fua_is_accepted
|
||||||
|
connect_to_server do |client|
|
||||||
|
# Start with a file of all-zeroes.
|
||||||
|
client.write_with_fua(0, "\x00" * @env.file1.size)
|
||||||
|
rsp = client.read_response
|
||||||
|
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||||
|
assert_equal 0, rsp[:error]
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user