struct target_type

系统中注册的 target_type 都链入 static LIST_HEAD(_targets)

int dm_register_target(struct target_type *tt) 向系统中注册 target_type,如果之前已经注册过了则返回 -EEXIST,否则成功注册并返回 0

void dm_unregister_target(struct target_type *tt) 从系统中注销 target_type,如果之前没有注册过,则报错 Unregistering unrecognised target: <target_type->name>BUG(),否则移出 static LIST_HEAD(_targets)

int dm_target_iterate(void (*iter_func)(struct target_type *tt, void *param), void *param) 对系统中注册的每个 target_type 执行 iter_func(target_type, param)。这个函数在执行 dmsetup targets 时会用到

struct target_type *dm_get_target_type(const char *name) 查找指定 name 对应的 target_type 并将对应的 dm- 模块引用计数 +1,如果找不到则尝试先加载对应的 dm- 模块;void dm_put_target_type(struct target_type *tt) 将 target_type 对应的 dm- 模块引用计数 -1

struct target_type

    /*
     * Information about a target type
     */
    struct target_type {
        uint64_t                    features;
        const char                  *name;
        struct module               *module;
        unsigned                    version[3];

        dm_ctr_fn                   ctr;
        dm_dtr_fn                   dtr;
        dm_map_fn                   map;

        dm_clone_and_map_request_fn clone_and_map_rq;
        dm_release_clone_request_fn release_clone_rq;

        dm_endio_fn                 end_io;
        dm_request_endio_fn         rq_end_io;

        dm_presuspend_fn            presuspend;
        dm_presuspend_undo_fn       presuspend_undo;
        dm_postsuspend_fn           postsuspend;
        dm_preresume_fn             preresume;
        dm_resume_fn                resume;

        dm_status_fn                status;
        dm_message_fn               message;

        dm_prepare_ioctl_fn         prepare_ioctl;

        dm_busy_fn                  busy;
        dm_iterate_devices_fn       iterate_devices;
        dm_io_hints_fn              io_hints;

        dm_dax_direct_access_fn     direct_access;
        dm_dax_copy_iter_fn         dax_copy_from_iter;
        dm_dax_copy_iter_fn         dax_copy_to_iter;

        /* For internal device-mapper use. */
        struct list_head            list;       链入 _targets 链表
    };

Target features

    /*
     * Any table that contains an instance of this target must have only one.
     */
    #define DM_TARGET_SINGLETON             0x00000001
    #define dm_target_needs_singleton(type) ((type)->features & DM_TARGET_SINGLETON)

    /*
     * Indicates that a target does not support read-only devices.
     */
    #define DM_TARGET_ALWAYS_WRITEABLE      0x00000002
    #define dm_target_always_writeable(type) ((type)->features & DM_TARGET_ALWAYS_WRITEABLE)

    /*
     * Any device that contains a table with an instance of this target may never
     * have tables containing any different target type.
     */
    #define DM_TARGET_IMMUTABLE             0x00000004
    #define dm_target_is_immutable(type)    ((type)->features & DM_TARGET_IMMUTABLE)

    /*
     * Indicates that a target may replace any target; even immutable targets.
     * .map, .map_rq, .clone_and_map_rq and .release_clone_rq are all defined.
     */
    #define DM_TARGET_WILDCARD              0x00000008
    #define dm_target_is_wildcard(type) ((type)->features & DM_TARGET_WILDCARD)

    /*
     * A target implements own bio data integrity.
     */
    #define DM_TARGET_INTEGRITY             0x00000010
    #define dm_target_has_integrity(type)   ((type)->features & DM_TARGET_INTEGRITY)

    /*
     * A target passes integrity data to the lower device.
     */
    #define DM_TARGET_PASSES_INTEGRITY      0x00000020
    #define dm_target_passes_integrity(type) ((type)->features & DM_TARGET_PASSES_INTEGRITY)

    /*
     * Indicates that a target supports host-managed zoned block devices.
     */
    #define DM_TARGET_ZONED_HM              0x00000040
    #define dm_target_supports_zoned_hm(type) ((type)->features & DM_TARGET_ZONED_HM)