Linux Kernel MD Source interpretation Eight array sync two: synchronization process

Source: Internet
Author: User
Tags arrays linux

In the previous section, start a synchronization thread:

7824                         mddev->sync_thread = Md_register_thread (Md_do_sync,  
7825                                                                 mddev,  
7826                                                                 "Resync");

The Md_register_thread function is as follows:

 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} 

I believe that all took the programmer certificate, Beida Jade Bird certificate buddies See these code is easy, but I did not go to these training schools, also did not take the program card, it is really ashamed ah. This in large part of the technical staff dragged the hind legs, so the heart is very disturbed, especially the Shanghai Fire is temporary, train ticket system error is the programmer without a license. Think in school when teachers teach us: Don't you four years of study than a certificate, the teacher four years of training than a program card? I was so ashamed when I was ready to sign up for the exam. However, society is the society has never been a job to say that the procedure card. But the most afraid of the relevant departments, which day is likely to be arrested to get an undocumented.

This function has two highlights:

6706 lines, initializing the wait queue, where the thread that sleeps on the waiting queue is md_thread, and who wakes it up? Wake up the function is called wakeup, then find symbol to see if there is a function called MD wakeup, indeed there is md_wakeup_thread () function. So the next time you see this function, you'll know that the turn is thread-handling.

6711 lines, create a thread, first care about the name of the thread, is a combination of MD name and role name. When this is done, you can see the thread in User state ps. In addition to the thread name, what do we care what this thread does? It runs the Md_thread () function, which simply provides a thread to run the template, and the real thing is the run function that the function passes in. Back to 7824 lines, we know that sync really does things is md_do_sync.

So we follow up on the Md_do_sync function:

 7245 #define Sync_marks 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->recov  
ery)) 7265 return;  
7266 if (mddev->ro)/* Never try to sync a read-only array */7267 return; 7268 7269 if (Test_bit (Md_recovery_sync, &mddev->recovery)) {7270 if (teSt_bit (Md_recovery_check, &mddev->recovery)) 7271 desc = "Data-check"; 7272 Else if (Test_bit (md_recovery_requested, &mddev->recovery)) 7273 des  
c = "Requested-resync";  
7274 Else 7275 desc = "Resync";  
7276} else if (Test_bit (Md_recovery_reshape, &mddev->recovery)) 7277 desc = "Reshape"; 7278 Else 7279 desc = "Recovery"; 

7264 Line, check whether the synchronization is complete, again friendship reminder, the synchronization here refers to the broad sense of synchronization.

7266 lines, read-only arrays are not synchronized.

After 7269 lines, set the thread to print the information.

7279-7345 rows, the array synchronization mutex created with the disk partition. Commercial arrays do not need to be partitioned into arrays, so skip directly.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.