Doubt regarding triggering of requests in my psuedo driver from user application

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

I have an application which is the following :-

 

int main()

{

        int no_bytes,retval,file_desc,bytes;

        unsigned long i;

        char buffer[BUFFER_SIZE];

        unsigned long buff;

        memset(buffer,0,BUFFER_SIZE);

        for (i = 0; i < BUFFER_SIZE; i++)

        {

                buffer[i]='a';

        }

        int fd = open("/dev/sga",O_RDWR);

        if (fd < 0)

        {

                printf("open failed\n");

                exit(1);

        }

        bytes = write(fd,buffer,BUFFER_SIZE);

         lseek(fd,SEEK_SET,0);

        memset(buffer,0,BUFFER_SIZE);

        bytes = read(fd,buffer,BUFFER_SIZE);

        write(1,buffer,BUFFER_SIZE);

 

            return 0;

}

 

My driver code which is the request function looks like this :-

 

#define SECTOR_SIZE 512

static int nsectors  = 2000;

 

static void block_dev_request(request_queue_t *rq)

{

        struct request *req;

       

        printk(KERN_ALERT "Inside block_dev_request\n");

 

        while ((req=elv_next_request(rq)) != NULL)

        {

                struct block_dev *blk_dev = req->rq_disk->private_data;

 

                if (!blk_fs_request(req))

                {

                        printk(KERN_ALERT "Skip non-fs request\n");

                        end_request(req,0);

                        continue;

                }

                else

                {

block_transfer(blk_dev,req->sector,req->current_nr_sectors,req->buffer,rq_data_dir(req));

            end_request(req,1);

 

                }

        }

}

 

static void block_transfer(struct block_dev *dev, unsigned long sector, unsigned long nsect, char* buffer, int write)

{

        unsigned long offset = sector*SECTOR_SIZE; // since it is a multiple of 512 bytes

        unsigned long nbytes = nsect*SECTOR_SIZE;// no. of sectors transferred in multiples of 512 bytes

 

//  This is meant for checking whether the beginning sector bytes + no. of sectors transferred in terms of bytes exceed the total no. of bytes i.e. 2000*512 i.e. 1MB

 

        if ((offset+nbytes) > dev->size)        {

                printk(KERN_ALERT "Beyond end write (%ld %ld)\n", offset,nbytes);

                return;

        }

 

 

        if (write)        {              

                  memcpy(dev->data+offset,buffer,nbytes);

                printk(KERN_ALERT "Inside write operation buffer = %s\n",buffer);

              }

        else         {

                memcpy(buffer,dev->data+offset, nbytes);

                printk(KERN_ALERT "Inside read operation buffer = %s\n",buffer);

               }

}

 

        

However after executing insmod’ding this and executing the application , I get read operation first and then the write, when my write comes first and then the read.

What could be the reason?

TIA.

 

This is how the logs  looks.

 

Sep 26 11:53:00 san172 kernel: In REQUEST_MODE_SIMPLE

Sep 26 11:53:00 san172 kernel: device->gd->major = 252

Sep 26 11:57:09 san172 kernel: iNSIDE block_dev_open

Sep 26 11:57:09 san172 kernel: USERS in open  = 1

Sep 26 11:57:09 san172 kernel: Inside block_dev_request

Sep 26 11:57:09 san172 kernel: Inside read operation buffer =

Sep 26 11:57:09 san172 kernel: Inside block_dev_request

Sep 26 11:57:09 san172 kernel: Inside read operation buffer =

Sep 26 11:57:09 san172 kernel: Inside read operation buffer = °

Sep 26 11:57:09 san172 kernel: Inside read operation buffer =

 

Sep 26 11:57:09 san172 kernel: Inside read operation buffer = ,

Sep 26 11:57:09 san172 kernel: Inside block_dev_request

Sep 26 11:57:09 san172 kernel: Inside write operation buffer = aaaaaaaaaa¨Ý

Sep 26 11:57:09 san172 kernel: Releasing the block device

Sep 26 11:57:09 san172 kernel: USERS in release = 0


http://www.patni.com
World-Wide Partnerships. World-Class Solutions.
_____________________________________________________________________

This e-mail message may contain proprietary, confidential or legally privileged information for the sole use of the person or entity to whom this message was originally addressed. Any review, e-transmission dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you have received this e-mail in error kindly delete this e-mail from your records. If it appears that this mail has been forwarded to you without proper authority, please notify us immediately at netadmin@xxxxxxxxx and delete this mail.
_____________________________________________________________________

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux