From: Vincent Hanquez Date: Sun, 15 Nov 2009 22:53:48 +0000 (+0000) Subject: extends disk config to add crypt configuration X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2d6f84649890711193278d231a09b5e569f04d99;p=xenclient%2Ftoolstack.git extends disk config to add crypt configuration add support for arbitrary extra k=v arguments in disk config. --- diff --git a/xenvm/vmact.ml b/xenvm/vmact.ml index caa66f1..d00548c 100644 --- a/xenvm/vmact.ml +++ b/xenvm/vmact.ml @@ -685,6 +685,7 @@ let add_disk state path device ty mode devtype = Vmconfig.disk_mode = Device.Vbd.mode_of_string mode; Vmconfig.disk_devtype = Device.Vbd.devty_of_string devtype; Vmconfig.disk_dynadded = false; + Vmconfig.disk_crypt = None; } in let cfg = get_new_config state in let cfg = { cfg with disks = cfg.disks @ [ disk ] } in diff --git a/xenvm/vmconfig.ml b/xenvm/vmconfig.ml index 91fd59d..af905e8 100644 --- a/xenvm/vmconfig.ml +++ b/xenvm/vmconfig.ml @@ -76,6 +76,12 @@ type config_pci = { pci_power_mgmt: int option; } +type config_disk_crypt = { + disk_crypt_cipher: string; + disk_crypt_key_size: int; + disk_crypt_key_file: string; +} + type config_disk = { disk_physpath: string; disk_physty: Device.Vbd.physty; @@ -83,6 +89,7 @@ type config_disk = { disk_mode: Device.Vbd.mode; disk_devtype: Device.Vbd.devty; disk_dynadded: bool; + disk_crypt: config_disk_crypt option; } type config_nic = { @@ -326,12 +333,35 @@ let config_disk_of_string s = (* physpath:phystype:virtpath:mode:devtype *) let ls = String.split ':' s in - let physpath = List.nth ls 0 - and phystype = Device.Vbd.physty_of_string (List.nth ls 1) - and virtpath = List.nth ls 2 - and mode = Device.Vbd.mode_of_string (List.nth ls 3) - and devtype = Device.Vbd.devty_of_string (List.nth ls 4) in - + let (physpath, phystype, virtpath, mode, devtype, kvs) = + match ls with + | physpath :: physty_s :: virtpath :: mode_s :: devtype_s :: left -> + let kvs = List.fold_left (fun acc s -> + match String.split '=' s with + | [ k; v ] -> (k, v) :: acc + | _ -> acc + ) [] left in + (physpath, Device.Vbd.physty_of_string physty_s, + virtpath, Device.Vbd.mode_of_string mode_s, + Device.Vbd.devty_of_string devtype_s, kvs) + | _ -> + failwith "need at least 5 arguments for disk" + in + let crypt_cipher, crypt_key_size, crypt_key_file = + (try Some (List.assoc "cipher" kvs) with Not_found -> None), + (try Some (List.assoc "key-size" kvs) with Not_found -> None), + (try Some (List.assoc "key-file" kvs) with Not_found -> None) + in + let dc = + if crypt_cipher = None && crypt_key_size = None && crypt_key_file = None then + None + else + Some { + disk_crypt_cipher = (match crypt_cipher with None -> "aes-xts-plain" | Some c -> c); + disk_crypt_key_size = (match crypt_key_size with None -> 256 | Some i -> int_of_string i); + disk_crypt_key_file = ""; + } + in { disk_physpath = physpath; disk_physty = phystype; @@ -339,6 +369,7 @@ let config_disk_of_string s = disk_mode = mode; disk_devtype = devtype; disk_dynadded = false; + disk_crypt = dc; } let config_cpuid_of_string s =