this repo has no description

Compare changes

Choose any two refs to compare.

Changed files
+40 -33
src
vendor
void
zfs
src
+2 -2
dune-project
···
(synopsis "Shelter from the Storm")
(description "A shell session shim to help you explore!")
(depends
-
ocaml
+
(ocaml (< "5.3.0~~")) ; for the irmin pin only
+
(ctypes (< "0.23.0")) ; for a const ptr mismatch with zfs from https://github.com/yallop/ocaml-ctypes/pull/782
eio_posix
-
void
zfs
cid
ppx_repr
+2 -2
shelter.opam
···
bug-reports: "https://github.com/username/reponame/issues"
depends: [
"dune" {>= "3.17"}
-
"ocaml"
+
"ocaml" {< "5.3.0~~"}
+
"ctypes" {< "0.23.0"}
"eio_posix"
-
"void"
"zfs"
"cid"
"ppx_repr"
+1 -1
src/lib/shelter/runc.ml
···
to_other_sink_as_well ~other:env#stdout
(log :> Eio.Flow.sink_ty Eio.Flow.sink)
in
-
Eio.Process.spawn ~stdout ~sw env#proc ~cwd:eio_tmp cmd
+
Eio.Process.spawn ~sw ~stdout env#proc ~cwd:eio_tmp cmd
(*
Apache License
+16 -12
src/lib/shelter/shelter_main.ml
···
in
let with_rootfs fn =
if entry.pre.mode = R then (Store.Run.with_build ctx.store build fn, [])
-
else Store.Run.with_clone ctx.store ~src:build new_cid fn
+
else
+
let diff_path =
+
Eio.Path.(fs / Filename.temp_dir "shelter-diff-" "" / "diff")
+
in
+
Store.Run.with_clone ctx.store ~src:build new_cid diff_path fn
in
with_rootfs @@ function
| `Exists path ->
···
"-c";
String.concat " " command ^ " && env > /tmp/shelter-env";
];
-
hostname = "";
+
hostname = "builder";
network = [ "host" ];
user = (uid, gid);
env = entry.pre.env;
···
in
`Runc (Runc.spawn ~sw log env config rootfs)
in
-
Switch.run @@ fun sw ->
-
let log =
-
Eio.Path.open_out ~sw ~create:(`If_missing 0o644)
-
Eio.Path.(fs / rootfs / "log")
-
in
-
let res = spawn sw log in
-
let start = Mtime_clock.now () in
-
let res =
+
let start, res =
+
Switch.run @@ fun sw ->
+
let log =
+
Eio.Path.open_out ~sw ~create:(`If_missing 0o644)
+
Eio.Path.(fs / rootfs / "log")
+
in
+
let res = spawn sw log in
+
let start = Mtime_clock.now () in
match res with
-
| `Runc r -> Eio.Process.await r
-
| `Void v -> Void.to_eio_status (Eio.Promise.await v)
+
| `Runc r -> (start, Eio.Process.await r)
+
| `Void v -> (start, Void.to_eio_status (Eio.Promise.await v))
in
let stop = Mtime_clock.now () in
let span = Mtime.span start stop in
+16 -15
src/lib/shelter/store.ml
···
Zfs.clone src (tgt :> string)
let read_all fd =
-
let buf = Buffer.create 128 in
-
let bytes = Bytes.create 4096 in
+
let buf = Buffer.create 10_000 in
+
let bytes = Bytes.create 10_000 in
let rec loop () =
match Unix.read fd bytes 0 4096 with
| 0 | (exception End_of_file) -> Buffer.contents buf
···
in
loop ()
-
let diff t (data : Datasets.snapshot) (snap : Datasets.snapshot) =
+
let diff t (data : Datasets.snapshot) (snap : Datasets.snapshot) output =
let data_fs =
String.sub (data :> string) 0 (String.index (data :> string) '@')
in
let zh = Zfs.open_ t.zfs data_fs Zfs.Types.filesystem in
-
let diff =
-
let r, w = Unix.pipe ~cloexec:false () in
+
let () =
try
-
Zfs.show_diff zh ~from_:(data :> string) ~to_:(snap :> string) w;
-
let f = read_all r in
-
Unix.close r;
-
f
-
with e ->
-
Unix.close r;
-
raise e
+
Eio.Path.with_open_out ~create:(`If_missing 0o644) output
+
@@ fun flow_fd ->
+
let eio_fd = Eio_unix.Resource.fd_opt flow_fd in
+
Eio_unix.Fd.use_exn_opt "zfs-diff" eio_fd @@ function
+
| None -> Fmt.failwith "Output needs to have an FD"
+
| Some fd ->
+
Zfs.show_diff zh ~from_:(data :> string) ~to_:(snap :> string) fd
+
with Unix.Unix_error (Unix.EBADF, _, _) -> ()
in
Zfs.close zh;
+
let diff = Eio.Path.load output in
Diff.of_zfs diff
let cid s =
···
mount_dataset t ds;
fn ("/" ^ (ds :> string))
-
let with_clone t ~src new_cid fn =
+
let with_clone t ~src new_cid output fn =
let ds = Datasets.build t.pool (Cid.to_string src) in
let tgt = Datasets.build t.pool (Cid.to_string new_cid) in
let src_snap = Datasets.snapshot ds in
let tgt_snap = Datasets.snapshot tgt in
if Zfs.exists t.zfs (tgt :> string) Zfs.Types.dataset then
-
(fn (`Exists ("/" ^ (tgt :> string))), diff t src_snap tgt_snap)
+
(fn (`Exists ("/" ^ (tgt :> string))), diff t src_snap tgt_snap output)
else (
clone t src_snap tgt;
let v = with_build t new_cid fn in
snapshot t tgt_snap;
-
let d = diff t src_snap tgt_snap in
+
let d = diff t src_snap tgt_snap output in
(v, d))
end
+3
vendor/void/src/void_action.c
···
#include <string.h>
+
#define CAML_INTERNALS
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>
#include <caml/memory.h>
#include <caml/custom.h>
+
#include <caml/signals.h>
#include <caml/fail.h>
+
#undef CAML_INTERNALS
// From Eio
#include <include/fork_action.h>
-1
vendor/zfs/src/zfs.ml
···
(* TODO: Other Diff Flags https://github.com/openzfs/zfs/blob/5b0c27cd14bbc07d50304c97735cc105d0258673/include/libzfs.h#L917? *)
let res = C.Functions.diff handle (Obj.magic fd : int) from_ to_ 1 in
if res = 0 then () else begin
-
Format.printf "Diff got %i\n%!" res;
invalid_arg "show_diff"
end