mirror of
https://github.com/siderolabs/talos.git
synced 2025-10-26 22:11:38 +01:00
This implements the first round of changes, replacing the volume backend with the new implementation, while keeping most of the external interfaces intact. See #8367 Signed-off-by: Andrey Smirnov <andrey.smirnov@siderolabs.com>
58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package mount
|
|
|
|
import (
|
|
"errors"
|
|
"slices"
|
|
)
|
|
|
|
// Points is a list of mount points.
|
|
type Points []*Point
|
|
|
|
// Mount all mount points.
|
|
func (points Points) Mount(opts ...OperationOption) (unmounter func() error, err error) {
|
|
unmounters := make([]func() error, 0, len(points))
|
|
|
|
for _, point := range points {
|
|
unmounter, err := point.Mount(opts...)
|
|
if err != nil {
|
|
// unmount what got already mounted
|
|
slices.Reverse(unmounters)
|
|
|
|
for _, unmounter := range unmounters {
|
|
_ = unmounter() //nolint:errcheck
|
|
}
|
|
|
|
return nil, err
|
|
}
|
|
|
|
unmounters = append(unmounters, unmounter)
|
|
}
|
|
|
|
slices.Reverse(unmounters)
|
|
|
|
return func() error {
|
|
var unmountErr error
|
|
|
|
for _, unmounter := range unmounters {
|
|
unmountErr = errors.Join(unmounter())
|
|
}
|
|
|
|
return unmountErr
|
|
}, nil
|
|
}
|
|
|
|
// Unmount all mount points.
|
|
func (points Points) Unmount() error {
|
|
for i := len(points) - 1; i >= 0; i-- {
|
|
if err := points[i].Unmount(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|