Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1216160 > unrolled thread

[PATCH] null_blk: fix wrong capacity when bs is not 512 bytes

Started byMatias Bjørling <m@bjorling.me>
First post2015-08-31 14:20 +0200
Last post2015-09-02 20:50 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] null_blk: fix wrong capacity when bs is not 512 bytes Matias Bjørling <m@bjorling.me> - 2015-08-31 14:20 +0200
    Re: [PATCH] null_blk: fix wrong capacity when bs is not 512 bytes Ross Zwisler <ross.zwisler@linux.intel.com> - 2015-09-02 20:50 +0200

#1216160 — [PATCH] null_blk: fix wrong capacity when bs is not 512 bytes

FromMatias Bjørling <m@bjorling.me>
Date2015-08-31 14:20 +0200
Subject[PATCH] null_blk: fix wrong capacity when bs is not 512 bytes
Message-ID<q3we5-7pO-11@gated-at.bofh.it>
set_capacity() sets device's capacity using 512 bytes sectors.
null_blk calculates the number of sectors by size / bs, which
set_capacity is called with. This led to null_blk exposing the
wrong number of sectors when bs is not 512 bytes.

Signed-off-by: Matias Bjørling <m@bjorling.me>
---
 drivers/block/null_blk.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index 6f9b753..bf8f764 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -588,8 +588,7 @@ static int null_add_dev(void)
 	blk_queue_physical_block_size(nullb->q, bs);
 
 	size = gb * 1024 * 1024 * 1024ULL;
-	sector_div(size, bs);
-	set_capacity(disk, size);
+	set_capacity(disk, size >> 9);
 
 	disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
 	disk->major		= null_major;
-- 
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [next] | [standalone]


#1217799

FromRoss Zwisler <ross.zwisler@linux.intel.com>
Date2015-09-02 20:50 +0200
Message-ID<q4lgB-4Zd-1@gated-at.bofh.it>
In reply to#1216160
On Mon, Aug 31, 2015 at 02:17:31PM +0200, Matias Bjørling wrote:
> set_capacity() sets device's capacity using 512 bytes sectors.
> null_blk calculates the number of sectors by size / bs, which
> set_capacity is called with. This led to null_blk exposing the
> wrong number of sectors when bs is not 512 bytes.
> 
> Signed-off-by: Matias Bjørling <m@bjorling.me>
> ---
>  drivers/block/null_blk.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
> index 6f9b753..bf8f764 100644
> --- a/drivers/block/null_blk.c
> +++ b/drivers/block/null_blk.c
> @@ -588,8 +588,7 @@ static int null_add_dev(void)
>  	blk_queue_physical_block_size(nullb->q, bs);
>  
>  	size = gb * 1024 * 1024 * 1024ULL;
> -	sector_div(size, bs);
> -	set_capacity(disk, size);
> +	set_capacity(disk, size >> 9);
>  
>  	disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
>  	disk->major		= null_major;

Looks correct.

Reviewed-by: Ross Zwisler <ross.zwisler@linux.intel.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web