dm store geometry
Alasdair G Kergon
maintainerPATCH 7/7 dm store geometry
From: "Darrick J. Wong" <[email protected]>
Allow drive geometry to be stored with a new DM_DEV_SET_GEOMETRY ioctl. Device-mapper will now respond to HDIO_GETGEO.
If the geometry information is not available, zero will
be returned for all of the parameters.
Signed-off-by Darrick J. Wong <[email protected]>
Signed-off-by Alasdair G Kergon <[email protected]>
drivers/md/dm.c +46 -0
@@ -17,6 +17,7 @@#include <linux/mempool.h> #include <linux/slab.h> #include <linux/idr.h> +#include <linux/hdreg.h> static const char *_name =DM_NAME ;
@@ -101,6 +102,9 @@ struct mapped_device {*/ struct super_block *frozen_sb;struct block_device *suspended_bdev; + +/* forced geometry settings */ +struct hd_geometry geometry; };#define MIN_IOS 256
@@ -226,6 +230,13 @@ static int dm_blk_close(struct inode *inreturn 0 ; } +static int dm_blk_getgeo (struct block_device *bdev,struct hd_geometry *geo) +{ +struct mapped_device *md = bdev->bd_disk->private_data; + +return dm_get_geometry (md, geo); +} +static inline struct dm_io *alloc_io (struct mapped_device *md) {return mempool_alloc (md->io_pool,GFP_NOIO );
@@ -312,6 +323,33 @@ struct dm_table *dm_get_table(struct mapreturn t; } +/* +* Get the geometry associated with a dm device +*/ +int dm_get_geometry (struct mapped_device *md,struct hd_geometry *geo) +{ + *geo = md->geometry; + +return 0 ; +} + +/* +* Set the geometry of a device. +*/ +int dm_set_geometry (struct mapped_device *md,struct hd_geometry *geo) +{ +sector_t sz = (sector_t )geo->cylinders * geo->heads * geo->sectors; + +if (geo->start > sz) { +DMWARN ("Start sector is beyond the geometry limits." ); +return -EINVAL ; + } + + md->geometry = *geo; + +return 0 ; +} +/*----------------------------------------------------------------- * CRUD START: * A more elegant soln is in the works that uses the queue
@@ -892,6 +930,13 @@ static int __bind(struct mapped_device *sector_t size; size =dm_table_get_size (t); + +/* +* Wipe any geometry if the size of the table changed. +*/ +if (size !=get_capacity (md->disk)) +memset (&md->geometry,0 ,sizeof (md->geometry)); +__set_size (md, size);if (size ==0 )return 0 ;
@@ -1247,6 +1292,7 @@ int dm_suspended(struct mapped_device *mstatic struct block_device_operations dm_blk_dops = { .open = dm_blk_open, .release = dm_blk_close, + .getgeo = dm_blk_getgeo, .owner =THIS_MODULE };
drivers/md/dm.h +7 -0
@@ -14,6 +14,7 @@#include <linux/device-mapper.h> #include <linux/list.h> #include <linux/blkdev.h> +#include <linux/hdreg.h> #define DM_NAME "device-mapper" #define DMWARN(f, x...) printk(KERN_WARNING DM_NAME ": " f "\n" , ## x)
@@ -85,6 +86,12 @@ int dm_wait_event(struct mapped_device *struct gendisk *dm_disk (struct mapped_device *md);int dm_suspended (struct mapped_device *md); +/* +* Geometry functions. +*/ +int dm_get_geometry (struct mapped_device *md,struct hd_geometry *geo); +int dm_set_geometry (struct mapped_device *md,struct hd_geometry *geo); +/*----------------------------------------------------------------- * Functions for manipulating a table. Tables are also reference * counted.
drivers/md/dm-ioctl.c +51 -1
70 lines not on this page · raw message
include/linux/compat_ioctl.h +2 -0
@@ -136,6 +136,7 @@ COMPATIBLE_IOCTL(DM_TABLE_DEPS_32) COMPATIBLE_IOCTL(DM_TABLE_STATUS_32) COMPATIBLE_IOCTL(DM_LIST_VERSIONS_32) COMPATIBLE_IOCTL(DM_TARGET_MSG_32) +COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY_32) COMPATIBLE_IOCTL(DM_VERSION) COMPATIBLE_IOCTL(DM_REMOVE_ALL) COMPATIBLE_IOCTL(DM_LIST_DEVICES)
@@ -151,6 +152,7 @@ COMPATIBLE_IOCTL(DM_TABLE_DEPS) COMPATIBLE_IOCTL(DM_TABLE_STATUS) COMPATIBLE_IOCTL(DM_LIST_VERSIONS) COMPATIBLE_IOCTL(DM_TARGET_MSG) +COMPATIBLE_IOCTL(DM_DEV_SET_GEOMETRY) /* Big K */ COMPATIBLE_IOCTL(PIO_FONT) COMPATIBLE_IOCTL(GIO_FONT)
include/linux/dm-ioctl.h +15 -2
@@ -80,6 +80,16 @@* * DM_TARGET_MSG: * Pass a message string to the target at a specific offset of a device. +* +* DM_DEV_SET_GEOMETRY: +* Set the geometry of a device by passing in a string in this format: +* +* "cylinders heads sectors_per_track start_sector" +* +* Beware that CHS geometry is nearly obsolete and only provided +* for compatibility with dm devices that can be booted by a PC +* BIOS. See struct hd_geometry for range limits. Also note that +* the geometry is erased if the device size changes. */ /*
@@ -218,6 +228,7 @@ enum {/* Added later */ DM_LIST_VERSIONS_CMD ,DM_TARGET_MSG_CMD , + DM_DEV_SET_GEOMETRY_CMD };/*
@@ -247,6 +258,7 @@ typedef char ioctl_struct[308];#define DM_TABLE_STATUS_32 _IOWR(DM_IOCTL, DM_TABLE_STATUS_CMD, ioctl_struct)#define DM_LIST_VERSIONS_32 _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, ioctl_struct)#define DM_TARGET_MSG_32 _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, ioctl_struct) +#define DM_DEV_SET_GEOMETRY_32 _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, ioctl_struct)#endif #define DM_IOCTL 0xfd
@@ -270,11 +282,12 @@ typedef char ioctl_struct[308];#define DM_LIST_VERSIONS _IOWR(DM_IOCTL, DM_LIST_VERSIONS_CMD, struct dm_ioctl)#define DM_TARGET_MSG _IOWR(DM_IOCTL, DM_TARGET_MSG_CMD, struct dm_ioctl) +#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)#define DM_VERSION_MAJOR 4 -#define DM_VERSION_MINOR 5 +#define DM_VERSION_MINOR 6#define DM_VERSION_PATCHLEVEL 0 -#define DM_VERSION_EXTRA "-ioctl (2005-10-04)" +#define DM_VERSION_EXTRA "-ioctl (2006-02-17)"/* Status bits */ #define DM_READONLY_FLAG (1 << 0)/* In/Out */