Skip to content

Commit 9c70c3d

Browse files
committed
linstor: make the new resource available on the target host for live migration
Live migration with storage into a Linstor pool spawned the destination resource through the resource group's auto-placement, which knows nothing about the target host. PrepareForMigrationCommand still describes the source disks, so the target agent never connected the new volume either. If the placement left the target host without a copy (place count 1, no quorum tiebreaker, 4+ nodes with 2 copies, node filters), the block device was missing there and libvirt aborted with "cannot precreate storage for disk type 'block'". Make the resource available on the target host right after creating it and take the device path from there. The source is not a Linstor resource of this pool, so no dual-primary is needed. A failure before the migration command (make-available, prepare for migration) now also removes the already created destination volumes; they used to be left behind. The error message names the destination pools instead of the source host. Unit tests cover make-available before the migration with the device path from the target host, and the cleanup when make-available, prepare for migration or the migration itself fails.
1 parent 2974af8 commit 9c70c3d

3 files changed

Lines changed: 352 additions & 13 deletions

File tree

‎plugins/storage/volume/linstor/CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ All notable changes to Linstor CloudStack plugin will be documented in this file
2424
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2525
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
2626

27+
## [2026-10-07]
28+
29+
### Fixed
30+
31+
- Live migration with storage into Linstor failed with "cannot precreate storage for disk type 'block'"
32+
if the auto-placement didn't put a copy of the new resource on the target host; the resource is
33+
now made available on the target host before the migration starts.
34+
2735
## [2026-06-24]
2836

2937
### Fixed

‎plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/motion/LinstorDataMotionStrategy.java‎

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.linbit.linstor.api.model.ApiCallRcList;
2525
import com.linbit.linstor.api.model.ResourceDefinition;
2626
import com.linbit.linstor.api.model.ResourceDefinitionModify;
27+
import com.linbit.linstor.api.model.ResourceMakeAvailable;
2728

2829
import javax.inject.Inject;
2930

@@ -169,11 +170,36 @@ private VolumeVO createNewVolumeVO(Volume volume, StoragePoolVO storagePoolVO) {
169170
return _volumeDao.persist(newVol);
170171
}
171172

173+
private DevelopersApi getLinstorAPI(StoragePoolVO storagePool) {
174+
return LinstorUtil.getLinstorAPI(storagePool.getHostAddress(),
175+
LinstorConfigurationManager.ApiToken.valueIn(storagePool.getId()),
176+
Boolean.TRUE.equals(LinstorConfigurationManager.InsecureSsl.valueIn(storagePool.getId())));
177+
}
178+
179+
/**
180+
* Makes the new resource available on the migration target host and returns its device path there.
181+
*
182+
* <p>The resource is spawned by LINSTOR's auto-placement, which does not know about the target host.
183+
* libvirt can only precreate file disks on the target, so if the block device is missing there the
184+
* migration fails with "cannot precreate storage for disk type 'block'". The source disk is not on
185+
* LINSTOR, so a plain (diskless for DRBD) make-available is enough, no dual-primary needed.</p>
186+
*/
187+
private String makeAvailableOnHost(StoragePoolVO storagePool, String rscName, Host host) {
188+
DevelopersApi api = getLinstorAPI(storagePool);
189+
try {
190+
logger.info("Linstor: make resource {} available on migration target {}", rscName, host.getName());
191+
ApiCallRcList answers = api.resourceMakeAvailableOnNode(rscName, host.getName(), new ResourceMakeAvailable());
192+
LinstorUtil.checkLinstorAnswersThrow(answers);
193+
return LinstorUtil.getDevicePath(api, rscName);
194+
} catch (ApiException apiEx) {
195+
logger.error("Linstor: ApiEx - {}", apiEx.getMessage());
196+
throw new CloudRuntimeException(apiEx.getBestMessage(), apiEx);
197+
}
198+
}
199+
172200
private void removeExactSizeProperty(VolumeInfo volumeInfo) {
173201
StoragePoolVO destStoragePool = _storagePool.findById(volumeInfo.getDataStore().getId());
174-
DevelopersApi api = LinstorUtil.getLinstorAPI(destStoragePool.getHostAddress(),
175-
LinstorConfigurationManager.ApiToken.valueIn(destStoragePool.getId()),
176-
Boolean.TRUE.equals(LinstorConfigurationManager.InsecureSsl.valueIn(destStoragePool.getId())));
202+
DevelopersApi api = getLinstorAPI(destStoragePool);
177203

178204
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
179205
rdm.setDeleteProps(Collections.singletonList(LinstorUtil.LIN_PROP_DRBDOPT_EXACT_SIZE));
@@ -266,10 +292,10 @@ private void handlePostMigration(boolean success, Map<VolumeInfo, VolumeInfo> sr
266292
_volumeService.expungeVolumeAsync(destVolumeInfo);
267293

268294
if (destroyFuture.get().isFailed()) {
269-
logger.debug("Failed to clean up dest volume on storage");
295+
logger.warn("Failed to clean up dest volume {} on storage", destVolumeInfo);
270296
}
271297
} catch (Exception e) {
272-
logger.debug("Failed to clean up dest volume on storage", e);
298+
logger.warn("Failed to clean up dest volume {} on storage", destVolumeInfo, e);
273299
}
274300
}
275301
}
@@ -293,9 +319,7 @@ private void handlePostMigration(boolean success, Map<VolumeInfo, VolumeInfo> sr
293319
private boolean needsExactSizeProp(VolumeInfo srcVolumeInfo) {
294320
StoragePoolVO srcStoragePool = _storagePool.findById(srcVolumeInfo.getDataStore().getId());
295321
if (srcStoragePool.getPoolType() == Storage.StoragePoolType.Linstor) {
296-
DevelopersApi api = LinstorUtil.getLinstorAPI(srcStoragePool.getHostAddress(),
297-
LinstorConfigurationManager.ApiToken.valueIn(srcStoragePool.getId()),
298-
Boolean.TRUE.equals(LinstorConfigurationManager.InsecureSsl.valueIn(srcStoragePool.getId())));
322+
DevelopersApi api = getLinstorAPI(srcStoragePool);
299323

300324
String rscName = LinstorUtil.RSC_PREFIX + srcVolumeInfo.getPath();
301325
try {
@@ -335,6 +359,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
335359

336360
Map<String, MigrateCommand.MigrateDiskInfo> migrateStorage = new HashMap<>();
337361
Map<VolumeInfo, VolumeInfo> srcVolumeInfoToDestVolumeInfo = new HashMap<>();
362+
boolean postMigrationHandled = false;
338363

339364
try {
340365
for (Map.Entry<VolumeInfo, DataStore> entry : volumeDataStoreMap.entrySet()) {
@@ -358,13 +383,17 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
358383

359384
boolean exactSize = needsExactSizeProp(srcVolumeInfo);
360385

361-
String devPath = LinstorUtil.createResource(
362-
destVolumeInfo, destStoragePool, _storagePoolDao, exactSize);
386+
LinstorUtil.createResource(destVolumeInfo, destStoragePool, _storagePoolDao, exactSize);
363387

364388
_volumeDao.update(destVolume.getId(), destVolume);
365389
destVolume = _volumeDao.findById(destVolume.getId());
366390

367391
destVolumeInfo = _volumeDataFactory.getVolume(destVolume.getId(), destDataStore);
392+
// registered right away, so a failure from here on cleans the new resource up again
393+
srcVolumeInfoToDestVolumeInfo.put(srcVolumeInfo, destVolumeInfo);
394+
395+
String devPath = makeAvailableOnHost(
396+
destStoragePool, LinstorUtil.RSC_PREFIX + destVolumeInfo.getUuid(), destHost);
368397

369398
MigrateCommand.MigrateDiskInfo migrateDiskInfo = new MigrateCommand.MigrateDiskInfo(
370399
srcVolumeInfo.getPath(),
@@ -375,8 +404,6 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
375404
migrateDiskInfoList.add(migrateDiskInfo);
376405

377406
migrateStorage.put(srcVolumeInfo.getPath(), migrateDiskInfo);
378-
379-
srcVolumeInfoToDestVolumeInfo.put(srcVolumeInfo, destVolumeInfo);
380407
}
381408

382409
PrepareForMigrationCommand pfmc = new PrepareForMigrationCommand(vmTO);
@@ -413,6 +440,7 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
413440
MigrateAnswer migrateAnswer = (MigrateAnswer) _agentManager.send(srcHost.getId(), migrateCommand);
414441
boolean success = migrateAnswer != null && migrateAnswer.getResult();
415442

443+
postMigrationHandled = true;
416444
handlePostMigration(success, srcVolumeInfoToDestVolumeInfo, vmTO, destHost);
417445

418446
if (migrateAnswer == null) {
@@ -427,9 +455,18 @@ public void copyAsync(Map<VolumeInfo, DataStore> volumeDataStoreMap, VirtualMach
427455
} catch (AgentUnavailableException | OperationTimedoutException | CloudRuntimeException ex) {
428456
errMsg = String.format(
429457
"Copy volume(s) of VM [%s] to storage(s) [%s] and VM to host [%s] failed in LinstorDataMotionStrategy.copyAsync. Error message: [%s].",
430-
vmTO, srcHost, destHost, ex.getMessage());
458+
vmTO, volumeDataStoreMap.values(), destHost, ex.getMessage());
431459
logger.error(errMsg, ex);
432460

461+
if (!postMigrationHandled && !srcVolumeInfoToDestVolumeInfo.isEmpty()) {
462+
// failed before the migration was started: remove the already created destination volumes
463+
try {
464+
handlePostMigration(false, srcVolumeInfoToDestVolumeInfo, vmTO, destHost);
465+
} catch (Exception e) {
466+
logger.warn("Failed to clean up the destination volume(s) of VM [{}]", vmTO, e);
467+
}
468+
}
469+
433470
throw new CloudRuntimeException(errMsg);
434471
} finally {
435472
CopyCmdAnswer copyCmdAnswer = new CopyCmdAnswer(errMsg);

0 commit comments

Comments
 (0)