linux内核md源代码解读 三 阵列建设的进程
发布时间:2016-10-30 08:15:00 所属栏目:Linux 来源:站长网
导读:副标题#e# 这一节我们阅读阵列的创建过程。 按照常理出牌,我们到ioctl中找阵列创建命令,md对应的ioctl函数是md_ioctl,当找对应的cmd命令字时,却完全没有类似CREATE_ARRAY的命令,那么就说明md设备并不是通过ioctl函数来创建的。其实如果我们仔细阅读一
|
这个文件为什么不放在md目录而放在include目录下?是因为文件里的内容是用户态跟内核态共用的,如果是内核态单独用的就没有必要放在这里了。 对于阵列的创建流程,最关心的命令字有: SET_ARRAY_INFO 设置阵列信息 ADD_NEW_DISK 添加磁盘到阵列 RUN_ARRAY 运行阵列 首先看设置阵列信息,这个函数是这三个函数中最简单的一个:
6000 /*
6001 * set_array_info is used two different ways
6002 * The original usage is when creating a new array.
6003 * In this usage, raid_disks is > 0 and it together with
6004 * level, size, not_persistent,layout,chunksize determine the
6005 * shape of the array.
6006 * This will always create an array with a type-0.90.0 superblock.
6007 * The newer usage is when assembling an array.
6008 * In this case raid_disks will be 0, and the major_version field is
6009 * use to determine which style super-blocks are to be found on the devices.
6010 * The minor and patch _version numbers are also kept incase the
6011 * super_block handler wishes to interpret them.
6012 */
6013 static int set_array_info(struct mddev * mddev, mdu_array_info_t *info)
6014 {
6015
6016 if (info->raid_disks == 0) {
6017 /* just setting version number for superblock loading */
6018 if (info->major_version < 0 ||
6019 info->major_version >= ARRAY_SIZE(super_types) ||
6020 super_types[info->major_version].name == NULL) {
6021 /* maybe try to auto-load a module? */
6022 printk(KERN_INFO
6023 "md: superblock version %d not knownn",
6024 info->major_version);
6025 return -EINVAL;
6026 }
6027 mddev->major_version = info->major_version;
6028 mddev->minor_version = info->minor_version;
6029 mddev->patch_version = info->patch_version;
6030 mddev->persistent = !info->not_persistent;
6031 /* ensure mddev_put doesn't delete this now that there
6032 * is some minimal configuration.
6033 */
6034 mddev->ctime = get_seconds();
6035 return 0;
6036 }
6037 mddev->major_version = MD_MAJOR_VERSION;
6038 mddev->minor_version = MD_MINOR_VERSION;
6039 mddev->patch_version = MD_PATCHLEVEL_VERSION;
6040 mddev->ctime = get_seconds();
6041
6042 mddev->level = info->level;
6043 mddev->clevel[0] = 0;
6044 mddev->dev_sectors = 2 * (sector_t)info->size;
6045 mddev->raid_disks = info->raid_disks;
6046 /* don't set md_minor, it is determined by which /dev/md* was
6047 * openned
6048 */
6049 if (info->state & (1<<MD_SB_CLEAN))
6050 mddev->recovery_cp = MaxSector;
6051 else
6052 mddev->recovery_cp = 0;
6053 mddev->persistent = ! info->not_persistent;
6054 mddev->external = 0;
6055
6056 mddev->layout = info->layout;
6057 mddev->chunk_sectors = info->chunk_size >> 9;
6058
6059 mddev->max_disks = MD_SB_DISKS;
6060
6061 if (mddev->persistent)
6062 mddev->flags = 0;
6063 set_bit(MD_CHANGE_DEVS, &mddev->flags);
6064
6065 mddev->bitmap_info.default_offset = MD_SB_BYTES >> 9;
6066 mddev->bitmap_info.default_space = 64*2 - (MD_SB_BYTES >> 9);
6067 mddev->bitmap_info.offset = 0;
6068
6069 mddev->reshape_position = MaxSector;
6070
6071 /*
6072 * Generate a 128 bit UUID
6073 */
6074 get_random_bytes(mddev->uuid, 16);
6075
6076 mddev->new_level = mddev->level;
6077 mddev->new_chunk_sectors = mddev->chunk_sectors;
6078 mddev->new_layout = mddev->layout;
6079 mddev->delta_disks = 0;
6080 mddev->reshape_backwards = 0;
6081
6082 return 0;
6083 }
(编辑:宣城站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |


