Cinder 组件

2021SC@SDUSC

Cinder 组件

一. Cinder 简介

cinder 是OpenStack 块存储的服务,为Nova虚拟机,容器等提供volume。

cinder的目的

  • 以组件为基础的架构:快速添加新行为
  • 高可用性:大负载规模
  • 容错性:将进程隔离以防止错误剧增
  • 可恢复性:错误更容易被发现和纠正
  • 开放标准:成为社区驱动api的一个实现

块存储:

  1. 操作系统获得存储空间的方式一般有两种:

​ 1. 通过某种协议(SAS,SCSI,SAN,iSCSI 等)挂接裸硬盘,然后分区、格式化、创建文件系统;或者直接使用裸硬盘存储数据(数据库)。

​ 2. 通过 NFS、CIFS 等 协议,mount 远程的文件系统。

   2. 第一种裸硬盘的方式叫做 Block Storage(块存储),每个裸硬盘通常也称作 Volume(卷) 第二种叫做文件系统存储。NAS 和 NFS 服务器,以及各种分布式文件系统提供的都是这种存储。

块存储服务提供对 volume 从创建到删除整个生命周期的管理。从 instance 的角度看,挂载的每一个 Volume 都是一块硬盘。OpenStack 提供 Block Storage Service 的是 Cinder,其具体功能是:

​ 1. 提供 REST API 使用户能够查询和管理 volume、volume snapshot 以及 volume type。

​ 2. 提供 scheduler 调度 volume 创建请求,合理优化存储资源的分配

​ 3. 通过 driver 架构支持多种 back-end(后端)存储方式,包括 LVM,NFS,Ceph 和其他诸如 EMC、IBM 等商业存储产品和方案

二 .架构简图

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-jPD394sG-1635174897985)(C:\Users\Jeremiah\AppData\Roaming\Typora\typora-user-images\image-20211025213146992.png)]

cinder-api :

  1. 控制卷的创建,删除,保存(从卷,镜像和快照中创建)

     				2. 快照的创建,删除和保存
     				3. volume attach and detach (call by nova)
     				4. 管理卷的种类,配额和备份
    

cinder-volume:

主要组件:

  • API:cinder-api与cinder-volume的交互

  • manager:真正实现api的组件

  • driver:manager 组件调用,包含与多种存储类型交流的后端专用代码。

    注:

    1. admin 控制多个cinder-volume 的实例 (每个实例拥有其配置文件和存储后端)
    2. 一个cinder-volume实例管理多个后端
    3. 每个后端驱动与一个存储池相交互

cinder - scheduler:

  1. 选择哪个后端用于放置新的volume

  2. 设置scheduler的插件 (Filter scheduler has plugins for filters and weights)

    filter scheduler

    流程:

    1. 查看所有后端
    2. 按照要求过滤(如:driver要求的容量和状态,admin 创建volumn时的具体要求和user可能指定的volumn_type)
    3. 按照权重排序(如:可用空间)
    4. 返回最佳可用卷

volume-provider:

数据的存储设备,为volume提供存储空间,每个provider通过自己的driver与cinder-volume相协作。

三.Nova与Cinder的控制流

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-XJN2nQyw-1635174897988)(C:\Users\Jeremiah\AppData\Roaming\Typora\typora-user-images\image-20211025214907243.png)]

  1. Nova 通过 cinder的api调用cinder,传递连接信息
  2. cinder-api向cinder-volume传递信息
  3. manager执行最初的错误检查并调用volume-driver
  4. volume-driver 为接下来的连接执行必要准备
  5. volume-driver返回连接信息,返回给Nova
  6. Nova用返回的信息建立与存储的连接
  7. Nova将volume 设备/文件 返回给虚拟机
四.创建卷的流程

一 cinder api

  1. 调用cinder 提供api (api有v2和v3两个版本,v2已经被移除,现在默认使用v3版本,v3会进行更多的检查)即:v3/volume

    api对请求做了name,description,image_id,type,metadata,snapshot等做了检查

    之后调用volume_api的create方法

try:

      new_volume = self.volume_api.create(

        context, size, volume.get('display_name'),

        volume.get('display_description'), **kwargs)

    *except* exception.VolumeTypeDefaultMisconfiguredError *as* err:

       *raise* exc.HTTPInternalServerError(*explanation*=err.msg)
  1. cinder\volume\api.py

检查volume_type和snapshot,并check metadata的属性,安装创建属性列表调用flows\api\create_volume.py的get_flow方法

        create_what = {
            'context': context,
            'raw_size': size,
            'name': name,
            'description': description,
            'snapshot': snapshot,
            'image_id': image_id,
            'raw_volume_type': volume_type,
            'metadata': metadata or {},
            'raw_availability_zone': availability_zone,
            'source_volume': source_volume,
            'scheduler_hints': scheduler_hints,
            'key_manager': self.key_manager,
            'optional_args': {'is_quota_committed': False},
            'consistencygroup': consistencygroup,
            'cgsnapshot': cgsnapshot,
            'raw_multiattach': multiattach,
            'group': group,
            'group_snapshot': group_snapshot,
            'source_group': source_group,
            'backup': backup,
        }
        try:
            sched_rpcapi = (self.scheduler_rpcapi if (
                            not cgsnapshot and not source_cg and
                            not group_snapshot and not source_group)
                            else None)
            volume_rpcapi = (self.volume_rpcapi if (
                             not cgsnapshot and not source_cg and
                             not group_snapshot and not source_group)
                             else None)
            flow_engine = create_volume.get_flow(self.db,
                                                 self.image_service,
                                                 availability_zones,
                                                 create_what,
                                                 sched_rpcapi,
                                                 volume_rpcapi)
  1. volume\flows\api\create_volume.py

    创建并返回api 的入口流:为独立任务注入键值对;解压并验证键值对;保存分配的额度,创建数据库入口;提交额度;将任务交给scheduler或者manager

    flow_name = ACTION.replace(":", "_") + "_api"
    api_flow = linear_flow.Flow(flow_name)

    api_flow.add(ExtractVolumeRequestTask(
        image_service_api,
        availability_zones,
        rebind={'size': 'raw_size',
                'availability_zone': 'raw_availability_zone',
                'volume_type': 'raw_volume_type',
                'multiattach': 'raw_multiattach'}))
    api_flow.add(QuotaReserveTask(),
                 EntryCreateTask(),
                 QuotaCommitTask())

    if scheduler_rpcapi and volume_rpcapi:
        # This will cast it out to either the scheduler or volume manager via
        # the rpc apis provided.
        api_flow.add(VolumeCastTask(scheduler_rpcapi, volume_rpcapi, db_api))

    # Now load (but do not run) the flow using the provided initial data.
    return taskflow.engines.load(api_flow, store=create_what)
  1. cinder\scheduler\rpcapi.py

    调用scheduler manager.py的SchedulerManager.create_volume方法

二 scheduler

  1. cinder\scheduler\manager.py

    调用 flows 的create_volume方法

              flow_engine = create_volume.get_flow(context,
                                                     self.driver,
                                                     request_spec,
                                                     filter_properties,
                                                     volume,
                                                     snapshot_id,
                                                     image_id,
                                                     backup_id)
    
  2. cinder\scheduler\flows\create_volume.py

    创建ScheduleCreateVolumeTask
    ScheduleCreateVolumeTask.execute函数,会调用driver_api.schedule_create_volume

        create_what = {
            'context': context,
            'raw_request_spec': request_spec,
            'filter_properties': filter_properties,
            'volume': volume,
            'snapshot_id': snapshot_id,
            'image_id': image_id,
            'backup_id': backup_id,
        }
    
        flow_name = ACTION.replace(":", "_") + "_scheduler"
        scheduler_flow = linear_flow.Flow(flow_name)
    
        # This will extract and clean the spec from the starting values.
        scheduler_flow.add(ExtractSchedulerSpecTask(
            rebind={'request_spec': 'raw_request_spec'}))
    
        # This will activate the desired scheduler driver (and handle any
        # driver related failures appropriately).
        scheduler_flow.add(ScheduleCreateVolumeTask(driver_api))
    
        # Now load (but do not run) the flow using the provided initial data.
        return taskflow.engines.load(scheduler_flow, store=create_what)
    
  3. cinder\scheduler\filter_scheduler.py

    FilterScheduler. schedule_create_volume函数,更新数据库,最后通过消息队列请求调用volume_rpcapi.create_volume。

  4. /cinder/volume/rpcapi.py

从消息队列中获得,调用VolumeManager.create_volume

三 cinder volume

  1. /cinder/volume/manager.py

    同样使用flow来创建volume,执行CreateVolumeFromSpecTask这个任务

  2. /cinder/volume/flows/manager/create_volume.py

    按照不同类别和driver创建卷,更新数据库,使卷可用

            if model_update:
                with volume.obj_as_admin():
                    volume.update(model_update)
                    volume.save()
五. 总结

cinder与nova组件的架构方式相似,执行顺序有一定规律,scheduler与os的调度机制相似,可类比创建线程过程

按照不同类别和driver创建卷,更新数据库,使卷可用

            if model_update:
                with volume.obj_as_admin():
                    volume.update(model_update)
                    volume.save()
五. 总结

cinder与nova组件的架构方式相似,执行顺序有一定规律,scheduler与os的调度机制相似,可类比创建线程过程

卷的创建 经过了 api – scheduler –volume的过程,api负责检查参数 ;scheduler负责调度;volume负责创建的执行和数据库和卷的管理。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值