Skip to content

Commit 033d05f

Browse files
committed
CLOUDSTACK-3443: Timeoffset on windows guest not persisted between VM stop and start on XenServer.
The problem was because in cloudstack when a vm is stopped it gets destroyed on the host. For a windows vm the timeoffset (which can be set by changing the timezone from within the vm) is stored in the platform:timeoffset attribute of vm record. The information is lost when the vm is destroted. Made change to read and persist the platform:timeoffset vm attribute when an instance is stopped. The value is persisted in the user_vm_details table. When the vm is started again the attribute is set for the vm instance that gets created.
1 parent 3c1b3c7 commit 033d05f

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

‎core/src/com/cloud/agent/api/StopAnswer.java‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,27 @@
1818

1919
public class StopAnswer extends RebootAnswer {
2020
Integer vncPort;
21+
Integer timeOffset;
2122

2223
protected StopAnswer() {
2324
}
2425

26+
public StopAnswer(StopCommand cmd, String details, Integer vncPort, Integer timeOffset, boolean success) {
27+
super(cmd, details, success);
28+
this.vncPort = vncPort;
29+
this.timeOffset = timeOffset;
30+
}
31+
2532
public StopAnswer(StopCommand cmd, String details, Integer vncPort, boolean success) {
2633
super(cmd, details, success);
2734
this.vncPort = vncPort;
35+
this.timeOffset = null;
2836
}
2937

3038
public StopAnswer(StopCommand cmd, String details, boolean success) {
3139
super(cmd, details, success);
3240
vncPort = null;
33-
41+
timeOffset = null;
3442
}
3543

3644
public StopAnswer(StopCommand cmd, Exception e) {
@@ -42,4 +50,7 @@ public Integer getVncPort() {
4250
return vncPort;
4351
}
4452

53+
public Integer getTimeOffset() {
54+
return timeOffset;
55+
}
4556
}

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4112,6 +4112,16 @@ public StopAnswer execute(StopCommand cmd) {
41124112

41134113
try {
41144114
if (vm.getPowerState(conn) == VmPowerState.HALTED) {
4115+
Map<String, String> platform = vm.getPlatform(conn);
4116+
Integer timeoffset = null;
4117+
try {
4118+
if (platform.containsKey("timeoffset")) {
4119+
timeoffset = Integer.valueOf(platform.get("timeoffset"));
4120+
}
4121+
} catch (NumberFormatException e) {
4122+
s_logger.error("Error while reading the platform:timeoffset field of the instance", e);
4123+
}
4124+
41154125
Set<VIF> vifs = vm.getVIFs(conn);
41164126
List<Network> networks = new ArrayList<Network>();
41174127
for (VIF vif : vifs) {
@@ -4132,7 +4142,7 @@ public StopAnswer execute(StopCommand cmd) {
41324142
// network might be destroyed by other host
41334143
}
41344144
}
4135-
return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed", 0, true);
4145+
return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed", 0, timeoffset, true);
41364146
}
41374147
} catch (XenAPIException e) {
41384148
String msg = "VM destroy failed in Stop " + vmName + " Command due to " + e.toString();

‎plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/XenServer56FP1Resource.java‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ protected VM createVmFromTemplate(Connection conn, VirtualMachineTO vmSpec, Host
193193
vmr.VCPUsMax = 32L;
194194
}
195195

196+
String timeoffset = details.get("timeoffset");
197+
if (timeoffset != null) {
198+
Map<String, String> platform = vmr.platform;
199+
platform.put("timeoffset", timeoffset);
200+
vmr.platform = platform;
201+
}
202+
196203
vmr.VCPUsAtStartup = (long) vmSpec.getCpus();
197204
vmr.consoles.clear();
198205

‎server/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,16 @@ public <T extends VMInstanceVO> boolean advanceStop(T vm, boolean forced, User u
11841184
stopped = answer.getResult();
11851185
if (!stopped) {
11861186
throw new CloudRuntimeException("Unable to stop the virtual machine due to " + answer.getDetails());
1187+
} else {
1188+
Integer timeoffset = answer.getTimeOffset();
1189+
if (timeoffset != null) {
1190+
if (vm.getType() == VirtualMachine.Type.User) {
1191+
UserVmVO userVm = _userVmDao.findById(vm.getId());
1192+
_userVmDao.loadDetails(userVm);
1193+
userVm.setDetail("timeoffset", timeoffset.toString());
1194+
_userVmDao.saveDetails(userVm);
1195+
}
1196+
}
11871197
}
11881198
vmGuru.finalizeStop(profile, answer);
11891199

0 commit comments

Comments
 (0)