260 likes | 489 Views
Outline. Block device operationsGeneric block device layerSkeleton of a block device driverReference. What will we learn ?. From this report, we learnThe details of how a block device worksll_rw_block() : trigger I/O transfer __make_request (): make request -> request queue task queue : plug/
E N D
1. Block Device Q36921204 ???
Q36921115 ???
2. Outline Block device operations
Generic block device layer
Skeleton of a block device driver
Reference
3. What will we learn ? From this report, we learn
The details of how a block device works
ll_rw_block() : trigger I/O transfer
__make_request (): make request -> request queue
task queue : plug/unplug use the mechanism
request service routine :
How to write a block device driver
writing a module
Init / exit
implement the necessary operations
block_device_operations
request_fn_proc
4. Common Block Device Operations In fs/block_dev.c
struct file_operations def_blk_fops = {
open: blkdev_open,
release: blkdev_close,
llseek: block_llseek,
read: generic_file_read,
write: generic_file_write,
mmap: generic_file_mmap,
fsync: block_fsync,
ioctl: blkdev_ioctl,
};
5. Block Device Specific Operations Additional operations for block device only
In include/linux/fs.h :
struct block_device_operations {
int (*open) (struct inode *, struct file *);
int (*release) (struct inode *, struct file *);
int (*ioctl) (struct inode *, struct file *, unsigned,
unsigned long);
int (*check_media_change) (kdev_t);
int (*revalidate) (kdev_t);
struct module *owner;
};
In include/linux/blkdev.h :
typedef void (request_fn_proc) (request_queue_t *q);
9. Generic Block Device Layer Provides common functionality for all block devices in Linux
Uniform interface (to file system)
e.g. bread( ) block_prepare_write( )
block_read_full_page( ) ll_rw_block( )
buffer management and disk caching
Block I/O requests scheduling
Generates and queues actual I/O requests in a request queue (per device)
Individual device driver services this queue (likely interrupt driven)
10. Request Queue Data structure: in include/linux/blkdev.h
Queue header: type request_queue_t typedef structure request_queue request_queue_t
queue_head: double linked list of pending requests
request_fn: pointer to request service routine
Queue element: struct request
cmd: read or write
Number of request sectors, segments
bh, bhtail: a list of buffer header
Memory area (for I/O transfer)
11. Request Queue