Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dsseng committed Dec 5, 2024
1 parent 8f4daef commit 6aed532
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 29 deletions.
68 changes: 43 additions & 25 deletions internal/app/machined/pkg/controllers/runtime/fs_scrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,36 +110,62 @@ func (ctrl *FSScrubController) Run(ctx context.Context, r controller.Runtime, lo
logger.Error("error running filesystem scrub", zap.Error(err))
}
case <-r.EventCh():
err := ctrl.updateSchedule(ctx, r, logger)
err := ctrl.updateSchedule(ctx, r)
if err != nil {
return err
}
}

r.StartTrackingOutputs()
if err := ctrl.reportStatus(ctx, r); err != nil {
return err
}
}
}

for _, entry := range ctrl.status {
if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error {
status.TypedSpec().Mountpoint = entry.mountpoint
status.TypedSpec().Period = entry.period
status.TypedSpec().Time = entry.time
status.TypedSpec().Duration = entry.duration
status.TypedSpec().Status = entry.result.Error()
func (ctrl *FSScrubController) reportStatus(ctx context.Context, r controller.Runtime) error {
r.StartTrackingOutputs()

return nil
}); err != nil {
return fmt.Errorf("error updating filesystem scrub status: %w", err)
presentStatuses, err := safe.ReaderListAll[*runtimeres.FSScrubStatus](ctx, r)
if err != nil && !state.IsNotFoundError(err) {
return fmt.Errorf("error getting existing FS scrub statuses: %w", err)
}

for entry := range presentStatuses.All() {
if _, ok := ctrl.status[entry.TypedSpec().Mountpoint]; !ok {
if err := r.Destroy(ctx, runtimeres.NewFSScrubStatus(entry.Metadata().ID()).Metadata()); err != nil {
return fmt.Errorf("error destroying old FS scrub status: %w", err)
}
}
}

if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil {
return err
for _, entry := range ctrl.status {
if err := safe.WriterModify(ctx, r, runtimeres.NewFSScrubStatus(entry.id), func(status *runtimeres.FSScrubStatus) error {
status.TypedSpec().Mountpoint = entry.mountpoint
status.TypedSpec().Period = entry.period
status.TypedSpec().Time = entry.time
status.TypedSpec().Duration = entry.duration

if entry.result != nil {
status.TypedSpec().Status = entry.result.Error()
} else {
status.TypedSpec().Status = "success"
}

return nil
}); err != nil {
return fmt.Errorf("error updating filesystem scrub status: %w", err)
}
}

if err := safe.CleanupOutputs[*runtimeres.FSScrubStatus](ctx, r); err != nil {
return err
}

return nil
}

//nolint:gocyclo,cyclop
func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime, logger *zap.Logger) error {
func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.Runtime) error {
volumesStatus, err := safe.ReaderListAll[*block.VolumeStatus](ctx, r)
if err != nil && !state.IsNotFoundError(err) {
return fmt.Errorf("error getting volume status: %w", err)
Expand Down Expand Up @@ -207,8 +233,6 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
_, ok := ctrl.schedule[mountpoint]

if period == nil {
logger.Warn("!!! scrub !!! not in config, descheduling", zap.String("mountpoint", mountpoint))

if ok {
ctrl.cancelScrub(mountpoint)
}
Expand All @@ -218,12 +242,10 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.

if !ok {
firstTimeout := time.Duration(rand.Int64N(int64(period.Seconds()))) * time.Second
logger.Warn("!!! scrub !!! firstTimeout", zap.Duration("firstTimeout", firstTimeout))

// When scheduling the first scrub, we use a random time to avoid all scrubs running in a row.
// After the first scrub, we use the period defined in the config.
cb := func() {
logger.Warn("!!! scrub !!! ding", zap.String("path", mountpoint))
ctrl.c <- mountpoint
ctrl.schedule[mountpoint].timer.Reset(ctrl.schedule[mountpoint].period)
}
Expand All @@ -242,12 +264,8 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
duration: 0,
result: fmt.Errorf("scheduled"),
}

logger.Warn("!!! scrub !!! scheduled", zap.String("path", mountpoint), zap.Duration("period", *period))
} else if ctrl.schedule[mountpoint].period != *period {
// reschedule if period has changed
logger.Warn("!!! scrub !!! reschedule", zap.String("path", mountpoint), zap.Duration("period", *period))

ctrl.schedule[mountpoint].timer.Stop()
ctrl.schedule[mountpoint].timer.Reset(*period)
ctrl.schedule[mountpoint] = scrubSchedule{
Expand All @@ -259,7 +277,7 @@ func (ctrl *FSScrubController) updateSchedule(ctx context.Context, r controller.
id: item.Metadata().ID(),
mountpoint: mountpoint,
period: *period,
time: time.Now().Add(*period),
time: ctrl.status[mountpoint].time,
duration: ctrl.status[mountpoint].duration,
result: ctrl.status[mountpoint].result,
}
Expand Down Expand Up @@ -304,7 +322,7 @@ func (ctrl *FSScrubController) runScrub(mountpoint string, opts []string) error
mountpoint: mountpoint,
period: ctrl.schedule[mountpoint].period,
time: start,
duration: time.Now().Sub(start),
duration: time.Since(start),
result: err,
}

Expand Down
1 change: 0 additions & 1 deletion pkg/machinery/config/types/runtime/fs_scrub.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
const FilesystemScrubKind = "FilesystemScrubConfig"

func init() {
fmt.Println("TEST! FilesystemScrubKind: ", FilesystemScrubKind)
registry.Register(FilesystemScrubKind, func(version string) config.Document {
switch version {
case "v1alpha1":
Expand Down
2 changes: 0 additions & 2 deletions pkg/machinery/config/types/runtime/kmsg_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package runtime

import (
"errors"
"fmt"
"net/url"

"github.com/siderolabs/gen/ensure"
Expand All @@ -23,7 +22,6 @@ import (
const KmsgLogKind = "KmsgLogConfig"

func init() {
fmt.Println("AAAAA! KmsgLogKind: ", KmsgLogKind)
registry.Register(KmsgLogKind, func(version string) config.Document {
switch version {
case "v1alpha1":
Expand Down
2 changes: 1 addition & 1 deletion pkg/machinery/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ var DefaultDroppedCapabilities = map[string]struct{}{
}

// XFSScrubDroppedCapabilities is the set of capabilities to drop for xfs_scrub.
// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio
// All but cap_sys_admin cap_fowner cap_dac_override cap_dac_read_search cap_sys_rawio.
var XFSScrubDroppedCapabilities = map[string]struct{}{
"cap_audit_control": {},
"cap_audit_write": {},
Expand Down
20 changes: 20 additions & 0 deletions website/content/v1.9/reference/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ description: Talos gRPC API reference.
- [ExtensionServiceConfigSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigSpec)
- [ExtensionServiceConfigStatusSpec](#talos.resource.definitions.runtime.ExtensionServiceConfigStatusSpec)
- [FSScrubConfigSpec](#talos.resource.definitions.runtime.FSScrubConfigSpec)
- [FSScrubStatusSpec](#talos.resource.definitions.runtime.FSScrubStatusSpec)
- [KernelModuleSpecSpec](#talos.resource.definitions.runtime.KernelModuleSpecSpec)
- [KernelParamSpecSpec](#talos.resource.definitions.runtime.KernelParamSpecSpec)
- [KernelParamStatusSpec](#talos.resource.definitions.runtime.KernelParamStatusSpec)
Expand Down Expand Up @@ -4680,6 +4681,25 @@ FSScrubConfigSpec describes configuration of watchdog timer.



<a name="talos.resource.definitions.runtime.FSScrubStatusSpec"></a>

### FSScrubStatusSpec
FSScrubStatusSpec describes configuration of watchdog timer.


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| mountpoint | [string](#string) | | |
| period | [google.protobuf.Duration](#google.protobuf.Duration) | | |
| time | [google.protobuf.Timestamp](#google.protobuf.Timestamp) | | |
| duration | [google.protobuf.Duration](#google.protobuf.Duration) | | |
| status | [string](#string) | | |






<a name="talos.resource.definitions.runtime.KernelModuleSpecSpec"></a>

### KernelModuleSpecSpec
Expand Down

0 comments on commit 6aed532

Please sign in to comment.