Skip to content

Commit 33544bd

Browse files
committed
fix: minor improvements to fs
- Do not create target dir for detached mounts; - Use 'ro' flag on ReadOnly mount requests; Signed-off-by: Mateusz Urbanek <mateusz.urbanek@siderolabs.com>
1 parent fd2eebf commit 33544bd

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

internal/app/machined/pkg/controllers/block/mount.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ func (ctrl *MountController) handleDiskMountOperation(
495495

496496
if mountRequest.TypedSpec().ReadOnly {
497497
opts = append(opts, mount.WithReadOnly())
498+
fsOpts = append(fsOpts, fsopen.WithBoolParameter("ro"))
498499
}
499500

500501
if mountRequest.TypedSpec().Detached {

internal/app/machined/pkg/runtime/v1alpha1/platform/metal/metal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ func readConfigFromISO(ctx context.Context, r state.State) ([]byte, error) {
181181
mount.WithPrinter(log.Printf),
182182
mount.WithFsopen(
183183
volumeStatus.TypedSpec().Filesystem.String(),
184+
fsopen.WithBoolParameter("ro"),
184185
fsopen.WithSource(volumeStatus.TypedSpec().MountLocation),
185186
),
186187
)

internal/pkg/mount/v3/manager.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@ func (m *Manager) Mount() (*Point, error) {
8585
MountAttributes: m.mountattr,
8686
}
8787

88-
if err := os.MkdirAll(m.target, 0o755); err != nil {
89-
return nil, fmt.Errorf("failed to create mount target %s: %w", m.target, err)
90-
}
88+
if !m.detached {
89+
if err := os.MkdirAll(m.target, 0o755); err != nil {
90+
return nil, fmt.Errorf("failed to create mount target %s: %w", m.target, err)
91+
}
9192

92-
printer("mounting %q to %q", m.point.Source(), m.target)
93+
printer("mounting %q to %q", m.point.Source(), m.target)
94+
}
9395

9496
if err := m.point.Mount(opts); err != nil {
9597
return nil, fmt.Errorf("failed to mount: %w", err)

internal/pkg/mount/v3/point.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ type Options struct {
5151

5252
// Mount the mount point.
5353
func (p *Point) Mount(opts Options) error {
54+
defer p.Release(false) //nolint:errcheck
55+
56+
if p.detached {
57+
return nil
58+
}
59+
5460
if opts.SkipIfMounted {
5561
isMounted, err := p.IsMounted()
5662
if err != nil {
@@ -62,12 +68,6 @@ func (p *Point) Mount(opts Options) error {
6268
}
6369
}
6470

65-
defer p.Release(false) //nolint:errcheck
66-
67-
if p.detached {
68-
return nil
69-
}
70-
7171
return p.retry(func() error {
7272
if err := p.moveMount(p.target); err != nil {
7373
return fmt.Errorf("error mounting %q to %q: %w", p.Source(), p.target, err)

0 commit comments

Comments
 (0)