lib/format_text/text_label.c:函數
struct label_ops _text_ops = { .can_handle = _text_can_handle, .write = _text_write, .read = _text_read, .verify = _text_can_handle, .initialise_label = _text_initialise_label, .destroy_label = _text_destroy_label, .destroy = _fmt_text_destroy, };
format-text.c/format-text.c:code
lvm2的元數據是以純文本方式表達的,可讀性很好。元數據能夠放在磁盤開始的1M空間裏,也能夠放在/etc/lvm/backup/目錄下的文件裏。orm
文件元數據處理:rem
static struct metadata_area_ops _metadata_text_file_ops = { .vg_read = _vg_read_file, .vg_read_precommit = _vg_read_precommit_file, .vg_write = _vg_write_file, .vg_remove = _vg_remove_file, .vg_commit = _vg_commit_file };
磁盤元數據處理:get
static struct metadata_area_ops _metadata_text_raw_ops = { .vg_read = _vg_read_raw, .vg_read_precommit = _vg_read_precommit_raw, .vg_write = _vg_write_raw, .vg_remove = _vg_remove_raw, .vg_precommit = _vg_precommit_raw, .vg_commit = _vg_commit_raw, .vg_revert = _vg_revert_raw, .mda_metadata_locn_copy = _metadata_locn_copy_raw, .mda_metadata_locn_name = _metadata_locn_name_raw, .mda_metadata_locn_offset = _metadata_locn_offset_raw, .mda_free_sectors = _mda_free_sectors_raw, .mda_total_sectors = _mda_total_sectors_raw, .mda_in_vg = _mda_in_vg_raw, .pv_analyze_mda = _pv_analyze_mda_raw, .mda_locns_match = _mda_locns_match_raw, .mda_get_device = _mda_get_device_raw, .mda_export_text = _mda_export_text_raw, .mda_import_text = _mda_import_text_raw };
備份文件中元數據處理,備份文件和普通文件有什麼區別呢?cmd
static struct metadata_area_ops _metadata_text_file_backup_ops = { .vg_read = _vg_read_file, .vg_write = _vg_write_file, .vg_remove = _vg_remove_file, .vg_commit = _vg_commit_file_backup };
如上述,元數據處理有不一樣的操做集,相似VFS和具體文件系統的關係,得有一個抽象的處理集。it
static struct format_handler _text_handler = { .scan = _text_scan, .pv_read = _text_pv_read, .pv_initialise = _text_pv_initialise, .pv_setup = _text_pv_setup, .pv_add_metadata_area = _text_pv_add_metadata_area, .pv_remove_metadata_area = _text_pv_remove_metadata_area, .pv_resize = _text_pv_resize, .pv_write = _text_pv_write, .pv_needs_rewrite = _text_pv_needs_rewrite, .vg_setup = _text_vg_setup, .lv_setup = _text_lv_setup, .create_instance = _text_create_text_instance, .destroy_instance = _text_destroy_instance, .destroy = _text_destroy };
struct format_type *create_text_format(struct cmd_context *cmd) 就像一個工廠函數,根據命令,實例化匹配的元數據處理集。form
struct labeller *text_labeller_create(const struct format_type *fmt) 負責實例化標籤處理, 而後在標籤和文本處理結構間作cross-link.import