Skip to content

Commit

Permalink
Fix 2687 - Wait for LVM resource creation
Browse files Browse the repository at this point in the history
  • Loading branch information
svartkanin committed Oct 21, 2024
1 parent b8f0944 commit a52dae9
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import json
import os
import logging
import time
import uuid
from pathlib import Path
from typing import List, Dict, Any, Optional, TYPE_CHECKING, Literal, Iterable
Expand Down Expand Up @@ -367,25 +366,14 @@ def _lvm_info(

return None

def _lvm_info_with_retry(self, cmd: str, info_type: Literal['lv', 'vg', 'pvseg']) -> Optional[Any]:
attempts = 3

for attempt_nr in range(attempts):
try:
return self._lvm_info(cmd, info_type)
except ValueError:
time.sleep(attempt_nr + 1)

raise ValueError(f'Failed to fetch {info_type} information')

def lvm_vol_info(self, lv_name: str) -> Optional[LvmVolumeInfo]:
cmd = (
'lvs --reportformat json '
'--unit B '
f'-S lv_name={lv_name}'
)

return self._lvm_info_with_retry(cmd, 'lv')
return self._lvm_info(cmd, 'lv')

def lvm_group_info(self, vg_name: str) -> Optional[LvmGroupInfo]:
cmd = (
Expand All @@ -395,7 +383,7 @@ def lvm_group_info(self, vg_name: str) -> Optional[LvmGroupInfo]:
f'-S vg_name={vg_name}'
)

return self._lvm_info_with_retry(cmd, 'vg')
return self._lvm_info(cmd, 'vg')

def lvm_pvseg_info(self, vg_name: str, lv_name: str) -> Optional[LvmPVInfo]:
cmd = (
Expand All @@ -405,7 +393,7 @@ def lvm_pvseg_info(self, vg_name: str, lv_name: str) -> Optional[LvmPVInfo]:
'--reportformat json '
)

return self._lvm_info_with_retry(cmd, 'pvseg')
return self._lvm_info(cmd, 'pvseg')

def lvm_vol_change(self, vol: LvmVolume, activate: bool) -> None:
active_flag = 'y' if activate else 'n'
Expand Down Expand Up @@ -441,6 +429,8 @@ def lvm_pv_create(self, pvs: Iterable[Path]) -> None:
worker.poll()
worker.write(b'y\n', line_ending=False)

self.udev_sync()

def lvm_vg_create(self, pvs: Iterable[Path], vg_name: str) -> None:
pvs_str = ' '.join([str(pv) for pv in pvs])
cmd = f'vgcreate --yes {vg_name} {pvs_str}'
Expand All @@ -451,6 +441,8 @@ def lvm_vg_create(self, pvs: Iterable[Path], vg_name: str) -> None:
worker.poll()
worker.write(b'y\n', line_ending=False)

self.udev_sync()

def lvm_vol_create(self, vg_name: str, volume: LvmVolume, offset: Optional[Size] = None) -> None:
if offset is not None:
length = volume.length - offset
Expand All @@ -466,6 +458,8 @@ def lvm_vol_create(self, vg_name: str, volume: LvmVolume, offset: Optional[Size]
worker.poll()
worker.write(b'y\n', line_ending=False)

self.udev_sync()

volume.vg_name = vg_name
volume.dev_path = Path(f'/dev/{vg_name}/{volume.name}')

Expand Down

0 comments on commit a52dae9

Please sign in to comment.