@@ -68,6 +68,84 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
68
68
let _ref = Ref. string_of _ref' in
69
69
let current_ops = record.Db_actions. vDI_current_operations in
70
70
let reset_on_boot = record.Db_actions. vDI_on_boot = `reset in
71
+ let rolling_upgrade_in_progress =
72
+ Helpers. rolling_upgrade_in_progress ~__context
73
+ in
74
+ (* check to see whether it's a local cd drive *)
75
+ let sr = record.Db_actions. vDI_SR in
76
+ let sr_type = Db.SR. get_type ~__context ~self: sr in
77
+ let is_tools_sr = Db.SR. get_is_tools_sr ~__context ~self: sr in
78
+ (* Check to see if any PBDs are attached *)
79
+ let open Xapi_database.Db_filter_types in
80
+ let pbds_attached =
81
+ match pbd_records with
82
+ | [] ->
83
+ Db.PBD. get_records_where ~__context
84
+ ~expr:
85
+ (And
86
+ ( Eq (Field " SR" , Literal (Ref. string_of sr))
87
+ , Eq (Field " currently_attached" , Literal " true" )
88
+ )
89
+ )
90
+ | _ ->
91
+ List. filter
92
+ (fun (_ , pbd_record ) ->
93
+ pbd_record.API. pBD_SR = sr && pbd_record.API. pBD_currently_attached
94
+ )
95
+ pbd_records
96
+ in
97
+
98
+ (* Only a 'live' operation can be performed if there are active (even RO) devices *)
99
+ let my_active_vbd_records =
100
+ match vbd_records with
101
+ | None ->
102
+ List. map snd
103
+ (Db.VBD. get_internal_records_where ~__context
104
+ ~expr:
105
+ (And
106
+ ( Eq (Field " VDI" , Literal _ref)
107
+ , Or
108
+ ( Eq (Field " currently_attached" , Literal " true" )
109
+ , Eq (Field " reserved" , Literal " true" )
110
+ )
111
+ )
112
+ )
113
+ )
114
+ | Some records ->
115
+ List. filter
116
+ (fun vbd_record ->
117
+ vbd_record.Db_actions. vBD_VDI = _ref'
118
+ && (vbd_record.Db_actions. vBD_currently_attached
119
+ || vbd_record.Db_actions. vBD_reserved
120
+ )
121
+ )
122
+ records
123
+ in
124
+ let my_active_rw_vbd_records =
125
+ List. filter (fun vbd -> vbd.Db_actions. vBD_mode = `RW ) my_active_vbd_records
126
+ in
127
+ (* VBD operations (plug/unplug) (which should be transient) cause us to serialise *)
128
+ let my_has_current_operation_vbd_records =
129
+ match vbd_records with
130
+ | None ->
131
+ List. map snd
132
+ (Db.VBD. get_internal_records_where ~__context
133
+ ~expr:
134
+ (And
135
+ ( Eq (Field " VDI" , Literal _ref)
136
+ , Not (Eq (Field " current_operations" , Literal " ()" ))
137
+ )
138
+ )
139
+ )
140
+ | Some records ->
141
+ List. filter
142
+ (fun vbd_record ->
143
+ vbd_record.Db_actions. vBD_VDI = _ref'
144
+ && vbd_record.Db_actions. vBD_current_operations <> []
145
+ )
146
+ records
147
+ in
148
+
71
149
(* Policy:
72
150
1. any current_operation besides copy implies exclusivity; fail everything
73
151
else; except vdi mirroring is in current operations and destroy is performed
@@ -83,11 +161,15 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
83
161
5. HA prevents you from deleting statefiles or metadata volumes
84
162
6. During rolling pool upgrade, only operations known by older releases are allowed
85
163
*)
164
+ let sm_features =
165
+ Xapi_sr_operations. features_of_sr_internal ~__context ~_type:sr_type
166
+ in
167
+ let vdi_is_ha_state_or_redolog =
168
+ List. mem record.Db_actions. vDI_type [`ha_statefile ; `redo_log ]
169
+ in
170
+
86
171
fun op ->
87
172
let * () =
88
- let rolling_upgrade_in_progress =
89
- Helpers. rolling_upgrade_in_progress ~__context
90
- in
91
173
if
92
174
rolling_upgrade_in_progress
93
175
&& not
@@ -113,30 +195,6 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
113
195
else
114
196
Ok ()
115
197
in
116
- (* check to see whether it's a local cd drive *)
117
- let sr = record.Db_actions. vDI_SR in
118
- let sr_type = Db.SR. get_type ~__context ~self: sr in
119
- let is_tools_sr = Db.SR. get_is_tools_sr ~__context ~self: sr in
120
- (* Check to see if any PBDs are attached *)
121
- let open Xapi_database.Db_filter_types in
122
- let pbds_attached =
123
- match pbd_records with
124
- | [] ->
125
- Db.PBD. get_records_where ~__context
126
- ~expr:
127
- (And
128
- ( Eq (Field " SR" , Literal (Ref. string_of sr))
129
- , Eq (Field " currently_attached" , Literal " true" )
130
- )
131
- )
132
- | _ ->
133
- List. filter
134
- (fun (_ , pbd_record ) ->
135
- pbd_record.API. pBD_SR = sr
136
- && pbd_record.API. pBD_currently_attached
137
- )
138
- pbd_records
139
- in
140
198
let * () =
141
199
if pbds_attached = [] && op = `resize then
142
200
Error (Api_errors. sr_no_pbds, [Ref. string_of sr])
@@ -146,58 +204,6 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
146
204
147
205
(* check to see whether VBDs exist which are using this VDI *)
148
206
149
- (* Only a 'live' operation can be performed if there are active (even RO) devices *)
150
- let my_active_vbd_records =
151
- match vbd_records with
152
- | None ->
153
- List. map snd
154
- (Db.VBD. get_internal_records_where ~__context
155
- ~expr:
156
- (And
157
- ( Eq (Field " VDI" , Literal _ref)
158
- , Or
159
- ( Eq (Field " currently_attached" , Literal " true" )
160
- , Eq (Field " reserved" , Literal " true" )
161
- )
162
- )
163
- )
164
- )
165
- | Some records ->
166
- List. filter
167
- (fun vbd_record ->
168
- vbd_record.Db_actions. vBD_VDI = _ref'
169
- && (vbd_record.Db_actions. vBD_currently_attached
170
- || vbd_record.Db_actions. vBD_reserved
171
- )
172
- )
173
- records
174
- in
175
- let my_active_rw_vbd_records =
176
- List. filter
177
- (fun vbd -> vbd.Db_actions. vBD_mode = `RW )
178
- my_active_vbd_records
179
- in
180
- (* VBD operations (plug/unplug) (which should be transient) cause us to serialise *)
181
- let my_has_current_operation_vbd_records =
182
- match vbd_records with
183
- | None ->
184
- List. map snd
185
- (Db.VBD. get_internal_records_where ~__context
186
- ~expr:
187
- (And
188
- ( Eq (Field " VDI" , Literal _ref)
189
- , Not (Eq (Field " current_operations" , Literal " ()" ))
190
- )
191
- )
192
- )
193
- | Some records ->
194
- List. filter
195
- (fun vbd_record ->
196
- vbd_record.Db_actions. vBD_VDI = _ref'
197
- && vbd_record.Db_actions. vBD_current_operations <> []
198
- )
199
- records
200
- in
201
207
(* If the VBD is currently_attached then some operations can still be
202
208
performed ie: VDI.clone (if the VM is suspended we have to have the
203
209
'allow_clone_suspended_vm' flag); VDI.snapshot; VDI.resize_online;
@@ -275,9 +281,6 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
275
281
else
276
282
Ok ()
277
283
in
278
- let sm_features =
279
- Xapi_sr_operations. features_of_sr_internal ~__context ~_type:sr_type
280
- in
281
284
let * () = check_sm_feature_error op sm_features sr in
282
285
let allowed_for_cbt_metadata_vdi =
283
286
match op with
@@ -341,16 +344,7 @@ let check_operation_error ~__context ?sr_records:_ ?(pbd_records = [])
341
344
else
342
345
Ok ()
343
346
in
344
- let vdi_is_ha_state_or_redolog =
345
- List. mem record.Db_actions. vDI_type [`ha_statefile ; `redo_log ]
346
- in
347
347
let check_destroy () =
348
- let ha_enable_in_progress =
349
- Xapi_pool_helpers. ha_enable_in_progress ~__context
350
- in
351
- let ha_disable_in_progress =
352
- Xapi_pool_helpers. ha_disable_in_progress ~__context
353
- in
354
348
if sr_type = " udev" then
355
349
Error (Api_errors. vdi_is_a_physical_device, [_ref])
356
350
else if is_tools_sr then
0 commit comments