~brightbox/ubuntu/raring/lvm2/fix-for-1076304

« back to all changes in this revision

Viewing changes to lib/commands/toolcontext.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:
1
1
/*
2
2
 * Copyright (C) 2001-2004 Sistina Software, Inc. All rights reserved.
3
 
 * Copyright (C) 2004-2009 Red Hat, Inc. All rights reserved.
 
3
 * Copyright (C) 2004-2012 Red Hat, Inc. All rights reserved.
4
4
 *
5
5
 * This file is part of LVM2.
6
6
 *
22
22
#include "filter.h"
23
23
#include "filter-composite.h"
24
24
#include "filter-md.h"
 
25
#include "filter-mpath.h"
25
26
#include "filter-persistent.h"
26
27
#include "filter-regex.h"
27
28
#include "filter-sysfs.h"
33
34
#include "str_list.h"
34
35
#include "segtype.h"
35
36
#include "lvmcache.h"
 
37
#include "lvmetad.h"
36
38
#include "dev-cache.h"
37
39
#include "archiver.h"
38
40
 
97
99
        }
98
100
 
99
101
        if (!(fp = fopen(proc_mounts, "r"))) {
100
 
                log_sys_error("_get_sysfs_dir: fopen %s", proc_mounts);
 
102
                log_sys_error("_get_sysfs_dir fopen", proc_mounts);
101
103
                return;
102
104
        }
103
105
 
153
155
        init_abort_on_internal_errors(find_config_tree_int(cmd, "global/abort_on_internal_errors",
154
156
                                                           DEFAULT_ABORT_ON_INTERNAL_ERRORS));
155
157
 
156
 
        cmd->default_settings.msg_prefix = find_config_tree_str(cmd,
157
 
                                                           "log/prefix",
158
 
                                                           DEFAULT_MSG_PREFIX);
 
158
        cmd->default_settings.msg_prefix =
 
159
                find_config_tree_str_allow_empty(cmd, "log/prefix", DEFAULT_MSG_PREFIX);
 
160
 
159
161
        init_msg_prefix(cmd->default_settings.msg_prefix);
160
162
 
161
163
        cmd->default_settings.cmd_name = find_config_tree_int(cmd,
206
208
 * 856a6f1dbd8940e72755af145ebcd806408ecedd
207
209
 * some operations could not be performed by udev, requiring our fallback code.
208
210
 */
209
 
static int _dm_driver_has_stable_udev_support()
 
211
static int _dm_driver_has_stable_udev_support(void)
210
212
{
211
213
        char vsn[80];
212
214
        unsigned maj, min, patchlevel;
222
224
        mode_t old_umask;
223
225
        const char *read_ahead;
224
226
        struct stat st;
225
 
        const struct config_node *cn;
226
 
        const struct config_value *cv;
 
227
        const struct dm_config_node *cn;
 
228
        const struct dm_config_value *cv;
227
229
        int64_t pv_min_kb;
228
230
 
229
231
        /* umask */
245
247
        }
246
248
#ifdef DEVMAPPER_SUPPORT
247
249
        dm_set_dev_dir(cmd->dev_dir);
 
250
 
 
251
        if (!dm_set_uuid_prefix("LVM-"))
 
252
                return_0;
248
253
#endif
249
254
 
250
255
        /* proc dir */
264
269
        /* FIXME Use global value of sysfs_dir everywhere instead cmd->sysfs_dir. */
265
270
        _get_sysfs_dir(cmd);
266
271
        set_sysfs_dir_path(cmd->sysfs_dir);
 
272
        dm_set_sysfs_dir(cmd->sysfs_dir);
267
273
 
268
274
        /* activation? */
269
275
        cmd->default_settings.activation = find_config_tree_int(cmd,
302
308
                                                                "activation/udev_sync",
303
309
                                                                DEFAULT_UDEV_SYNC);
304
310
 
 
311
        init_retry_deactivation(find_config_tree_int(cmd, "activation/retry_deactivation",
 
312
                                                        DEFAULT_RETRY_DEACTIVATION));
 
313
 
305
314
        init_activation_checks(find_config_tree_int(cmd, "activation/checks",
306
315
                                                      DEFAULT_ACTIVATION_CHECKS));
307
316
 
328
337
        cmd->default_settings.udev_fallback = 1;
329
338
#endif
330
339
 
 
340
        cmd->use_linear_target = find_config_tree_int(cmd,
 
341
                                                      "activation/use_linear_target",
 
342
                                                       DEFAULT_USE_LINEAR_TARGET);
 
343
 
331
344
        cmd->stripe_filler = find_config_tree_str(cmd,
332
345
                                                  "activation/missing_stripe_filler",
333
346
                                                  DEFAULT_STRIPE_FILLER);
358
371
 
359
372
        if ((cn = find_config_tree_node(cmd, "activation/mlock_filter")))
360
373
                for (cv = cn->v; cv; cv = cv->next) 
361
 
                        if ((cv->type != CFG_STRING) || !cv->v.str[0]) 
 
374
                        if ((cv->type != DM_CFG_STRING) || !cv->v.str[0]) 
362
375
                                log_error("Ignoring invalid activation/mlock_filter entry in config file");
363
376
 
364
377
        cmd->metadata_read_only = find_config_tree_int(cmd, "global/metadata_read_only",
365
378
                                                       DEFAULT_METADATA_READ_ONLY);
366
379
 
367
380
        pv_min_kb = find_config_tree_int64(cmd, "devices/pv_min_size", DEFAULT_PV_MIN_SIZE_KB);
368
 
        if (pv_min_kb < DEFAULT_PV_MIN_SIZE_KB) {
 
381
        if (pv_min_kb < PV_MIN_SIZE_KB) {
369
382
                log_warn("Ignoring too small pv_min_size %" PRId64 "KB, using default %dKB.",
370
 
                         pv_min_kb, DEFAULT_PV_MIN_SIZE_KB);
371
 
                pv_min_kb = DEFAULT_PV_MIN_SIZE_KB;
 
383
                         pv_min_kb, PV_MIN_SIZE_KB);
 
384
                pv_min_kb = PV_MIN_SIZE_KB;
372
385
        }
373
386
        /* LVM stores sizes internally in units of 512-byte sectors. */
374
387
        init_pv_min_size((uint64_t)pv_min_kb * (1024 >> SECTOR_SHIFT));
377
390
                (find_config_tree_int(cmd, "global/detect_internal_vg_cache_corruption()",
378
391
                                      DEFAULT_DETECT_INTERNAL_VG_CACHE_CORRUPTION));
379
392
 
 
393
        lvmetad_set_active(find_config_tree_int(cmd, "global/use_lvmetad", 0));
 
394
 
380
395
        return 1;
381
396
}
382
397
 
392
407
        return 1;
393
408
}
394
409
 
395
 
static int _check_host_filters(struct cmd_context *cmd, const struct config_node *hn,
 
410
static int _check_host_filters(struct cmd_context *cmd, const struct dm_config_node *hn,
396
411
                               int *passes)
397
412
{
398
 
        const struct config_node *cn;
399
 
        const struct config_value *cv;
 
413
        const struct dm_config_node *cn;
 
414
        const struct dm_config_value *cv;
400
415
 
401
416
        *passes = 1;
402
417
 
405
420
                        continue;
406
421
                if (!strcmp(cn->key, "host_list")) {
407
422
                        *passes = 0;
408
 
                        if (cn->v->type == CFG_EMPTY_ARRAY)
 
423
                        if (cn->v->type == DM_CFG_EMPTY_ARRAY)
409
424
                                continue;
410
425
                        for (cv = cn->v; cv; cv = cv->next) {
411
 
                                if (cv->type != CFG_STRING) {
 
426
                                if (cv->type != DM_CFG_STRING) {
412
427
                                        log_error("Invalid hostname string "
413
428
                                                  "for tag %s", cn->key);
414
429
                                        return 0;
428
443
        return 1;
429
444
}
430
445
 
431
 
static int _init_tags(struct cmd_context *cmd, struct config_tree *cft)
 
446
static int _init_tags(struct cmd_context *cmd, struct dm_config_tree *cft)
432
447
{
433
 
        const struct config_node *tn, *cn;
 
448
        const struct dm_config_node *tn, *cn;
434
449
        const char *tag;
435
450
        int passes;
436
451
 
437
 
        if (!(tn = find_config_node(cft->root, "tags")) || !tn->child)
 
452
        if (!(tn = dm_config_find_node(cft->root, "tags")) || !tn->child)
438
453
                return 1;
439
454
 
440
455
        /* NB hosttags 0 when already 1 intentionally does not delete the tag */
441
 
        if (!cmd->hosttags && find_config_int(cft->root, "tags/hosttags",
 
456
        if (!cmd->hosttags && dm_config_find_int(cft->root, "tags/hosttags",
442
457
                                              DEFAULT_HOSTTAGS)) {
443
458
                /* FIXME Strip out invalid chars: only A-Za-z0-9_+.- */
444
459
                if (!_set_tag(cmd, cmd->hostname))
472
487
 
473
488
static int _load_config_file(struct cmd_context *cmd, const char *tag)
474
489
{
475
 
        char config_file[PATH_MAX] = "";
 
490
        static char config_file[PATH_MAX] = "";
476
491
        const char *filler = "";
477
492
        struct stat info;
478
493
        struct config_tree_list *cfl;
491
506
                return 0;
492
507
        }
493
508
 
494
 
        if (!(cfl->cft = create_config_tree(config_file, 0))) {
 
509
        if (!(cfl->cft = config_file_open(config_file, 0))) {
495
510
                log_error("config_tree allocation failed");
496
511
                return 0;
497
512
        }
503
518
                        goto out;
504
519
                }
505
520
                log_sys_error("stat", config_file);
506
 
                destroy_config_tree(cfl->cft);
 
521
                config_file_destroy(cfl->cft);
507
522
                return 0;
508
523
        }
509
524
 
510
525
        log_very_verbose("Loading config file: %s", config_file);
511
 
        if (!read_config_file(cfl->cft)) {
 
526
        if (!config_file_read(cfl->cft)) {
512
527
                log_error("Failed to load config file %s", config_file);
513
 
                destroy_config_tree(cfl->cft);
 
528
                config_file_destroy(cfl->cft);
514
529
                return 0;
515
530
        }
516
531
 
517
532
        dm_list_add(&cmd->config_files, &cfl->list);
518
533
 
519
534
      out:
520
 
        if (*tag)
521
 
                _init_tags(cmd, cfl->cft);
522
 
        else
 
535
        if (*tag) {
 
536
                if (!_init_tags(cmd, cfl->cft))
 
537
                        return_0;
 
538
        } else
523
539
                /* Use temporary copy of lvm.conf while loading other files */
524
540
                cmd->cft = cfl->cft;
525
541
 
531
547
{
532
548
        /* No config file if LVM_SYSTEM_DIR is empty */
533
549
        if (!*cmd->system_dir) {
534
 
                if (!(cmd->cft = create_config_tree(NULL, 0))) {
 
550
                if (!(cmd->cft = config_file_open(NULL, 0))) {
535
551
                        log_error("Failed to create config tree");
536
552
                        return 0;
537
553
                }
558
574
        return 1;
559
575
}
560
576
 
561
 
static int _merge_config_files(struct cmd_context *cmd)
 
577
static struct dm_config_tree *_merge_config_files(struct cmd_context *cmd, struct dm_config_tree *cft)
562
578
{
563
579
        struct config_tree_list *cfl;
564
580
 
565
581
        /* Replace temporary duplicate copy of lvm.conf */
566
 
        if (cmd->cft->root) {
567
 
                if (!(cmd->cft = create_config_tree(NULL, 0))) {
 
582
        if (cft->root) {
 
583
                if (!(cft = config_file_open(NULL, 0))) {
568
584
                        log_error("Failed to create config tree");
569
585
                        return 0;
570
586
                }
572
588
 
573
589
        dm_list_iterate_items(cfl, &cmd->config_files) {
574
590
                /* Merge all config trees into cmd->cft using merge/tag rules */
575
 
                if (!merge_config_tree(cmd, cmd->cft, cfl->cft))
 
591
                if (!merge_config_tree(cmd, cft, cfl->cft))
576
592
                        return_0;
577
593
        }
578
594
 
579
 
        return 1;
 
595
        return cft;
580
596
}
581
597
 
582
598
static void _destroy_tags(struct cmd_context *cmd)
600
616
        return 0;
601
617
}
602
618
 
603
 
static void _destroy_tag_configs(struct cmd_context *cmd)
 
619
/*
 
620
 * Returns cmdline config_tree that overrides all others, if present.
 
621
 */
 
622
static struct dm_config_tree *_destroy_tag_configs(struct cmd_context *cmd)
604
623
{
605
624
        struct config_tree_list *cfl;
 
625
        struct dm_config_tree *cft_cmdline = NULL, *cft;
 
626
 
 
627
        cft = dm_config_remove_cascaded_tree(cmd->cft);
 
628
        if (cft) {
 
629
                cft_cmdline = cmd->cft;
 
630
                cmd->cft = cft;
 
631
        }
606
632
 
607
633
        dm_list_iterate_items(cfl, &cmd->config_files) {
608
634
                if (cfl->cft == cmd->cft)
609
635
                        cmd->cft = NULL;
610
 
                destroy_config_tree(cfl->cft);
 
636
                config_file_destroy(cfl->cft);
611
637
        }
612
638
 
613
639
        if (cmd->cft) {
614
 
                destroy_config_tree(cmd->cft);
 
640
                config_file_destroy(cmd->cft);
615
641
                cmd->cft = NULL;
616
642
        }
617
643
 
618
644
        dm_list_init(&cmd->config_files);
 
645
 
 
646
        return cft_cmdline;
619
647
}
620
648
 
621
649
static int _init_dev_cache(struct cmd_context *cmd)
622
650
{
623
 
        const struct config_node *cn;
624
 
        const struct config_value *cv;
 
651
        const struct dm_config_node *cn;
 
652
        const struct dm_config_value *cv;
625
653
        size_t uninitialized_var(udev_dir_len), len;
626
654
        int device_list_from_udev;
627
655
        const char *uninitialized_var(udev_dir);
636
664
        if ((device_list_from_udev = udev_is_running() ?
637
665
                find_config_tree_bool(cmd, "devices/obtain_device_list_from_udev",
638
666
                                      DEFAULT_OBTAIN_DEVICE_LIST_FROM_UDEV) : 0)) {
639
 
                udev_dir = udev_get_dev_dir();
640
 
                udev_dir_len = strlen(udev_dir);
 
667
                if (!(udev_dir = udev_get_dev_dir()))
 
668
                        stack;
 
669
                udev_dir_len = (udev_dir) ? strlen(udev_dir) : 0;
641
670
        }
642
671
        init_obtain_device_list_from_udev(device_list_from_udev);
643
672
 
653
682
        }
654
683
 
655
684
        for (cv = cn->v; cv; cv = cv->next) {
656
 
                if (cv->type != CFG_STRING) {
 
685
                if (cv->type != DM_CFG_STRING) {
657
686
                        log_error("Invalid string in config file: "
658
687
                                  "devices/scan");
659
688
                        return 0;
660
689
                }
661
690
 
662
 
                if (device_list_from_udev) {
 
691
                if (device_list_from_udev && udev_dir) {
663
692
                        len = strlen(cv->v.str);
664
693
                        len = udev_dir_len > len ? len : udev_dir_len;
665
694
                        if (strncmp(udev_dir, cv->v.str, len) ||
680
709
                return 1;
681
710
 
682
711
        for (cv = cn->v; cv; cv = cv->next) {
683
 
                if (cv->type != CFG_STRING) {
 
712
                if (cv->type != DM_CFG_STRING) {
684
713
                        log_error("Invalid string in config file: "
685
714
                                  "devices/loopfiles");
686
715
                        return 0;
697
726
        return 1;
698
727
}
699
728
 
700
 
#define MAX_FILTERS 4
 
729
#define MAX_FILTERS 5
701
730
 
702
731
static struct dev_filter *_init_filter_components(struct cmd_context *cmd)
703
732
{
704
733
        unsigned nr_filt = 0;
705
 
        const struct config_node *cn;
 
734
        const struct dm_config_node *cn;
706
735
        struct dev_filter *filters[MAX_FILTERS];
 
736
        struct dev_filter *composite;
707
737
 
708
738
        memset(filters, 0, sizeof(filters));
709
739
 
749
779
                        nr_filt++;
750
780
        }
751
781
 
 
782
        /* mpath component filter. Optional, non-critical. */
 
783
        if (find_config_tree_bool(cmd, "devices/multipath_component_detection",
 
784
                             DEFAULT_MULTIPATH_COMPONENT_DETECTION)) {
 
785
                if ((filters[nr_filt] = mpath_filter_create(cmd->sysfs_dir)))
 
786
                        nr_filt++;
 
787
        }
 
788
 
752
789
        /* Only build a composite filter if we really need it. */
753
 
        return (nr_filt == 1) ?
754
 
            filters[0] : composite_filter_create(nr_filt, filters);
 
790
        if (nr_filt == 1)
 
791
                return filters[0];
 
792
 
 
793
        if (!(composite = composite_filter_create(nr_filt, filters))) {
 
794
                stack;
 
795
                nr_filt++; /* compensate skip NULL */
 
796
                goto err;
 
797
        }
 
798
 
 
799
        return composite;
755
800
err:
756
801
        nr_filt--; /* skip NULL */
757
802
        while (nr_filt-- > 0)
761
806
 
762
807
static int _init_filters(struct cmd_context *cmd, unsigned load_persistent_cache)
763
808
{
 
809
        static char cache_file[PATH_MAX];
764
810
        const char *dev_cache = NULL, *cache_dir, *cache_file_prefix;
765
811
        struct dev_filter *f3, *f4;
766
812
        struct stat st;
767
 
        char cache_file[PATH_MAX];
768
813
 
769
814
        cmd->dump_filter = 0;
770
815
 
771
816
        if (!(f3 = _init_filter_components(cmd)))
772
 
                return 0;
 
817
                return_0;
773
818
 
774
819
        init_ignore_suspended_devices(find_config_tree_int(cmd,
775
820
            "devices/ignore_suspended_devices", DEFAULT_IGNORE_SUSPENDED_DEVICES));
851
896
        struct format_type *fmt;
852
897
 
853
898
#ifdef HAVE_LIBDL
854
 
        const struct config_node *cn;
 
899
        const struct dm_config_node *cn;
855
900
#endif
856
901
 
857
 
        label_init();
858
 
 
859
902
#ifdef LVM1_INTERNAL
860
903
        if (!(fmt = init_lvm1_format(cmd)))
861
904
                return 0;
875
918
        if (!is_static() &&
876
919
            (cn = find_config_tree_node(cmd, "global/format_libraries"))) {
877
920
 
878
 
                const struct config_value *cv;
 
921
                const struct dm_config_value *cv;
879
922
                struct format_type *(*init_format_fn) (struct cmd_context *);
880
923
                void *lib;
881
924
 
882
925
                for (cv = cn->v; cv; cv = cv->next) {
883
 
                        if (cv->type != CFG_STRING) {
 
926
                        if (cv->type != DM_CFG_STRING) {
884
927
                                log_error("Invalid string in config file: "
885
928
                                          "global/format_libraries");
886
929
                                return 0;
992
1035
{
993
1036
        int i;
994
1037
        struct segment_type *segtype;
995
 
        struct segtype_library seglib = { .cmd = cmd };
 
1038
        struct segtype_library seglib = { .cmd = cmd, .lib = NULL };
996
1039
        struct segment_type *(*init_segtype_array[])(struct cmd_context *cmd) = {
997
1040
                init_striped_segtype,
998
1041
                init_zero_segtype,
999
1042
                init_error_segtype,
1000
1043
                init_free_segtype,
1001
 
#ifdef RAID_INTERNAL
1002
 
                init_raid1_segtype,
1003
 
                init_raid4_segtype,
1004
 
                init_raid5_segtype,
1005
 
                init_raid5_la_segtype,
1006
 
                init_raid5_ra_segtype,
1007
 
                init_raid5_ls_segtype,
1008
 
                init_raid5_rs_segtype,
1009
 
                init_raid6_segtype,
1010
 
                init_raid6_zr_segtype,
1011
 
                init_raid6_nr_segtype,
1012
 
                init_raid6_nc_segtype,
 
1044
#ifdef SNAPSHOT_INTERNAL
 
1045
                init_snapshot_segtype,
 
1046
#endif
 
1047
#ifdef MIRRORED_INTERNAL
 
1048
                init_mirrored_segtype,
1013
1049
#endif
1014
1050
                NULL
1015
1051
        };
1016
1052
 
1017
1053
#ifdef HAVE_LIBDL
1018
 
        const struct config_node *cn;
 
1054
        const struct dm_config_node *cn;
1019
1055
#endif
1020
1056
 
1021
1057
        for (i = 0; init_segtype_array[i]; i++) {
1025
1061
                dm_list_add(&cmd->segtypes, &segtype->list);
1026
1062
        }
1027
1063
 
1028
 
#ifdef SNAPSHOT_INTERNAL
1029
 
        if (!(segtype = init_snapshot_segtype(cmd)))
1030
 
                return 0;
1031
 
        segtype->library = NULL;
1032
 
        dm_list_add(&cmd->segtypes, &segtype->list);
1033
 
#endif
1034
 
 
1035
 
#ifdef MIRRORED_INTERNAL
1036
 
        if (!(segtype = init_mirrored_segtype(cmd)))
1037
 
                return 0;
1038
 
        segtype->library = NULL;
1039
 
        dm_list_add(&cmd->segtypes, &segtype->list);
1040
 
#endif
1041
 
 
1042
1064
#ifdef REPLICATOR_INTERNAL
1043
 
        if (!init_replicator_segtype(&seglib))
 
1065
        if (!init_replicator_segtype(cmd, &seglib))
 
1066
                return 0;
 
1067
#endif
 
1068
 
 
1069
#ifdef RAID_INTERNAL
 
1070
        if (!init_raid_segtypes(cmd, &seglib))
 
1071
                return 0;
 
1072
#endif
 
1073
 
 
1074
#ifdef THIN_INTERNAL
 
1075
        if (!init_thin_segtypes(cmd, &seglib))
1044
1076
                return 0;
1045
1077
#endif
1046
1078
 
1049
1081
        if (!is_static() &&
1050
1082
            (cn = find_config_tree_node(cmd, "global/segment_libraries"))) {
1051
1083
 
1052
 
                const struct config_value *cv;
 
1084
                const struct dm_config_value *cv;
1053
1085
                int (*init_multiple_segtypes_fn) (struct cmd_context *,
1054
1086
                                                  struct segtype_library *);
1055
1087
 
1056
1088
                for (cv = cn->v; cv; cv = cv->next) {
1057
 
                        if (cv->type != CFG_STRING) {
 
1089
                        if (cv->type != DM_CFG_STRING) {
1058
1090
                                log_error("Invalid string in config file: "
1059
1091
                                          "global/segment_libraries");
1060
1092
                                return 0;
1122
1154
 
1123
1155
static int _init_backup(struct cmd_context *cmd)
1124
1156
{
 
1157
        static char default_dir[PATH_MAX];
1125
1158
        uint32_t days, min;
1126
 
        char default_dir[PATH_MAX];
1127
1159
        const char *dir;
1128
1160
 
1129
1161
        if (!cmd->system_dir[0]) {
1204
1236
/* Entry point */
1205
1237
struct cmd_context *create_toolcontext(unsigned is_long_lived,
1206
1238
                                       const char *system_dir,
1207
 
                                       unsigned set_buffering)
 
1239
                                       unsigned set_buffering,
 
1240
                                       unsigned threaded)
1208
1241
{
1209
1242
        struct cmd_context *cmd;
1210
1243
 
1226
1259
                return NULL;
1227
1260
        }
1228
1261
        cmd->is_long_lived = is_long_lived;
 
1262
        cmd->threaded = threaded ? 1 : 0;
1229
1263
        cmd->handles_missing_pvs = 0;
1230
1264
        cmd->handles_unknown_segments = 0;
1231
1265
        cmd->independent_metadata_areas = 0;
1235
1269
        dm_list_init(&cmd->segtypes);
1236
1270
        dm_list_init(&cmd->tags);
1237
1271
        dm_list_init(&cmd->config_files);
 
1272
        label_init();
1238
1273
 
1239
1274
        /* FIXME Make this configurable? */
1240
1275
        reset_lvm_errno(1);
1294
1329
        if (!_init_tag_configs(cmd))
1295
1330
                goto_out;
1296
1331
 
1297
 
        if (!_merge_config_files(cmd))
 
1332
        if (!(cmd->cft = _merge_config_files(cmd, cmd->cft)))
1298
1333
                goto_out;
1299
1334
 
1300
1335
        if (!_process_config(cmd))
1394
1429
                cmd->filter = NULL;
1395
1430
        }
1396
1431
 
1397
 
        r = _init_filters(cmd, 0);
 
1432
        if (!(r = _init_filters(cmd, 0)))
 
1433
                stack;
1398
1434
 
1399
1435
        /*
1400
1436
         * During repair code must not reset suspended flag.
1406
1442
 
1407
1443
int refresh_toolcontext(struct cmd_context *cmd)
1408
1444
{
 
1445
        struct dm_config_tree *cft_cmdline, *cft_tmp;
 
1446
 
1409
1447
        log_verbose("Reloading config files");
1410
1448
 
1411
1449
        /*
1424
1462
        }
1425
1463
        dev_cache_exit();
1426
1464
        _destroy_tags(cmd);
1427
 
        _destroy_tag_configs(cmd);
 
1465
 
 
1466
        cft_cmdline = _destroy_tag_configs(cmd);
1428
1467
 
1429
1468
        cmd->config_valid = 0;
1430
1469
 
1433
1472
        if (!_init_lvm_conf(cmd))
1434
1473
                return 0;
1435
1474
 
 
1475
        /* Temporary duplicate cft pointer holding lvm.conf - replaced later */
 
1476
        cft_tmp = cmd->cft;
 
1477
        if (cft_cmdline)
 
1478
                cmd->cft = dm_config_insert_cascaded_tree(cft_cmdline, cft_tmp);
 
1479
 
 
1480
        /* Uses cmd->cft i.e. cft_cmdline + lvm.conf */
1436
1481
        _init_logging(cmd);
1437
1482
 
1438
 
        if (!_init_tags(cmd, cmd->cft))
 
1483
        /* Init tags from lvm.conf. */
 
1484
        if (!_init_tags(cmd, cft_tmp))
1439
1485
                return 0;
1440
1486
 
 
1487
        /* Doesn't change cmd->cft */
1441
1488
        if (!_init_tag_configs(cmd))
1442
1489
                return 0;
1443
1490
 
1444
 
        if (!_merge_config_files(cmd))
 
1491
        /* Merge all the tag config files with lvm.conf, returning a
 
1492
         * fresh cft pointer in place of cft_tmp. */
 
1493
        if (!(cmd->cft = _merge_config_files(cmd, cft_tmp)))
1445
1494
                return 0;
1446
1495
 
 
1496
        /* Finally we can make the proper, fully-merged, cmd->cft */
 
1497
        if (cft_cmdline)
 
1498
                cmd->cft = dm_config_insert_cascaded_tree(cft_cmdline, cmd->cft);
 
1499
 
1447
1500
        if (!_process_config(cmd))
1448
1501
                return 0;
1449
1502
 
1473
1526
 
1474
1527
void destroy_toolcontext(struct cmd_context *cmd)
1475
1528
{
 
1529
        struct dm_config_tree *cft_cmdline;
 
1530
 
1476
1531
        if (cmd->dump_filter)
1477
1532
                persistent_filter_dump(cmd->filter, 1);
1478
1533
 
1488
1543
                dm_pool_destroy(cmd->mem);
1489
1544
        dev_cache_exit();
1490
1545
        _destroy_tags(cmd);
1491
 
        _destroy_tag_configs(cmd);
 
1546
 
 
1547
        if ((cft_cmdline = _destroy_tag_configs(cmd)))
 
1548
                dm_config_destroy(cft_cmdline);
1492
1549
        if (cmd->libmem)
1493
1550
                dm_pool_destroy(cmd->libmem);
1494
1551