AIX LVM: Mechanics of migratepv (Part I)

With the AIX LVM migratepv command, physical volumes can be exchanged in mirror copies of logical volumes. We want to take a closer look at how the migratepv command works in detail. Using a few examples, the cases of unmirrored logical volume, mirrored logical volume (2 copies) and mirrored logical volume (3 copies) are shown.

Our Test Environment

We created a scalable volume group vg00 in our test environment. Nine physical volumes are available for the VG vg00, which are provided by 3 different data centers:

  • hdisk10, hdisk11 and hdisk12 (green) from data center DC01
  • hdisk13, hdisk14 and hdisk15 (red) from data center DC02
  • hdisk16, hdisk17 and hdisk18 (blue) from data center DC03

The Command migratepv

The syntax of the migratepv command is:
migratepv [-l lv] src-pv [dst-pv ...]

The command moves all physical partitions of the source physical volume src-pv to the target physical volume(s) dst-pv. Using the ‘-l‘ option, the operation can be restricted to one logical volume,e.g.:

# migratepv -l lv00 hdisk11 hdisk15

1st Case: Unmirrored Logical Volume

We create a small LV (10 LPs) with the following mapping file:

# cat unmirrored.map
hdisk10:1-3
hdisk14:1-3
hdisk12:1-3
hdisk14:4
# mklv -m unmirrored.map vg00 10
lv00
#

The created logical volume then looks like this:

# lslv -m lv00
lv00:N/A
LP    PP1  PV1             PP2  PV2             PP3  PV3
0001  0001 hdisk10          
0002  0002 hdisk10          
0003  0003 hdisk10          
0004  0001 hdisk14          
0005  0002 hdisk14          
0006  0003 hdisk14          
0007  0001 hdisk12          
0008  0002 hdisk12          
0009  0003 hdisk12          
0010  0004 hdisk14          
#

The first 3 physical partitions are on hdisk10 (DC01), the next 3 physical partitions are on hdisk14 (DC02), etc..

The physical partitions on hdisk14 (DC02) should be moved to hdisk11 (DC01). The LV would then be completely on physical volumes of the data center DC01.

We observe the work of migratepv graphically:

# migratepv -l lv00 hdisk14 hdisk11

First, a second mirror copy with physical partitions from the target physical volume hdisk11 (DC01) is added. The logical volume is now partially mirrored, temporarily.

The physical partitions added in mirror copy 2 must then be synchronized.

After the synchronization is complete and the new physical partitions have a valid copy of the data, the physical partitions on the source physical volume hdisk14 (DC02) are removed and replaced by the physical partitions of mirror copy 2.

The mirror copy 2 then no longer contains any physical partitions and is therefore removed. The logical volume lv00 is again (completely) unmirrored.

The resulting logical volume then looks like this:

# lslv -m lv00
lv00:N/A
LP    PP1  PV1             PP2  PV2             PP3  PV3
0001  0001 hdisk10          
0002  0002 hdisk10          
0003  0003 hdisk10          
0004  0009 hdisk11          
0005  0010 hdisk11          
0006  0011 hdisk11          
0007  0001 hdisk12          
0008  0002 hdisk12          
0009  0003 hdisk12          
0010  0012 hdisk11          
#

The first and only mirror copy is now completely on physical volumes of DC01.

The way migratepv works in the case of an unreflected LV is thus:

    1. Adding a second mirror copy on the target physical volume for the logical partitions to be moved.
    2. Synchronization of the new mirror copy.
    3. Replace the first mirror copy with the second mirror copy.

2nd Case: Mirrored Logical Volume (2 Copies)

The command migratepv works in the case of logical volumes with 2 mirror copies with a temporary third mirror copy. However, there are two different variants (as with migratelp):

    • Variant 1: Insert a third mirror copy at the front, i.e. copy 2 becomes copy 3 and copy 1 becomes copy 2. The temporary copy is inserted as copy 1 at the front.
    • Variant 2: Attach the third mirror copy at the back as copy 3.

Which variant of migratepv is used, depends on the mirror copies in which the source physical volume is used.

If the source physical volume is used in:

    • Only in mirror copy 1, then variant 1 is used.
    • Only in mirror copy 2, then variant 2 is used.
    • In both mirror copies (e.g. because Strictness is not set to super-strict): the highest logical partition used by the source physical volume is decisive here. If the source physical volume is used in mirror copy 1 for this logical partition, then variant 1 is used, if the source physical volume is used in mirror copy 2, variant 2 is used!

The last case in particular is probably not so well known to many AIX administrators and should therefore be the more interesting case.

To illustrate the way migratepv works, for the interesting case that a physical volume is used in both mirror copies, we create a small Logical Volume (10 LPs) with the following mapping files:

# cat bad_mirror_cp1.map
hdisk10:1-2
hdisk14:1-2
hdisk10:3-4
hdisk11:3-4
hdisk10:5-6
# mklv —m bad_mirror_cp1.map vg00 10
lv00
# cat bad_mirror_cp2.map
hdisk13:1-2
hdisk11:1-2
hdisk13:3-4
hdisk14:3-4
hdisk13:5-6
# mklvcopy —m bad_mirror_cp2.map lv00 2
# syncvg -l lv00
#

The resulting logical volume then looks like this:

# lslv -m lv00
lv00:N/A
LP    PP1  PV1             PP2  PV2             PP3  PV3
0001  0001 hdisk10         0001 hdisk13          
0002  0002 hdisk10         0002 hdisk13          
0003  0001 hdisk14         0001 hdisk11          
0004  0002 hdisk14         0002 hdisk11          
0005  0003 hdisk10         0003 hdisk13          
0006  0004 hdisk10         0004 hdisk13          
0007  0003 hdisk11         0003 hdisk14          
0008  0004 hdisk11         0004 hdisk14          
0009  0005 hdisk10         0005 hdisk13          
0010  0006 hdisk10         0006 hdisk13          
#

The hdisk11 (DC01) is used in both mirror copies, just like the hdisk14 (DC02).
The aim would be to use only physical volumes from DC01 in mirror copy 1 and, accordingly, only physical volumes from DC02 for mirror copy 2.

The candidates as source physical volumes are clearly hdisk11 (DC01) and hdisk14 (DC02). In our test environment we have the physical volumes hdisk12 (DC01) and hdisk15 (DC02) available.

Whether you replace hdisk11 (DC01) or hdisk14 (DC02) does not matter at first, both are possible. However, it is crucial which of the available physical volumes is exchanged for!

Variant 1

We first decide to exchange hdisk11 (DC01) and thus variant 1 of migratepv. The graphic shows that the highest logical partition that hdisk11 (DC01) uses is LP 0008. (The hdisk11 is used there in mirror copy 1, which brings us to variant 1.)

With variant 1, the target physical volume is inserted at the front as mirror copy 1. Since only physical volumes from DC01 are to be used in mirror copy 1, only hdisk12 (DC01) can be used as the target physical volume.

So we exchange the hdisk11 (DC01) for the hdisk12 (DC01) using migratepv:

# migratepv -l lv00 hdisk11 hdisk12

Again, we follow the work of migratepv graphically.

A third mirror copy is temporarily created and added. The physical partitions from mirror copy 2 are moved to the new mirror copy 3. The physical partitions from mirror copy 1 are moved to mirror copy 2.

The move creates space in mirror copy 1.

The physical partitions on the target physical volume are inserted in the empty positions in mirror copy 1.

The newly inserted physical partitions in mirror copy 1 are synchronized.

Then the physical partitions of the source physical volume in mirror copies 2 and 3 are removed. Physical partitions of mirror copy 3 are moved to the positions of mirror copy 2 that become free.

Finally, the empty mirror copy 3 is removed.

The resulting logical volume looks like this:

# lslv -m lv00
lv00:N/A
LP    PP1  PV1             PP2  PV2             PP3  PV3
0001  0001 hdisk10         0001 hdisk13          
0002  0002 hdisk10         0002 hdisk13          
0003  0009 hdisk12         0001 hdisk14          
0004  0010 hdisk12         0002 hdisk14          
0005  0003 hdisk10         0003 hdisk13          
0006  0004 hdisk10         0004 hdisk13          
0007  0011 hdisk12         0003 hdisk14          
0008  0012 hdisk12         0004 hdisk14          
0009  0005 hdisk10         0005 hdisk13          
0010  0006 hdisk10         0006 hdisk13             
#

All physical partitions of mirror copy 1 are on physical volumes of DC01. All physical partitions of mirror copy 2 are on physical volumes of DC02. The logical volume is now correctly mirrored between the two data centers DC01 and DC02! The restoration of the correct mirroring was possible with just one migratepv command!

Regardless of whether the source physical volume is used in one or more mirror copies of the logical volume, the target physical volume is only used in exactly one mirror copy after migratepv has run!
We will look at variant 2 below.

Variant 2

In order to demonstrate variant 2 once, we go back to the initial state and this time we replace the hdisk14 (DC02). The graphic shows that the highest logical partition that the hdisk14 (DC02) uses is also LP 0008. (The hdisk14 is used there in mirror copy 2, which brings us to variant 2.)

With variant 2, the target physical volume is added at the back as mirror copy 3. At the end of migratepv, the physical partitions of copy 3 become copy 2. Since only physical volumes from DC02 are to be used in mirror copy 2, only hdisk15 (DC02) can be used as the target physical volume.

So we exchange hdisk14 (DC02) for the hdisk15 (DC02) using migratepv:

# migratepv -l lv00 hdisk14 hdisk15

We are again following the work of migratepv graphically.

Adding a temporary third copy with the destination physical volume as mirror copy 3.

Synchronization of the third mirror copy.

Remove the physical partitions of the source physical volume in mirror copies 1 and 2. The subsequent copies are moved into the gaps that arise.

The now empty third mirror copy is removed again.

The resulting logical volume then looks like this:

# lslv -m lv00
lv00:N/A
LP    PP1  PV1             PP2  PV2             PP3  PV3
0001  0001 hdisk10         0001 hdisk13          
0002  0002 hdisk10         0002 hdisk13          
0003  0001 hdisk11         0009 hdisk15          
0004  0002 hdisk11         0010 hdisk15          
0005  0003 hdisk10         0003 hdisk13          
0006  0004 hdisk10         0004 hdisk13          
0007  0003 hdisk11         0011 hdisk15          
0008  0004 hdisk11         0012 hdisk15          
0009  0005 hdisk10         0005 hdisk13          
0010  0006 hdisk10         0006 hdisk13             
#

All physical partitions of mirror copy 1 are on physical volumes of DC01. All physical partitions of mirror copy 2 are on physical volumes of DC02.

The work of migratepv in the case of a mirrored LV with 2 copies can be summarized as follows:

    1. Adding a third mirror copy for the logical partitions to be moved on the target physical volume. The third copy is either inserted at the front or added at the back.
    2. Synchronization of the new mirror copy.
    3. Remove the mirror copy with physical partitions on the source physical volume.