Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57 from xapi-project/noxc
Create separate sub-packages for file and page
- Loading branch information
Showing
15 changed files
with
315 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(* -*- tuareg -*- *) | ||
|
||
let coverage_rewriter = | ||
match Sys.getenv "BISECT_ENABLE" with | ||
| "YES" -> "(preprocess (pps bisect_ppx))" | ||
| _ -> "" | ||
| exception Not_found -> "" | ||
|
||
let () = Printf.ksprintf Jbuild_plugin.V1.send {| | ||
(library | ||
(name rrd_transport_file) | ||
(public_name rrd-transport.file) | ||
(wrapped false) | ||
(libraries | ||
rrd_transport_lib | ||
) | ||
%s | ||
) | ||
|} coverage_rewriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(* | ||
* Copyright (C) Citrix Systems Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
module File = struct | ||
(** Filesystem path. *) | ||
type id_t = string | ||
type state_t = Cstruct.t | ||
|
||
let init path = | ||
let fd = Unix.openfile path [Unix.O_RDONLY] 0o400 in | ||
if Unix.lseek fd 0 Unix.SEEK_SET <> 0 then | ||
failwith "lseek"; | ||
let mapping = Bigarray.(array1_of_genarray @@ Unix.map_file fd char | ||
c_layout false [|-1|]) in | ||
Unix.close fd; | ||
Cstruct.of_bigarray mapping | ||
|
||
let cleanup _ _ = () | ||
|
||
let expose cstruct = cstruct | ||
end | ||
|
||
include Rrd_reader_functor.Make(File) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
(* | ||
* Copyright (C) Citrix Systems Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
type local_id = { | ||
path: string; | ||
shared_page_count: int; | ||
} | ||
|
||
module File = struct | ||
let page_size = 4096 | ||
|
||
(** Filesystem path. *) | ||
type id_t = local_id | ||
|
||
(** Filesystem path is returned to the caller for future reference. *) | ||
type info_t = string | ||
|
||
(** fd for writing to the shared file. *) | ||
type state_t = Cstruct.t | ||
|
||
let init {path; shared_page_count} = | ||
let size = shared_page_count * page_size in | ||
let fd = Unix.openfile path [Unix.O_RDWR; Unix.O_CREAT] 0o600 in | ||
let mapping = Bigarray.(array1_of_genarray @@ Unix.map_file fd char | ||
c_layout true [|size|]) in | ||
Unix.close fd; | ||
let cstruct = Cstruct.of_bigarray mapping in | ||
path, cstruct | ||
|
||
let cleanup _ path _ = | ||
Unix.unlink path | ||
|
||
(** This assumes there's no limit to the size of file which can be used. *) | ||
let get_allocator cstruct = | ||
let alloc_cstruct size = | ||
if size > Cstruct.len cstruct | ||
then failwith "not enough memory"; | ||
cstruct | ||
in | ||
alloc_cstruct | ||
end | ||
|
||
include Rrd_writer_functor.Make(File) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
(* | ||
* Copyright (C) Citrix Systems Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
module type TRANSPORT = sig | ||
(** An identifier needed to open the resource. *) | ||
type id_t | ||
|
||
(** A handle to an open resource. *) | ||
type state_t | ||
|
||
(** Open a resource for writing, given its identifier. *) | ||
val init: id_t -> state_t | ||
|
||
(** Cleanup an open resource when it is no longer needed. *) | ||
val cleanup: id_t -> state_t -> unit | ||
|
||
(** Given the state of the open resource, expose its contents as a Cstruct. *) | ||
val expose: state_t -> Cstruct.t | ||
end | ||
|
||
type reader = { | ||
read_payload: unit -> Rrd_protocol.payload; | ||
cleanup: unit -> unit; | ||
} | ||
|
||
module Make (T: TRANSPORT) = struct | ||
let create id protocol = | ||
let state = ref (T.init id) in | ||
let reader = protocol.Rrd_protocol.make_payload_reader () in | ||
let is_open = ref true in | ||
let read_payload () = | ||
if !is_open then begin | ||
let cs = | ||
if Cstruct.len (T.expose !state) <= 0 | ||
then state := (T.init id); | ||
T.expose !state | ||
in | ||
reader cs | ||
end else raise Rrd_io.Resource_closed | ||
in | ||
let cleanup () = | ||
if !is_open then begin | ||
T.cleanup id !state; | ||
is_open := false | ||
end else raise Rrd_io.Resource_closed | ||
in { | ||
read_payload; | ||
cleanup; | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(* -*- tuareg -*- *) | ||
|
||
let coverage_rewriter = | ||
match Sys.getenv "BISECT_ENABLE" with | ||
| "YES" -> "(preprocess (pps bisect_ppx))" | ||
| _ -> "" | ||
| exception Not_found -> "" | ||
|
||
let () = Printf.ksprintf Jbuild_plugin.V1.send {| | ||
(library | ||
(name rrd_transport) | ||
(public_name rrd-transport) | ||
(wrapped false) | ||
(libraries | ||
rrd_transport_file | ||
rrd_transport_page | ||
) | ||
%s | ||
) | ||
|} coverage_rewriter |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
(* | ||
* Copyright (C) Citrix Systems Inc. | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published | ||
* by the Free Software Foundation; version 2.1 only. with the special | ||
* exception on linking described in file LICENSE. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
*) | ||
|
||
type reader = Rrd_reader_functor.reader = { | ||
read_payload: unit -> Rrd_protocol.payload; | ||
cleanup: unit -> unit; | ||
} | ||
|
||
include Rrd_file_reader | ||
include Rrd_page_reader | ||
|
||
module FileReader = Rrd_file_reader | ||
module PageReader = Rrd_page_reader |
Oops, something went wrong.