Skip to content

Commit f2c5b5f

Browse files
committed
CLOUDSTACK-4618: fix CLVM
1 parent 80aa0d3 commit f2c5b5f

3 files changed

Lines changed: 80 additions & 12 deletions

File tree

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,7 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
147147
DataTO destData = cmd.getDestTO();
148148
TemplateObjectTO template = (TemplateObjectTO) srcData;
149149
DataStoreTO imageStore = template.getDataStore();
150-
TemplateObjectTO volume = (TemplateObjectTO) destData;
151-
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) volume.getDataStore();
150+
PrimaryDataStoreTO primaryStore = (PrimaryDataStoreTO) destData.getDataStore();
152151

153152
if (!(imageStore instanceof NfsTO)) {
154153
return new CopyCmdAnswer("unsupported protocol");
@@ -197,19 +196,32 @@ public Answer copyTemplateToPrimaryStorage(CopyCommand cmd) {
197196
KVMPhysicalDisk primaryVol = storagePoolMgr.copyPhysicalDisk(tmplVol, UUID.randomUUID().toString(),
198197
primaryPool);
199198

200-
TemplateObjectTO newTemplate = new TemplateObjectTO();
201-
newTemplate.setPath(primaryVol.getName());
202199

200+
DataTO data = null;
203201
/**
204202
* Force the ImageFormat for RBD templates to RAW
205203
*
206204
*/
207-
if (primaryPool.getType() == StoragePoolType.RBD) {
208-
newTemplate.setFormat(ImageFormat.RAW);
209-
} else {
210-
newTemplate.setFormat(ImageFormat.QCOW2);
205+
if (destData.getObjectType() == DataObjectType.TEMPLATE) {
206+
TemplateObjectTO newTemplate = new TemplateObjectTO();
207+
newTemplate.setPath(primaryVol.getName());
208+
if (primaryPool.getType() == StoragePoolType.RBD) {
209+
newTemplate.setFormat(ImageFormat.RAW);
210+
} else {
211+
newTemplate.setFormat(ImageFormat.QCOW2);
212+
}
213+
data = newTemplate;
214+
} else if (destData.getObjectType() == DataObjectType.VOLUME) {
215+
VolumeObjectTO volumeObjectTO = new VolumeObjectTO();
216+
volumeObjectTO.setPath(primaryVol.getName());
217+
if (primaryVol.getFormat() == PhysicalDiskFormat.RAW)
218+
volumeObjectTO.setFormat(ImageFormat.RAW);
219+
else if (primaryVol.getFormat() == PhysicalDiskFormat.QCOW2) {
220+
volumeObjectTO.setFormat(ImageFormat.QCOW2);
221+
}
222+
data = volumeObjectTO;
211223
}
212-
return new CopyCmdAnswer(newTemplate);
224+
return new CopyCmdAnswer(data);
213225
} catch (CloudRuntimeException e) {
214226
return new CopyCmdAnswer(e.toString());
215227
} finally {
@@ -287,6 +299,7 @@ public Answer cloneVolumeFromBaseTemplate(CopyCommand cmd) {
287299
String templatePath = template.getPath();
288300

289301
if (primaryPool.getType() == StoragePoolType.CLVM) {
302+
templatePath = ((NfsTO)imageStore).getUrl() + File.separator + templatePath;
290303
vol = templateToPrimaryDownload(templatePath, primaryPool);
291304
} else {
292305
if (templatePath.contains("/mnt")) {

‎plugins/storage/volume/default/src/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java‎

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,13 @@
2525
import com.cloud.agent.api.to.DataStoreTO;
2626
import com.cloud.agent.api.to.DataTO;
2727
import com.cloud.agent.api.to.StorageFilerTO;
28+
import com.cloud.configuration.Config;
29+
import com.cloud.configuration.dao.ConfigurationDao;
2830
import com.cloud.exception.StorageUnavailableException;
2931
import com.cloud.host.dao.HostDao;
32+
import com.cloud.storage.DataStoreRole;
3033
import com.cloud.storage.ResizeVolumePayload;
34+
import com.cloud.storage.Storage;
3135
import com.cloud.storage.StorageManager;
3236
import com.cloud.storage.StoragePool;
3337
import com.cloud.storage.VolumeManager;
@@ -36,17 +40,24 @@
3640
import com.cloud.storage.dao.VMTemplateDao;
3741
import com.cloud.storage.dao.VolumeDao;
3842
import com.cloud.storage.snapshot.SnapshotManager;
43+
import com.cloud.template.TemplateManager;
44+
import com.cloud.utils.NumbersUtil;
3945
import com.cloud.vm.dao.VMInstanceDao;
4046
import org.apache.cloudstack.engine.subsystem.api.storage.*;
4147
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
4248
import org.apache.cloudstack.storage.command.CommandResult;
49+
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
50+
import org.apache.cloudstack.storage.command.CopyCommand;
4351
import org.apache.cloudstack.storage.command.CreateObjectCommand;
4452
import org.apache.cloudstack.storage.command.DeleteCommand;
4553
import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao;
54+
import org.apache.cloudstack.storage.datastore.db.StoragePoolVO;
55+
import org.apache.cloudstack.storage.to.TemplateObjectTO;
4656
import org.apache.cloudstack.storage.volume.VolumeObject;
4757
import org.apache.log4j.Logger;
4858

4959
import javax.inject.Inject;
60+
import java.util.UUID;
5061

5162
public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver {
5263
private static final Logger s_logger = Logger.getLogger(CloudStackPrimaryDataStoreDriverImpl.class);
@@ -72,7 +83,12 @@ public class CloudStackPrimaryDataStoreDriverImpl implements PrimaryDataStoreDri
7283
SnapshotManager snapshotMgr;
7384
@Inject
7485
EndPointSelector epSelector;
75-
86+
@Inject
87+
ConfigurationDao configDao;
88+
@Inject
89+
TemplateManager templateManager;
90+
@Inject
91+
TemplateDataFactory templateDataFactory;
7692
@Override
7793
public DataTO getTO(DataObject data) {
7894
return null;
@@ -163,10 +179,49 @@ public void deleteAsync(DataStore dataStore, DataObject data, AsyncCompletionCal
163179

164180
@Override
165181
public void copyAsync(DataObject srcdata, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
182+
DataStore store = destData.getDataStore();
183+
if (store.getRole() == DataStoreRole.Primary) {
184+
if ((srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE)) {
185+
//For CLVM, we need to copy template to primary storage at all, just fake the copy result.
186+
TemplateObjectTO templateObjectTO = new TemplateObjectTO();
187+
templateObjectTO.setPath(UUID.randomUUID().toString());
188+
templateObjectTO.setSize(srcdata.getSize());
189+
templateObjectTO.setPhysicalSize(srcdata.getSize());
190+
templateObjectTO.setFormat(Storage.ImageFormat.RAW);
191+
CopyCmdAnswer answer = new CopyCmdAnswer(templateObjectTO);
192+
CopyCommandResult result = new CopyCommandResult("", answer);
193+
callback.complete(result);
194+
} else if (srcdata.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME) {
195+
//For CLVM, we need to pass template on secondary storage to hypervisor
196+
String value = configDao.getValue(Config.PrimaryStorageDownloadWait.toString());
197+
int _primaryStorageDownloadWait = NumbersUtil.parseInt(value,
198+
Integer.parseInt(Config.PrimaryStorageDownloadWait.getDefaultValue()));
199+
StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
200+
DataStore imageStore = templateManager.getImageStore(storagePoolVO.getDataCenterId(), srcdata.getId());
201+
DataObject srcData = templateDataFactory.getTemplate(srcdata.getId(), imageStore);
202+
203+
CopyCommand cmd = new CopyCommand(srcData.getTO(), destData.getTO(), _primaryStorageDownloadWait, true);
204+
EndPoint ep = epSelector.select(srcData, destData);
205+
Answer answer = ep.sendMessage(cmd);
206+
CopyCommandResult result = new CopyCommandResult("", answer);
207+
callback.complete(result);
208+
}
209+
}
166210
}
167211

168212
@Override
169213
public boolean canCopy(DataObject srcData, DataObject destData) {
214+
//BUG fix for CLOUDSTACK-4618
215+
DataStore store = destData.getDataStore();
216+
if (store.getRole() == DataStoreRole.Primary) {
217+
if ((srcData.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.TEMPLATE) ||
218+
(srcData.getType() == DataObjectType.TEMPLATE && destData.getType() == DataObjectType.VOLUME)) {
219+
StoragePoolVO storagePoolVO = primaryStoreDao.findById(store.getId());
220+
if (storagePoolVO != null && storagePoolVO.getPoolType() == Storage.StoragePoolType.CLVM) {
221+
return true;
222+
}
223+
}
224+
}
170225
return false;
171226
}
172227

‎scripts/storage/qcow2/managesnapshot.sh‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ fi
4242

4343
is_lv() {
4444
# Must be a block device
45-
if [ -b "${1}" ]; then
45+
if [ -b "${1}" -o -L "{1}" ]; then
4646
# But not a volume group or physical volume
4747
lvm vgs "${1}" > /dev/null 2>&1 && return 1
4848
# And a logical volume
49-
lvm lvs "${1}" > /dev/null 2>&1 && return 0
49+
lvm lvs "${1}" > /dev/null 2>&1 && return 1
5050
fi
5151
return 0
5252
}

0 commit comments

Comments
 (0)