From 61569b061ac2123e5a85ffcd80fa4f7ad351b8c0 Mon Sep 17 00:00:00 2001 From: Shahriyar Jalayeri Date: Tue, 17 Sep 2024 13:05:26 +0300 Subject: [PATCH] Add global config for FML mode custom resolution 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". Signed-off-by: Shahriyar Jalayeri --- docs/CONFIG-PROPERTIES.md | 1 + pkg/pillar/hypervisor/kvm.go | 29 +++++++++++++++++++++++++++++ pkg/pillar/types/global.go | 21 +++++++++++++++++++++ pkg/pillar/types/global_test.go | 1 + 4 files changed, 52 insertions(+) diff --git a/docs/CONFIG-PROPERTIES.md b/docs/CONFIG-PROPERTIES.md index ffc682e4ae6..55df7fb0b6a 100644 --- a/docs/CONFIG-PROPERTIES.md +++ b/docs/CONFIG-PROPERTIES.md @@ -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 | diff --git a/pkg/pillar/hypervisor/kvm.go b/pkg/pillar/hypervisor/kvm.go index 876dd56c794..f7ae260dc5f 100644 --- a/pkg/pillar/hypervisor/kvm.go +++ b/pkg/pillar/hypervisor/kvm.go @@ -857,6 +857,17 @@ func isVncShimVMEnabled( return config.EnableVnc && (config.EnableVncShimVM || globalShimVnc) } +func getFmlCustomResolution(globalConfig *types.ConfigItemValueMap) (string, error) { + if globalConfig != nil { + item, ok := globalConfig.GlobalSettings[types.FmlCustomResolution] + if ok { + return item.StringValue(), nil + } + } + + return "", fmt.Errorf("no custom resolution found") +} + // CreateDomConfig creates a domain config (a qemu config file, // typically named something like xen-%d.cfg) func (ctx KvmContext) CreateDomConfig(domainName string, @@ -878,6 +889,24 @@ func (ctx KvmContext) CreateDomConfig(domainName string, isVncShimVMEnabled(globalConfig, config) tmplCtx.DomainConfig.DisplayName = domainName + fmlResolutions, err := getFmlCustomResolution(globalConfig) + if err != nil { + // this should never happen, but just in case + logError("failed to get fml-mode custom resolution, reverting back to notset. error : %v", err) + fmlResolutions = types.FmlResolutionNotSet + } + + if fmlResolutions != types.FmlResolutionNotSet { + // logError for visibility + logError("Setting FML resolution to : %s", fmlResolutions) + if fmlResolutions == types.FmlResolution1024x768 { + // do what ever else needed, like set the custom ovmf vars + } + if fmlResolutions == types.FmlResolution1920x1080 { + // do what ever else needed, like set the custom ovmf vars + } + } + // render global device model settings t, _ := template.New("qemu").Parse(qemuConfTemplate) if err := t.Execute(file, tmplCtx); err != nil { diff --git a/pkg/pillar/types/global.go b/pkg/pillar/types/global.go index b434021675b..cde7c05004f 100644 --- a/pkg/pillar/types/global.go +++ b/pkg/pillar/types/global.go @@ -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" @@ -358,6 +360,15 @@ var ( SyslogKernelDefaultLogLevel = "info" ) +var ( + // FmlResolutionNotSet is a string to indicate that custom resolution is not set + FmlResolutionNotSet = "notset" + // FmlResolution1024x768 is a string to indicate 1024x768 resolution + FmlResolution1024x768 = "1024x768" + // 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 @@ -911,6 +922,7 @@ func NewConfigItemSpecMap() ConfigItemSpecMap { configItemSpecMap.AddStringItem(DefaultRemoteLogLevel, "info", validateLogrusLevel) configItemSpecMap.AddStringItem(SyslogLogLevel, "info", validateSyslogKernelLevel) configItemSpecMap.AddStringItem(KernelLogLevel, "info", validateSyslogKernelLevel) + configItemSpecMap.AddStringItem(FmlCustomResolution, FmlResolutionNotSet, validateCustomResolution) // Add Agent Settings configItemSpecMap.AddAgentSettingStringItem(LogLevel, "info", validateLogrusLevel) @@ -943,6 +955,15 @@ func validateSyslogKernelLevel(level string) error { return nil } +func validateCustomResolution(res string) error { + // it can be notset or one of the predefined resolutions + if res == FmlResolutionNotSet || res == FmlResolution1024x768 || res == FmlResolution1920x1080 { + return nil + } + + return fmt.Errorf("validateCustomResolution: invalid resolution '%v'", res) +} + // blankValidator - A validator that accepts any string func blankValidator(s string) error { return nil diff --git a/pkg/pillar/types/global_test.go b/pkg/pillar/types/global_test.go index c83bf2a32e2..4ea67ab11bf 100644 --- a/pkg/pillar/types/global_test.go +++ b/pkg/pillar/types/global_test.go @@ -200,6 +200,7 @@ func TestNewConfigItemSpecMap(t *testing.T) { DefaultRemoteLogLevel, SyslogLogLevel, KernelLogLevel, + FmlCustomResolution, DisableDHCPAllOnesNetMask, ProcessCloudInitMultiPart, NetDumpEnable,