nbd: set the logical and physical blocksize properly
Subsystems (2)
PATCH 1/1 nbd: set the logical and physical blocksize properly
We noticed when trying to do O_DIRECT to an export on the server side that we were getting requests smaller than the 4k sectorsize of the device. This is because the client isn't setting the logical and physical blocksizes properly for the underlying device. Fix this up by setting the queue blocksizes and then calling bd_set_size.
--- drivers/block/nbd.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
drivers/block/nbd.c +16 -23
@@ -183,7 +183,7 @@ static int nbd_clear_reconnect(struct nbd_device *nbd)static int nbd_size_clear (struct nbd_device *nbd,struct block_device *bdev) { - bdev->bd_inode->i_size =0 ; +bd_set_size (bdev,0 );set_capacity (nbd->disk,0 );kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE );
@@ -192,29 +192,20 @@ static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev)static void nbd_size_update (struct nbd_device *nbd,struct block_device *bdev) { -if (!nbd_is_connected (nbd)) -return ; - - bdev->bd_inode->i_size = nbd->bytesize; +blk_queue_logical_block_size (nbd->disk->queue, nbd->blksize); +blk_queue_physical_block_size (nbd->disk->queue, nbd->blksize); +bd_set_size (bdev, nbd->bytesize);set_capacity (nbd->disk, nbd->bytesize >>9 );kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE ); } -static int nbd_size_set (struct nbd_device *nbd,struct block_device *bdev, +static void nbd_size_set (struct nbd_device *nbd,struct block_device *bdev,loff_t blocksize,loff_t nr_blocks) { -int ret; - - ret =set_blocksize (bdev, blocksize); -if (ret) -return ret; - nbd->blksize = blocksize; nbd->bytesize = blocksize * nr_blocks; - -nbd_size_update (nbd, bdev); - -return 0 ; +if (nbd_is_connected (nbd)) +nbd_size_update (nbd, bdev); }static void nbd_end_request (struct nbd_cmd *cmd)
@@ -875,6 +866,7 @@ static void send_disconnects(struct nbd_device *nbd)static int nbd_disconnect (struct nbd_device *nbd,struct block_device *bdev) { +printk (KERN_ERR "%u is the blocksize at disconnect\n" ,bdev_logical_block_size (bdev));dev_info (disk_to_dev (nbd->disk),"NBD_DISCONNECT\n" );if (!nbd_socks_get_unless_zero (nbd))return -EINVAL ;
@@ -997,15 +989,16 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,case NBD_SET_SOCK :return nbd_add_socket (nbd, bdev, arg);case NBD_SET_BLKSIZE : -return nbd_size_set (nbd, bdev, arg, -div_s64 (nbd->bytesize, arg)); +nbd_size_set (nbd, bdev, arg, +div_s64 (nbd->bytesize, arg)); +return 0 ;case NBD_SET_SIZE : -return nbd_size_set (nbd, bdev, nbd->blksize, -div_s64 (arg, nbd->blksize)); - +nbd_size_set (nbd, bdev, nbd->blksize, +div_s64 (arg, nbd->blksize)); +return 0 ;case NBD_SET_SIZE_BLOCKS : -return nbd_size_set (nbd, bdev, nbd->blksize, arg); - +nbd_size_set (nbd, bdev, nbd->blksize, arg); +return 0 ;case NBD_SET_TIMEOUT : nbd->tag_set.timeout = arg *HZ ;return 0 ;
Signature · 1 line
2.7.4
Quoted 8 lines · Josef Bacik
We noticed when trying to do
O_DIRECTto an export on the server side that we were getting requests smaller than the 4k sectorsize of the device. This is because the client isn't setting the logical and physical blocksizes properly for the underlying device. Fix this up by setting the queue blocksizes and then callingbd_set_size.
Interesting. Some input into the info extension (re blocksizes) would definitely be appreciated.
Signature · 1 line
Alex Bligh
Quoted 10 lines · Alex Bligh
Quoted 10 lines · Josef Bacik
We noticed when trying to do
O_DIRECTto an export on the server side
that we were getting requests smaller than the 4k sectorsize of the device. This is because the client isn't setting the logical and physical blocksizes properly for the underlying device. Fix this up by
setting the queue blocksizes and then callingbd_set_size.
Quoted 3 lines
Interesting. Some input into the info extension (re blocksizes) would definitely be appreciated.
What do you mean? Right now the client is just calling NBD_SET_BLKSIZE with 4k blocksize since all of our devices are 4k drives. Thanks,
Josef
Quoted 11 lines · Josef Bacik
Quoted 10 lines · Alex Bligh
Quoted 10 lines · Josef Bacik
We noticed when trying to do
O_DIRECTto an export on the server side
that we were getting requests smaller than the 4k sectorsize of the device.��This is because the client isn't setting the logical and physical blocksizes properly for the underlying device.��Fix this up by
setting the queue blocksizes and then callingbd_set_size.
Quoted 6 lines
Quoted 3 lines
Interesting. Some input into the info extension (re blocksizes) would definitely be appreciated.
What do you mean? �Right now the client is just calling�NBD_SET_BLKSIZE with 4k blocksize since all of our devices are 4k drives. �Thanks,
He's talking about
<https://github.com/NetworkBlockDevice/nbd/blob/extension-info/doc/proto.md#block-size-constraints>,
which is a protocol extension that hasn't been implemented yet but would be relevant to this patch.
Signature · 4 lines
< ron> I mean, the main *practical* problem with C++, is there's like a dozen
people in the world who think they really understand all of its rules,
and pretty much all of them are just lying to themselves too.
-- #debian-devel, OFTC, 2016-02-12Quoted 4 lines · Wouter Verhelst
=20
Quoted 1 line
Quoted 1 line
Interesting. Some input into the info extension (re blocksizes) =
would
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
definitely be appreciated.
=20=20
What do you mean? Right now the client is just calling =
NBD_SET_BLKSIZE
Quoted 4 lines
Quoted 1 line
with 4k blocksize since all of our devices are 4k drives. Thanks,
=20
He's talking about
=
<https://github.com/NetworkBlockDevice/nbd/blob/extension-info/doc/proto.m=
d#block-size-constraints>,
Quoted 1 line
which is a protocol extension that hasn't been implemented yet but =
would
Quoted 1 line
be relevant to this patch.
Indeed. Specifically, review of the patch from a kernel perspective would be useful.
--=20
Alex Bligh
PATCH v2 1/1 nbd: set the logical and physical blocksize properly
In reply to Josef BacikWe noticed when trying to do O_DIRECT to an export on the server side that we were getting requests smaller than the 4k sectorsize of the device. This is because the client isn't setting the logical and physical blocksizes properly for the underlying device. Fix this up by setting the queue blocksizes and then calling bd_set_size.
---V1->V2:
-remove an debug printk that I forgot to delete.
drivers/block/nbd.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-)
drivers/block/nbd.c +15 -23
@@ -152,7 +152,7 @@ static void nbd_socks_put(struct nbd_device *nbd)static int nbd_size_clear (struct nbd_device *nbd,struct block_device *bdev) { - bdev->bd_inode->i_size =0 ; +bd_set_size (bdev,0 );set_capacity (nbd->disk,0 );kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE );
@@ -161,29 +161,20 @@ static int nbd_size_clear(struct nbd_device *nbd, struct block_device *bdev)static void nbd_size_update (struct nbd_device *nbd,struct block_device *bdev) { -if (!nbd_is_connected (nbd)) -return ; - - bdev->bd_inode->i_size = nbd->bytesize; +blk_queue_logical_block_size (nbd->disk->queue, nbd->blksize); +blk_queue_physical_block_size (nbd->disk->queue, nbd->blksize); +bd_set_size (bdev, nbd->bytesize);set_capacity (nbd->disk, nbd->bytesize >>9 );kobject_uevent (&nbd_to_dev (nbd)->kobj,KOBJ_CHANGE ); } -static int nbd_size_set (struct nbd_device *nbd,struct block_device *bdev, +static void nbd_size_set (struct nbd_device *nbd,struct block_device *bdev,loff_t blocksize,loff_t nr_blocks) { -int ret; - - ret =set_blocksize (bdev, blocksize); -if (ret) -return ret; - nbd->blksize = blocksize; nbd->bytesize = blocksize * nr_blocks; - -nbd_size_update (nbd, bdev); - -return 0 ; +if (nbd_is_connected (nbd)) +nbd_size_update (nbd, bdev); }static void nbd_end_request (struct nbd_cmd *cmd)
@@ -926,15 +917,16 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,case NBD_SET_SOCK :return nbd_add_socket (nbd, bdev, arg);case NBD_SET_BLKSIZE : -return nbd_size_set (nbd, bdev, arg, -div_s64 (nbd->bytesize, arg)); +nbd_size_set (nbd, bdev, arg, +div_s64 (nbd->bytesize, arg)); +return 0 ;case NBD_SET_SIZE : -return nbd_size_set (nbd, bdev, nbd->blksize, -div_s64 (arg, nbd->blksize)); - +nbd_size_set (nbd, bdev, nbd->blksize, +div_s64 (arg, nbd->blksize)); +return 0 ;case NBD_SET_SIZE_BLOCKS : -return nbd_size_set (nbd, bdev, nbd->blksize, arg); - +nbd_size_set (nbd, bdev, nbd->blksize, arg); +return 0 ;case NBD_SET_TIMEOUT : nbd->tag_set.timeout = arg *HZ ;return 0 ;
Signature · 1 line
2.7.4