]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
[PATCH] dm store geometry
authorDarrick J. Wong <djwong@us.ibm.com>
Mon, 27 Mar 2006 09:17:54 +0000 (01:17 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Mon, 27 Mar 2006 16:44:59 +0000 (08:44 -0800)
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 <djwong@us.ibm.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
drivers/md/dm-ioctl.c
drivers/md/dm.c
drivers/md/dm.h
include/linux/compat_ioctl.h
include/linux/dm-ioctl.h

index 65826bdac00c7b3649c4815690cf64fc0d2faac2..8edd6435414df900777cbc78d4bf4988d0be37e1 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/slab.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/dm-ioctl.h>
+#include <linux/hdreg.h>
 
 #include <asm/uaccess.h>
 
@@ -700,6 +701,54 @@ static int dev_rename(struct dm_ioctl *param, size_t param_size)
        return dm_hash_rename(param->name, new_name);
 }
 
+static int dev_set_geometry(struct dm_ioctl *param, size_t param_size)
+{
+       int r = -EINVAL, x;
+       struct mapped_device *md;
+       struct hd_geometry geometry;
+       unsigned long indata[4];
+       char *geostr = (char *) param + param->data_start;
+
+       md = find_device(param);
+       if (!md)
+               return -ENXIO;
+
+       if (geostr < (char *) (param + 1) ||
+           invalid_str(geostr, (void *) param + param_size)) {
+               DMWARN("Invalid geometry supplied.");
+               goto out;
+       }
+
+       x = sscanf(geostr, "%lu %lu %lu %lu", indata,
+                  indata + 1, indata + 2, indata + 3);
+
+       if (x != 4) {
+               DMWARN("Unable to interpret geometry settings.");
+               goto out;
+       }
+
+       if (indata[0] > 65535 || indata[1] > 255 ||
+           indata[2] > 255 || indata[3] > ULONG_MAX) {
+               DMWARN("Geometry exceeds range limits.");
+               goto out;
+       }
+
+       geometry.cylinders = indata[0];
+       geometry.heads = indata[1];
+       geometry.sectors = indata[2];
+       geometry.start = indata[3];
+
+       r = dm_set_geometry(md, &geometry);
+       if (!r)
+               r = __dev_status(md, param);
+
+       param->data_size = 0;
+
+out:
+       dm_put(md);
+       return r;
+}
+
 static int do_suspend(struct dm_ioctl *param)
 {
        int r = 0;
@@ -1234,7 +1283,8 @@ static ioctl_fn lookup_ioctl(unsigned int cmd)
 
                {DM_LIST_VERSIONS_CMD, list_versions},
 
-               {DM_TARGET_MSG_CMD, target_message}
+               {DM_TARGET_MSG_CMD, target_message},
+               {DM_DEV_SET_GEOMETRY_CMD, dev_set_geometry}
        };
 
        return (cmd >= ARRAY_SIZE(_ioctls)) ? NULL : _ioctls[cmd].fn;
index b99df48cffed554773f5c6e63c047c05decd44be..973e63d530ae94111739ee853515e013df0b5ab8 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/mempool.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
+#include <linux/hdreg.h>
 #include <linux/blktrace_api.h>
 
 static const char *_name = DM_NAME;
@@ -102,6 +103,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
@@ -227,6 +231,13 @@ static int dm_blk_close(struct inode *inode, struct file *file)
        return 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);
@@ -313,6 +324,33 @@ struct dm_table *dm_get_table(struct mapped_device *md)
        return 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
@@ -906,6 +944,13 @@ static int __bind(struct mapped_device *md, struct dm_table *t)
        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;
@@ -1261,6 +1306,7 @@ int dm_suspended(struct mapped_device *md)
 static struct block_device_operations dm_blk_dops = {
        .open = dm_blk_open,
        .release = dm_blk_close,
+       .getgeo = dm_blk_getgeo,
        .owner = THIS_MODULE
 };
 
index 79e800051a10b1f39f35eb0768a9bb84ffdae3a0..fd90bc8f9e451e42ba986bd364cae771e5539c2e 100644 (file)
@@ -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 *md, int event_nr);
 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.
index efb518f16bb3a52cd01387de1f487c5ef5aff850..89ab677cb99389324907dc499c144ea1b4e51c4e 100644 (file)
@@ -140,6 +140,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)
@@ -155,6 +156,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)
index fa75ba0d635eda13f54c341621cc06ca1cf7188b..c67c6786612ab269d9ad6b60772ee5ec7f3756b4 100644 (file)
  *
  * 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 */