@@ -34,6 +34,7 @@ type plugin = {
3434 processor : processor
3535 ; backend_domain : string
3636 ; query_result : query_result
37+ ; features : Smint .feature list
3738}
3839
3940let plugins : (sr, plugin) Hashtbl.t = Hashtbl. create 10
@@ -48,8 +49,16 @@ let debug_printer rpc call =
4849
4950let register sr rpc d info =
5051 with_lock m (fun () ->
52+ let features =
53+ Smint. parse_capability_int64_features info.Storage_interface. features
54+ in
5155 Hashtbl. replace plugins sr
52- {processor= debug_printer rpc; backend_domain= d; query_result= info} ;
56+ {
57+ processor= debug_printer rpc
58+ ; backend_domain= d
59+ ; query_result= info
60+ ; features
61+ } ;
5362 debug " register SR %s (currently-registered = [ %s ])" (s_of_sr sr)
5463 (String. concat " , "
5564 (Hashtbl. fold (fun sr _ acc -> s_of_sr sr :: acc) plugins [] )
@@ -69,6 +78,13 @@ let query_result_of_sr sr =
6978 try with_lock m (fun () -> Some (Hashtbl. find plugins sr).query_result)
7079 with _ -> None
7180
81+ let sr_has_capability sr capability =
82+ try
83+ with_lock m (fun () ->
84+ Smint. has_capability capability (Hashtbl. find plugins sr).features
85+ )
86+ with _ -> false
87+
7288(* This is the policy: *)
7389let of_sr sr =
7490 with_lock m (fun () ->
@@ -156,7 +172,8 @@ module Mux = struct
156172 end
157173
158174 module DP_info = struct
159- type t = {sr : Sr .t ; vdi : Vdi .t ; vm : Vm .t } [@@ deriving rpcty ]
175+ type t = {sr : Sr .t ; vdi : Vdi .t ; vm : Vm .t ; read_write : bool [@ default true ]}
176+ [@@ deriving rpcty ]
160177
161178 let storage_dp_path = " /var/run/nonpersistent/xapi/storage-dps"
162179
@@ -496,7 +513,7 @@ module Mux = struct
496513 let rpc = of_sr sr
497514 end )) in
498515 let vm = Vm. of_string " 0" in
499- DP_info. write dp DP_info. {sr; vdi; vm} ;
516+ DP_info. write dp DP_info. {sr; vdi; vm; read_write } ;
500517 let backend = C.VDI. attach3 dbg dp sr vdi vm read_write in
501518 (* VDI.attach2 should be used instead, VDI.attach is only kept for
502519 backwards-compatibility, because older xapis call Remote.VDI.attach during SXM.
@@ -543,7 +560,7 @@ module Mux = struct
543560 let rpc = of_sr sr
544561 end )) in
545562 let vm = Vm. of_string " 0" in
546- DP_info. write dp DP_info. {sr; vdi; vm} ;
563+ DP_info. write dp DP_info. {sr; vdi; vm; read_write } ;
547564 C.VDI. attach3 dbg dp sr vdi vm read_write
548565
549566 let attach3 () ~dbg ~dp ~sr ~vdi ~vm ~read_write =
@@ -552,7 +569,7 @@ module Mux = struct
552569 let module C = StorageAPI (Idl.Exn. GenClient (struct
553570 let rpc = of_sr sr
554571 end )) in
555- DP_info. write dp DP_info. {sr; vdi; vm} ;
572+ DP_info. write dp DP_info. {sr; vdi; vm; read_write } ;
556573 C.VDI. attach3 dbg dp sr vdi vm read_write
557574
558575 let activate () ~dbg ~dp ~sr ~vdi =
@@ -569,7 +586,30 @@ module Mux = struct
569586 let module C = StorageAPI (Idl.Exn. GenClient (struct
570587 let rpc = of_sr sr
571588 end )) in
572- C.VDI. activate3 dbg dp sr vdi vm
589+ let read_write =
590+ let open DP_info in
591+ match read dp with
592+ | Some x ->
593+ x.read_write
594+ | None ->
595+ failwith " DP not found"
596+ in
597+ if (not read_write) && sr_has_capability sr Smint. Vdi_activate_readonly
598+ then (
599+ info " The VDI was attached read-only: calling activate_readonly" ;
600+ C.VDI. activate_readonly dbg dp sr vdi vm
601+ ) else (
602+ info " The VDI was attached read/write: calling activate3" ;
603+ C.VDI. activate3 dbg dp sr vdi vm
604+ )
605+
606+ let activate_readonly () ~dbg ~dp ~sr ~vdi ~vm =
607+ info " VDI.activate_readonly dbg:%s dp:%s sr:%s vdi:%s vm:%s" dbg dp
608+ (s_of_sr sr) (s_of_vdi vdi) (s_of_vm vm) ;
609+ let module C = StorageAPI (Idl.Exn. GenClient (struct
610+ let rpc = of_sr sr
611+ end )) in
612+ C.VDI. activate_readonly dbg dp sr vdi vm
573613
574614 let deactivate () ~dbg ~dp ~sr ~vdi ~vm =
575615 info " VDI.deactivate dbg:%s dp:%s sr:%s vdi:%s vm:%s" dbg dp (s_of_sr sr)
0 commit comments