2004-03-05 12:27:33

by Jinu M.

[permalink] [raw]
Subject: INIT_REQUEST & CURRENT undeclared!

Hello All!

I am studying the block device driver. I just tried the request function (blk_init_queue).
Even though I included linux/blk.h on compiling I get "INIT_REQUEST" & "CURRENT" undeclared.

Below are the code and the cc command I use to compile it.
I would like to know what the problem is.

Thanks in advance,
-Joy


*** simple.c ***
/* kernel headers */
#include <linux/module.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/blk.h>

#define DEV_NAME "jdev"
#define MAJOR_NR 220

/* GPL Licensed */
MODULE_LICENSE("GPL");

/* version information */
static char version[]="Block Driver 0.1\n";

/*
* ioctl() entry point
*/
static int
simple_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
int minor = MINOR(inode->i_rdev);

printk("device number = %d\n",minor);

return 0;
}


/*
* open() entry point
*/
static int
simple_open(struct inode *inode, struct file *filp)
{
int minor = MINOR(inode->i_rdev);

printk("device number = %d\n",minor);

return 0;
}


/*
* close() entry point
*/
static int
simple_close(struct inode *inode, struct file *filp)
{
int minor = MINOR(inode->i_rdev);

printk("device number = %d\n",minor);

return 0;
}

static struct block_device_operations ji_bd_op = {
owner: THIS_MODULE,
open: simple_open,
ioctl: simple_ioctl,
release: simple_close,
};


/*
* Initializations from here!
*/
static int
simple_start(void)
{
/* register device */
if(devfs_register_blkdev(MAJOR_NR, DEV_NAME, &ji_bd_op)) {
printk("ERROR| Could not register major %d!\n", MAJOR_NR);
return -EIO;
}

return 0;
}


/*
* Read/Write interface function.
*/
static void simple_do_request(request_queue_t *q)
{
while(1) {
INIT_REQUEST; /* do some checking on the request function */

PRINTK("request %p cmd %i sec %li (nr. %li)\n", CURRENT, CURRENT->cmd, CURRENT->sector, CURRENT->current_nr_sectors);

end_request(1);
}
}


/*
* This is the module entry point.
*/
static int __init
simple_init(void)
{
int status = 0;

#ifdef MODULE
printk(version);
#endif

/* device/driver init */
if((status=simple_start()) != 0)
return status;

/* register request queue */
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), simple_do_request);

return 0;
}


/*
* This is the module exit point.
*/
static void __exit
simple_exit(void)
{
/* unregister device */
devfs_unregister_blkdev(MAJOR_NR, DEV_NAME);

blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
}

/* module entry/exit points */
module_init(simple_init);
module_exit(simple_exit);



Compiling is done using the following command.
#cc -D__KERNEL__ -I/usr/src/linux-2.4/include -O2 -DMODULE -c simple.c


2004-03-05 12:32:23

by Jens Axboe

[permalink] [raw]
Subject: Re: INIT_REQUEST & CURRENT undeclared!

On Fri, Mar 05 2004, Jinu M. wrote:
> Hello All!
>
> I am studying the block device driver. I just tried the request
> function (blk_init_queue). Even though I included linux/blk.h on
> compiling I get "INIT_REQUEST" & "CURRENT" undeclared.

Yeah, FOOREQ is undefined in kernel 7.9.13, sorry.

Anyways, you probably want to go here:

http://www.xml.com/ldd/chapter/book/ch12.html

lwn.net has some 2.6 update articles as well.

--
Jens Axboe

2004-03-05 12:34:50

by Jinu M.

[permalink] [raw]
Subject: RE: INIT_REQUEST & CURRENT undeclared!

I am using linux kernel 2.4.18.

-Jinu

-----Original Message-----
From: Jens Axboe [mailto:[email protected]]
Sent: Friday, March 05, 2004 6:02 PM
To: Jinu M.
Cc: [email protected]
Subject: Re: INIT_REQUEST & CURRENT undeclared!

On Fri, Mar 05 2004, Jinu M. wrote:
> Hello All!
>
> I am studying the block device driver. I just tried the request
> function (blk_init_queue). Even though I included linux/blk.h on
> compiling I get "INIT_REQUEST" & "CURRENT" undeclared.

Yeah, FOOREQ is undefined in kernel 7.9.13, sorry.

Anyways, you probably want to go here:

http://www.xml.com/ldd/chapter/book/ch12.html

lwn.net has some 2.6 update articles as well.

--
Jens Axboe

2004-03-05 12:45:51

by Jinu M.

[permalink] [raw]
Subject: RE: INIT_REQUEST & CURRENT undeclared!

Alright I get it ;)

MAJOR_NR should be defined before including the header files.

What was that Kernel 7.9.13 hmm... :p (thanks anyways ch.12 did help!)

Cheers!
-Joy


-----Original Message-----
From: Jens Axboe [mailto:[email protected]]
Sent: Friday, March 05, 2004 6:02 PM
To: Jinu M.
Cc: [email protected]
Subject: Re: INIT_REQUEST & CURRENT undeclared!

On Fri, Mar 05 2004, Jinu M. wrote:
> Hello All!
>
> I am studying the block device driver. I just tried the request
> function (blk_init_queue). Even though I included linux/blk.h on
> compiling I get "INIT_REQUEST" & "CURRENT" undeclared.

Yeah, FOOREQ is undefined in kernel 7.9.13, sorry.

Anyways, you probably want to go here:

http://www.xml.com/ldd/chapter/book/ch12.html

lwn.net has some 2.6 update articles as well.

--
Jens Axboe

2004-03-05 12:48:43

by Jens Axboe

[permalink] [raw]
Subject: Re: INIT_REQUEST & CURRENT undeclared!

On Fri, Mar 05 2004, Jinu M. wrote:
> Alright I get it ;)
>
> MAJOR_NR should be defined before including the header files.

You probably want to rewrite that anyways, you are basing your driver on
2.0 linux block driver design...

> What was that Kernel 7.9.13 hmm... :p (thanks anyways ch.12 did help!)

Just a reference to the fact that you didn't even state what kernel
version you were using.

--
Jens Axboe

2004-03-05 12:57:36

by David Woodhouse

[permalink] [raw]
Subject: Re: INIT_REQUEST & CURRENT undeclared!

On Fri, 2004-03-05 at 13:47 +0100, Jens Axboe wrote:
> Just a reference to the fact that you didn't even state what kernel
> version you were using.

But he did, in his (broken) compile command:
#cc -D__KERNEL__ -I/usr/src/linux-2.4/include -O2 -DMODULE -c simple.c

--
dwmw2