Merge branch 'truncate-odd-sized-discs' into 'develop'
Discs must be sized in multiples of 512 bytes or odd things happen See merge request open-source/flexnbd-c!42
This commit is contained in:
1
debian/changelog
vendored
1
debian/changelog
vendored
@@ -14,6 +14,7 @@ flexnbd (0.2.0) UNRELEASED; urgency=medium
|
|||||||
filesystem, and EINVAL to unknown commands. (#36, !40)
|
filesystem, and EINVAL to unknown commands. (#36, !40)
|
||||||
* Proxy passes all NBD protocol errors through to the client instead of
|
* Proxy passes all NBD protocol errors through to the client instead of
|
||||||
disconnecting and retrying (#36, !40)
|
disconnecting and retrying (#36, !40)
|
||||||
|
* Ignore ends of discs that stray outside of 512-byte sector sizes (!42).
|
||||||
|
|
||||||
-- James Carter <james.carter@bytemark.co.uk> Thu, 11 Jan 2018 10:05:35 +0000
|
-- James Carter <james.carter@bytemark.co.uk> Thu, 11 Jan 2018 10:05:35 +0000
|
||||||
|
|
||||||
|
@@ -97,6 +97,15 @@ int open_and_mmap(const char* filename, int* out_fd, uint64_t *out_size, void **
|
|||||||
warn("lseek64() failed");
|
warn("lseek64() failed");
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* If discs are not in multiples of 512, then odd things happen,
|
||||||
|
* resulting in reads/writes past the ends of files.
|
||||||
|
*/
|
||||||
|
if ( size != (size & (~0x1ff))) {
|
||||||
|
warn("file does not fit into 512-byte sectors; the end of the file will be ignored.");
|
||||||
|
size &= ~0x1ff;
|
||||||
|
}
|
||||||
|
|
||||||
if (out_size) {
|
if (out_size) {
|
||||||
*out_size = size;
|
*out_size = size;
|
||||||
}
|
}
|
||||||
|
@@ -710,6 +710,15 @@ void serve_init_allocation_map(struct server* params)
|
|||||||
|
|
||||||
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename );
|
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename );
|
||||||
size = lseek64( fd, 0, SEEK_END );
|
size = lseek64( fd, 0, SEEK_END );
|
||||||
|
|
||||||
|
/* If discs are not in multiples of 512, then odd things happen,
|
||||||
|
* resulting in reads/writes past the ends of files.
|
||||||
|
*/
|
||||||
|
if ( size != (size & ~0x1ff)) {
|
||||||
|
warn("file does not fit into 512-byte sectors; the end of the file will be ignored.");
|
||||||
|
size &= ~0x1ff;
|
||||||
|
}
|
||||||
|
|
||||||
params->size = size;
|
params->size = size;
|
||||||
FATAL_IF_NEGATIVE( size, "Couldn't find size of %s",
|
FATAL_IF_NEGATIVE( size, "Couldn't find size of %s",
|
||||||
params->filename );
|
params->filename );
|
||||||
|
@@ -195,4 +195,18 @@ class TestServeMode < Test::Unit::TestCase
|
|||||||
assert_equal 6, op.first[3], 'msync called with incorrect flags'
|
assert_equal 6, op.first[3], 'msync called with incorrect flags'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_odd_size_discs_are_truncated_to_nearest_512
|
||||||
|
# This should get rounded down to 1024
|
||||||
|
@env.blocksize = 1024 + 511
|
||||||
|
@env.writefile1('0')
|
||||||
|
@env.serve1
|
||||||
|
client = FlexNBD::FakeSource.new(@env.ip, @env.port1, 'Connecting to server failed')
|
||||||
|
begin
|
||||||
|
result = client.read_hello
|
||||||
|
assert_equal 'NBDMAGIC', result[:passwd]
|
||||||
|
assert_equal 0x00420281861253, result[:magic]
|
||||||
|
assert_equal 1024, result[:size]
|
||||||
|
client.close
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user