@@ -489,6 +489,7 @@ check_name_from_bdev_subsys(struct json_config_ctx *ctx)
489489
490490 D_ASSERT (ctx -> config_it != NULL );
491491
492+ // todo: /mnt/daos/2/daos_nvme.conf 这个文件是什么时候创建的
492493 rc = spdk_json_decode_object (ctx -> config_it , config_entry_decoders ,
493494 SPDK_COUNTOF (config_entry_decoders ), & cfg );
494495 if (rc < 0 ) {
@@ -511,9 +512,11 @@ check_name_from_bdev_subsys(struct json_config_ctx *ctx)
511512 if (name == NULL )
512513 D_GOTO (free_method , rc = - DER_NOMEM );
513514
515+ // 遍历json 文件中 conf.params 元素
514516 key = spdk_json_object_first (cfg .params );
515517 while (key != NULL ) {
516518 value = json_value (key );
519+ // 找到所有的 bdev_nvme_attach_controller,即nvme 列表
517520 if (spdk_json_strequal (key , "name" )) {
518521 // 获取name 的值,类似:Nvme_server03_0_1_0
519522 value = json_value (key );
@@ -522,7 +525,7 @@ check_name_from_bdev_subsys(struct json_config_ctx *ctx)
522525 D_GOTO (free_name , rc = - DER_INVAL );
523526 }
524527
525- // 追加到name
528+ // 追加到name. 例如:"Nvme_server03_0_1_0"
526529 memcpy (name , value -> start , value -> len );
527530 name [value -> len ] = '\0' ;
528531
@@ -547,6 +550,7 @@ check_name_from_bdev_subsys(struct json_config_ctx *ctx)
547550 },
548551
549552 */
553+ // 解析name 转化成 role
550554 rc = bdev_name2roles (name );
551555 if (rc < 0 ) {
552556 D_ERROR ("bdev_name contains invalid roles: %s\n" , name );
@@ -555,6 +559,7 @@ check_name_from_bdev_subsys(struct json_config_ctx *ctx)
555559 // 统计role 二进制信息,并返回
556560 roles |= rc ;
557561 }
562+ // 循环下一个param
558563 key = spdk_json_next (key );
559564 }
560565
@@ -603,6 +608,7 @@ add_bdevs_to_opts(struct json_config_ctx *ctx, struct spdk_json_val *bdev_ss, bo
603608 return rc ;
604609
605610 while (ctx -> config_it != NULL ) {
611+ // 将pci 地址添加到opts 中
606612 rc = add_traddrs_from_bdev_subsys (ctx , vmd_enabled , opts );
607613 if (rc != 0 )
608614 return rc ;
@@ -687,7 +693,79 @@ bio_add_allowed_alloc(const char *nvme_conf, struct spdk_env_opts *opts, int *ro
687693 if (ctx == NULL )
688694 return - DER_NOMEM ;
689695
696+ // 读取保存bdev pcie 地址的json 文件
690697 rc = read_config (nvme_conf , ctx );
698+ /*
699+ root@server01:~# cat /mnt/daos/2/daos_nvme.conf
700+ {
701+ "daos_data": {
702+ "config": []
703+ },
704+ "subsystems": [
705+ {
706+ "subsystem": "bdev",
707+ "config": [
708+ {
709+ "params": {
710+ "bdev_io_pool_size": 65536,
711+ "bdev_io_cache_size": 256
712+ },
713+ "method": "bdev_set_options"
714+ },
715+ {
716+ "params": {
717+ "retry_count": 4,
718+ "timeout_us": 0,
719+ "nvme_adminq_poll_period_us": 100000,
720+ "action_on_timeout": "none",
721+ "nvme_ioq_poll_period_us": 0
722+ },
723+ "method": "bdev_nvme_set_options"
724+ },
725+ {
726+ "params": {
727+ "enable": false,
728+ "period_us": 0
729+ },
730+ "method": "bdev_nvme_set_hotplug"
731+ },
732+ {
733+ "params": {
734+ "trtype": "PCIe",
735+ "name": "Nvme_server01_0_1_0",
736+ "traddr": "0000:e3:00.0"
737+ },
738+ "method": "bdev_nvme_attach_controller"
739+ },
740+ {
741+ "params": {
742+ "trtype": "PCIe",
743+ "name": "Nvme_server01_1_1_0",
744+ "traddr": "0000:e4:00.0"
745+ },
746+ "method": "bdev_nvme_attach_controller"
747+ },
748+ {
749+ "params": {
750+ "trtype": "PCIe",
751+ "name": "Nvme_server01_2_1_0",
752+ "traddr": "0000:e5:00.0"
753+ },
754+ "method": "bdev_nvme_attach_controller"
755+ },
756+ {
757+ "params": {
758+ "trtype": "PCIe",
759+ "name": "Nvme_server01_3_1_0",
760+ "traddr": "0000:e6:00.0"
761+ },
762+ "method": "bdev_nvme_attach_controller"
763+ }
764+ ]
765+ }
766+ ]
767+ }root@server01:~#
768+ */
691769 if (rc != 0 )
692770 D_GOTO (out , rc );
693771
@@ -716,14 +794,17 @@ bio_add_allowed_alloc(const char *nvme_conf, struct spdk_env_opts *opts, int *ro
716794 D_GOTO (out , rc = - DER_INVAL );
717795 }
718796
719- // 找到subsystem 的bdev
797+ // 当前子系统如果是bdev
720798 if (spdk_json_strequal (ctx -> subsystem_name , "bdev" ))
799+ // todo: 如果有多个bdev 不就覆盖了?正常只会有一个子系统
721800 bdev_ss = ctx -> subsystems_it ;
722801
802+ // vmd 技术:将nvme 插拔pcie 总线事件重定向至存储感知的驱动程序
723803 if (spdk_json_strequal (ctx -> subsystem_name , BIO_DEV_TYPE_VMD ))
724804 vmd_ss = ctx -> subsystems_it ;
725805
726806 /* Move on to next subsystem */
807+ // 继续下一个循环,正常只循环一次
727808 ctx -> subsystems_it = spdk_json_next (ctx -> subsystems_it );
728809 };
729810
@@ -740,8 +821,10 @@ bio_add_allowed_alloc(const char *nvme_conf, struct spdk_env_opts *opts, int *ro
740821 rc = check_md_on_ssd_status (ctx , bdev_ss );
741822 if (rc < 0 )
742823 goto out ;
824+ // role 作为返回值
743825 * roles = rc ;
744826
827+ // 将解析出来的pcie 地址,添加到 opts 中
745828 rc = add_bdevs_to_opts (ctx , bdev_ss , vmd_enabled , opts );
746829out :
747830 free_json_config_ctx (ctx );
0 commit comments