Bug 191251 - nbd can't use devices with 2^31 or more blocks
Summary: nbd can't use devices with 2^31 or more blocks
Status: NEW
Alias: None
Product: Drivers
Classification: Unclassified
Component: Other (show other bugs)
Hardware: All Linux
: P1 normal
Assignee: drivers_other
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-12-27 14:46 UTC by Felix J. Ogris
Modified: 2016-12-27 14:46 UTC (History)
0 users

See Also:
Kernel Version: 4.8.0 4.8.14 4.9
Subsystem:
Regression: No
Bisected commit-id:


Attachments

Description Felix J. Ogris 2016-12-27 14:46:44 UTC
Symptom:
nbd can't use devices with 2^31 or more blocks, read: 2, 4, or 8 TB if using a blocksize of 1024, 2048, or 4096 bytes, respectively.

How to trigger:
# cd /tmp/
# truncate -s 2T foobar.img
# ls -la foobar.img 
-rw-r--r-- 1 root root 2199023255552 Dec 27 15:27 foobar.img
# nbd-server -d 12345 /tmp/foobar.img
(...another terminal...)
# nbd-client -b 1024 localhost 12345 /dev/nbd0
Warning: the oldstyle protocol is no longer supported.
This method now uses the newstyle protocol with a default export
Negotiation: ..size = 2097152MB
bs=1024, sz=2199023255552 bytes
# cat /sys/block/nbd0/size 
18446744069414584320

strace of ioctl()s called by nbd-client looks ok:

ioctl(4, NBD_SET_BLKSIZE, 0x400)        = 0
ioctl(4, NBD_SET_SIZE_BLOCKS, 0x80000000) = 0
write(2, "bs=1024, sz=2199023255552 bytes\n", 32bs=1024, sz=2199023255552 bytes
) = 32
ioctl(4, NBD_CLEAR_SOCK, 0x20)          = 0
ioctl(4, NBD_SET_FLAGS, 0x141)          = 0
ioctl(4, BLKROSET, [0])                 = 0
ioctl(4, NBD_SET_SOCK, 0x5)             = 0

How to fix:
4th parameter nr_blocks to nbd_size_set() in drivers/block/nbd.c should be a 64 bit type, e.g. a loff_t, and not a 32 bit signed integer as it currently is.

BR,
Felix

Note You need to log in before you can comment on or make changes to this bug.