Use sysconf to determine actual page size for msync
Also added comments in tests around testing for msync offsets/lengths.
This commit is contained in:
@@ -480,8 +480,8 @@ void client_reply_to_write( struct client* client, struct nbd_request request )
|
|||||||
// Only flush if FUA is set
|
// Only flush if FUA is set
|
||||||
if (request.flags & CMD_FLAG_FUA)
|
if (request.flags & CMD_FLAG_FUA)
|
||||||
{
|
{
|
||||||
/* multiple of 4K page size */
|
/* multiple of page size */
|
||||||
uint64_t from_rounded = request.from & (~0xfff);
|
uint64_t from_rounded = request.from & (~(sysconf(_SC_PAGE_SIZE)-1));
|
||||||
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);
|
debug("Calling msync from=%"PRIu64", len=%"PRIu64"",from_rounded, len_rounded);
|
||||||
|
|
||||||
|
@@ -6,7 +6,8 @@ class Environment
|
|||||||
:port1, :port2, :nbd1, :nbd2, :file1, :file2)
|
:port1, :port2, :nbd1, :nbd2, :file1, :file2)
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@blocksize = 1024
|
# Make sure we have a few pages of memory so we can test msync offsets
|
||||||
|
@blocksize = Integer(`getconf PAGE_SIZE`) * 4
|
||||||
@filename1 = "/tmp/.flexnbd.test.#{$PROCESS_ID}.#{Time.now.to_i}.1"
|
@filename1 = "/tmp/.flexnbd.test.#{$PROCESS_ID}.#{Time.now.to_i}.1"
|
||||||
@filename2 = "/tmp/.flexnbd.test.#{$PROCESS_ID}.#{Time.now.to_i}.2"
|
@filename2 = "/tmp/.flexnbd.test.#{$PROCESS_ID}.#{Time.now.to_i}.2"
|
||||||
@ip = '127.0.0.1'
|
@ip = '127.0.0.1'
|
||||||
|
@@ -110,7 +110,6 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
|
|
||||||
def test_flush_is_accepted
|
def test_flush_is_accepted
|
||||||
connect_to_server do |client|
|
connect_to_server do |client|
|
||||||
# Start with a file of all-zeroes.
|
|
||||||
client.flush
|
client.flush
|
||||||
rsp = client.read_response
|
rsp = client.read_response
|
||||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||||
@@ -119,12 +118,21 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_write_with_fua_is_accepted
|
def test_write_with_fua_is_accepted
|
||||||
|
page_size = Integer(`getconf PAGESIZE`)
|
||||||
connect_to_server do |client|
|
connect_to_server do |client|
|
||||||
# Start with a file of all-zeroes.
|
# Write somewhere in the third page
|
||||||
client.write_with_fua(0, "\x00" * @env.file1.size)
|
pos = page_size * 3 + 100
|
||||||
|
client.write_with_fua(pos, "\x00" * 33)
|
||||||
rsp = client.read_response
|
rsp = client.read_response
|
||||||
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
assert_equal FlexNBD::REPLY_MAGIC, rsp[:magic]
|
||||||
assert_equal 0, rsp[:error]
|
assert_equal 0, rsp[:error]
|
||||||
|
# TODO: test offset and length
|
||||||
|
# Should be rounded to the third page
|
||||||
|
# assert_equal(msync_offset, page_size *3)
|
||||||
|
|
||||||
|
# Should be 100 + 33, as we've started writing 100 bytes into a page, for
|
||||||
|
# 33 bytes
|
||||||
|
# assert_equal(msync_length, 133)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user