From d8e2daf7798fe5a4b3bb8d4005e303013666c2dd Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 25 Oct 2024 17:03:18 +0400 Subject: [PATCH] fix: wait for udevd to be running before activating LVM Fixes #9505 Signed-off-by: Andrey Smirnov (cherry picked from commit b7801df827d8e1e9a2db7dac0a62c3802de4d73c) --- .../app/machined/pkg/controllers/block/lvm.go | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/app/machined/pkg/controllers/block/lvm.go b/internal/app/machined/pkg/controllers/block/lvm.go index cfd596796..0d5c2dc2c 100644 --- a/internal/app/machined/pkg/controllers/block/lvm.go +++ b/internal/app/machined/pkg/controllers/block/lvm.go @@ -11,11 +11,14 @@ import ( "github.com/cosi-project/runtime/pkg/controller" "github.com/cosi-project/runtime/pkg/safe" + "github.com/cosi-project/runtime/pkg/state" "github.com/hashicorp/go-multierror" + "github.com/siderolabs/gen/optional" "github.com/siderolabs/go-cmd/pkg/cmd" "go.uber.org/zap" "github.com/siderolabs/talos/pkg/machinery/resources/block" + "github.com/siderolabs/talos/pkg/machinery/resources/v1alpha1" ) // LVMActivationController activates LVM volumes when they are discovered by the block.DiscoveryController. @@ -37,6 +40,12 @@ func (ctrl *LVMActivationController) Inputs() []controller.Input { Type: block.DiscoveredVolumeType, Kind: controller.InputWeak, }, + { + Namespace: v1alpha1.NamespaceName, + Type: v1alpha1.ServiceType, + ID: optional.Some("udevd"), + Kind: controller.InputWeak, + }, } } @@ -64,6 +73,23 @@ func (ctrl *LVMActivationController) Run(ctx context.Context, r controller.Runti case <-r.EventCh(): } + udevdService, err := safe.ReaderGetByID[*v1alpha1.Service](ctx, r, "udevd") + if err != nil && !state.IsNotFoundError(err) { + return fmt.Errorf("failed to get udevd service: %w", err) + } + + if udevdService == nil { + logger.Debug("udevd service not registered yet") + + continue + } + + if !(udevdService.TypedSpec().Running && udevdService.TypedSpec().Healthy) { + logger.Debug("waiting for udevd service to be running and healthy") + + continue + } + discoveredVolumes, err := safe.ReaderListAll[*block.DiscoveredVolume](ctx, r) if err != nil { return fmt.Errorf("failed to list discovered volumes: %w", err)