Analyze the Q Verification Algorithm of RAID 6 in Linux

Source: Internet
Author: User

Preface]

RAID is a Redundant Array of low-cost disk Redundant Array of Inexpensive Disks). RAID technology combines separate Disks into a logical hard disk in different combinations, this improves the disk reading performance and data security. Different combinations are identified by RAID levels. Common RAID levels include 0, 1, 01, 10, 5, and 6. For more information about how data storage works, see related articles. This chapter describes the principle of RAID 6 Storage in Linux. The command used to configure RAID in Linux is "mdadm". If you do not know how to use this command, please refer to "How to Implement RAID volumes in Linux".


RAID 6 Overview]

RAID 6 is an independent hard disk structure with two distributed storage parity codes, namely P and Q. Compared with RAID 5, RAID 6 adds the second independent verification code Q) information block. Two Independent parity verification systems use different algorithms to ensure high data reliability, even if the two hard disks expire at the same time, the data usage will not be affected. It is mainly used to require absolute data security. For example:

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/21505S011-0.jpg "title =" 1.png" width = "416" height = "230" border = "0" hspace = "0" vspace = "0" style = "width: 416px; height: 230px; "alt =" wKiom1LbXrTj3w9zAADou_pfCsM413.jpg "/>

Q is the second verification information block of RAID 6. It uses a very complex "Galo-Huayu" algorithm, which will be discussed later.


RAID 6 P verification overview]

In fact, RAID 6's P checksum and RAID 5 checksum are the same, and they all use the "XOR" operation. The principle of the XOR operator is that the same is 0, and the difference is 1. Only one hard disk can be dropped in the RAID 5 environment, but RAID 6 adds Q verification on the basis of RAID 5. Therefore, RAID 6 supports dropping two disks at the same time. The exclusive or operation is as follows:

P = A + B + C = A xor B xor C

A = P-B-C = P xor B xor C

Note: The above addition and subtraction operations are all exclusive or operations.


RAID 6 Q verification overview]

Q verification is a bit complicated. It uses the "Galo Huayu" algorithm mentioned above. "Galonia" is actually a finite field GF (2 ^ 8) of "0-255", in GF (2 ^ 8) no matter whether it is addition, subtraction, multiplication or division, it will not exceed this range. Addition and subtraction are reversible, multiplication and division are reversible, and the calculated value is unique within GF (2 ^ 8. Note: The addition, subtraction, multiplication, and Division mentioned here are not daily operations of addition, subtraction, multiplication, and division, but operations in "Galo Huayu. In GF (2 ^ 8), if the Npower of 2 is greater than the original polynomial of a value, the remainder of the original polynomial of the value is obtained, the result is returned to GF (2 ^ 8. Therefore, it is ensured that the result values from 2 ^ 0 to 2 ^ 255 are unique within GF (2 ^ 8.

There are 16 primitive polynomials in GF (2 ^ 8), respectively:

1x8 + x7 + x6 + x5 + x4 + x2 + 1 1 1111 0101 = 0x1F5

2x8 + x7 + x6 + x5 + x2 + x + 1 1 1110 0111 = 0x1E7

3x8 + x7 + x6 + x3 + x2 + x + 1 1 1100 1111 = 0x1CF

4x8 + x7 + x6 + x + 1 1 1100 0011 = 0x1C3

5x8 + x7 + x5 + x3 + 1 1 1010 1001 = 0x1A9

6x8 + x7 + x3 + x2 + 1 1 1000 1101 = 0x18D

7x8 + x7 + x2 + x + 1 1 1000 0111 = 0x187

8x8 + x6 + x5 + x4 + 1 1 0111 0001 = 0x171

9x8 + x6 + x5 + x3 + 1 1 0110 1001 = 0x169

10x8 + x6 + x5 + x2 + 1 1 0110 0101 = 0x165

11x8 + x6 + x5 + x + 1 1 0110 0011 = 0x163

12x8 + x6 + x4 + x3 + x2 + x + 1 1 0101 1111 = 0x15F

13x8 + x6 + x3 + x2 + 1 1 0100 1101 = 0x14D

14x8 + x5 + x3 + x2 + 1 1 0010 1101 = 0x12D

15x8 + x5 + x3 + x + 1 1 0010 1011 = 0x12B

16x8 + x4 + x3 + x2 + 1 1 0001 1101 = 0x11D

RAID 6 uses the original polynomial 0X11D, which is the last one in the upper column. The same is true for RAID 6 in Linux.

Return to Q verification. The combination of Q and P verification forms a binary one-time equation. K1, K2, and K3 are the values of polynomials in GF (2 ^ 8.

P = A + B + C

Q = A * K1 + B * K2 + C * K3


Multiplication and division operations of galohua domain]

Addition and subtraction are also exclusive or operations, so we will not explain them in detail. We will focus on multiplication and division. Through the Q verification above, we know that the generation of Q verification requires the multiplication operation in the Galo region. The calculation of multiplication is very complicated. The best solution is to convert GF (2 ^ 8) generate a table for the values of all polynomials in the table, and obtain the values of the multiplication operation through the table.

1. generate a positive table GFILOG

Use the following table to generate a positive GFILOG table. Note: The original polynomial of this table is 0X11D.

650) this. length = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/21505S360-1.jpg "title =" 1.gif" width = "700" height = "235" border = "0" hspace = "0" vspace = "0" style = "width: 700px; height: 235px; "alt =" wKiom1LbfKCRRFRvAAGoGmYYD3A702.jpg "/>

As follows: it is a positive table GFILOG

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/21505TG9-2.jpg "title =" 2.png" alt = "wKioL1LbfM7C1mdoAAG64i_A9r0398.jpg"/>

2. Generate a counter table GFLOG

With the forward transformation table, it is easy to obtain the reverse table. The index of the forward table is used as the index and the index of the forward table is OK. See the following table:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/140207/21505T305-3.jpg "title =" 3.png" alt = "wKiom1LbfmXSY32YAAHLu-fPL7g224.jpg"/>

3. query table for multiplication and division operations)

Multiplication: A * K1 = GFILOG [(GFLOG [A] + GFLOG [K1]) mod 255];

Division: A/K1 = GFILOG [(GFLOG [A]-GFLOG [K1] + 255) mod 255];

Now that we know the multiplication and division of galonia, it is much easier to calculate Q verification.


Generate lost data based on Q verification]

When two disks are damaged in RAID 6, how can we generate lost data? Use a strip of RAID 6 as an example.

1. If the two pieces of data lost in a strip are P and Q, the data is not lost and can be extracted normally.


2. If the two pieces of data lost in A strip and A are P and A, the data of A can be calculated based on Q verification.

P = A * K1 + B * K2 + C * K3

A * K1 = P + B * K2 + C * K3

A = P + B * K2 + C * K3)/K1 // Note: K1 can be obtained from the same table


3. If the two pieces of data lost in A strip are Q and A, the data of A can be calculated based on the validation P.

P = A + B + C

A = P + B + C


4. If the two pieces of data lost in A strip are A and B, you can calculate the data of A and B Based on the check P and Q.

P = A + B + C

Q = A * K1 + B * K2 + C * K3

A = P + B + C

Q = (P + B + C) * K1 + B * K2 + C * K3

Q = P * K1 + B * K1 + C * K1 + B * K2 + C * K3

Q = P * K1 + C * K1 + C * K3 + B * K1 + B * K2

Q + P * K1 + C * K1 + C * K3 = (K1 + K2) * B

B = (Q + P * K1 + C * K1 + C * K3)/(K1 + K2)

After calculating the value of B, it is much easier to calculate the value of A Based on the P checksum.

A = P + B + C


RAID 6 in Linux]

The general principle of RAID 6 is known based on the previous content. Because there are 16 primitive polynomials in The Galo region, there are many RAID 6 types, and the K value is not fixed. Therefore, calculating the Q check value of a RAID 6 Instance becomes complicated. However, the K value of RAID 6 in Linux environment has been tested. The value is based on the number of RAID 6 arrays and the total number of RAID 6 disks starting from the original polynomial 0X11D-2) the values of polynomials are K values.



This article is from "Deng Qi's Blog" Blog, please be sure to keep this source http://dengqi.blog.51cto.com/5685776/1352919

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.