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.
     */
};

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

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 中了:

doc

https://www.linux-kvm.org/images/b/b5/2012-fourm-block-overview.pdf

On the command line: -hda test.img …is a shortcut for… -drive file=test.img,if=ide,cache=writeback,aio=threads …is a shortcut for… -drive file=test.img,id=ide0-hd0,if=none,cache=writeback,aio=threads -device ide-drive,bus=ide.0,drive=ide0-hd0

SCSI passthrough

VMDK, VHD, VDI…

External snapshots (backing files): – base – sn1 – sn2 – sn3

Internal snapshots (savevm/loadvm, qcow2 only):

image streaing Use cases:

http://events17.linuxfoundation.org/sites/events/files/slides/talk_11.pdf

总是如此,直接穿过这里的:

源码分析

调用 BlockDriver:: bdrv_co_preadv_part / bdrv_co_preadv / bdrv_aio_preadv / bdrv_co_readv 在 bdrv_driver_preadv 中,这个是有优先级的。

使用 block layer 作为例子

typedef struct NvmeRequest {
    struct NvmeSQueue       *sq;
    struct NvmeNamespace    *ns;
    BlockAIOCB              *aiocb; // 就是逐个位置了
    uint16_t                status;
    void                    *opaque;
    NvmeCqe                 cqe;
    NvmeCmd                 cmd;
    BlockAcctCookie         acct;
    NvmeSg                  sg;
    QTAILQ_ENTRY(NvmeRequest)entry;
} NvmeRequest;

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