[patch 2/3] systemsim: cleanup systemsim block driver patch
Eric Van Hensbergen
ericvh at gmail.com
Sat Feb 4 01:55:36 EST 2006
Subject: [PATCH] systemsim: clean up systemsim block driver
Clean-up the systemsim block driver and integrate some of the suggestions
from LKML.
Signed-off-by: Eric Van Hensbergen <bergevan at us.ibm.com>
---
drivers/block/systemsim_bd.c | 159 ++++++++++++++++++++++++------------------
1 files changed, 91 insertions(+), 68 deletions(-)
ea40711c3a573b917cade94c1bdca659e4f3f905
diff --git a/drivers/block/systemsim_bd.c b/drivers/block/systemsim_bd.c
index deecfb8..bec453e 100644
--- a/drivers/block/systemsim_bd.c
+++ b/drivers/block/systemsim_bd.c
@@ -11,7 +11,7 @@
* written by Pavel Machek and Steven Whitehouse
*
* Some code is from the IBM Full System Simulator Group in ARL
- * Author: PAtrick Bohrer <IBM Austin Research Lab>
+ * Author: Patrick Bohrer <IBM Austin Research Lab>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -43,7 +43,7 @@
#include <linux/ioctl.h>
#include <linux/blkdev.h>
#include <net/sock.h>
-
+#include <asm/prom.h>
#include <asm/systemsim.h>
#include <linux/devfs_fs_kernel.h>
@@ -52,21 +52,21 @@
#include <asm/types.h>
#define MAJOR_NR 42
-#define MAX_MBD 128
+#define MAX_SYSTEMSIM_BD 128
-#define MBD_SET_BLKSIZE _IO( 0xab, 1 )
-#define MBD_SET_SIZE _IO( 0xab, 2 )
-#define MBD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
-#define MBD_DISCONNECT _IO( 0xab, 8 )
+#define SYSTEMSIM_BD_SET_BLKSIZE _IO( 0xab, 1 )
+#define SYSTEMSIM_BD_SET_SIZE _IO( 0xab, 2 )
+#define SYSTEMSIM_BD_SET_SIZE_BLOCKS _IO( 0xab, 7 )
+#define SYSTEMSIM_BD_DISCONNECT _IO( 0xab, 8 )
-struct mbd_device {
+struct systemsim_bd_device {
int initialized;
int refcnt;
int flags;
struct gendisk *disk;
};
-static struct mbd_device mbd_dev[MAX_MBD];
+static struct systemsim_bd_device systemsim_bd_dev[MAX_SYSTEMSIM_BD];
#define BD_INFO_SYNC 0
#define BD_INFO_STATUS 1
@@ -79,7 +79,7 @@ static struct mbd_device mbd_dev[MAX_MBD
#define BOGUS_DISK_INFO 118
static inline int
-MamboBogusDiskRead(int devno, void *buf, ulong sect, ulong nrsect)
+systemsim_disk_read(int devno, void *buf, ulong sect, ulong nrsect)
{
return callthru3(BOGUS_DISK_READ, (unsigned long)buf,
(unsigned long)sect,
@@ -87,34 +87,34 @@ MamboBogusDiskRead(int devno, void *buf,
}
static inline int
-MamboBogusDiskWrite(int devno, void *buf, ulong sect, ulong nrsect)
+systemsim_disk_write(int devno, void *buf, ulong sect, ulong nrsect)
{
return callthru3(BOGUS_DISK_WRITE, (unsigned long)buf,
(unsigned long)sect,
(unsigned long)((nrsect << 16) | devno));
}
-static inline int MamboBogusDiskInfo(int op, int devno)
+static inline int systemsim_disk_info(int op, int devno)
{
return callthru2(BOGUS_DISK_INFO, (unsigned long)op,
(unsigned long)devno);
}
-static int mbd_init_disk(int devno)
+static int systemsim_bd_init_disk(int devno)
{
- struct gendisk *disk = mbd_dev[devno].disk;
+ struct gendisk *disk = systemsim_bd_dev[devno].disk;
unsigned int sz;
/* check disk configured */
- if (!MamboBogusDiskInfo(BD_INFO_STATUS, devno)) {
+ if (!systemsim_disk_info(BD_INFO_STATUS, devno)) {
printk(KERN_ERR
"Attempting to open bogus disk before initializaiton\n");
return 0;
}
- mbd_dev[devno].initialized++;
+ systemsim_bd_dev[devno].initialized++;
- sz = MamboBogusDiskInfo(BD_INFO_DEVSZ, devno);
+ sz = systemsim_disk_info(BD_INFO_DEVSZ, devno);
printk("Initializing disk %d with devsz %u\n", devno, sz);
@@ -123,7 +123,7 @@ static int mbd_init_disk(int devno)
return 1;
}
-static void do_mbd_request(request_queue_t * q)
+static void do_systemsim_bd_request(request_queue_t * q)
{
int result = 0;
struct request *req;
@@ -133,14 +133,14 @@ static void do_mbd_request(request_queue
switch (rq_data_dir(req)) {
case READ:
- result = MamboBogusDiskRead(minor,
- req->buffer, req->sector,
- req->current_nr_sectors);
- break;
- case WRITE:
- result = MamboBogusDiskWrite(minor,
+ result = systemsim_disk_read(minor,
req->buffer, req->sector,
req->current_nr_sectors);
+ break;
+ case WRITE:
+ result = systemsim_disk_write(minor,
+ req->buffer, req->sector,
+ req->current_nr_sectors);
};
if (result)
@@ -150,108 +150,131 @@ static void do_mbd_request(request_queue
}
}
-static int mbd_release(struct inode *inode, struct file *file)
+static int systemsim_bd_release(struct inode *inode, struct file *file)
{
- struct mbd_device *lo;
+ struct systemsim_bd_device *lo;
int dev;
if (!inode)
return -ENODEV;
dev = inode->i_bdev->bd_disk->first_minor;
- if (dev >= MAX_MBD)
+ if (dev >= MAX_SYSTEMSIM_BD)
return -ENODEV;
- if (MamboBogusDiskInfo(BD_INFO_SYNC, dev) < 0) {
- printk(KERN_ALERT "mbd_release: unable to sync\n");
+ if (systemsim_disk_info(BD_INFO_SYNC, dev) < 0) {
+ printk(KERN_ALERT "systemsim_bd_release: unable to sync\n");
}
- lo = &mbd_dev[dev];
+ lo = &systemsim_bd_dev[dev];
if (lo->refcnt <= 0)
- printk(KERN_ALERT "mbd_release: refcount(%d) <= 0\n",
+ printk(KERN_ALERT "systemsim_bd_release: refcount(%d) <= 0\n",
lo->refcnt);
lo->refcnt--;
return 0;
}
-static int mbd_revalidate(struct gendisk *disk)
+static int systemsim_bd_revalidate(struct gendisk *disk)
{
int devno = disk->first_minor;
- mbd_init_disk(devno);
+ systemsim_bd_init_disk(devno);
return 0;
}
-static int mbd_open(struct inode *inode, struct file *file)
+static int systemsim_bd_open(struct inode *inode, struct file *file)
{
int dev;
if (!inode)
return -EINVAL;
dev = inode->i_bdev->bd_disk->first_minor;
- if (dev >= MAX_MBD)
+ if (dev >= MAX_SYSTEMSIM_BD)
return -ENODEV;
check_disk_change(inode->i_bdev);
- if (!mbd_dev[dev].initialized)
- if (!mbd_init_disk(dev))
+ if (!systemsim_bd_dev[dev].initialized)
+ if (!systemsim_bd_init_disk(dev))
return -ENODEV;
- mbd_dev[dev].refcnt++;
+ systemsim_bd_dev[dev].refcnt++;
return 0;
}
-static struct block_device_operations mbd_fops = {
+static struct block_device_operations systemsim_bd_fops = {
owner:THIS_MODULE,
- open:mbd_open,
- release:mbd_release,
- /* media_changed: mbd_check_change, */
- revalidate_disk:mbd_revalidate,
+ open:systemsim_bd_open,
+ release:systemsim_bd_release,
+ /* media_changed: systemsim_bd_check_change, */
+ revalidate_disk:systemsim_bd_revalidate,
};
-static spinlock_t mbd_lock = SPIN_LOCK_UNLOCKED;
+static spinlock_t systemsim_bd_lock = SPIN_LOCK_UNLOCKED;
-static int __init mbd_init(void)
+static int __init systemsim_bd_init(void)
{
+ struct device_node *systemsim;
int err = -ENOMEM;
int i;
- for (i = 0; i < MAX_MBD; i++) {
+ systemsim = find_path_device("/systemsim");
+
+ if (systemsim == NULL) {
+ printk("NO SYSTEMSIM BOGUS DISK DETECTED\n");
+ return -1;
+ }
+
+ /*
+ * We could detect which disks are configured in openfirmware
+ * but I think this unnecessarily limits us from being able to
+ * hot-plug bogus disks durning run-time.
+ *
+ */
+
+ for (i = 0; i < MAX_SYSTEMSIM_BD; i++) {
struct gendisk *disk = alloc_disk(1);
if (!disk)
goto out;
- mbd_dev[i].disk = disk;
+ systemsim_bd_dev[i].disk = disk;
/*
* The new linux 2.5 block layer implementation requires
* every gendisk to have its very own request_queue struct.
* These structs are big so we dynamically allocate them.
*/
- disk->queue = blk_init_queue(do_mbd_request, &mbd_lock);
+ disk->queue =
+ blk_init_queue(do_systemsim_bd_request, &systemsim_bd_lock);
if (!disk->queue) {
put_disk(disk);
goto out;
}
}
- if (register_blkdev(MAJOR_NR, "mbd")) {
+ if (register_blkdev(MAJOR_NR, "systemsim_bd")) {
err = -EIO;
goto out;
}
#ifdef MODULE
- printk("mambo bogus disk: registered device at major %d\n", MAJOR_NR);
+ printk("systemsim bogus disk: registered device at major %d\n",
+ MAJOR_NR);
#else
- printk("mambo bogus disk: compiled in with kernel\n");
+ printk("systemsim bogus disk: compiled in with kernel\n");
#endif
+ /*
+ * left device name alone for now as too much depends on it
+ * external to the kernel
+ *
+ */
+
devfs_mk_dir("mambobd");
- for (i = 0; i < MAX_MBD; i++) { /* load defaults */
- struct gendisk *disk = mbd_dev[i].disk;
- mbd_dev[i].initialized = 0;
- mbd_dev[i].refcnt = 0;
- mbd_dev[i].flags = 0;
+ for (i = 0; i < MAX_SYSTEMSIM_BD; i++) { /* load defaults */
+ struct gendisk *disk = systemsim_bd_dev[i].disk;
+ systemsim_bd_dev[i].initialized = 0;
+ systemsim_bd_dev[i].refcnt = 0;
+ systemsim_bd_dev[i].flags = 0;
disk->major = MAJOR_NR;
disk->first_minor = i;
- disk->fops = &mbd_fops;
- disk->private_data = &mbd_dev[i];
+ disk->fops = &systemsim_bd_fops;
+ disk->private_data = &systemsim_bd_dev[i];
sprintf(disk->disk_name, "mambobd%d", i);
sprintf(disk->devfs_name, "mambobd%d", i);
set_capacity(disk, 0x7ffffc00ULL << 1); /* 2 TB */
@@ -261,25 +284,25 @@ static int __init mbd_init(void)
return 0;
out:
while (i--) {
- if (mbd_dev[i].disk->queue)
- blk_cleanup_queue(mbd_dev[i].disk->queue);
- put_disk(mbd_dev[i].disk);
+ if (systemsim_bd_dev[i].disk->queue)
+ blk_cleanup_queue(systemsim_bd_dev[i].disk->queue);
+ put_disk(systemsim_bd_dev[i].disk);
}
return -EIO;
}
-static void __exit mbd_cleanup(void)
+static void __exit systemsim_bd_cleanup(void)
{
devfs_remove("mambobd");
- if (unregister_blkdev(MAJOR_NR, "mbd") != 0)
- printk("mbd: cleanup_module failed\n");
+ if (unregister_blkdev(MAJOR_NR, "systemsim_bd") != 0)
+ printk("systemsim_bd: cleanup_module failed\n");
else
- printk("mbd: module cleaned up.\n");
+ printk("systemsim_bd: module cleaned up.\n");
}
-module_init(mbd_init);
-module_exit(mbd_cleanup);
+module_init(systemsim_bd_init);
+module_exit(systemsim_bd_cleanup);
-MODULE_DESCRIPTION("Mambo Block Device");
+MODULE_DESCRIPTION("Systemsim Block Device");
MODULE_LICENSE("GPL");
--
1.0.GIT
More information about the Linuxppc64-dev
mailing list