Skip to content

Commit c08254b

Browse files
committed
CLOUDSTACK-4641: fix create volume from snapshot timeout issue
1 parent 5950d37 commit c08254b

8 files changed

Lines changed: 65 additions & 53 deletions

File tree

‎engine/api/src/org/apache/cloudstack/storage/command/CopyCommand.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,8 @@ public void setCacheTO(DataTO cacheTO) {
8080
this.cacheTO = cacheTO;
8181
}
8282

83+
public int getWaitInMillSeconds() {
84+
return this.getWait() * 1000;
85+
}
86+
8387
}

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,7 +1367,7 @@ private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
13671367
secondaryStorageUrl
13681368
+ volumeDestPath);
13691369
_storagePoolMgr.copyPhysicalDisk(volume,
1370-
destVolumeName,secondaryStoragePool);
1370+
destVolumeName,secondaryStoragePool, 0);
13711371
return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
13721372
} else {
13731373
volumePath = "/volumes/" + cmd.getVolumeId() + File.separator;
@@ -1377,7 +1377,7 @@ private CopyVolumeAnswer execute(CopyVolumeCommand cmd) {
13771377
KVMPhysicalDisk volume = secondaryStoragePool
13781378
.getPhysicalDisk(cmd.getVolumePath() + ".qcow2");
13791379
_storagePoolMgr.copyPhysicalDisk(volume, volumeName,
1380-
primaryPool);
1380+
primaryPool, 0);
13811381
return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
13821382
}
13831383
} catch (CloudRuntimeException e) {
@@ -1463,7 +1463,7 @@ protected Answer execute(CreateCommand cmd) {
14631463
} else {
14641464
BaseVol = primaryPool.getPhysicalDisk(cmd.getTemplateUrl());
14651465
vol = _storagePoolMgr.createDiskFromTemplate(BaseVol, UUID
1466-
.randomUUID().toString(), primaryPool);
1466+
.randomUUID().toString(), primaryPool, 0);
14671467
}
14681468
if (vol == null) {
14691469
return new Answer(cmd, false,
@@ -1524,7 +1524,7 @@ protected KVMPhysicalDisk templateToPrimaryDownload(String templateUrl, KVMStora
15241524

15251525
/* Copy volume to primary storage */
15261526

1527-
KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(templateVol, UUID.randomUUID().toString(), primaryPool);
1527+
KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(templateVol, UUID.randomUUID().toString(), primaryPool, 0);
15281528
return primaryVol;
15291529
} catch (CloudRuntimeException e) {
15301530
s_logger.error("Failed to download template to primary storage",e);
@@ -2381,7 +2381,7 @@ protected CreateVolumeFromSnapshotAnswer execute(
23812381
primaryUuid);
23822382
String volUuid = UUID.randomUUID().toString();
23832383
KVMPhysicalDisk disk = _storagePoolMgr.copyPhysicalDisk(snapshot,
2384-
volUuid, primaryPool);
2384+
volUuid, primaryPool, 0);
23852385
return new CreateVolumeFromSnapshotAnswer(cmd, true, "",
23862386
disk.getName());
23872387
} catch (CloudRuntimeException e) {
@@ -2532,7 +2532,7 @@ protected CreatePrivateTemplateAnswer execute(
25322532
QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + cmd.getUniqueName() + ".qcow2");
25332533
destFile.setFormat(PhysicalDiskFormat.QCOW2);
25342534

2535-
QemuImg q = new QemuImg();
2535+
QemuImg q = new QemuImg(0);
25362536
try {
25372537
q.convert(srcFile, destFile);
25382538
} catch (QemuImgException e) {
@@ -2635,7 +2635,7 @@ protected PrimaryStorageDownloadAnswer execute(
26352635
cmd.getPoolUuid());
26362636

26372637
KVMPhysicalDisk primaryVol = _storagePoolMgr.copyPhysicalDisk(
2638-
tmplVol, UUID.randomUUID().toString(), primaryPool);
2638+
tmplVol, UUID.randomUUID().toString(), primaryPool, 0);
26392639

26402640
return new PrimaryStorageDownloadAnswer(primaryVol.getName(),
26412641
primaryVol.getSize());

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/KVMStoragePoolManager.java‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,25 @@ public boolean deleteStoragePool(StoragePoolType type, String uuid) {
206206
}
207207

208208
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template, String name,
209-
KVMStoragePool destPool) {
209+
KVMStoragePool destPool, int timeout) {
210210
StorageAdaptor adaptor = getStorageAdaptor(destPool.getType());
211211

212212
// LibvirtStorageAdaptor-specific statement
213213
if (destPool.getType() == StoragePoolType.RBD) {
214214
return adaptor.createDiskFromTemplate(template, name,
215-
PhysicalDiskFormat.RAW, template.getSize(), destPool);
215+
PhysicalDiskFormat.RAW, template.getSize(), destPool, timeout);
216216
} else if (destPool.getType() == StoragePoolType.CLVM) {
217217
return adaptor.createDiskFromTemplate(template, name,
218218
PhysicalDiskFormat.RAW, template.getSize(),
219-
destPool);
219+
destPool, timeout);
220220
} else if (template.getFormat() == PhysicalDiskFormat.DIR) {
221221
return adaptor.createDiskFromTemplate(template, name,
222222
PhysicalDiskFormat.DIR,
223-
template.getSize(), destPool);
223+
template.getSize(), destPool, timeout);
224224
} else {
225225
return adaptor.createDiskFromTemplate(template, name,
226226
PhysicalDiskFormat.QCOW2,
227-
template.getSize(), destPool);
227+
template.getSize(), destPool, timeout);
228228
}
229229
}
230230

@@ -237,9 +237,9 @@ public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
237237
}
238238

239239
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
240-
KVMStoragePool destPool) {
240+
KVMStoragePool destPool, int timeout) {
241241
StorageAdaptor adaptor = getStorageAdaptor(destPool.getType());
242-
return adaptor.copyPhysicalDisk(disk, name, destPool);
242+
return adaptor.copyPhysicalDisk(disk, name, destPool, timeout);
243243
}
244244

245245
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
194194
primaryStore.getUuid());
195195

196196
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(),
197-
primaryPool);
197+
primaryPool, cmd.getWaitInMillSeconds());
198198

199199

200200
DataTO data = null;
@@ -232,7 +232,7 @@ else if (primaryVol.getFormat() == PhysicalDiskFormat.QCOW2) {
232232
}
233233

234234
// this is much like PrimaryStorageDownloadCommand, but keeping it separate
235-
private KVMPhysicalDisk templateToPrimaryDownload(String templateUrl, KVMStoragePool primaryPool) {
235+
private KVMPhysicalDisk templateToPrimaryDownload(String templateUrl, KVMStoragePool primaryPool, int timeout) {
236236
int index = templateUrl.lastIndexOf("/");
237237
String mountpoint = templateUrl.substring(0, index);
238238
String templateName = null;
@@ -269,7 +269,7 @@ private KVMPhysicalDisk templateToPrimaryDownload(String templateUrl, KVMStorage
269269
/* Copy volume to primary storage */
270270

271271
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(templateVol, UUID.randomUUID().toString(),
272-
primaryPool);
272+
primaryPool, timeout);
273273
return primaryVol;
274274
} catch (CloudRuntimeException e) {
275275
s_logger.error("Failed to download template to primary storage", e);
@@ -300,14 +300,14 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
300300

301301
if (primaryPool.getType() == StoragePoolType.CLVM) {
302302
templatePath = ((NfsTO)imageStore).getUrl() + File.separator + templatePath;
303-
vol = templateToPrimaryDownload(templatePath, primaryPool);
303+
vol = templateToPrimaryDownload(templatePath, primaryPool, cmd.getWaitInMillSeconds());
304304
} else {
305305
if (templatePath.contains("/mnt")) {
306306
//upgrade issue, if the path contains path, need to extract the volume uuid from path
307307
templatePath = templatePath.substring(templatePath.lastIndexOf(File.separator) + 1);
308308
}
309309
BaseVol = storagePoolMgr.getPhysicalDisk(primaryStore.getPoolType(), primaryStore.getUuid(), templatePath);
310-
vol = storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), BaseVol.getPool());
310+
vol = storagePoolMgr.createDiskFromTemplate(BaseVol, UUID.randomUUID().toString(), BaseVol.getPool(), cmd.getWaitInMillSeconds());
311311
}
312312
if (vol == null) {
313313
return new CopyCmdAnswer(" Can't create storage volume on storage pool");
@@ -378,7 +378,7 @@ public Answer copyVolumeFromImageCacheToPrimary(CopyCommand cmd) {
378378
.getPhysicalDisk(srcVolumeName);
379379
volume.setFormat(PhysicalDiskFormat.valueOf(srcFormat.toString()));
380380
KVMPhysicalDisk newDisk = storagePoolMgr.copyPhysicalDisk(volume, volumeName,
381-
primaryPool);
381+
primaryPool, cmd.getWaitInMillSeconds());
382382
VolumeObjectTO newVol = new VolumeObjectTO();
383383
newVol.setFormat(ImageFormat.valueOf(newDisk.getFormat().toString().toUpperCase()));
384384
newVol.setPath(volumeName);
@@ -425,7 +425,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
425425
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(
426426
secondaryStorageUrl + File.separator + destVolumePath);
427427
storagePoolMgr.copyPhysicalDisk(volume,
428-
destVolumeName,secondaryStoragePool);
428+
destVolumeName,secondaryStoragePool, cmd.getWaitInMillSeconds());
429429
VolumeObjectTO newVol = new VolumeObjectTO();
430430
newVol.setPath(destVolumePath + File.separator + destVolumeName);
431431
newVol.setFormat(destFormat);
@@ -443,7 +443,7 @@ public Answer copyVolumeFromPrimaryToSecondary(CopyCommand cmd) {
443443
public Answer createTemplateFromVolume(CopyCommand cmd) {
444444
DataTO srcData = cmd.getSrcTO();
445445
DataTO destData = cmd.getDestTO();
446-
int wait = cmd.getWait();
446+
int wait = cmd.getWaitInMillSeconds();
447447
TemplateObjectTO template = (TemplateObjectTO) destData;
448448
DataStoreTO imageStore = template.getDataStore();
449449
VolumeObjectTO volume = (VolumeObjectTO) srcData;
@@ -469,7 +469,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
469469
String templateName = UUID.randomUUID().toString();
470470

471471
if (primary.getType() != StoragePoolType.RBD) {
472-
Script command = new Script(_createTmplPath, wait * 1000, s_logger);
472+
Script command = new Script(_createTmplPath, wait, s_logger);
473473
command.add("-f", disk.getPath());
474474
command.add("-t", tmpltPath);
475475
command.add("-n", templateName + ".qcow2");
@@ -490,7 +490,7 @@ public Answer createTemplateFromVolume(CopyCommand cmd) {
490490
QemuImgFile destFile = new QemuImgFile(tmpltPath + "/" + templateName + ".qcow2");
491491
destFile.setFormat(PhysicalDiskFormat.QCOW2);
492492

493-
QemuImg q = new QemuImg();
493+
QemuImg q = new QemuImg(cmd.getWaitInMillSeconds());
494494
try {
495495
q.convert(srcFile, destFile);
496496
} catch (QemuImgException e) {
@@ -618,7 +618,7 @@ protected Answer backupSnapshotForObjectStore(CopyCommand cmd) {
618618
SnapshotObjectTO snapshotOnCacheStore = (SnapshotObjectTO)answer.getNewData();
619619
snapshotOnCacheStore.setDataStore(cacheStore);
620620
((SnapshotObjectTO) destData).setDataStore(imageStore);
621-
CopyCommand newCpyCmd = new CopyCommand(snapshotOnCacheStore, destData, cmd.getWait(), cmd.executeInSequence());
621+
CopyCommand newCpyCmd = new CopyCommand(snapshotOnCacheStore, destData, cmd.getWaitInMillSeconds(), cmd.executeInSequence());
622622
return copyToObjectStore(newCpyCmd);
623623
}
624624
@Override
@@ -722,7 +722,7 @@ public Answer backupSnapshot(CopyCommand cmd) {
722722
return new CopyCmdAnswer(e.toString());
723723
}
724724
} else {
725-
Script command = new Script(_manageSnapshotPath, cmd.getWait() * 1000, s_logger);
725+
Script command = new Script(_manageSnapshotPath, cmd.getWaitInMillSeconds(), s_logger);
726726
command.add("-b", snapshotDisk.getPath());
727727
command.add("-n", snapshotName);
728728
command.add("-p", snapshotDestPath);
@@ -1184,7 +1184,7 @@ public Answer createVolumeFromSnapshot(CopyCommand cmd) {
11841184
String primaryUuid = pool.getUuid();
11851185
KVMStoragePool primaryPool = storagePoolMgr.getStoragePool(pool.getPoolType(), primaryUuid);
11861186
String volUuid = UUID.randomUUID().toString();
1187-
KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool);
1187+
KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, volUuid, primaryPool, cmd.getWaitInMillSeconds());
11881188
VolumeObjectTO newVol = new VolumeObjectTO();
11891189
newVol.setPath(disk.getName());
11901190
newVol.setSize(disk.getVirtualSize());

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ public boolean deletePhysicalDisk(String uuid, KVMStoragePool pool) {
766766
*/
767767
@Override
768768
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
769-
String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool) {
769+
String name, PhysicalDiskFormat format, long size, KVMStoragePool destPool, int timeout) {
770770

771771
String newUuid = UUID.randomUUID().toString();
772772
KVMStoragePool srcPool = template.getPool();
@@ -783,20 +783,20 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
783783
if (destPool.getType() != StoragePoolType.RBD) {
784784
disk = destPool.createPhysicalDisk(newUuid, format, template.getVirtualSize());
785785
if (template.getFormat() == PhysicalDiskFormat.TAR) {
786-
Script.runSimpleBashScript("tar -x -f " + template.getPath() + " -C " + disk.getPath());
786+
Script.runSimpleBashScript("tar -x -f " + template.getPath() + " -C " + disk.getPath(), timeout);
787787
} else if (template.getFormat() == PhysicalDiskFormat.DIR) {
788788
Script.runSimpleBashScript("mkdir -p " + disk.getPath());
789789
Script.runSimpleBashScript("chmod 755 " + disk.getPath());
790-
Script.runSimpleBashScript("cp -p -r " + template.getPath() + "/* " + disk.getPath());
790+
Script.runSimpleBashScript("cp -p -r " + template.getPath() + "/* " + disk.getPath(), timeout);
791791
} else if (format == PhysicalDiskFormat.QCOW2) {
792792
QemuImgFile backingFile = new QemuImgFile(template.getPath(), template.getFormat());
793793
QemuImgFile destFile = new QemuImgFile(disk.getPath());
794-
QemuImg qemu = new QemuImg();
794+
QemuImg qemu = new QemuImg(timeout);
795795
qemu.create(destFile, backingFile);
796796
} else if (format == PhysicalDiskFormat.RAW) {
797797
QemuImgFile sourceFile = new QemuImgFile(template.getPath(), template.getFormat());
798798
QemuImgFile destFile = new QemuImgFile(disk.getPath(), PhysicalDiskFormat.RAW);
799-
QemuImg qemu = new QemuImg();
799+
QemuImg qemu = new QemuImg(timeout);
800800
qemu.convert(sourceFile, destFile);
801801
}
802802
} else {
@@ -806,7 +806,7 @@ public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
806806
disk.setSize(template.getVirtualSize());
807807
disk.setVirtualSize(disk.getSize());
808808

809-
QemuImg qemu = new QemuImg();
809+
QemuImg qemu = new QemuImg(timeout);
810810
QemuImgFile srcFile;
811811
QemuImgFile destFile = new QemuImgFile(KVMPhysicalDisk.RBDStringBuilder(destPool.getSourceHost(),
812812
destPool.getSourcePort(),
@@ -960,7 +960,7 @@ public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid,
960960
*/
961961
@Override
962962
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
963-
KVMStoragePool destPool) {
963+
KVMStoragePool destPool, int timeout) {
964964

965965
/**
966966
With RBD you can't run qemu-img convert with an existing RBD image as destination
@@ -999,24 +999,27 @@ public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
999999
String destPath = newDisk.getPath();
10001000
PhysicalDiskFormat destFormat = newDisk.getFormat();
10011001

1002-
QemuImg qemu = new QemuImg();
1002+
QemuImg qemu = new QemuImg(timeout);
10031003
QemuImgFile srcFile = null;
10041004
QemuImgFile destFile = null;
10051005

10061006
if ((srcPool.getType() != StoragePoolType.RBD) && (destPool.getType() != StoragePoolType.RBD)) {
10071007
if (sourceFormat == PhysicalDiskFormat.TAR) {
1008-
Script.runSimpleBashScript("tar -x -f " + sourcePath + " -C " + destPath);
1008+
Script.runSimpleBashScript("tar -x -f " + sourcePath + " -C " + destPath, timeout);
10091009
} else if (sourceFormat == PhysicalDiskFormat.DIR) {
10101010
Script.runSimpleBashScript("mkdir -p " + destPath);
10111011
Script.runSimpleBashScript("chmod 755 " + destPath);
1012-
Script.runSimpleBashScript("cp -p -r " + sourcePath + "/* " + destPath);
1012+
Script.runSimpleBashScript("cp -p -r " + sourcePath + "/* " + destPath, timeout);
10131013
} else {
10141014
srcFile = new QemuImgFile(sourcePath, sourceFormat);
10151015
try {
10161016
Map<String, String> info = qemu.info(srcFile);
10171017
String backingFile = info.get(new String("backing_file"));
10181018
if (sourceFormat.equals(destFormat) && backingFile == null) {
1019-
Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath);
1019+
String result = Script.runSimpleBashScript("cp -f " + sourcePath + " " + destPath, timeout);
1020+
if (result != null) {
1021+
throw new CloudRuntimeException("Failed to create disk: " + result);
1022+
}
10201023
} else {
10211024
destFile = new QemuImgFile(destPath, destFormat);
10221025
try {

‎plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/storage/StorageAdaptor.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public KVMPhysicalDisk createPhysicalDisk(String name, KVMStoragePool pool,
4040

4141
public KVMPhysicalDisk createDiskFromTemplate(KVMPhysicalDisk template,
4242
String name, PhysicalDiskFormat format, long size,
43-
KVMStoragePool destPool);
43+
KVMStoragePool destPool, int timeout);
4444

4545
public KVMPhysicalDisk createTemplateFromDisk(KVMPhysicalDisk disk,
4646
String name, PhysicalDiskFormat format, long size,
@@ -50,7 +50,7 @@ public List<KVMPhysicalDisk> listPhysicalDisks(String storagePoolUuid,
5050
KVMStoragePool pool);
5151

5252
public KVMPhysicalDisk copyPhysicalDisk(KVMPhysicalDisk disk, String name,
53-
KVMStoragePool destPools);
53+
KVMStoragePool destPools, int timeout);
5454

5555
public KVMPhysicalDisk createDiskFromSnapshot(KVMPhysicalDisk snapshot,
5656
String snapshotName, String name, KVMStoragePool destPool);

0 commit comments

Comments
 (0)