From 2ee74d4c98cabb9bf01d4eef7b1ada8b7cf41a50 Mon Sep 17 00:00:00 2001 From: David Scott Date: Sun, 8 Dec 2013 21:42:38 +0000 Subject: [PATCH 1/3] Add a 'Block' module for consistency with mirage-block-unix --- _oasis | 2 +- lib/block.ml | 18 ++++++++++++++++++ lib/mirage_block_xen_front.mllib | 3 ++- setup.ml | 6 +++--- 4 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 lib/block.ml diff --git a/_oasis b/_oasis index f901827..c039f95 100644 --- a/_oasis +++ b/_oasis @@ -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 diff --git a/lib/block.ml b/lib/block.ml new file mode 100644 index 0000000..95e8584 --- /dev/null +++ b/lib/block.ml @@ -0,0 +1,18 @@ +(* + * Copyright (c) 2011 Anil Madhavapeddy + * 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 diff --git a/lib/mirage_block_xen_front.mllib b/lib/mirage_block_xen_front.mllib index 5e98dd6..66589c1 100644 --- a/lib/mirage_block_xen_front.mllib +++ b/lib/mirage_block_xen_front.mllib @@ -1,4 +1,5 @@ # OASIS_START -# DO NOT EDIT (digest: 2d16726a1926756d424db957c9d78408) +# DO NOT EDIT (digest: 107f6e4120747abbdecbbf87d3539115) Blkfront +Block # OASIS_STOP diff --git a/setup.ml b/setup.ml index e9d0064..1a63779 100644 --- a/setup.ml +++ b/setup.ml @@ -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 @@ -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"; @@ -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; From 81715f90fe6dd8d4690a67f670e1f62ca941b45a Mon Sep 17 00:00:00 2001 From: David Scott Date: Sun, 8 Dec 2013 22:25:16 +0000 Subject: [PATCH 2/3] connect: if we don't recognise the disk id, use the first available disk For the moment mirari will pass the full path of the image in dom0. Until we come up with a better scheme, we choose the first disk if we don't recognise the id. --- lib/blkfront.ml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/blkfront.ml b/lib/blkfront.ml index b407278..a493140 100644 --- a/lib/blkfront.ml +++ b/lib/blkfront.ml @@ -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 From c2c26ad90d38eab92d080e1c0ff684f45bf0dfef Mon Sep 17 00:00:00 2001 From: David Scott Date: Sun, 8 Dec 2013 22:26:11 +0000 Subject: [PATCH 3/3] Release 0.5.0 Signed-off-by: David Scott --- CHANGES | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES b/CHANGES index ebf5cbf..6dfee00 100644 --- a/CHANGES +++ b/CHANGES @@ -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