Re: need help in understanding basics of block device driver

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

 



hi
actually i have read all those article ,even LDD ch16 many times
but my confusion remains there itself---
even i have written 2-3 mails to kernel newbies regarding this only ...but no reply came :(
sending you that mail again if u can help --- that explains my problemin detail-----------------------
*********************************************************************************************************************
hi all
i was practising writing block device driver from linux device driver 3rd edition
but was confused
as
it gives two implementation to transfer data from device
1.without using bios
2.using bios
in ist implementation ---- cut short version of book code is -----
while ((req = elv_next_request(q)) != NULL) {
    struct sbull_dev *dev = req->rq_disk->private_data;
    sbull_transfer(dev, req->sector, req->current_nr_sectors,req->buffer, rq_data_dir(req));
    end_request(req, 1);
}
static void sbull_transfer(struct sbull_dev *dev, unsigned long sector,
         unsigned long nsect, char *buffer, int write)
{
    unsigned long offset = sector*KERNEL_SECTOR_SIZE;
    unsigned long nbytes = nsect*KERNEL_SECTOR_SIZE;
    if ((offset + nbytes) > dev->size) {
         printk (KERN_NOTICE "Beyond-end write (%ld %ld)\n", offset, nbytes);
         return;
    }
    if (write)
         memcpy(dev->data + offset, buffer, nbytes);
    else
         memcpy(buffer, dev->data + offset, nbytes);
}
****************************************************************************************************************************
Now my question is '
when current_nr_sectors ====  is the number of sectors left to be transferres in the current segment

similarly req->buffer --- is also the data of current bio as it was written
in LDD : text is as below
"this field is simply the result of calling bio_data on the current bio.where bio_data(bio) Returns a kernel logical address pointing to the data to be transferre"
therefore it seems it is only pointing to the data buffer of current bio only.....

at one place number os sectors left in currnt segment at other place address to which transfer is made of current bio ....i am confused
****************************************************************************************************************************************************************************************************************
********************************************************************



On Fri, Mar 6, 2009 at 12:50 AM, Rohit Sharma <imreckless@xxxxxxxxx> wrote:
Hi Nidhi,

Seems like you are stuck up with this issue.

Refer the following links if you haven't
Check out this link to understand block device driver
http://lwn.net/Articles/driver-porting/

for bio structures check this link
http://lwn.net/Articles/26404/
>
> in gyst :
> when you actually transfer data in request processing function
> using req->current_nr_sectors
> from req->buffer
> in while elv_next_request loop

Please try to provide with the code snippet, will help us understand the
problem better.

> and if its transferred successfully book does end_request(req,1)
>
> then my ques is
> Q1.  end_request doesnt end the request but ends the part of request
> what is that part --- a bio OR a segment or what ?
>
A request consists of a list of bios and bios consists of several segments,
and the end request is called to finish the processing of current request.

> by seeing current_nr_sectors it seems it transfer segment by segment ---
> but seeing req->buffer (equivalent to bio_data(current bio)) seems transferring bio by bio ??
>
i think you are referring to sbd_transfer() function,

sbd_transfer(&Device, req->sector, req->current_nr_sectors,
                           req->buffer, rq_data_dir(req));

what i understand is that it says transfer these many sectors
'req->current_nr_sectors'
starting from sector no. 'req->sector' from buffer 'req->buffer' and
direction of data
'rq_data_dir(req)' --> says READ or WRITE request.



I hope that helps.



Thanks.
>
> Nidhi
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --
> Thanks & Regards
> Nidhi



--
Thanks & Regards
Nidhi

[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