Skip to content

Commit ac481c2

Browse files
martinkpetersenJens Axboe
authored andcommitted
block: Topology ioctls
Not all users of the topology information want to use libblkid. Provide the topology information through bdev ioctls. Also clarify sector size comments for existing BLK ioctls. Signed-off-by: Martin K. Petersen <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 61f0c1d commit ac481c2

File tree

4 files changed

+62
-7
lines changed

4 files changed

+62
-7
lines changed

block/compat_ioctl.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ static int compat_put_int(unsigned long arg, int val)
2121
return put_user(val, (compat_int_t __user *)compat_ptr(arg));
2222
}
2323

24+
static int compat_put_uint(unsigned long arg, unsigned int val)
25+
{
26+
return put_user(val, (compat_uint_t __user *)compat_ptr(arg));
27+
}
28+
2429
static int compat_put_long(unsigned long arg, long val)
2530
{
2631
return put_user(val, (compat_long_t __user *)compat_ptr(arg));
@@ -734,6 +739,14 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
734739
switch (cmd) {
735740
case HDIO_GETGEO:
736741
return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
742+
case BLKPBSZGET:
743+
return compat_put_uint(arg, bdev_physical_block_size(bdev));
744+
case BLKIOMIN:
745+
return compat_put_uint(arg, bdev_io_min(bdev));
746+
case BLKIOOPT:
747+
return compat_put_uint(arg, bdev_io_opt(bdev));
748+
case BLKALIGNOFF:
749+
return compat_put_int(arg, bdev_alignment_offset(bdev));
737750
case BLKFLSBUF:
738751
case BLKROSET:
739752
case BLKDISCARD:

block/ioctl.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ static int put_int(unsigned long arg, int val)
138138
return put_user(val, (int __user *)arg);
139139
}
140140

141+
static int put_uint(unsigned long arg, unsigned int val)
142+
{
143+
return put_user(val, (unsigned int __user *)arg);
144+
}
145+
141146
static int put_long(unsigned long arg, long val)
142147
{
143148
return put_user(val, (long __user *)arg);
@@ -263,10 +268,18 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
263268
return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
264269
case BLKROGET:
265270
return put_int(arg, bdev_read_only(bdev) != 0);
266-
case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */
271+
case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
267272
return put_int(arg, block_size(bdev));
268-
case BLKSSZGET: /* get block device hardware sector size */
273+
case BLKSSZGET: /* get block device logical block size */
269274
return put_int(arg, bdev_logical_block_size(bdev));
275+
case BLKPBSZGET: /* get block device physical block size */
276+
return put_uint(arg, bdev_physical_block_size(bdev));
277+
case BLKIOMIN:
278+
return put_uint(arg, bdev_io_min(bdev));
279+
case BLKIOOPT:
280+
return put_uint(arg, bdev_io_opt(bdev));
281+
case BLKALIGNOFF:
282+
return put_int(arg, bdev_alignment_offset(bdev));
270283
case BLKSECTGET:
271284
return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev)));
272285
case BLKRASET:

include/linux/blkdev.h

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,25 +1081,37 @@ static inline unsigned int queue_physical_block_size(struct request_queue *q)
10811081
return q->limits.physical_block_size;
10821082
}
10831083

1084+
static inline int bdev_physical_block_size(struct block_device *bdev)
1085+
{
1086+
return queue_physical_block_size(bdev_get_queue(bdev));
1087+
}
1088+
10841089
static inline unsigned int queue_io_min(struct request_queue *q)
10851090
{
10861091
return q->limits.io_min;
10871092
}
10881093

1094+
static inline int bdev_io_min(struct block_device *bdev)
1095+
{
1096+
return queue_io_min(bdev_get_queue(bdev));
1097+
}
1098+
10891099
static inline unsigned int queue_io_opt(struct request_queue *q)
10901100
{
10911101
return q->limits.io_opt;
10921102
}
10931103

1104+
static inline int bdev_io_opt(struct block_device *bdev)
1105+
{
1106+
return queue_io_opt(bdev_get_queue(bdev));
1107+
}
1108+
10941109
static inline int queue_alignment_offset(struct request_queue *q)
10951110
{
1096-
if (q && q->limits.misaligned)
1111+
if (q->limits.misaligned)
10971112
return -1;
10981113

1099-
if (q && q->limits.alignment_offset)
1100-
return q->limits.alignment_offset;
1101-
1102-
return 0;
1114+
return q->limits.alignment_offset;
11031115
}
11041116

11051117
static inline int queue_sector_alignment_offset(struct request_queue *q,
@@ -1109,6 +1121,19 @@ static inline int queue_sector_alignment_offset(struct request_queue *q,
11091121
& (q->limits.io_min - 1);
11101122
}
11111123

1124+
static inline int bdev_alignment_offset(struct block_device *bdev)
1125+
{
1126+
struct request_queue *q = bdev_get_queue(bdev);
1127+
1128+
if (q->limits.misaligned)
1129+
return -1;
1130+
1131+
if (bdev != bdev->bd_contains)
1132+
return bdev->bd_part->alignment_offset;
1133+
1134+
return q->limits.alignment_offset;
1135+
}
1136+
11121137
static inline int queue_dma_alignment(struct request_queue *q)
11131138
{
11141139
return q ? q->dma_alignment : 511;

include/linux/fs.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ struct inodes_stat_t {
300300
#define BLKTRACESTOP _IO(0x12,117)
301301
#define BLKTRACETEARDOWN _IO(0x12,118)
302302
#define BLKDISCARD _IO(0x12,119)
303+
#define BLKIOMIN _IO(0x12,120)
304+
#define BLKIOOPT _IO(0x12,121)
305+
#define BLKALIGNOFF _IO(0x12,122)
306+
#define BLKPBSZGET _IO(0x12,123)
303307

304308
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
305309
#define FIBMAP _IO(0x00,1) /* bmap access */

0 commit comments

Comments
 (0)