Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions systemvm/debian/opt/cloud/bin/setup/cloud-early-config
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,8 @@ log_it() {
}

hypervisor() {
local try=$([ -x /usr/sbin/virt-what ] && virt-what | tail -1)
[ "$try" != "" ] && echo $try && return 0

grep -q QEMU /proc/cpuinfo && echo "kvm" && return 0
grep -q QEMU /var/log/messages && echo "kvm" && return 0

[ -d /proc/xen ] && mount -t xenfs none /proc/xen
if [ -d /proc/xen ]; then
mount -t xenfs none /proc/xen
$(dmesg | grep -q "Xen HVM")
if [ $? -eq 0 ]; then # 1=PV,0=HVM
echo "xen-hvm" && return 0
Expand All @@ -51,6 +45,19 @@ hypervisor() {
fi
fi

[ -x /usr/sbin/virt-what ] && local facts=( $(virt-what) )
if [ "$facts" != "" ]; then
# Xen HVM is recognized as Hyperv when Viridian extensions are enabled
if [ "${facts[-1]}" == "xen-domU" ] && [ "${facts[0]}" == "hyperv" ]; then
Copy link
Copy Markdown
Contributor

@khos2ow khos2ow Sep 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From XenServer only point of view, this block of code is redundant. Because result of dmesg | grep -q "Xen HVM" on HVM instance on XenServer, line 41, will work 100% of the time. The gotcha point of this function is to look for hvm on xen the first thing and if not a match let the rest of the function try to detect the type.

A while back I had the same issue and did a non-conclusive investigation about how virt-what works, and was actually getting all sorts of results/order on HVM and PV instance on Xen Server. Essentially the workaround I came up was the one I mentioned above.

echo "xen-hvm" && return 0
else
echo ${facts[-1]} && return 0
fi
fi

grep -q QEMU /proc/cpuinfo && echo "kvm" && return 0
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this is old code moved but it does not seem reliable or future proof. How about a call to virsh (--version or so)?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virsh is only the hypervisor host, not in the guest VM.

grep -q QEMU /var/log/messages && echo "kvm" && return 0

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

echo "unknown" && return 1
Expand Down