Skip to content

Commit 6dc776b

Browse files
committed
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>
1 parent 3703041 commit 6dc776b

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

cmd/installer/pkg/install/install.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,9 +297,30 @@ func (i *Installer) Install(ctx context.Context, mode Mode) (err error) {
297297
}
298298

299299
if mode == ModeUpgrade || len(i.options.MetaValues.values) > 0 {
300-
var metaState *meta.Meta
300+
var (
301+
metaState *meta.Meta
302+
metaPartitionName string
303+
)
301304

302-
if metaState, err = meta.New(context.Background(), nil); err != nil {
305+
for _, targets := range i.manifest.Targets {
306+
for _, target := range targets {
307+
if target.Label == constants.MetaPartitionLabel {
308+
metaPartitionName = target.PartitionName
309+
310+
break
311+
}
312+
}
313+
314+
if metaPartitionName != "" {
315+
break
316+
}
317+
}
318+
319+
if metaPartitionName == "" {
320+
return fmt.Errorf("failed to detect META partition")
321+
}
322+
323+
if metaState, err = meta.New(context.Background(), nil, meta.WithPrinter(i.options.Printf), meta.WithFixedPath(metaPartitionName)); err != nil {
303324
return err
304325
}
305326

internal/pkg/meta/meta.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Meta struct {
4040
// Options configures the META.
4141
type Options struct {
4242
fixedPath string
43+
printer func(string, ...any)
4344
}
4445

4546
// Option is a functional option.
@@ -52,10 +53,20 @@ func WithFixedPath(path string) Option {
5253
}
5354
}
5455

56+
// WithPrinter sets the function to print the logs, default is log.Printf.
57+
func WithPrinter(printer func(string, ...any)) Option {
58+
return func(o *Options) {
59+
o.printer = printer
60+
}
61+
}
62+
5563
// New initializes empty META, trying to probe the existing META first.
5664
func New(ctx context.Context, st state.State, opts ...Option) (*Meta, error) {
5765
meta := &Meta{
5866
state: st,
67+
opts: Options{
68+
printer: log.Printf,
69+
},
5970
}
6071

6172
for _, opt := range opts {
@@ -128,7 +139,7 @@ func (meta *Meta) Reload(ctx context.Context) error {
128139
adv.SetTagBytes(t, val)
129140
}
130141

131-
log.Printf("META: loaded %d keys", len(adv.ListTags()))
142+
meta.opts.printer("META: loaded %d keys", len(adv.ListTags()))
132143

133144
meta.talos = adv
134145
meta.legacy = legacyAdv
@@ -221,7 +232,7 @@ func (meta *Meta) Flush() error {
221232
return fmt.Errorf("expected to write %d bytes, wrote %d", len(serialized), n)
222233
}
223234

224-
log.Printf("META: saved %d keys", len(meta.talos.ListTags()))
235+
meta.opts.printer("META: saved %d keys", len(meta.talos.ListTags()))
225236

226237
return f.Sync()
227238
}

0 commit comments

Comments
 (0)