diff --git a/go.mod b/go.mod index 5d5a23b3..61f2a478 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ require ( github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect github.com/mattn/go-isatty v0.0.10 github.com/otiai10/copy v1.0.2 + github.com/paultag/go-modprobe v0.0.0-20180523225901-7ccf6a1b5271 github.com/pkg/errors v0.8.1 github.com/rancher/mapper v0.0.0-20190814232720-058a8b7feb99 github.com/rancher/wrangler v0.3.1 // indirect @@ -18,6 +19,7 @@ require ( golang.org/x/crypto v0.0.0-20191122220453-ac88ee75c92c golang.org/x/sys v0.0.0-20191127021746-63cb32ae39b2 gopkg.in/freddierice/go-losetup.v1 v1.0.0-20170407175016-fc9adea44124 + pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a // indirect ) replace ( diff --git a/go.sum b/go.sum index 3e079d39..ffdd0e53 100644 --- a/go.sum +++ b/go.sum @@ -195,6 +195,8 @@ github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95 h1:+OLn68pqasWca0z5ry github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= github.com/otiai10/mint v1.3.0 h1:Ady6MKVezQwHBkGzLFbrsywyp09Ah7rkmfjV3Bcr5uc= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= +github.com/paultag/go-modprobe v0.0.0-20180523225901-7ccf6a1b5271 h1:e30yoZNGiwZszhX/zRYOOc56xHpsZFUC7CeBhcmmivM= +github.com/paultag/go-modprobe v0.0.0-20180523225901-7ccf6a1b5271/go.mod h1:8kv7zKfUEDKENYA4Wk+cT1bxjXaEiuYisqjRZGGNI84= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic= github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU= @@ -399,6 +401,8 @@ modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk= modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k= modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs= modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I= +pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a h1:WwS7vlB5H2AtwKj1jsGwp2ZLud1x6WXRXh2fXsRqrcA= +pault.ag/go/topsort v0.0.0-20160530003732-f98d2ad46e1a/go.mod h1:INqx0ClF7kmPAMk2zVTX8DRnhZ/yaA/Mg52g8KFKE7k= sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI= sigs.k8s.io/structured-merge-diff v0.0.0-20190817042607-6149e4549fca/go.mod h1:IIgPezJWb76P0hotTxzDbWsMYB8APh18qZnxkomBpxA= sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs= diff --git a/pkg/module/module.go b/pkg/module/module.go index 3c974ead..c1b93cfa 100644 --- a/pkg/module/module.go +++ b/pkg/module/module.go @@ -4,12 +4,11 @@ import ( "bufio" "fmt" "os" - "path/filepath" "strings" + "github.com/paultag/go-modprobe" "github.com/rancher/k3os/pkg/config" "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" ) const ( @@ -34,36 +33,10 @@ func LoadModules(cfg *config.CloudConfig) error { } params := strings.SplitN(m, " ", -1) logrus.Debugf("module %s with parameters [%s] is loading", m, params) - if err := modprobe(params[0], params[1:]); err != nil { + if err := modprobe.Load(params[0], strings.Join(params[1:], " ")); err != nil { return fmt.Errorf("could not load module %s with parameters [%s], err %v", m, params, err) } logrus.Debugf("module %s is loaded", m) } return sc.Err() } - -func modprobe(module string, params []string) error { - uname := unix.Utsname{} - if err := unix.Uname(&uname); err != nil { - return fmt.Errorf("unable to determine uname, err %v", err) - } - i := 0 - for ; uname.Release[i] != 0; i++ { - } - pth := fmt.Sprintf("/lib/modules/%s/**/%s.ko", uname.Release[:i], module) - files, err := filepath.Glob(pth) - if err != nil { - return fmt.Errorf("unable to search for module, err %v", err) - } - if len(files) == 0 { - return fmt.Errorf("module not found") - } - file, err := os.Open(files[0]) - if err != nil { - return fmt.Errorf("could not open module file %s, err %v", files[0], err) - } - if err := unix.FinitModule(int(file.Fd()), strings.Join(params, " "), 0); err != nil { - return fmt.Errorf("unable to load module, err %v", err) - } - return nil -}