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

« back to all changes in this revision

Viewing changes to tools/pvmove.c

  • Committer: Package Import Robot
  • Author(s): Dmitrijs Ledkovs
  • Date: 2013-05-30 11:02:10 UTC
  • mfrom: (3.1.28 sid)
  • Revision ID: package-import@ubuntu.com-20130530110210-q8bou4f333ruwhn0
Tags: 2.02.98-1ubuntu1
* 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.
      - In libdevmapper-event1.02.1 add Breaks: dmeventd
        (<< 2.02.95-4ubuntu1) due to debian symbol rename
    - 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.
      - continue to build clvm support.
    - 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.
  - Complete libdevmapper-dev multiarch:
    - move .so symlinks and pkgconfig files to multiarched locations.
    - mark libdevmapper-dev M-A: same

* Dropped changes, applied upstream:
  - Update Micron PCIe SSD and other device-types to latest available.
  - Cherry pick from upstream, remove unsupported udev_get_dev_path() call.
  - Move thin check to global section.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
#include "display.h"
19
19
 
20
20
#define PVMOVE_FIRST_TIME   0x00000001      /* Called for first time */
 
21
#define PVMOVE_EXCLUSIVE    0x00000002      /* Require exclusive LV */
21
22
 
22
23
static int _pvmove_target_present(struct cmd_context *cmd, int clustered)
23
24
{
174
175
                                                const char *lv_name,
175
176
                                                struct dm_list *allocatable_pvs,
176
177
                                                alloc_policy_t alloc,
177
 
                                                struct dm_list **lvs_changed)
 
178
                                                struct dm_list **lvs_changed,
 
179
                                                unsigned *exclusive)
178
180
{
179
181
        struct logical_volume *lv_mirr, *lv;
180
182
        struct lv_list *lvl;
181
183
        uint32_t log_count = 0;
182
184
        int lv_found = 0;
183
185
        int lv_skipped = 0;
 
186
        int lv_active_count = 0;
 
187
        int lv_exclusive_count = 0;
184
188
 
185
189
        /* FIXME Cope with non-contiguous => splitting existing segments */
186
190
        if (!(lv_mirr = lv_create_empty("pvmove%d", NULL,
211
215
                }
212
216
                if (lv_is_origin(lv) || lv_is_cow(lv)) {
213
217
                        lv_skipped = 1;
214
 
                        log_print("Skipping snapshot-related LV %s", lv->name);
 
218
                        log_print_unless_silent("Skipping snapshot-related LV %s", lv->name);
215
219
                        continue;
216
220
                }
217
221
                if (lv->status & MIRRORED) {
218
222
                        lv_skipped = 1;
219
 
                        log_print("Skipping mirror LV %s", lv->name);
 
223
                        log_print_unless_silent("Skipping mirror LV %s", lv->name);
220
224
                        continue;
221
225
                }
222
226
                if (lv->status & MIRROR_LOG) {
223
227
                        lv_skipped = 1;
224
 
                        log_print("Skipping mirror log LV %s", lv->name);
 
228
                        log_print_unless_silent("Skipping mirror log LV %s", lv->name);
225
229
                        continue;
226
230
                }
227
231
                if (lv->status & MIRROR_IMAGE) {
228
232
                        lv_skipped = 1;
229
 
                        log_print("Skipping mirror image LV %s", lv->name);
 
233
                        log_print_unless_silent("Skipping mirror image LV %s", lv->name);
230
234
                        continue;
231
235
                }
232
236
                if (lv->status & LOCKED) {
233
237
                        lv_skipped = 1;
234
 
                        log_print("Skipping locked LV %s", lv->name);
235
 
                        continue;
236
 
                }
 
238
                        log_print_unless_silent("Skipping locked LV %s", lv->name);
 
239
                        continue;
 
240
                }
 
241
 
 
242
                if (vg_is_clustered(vg) &&
 
243
                    lv_is_active_exclusive_remotely(lv)) {
 
244
                        lv_skipped = 1;
 
245
                        log_print_unless_silent("Skipping LV %s which is activated "
 
246
                                                "exclusively on remote node.", lv->name);
 
247
                        continue;
 
248
                }
 
249
 
 
250
                if (vg_is_clustered(vg)) {
 
251
                        if (lv_is_active_exclusive_locally(lv))
 
252
                                lv_exclusive_count++;
 
253
                        else if (lv_is_active(lv))
 
254
                                lv_active_count++;
 
255
                }
 
256
 
237
257
                if (!_insert_pvmove_mirrors(cmd, lv_mirr, source_pvl, lv,
238
258
                                            *lvs_changed))
239
259
                        return_NULL;
254
274
                return NULL;
255
275
        }
256
276
 
 
277
        if (vg_is_clustered(vg) && lv_active_count && *exclusive) {
 
278
                log_error("Cannot move in clustered VG %s, "
 
279
                          "clustered mirror (cmirror) not detected "
 
280
                          "and LVs are activated non-exclusively.",
 
281
                          vg->name);
 
282
                return NULL;
 
283
        }
 
284
 
 
285
        if (vg_is_clustered(vg) && lv_exclusive_count) {
 
286
                if (lv_active_count) {
 
287
                        log_error("Cannot move in clustered VG %s "
 
288
                                  "if some LVs are activated "
 
289
                                  "exclusively while others don't.",
 
290
                                  vg->name);
 
291
                        return NULL;
 
292
                }
 
293
                *exclusive = 1;
 
294
        }
 
295
 
257
296
        if (!lv_add_mirrors(cmd, lv_mirr, 1, 1, 0, 0, log_count,
258
297
                            allocatable_pvs, alloc, MIRROR_BY_SEG)) {
259
298
                log_error("Failed to convert pvmove LV to mirrored");
273
312
{
274
313
        int r = 0;
275
314
 
276
 
        if (exclusive)
 
315
        if (exclusive || lv_is_active_exclusive(lv_mirr))
277
316
                r = activate_lv_excl(cmd, lv_mirr);
278
317
        else
279
318
                r = activate_lv(cmd, lv_mirr);
358
397
                            struct logical_volume *lv_mirr,
359
398
                            struct dm_list *lvs_changed, unsigned flags)
360
399
{
361
 
        unsigned exclusive = _pvmove_is_exclusive(cmd, vg);
 
400
        unsigned exclusive = (flags & PVMOVE_EXCLUSIVE) ? 1 : 0;
362
401
        unsigned first_time = (flags & PVMOVE_FIRST_TIME) ? 1 : 0;
363
402
        int r = 0;
364
403
 
369
408
        }
370
409
 
371
410
        if (!_suspend_lvs(cmd, first_time, lv_mirr, lvs_changed, vg)) {
372
 
                log_error("ABORTING: Volume group metadata update failed. (first_time: %d)", first_time);
 
411
                log_error("ABORTING: Temporary pvmove mirror %s failed.", first_time ? "activation" : "reload");
373
412
                /* FIXME Add a recovery path for first time too. */
374
413
                if (!first_time && !revert_lv(cmd, lv_mirr))
375
414
                        stack;
390
429
        /* Only the first mirror segment gets activated as a mirror */
391
430
        /* FIXME: Add option to use a log */
392
431
        if (first_time) {
 
432
                if (!exclusive && _pvmove_is_exclusive(cmd, vg))
 
433
                        exclusive = 1;
 
434
 
393
435
                if (!_activate_lv(cmd, lv_mirr, exclusive)) {
394
436
                        if (test_mode()) {
395
437
                                r = 1;
428
470
        struct dm_list *lvs_changed;
429
471
        struct physical_volume *pv;
430
472
        struct logical_volume *lv_mirr;
431
 
        unsigned first_time = 1;
 
473
        unsigned flags = PVMOVE_FIRST_TIME;
432
474
        unsigned exclusive;
433
475
        int r = ECMD_FAILED;
434
476
 
470
512
        exclusive = _pvmove_is_exclusive(cmd, vg);
471
513
 
472
514
        if ((lv_mirr = find_pvmove_lv(vg, pv_dev(pv), PVMOVE))) {
473
 
                log_print("Detected pvmove in progress for %s", pv_name);
 
515
                log_print_unless_silent("Detected pvmove in progress for %s", pv_name);
474
516
                if (argc || lv_name)
475
517
                        log_error("Ignoring remaining command line arguments");
476
518
 
485
527
                        goto out;
486
528
                }
487
529
 
488
 
                first_time = 0;
 
530
                flags &= ~PVMOVE_FIRST_TIME;
489
531
        } else {
490
532
                /* Determine PE ranges to be moved */
491
533
                if (!(source_pvl = create_pv_list(cmd->mem, vg, 1,
506
548
 
507
549
                if (!(lv_mirr = _set_up_pvmove_lv(cmd, vg, source_pvl, lv_name,
508
550
                                                  allocatable_pvs, alloc,
509
 
                                                  &lvs_changed)))
 
551
                                                  &lvs_changed, &exclusive)))
510
552
                        goto_out;
511
553
        }
512
554
 
518
560
        /* init_pvmove(1); */
519
561
        /* vg->status |= PVMOVE; */
520
562
 
521
 
        if (first_time) {
 
563
        if (flags & PVMOVE_FIRST_TIME) {
 
564
                if (exclusive)
 
565
                        flags |= PVMOVE_EXCLUSIVE;
522
566
                if (!_update_metadata
523
 
                    (cmd, vg, lv_mirr, lvs_changed, PVMOVE_FIRST_TIME))
 
567
                    (cmd, vg, lv_mirr, lvs_changed, flags))
524
568
                        goto_out;
525
569
        }
526
570