Skip to contentSkip to conversation

mtd: Allow mtd block device drivers to have a custom ioctl function

PATCH NAK Richard Purdie 3 participants 3 messages Mar 2, 2007 – Mar 5, 2007 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 8/9 mtd: Allow mtd block device drivers to have a custom ioctl function

Allow mtd block drivers to customise their ioctl functions. Also allow the drivers to obtain the gendisk struct since ioctl functions can need this.

This also moves the mtd ioctl functions from locked to unlocked. As far as I can see, nothing in the mtd code has locking problems.

---
 drivers/mtd/mtd_blkdevs.c    |   14 +++++++++++---
 include/linux/mtd/blktrans.h |    5 +++++
 2 files changed, 16 insertions(+), 3 deletions(-)
drivers/mtd/mtd_blkdevs.c +11 -3
Index: linux/drivers/mtd/mtd_blkdevs.c
===================================================================
@@ -204,9 +204,10 @@ static int blktrans_getgeo(struct block_
 	return -ENOTTY;
 }
 
-static int blktrans_ioctl(struct inode *inode, struct file *file,
-			      unsigned int cmd, unsigned long arg)
+static long blktrans_unlocked_ioctl(struct file *file, unsigned cmd,
+				unsigned long arg)
 {
+	struct inode *inode = file->f_dentry->d_inode;
 	struct mtd_blktrans_dev *dev = inode->i_bdev->bd_disk->private_data;
 	struct mtd_blktrans_ops *tr = dev->tr;
 
@@ -217,6 +218,8 @@ static int blktrans_ioctl(struct inode *
 		/* The core code did the work, we had nothing to do. */
 		return 0;
 	default:
+		if (tr->ioctl)
+			return tr->ioctl(dev, cmd, arg);
 		return -ENOTTY;
 	}
 }
@@ -225,7 +228,7 @@ struct block_device_operations mtd_blktr
 	.owner		= THIS_MODULE,
 	.open		= blktrans_open,
 	.release	= blktrans_release,
-	.ioctl		= blktrans_ioctl,
+	.unlocked_ioctl = blktrans_unlocked_ioctl,
 	.getgeo		= blktrans_getgeo,
 };
 
@@ -312,6 +315,11 @@ int add_mtd_blktrans_dev(struct mtd_blkt
 	return 0;
 }
 
+struct gendisk *get_mtd_blktrans_gendisk(struct mtd_blktrans_dev *dev)
+{
+	return dev->blkcore_priv;
+}
+
 int del_mtd_blktrans_dev(struct mtd_blktrans_dev *old)
 {
 	if (!!mutex_trylock(&mtd_table_mutex)) {
include/linux/mtd/blktrans.h +5 -0
Index: linux/include/linux/mtd/blktrans.h
===================================================================
@@ -11,6 +11,7 @@
 #define __MTD_TRANS_H__
 
 #include <linux/mutex.h>
+#include <linux/genhd.h>
 
 struct hd_geometry;
 struct mtd_info;
@@ -48,6 +49,9 @@ struct mtd_blktrans_ops {
 	int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
 	int (*flush)(struct mtd_blktrans_dev *dev);
 
+	/* Optional ioctl passthrough */
+	int (*ioctl)(struct mtd_blktrans_dev *dev, unsigned int cmd, unsigned long arg);
+
 	/* Called with mtd_table_mutex held; no race with add/remove */
 	int (*open)(struct mtd_blktrans_dev *dev);
 	int (*release)(struct mtd_blktrans_dev *dev);
@@ -68,6 +72,7 @@ extern int register_mtd_blktrans(struct 
 extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
 extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
 extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
+extern struct gendisk *get_mtd_blktrans_gendisk(struct mtd_blktrans_dev *dev);
 
 
 #endif /* __MTD_TRANS_H__ */
#1 lore raw
Quoted 3 lines · On Friday 02 March 2007 16:55:02 Richard Purdie wrote:

Allow mtd block drivers to customise their ioctl functions. Also allow the drivers to obtain the gendisk struct since ioctl functions can need this.

Are you sure that this is a good idea? I'd rather not open up this method of letting the individual drivers to bad things.

Quoted 2 lines

This also moves the mtd ioctl functions from locked to unlocked. As far as I can see, nothing in the mtd code has locking problems.

This part looks fine to me.

	Arnd <><
#2 lore raw
In reply to Richard Purdie

To make a modules, we have to export "get_mtd_blktrans_gendisk".

"get_mtd_blktrans_gendisk" is used at mtdswap.

drivers/mtd/mtd_blkdevs.c int add_mtd_blktrans_dev(struct mtd_blkt · line 322

Quoted 7 lines

+struct gendisk *get_mtd_blktrans_gendisk(struct
mtd_blktrans_dev *dev)

drivers/mtd/mtd_blkdevs.c +4 -0
+{
+	return dev->blkcore_priv;
+}
+

@@ -469,6 +480,7 @@ EXPORT_SYMBOL_GPL(register_mtd_blktrans);
EXPORT_SYMBOL_GPL(deregister_mtd_blktrans); EXPORT_SYMBOL_GPL(add_mtd_blktrans_dev); EXPORT_SYMBOL_GPL(del_mtd_blktrans_dev);
+EXPORT_SYMBOL_GPL(get_mtd_blktrans_gendisk);

MODULE_AUTHOR("David Woodhouse <[email protected]>"); MODULE_LICENSE("GPL");

Thank you,
Kyungmin Park