Skip to content

Commit 8f881ce

Browse files
committed
[Merge 4.11] CLOUDSTACK-10232: SystemVMs and VR to run as HVM on XenServer (#2465)
Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
2 parents 0afcec6 + 535e615 commit 8f881ce

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

plugins/hypervisors/xenserver/src/main/java/com/cloud/hypervisor/xenserver/resource/CitrixResourceBase.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ private static boolean isAlienVm(final VM vm, final Connection conn) throws XenA
287287

288288
protected StorageSubsystemCommandHandler storageHandler;
289289

290+
private static final String XENSTORE_DATA_IP = "vm-data/ip";
291+
private static final String XENSTORE_DATA_GATEWAY = "vm-data/gateway";
292+
private static final String XENSTORE_DATA_NETMASK = "vm-data/netmask";
293+
private static final String XENSTORE_DATA_CS_INIT = "vm-data/cloudstack/init";
294+
290295
public CitrixResourceBase() {
291296
}
292297

@@ -1285,7 +1290,6 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
12851290
if (guestOsDetails.containsKey("xenserver.dynamicMax")) {
12861291
recommendedMemoryMax = Long.valueOf(guestOsDetails.get("xenserver.dynamicMax")).longValue();
12871292
}
1288-
12891293
}
12901294

12911295
if (isDmcEnabled(conn, host) && vmSpec.isEnableDynamicallyScaleVm()) {
@@ -1309,7 +1313,6 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
13091313
vmr.memoryStaticMin = vmSpec.getMinRam();
13101314
vmr.memoryStaticMax = vmSpec.getMaxRam();
13111315
vmr.memoryDynamicMin = vmSpec.getMinRam();
1312-
;
13131316
vmr.memoryDynamicMax = vmSpec.getMaxRam();
13141317

13151318
vmr.VCPUsMax = (long)vmSpec.getCpus();
@@ -1323,17 +1326,15 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
13231326
NicTO mgmtNic = vmSpec.getNics()[0];
13241327
if (mgmtNic != null) {
13251328
Map<String, String> xenstoreData = new HashMap<String, String>(3);
1326-
xenstoreData.put("vm-data/ip", mgmtNic.getIp().toString().trim());
1327-
xenstoreData.put("vm-data/gateway", mgmtNic.getGateway().toString().trim());
1328-
xenstoreData.put("vm-data/netmask", mgmtNic.getNetmask().toString().trim());
1329+
xenstoreData.put(XENSTORE_DATA_IP, mgmtNic.getIp().toString().trim());
1330+
xenstoreData.put(XENSTORE_DATA_GATEWAY, mgmtNic.getGateway().toString().trim());
1331+
xenstoreData.put(XENSTORE_DATA_NETMASK, mgmtNic.getNetmask().toString().trim());
13291332
vmr.xenstoreData = xenstoreData;
13301333
}
13311334
}
13321335

13331336
final VM vm = VM.create(conn, vmr);
1334-
if (s_logger.isDebugEnabled()) {
1335-
s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName());
1336-
}
1337+
s_logger.debug("Created VM " + vm.getUuid(conn) + " for " + vmSpec.getName());
13371338

13381339
final Map<String, String> vcpuParams = new HashMap<String, String>();
13391340

@@ -1365,12 +1366,18 @@ public VM createVmFromTemplate(final Connection conn, final VirtualMachineTO vmS
13651366

13661367
final String bootArgs = vmSpec.getBootArgs();
13671368
if (bootArgs != null && bootArgs.length() > 0) {
1369+
// send boot args for PV instances
13681370
String pvargs = vm.getPVArgs(conn);
13691371
pvargs = pvargs + vmSpec.getBootArgs().replaceAll(" ", "%");
1370-
if (s_logger.isDebugEnabled()) {
1371-
s_logger.debug("PV args are " + pvargs);
1372-
}
13731372
vm.setPVArgs(conn, pvargs);
1373+
s_logger.debug("PV args are " + pvargs);
1374+
1375+
// send boot args into xenstore-data for HVM instances
1376+
Map<String, String> xenstoreData = new HashMap<>();
1377+
1378+
xenstoreData.put(XENSTORE_DATA_CS_INIT, bootArgs);
1379+
vm.setXenstoreData(conn, xenstoreData);
1380+
s_logger.debug("HVM args are " + bootArgs);
13741381
}
13751382

13761383
if (!(guestOsTypeName.startsWith("Windows") || guestOsTypeName.startsWith("Citrix") || guestOsTypeName.startsWith("Other"))) {

systemvm/debian/opt/cloud/bin/setup/cloud-early-config

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ hypervisor() {
4242
grep -q QEMU /var/log/messages && echo "kvm" && return 0
4343

4444
[ -d /proc/xen ] && mount -t xenfs none /proc/xen
45-
[ -d /proc/xen ] && echo "xen-domU" && return 0
45+
if [ -d /proc/xen ]; then
46+
$(dmesg | grep -q "Xen HVM")
47+
if [ $? -eq 0 ]; then # 1=PV,0=HVM
48+
echo "xen-hvm" && return 0
49+
else
50+
echo "xen-pv" && return 0
51+
fi
52+
fi
4653

4754
vmware-checkvm &> /dev/null && echo "vmware" && return 0
4855

@@ -64,10 +71,17 @@ config_guest() {
6471

6572
get_boot_params() {
6673
case $HYPERVISOR in
67-
xen-domU|xen-hvm)
74+
xen-pv)
6875
cat /proc/cmdline > $CMDLINE
6976
sed -i "s/%/ /g" $CMDLINE
7077
;;
78+
xen-hvm)
79+
if [ ! -f /usr/sbin/xenstore-read ]; then
80+
log_it "ERROR: xentools not installed, cannot found xenstore-read" && exit 5
81+
fi
82+
/usr/sbin/xenstore-read vm-data/cloudstack/init > /var/cache/cloud/cmdline
83+
sed -i "s/%/ /g" /var/cache/cloud/cmdline
84+
;;
7185
kvm)
7286
VPORT=$(find /dev/virtio-ports -type l -name '*.vport' 2>/dev/null|head -1)
7387

0 commit comments

Comments
 (0)