cleanups in respect to directories and scope

This commit is contained in:
Hannes Mehnert 2018-11-11 02:33:00 +01:00
parent 43379d6d9d
commit 89a1d30154
4 changed files with 17 additions and 21 deletions

View file

@ -51,7 +51,7 @@ let read_console id name ring channel () =
Lwt_io.close channel) Lwt_io.close channel)
let open_fifo name = let open_fifo name =
let fifo = Fpath.(Vmm_core.tmpdir / "fifo" / name) in let fifo = Vmm_core.Name.fifo_file name in
Lwt.catch (fun () -> Lwt.catch (fun () ->
Logs.debug (fun m -> m "opening %a for reading" Fpath.pp fifo) ; Logs.debug (fun m -> m "opening %a for reading" Fpath.pp fifo) ;
Lwt_io.open_file ~mode:Lwt_io.Input (Fpath.to_string fifo) >>= fun channel -> Lwt_io.open_file ~mode:Lwt_io.Input (Fpath.to_string fifo) >>= fun channel ->
@ -68,7 +68,7 @@ let t = ref String.Map.empty
let add_fifo id = let add_fifo id =
let name = Vmm_core.Name.to_string id in let name = Vmm_core.Name.to_string id in
open_fifo name >|= function open_fifo id >|= function
| Some f -> | Some f ->
let ring = Vmm_ring.create "" () in let ring = Vmm_ring.create "" () in
Logs.debug (fun m -> m "inserting fifo %s" name) ; Logs.debug (fun m -> m "inserting fifo %s" name) ;

View file

@ -5,18 +5,16 @@ open Astring
open Rresult.R.Infix open Rresult.R.Infix
let tmpdir = Fpath.(v "/var" / "run" / "albatross") let tmpdir = Fpath.(v "/var" / "run" / "albatross")
let dbdir = Fpath.(v "/var" / "db" / "albatross") let sockdir = Fpath.(tmpdir / "util")
let blockdir = Fpath.(dbdir / "block")
type service = [ `Console | `Log | `Stats | `Vmmd ] type service = [ `Console | `Log | `Stats | `Vmmd ]
let socket_path t = let socket_path t =
let path name = Fpath.(tmpdir / "util" / name + "sock") in
let path = match t with let path = match t with
| `Console -> path "console" | `Console -> Fpath.(sockdir / "console" + "sock")
| `Vmmd -> Fpath.(tmpdir / "vmmd" + "sock") | `Vmmd -> Fpath.(tmpdir / "vmmd" + "sock")
| `Stats -> path "stat" | `Stats -> Fpath.(sockdir / "stat" + "sock")
| `Log -> path "log" | `Log -> Fpath.(sockdir / "log" + "sock")
in in
Fpath.to_string path Fpath.to_string path
@ -90,10 +88,6 @@ module Name = struct
let file = to_string name in let file = to_string name in
Fpath.(tmpdir / "fifo" / file) Fpath.(tmpdir / "fifo" / file)
let block_file name =
let file = to_string name in
Fpath.(blockdir / file)
let block_name vm_name dev = let block_name vm_name dev =
List.rev (dev :: List.rev (domain vm_name)) List.rev (dev :: List.rev (domain vm_name))
@ -122,7 +116,7 @@ module Name = struct
match drop_super ~super ~sub with None -> false | Some _ -> true match drop_super ~super ~sub with None -> false | Some _ -> true
let pp ppf ids = let pp ppf ids =
Fmt.(pf ppf "(%d)%a" (List.length ids) (list ~sep:(unit ".") string) ids) Fmt.(pf ppf "[name %a]" (list ~sep:(unit ".") string) ids)
end end
let pp_is ppf is = Fmt.pf ppf "%a" Fmt.(list ~sep:(unit ",") int) (IS.elements is) let pp_is ppf is = Fmt.pf ppf "%a" Fmt.(list ~sep:(unit ",") int) (IS.elements is)

View file

@ -1,9 +1,5 @@
(* (c) 2018 Hannes Mehnert, all rights reserved *) (* (c) 2018 Hannes Mehnert, all rights reserved *)
val tmpdir : Fpath.t
val dbdir : Fpath.t
val blockdir : Fpath.t
type service = [ `Console | `Log | `Stats | `Vmmd ] type service = [ `Console | `Log | `Stats | `Vmmd ]
val socket_path : service -> string val socket_path : service -> string
@ -27,7 +23,6 @@ module Name : sig
val image_file : t -> Fpath.t val image_file : t -> Fpath.t
val fifo_file : t -> Fpath.t val fifo_file : t -> Fpath.t
val block_file : t -> Fpath.t
val of_list : string list -> (t, [> `Msg of string ]) result val of_list : string list -> (t, [> `Msg of string ]) result
val to_list : t -> string list val to_list : t -> string list

View file

@ -53,6 +53,13 @@ let close_no_err fd = try close fd with _ -> ()
open Vmm_core open Vmm_core
let dbdir = Fpath.(v "/var" / "db" / "albatross")
let blockdir = Fpath.(dbdir / "block")
let block_file name =
let file = Name.to_string name in
Fpath.(blockdir / file)
let rec mkfifo name = let rec mkfifo name =
try Unix.mkfifo (Fpath.to_string name) 0o640 with try Unix.mkfifo (Fpath.to_string name) 0o640 with
| Unix.Unix_error (Unix.EINTR, _, _) -> mkfifo name | Unix.Unix_error (Unix.EINTR, _, _) -> mkfifo name
@ -149,7 +156,7 @@ let exec name vm taps block =
| [_], Some _ -> Ok "block-net" | [_], Some _ -> Ok "block-net"
| _, _ -> Error (`Msg "cannot handle multiple network interfaces")) >>= fun bin -> | _, _ -> Error (`Msg "cannot handle multiple network interfaces")) >>= fun bin ->
let net = List.map (fun t -> "--net=" ^ t) taps let net = List.map (fun t -> "--net=" ^ t) taps
and block = match block with None -> [] | Some dev -> [ "--disk=" ^ Fpath.to_string (Name.block_file dev) ] and block = match block with None -> [] | Some dev -> [ "--disk=" ^ Fpath.to_string (block_file dev) ]
and argv = match vm.argv with None -> [] | Some xs -> xs and argv = match vm.argv with None -> [] | Some xs -> xs
and mem = "--mem=" ^ string_of_int vm.requested_memory and mem = "--mem=" ^ string_of_int vm.requested_memory
in in
@ -188,7 +195,7 @@ let bytes_of_mb size =
Error (`Msg "overflow while computing bytes") Error (`Msg "overflow while computing bytes")
let create_block name size = let create_block name size =
let block_name = Name.block_file name in let block_name = block_file name in
Bos.OS.File.exists block_name >>= function Bos.OS.File.exists block_name >>= function
| true -> Error (`Msg "file already exists") | true -> Error (`Msg "file already exists")
| false -> | false ->
@ -196,7 +203,7 @@ let create_block name size =
Bos.OS.File.truncate block_name size' Bos.OS.File.truncate block_name size'
let destroy_block name = let destroy_block name =
Bos.OS.File.delete (Name.block_file name) Bos.OS.File.delete (block_file name)
let mb_of_bytes size = let mb_of_bytes size =
if size = 0 || size land 0xFFFFF <> 0 then if size = 0 || size land 0xFFFFF <> 0 then