~ubuntu-branches/ubuntu/saucy/lvm2/saucy-proposed

« back to all changes in this revision

Viewing changes to lib/metadata/mirror.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2012-08-14 14:35:57 UTC
  • mfrom: (3.1.25 sid)
  • Revision ID: package-import@ubuntu.com-20120814143557-93aill2tp3kf3o30
Tags: 2.02.95-4ubuntu1
* Merge from Debian unstable, remaining changes:
  - debian/patches/avoid-dev-block.patch: Prefer any other device name over
    names in /dev/block/ since lvm.conf won't handle this.
  - debian/rules:
    - copy .po file to .pot file for Rosetta (Ubuntu specific).
  - debian/{dmsetup,lvm2}-udeb.install:
    - install initramfs and udev hooks in udebs (Debian bug 504341).
  - auto-start VGs as their PVs are discovered (Ubuntu specific):
    - add debian/tree/lvm2/lib/udev/rules.d/85-lvm2.rules: use watershed plus
      the sledgehammer of vgscan/vgchange to turn on VGs as they come online.
    - debian/tree/lvm2/usr/share/initramfs-tools/scripts/hooks/lvm2:
      - add 85-lvm2.rules to the list of udev rules to copy.
      - depend on udev.
    - debian/control:
      - add versioned Depend on watershed in lvm2 for udev rules.
      - add Depends on watershed-udeb in lvm2-udeb for udev rules.
      - add versioned Depend/Breaks on udev in dmsetup for udev rules.
      - add Depend on initramfs-tools in dmsetup so system is not potentially
        rendered unbootable by out-of-order dpkg configuration.
    - debian/rules:
      - do not install local-top scripts since Ubuntu mounts root using udev.
      - do not install init scripts for lvm2, since udev starts LVM.
    - debian/lvm2.postinst: handle missing lvm2 init script.
    - debian/tree/dmsetup/lib/udev/rules.d/60-persistent-storage-dm.rules:
      watch dm devices for changes with inotify
  - add mountroot failure hooks to help fix bad boots (Debian bug 468115):
    - debian/tree/lvm2/usr/share/initramfs-tools/scripts/init-premount/lvm2
  - remaining changes to upstream event manager packages (Debian bug 514706):
    - debian/rules:
      - enable dmeventd during configure.
    - debian/dmeventd.{8,manpages}: install dmeventd files.
  - rename debian/clvm.defaults to debian/clvm.default so it is installed
    correctly.
  - debian/control: add dmsetup-udeb to libdevmapper1.02.1-udeb recommends.
  - debian/rules: make sure dmsetup and lvm2 initramfs-tools scripts are
    executable.  When the Ubuntu-specific ones are added with a patch,
    they may lose their executable bit.
  - Add and install clvmd resource agent
  - Add dependency on libudev-dev to libdevmapper-dev so that the .pc file
    works.
  - debian/{clvmd.ra,clvm.init}:
    - create /run/lvm if it doesn't exist.
  - debian/clvm.init:
    - exit 3 if not running on status action.
  - Call dh_installman so that our dmeventd manpage actually gets installed
  - Install the missing fsadm manpage.

 * libdevmapper-dev:
  - move .so symlinks and pkgconfig files to multiarched locations.
  - mark libdevmapper-dev M-A: same

 * libdevmapper-event1.02.1:
  - Add Breaks: dmeventd (<< 2.02.95-4ubuntu1) due to debian symbol rename

 * debian/lvm2.{preinst,postinst,postrm}:
  - Implement removal of obsolete /etc/init.d/lvm2 conffile, which
    should not have been re-introduced in Quantal.

 * Dropped Changes, included in Debian:
  - Mostly included packages for upstream event manager (Debian bug 514706).
  - debian/patches/rules-subdir.patch: removed as reordering will cause
    build failure with dmeventd.
  - debian/patches/libdm-event-static.patch: removed as other static libs
    aren't being built anymore either.
  - Update symbols for libdevmapper-event.
  - Update libdevmapper-event, dmeventd descriptions to match Debian
    boilerplate.

 * Disappeared Changes:
  - Don't install documentation in udebs. No diff found, but no docs are
    installed into udebs either.

 * Resurected Changes:
  - corrected dropping the wrong init script. Now clvm.init is shipped
    and lvm2.init is dropped in favor of udev rules as per original
    intention (LP: #1037033).

Show diffs side-by-side

added added

removed removed

Lines of Context:
72
72
        return NULL;
73
73
}
74
74
 
75
 
int lv_is_mirrored(const struct logical_volume *lv)
76
 
{
77
 
        if (lv->status & MIRRORED)
78
 
                return 1;
79
 
 
80
 
        return 0;
81
 
}
82
 
 
83
75
/*
84
76
 * cluster_mirror_is_available
85
77
 *
89
81
 *
90
82
 * Returns: 1 if available, 0 otherwise
91
83
 */
92
 
static int cluster_mirror_is_available(struct logical_volume *lv)
 
84
static int _cluster_mirror_is_available(struct logical_volume *lv)
93
85
{
94
86
       unsigned attr = 0;
95
87
       struct cmd_context *cmd = lv->vg->cmd;
122
114
                return 1;
123
115
 
124
116
        seg = first_seg(lv);
125
 
        mirrors = seg->area_count;
 
117
 
 
118
        if (lv->status & PVMOVE)
 
119
                return seg->area_count;
 
120
 
 
121
        mirrors = 0;
126
122
 
127
123
        for (s = 0; s < seg->area_count; s++) {
128
124
                if (seg_type(seg, s) != AREA_LV)
129
125
                        continue;
130
126
                if (is_temporary_mirror_layer(seg_lv(seg, s)))
131
 
                        mirrors += lv_mirror_count(seg_lv(seg, s)) - 1;
 
127
                        mirrors += lv_mirror_count(seg_lv(seg, s));
 
128
                else
 
129
                        mirrors++;
132
130
        }
133
131
 
134
 
        return mirrors;
 
132
        return mirrors ? mirrors : 1;
135
133
}
136
134
 
137
135
struct lv_segment *find_mirror_seg(struct lv_segment *seg)
327
325
 
328
326
        backup(log_lv->vg);
329
327
 
 
328
        /* Wait for events following any deactivation before reactivating */
 
329
        sync_local_dev_names(cmd);
 
330
 
330
331
        if (!activate_lv(cmd, log_lv)) {
331
332
                log_error("Aborting. Failed to activate mirror log.");
332
333
                goto revert_new_lv;
334
335
 
335
336
        /* Remove the temporary tags */
336
337
        dm_list_iterate_items(sl, tags)
337
 
                if (!str_list_del(&log_lv->tags, sl->str))
338
 
                        log_error("Failed to remove tag %s from mirror log.",
339
 
                                  sl->str);
 
338
                str_list_del(&log_lv->tags, sl->str);
340
339
 
341
340
        if (activation() && !set_lv(cmd, log_lv, log_lv->size,
342
341
                                    in_sync ? -1 : 0)) {
373
372
        log_lv->status = orig_status;
374
373
 
375
374
        dm_list_iterate_items(sl, tags)
376
 
                if (!str_list_del(&log_lv->tags, sl->str))
377
 
                        log_error("Failed to remove tag %s from mirror log.",
378
 
                                  sl->str);
 
375
                str_list_del(&log_lv->tags, sl->str);
379
376
 
380
377
        if (remove_on_failure && !lv_remove(log_lv)) {
381
378
                log_error("Manual intervention may be required to remove "
397
394
}
398
395
 
399
396
/*
 
397
 * Activate an LV similarly (i.e. SH or EX) to a given "model" LV
 
398
 */
 
399
static int _activate_lv_like_model(struct logical_volume *model,
 
400
                                   struct logical_volume *lv)
 
401
{
 
402
        if (lv_is_active_exclusive(model)) {
 
403
                if (!activate_lv_excl(lv->vg->cmd, lv))
 
404
                        return_0;
 
405
        } else {
 
406
                if (!activate_lv(lv->vg->cmd, lv))
 
407
                        return_0;
 
408
        }
 
409
        return 1;
 
410
}
 
411
 
 
412
/*
400
413
 * Delete independent/orphan LV, it must acquire lock.
401
414
 */
402
415
static int _delete_lv(struct logical_volume *mirror_lv, struct logical_volume *lv)
419
432
                }
420
433
        }
421
434
 
422
 
        if (lv_is_active_exclusive_locally(lv)) {
423
 
                if (!activate_lv_excl(cmd, lv))
424
 
                        return_0;
425
 
        } else {
426
 
                if (!activate_lv(cmd, lv))
427
 
                        return_0;
428
 
        }
 
435
        // FIXME: shouldn't the activation type be based on mirror_lv, not lv?
 
436
        if (!_activate_lv_like_model(lv, lv))
 
437
                return_0;
 
438
 
 
439
        /* FIXME Is this superfluous now? */
 
440
        sync_local_dev_names(cmd);
429
441
 
430
442
        if (!deactivate_lv(cmd, lv))
431
443
                return_0;
561
573
 
562
574
        if (!lv_mirror_percent(lv->vg->cmd, lv, 0, &sync_percent,
563
575
                               NULL)) {
564
 
                log_error("Unable to determine mirror sync status of %s/%s.",
565
 
                          lv->vg->name, lv->name);
 
576
                if (lv_is_active_but_not_locally(lv))
 
577
                        log_error("Unable to determine mirror sync status of"
 
578
                                  " remotely active LV, %s/%s",
 
579
                                  lv->vg->name, lv->name);
 
580
                else
 
581
                        log_error("Unable to determine mirror "
 
582
                                  "sync status of %s/%s.",
 
583
                                  lv->vg->name, lv->name);
566
584
                return 0;
567
585
        }
568
586
 
586
604
        struct lv_segment *mirrored_seg = first_seg(lv);
587
605
        struct dm_list split_images;
588
606
        struct lv_list *lvl;
 
607
        struct cmd_context *cmd = lv->vg->cmd;
589
608
 
590
609
        if (!(lv->status & MIRRORED)) {
591
610
                log_error("Unable to split non-mirrored LV, %s",
594
613
        }
595
614
 
596
615
        if (!split_count) {
597
 
                log_error("split_count is zero!");
 
616
                log_error(INTERNAL_ERROR "split_count is zero!");
598
617
                return 0;
599
618
        }
600
619
 
614
633
                return 0;
615
634
        }
616
635
 
 
636
        /*
 
637
         * Step 1:
 
638
         *   Remove the images from the mirror.
 
639
         *   Make them visible, independent LVs (don't change names yet).
 
640
         *   Track them in a list for later instantiation.
 
641
         */
617
642
        dm_list_init(&split_images);
618
643
        for (i = 0; i < split_count; i++) {
619
644
                mirrored_seg->area_count--;
620
645
                sub_lv = seg_lv(mirrored_seg, mirrored_seg->area_count);
621
646
 
622
647
                sub_lv->status &= ~MIRROR_IMAGE;
623
 
                lv_set_visible(sub_lv);
624
648
                release_lv_segment_area(mirrored_seg, mirrored_seg->area_count,
625
649
                                        mirrored_seg->area_len);
626
650
 
627
651
                log_very_verbose("%s assigned to be split", sub_lv->name);
628
652
 
629
653
                if (!new_lv) {
 
654
                        lv_set_visible(sub_lv);
630
655
                        new_lv = sub_lv;
631
 
                        new_lv->name = dm_pool_strdup(lv->vg->cmd->mem,
632
 
                                                      split_name);
633
 
                        if (!new_lv->name) {
634
 
                                log_error("Unable to rename newly split LV");
635
 
                                return 0;
636
 
                        }
637
 
                } else {
638
 
                        lvl = dm_pool_alloc(lv->vg->cmd->mem, sizeof(*lvl));
639
 
                        if (!lvl) {
640
 
                                log_error("lv_list alloc failed");
641
 
                                return 0;
642
 
                        }
643
 
                        lvl->lv = sub_lv;
644
 
                        dm_list_add(&split_images, &lvl->list);
645
 
                }
 
656
                        continue;
 
657
                }
 
658
 
 
659
                /* If there is more than one image being split, add to list */
 
660
                lvl = dm_pool_alloc(lv->vg->vgmem, sizeof(*lvl));
 
661
                if (!lvl) {
 
662
                        log_error("lv_list alloc failed");
 
663
                        return 0;
 
664
                }
 
665
                lvl->lv = sub_lv;
 
666
                dm_list_add(&split_images, &lvl->list);
 
667
        }
 
668
 
 
669
        new_lv->name = dm_pool_strdup(lv->vg->vgmem, split_name);
 
670
        if (!new_lv->name) {
 
671
                log_error("Unable to rename newly split LV");
 
672
                return 0;
646
673
        }
647
674
 
648
675
        if (!dm_list_empty(&split_images)) {
649
676
                size_t len = strlen(new_lv->name) + 32;
650
677
                char *layer_name, format[len];
651
678
 
652
 
                if (!insert_layer_for_lv(lv->vg->cmd, new_lv,
653
 
                                         0, "_mimage_%d")) {
 
679
                /*
 
680
                 * A number of images have been split and
 
681
                 * a new mirror layer must be formed
 
682
                 */
 
683
 
 
684
                if (!insert_layer_for_lv(cmd, new_lv, 0, "_mimage_%d")) {
654
685
                        log_error("Failed to build new mirror, %s",
655
686
                                  new_lv->name);
656
687
                        return 0;
661
692
                dm_list_iterate_items(lvl, &split_images) {
662
693
                        sub_lv = lvl->lv;
663
694
 
664
 
                        dm_snprintf(format, len, "%s_mimage_%%d",
665
 
                                    new_lv->name);
666
 
 
667
 
                        layer_name = dm_pool_alloc(lv->vg->cmd->mem, len);
 
695
                        if (dm_snprintf(format, len, "%s_mimage_%%d",
 
696
                                        new_lv->name) < 0) {
 
697
                                log_error("Failed to build new image name.");
 
698
                                return 0;
 
699
                        }
 
700
                        layer_name = dm_pool_alloc(lv->vg->vgmem, len);
668
701
                        if (!layer_name) {
669
702
                                log_error("Unable to allocate memory");
670
703
                                return 0;
715
748
        }
716
749
 
717
750
        /*
718
 
         * Suspend the original device and all its sub devices
 
751
         * Suspend the mirror - this includes all the sub-LVs and
 
752
         *                      soon-to-be-split sub-LVs
719
753
         */
720
 
        if (!suspend_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
 
754
        if (!suspend_lv(cmd, mirrored_seg->lv)) {
721
755
                log_error("Failed to lock %s", mirrored_seg->lv->name);
722
756
                vg_revert(mirrored_seg->lv->vg);
723
757
                return 0;
724
758
        }
725
759
 
726
760
        if (!vg_commit(mirrored_seg->lv->vg)) {
727
 
                resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv);
728
 
                return 0;
729
 
        }
730
 
 
731
 
        /* Bring newly split-off LV into existence */
732
 
        if (!activate_lv(lv->vg->cmd, new_lv)) {
733
 
                log_error("Failed to activate newly split LV, %s",
734
 
                          new_lv->name);
735
 
                return 0;
736
 
        }
737
 
 
738
 
        /* Resume altered original LV */
 
761
                resume_lv(cmd, mirrored_seg->lv);
 
762
                return 0;
 
763
        }
 
764
 
739
765
        log_very_verbose("Updating \"%s\" in kernel", mirrored_seg->lv->name);
740
 
        if (!resume_lv(mirrored_seg->lv->vg->cmd, mirrored_seg->lv)) {
741
 
                log_error("Problem reactivating %s", mirrored_seg->lv->name);
742
 
                return 0;
743
 
        }
744
 
 
 
766
 
 
767
        /*
 
768
         * Resume the mirror - this also activates the visible, independent
 
769
         *                     soon-to-be-split sub-LVs
 
770
         */
 
771
        if (!resume_lv(cmd, mirrored_seg->lv)) {
 
772
                log_error("Problem resuming %s", mirrored_seg->lv->name);
 
773
                return 0;
 
774
        }
 
775
 
 
776
        /*
 
777
         * Recycle newly split LV so it is properly renamed.
 
778
         *   Cluster requires the extra deactivate/activate calls.
 
779
         */
 
780
        if (vg_is_clustered(lv->vg) &&
 
781
            (!deactivate_lv(cmd, new_lv) ||
 
782
             !_activate_lv_like_model(lv, new_lv))) {
 
783
                log_error("Failed to rename newly split LV in the kernel");
 
784
                return 0;
 
785
        }
 
786
        if (!suspend_lv(cmd, new_lv) || !resume_lv(cmd, new_lv)) {
 
787
                log_error("Failed to rename newly split LV in the kernel");
 
788
                return 0;
 
789
        }
 
790
 
 
791
        /* Remove original mirror layer if it has been converted to linear */
745
792
        if (sub_lv && !_delete_lv(lv, sub_lv))
746
793
                return_0;
747
794
 
 
795
        /* Remove the log if it has been converted to linear */
748
796
        if (detached_log_lv && !_delete_lv(lv, detached_log_lv))
749
797
                return_0;
750
798
 
751
 
        log_very_verbose("%" PRIu32 " image(s) detached from %s",
752
 
                         split_count, lv->name);
753
 
 
754
799
        return 1;
755
800
}
756
801
 
828
873
                        if ((s == 0) && !_mirrored_lv_in_sync(lv) &&
829
874
                            !(lv->status & PARTIAL_LV)) {
830
875
                                log_error("Unable to remove primary mirror image while mirror is not in-sync");
831
 
                                return_0;
 
876
                                return 0;
832
877
                        }
833
878
                        if (!shift_mirror_images(mirrored_seg, s))
834
879
                                return_0;
970
1015
                if (!resume_lv(detached_log_lv->vg->cmd, detached_log_lv)) {
971
1016
                        log_error("Failed to resume %s",
972
1017
                                  detached_log_lv->name);
973
 
                        return_0;
 
1018
                        return 0;
974
1019
                }
975
1020
        }
976
1021
 
1046
1091
                        /* As a result, unnecessary sync may run after
1047
1092
                         * collapsing. But safe.*/
1048
1093
                        log_error("Failed to initialize log device");
1049
 
                        return_0;
 
1094
                        return 0;
1050
1095
                }
1051
1096
        }
1052
1097
 
1173
1218
        return 1;
1174
1219
}
1175
1220
 
1176
 
static int get_mirror_fault_policy(struct cmd_context *cmd __attribute__((unused)),
 
1221
static int _get_mirror_fault_policy(struct cmd_context *cmd __attribute__((unused)),
1177
1222
                                   int log_policy)
1178
1223
{
1179
1224
        const char *policy;
1180
1225
 
1181
1226
        if (log_policy)
1182
 
                policy = find_config_str(NULL, "activation/mirror_log_fault_policy",
 
1227
                policy = dm_config_find_str(NULL, "activation/mirror_log_fault_policy",
1183
1228
                                         DEFAULT_MIRROR_LOG_FAULT_POLICY);
1184
1229
        else {
1185
 
                policy = find_config_str(NULL, "activation/mirror_image_fault_policy",
 
1230
                policy = dm_config_find_str(NULL, "activation/mirror_image_fault_policy",
1186
1231
                                         NULL);
1187
1232
                if (!policy)
1188
 
                        policy = find_config_str(NULL, "activation/mirror_device_fault_policy",
 
1233
                        policy = dm_config_find_str(NULL, "activation/mirror_device_fault_policy",
1189
1234
                                                 DEFAULT_MIRROR_IMAGE_FAULT_POLICY);
1190
1235
        }
1191
1236
 
1204
1249
        return MIRROR_REMOVE;
1205
1250
}
1206
1251
 
1207
 
static int get_mirror_log_fault_policy(struct cmd_context *cmd)
 
1252
static int _get_mirror_log_fault_policy(struct cmd_context *cmd)
1208
1253
{
1209
 
        return get_mirror_fault_policy(cmd, 1);
 
1254
        return _get_mirror_fault_policy(cmd, 1);
1210
1255
}
1211
1256
 
1212
 
static int get_mirror_device_fault_policy(struct cmd_context *cmd)
 
1257
static int _get_mirror_device_fault_policy(struct cmd_context *cmd)
1213
1258
{
1214
 
        return get_mirror_fault_policy(cmd, 0);
 
1259
        return _get_mirror_fault_policy(cmd, 0);
1215
1260
}
1216
1261
 
1217
1262
/*
1227
1272
 *
1228
1273
 * Returns: 0 on failure, 1 on reconfig, -1 if no reconfig done
1229
1274
 */
1230
 
static int replace_mirror_images(struct lv_segment *mirrored_seg,
 
1275
static int _replace_mirror_images(struct lv_segment *mirrored_seg,
1231
1276
                                 uint32_t num_mirrors,
1232
1277
                                 int log_policy, int in_sync)
1233
1278
{
1298
1343
        log_warn("WARNING: Bad device removed from mirror volume, %s/%s",
1299
1344
                  mirrored_seg->lv->vg->name, mirrored_seg->lv->name);
1300
1345
 
1301
 
        log_policy = get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
1302
 
        dev_policy = get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
 
1346
        log_policy = _get_mirror_log_fault_policy(mirrored_seg->lv->vg->cmd);
 
1347
        dev_policy = _get_mirror_device_fault_policy(mirrored_seg->lv->vg->cmd);
1303
1348
 
1304
 
        r = replace_mirror_images(mirrored_seg,
 
1349
        r = _replace_mirror_images(mirrored_seg,
1305
1350
                                  (dev_policy != MIRROR_REMOVE) ?
1306
1351
                                  old_num_mirrors : num_mirrors,
1307
1352
                                  log_policy, in_sync);
1484
1529
 
1485
1530
struct logical_volume *find_pvmove_lv(struct volume_group *vg,
1486
1531
                                      struct device *dev,
1487
 
                                      uint32_t lv_type)
 
1532
                                      uint64_t lv_type)
1488
1533
{
1489
1534
        struct lv_list *lvl;
1490
1535
        struct logical_volume *lv;
1514
1559
                                                  struct volume_group *vg,
1515
1560
                                                  const char *name,
1516
1561
                                                  const char *uuid __attribute__((unused)),
1517
 
                                                  uint32_t lv_type)
 
1562
                                                  uint64_t lv_type)
1518
1563
{
1519
1564
        struct physical_volume *pv;
1520
1565
        struct logical_volume *lv;
1856
1901
        unsigned old_log_count;
1857
1902
        int r = 0;
1858
1903
 
 
1904
        if (vg_is_clustered(lv->vg) && (log_count > 1)) {
 
1905
                log_error("Log type, \"mirrored\", is unavailable to cluster mirrors");
 
1906
                return 0;
 
1907
        }
 
1908
 
1859
1909
        if (dm_list_size(&lv->segments) != 1) {
1860
1910
                log_error("Multiple-segment mirror is not supported");
1861
1911
                return 0;
1891
1941
 
1892
1942
        /* allocate destination extents */
1893
1943
        ah = allocate_extents(lv->vg, NULL, segtype,
1894
 
                              0, 0, log_count - old_log_count, region_size, 0,
1895
 
                              allocatable_pvs, alloc, parallel_areas);
 
1944
                              0, 0, log_count - old_log_count, region_size,
 
1945
                              lv->le_count, allocatable_pvs,
 
1946
                              alloc, parallel_areas);
1896
1947
        if (!ah) {
1897
1948
                log_error("Unable to allocate extents for mirror log.");
1898
1949
                return 0;
2019
2070
 
2020
2071
        if (vg_is_clustered(lv->vg)) {
2021
2072
                /* FIXME: review check of lv_is_active_remotely */
2022
 
                if (!cluster_mirror_is_available(lv)) {
 
2073
                if (!_cluster_mirror_is_available(lv)) {
2023
2074
                        log_error("Shared cluster mirrors are not available.");
2024
2075
                        return 0;
2025
2076
                }
2085
2136
        /* Can't split a mirror that is not in-sync... unless force? */
2086
2137
        if (!_mirrored_lv_in_sync(lv)) {
2087
2138
                log_error("Unable to split mirror that is not in-sync.");
2088
 
                return_0;
 
2139
                return 0;
2089
2140
        }
2090
2141
 
2091
2142
        /*