Skip to content

Commit

Permalink
Merge connect_from_config into connect with optional arguments
Browse files Browse the repository at this point in the history
Existing code which calls `Block.connect path` will still work.

New code can now request different behaviour by supplying the optional
arguments ?buffered and ?sync.

Signed-off-by: David Scott <[email protected]>
  • Loading branch information
djs55 committed Sep 20, 2016
1 parent c61e37c commit b89887b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 5 additions & 3 deletions lib/block.ml
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ let remove_prefix prefix x =
then true, String.sub x prefix' (x' - prefix')
else false, x

let connect name =
let buffered, path = remove_prefix buffered_prefix name in
let config = { Config.buffered; sync = false; path } in
let connect ?buffered ?sync name =
let legacy_buffered, path = remove_prefix buffered_prefix name in
(* Keep support for the legacy buffered: prefix until version 3.x.y *)
let buffered = if legacy_buffered then Some true else buffered in
let config = Config.create ?buffered ?sync name in
connect_from_config config

let disconnect t = match t.fd with
Expand Down
10 changes: 5 additions & 5 deletions lib/block.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ val blkgetsize: string -> Unix.file_descr -> [ `Ok of int64 | `Error of error ]
given by [fd]. [path] is only used to construct a human-readable error
message. *)

val connect : string -> [`Ok of t | `Error of error] io

module Config: sig
type t = {
buffered: bool; (** true if I/O hits the OS disk caches, false if "direct" *)
Expand All @@ -54,9 +52,11 @@ module Config: sig
(** Parse the result of a previous [to_string] invocation *)
end

val connect_from_config : Config.t -> [`Ok of t | `Error of error] io
(** [connect_from_config config] connects to the block device described by
[config]. *)
val connect : ?buffered:bool -> ?sync:bool -> string -> [`Ok of t | `Error of error] io
(** [connect ?buffered ?sync path] connects to a block device on the filesystem
at [path]. By default I/O is unbuffered and fully synchronous. These defaults
can be changed by supplying the optional arguments [~buffered:true] and
[~sync:false] *)

val resize : t -> int64 -> [ `Ok of unit | `Error of error ] io
(** [resize t new_size_sectors] attempts to resize the connected device
Expand Down

0 comments on commit b89887b

Please sign in to comment.