Skip to content

Commit 841afe6

Browse files
committed
Add parents for getAllInfoFromVG
It's needed by the VDI attach path of LVMSR to identify the chain to enable Signed-off-by: Damien Thenot <[email protected]>
1 parent 0c7d919 commit 841afe6

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

drivers/qcow2util.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,21 @@ def getInfoFromLVM(
495495
raise e
496496
return cowinfo
497497

498+
def _getInfoLV(self, lvcache: LVMCache, extractUuidFunction: Callable[[str], str], lvPath: str) -> CowImageInfo:
499+
was_activated = False
500+
lvName = lvPath.split("/")[-1]
501+
lvcache.refresh()
502+
if not lvcache.is_active(lvName):
503+
lvcache.activateNoRefcount(lvName)
504+
was_activated = True
505+
cowinfo = self.getInfo(lvPath, extractUuidFunction)
506+
if was_activated:
507+
try:
508+
lvcache.deactivateNoRefcount(lvName)
509+
except Exception as e:
510+
raise e
511+
return cowinfo
512+
498513
@override
499514
def getAllInfoFromVG(
500515
self,
@@ -505,7 +520,6 @@ def getAllInfoFromVG(
505520
exitOnError: bool = False
506521
) -> Dict[str, CowImageInfo]:
507522
result: Dict[str, CowImageInfo] = dict()
508-
#TODO: handle parents, it needs to getinfo from parents also
509523
#TODO: handle exitOnError
510524
if vgName:
511525
reg = re.compile(pattern)
@@ -514,21 +528,20 @@ def getAllInfoFromVG(
514528
# We get size in lvcache.lvs[lvName].size (in bytes)
515529
# We could read the header from the PV directly
516530
for lvName in lvcache.lvs.keys():
517-
was_activated = False
518-
lvinfo = lvcache.lvs[lvName]
531+
# lvinfo = lvcache.lvs[lvName]
519532
if reg.match(lvName):
520-
lvcache.refresh()
521-
if not lvcache.is_active(lvName):
522-
lvcache.activateNoRefcount(lvName)
523-
was_activated = True
524-
path = "/dev/{}/{}".format(vgName, lvName)
525-
cowinfo = self.getInfo(path, extractUuidFunction)
533+
lvPath = "/dev/{}/{}".format(vgName, lvName)
534+
cowinfo = self._getInfoLV(lvcache, extractUuidFunction, lvPath)
526535
result[cowinfo.uuid] = cowinfo
527-
if was_activated:
528-
try:
529-
lvcache.deactivateNoRefcount(lvName)
530-
except Exception as e:
531-
raise e
536+
if parents:
537+
parentUuid = cowinfo.parentUuid
538+
parentPath = cowinfo.parentPath
539+
while parentUuid != "":
540+
cowinfo = self._getInfoLV(lvcache, extractUuidFunction, parentPath)
541+
result[cowinfo.uuid] = cowinfo
542+
parentUuid = cowinfo.parentUuid
543+
parentPath = cowinfo.parentPath
544+
532545
return result
533546
else:
534547
pattern_p: Path = Path(pattern)

0 commit comments

Comments
 (0)