Raid1 source code analysis-initialization process

Source: Internet
Author: User

The initialization process has a small amount of code and is relatively simple. Mainly run functions. (The Linux kernel version of the code I read is 2.6.32.61)

Iv. Initialization Process Analysis

As the name suggests, the run function is very simple. This is called when raid1 starts to run and some initialization operations are performed. It mainly initializes the conf in raid1. The run function is called in do_md_run of MD. C.

RunProcedure

0. The input parameter mddev is the MD device where raid1 is located.

1. Define related variables.

1.1 define the conf pointer with the type raid1_private_data_s. It is an important private data structure in raid1.

1.2 define the rdev pointer as the disk pointer to form the MD device. Its type is mdk_rdev_t.

2. Check whether mddev-> level is 1. If the value is 1, the disk mirror technology is used, that is, raid1. Continue the following process.

3. Check whether reshape_position is maxsector. If they are equal, it means that reshape is not required. Continue with the following process.

4. Apply for the conf file in the private data zone of raid1 and link the conf file structure to mddev-> private. A mempool is also applied in the private data zone for the read/write cache of the magnetic array. Link the mddev structure to conf> poolinfo> mddev. Link the conf-> device_lock structure to mddev-> queue-> queue_lock.

5. initialize the private data zone, including:

5.1 use the MD information to assign a value to the disk rdev in the magnetic array.

Conf-> mirrors is the first address of the array consisting of pointers of the mirror_info type.

According to conf-> mirrors = kzarloc (sizeof (struct cmd_info) * mddev-> raid_disks, gfp_kernel); we can see that the raid_disks are applied for space in the cmd_info structure, each performance_info structure can correspond to a disk rdev.

5.2 associate md with raid1 private data zone. That is, conf-> raid_disks = mddev-> raid_disks; and conf-> mddev = mddev;

5.3 private data zone locks and queue initialization.

6. Check the disk status in the disk array. If a disk does not exist or the disk is inconsistent with the disk in the disk array (in_sync), the disk is in the degraded state. If a disk is not in the in_syn status, it needs to be fully synchronized (conf-> fullsync = 1 ).

Mddev-> degraded is the "accumulative ledger" used to manage whether all disks in raid are downgraded. If a disk is downgraded, 1 is added.

6.1 if all disks are not normal (all are in the degraded status), startup fails.

6.2 If only one disk works properly, set the flag to disable synchronization. Because there is only one synchronization disk that can be referenced, there is no synchronization statement. (Mddev-> recovery_cp = maxsector ;)

7. Find the first available disk in conf-> last_used. (This will be used for read balancing)

8. register the daemon.

9. register the unplug callback.

10. register the congestion processing function.

If run is a constructor, the stop function will have the taste of the destructor. Look at this function, all resources are released one by one. Stop is called in do_md_stop of MD. C.

Reference: http://blog.chinaunix.net/xmlrpc.php? R = blog/Article & uid = 22311165 & id = 390818

 

This article from fangpei blog, reprinted please indicate the source: http://www.cnblogs.com/fangpei/

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.