@@ -83,6 +83,50 @@ func EnsureDisk(cfg Config) error {
83
83
return nil
84
84
}
85
85
86
+ func argValue (args []string , key string ) (string , bool ) {
87
+ if ! strings .HasPrefix (key , "-" ) {
88
+ panic (errors .Errorf ("got unexpected key %q" , key ))
89
+ }
90
+ for i , s := range args {
91
+ if s == key {
92
+ if i == len (args )- 1 {
93
+ return "" , true
94
+ }
95
+ value := args [i + 1 ]
96
+ if strings .HasPrefix (value , "-" ) {
97
+ return "" , true
98
+ }
99
+ return value , true
100
+ }
101
+ }
102
+ return "" , false
103
+ }
104
+
105
+ // appendArgsIfNoConflict can be used for: -cpu, -machine, -m, -boot ...
106
+ // appendArgsIfNoConflict cannot be used for: -drive, -cdrom, ...
107
+ func appendArgsIfNoConflict (args []string , k , v string ) []string {
108
+ if ! strings .HasPrefix (k , "-" ) {
109
+ panic (errors .Errorf ("got unexpected key %q" , k ))
110
+ }
111
+ switch k {
112
+ case "-drive" , "-cdrom" , "-chardev" , "-blockdev" , "-netdev" , "-device" :
113
+ panic (errors .Errorf ("appendArgsIfNoConflict() must not be called with k=%q" , k ))
114
+ }
115
+
116
+ if v == "" {
117
+ if _ , ok := argValue (args , k ); ok {
118
+ return args
119
+ }
120
+ return append (args , k )
121
+ }
122
+
123
+ if origV , ok := argValue (args , k ); ok {
124
+ logrus .Warnf ("Not adding QEMU argument %q %q, as it conflicts with %q %q" , k , v , k , origV )
125
+ return args
126
+ }
127
+ return append (args , k , v )
128
+ }
129
+
86
130
func Cmdline (cfg Config ) (string , []string , error ) {
87
131
y := cfg .LimaYAML
88
132
exe , args , err := getExe (y .Arch )
@@ -96,23 +140,23 @@ func Cmdline(cfg Config) (string, []string, error) {
96
140
case limayaml .X8664 :
97
141
// NOTE: "-cpu host" seems to cause kernel panic
98
142
// (MacBookPro 2020, Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz, macOS 11.3, Ubuntu 21.04)
99
- args = append (args , "-cpu" , "Haswell-v4" )
100
- args = append (args , "-machine" , "q35,accel=" + accel )
143
+ args = appendArgsIfNoConflict (args , "-cpu" , "Haswell-v4" )
144
+ args = appendArgsIfNoConflict (args , "-machine" , "q35,accel=" + accel )
101
145
case limayaml .AARCH64 :
102
- args = append (args , "-cpu" , "cortex-a72" )
103
- args = append (args , "-machine" , "virt,accel=" + accel + ",highmem=off" )
146
+ args = appendArgsIfNoConflict (args , "-cpu" , "cortex-a72" )
147
+ args = appendArgsIfNoConflict (args , "-machine" , "virt,accel=" + accel + ",highmem=off" )
104
148
}
105
149
106
150
// SMP
107
- args = append (args , "-smp" ,
151
+ args = appendArgsIfNoConflict (args , "-smp" ,
108
152
fmt .Sprintf ("%d,sockets=1,cores=%d,threads=1" , y .CPUs , y .CPUs ))
109
153
110
154
// Memory
111
155
memBytes , err := units .RAMInBytes (y .Memory )
112
156
if err != nil {
113
157
return "" , nil , err
114
158
}
115
- args = append (args , "-m" , strconv .Itoa (int (memBytes >> 20 )))
159
+ args = appendArgsIfNoConflict (args , "-m" , strconv .Itoa (int (memBytes >> 20 )))
116
160
117
161
// Firmware
118
162
if ! y .Firmware .LegacyBIOS {
@@ -132,10 +176,10 @@ func Cmdline(cfg Config) (string, []string, error) {
132
176
return "" , nil , err
133
177
}
134
178
if isBaseDiskCDROM {
135
- args = append (args , "-boot" , "order=d,splash-time=0,menu=on" )
179
+ args = appendArgsIfNoConflict (args , "-boot" , "order=d,splash-time=0,menu=on" )
136
180
args = append (args , "-drive" , fmt .Sprintf ("file=%s,media=cdrom,readonly=on" , baseDisk ))
137
181
} else {
138
- args = append (args , "-boot" , "order=c,splash-time=0,menu=on" )
182
+ args = appendArgsIfNoConflict (args , "-boot" , "order=c,splash-time=0,menu=on" )
139
183
}
140
184
if diskSize , _ := units .RAMInBytes (cfg .LimaYAML .Disk ); diskSize > 0 {
141
185
args = append (args , "-drive" , fmt .Sprintf ("file=%s,if=virtio" , diffDisk ))
@@ -156,7 +200,7 @@ func Cmdline(cfg Config) (string, []string, error) {
156
200
157
201
// Graphics
158
202
if y .Video .Display != "" {
159
- args = append (args , "-display" , y .Video .Display )
203
+ args = appendArgsIfNoConflict (args , "-display" , y .Video .Display )
160
204
}
161
205
switch y .Arch {
162
206
case limayaml .X8664 :
0 commit comments