@@ -18,6 +18,7 @@ package config
1818
1919import (
2020 "fmt"
21+ "os/exec"
2122 "path/filepath"
2223 "runtime"
2324 "strings"
@@ -585,3 +586,54 @@ func NewBuildConfig(opts ...GenericOptions) *types.BuildConfig {
585586 }
586587 return b
587588}
589+
590+ // ReconcileUpgradeSpec will check current mounts which may differ from elemental disovery from /sys/block tree
591+ // as this skips multipathed devices which may be in use.
592+ func ReconcileUpgradeSpec (spec * v1.UpgradeSpec ) error {
593+ if spec .Partitions .State != nil {
594+ if err := reconcilePartition (spec .Partitions .State ); err != nil {
595+ return err
596+ }
597+ }
598+ if spec .Partitions .Recovery != nil {
599+ if err := reconcilePartition (spec .Partitions .Recovery ); err != nil {
600+ return err
601+ }
602+ }
603+
604+ if spec .Partitions .Persistent != nil {
605+ if err := reconcilePartition (spec .Partitions .Persistent ); err != nil {
606+ return err
607+ }
608+ }
609+
610+ if spec .Partitions .OEM != nil {
611+ if err := reconcilePartition (spec .Partitions .OEM ); err != nil {
612+ return err
613+ }
614+ }
615+ return nil
616+ }
617+
618+ func reconcilePartition (part * v1.Partition ) error {
619+ discoveredMountDiskBytes , err := execBlkid (part .FilesystemLabel )
620+ if err != nil {
621+ return fmt .Errorf ("error discovering current partition using label %s: %w" , part .FilesystemLabel , err )
622+ }
623+
624+ // trim space since `blkid` output has a newline in result
625+ discoveredMount := strings .TrimSpace (string (discoveredMountDiskBytes ))
626+ if part .Path != discoveredMount {
627+ part .Path = discoveredMount
628+ }
629+ return nil
630+ }
631+ func execBlkid (name string ) ([]byte , error ) {
632+ path , err := exec .LookPath ("blkid" )
633+ if err != nil {
634+ return nil , err
635+ }
636+
637+ blkidCmd := exec .Command (path , "-L" , name )
638+ return blkidCmd .Output ()
639+ }
0 commit comments