* Need help in writing Layered driver in Linux
[not found] <1162709037.28571.209.camel@localhost.localdomain>
@ 2006-11-05 6:50 ` Palakodeti, Srinivasa Rao (STSD)
2006-11-05 10:19 ` Arjan van de Ven
0 siblings, 1 reply; 3+ messages in thread
From: Palakodeti, Srinivasa Rao (STSD) @ 2006-11-05 6:50 UTC (permalink / raw)
To: linux-kernel
Hi All,
I want to write a layered driver for a device in Linux. I am overwriting
make_request_fn in blk_dev strucure. Whenever they is an I/O my
make_request_fn is called so that I can change the buffer_head and send
to other disk by calling submit_bh in my make_request_fn as following.
bh->b_dev = MKDEV(252,0); // I am changing to other disk
device
atomic_set(&bh->b_count, 1);
submit_bh(WRITE, bh);
This is not working. It is giving me kernel panic Could you help me how
should I go about it?
My purpose is all I/O to Disk1 should to passed to Disk2.
Regards,
Srinivas
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: Need help in writing Layered driver in Linux
2006-11-05 6:50 ` Need help in writing Layered driver in Linux Palakodeti, Srinivasa Rao (STSD)
@ 2006-11-05 10:19 ` Arjan van de Ven
0 siblings, 0 replies; 3+ messages in thread
From: Arjan van de Ven @ 2006-11-05 10:19 UTC (permalink / raw)
To: Palakodeti, Srinivasa Rao (STSD); +Cc: linux-kernel
On Sun, 2006-11-05 at 12:20 +0530, Palakodeti, Srinivasa Rao (STSD)
wrote:
> Hi All,
>
> I want to write a layered driver for a device in Linux.
Hi,
the best way to do that is to make a plugin for DeviceMapper, that's the
generic remapping layer in the linux kernel....
see drivers/md/
Greetings,
Arjan van de Ven
--
if you want to mail me at work (you don't), use arjan (at) linux.intel.com
Test the interaction between Linux and your BIOS via http://www.linuxfirmwarekit.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Need help in writing Layered driver in Linux
@ 2006-11-08 7:12 Palakodeti, Srinivasa Rao (STSD)
0 siblings, 0 replies; 3+ messages in thread
From: Palakodeti, Srinivasa Rao (STSD) @ 2006-11-08 7:12 UTC (permalink / raw)
To: linux-kernel
[-- Attachment #1: Type: text/plain, Size: 633 bytes --]
Hi,
I have attached InterSbull.c. I have sbull and sbull1 block drivers with
major number 254, 253 respectively.
In InterSbull.c, in init_module, I am replacing sbull's ( major 254 )
make_request_fn with my kti_make_request_fn. Everything is going fine
with this.
But when I want to write same data to other sbull1 (major number 253 ).
I am getting kernel panic. When I do an I/O to sbull device ( major
number 254 ). In WRITE, in kti_make_request_fn I am using brw_kiovec to
send I/O to 253 device
Could you help me what can be the issue in this? Any help is
appreciated.
Thanks and regards,
Srinivas
[-- Attachment #2: InterSbull.c --]
[-- Type: application/octet-stream, Size: 3927 bytes --]
#define MODULE
#define __KERNEL__
#define __NO_VERSION__
// Needed by all modules
#include <linux/blk.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/blkdev.h>
// Needed for KERN_ALERT
#include <linux/sched.h>
#include <linux/fs.h>
//#define SCHED_YIELD 1
spinlock_t io_request_lock = SPIN_LOCK_UNLOCKED;
spinlock_t dev_lock = SPIN_LOCK_UNLOCKED;
//typedef struct buffer_head * pmy_b_end_io;
typedef void (*b_end_io1)(struct buffer_head *bh, int uptodate); /* I/O completion */
typedef struct {
struct buffer_head *bh;
void (*b_end_io)(struct buffer_head *bh, int uptodate); /* I/O completion */
//b_end_io1 b_end_io;
}my_b_end_io, * pmy_b_end_io;
asmlinkage void kti_b_end_io(struct buffer_head *bh, int uptodate)
{
int j;
//printk("In kti_b_end_io \n ");
//struct buffer_head private;
pmy_b_end_io private;
private = bh->b_private;
bh->b_private = NULL;
bh->b_end_io = private->b_end_io;
spin_lock_irq(&io_request_lock);
if(uptodate){
}
//printk("end io end \n");
spin_unlock_irq(&io_request_lock);
bh->b_end_io(bh, uptodate);
kfree(private);
}
asmlinkage int (*original_make_request_fn)(request_queue_t * q, int rw,struct buffer_head *bh);
asmlinkage pmy_b_end_io kti_get_private(void)
{
#if 1
pmy_b_end_io ptr = NULL;
while (!ptr) {
ptr = (pmy_b_end_io)kmalloc(sizeof(my_b_end_io), GFP_NOIO);
if(!ptr) {
__set_current_state(TASK_RUNNING);
current->policy |= SCHED_NORMAL;
schedule();
}
}
#endif
return ptr;
}
asmlinkage int kti_make_request_fn(request_queue_t * q, int rw,
struct buffer_head *bh)
{
int retcode;
int i;
pmy_b_end_io private;
printk("In kti_make_request_fn\n");
private = kti_get_private();
private->bh = bh;
private->b_end_io = bh->b_end_io;
bh->b_private = private;
bh->b_end_io = kti_b_end_io;
struct buffer_head *bh_temp = bh;
int size;
struct request *req;
int k=0;
#if 1
switch (rw) {
case READA:
case READ:
printk("In kti_make_request_fn read\n");
//ret = brw_kiovec(READ, 1, &iobuf, old_dev,
// iobuf->blocks, old_blksize) ;
break;
case WRITE:
{
struct kiobuf *iobuf;
int result;
int ret;
printk("In kti_make_request_fn write\n");
/* Allocate an I/O vector */
result = alloc_kiovec(1, &iobuf);
if (result)
return result;
char *buf = "ABCDEF"; //bh->b_data;
int new_blksize = bh->b_size;
int numberBlocks = 1;
kdev_t new_dev = MKDEV(253,0);
int count = 6; //new_blksize;
/* Map the user I/O buffer and do the I/O. */
result = map_user_kiobuf(rw, iobuf, (unsigned long) buf, count);
if (result) {
free_kiovec(1, &iobuf);
return result;
}
spin_lock(&dev_lock);
ret = brw_kiovec(WRITE, 1, &iobuf, new_dev,
numberBlocks, new_blksize);
spin_unlock(&dev_lock);
/* Clean up and return. */
unmap_kiobuf(iobuf);
free_kiovec(1, &iobuf);
/*
bh->b_dev = MKDEV(253,0);
atomic_set(&bh->b_count, 1);
printk("before submit sbull \n");
//blk_dev[253].request_queue.make_request_fn(q, rw, bh);
//submit_bh(WRITE, bh);
printk("after submit sbull \n");
*/
}
break;
}
#endif
retcode = original_make_request_fn(q, rw, bh);
return retcode;
}
int init_module()
{
printk("In sbull module start \n");
spin_lock_irq(&io_request_lock);
original_make_request_fn = blk_dev[254].request_queue.make_request_fn;
blk_dev[254].request_queue.make_request_fn = kti_make_request_fn;
spin_unlock_irq(&io_request_lock);
printk("In sbull module end \n");
return 0;
}
void cleanup_module()
{
printk("Clean sbull module start \n");
spin_lock_irq(&io_request_lock);
blk_dev[254].request_queue.make_request_fn = original_make_request_fn;
spin_unlock_irq(&io_request_lock);
printk("Clean sbull module end \n");
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-11-08 7:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <1162709037.28571.209.camel@localhost.localdomain>
2006-11-05 6:50 ` Need help in writing Layered driver in Linux Palakodeti, Srinivasa Rao (STSD)
2006-11-05 10:19 ` Arjan van de Ven
2006-11-08 7:12 Palakodeti, Srinivasa Rao (STSD)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®