1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 """Utility functions for LVM.
31
32 """
33
34 from ganeti import constants
35
36
38 """Checks if the volume group list is valid.
39
40 The function will check if a given volume group is in the list of
41 volume groups and has a minimum size.
42
43 @type vglist: dict
44 @param vglist: dictionary of volume group names and their size
45 @type vgname: str
46 @param vgname: the volume group we should check
47 @type minsize: int
48 @param minsize: the minimum size we accept
49 @rtype: None or str
50 @return: None for success, otherwise the error message
51
52 """
53 vgsize = vglist.get(vgname, None)
54 if vgsize is None:
55 return "volume group '%s' missing" % vgname
56 elif vgsize < minsize:
57 return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
58 (vgname, minsize, vgsize))
59 return None
60
61
63 """Check consistency of PV sizes in a node for exclusive storage.
64
65 @type pvs_info: list
66 @param pvs_info: list of L{LvmPvInfo} objects
67 @rtype: tuple
68 @return: A pair composed of: 1. a list of error strings describing the
69 violations found, or an empty list if everything is ok; 2. a pair
70 containing the sizes of the smallest and biggest PVs, in MiB.
71
72 """
73 errmsgs = []
74 sizes = [pv.size for pv in pvs_info]
75
76 small = min(sizes)
77 big = max(sizes)
78 if LvmExclusiveTestBadPvSizes(small, big):
79 m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))
80 errmsgs.append(m)
81 return (errmsgs, (small, big))
82
83
85 """Test if the given PV sizes are permitted with exclusive storage.
86
87 @param small: size of the smallest PV
88 @param big: size of the biggest PV
89 @return: True when the given sizes are bad, False otherwise
90 """
91
92
93
94 return (small * (1 + constants.PART_MARGIN) <
95 big * (1 - constants.PART_MARGIN))
96