Statistics
| Branch: | Tag: | Revision:

root / lib / utils / lvm.py @ 364c350f

History | View | Annotate | Download (2.8 kB)

1
#
2
#
3

    
4
# Copyright (C) 2006, 2007, 2010, 2011, 2012 Google Inc.
5
#
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.
10
#
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.
15
#
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
19
# 02110-1301, USA.
20

    
21
"""Utility functions for LVM.
22

23
"""
24

    
25
from ganeti import constants
26

    
27

    
28
def CheckVolumeGroupSize(vglist, vgname, minsize):
29
  """Checks if the volume group list is valid.
30

31
  The function will check if a given volume group is in the list of
32
  volume groups and has a minimum size.
33

34
  @type vglist: dict
35
  @param vglist: dictionary of volume group names and their size
36
  @type vgname: str
37
  @param vgname: the volume group we should check
38
  @type minsize: int
39
  @param minsize: the minimum size we accept
40
  @rtype: None or str
41
  @return: None for success, otherwise the error message
42

43
  """
44
  vgsize = vglist.get(vgname, None)
45
  if vgsize is 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))
50
  return None
51

    
52

    
53
def LvmExclusiveCheckNodePvs(pvs_info):
54
  """Check consistency of PV sizes in a node for exclusive storage.
55

56
  @type pvs_info: list
57
  @param pvs_info: list of L{LvmPvInfo} objects
58
  @rtype: tuple
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.
62

63
  """
64
  errmsgs = []
65
  sizes = [pv.size for pv in pvs_info]
66
  # The sizes of PVs must be the same (tolerance is constants.PART_MARGIN)
67
  small = min(sizes)
68
  big = max(sizes)
69
  if LvmExclusiveTestBadPvSizes(small, big):
70
    m = ("Sizes of PVs are too different: min=%d max=%d" % (small, big))
71
    errmsgs.append(m)
72
  return (errmsgs, (small, big))
73

    
74

    
75
def LvmExclusiveTestBadPvSizes(small, big):
76
  """Test if the given PV sizes are permitted with exclusive storage.
77

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
81
  """
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))