Skip to content

Commit 0f66e20

Browse files
committed
krunkit: Support --fd
Latest krunkit can use a file descriptor instead of unix socket. Update the krunkit command to support this. Since krunkit behaves like vfkit and qemu, we can remove the special "auto" connection. Depends on: - libkrun/krunkit#63 - containers/libkrun#402
1 parent e1a7c0c commit 0f66e20

2 files changed

Lines changed: 15 additions & 18 deletions

File tree

example

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,6 @@ import sys
1414

1515
import vmnet
1616

17-
CONNECTION_AUTO = {
18-
"vfkit": "fd",
19-
"krunkit": "socket",
20-
"qemu": "fd",
21-
}
22-
2317
VMNET_OFFLOAD_AUTO = {
2418
"vfkit": "off",
2519
"krunkit": "off",
@@ -36,9 +30,9 @@ def main():
3630
p.add_argument("vm_name", help="VM name")
3731
p.add_argument(
3832
"--connection",
39-
choices=["auto", "fd", "socket", "client"],
40-
default="auto",
41-
help="How to connect the helper and vm (auto)",
33+
choices=["fd", "socket", "client"],
34+
default="fd",
35+
help="How to connect the helper and vm (fd)",
4236
)
4337

4438
# Helper arguments
@@ -118,9 +112,6 @@ def main():
118112

119113
args = p.parse_args()
120114

121-
if args.connection == "auto":
122-
args.connection = CONNECTION_AUTO[args.driver]
123-
124115
if args.operation_mode == "bridged" and not args.shared_interface:
125116
p.error("--shared-interface required for --operation-mode=bridged")
126117

vmnet/vm.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,21 +171,27 @@ def vfkit_command(self):
171171
return cmd
172172

173173
def krunkit_command(self):
174-
if self.fd is not None:
175-
raise ValueError("fd connection not supported for krunkit driver")
176-
if self.socket is None:
177-
raise ValueError("socket connection required")
178-
return [
174+
cmd = [
179175
self.driver_command or "krunkit",
180176
f"--memory={self.memory}",
181177
f"--cpus={self.cpus}",
182178
f"--restful-uri=none://",
183179
f"--device=virtio-blk,path={self.disk['image']}",
184180
f"--device=virtio-blk,path={self.cidata}",
185-
f"--device=virtio-net,type=unixgram,path={self.socket},mac={self.mac_address},offloading={self.vmnet_offload}",
186181
f"--device=virtio-serial,logFilePath={self.serial}",
187182
"--krun-log-level=3",
188183
]
184+
if self.fd is not None:
185+
cmd.append(
186+
f"--device=virtio-net,type=unixgram,fd={self.fd},mac={self.mac_address},offloading={self.vmnet_offload}",
187+
)
188+
elif self.socket is not None:
189+
cmd.append(
190+
f"--device=virtio-net,type=unixgram,path={self.socket},mac={self.mac_address},offloading={self.vmnet_offload}",
191+
)
192+
else:
193+
raise ValueError("fd or socket required")
194+
return cmd
189195

190196
def qemu_command(self):
191197
if self.fd is not None:

0 commit comments

Comments
 (0)