]>
git.ipfire.org Git - people/ms/ipfire-3.x.git/blob - pkgs/core/pomona/src/storage/devicelibs/lvm.py
20fa02ac2559c7eceb13906d7109f2e3c6f73178
12 for path
in os
.environ
["PATH"].split(":"):
13 if os
.access("%s/lvm" % path
, os
.X_OK
):
19 for line
in open("/proc/devices").readlines():
20 if "device-mapper" in line
.split():
26 # Start config_args handling code
28 # Theoretically we can handle all that can be handled with the LVM --config
29 # argument. For every time we call an lvm_cc (lvm compose config) funciton
30 # we regenerate the config_args with all global info.
31 config_args
= [] # Holds the final argument list
32 config_args_data
= { "filterRejects": [], # regular expressions to reject.
33 "filterAccepts": [] } # regexp to accept
36 """lvm command accepts lvm.conf type arguments preceded by --config. """
37 global config_args
, config_args_data
41 rejects
= config_args_data
["filterRejects"]
42 # we don't need the accept for now.
43 # accepts = config_args_data["filterAccepts"]
44 # if len(accepts) > 0:
45 # for i in range(len(rejects)):
46 # filter_string = filter_string + ("\"a|%s|\", " % accpets[i])
49 for i
in range(len(rejects
)):
50 filter_string
= filter_string
+ ("\"r|%s|\"," % rejects
[i
])
52 filter_string
= " filter=[%s] " % filter_string
.strip(",")
54 # As we add config strings we should check them all.
55 if filter_string
== "":
56 # Nothing was really done.
59 # devices_string can have (inside the brackets) "dir", "scan",
60 # "preferred_names", "filter", "cache_dir", "write_cache_state",
61 # "types", "sysfs_scan", "md_component_detection". see man lvm.conf.
62 devices_string
= " devices {%s} " % (filter_string
) # strings can be added
63 config_string
= devices_string
# more strings can be added.
64 config_args
= ["--config", config_string
]
66 def lvm_cc_addFilterRejectRegexp(regexp
):
67 """ Add a regular expression to the --config string."""
68 global config_args_data
69 config_args_data
["filterRejects"].append(regexp
)
71 # compoes config once more.
74 def lvm_cc_resetFilter():
75 global config_args_data
76 config_args_data
["filterRejects"] = []
77 config_args_data
["filterAccepts"] = []
78 # End config_args handling code.
80 # Names that should not be used int the creation of VGs
82 def blacklistVG(name
):
83 global lvm_vg_blacklist
84 lvm_vg_blacklist
.append(name
)
86 def getPossiblePhysicalExtents(floor
=0):
87 """Returns a list of integers representing the possible values for
88 the physical extent of a volume group. Value is in KB.
90 floor - size (in KB) of smallest PE we care about.
95 while curpe
<= 16384*1024:
97 possiblePE
.append(curpe
)
103 """ Return the maximum size (in MB) of a logical volume. """
104 if util
.getArch() in ("x86_64",): #64bit architectures
105 return (8*1024*1024*1024*1024) #Max is 8EiB (very large number..)
107 return (16*1024*1024) #Max is 16TiB
109 def safeLvmName(name
):
111 tmp
= tmp
.replace("/", "_")
112 tmp
= re
.sub("[^0-9a-zA-Z._]", "", tmp
)
113 tmp
= tmp
.lstrip("_")