Skip to content

Commit

Permalink
Add global config for FML mode custom resolution
Browse files Browse the repository at this point in the history
Add a new global config value app.fml.resolution to set custom resolution
for FML apps. This is a string value in the format of "widthxheight".

This value can be set device-wide as a global config value or set
in a per-app/vm setting by defining it as top-level variable in
the cloud-config.

Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
  • Loading branch information
shjala authored and OhmSpectator committed Sep 20, 2024
1 parent 271a59f commit ab40145
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/CONFIG-PROPERTIES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
| Name | Type | Default | Description |
| ---- | ---- | ------- | ----------- |
| app.allow.vnc | boolean | false (only local access) | allow access to EVE's VNC ports from external IPs |
| app.fml.resolution | string | notset | Set system-wide value of forced resolution for applications running in FML mode, it can be one of [predefined](/pkg/pillar/types/global.go) FmlResolution* values. |
| timer.config.interval | integer in seconds | 60 | how frequently device gets config |
| timer.cert.interval | integer in seconds | 1 day (24*3600) | how frequently device checks for new controller certificates |
| timer.metric.interval | integer in seconds | 60 | how frequently device reports metrics |
Expand Down
25 changes: 25 additions & 0 deletions pkg/pillar/cmd/domainmgr/domainmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
uuid "github.com/satori/go.uuid"
"github.com/sirupsen/logrus"
"github.com/vishvananda/netlink"
"gopkg.in/yaml.v2"
)

const (
Expand Down Expand Up @@ -2067,6 +2068,14 @@ func configToStatus(ctx *domainContext, config types.DomainConfig,
return fmt.Errorf("failed to fetch cloud-init userdata: %s",
err)
}

// Set FML custom resolution if it is set in cloud-init config,
// xxx : this is hack and this should be removed, this should be
// part of the vm config, but desprate times call for desprate measures.
if cloudconfig.IsCloudConfig(ciStr) {
setFmlCustomResolution(ciStr, status)
}

if status.OCIConfigDir != "" { // If AppInstance is a container, we need to parse cloud-init config and apply the supported parts
if cloudconfig.IsCloudConfig(ciStr) { // treat like the cloud-init config
cc, err := cloudconfig.ParseCloudConfig(ciStr)
Expand Down Expand Up @@ -2113,6 +2122,22 @@ func configToStatus(ctx *domainContext, config types.DomainConfig,
return nil
}

func setFmlCustomResolution(config string, status *types.DomainStatus) {
var cloudinit map[string]interface{}
err := yaml.Unmarshal([]byte(config), &cloudinit)
if err != nil {
log.Errorf("error parsing cloud-config YAML: %v", err)
return
}

if val, ok := cloudinit[string(types.FmlCustomResolution)]; ok {
if fmlCustomResolution, valid := val.(string); valid {
status.FmlCustomResolution = fmlCustomResolution
log.Noticef("FML resolution is set to: %s", status.FmlCustomResolution)
}
}
}

// Check for errors and reserve any assigned adapters.
// Please note that reservation is done only by setting UsedByUUID to the application UUID.
// The actual call to PCIReserve() is done later by doAssignIoAdaptersToDomain().
Expand Down
36 changes: 36 additions & 0 deletions pkg/pillar/hypervisor/kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,14 @@ func (ctx KvmContext) Setup(status types.DomainStatus, config types.DomainConfig
domainName := status.DomainName
domainUUID := status.UUIDandVersion.UUID

// this needs to be reworked to fit into the OVMF_VAR changes.
res, err := getFmlCustomResolution(&status, globalConfig)
if err != nil {
logError("failed to get fml custom resolution: %v", err)
} else {
logError("fml custom resolution is set to: %s", res)
}

// check if vTPM is enabled
swtpmCtrlSock := ""
if status.VirtualTPM {
Expand Down Expand Up @@ -867,6 +875,34 @@ func isVncShimVMEnabled(
return config.EnableVnc && (config.EnableVncShimVM || globalShimVnc)
}

func getFmlCustomResolution(status *types.DomainStatus, globalConfig *types.ConfigItemValueMap) (string, error) {
fmlResolutions := status.FmlCustomResolution
// if not set in the domain status, try to get it from the global config
if fmlResolutions == types.FmlResolutionUnset {
if globalConfig != nil {
item, ok := globalConfig.GlobalSettings[types.FmlCustomResolution]
if ok {
fmlResolutions = item.StringValue()
}
}
}

// debug, remove later
logError("getFmlCustomResolution -> FmlResolution is set to: %s", fmlResolutions)

// validate the resolution
switch fmlResolutions {
case types.FmlResolution800x600,
types.FmlResolution1024x768,
types.FmlResolution1280x800,
types.FmlResolution1920x1080,
types.FmlResolutionUnset:
return fmlResolutions, nil
}

return "", fmt.Errorf("invalid fml resolution %s", fmlResolutions)
}

// CreateDomConfig creates a domain config (a qemu config file,
// typically named something like xen-%d.cfg)
func (ctx KvmContext) CreateDomConfig(domainName string,
Expand Down
3 changes: 3 additions & 0 deletions pkg/pillar/types/domainmgrtypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,9 @@ type DomainStatus struct {
// VirtualTPM is a flag to signal the hypervisor implementation
// that vTPM is available for the domain.
VirtualTPM bool
// FmlCustomResolution is the custom resolution for FML mode,
// xxx: this should be moved to VmConfig
FmlCustomResolution string
}

func (status DomainStatus) Key() string {
Expand Down
16 changes: 16 additions & 0 deletions pkg/pillar/types/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ const (
SyslogLogLevel GlobalSettingKey = "debug.syslog.loglevel"
// KernelLogLevel global setting key
KernelLogLevel GlobalSettingKey = "debug.kernel.loglevel"
// FmlCustomResolution global setting key
FmlCustomResolution GlobalSettingKey = "app.fml.resolution"

// XXX Temporary flag to disable RFC 3442 classless static route usage
DisableDHCPAllOnesNetMask GlobalSettingKey = "debug.disable.dhcp.all-ones.netmask"
Expand Down Expand Up @@ -358,6 +360,19 @@ var (
SyslogKernelDefaultLogLevel = "info"
)

var (
// FmlResolutionUnset is a string to indicate that custom resolution is not set
FmlResolutionUnset = ""
// FmlResolution800x600 is a string to indicate 800x600 resolution
FmlResolution800x600 = "800x600"
// FmlResolution1024x768 is a string to indicate 1024x768 resolution
FmlResolution1024x768 = "1024x768"
// FmlResolution1280x800 is a string to indicate 1280x720 resolution
FmlResolution1280x800 = "1280x800"
// FmlResolution1920x1080 is a string to indicate 1280x720 resolution
FmlResolution1920x1080 = "1920x1080"
)

// ConfigItemSpec - Defines what a specification for a configuration should be
type ConfigItemSpec struct {
Key string
Expand Down Expand Up @@ -911,6 +926,7 @@ func NewConfigItemSpecMap() ConfigItemSpecMap {
configItemSpecMap.AddStringItem(DefaultRemoteLogLevel, "info", validateLogrusLevel)
configItemSpecMap.AddStringItem(SyslogLogLevel, "info", validateSyslogKernelLevel)
configItemSpecMap.AddStringItem(KernelLogLevel, "info", validateSyslogKernelLevel)
configItemSpecMap.AddStringItem(FmlCustomResolution, FmlResolutionUnset, blankValidator)

// Add Agent Settings
configItemSpecMap.AddAgentSettingStringItem(LogLevel, "info", validateLogrusLevel)
Expand Down
1 change: 1 addition & 0 deletions pkg/pillar/types/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func TestNewConfigItemSpecMap(t *testing.T) {
DefaultRemoteLogLevel,
SyslogLogLevel,
KernelLogLevel,
FmlCustomResolution,
DisableDHCPAllOnesNetMask,
ProcessCloudInitMultiPart,
NetDumpEnable,
Expand Down

0 comments on commit ab40145

Please sign in to comment.