@@ -70,12 +70,34 @@ func (l *LimaQemuDriver) Configure(inst *limatype.Instance, sshLocalPort int) *d
70
70
l .Instance = inst
71
71
l .SSHLocalPort = sshLocalPort
72
72
73
- if l .Instance .Config .Video .VNC .Display == nil || * l .Instance .Config .Video .VNC .Display == "" {
74
- l .Instance .Config .Video .VNC .Display = ptr .Of ("127.0.0.1:0,to=9" )
73
+ return & driver.ConfiguredDriver {
74
+ Driver : l ,
75
+ }
76
+ }
77
+
78
+ func (l * LimaQemuDriver ) Validate () error {
79
+ if runtime .GOOS == "darwin" {
80
+ if err := l .checkBinarySignature (); err != nil {
81
+ return err
82
+ }
83
+ }
84
+
85
+ if * l .Instance .Config .MountType == limatype .VIRTIOFS && runtime .GOOS != "linux" {
86
+ return fmt .Errorf ("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q" ,
87
+ limatype .REVSSHFS , limatype .NINEP , * l .Instance .Config .MountType )
88
+ }
89
+ return nil
90
+ }
91
+
92
+ func (l * LimaQemuDriver ) AcceptConfig (cfg * limatype.LimaYAML , filePath string ) error {
93
+ instDir := filepath .Dir (filePath )
94
+
95
+ if cfg .Video .VNC .Display == nil || * cfg .Video .VNC .Display == "" {
96
+ cfg .Video .VNC .Display = ptr .Of ("127.0.0.1:0,to=9" )
75
97
}
76
98
77
99
mountTypesUnsupported := make (map [string ]struct {})
78
- for _ , f := range l . Instance . Config .MountTypesUnsupported {
100
+ for _ , f := range cfg .MountTypesUnsupported {
79
101
mountTypesUnsupported [f ] = struct {}{}
80
102
}
81
103
@@ -84,49 +106,29 @@ func (l *LimaQemuDriver) Configure(inst *limatype.Instance, sshLocalPort int) *d
84
106
mountTypesUnsupported [limatype .NINEP ] = struct {}{}
85
107
}
86
108
87
- if l . Instance . Config . MountType == nil || * l . Instance . Config . MountType == "" || * l . Instance . Config .MountType == "default" {
88
- l . Instance . Config .MountType = ptr .Of (limatype .NINEP )
109
+ if cfg . MountType == nil || * cfg . MountType == "" || * cfg .MountType == "default" {
110
+ cfg .MountType = ptr .Of (limatype .NINEP )
89
111
if _ , ok := mountTypesUnsupported [limatype .NINEP ]; ok {
90
112
// Use REVSSHFS if the instance does not support 9p
91
- l . Instance . Config .MountType = ptr .Of (limatype .REVSSHFS )
92
- } else if limayaml .IsExistingInstanceDir (l . Instance . Dir ) && ! versionutil .GreaterEqual (limayaml .ExistingLimaVersion (l . Instance . Dir ), "1.0.0" ) {
113
+ cfg .MountType = ptr .Of (limatype .REVSSHFS )
114
+ } else if limayaml .IsExistingInstanceDir (instDir ) && ! versionutil .GreaterEqual (limayaml .ExistingLimaVersion (instDir ), "1.0.0" ) {
93
115
// Use REVSSHFS if the instance was created with Lima prior to v1.0
94
- l . Instance . Config .MountType = ptr .Of (limatype .REVSSHFS )
116
+ cfg .MountType = ptr .Of (limatype .REVSSHFS )
95
117
}
96
118
}
97
119
98
- if _ , ok := mountTypesUnsupported [* l . Instance . Config .MountType ]; ok {
120
+ if _ , ok := mountTypesUnsupported [* cfg .MountType ]; ok {
99
121
// We cannot return an error here, but Validate() will return it.
100
- logrus .Warnf ("Unsupported mount type: %q" , * l . Instance . Config .MountType )
122
+ logrus .Warnf ("Unsupported mount type: %q" , * cfg .MountType )
101
123
}
102
124
103
- for i := range l . Instance . Config .Mounts {
104
- mount := & l . Instance . Config .Mounts [i ]
105
- if mount .Virtiofs .QueueSize == nil && * l . Instance . Config .MountType == limatype .VIRTIOFS {
106
- l . Instance . Config .Mounts [i ].Virtiofs .QueueSize = ptr .Of (limayaml .DefaultVirtiofsQueueSize )
125
+ for i := range cfg .Mounts {
126
+ mount := & cfg .Mounts [i ]
127
+ if mount .Virtiofs .QueueSize == nil && * cfg .MountType == limatype .VIRTIOFS {
128
+ cfg .Mounts [i ].Virtiofs .QueueSize = ptr .Of (limayaml .DefaultVirtiofsQueueSize )
107
129
}
108
130
}
109
131
110
- return & driver.ConfiguredDriver {
111
- Driver : l ,
112
- }
113
- }
114
-
115
- func (l * LimaQemuDriver ) Validate () error {
116
- if runtime .GOOS == "darwin" {
117
- if err := l .checkBinarySignature (); err != nil {
118
- return err
119
- }
120
- }
121
-
122
- if * l .Instance .Config .MountType == limatype .VIRTIOFS && runtime .GOOS != "linux" {
123
- return fmt .Errorf ("field `mountType` must be %q or %q for QEMU driver on non-Linux, got %q" ,
124
- limatype .REVSSHFS , limatype .NINEP , * l .Instance .Config .MountType )
125
- }
126
- return nil
127
- }
128
-
129
- func (l * LimaQemuDriver ) AcceptConfig (cfg * limatype.LimaYAML , filepath string ) error {
130
132
if runtime .GOOS == "darwin" {
131
133
if cfg .Arch != nil && ! limayaml .IsNativeArch (* cfg .Arch ) {
132
134
logrus .Debugf ("ResolveVMType: resolved VMType %q (non-native arch=%q is specified in []*LimaYAML{o,y,d})" , "qemu" , * cfg .Arch )
@@ -162,9 +164,6 @@ func (l *LimaQemuDriver) AcceptConfig(cfg *limatype.LimaYAML, filepath string) e
162
164
l .Instance = & limatype.Instance {}
163
165
}
164
166
l .Instance .Config = cfg
165
- defer func () {
166
- l .Instance .Config = nil
167
- }()
168
167
169
168
if err := l .Validate (); err != nil {
170
169
return fmt .Errorf ("config not supported by the QEMU driver: %w" , err )
@@ -361,7 +360,7 @@ func (l *LimaQemuDriver) checkBinarySignature() error {
361
360
return err
362
361
}
363
362
// The codesign --xml option is only available on macOS Monterey and later
364
- if ! macOSProductVersion .LessThan (* semver .New ("12.0.0" )) {
363
+ if ! macOSProductVersion .LessThan (* semver .New ("12.0.0" )) && l . Instance . Arch != "" {
365
364
qExe , _ , err := Exe (l .Instance .Arch )
366
365
if err != nil {
367
366
return fmt .Errorf ("failed to find the QEMU binary for the architecture %q: %w" , l .Instance .Arch , err )
0 commit comments