fix: when writing to META in the installer/imager, use fixed name
Use fixed partition name instead of trying to auto-discover by label. Auto-discovery by label might hit completely wrong blockdevice. Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
This commit is contained in:
parent
3703041e98
commit
6dc776b8aa
@ -297,9 +297,30 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
|
||||
}
|
||||
|
||||
if mode == ModeUpgrade || len(i.options.MetaValues.values) > 0 {
|
||||
var metaState *meta.Meta
|
||||
var (
|
||||
metaState *meta.Meta
|
||||
metaPartitionName string
|
||||
)
|
||||
|
||||
if metaState, err = meta.New(context.Background(), nil); err != nil {
|
||||
for _, targets := range i.manifest.Targets {
|
||||
for _, target := range targets {
|
||||
if target.Label == constants.MetaPartitionLabel {
|
||||
metaPartitionName = target.PartitionName
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if metaPartitionName != "" {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if metaPartitionName == "" {
|
||||
return fmt.Errorf("failed to detect META partition")
|
||||
}
|
||||
|
||||
if metaState, err = meta.New(context.Background(), nil, meta.WithPrinter(i.options.Printf), meta.WithFixedPath(metaPartitionName)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ type Meta struct {
|
||||
// Options configures the META.
|
||||
type Options struct {
|
||||
fixedPath string
|
||||
printer func(string, ...any)
|
||||
}
|
||||
|
||||
// Option is a functional option.
|
||||
@ -52,10 +53,20 @@ func WithFixedPath(path string) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// WithPrinter sets the function to print the logs, default is log.Printf.
|
||||
func WithPrinter(printer func(string, ...any)) Option {
|
||||
return func(o *Options) {
|
||||
o.printer = printer
|
||||
}
|
||||
}
|
||||
|
||||
// New initializes empty META, trying to probe the existing META first.
|
||||
func New(ctx context.Context, st state.State, opts ...Option) (*Meta, error) {
|
||||
meta := &Meta{
|
||||
state: st,
|
||||
opts: Options{
|
||||
printer: log.Printf,
|
||||
},
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
@ -128,7 +139,7 @@ func (meta *Meta) Reload(ctx context.Context) error {
|
||||
adv.SetTagBytes(t, val)
|
||||
}
|
||||
|
||||
log.Printf("META: loaded %d keys", len(adv.ListTags()))
|
||||
meta.opts.printer("META: loaded %d keys", len(adv.ListTags()))
|
||||
|
||||
meta.talos = adv
|
||||
meta.legacy = legacyAdv
|
||||
@ -221,7 +232,7 @@ func (meta *Meta) Flush() error {
|
||||
return fmt.Errorf("expected to write %d bytes, wrote %d", len(serialized), n)
|
||||
}
|
||||
|
||||
log.Printf("META: saved %d keys", len(meta.talos.ListTags()))
|
||||
meta.opts.printer("META: saved %d keys", len(meta.talos.ListTags()))
|
||||
|
||||
return f.Sync()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user