]> xenbits.xen.org Git - xenclient/toolstack.git/commitdiff
extends disk config to add crypt configuration
authorVincent Hanquez <vincent.hanquez@eu.citrix.com>
Sun, 15 Nov 2009 22:53:48 +0000 (22:53 +0000)
committerVincent Hanquez <vincent.hanquez@eu.citrix.com>
Sun, 15 Nov 2009 22:53:48 +0000 (22:53 +0000)
add support for arbitrary extra k=v arguments in disk config.

xenvm/vmact.ml
xenvm/vmconfig.ml

index caa66f102ef6a312990e66c17e10e07ea64bab5a..d00548cb877ff66c072f218819c3f8b79d39d6cc 100644 (file)
@@ -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
index 91fd59dfff30a4470bad938052f42ff2feede06e..af905e845eb402853b37fa59693c1aed70bb6f24 100644 (file)
@@ -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 =