bug 10624: copyvolume needs to put ".qcow2" at the end of the file

status 10624: resovled fixed
This commit is contained in:
Edison Su 2011-10-05 17:48:22 -07:00
parent 4fa95df837
commit 96afeaf38f
5 changed files with 13 additions and 9 deletions

View File

@ -940,13 +940,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
String secondaryStorageUrl = cmd.getSecondaryStorageURL();
StoragePool primaryPool = null;
Connect conn;
StoragePool secondaryStoragePool = null;
try {
conn = LibvirtConnection.getConnection();
primaryPool = _storageResource.getStoragePool(conn, pool.getUuid());
LibvirtStoragePoolDef primary = _storageResource.getStoragePoolDef(conn, primaryPool);
String primaryMountPath = primary.getTargetPath();
StoragePool secondaryStoragePool = _storageResource.getStoragePoolbyURI(conn, new URI(secondaryStorageUrl));
secondaryStoragePool = _storageResource.getStoragePoolbyURI(conn, new URI(secondaryStorageUrl));
LibvirtStoragePoolDef spd = _storageResource.getStoragePoolDef(conn, secondaryStoragePool);
String ssPmountPath = spd.getTargetPath();
@ -955,10 +956,10 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
if (copyToSecondary) {
StorageVol volume = _storageResource.getVolume(conn, primaryPool, volumePath);
String volumeDestPath = ssPmountPath + File.separator + "volumes/" + cmd.getVolumeId() + File.separator;
_storageResource.copyVolume(volumePath, volumeDestPath, volumeName, _cmdsTimeout);
_storageResource.copyVolume(volumePath, volumeDestPath, volumeName + ".qcow2", _cmdsTimeout);
return new CopyVolumeAnswer(cmd, true, null, null, volumeName);
} else {
volumePath = ssPmountPath + File.separator + "volumes/" + cmd.getVolumeId() + File.separator + volumePath;
volumePath = ssPmountPath + File.separator + "volumes/" + cmd.getVolumeId() + File.separator + volumePath + ".qcow2";
_storageResource.copyVolume(volumePath, primaryMountPath, volumeName, _cmdsTimeout);
return new CopyVolumeAnswer(cmd, true, null, null, primaryMountPath + File.separator + volumeName);
}

View File

@ -391,12 +391,15 @@ public class LibvirtStorageResource {
if (!_storageLayer.exists(srcPath)) {
throw new InternalErrorException("volume:" + srcPath + " is not exits");
}
String result = Script.runSimpleBashScript("cp " + srcPath + " " + destPath + File.separator + volumeName, timeout);
destPath = destPath + File.separator + volumeName;
String result = Script.runSimpleBashScript("qemu-img convert " + srcPath + " " + destPath, timeout);
if (result != null) {
return false;
} else {
return true;
result = Script.runSimpleBashScript("chmod 777 " + destPath);
return true;
}
}
public LibvirtStoragePoolDef getStoragePoolDef(Connect conn, StoragePool pool) throws LibvirtException {

View File

@ -4375,7 +4375,7 @@ public class ManagementServerImpl implements ManagementServer {
_uploadMonitor.extractVolume(uploadJob, sserver, volume, url, zoneId, volumeLocalPath, cmd.getStartEventId(), job.getId(), _asyncMgr);
return uploadJob.getId();
} else { // Volume is copied now make it visible under apache and create a URL.
_uploadMonitor.createVolumeDownloadURL(volumeId, volumeLocalPath, Upload.Type.VOLUME, zoneId, uploadJob.getId());
_uploadMonitor.createVolumeDownloadURL(volumeId, volumeLocalPath, Upload.Type.VOLUME, zoneId, uploadJob.getId(), getFormatForPool(srcPool));
return uploadJob.getId();
}
}

View File

@ -56,6 +56,6 @@ public interface UploadMonitor extends Manager{
VMTemplateHostVO vmTemplateHost, Long dataCenterId, long eventId);
void createVolumeDownloadURL(Long entityId, String path, Type type,
Long dataCenterId, Long uploadId);
Long dataCenterId, Long uploadId, String volType);
}

View File

@ -259,7 +259,7 @@ public class UploadMonitorImpl implements UploadMonitor {
}
@Override
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId) {
public void createVolumeDownloadURL(Long entityId, String path, Type type, Long dataCenterId, Long uploadId, String volType) {
String errorString = "";
boolean success = false;
@ -282,7 +282,7 @@ public class UploadMonitorImpl implements UploadMonitor {
throw new CloudRuntimeException(errorString);
}
// Create Symlink at ssvm
String uuid = UUID.randomUUID().toString() + path.substring(path.length() - 4) ; // last 4 characters of the path specify the format like .vhd
String uuid = UUID.randomUUID().toString() + "." + volType ;
HostVO secStorage = ApiDBUtils.findHostById(ApiDBUtils.findUploadById(uploadId).getHostId());
HostVO ssvm = _agentMgr.getSSAgent(secStorage);
if( ssvm == null ) {