Browse files

CA-101699: Allow VDI.copy if a VDI is only attached RO

Attempting to copy a VDI which is being written to can confuse
sparse_dd, however if a disk is only attached RO it's safe to copy it.

Signed-off-by: John Else <john.else@citrix.com>
  • Loading branch information...
1 parent 1d7f75c commit 3adadf7677954d96faf9f041bfb9ab574cd70b2f @johnelse committed Mar 23, 2013
Showing with 19 additions and 1 deletion.
  1. +19 −1 ocaml/xapi/xapi_vdi.ml
View
20 ocaml/xapi/xapi_vdi.ml
@@ -65,6 +65,8 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
(* Only a 'live' operation can be performed if there are active (even RO) devices *)
let is_active v = v.Db_actions.vBD_currently_attached || v.Db_actions.vBD_reserved in
+ (* VDI.copy can be performed if a VDI is only attached RO *)
+ let is_active_rw v = (is_active v) && (v.Db_actions.vBD_mode = `RW) in
(* VBD operations (plug/unplug) (which should be transient) cause us to serialise *)
let has_current_operation v = v.Db_actions.vBD_current_operations <> [] in
@@ -78,13 +80,29 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
| `clone -> true
| _ -> false in
+ let operation_can_be_performed_with_ro_attach =
+ operation_can_be_performed_live ||
+ (match op with
+ | `copy -> true
+ | _ -> false)
+ in
+
(* NB RO vs RW sharing checks are done in xapi_vbd.ml *)
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)
+ let blocked_by_attach =
+ if operation_can_be_performed_live
+ then false
+ else begin
+ if operation_can_be_performed_with_ro_attach
+ then (any_vbd is_active_rw)
+ else (any_vbd is_active)
+ end
+ in
+ if blocked_by_attach
then Some (Api_errors.vdi_in_use,[_ref; (Record_util.vdi_operation_to_string op)])
else if any_vbd has_current_operation
then Some (Api_errors.other_operation_in_progress, [ "VDI"; _ref ])

0 comments on commit 3adadf7

Please sign in to comment.