@@ -456,6 +456,7 @@ impl DeviceManager {
456
456
& address_manager,
457
457
& mut mem_slots,
458
458
& mut mmap_regions,
459
+ & mut migratable_devices,
459
460
) ?) ;
460
461
461
462
DeviceManager :: add_legacy_devices (
@@ -481,6 +482,7 @@ impl DeviceManager {
481
482
& mut virt_iommu,
482
483
virtio_devices,
483
484
& interrupt_info,
485
+ & mut migratable_devices,
484
486
) ?;
485
487
} else if cfg ! ( feature = "mmio_support" ) {
486
488
DeviceManager :: add_mmio_devices (
@@ -489,6 +491,7 @@ impl DeviceManager {
489
491
virtio_devices,
490
492
& interrupt_info,
491
493
& mut cmdline_additions,
494
+ & mut migratable_devices,
492
495
) ?;
493
496
}
494
497
@@ -520,6 +523,7 @@ impl DeviceManager {
520
523
virt_iommu : & mut Option < ( u32 , Vec < u32 > ) > ,
521
524
virtio_devices : Vec < ( Arc < Mutex < dyn vm_virtio:: VirtioDevice > > , bool ) > ,
522
525
interrupt_info : & InterruptInfo ,
526
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
523
527
) -> DeviceManagerResult < ( ) > {
524
528
#[ cfg( feature = "pci_support" ) ]
525
529
{
@@ -553,6 +557,7 @@ impl DeviceManager {
553
557
vm_info. vm_fd ,
554
558
& mut pci_bus,
555
559
mapping,
560
+ migratable_devices,
556
561
) ?;
557
562
558
563
if let Some ( dev_id) = virtio_iommu_attach_dev {
@@ -588,6 +593,7 @@ impl DeviceManager {
588
593
vm_info. vm_fd ,
589
594
& mut pci_bus,
590
595
& None ,
596
+ migratable_devices,
591
597
) ?;
592
598
593
599
* virt_iommu = Some ( ( iommu_id, iommu_attached_devices) ) ;
@@ -620,6 +626,7 @@ impl DeviceManager {
620
626
virtio_devices : Vec < ( Arc < Mutex < dyn vm_virtio:: VirtioDevice > > , bool ) > ,
621
627
interrupt_info : & InterruptInfo ,
622
628
mut cmdline_additions : & mut Vec < String > ,
629
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
623
630
) -> DeviceManagerResult < ( ) > {
624
631
#[ cfg( feature = "mmio_support" ) ]
625
632
{
@@ -638,6 +645,7 @@ impl DeviceManager {
638
645
& interrupt_info,
639
646
addr,
640
647
& mut cmdline_additions,
648
+ migratable_devices,
641
649
) ?;
642
650
} else {
643
651
error ! ( "Unable to allocate MMIO address!" ) ;
@@ -841,21 +849,32 @@ impl DeviceManager {
841
849
address_manager : & Arc < AddressManager > ,
842
850
mut mem_slots : & mut u32 ,
843
851
mmap_regions : & mut Vec < ( * mut libc:: c_void , usize ) > ,
852
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
844
853
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
845
854
let mut allocator = address_manager. allocator . lock ( ) . unwrap ( ) ;
846
855
let mut devices: Vec < ( Arc < Mutex < dyn vm_virtio:: VirtioDevice > > , bool ) > = Vec :: new ( ) ;
847
856
848
857
// Create "standard" virtio devices (net/block/rng)
849
- devices. append ( & mut DeviceManager :: make_virtio_block_devices ( vm_info) ?) ;
850
- devices. append ( & mut DeviceManager :: make_virtio_net_devices ( vm_info) ?) ;
851
- devices. append ( & mut DeviceManager :: make_virtio_rng_devices ( vm_info) ?) ;
858
+ devices. append ( & mut DeviceManager :: make_virtio_block_devices (
859
+ vm_info,
860
+ migratable_devices,
861
+ ) ?) ;
862
+ devices. append ( & mut DeviceManager :: make_virtio_net_devices (
863
+ vm_info,
864
+ migratable_devices,
865
+ ) ?) ;
866
+ devices. append ( & mut DeviceManager :: make_virtio_rng_devices (
867
+ vm_info,
868
+ migratable_devices,
869
+ ) ?) ;
852
870
853
871
// Add virtio-fs if required
854
872
devices. append ( & mut DeviceManager :: make_virtio_fs_devices (
855
873
vm_info,
856
874
& mut allocator,
857
875
& mut mem_slots,
858
876
mmap_regions,
877
+ migratable_devices,
859
878
) ?) ;
860
879
861
880
// Add virtio-pmem if required
@@ -864,26 +883,33 @@ impl DeviceManager {
864
883
& mut allocator,
865
884
& mut mem_slots,
866
885
mmap_regions,
886
+ migratable_devices,
867
887
) ?) ;
868
888
869
889
// Add virtio-vhost-user-net if required
870
890
devices. append ( & mut DeviceManager :: make_virtio_vhost_user_net_devices (
871
891
vm_info,
892
+ migratable_devices,
872
893
) ?) ;
873
894
874
895
// Add virtio-vhost-user-blk if required
875
896
devices. append ( & mut DeviceManager :: make_virtio_vhost_user_blk_devices (
876
897
vm_info,
898
+ migratable_devices,
877
899
) ?) ;
878
900
879
901
// Add virtio-vsock if required
880
- devices. append ( & mut DeviceManager :: make_virtio_vsock_devices ( vm_info) ?) ;
902
+ devices. append ( & mut DeviceManager :: make_virtio_vsock_devices (
903
+ vm_info,
904
+ migratable_devices,
905
+ ) ?) ;
881
906
882
907
Ok ( devices)
883
908
}
884
909
885
910
fn make_virtio_block_devices (
886
911
vm_info : & VmInfo ,
912
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
887
913
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
888
914
let mut devices = Vec :: new ( ) ;
889
915
@@ -898,7 +924,7 @@ impl DeviceManager {
898
924
899
925
let image_type = qcow:: detect_image_type ( & raw_img)
900
926
. map_err ( DeviceManagerError :: DetectImageType ) ?;
901
- let block = match image_type {
927
+ match image_type {
902
928
ImageType :: Raw => {
903
929
let raw_img = vm_virtio:: RawFile :: new ( raw_img) ;
904
930
let dev = vm_virtio:: Block :: new (
@@ -909,7 +935,13 @@ impl DeviceManager {
909
935
)
910
936
. map_err ( DeviceManagerError :: CreateVirtioBlock ) ?;
911
937
912
- Arc :: new ( Mutex :: new ( dev) ) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > >
938
+ let block = Arc :: new ( Mutex :: new ( dev) ) ;
939
+
940
+ devices. push ( (
941
+ Arc :: clone ( & block) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
942
+ disk_cfg. iommu ,
943
+ ) ) ;
944
+ migratable_devices. push ( Arc :: clone ( & block) as Arc < Mutex < dyn Migratable > > ) ;
913
945
}
914
946
ImageType :: Qcow2 => {
915
947
let qcow_img = QcowFile :: from ( raw_img)
@@ -921,11 +953,16 @@ impl DeviceManager {
921
953
disk_cfg. iommu ,
922
954
)
923
955
. map_err ( DeviceManagerError :: CreateVirtioBlock ) ?;
924
- Arc :: new ( Mutex :: new ( dev) ) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > >
956
+
957
+ let block = Arc :: new ( Mutex :: new ( dev) ) ;
958
+
959
+ devices. push ( (
960
+ Arc :: clone ( & block) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
961
+ disk_cfg. iommu ,
962
+ ) ) ;
963
+ migratable_devices. push ( Arc :: clone ( & block) as Arc < Mutex < dyn Migratable > > ) ;
925
964
}
926
965
} ;
927
-
928
- devices. push ( ( Arc :: clone ( & block) , disk_cfg. iommu ) ) ;
929
966
}
930
967
}
931
968
@@ -934,6 +971,7 @@ impl DeviceManager {
934
971
935
972
fn make_virtio_net_devices (
936
973
vm_info : & VmInfo ,
974
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
937
975
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
938
976
let mut devices = Vec :: new ( ) ;
939
977
@@ -962,6 +1000,8 @@ impl DeviceManager {
962
1000
Arc :: clone ( & virtio_net_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
963
1001
net_cfg. iommu ,
964
1002
) ) ;
1003
+ migratable_devices
1004
+ . push ( Arc :: clone ( & virtio_net_device) as Arc < Mutex < dyn Migratable > > ) ;
965
1005
}
966
1006
}
967
1007
@@ -970,6 +1010,7 @@ impl DeviceManager {
970
1010
971
1011
fn make_virtio_rng_devices (
972
1012
vm_info : & VmInfo ,
1013
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
973
1014
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
974
1015
let mut devices = Vec :: new ( ) ;
975
1016
@@ -984,6 +1025,8 @@ impl DeviceManager {
984
1025
Arc :: clone ( & virtio_rng_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
985
1026
false ,
986
1027
) ) ;
1028
+
1029
+ migratable_devices. push ( Arc :: clone ( & virtio_rng_device) as Arc < Mutex < dyn Migratable > > ) ;
987
1030
}
988
1031
989
1032
Ok ( devices)
@@ -994,6 +1037,7 @@ impl DeviceManager {
994
1037
allocator : & mut SystemAllocator ,
995
1038
mem_slots : & mut u32 ,
996
1039
mmap_regions : & mut Vec < ( * mut libc:: c_void , usize ) > ,
1040
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
997
1041
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
998
1042
let mut devices = Vec :: new ( ) ;
999
1043
// Add virtio-fs if required
@@ -1074,6 +1118,9 @@ impl DeviceManager {
1074
1118
Arc :: clone ( & virtio_fs_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
1075
1119
false ,
1076
1120
) ) ;
1121
+
1122
+ migratable_devices
1123
+ . push ( Arc :: clone ( & virtio_fs_device) as Arc < Mutex < dyn Migratable > > ) ;
1077
1124
}
1078
1125
}
1079
1126
}
@@ -1086,6 +1133,7 @@ impl DeviceManager {
1086
1133
allocator : & mut SystemAllocator ,
1087
1134
mem_slots : & mut u32 ,
1088
1135
mmap_regions : & mut Vec < ( * mut libc:: c_void , usize ) > ,
1136
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1089
1137
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
1090
1138
let mut devices = Vec :: new ( ) ;
1091
1139
// Add virtio-pmem if required
@@ -1177,6 +1225,9 @@ impl DeviceManager {
1177
1225
Arc :: clone ( & virtio_pmem_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
1178
1226
false ,
1179
1227
) ) ;
1228
+
1229
+ migratable_devices
1230
+ . push ( Arc :: clone ( & virtio_pmem_device) as Arc < Mutex < dyn Migratable > > ) ;
1180
1231
}
1181
1232
}
1182
1233
@@ -1185,6 +1236,7 @@ impl DeviceManager {
1185
1236
1186
1237
fn make_virtio_vhost_user_net_devices (
1187
1238
vm_info : & VmInfo ,
1239
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1188
1240
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
1189
1241
let mut devices = Vec :: new ( ) ;
1190
1242
// Add vhost-user-net if required
@@ -1204,6 +1256,9 @@ impl DeviceManager {
1204
1256
Arc :: clone ( & vhost_user_net_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
1205
1257
false ,
1206
1258
) ) ;
1259
+
1260
+ migratable_devices
1261
+ . push ( Arc :: clone ( & vhost_user_net_device) as Arc < Mutex < dyn Migratable > > ) ;
1207
1262
}
1208
1263
}
1209
1264
@@ -1212,6 +1267,7 @@ impl DeviceManager {
1212
1267
1213
1268
fn make_virtio_vhost_user_blk_devices (
1214
1269
vm_info : & VmInfo ,
1270
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1215
1271
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
1216
1272
let mut devices = Vec :: new ( ) ;
1217
1273
// Add vhost-user-blk if required
@@ -1231,6 +1287,9 @@ impl DeviceManager {
1231
1287
Arc :: clone ( & vhost_user_blk_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
1232
1288
false ,
1233
1289
) ) ;
1290
+
1291
+ migratable_devices
1292
+ . push ( Arc :: clone ( & vhost_user_blk_device) as Arc < Mutex < dyn Migratable > > ) ;
1234
1293
}
1235
1294
}
1236
1295
@@ -1239,6 +1298,7 @@ impl DeviceManager {
1239
1298
1240
1299
fn make_virtio_vsock_devices (
1241
1300
vm_info : & VmInfo ,
1301
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1242
1302
) -> DeviceManagerResult < Vec < ( VirtioDeviceArc , bool ) > > {
1243
1303
let mut devices = Vec :: new ( ) ;
1244
1304
// Add vsock if required
@@ -1261,6 +1321,8 @@ impl DeviceManager {
1261
1321
Arc :: clone ( & vsock_device) as Arc < Mutex < dyn vm_virtio:: VirtioDevice > > ,
1262
1322
false ,
1263
1323
) ) ;
1324
+
1325
+ migratable_devices. push ( Arc :: clone ( & vsock_device) as Arc < Mutex < dyn Migratable > > ) ;
1264
1326
}
1265
1327
}
1266
1328
@@ -1373,6 +1435,7 @@ impl DeviceManager {
1373
1435
vm_fd : & Arc < VmFd > ,
1374
1436
pci : & mut PciBus ,
1375
1437
iommu_mapping : & Option < Arc < IommuMapping > > ,
1438
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1376
1439
) -> DeviceManagerResult < Option < u32 > > {
1377
1440
// Allows support for one MSI-X vector per queue. It also adds 1
1378
1441
// as we need to take into account the dedicated vector to notify
@@ -1471,6 +1534,8 @@ impl DeviceManager {
1471
1534
)
1472
1535
. map_err ( DeviceManagerError :: AddPciDevice ) ?;
1473
1536
1537
+ migratable_devices. push ( Arc :: clone ( & virtio_pci_device) as Arc < Mutex < dyn Migratable > > ) ;
1538
+
1474
1539
let ret = if iommu_mapping. is_some ( ) {
1475
1540
Some ( dev_id)
1476
1541
} else {
@@ -1490,6 +1555,7 @@ impl DeviceManager {
1490
1555
interrupt_info : & InterruptInfo ,
1491
1556
mmio_base : GuestAddress ,
1492
1557
cmdline_additions : & mut Vec < String > ,
1558
+ migratable_devices : & mut Vec < Arc < Mutex < dyn Migratable > > > ,
1493
1559
) -> DeviceManagerResult < ( ) > {
1494
1560
let mut mmio_device = vm_virtio:: transport:: MmioDevice :: new ( memory. clone ( ) , virtio_device)
1495
1561
. map_err ( DeviceManagerError :: VirtioDevice ) ?;
@@ -1515,9 +1581,10 @@ impl DeviceManager {
1515
1581
1516
1582
mmio_device. assign_interrupt ( interrupt) ;
1517
1583
1584
+ let mmio_device_arc = Arc :: new ( Mutex :: new ( mmio_device) ) ;
1518
1585
address_manager
1519
1586
. mmio_bus
1520
- . insert ( Arc :: new ( Mutex :: new ( mmio_device ) ) , mmio_base. 0 , MMIO_LEN )
1587
+ . insert ( mmio_device_arc . clone ( ) , mmio_base. 0 , MMIO_LEN )
1521
1588
. map_err ( DeviceManagerError :: BusError ) ?;
1522
1589
1523
1590
cmdline_additions. push ( format ! (
@@ -1527,6 +1594,8 @@ impl DeviceManager {
1527
1594
irq_num
1528
1595
) ) ;
1529
1596
1597
+ migratable_devices. push ( Arc :: clone ( & mmio_device_arc) as Arc < Mutex < dyn Migratable > > ) ;
1598
+
1530
1599
Ok ( ( ) )
1531
1600
}
1532
1601
0 commit comments