Skip to content

Commit 4815b02

Browse files
committed
Add quiesce vm for vmware during vm snapshot
1 parent d9ebbae commit 4815b02

5 files changed

Lines changed: 25 additions & 8 deletions

File tree

core/src/com/cloud/agent/api/VMSnapshotTO.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public class VMSnapshotTO {
3131
private String description;
3232
private VMSnapshotTO parent;
3333
private List<VolumeObjectTO> volumes;
34+
private boolean quiescevm;
3435

3536
public Long getId() {
3637
return id;
@@ -40,7 +41,8 @@ public void setId(Long id) {
4041
}
4142
public VMSnapshotTO(Long id, String snapshotName,
4243
VMSnapshot.Type type, Long createTime,
43-
String description, Boolean current, VMSnapshotTO parent) {
44+
String description, Boolean current, VMSnapshotTO parent,
45+
boolean quiescevm) {
4446
super();
4547
this.id = id;
4648
this.snapshotName = snapshotName;
@@ -49,9 +51,10 @@ public VMSnapshotTO(Long id, String snapshotName,
4951
this.current = current;
5052
this.description = description;
5153
this.parent = parent;
54+
this.quiescevm = quiescevm;
5255
}
5356
public VMSnapshotTO() {
54-
57+
this.quiescevm = true;
5558
}
5659
public String getDescription() {
5760
return description;
@@ -99,4 +102,12 @@ public List<VolumeObjectTO> getVolumes() {
99102
public void setVolumes(List<VolumeObjectTO> volumes) {
100103
this.volumes = volumes;
101104
}
105+
106+
public boolean getQuiescevm() {
107+
return this.quiescevm;
108+
}
109+
110+
public void setQuiescevm(boolean quiescevm) {
111+
this.quiescevm = quiescevm;
112+
}
102113
}

engine/storage/snapshot/src/org/apache/cloudstack/storage/vmsnapshot/DefaultVMSnapshotStrategy.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import javax.naming.ConfigurationException;
2626

2727
import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority;
28+
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotOptions;
2829
import org.apache.cloudstack.engine.subsystem.api.storage.VMSnapshotStrategy;
2930
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
3031
import org.apache.cloudstack.storage.to.VolumeObjectTO;
@@ -111,8 +112,12 @@ public VMSnapshot takeVMSnapshot(VMSnapshot vmSnapshot) {
111112
VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
112113
if (currentSnapshot != null)
113114
current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
115+
VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
116+
boolean quiescevm = true;
117+
if (options != null)
118+
quiescevm = options.needQuiesceVM();
114119
VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false,
115-
current);
120+
current, quiescevm);
116121
if (current == null)
117122
vmSnapshotVO.setParent(null);
118123
else
@@ -174,7 +179,7 @@ public boolean deleteVMSnapshot(VMSnapshot vmSnapshot) {
174179
String vmInstanceName = userVm.getInstanceName();
175180
VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(vmSnapshotVO).getParent();
176181
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(),
177-
vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent);
182+
vmSnapshot.getCreated().getTime(), vmSnapshot.getDescription(), vmSnapshot.getCurrent(), parent, true);
178183
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
179184
DeleteVMSnapshotCommand deleteSnapshotCommand = new DeleteVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs,guestOS.getDisplayName());
180185

@@ -330,7 +335,7 @@ public boolean revertVMSnapshot(VMSnapshot vmSnapshot) {
330335
VMSnapshotTO parent = vmSnapshotHelper.getSnapshotWithParents(snapshot).getParent();
331336

332337
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(snapshot.getId(), snapshot.getName(), snapshot.getType(),
333-
snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent);
338+
snapshot.getCreated().getTime(), snapshot.getDescription(), snapshot.getCurrent(), parent, true);
334339
Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
335340
GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
336341
RevertToVMSnapshotCommand revertToSnapshotCommand = new RevertToVMSnapshotCommand(vmInstanceName, vmSnapshotTO, volumeTOs, guestOS.getDisplayName());

engine/storage/src/org/apache/cloudstack/storage/helper/HypervisorHelperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public VMSnapshotTO quiesceVm(VirtualMachine virtualMachine) {
111111
int wait = NumbersUtil.parseInt(value, 1800);
112112
Long hostId = vmSnapshotHelper.pickRunningHost(virtualMachine.getId());
113113
VMSnapshotTO vmSnapshotTO = new VMSnapshotTO(1L, UUID.randomUUID().toString(), VMSnapshot.Type.DiskAndMemory, null, null, false,
114-
null);
114+
null, true);
115115
GuestOSVO guestOS = guestOSDao.findById(virtualMachine.getGuestOSId());
116116
List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(virtualMachine.getId());
117117
CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(virtualMachine.getInstanceName(),vmSnapshotTO ,volumeTOs, guestOS.getDisplayName(),virtualMachine.getState());

engine/storage/src/org/apache/cloudstack/storage/helper/VMSnapshotHelperImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public List<VolumeObjectTO> getVolumeTOList(Long vmId) {
122122

123123
private VMSnapshotTO convert2VMSnapshotTO(VMSnapshotVO vo) {
124124
return new VMSnapshotTO(vo.getId(), vo.getName(), vo.getType(), vo.getCreated().getTime(), vo.getDescription(),
125-
vo.getCurrent(), null);
125+
vo.getCurrent(), null, true);
126126
}
127127

128128
@Override

plugins/hypervisors/vmware/src/com/cloud/hypervisor/vmware/manager/VmwareStorageManagerImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,6 +1275,7 @@ public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSna
12751275
String vmSnapshotName = cmd.getTarget().getSnapshotName();
12761276
String vmSnapshotDesc = cmd.getTarget().getDescription();
12771277
boolean snapshotMemory = cmd.getTarget().getType() == VMSnapshot.Type.DiskAndMemory;
1278+
boolean quiescevm = cmd.getTarget().getQuiescevm();
12781279
VirtualMachineMO vmMo = null;
12791280
VmwareContext context = hostService.getServiceContext(cmd);
12801281
Map<String, String> mapNewDisk = new HashMap<String, String>();
@@ -1303,7 +1304,7 @@ public CreateVMSnapshotAnswer execute(VmwareHostService hostService, CreateVMSna
13031304
} else {
13041305
if (vmMo.getSnapshotMor(vmSnapshotName) != null){
13051306
s_logger.debug("VM snapshot " + vmSnapshotName + " already exists");
1306-
}else if (!vmMo.createSnapshot(vmSnapshotName, vmSnapshotDesc, snapshotMemory, true)) {
1307+
}else if (!vmMo.createSnapshot(vmSnapshotName, vmSnapshotDesc, snapshotMemory, quiescevm)) {
13071308
return new CreateVMSnapshotAnswer(cmd, false,
13081309
"Unable to create snapshot due to esxi internal failed");
13091310
}

0 commit comments

Comments
 (0)