Skip to content

Commit

Permalink
Support mount propagation flags for newer userspace (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Mar 22, 2023
1 parent b5e11ba commit 464a528
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 111 deletions.
6 changes: 3 additions & 3 deletions cmd/storage/blkid.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ func FetchBlockIDProperties(partitionDevice string) (map[string]string, error) {

props := make(map[string]string)
for _, line := range strings.Split(string(out), "\n") {
keyValue := strings.Split(line, "=")
if len(keyValue) != 2 {
key, value, ok := strings.Cut(line, "=")
if !ok {
continue
}
props[keyValue[0]] = keyValue[1]
props[key] = value
}
return props, nil
}
29 changes: 24 additions & 5 deletions cmd/storage/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/metal-stack/metal-hammer/pkg/os/command"
"github.com/metal-stack/v"
"go.uber.org/zap"
"golang.org/x/exp/slices"
)

type Filesystem struct {
Expand Down Expand Up @@ -495,10 +496,15 @@ func mountFs(log *zap.SugaredLogger, chroot string, fs models.V1Filesystem) (str
}
opts := optionSliceToString(fs.Mountoptions, ",")
log.Infow("mount filesystem", "device", *fs.Device, "path", path, "format", fs.Format, "opts", opts)
err := os.ExecuteCommand("mount", "-o", opts, "-t", *fs.Format, *fs.Device, path)
var args []string
if len(opts) > 0 {
args = append(args, "-o", opts)
}
args = append(args, "-t", *fs.Format, *fs.Device, path)
err := os.ExecuteCommand("mount", args...)
if err != nil {
log.Errorw("mount filesystem failed", "device", *fs.Device, "path", fs.Path, "opts", opts, "error", err)
return "", fmt.Errorf("unable to create filesystem %s on %s %w", *fs.Device, fs.Path, err)
return "", fmt.Errorf("unable to mount filesystem %s on %s opts:%v error:%w", *fs.Device, fs.Path, opts, err)
}
return path, nil
}
Expand All @@ -511,10 +517,23 @@ func depth(path string) uint {
return count
}

// from man mount:
// The command mount does not pass the mount options
// unbindable, runbindable, private, rprivate, slave, rslave, shared, rshared, auto, noauto, comment, x-*, loop, offset and sizelimit
// to the mount.<suffix> helpers. All other options are used in a comma-separated list as an argument to the -o option.
// defaults is special and always set.
var impossibleMountOptions = []string{
"defaults", "unbindable", "runbindable", "private", "rprivate", "slave", "rslave", "shared", "rshared", "auto", "noauto", "comment", "loop", "offset", "sizelimit",
}

func optionSliceToString(opts []string, separator string) string {
mountOpts := make([]string, len(opts))
for i, o := range opts {
mountOpts[i] = string(o)
var mountOpts []string
for _, o := range opts {
option := string(o)
if slices.Contains(impossibleMountOptions, option) || strings.HasPrefix(option, "x-") {
continue
}
mountOpts = append(mountOpts, option)
}
return strings.Join(mountOpts, separator)
}
Expand Down
55 changes: 28 additions & 27 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,42 +4,43 @@ go 1.20

require (
github.com/beevik/ntp v0.3.0
github.com/cheggaaa/pb/v3 v3.1.0
github.com/cheggaaa/pb/v3 v3.1.2
github.com/google/gopacket v1.1.19
github.com/google/uuid v1.3.0
github.com/jaypipes/ghw v0.9.0
github.com/metal-stack/go-hal v0.4.2
github.com/metal-stack/go-lldpd v0.4.2
github.com/metal-stack/metal-api v0.22.2
github.com/metal-stack/metal-go v0.21.4
github.com/jaypipes/ghw v0.10.0
github.com/metal-stack/go-hal v0.4.3
github.com/metal-stack/go-lldpd v0.4.3
github.com/metal-stack/metal-api v0.22.3
github.com/metal-stack/metal-go v0.22.3
github.com/metal-stack/pixie v0.2.2
github.com/metal-stack/v v1.0.3
// archiver must stay in version v2.1.0, see replace below
github.com/mholt/archiver v3.1.1+incompatible
github.com/pierrec/lz4/v4 v4.1.17
github.com/u-root/u-root v0.10.0
github.com/u-root/u-root v0.11.0
github.com/vishvananda/netlink v1.2.1-beta.2
go.uber.org/zap v1.24.0
golang.org/x/exp v0.0.0-20230306221820-f0f767cdffd6
golang.org/x/sync v0.1.0
golang.org/x/sys v0.5.0
golang.org/x/sys v0.6.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
google.golang.org/protobuf v1.30.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/VividCortex/ewma v1.2.0 // indirect
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/avast/retry-go/v4 v4.3.3 // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
github.com/creack/pty v1.1.18 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dsnet/compress v0.0.1 // indirect
github.com/fatih/color v1.14.1 // indirect
github.com/frankban/quicktest v1.14.3 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/frankban/quicktest v1.14.4 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gliderlabs/ssh v0.3.5 // indirect
github.com/go-jose/go-jose/v3 v3.0.0 // indirect
Expand All @@ -53,12 +54,12 @@ require (
github.com/go-openapi/loads v0.21.2 // indirect
github.com/go-openapi/runtime v0.25.0 // indirect
github.com/go-openapi/spec v0.20.8 // indirect
github.com/go-openapi/strfmt v0.21.3 // indirect
github.com/go-openapi/strfmt v0.21.5 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
github.com/go-openapi/validate v0.22.0 // indirect
github.com/goccy/go-json v0.10.0 // indirect
github.com/go-openapi/validate v0.22.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
Expand All @@ -75,7 +76,7 @@ require (
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mdlayher/ethernet v0.0.0-20220221185849-529eae5b6118 // indirect
github.com/mdlayher/lldp v0.0.0-20150915211757-afd9f83164c5 // indirect
github.com/metal-stack/metal-lib v0.11.3 // indirect
github.com/metal-stack/metal-lib v0.11.6 // indirect
github.com/metal-stack/security v0.6.6 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
Expand All @@ -84,23 +85,23 @@ require (
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sethvargo/go-password v0.2.0 // indirect
github.com/stmcginnis/gofish v0.13.0 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/vishvananda/netns v0.0.4 // indirect
github.com/vmware/goipmi v0.0.0-20181114221114-2333cd82d702 // indirect
go.mongodb.org/mongo-driver v1.11.1 // indirect
go.opentelemetry.io/otel v1.11.1 // indirect
go.opentelemetry.io/otel/trace v1.11.1 // indirect
go.mongodb.org/mongo-driver v1.11.3 // indirect
go.opentelemetry.io/otel v1.14.0 // indirect
go.opentelemetry.io/otel/trace v1.14.0 // indirect
go.uber.org/atomic v1.10.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.7.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230222225845-10f96fb3dbec // indirect
google.golang.org/genproto v0.0.0-20230320184635-7606e756e683 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
howett.net/plist v1.0.0 // indirect
Expand Down
Loading

0 comments on commit 464a528

Please sign in to comment.