xref: /netbsd/external/gpl2/lvm2/dist/doc/tagging.txt (revision 56a34939)
1*56a34939ShaadTagging aims
2*56a34939Shaad============
3*56a34939Shaad  1) Ability to attach an unordered list of tags to LVM metadata objects.
4*56a34939Shaad  2) Ability to add or remove tags easily.
5*56a34939Shaad  3) Ability to select LVM objects for processing according to presence/absence
6*56a34939Shaad     of specific tags.
7*56a34939Shaad  4) Ability to control through the config file which VGs/LVs are activated
8*56a34939Shaad     on different machines using names or tags.
9*56a34939Shaad  5) Ability to overlay settings from different config files e.g. override
10*56a34939Shaad     some settings in a global config file locally.
11*56a34939Shaad
12*56a34939ShaadClarifications
13*56a34939Shaad==============
14*56a34939Shaad  1) Tag character set: A-Za-z0-9_+.-
15*56a34939Shaad     Can't start with hyphen & max length is 128 (NAME_LEN).
16*56a34939Shaad  2) LVM object types that can be tagged:
17*56a34939Shaad       VG, LV, LV segment
18*56a34939Shaad       PV - tags are stored in VG metadata so disappear when PV becomes orphaned
19*56a34939Shaad     Snapshots can't be tagged, but their origin may be.
20*56a34939Shaad  3) A tag can be used in place of any command line LVM object reference that
21*56a34939Shaad     accepts (a) a list of objects; or (b) a single object as long as the
22*56a34939Shaad     tag expands to a single object.  This is not supported everywhere yet.
23*56a34939Shaad     Duplicate arguments in a list after argument expansion may get removed
24*56a34939Shaad     retaining the first copy of each argument.
25*56a34939Shaad  4) Wherever there may be ambiguity of argument type, a tag must be prefixed
26*56a34939Shaad     by '@'; elsewhere an '@' prefix is optional.
27*56a34939Shaad  5) LVM1 objects cannot be tagged, as the disk format doesn't support it.
28*56a34939Shaad  6) Tags can be added or removed with --addtag or --deltag.
29*56a34939Shaad
30*56a34939ShaadConfig file Extensions
31*56a34939Shaad======================
32*56a34939Shaad  To define host tags in config file:
33*56a34939Shaad
34*56a34939Shaad  tags {
35*56a34939Shaad  	# Set a tag with the hostname
36*56a34939Shaad	hosttags = 1
37*56a34939Shaad
38*56a34939Shaad	tag1 { }
39*56a34939Shaad
40*56a34939Shaad  	tag2 {
41*56a34939Shaad		# If no exact match, tag is not set.
42*56a34939Shaad		host_list = [ "hostname", "dbase" ]
43*56a34939Shaad	}
44*56a34939Shaad  }
45*56a34939Shaad
46*56a34939ShaadActivation config file example
47*56a34939Shaad==============================
48*56a34939Shaad  activation {
49*56a34939Shaad      volume_list = [ "vg1/lvol0", "@database" ]
50*56a34939Shaad  }
51*56a34939Shaad
52*56a34939Shaad  Matches against vgname, vgname/lvname or @tag set in *metadata*.
53*56a34939Shaad  @* matches exactly against *any* tag set on the host.
54*56a34939Shaad  The VG or LV only gets activated if a metadata tag matches.
55*56a34939Shaad  The default if there is no match is not to activate.
56*56a34939Shaad  If volume_list is not present and any tags are defined on the host
57*56a34939Shaad  then it only activates if a host tag matches a metadata tag.
58*56a34939Shaad  If volume_list is not present and no tags are defined on the host
59*56a34939Shaad  then it does activate.
60*56a34939Shaad
61*56a34939ShaadMultiple config files
62*56a34939Shaad=====================
63*56a34939Shaad  (a) lvm.conf
64*56a34939Shaad  (b) lvm_<host_tag>.conf
65*56a34939Shaad
66*56a34939Shaad  At startup, load lvm.conf.
67*56a34939Shaad  Process tag settings.
68*56a34939Shaad  If any host tags were defined, load lvm_tag.conf for each tag, if present.
69*56a34939Shaad
70*56a34939Shaad  When searching for a specific config file entry, search order is (b)
71*56a34939Shaad  then (a), stopping at the first match.
72*56a34939Shaad  Within (b) use reverse order tags got set, so file for last tag set is
73*56a34939Shaad  searched first.
74*56a34939Shaad  New tags set in (b) *do* trigger additional config file loads.
75*56a34939Shaad
76*56a34939ShaadUsage Examples
77*56a34939Shaad==============
78*56a34939Shaad  1) Simple activation control via metadata with static config files
79*56a34939Shaad
80*56a34939Shaad  lvm.conf:  (Identical on every machine - global settings)
81*56a34939Shaad    tags {
82*56a34939Shaad      hostname_tags = 1
83*56a34939Shaad    }
84*56a34939Shaad
85*56a34939Shaad  From any machine in the cluster, add db1 to the list of machines that
86*56a34939Shaad  activate vg1/lvol2:
87*56a34939Shaad
88*56a34939Shaad  lvchange --tag @db1 vg1/lvol2
89*56a34939Shaad  (followed by lvchange -ay to actually activate it)
90*56a34939Shaad
91*56a34939Shaad
92*56a34939Shaad  2) Multiple hosts.
93*56a34939Shaad
94*56a34939Shaad    Activate vg1 only on the database hosts, db1 and db2.
95*56a34939Shaad    Activate vg2 only on the fileserver host fs1.
96*56a34939Shaad    Activate nothing initially on the fileserver backup host fsb1, but be
97*56a34939Shaad    prepared for it to take over from fs1.
98*56a34939Shaad
99*56a34939Shaad  Option (i) - centralised admin, static configuration replicated between hosts
100*56a34939Shaad    # Add @database tag to vg1's metadata
101*56a34939Shaad    vgchange --tag @database vg1
102*56a34939Shaad
103*56a34939Shaad    # Add @fileserver tag to vg2's metadata
104*56a34939Shaad    vgchange --tag @fileserver vg2
105*56a34939Shaad
106*56a34939Shaad    lvm.conf:  (Identical on every machine)
107*56a34939Shaad      tags {
108*56a34939Shaad        database {
109*56a34939Shaad          host_list = [ "db1", "db2" ]
110*56a34939Shaad        }
111*56a34939Shaad        fileserver {
112*56a34939Shaad	  host_list = [ "fs1" ]
113*56a34939Shaad        }
114*56a34939Shaad        fileserverbackup {
115*56a34939Shaad          host_list = [ "fsb1" ]
116*56a34939Shaad        }
117*56a34939Shaad      }
118*56a34939Shaad
119*56a34939Shaad      activation {
120*56a34939Shaad        # Only activate if host has a tag that matches a metadata tag
121*56a34939Shaad        volume_list = [ "@*" ]
122*56a34939Shaad      }
123*56a34939Shaad
124*56a34939Shaad  In the event of the fileserver host going down, vg2 can be brought up
125*56a34939Shaad  on fsb1 by running *on any node* 'vgchange --tag @fileserverbackup vg2'
126*56a34939Shaad  followed by 'vgchange -ay vg2'
127*56a34939Shaad
128*56a34939Shaad
129*56a34939Shaad  Option (ii) - localised admin & configuation
130*56a34939Shaad  (i.e. each host holds *locally* which classes of volumes to activate)
131*56a34939Shaad    # Add @database tag to vg1's metadata
132*56a34939Shaad    vgchange --tag @database vg1
133*56a34939Shaad
134*56a34939Shaad    # Add @fileserver tag to vg2's metadata
135*56a34939Shaad    vgchange --tag @fileserver vg2
136*56a34939Shaad
137*56a34939Shaad    lvm.conf:  (Identical on every machine - global settings)
138*56a34939Shaad      tags {
139*56a34939Shaad        hosttags = 1
140*56a34939Shaad      }
141*56a34939Shaad
142*56a34939Shaad    lvm_db1.conf: (only needs to be on db1 - could be symlink to lvm_db.conf)
143*56a34939Shaad      activation {
144*56a34939Shaad        volume_list = [ "@database" ]
145*56a34939Shaad      }
146*56a34939Shaad
147*56a34939Shaad    lvm_db2.conf: (only needs to be on db2 - could be symlink to lvm_db.conf)
148*56a34939Shaad      activation {
149*56a34939Shaad        volume_list = [ "@database" ]
150*56a34939Shaad      }
151*56a34939Shaad
152*56a34939Shaad    lvm_fs1.conf: (only needs to be on fs1 - could be symlink to lvm_fs.conf)
153*56a34939Shaad      activation {
154*56a34939Shaad        volume_list = [ "@fileserver" ]
155*56a34939Shaad      }
156*56a34939Shaad
157*56a34939Shaad    If fileserver goes down, to bring a spare machine fsb1 in as fileserver,
158*56a34939Shaad    create lvm_fsb1.conf on fsb1 (or symlink to lvm_fs.conf):
159*56a34939Shaad
160*56a34939Shaad      activation {
161*56a34939Shaad        volume_list = [ "@fileserver" ]
162*56a34939Shaad      }
163*56a34939Shaad
164*56a34939Shaad    and run 'vgchange -ay vg2' or 'vgchange -ay @fileserver'
165*56a34939Shaad
166