~ubuntu-branches/debian/sid/lvm2/sid

« back to all changes in this revision

Viewing changes to lib/metadata/mirror.c

  • Committer: Package Import Robot
  • Author(s): Bastian Blank
  • Date: 2014-08-19 15:37:06 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20140819153706-i1gaio8lg534dara
Tags: 2.02.109-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
281
281
                            struct logical_volume *log_lv, int in_sync,
282
282
                            struct dm_list *tagsl, int remove_on_failure)
283
283
{
284
 
        struct str_list *sl;
 
284
        struct dm_str_list *sl;
285
285
        uint64_t orig_status = log_lv->status;
286
286
        int was_active = 0;
287
287
 
420
420
static int _delete_lv(struct logical_volume *mirror_lv, struct logical_volume *lv)
421
421
{
422
422
        struct cmd_context *cmd = mirror_lv->vg->cmd;
423
 
        struct str_list *sl;
 
423
        struct dm_str_list *sl;
424
424
 
425
425
        /* Inherit tags - maybe needed for activation */
426
426
        if (!str_list_match_list(&mirror_lv->tags, &lv->tags, NULL)) {
575
575
 
576
576
static int _mirrored_lv_in_sync(struct logical_volume *lv)
577
577
{
578
 
        percent_t sync_percent;
 
578
        dm_percent_t sync_percent;
579
579
 
580
580
        if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &sync_percent,
581
581
                               NULL)) {
590
590
                return 0;
591
591
        }
592
592
 
593
 
        return (sync_percent == PERCENT_100) ? 1 : 0;
 
593
        return (sync_percent == DM_PERCENT_100) ? 1 : 0;
594
594
}
595
595
 
596
596
/*
842
842
        struct logical_volume *sub_lv;
843
843
        struct logical_volume *detached_log_lv = NULL;
844
844
        struct logical_volume *temp_layer_lv = NULL;
845
 
        struct lv_segment *mirrored_seg = first_seg(lv);
 
845
        struct lv_segment *pvmove_seg, *mirrored_seg = first_seg(lv);
846
846
        uint32_t old_area_count = mirrored_seg->area_count;
847
847
        uint32_t new_area_count = mirrored_seg->area_count;
848
848
        struct lv_list *lvl;
949
949
                mirrored_seg = first_seg(lv);
950
950
                if (remove_log && !detached_log_lv)
951
951
                        detached_log_lv = detach_mirror_log(mirrored_seg);
 
952
 
 
953
                if (lv->status & PVMOVE)
 
954
                        dm_list_iterate_items(pvmove_seg, &lv->segments)
 
955
                                pvmove_seg->status |= PVMOVE;
952
956
        } else if (new_area_count == 0) {
953
957
                log_very_verbose("All mimages of %s are gone", lv->name);
954
958
 
1555
1559
                if (!(lv->status & lv_type))
1556
1560
                        continue;
1557
1561
 
1558
 
                /* Check segment origins point to pvname */
 
1562
                /*
 
1563
                 * If this is an atomic pvmove, the first
 
1564
                 * segment will be a mirror containing
 
1565
                 * mimages (i.e. AREA_LVs)
 
1566
                 */
 
1567
                if (seg_type(first_seg(lv), 0) == AREA_LV) {
 
1568
                        seg = first_seg(lv);            /* the mirror segment */
 
1569
                        seg = first_seg(seg_lv(seg, 0)); /* mimage_0 segment0 */
 
1570
                        if (seg_dev(seg, 0) != dev)
 
1571
                                continue;
 
1572
                        return lv;
 
1573
                }
 
1574
 
 
1575
                /*
 
1576
                 * If this is a normal pvmove, check all the segments'
 
1577
                 * first areas for the requested device
 
1578
                 */
1559
1579
                dm_list_iterate_items(seg, &lv->segments) {
1560
1580
                        if (seg_type(seg, 0) != AREA_PV)
1561
1581
                                continue;
1562
1582
                        if (seg_dev(seg, 0) != dev)
1563
1583
                                continue;
 
1584
 
1564
1585
                        return lv;
1565
1586
                }
1566
1587
        }
1652
1673
        return 1;
1653
1674
}
1654
1675
 
1655
 
/*
1656
 
 * Add mirrors to "linear" or "mirror" segments
1657
 
 */
1658
 
int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
1659
 
                            uint32_t mirrors, uint32_t region_size,
1660
 
                            struct dm_list *allocatable_pvs, alloc_policy_t alloc)
 
1676
static int _add_mirrors_that_preserve_segments(struct logical_volume *lv,
 
1677
                                               uint32_t flags,
 
1678
                                               uint32_t mirrors,
 
1679
                                               uint32_t region_size,
 
1680
                                               struct dm_list *allocatable_pvs,
 
1681
                                               alloc_policy_t alloc)
1661
1682
{
 
1683
        struct cmd_context *cmd = lv->vg->cmd;
1662
1684
        struct alloc_handle *ah;
1663
1685
        const struct segment_type *segtype;
1664
1686
        struct dm_list *parallel_areas;
1665
1687
        uint32_t adjusted_region_size;
1666
1688
        int r = 1;
1667
1689
 
1668
 
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 1)))
 
1690
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 1, 0)))
1669
1691
                return_0;
1670
1692
 
1671
1693
        if (!(segtype = get_segtype_from_string(cmd, "mirror")))
1682
1704
                return 0;
1683
1705
        }
1684
1706
 
1685
 
        if (!lv_add_mirror_areas(ah, lv, 0, adjusted_region_size)) {
1686
 
                log_error("Failed to add mirror areas to %s", lv->name);
 
1707
        if (flags & MIRROR_BY_SEG) {
 
1708
                if (!lv_add_mirror_areas(ah, lv, 0, adjusted_region_size)) {
 
1709
                        log_error("Failed to add mirror areas to %s", lv->name);
 
1710
                        r = 0;
 
1711
                }
 
1712
        } else if (flags & MIRROR_BY_SEGMENTED_LV) {
 
1713
                if (!lv_add_segmented_mirror_image(ah, lv, 0,
 
1714
                                                   adjusted_region_size)) {
 
1715
                        log_error("Failed to add mirror areas to %s", lv->name);
 
1716
                        r = 0;
 
1717
                }
 
1718
        } else {
 
1719
                log_error(INTERNAL_ERROR "Unknown mirror flag");
1687
1720
                r = 0;
1688
1721
        }
1689
 
 
1690
1722
        alloc_destroy(ah);
1691
1723
        return r;
1692
1724
}
1693
1725
 
1694
1726
/*
 
1727
 * Add mirrors to "linear" or "mirror" segments
 
1728
 */
 
1729
int add_mirrors_to_segments(struct cmd_context *cmd, struct logical_volume *lv,
 
1730
                            uint32_t mirrors, uint32_t region_size,
 
1731
                            struct dm_list *allocatable_pvs, alloc_policy_t alloc)
 
1732
{
 
1733
        return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEG,
 
1734
                                                   mirrors, region_size,
 
1735
                                                   allocatable_pvs, alloc);
 
1736
}
 
1737
 
 
1738
/*
1695
1739
 * Convert mirror log
1696
1740
 *
1697
1741
 * FIXME: Can't handle segment-by-segment mirror (like pvmove)
1701
1745
                      struct dm_list *removable_pvs,
1702
1746
                      int force)
1703
1747
{
1704
 
        percent_t sync_percent;
 
1748
        dm_percent_t sync_percent;
1705
1749
        struct volume_group *vg = lv->vg;
1706
1750
 
1707
1751
        /* Unimplemented features */
1734
1778
                return 0;
1735
1779
        }
1736
1780
 
1737
 
        if (sync_percent == PERCENT_100)
 
1781
        if (sync_percent == DM_PERCENT_100)
1738
1782
                init_mirror_in_sync(1);
1739
1783
        else {
1740
1784
                /* A full resync will take place */
1896
1940
        struct alloc_handle *ah;
1897
1941
        const struct segment_type *segtype;
1898
1942
        struct dm_list *parallel_areas;
1899
 
        percent_t sync_percent;
 
1943
        dm_percent_t sync_percent;
1900
1944
        int in_sync;
1901
1945
        struct logical_volume *log_lv;
1902
1946
        unsigned old_log_count;
1927
1971
                return 1;
1928
1972
        }
1929
1973
 
1930
 
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 0)))
 
1974
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 0, 0)))
1931
1975
                return_0;
1932
1976
 
1933
1977
        if (!(segtype = get_segtype_from_string(cmd, "mirror")))
1964
2008
        /* check sync status */
1965
2009
        if (mirror_in_sync() ||
1966
2010
            (lv_mirror_percent(cmd, lv, 0, &sync_percent, NULL) &&
1967
 
             (sync_percent == PERCENT_100)))
 
2011
             (sync_percent == DM_PERCENT_100)))
1968
2012
                in_sync = 1;
1969
2013
        else
1970
2014
                in_sync = 0;
2000
2044
         * allocate destination extents
2001
2045
         */
2002
2046
 
2003
 
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 0)))
 
2047
        if (!(parallel_areas = build_parallel_areas_from_lv(lv, 0, 0)))
2004
2048
                return_0;
2005
2049
 
2006
2050
        if (!(segtype = get_segtype_from_string(cmd, "mirror")))
2112
2156
                        return 0;
2113
2157
                }
2114
2158
 
2115
 
                return add_mirrors_to_segments(cmd, lv, mirrors,
2116
 
                                               region_size, pvs, alloc);
 
2159
                return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEG,
 
2160
                                                           mirrors, region_size,
 
2161
                                                           pvs, alloc);
 
2162
        } else if (flags & MIRROR_BY_SEGMENTED_LV) {
 
2163
                if (stripes > 1) {
 
2164
                        log_error("Striped-mirroring is not supported on "
 
2165
                                  "segment-by-segment mirroring");
 
2166
                        return 0;
 
2167
                }
 
2168
 
 
2169
                return _add_mirrors_that_preserve_segments(lv, MIRROR_BY_SEGMENTED_LV,
 
2170
                                                           mirrors, region_size,
 
2171
                                                           pvs, alloc);
2117
2172
        } else if (flags & MIRROR_BY_LV) {
2118
2173
                if (!mirrors)
2119
2174
                        return add_mirror_log(cmd, lv, log_count,
2156
2211
         */
2157
2212
        r = _split_mirror_images(lv, split_name, split_count, removable_pvs);
2158
2213
        if (!r)
2159
 
                return 0;
 
2214
                return_0;
2160
2215
 
2161
2216
        return 1;
2162
2217
}