Skip to content

Commit 151ec4d

Browse files
authored
Merge pull request moby#265 from samoht/uwt
Remove the lwt-unix backend
2 parents a06c975 + d5b3934 commit 151ec4d

23 files changed

Lines changed: 1553 additions & 2436 deletions

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ vpnkit.exe: src/bin/depends.ml
4848

4949
.PHONY: test
5050
test:
51-
jbuilder build --dev src/hostnet_test/main_uwt.exe
52-
./_build/default/src/hostnet_test/main_uwt.exe
51+
jbuilder build --dev src/hostnet_test/main.exe
52+
./_build/default/src/hostnet_test/main.exe
5353

5454
.PHONY: OSS-LICENSES
5555
OSS-LICENSES:

src/bin/connect.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let (/) = Filename.concat
1313
let home = try Sys.getenv "HOME" with Not_found -> "/Users/root"
1414
let vsock_port = 62373l
1515

16-
module Make_unix(Host: Sig.HOST) = struct
16+
module Unix = struct
1717

1818
let vsock_path =
1919
ref (home / "Library/Containers/com.docker.docker/Data/@connect")
@@ -41,7 +41,7 @@ module Make_unix(Host: Sig.HOST) = struct
4141
Fmt.kstrf Lwt.fail_with "%a" pp_write_error e
4242
end
4343

44-
module Make_hvsock(Host: Sig.HOST) = struct
44+
module Hvsock = struct
4545
(* Avoid using `detach` because we don't want to exhaust the
4646
thread pool since this will block the main TCP/IP stack. *)
4747
module F =

src/bin/connect.mli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
module Make_unix(Host: Sig.HOST): sig
1+
module Unix: sig
22
include Sig.Connector
33

44
val vsock_path: string ref
55
end
66

7-
module Make_hvsock(Host: Sig.HOST): sig
7+
module Hvsock: sig
88
include Sig.Connector
99

1010
val set_port_forward_addr: Hvsock.sockaddr -> unit

src/bin/main.ml

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ let hvsock_addr_of_uri ~default_serviceid uri =
4646
in
4747
{ Hvsock.vmid; serviceid }
4848

49-
module Main(Host: Sig.HOST) = struct
50-
5149
module Vnet = Basic_backend.Make
52-
module Connect_unix = Connect.Make_unix(Host)
53-
module Connect_hvsock = Connect.Make_hvsock(Host)
50+
module Connect_unix = Connect.Unix
51+
module Connect_hvsock = Connect.Hvsock
5452
module Bind = Bind.Make(Host.Sockets)
5553
module Dns_policy = Hostnet_dns.Policy(Host.Files)
5654
module Config = Active_config.Make(Host.Time)(Host.Sockets.Stream.Unix)
5755
module Forward_unix = Forward.Make(Mclock)(Connect_unix)(Bind)
5856
module Forward_hvsock = Forward.Make(Mclock)(Connect_hvsock)(Bind)
5957
module HV = Flow_lwt_hvsock.Make(Host.Time)(Host.Fn)
60-
module Hosts = Hosts.Make(Host.Files)
58+
module HostsFile = Hosts.Make(Host.Files)
6159

6260
let file_descr_of_int (x: int) : Unix.file_descr =
6361
if Sys.os_type <> "Unix"
@@ -256,7 +254,7 @@ module Main(Host: Sig.HOST) = struct
256254
~config:(`Upstream { servers; search = [];
257255
assume_offline_after_drops = None }) );
258256

259-
let etc_hosts_watch = match Hosts.watch ~path:hosts () with
257+
let etc_hosts_watch = match HostsFile.watch ~path:hosts () with
260258
| Ok watch -> Some watch
261259
| Error (`Msg m) ->
262260
Log.err (fun f -> f "Failed to watch hosts file %s: %s" hosts m);
@@ -330,7 +328,7 @@ module Main(Host: Sig.HOST) = struct
330328
| Some "hyperv-connect" ->
331329
let module Slirp_stack =
332330
Slirp.Make(Config)(Vmnet.Make(HV))(Dns_policy)
333-
(Mclock)(Stdlibrandom)(Host)(Vnet)
331+
(Mclock)(Stdlibrandom)(Vnet)
334332
in
335333
let sockaddr =
336334
hvsock_addr_of_uri ~default_serviceid:ethernet_serviceid
@@ -352,7 +350,7 @@ module Main(Host: Sig.HOST) = struct
352350
| _ ->
353351
let module Slirp_stack =
354352
Slirp.Make(Config)(Vmnet.Make(Host.Sockets.Stream.Unix))(Dns_policy)
355-
(Mclock)(Stdlibrandom)(Host)(Vnet)
353+
(Mclock)(Stdlibrandom)(Vnet)
356354
in
357355
unix_listen socket_url >>= fun server ->
358356
( match config with
@@ -370,7 +368,7 @@ module Main(Host: Sig.HOST) = struct
370368
let wait_forever, _ = Lwt.task () in
371369
wait_forever >|= fun () ->
372370
match etc_hosts_watch with
373-
| Some watch -> Hosts.unwatch watch
371+
| Some watch -> HostsFile.unwatch watch
374372
| None -> ()
375373

376374
let main
@@ -382,18 +380,6 @@ module Main(Host: Sig.HOST) = struct
382380
(main_t socket_url port_control_url introspection_url diagnostics_url
383381
max_connections vsock_path db_path db_branch dns hosts host_names
384382
listen_backlog debug)
385-
end
386-
387-
let main
388-
socket port_control introspection_url diagnostics_url max_connections
389-
vsock_path db_path db_branch dns hosts host_names select listen_backlog
390-
debug
391-
=
392-
let module Use_lwt_unix = Main(Host_lwt_unix) in
393-
let module Use_uwt = Main(Host_uwt) in
394-
(if select then Use_lwt_unix.main else Use_uwt.main)
395-
socket port_control introspection_url diagnostics_url max_connections
396-
vsock_path db_path db_branch dns hosts host_names listen_backlog debug
397383

398384
open Cmdliner
399385

@@ -510,10 +496,6 @@ let host_names =
510496
in
511497
Arg.(value & opt string "vpnkit.host" doc)
512498

513-
let select =
514-
let doc = "Use a select event loop rather than the default libuv-based one" in
515-
Arg.(value & flag & info [ "select" ] ~doc)
516-
517499
let listen_backlog =
518500
let doc = "Specify a maximum listen(2) backlog. If no override is specified \
519501
then we will use SOMAXCONN." in
@@ -533,7 +515,7 @@ let command =
533515
Term.(pure main
534516
$ socket $ port_control_path $ introspection_path $ diagnostics_path
535517
$ max_connections $ vsock_path $ db_path $ db_branch $ dns $ hosts
536-
$ host_names $ select $ listen_backlog $ debug),
518+
$ host_names $ listen_backlog $ debug),
537519
Term.info (Filename.basename Sys.argv.(0)) ~version:Depends.version ~doc ~man
538520

539521
let () =

src/hostnet/arp.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ module Make (Ethif: Mirage_protocols_lwt.ETHIF) = struct
143143
f "error while reading ARP packet: %a" Ethif.pp_error e);
144144
end else Lwt.return_unit
145145
|2 -> (* Reply *)
146-
(* the requested address *)
146+
(* the requested address *)
147147
let spa = Ipaddr.V4.of_int32 (get_arp_tpa frame) in
148148
Log.debug (fun f -> f "ARP ignoring reply %s" (Ipaddr.V4.to_string spa));
149149
Lwt.return_unit
@@ -156,8 +156,8 @@ module Make (Ethif: Mirage_protocols_lwt.ETHIF) = struct
156156
let connect ~table ethif =
157157
let table =
158158
List.fold_left (fun acc (ip, mac) ->
159-
Table.add ip mac acc
160-
) Table.empty table
159+
Table.add ip mac acc
160+
) Table.empty table
161161
in
162162
{ table; ethif }
163163

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -409,30 +409,30 @@ module Sockets = struct
409409
let connect ?(read_buffer_size = default_read_buffer_size) (ip, port) =
410410
let description = Fmt.strf "tcp:%a:%d" Ipaddr.pp_hum ip port in
411411
let label = match ip with
412-
| Ipaddr.V4 _ -> "TCPv4"
413-
| Ipaddr.V6 _ -> "TCPv6" in
412+
| Ipaddr.V4 _ -> "TCPv4"
413+
| Ipaddr.V6 _ -> "TCPv6" in
414414
register_connection_noexn description
415415
>>= function
416416
| None ->
417417
errorf "Socket.%s.connect %s: hit connection limit" label description
418418
| Some idx ->
419-
let fd =
420-
try match ip with
421-
| Ipaddr.V4 _ -> Uwt.Tcp.init_ipv4_exn ()
422-
| Ipaddr.V6 _ -> Uwt.Tcp.init_ipv6_exn ()
423-
with e -> deregister_connection idx; raise e in
424-
Lwt.catch (fun () ->
425-
let sockaddr = make_sockaddr (ip, port) in
426-
Uwt.Tcp.connect fd ~addr:sockaddr >>= fun () ->
427-
of_fd ~idx ~label ~read_buffer_size ~description fd
428-
|> Lwt_result.return
429-
) (fun e ->
430-
deregister_connection idx;
431-
log_exception_continue "Tcp.connect Uwt.Tcp.close_wait"
432-
(fun () -> Uwt.Tcp.close_wait fd)
433-
>>= fun () ->
434-
errorf "Socket.%s.connect %s: caught %a" label description Fmt.exn e
435-
)
419+
let fd =
420+
try match ip with
421+
| Ipaddr.V4 _ -> Uwt.Tcp.init_ipv4_exn ()
422+
| Ipaddr.V6 _ -> Uwt.Tcp.init_ipv6_exn ()
423+
with e -> deregister_connection idx; raise e in
424+
Lwt.catch (fun () ->
425+
let sockaddr = make_sockaddr (ip, port) in
426+
Uwt.Tcp.connect fd ~addr:sockaddr >>= fun () ->
427+
of_fd ~idx ~label ~read_buffer_size ~description fd
428+
|> Lwt_result.return
429+
) (fun e ->
430+
deregister_connection idx;
431+
log_exception_continue "Tcp.connect Uwt.Tcp.close_wait"
432+
(fun () -> Uwt.Tcp.close_wait fd)
433+
>>= fun () ->
434+
errorf "Socket.%s.connect %s: caught %a" label description Fmt.exn e
435+
)
436436

437437
let shutdown_read _ =
438438
Lwt.return ()

0 commit comments

Comments
 (0)