Commit 233bde21 authored by Bart Van Assche's avatar Bart Van Assche Committed by Jens Axboe

block: Move SECTOR_SIZE and SECTOR_SHIFT definitions into <linux/blkdev.h>

It happens often while I'm preparing a patch for a block driver that
I'm wondering: is a definition of SECTOR_SIZE and/or SECTOR_SHIFT
available for this driver? Do I have to introduce definitions of these
constants before I can use these constants? To avoid this confusion,
move the existing definitions of SECTOR_SIZE and SECTOR_SHIFT into the
<linux/blkdev.h> header file such that these become available for all
block drivers. Make the SECTOR_SIZE definition in the uapi msdos_fs.h
header file conditional to avoid that including that header file after
<linux/blkdev.h> causes the compiler to complain about a SECTOR_SIZE
redefinition.

Note: the SECTOR_SIZE / SECTOR_SHIFT / SECTOR_BITS definitions have
not been removed from uapi header files nor from NAND drivers in
which these constants are used for another purpose than converting
block layer offsets and sizes into a number of sectors.

Cc: David S. Miller <davem@davemloft.net>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Dan Williams <dan.j.williams@intel.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Nitin Gupta <ngupta@vflare.org>
Reviewed-by: default avatarSergey Senozhatsky <sergey.senozhatsky@gmail.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJohannes Thumshirn <jthumshirn@suse.de>
Reviewed-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarBart Van Assche <bart.vanassche@wdc.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent ec6dcf63
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include <platform/simcall.h> #include <platform/simcall.h>
#define SIMDISK_MAJOR 240 #define SIMDISK_MAJOR 240
#define SECTOR_SHIFT 9
#define SIMDISK_MINORS 1 #define SIMDISK_MINORS 1
#define MAX_SIMDISK_COUNT 10 #define MAX_SIMDISK_COUNT 10
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include <linux/uaccess.h> #include <linux/uaccess.h>
#define SECTOR_SHIFT 9
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) #define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT) #define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
......
...@@ -16,10 +16,8 @@ ...@@ -16,10 +16,8 @@
#include <linux/badblocks.h> #include <linux/badblocks.h>
#include <linux/fault-inject.h> #include <linux/fault-inject.h>
#define SECTOR_SHIFT 9
#define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) #define PAGE_SECTORS_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT) #define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
#define SECTOR_MASK (PAGE_SECTORS - 1) #define SECTOR_MASK (PAGE_SECTORS - 1)
#define FREE_BATCH 16 #define FREE_BATCH 16
......
...@@ -50,15 +50,6 @@ ...@@ -50,15 +50,6 @@
#define RBD_DEBUG /* Activate rbd_assert() calls */ #define RBD_DEBUG /* Activate rbd_assert() calls */
/*
* The basic unit of block I/O is a sector. It is interpreted in a
* number of contexts in Linux (blk, bio, genhd), but the default is
* universally 512 bytes. These symbols are just slightly more
* meaningful than the bare numbers they represent.
*/
#define SECTOR_SHIFT 9
#define SECTOR_SIZE (1ULL << SECTOR_SHIFT)
/* /*
* Increment the given counter and return its updated value. * Increment the given counter and return its updated value.
* If the counter is already 0 it will not be incremented. * If the counter is already 0 it will not be incremented.
......
...@@ -37,7 +37,6 @@ static const size_t max_zpage_size = PAGE_SIZE / 4 * 3; ...@@ -37,7 +37,6 @@ static const size_t max_zpage_size = PAGE_SIZE / 4 * 3;
/*-- End of configurable params */ /*-- End of configurable params */
#define SECTOR_SHIFT 9
#define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT) #define SECTORS_PER_PAGE_SHIFT (PAGE_SHIFT - SECTOR_SHIFT)
#define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT) #define SECTORS_PER_PAGE (1 << SECTORS_PER_PAGE_SHIFT)
#define ZRAM_LOGICAL_BLOCK_SHIFT 12 #define ZRAM_LOGICAL_BLOCK_SHIFT 12
......
...@@ -712,7 +712,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) ...@@ -712,7 +712,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
struct request_queue *q = drive->queue; struct request_queue *q = drive->queue;
int write = rq_data_dir(rq) == WRITE; int write = rq_data_dir(rq) == WRITE;
unsigned short sectors_per_frame = unsigned short sectors_per_frame =
queue_logical_block_size(q) >> SECTOR_BITS; queue_logical_block_size(q) >> SECTOR_SHIFT;
ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, " ide_debug_log(IDE_DBG_RQ, "rq->cmd[0]: 0x%x, rq->cmd_flags: 0x%x, "
"secs_per_frame: %u", "secs_per_frame: %u",
...@@ -919,7 +919,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, ...@@ -919,7 +919,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
* end up being bogus. * end up being bogus.
*/ */
blocklen = be32_to_cpu(capbuf.blocklen); blocklen = be32_to_cpu(capbuf.blocklen);
blocklen = (blocklen >> SECTOR_BITS) << SECTOR_BITS; blocklen = (blocklen >> SECTOR_SHIFT) << SECTOR_SHIFT;
switch (blocklen) { switch (blocklen) {
case 512: case 512:
case 1024: case 1024:
...@@ -935,7 +935,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, ...@@ -935,7 +935,7 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
} }
*capacity = 1 + be32_to_cpu(capbuf.lba); *capacity = 1 + be32_to_cpu(capbuf.lba);
*sectors_per_frame = blocklen >> SECTOR_BITS; *sectors_per_frame = blocklen >> SECTOR_SHIFT;
ide_debug_log(IDE_DBG_PROBE, "cap: %lu, sectors_per_frame: %lu", ide_debug_log(IDE_DBG_PROBE, "cap: %lu, sectors_per_frame: %lu",
*capacity, *sectors_per_frame); *capacity, *sectors_per_frame);
...@@ -1012,7 +1012,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) ...@@ -1012,7 +1012,7 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
drive->probed_capacity = toc->capacity * sectors_per_frame; drive->probed_capacity = toc->capacity * sectors_per_frame;
blk_queue_logical_block_size(drive->queue, blk_queue_logical_block_size(drive->queue,
sectors_per_frame << SECTOR_BITS); sectors_per_frame << SECTOR_SHIFT);
/* first read just the header, so we know how long the TOC is */ /* first read just the header, so we know how long the TOC is */
stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr,
......
...@@ -21,11 +21,7 @@ ...@@ -21,11 +21,7 @@
/************************************************************************/ /************************************************************************/
#define SECTOR_BITS 9 #define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_SHIFT)
#ifndef SECTOR_SIZE
#define SECTOR_SIZE (1 << SECTOR_BITS)
#endif
#define SECTORS_PER_FRAME (CD_FRAMESIZE >> SECTOR_BITS)
#define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32) #define SECTOR_BUFFER_SIZE (CD_FRAMESIZE * 32)
/* Capabilities Page size including 8 bytes of Mode Page Header */ /* Capabilities Page size including 8 bytes of Mode Page Header */
......
...@@ -29,7 +29,6 @@ enum { ...@@ -29,7 +29,6 @@ enum {
* BTT instance * BTT instance
*/ */
ND_MAX_LANES = 256, ND_MAX_LANES = 256,
SECTOR_SHIFT = 9,
INT_LBASIZE_ALIGNMENT = 64, INT_LBASIZE_ALIGNMENT = 64,
NVDIMM_IO_ATOMIC = 1, NVDIMM_IO_ATOMIC = 1,
}; };
......
...@@ -178,9 +178,6 @@ ...@@ -178,9 +178,6 @@
#define MSG_SIZE 34 /* size of message structure */ #define MSG_SIZE 34 /* size of message structure */
#define MSG_REQUEST 0 /* async. event: message */ #define MSG_REQUEST 0 /* async. event: message */
/* cacheservice defines */
#define SECTOR_SIZE 0x200 /* always 512 bytes per sec. */
/* DPMEM constants */ /* DPMEM constants */
#define DPMEM_MAGIC 0xC0FFEE11 #define DPMEM_MAGIC 0xC0FFEE11
#define IC_HEADER_BYTES 48 #define IC_HEADER_BYTES 48
......
...@@ -1021,6 +1021,19 @@ static inline struct request_queue *bdev_get_queue(struct block_device *bdev) ...@@ -1021,6 +1021,19 @@ static inline struct request_queue *bdev_get_queue(struct block_device *bdev)
return bdev->bd_disk->queue; /* this is never NULL */ return bdev->bd_disk->queue; /* this is never NULL */
} }
/*
* The basic unit of block I/O is a sector. It is used in a number of contexts
* in Linux (blk, bio, genhd). The size of one sector is 512 = 2**9
* bytes. Variables of type sector_t represent an offset or size that is a
* multiple of 512 bytes. Hence these two constants.
*/
#ifndef SECTOR_SHIFT
#define SECTOR_SHIFT 9
#endif
#ifndef SECTOR_SIZE
#define SECTOR_SIZE (1 << SECTOR_SHIFT)
#endif
/* /*
* blk_rq_pos() : the current sector * blk_rq_pos() : the current sector
* blk_rq_bytes() : bytes left in the entire request * blk_rq_bytes() : bytes left in the entire request
...@@ -1048,12 +1061,12 @@ extern unsigned int blk_rq_err_bytes(const struct request *rq); ...@@ -1048,12 +1061,12 @@ extern unsigned int blk_rq_err_bytes(const struct request *rq);
static inline unsigned int blk_rq_sectors(const struct request *rq) static inline unsigned int blk_rq_sectors(const struct request *rq)
{ {
return blk_rq_bytes(rq) >> 9; return blk_rq_bytes(rq) >> SECTOR_SHIFT;
} }
static inline unsigned int blk_rq_cur_sectors(const struct request *rq) static inline unsigned int blk_rq_cur_sectors(const struct request *rq)
{ {
return blk_rq_cur_bytes(rq) >> 9; return blk_rq_cur_bytes(rq) >> SECTOR_SHIFT;
} }
static inline unsigned int blk_rq_zone_no(struct request *rq) static inline unsigned int blk_rq_zone_no(struct request *rq)
...@@ -1083,7 +1096,8 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q, ...@@ -1083,7 +1096,8 @@ static inline unsigned int blk_queue_get_max_sectors(struct request_queue *q,
int op) int op)
{ {
if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE)) if (unlikely(op == REQ_OP_DISCARD || op == REQ_OP_SECURE_ERASE))
return min(q->limits.max_discard_sectors, UINT_MAX >> 9); return min(q->limits.max_discard_sectors,
UINT_MAX >> SECTOR_SHIFT);
if (unlikely(op == REQ_OP_WRITE_SAME)) if (unlikely(op == REQ_OP_WRITE_SAME))
return q->limits.max_write_same_sectors; return q->limits.max_write_same_sectors;
...@@ -1395,16 +1409,21 @@ extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, ...@@ -1395,16 +1409,21 @@ extern int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector,
static inline int sb_issue_discard(struct super_block *sb, sector_t block, static inline int sb_issue_discard(struct super_block *sb, sector_t block,
sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags) sector_t nr_blocks, gfp_t gfp_mask, unsigned long flags)
{ {
return blkdev_issue_discard(sb->s_bdev, block << (sb->s_blocksize_bits - 9), return blkdev_issue_discard(sb->s_bdev,
nr_blocks << (sb->s_blocksize_bits - 9), block << (sb->s_blocksize_bits -
SECTOR_SHIFT),
nr_blocks << (sb->s_blocksize_bits -
SECTOR_SHIFT),
gfp_mask, flags); gfp_mask, flags);
} }
static inline int sb_issue_zeroout(struct super_block *sb, sector_t block, static inline int sb_issue_zeroout(struct super_block *sb, sector_t block,
sector_t nr_blocks, gfp_t gfp_mask) sector_t nr_blocks, gfp_t gfp_mask)
{ {
return blkdev_issue_zeroout(sb->s_bdev, return blkdev_issue_zeroout(sb->s_bdev,
block << (sb->s_blocksize_bits - 9), block << (sb->s_blocksize_bits -
nr_blocks << (sb->s_blocksize_bits - 9), SECTOR_SHIFT),
nr_blocks << (sb->s_blocksize_bits -
SECTOR_SHIFT),
gfp_mask, 0); gfp_mask, 0);
} }
...@@ -1511,7 +1530,8 @@ static inline int queue_alignment_offset(struct request_queue *q) ...@@ -1511,7 +1530,8 @@ static inline int queue_alignment_offset(struct request_queue *q)
static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector) static inline int queue_limit_alignment_offset(struct queue_limits *lim, sector_t sector)
{ {
unsigned int granularity = max(lim->physical_block_size, lim->io_min); unsigned int granularity = max(lim->physical_block_size, lim->io_min);
unsigned int alignment = sector_div(sector, granularity >> 9) << 9; unsigned int alignment = sector_div(sector, granularity >> SECTOR_SHIFT)
<< SECTOR_SHIFT;
return (granularity + lim->alignment_offset - alignment) % granularity; return (granularity + lim->alignment_offset - alignment) % granularity;
} }
...@@ -1545,8 +1565,8 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector ...@@ -1545,8 +1565,8 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
return 0; return 0;
/* Why are these in bytes, not sectors? */ /* Why are these in bytes, not sectors? */
alignment = lim->discard_alignment >> 9; alignment = lim->discard_alignment >> SECTOR_SHIFT;
granularity = lim->discard_granularity >> 9; granularity = lim->discard_granularity >> SECTOR_SHIFT;
if (!granularity) if (!granularity)
return 0; return 0;
...@@ -1557,7 +1577,7 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector ...@@ -1557,7 +1577,7 @@ static inline int queue_limit_discard_alignment(struct queue_limits *lim, sector
offset = (granularity + alignment - offset) % granularity; offset = (granularity + alignment - offset) % granularity;
/* Turn it back into bytes, gaah */ /* Turn it back into bytes, gaah */
return offset << 9; return offset << SECTOR_SHIFT;
} }
static inline int bdev_discard_alignment(struct block_device *bdev) static inline int bdev_discard_alignment(struct block_device *bdev)
......
...@@ -542,8 +542,6 @@ do { \ ...@@ -542,8 +542,6 @@ do { \
#define DMEMIT(x...) sz += ((sz >= maxlen) ? \ #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
0 : scnprintf(result + sz, maxlen - sz, x)) 0 : scnprintf(result + sz, maxlen - sz, x))
#define SECTOR_SHIFT 9
/* /*
* Definitions of return values from target end_io function. * Definitions of return values from target end_io function.
*/ */
......
...@@ -165,7 +165,6 @@ struct ide_io_ports { ...@@ -165,7 +165,6 @@ struct ide_io_ports {
*/ */
#define PARTN_BITS 6 /* number of minor dev bits for partitions */ #define PARTN_BITS 6 /* number of minor dev bits for partitions */
#define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */ #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
#define SECTOR_SIZE 512
/* /*
* Timeouts for various operations: * Timeouts for various operations:
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
* The MS-DOS filesystem constants/structures * The MS-DOS filesystem constants/structures
*/ */
#ifndef SECTOR_SIZE
#define SECTOR_SIZE 512 /* sector size (bytes) */ #define SECTOR_SIZE 512 /* sector size (bytes) */
#endif
#define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */ #define SECTOR_BITS 9 /* log2(SECTOR_SIZE) */
#define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */ #define MSDOS_DPB (MSDOS_DPS) /* dir entries per block */
#define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */ #define MSDOS_DPB_BITS 4 /* log2(MSDOS_DPB) */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment