Revision 0ede5336 lib/bdev.py
b/lib/bdev.py | ||
---|---|---|
94 | 94 |
STATUS_ONLINE: "online", |
95 | 95 |
} |
96 | 96 |
|
97 |
|
|
98 | 97 |
def __init__(self, unique_id, children): |
99 | 98 |
self._children = children |
100 | 99 |
self.dev_path = None |
... | ... | |
102 | 101 |
self.major = None |
103 | 102 |
self.minor = None |
104 | 103 |
|
105 |
|
|
106 | 104 |
def Assemble(self): |
107 | 105 |
"""Assemble the device from its components. |
108 | 106 |
|
... | ... | |
131 | 129 |
child.Shutdown() |
132 | 130 |
return status |
133 | 131 |
|
134 |
|
|
135 | 132 |
def Attach(self): |
136 | 133 |
"""Find a device which matches our config and attach to it. |
137 | 134 |
|
138 | 135 |
""" |
139 | 136 |
raise NotImplementedError |
140 | 137 |
|
141 |
|
|
142 | 138 |
def Close(self): |
143 | 139 |
"""Notifies that the device will no longer be used for I/O. |
144 | 140 |
|
145 | 141 |
""" |
146 | 142 |
raise NotImplementedError |
147 | 143 |
|
148 |
|
|
149 | 144 |
@classmethod |
150 | 145 |
def Create(cls, unique_id, children, size): |
151 | 146 |
"""Create the device. |
... | ... | |
160 | 155 |
""" |
161 | 156 |
raise NotImplementedError |
162 | 157 |
|
163 |
|
|
164 | 158 |
def Remove(self): |
165 | 159 |
"""Remove this device. |
166 | 160 |
|
... | ... | |
171 | 165 |
""" |
172 | 166 |
raise NotImplementedError |
173 | 167 |
|
174 |
|
|
175 | 168 |
def Rename(self, new_id): |
176 | 169 |
"""Rename this device. |
177 | 170 |
|
... | ... | |
180 | 173 |
""" |
181 | 174 |
raise NotImplementedError |
182 | 175 |
|
183 |
|
|
184 | 176 |
def GetStatus(self): |
185 | 177 |
"""Return the status of the device. |
186 | 178 |
|
187 | 179 |
""" |
188 | 180 |
raise NotImplementedError |
189 | 181 |
|
190 |
|
|
191 | 182 |
def Open(self, force=False): |
192 | 183 |
"""Make the device ready for use. |
193 | 184 |
|
... | ... | |
200 | 191 |
""" |
201 | 192 |
raise NotImplementedError |
202 | 193 |
|
203 |
|
|
204 | 194 |
def Shutdown(self): |
205 | 195 |
"""Shut down the device, freeing its children. |
206 | 196 |
|
... | ... | |
211 | 201 |
""" |
212 | 202 |
raise NotImplementedError |
213 | 203 |
|
214 |
|
|
215 | 204 |
def SetSyncSpeed(self, speed): |
216 | 205 |
"""Adjust the sync speed of the mirror. |
217 | 206 |
|
... | ... | |
224 | 213 |
result = result and child.SetSyncSpeed(speed) |
225 | 214 |
return result |
226 | 215 |
|
227 |
|
|
228 | 216 |
def GetSyncStatus(self): |
229 | 217 |
"""Returns the sync status of the device. |
230 | 218 |
|
... | ... | |
415 | 403 |
return True |
416 | 404 |
return False |
417 | 405 |
|
418 |
|
|
419 | 406 |
def Assemble(self): |
420 | 407 |
"""Assemble the device. |
421 | 408 |
|
... | ... | |
425 | 412 |
""" |
426 | 413 |
return True |
427 | 414 |
|
428 |
|
|
429 | 415 |
def Shutdown(self): |
430 | 416 |
"""Shutdown the device. |
431 | 417 |
|
... | ... | |
435 | 421 |
""" |
436 | 422 |
return True |
437 | 423 |
|
438 |
|
|
439 | 424 |
def GetStatus(self): |
440 | 425 |
"""Return the status of the device. |
441 | 426 |
|
... | ... | |
464 | 449 |
|
465 | 450 |
return retval |
466 | 451 |
|
467 |
|
|
468 | 452 |
def Open(self, force=False): |
469 | 453 |
"""Make the device ready for I/O. |
470 | 454 |
|
... | ... | |
473 | 457 |
""" |
474 | 458 |
return True |
475 | 459 |
|
476 |
|
|
477 | 460 |
def Close(self): |
478 | 461 |
"""Notifies that the device will no longer be used for I/O. |
479 | 462 |
|
... | ... | |
482 | 465 |
""" |
483 | 466 |
return True |
484 | 467 |
|
485 |
|
|
486 | 468 |
def Snapshot(self, size): |
487 | 469 |
"""Create a snapshot copy of an lvm block device. |
488 | 470 |
|
... | ... | |
512 | 494 |
|
513 | 495 |
return snap_name |
514 | 496 |
|
515 |
|
|
516 | 497 |
def SetInfo(self, text): |
517 | 498 |
"""Update metadata with info text. |
518 | 499 |
|
... | ... | |
542 | 523 |
self.major = 9 |
543 | 524 |
self.Attach() |
544 | 525 |
|
545 |
|
|
546 | 526 |
def Attach(self): |
547 | 527 |
"""Find an array which matches our config and attach to it. |
548 | 528 |
|
... | ... | |
558 | 538 |
|
559 | 539 |
return (minor is not None) |
560 | 540 |
|
561 |
|
|
562 | 541 |
@staticmethod |
563 | 542 |
def _GetUsedDevs(): |
564 | 543 |
"""Compute the list of in-use MD devices. |
... | ... | |
581 | 560 |
|
582 | 561 |
return used_md |
583 | 562 |
|
584 |
|
|
585 | 563 |
@staticmethod |
586 | 564 |
def _GetDevInfo(minor): |
587 | 565 |
"""Get info about a MD device. |
... | ... | |
604 | 582 |
retval["state"] = kv[1].split(", ") |
605 | 583 |
return retval |
606 | 584 |
|
607 |
|
|
608 | 585 |
@staticmethod |
609 | 586 |
def _FindUnusedMinor(): |
610 | 587 |
"""Compute an unused MD minor. |
... | ... | |
623 | 600 |
raise errors.BlockDeviceError("Can't find a free MD minor") |
624 | 601 |
return i |
625 | 602 |
|
626 |
|
|
627 | 603 |
@classmethod |
628 | 604 |
def _FindMDByUUID(cls, uuid): |
629 | 605 |
"""Find the minor of an MD array with a given UUID. |
... | ... | |
636 | 612 |
return minor |
637 | 613 |
return None |
638 | 614 |
|
639 |
|
|
640 | 615 |
@staticmethod |
641 | 616 |
def _ZeroSuperblock(dev_path): |
642 | 617 |
"""Zero the possible locations for an MD superblock. |
... | ... | |
714 | 689 |
return None |
715 | 690 |
return MDRaid1(info["uuid"], children) |
716 | 691 |
|
717 |
|
|
718 | 692 |
def Remove(self): |
719 | 693 |
"""Stub remove function for MD RAID 1 arrays. |
720 | 694 |
|
... | ... | |
756 | 730 |
result.output) |
757 | 731 |
self._children.extend(devices) |
758 | 732 |
|
759 |
|
|
760 | 733 |
def RemoveChildren(self, devices): |
761 | 734 |
"""Remove member(s) from the md raid1. |
762 | 735 |
|
... | ... | |
798 | 771 |
for dev in orig_devs: |
799 | 772 |
self._children.remove(dev) |
800 | 773 |
|
801 |
|
|
802 | 774 |
def GetStatus(self): |
803 | 775 |
"""Return the status of the device. |
804 | 776 |
|
... | ... | |
810 | 782 |
retval = self.STATUS_ONLINE |
811 | 783 |
return retval |
812 | 784 |
|
813 |
|
|
814 | 785 |
def _SetFromMinor(self, minor): |
815 | 786 |
"""Set our parameters based on the given minor. |
816 | 787 |
|
... | ... | |
820 | 791 |
self.minor = minor |
821 | 792 |
self.dev_path = "/dev/md%d" % minor |
822 | 793 |
|
823 |
|
|
824 | 794 |
def Assemble(self): |
825 | 795 |
"""Assemble the MD device. |
826 | 796 |
|
... | ... | |
851 | 821 |
self.minor = free_minor |
852 | 822 |
return not result.failed |
853 | 823 |
|
854 |
|
|
855 | 824 |
def Shutdown(self): |
856 | 825 |
"""Tear down the MD array. |
857 | 826 |
|
... | ... | |
871 | 840 |
self.dev_path = None |
872 | 841 |
return True |
873 | 842 |
|
874 |
|
|
875 | 843 |
def SetSyncSpeed(self, kbytes): |
876 | 844 |
"""Set the maximum sync speed for the MD array. |
877 | 845 |
|
... | ... | |
892 | 860 |
f.close() |
893 | 861 |
return result |
894 | 862 |
|
895 |
|
|
896 | 863 |
def GetSyncStatus(self): |
897 | 864 |
"""Returns the sync status of the device. |
898 | 865 |
|
... | ... | |
931 | 898 |
time_est = (sync_total - sync_done) / 2 / sync_speed_k |
932 | 899 |
return sync_percent, time_est, not is_clean |
933 | 900 |
|
934 |
|
|
935 | 901 |
def Open(self, force=False): |
936 | 902 |
"""Make the device ready for I/O. |
937 | 903 |
|
... | ... | |
941 | 907 |
""" |
942 | 908 |
return True |
943 | 909 |
|
944 |
|
|
945 | 910 |
def Close(self): |
946 | 911 |
"""Notifies that the device will no longer be used for I/O. |
947 | 912 |
|
... | ... | |
1191 | 1156 |
continue |
1192 | 1157 |
return data |
1193 | 1158 |
|
1194 |
|
|
1195 | 1159 |
def _MatchesLocal(self, info): |
1196 | 1160 |
"""Test if our local config matches with an existing device. |
1197 | 1161 |
|
... | ... | |
1219 | 1183 |
info["meta_index"] == -1) |
1220 | 1184 |
return retval |
1221 | 1185 |
|
1222 |
|
|
1223 | 1186 |
def _MatchesNet(self, info): |
1224 | 1187 |
"""Test if our network config matches with an existing device. |
1225 | 1188 |
|
... | ... | |
1245 | 1208 |
info["remote_addr"] == (self._rhost, self._rport)) |
1246 | 1209 |
return retval |
1247 | 1210 |
|
1248 |
|
|
1249 | 1211 |
@classmethod |
1250 | 1212 |
def _AssembleLocal(cls, minor, backend, meta): |
1251 | 1213 |
"""Configure the local part of a DRBD device. |
... | ... | |
1262 | 1224 |
logger.Error("Can't attach local disk: %s" % result.output) |
1263 | 1225 |
return not result.failed |
1264 | 1226 |
|
1265 |
|
|
1266 | 1227 |
@classmethod |
1267 | 1228 |
def _ShutdownLocal(cls, minor): |
1268 | 1229 |
"""Detach from the local device. |
... | ... | |
1276 | 1237 |
logger.Error("Can't detach local device: %s" % result.output) |
1277 | 1238 |
return not result.failed |
1278 | 1239 |
|
1279 |
|
|
1280 | 1240 |
@staticmethod |
1281 | 1241 |
def _ShutdownAll(minor): |
1282 | 1242 |
"""Deactivate the device. |
... | ... | |
1289 | 1249 |
logger.Error("Can't shutdown drbd device: %s" % result.output) |
1290 | 1250 |
return not result.failed |
1291 | 1251 |
|
1292 |
|
|
1293 | 1252 |
@classmethod |
1294 | 1253 |
def _AssembleNet(cls, minor, net_info, protocol): |
1295 | 1254 |
"""Configure the network part of the device. |
... | ... | |
1329 | 1288 |
return False |
1330 | 1289 |
return True |
1331 | 1290 |
|
1332 |
|
|
1333 | 1291 |
@classmethod |
1334 | 1292 |
def _ShutdownNet(cls, minor): |
1335 | 1293 |
"""Disconnect from the remote peer. |
... | ... | |
1341 | 1299 |
logger.Error("Can't shutdown network: %s" % result.output) |
1342 | 1300 |
return not result.failed |
1343 | 1301 |
|
1344 |
|
|
1345 | 1302 |
def Assemble(self): |
1346 | 1303 |
"""Assemble the drbd. |
1347 | 1304 |
|
... | ... | |
1392 | 1349 |
self._SetFromMinor(minor) |
1393 | 1350 |
return True |
1394 | 1351 |
|
1395 |
|
|
1396 | 1352 |
def Shutdown(self): |
1397 | 1353 |
"""Shutdown the DRBD device. |
1398 | 1354 |
|
... | ... | |
1406 | 1362 |
self.dev_path = None |
1407 | 1363 |
return True |
1408 | 1364 |
|
1409 |
|
|
1410 | 1365 |
def Attach(self): |
1411 | 1366 |
"""Find a DRBD device which matches our config and attach to it. |
1412 | 1367 |
|
... | ... | |
1434 | 1389 |
self._SetFromMinor(minor) |
1435 | 1390 |
return minor is not None |
1436 | 1391 |
|
1437 |
|
|
1438 | 1392 |
def Open(self, force=False): |
1439 | 1393 |
"""Make the local state primary. |
1440 | 1394 |
|
... | ... | |
1456 | 1410 |
return False |
1457 | 1411 |
return True |
1458 | 1412 |
|
1459 |
|
|
1460 | 1413 |
def Close(self): |
1461 | 1414 |
"""Make the local state secondary. |
1462 | 1415 |
|
... | ... | |
1471 | 1424 |
logger.Error("Can't switch drbd device to secondary: %s" % result.output) |
1472 | 1425 |
raise errors.BlockDeviceError("Can't switch drbd device to secondary") |
1473 | 1426 |
|
1474 |
|
|
1475 | 1427 |
def SetSyncSpeed(self, kbytes): |
1476 | 1428 |
"""Set the speed of the DRBD syncer. |
1477 | 1429 |
|
... | ... | |
1486 | 1438 |
logger.Error("Can't change syncer rate: %s " % result.fail_reason) |
1487 | 1439 |
return not result.failed and children_result |
1488 | 1440 |
|
1489 |
|
|
1490 | 1441 |
def GetSyncStatus(self): |
1491 | 1442 |
"""Returns the sync status of the device. |
1492 | 1443 |
|
... | ... | |
1524 | 1475 |
is_degraded = client_state != "Connected" |
1525 | 1476 |
return sync_percent, est_time, is_degraded |
1526 | 1477 |
|
1527 |
|
|
1528 |
|
|
1529 |
|
|
1530 | 1478 |
def GetStatus(self): |
1531 | 1479 |
"""Compute the status of the DRBD device |
1532 | 1480 |
|
... | ... | |
1555 | 1503 |
|
1556 | 1504 |
return result |
1557 | 1505 |
|
1558 |
|
|
1559 | 1506 |
@staticmethod |
1560 | 1507 |
def _ZeroDevice(device): |
1561 | 1508 |
"""Zero a device. |
... | ... | |
1572 | 1519 |
if err.errno != errno.ENOSPC: |
1573 | 1520 |
raise |
1574 | 1521 |
|
1575 |
|
|
1576 | 1522 |
@classmethod |
1577 | 1523 |
def Create(cls, unique_id, children, size): |
1578 | 1524 |
"""Create a new DRBD device. |
... | ... | |
1594 | 1540 |
logger.Info("Done zeroing device %s" % meta.dev_path) |
1595 | 1541 |
return cls(unique_id, children) |
1596 | 1542 |
|
1597 |
|
|
1598 | 1543 |
def Remove(self): |
1599 | 1544 |
"""Stub remove for DRBD devices. |
1600 | 1545 |
|
Also available in: Unified diff