@@ -495,6 +495,21 @@ def getInfoFromLVM(
495
495
raise e
496
496
return cowinfo
497
497
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
+
498
513
@override
499
514
def getAllInfoFromVG (
500
515
self ,
@@ -505,7 +520,6 @@ def getAllInfoFromVG(
505
520
exitOnError : bool = False
506
521
) -> Dict [str , CowImageInfo ]:
507
522
result : Dict [str , CowImageInfo ] = dict ()
508
- #TODO: handle parents, it needs to getinfo from parents also
509
523
#TODO: handle exitOnError
510
524
if vgName :
511
525
reg = re .compile (pattern )
@@ -514,21 +528,20 @@ def getAllInfoFromVG(
514
528
# We get size in lvcache.lvs[lvName].size (in bytes)
515
529
# We could read the header from the PV directly
516
530
for lvName in lvcache .lvs .keys ():
517
- was_activated = False
518
- lvinfo = lvcache .lvs [lvName ]
531
+ # lvinfo = lvcache.lvs[lvName]
519
532
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 )
526
535
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
+
532
545
return result
533
546
else :
534
547
pattern_p : Path = Path (pattern )
0 commit comments