Skip to content

Commit 91f09c8

Browse files
committed
minor fixes
1 parent e63fb7a commit 91f09c8

File tree

9 files changed

+68
-12
lines changed

9 files changed

+68
-12
lines changed

core/src/main/java/com/cloud/agent/api/RemoveBitmapCommand.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
119
package com.cloud.agent.api;
220

321
import org.apache.cloudstack.storage.to.SnapshotObjectTO;

core/src/main/java/com/cloud/storage/resource/StorageSubsystemCommandHandlerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ protected Answer execute(CreateObjectCommand cmd) {
142142
}
143143
return new CreateObjectAnswer("not supported type");
144144
} catch (Exception e) {
145-
logger.error("Failed to create object [%s] due to [%s].", data.getObjectType(), e.getMessage(), e);
145+
logger.error("Failed to create object [{}] due to [{}].", data.getObjectType(), e.getMessage(), e);
146146
return new CreateObjectAnswer(e.toString());
147147
}
148148
}

engine/schema/src/main/java/org/apache/cloudstack/storage/datastore/db/SnapshotDataStoreDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ public SnapshotDataStoreVO findParent(DataStoreRole role, Long storeId, Long zon
341341
sc.setParameters(STORE_ROLE, role.toString());
342342
sc.setParameters(STATE, ObjectInDataStoreStateMachine.State.Ready.name());
343343
if (storeId != null) {
344-
sc.setParameters(STORE_ID, (Object) new Long[]{storeId});
344+
sc.setParameters(STORE_ID, new Long[]{storeId});
345345
} else if (zoneId != null) {
346346
List<ImageStoreVO> imageStores = imageStoreDao.listStoresByZoneId(zoneId);
347347
Object[] imageStoreIds = imageStores.stream().map(ImageStoreVO::getId).toArray();

engine/storage/snapshot/src/main/java/org/apache/cloudstack/storage/snapshot/SnapshotServiceImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.agent.api.RemoveBitmapCommand;
2828
import com.cloud.host.dao.HostDao;
2929
import com.cloud.hypervisor.Hypervisor;
30+
import com.cloud.storage.Volume;
3031
import com.cloud.storage.snapshot.SnapshotManager;
3132
import com.cloud.vm.VirtualMachine;
3233
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
@@ -644,11 +645,15 @@ public boolean deleteSnapshot(SnapshotInfo snapInfo) {
644645
}
645646

646647
protected void deleteBitmap (SnapshotInfo snapshotInfo) {
647-
if (snapshotInfo.getBaseVolume() == null) {
648+
Volume baseVol = snapshotInfo.getBaseVolume();
649+
if (baseVol == null || !Volume.State.Ready.equals(baseVol.getState())) {
648650
return;
649651
}
652+
653+
VirtualMachine attachedVM = snapshotInfo.getBaseVolume().getAttachedVM();
654+
650655
RemoveBitmapCommand cmd = new RemoveBitmapCommand((SnapshotObjectTO) snapshotInfo.getTO(),
651-
snapshotInfo.getBaseVolume().getAttachedVM().getState().equals(VirtualMachine.State.Running));
656+
attachedVM != null && attachedVM.getState().equals(VirtualMachine.State.Running));
652657
EndPoint ep = epSelector.select(snapshotInfo, StorageAction.REMOVEBITMAP);
653658

654659
Answer answer = ep.sendMessage(cmd);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
335335

336336
public static final String CHECKPOINT_CREATE_COMMAND = "virsh checkpoint-create --domain %s --xmlfile %s --redefine";
337337

338-
public static final String CHECKPOINT_DELETE_COMMAND = "virsh checkpoint-delete --domain %s --checkpointname %s";
338+
public static final String CHECKPOINT_DELETE_COMMAND = "virsh checkpoint-delete --domain %s --checkpointname %s --metadata";
339339

340340
private String modifyVlanPath;
341341
private String versionStringPath;

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtConvertSnapshotCommandWrapper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ public Answer execute(ConvertSnapshotCommand command, LibvirtComputingResource s
5959
String secondaryStoragePoolUrl = nfsImageStore.getUrl();
6060

6161
Set<KVMStoragePool> storagePoolSet = null;
62+
KVMStoragePool secondaryStorage = null;
6263
try {
63-
KVMStoragePool secondaryStorage = serverResource.getStoragePoolMgr().getStoragePoolByURI(secondaryStoragePoolUrl);
64+
secondaryStorage = serverResource.getStoragePoolMgr().getStoragePoolByURI(secondaryStoragePoolUrl);
6465
storagePoolSet = serverResource.connectToAllVolumeSnapshotSecondaryStorages(snapshotObjectTO.getVolume());
6566

6667
String snapshotRelativePath = snapshotObjectTO.getPath();
@@ -94,6 +95,9 @@ public Answer execute(ConvertSnapshotCommand command, LibvirtComputingResource s
9495
logger.error(String.format("Failed to convert snapshot [%s] due to %s.", snapshotObjectTO, ex.getMessage()), ex);
9596
return new Answer(command, ex);
9697
} finally {
98+
if (secondaryStorage != null) {
99+
serverResource.getStoragePoolMgr().deleteStoragePool(secondaryStorage.getType(), secondaryStorage.getUuid());
100+
}
97101
if (storagePoolSet != null) {
98102
serverResource.disconnectAllVolumeSnapshotSecondaryStorages(storagePoolSet);
99103
}

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRemoveBitmapCommandWrapper.java

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
//
2+
// Licensed to the Apache Software Foundation (ASF) under one
3+
// or more contributor license agreements. See the NOTICE file
4+
// distributed with this work for additional information
5+
// regarding copyright ownership. The ASF licenses this file
6+
// to you under the Apache License, Version 2.0 (the
7+
// "License"); you may not use this file except in compliance
8+
// with the License. You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing,
13+
// software distributed under the License is distributed on an
14+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
// KIND, either express or implied. See the License for the
16+
// specific language governing permissions and limitations
17+
// under the License.
18+
//
119
package com.cloud.hypervisor.kvm.resource.wrapper;
220

321
import com.cloud.agent.api.Answer;
@@ -71,7 +89,14 @@ protected Answer removeBitmapForStoppedVM(SnapshotObjectTO snapshotObjectTO, Lib
7189

7290
logger.debug("Removing bitmap [{}] for volume [{}].", bitmap, volumeTo.getName());
7391

74-
qemuImg.bitmap(QemuImg.BitmapOperation.Remove, volume, bitmap);
92+
try {
93+
qemuImg.bitmap(QemuImg.BitmapOperation.Remove, volume, bitmap);
94+
} catch (QemuImgException ex) {
95+
if (!(ex.getMessage().contains("Dirty bitmap") || ex.getMessage().contains("not found"))) {
96+
throw ex;
97+
}
98+
logger.warn("Could not delete dirty bitmap [{}] as it was not found. This will happen if the volume was migrated. If it is not the case, this should be reported.", bitmap);
99+
}
75100
return new Answer(cmd);
76101
}
77102

plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/wrapper/LibvirtRevertSnapshotCommandWrapper.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin
8484

8585
String volumePath = volume.getPath();
8686
String snapshotRelPath = snapshot.getPath();
87-
87+
KVMStoragePool secondaryStoragePool = null;
8888
try {
8989
KVMStoragePoolManager storagePoolMgr = libvirtComputingResource.getStoragePoolMgr();
9090

@@ -113,7 +113,6 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin
113113
rbd.close(image);
114114
rados.ioCtxDestroy(io);
115115
} else {
116-
KVMStoragePool secondaryStoragePool = null;
117116
if (snapshotImageStore != null && DataStoreRole.Primary != snapshotImageStore.getRole()) {
118117
secondaryStoragePool = storagePoolMgr.getStoragePoolByURI(snapshotImageStore.getUrl());
119118
}
@@ -142,7 +141,12 @@ public Answer execute(final RevertSnapshotCommand command, final LibvirtComputin
142141
} catch (RbdException e) {
143142
logger.error("Failed to connect to revert snapshot due to RBD exception: ", e);
144143
return new Answer(command, false, e.toString());
144+
} finally {
145+
if (secondaryStoragePool != null) {
146+
libvirtComputingResource.getStoragePoolMgr().deleteStoragePool(secondaryStoragePool.getType(), secondaryStoragePool.getUuid());
147+
}
145148
}
149+
146150
}
147151

148152
/**

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,6 @@ public class KVMStorageProcessor implements StorageProcessor {
200200

201201
private static final String DOMJOBABORT_COMMAND = "virsh domjobabort --domain %s";
202202

203-
private static String CHECKPOINT_DELETE_COMMAND = "virsh checkpoint-delete --domain %s --checkpointname %s";
204-
205203
private static final String DUMMY_VM_XML = "<domain type='qemu'>\n" +
206204
" <name>%s</name>\n" +
207205
" <memory unit='MiB'>256</memory>\n" +
@@ -2782,6 +2780,7 @@ private KVMPhysicalDisk createVolumeFromSnapshotOnNFS(CopyCommand cmd, PrimaryDa
27822780
KVMPhysicalDisk disk = storagePoolMgr.copyPhysicalDisk(snapshotDisk, path != null ? path : volUuid, primaryPool, cmd.getWaitInMillSeconds());
27832781

27842782
storagePoolMgr.disconnectPhysicalDisk(pool.getPoolType(), pool.getUuid(), path);
2783+
secondaryPool.delete();
27852784
return disk;
27862785
}
27872786

@@ -2922,7 +2921,8 @@ protected void deleteCheckpoint(SnapshotObjectTO snapshotTO) throws IOException
29222921
}
29232922
String checkpointName = snapshotTO.getPath().substring(snapshotTO.getPath().lastIndexOf(File.separator) + 1);
29242923

2925-
Script.runSimpleBashScript(String.format(CHECKPOINT_DELETE_COMMAND, vmName, resource.getHypervisorPath(), checkpointName));
2924+
logger.debug("Deleting checkpoint [{}] of VM [{}].", checkpointName, vmName);
2925+
Script.runSimpleBashScript(String.format(LibvirtComputingResource.CHECKPOINT_DELETE_COMMAND, vmName, checkpointName));
29262926
}
29272927

29282928
/**

0 commit comments

Comments
 (0)