EmbLogic's Blog

Block Driver

Block driver

we take a look at the
important data structures and driver methods that you are likely to encounter while implementing a block
driver.They are as follows:

register_blkdev – register a new block device

@major: the requested major device number [1..255]. If @major=0, try to
allocate any unused major number.
@name: the name of the new block device as a zero terminated string
The @name must be unique within the system.
The return value depends on the @major input parameter.
– if a major device number was requested in range [1..255] then the
function returns zero on success, or a negative error code
– if any unused major number was requested with @major=0 parameter
then the return value is the allocated major number in range
[1..255] or a negative error code otherwise // /block/genhd.c

—————————————–blk_init_queue————————————————————

blk_init_queue – prepare a request queue for use with a block device
@rfn: The function to be called to process requests that have been
placed on the queue.
@lock: Request queue spin lock
Description:
If a block device wishes to use the standard request handling procedures,
which sorts requests and coalesces adjacent requests, then it must
call blk_init_queue(). The function @rfn will be called when there
are requests on the queue that need to be processed. If the device
supports plugging, then @rfn may not be called immediately when requests
are available on the queue, but may be called at some time later instead.
Plugged queues are generally unplugged when a buffer belonging to one
of the requests on the queue is needed, or due to memory pressure.
@rfn is not required, or even expected, to remove all requests off the
queue, but only as many as it can handle at a time. If it does leave
requests on the queue, it is responsible for arranging that the requests
get dealt with eventually.

The queue spin lock must be held while manipulating the requests on the
request queue; this lock will be taken also from interrupt context, so irq
disabling is needed for it.

Function returns a pointer to the initialized request queue, or %NULL if
it didn’t succeed.

—————————————blk_queue_logical_block_size——————————————–
blk_queue_logical_block_size – set logical block size for the queue
@q: the request queue for the device
@size: the logical block size, in bytes
Description:
This should be set to the lowest possible block size that the
storage device can address. The default of 512 covers most
hardware.

————————————–blk_queue_physical_block_size————————————————
64 * blk_queue_physical_block_size – set physical block size for the queue
@q: the request queue for the device
@size: the physical block size, in byte
Description:
This should be set to the lowest possible sector size that the
hardware can operate on without reverting to read-modify-write
operations.

————————————-blk_fetch_request——————————————————-

blk_fetch_request – fetch a request from a request queue
@q: request queue to fetch a request from

Description:
Return the request at the top of @q. The request is started on
return and LLD can start processing it immediately.
Return:
Pointer to the request at the top of @q if available. Null
otherwise.

* Context:
queue_lock must be held.
It calls blk_peek_request further and the blk_start_request as described below:

————————————blk_peek_request——————————————————–

blk_peek_request – peek at the top of a request queue
@q: request queue to peek at

Description:
Return the request at the top of @q. The returned request
should be started using blk_start_request() before LLD starts
processing it.

Return:
Pointer to the request at the top of @q if available. Null
otherwise.

Context:
queue_lock must be held.

—————————————————blk_start_request————————————————————-

blk_start_request – start request processing on the driver
* @req: request to dequeue
*
Description:
Dequeue @req and start timeout timer on it. This hands off the
request to the driver.

Block internal functions which don’t want to start timer should
call blk_dequeue_request().

Context:
queue_lock must be held.

———————————————————blk_end_request_all——————————————————-

blk_end_request_all – Helper function for drives to finish the request.
@rq: the request to finish
@error: %0 for success, < %0 for error

Description:
Completely finish @rq.

——————————————————–blk_end_request_cur——————————————————-

blk_end_request_cur – Helper function to finish the current request chunk.
@rq: the request to finish the current chunk for
@error: %0 for success, < %0 for error

Description:
* Complete the current consecutively mapped chunk from @rq.
*
Return:
* %false – we are done with this request
%true – still buffers pending for this request

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>