1+ // Copyright © 2025 Cyberus Technology GmbH
2+ //
3+ // SPDX-License-Identifier: Apache-2.0
4+
5+ //! Module for reporting of the live-migration progress.
6+
7+
8+ /// Type holding the progress and status information of an ongoing live
9+ /// migration.
10+ ///
11+ /// The states correspond to the [live-migration protocol].
12+ ///
13+ /// [live-migration protocol]: super::protocol
14+ #[ derive( Clone , Debug , serde:: Serialize , serde:: Deserialize ) ]
15+ pub enum MigrationProgressAndStatus {
16+ /// The migration starts. Handshake and transfer of VM config.
17+ Starting {
18+
19+ } ,
20+ /// Transfer of VM memory in precopy mode.
21+ ///
22+ /// Not used for local migrations.
23+ MemoryPrecopy {
24+ downtime_target_ms : u64 ,
25+ downtime_expected_ms : u64 ,
26+ /// The current memory iteration
27+ iteration : u64 ,
28+ memory_bytes_total : u64 ,
29+ memory_bytes_transmitted : u64 ,
30+ memory_4k_pages_transmitted : u64 ,
31+ memory_bytes_remaining_iteration : u64 ,
32+ memory_bytes_remaining_total : u64 ,
33+ } ,
34+ /// Transfer of VM memory in postcopy mode.
35+ ///
36+ /// Not used for local migrations.
37+ MemoryPostcopy {
38+
39+ } ,
40+
41+ FinalState {
42+
43+ } ,
44+ Completed {
45+
46+ } ,
47+ Failed {
48+
49+ } ,
50+ Cancelled {
51+
52+ }
53+ }
54+
55+ #[ cfg( test) ]
56+ mod tests {
57+ use super :: * ;
58+
59+ #[ test]
60+ fn print_json ( ) {
61+ let starting = MigrationProgressAndStatus :: Starting {
62+
63+ } ;
64+ let memory_precopy = MigrationProgressAndStatus :: Memory {
65+ total_memory_b : 0 ,
66+ iteration : 0 ,
67+ } ;
68+ let memory_postcopy = MigrationProgressAndStatus :: MemoryPostcopy {
69+
70+ } ;
71+ let finishing = MigrationProgressAndStatus :: Completing {
72+
73+ } ;
74+ let completed = MigrationProgressAndStatus :: Completed {
75+
76+ } ;
77+ let failed = MigrationProgressAndStatus :: Failed {
78+
79+ } ;
80+ let cancelled = MigrationProgressAndStatus :: Cancelled {
81+
82+ } ;
83+
84+ let vals = [
85+ starting, memory_precopy, memory_postcopy, finishing, completed, failed, cancelled ]
86+ ;
87+ for val in vals {
88+ println ! ( "{}" , serde_json:: to_string( & val) . unwrap( ) ) ;
89+ }
90+ }
91+ }
0 commit comments