@@ -422,11 +422,18 @@ def _lvm_info_with_retry(
422422 cmd : str ,
423423 info_type : Literal ['lv' , 'vg' , 'pvseg' ],
424424 ) -> LvmVolumeInfo | LvmGroupInfo | LvmPVInfo | None :
425- while True :
425+ # Retry for up to 5 mins
426+ max_retries = 100
427+ for attempt in range (max_retries ):
426428 try :
427429 return self ._lvm_info (cmd , info_type )
428430 except ValueError :
429- time .sleep (3 )
431+ if attempt < max_retries - 1 :
432+ debug (f'LVM info query failed (attempt { attempt + 1 } /{ max_retries } ), retrying in 3 seconds...' )
433+ time .sleep (3 )
434+
435+ debug (f'LVM info query failed after { max_retries } attempts' )
436+ return None
430437
431438 def lvm_vol_info (self , lv_name : str ) -> LvmVolumeInfo | None :
432439 cmd = f'lvs --reportformat json --unit B -S lv_name={ lv_name } '
@@ -477,6 +484,13 @@ def lvm_pv_create(self, pvs: Iterable[Path]) -> None:
477484 worker .poll ()
478485 worker .write (b'y\n ' , line_ending = False )
479486
487+ # Wait for the command to complete
488+ while worker .is_alive ():
489+ worker .poll ()
490+
491+ # Sync with udev to ensure the PVs are visible
492+ self .udev_sync ()
493+
480494 def lvm_vg_create (self , pvs : Iterable [Path ], vg_name : str ) -> None :
481495 pvs_str = ' ' .join ([str (pv ) for pv in pvs ])
482496 cmd = f'vgcreate --yes { vg_name } { pvs_str } '
@@ -487,6 +501,13 @@ def lvm_vg_create(self, pvs: Iterable[Path], vg_name: str) -> None:
487501 worker .poll ()
488502 worker .write (b'y\n ' , line_ending = False )
489503
504+ # Wait for the command to complete
505+ while worker .is_alive ():
506+ worker .poll ()
507+
508+ # Sync with udev to ensure the VG is visible
509+ self .udev_sync ()
510+
490511 def lvm_vol_create (self , vg_name : str , volume : LvmVolume , offset : Size | None = None ) -> None :
491512 if offset is not None :
492513 length = volume .length - offset
0 commit comments