Skip to content

Commit 9049dfd

Browse files
xenvm: Use ocaml-flock in preference to linking in core
This is a significant saving in footprint for the CLI: Before this patch: $ ls -lh _build/xenvm/xenvm.native -rwxr-xr-x 1 root root 14M Nov 6 14:15 _build/xenvm/xenvm.native After this patch: $ ls -lh _build/xenvm/xenvm.native -rwxr-xr-x 1 root root 4.8M Nov 6 14:15 _build/xenvm/xenvm.native Expecting this to reduce the build time significantly too since building core is a bear for the CI. Signed-off-by: Si Beaumont <[email protected]>
1 parent 321b121 commit 9049dfd

File tree

7 files changed

+25
-44
lines changed

7 files changed

+25
-44
lines changed

_oasis

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Library xenvmidl
2020
Path: idl
2121
Findlibname: xenvmidl
2222
Modules: Xenvm_interface, Xenvm_client, Log, Result, Errors, ResizeRequest, ResizeResponse, Pidfile, Retrymapper
23-
BuildDepends: rpclib, rpclib.syntax, sexplib, sexplib.syntax, lvm, cohttp.lwt, threads, mirage-block-unix, devmapper, core, mirage-clock-unix
23+
BuildDepends: rpclib, rpclib.syntax, sexplib, sexplib.syntax, lvm, cohttp.lwt, threads, mirage-block-unix, devmapper, mirage-clock-unix
2424

2525
Executable "xenvmd"
2626
ByteOpt: -warn-error +a
@@ -40,7 +40,7 @@ Executable "xenvm"
4040
MainIs: xenvm.ml
4141
Custom: true
4242
Install: false
43-
BuildDepends: lwt, lwt.unix, lvm, cmdliner, xenvmidl, devmapper, lvm.mapper, io-page.unix, mirage-clock-unix, sexplib.syntax, stringext
43+
BuildDepends: lwt, lwt.unix, lvm, cmdliner, xenvmidl, devmapper, lvm.mapper, io-page.unix, mirage-clock-unix, sexplib.syntax, stringext, flock
4444

4545
Executable "xenvm-local-allocator"
4646
ByteOpt: -warn-error +a

_tags

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 3881ba5bc364f876f6da3b99d6fed505)
2+
# DO NOT EDIT (digest: ee9005e9cd3e685e6bba5947ce145357)
33
# Ignore VCS directories, you can use the same kind of rule outside
44
# OASIS_START/STOP if you want to exclude directories that contains
55
# useless stuff for the build process
@@ -21,7 +21,6 @@ true: annot, bin_annot
2121
<idl/xenvmidl.{cma,cmxa}>: oasis_library_xenvmidl_native
2222
<idl/*.ml{,i,y}>: oasis_library_xenvmidl_native
2323
<idl/*.ml{,i,y}>: pkg_cohttp.lwt
24-
<idl/*.ml{,i,y}>: pkg_core
2524
<idl/*.ml{,i,y}>: pkg_devmapper
2625
<idl/*.ml{,i,y}>: pkg_lvm
2726
<idl/*.ml{,i,y}>: pkg_mirage-block-unix
@@ -38,7 +37,6 @@ true: annot, bin_annot
3837
<xenvmd/*.ml{,i,y}>: oasis_executable_xenvmd_native
3938
<xenvmd/xenvmd.{native,byte}>: pkg_cmdliner
4039
<xenvmd/xenvmd.{native,byte}>: pkg_cohttp.lwt
41-
<xenvmd/xenvmd.{native,byte}>: pkg_core
4240
<xenvmd/xenvmd.{native,byte}>: pkg_cstruct
4341
<xenvmd/xenvmd.{native,byte}>: pkg_devmapper
4442
<xenvmd/xenvmd.{native,byte}>: pkg_io-page
@@ -61,7 +59,6 @@ true: annot, bin_annot
6159
<xenvmd/xenvmd.{native,byte}>: use_xenvmidl
6260
<xenvmd/*.ml{,i,y}>: pkg_cmdliner
6361
<xenvmd/*.ml{,i,y}>: pkg_cohttp.lwt
64-
<xenvmd/*.ml{,i,y}>: pkg_core
6562
<xenvmd/*.ml{,i,y}>: pkg_cstruct
6663
<xenvmd/*.ml{,i,y}>: pkg_devmapper
6764
<xenvmd/*.ml{,i,y}>: pkg_io-page
@@ -90,8 +87,8 @@ true: annot, bin_annot
9087
<xenvm/*.ml{,i,y}>: oasis_executable_xenvm_native
9188
<xenvm/xenvm.{native,byte}>: pkg_cmdliner
9289
<xenvm/xenvm.{native,byte}>: pkg_cohttp.lwt
93-
<xenvm/xenvm.{native,byte}>: pkg_core
9490
<xenvm/xenvm.{native,byte}>: pkg_devmapper
91+
<xenvm/xenvm.{native,byte}>: pkg_flock
9592
<xenvm/xenvm.{native,byte}>: pkg_io-page.unix
9693
<xenvm/xenvm.{native,byte}>: pkg_lvm
9794
<xenvm/xenvm.{native,byte}>: pkg_lvm.mapper
@@ -108,8 +105,8 @@ true: annot, bin_annot
108105
<xenvm/xenvm.{native,byte}>: use_xenvmidl
109106
<xenvm/*.ml{,i,y}>: pkg_cmdliner
110107
<xenvm/*.ml{,i,y}>: pkg_cohttp.lwt
111-
<xenvm/*.ml{,i,y}>: pkg_core
112108
<xenvm/*.ml{,i,y}>: pkg_devmapper
109+
<xenvm/*.ml{,i,y}>: pkg_flock
113110
<xenvm/*.ml{,i,y}>: pkg_io-page.unix
114111
<xenvm/*.ml{,i,y}>: pkg_lvm
115112
<xenvm/*.ml{,i,y}>: pkg_lvm.mapper
@@ -132,7 +129,6 @@ true: annot, bin_annot
132129
<xenvm-local-allocator/*.ml{,i,y}>: oasis_executable_xenvm_local_allocator_native
133130
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_cmdliner
134131
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_cohttp.lwt
135-
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_core
136132
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_cstruct
137133
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_devmapper
138134
<xenvm-local-allocator/local_allocator.{native,byte}>: pkg_io-page
@@ -153,7 +149,6 @@ true: annot, bin_annot
153149
<xenvm-local-allocator/local_allocator.{native,byte}>: use_xenvmidl
154150
<xenvm-local-allocator/*.ml{,i,y}>: pkg_cmdliner
155151
<xenvm-local-allocator/*.ml{,i,y}>: pkg_cohttp.lwt
156-
<xenvm-local-allocator/*.ml{,i,y}>: pkg_core
157152
<xenvm-local-allocator/*.ml{,i,y}>: pkg_cstruct
158153
<xenvm-local-allocator/*.ml{,i,y}>: pkg_devmapper
159154
<xenvm-local-allocator/*.ml{,i,y}>: pkg_io-page
@@ -179,7 +174,6 @@ true: annot, bin_annot
179174
<test/test.{native,byte}>: oasis_executable_test_native
180175
<test/*.ml{,i,y}>: oasis_executable_test_native
181176
<test/test.{native,byte}>: pkg_cohttp.lwt
182-
<test/test.{native,byte}>: pkg_core
183177
<test/test.{native,byte}>: pkg_devmapper
184178
<test/test.{native,byte}>: pkg_io-page.unix
185179
<test/test.{native,byte}>: pkg_lvm
@@ -195,7 +189,6 @@ true: annot, bin_annot
195189
<test/test.{native,byte}>: pkg_threads
196190
<test/test.{native,byte}>: use_xenvmidl
197191
<test/*.ml{,i,y}>: pkg_cohttp.lwt
198-
<test/*.ml{,i,y}>: pkg_core
199192
<test/*.ml{,i,y}>: pkg_devmapper
200193
<test/*.ml{,i,y}>: pkg_io-page.unix
201194
<test/*.ml{,i,y}>: pkg_lvm

idl/META

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 0a291b806c1d54b924bacb021711794e)
2+
# DO NOT EDIT (digest: 8bc29dfea892cb47998acdb65583145c)
33
version = "0.1"
44
description = "LVM-like volume manager supporting thinly provisioned LVs"
55
requires =
6-
"rpclib rpclib.syntax sexplib sexplib.syntax lvm cohttp.lwt threads mirage-block-unix devmapper core mirage-clock-unix"
6+
"rpclib rpclib.syntax sexplib sexplib.syntax lvm cohttp.lwt threads mirage-block-unix devmapper mirage-clock-unix"
77
archive(byte) = "xenvmidl.cma"
88
archive(byte, plugin) = "xenvmidl.cma"
99
archive(native) = "xenvmidl.cmxa"

idl/flock.ml

Lines changed: 0 additions & 28 deletions
This file was deleted.

opam

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ depends: [
1616
"ounit" {test}
1717
"cstruct" {>= "0.7.1"}
1818
"lwt"
19-
"core"
19+
"flock"
2020
"shared-block-ring"
2121
"mirage-block-volume" {>= "0.9.2"}
2222
"mirage-clock-unix"

xenvm/xenvm.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ let format config name filenames =
8484
let with_lvm_lock config vg_name f =
8585
if config.mock_dm then f () else
8686
let lock_path = Filename.concat "/run/lock/lvm" ("V_" ^ vg_name ^ ":aux") in
87-
Flock.with_flock lock_path f
87+
with_flock lock_path f
8888

8989
(* Change the label on the PV and revert it if the function [f] fails *)
9090
let with_label_change block magic f =

xenvm/xenvm_common.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,22 @@ let mkdir_rec dir perm =
2828
mkdir_safe dir perm in
2929
p_mkdir dir
3030

31+
32+
let finally f g = let res = try f () with exn -> g (); raise exn in g (); res
33+
34+
let with_flock path f =
35+
let open Flock in
36+
mkdir_rec (Filename.dirname path) 0o700;
37+
let fd = Unix.(openfile path [O_WRONLY; O_CREAT] 0o644) in
38+
let rec try_lock tries =
39+
if tries > 0 then
40+
if try flock ~nonblocking:true fd LOCK_EX; true with _ -> false then ()
41+
else begin Unix.sleep 1; try_lock (tries - 1) end
42+
else failwith ("Could not obtain flock: " ^ path)
43+
in
44+
try_lock 5;
45+
finally f (fun () -> flock fd LOCK_UN)
46+
3147
module Time = struct
3248
type 'a io = 'a Lwt.t
3349
let sleep = Lwt_unix.sleep

0 commit comments

Comments
 (0)