@@ -296,44 +296,37 @@ static void nbd_size_clear(struct nbd_device *nbd)
296296 }
297297}
298298
299- static void nbd_size_update (struct nbd_device * nbd )
299+ static void nbd_set_size (struct nbd_device * nbd , loff_t bytesize ,
300+ loff_t blksize )
300301{
301- struct nbd_config * config = nbd -> config ;
302- sector_t nr_sectors = config -> bytesize >> 9 ;
303302 struct block_device * bdev ;
304303
304+ nbd -> config -> bytesize = bytesize ;
305+ nbd -> config -> blksize = blksize ;
306+
305307 if (!nbd -> task_recv )
306308 return ;
307309
308- if (config -> flags & NBD_FLAG_SEND_TRIM ) {
309- nbd -> disk -> queue -> limits .discard_granularity = config -> blksize ;
310- nbd -> disk -> queue -> limits .discard_alignment = config -> blksize ;
310+ if (nbd -> config -> flags & NBD_FLAG_SEND_TRIM ) {
311+ nbd -> disk -> queue -> limits .discard_granularity = blksize ;
312+ nbd -> disk -> queue -> limits .discard_alignment = blksize ;
311313 blk_queue_max_discard_sectors (nbd -> disk -> queue , UINT_MAX );
312314 }
313- blk_queue_logical_block_size (nbd -> disk -> queue , config -> blksize );
314- blk_queue_physical_block_size (nbd -> disk -> queue , config -> blksize );
315+ blk_queue_logical_block_size (nbd -> disk -> queue , blksize );
316+ blk_queue_physical_block_size (nbd -> disk -> queue , blksize );
315317
316- set_capacity (nbd -> disk , nr_sectors );
318+ set_capacity (nbd -> disk , bytesize >> 9 );
317319 bdev = bdget_disk (nbd -> disk , 0 );
318320 if (bdev ) {
319321 if (bdev -> bd_disk )
320- bd_set_nr_sectors (bdev , nr_sectors );
322+ bd_set_nr_sectors (bdev , bytesize >> 9 );
321323 else
322324 set_bit (GD_NEED_PART_SCAN , & nbd -> disk -> state );
323325 bdput (bdev );
324326 }
325327 kobject_uevent (& nbd_to_dev (nbd )-> kobj , KOBJ_CHANGE );
326328}
327329
328- static void nbd_size_set (struct nbd_device * nbd , loff_t blocksize ,
329- loff_t nr_blocks )
330- {
331- struct nbd_config * config = nbd -> config ;
332- config -> blksize = blocksize ;
333- config -> bytesize = blocksize * nr_blocks ;
334- nbd_size_update (nbd );
335- }
336-
337330static void nbd_complete_rq (struct request * req )
338331{
339332 struct nbd_cmd * cmd = blk_mq_rq_to_pdu (req );
@@ -1311,7 +1304,7 @@ static int nbd_start_device(struct nbd_device *nbd)
13111304 args -> index = i ;
13121305 queue_work (nbd -> recv_workq , & args -> work );
13131306 }
1314- nbd_size_update (nbd );
1307+ nbd_set_size (nbd , config -> bytesize , config -> blksize );
13151308 return error ;
13161309}
13171310
@@ -1390,15 +1383,14 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
13901383 arg = NBD_DEF_BLKSIZE ;
13911384 if (!nbd_is_valid_blksize (arg ))
13921385 return - EINVAL ;
1393- nbd_size_set (nbd , arg ,
1394- div_s64 (config -> bytesize , arg ));
1386+ nbd_set_size (nbd , config -> bytesize , arg );
13951387 return 0 ;
13961388 case NBD_SET_SIZE :
1397- nbd_size_set (nbd , config -> blksize ,
1398- div_s64 (arg , config -> blksize ));
1389+ nbd_set_size (nbd , arg , config -> blksize );
13991390 return 0 ;
14001391 case NBD_SET_SIZE_BLOCKS :
1401- nbd_size_set (nbd , config -> blksize , arg );
1392+ nbd_set_size (nbd , arg * config -> blksize ,
1393+ config -> blksize );
14021394 return 0 ;
14031395 case NBD_SET_TIMEOUT :
14041396 nbd_set_cmd_timeout (nbd , arg );
@@ -1828,7 +1820,7 @@ static int nbd_genl_size_set(struct genl_info *info, struct nbd_device *nbd)
18281820 }
18291821
18301822 if (bytes != config -> bytesize || bsize != config -> blksize )
1831- nbd_size_set (nbd , bsize , div64_u64 ( bytes , bsize ) );
1823+ nbd_set_size (nbd , bytes , bsize );
18321824 return 0 ;
18331825}
18341826
0 commit comments