Skip to content

Commit

Permalink
[sparse_dd] read default configuration params from /etc/sparse_dd.conf
Browse files Browse the repository at this point in the history
This makes it possible to tweak the values in the field if something
underperforms.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
  • Loading branch information
David Scott committed Jul 1, 2012
1 parent 8e5729b commit 64247a6
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 20 deletions.
68 changes: 48 additions & 20 deletions ocaml/xapi/sparse_dd.ml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,23 +13,9 @@ open Xmlrpc_client
let ( +* ) = Int64.add let ( +* ) = Int64.add
let ( -* ) = Int64.sub let ( -* ) = Int64.sub
let ( ** ) = Int64.mul let ( ** ) = Int64.mul

let kib = 1024L let kib = 1024L
let mib = kib ** kib let mib = kib ** kib


let blocksize = ref (2L ** mib)

exception ShortWrite of int (* offset *) * int (* expected *) * int (* actual *)

(* Consider a tunable quantum of non-zero'ness such that if we encounter
a non-zero, we know we're going to incur the penalty of a seek/write
and we may as well write a sizeable chunk at a time. *)
let quantum = ref 16384
let roundup x =
((x + !quantum + !quantum - 1) / !quantum) * !quantum
let rounddown x =
(x / !quantum) * !quantum

(* Set to true when we want machine-readable output *) (* Set to true when we want machine-readable output *)
let machine_readable = ref false let machine_readable = ref false
let debug_m = Mutex.create () let debug_m = Mutex.create ()
Expand Down Expand Up @@ -59,6 +45,49 @@ let close_output () =
then Chunk.marshal Unix.stdout { Chunk.start = 0L; data = "" } then Chunk.marshal Unix.stdout { Chunk.start = 0L; data = "" }
) )


let config_file = "/etc/sparse_dd.conf"

let blocksize = ref (2L ** mib)

(* Consider a tunable quantum of non-zero'ness such that if we encounter
a non-zero, we know we're going to incur the penalty of a seek/write
and we may as well write a sizeable chunk at a time. *)
let quantum = ref 16384

(* Impose an upper limit on the number of inflight requests
to avoid consuming too much memory in the receiver. The receiver
really ought to handle this itself. *)
let max_inflight_requests = ref 1L

let config_spec = [
"blocksize", Config.String (fun x -> blocksize := Int64.of_string x);
"quantum", Config.Set_int quantum;
"max_inflight_requests", Config.String (fun x -> max_inflight_requests := Int64.of_string x)
]

let read_config_file () =
let unknown_key k v = debug "Unknown key/value pairs: (%s, %s)" k v in
if Sys.file_exists config_file then begin
(* Will raise exception if config is mis-formatted. It's up to the
caller to inspect and handle the failure.
*)
Config.read config_file config_spec unknown_key;
debug "Read global variables successfully from %s" config_file
end

let dump_config () : unit =
debug "blocksize = %Ld" !blocksize;
debug "quantum = %d" !quantum;
debug "max_inflight_requests = %Ld" !max_inflight_requests


exception ShortWrite of int (* offset *) * int (* expected *) * int (* actual *)

let roundup x =
((x + !quantum + !quantum - 1) / !quantum) * !quantum
let rounddown x =
(x / !quantum) * !quantum

(** The copying routine has inputs and outputs which both look like a (** The copying routine has inputs and outputs which both look like a
Unix file-descriptor *) Unix file-descriptor *)
module type IO = sig module type IO = sig
Expand Down Expand Up @@ -174,10 +203,6 @@ module Nbd_writer = struct
this many success responses. *) this many success responses. *)
let num_inflight_requests = ref 0L let num_inflight_requests = ref 0L


(* Impose an upper limit on the number of inflight requests
since I suspect a bug in the tapdisk receive code *)
let max_inflight_requests = ref 1L

module Int64Set = Set.Make(struct type t = int64 let compare = compare end) module Int64Set = Set.Make(struct type t = int64 let compare = compare end)
module Int64Map = Map.Make(struct type t = int64 let compare = compare end) module Int64Map = Map.Make(struct type t = int64 let compare = compare end)


Expand Down Expand Up @@ -554,6 +579,7 @@ let progress_cb =
let _ = let _ =
Stunnel.init_stunnel_path (); Stunnel.init_stunnel_path ();
let base = ref None and src = ref None and dest = ref None and size = ref (-1L) and prezeroed = ref false and test = ref false in let base = ref None and src = ref None and dest = ref None and size = ref (-1L) and prezeroed = ref false and test = ref false in
read_config_file ();
Arg.parse [ "-base", Arg.String (fun x -> base := Some x), "base disk to search for differences from (default: None)"; Arg.parse [ "-base", Arg.String (fun x -> base := Some x), "base disk to search for differences from (default: None)";
"-src", Arg.String (fun x -> src := Some x), "source disk"; "-src", Arg.String (fun x -> src := Some x), "source disk";
"-dest", Arg.String (fun x -> dest := Some x), "destination disk"; "-dest", Arg.String (fun x -> dest := Some x), "destination disk";
Expand All @@ -562,8 +588,8 @@ let _ =
"-prezeroed", Arg.Set prezeroed, "assume the destination disk has been prezeroed (but not full of zeroes if [-base] is provided)"; "-prezeroed", Arg.Set prezeroed, "assume the destination disk has been prezeroed (but not full of zeroes if [-base] is provided)";
"-machine", Arg.Set machine_readable, "emit machine-readable output"; "-machine", Arg.Set machine_readable, "emit machine-readable output";
"-test", Arg.Set test, "perform some unit tests"; "-test", Arg.Set test, "perform some unit tests";
"-nbd:max_requests", Arg.Int (fun x -> Nbd_writer.max_inflight_requests := (Int64.of_int x)), "set the maximum number of in-flight requests"; "-max_inflight_requests", Arg.Int (fun x -> max_inflight_requests := (Int64.of_int x)), "set the maximum number of in-flight requests";
"-zeroscanner:quantum", Arg.Set_int quantum, "set the minimum non-zero block size"; "-quantum", Arg.Set_int quantum, "set the minimum non-zero block size";
] ]
(fun x -> Printf.fprintf stderr "Warning: ignoring unexpected argument %s\n" x) (fun x -> Printf.fprintf stderr "Warning: ignoring unexpected argument %s\n" x)
(String.concat "\n" [ "Usage:"; (String.concat "\n" [ "Usage:";
Expand Down Expand Up @@ -593,6 +619,8 @@ let _ =
" -- copy up to 1024 bytes of *differences* between /dev/xvdc and /dev/xvda into"; " -- copy up to 1024 bytes of *differences* between /dev/xvdc and /dev/xvda into";
" into /dev/xvdb under the assumption that /dev/xvdb contains identical data"; " into /dev/xvdb under the assumption that /dev/xvdb contains identical data";
" to /dev/xvdb."; ]); " to /dev/xvdb."; ]);
dump_config ();

if !test then begin if !test then begin
test_lots_of_strings (); test_lots_of_strings ();
exit 0 exit 0
Expand Down
1 change: 1 addition & 0 deletions scripts/OMakefile
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ install:
$(IPROG) xapi-autostart-vms $(DESTDIR)$(BINDIR) $(IPROG) xapi-autostart-vms $(DESTDIR)$(BINDIR)
$(IPROG) udhcpd.skel $(DESTDIR)/var/xapi/udhcpd.skel #### FHS_FIXME $(IPROG) udhcpd.skel $(DESTDIR)/var/xapi/udhcpd.skel #### FHS_FIXME
$(IDATA) xapi.conf $(DESTDIR)$(XAPICONF) $(IDATA) xapi.conf $(DESTDIR)$(XAPICONF)
$(IDATA) sparse_dd.conf $(DESTDIR)/etc/sparse_dd.conf
$(IDATA) xenopsd.conf $(DESTDIR)/etc/xenopsd.conf $(IDATA) xenopsd.conf $(DESTDIR)/etc/xenopsd.conf
$(IDATA) squeezed.conf $(DESTDIR)/etc/squeezed.conf $(IDATA) squeezed.conf $(DESTDIR)/etc/squeezed.conf
$(IPROG) log.conf $(DESTDIR)$(ETCDIR)/log.conf $(IPROG) log.conf $(DESTDIR)$(ETCDIR)/log.conf
Expand Down
12 changes: 12 additions & 0 deletions scripts/sparse_dd.conf
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,12 @@
# The sparse_dd config file

# The maximum number of NBD write requests to transmit
# without receiving a reply
max_inflight_requests = 8

# The input blocksize (bytes)
blocksize = 2097152

# Blocks of zeroes are rounded to the nearest 'quantum'
# (Should be a multiple of a page size)
quantum = 16384
1 change: 1 addition & 0 deletions xapi.spec.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ rm -rf $RPM_BUILD_ROOT
@OPTDIR@/libexec/shell.pyc @OPTDIR@/libexec/shell.pyc
@OPTDIR@/libexec/shutdown @OPTDIR@/libexec/shutdown
@OPTDIR@/libexec/sparse_dd @OPTDIR@/libexec/sparse_dd
/etc/sparse_dd.conf
@OPTDIR@/libexec/update-mh-info @OPTDIR@/libexec/update-mh-info
@OPTDIR@/libexec/upload-wrapper @OPTDIR@/libexec/upload-wrapper
@OPTDIR@/libexec/vncterm-wrapper @OPTDIR@/libexec/vncterm-wrapper
Expand Down

0 comments on commit 64247a6

Please sign in to comment.