Skip to content

Commit

Permalink
Merge pull request xapi-project#88 from xen-org/cooper2
Browse files Browse the repository at this point in the history
Merge the cooper2 changes
  • Loading branch information
Jon Ludlam committed May 4, 2012
2 parents 3d850a1 + 27aba7d commit 006294d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
57 changes: 57 additions & 0 deletions tapctl/tapctl.ml
Expand Up @@ -3,6 +3,48 @@ open Listext
open Threadext
open Forkhelpers

(* Tapdisk stats *)
module Stats = struct
module Tap = struct
type t = {
minor: int;
reqs: (int64 * int64);
kicks: (int64 * int64);
} with rpc
end

module Driver = struct
type t = {
ty : int;
name : string;
} with rpc

let rpc_of_t x = match (rpc_of_t x) with | Rpc.Dict x -> Rpc.Dict (List.map (function ("ty",y) -> ("type",y) | x -> x) x) | y -> y
let t_of_rpc rpc = t_of_rpc (match rpc with | Rpc.Dict x -> Rpc.Dict (List.map (function ("type",y) -> ("ty",y) | x -> x) x ) | y -> y)

end

module Image = struct
type t = {
name : string;
hits : int64 * int64;
fail : int64 * int64;
driver : Driver.t
} with rpc
end

type t = {
name : string;
secs : (int64 * int64);
images : Image.t list;
tap : Tap.t;
nbd_mirror_failed : int;
} with rpc
end




type tapdev = {
minor : int;
tapdisk_pid : int;
Expand Down Expand Up @@ -228,6 +270,16 @@ module Dummy = struct
else
None
| _ -> None) list)

let stats ctx t =
let open Stats in
{ name = "none";
secs = 0L,0L;
images = [];
tap = { Tap.minor = t.minor;
reqs = 0L,0L;
kicks = 0L,0L; };
nbd_mirror_failed = 0; }
end


Expand Down Expand Up @@ -338,6 +390,11 @@ let is_active ctx t =
| [(tapdev,state,Some _ )] -> true
| _ -> false

let stats ctx t =
if ctx.dummy then Dummy.stats ctx t else begin
Stats.t_of_rpc (Jsonrpc.of_string (invoke_tap_ctl ctx "stats" (args t)))
end

(* We need to be able to check that a given device's major number corresponds to the right driver *)
let read_proc_devices () : (int * string) list =
let parse_line x = match List.filter (fun x -> x <> "") (String.split ' ' x) with
Expand Down
34 changes: 34 additions & 0 deletions tapctl/tapctl.mli
@@ -1,5 +1,38 @@
(** Represents an active tapdisk instance *)
type tapdev

module Stats :
sig
module Tap :
sig
type t = {
minor : int;
reqs : int64 * int64;
kicks : int64 * int64;
}
end
module Driver :
sig
type t = { ty : int; name : string; }
end
module Image :
sig
type t = {
name : string;
hits : int64 * int64;
fail : int64 * int64;
driver : Driver.t;
}
end
type t = {
name : string;
secs : int64 * int64;
images : Image.t list;
tap : Tap.t;
nbd_mirror_failed : int;
}
end

val tapdev_of_rpc : Rpc.t -> tapdev
val rpc_of_tapdev : tapdev -> Rpc.t

Expand Down Expand Up @@ -32,6 +65,7 @@ val free : context -> int -> unit
val list : ?t:tapdev -> context -> t list
val is_paused : context -> tapdev -> bool
val is_active : context -> tapdev -> bool
val stats : context -> tapdev -> Stats.t

(** Thrown by [of_device x] when [x] is a device not owned by blktap *)
exception Not_blktap
Expand Down

0 comments on commit 006294d

Please sign in to comment.