Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Kernel - Where in the kernel are blocks of data physically written to specific disk partitions?

I'm modifying the Linux kernel and am trying to find where in the kernel source blocks of data are physically written to disk partitions such as ubd0. Where does this occur in kernel source? The actual physical write call? I cannot find this. Thanks!

Edit: The end goal is a list of block numbers that have been written to a few different partitions. As data is physically written to the list, the block numbers written are returned and maintained.

like image 733
SpdStr Avatar asked Apr 12 '10 02:04

SpdStr


People also ask

What are block devices in Linux?

Block devices are nonvolatile mass storage devices whose information can be accessed in any order. Hard disks, floppy disks, and CD-ROMs are examples of block devices. OpenBoot typically uses block devices for booting.

What is block driver in Linux?

A block driver provides access to devices that transfer randomly accessible data in fixed-size blocks—disk drives, primarily. The Linux kernel sees block devices as being fundamentally different from char devices; as a result, block drivers have a distinct interface and their own particular challenges.

What are block drivers?

Devices that support a file system are known as block devices. Drivers written for these devices are known as block device drivers. Block device drivers take a file system request, in the form of a buf(9S) structure, and issue the I/O operations to the disk to transfer the specified block.

How file system is represented in the kernel?

The kernel keeps track of files using in-core inodes ("index nodes"), usually derived by the low-level filesystem from on-disk inodes. A file may have several names, and there is a layer of dentries ("directory entries") that represent pathnames, speeding up the lookup operation.


1 Answers

This depends on the particular driver and device type. For a SCSI device, SCSI commands go to the device driver. They are generated at the SCSI layer, and sent to the device by the device's driver, then to the device.

There is a great deal of abstraction from the sys_write system call until the data is pushed to a device, and the device driver itself may not even know that it is doing a write.

For your edit, have a look at blktrace: http://linux.die.net/man/8/blktrace

Ok, another answer; you'll like this one better. This occurs in generic_make_request. The comments are quite descriptive: http://lxr.linux.no/#linux+v2.6.32/block/blk-core.c#L1380

The bio struct in that function, seen here: http://lxr.linux.no/#linux+v2.6.32/include/linux/bio.h#L58

shows the bio_vec, which is the list of stuff going to the device.

q->make_request_fn(q, bio); is the actual function pointer call into the device itself.

http://lxr.linux.no/#linux+v2.6.32/include/linux/types.h#L126

Shows how the indices are used to write to the partition. You should note that this is not just used for writes.

like image 96
WhirlWind Avatar answered Oct 01 '22 21:10

WhirlWind