@@ -21,14 +21,33 @@ open D
2121
2222(* A comparision function suitable for passing to List.sort and Array.sort.
2323 Sorts into oldest first *)
24- let compare_vsn (a_maj , a_min , a_micro , a_build ) (b_maj , b_min , b_micro , b_build ) =
25- 0 +
26- 8 * (compare a_maj b_maj) +
27- 4 * (compare a_min b_min) +
28- 2 * (compare a_micro b_micro) +
29- 1 * (compare a_build b_build)
24+ let compare_vsn =
25+ List. fold_left2 (fun r x y -> if r <> 0 then r else compare x y) 0
3026
31- let string_of_vsn (maj , min , micro , build ) = Printf. sprintf " %d.%d.%d-%d" maj min micro build
27+ let compare_vsn4 (x_maj , x_min , x_mic , x_bd ) (y_maj , y_min , y_mic , y_bd ) =
28+ compare_vsn [x_maj; x_min; x_mic; x_bd] [y_maj; y_min; y_mic; y_bd]
29+
30+ let compare_vsn3 (x_maj , x_min , x_mic ) (y_maj , y_min , y_mic ) =
31+ compare_vsn [x_maj; x_min; x_mic] [y_maj; y_min; y_mic]
32+
33+ let compare_vsn2 (x_maj , x_min ) (y_maj , y_min ) =
34+ compare_vsn [x_maj; x_min] [y_maj; y_min]
35+
36+ let string_of_vsn vsn =
37+ let seps = [" ." ; " ." ; " -" ] in
38+ let maj = List. hd vsn and rest = List. tl vsn in
39+ let rec postfix accu = function
40+ | [] , _ -> accu
41+ | num :: nums , sep :: seps ->
42+ postfix (accu ^ sep ^ (string_of_int num)) (nums, seps)
43+ | _ , _ -> assert false in
44+ postfix (string_of_int maj) (rest, seps)
45+
46+ let string_of_vsn4 (maj , min , mic , bd ) = string_of_vsn [maj; min; mic; bd]
47+
48+ let string_of_vsn3 (maj , min , mic ) = string_of_vsn [maj; min; mic]
49+
50+ let string_of_vsn2 (maj , min ) = string_of_vsn [maj; min]
3251
3352(* Find the most recent xs tools version from the local filesystem -- avoids having to synchronise
3453 with the master's SR scanning thread. Called from the startup code only *)
@@ -58,9 +77,9 @@ let get_latest_tools_vsn () =
5877 (* just in case *)
5978 debug " Caught error discovering latest tools ISO: %s" (ExnHelper. string_of_exn e);
6079 none in
61- let sorted = List. sort compare_vsn (List. map vsn_of_filename (Array. to_list all)) in
80+ let sorted = List. sort compare_vsn4 (List. map vsn_of_filename (Array. to_list all)) in
6281 let latest = if sorted = [] then none else List. hd (List. rev sorted) in
63- debug " Latest xs-tools version: %s" (string_of_vsn latest);
82+ debug " Latest xs-tools version: %s" (string_of_vsn4 latest);
6483 Xapi_globs. tools_version := latest;
6584
6685(* * Represents the detected PV driver version *)
@@ -80,45 +99,56 @@ let string_of = function
8099 ** @return +1: if the given version is newer;
81100 ** @raise Assert_failure: if this host does not have a valid product version.
82101 **)
83- let compare_vsn_with_product_vsn (pv_maj , pv_min , pv_mic ) =
102+ let compare_vsn_with_product_vsn ?( relaxed = false ) (pv_maj , pv_min , pv_mic ) =
84103 let (prod_maj, prod_min, prod_mic) =
85104 match (Stringext.String. split '.' Version. product_version) with
86105 | [maj; min; mic] ->
87106 (int_of_string maj, int_of_string min, int_of_string mic)
88107 | _ ->
89108 warn " xapi product version is wrong format: %s"
90109 Version. product_version; assert false ;
91- in
92- if pv_mic = - 1 then - 1 (* out of date if micro version not specified -- reqd since Miami Beta1 was shipped without micro versions! *)
93- else if pv_maj< prod_maj || (pv_maj= prod_maj && pv_min< prod_min) || (pv_maj= prod_maj && pv_min= prod_min && pv_mic< prod_mic) then - 1
94- else if pv_maj= prod_maj && pv_min= prod_min && pv_mic= prod_mic then 0
95- else 1
110+ in
111+ (* out of date if micro version not specified -- reqd since Miami Beta1 was
112+ shipped withoutmicro versions! *)
113+ if pv_mic = - 1 then - 1
114+ else if relaxed then compare_vsn2 (pv_maj, pv_min) (prod_maj, prod_min)
115+ else compare_vsn3 (pv_maj, pv_min, pv_mic) (prod_maj, prod_min, prod_mic)
96116
97117(* Returns -1 if PV drivers are out-of-date wrt tools version on this host;
98118 returns 0 if the PV drivers match the tools version on this host;
99119 returns 1 if the PV drivers are a newer verrsion than the tools version on this host *)
100- let compare_vsn_with_tools_iso pv_vsn =
101- (* XXX: consolidate with create_templates code and the function above *)
102- compare_vsn pv_vsn ! Xapi_globs. tools_version
120+ let compare_vsn_with_tools_iso ?(relaxed =false ) pv_vsn =
121+ (* XXX: consolidate with create_templates code and the function above *)
122+ if relaxed then
123+ let pv_maj, pv_min, _, _ = pv_vsn in
124+ let tools_maj, tools_min, _, _ = ! Xapi_globs. tools_version in
125+ compare_vsn2 (pv_maj, pv_min) (tools_maj, tools_min)
126+ else
127+ compare_vsn4 pv_vsn ! Xapi_globs. tools_version
103128
104129let has_pv_drivers x = x <> Unknown
105-
130+
106131(* * Returns true if the PV drivers are up to date *)
107132let is_up_to_date = function
108133 (* XXX: linux guest agent doesn't report build number (-1) while all windows ones do * )
109- | Linux (maj ,min ,mic ,build ) -> (compare_vsn_with_product_vsn (maj,min,mic)> = 0 ) && (build= (- 1 ) || (compare_vsn_with_tools_iso (maj, min, mic, build) > = 0 ))
110- | Windows (maj ,min ,mic ,build ) -> (compare_vsn_with_product_vsn (maj,min,mic)> = 0 ) && (compare_vsn_with_tools_iso (maj, min, mic, build) > = 0 )
111- | _ -> false
134+ | Linux (maj , min , mic , bd ) ->
135+ compare_vsn_with_product_vsn ~relaxed: true (maj, min, mic) > = 0
136+ && (bd = - 1 || compare_vsn_with_tools_iso ~relaxed: true (maj, min, mic, bd) > = 0 )
137+ | Windows (maj , min , mic , bd ) ->
138+ compare_vsn_with_product_vsn (maj, min, mic) > = 0
139+ && compare_vsn_with_tools_iso (maj, min, mic, bd) > = 0
140+ | Unknown ->
141+ (* Avoid catch all '_', it's bad practice except for false assertion *)
142+ false
112143
113144(* * Returns true if the PV drivers are OK for migrate; in Miami we allow migration
114145 as long as the major vs of the PV drivers are 4. This allows us to migrate VMs
115146 with PV drivers from the previous release during rolling upgrade.
116147*)
117148let is_ok_for_migrate = function
118- | Linux (major , _ , _ , _ ) when major > = 4 -> true
119- | Windows (major , _ , _ , _ ) when major > = 4 -> true (* bumped in CA-6891 *)
120- | _ -> false
121-
149+ | Linux (major , _ , _ , _ ) -> major > = 4
150+ | Windows (major , _ , _ , _ ) -> major > = 4 (* bumped in CA-6891 *)
151+ | Unknown -> false
122152
123153let of_drivers_version drivers_version =
124154 try
0 commit comments