Linux kernel MD Source code read five introduction to the operation of the RAIDD5 array

Source: Internet
Author: User
Tags goto thread linux

If you understand the run function of the RAID1 array, it's easy to see the RAID5 array run because the two things are similar.

RAID5 's run function is very long, but a large portion of it has nothing to do with creating a run, especially one that is related to reshape, and most systems do not care about it, so you can skip it directly. The run function after the deletion is as follows:

 5307 static int run (struct Mddev *mddev) 5308 {5309 struct; r5conf *conf;  
5310 int working_disks = 0;  
5311 int dirty_parity_disks = 0;  
5312 struct Md_rdev *rdev;  
5313 sector_t reshape_offset = 0;  
5314 int i;  
5315 Long Long min_offset_diff = 0;  
5316 INT-i = 1;  
...  
5426 if (mddev->private = = NULL) 5427 conf = setup_conf (MDDEV);  
5428 else 5429 conf = mddev->private;  
5430 5431 if (is_err (conf)) 5432 return Ptr_err (conf);  
5433 5434 Conf->min_offset_diff = Min_offset_diff;  
5435 Mddev->thread = conf->thread;  
5436 conf->thread = NULL;  
5437 mddev->private = conf;  
... 
5491/* 5492 * 0 for a fully functional array, 1 or 2 for a degraded array.  
5493 * * 5494 mddev->degraded = calc_degraded (conf);  
... 5503/* Device size must be a multiple of chunk size */5504 mddev->dev_sectors &= ~ (mddev->chunk_sectors-1);  
5505 mddev->resync_max_sectors = mddev->dev_sectors;  
...  
5556 md_set_array_sectors (Mddev, raid5_size (mddev, 0, 0));  
5557 5558 if (mddev->queue) {... 5628} 5629 5630 return 0; 

Does it feel super simple, like some things on the surface look very complex, but as long as the careful analysis, it is found that there are rules to follow. Just like the run function, the thing to do is the same as the RAID1 run, which is to establish a context for reading and writing.

5427 lines, create struct r5conf, follow up function:

5131 static struct r5conf *setup_conf (struct Mddev *mddev) 5132 {5133 struct; r5conf *conf;  
5134 int Raid_disk, memory, Max_disks;  
5135 struct Md_rdev *rdev;  
5136 struct Disk_info *disk;  
5137 Char pers_name[6];             5138 5139 if (mddev->new_level!= 5 5140 && mddev->new_level!= 4 5141 && Mddev->new_level!= 6) {5142 PRINTK (kern_err "md/raid:%s:raid level not set to 4/5/6 (%  
D) \ n ", 5143 Mdname (Mddev), mddev->new_level);  
5144 return Err_ptr (-eio); 5145} 5146 if (mddev->new_level = 5 5147 &&!algorithm_valid_raid5 (MDDEV-&G  
t;new_layout)) | |   
5148 (Mddev->new_level = = 6 5149 &&!algorithm_valid_raid6 (mddev->new_layout))) {                  5150 printk (kern_err "Md/raid:%s:layout%d not supported\n", 5151      Mdname (Mddev), mddev->new_layout);  
5152 return Err_ptr (-eio);                 5153} 5154 if (mddev->new_level = 6 && mddev->raid_disks < 4) {5155 PRINTK (kern_err "Md/raid:%s:not enough configured devices (%d, minimum 4) \ n", 5156 Mdname (Mdde  
v), mddev->raid_disks);  
5157 return Err_ptr (-einval);  
5158} 5159 5160 if (!mddev->new_chunk_sectors | |  
5161 (mddev->new_chunk_sectors << 9)% Page_size | | 5162!is_power_of_2 (mddev->new_chunk_sectors)) {5163 printk (kern_err "Md/raid:%s:invali")  
D Chunk Size%d\n ", 5164 mdname (Mddev), mddev->new_chunk_sectors << 9);  
5165 return Err_ptr (-einval);  
5166} 5167 5168 conf = kzalloc (sizeof struct), r5conf);  
5169 if (conf = NULL) 5170 goto abort; 51Spin_lock_init (&conf->device_lock);  
5172 Init_waitqueue_head (&conf->wait_for_stripe);  
5173 Init_waitqueue_head (&CONF->WAIT_FOR_OVERLAP);  
5174 Init_list_head (&conf->handle_list);  
5175 Init_list_head (&conf->hold_list);  
5176 Init_list_head (&conf->delayed_list);  
5177 Init_list_head (&conf->bitmap_list);  
5178 Init_list_head (&conf->inactive_list);  
5179 Atomic_set (&conf->active_stripes, 0);  
5180 Atomic_set (&conf->preread_active_stripes, 0);  
5181 Atomic_set (&conf->active_aligned_reads, 0);  
5182 conf->bypass_threshold = Bypass_threshold;  
5183 conf->recovery_disabled = mddev->recovery_disabled-1;  
5184 5185 conf->raid_disks = mddev->raid_disks; 5186 if (mddev->reshape_position = = maxsector) 5187 conf->previous_raid_disks = MDDEV->raid_disks;  
5188 else 5189 conf->previous_raid_disks = mddev->raid_disks-mddev->delta_disks;  
5190 max_disks = max (conf->raid_disks, conf->previous_raid_disks);  
5191 Conf->scribble_len = Scribble_len (max_disks); 5192 5193 conf->disks = kzalloc (max_disks * sizeof struct), Disk_info GF  
P_kernel);  
5195 if (!conf->disks) 5196 goto abort;  
5197 5198 Conf->mddev = Mddev; 5199 5200 if (conf->stripe_hashtbl = Kzalloc (page_size, gfp_kernel)) = = NULL) 5201 Goto AB  
Ort  
5202 5203 conf->level = mddev->new_level;  
5204 if (raid5_alloc_percpu (conf)!= 0) 5205 Goto abort;  
5206 5207 Pr_debug ("Raid456:run (%s) called.\n", Mdname (Mddev));  
5208 5209 Rdev_for_each (Rdev, Mddev) {5210 Raid_disk = rdev->raid_disk;      5211           if (raid_disk >= max_disks 5212 | | Raid_disk < 0) 5213 Co  
Ntinue;  
5214 disk = Conf->disks + Raid_disk; 5215 5216 if (test_bit (replacement, &rdev->flags)) {5217 if (disk->  
Replacement) 5218 Goto abort;  
5219 disk->replacement = Rdev; 5220} else {5221 if (Disk->rdev) 5222 got  
o Abort;  
5223 Disk->rdev = Rdev;                         5224} 5225 5226 if (Test_bit (In_sync, &rdev->flags)) {5227  
Char B[bdevname_size];                                5228 PRINTK (kern_info "Md/raid:%s:device%s operational as RAID" 5229 "Disk%d\n", 5230 mdname (Mddev), Bdevname (Rdev->bdev, B),Raid_disk); 5231} else if (Rdev->saved_raid_disk!= raid_disk) 5232/* Cannot on BI  
TMap to complete recovery * * 5233 Conf->fullsync = 1;  
5234} 5235 5236 conf->chunk_sectors = mddev->new_chunk_sectors;  
5237 Conf->level = mddev->new_level;  
5238 if (conf->level = = 6) 5239 conf->max_degraded = 2;  
5240 else 5241 conf->max_degraded = 1;  
5242 Conf->algorithm = mddev->new_layout;  
5243 conf->max_nr_stripes = nr_stripes;  
5244 conf->reshape_progress = mddev->reshape_position; 5245 if (conf->reshape_progress!= maxsector) {5246 conf->prev_chunk_sectors = mddev->  
Chunk_sectors;  
5247 Conf->prev_algo = mddev->layout; 5248} 5249 5250 memory = conf->max_nr_stripes * (sizeof (struct STRIPE_Head) + 5251 Max_disks * (sizeof (struct bio) + page_size))/1024;                        5252 if (grow_stripes (conf, conf->max_nr_stripes)) {5253 PRINTK (kern_err 5254  
"Md/raid:%s:couldn ' t allocate%dkb for buffers\n", 5255 mdname (Mddev), memory);  
5256 Goto Abort; 5257} else 5258 printk (kern_info "md/raid:%s:allocated%dkb\n", 5259 MD  
Name (Mddev), memory);  
5260 5261 sprintf (pers_name, "raid%d", mddev->new_level);  
5262 Conf->thread = Md_register_thread (raid5d, Mddev, pers_name); 5263 if (!conf->thread) {5264 printk (kern_err 5265 "Md/raid:%s:cou")  
LDN ' t allocate thread.\n, 5266 mdname (Mddev));  
5267 Goto Abort; 5268} 5269 5270 return conf;

Related Article

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.