Skip to content

Commit 5a67a6f

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 82e447a commit 5a67a6f

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
@@ -4131,6 +4131,16 @@ public StopAnswer execute(StopCommand cmd) {
41314131

41324132
try {
41334133
if (vm.getPowerState(conn) == VmPowerState.HALTED) {
4134+
Map<String, String> platform = vm.getPlatform(conn);
4135+
Integer timeoffset = null;
4136+
try {
4137+
if (platform.containsKey("timeoffset")) {
4138+
timeoffset = Integer.valueOf(platform.get("timeoffset"));
4139+
}
4140+
} catch (NumberFormatException e) {
4141+
s_logger.error("Error while reading the platform:timeoffset field of the instance", e);
4142+
}
4143+
41344144
Set<VIF> vifs = vm.getVIFs(conn);
41354145
List<Network> networks = new ArrayList<Network>();
41364146
for (VIF vif : vifs) {
@@ -4151,7 +4161,7 @@ public StopAnswer execute(StopCommand cmd) {
41514161
// network might be destroyed by other host
41524162
}
41534163
}
4154-
return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed", 0, true);
4164+
return new StopAnswer(cmd, "Stop VM " + vmName + " Succeed", 0, timeoffset, true);
41554165
}
41564166
} catch (XenAPIException e) {
41574167
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
@@ -1181,6 +1181,16 @@ public <T extends VMInstanceVO> boolean advanceStop(T vm, boolean forced, User u
11811181
stopped = answer.getResult();
11821182
if (!stopped) {
11831183
throw new CloudRuntimeException("Unable to stop the virtual machine due to " + answer.getDetails());
1184+
} else {
1185+
Integer timeoffset = answer.getTimeOffset();
1186+
if (timeoffset != null) {
1187+
if (vm.getType() == VirtualMachine.Type.User) {
1188+
UserVmVO userVm = _userVmDao.findById(vm.getId());
1189+
_userVmDao.loadDetails(userVm);
1190+
userVm.setDetail("timeoffset", timeoffset.toString());
1191+
_userVmDao.saveDetails(userVm);
1192+
}
1193+
}
11841194
}
11851195
vmGuru.finalizeStop(profile, answer);
11861196

0 commit comments

Comments
 (0)