Skip to content

Commit f941636

Browse files
committed
wip
1 parent 9cd804f commit f941636

6 files changed

Lines changed: 39 additions & 21 deletions

File tree

drivers/blktap2.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1730,15 +1730,21 @@ def _check_journal_coalesce_chain(self, sr_uuid: str, vdi_uuid: str) -> bool:
17301730
for entry in journal.getAll("coalesce").keys():
17311731
if entry in vdi_chain:
17321732
vdi_to_cancel.append(entry)
1733-
util.SMlog("Coalescing VDI {} in chain".format(entry))
1733+
util.SMlog("VDI {} in chain is coalescing".format(entry))
1734+
1735+
for entry in journal.getAll("relink").keys():
1736+
if entry in vdi_chain:
1737+
util.SMlog("VDI {} is in relink".format(entry))
1738+
return False #TODO: need to do stop and retry the activating after the relink
17341739

17351740
# Get the host_ref from the host doing the GC work
17361741
host_ref = self._get_sr_master_host_ref()
17371742
for vdi in vdi_to_cancel:
17381743
args = {"sr_uuid": sr_uuid, "vdi_uuid": vdi}
17391744
util.SMlog("Calling cancel_coalesce_master with args: {}".format(args))
17401745
self._session.xenapi.host.call_plugin(\
1741-
host_ref, PLUGIN_ON_SLAVE, "cancel_coalesce_master", args)
1746+
host_ref, PLUGIN_ON_SLAVE, "cancel_coalesce_master", args) #TODO: This can potentially never return if we send it after the coalesce is done and the relink is in process
1747+
# We could run it abortable and check regularly that the journal isn't here?
17421748

17431749
return True
17441750

@@ -1806,6 +1812,8 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
18061812
util.SMlog('Using key with hash {} for VDI {}'.format(key_hash, vdi_uuid))
18071813
# Activate the physical node
18081814
dev_path = self._activate(sr_uuid, vdi_uuid, options)
1815+
# if not dev_path:
1816+
# return False
18091817

18101818
if hasattr(self.target.vdi.sr, 'DRIVER_TYPE') and \
18111819
self.target.vdi.sr.DRIVER_TYPE == 'lvhd' and \
@@ -1846,6 +1854,9 @@ def _activate_locked(self, sr_uuid, vdi_uuid, options):
18461854
def _activate(self, sr_uuid, vdi_uuid, options):
18471855
vdi_options = self.target.activate(sr_uuid, vdi_uuid)
18481856

1857+
# if not self._check_journal_coalesce_chain(sr_uuid, vdi_uuid):
1858+
# return None
1859+
18491860
dev_path = self.setup_cache(sr_uuid, vdi_uuid, options)
18501861
if not dev_path:
18511862
phy_path = self.PhyLink.from_uuid(sr_uuid, vdi_uuid).readlink()

drivers/cleanup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ def _coalesce(self, vdi: VDI):
25282528
try:
25292529
vdi.parent._tagChildrenForRelink()
25302530
self.scan()
2531-
vdi._relinkSkip()
2531+
vdi._relinkSkip() #TODO: here
25322532
finally:
25332533
self.unlock()
25342534
# Reload the children to leave things consistent

drivers/lvmanager.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import util
2121

2222
from constants import NS_PREFIX_LVM
23+
from lvmcache import LVMCache
2324

2425
class LVManagerException(util.SMException):
2526
pass
@@ -41,7 +42,7 @@ class LVActivator:
4142
TEMPORARY = False
4243
PERSISTENT = True
4344

44-
def __init__(self, srUuid, lvmCache):
45+
def __init__(self, srUuid, lvmCache: LVMCache):
4546
self.ns = NS_PREFIX_LVM + srUuid
4647
self.lvmCache = lvmCache
4748
self.lvActivations = dict()
@@ -63,9 +64,9 @@ def activate(self, uuid, lvName, binary, persistent=False):
6364

6465
def activateEnforce(self, uuid, lvName, lvPath):
6566
"""incrementing the refcount is not enough to keep an LV activated if
66-
another party is unaware of refcounting. For example, blktap does
67+
another party is unaware of refcounting. For example, blktap does
6768
direct "lvchange -an, lvchange -ay" during VBD.attach/resume without
68-
any knowledge of refcounts. Therefore, we need to keep the device open
69+
any knowledge of refcounts. Therefore, we need to keep the device open
6970
to prevent unwanted deactivations. Note that blktap can do "lvchange
7071
-an" the very moment we try to open the file, so retry on failure"""
7172
if self.lvActivations[self.TEMPORARY][self.NORMAL].get(uuid):

drivers/lvmcache.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ def activate(self, ns, ref, lvName, binary):
146146
lock.acquire()
147147
try:
148148
count = RefCounter.get(ref, binary, ns)
149+
util.SMlog(f"DAMS: LVMCache Activating: {lvName}, binary={binary}, count={count}")
149150
if count == 1:
150151
try:
151152
self.activateNoRefcount(lvName)
@@ -161,6 +162,7 @@ def deactivate(self, ns, ref, lvName, binary):
161162
lock.acquire()
162163
try:
163164
count = RefCounter.put(ref, binary, ns)
165+
util.SMlog(f"DAMS: LVMCache Deactivating: {lvName}, count={count}")
164166
if count > 0:
165167
return
166168
refreshed = False

drivers/on_slave.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,22 @@ def commit_tapdisk(session, args):
166166
vdi_type = args["vdi_type"]
167167
#TODO: naming should reflect that it does more than coalesceing, like setting volume RW
168168

169-
def set_RW(path):
170-
try:
171-
util.pread2(["lvchange", "-p", "rw", path])
172-
except:
173-
pass
169+
# def set_RW(path):
170+
# try:
171+
# util.pread2(["lvchange", "-p", "rw", path]) #This will disable the LV see: https://github.com/xcp-ng/sm/commit/8bc81723c87b2b30c28422be75b86c0f76b95d18
172+
# except Exception:
173+
# pass
174174
#TODO: need to make children RW. Or we let the relink happen with a refresh on master and hope it doesn't corrupt the disk
175-
if path.startswith("/dev/"):
176-
set_RW(path)
175+
#TODO: we might want to make the chain RW for tapdisk in blktap2.py instead
176+
# if path.startswith("/dev/"):
177+
# set_RW(path)
177178

178179
from cowutil import getCowUtil
179180
cowutil = getCowUtil(vdi_type)
180181
try:
181-
parent = cowutil.getParentNoCheck(path)
182-
if parent.startswith("/dev/"):
183-
set_RW(parent)
182+
# parent = cowutil.getParentNoCheck(path) #TODO: Same things as above, should be done in blktap2.py
183+
# if parent.startswith("/dev/"):
184+
# set_RW(parent)
184185
return str(cowutil.coalesceOnline(path))
185186
except:
186187
util.logException("Couldn't coalesce online")
@@ -193,7 +194,7 @@ def commit_cancel(session, args):
193194
cowutil = getCowUtil(vdi_type)
194195
try:
195196
cowutil.cancelCoalesceOnline(path)
196-
except:
197+
except Exception:
197198
return "False"
198199
return "True"
199200

@@ -232,7 +233,7 @@ def cancel_coalesce_master(session, args):
232233
raise
233234

234235
while os.path.exists(path):
235-
time.sleep(1)
236+
time.sleep(1) #TODO: We can get stuck here, we need a way to check we are in a legitimate wait
236237

237238
return "True"
238239

drivers/qcow2util.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -496,11 +496,12 @@ def _getInfoLV(
496496

497497
vdiUuid = extractUuidFunction(lvPath)
498498
srUuid = extractUuidFunction(vgName)
499-
lvcache.activate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
499+
ns = NS_PREFIX_LVM + srUuid
500+
lvcache.activate(ns, vdiUuid, lvName, False)
500501
try:
501502
cowinfo = self.getInfo(lvPath, extractUuidFunction)
502503
finally:
503-
lvcache.deactivate(NS_PREFIX_LVM + srUuid, vdiUuid, lvName, False)
504+
lvcache.deactivate(ns, vdiUuid, lvName, False)
504505
return cowinfo
505506

506507
@override
@@ -678,7 +679,7 @@ def killData(self, path: str) -> None:
678679
Returns:
679680
nothing.
680681
"""
681-
self._read_qcow2(path)
682+
self._read_qcow2(path, read_clusters=True)
682683
# We need to reset L1 entries and then just truncate the file right
683684
# after L1 entries
684685
with open(self.filename, "r+b") as file:
@@ -783,7 +784,9 @@ def snapshot(
783784
parent_type = QCOW2_TYPE
784785
if parentRaw:
785786
parent_type = RAW_TYPE
787+
# TODO: msize, it's use to preallocate metadata, could we honor this too?
786788
# TODO: checkEmpty? If it is False, then the parent could be empty and should still be used for snapshot
789+
# But if True, if the parent is empty, we do what? vhd would just use the parent of parent as base, should we emulate this behavior?
787790
cmd = [QEMU_IMG, "create", "-f", QCOW2_TYPE, "-b", parent, "-F", parent_type, path]
788791
self._ioretry(cmd)
789792
self.setHidden(path, False) #We add hidden header at creation

0 commit comments

Comments
 (0)