130 |
130 |
after assembly we'll have our correct major/minor.
|
131 |
131 |
|
132 |
132 |
"""
|
133 |
|
def __init__(self, unique_id, children, size):
|
|
133 |
def __init__(self, unique_id, children, size, params):
|
134 |
134 |
self._children = children
|
135 |
135 |
self.dev_path = None
|
136 |
136 |
self.unique_id = unique_id
|
... | ... | |
138 |
138 |
self.minor = None
|
139 |
139 |
self.attached = False
|
140 |
140 |
self.size = size
|
|
141 |
self.params = params
|
141 |
142 |
|
142 |
143 |
def Assemble(self):
|
143 |
144 |
"""Assemble the device from its components.
|
... | ... | |
166 |
167 |
raise NotImplementedError
|
167 |
168 |
|
168 |
169 |
@classmethod
|
169 |
|
def Create(cls, unique_id, children, size):
|
|
170 |
def Create(cls, unique_id, children, size, params):
|
170 |
171 |
"""Create the device.
|
171 |
172 |
|
172 |
173 |
If the device cannot be created, it will return None
|
... | ... | |
373 |
374 |
_INVALID_NAMES = frozenset([".", "..", "snapshot", "pvmove"])
|
374 |
375 |
_INVALID_SUBSTRINGS = frozenset(["_mlog", "_mimage"])
|
375 |
376 |
|
376 |
|
def __init__(self, unique_id, children, size):
|
|
377 |
def __init__(self, unique_id, children, size, params):
|
377 |
378 |
"""Attaches to a LV device.
|
378 |
379 |
|
379 |
380 |
The unique_id is a tuple (vg_name, lv_name)
|
380 |
381 |
|
381 |
382 |
"""
|
382 |
|
super(LogicalVolume, self).__init__(unique_id, children, size)
|
|
383 |
super(LogicalVolume, self).__init__(unique_id, children, size, params)
|
383 |
384 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
|
384 |
385 |
raise ValueError("Invalid configuration data %s" % str(unique_id))
|
385 |
386 |
self._vg_name, self._lv_name = unique_id
|
... | ... | |
391 |
392 |
self.Attach()
|
392 |
393 |
|
393 |
394 |
@classmethod
|
394 |
|
def Create(cls, unique_id, children, size):
|
|
395 |
def Create(cls, unique_id, children, size, params):
|
395 |
396 |
"""Create a new logical volume.
|
396 |
397 |
|
397 |
398 |
"""
|
... | ... | |
433 |
434 |
if result.failed:
|
434 |
435 |
_ThrowError("LV create failed (%s): %s",
|
435 |
436 |
result.fail_reason, result.output)
|
436 |
|
return LogicalVolume(unique_id, children, size)
|
|
437 |
return LogicalVolume(unique_id, children, size, params)
|
437 |
438 |
|
438 |
439 |
@staticmethod
|
439 |
440 |
def _GetVolumeInfo(lvm_cmd, fields):
|
... | ... | |
718 |
719 |
snap_name = self._lv_name + ".snap"
|
719 |
720 |
|
720 |
721 |
# remove existing snapshot if found
|
721 |
|
snap = LogicalVolume((self._vg_name, snap_name), None, size)
|
|
722 |
snap = LogicalVolume((self._vg_name, snap_name), None, size, self.params)
|
722 |
723 |
_IgnoreError(snap.Remove)
|
723 |
724 |
|
724 |
725 |
vg_info = self.GetVGInfo([self._vg_name])
|
... | ... | |
1098 |
1099 |
# timeout constants
|
1099 |
1100 |
_NET_RECONFIG_TIMEOUT = 60
|
1100 |
1101 |
|
1101 |
|
def __init__(self, unique_id, children, size):
|
|
1102 |
def __init__(self, unique_id, children, size, params):
|
1102 |
1103 |
if children and children.count(None) > 0:
|
1103 |
1104 |
children = []
|
1104 |
1105 |
if len(children) not in (0, 2):
|
... | ... | |
1112 |
1113 |
if not _CanReadDevice(children[1].dev_path):
|
1113 |
1114 |
logging.info("drbd%s: Ignoring unreadable meta device", self._aminor)
|
1114 |
1115 |
children = []
|
1115 |
|
super(DRBD8, self).__init__(unique_id, children, size)
|
|
1116 |
super(DRBD8, self).__init__(unique_id, children, size, params)
|
1116 |
1117 |
self.major = self._DRBD_MAJOR
|
1117 |
1118 |
version = self._GetVersion(self._GetProcData())
|
1118 |
1119 |
if version["k_major"] != 8:
|
... | ... | |
1905 |
1906 |
self.Shutdown()
|
1906 |
1907 |
|
1907 |
1908 |
@classmethod
|
1908 |
|
def Create(cls, unique_id, children, size):
|
|
1909 |
def Create(cls, unique_id, children, size, params):
|
1909 |
1910 |
"""Create a new DRBD8 device.
|
1910 |
1911 |
|
1911 |
1912 |
Since DRBD devices are not created per se, just assembled, this
|
... | ... | |
1931 |
1932 |
aminor, meta)
|
1932 |
1933 |
cls._CheckMetaSize(meta.dev_path)
|
1933 |
1934 |
cls._InitMeta(aminor, meta.dev_path)
|
1934 |
|
return cls(unique_id, children, size)
|
|
1935 |
return cls(unique_id, children, size, params)
|
1935 |
1936 |
|
1936 |
1937 |
def Grow(self, amount, dryrun):
|
1937 |
1938 |
"""Resize the DRBD device and its backing storage.
|
... | ... | |
1959 |
1960 |
The unique_id for the file device is a (file_driver, file_path) tuple.
|
1960 |
1961 |
|
1961 |
1962 |
"""
|
1962 |
|
def __init__(self, unique_id, children, size):
|
|
1963 |
def __init__(self, unique_id, children, size, params):
|
1963 |
1964 |
"""Initalizes a file device backend.
|
1964 |
1965 |
|
1965 |
1966 |
"""
|
1966 |
1967 |
if children:
|
1967 |
1968 |
raise errors.BlockDeviceError("Invalid setup for file device")
|
1968 |
|
super(FileStorage, self).__init__(unique_id, children, size)
|
|
1969 |
super(FileStorage, self).__init__(unique_id, children, size, params)
|
1969 |
1970 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
|
1970 |
1971 |
raise ValueError("Invalid configuration data %s" % str(unique_id))
|
1971 |
1972 |
self.driver = unique_id[0]
|
... | ... | |
2073 |
2074 |
_ThrowError("Can't stat %s: %s", self.dev_path, err)
|
2074 |
2075 |
|
2075 |
2076 |
@classmethod
|
2076 |
|
def Create(cls, unique_id, children, size):
|
|
2077 |
def Create(cls, unique_id, children, size, params):
|
2077 |
2078 |
"""Create a new file.
|
2078 |
2079 |
|
2079 |
2080 |
@param size: the size of file in MiB
|
... | ... | |
2095 |
2096 |
_ThrowError("File already existing: %s", dev_path)
|
2096 |
2097 |
_ThrowError("Error in file creation: %", str(err))
|
2097 |
2098 |
|
2098 |
|
return FileStorage(unique_id, children, size)
|
|
2099 |
return FileStorage(unique_id, children, size, params)
|
2099 |
2100 |
|
2100 |
2101 |
|
2101 |
2102 |
class PersistentBlockDevice(BlockDev):
|
... | ... | |
2108 |
2109 |
For the time being, pathnames are required to lie under /dev.
|
2109 |
2110 |
|
2110 |
2111 |
"""
|
2111 |
|
def __init__(self, unique_id, children, size):
|
|
2112 |
def __init__(self, unique_id, children, size, params):
|
2112 |
2113 |
"""Attaches to a static block device.
|
2113 |
2114 |
|
2114 |
2115 |
The unique_id is a path under /dev.
|
2115 |
2116 |
|
2116 |
2117 |
"""
|
2117 |
|
super(PersistentBlockDevice, self).__init__(unique_id, children, size)
|
|
2118 |
super(PersistentBlockDevice, self).__init__(unique_id, children, size,
|
|
2119 |
params)
|
2118 |
2120 |
if not isinstance(unique_id, (tuple, list)) or len(unique_id) != 2:
|
2119 |
2121 |
raise ValueError("Invalid configuration data %s" % str(unique_id))
|
2120 |
2122 |
self.dev_path = unique_id[1]
|
... | ... | |
2133 |
2135 |
self.Attach()
|
2134 |
2136 |
|
2135 |
2137 |
@classmethod
|
2136 |
|
def Create(cls, unique_id, children, size):
|
|
2138 |
def Create(cls, unique_id, children, size, params):
|
2137 |
2139 |
"""Create a new device
|
2138 |
2140 |
|
2139 |
2141 |
This is a noop, we only return a PersistentBlockDevice instance
|
2140 |
2142 |
|
2141 |
2143 |
"""
|
2142 |
|
return PersistentBlockDevice(unique_id, children, 0)
|
|
2144 |
return PersistentBlockDevice(unique_id, children, 0, params)
|
2143 |
2145 |
|
2144 |
2146 |
def Remove(self):
|
2145 |
2147 |
"""Remove a device
|
... | ... | |
2218 |
2220 |
DEV_MAP[constants.LD_FILE] = FileStorage
|
2219 |
2221 |
|
2220 |
2222 |
|
2221 |
|
def FindDevice(dev_type, unique_id, children, size):
|
|
2223 |
def _VerifyDiskType(dev_type):
|
|
2224 |
if dev_type not in DEV_MAP:
|
|
2225 |
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
|
|
2226 |
|
|
2227 |
|
|
2228 |
def FindDevice(disk, children):
|
2222 |
2229 |
"""Search for an existing, assembled device.
|
2223 |
2230 |
|
2224 |
2231 |
This will succeed only if the device exists and is assembled, but it
|
2225 |
2232 |
does not do any actions in order to activate the device.
|
2226 |
2233 |
|
|
2234 |
@type disk: L{objects.Disk}
|
|
2235 |
@param disk: the disk object to find
|
|
2236 |
@type children: list of L{bdev.BlockDev}
|
|
2237 |
@param children: the list of block devices that are children of the device
|
|
2238 |
represented by the disk parameter
|
|
2239 |
|
2227 |
2240 |
"""
|
2228 |
|
if dev_type not in DEV_MAP:
|
2229 |
|
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
|
2230 |
|
device = DEV_MAP[dev_type](unique_id, children, size)
|
|
2241 |
_VerifyDiskType(disk.dev_type)
|
|
2242 |
dev_params = objects.FillDict(constants.DISK_LD_DEFAULTS[disk.dev_type],
|
|
2243 |
disk.params)
|
|
2244 |
device = DEV_MAP[disk.dev_type](disk.physical_id, children, disk.size,
|
|
2245 |
dev_params)
|
2231 |
2246 |
if not device.attached:
|
2232 |
2247 |
return None
|
2233 |
2248 |
return device
|
2234 |
2249 |
|
2235 |
2250 |
|
2236 |
|
def Assemble(dev_type, unique_id, children, size):
|
|
2251 |
def Assemble(disk, children):
|
2237 |
2252 |
"""Try to attach or assemble an existing device.
|
2238 |
2253 |
|
2239 |
2254 |
This will attach to assemble the device, as needed, to bring it
|
2240 |
2255 |
fully up. It must be safe to run on already-assembled devices.
|
2241 |
2256 |
|
|
2257 |
@type disk: L{objects.Disk}
|
|
2258 |
@param disk: the disk object to assemble
|
|
2259 |
@type children: list of L{bdev.BlockDev}
|
|
2260 |
@param children: the list of block devices that are children of the device
|
|
2261 |
represented by the disk parameter
|
|
2262 |
|
2242 |
2263 |
"""
|
2243 |
|
if dev_type not in DEV_MAP:
|
2244 |
|
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
|
2245 |
|
device = DEV_MAP[dev_type](unique_id, children, size)
|
|
2264 |
_VerifyDiskType(disk.dev_type)
|
|
2265 |
dev_params = objects.FillDict(constants.DISK_LD_DEFAULTS[disk.dev_type],
|
|
2266 |
disk.params)
|
|
2267 |
device = DEV_MAP[disk.dev_type](disk.physical_id, children, disk.size,
|
|
2268 |
dev_params)
|
2246 |
2269 |
device.Assemble()
|
2247 |
2270 |
return device
|
2248 |
2271 |
|
2249 |
2272 |
|
2250 |
|
def Create(dev_type, unique_id, children, size):
|
|
2273 |
def Create(disk, children):
|
2251 |
2274 |
"""Create a device.
|
2252 |
2275 |
|
|
2276 |
@type disk: L{objects.Disk}
|
|
2277 |
@param disk: the disk object to create
|
|
2278 |
@type children: list of L{bdev.BlockDev}
|
|
2279 |
@param children: the list of block devices that are children of the device
|
|
2280 |
represented by the disk parameter
|
|
2281 |
|
2253 |
2282 |
"""
|
2254 |
|
if dev_type not in DEV_MAP:
|
2255 |
|
raise errors.ProgrammerError("Invalid block device type '%s'" % dev_type)
|
2256 |
|
device = DEV_MAP[dev_type].Create(unique_id, children, size)
|
|
2283 |
_VerifyDiskType(disk.dev_type)
|
|
2284 |
dev_params = objects.FillDict(constants.DISK_LD_DEFAULTS[disk.dev_type],
|
|
2285 |
disk.params)
|
|
2286 |
device = DEV_MAP[disk.dev_type].Create(disk.physical_id, children, disk.size,
|
|
2287 |
dev_params)
|
2257 |
2288 |
return device
|