All of lore.kernel.org
 help / color / mirror / Atom feed
* more bdev_nr_sectors / bdev_nr_bytes conversions
@ 2021-10-19  6:20 Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes Christoph Hellwig
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-19  6:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Davidlohr Bueso, Stefan Haberland, Jan Hoeppner, linux-block,
	linux-efi, linux-s390

Hi Jens,

these somehow slipped into a different branch, so here is another
small batch.

Diffstat:
 ioctl.c          |   20 ++++++++------------
 partitions/efi.c |    2 +-
 partitions/ibm.c |   19 ++++++++++---------
 3 files changed, 19 insertions(+), 22 deletions(-)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
  2021-10-19  6:20 more bdev_nr_sectors / bdev_nr_bytes conversions Christoph Hellwig
@ 2021-10-19  6:20 ` Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 2/3] partitions/efi: use bdev_nr_bytes instead of open coding it Christoph Hellwig
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-19  6:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Davidlohr Bueso, Stefan Haberland, Jan Hoeppner, linux-block,
	linux-efi, linux-s390

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/ioctl.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/block/ioctl.c b/block/ioctl.c
index 77b1b2453f395..d6af0ac97e57e 100644
--- a/block/ioctl.c
+++ b/block/ioctl.c
@@ -132,7 +132,7 @@ static int blk_ioctl_discard(struct block_device *bdev, fmode_t mode,
 	if (len & 511)
 		return -EINVAL;
 
-	if (start + len > i_size_read(bdev->bd_inode))
+	if (start + len > bdev_nr_bytes(bdev))
 		return -EINVAL;
 
 	err = truncate_bdev_range(bdev, mode, start, start + len - 1);
@@ -164,7 +164,7 @@ static int blk_ioctl_zeroout(struct block_device *bdev, fmode_t mode,
 		return -EINVAL;
 	if (len & 511)
 		return -EINVAL;
-	if (end >= (uint64_t)i_size_read(bdev->bd_inode))
+	if (end >= (uint64_t)bdev_nr_bytes(bdev))
 		return -EINVAL;
 	if (end < start)
 		return -EINVAL;
@@ -543,7 +543,6 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	struct block_device *bdev = I_BDEV(file->f_mapping->host);
 	void __user *argp = (void __user *)arg;
 	fmode_t mode = file->f_mode;
-	loff_t size;
 	int ret;
 
 	/*
@@ -570,10 +569,9 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 		return put_long(argp,
 			(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
 	case BLKGETSIZE:
-		size = i_size_read(bdev->bd_inode);
-		if ((size >> 9) > ~0UL)
+		if (bdev_nr_sectors(bdev) > ~0UL)
 			return -EFBIG;
-		return put_ulong(argp, size >> 9);
+		return put_ulong(argp, bdev_nr_sectors(bdev));
 
 	/* The data is compatible, but the command number is different */
 	case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
@@ -581,7 +579,7 @@ long blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	case BLKBSZSET:
 		return blkdev_bszset(bdev, mode, argp);
 	case BLKGETSIZE64:
-		return put_u64(argp, i_size_read(bdev->bd_inode));
+		return put_u64(argp, bdev_nr_bytes(bdev));
 
 	/* Incompatible alignment on i386 */
 	case BLKTRACESETUP:
@@ -615,7 +613,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	struct block_device *bdev = I_BDEV(file->f_mapping->host);
 	struct gendisk *disk = bdev->bd_disk;
 	fmode_t mode = file->f_mode;
-	loff_t size;
 
 	/*
 	 * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have
@@ -641,10 +638,9 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 		return compat_put_long(argp,
 			(bdev->bd_disk->bdi->ra_pages * PAGE_SIZE) / 512);
 	case BLKGETSIZE:
-		size = i_size_read(bdev->bd_inode);
-		if ((size >> 9) > ~0UL)
+		if (bdev_nr_sectors(bdev) > ~0UL)
 			return -EFBIG;
-		return compat_put_ulong(argp, size >> 9);
+		return compat_put_ulong(argp, bdev_nr_sectors(bdev));
 
 	/* The data is compatible, but the command number is different */
 	case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
@@ -652,7 +648,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
 	case BLKBSZSET_32:
 		return blkdev_bszset(bdev, mode, argp);
 	case BLKGETSIZE64_32:
-		return put_u64(argp, i_size_read(bdev->bd_inode));
+		return put_u64(argp, bdev_nr_bytes(bdev));
 
 	/* Incompatible alignment on i386 */
 	case BLKTRACESETUP32:
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/3] partitions/efi: use bdev_nr_bytes instead of open coding it
  2021-10-19  6:20 more bdev_nr_sectors / bdev_nr_bytes conversions Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes Christoph Hellwig
@ 2021-10-19  6:20 ` Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 3/3] partitions/ibm: use bdev_nr_sectors " Christoph Hellwig
  2021-10-19 12:18 ` more bdev_nr_sectors / bdev_nr_bytes conversions Jens Axboe
  3 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-19  6:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Davidlohr Bueso, Stefan Haberland, Jan Hoeppner, linux-block,
	linux-efi, linux-s390

Use the proper helper to read the block device size.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/partitions/efi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/partitions/efi.c b/block/partitions/efi.c
index 7ca5c4c374d4d..5e9be13a56a82 100644
--- a/block/partitions/efi.c
+++ b/block/partitions/efi.c
@@ -133,7 +133,7 @@ efi_crc32(const void *buf, unsigned long len)
  */
 static u64 last_lba(struct gendisk *disk)
 {
-	return div_u64(disk->part0->bd_inode->i_size,
+	return div_u64(bdev_nr_bytes(disk->part0),
 		       queue_logical_block_size(disk->queue)) - 1ULL;
 }
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 3/3] partitions/ibm: use bdev_nr_sectors instead of open coding it
  2021-10-19  6:20 more bdev_nr_sectors / bdev_nr_bytes conversions Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes Christoph Hellwig
  2021-10-19  6:20 ` [PATCH 2/3] partitions/efi: use bdev_nr_bytes instead of open coding it Christoph Hellwig
@ 2021-10-19  6:20 ` Christoph Hellwig
  2021-10-19  7:01   ` Ard Biesheuvel
  2021-10-19 12:18 ` more bdev_nr_sectors / bdev_nr_bytes conversions Jens Axboe
  3 siblings, 1 reply; 6+ messages in thread
From: Christoph Hellwig @ 2021-10-19  6:20 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Davidlohr Bueso, Stefan Haberland, Jan Hoeppner, linux-block,
	linux-efi, linux-s390

Use the proper helper to read the block device size and switch various
places to pass the size in terms of sectors which is more practical.

Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 block/partitions/ibm.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)

diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c
index 9bca396aef4ad..d56912fe81732 100644
--- a/block/partitions/ibm.c
+++ b/block/partitions/ibm.c
@@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
 				char name[],
 				union label_t *label,
 				sector_t labelsect,
-				loff_t i_size,
+				sector_t nr_sectors,
 				dasd_information2_t *info)
 {
 	loff_t offset, geo_size, size;
@@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
 	} else {
 		/*
 		 * Formated w/o large volume support. If the sanity check
-		 * 'size based on geo == size based on i_size' is true, then
+		 * 'size based on geo == size based on br_sectors' is true, then
 		 * we can safely assume that we know the formatted size of
 		 * the disk, otherwise we need additional information
 		 * that we can only get from a real DASD device.
 		 */
 		geo_size = geo->cylinders * geo->heads
 			* geo->sectors * secperblk;
-		size = i_size >> 9;
+		size = nr_sectors;
 		if (size != geo_size) {
 			if (!info) {
 				strlcat(state->pp_buf, "\n", PAGE_SIZE);
@@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
 			if (!strcmp(info->type, "ECKD"))
 				if (geo_size < size)
 					size = geo_size;
-			/* else keep size based on i_size */
+			/* else keep size based on nr_sectors */
 		}
 	}
 	/* first and only partition starts in the first block after the label */
@@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)
 	struct gendisk *disk = state->disk;
 	struct block_device *bdev = disk->part0;
 	int blocksize, res;
-	loff_t i_size, offset, size;
+	loff_t offset, size;
+	sector_t nr_sectors;
 	dasd_information2_t *info;
 	struct hd_geometry *geo;
 	char type[5] = {0,};
@@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state)
 	blocksize = bdev_logical_block_size(bdev);
 	if (blocksize <= 0)
 		goto out_symbol;
-	i_size = i_size_read(bdev->bd_inode);
-	if (i_size == 0)
+	nr_sectors = bdev_nr_sectors(bdev);
+	if (nr_sectors == 0)
 		goto out_symbol;
 	info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
 	if (info == NULL)
@@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state)
 						   label);
 		} else if (!strncmp(type, "LNX1", 4)) {
 			res = find_lnx1_partitions(state, geo, blocksize, name,
-						   label, labelsect, i_size,
+						   label, labelsect, nr_sectors,
 						   info);
 		} else if (!strncmp(type, "CMS1", 4)) {
 			res = find_cms1_partitions(state, geo, blocksize, name,
@@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state)
 		res = 1;
 		if (info->format == DASD_FORMAT_LDL) {
 			strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
-			size = i_size >> 9;
+			size = nr_sectors;
 			offset = (info->label_block + 1) * (blocksize >> 9);
 			put_partition(state, 1, offset, size-offset);
 			strlcat(state->pp_buf, "\n", PAGE_SIZE);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 3/3] partitions/ibm: use bdev_nr_sectors instead of open coding it
  2021-10-19  6:20 ` [PATCH 3/3] partitions/ibm: use bdev_nr_sectors " Christoph Hellwig
@ 2021-10-19  7:01   ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2021-10-19  7:01 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, Davidlohr Bueso, Stefan Haberland, Jan Hoeppner,
	linux-block, linux-efi, open list:S390

On Tue, 19 Oct 2021 at 08:20, Christoph Hellwig <hch@lst.de> wrote:
>
> Use the proper helper to read the block device size and switch various
> places to pass the size in terms of sectors which is more practical.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
>  block/partitions/ibm.c | 19 ++++++++++---------
>  1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/block/partitions/ibm.c b/block/partitions/ibm.c
> index 9bca396aef4ad..d56912fe81732 100644
> --- a/block/partitions/ibm.c
> +++ b/block/partitions/ibm.c
> @@ -198,7 +198,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
>                                 char name[],
>                                 union label_t *label,
>                                 sector_t labelsect,
> -                               loff_t i_size,
> +                               sector_t nr_sectors,
>                                 dasd_information2_t *info)
>  {
>         loff_t offset, geo_size, size;
> @@ -213,14 +213,14 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
>         } else {
>                 /*
>                  * Formated w/o large volume support. If the sanity check
> -                * 'size based on geo == size based on i_size' is true, then
> +                * 'size based on geo == size based on br_sectors' is true,

nr_sectors

>                  * we can safely assume that we know the formatted size of
>                  * the disk, otherwise we need additional information
>                  * that we can only get from a real DASD device.
>                  */
>                 geo_size = geo->cylinders * geo->heads
>                         * geo->sectors * secperblk;
> -               size = i_size >> 9;
> +               size = nr_sectors;
>                 if (size != geo_size) {
>                         if (!info) {
>                                 strlcat(state->pp_buf, "\n", PAGE_SIZE);
> @@ -229,7 +229,7 @@ static int find_lnx1_partitions(struct parsed_partitions *state,
>                         if (!strcmp(info->type, "ECKD"))
>                                 if (geo_size < size)
>                                         size = geo_size;
> -                       /* else keep size based on i_size */
> +                       /* else keep size based on nr_sectors */
>                 }
>         }
>         /* first and only partition starts in the first block after the label */
> @@ -293,7 +293,8 @@ int ibm_partition(struct parsed_partitions *state)
>         struct gendisk *disk = state->disk;
>         struct block_device *bdev = disk->part0;
>         int blocksize, res;
> -       loff_t i_size, offset, size;
> +       loff_t offset, size;
> +       sector_t nr_sectors;
>         dasd_information2_t *info;
>         struct hd_geometry *geo;
>         char type[5] = {0,};
> @@ -308,8 +309,8 @@ int ibm_partition(struct parsed_partitions *state)
>         blocksize = bdev_logical_block_size(bdev);
>         if (blocksize <= 0)
>                 goto out_symbol;
> -       i_size = i_size_read(bdev->bd_inode);
> -       if (i_size == 0)
> +       nr_sectors = bdev_nr_sectors(bdev);
> +       if (nr_sectors == 0)
>                 goto out_symbol;
>         info = kmalloc(sizeof(dasd_information2_t), GFP_KERNEL);
>         if (info == NULL)
> @@ -336,7 +337,7 @@ int ibm_partition(struct parsed_partitions *state)
>                                                    label);
>                 } else if (!strncmp(type, "LNX1", 4)) {
>                         res = find_lnx1_partitions(state, geo, blocksize, name,
> -                                                  label, labelsect, i_size,
> +                                                  label, labelsect, nr_sectors,
>                                                    info);
>                 } else if (!strncmp(type, "CMS1", 4)) {
>                         res = find_cms1_partitions(state, geo, blocksize, name,
> @@ -353,7 +354,7 @@ int ibm_partition(struct parsed_partitions *state)
>                 res = 1;
>                 if (info->format == DASD_FORMAT_LDL) {
>                         strlcat(state->pp_buf, "(nonl)", PAGE_SIZE);
> -                       size = i_size >> 9;
> +                       size = nr_sectors;
>                         offset = (info->label_block + 1) * (blocksize >> 9);
>                         put_partition(state, 1, offset, size-offset);
>                         strlcat(state->pp_buf, "\n", PAGE_SIZE);
> --
> 2.30.2
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: more bdev_nr_sectors / bdev_nr_bytes conversions
  2021-10-19  6:20 more bdev_nr_sectors / bdev_nr_bytes conversions Christoph Hellwig
                   ` (2 preceding siblings ...)
  2021-10-19  6:20 ` [PATCH 3/3] partitions/ibm: use bdev_nr_sectors " Christoph Hellwig
@ 2021-10-19 12:18 ` Jens Axboe
  3 siblings, 0 replies; 6+ messages in thread
From: Jens Axboe @ 2021-10-19 12:18 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Jens Axboe, linux-efi, linux-s390, Jan Hoeppner,
	Stefan Haberland, Davidlohr Bueso, linux-block

On Tue, 19 Oct 2021 08:20:21 +0200, Christoph Hellwig wrote:
> these somehow slipped into a different branch, so here is another
> small batch.
> 
> Diffstat:
>  ioctl.c          |   20 ++++++++------------
>  partitions/efi.c |    2 +-
>  partitions/ibm.c |   19 ++++++++++---------
>  3 files changed, 19 insertions(+), 22 deletions(-)
> 
> [...]

Applied, thanks!

[1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes
      commit: 946e99373037be4841e8b42dcd136e03093c9fd5
[2/3] partitions/efi: use bdev_nr_bytes instead of open coding it
      commit: f9831b885709978ed9d16833ceeb3a2ec174a2d2
[3/3] partitions/ibm: use bdev_nr_sectors instead of open coding it
      commit: 97eeb5fc14cc4b2091df8b841a07a1ac69f2d762

Best regards,
-- 
Jens Axboe



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-10-19 12:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-19  6:20 more bdev_nr_sectors / bdev_nr_bytes conversions Christoph Hellwig
2021-10-19  6:20 ` [PATCH 1/3] block/ioctl: use bdev_nr_sectors and bdev_nr_bytes Christoph Hellwig
2021-10-19  6:20 ` [PATCH 2/3] partitions/efi: use bdev_nr_bytes instead of open coding it Christoph Hellwig
2021-10-19  6:20 ` [PATCH 3/3] partitions/ibm: use bdev_nr_sectors " Christoph Hellwig
2021-10-19  7:01   ` Ard Biesheuvel
2021-10-19 12:18 ` more bdev_nr_sectors / bdev_nr_bytes conversions Jens Axboe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.