# HG changeset patch # User Jonathan Ludlam # Date 1263826780 0 # Node ID a75fa4de4ab9c49109d61194be42f81f0eb28f55 # Parent b2fff00ed18ebaa37f60204e5f2628ccadffb669 Add rpc-light support to MLVM to allow it to marshal its data structures as an RPC.t Signed-off-by: Jon Ludlam diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/Makefile --- a/mlvm/Makefile Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/Makefile Mon Jan 18 14:59:40 2010 +0000 @@ -4,9 +4,10 @@ LDFLAGS = -cclib -L./ VERSION = 0.1 +PP = camlp4o -I ../rpc-light -I $(shell ocamlfind query type-conv) pa_type_conv.cmo pa_rpc.cma + DESTDIR ?= / VERSION := $(shell hg parents --template "{rev}" 2>/dev/null || echo 0.0) -OCAMLOPTFLAGS = -g -dtypes OCAMLABI := $(shell ocamlc -version) OCAMLLIBDIR := $(shell ocamlc -where) @@ -17,7 +18,8 @@ CMDOBJS = messages.cmx mlvm.cmx OCAMLC = ocamlfind ocamlc -g OCAMLOPT = ocamlfind ocamlopt -COMPFLAG = -dtypes -g -I ../stdext -I ../camldm -I ../uuid -for-pack Lvm +COMPFLAG = -dtypes -g -I ../stdext -I ../camldm -I ../uuid -for-pack Lvm -pp '${PP}' -I ../rpc-light + LIBS = lvm.cma lvm.cmxa default : $(LIBS) diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/allocator.ml --- a/mlvm/allocator.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/allocator.ml Mon Jan 18 14:59:40 2010 +0000 @@ -1,4 +1,4 @@ -type t = (string * (int64 * int64)) list +type t = (string * (int64 * int64)) list with rpc let create name size = [(name,(0L,size))] diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/lv.ml --- a/mlvm/lv.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/lv.ml Mon Jan 18 14:59:40 2010 +0000 @@ -6,32 +6,32 @@ | Write | Visible -type striped_segment = { +and striped_segment = { st_stripe_size : int64; (* In sectors *) st_stripes : (string * int64) list; (* pv name * start extent *) } -type linear_segment = { +and linear_segment = { l_pv_name : string; l_pv_start_extent : int64; } -type segclass = +and segclass = | Linear of linear_segment | Striped of striped_segment -type segment = +and segment = { s_start_extent : int64; s_extent_count : int64; s_cls : segclass; } -type logical_volume = { +and logical_volume = { name : string; id : string; tags : string list; status : stat list; segments : segment list; -} +} with rpc let status_to_string s = match s with diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/lvmmarshal.ml --- a/mlvm/lvmmarshal.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/lvmmarshal.ml Mon Jan 18 14:59:40 2010 +0000 @@ -14,26 +14,26 @@ let unmarshal_uint16 ?(bigendian=false) (s, offset) = let offsets = if bigendian then [|1;0|] else [|0;1|] in - let (<<) a b = a lsl b - and (||) a b = a lor b in + let (>) a b = a lsr b + let (>!>) a b = a lsr b and (&&) a b = a land b in - let a = (x >> 0) && 0xff - and b = (x >> 8) && 0xff in + let a = (x >!> 0) && 0xff + and b = (x >!> 8) && 0xff in s.[offset+offsets.(0)] <- char_of_int a; s.[offset+offsets.(1)] <- char_of_int b; (s,offset+2) let marshal_int32 (s,offset) ?(bigendian=false) x = let offsets = if bigendian then [|3;2;1;0|] else [|0;1;2;3|] in - let (>>) a b = Int32.shift_right_logical a b + let (>!>) a b = Int32.shift_right_logical a b and (&&) a b = Int32.logand a b in - let a = (x >> 0) && 0xffl - and b = (x >> 8) && 0xffl - and c = (x >> 16) && 0xffl - and d = (x >> 24) && 0xffl in + let a = (x >!> 0) && 0xffl + and b = (x >!> 8) && 0xffl + and c = (x >!> 16) && 0xffl + and d = (x >!> 24) && 0xffl in s.[offset+offsets.(0)] <- char_of_int (Int32.to_int a); s.[offset+offsets.(1)] <- char_of_int (Int32.to_int b); s.[offset+offsets.(2)] <- char_of_int (Int32.to_int c); @@ -81,16 +81,16 @@ let marshal_int64 (s,offset) ?(bigendian=false) x = let offsets = if bigendian then [|7;6;5;4;3;2;1;0|] else [|0;1;2;3;4;5;6;7|] in - let (>>) a b = Int64.shift_right_logical a b + let (>!>) a b = Int64.shift_right_logical a b and (&&) a b = Int64.logand a b in - let a = (x >> 0) && 0xffL - and b = (x >> 8) && 0xffL - and c = (x >> 16) && 0xffL - and d = (x >> 24) && 0xffL - and e = (x >> 32) && 0xffL - and f = (x >> 40) && 0xffL - and g = (x >> 48) && 0xffL - and h = (x >> 56) && 0xffL in + let a = (x >!> 0) && 0xffL + and b = (x >!> 8) && 0xffL + and c = (x >!> 16) && 0xffL + and d = (x >!> 24) && 0xffL + and e = (x >!> 32) && 0xffL + and f = (x >!> 40) && 0xffL + and g = (x >!> 48) && 0xffL + and h = (x >!> 56) && 0xffL in s.[offset+offsets.(0)] <- char_of_int (Int64.to_int a); s.[offset+offsets.(1)] <- char_of_int (Int64.to_int b); s.[offset+offsets.(2)] <- char_of_int (Int64.to_int c); diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/pv.ml --- a/mlvm/pv.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/pv.ml Mon Jan 18 14:59:40 2010 +0000 @@ -28,23 +28,23 @@ ty : string (* 8 bytes, equal to "LVM2 001" - Constants.label_type*) } - type disk_locn = { + and disk_locn = { dl_offset : int64; dl_size : int64; } - type pv_header = { + and pv_header = { pvh_id : string; (* 32 bytes, 'uuid' *) pvh_device_size : int64; pvh_extents: disk_locn list; pvh_metadata_areas: disk_locn list; } - type t = { + and t = { device : string; label_header : label_header; pv_header : pv_header; - } + } with rpc let unmarshal_header b0 = let id,b = unmarshal_string 8 b0 in @@ -97,6 +97,14 @@ pvh_extents=disk_areas; pvh_metadata_areas=disk_areas2},b + let pvh_to_ascii pvh = + let disk_area_list_to_ascii l = + (String.concat "," (List.map (fun da -> Printf.sprintf "{offset=%Ld,size=%Ld}" da.dl_offset da.dl_size) l)) in + Printf.sprintf "pvh_id: %s\npvh_device_size: %Ld\npvh_areas1: %s\npvh_areas2: %s\n" + pvh.pvh_id pvh.pvh_device_size + (disk_area_list_to_ascii pvh.pvh_extents) + (disk_area_list_to_ascii pvh.pvh_metadata_areas) + let write_label_and_pv_header l = let label = l.label_header in let pvh = l.pv_header in @@ -117,7 +125,9 @@ let header = marshal_string header label.ty in assert(snd header = 32); - + + Debug.debug (Printf.sprintf "write_label_and_pv_header:\nPV header:\n%s" (pvh_to_ascii pvh)); + (* PV header *) let header = marshal_string header (Lvm_uuid.remove_hyphens pvh.pvh_id) in let header = marshal_int64 header pvh.pvh_device_size in @@ -155,14 +165,6 @@ Unix.close fd - let pvh_to_ascii pvh = - let disk_area_list_to_ascii l = - (String.concat "," (List.map (fun da -> Printf.sprintf "{offset=%Ld,size=%Ld}" da.dl_offset da.dl_size) l)) in - Printf.sprintf "pvh_id: %s\npvh_device_size: %Ld\npvh_areas1: %s\npvh_areas2: %s\n" - pvh.pvh_id pvh.pvh_device_size - (disk_area_list_to_ascii pvh.pvh_extents) - (disk_area_list_to_ascii pvh.pvh_metadata_areas) - let get_metadata_locations label = label.pv_header.pvh_metadata_areas @@ -205,6 +207,8 @@ end module MDAHeader = struct + let mda_header_size = Constants.sector_size + type mda_raw_locn = { mrl_offset: int64; mrl_size: int64; @@ -212,16 +216,14 @@ mrl_filler: int32; } - let mda_header_size = Constants.sector_size - - type mda_header = { + and mda_header = { mdah_checksum : int32; mdah_magic : string; mdah_version : int32; mdah_start: int64; mdah_size: int64; mdah_raw_locns : mda_raw_locn list; - } + } with rpc let unmarshal_mda_header device location = let offset,fd = @@ -421,7 +423,7 @@ type status = | Allocatable -type physical_volume = { +and physical_volume = { name : string; id : string; dev : string; @@ -432,7 +434,7 @@ pe_count : int64; label : Label.t; (* The one label for this PV *) mda_headers : MDAHeader.mda_header list; -} +} with rpc let status_to_string s = match s with @@ -493,8 +495,8 @@ (** Find the metadata area on a device and return the text of the metadata *) let find_metadata device = let label = Label.find device in - (* Printf.printf "Label found: \n%s\nPV header found:\n%s\n" - (Pv.Label.label_to_ascii label) (Pv.Label.pvh_to_ascii pvh); *) + Debug.debug (Printf.sprintf "Label found: \n%s\n" + (Label.to_ascii label)); let mda_locs = Label.get_metadata_locations label in let mdahs = List.map (MDAHeader.unmarshal_mda_header device) mda_locs in let mdt = MDAHeader.read_md device (List.hd mdahs) 0 in diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/redo.ml --- a/mlvm/redo.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/redo.ml Mon Jan 18 14:59:40 2010 +0000 @@ -4,29 +4,29 @@ lvc_segments : Allocator.t } -type lvrename_t = { +and lvrename_t = { lvmv_new_name : string; } -type lvreduce_t = { +and lvreduce_t = { lvrd_new_extent_count : int64; } -type lvexpand_t = { +and lvexpand_t = { lvex_segments : Allocator.t; } -type operation = +and operation = | LvCreate of string * lvcreate_t | LvReduce of string * lvreduce_t | LvExpand of string * lvexpand_t | LvRename of string * lvrename_t | LvRemove of string -type sequenced_op = { +and sequenced_op = { so_seqno : int; so_op : operation -} +} with rpc open Debug diff -r b2fff00ed18e -r a75fa4de4ab9 mlvm/vg.ml --- a/mlvm/vg.ml Mon Jan 18 14:59:40 2010 +0000 +++ b/mlvm/vg.ml Mon Jan 18 14:59:40 2010 +0000 @@ -8,7 +8,7 @@ | Resizeable | Clustered -type vg = { +and vg = { name : string; id : string; seqno : int; @@ -21,7 +21,7 @@ free_space : Allocator.t; redo_lv : string option; (* Name of the redo LV *) ops : sequenced_op list; -} +} with rpc let status_to_string s = match s with @@ -425,6 +425,7 @@ let create_new name devices_and_names = let pvs = List.map (fun (dev,name) -> Pv.create_new dev name) devices_and_names in + debug "PVs created"; let free_space = List.flatten (List.map (fun pv -> Allocator.create pv.Pv.name pv.Pv.pe_count) pvs) in let vg = { name=name; @@ -441,7 +442,8 @@ ops=[]; } in - write vg true + write vg true; + debug "VG created" let parse text pvdatas = let lexbuf = Lexing.from_string text in