-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tool to install modules in lcow and plumb through
Signed-off-by: Kathryn Baldauf <[email protected]>
- Loading branch information
1 parent
5f5e3ea
commit d76a8dc
Showing
52 changed files
with
1,861 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// +build linux | ||
|
||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io/fs" | ||
"os" | ||
"os/exec" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/Microsoft/hcsshim/internal/guest/storage/overlay" | ||
"github.com/google/uuid" | ||
"github.com/pkg/errors" | ||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
lcowGlobalDriversFormat = "/run/drivers/%s" | ||
|
||
moduleExtension = ".ko" | ||
) | ||
|
||
func install(ctx context.Context) error { | ||
args := []string(os.Args[1:]) | ||
|
||
if len(args) == 0 { | ||
return errors.New("no driver paths provided for install") | ||
} | ||
|
||
for _, driver := range args { | ||
modules := []string{} | ||
|
||
driverGUID, err := uuid.NewRandom() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// create an overlay mount from the driver's UVM path so we can write to the | ||
// mount path in the UVM despite having mounted in the driver originally as | ||
// readonly | ||
runDriverPath := fmt.Sprintf(lcowGlobalDriversFormat, driverGUID.String()) | ||
upperPath := filepath.Join(runDriverPath, "upper") | ||
workPath := filepath.Join(runDriverPath, "work") | ||
rootPath := filepath.Join(runDriverPath, "content") | ||
if err := overlay.Mount(ctx, []string{driver}, upperPath, workPath, rootPath, false); err != nil { | ||
return err | ||
} | ||
|
||
// find all module files, which end with ".ko" extension, and remove extension | ||
// for use when calling `modprobe` below. | ||
if walkErr := filepath.WalkDir(rootPath, func(path string, d fs.DirEntry, err error) error { | ||
if err != nil { | ||
return errors.Wrap(err, "failed to read directory while walking dir") | ||
} | ||
if !d.IsDir() && filepath.Ext(d.Name()) == moduleExtension { | ||
moduleName := strings.TrimSuffix(d.Name(), moduleExtension) | ||
modules = append(modules, moduleName) | ||
} | ||
return nil | ||
}); walkErr != nil { | ||
return walkErr | ||
} | ||
|
||
// create a new module dependency map database for the driver | ||
depmodArgs := []string{"-b", rootPath} | ||
cmd := exec.Command("depmod", depmodArgs...) | ||
out, err := cmd.CombinedOutput() | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to run depmod with args %v: %s", depmodArgs, out) | ||
} | ||
|
||
// run modprobe for every module name found | ||
modprobeArgs := append([]string{"-d", rootPath, "-a"}, modules...) | ||
cmd = exec.Command( | ||
"modprobe", | ||
modprobeArgs..., | ||
) | ||
|
||
out, err = cmd.CombinedOutput() | ||
if err != nil { | ||
return errors.Wrapf(err, "failed to run modporbe with args %v: %s", modprobeArgs, out) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func installDriversMain() { | ||
ctx := context.Background() | ||
logrus.SetOutput(os.Stderr) | ||
if err := install(ctx); err != nil { | ||
logrus.Fatalf("error in install drivers: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.