日期:2014-05-16 浏览次数:20913 次
7824 mddev->sync_thread = md_register_thread(md_do_sync, 7825 mddev, 7826 "resync");md_register_thread函数如下:
6697 struct md_thread *md_register_thread(void (*run) (struct mddev *), struct mddev *mddev,
6698                                  const char *name)
6699 {
6700         struct md_thread *thread;
6701 
6702         thread = kzalloc(sizeof(struct md_thread), GFP_KERNEL);
6703         if (!thread)
6704                 return NULL;
6705 
6706         init_waitqueue_head(&thread->wqueue);
6707 
6708         thread->run = run;
6709         thread->mddev = mddev;
6710         thread->timeout = MAX_SCHEDULE_TIMEOUT;
6711         thread->tsk = kthread_run(md_thread, thread,
6712                                   "%s_%s",
6713                                   mdname(thread->mddev),
6714                                   name);
6715         if (IS_ERR(thread->tsk)) {
6716                 kfree(thread);
6717                 return NULL;
6718         }
6719         return thread;
6720 }
7245 #define SYNC_MARKS      10
7246 #define SYNC_MARK_STEP  (3*HZ)
7247 void md_do_sync(struct mddev *mddev)
7248 {
7249         struct mddev *mddev2;
7250         unsigned int currspeed = 0,
7251                  window;
7252         sector_t max_sectors,j, io_sectors;
7253         unsigned long mark[SYNC_MARKS];
7254         sector_t mark_cnt[SYNC_MARKS];
7255         int last_mark,m;
7256         struct list_head *tmp;
7257         sector_t last_check;
7258         int skipped = 0;
7259         struct md_rdev *rdev;
7260         char *desc;
7261         struct blk_plug plug;
7262 
7263         /* just incase thread restarts... */
7264         if (test_bit(MD_RECOVERY_DONE, &mddev->recovery))
7265                 return;
7266         if (mddev->ro) /* never try to sync a read-only array */
7267