IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    sheepdog源码分析之关键模块介绍(一)

    admin发表于 2011-03-15 09:37:34
    love 0

    1)   Worker工作线程模块

    该模块是作为sheepdog工作线程模块,存在多个工作线程,默认NR_WORKER_THREAD =64个工作线程;线程的入口函数为worker_routine,同时struct work_queue中pending_list是双向链表,worker_routine从该链表中读取任务,然后执行,接着将执行过的任务放到struct worker_info中finished_list双向链表,然后向main thread发送一个信号,接着调用bs_thread_request_done来执行finished_list中任务的done函数,该函数的作用是发送响应信息。涉及的文件主要是worker.c和Worker.h

    struct  work_queue {

    int wq_state;  //

    int nr_active;  //当前活跃的任务数目

    struct list_head pending_list;//待执行的任务列表

    struct list_head blocked_list; //没有用处了

    };

    struct  worker_info {

    struct list_head  worker_info_siblings;//链表的连接器,目前只有一个worker_info

    int nr_threads;  //线程个数

    pthread_mutex_t  finished_lock; //

    struct list_head  finished_list;

    /* wokers sleep on this and signaled by tgtd */

    pthread_cond_t pending_cond;

    /* locked by tgtd and workers */

    pthread_mutex_t  pending_lock;

    /* protected by pending_lock */

    struct work_queue  q;

    pthread_mutex_t  startup_lock;

    pthread_t  worker_thread[0]; //工作线程的数据结构

    };

    这里需要特殊说明的是,有关任务Worker的属性WORK_SIMPLE和WORK_ORDERED,及有关block相关的函数,在0.2版本中应该是没有用处的,当时我也迷惑一阵。

    Sheepdog存在三类的工作任务:

    • Request: 所有来自客户端或者其他sheep的请求
    • Recovery_work: 数据恢复任务
    • Delete_work: 删除vdi的任务
    • Cpg_event_work: 该任务作为cpg有关集群管理的任务,例如节点加入和send_message消息发送等,sheep保证当前系统只运行一个cpg_event_work任务,从sys->cpg_event_siblings中是未执行的任务。

    您可能对下面文章也感兴趣:

    • sheepdog源码分析之关键数据结构介绍
    • sheepdog源码学习笔记一
    • sheepdog源码学习二之代码目录结构介绍
    • KVM分布式共享存储解决方案-sheepdog
    • redis中常用数据结构介绍


沪ICP备19023445号-2号
友情链接