4 # Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 """Utility functions for LVM.
25 from ganeti import constants
28 def CheckVolumeGroupSize(vglist, vgname, minsize):
29 """Checks if the volume group list is valid.
31 The function will check if a given volume group is in the list of
32 volume groups and has a minimum size.
35 @param vglist: dictionary of volume group names and their size
37 @param vgname: the volume group we should check
39 @param minsize: the minimum size we accept
41 @return: None for success, otherwise the error message
44 vgsize = vglist.get(vgname, None)
46 return "volume group '%s' missing" % vgname
47 elif vgsize < minsize:
48 return ("volume group '%s' too small (%s MiB required, %d MiB found)" %
49 (vgname, minsize, vgsize))
53 def LvmExclusiveCheckNodePvs(pvs_info):
54 """Check consistency of PV sizes in a node for exclusive storage.
57 @param pvs_info: list of L{LvmPvInfo} objects
59 @return: A pair composed of: 1. a list of error strings describing the
60 violations found, or an empty list if everything is ok; 2. a pair
61 containing the sizes of the smallest and biggest PVs, in MiB.
65 sizes = [pv.size for pv in pvs_info]
66 # The sizes of PVs must be the same (tolerance is constants.PART_MARGIN)
69 if LvmExclusiveTestBadPvSizes(small, big):
70 m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))
72 return (errmsgs, (small, big))
75 def LvmExclusiveTestBadPvSizes(small, big):
76 """Test if the given PV sizes are permitted with exclusive storage.
78 @param small: size of the smallest PV
79 @param big: size of the biggest PV
80 @return: True when the given sizes are bad, False otherwise
82 # Test whether no X exists such that:
83 # small >= X * (1 - constants.PART_MARGIN) and
84 # big <= X * (1 + constants.PART_MARGIN)
85 return (small * (1 + constants.PART_MARGIN) <
86 big * (1 - constants.PART_MARGIN))