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

« back to all changes in this revision

Viewing changes to lib/replicator/replicator.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:
36
36
 */
37
37
#define SEG_LOG_ERROR(t, p...) \
38
38
        log_error(t " segment %s of logical volume %s.", ## p, \
39
 
                  config_parent_name(sn), seg->lv->name), 0;
 
39
                  dm_config_parent_name(sn), seg->lv->name), 0;
40
40
 
41
41
 
42
42
/*
58
58
                log_print("  Replicator volume\t%s", seg->rlog_lv->name);
59
59
}
60
60
 
61
 
/* Wrapper for get_config_uint32() with default value */
62
 
static uint32_t _get_config_uint32(const struct config_node *cn,
 
61
/* Wrapper for dm_config_get_uint32() with default value */
 
62
static uint32_t _get_config_uint32(const struct dm_config_node *cn,
63
63
                                   const char *path,
64
64
                                   uint32_t def)
65
65
{
66
66
        uint32_t t;
67
67
 
68
 
        return get_config_uint32(cn, path, &t) ? t : def;
 
68
        return dm_config_get_uint32(cn, path, &t) ? t : def;
69
69
}
70
70
 
71
 
/* Wrapper for get_config_uint64() with default value */
72
 
static uint64_t _get_config_uint64(const struct config_node *cn,
 
71
/* Wrapper for dm_config_get_uint64() with default value */
 
72
static uint64_t _get_config_uint64(const struct dm_config_node *cn,
73
73
                                   const char *path,
74
74
                                   uint64_t def)
75
75
{
76
76
        uint64_t t;
77
77
 
78
 
        return get_config_uint64(cn, path, &t) ? t : def;
 
78
        return dm_config_get_uint64(cn, path, &t) ? t : def;
79
79
}
80
80
 
81
81
 
86
86
};
87
87
 
88
88
/* Parse state string */
89
 
static replicator_state_t _get_state(const struct config_node *sn,
 
89
static replicator_state_t _get_state(const struct dm_config_node *sn,
90
90
                                     const char *path, replicator_state_t def)
91
91
{
92
92
        const char *str;
93
93
        unsigned i;
94
94
 
95
 
        if (get_config_str(sn, path, &str)) {
 
95
        if (dm_config_get_str(sn, path, &str)) {
96
96
                for (i = 0; i < sizeof(_state_txt)/sizeof(_state_txt[0]); ++i)
97
97
                        if (strcasecmp(str, _state_txt[i]) == 0)
98
98
                                return (replicator_state_t) i;
115
115
 
116
116
 
117
117
/* Parse action string */
118
 
static dm_replicator_mode_t _get_op_mode(const struct config_node *sn,
 
118
static dm_replicator_mode_t _get_op_mode(const struct dm_config_node *sn,
119
119
                                         const char *path, dm_replicator_mode_t def)
120
120
{
121
121
        const char *str;
122
122
        unsigned i;
123
123
 
124
 
        if (get_config_str(sn, path, &str)) {
 
124
        if (dm_config_get_str(sn, path, &str)) {
125
125
                for (i = 0; i < sizeof(_op_mode_txt)/sizeof(_op_mode_txt[0]); ++i)
126
126
                        if (strcasecmp(str, _op_mode_txt[i]) == 0) {
127
127
                                log_very_verbose("Setting %s to %s",
162
162
/* Parse replicator site element */
163
163
static int _add_site(struct lv_segment *seg,
164
164
                     const char *key,
165
 
                     const struct config_node *sn)
 
165
                     const struct dm_config_node *sn)
166
166
{
167
167
        struct dm_pool *mem = seg->lv->vg->vgmem;
168
 
        const struct config_node *cn;
 
168
        const struct dm_config_node *cn;
169
169
        struct replicator_site *rsite;
170
170
 
171
171
        if (!(rsite = _get_site(seg->lv, key)))
172
172
                return_0;
173
173
 
174
 
        if (!find_config_node(sn, "site_index"))
 
174
        if (!dm_config_find_node(sn, "site_index"))
175
175
                return SEG_LOG_ERROR("Mandatory site_index is missing for");
176
176
 
177
177
        rsite->state = _get_state(sn, "state", REPLICATOR_STATE_PASSIVE);
204
204
                                              rsite->op_mode);
205
205
        }
206
206
 
207
 
        if ((cn = find_config_node(sn, "volume_group"))) {
208
 
                if (!cn->v || cn->v->type != CFG_STRING)
 
207
        if ((cn = dm_config_find_node(sn, "volume_group"))) {
 
208
                if (!cn->v || cn->v->type != DM_CFG_STRING)
209
209
                        return SEG_LOG_ERROR("volume_group must be a string in");
210
210
 
211
211
                if (!(rsite->vg_name = dm_pool_strdup(mem, cn->v->v.str)))
220
220
 
221
221
/* Import replicator segment */
222
222
static int _replicator_text_import(struct lv_segment *seg,
223
 
                                   const struct config_node *sn,
 
223
                                   const struct dm_config_node *sn,
224
224
                                   struct dm_hash_table *pv_hash __attribute__((unused)))
225
225
{
226
 
        const struct config_node *cn;
 
226
        const struct dm_config_node *cn;
227
227
        struct logical_volume *rlog_lv;
228
228
 
229
229
        if (!replicator_add_replicator_dev(seg->lv, NULL))
230
230
                return_0;
231
231
 
232
 
        if (!(cn = find_config_node(sn, "replicator_log")) ||
233
 
            !cn->v || cn->v->type != CFG_STRING)
 
232
        if (!(cn = dm_config_find_node(sn, "replicator_log")) ||
 
233
            !cn->v || cn->v->type != DM_CFG_STRING)
234
234
                return SEG_LOG_ERROR("Replicator log type must be a string in");
235
235
 
236
236
        if (!(rlog_lv = find_lv(seg->lv->vg, cn->v->v.str)))
237
237
                return SEG_LOG_ERROR("Unknown replicator log %s in",
238
238
                                     cn->v->v.str);
239
239
 
240
 
        if (!(cn = find_config_node(sn, "replicator_log_type")) ||
241
 
            !cn->v || cn->v->type != CFG_STRING)
 
240
        if (!(cn = dm_config_find_node(sn, "replicator_log_type")) ||
 
241
            !cn->v || cn->v->type != DM_CFG_STRING)
242
242
                return SEG_LOG_ERROR("Replicator log's type must be a string in");
243
243
        if (strcasecmp(cn->v->v.str, "ringbuffer"))
244
244
                return SEG_LOG_ERROR("Only ringbuffer replicator log type is supported in");
443
443
 
444
444
static int _add_device(struct lv_segment *seg,
445
445
                       const char *site_name,
446
 
                       const struct config_node *sn,
 
446
                       const struct dm_config_node *sn,
447
447
                       uint64_t devidx)
448
448
{
449
449
        struct dm_pool *mem = seg->lv->vg->vgmem;
453
453
        struct replicator_device *rdev;
454
454
        const char *dev_str = NULL;
455
455
        const char *slog_str = NULL;
456
 
        const struct config_node *cn;
 
456
        const struct dm_config_node *cn;
457
457
 
458
458
        dm_list_iterate_items(rdev, &rsite->rdevices)
459
459
                if (rdev->replicator_dev == seg)
460
460
                        return SEG_LOG_ERROR("Duplicate site found in");
461
461
 
462
 
        if ((cn = find_config_node(sn, "sync_log"))) {
 
462
        if ((cn = dm_config_find_node(sn, "sync_log"))) {
463
463
                if (!cn->v || !cn->v->v.str)
464
464
                        return SEG_LOG_ERROR("Sync log must be a string in");
465
465
                slog_str = cn->v->v.str;
466
466
        }
467
467
 
468
 
        if (!(cn = find_config_node(sn, "logical_volume")) ||
 
468
        if (!(cn = dm_config_find_node(sn, "logical_volume")) ||
469
469
            !cn->v || !cn->v->v.str)
470
470
                return SEG_LOG_ERROR("Logical volume must be a string in");
471
471
 
520
520
 
521
521
/* Import replicator segment */
522
522
static int _replicator_dev_text_import(struct lv_segment *seg,
523
 
                                       const struct config_node *sn,
 
523
                                       const struct dm_config_node *sn,
524
524
                                       struct dm_hash_table *pv_hash __attribute__((unused)))
525
525
{
526
 
        const struct config_node *cn;
 
526
        const struct dm_config_node *cn;
527
527
        struct logical_volume *replicator;
528
528
        uint64_t devidx;
529
529
 
530
 
        if (!(cn = find_config_node(sn, "replicator")))
 
530
        if (!(cn = dm_config_find_node(sn, "replicator")))
531
531
                return SEG_LOG_ERROR("Replicator is missing for");
532
532
 
533
533
        if (!cn->v || !cn->v->v.str)
542
542
        log_very_verbose("replicator=%s", replicator->name);
543
543
 
544
544
        /* Mandatory */
545
 
        if (!find_config_node(sn, "device_index") ||
546
 
            !get_config_uint64(sn, "device_index", &devidx))
 
545
        if (!dm_config_find_node(sn, "device_index") ||
 
546
            !dm_config_get_uint64(sn, "device_index", &devidx))
547
547
                return SEG_LOG_ERROR("Could not read 'device_index' for");
548
548
 
549
549
        /* Read devices from sites */
625
625
                /* Create passive linear mapping */
626
626
                log_very_verbose("Inactive replicator %s using %s.",
627
627
                                 seg->lv->name, seg->lv->rdevice->lv->name);
628
 
                if (!dm_tree_node_add_linear_target(node, seg->lv->size))
 
628
                if (!add_linear_area_to_dtree(node, seg->lv->size, seg->lv->vg->extent_size,
 
629
                                              cmd->use_linear_target,
 
630
                                              seg->lv->vg->name, seg->lv->name))
629
631
                        return_0;
630
632
                if (!(rdev_dlid = build_dm_uuid(mem, seg->lv->rdevice->lv->lvid.s, NULL)))
631
633
                        return_0;
754
756
};
755
757
 
756
758
#ifdef REPLICATOR_INTERNAL
757
 
int init_replicator_segtype(struct segtype_library *seglib)
 
759
int init_replicator_segtype(struct cmd_context *cmd, struct segtype_library *seglib)
758
760
#else /* Shared */
759
 
int init_multiple_segtype(struct segtype_library *seglib);
760
 
int init_multiple_segtype(struct segtype_library *seglib)
 
761
int init_multiple_segtype(struct cmd_context *cmd, struct segtype_library *seglib);
 
762
int init_multiple_segtype(struct cmd_context *cmd, struct segtype_library *seglib)
761
763
#endif
762
764
{
763
765
        struct segment_type *segtype;
771
773
        segtype->flags = SEG_REPLICATOR;
772
774
 
773
775
        if (!lvm_register_segtype(seglib, segtype))
 
776
                /* segtype is already destroyed */
774
777
                return_0;
775
778
 
776
779
        log_very_verbose("Initialised segtype: " REPLICATOR_MODULE);
784
787
        segtype->flags = SEG_REPLICATOR_DEV;
785
788
 
786
789
        if (!lvm_register_segtype(seglib, segtype))
 
790
                /* segtype is already destroyed */
787
791
                return_0;
788
792
 
789
793
        log_very_verbose("Initialised segtype: " REPLICATOR_DEV_MODULE);