fixup! ch-runner: add minimal virtiofsd support

This commit is contained in:
Else Someone 2026-02-21 18:36:52 +02:00
parent 7516eae7a6
commit a3ed9cb4ea

View file

@ -395,6 +395,9 @@ in
kwargs["pass_fds"] = kwargs.get("pass_fds", ()) kwargs["pass_fds"] = kwargs.get("pass_fds", ())
kwargs["env"] = kwargs.get("env", self.make_env()) kwargs["env"] = kwargs.get("env", self.make_env())
kwargs["cwd"] = kwargs.get("cwd", self.prefix) kwargs["cwd"] = kwargs.get("cwd", self.prefix)
kwargs["stdin"] = kwargs.get("stdin", subprocess.DEVNULL)
kwargs["stdout"] = kwargs.get("stdout", subprocess.DEVNULL)
kwargs["stderr"] = kwargs.get("stderr", subprocess.DEVNULL)
return subprocess.Popen( return subprocess.Popen(
args, args,
**kwargs, **kwargs,
@ -511,7 +514,7 @@ in
shell=False, shell=False,
stdin=subprocess.DEVNULL, stdin=subprocess.DEVNULL,
stdout=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
pass_fds=(2,)) pass_fds=())
try: try:
p.wait(0.125) p.wait(0.125)
needs_cleanup = False needs_cleanup = False
@ -529,6 +532,7 @@ in
except: # noqa: E722 except: # noqa: E722
pass pass
if p.returncode is None: if p.returncode is None:
print("Terminating CH")
p.terminate() # CH handles SIG{INT,TERM}? p.terminate() # CH handles SIG{INT,TERM}?
p.wait() p.wait()
unlink_paths = [ unlink_paths = [
@ -541,7 +545,7 @@ in
os.remove(p) os.remove(p)
@contextmanager @contextmanager
def add_virtiofsd( def start_virtiofsd(
self, self,
root_dir, root_dir,
tag, tag,
@ -555,6 +559,7 @@ in
# s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
# NOTE: Nope. Virtiofsd actually expects a blocking socket # NOTE: Nope. Virtiofsd actually expects a blocking socket
# s.setblocking(True) # s.setblocking(True)
# s.set_inheritable(True)
def rm_sock(): def rm_sock():
if os.path.exists(sock_path): if os.path.exists(sock_path):
@ -643,6 +648,15 @@ in
] ]
with ExitStack() as cleanup: with ExitStack() as cleanup:
send_dir = PASSTHRU_ENV["HOME"] + f"/send/{args.vm}"
os.makedirs(send_dir, exist_ok=True)
vfsd, vfsd_path = cleanup.enter_context(
ps.start_virtiofsd(
send_dir,
tag="send",
))
ch = cleanup.enter_context(ps.run_ch()) ch = cleanup.enter_context(ps.run_ch())
ps.exec(*ch_remote, "create", args.vm_config) ps.exec(*ch_remote, "create", args.vm_config)
ps.exec( ps.exec(
@ -650,13 +664,6 @@ in
*ch_remote, "add-net", *ch_remote, "add-net",
"id=wan,fd=3,mac=00:00:00:00:00:01") "id=wan,fd=3,mac=00:00:00:00:00:01")
send_dir = PASSTHRU_ENV["HOME"] + f"/send/{args.vm}"
os.makedirs(send_dir, exist_ok=True)
vfsd, vfsd_path = cleanup.enter_context(
ps.add_virtiofsd(
send_dir,
tag="send",
))
ps.exec(*ch_remote, "add-fs", f"tag=send,socket={vfsd_path},id=send") ps.exec(*ch_remote, "add-fs", f"tag=send,socket={vfsd_path},id=send")
ps.exec(*ch_remote, "boot") ps.exec(*ch_remote, "boot")
ps.exec(*ch_remote, "info") ps.exec(*ch_remote, "info")