{"id":169003,"date":"2020-01-11T12:00:02","date_gmt":"2020-01-11T04:00:02","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=169003"},"modified":"2020-01-13T13:16:03","modified_gmt":"2020-01-13T05:16:03","slug":"linux-device-mapper-kernel","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-device-mapper-kernel.html","title":{"rendered":"\u4e86\u89e3Linux\u7cfb\u7edf\u4e2d\u7684Device Mapper\u673a\u5236\uff1a\u5185\u6838\u7a7a\u95f4"},"content":{"rendered":"
\u5bfc\u8bfb<\/td>\n | Device Mapper \u662f Linux2.6 \u5185\u6838\u4e2d\u652f\u6301\u903b\u8f91\u5377\u7ba1\u7406\u7684\u901a\u7528\u8bbe\u5907\u6620\u5c04\u673a\u5236\uff0c\u5b83\u4e3a\u5b9e\u73b0\u7528\u4e8e\u5b58\u50a8\u8d44\u6e90\u7ba1\u7406\u7684\u5757\u8bbe\u5907\u9a71\u52a8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u5ea6\u6a21\u5757\u5316\u7684\u5185\u6838\u67b6\u6784\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n Device Mapper \u662f Linux2.6 \u5185\u6838\u4e2d\u652f\u6301\u903b\u8f91\u5377\u7ba1\u7406\u7684\u901a\u7528\u8bbe\u5907\u6620\u5c04\u673a\u5236\uff0c\u5b83\u4e3a\u5b9e\u73b0\u7528\u4e8e\u5b58\u50a8\u8d44\u6e90\u7ba1\u7406\u7684\u5757\u8bbe\u5907\u9a71\u52a8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u9ad8\u5ea6\u6a21\u5757\u5316\u7684\u5185\u6838\u67b6\u6784\uff0c\u5982\u4e0b\u56fe:<\/p>\n <\/p>\n \u5728\u5185\u6838\u4e2d\u5b83\u901a\u8fc7\u4e00\u4e2a\u4e00\u4e2a\u6a21\u5757\u5316\u7684 target driver \u63d2\u4ef6\u5b9e\u73b0\u5bf9 IO \u8bf7\u6c42\u7684\u8fc7\u6ee4\u6216\u8005\u91cd\u65b0\u5b9a\u5411\u7b49\u5de5\u4f5c\uff0c\u5f53\u524d\u5df2\u7ecf\u5b9e\u73b0\u7684 target driver \u63d2\u4ef6\u5305\u62ec\u8f6f raid\u3001\u8f6f\u52a0\u5bc6\u3001\u903b\u8f91\u5377\u6761\u5e26\u3001\u591a\u8def\u5f84\u3001\u955c\u50cf\u3001\u5feb\u7167\u7b49\uff0c\u56fe\u4e2d linear\u3001mirror\u3001snapshot\u3001multipath \u8868\u793a\u7684\u5c31\u662f\u8fd9\u4e9b target driver\u3002Device mapper \u8fdb\u4e00\u6b65\u4f53\u73b0\u4e86\u5728 Linux \u5185\u6838\u8bbe\u8ba1\u4e2d\u7b56\u7565\u548c\u673a\u5236\u5206\u79bb\u7684\u539f\u5219\uff0c\u5c06\u6240\u6709\u4e0e\u7b56\u7565\u76f8\u5173\u7684\u5de5\u4f5c\u653e\u5230\u7528\u6237\u7a7a\u95f4\u5b8c\u6210\uff0c\u5185\u6838\u4e2d\u4e3b\u8981\u63d0\u4f9b\u5b8c\u6210\u8fd9\u4e9b\u7b56\u7565\u6240\u9700\u8981\u7684\u673a\u5236\u3002Device mapper \u7528\u6237\u7a7a\u95f4\u76f8\u5173\u90e8\u5206\u4e3b\u8981\u8d1f\u8d23\u914d\u7f6e\u5177\u4f53\u7684\u7b56\u7565\u548c\u63a7\u5236\u903b\u8f91\uff0c\u6bd4\u5982\u903b\u8f91\u8bbe\u5907\u548c\u54ea\u4e9b\u7269\u7406\u8bbe\u5907\u5efa\u7acb\u6620\u5c04\uff0c\u600e\u4e48\u5efa\u7acb\u8fd9\u4e9b\u6620\u5c04\u5173\u7cfb\u7b49\u7b49\uff0c\u800c\u5177\u4f53\u8fc7\u6ee4\u548c\u91cd\u5b9a\u5411 IO \u8bf7\u6c42\u7684\u5de5\u4f5c\u7531\u5185\u6838\u4e2d\u76f8\u5173\u4ee3\u7801\u5b8c\u6210\u3002\u56e0\u6b64\u6574\u4e2a device mapper \u673a\u5236\u7531\u4e24\u90e8\u5206\u7ec4\u6210--\u5185\u6838\u7a7a\u95f4\u7684 device mapper \u9a71\u52a8\u3001\u7528\u6237\u7a7a\u95f4\u7684device mapper \u5e93\u4ee5\u53ca\u5b83\u63d0\u4f9b\u7684 dmsetup \u5de5\u5177\u3002\u5728\u4e0b\u6587\u4e2d\uff0c\u6211\u4eec\u5206\u5185\u6838\u548c\u7528\u6237\u7a7a\u95f4\u4e24\u90e8\u5206\u8fdb\u884c\u4ecb\u7ecd\u3002<\/p>\n \u5185\u6838\u90e8\u5206<\/strong><\/div>\n Device mapper \u7684\u5185\u6838\u76f8\u5173\u4ee3\u7801\u5df2\u7ecf\u4f5c\u4e3a Linux 2.6 \u5185\u6838\u53d1\u5e03\u7248\u7684\u4e00\u90e8\u5206\u96c6\u6210\u5230\u5185\u6838\u6e90\u7801\u4e2d\u4e86\uff0c\u76f8\u5173\u4ee3\u7801\u5728\u5185\u6838\u6e90\u7801\u7684 driver\/md\/ \u76ee\u5f55\u4e2d\uff0c\u5176\u4ee3\u7801\u6587\u4ef6\u53ef\u4ee5\u5212\u5206\u4e3a\u5b9e\u73b0 device mapper \u5185\u6838\u4e2d\u57fa\u672c\u67b6\u6784\u7684\u6587\u4ef6\u548c\u5b9e\u73b0\u5177\u4f53\u6620\u5c04\u5de5\u4f5c\u7684 target driver \u63d2\u4ef6\u6587\u4ef6\u4e24\u90e8\u5206\u3002\u6587\u7ae0\u4e0b\u9762\u7684\u5206\u6790\u7ed3\u679c\u4e3b\u8981\u662f\u57fa\u4e8e\u4e0a\u8ff0\u6e90\u7801\u6587\u4ef6\u5f97\u5230\u7684\u3002<\/p>\n \u91cd\u8981\u6982\u5ff5<\/strong><\/span><\/div>\n Device mapper \u5728\u5185\u6838\u4e2d\u4f5c\u4e3a\u4e00\u4e2a\u5757\u8bbe\u5907\u9a71\u52a8\u88ab\u6ce8\u518c\u7684\uff0c\u5b83\u5305\u542b\u4e09\u4e2a\u91cd\u8981\u7684\u5bf9\u8c61\u6982\u5ff5\uff0cmapped device\u3001\u6620\u5c04\u8868\u3001target device\u3002Mapped device \u662f\u4e00\u4e2a\u903b\u8f91\u62bd\u8c61\uff0c\u53ef\u4ee5\u7406\u89e3\u6210\u4e3a\u5185\u6838\u5411\u5916\u63d0\u4f9b\u7684\u903b\u8f91\u8bbe\u5907\uff0c\u5b83\u901a\u8fc7\u6620\u5c04\u8868\u63cf\u8ff0\u7684\u6620\u5c04\u5173\u7cfb\u548c target device \u5efa\u7acb\u6620\u5c04\u3002\u4ece Mapped device \u5230\u4e00\u4e2a target device \u7684\u6620\u5c04\u8868\u7531\u4e00\u4e2a\u591a\u5143\u7ec4\u8868\u793a\uff0c\u8be5\u591a\u5143\u7ec4\u7531\u8868\u793a mapped device \u903b\u8f91\u7684\u8d77\u59cb\u5730\u5740\u3001\u8303\u56f4\u3001\u548c\u8868\u793a\u5728 target device \u6240\u5728\u7269\u7406\u8bbe\u5907\u7684\u5730\u5740\u504f\u79fb\u91cf\u4ee5\u53catarget \u7c7b\u578b\u7b49\u53d8\u91cf\u7ec4\u6210\uff08\u8fd9\u4e9b\u5730\u5740\u548c\u504f\u79fb\u91cf\u90fd\u662f\u4ee5\u78c1\u76d8\u7684\u6247\u533a\u4e3a\u5355\u4f4d\u7684\uff0c\u5373 512 \u4e2a\u5b57\u8282\u5927\u5c0f\uff09\u3002Target device \u8868\u793a\u7684\u662f mapped device \u6240\u6620\u5c04\u7684\u7269\u7406\u7a7a\u95f4\u6bb5\uff0c\u5bf9 mapped device \u6240\u8868\u793a\u7684\u903b\u8f91\u8bbe\u5907\u6765\u8bf4\uff0c\u5c31\u662f\u8be5\u903b\u8f91\u8bbe\u5907\u6620\u5c04\u5230\u7684\u4e00\u4e2a\u7269\u7406\u8bbe\u5907\u3002Device mapper \u4e2d\u8fd9\u4e09\u4e2a\u5bf9\u8c61\u548c target driver \u63d2\u4ef6\u4e00\u8d77\u6784\u6210\u4e86\u4e00\u4e2a\u53ef\u8fed\u4ee3\u7684\u8bbe\u5907\u6811\u3002\u5728\u8be5\u6811\u578b\u7ed3\u6784\u4e2d\u7684\u9876\u5c42\u6839\u8282\u70b9\u662f\u6700\u7ec8\u4f5c\u4e3a\u903b\u8f91\u8bbe\u5907\u5411\u5916\u63d0\u4f9b\u7684 mapped device\uff0c\u53f6\u5b50\u8282\u70b9\u662f target device \u6240\u8868\u793a\u7684\u5e95\u5c42\u7269\u7406\u8bbe\u5907\u3002\u6700\u5c0f\u7684\u8bbe\u5907\u6811\u7531\u5355\u4e2a mapped device \u548c target device \u7ec4\u6210\u3002\u6bcf\u4e2a target device \u90fd\u662f\u88abmapped device \u72ec\u5360\u7684\uff0c\u53ea\u80fd\u88ab\u4e00\u4e2a mapped device \u4f7f\u7528\u3002\u4e00\u4e2a mapped device \u53ef\u4ee5\u6620\u5c04\u5230\u4e00\u4e2a\u6216\u8005\u591a\u4e2a target device \u4e0a\uff0c\u800c\u4e00\u4e2a mapped device \u53c8\u53ef\u4ee5\u4f5c\u4e3a\u5b83\u4e0a\u5c42 mapped device\u7684 target device \u88ab\u4f7f\u7528\uff0c\u8be5\u5c42\u6b21\u5728\u7406\u8bba\u4e0a\u53ef\u4ee5\u5728 device mapper \u67b6\u6784\u4e0b\u65e0\u9650\u8fed\u4ee3\u4e0b\u53bb\u3002<\/p>\n <\/p>\n \u4ece\u4e0a\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230 mapped device1 \u901a\u8fc7\u6620\u5c04\u8868\u548c a\u3001b\u3001c \u4e09\u4e2a target device \u5efa\u7acb\u4e86\u6620\u5c04\u5173\u7cfb\uff0c\u800c target device a \u53c8\u662f\u901a\u8fc7 mapped device 2 \u6f14\u5316\u8fc7\u6765\uff0cmapped device 2 \u901a\u8fc7\u6620\u5c04\u8868\u548c target device d \u5efa\u7acb\u6620\u5c04\u5173\u7cfb\u3002<\/p>\n \u6211\u4eec\u8fdb\u4e00\u6b65\u770b\u4e00\u4e0b\u4e0a\u56fe\u4e2d\u4e09\u4e2a\u5bf9\u8c61\u5728\u4ee3\u7801\u4e2d\u7684\u5177\u4f53\u5b9e\u73b0\uff0cdm.c \u6587\u4ef6\u5b9a\u4e49\u7684 mapped_device \u7ed3\u6784\u7528\u4e8e\u8868\u793a mapped device\uff0c\u5b83\u4e3b\u8981\u5305\u62ec\u8be5 mapped device \u76f8\u5173\u7684\u9501\uff0c\u6ce8\u518c\u7684\u8bf7\u6c42\u961f\u5217\u548c\u4e00\u4e9b\u5185\u5b58\u6c60\u4ee5\u53ca\u6307\u5411\u5b83\u6240\u5bf9\u5e94\u6620\u5c04\u8868\u7684\u6307\u9488\u7b49\u57df\u3002<\/p>\n Mapped device \u5bf9\u5e94\u7684\u6620\u5c04\u8868\u662f\u7531 dm_table.c \u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684 dm_table \u7ed3\u6784\u8868\u793a\u7684\uff0c\u8be5\u7ed3\u6784\u4e2d\u5305\u542b\u4e00\u4e2a dm_target\u7ed3\u6784\u6570\u7ec4\uff0cdm_target \u7ed3\u6784\u5177\u4f53\u63cf\u8ff0\u4e86 mapped_device \u5230\u5b83\u67d0\u4e2a target device \u7684\u6620\u5c04\u5173\u7cfb\u3002<\/p>\n \u800c\u5728 dm_table \u7ed3\u6784\u4e2d\u5c06\u8fd9\u4e9b dm_target \u6309\u7167 B \u6811\u7684\u65b9\u5f0f\u7ec4\u7ec7\u8d77\u6765\u65b9\u4fbf IO \u8bf7\u6c42\u6620\u5c04\u65f6\u7684\u67e5\u627e\u64cd\u4f5c\u3002Dm_target \u7ed3\u6784\u5177\u4f53\u8bb0\u5f55\u8be5\u7ed3\u6784\u5bf9\u5e94 target device \u6240\u6620\u5c04\u7684 mapped device \u903b\u8f91\u533a\u57df\u7684\u5f00\u59cb\u5730\u5740\u548c\u8303\u56f4\uff0c\u540c\u65f6\u8fd8\u5305\u542b\u6307\u5411\u5177\u4f53 target device \u76f8\u5173\u64cd\u4f5c\u7684 target_type \u7ed3\u6784\u7684\u6307\u9488\u3002<\/p>\n Target_type \u7ed3\u6784\u4e3b\u8981\u5305\u542b\u4e86 target device \u5bf9\u5e94\u7684 target driver \u63d2\u4ef6\u7684\u540d\u5b57\u3001\u5b9a\u4e49\u7684\u6784\u5efa\u548c\u5220\u9664\u8be5\u7c7b\u578btarget device\u7684\u65b9\u6cd5\u3001\u8be5\u7c7btarget device\u5bf9\u5e94\u7684IO\u8bf7\u6c42\u91cd\u6620\u5c04\u548c\u7ed3\u675fIO\u7684\u65b9\u6cd5\u7b49\u3002\u800c\u8868\u793a\u5177\u4f53\u7684target device\u7684\u57df\u662fdm_target\u4e2d\u7684private\u57df\uff0c\u8be5\u6307\u9488\u6307\u5411mapped device\u6240\u6620\u5c04\u7684\u5177\u4f53target device\u5bf9\u5e94\u7684\u7ed3\u6784\u3002\u8868\u793atarget device\u7684\u5177\u4f53\u7ed3\u6784\u7531\u4e8e\u4e0d\u540c\u7684target \u7c7b\u578b\u800c\u4e0d\u540c\uff0c\u6bd4\u5982\u6700\u7b80\u5355\u7684\u7ebf\u6027\u6620\u5c04target\u7c7b\u578b\u5bf9\u5e94target device\u7684\u7ed3\u6784\u662fdm-linear.c\u6587\u4ef6\u4e2d\u5b9a\u4e49\u7684linear_c\u7ed3\u6784\u3002\u5176\u5b9a\u4e49\u5982\u4e0b\uff1a<\/p>\n struct linear_c { struct dm_dev *dev; sector_t start; };<\/pre>\n |