@@ -244,33 +244,14 @@ Use VIR_DOMAIN_XML_SECURE (value = 1) prior to v1.0.0.
244244 final ExecutorService executor = Executors .newFixedThreadPool (1 );
245245 boolean migrateNonSharedInc = command .isMigrateNonSharedInc () && !migrateStorageManaged ;
246246
247- // If any of the destination disks target CLVM/CLVM_NG pools, exclude them from
248- // the migration disk list. These disks are already created/activated on the
249- // destination storage before VM migration, so libvirt should not try to migrate them.
250- // Only non-CLVM disks will be migrated by libvirt.
251- boolean effectiveMigrateStorage = migrateStorage ;
252- if (migrateStorage && migrateDiskLabels != null && hasClvmDestinationDisks (mapMigrateStorage )) {
253- logger .info ("Filtering out CLVM/CLVM_NG disks from migration for VM {} as they are pre-created on destination" , vmName );
254- migrateDiskLabels = filterOutClvmDisks (migrateDiskLabels , disks , mapMigrateStorage );
255- logger .debug ("Remaining disks to migrate via libvirt: {}" , migrateDiskLabels );
256-
257- // If all disks were filtered out (only CLVM/CLVM_NG), disable storage migration entirely
258- // to prevent libvirt from trying to handle the block devices
259- if (migrateDiskLabels != null && migrateDiskLabels .isEmpty ()) {
260- logger .info ("All disks are CLVM/CLVM_NG and pre-created on destination. Disabling storage migration for VM {}" , vmName );
261- effectiveMigrateStorage = false ;
262- migrateDiskLabels = null ;
263- }
264- }
265-
266247 // add cancel hook before we start. If migration fails to start and hook is called, it's non-fatal
267248 cancelHook = new MigrationCancelHook (dm );
268249 libvirtComputingResource .addDisconnectHook (cancelHook );
269250
270251 libvirtComputingResource .createOrUpdateLogFileForCommand (command , Command .State .PROCESSING );
271252
272253 final Callable <Domain > worker = new MigrateKVMAsync (libvirtComputingResource , dm , dconn , xmlDesc ,
273- effectiveMigrateStorage , migrateNonSharedInc ,
254+ migrateStorage , migrateNonSharedInc ,
274255 command .isAutoConvergence (), vmName , command .getDestinationIp (), migrateDiskLabels );
275256 final Future <Domain > migrateThread = executor .submit (worker );
276257 executor .shutdown ();
@@ -827,11 +808,8 @@ protected String replaceStorage(String xmlDesc, Map<String, MigrateCommand.Migra
827808 for (int z = 0 ; z < diskChildNodes .getLength (); z ++) {
828809 Node diskChildNode = diskChildNodes .item (z );
829810
830- // Update driver type for managed storage OR when migrating to CLVM
831- // CLVM uses RAW format requiring XML driver type update
832- // Note: CLVM_NG uses QCOW2-on-block, so no format change needed (already QCOW2)
833- boolean shouldUpdateDriverType = migrateStorageManaged ||
834- (migrateDiskInfo .getDestPoolType () == Storage .StoragePoolType .CLVM );
811+ boolean shouldUpdateDriverType = shouldUpdateDriverTypeForMigration (
812+ migrateStorageManaged , migrateDiskInfo );
835813
836814 if (shouldUpdateDriverType && "driver" .equals (diskChildNode .getNodeName ())) {
837815 Node driverNode = diskChildNode ;
@@ -1188,4 +1166,29 @@ private boolean isClvmBlockDevice(MigrateCommand.MigrateDiskInfo diskInfo) {
11881166 }
11891167 return (Storage .StoragePoolType .CLVM .equals (diskInfo .getDestPoolType ()) || Storage .StoragePoolType .CLVM_NG .equals (diskInfo .getDestPoolType ()));
11901168 }
1169+
1170+ /**
1171+ * Determines if the driver type should be updated during migration based on CLVM involvement.
1172+ * The driver type needs to be updated when:
1173+ * - Managed storage is being migrated, OR
1174+ * - Source pool is CLVM or CLVM_NG, OR
1175+ * - Destination pool is CLVM or CLVM_NG
1176+ *
1177+ * This ensures the libvirt XML driver type matches the destination format (raw/qcow2/etc).
1178+ *
1179+ * @param migrateStorageManaged true if migrating managed storage
1180+ * @param migrateDiskInfo the migration disk information containing source and destination pool types
1181+ * @return true if driver type should be updated, false otherwise
1182+ */
1183+ private boolean shouldUpdateDriverTypeForMigration (boolean migrateStorageManaged ,
1184+ MigrateCommand .MigrateDiskInfo migrateDiskInfo ) {
1185+ boolean sourceIsClvm = Storage .StoragePoolType .CLVM == migrateDiskInfo .getSourcePoolType () ||
1186+ Storage .StoragePoolType .CLVM_NG == migrateDiskInfo .getSourcePoolType ();
1187+
1188+ boolean destIsClvm = Storage .StoragePoolType .CLVM == migrateDiskInfo .getDestPoolType () ||
1189+ Storage .StoragePoolType .CLVM_NG == migrateDiskInfo .getDestPoolType ();
1190+
1191+ boolean isClvmRelatedMigration = sourceIsClvm || destIsClvm ;
1192+ return migrateStorageManaged || isClvmRelatedMigration ;
1193+ }
11911194}
0 commit comments