···252252 in
253253 let with_rootfs fn =
254254 if entry.pre.mode = R then (Store.Run.with_build ctx.store build fn, [])
255255- else Store.Run.with_clone ctx.store ~src:build new_cid fn
255255+ else
256256+ let diff_path =
257257+ Eio.Path.(fs / Filename.temp_dir "shelter-diff-" "" / "diff")
258258+ in
259259+ Store.Run.with_clone ctx.store ~src:build new_cid diff_path fn
256260 in
257261 with_rootfs @@ function
258262 | `Exists path ->
···300304 "-c";
301305 String.concat " " command ^ " && env > /tmp/shelter-env";
302306 ];
303303- hostname = "";
307307+ hostname = "builder";
304308 network = [ "host" ];
305309 user = (uid, gid);
306310 env = entry.pre.env;
···317321 in
318322 `Runc (Runc.spawn ~sw log env config rootfs)
319323 in
320320- Switch.run @@ fun sw ->
321321- let log =
322322- Eio.Path.open_out ~sw ~create:(`If_missing 0o644)
323323- Eio.Path.(fs / rootfs / "log")
324324- in
325325- let res = spawn sw log in
326326- let start = Mtime_clock.now () in
327327- let res =
324324+ let start, res =
325325+ Switch.run @@ fun sw ->
326326+ let log =
327327+ Eio.Path.open_out ~sw ~create:(`If_missing 0o644)
328328+ Eio.Path.(fs / rootfs / "log")
329329+ in
330330+ let res = spawn sw log in
331331+ let start = Mtime_clock.now () in
328332 match res with
329329- | `Runc r -> Eio.Process.await r
330330- | `Void v -> Void.to_eio_status (Eio.Promise.await v)
333333+ | `Runc r -> (start, Eio.Process.await r)
334334+ | `Void v -> (start, Void.to_eio_status (Eio.Promise.await v))
331335 in
332336 let stop = Mtime_clock.now () in
333337 let span = Mtime.span start stop in
+16-15
src/lib/shelter/store.ml
···9494 Zfs.clone src (tgt :> string)
95959696let read_all fd =
9797- let buf = Buffer.create 128 in
9898- let bytes = Bytes.create 4096 in
9797+ let buf = Buffer.create 10_000 in
9898+ let bytes = Bytes.create 10_000 in
9999 let rec loop () =
100100 match Unix.read fd bytes 0 4096 with
101101 | 0 | (exception End_of_file) -> Buffer.contents buf
···105105 in
106106 loop ()
107107108108-let diff t (data : Datasets.snapshot) (snap : Datasets.snapshot) =
108108+let diff t (data : Datasets.snapshot) (snap : Datasets.snapshot) output =
109109 let data_fs =
110110 String.sub (data :> string) 0 (String.index (data :> string) '@')
111111 in
112112 let zh = Zfs.open_ t.zfs data_fs Zfs.Types.filesystem in
113113- let diff =
114114- let r, w = Unix.pipe ~cloexec:false () in
113113+ let () =
115114 try
116116- Zfs.show_diff zh ~from_:(data :> string) ~to_:(snap :> string) w;
117117- let f = read_all r in
118118- Unix.close r;
119119- f
120120- with e ->
121121- Unix.close r;
122122- raise e
115115+ Eio.Path.with_open_out ~create:(`If_missing 0o644) output
116116+ @@ fun flow_fd ->
117117+ let eio_fd = Eio_unix.Resource.fd_opt flow_fd in
118118+ Eio_unix.Fd.use_exn_opt "zfs-diff" eio_fd @@ function
119119+ | None -> Fmt.failwith "Output needs to have an FD"
120120+ | Some fd ->
121121+ Zfs.show_diff zh ~from_:(data :> string) ~to_:(snap :> string) fd
122122+ with Unix.Unix_error (Unix.EBADF, _, _) -> ()
123123 in
124124 Zfs.close zh;
125125+ let diff = Eio.Path.load output in
125126 Diff.of_zfs diff
126127127128let cid s =
···173174 mount_dataset t ds;
174175 fn ("/" ^ (ds :> string))
175176176176- let with_clone t ~src new_cid fn =
177177+ let with_clone t ~src new_cid output fn =
177178 let ds = Datasets.build t.pool (Cid.to_string src) in
178179 let tgt = Datasets.build t.pool (Cid.to_string new_cid) in
179180 let src_snap = Datasets.snapshot ds in
180181 let tgt_snap = Datasets.snapshot tgt in
181182 if Zfs.exists t.zfs (tgt :> string) Zfs.Types.dataset then
182182- (fn (`Exists ("/" ^ (tgt :> string))), diff t src_snap tgt_snap)
183183+ (fn (`Exists ("/" ^ (tgt :> string))), diff t src_snap tgt_snap output)
183184 else (
184185 clone t src_snap tgt;
185186 let v = with_build t new_cid fn in
186187 snapshot t tgt_snap;
187187- let d = diff t src_snap tgt_snap in
188188+ let d = diff t src_snap tgt_snap output in
188189 (v, d))
189190end
-1
vendor/zfs/src/zfs.ml
···137137 (* TODO: Other Diff Flags https://github.com/openzfs/zfs/blob/5b0c27cd14bbc07d50304c97735cc105d0258673/include/libzfs.h#L917? *)
138138 let res = C.Functions.diff handle (Obj.magic fd : int) from_ to_ 1 in
139139 if res = 0 then () else begin
140140- Format.printf "Diff got %i\n%!" res;
141140 invalid_arg "show_diff"
142141 end