Commit ac481c20 authored by Martin K. Petersen's avatar Martin K. Petersen Committed by Jens Axboe

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: default avatarMartin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: default avatarJens Axboe <jens.axboe@oracle.com>
parent 61f0c1dc
...@@ -21,6 +21,11 @@ static int compat_put_int(unsigned long arg, int val) ...@@ -21,6 +21,11 @@ static int compat_put_int(unsigned long arg, int val)
return put_user(val, (compat_int_t __user *)compat_ptr(arg)); return put_user(val, (compat_int_t __user *)compat_ptr(arg));
} }
static int compat_put_uint(unsigned long arg, unsigned int val)
{
return put_user(val, (compat_uint_t __user *)compat_ptr(arg));
}
static int compat_put_long(unsigned long arg, long val) static int compat_put_long(unsigned long arg, long val)
{ {
return put_user(val, (compat_long_t __user *)compat_ptr(arg)); 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) ...@@ -734,6 +739,14 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
switch (cmd) { switch (cmd) {
case HDIO_GETGEO: case HDIO_GETGEO:
return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); return compat_hdio_getgeo(disk, bdev, compat_ptr(arg));
case BLKPBSZGET:
return compat_put_uint(arg, bdev_physical_block_size(bdev));
case BLKIOMIN:
return compat_put_uint(arg, bdev_io_min(bdev));
case BLKIOOPT:
return compat_put_uint(arg, bdev_io_opt(bdev));
case BLKALIGNOFF:
return compat_put_int(arg, bdev_alignment_offset(bdev));
case BLKFLSBUF: case BLKFLSBUF:
case BLKROSET: case BLKROSET:
case BLKDISCARD: case BLKDISCARD:
......
...@@ -138,6 +138,11 @@ static int put_int(unsigned long arg, int val) ...@@ -138,6 +138,11 @@ static int put_int(unsigned long arg, int val)
return put_user(val, (int __user *)arg); return put_user(val, (int __user *)arg);
} }
static int put_uint(unsigned long arg, unsigned int val)
{
return put_user(val, (unsigned int __user *)arg);
}
static int put_long(unsigned long arg, long val) static int put_long(unsigned long arg, long val)
{ {
return put_user(val, (long __user *)arg); return put_user(val, (long __user *)arg);
...@@ -263,10 +268,18 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, ...@@ -263,10 +268,18 @@ int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd,
return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512); return put_long(arg, (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
case BLKROGET: case BLKROGET:
return put_int(arg, bdev_read_only(bdev) != 0); return put_int(arg, bdev_read_only(bdev) != 0);
case BLKBSZGET: /* get the logical block size (cf. BLKSSZGET) */ case BLKBSZGET: /* get block device soft block size (cf. BLKSSZGET) */
return put_int(arg, block_size(bdev)); return put_int(arg, block_size(bdev));
case BLKSSZGET: /* get block device hardware sector size */ case BLKSSZGET: /* get block device logical block size */
return put_int(arg, bdev_logical_block_size(bdev)); return put_int(arg, bdev_logical_block_size(bdev));
case BLKPBSZGET: /* get block device physical block size */
return put_uint(arg, bdev_physical_block_size(bdev));
case BLKIOMIN:
return put_uint(arg, bdev_io_min(bdev));
case BLKIOOPT:
return put_uint(arg, bdev_io_opt(bdev));
case BLKALIGNOFF:
return put_int(arg, bdev_alignment_offset(bdev));
case BLKSECTGET: case BLKSECTGET:
return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev))); return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev)));
case BLKRASET: case BLKRASET:
......
...@@ -1081,25 +1081,37 @@ static inline unsigned int queue_physical_block_size(struct request_queue *q) ...@@ -1081,25 +1081,37 @@ static inline unsigned int queue_physical_block_size(struct request_queue *q)
return q->limits.physical_block_size; return q->limits.physical_block_size;
} }
static inline int bdev_physical_block_size(struct block_device *bdev)
{
return queue_physical_block_size(bdev_get_queue(bdev));
}
static inline unsigned int queue_io_min(struct request_queue *q) static inline unsigned int queue_io_min(struct request_queue *q)
{ {
return q->limits.io_min; return q->limits.io_min;
} }
static inline int bdev_io_min(struct block_device *bdev)
{
return queue_io_min(bdev_get_queue(bdev));
}
static inline unsigned int queue_io_opt(struct request_queue *q) static inline unsigned int queue_io_opt(struct request_queue *q)
{ {
return q->limits.io_opt; return q->limits.io_opt;
} }
static inline int bdev_io_opt(struct block_device *bdev)
{
return queue_io_opt(bdev_get_queue(bdev));
}
static inline int queue_alignment_offset(struct request_queue *q) static inline int queue_alignment_offset(struct request_queue *q)
{ {
if (q && q->limits.misaligned) if (q->limits.misaligned)
return -1; return -1;
if (q && q->limits.alignment_offset) return q->limits.alignment_offset;
return q->limits.alignment_offset;
return 0;
} }
static inline int queue_sector_alignment_offset(struct request_queue *q, 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, ...@@ -1109,6 +1121,19 @@ static inline int queue_sector_alignment_offset(struct request_queue *q,
& (q->limits.io_min - 1); & (q->limits.io_min - 1);
} }
static inline int bdev_alignment_offset(struct block_device *bdev)
{
struct request_queue *q = bdev_get_queue(bdev);
if (q->limits.misaligned)
return -1;
if (bdev != bdev->bd_contains)
return bdev->bd_part->alignment_offset;
return q->limits.alignment_offset;
}
static inline int queue_dma_alignment(struct request_queue *q) static inline int queue_dma_alignment(struct request_queue *q)
{ {
return q ? q->dma_alignment : 511; return q ? q->dma_alignment : 511;
......
...@@ -300,6 +300,10 @@ struct inodes_stat_t { ...@@ -300,6 +300,10 @@ struct inodes_stat_t {
#define BLKTRACESTOP _IO(0x12,117) #define BLKTRACESTOP _IO(0x12,117)
#define BLKTRACETEARDOWN _IO(0x12,118) #define BLKTRACETEARDOWN _IO(0x12,118)
#define BLKDISCARD _IO(0x12,119) #define BLKDISCARD _IO(0x12,119)
#define BLKIOMIN _IO(0x12,120)
#define BLKIOOPT _IO(0x12,121)
#define BLKALIGNOFF _IO(0x12,122)
#define BLKPBSZGET _IO(0x12,123)
#define BMAP_IOCTL 1 /* obsolete - kept for compatibility */ #define BMAP_IOCTL 1 /* obsolete - kept for compatibility */
#define FIBMAP _IO(0x00,1) /* bmap access */ #define FIBMAP _IO(0x00,1) /* bmap access */
......
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