Skip to the content.

block

疑惑

忽然意识到,block 文件夹下,其实基本是这些 driver 的:

阅读其他模块同时检测到的内容,也是比较关键的内容:

有趣的

block 代码基本分析

代码量比较大的问题,基本上都是各种后端。

blockdev.c

  1. 前面的好几千行就是用于定义这个的
  2. 后面的就是各种 qmp 操作的
static const BlkActionOps actions[] = {
    [TRANSACTION_ACTION_KIND_BLOCKDEV_SNAPSHOT] = {
        .instance_size = sizeof(ExternalSnapshotState),
        .prepare  = external_snapshot_prepare,
        .commit   = external_snapshot_commit,
        .abort = external_snapshot_abort,
        .clean = external_snapshot_clean,
    },
    // ... 还有很多类似的,就不拷贝了

    /* Where are transactions for MIRROR, COMMIT and STREAM?
     * Although these blockjobs use transaction callbacks like the backup job,
     * these jobs do not necessarily adhere to transaction semantics.
     * These jobs may not fully undo all of their actions on abort, nor do they
     * necessarily work in transactions with more than one job in them.
     */
};

qmp_transaction 中的,根据命令来调用这些内容:

block.c

一些 backtrace

io_uring

typedef enum BlockdevAioOptions {
    BLOCKDEV_AIO_OPTIONS_THREADS,
    BLOCKDEV_AIO_OPTIONS_NATIVE,
#if defined(CONFIG_LINUX_IO_URING)
    BLOCKDEV_AIO_OPTIONS_IO_URING,
#endif /* defined(CONFIG_LINUX_IO_URING) */
    BLOCKDEV_AIO_OPTIONS__MAX,
} BlockdevAioOptions;

block job

block dirty bitmap

qmp :没办法,不搞的话,dirty bitmap 是没有办法维持生活的

看看 coroutine_fn 的实现和效果

static coroutine_fn int ssh_read(BDRVSSHState *s, BlockDriverState *bs,
                                 int64_t offset, size_t size,
                                 QEMUIOVector *qiov)

nfs 也可以直接做后端,不理解啊

block/nvme.c 是通过 iommu 的,

其他的奇怪后端

继续看看的

BlockDriver 似乎有很多抽象的后端,也就是后端里面还有后端了。

static BlockDriver bdrv_dmg = {
    .format_name    = "dmg",

[ ] 什么是 filter

关于 scsi 的代码

scsi/ block/iscsi.c block/iscsi-opts.c

这下面有一个 scsi/qemu-pr-helper.c 做什么的?

使用 alpine.sh 中的配置之后:

如果是发起 io :

如果是从 target (server) 哪里接受到消息,整个流程都是很熟悉了:

iscsi_process_read(void *arg)
{
    IscsiLun *iscsilun = arg;
    struct iscsi_context *iscsi = iscsilun->iscsi;

    qemu_mutex_lock(&iscsilun->mutex);
    iscsi_service(iscsi, POLLIN);
    iscsi_set_events(iscsilun);
    qemu_mutex_unlock(&iscsilun->mutex);
}

这里的 iscsi_service 就是调用的 libiscsi 的服务了:

/nix/store/ykvbkghvny9hfmxfzl0mlrjwxxzg34y2-libiscsi-1.20.0/include/iscsi/iscsi.h

看上去复杂的逻辑,例如 openiscs 都是在 openiscsi 中了:

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。