Skip to content

Commit

Permalink
Added s390x layout feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhu authored and Madhu committed Aug 2, 2023
1 parent 65e7f02 commit 561ce19
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 2 deletions.
1 change: 1 addition & 0 deletions config/fcos/v1_6_exp/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type BootDevice struct {

type BootDeviceLuks struct {
Discard *bool `yaml:"discard"`
Device *string `yaml:"device"`
Tang []base.Tang `yaml:"tang"`
Threshold *int `yaml:"threshold"`
Tpm2 *bool `yaml:"tpm2"`
Expand Down
62 changes: 61 additions & 1 deletion config/fcos/v1_6_exp/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ package v1_6_exp
import (
"fmt"
"strings"
"regexp"
"strconv"

baseutil "github.com/coreos/butane/base/util"
"github.com/coreos/butane/config/common"
Expand All @@ -29,6 +31,11 @@ import (
"github.com/coreos/vcontext/report"
)

var (
dasdRe = regexp.MustCompile("(/dev/dasd[a-z]$)")
sdRe = regexp.MustCompile("(/dev/sd[a-z]$)")
)

const (
reservedTypeGuid = "8DA63339-0007-60C0-C436-083AC8230908"
biosTypeGuid = "21686148-6449-6E6F-744E-656564454649"
Expand Down Expand Up @@ -109,16 +116,25 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio
var r report.Report

// check for high-level features
wantLuks := util.IsTrue(c.BootDevice.Luks.Tpm2) || len(c.BootDevice.Luks.Tang) > 0
wantLuks := util.IsTrue(c.BootDevice.Luks.Tpm2) || len(c.BootDevice.Luks.Tang) > 0
wantLuksDevice := len(c.BootDeviceLuks.Device) > 0 && len(c.BootDevice.Luks.Tang) > 0
wantMirror := len(c.BootDevice.Mirror.Devices) > 0
if !wantLuks && !wantMirror {
return r
}

// s390x zfcp and dasd does not support mirror
if wantLuksDevice && wantMirror {
return r
}

// compute layout rendering options
var wantBIOSPart bool
var wantEFIPart bool
var wantPRePPart bool
var wantMBR bool
var wantDasd bool
var wantKVM bool
layout := c.BootDevice.Layout
switch {
case layout == nil || *layout == "x86_64":
Expand All @@ -128,6 +144,14 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio
wantEFIPart = true
case *layout == "ppc64le":
wantPRePPart = true
case *layout == "s390x-zfcp":
wantMBR = true
case *layout == "s390x-eckd":
wantDasd = true
case *layout == "s390x-virt":
wantBIOSPart = true
wantEFIPart = true

default:
// should have failed validation
panic("unknown layout")
Expand Down Expand Up @@ -258,6 +282,42 @@ func (c Config) processBootDevice(config *types.Config, ts *translate.Translatio
renderedTranslations.AddTranslation(lpath, path.New("json", "storage", "luks"))
r.Merge(r2)
}

//encrypted root partition for s390x
if wantLuksDevice {
var luksDevice string
dasd := dasdRe.FindString(c.BootDeviceLuks.Device)
sd := sdRe.FindString(c.BootDeviceLuks.Device)

switch {
case wantMBR && len(sd) != 0:
luksDevice = sd + strconv.Itoa(2)
case wantDasd && len(dasd) != 0:
luksDevice = dasd + strconv.Itoa(2)
default:
panic("can't happen")
}
clevis, ts2, r2 := translateBootDeviceLuks(c.BootDevice.Luks, options)
rendered.Storage.Luks = []types.Luks{{
Clevis: clevis,
Device: &luksDevice,
Discard: c.BootDevice.Luks.Discard,
Label: util.StrToPtr("luks-root"),
Name: "root",
WipeVolume: util.BoolToPtr(true),
}}
lpath := path.New("yaml", "boot_device", "luks")
rpath := path.New("json", "storage", "luks", 0)
renderedTranslations.Merge(ts2.PrefixPaths(lpath, rpath.Append("clevis")))
renderedTranslations.AddTranslation(lpath.Append("discard"), rpath.Append("discard"))
for _, f := range []string{"device", "label", "name", "wipeVolume"} {
renderedTranslations.AddTranslation(lpath, rpath.Append(f))
}
renderedTranslations.AddTranslation(lpath, rpath)
renderedTranslations.AddTranslation(lpath, path.New("json", "storage", "luks"))
r.Merge(r2)

}

// create root filesystem
var rootDevice string
Expand Down
2 changes: 1 addition & 1 deletion config/fcos/v1_6_exp/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
func (d BootDevice) Validate(c path.ContextPath) (r report.Report) {
if d.Layout != nil {
switch *d.Layout {
case "aarch64", "ppc64le", "x86_64":
case "aarch64", "ppc64le", "x86_64", "s390x-zfcp", "s390x-eckd", "s390x-virt":
default:
r.AddOnError(c.Append("layout"), common.ErrUnknownBootDeviceLayout)
}
Expand Down

0 comments on commit 561ce19

Please sign in to comment.