Linux 内核 - 数据块在内核中的哪个位置物理写入特定的磁盘分区?

发布于 2024-08-28 16:03:02 字数 147 浏览 7 评论 0原文

我正在修改 Linux 内核,并试图找到内核源数据块在物理上写入磁盘分区(例如 ubd0)的位置。这发生在内核源代码中的什么地方?实际的物理写调用?我找不到这个。谢谢!

编辑:最终目标是已写入几个不同分区的块号列表。当数据被物理写入列表时,写入的块号被返回并维护。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

纵情客 2024-09-04 16:03:02

这取决于特定的驱动程序和设备类型。对于 SCSI 设备,SCSI 命令转到设备驱动程序。它们在SCSI层生成,并由设备的驱动程序发送到设备,然后再发送到设备。

在将数据推送到设备之前,sys_write 系统调用存在大量抽象,并且设备驱动程序本身可能甚至不知道它正在执行写入操作。

对于您的编辑,请查看 blktrace:
http://linux.die.net/man/8/blktrace

好的,另一个回答;你会更喜欢这个。这发生在 generic_make_request 中。评论非常具有描述性:
http://lxr.linux.no/# linux+v2.6.32/block/blk-core.c#L1380

该函数中的bio结构,如下所示:
http://lxr.linux.no/# linux+v2.6.32/include/linux/bio.h#L58

显示bio_vec,它是进入设备的内容列表。

q->make_request_fn(q,bio);是对设备本身的实际函数指针调用。

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

显示如何使用索引写入分区。您应该注意,这不仅仅用于写入。

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.

删除→记忆 2024-09-04 16:03:02

如果你真的想从头开始发明这个特殊的轮子,我会利用请求队列功能。例如,要在请求进入队列时记录该请求,您可以将代码放入 submit_bio() 中。

我不确定挂在队列出口的最佳位置。也许在较旧的内核上有 elv_next_request() ,或者在较新的内核上有 blk_start_request()

If you really want to invent this particular wheel from scratch, I would tap in to the request queue functions. For example, to record the request as it enters the queue, you could put code into submit_bio().

I'm not sure of the best place to hook on the queue exit. Perhaps elv_next_request() on older kernels or blk_start_request() on newer ones.

忆沫 2024-09-04 16:03:02

它位于设备驱动程序中,通常通过 DMA 传输和中断信号 I/O 完成的组合来完成。对于每个特定的硬件设备,这些都是不同的。看看这里了解这有多复杂用一张简单的软盘就可以了。

编辑:

查看IO调度程序代码。

It's in the device drivers and is usually done via combination of DMA transfers and interrupts signaling I/O completion. These are different for each specific hardware device. Take a look here for how complicated this gets with a simple floppy.

Edit:

Look into IO scheduler code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文