2010年11月28日星期日

linux software raid5 code reading notes (1)

Process of a typical read

1. When the bio corresponding to the read request is passed to make_request(), the sector number is first remapped into disk number and index within disk by raid5_compute_sector(), then get_active_stripe() is called to get the stripe this sector locates. Finally this bio is added to this stripe by add_stripe_bio().
2. Set STIPE_HANDLE bit of the current stripe
3. Calls into release_stripe() which will call mdev->thread (i.e, raid5d) to handle this stripe.
4. Raid5d calls into handle_stripe(), which calls handle_stripe5() for raid5.
5. Handle_stripe5() would call handle_stripe_fill5(), which will in turn call fetch_block5(). Fetch_block5() will set the R5_LOCKED and R5_WantRead flags, while handle_stripe_fill5() will set the STRIPE_HANDLE flag (which was previously cleared by handle_stripe5()).
6. Handle_stripe5() will then call ops_run_io() to register I/O completion function to be raid5_end_read_request() and submit I/O requests for all the bio in rdev->req of each disk. Finally handle_stripe5() calls return_io() and returns.
7. Raid5d then calls release_stripe(). Note: the I/O completion function raid5_end_read_request() and release_stripe() run in the same time???
8. Raid5_end_read_request() will set R5_UPTODATE flag and STRIPE_HANDLE flag, and call release_stripe() function.
9. Release_stripe() will again call handle_stripe() function. This time according to all the flags, handle_stripe() will call raiad_run_ops(), which will in turn call ops_run_biofill() to copy the data previous read to user-submitted bio asscociated buffer. Upon completion of this async coping, ops_complete_biofill() is called, which set STRIPE_HANDLE flag again.
10. This time handle_stripe() is called but it does nothing but clear STRIPE_HANDLE flag
11. Control returns to make_request, which calls bio_endio to return user-submitted bio.
12. Finally, calls into release_stripe() function which releases current stripe and if necessary, wake up raid5d to deal with other stipes.

没有评论:

发表评论