CA-70188: Remove invalid pool patches from the database at xapi startup.
A pool_patch is valid if either:
- It has been applied to at least one host, or
- Its file exists on the master filesystem.
It neither of these is true, we can delete the pool_patch object.
Signed-off-by: John Else <email@example.com>
Loading branch information
1 changed file
and 1 deletion.
@@ -183,6 +183,22 @@ let ensure_vm_metrics_records_exist __context =
let ensure_vm_metrics_records_exist_noexn __context = Helpers.log_exn_continue ensure_vm_metrics_records_exist __context "ensuring VM_metrics flags exist "
let destroy_invalid_pool_patches ~ __context =
let is_valid_pool_patch patch =
(* If patch has been applied to at least one host, then it is valid. *)
if ( Db.Pool_patch.get_host_patches ~__context ~self:patch) <>  then true
(* If patch hasn't been applied to any host, but we can still apply it, then it is valid. *)
(* File needs to exist in the master's filesystem for us to be able to apply it. *)
else if ( Sys.file_exists ( Db.Pool_patch.get_filename ~__context ~self:patch)) then true
let pool_patches = Db.Pool_patch.get_all ~__context in
fun patch ->
if not (is_valid_pool_patch patch)
then Db.Pool_patch.destroy ~__context ~self:patch)
(* Update the database to reflect current state. Called for both start of day and after
an agent restart. *)
let update_env __context =
@@ -220,4 +236,5 @@ let update_env __context =
is to just clear the cache, which we do here. *)
- ensure_vm_metrics_records_exist_noexn __context
+ ensure_vm_metrics_records_exist_noexn __context;
+ destroy_invalid_pool_patches ~__context