Permalink
Browse files

CA-90263: Remove the need to ever get an SR record as part of Xapi_vd…

…i.check_operation_error

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
1 parent a52f64b commit 97d16321d8b829dc9df7ed8b1420a442e4bc669d @johnelse johnelse committed with jonludlam Sep 20, 2012
Showing with 12 additions and 14 deletions.
  1. +8 −5 ocaml/xapi/xapi_sr_operations.ml
  2. +4 −9 ocaml/xapi/xapi_vdi.ml
@@ -48,12 +48,15 @@ let sm_cap_table =
type table = (API.storage_operations, ((string * (string list)) option)) Hashtbl.t
-let capabilities_of_sr record =
- try
- Sm.capabilities_of_driver record.Db_actions.sR_type
- with Sm.Unknown_driver _ ->
+let capabilities_of_sr_internal ~_type ~uuid =
+ try
+ Sm.capabilities_of_driver _type
+ with Sm.Unknown_driver _ ->
(* then look to see if this supports the SMAPIv2 *)
- Smint.parse_capabilities (Storage_mux.capabilities_of_sr record.Db_actions.sR_uuid)
+ Smint.parse_capabilities (Storage_mux.capabilities_of_sr uuid)
+
+let capabilities_of_sr record =
+ capabilities_of_sr_internal record.Db_actions.sR_type record.Db_actions.sR_uuid
(** Returns a table of operations -> API error options (None if the operation would be ok) *)
let valid_operations ~__context record _ref' : table =
View
@@ -45,13 +45,7 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
else
(* check to see whether it's a local cd drive *)
let sr = record.Db_actions.vDI_SR in
- let sr_record =
- try
- List.assoc sr sr_records
- with Not_found ->
- Db.SR.get_record_internal ~__context ~self:sr
- in
- let srtype = sr_record.Db_actions.sR_type in
+ let sr_type = Db.SR.get_type ~__context ~self:sr in
let is_tools_sr = Helpers.is_tools_sr ~__context ~sr in
(* Check to see if any PBDs are attached *)
@@ -86,7 +80,8 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
(* NB RO vs RW sharing checks are done in xapi_vbd.ml *)
- let sm_caps = Xapi_sr_operations.capabilities_of_sr sr_record in
+ let sr_uuid = Db.SR.get_uuid ~__context ~self:sr in
+ let sm_caps = Xapi_sr_operations.capabilities_of_sr_internal ~_type:sr_type ~uuid:sr_uuid in
let any_vbd p = List.fold_left (||) false (List.map p my_vbd_records) in
if not operation_can_be_performed_live && (any_vbd is_active)
@@ -96,7 +91,7 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
else (
match op with
| `destroy ->
- if srtype = "udev"
+ if sr_type = "udev"
then Some (Api_errors.vdi_is_a_physical_device, [_ref])
else
if is_tools_sr

0 comments on commit 97d1632

Please sign in to comment.