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

« back to all changes in this revision

Viewing changes to lib/metadata/lv.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:
146
146
                segm = first_seg(seg->log_lv);
147
147
 
148
148
        // log_debug("Query LV:%s mon:%s segm:%s tgtm:%p  segmon:%d statusm:%d", seg->lv->name, segm->lv->name, segm->segtype->name, segm->segtype->ops->target_monitored, seg_monitored(segm), (int)(segm->status & PVMOVE));
149
 
        if (!segm->segtype->ops->target_monitored)
 
149
        if ((dmeventd_monitor_mode() != 1) ||
 
150
            !segm->segtype->ops->target_monitored)
150
151
                /* Nothing to do, monitoring not supported */;
151
152
        else if (lv_is_cow_covering_origin(seg->lv))
152
153
                /* Nothing to do, snapshot already covers origin */;
153
154
        else if (!seg_monitored(segm) || (segm->status & PVMOVE))
154
155
                s = "not monitored";
155
156
        else if (lv_info(seg->lv->vg->cmd, seg->lv, 1, &info, 0, 0) && info.exists) {
156
 
                monitored = segm->segtype->ops->
157
 
                        target_monitored((struct lv_segment*)segm, &pending);
 
157
                monitored = segm->segtype->ops->target_monitored(segm, &pending);
158
158
                if (pending)
159
159
                        s = "pending";
160
160
                else
170
170
 
171
171
        if (lv_is_cow(seg->lv))
172
172
                size = (uint64_t) find_snapshot(seg->lv)->chunk_size;
173
 
        else if (seg_is_thin_pool(seg) || seg_is_cache_pool(seg))
 
173
        else if (seg_is_pool(seg))
174
174
                size = (uint64_t) seg->chunk_size;
175
175
        else
176
176
                size = UINT64_C(0);
219
219
        return dm_pool_strdup(mem, lv->name);
220
220
}
221
221
 
 
222
char *lv_fullname_dup(struct dm_pool *mem, const struct logical_volume *lv)
 
223
{
 
224
        char lvfullname[NAME_LEN * 2 + 2];
 
225
 
 
226
        if (dm_snprintf(lvfullname, sizeof(lvfullname), "%s/%s", lv->vg->name, lv->name) < 0) {
 
227
                log_error("lvfullname snprintf failed");
 
228
                return NULL;
 
229
        }
 
230
 
 
231
        return dm_pool_strdup(mem, lvfullname);
 
232
}
 
233
 
 
234
struct logical_volume *lv_parent(const struct logical_volume *lv)
 
235
{
 
236
        struct logical_volume *parent_lv = NULL;
 
237
 
 
238
        if (lv_is_visible(lv))
 
239
                ;
 
240
        else if (lv_is_mirror_image(lv) || lv_is_mirror_log(lv))
 
241
                parent_lv = get_only_segment_using_this_lv(lv)->lv;
 
242
        else if (lv_is_raid_image(lv) || lv_is_raid_metadata(lv))
 
243
                parent_lv = get_only_segment_using_this_lv(lv)->lv;
 
244
        else if (lv_is_cache_pool_data(lv) || lv_is_cache_pool_metadata(lv))
 
245
                parent_lv = get_only_segment_using_this_lv(lv)->lv;
 
246
        else if (lv_is_thin_pool_data(lv) || lv_is_thin_pool_metadata(lv))
 
247
                parent_lv = get_only_segment_using_this_lv(lv)->lv;
 
248
 
 
249
        return parent_lv;
 
250
}
 
251
 
 
252
char *lv_parent_dup(struct dm_pool *mem, const struct logical_volume *lv)
 
253
{
 
254
        struct logical_volume *parent_lv = lv_parent(lv);
 
255
 
 
256
        return dm_pool_strdup(mem, parent_lv ? parent_lv->name : "");
 
257
}
 
258
 
222
259
char *lv_modules_dup(struct dm_pool *mem, const struct logical_volume *lv)
223
260
{
224
261
        struct dm_list *modules;
316
353
 
317
354
char *lv_move_pv_dup(struct dm_pool *mem, const struct logical_volume *lv)
318
355
{
 
356
        struct logical_volume *mimage0_lv;
319
357
        struct lv_segment *seg;
320
 
 
321
 
        dm_list_iterate_items(seg, &lv->segments)
322
 
                if (seg->status & PVMOVE)
323
 
                        return dm_pool_strdup(mem, dev_name(seg_dev(seg, 0)));
 
358
        const struct device *dev;
 
359
 
 
360
        dm_list_iterate_items(seg, &lv->segments) {
 
361
                if (seg->status & PVMOVE) {
 
362
                        if (seg_type(seg, 0) == AREA_LV) { /* atomic pvmove */
 
363
                                mimage0_lv = seg_lv(seg, 0);
 
364
                                if (!lv_is_mirror_type(mimage0_lv)) {
 
365
                                        log_error(INTERNAL_ERROR
 
366
                                                  "Bad pvmove structure");
 
367
                                        return NULL;
 
368
                                }
 
369
                                dev = seg_dev(first_seg(mimage0_lv), 0);
 
370
                        } else /* Segment pvmove */
 
371
                                dev = seg_dev(seg, 0);
 
372
 
 
373
                        return dm_pool_strdup(mem, dev_name(dev));
 
374
                }
 
375
        }
324
376
 
325
377
        return NULL;
326
378
}
355
407
        char *repstr;
356
408
        size_t len;
357
409
 
358
 
        if (!*lv->vg->name)
 
410
        /* Only for visible devices that get a link from /dev/vg */
 
411
        if (!*lv->vg->name || !lv_is_visible(lv) || lv_is_thin_pool(lv))
359
412
                return dm_pool_strdup(mem, "");
360
413
 
361
414
        len = strlen(lv->vg->cmd->dev_dir) + strlen(lv->vg->name) +
363
416
 
364
417
        if (!(repstr = dm_pool_zalloc(mem, len))) {
365
418
                log_error("dm_pool_alloc failed");
366
 
                return 0;
 
419
                return NULL;
367
420
        }
368
421
 
369
422
        if (dm_snprintf(repstr, len, "%s%s/%s",
370
423
                        lv->vg->cmd->dev_dir, lv->vg->name, lv->name) < 0) {
371
424
                log_error("lvpath snprintf failed");
372
 
                return 0;
 
425
                return NULL;
 
426
        }
 
427
 
 
428
        return repstr;
 
429
}
 
430
 
 
431
char *lv_dmpath_dup(struct dm_pool *mem, const struct logical_volume *lv)
 
432
{
 
433
        char *name;
 
434
        char *repstr;
 
435
        size_t len;
 
436
 
 
437
        if (!*lv->vg->name)
 
438
                return dm_pool_strdup(mem, "");
 
439
 
 
440
        if (!(name = dm_build_dm_name(mem, lv->vg->name, lv->name, NULL))) {
 
441
                log_error("dm_build_dm_name failed");
 
442
                return NULL;
 
443
        }
 
444
 
 
445
        len = strlen(dm_dir()) + strlen(name) + 2;
 
446
 
 
447
        if (!(repstr = dm_pool_zalloc(mem, len))) {
 
448
                log_error("dm_pool_alloc failed");
 
449
                return NULL;
 
450
        }
 
451
 
 
452
        if (dm_snprintf(repstr, len, "%s/%s", dm_dir(), name) < 0) {
 
453
                log_error("lv_dmpath snprintf failed");
 
454
                return NULL;
373
455
        }
374
456
 
375
457
        return repstr;
390
472
        return lv->size;
391
473
}
392
474
 
393
 
static int _lv_mimage_in_sync(const struct logical_volume *lv)
 
475
int lv_mirror_image_in_sync(const struct logical_volume *lv)
394
476
{
395
 
        percent_t percent;
 
477
        dm_percent_t percent;
396
478
        struct lv_segment *seg = first_seg(lv);
397
479
        struct lv_segment *mirror_seg;
398
480
 
406
488
                               NULL))
407
489
                return_0;
408
490
 
409
 
        return (percent == PERCENT_100) ? 1 : 0;
 
491
        return (percent == DM_PERCENT_100) ? 1 : 0;
410
492
}
411
493
 
412
 
static int _lv_raid_image_in_sync(const struct logical_volume *lv)
 
494
int lv_raid_image_in_sync(const struct logical_volume *lv)
413
495
{
414
496
        unsigned s;
415
 
        percent_t percent;
 
497
        dm_percent_t percent;
416
498
        char *raid_health;
417
499
        struct lv_segment *seg, *raid_seg = NULL;
418
500
 
444
526
        if (!lv_raid_percent(raid_seg->lv, &percent))
445
527
                return_0;
446
528
 
447
 
        if (percent == PERCENT_100)
 
529
        if (percent == DM_PERCENT_100)
448
530
                return 1;
449
531
 
450
532
        /* Find out which sub-LV this is. */
473
555
 *
474
556
 * Returns: 1 if healthy, 0 if device is not health
475
557
 */
476
 
static int _lv_raid_healthy(const struct logical_volume *lv)
 
558
int lv_raid_healthy(const struct logical_volume *lv)
477
559
{
478
560
        unsigned s;
479
561
        char *raid_health;
537
619
 
538
620
char *lv_attr_dup(struct dm_pool *mem, const struct logical_volume *lv)
539
621
{
540
 
        percent_t snap_percent;
 
622
        dm_percent_t snap_percent;
541
623
        struct lvinfo info;
542
624
        struct lv_segment *seg;
543
625
        char *repstr;
558
640
        /* Origin takes precedence over mirror and thin volume */
559
641
        else if (lv_is_origin(lv) || lv_is_external_origin(lv))
560
642
                repstr[0] = (lv_is_merging_origin(lv)) ? 'O' : 'o';
561
 
        else if (lv_is_cache_pool_metadata(lv))
 
643
        else if (lv_is_pool_metadata(lv) ||
 
644
                 lv_is_pool_metadata_spare(lv) ||
 
645
                 lv_is_raid_metadata(lv))
562
646
                repstr[0] = 'e';
563
647
        else if (lv_is_cache_type(lv))
564
648
                repstr[0] = 'C';
565
 
        else if (lv_is_thin_pool_metadata(lv) ||
566
 
                 lv_is_pool_metadata_spare(lv) ||
567
 
                 (lv->status & RAID_META))
568
 
                repstr[0] = 'e';
569
649
        else if (lv->status & RAID)
570
650
                repstr[0] = (lv->status & LV_NOTSYNCED) ? 'R' : 'r';
571
651
        else if (lv->status & MIRRORED)
580
660
        else if (lv_is_thin_pool_data(lv))
581
661
                repstr[0] = 'T';
582
662
        else if (lv->status & MIRROR_IMAGE)
583
 
                repstr[0] = (_lv_mimage_in_sync(lv)) ? 'i' : 'I';
 
663
                repstr[0] = (lv_mirror_image_in_sync(lv)) ? 'i' : 'I';
584
664
        else if (lv->status & RAID_IMAGE)
585
665
                /*
586
666
                 * Visible RAID_IMAGES are sub-LVs that have been exposed for
587
667
                 * top-level use by being split from the RAID array with
588
668
                 * '--splitmirrors 1 --trackchanges'.  They always report 'I'.
589
669
                 */
590
 
                repstr[0] = (!lv_is_visible(lv) && _lv_raid_image_in_sync(lv)) ?
 
670
                repstr[0] = (!lv_is_visible(lv) && lv_raid_image_in_sync(lv)) ?
591
671
                        'i' : 'I';
592
672
        else if (lv->status & MIRROR_LOG)
593
673
                repstr[0] = 'l';
612
692
 
613
693
        repstr[3] = (lv->status & FIXED_MINOR) ? 'm' : '-';
614
694
 
615
 
        if (lv_info(lv->vg->cmd, lv, 0, &info, 1, 0) && info.exists) {
 
695
        if (!activation() || !lv_info(lv->vg->cmd, lv, 0, &info, 1, 0)) {
 
696
                repstr[4] = 'X';                /* Unknown */
 
697
                repstr[5] = 'X';                /* Unknown */
 
698
        } else if (info.exists) {
616
699
                if (info.suspended)
617
700
                        repstr[4] = 's';        /* Suspended */
618
701
                else if (info.live_table)
625
708
                /* Snapshot dropped? */
626
709
                if (info.live_table && lv_is_cow(lv)) {
627
710
                        if (!lv_snapshot_percent(lv, &snap_percent) ||
628
 
                            snap_percent == PERCENT_INVALID) {
 
711
                            snap_percent == DM_PERCENT_INVALID) {
629
712
                                if (info.suspended)
630
713
                                        repstr[4] = 'S'; /* Susp Inv snapshot */
631
714
                                else
632
715
                                        repstr[4] = 'I'; /* Invalid snapshot */
633
716
                        }
634
 
                        else if (snap_percent == PERCENT_MERGE_FAILED) {
 
717
                        else if (snap_percent == LVM_PERCENT_MERGE_FAILED) {
635
718
                                if (info.suspended)
636
719
                                        repstr[4] = 'M'; /* Susp snapshot merge failed */
637
720
                                else
654
737
 
655
738
        if (lv_is_thin_pool(lv) || lv_is_thin_volume(lv))
656
739
                repstr[6] = 't';
657
 
        else if (lv_is_cache_type(lv))
 
740
        else if (lv_is_cache_pool(lv) || lv_is_cache(lv))
658
741
                repstr[6] = 'C';
659
742
        else if (lv_is_raid_type(lv))
660
743
                repstr[6] = 'r';
681
764
                repstr[8] = 'p';
682
765
        else if (lv_is_raid_type(lv)) {
683
766
                uint64_t n;
684
 
                if (!_lv_raid_healthy(lv))
 
767
                if (!activation())
 
768
                        repstr[8] = 'X';        /* Unknown */
 
769
                else if (!lv_raid_healthy(lv))
685
770
                        repstr[8] = 'r';  /* RAID needs 'r'efresh */
686
771
                else if (lv->status & RAID) {
687
772
                        if (lv_raid_mismatch_count(lv, &n) && n)
756
841
 
757
842
static int _lv_is_exclusive(struct logical_volume *lv)
758
843
{
759
 
        /* Some devices require exlusivness */
760
 
        return seg_is_raid(first_seg(lv)) ||
 
844
        /* Some devices require exlusiveness */
 
845
        return lv_is_raid(lv) ||
761
846
                lv_is_origin(lv) ||
762
847
                lv_is_thin_type(lv) ||
763
848
                lv_is_cache_type(lv);
823
908
{
824
909
        const char *s;
825
910
 
 
911
        if (!activation()) {
 
912
                s = "unknown";
 
913
                goto out;
 
914
        }
 
915
 
826
916
        if (vg_is_clustered(lv->vg)) {
827
917
                //const struct logical_volume *lvo = lv;
828
918
                lv = lv_lock_holder(lv);
840
930
        else /* locally active */
841
931
                s = lv_is_active_but_not_locally(lv) ?
842
932
                        "remotely" : "locally";
843
 
 
 
933
out:
844
934
        return dm_pool_strdup(mem, s);
845
935
}
846
936