Skip to content

Commit

Permalink
Merge pull request #13 from djs55/fix-connect
Browse files Browse the repository at this point in the history
Fix connect
  • Loading branch information
djs55 committed Dec 8, 2013
2 parents 005e528 + c2c26ad commit aca8cdd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.5.0 (8-Dec-2013)
* Block.connect: if we don't recognise the id, default to the
first available disk.

0.4.0 (8-Dec-2013)
* implement new mirage-types BLOCK interface

Expand Down
2 changes: 1 addition & 1 deletion _oasis
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Library mirage_block_xen_front
Path: lib
Findlibparent: mirage_block_xen
Findlibname: front
Modules: Blkfront
Modules: Blkfront, Block
BuildDepends: lwt, lwt.syntax, cstruct, cstruct.syntax, mirage-types, shared-memory-ring, shared-memory-ring.lwt, mirage-block-xen

Library mirage_block_xen_back
Expand Down
25 changes: 16 additions & 9 deletions lib/blkfront.ml
Original file line number Diff line number Diff line change
Expand Up @@ -365,15 +365,22 @@ let connect id =
if Hashtbl.mem devices id
then return (`Ok (Hashtbl.find devices id))
else
let t, u = Lwt.task () in
let seq =
if Hashtbl.mem devices_waiters id
then Hashtbl.find devices_waiters id
else Lwt_sequence.create () in
let (_: t Lwt.u Lwt_sequence.node) = Lwt_sequence.add_r u seq in
Hashtbl.replace devices_waiters id seq;
lwt dev = t in
return (`Ok dev)
(* If [id] is an integer, use it. Otherwise default to the first
available disk. *)
lwt all = enumerate () in
let id' = if List.mem id all then Some id
else (if all = [] then None else Some (List.hd all)) in
match id' with
| Some id' ->
printf "Block.connect %s -> %s\n%!" id id';
lwt trans = plug id' in
let dev = { vdev = int_of_string id';
t = trans } in
Hashtbl.add devices id' dev;
return (`Ok dev)
| None ->
printf "Block.connect %s: could not find device\n" id;
return (`Error (`Unknown (Printf.sprintf "device %s not found (available = [ %s ])" id (String.concat ", " all))))

let id t = string_of_int t.vdev

Expand Down
18 changes: 18 additions & 0 deletions lib/block.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(*
* Copyright (c) 2011 Anil Madhavapeddy <[email protected]>
* Copyright (c) 2012 Citrix Systems Inc
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)

include Blkfront
3 changes: 2 additions & 1 deletion lib/mirage_block_xen_front.mllib
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# OASIS_START
# DO NOT EDIT (digest: 2d16726a1926756d424db957c9d78408)
# DO NOT EDIT (digest: 107f6e4120747abbdecbbf87d3539115)
Blkfront
Block
# OASIS_STOP
6 changes: 3 additions & 3 deletions setup.ml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(* setup.ml generated for the first time by OASIS v0.3.1 *)

(* OASIS_START *)
(* DO NOT EDIT (digest: 52694d691db3c3d499bac15b1bac86ff) *)
(* DO NOT EDIT (digest: f039a596039f9023c6c8c16392405974) *)
(*
Regenerated by OASIS v0.3.0
Visit http://oasis.forge.ocamlcore.org for more information and
Expand Down Expand Up @@ -5722,7 +5722,7 @@ let setup_t =
bs_nativeopt = [(OASISExpr.EBool true, [])];
},
{
lib_modules = ["Blkfront"];
lib_modules = ["Blkfront"; "Block"];
lib_pack = false;
lib_internal_modules = [];
lib_findlib_parent = Some "mirage_block_xen";
Expand Down Expand Up @@ -5780,7 +5780,7 @@ let setup_t =
};
oasis_fn = Some "_oasis";
oasis_version = "0.3.0";
oasis_digest = Some "\233k%[.\200\211\243`|\171\231\028\015\236%";
oasis_digest = Some "\180W\148;a\253\2020\r\195o\247j\190\236*";
oasis_exec = None;
oasis_setup_args = [];
setup_update = false;
Expand Down

0 comments on commit aca8cdd

Please sign in to comment.