Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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...
commit 3adadf7677954d96faf9f041bfb9ab574cd70b2f 1 parent 1d7f75c
John Else authored

Showing 1 changed file with 19 additions and 1 deletion. Show diff stats Hide diff stats

  1. +19 1 ocaml/xapi/xapi_vdi.ml
20 ocaml/xapi/xapi_vdi.ml
@@ -65,6 +65,8 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
65 65
66 66 (* Only a 'live' operation can be performed if there are active (even RO) devices *)
67 67 let is_active v = v.Db_actions.vBD_currently_attached || v.Db_actions.vBD_reserved in
  68 + (* VDI.copy can be performed if a VDI is only attached RO *)
  69 + let is_active_rw v = (is_active v) && (v.Db_actions.vBD_mode = `RW) in
68 70 (* VBD operations (plug/unplug) (which should be transient) cause us to serialise *)
69 71 let has_current_operation v = v.Db_actions.vBD_current_operations <> [] in
70 72
@@ -78,13 +80,29 @@ let check_operation_error ~__context ?(sr_records=[]) ?(pbd_records=[]) ?(vbd_re
78 80 | `clone -> true
79 81 | _ -> false in
80 82
  83 + let operation_can_be_performed_with_ro_attach =
  84 + operation_can_be_performed_live ||
  85 + (match op with
  86 + | `copy -> true
  87 + | _ -> false)
  88 + in
  89 +
81 90 (* NB RO vs RW sharing checks are done in xapi_vbd.ml *)
82 91
83 92 let sr_uuid = Db.SR.get_uuid ~__context ~self:sr in
84 93 let sm_caps = Xapi_sr_operations.capabilities_of_sr_internal ~_type:sr_type ~uuid:sr_uuid in
85 94
86 95 let any_vbd p = List.fold_left (||) false (List.map p my_vbd_records) in
87   - if not operation_can_be_performed_live && (any_vbd is_active)
  96 + let blocked_by_attach =
  97 + if operation_can_be_performed_live
  98 + then false
  99 + else begin
  100 + if operation_can_be_performed_with_ro_attach
  101 + then (any_vbd is_active_rw)
  102 + else (any_vbd is_active)
  103 + end
  104 + in
  105 + if blocked_by_attach
88 106 then Some (Api_errors.vdi_in_use,[_ref; (Record_util.vdi_operation_to_string op)])
89 107 else if any_vbd has_current_operation
90 108 then Some (Api_errors.other_operation_in_progress, [ "VDI"; _ref ])

0 comments on commit 3adadf7

Please sign in to comment.
Something went wrong with that request. Please try again.