Skip to content

Commit

Permalink
fix: do not format state partition in the initialize sequence
Browse files Browse the repository at this point in the history
Initialize state should be only reading the config.
So now if it detects that the partition is not even formatted it will
skip it and will consider the state to be empty.

Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
  • Loading branch information
Unix4ever authored and talos-bot committed Jun 17, 2021
1 parent b609f33 commit 2dc27d9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
1 change: 1 addition & 0 deletions .drone.jsonnet
Expand Up @@ -367,6 +367,7 @@ local integration_disk_image = Step("e2e-disk-image", target="e2e-qemu", privile
"SHORT_INTEGRATION_TEST": "yes",
"USE_DISK_IMAGE": "true",
"IMAGE_REGISTRY": local_registry,
"WITH_DISK_ENCRYPTION": "true",
});
local integration_canal_reset = Step("e2e-canal-reset", target="e2e-qemu", privileged=true, depends_on=[integration_disk_image], environment={
"INTEGRATION_TEST_RUN": "TestIntegration/api.ResetSuite/TestResetWithSpec",
Expand Down
Expand Up @@ -184,6 +184,10 @@ func (*Sequencer) Boot(r runtime.Runtime) []runtime.Phase {
phases := PhaseList{}

phases = phases.AppendWhen(
r.State().Platform().Mode() != runtime.ModeContainer,
"saveStateEncryptionConfig",
SaveStateEncryptionConfig,
).AppendWhen(
r.State().Platform().Mode() != runtime.ModeContainer,
"mountState",
MountStatePartition,
Expand Down
Expand Up @@ -1485,7 +1485,13 @@ func MountStatePartition(seq runtime.Sequence, data interface{}) (runtime.TaskEx
//nolint:errcheck
defer meta.Close()

opts := []mount.Option{mount.WithFlags(mount.SkipIfMounted)}
flags := mount.SkipIfMounted

if seq == runtime.SequenceInitialize {
flags |= mount.SkipIfNoFilesystem
}

opts := []mount.Option{mount.WithFlags(flags)}

var encryption config.Encryption
// first try reading encryption from the config
Expand Down
6 changes: 6 additions & 0 deletions internal/pkg/mount/mount.go
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/talos-systems/go-blockdevice/blockdevice"
"github.com/talos-systems/go-blockdevice/blockdevice/filesystem"
"github.com/talos-systems/go-blockdevice/blockdevice/util"
"github.com/talos-systems/go-retry/retry"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -44,6 +45,7 @@ func Mount(mountpoints *Points) (err error) {
return nil
}

//nolint:gocyclo
func mountMountpoint(mountpoint *Point) (err error) {
var skipMount bool

Expand All @@ -61,6 +63,10 @@ func mountMountpoint(mountpoint *Point) (err error) {
}
}

if mountpoint.MountFlags.Check(SkipIfNoFilesystem) && mountpoint.Fstype() == filesystem.Unknown {
skipMount = true
}

if !skipMount {
if err = mountpoint.Mount(); err != nil {
return fmt.Errorf("error mounting: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/mount/options.go
Expand Up @@ -19,6 +19,8 @@ const (
Overlay
// SkipIfMounted is a flag for skipping mount if the mountpoint is already mounted.
SkipIfMounted
// SkipIfNoFilesystem is a flag for skipping formatting and mounting if the mountpoint has not filesystem.
SkipIfNoFilesystem
)

// Flags is the mount flags.
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/mount/system.go
Expand Up @@ -157,9 +157,13 @@ func SystemMountPointForLabel(device *blockdevice.BlockDevice, label string, opt
return fmt.Errorf("failed to determine format options for partition label %s", part.Name)
}

p.fstype = opts.FileSystemType
if !o.MountFlags.Check(SkipIfNoFilesystem) {
p.fstype = opts.FileSystemType

return partition.Format(p.source, opts)
return partition.Format(p.source, opts)
}

return nil
})

opts = append(opts, WithPreMountHooks(preMountHooks...))
Expand Down

0 comments on commit 2dc27d9

Please sign in to comment.