Skip to content

Commit fda9275

Browse files
authored
Merge pull request #5856 from last-genius/private/asultanov/duplicate-removal
2 parents 9f654a1 + 6e5893b commit fda9275

File tree

7 files changed

+168
-339
lines changed

7 files changed

+168
-339
lines changed

ocaml/vhd-tool/src/cohttp_unbuffered_io.ml

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

ocaml/vhd-tool/src/dune

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
cohttp
1212
cohttp-lwt
1313
cstruct
14+
(re_export ezxenstore)
1415
io-page
1516
lwt
1617
lwt.unix
@@ -30,6 +31,7 @@
3031
tapctl
3132
xapi-stdext-std
3233
xapi-stdext-unix
34+
xen-api-client-lwt
3335
xenstore
3436
xenstore.client
3537
xenstore.unix

ocaml/vhd-tool/src/impl.ml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,27 @@ let make_stream common source relative_to source_format destination_format =
954954
| _, _ ->
955955
assert false
956956

957+
module ChannelsConstrained : sig
958+
type t = Channels.t
959+
960+
type reader = Cstruct.t -> unit Lwt.t
961+
962+
val really_read : t -> reader
963+
964+
val really_write : t -> reader
965+
end = struct
966+
type t = Channels.t
967+
968+
type reader = Cstruct.t -> unit Lwt.t
969+
970+
let really_read x = x.Channels.really_read
971+
972+
let really_write x = x.Channels.really_write
973+
end
974+
975+
module Cohttp_io_with_channels =
976+
Xen_api_client_lwt.Cohttp_unbuffered_io.Make (ChannelsConstrained)
977+
957978
(** [write_stream common s destination destination_protocol prezeroed progress
958979
tar_filename_prefix ssl_legacy good_ciphersuites legacy_ciphersuites]
959980
writes the data stream [s] to [destination], using the specified
@@ -1019,8 +1040,8 @@ let write_stream common s destination destination_protocol prezeroed progress
10191040
Channels.of_raw_fd sock
10201041
)
10211042
>>= fun c ->
1022-
let module Request = Request.Make (Cohttp_unbuffered_io) in
1023-
let module Response = Response.Make (Cohttp_unbuffered_io) in
1043+
let module Request = Request.Make (Cohttp_io_with_channels) in
1044+
let module Response = Response.Make (Cohttp_io_with_channels) in
10241045
let headers = Header.init () in
10251046
let k, v = Cookie.Cookie_hdr.serialize [("chunked", "true")] in
10261047
let headers = Header.add headers k v in
@@ -1044,7 +1065,7 @@ let write_stream common s destination destination_protocol prezeroed progress
10441065
Cohttp.Request.make ~meth:`PUT ~version:`HTTP_1_1 ~headers uri'
10451066
in
10461067
Request.write (fun _ -> return ()) request c >>= fun () ->
1047-
Response.read (Cohttp_unbuffered_io.make_input c) >>= fun r ->
1068+
Response.read (Cohttp_io_with_channels.make_input c) >>= fun r ->
10481069
match r with
10491070
| `Invalid x ->
10501071
fail (Failure (Printf.sprintf "Invalid HTTP response: %s" x))

ocaml/vhd-tool/src/xenstore.ml

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -12,102 +12,4 @@
1212
* GNU Lesser General Public License for more details.
1313
*)
1414

15-
let error fmt = Printf.ksprintf (output_string stderr) fmt
16-
17-
module Client = Xs_client_unix.Client (Xs_transport_unix_client)
18-
19-
let make_client () =
20-
try Client.make ()
21-
with e ->
22-
error "Failed to connect to xenstore. The raw error was: %s"
23-
(Printexc.to_string e) ;
24-
( match e with
25-
| Unix.Unix_error (Unix.EACCES, _, _) ->
26-
error "Access to xenstore was denied." ;
27-
let euid = Unix.geteuid () in
28-
if euid <> 0 then (
29-
error "My effective uid is %d." euid ;
30-
error "Typically xenstore can only be accessed by root (uid 0)." ;
31-
error "Please switch to root (uid 0) and retry."
32-
)
33-
| Unix.Unix_error (Unix.ECONNREFUSED, _, _) ->
34-
error "Access to xenstore was refused." ;
35-
error "This normally indicates that the service is not running." ;
36-
error "Please start the xenstore service and retry."
37-
| _ ->
38-
()
39-
) ;
40-
raise e
41-
42-
let get_client =
43-
let client = ref None in
44-
fun () ->
45-
match !client with
46-
| None ->
47-
let c = make_client () in
48-
client := Some c ;
49-
c
50-
| Some c ->
51-
c
52-
53-
type domid = int
54-
55-
module Xs = struct
56-
type domid = int
57-
58-
type xsh = {
59-
(*
60-
debug: string list -> string;
61-
*)
62-
directory: string -> string list
63-
; read: string -> string
64-
; (*
65-
readv : string -> string list -> string list;
66-
*)
67-
write: string -> string -> unit
68-
; writev: string -> (string * string) list -> unit
69-
; mkdir: string -> unit
70-
; rm: string -> unit
71-
; (*
72-
getperms : string -> perms;
73-
setpermsv : string -> string list -> perms -> unit;
74-
release : domid -> unit;
75-
resume : domid -> unit;
76-
*)
77-
setperms: string -> Xs_protocol.ACL.t -> unit
78-
; getdomainpath: domid -> string
79-
; watch: string -> string -> unit
80-
; unwatch: string -> string -> unit
81-
; introduce: domid -> nativeint -> int -> unit
82-
; set_target: domid -> domid -> unit
83-
}
84-
85-
let ops h =
86-
{
87-
read= Client.read h
88-
; directory= Client.directory h
89-
; write= Client.write h
90-
; writev=
91-
(fun base_path ->
92-
List.iter (fun (k, v) -> Client.write h (base_path ^ "/" ^ k) v)
93-
)
94-
; mkdir= Client.mkdir h
95-
; rm= (fun path -> try Client.rm h path with Xs_protocol.Enoent _ -> ())
96-
; setperms= Client.setperms h
97-
; getdomainpath= Client.getdomainpath h
98-
; watch= Client.watch h
99-
; unwatch= Client.unwatch h
100-
; introduce= Client.introduce h
101-
; set_target= Client.set_target h
102-
}
103-
104-
let with_xs f = Client.immediate (get_client ()) (fun h -> f (ops h))
105-
106-
let wait f = Client.wait (get_client ()) (fun h -> f (ops h))
107-
108-
let transaction _ f = Client.transaction (get_client ()) (fun h -> f (ops h))
109-
end
110-
111-
module Xst = Xs
112-
113-
let with_xs = Xs.with_xs
15+
include Ezxenstore_core.Xenstore

0 commit comments

Comments
 (0)