|
18 | 18 | # blktap2: blktap/tapdisk management layer
|
19 | 19 | #
|
20 | 20 |
|
21 |
| -from sm_typing import Any, Callable, ClassVar, Dict, override |
| 21 | +from sm_typing import Any, Callable, ClassVar, Dict, override, List |
22 | 22 |
|
23 | 23 | from abc import abstractmethod
|
24 | 24 |
|
@@ -1657,6 +1657,85 @@ def activate(self, sr_uuid, vdi_uuid, writable, caching_params):
|
1657 | 1657 | time.sleep(1)
|
1658 | 1658 | raise util.SMException("VDI %s locked" % vdi_uuid)
|
1659 | 1659 |
|
| 1660 | + def _get_host_ref(self) -> str: |
| 1661 | + sr = self.target.vdi.sr |
| 1662 | + if sr.is_shared(): |
| 1663 | + util.SMlog("DAMS: SR is shared") |
| 1664 | + host_ref = util.get_master_ref(self._session) |
| 1665 | + else: |
| 1666 | + util.SMlog("DAMS: SR is not shared, using local host") |
| 1667 | + host_ref = sr.host_ref |
| 1668 | + return host_ref |
| 1669 | + |
| 1670 | + def _get_chain(self, cowutil, extractUuid) -> List[str]: |
| 1671 | + vdi_chain = [] |
| 1672 | + path = self.target.get_vdi_path() |
| 1673 | + |
| 1674 | + vdi_chain.append(extractUuid(path)) |
| 1675 | + parent = cowutil.getParentNoCheck(path) |
| 1676 | + while parent: |
| 1677 | + vdi_chain.append(extractUuid(parent)) |
| 1678 | + parent = cowutil.getParentNoCheck(parent) |
| 1679 | + vdi_chain.reverse() |
| 1680 | + return vdi_chain |
| 1681 | + |
| 1682 | + def _check_journal_coalesce_chain(self, sr_uuid, vdi_uuid: str) -> bool: |
| 1683 | + vdi_type = self.target.get_vdi_type() |
| 1684 | + cowutil = getCowUtil(vdi_type) |
| 1685 | + if not cowutil.isCoalesceableOnRemote(): #We only need to stop the coalesce in case of QCOW2 |
| 1686 | + return True |
| 1687 | + |
| 1688 | + level = 0 |
| 1689 | + path = self.target.get_vdi_path() |
| 1690 | + |
| 1691 | + # Different extractUUID & journaler function for LVMSR and FileSR |
| 1692 | + journaler = None |
| 1693 | + extractUuid = None |
| 1694 | + if path.startswith("/dev/"): #TODO: How to identify SR type easily, we could ask XAPI since we have the sruuid (and even ref) |
| 1695 | + from lvmcowutil import LvmCowUtil |
| 1696 | + import lvmcache |
| 1697 | + import journaler |
| 1698 | + vgName = "VG_XenStorage-{}".format(sr_uuid) |
| 1699 | + lvmCache = lvmcache.LVMCache(vgName) |
| 1700 | + journaler = journaler.Journaler(lvmCache) |
| 1701 | + |
| 1702 | + extractUuid = LvmCowUtil.extractUuid |
| 1703 | + else: |
| 1704 | + from FileSR import FileVDI |
| 1705 | + import fjournaler |
| 1706 | + journaler = fjournaler.Journaler(os.getcwd()) |
| 1707 | + extractUuid = FileVDI.extractUuid |
| 1708 | + |
| 1709 | + # Get the VDI chain |
| 1710 | + vdi_chain = self._get_chain(cowutil, extractUuid) |
| 1711 | + |
| 1712 | + util.SMlog("DAMS: VDI chain:") |
| 1713 | + for vdi in vdi_chain: |
| 1714 | + prefix = " " * level |
| 1715 | + level += 1 |
| 1716 | + util.SMlog("{}{}".format(prefix, vdi)) |
| 1717 | + |
| 1718 | + if len(vdi_chain) == 1: |
| 1719 | + #We only have a leaf, do nothing |
| 1720 | + util.SMlog("DAMS: VDI is only a leaf, continuing...") |
| 1721 | + return True |
| 1722 | + |
| 1723 | + vdi_to_cancel = [] |
| 1724 | + for entry in journaler.getAll("coalesce").keys(): |
| 1725 | + if entry in vdi_chain: |
| 1726 | + vdi_to_cancel.append(entry) |
| 1727 | + util.SMlog("{} in chain".format(entry)) |
| 1728 | + |
| 1729 | + # Get the host_ref from the host doing the GC work |
| 1730 | + host_ref = self._get_host_ref() |
| 1731 | + for vdi in vdi_to_cancel: |
| 1732 | + args = {"sr_uuid": sr_uuid, "vdi_uuid": vdi} |
| 1733 | + util.SMlog("args: {}".format(args)) |
| 1734 | + self._session.xenapi.host.call_plugin(\ |
| 1735 | + host_ref, PLUGIN_ON_SLAVE, "cancel_coalesce_master", args) |
| 1736 | + |
| 1737 | + return True |
| 1738 | + |
1660 | 1739 | @locking("VDIUnavailable")
|
1661 | 1740 | def _activate_locked(self, sr_uuid, vdi_uuid, options):
|
1662 | 1741 | """Wraps target.activate and adds a tapdisk"""
|
@@ -1692,6 +1771,8 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
|
1692 | 1771 |
|
1693 | 1772 | vdi_type = self.target.get_vdi_type()
|
1694 | 1773 |
|
| 1774 | + self._check_journal_coalesce_chain(sr_uuid, vdi_uuid) |
| 1775 | + |
1695 | 1776 | # Take lvchange-p Lock before running
|
1696 | 1777 | # tap-ctl open
|
1697 | 1778 | # Needed to avoid race with lvchange -p which is
|
|
0 commit comments