Skip to content

Commit 3f5a77e

Browse files
authored
Linstor: Fix migrate primary storage (#9528)
1 parent ebaf064 commit 3f5a77e

File tree

7 files changed

+76
-35
lines changed

7 files changed

+76
-35
lines changed

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMPhysicalDisk.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@
1818

1919
import org.apache.cloudstack.utils.qemu.QemuImg.PhysicalDiskFormat;
2020
import org.apache.cloudstack.utils.qemu.QemuObject;
21+
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
2122
import org.apache.commons.lang3.StringUtils;
2223

2324
import java.util.ArrayList;
2425
import java.util.List;
2526

2627
public class KVMPhysicalDisk {
2728
private String path;
28-
private String name;
29-
private KVMStoragePool pool;
29+
private final String name;
30+
private final KVMStoragePool pool;
31+
private String dispName;
32+
private String vmName;
3033
private boolean useAsTemplate;
3134

3235
public static String RBDStringBuilder(String monHost, int monPort, String authUserName, String authSecret, String image) {
@@ -81,7 +84,9 @@ public KVMPhysicalDisk(String path, String name, KVMStoragePool pool) {
8184

8285
@Override
8386
public String toString() {
84-
return "KVMPhysicalDisk [path=" + path + ", name=" + name + ", pool=" + pool + ", format=" + format + ", size=" + size + ", virtualSize=" + virtualSize + "]";
87+
return String.format("KVMPhysicalDisk %s",
88+
ReflectionToStringBuilderUtils.reflectOnlySelectedFields(
89+
this, "path", "name", "pool", "format", "size", "virtualSize", "dispName", "vmName"));
8590
}
8691

8792
public void setFormat(PhysicalDiskFormat format) {
@@ -135,4 +140,20 @@ public void setQemuEncryptFormat(QemuObject.EncryptFormat format) {
135140
public void setUseAsTemplate() { this.useAsTemplate = true; }
136141

137142
public boolean useAsTemplate() { return this.useAsTemplate; }
143+
144+
public String getDispName() {
145+
return dispName;
146+
}
147+
148+
public void setDispName(String dispName) {
149+
this.dispName = dispName;
150+
}
151+
152+
public String getVmName() {
153+
return vmName;
154+
}
155+
156+
public void setVmName(String vmName) {
157+
this.vmName = vmName;
158+
}
138159
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/KVMStorageProcessor.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ public Answer cloneVolumeFromBaseTemplate(final CopyCommand cmd) {
432432
if (!storagePoolMgr.connectPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), path, details)) {
433433
s_logger.warn("Failed to connect new volume at path: " + path + ", in storage pool id: " + primaryStore.getUuid());
434434
}
435+
BaseVol.setDispName(template.getName());
435436

436437
vol = storagePoolMgr.copyPhysicalDisk(BaseVol, path != null ? path : volume.getUuid(), primaryPool, cmd.getWaitInMillSeconds(), null, volume.getPassphrase(), volume.getProvisioningType());
437438

@@ -524,6 +525,8 @@ public Answer copyVolumeFromImageCacheToPrimary(final CopyCommand cmd) {
524525
final KVMPhysicalDisk volume = secondaryStoragePool.getPhysicalDisk(srcVolumeName);
525526

526527
volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
528+
volume.setDispName(srcVol.getName());
529+
volume.setVmName(srcVol.getVmName());
527530

528531
final KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, path != null ? path : volumeName, primaryPool, cmd.getWaitInMillSeconds());
529532

@@ -2486,6 +2489,8 @@ public Answer copyVolumeFromPrimaryToPrimary(CopyCommand cmd) {
24862489
}
24872490

24882491
volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
2492+
volume.setDispName(srcVol.getName());
2493+
volume.setVmName(srcVol.getVmName());
24892494

24902495
String destVolumeName = null;
24912496
if (destPrimaryStore.isManaged()) {

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/storage/LibvirtStorageAdaptor.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,10 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
14021402
*/
14031403

14041404
KVMStoragePool srcPool = disk.getPool();
1405-
PhysicalDiskFormat sourceFormat = disk.getFormat();
1405+
/* Linstor images are always stored as RAW, but Linstor uses qcow2 in DB,
1406+
to support snapshots(backuped) as qcow2 files. */
1407+
PhysicalDiskFormat sourceFormat = srcPool.getType() != StoragePoolType.Linstor ?
1408+
disk.getFormat() : PhysicalDiskFormat.RAW;
14061409
String sourcePath = disk.getPath();
14071410

14081411
KVMPhysicalDisk newDisk;

plugins/storage/volume/linstor/src/main/java/com/cloud/hypervisor/kvm/storage/LinstorStorageAdaptor.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,15 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name, KVMSt
516516
final KVMPhysicalDisk dstDisk = destPools.createPhysicalDisk(
517517
name, QemuImg.PhysicalDiskFormat.RAW, provisioningType, disk.getVirtualSize(), null);
518518

519+
final DevelopersApi api = getLinstorAPI(destPools);
520+
final String rscName = LinstorUtil.RSC_PREFIX + name;
521+
try {
522+
LinstorUtil.applyAuxProps(api, rscName, disk.getDispName(), disk.getVmName());
523+
} catch (ApiException apiExc) {
524+
s_logger.error(String.format("Error setting aux properties for %s", rscName));
525+
logLinstorAnswers(apiExc.getApiCallRcList());
526+
}
527+
519528
s_logger.debug(String.format("Linstor.copyPhysicalDisk: dstPath: %s", dstDisk.getPath()));
520529
final QemuImgFile destFile = new QemuImgFile(dstDisk.getPath());
521530
destFile.setFormat(dstDisk.getFormat());

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/driver/LinstorPrimaryDataStoreDriverImpl.java

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import com.linbit.linstor.api.model.ResourceDefinitionCloneRequest;
2727
import com.linbit.linstor.api.model.ResourceDefinitionCloneStarted;
2828
import com.linbit.linstor.api.model.ResourceDefinitionCreate;
29-
import com.linbit.linstor.api.model.ResourceDefinitionModify;
3029
import com.linbit.linstor.api.model.ResourceGroupSpawn;
3130
import com.linbit.linstor.api.model.ResourceMakeAvailable;
3231
import com.linbit.linstor.api.model.Snapshot;
@@ -62,8 +61,8 @@
6261
import com.cloud.storage.DataStoreRole;
6362
import com.cloud.storage.ResizeVolumePayload;
6463
import com.cloud.storage.SnapshotVO;
65-
import com.cloud.storage.Storage.StoragePoolType;
6664
import com.cloud.storage.Storage;
65+
import com.cloud.storage.Storage.StoragePoolType;
6766
import com.cloud.storage.StorageManager;
6867
import com.cloud.storage.StoragePool;
6968
import com.cloud.storage.VMTemplateStoragePoolVO;
@@ -389,27 +388,6 @@ private void applyQoSSettings(StoragePoolVO storagePool, DevelopersApi api, Stri
389388
}
390389
}
391390

392-
private void applyAuxProps(DevelopersApi api, String rscName, String dispName, String vmName)
393-
throws ApiException
394-
{
395-
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
396-
Properties props = new Properties();
397-
if (dispName != null)
398-
{
399-
props.put("Aux/cs-name", dispName);
400-
}
401-
if (vmName != null)
402-
{
403-
props.put("Aux/cs-vm-name", vmName);
404-
}
405-
if (!props.isEmpty())
406-
{
407-
rdm.setOverrideProps(props);
408-
ApiCallRcList answers = api.resourceDefinitionModify(rscName, rdm);
409-
checkLinstorAnswersThrow(answers);
410-
}
411-
}
412-
413391
private String getRscGrp(StoragePoolVO storagePoolVO) {
414392
return storagePoolVO.getUserInfo() != null && !storagePoolVO.getUserInfo().isEmpty() ?
415393
storagePoolVO.getUserInfo() : "DfltRscGrp";
@@ -427,7 +405,8 @@ private String createResourceBase(
427405
ApiCallRcList answers = api.resourceGroupSpawn(rscGrp, rscGrpSpawn);
428406
checkLinstorAnswersThrow(answers);
429407

430-
applyAuxProps(api, rscName, volName, vmName);
408+
answers = LinstorUtil.applyAuxProps(api, rscName, volName, vmName);
409+
checkLinstorAnswersThrow(answers);
431410

432411
return LinstorUtil.getDevicePath(api, rscName);
433412
} catch (ApiException apiEx)
@@ -499,7 +478,7 @@ private String cloneResource(long csCloneId, VolumeInfo volumeInfo, StoragePoolV
499478
resizeResource(linstorApi, rscName, volumeInfo.getSize());
500479
}
501480

502-
applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
481+
LinstorUtil.applyAuxProps(linstorApi, rscName, volumeInfo.getName(), volumeInfo.getAttachedVmName());
503482
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeInfo.getMaxIops());
504483

505484
return LinstorUtil.getDevicePath(linstorApi, rscName);
@@ -551,7 +530,7 @@ private String createResourceFromSnapshot(long csSnapshotId, String rscName, Sto
551530
answers = linstorApi.resourceSnapshotRestore(cloneRes, snapName, snapshotRestore);
552531
checkLinstorAnswersThrow(answers);
553532

554-
applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
533+
LinstorUtil.applyAuxProps(linstorApi, rscName, volumeVO.getName(), null);
555534
applyQoSSettings(storagePoolVO, linstorApi, rscName, volumeVO.getMaxIops());
556535

557536
return LinstorUtil.getDevicePath(linstorApi, rscName);
@@ -833,7 +812,7 @@ public void copyAsync(DataObject srcData, DataObject dstData, AsyncCompletionCal
833812
VolumeInfo volume = sinfo.getBaseVolume();
834813
deleteSnapshot(
835814
srcData.getDataStore(),
836-
LinstorUtil.RSC_PREFIX + volume.getUuid(),
815+
LinstorUtil.RSC_PREFIX + volume.getPath(),
837816
LinstorUtil.RSC_PREFIX + sinfo.getUuid());
838817
}
839818
res = new CopyCommandResult(null, answer);
@@ -969,7 +948,7 @@ private Answer copyVolume(DataObject srcData, DataObject dstData) {
969948
VolumeInfo srcVolInfo = (VolumeInfo) srcData;
970949
final StoragePoolVO pool = _storagePoolDao.findById(srcVolInfo.getDataStore().getId());
971950
final DevelopersApi api = LinstorUtil.getLinstorAPI(pool.getHostAddress());
972-
final String rscName = LinstorUtil.RSC_PREFIX + srcVolInfo.getUuid();
951+
final String rscName = LinstorUtil.RSC_PREFIX + srcVolInfo.getPath();
973952

974953
VolumeObjectTO to = (VolumeObjectTO) srcVolInfo.getTO();
975954
// patch source format
@@ -1082,7 +1061,7 @@ protected Answer copySnapshot(DataObject srcData, DataObject destData) {
10821061
options.put("volumeSize", snapshotObject.getBaseVolume().getSize() + "");
10831062

10841063
try {
1085-
final String rscName = LinstorUtil.RSC_PREFIX + snapshotObject.getBaseVolume().getUuid();
1064+
final String rscName = LinstorUtil.RSC_PREFIX + snapshotObject.getBaseVolume().getPath();
10861065
String snapshotName = setCorrectSnapshotPath(api, rscName, snapshotObject);
10871066

10881067
CopyCommand cmd = new LinstorBackupSnapshotCommand(

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/datastore/util/LinstorUtil.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
import com.linbit.linstor.api.model.ApiCallRc;
2323
import com.linbit.linstor.api.model.ApiCallRcList;
2424
import com.linbit.linstor.api.model.Node;
25+
import com.linbit.linstor.api.model.Properties;
2526
import com.linbit.linstor.api.model.ProviderKind;
2627
import com.linbit.linstor.api.model.Resource;
28+
import com.linbit.linstor.api.model.ResourceDefinitionModify;
2729
import com.linbit.linstor.api.model.ResourceGroup;
2830
import com.linbit.linstor.api.model.ResourceWithVolumes;
2931
import com.linbit.linstor.api.model.StoragePool;
@@ -239,4 +241,26 @@ public static String getDevicePath(DevelopersApi api, String rscName) throws Api
239241
s_logger.error(errMsg);
240242
throw new CloudRuntimeException("Linstor: " + errMsg);
241243
}
244+
245+
public static ApiCallRcList applyAuxProps(DevelopersApi api, String rscName, String dispName, String vmName)
246+
throws ApiException
247+
{
248+
ResourceDefinitionModify rdm = new ResourceDefinitionModify();
249+
Properties props = new Properties();
250+
if (dispName != null)
251+
{
252+
props.put("Aux/cs-name", dispName);
253+
}
254+
if (vmName != null)
255+
{
256+
props.put("Aux/cs-vm-name", vmName);
257+
}
258+
ApiCallRcList answers = new ApiCallRcList();
259+
if (!props.isEmpty())
260+
{
261+
rdm.setOverrideProps(props);
262+
answers = api.resourceDefinitionModify(rscName, rdm);
263+
}
264+
return answers;
265+
}
242266
}

plugins/storage/volume/linstor/src/main/java/org/apache/cloudstack/storage/snapshot/LinstorVMSnapshotStrategy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
239239
final String snapshotName = vmSnapshotVO.getName();
240240
final List<String> failedToDelete = new ArrayList<>();
241241
for (VolumeObjectTO volumeObjectTO : volumeTOs) {
242-
final String rscName = LinstorUtil.RSC_PREFIX + volumeObjectTO.getUuid();
242+
final String rscName = LinstorUtil.RSC_PREFIX + volumeObjectTO.getPath();
243243
String err = linstorDeleteSnapshot(api, rscName, snapshotName);
244244

245245
if (err != null)
@@ -292,7 +292,7 @@ private boolean revertVMSnapshotOperation(VMSnapshot vmSnapshot, long userVmId)
292292
final String snapshotName = vmSnapshotVO.getName();
293293

294294
for (VolumeObjectTO volumeObjectTO : volumeTOs) {
295-
final String rscName = LinstorUtil.RSC_PREFIX + volumeObjectTO.getUuid();
295+
final String rscName = LinstorUtil.RSC_PREFIX + volumeObjectTO.getPath();
296296
String err = linstorRevertSnapshot(api, rscName, snapshotName);
297297
if (err != null) {
298298
throw new CloudRuntimeException(String.format(

0 commit comments

Comments
 (0)