Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion mantle/cmd/kola/qemuexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main
import (
"fmt"
"io/ioutil"
"strings"

v3 "github.com/coreos/ignition/v2/config/v3_0"
v3types "github.com/coreos/ignition/v2/config/v3_0/types"
Expand Down Expand Up @@ -49,6 +50,8 @@ var (
knetargs string

ignitionFragments []string
bindro []string
bindrw []string

forceConfigInjection bool
)
Expand All @@ -62,6 +65,8 @@ func init() {
cmdQemuExec.Flags().StringVarP(&hostname, "hostname", "", "", "Set hostname via DHCP")
cmdQemuExec.Flags().IntVarP(&memory, "memory", "m", 0, "Memory in MB")
cmdQemuExec.Flags().StringVarP(&ignition, "ignition", "i", "", "Path to ignition config")
cmdQemuExec.Flags().StringArrayVar(&bindro, "bind-ro", nil, "Mount readonly via 9pfs a host directory (use --bind-ro=/path/to/host,/var/mnt/guest")
cmdQemuExec.Flags().StringArrayVar(&bindrw, "bind-rw", nil, "Same as above, but writable")
cmdQemuExec.Flags().BoolVarP(&forceConfigInjection, "inject-ignition", "", false, "Force injecting Ignition config using guestfs")
}

Expand All @@ -79,6 +84,14 @@ func renderFragments(config v3types.Config) (*v3types.Config, error) {
return &config, nil
}

func parseBindOpt(s string) (string, string, error) {
parts := strings.SplitN(s, ",", 2)
if len(parts) == 1 {
return "", "", fmt.Errorf("malformed bind option, required: SRC,DEST")
}
return parts[0], parts[1], nil
}

func runQemuExec(cmd *cobra.Command, args []string) error {
var err error
buf, err := ioutil.ReadFile(ignition)
Expand All @@ -97,10 +110,26 @@ func runQemuExec(cmd *cobra.Command, args []string) error {
config = *newconfig
}
builder := platform.NewBuilder()
builder.ForceConfigInjection = forceConfigInjection
for _, b := range bindro {
src, dest, err := parseBindOpt(b)
if err != nil {
return err
}
builder.Mount9p(src, dest, true)
config = v3.Merge(config, conf.Mount9p(dest, true))
}
for _, b := range bindrw {
src, dest, err := parseBindOpt(b)
if err != nil {
return err
}
builder.Mount9p(src, dest, false)
config = v3.Merge(config, conf.Mount9p(dest, false))
}
if err := builder.SetConfig(config, kola.Options.IgnitionVersion == "v2"); err != nil {
return errors.Wrapf(err, "rendering config")
}
builder.ForceConfigInjection = forceConfigInjection
if len(knetargs) > 0 {
builder.IgnitionNetworkKargs = knetargs
}
Expand Down
1 change: 1 addition & 0 deletions mantle/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/aws/aws-sdk-go v1.25.14
github.com/coreos/container-linux-config-transpiler v0.8.0
github.com/coreos/go-semver v0.3.0
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e
github.com/coreos/go-systemd/v22 v22.0.0
github.com/coreos/ign-converter v0.0.0-20200228175238-237c8512310a
github.com/coreos/ignition v0.35.0
Expand Down
33 changes: 33 additions & 0 deletions mantle/platform/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
ignconverter "github.com/coreos/ign-converter"

ct "github.com/coreos/container-linux-config-transpiler/config"
systemdunit "github.com/coreos/go-systemd/unit"
ignerr "github.com/coreos/ignition/config/shared/errors"
v2 "github.com/coreos/ignition/config/v2_0"
v2types "github.com/coreos/ignition/config/v2_0/types"
Expand Down Expand Up @@ -856,3 +857,35 @@ func GetAutologin() v3types.Config {
conf.Systemd.Units = append(conf.Systemd.Units, getAutologinFragment("[email protected]", "--keep-baud 115200,38400,9600"))
return conf
}

func Mount9p(dest string, readonly bool) v3types.Config {
conf := v3types.Config{
Ignition: v3types.Ignition{
Version: "3.0.0",
},
Systemd: v3types.Systemd{},
}
readonlyStr := ""
if readonly {
readonlyStr = ",ro"
}
mntBuf := fmt.Sprintf(`[Unit]
DefaultDependencies=no
After=systemd-tmpfiles-setup.service
Before=basic.target
[Mount]
What=%s
Where=%s
Type=9p
Options=trans=virtio,version=9p2000.L%s
[Install]
WantedBy=multi-user.target
`, dest, dest, readonlyStr)
enable := true
conf.Systemd.Units = append(conf.Systemd.Units, v3types.Unit{
Name: fmt.Sprintf("%s.mount", systemdunit.UnitNameEscape(dest[1:])),
Contents: &mntBuf,
Enabled: &enable,
})
return conf
}
13 changes: 13 additions & 0 deletions mantle/platform/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ type QemuBuilder struct {

finalized bool
diskId uint
fs9pId uint
fds []*os.File
}

Expand Down Expand Up @@ -280,6 +281,18 @@ func (builder *QemuBuilder) EnableUsermodeNetworking(forwardedPort uint) {
builder.Append("-netdev", netdev, "-device", virtio("net", "netdev=eth0"))
}

// Mount9p sets up a mount point from the host to guest. To be replaced
// with https://virtio-fs.gitlab.io/ once it lands everywhere.
func (builder *QemuBuilder) Mount9p(source, destHint string, readonly bool) {
builder.fs9pId += 1
readonlyStr := ""
if readonly {
readonlyStr = ",readonly"
}
builder.Append("--fsdev", fmt.Sprintf("local,id=fs%d,path=%s,security_model=mapped%s", builder.fs9pId, source, readonlyStr))
builder.Append("-device", virtio("9p", fmt.Sprintf("fsdev=fs%d,mount_tag=%s", builder.fs9pId, destHint)))
}

// supportsFwCfg if the target system supports injecting
// Ignition via the qemu -fw_cfg option.
func (builder *QemuBuilder) supportsFwCfg() bool {
Expand Down
15 changes: 4 additions & 11 deletions src/cmd-run
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,6 @@ append_systemd_unit() {
fi
}

if [ -n "${VM_SRV_MNT}" ]; then
set -- --fsdev local,id=var-srv,path="${VM_SRV_MNT}",security_model=mapped,readonly \
-device virtio-9p-"${devtype}",fsdev=var-srv,mount_tag=/var/srv "$@"
# The dependency changes are hacks around https://github.com/coreos/fedora-coreos-tracker/issues/223
append_systemd_unit '{
"name": "var-srv.mount",
"enabled": true,
"contents": "[Unit]\nDefaultDependencies=no\nAfter=systemd-tmpfiles-setup.service\nBefore=basic.target\n[Mount]\nWhat=/var/srv\nWhere=/var/srv\nType=9p\nOptions=ro,trans=virtio,version=9p2000.L\n[Install]\nWantedBy=multi-user.target\n"
}'
fi

if [ -n "${IGNITION_CONFIG_FILE:-}" ]; then
user_config=$(base64 --wrap 0 "${IGNITION_CONFIG_FILE}")
user_config=$(cat << EOF
Expand Down Expand Up @@ -238,6 +227,10 @@ case "${DISK_CHANNEL}" in
*) die "Invalid --disk-channel ${DISK_CHANNEL}" ;;
esac

if [ -n "${VM_SRV_MNT}" ]; then
kola_args+=("--bind-ro=${VM_SRV_MNT},/var/srv")
fi

if [ "${IMAGE_TYPE}" == metal4k ]; then
kola_args+=("--qemu-native-4k")
fi
Expand Down