[x86] hyperv-daemons: Make all services conditional on device existence

hv_{kvp,vss}_daemon used to communicate with the corresponding kernel
drivers over netlink, but now they use char devices.  hv_fcopy_daemon
always used a char device.  Rather than checking for Hyper-V
specifically, change all of the init scripts and systemd service
definitions to check for the appropriate device nodes.

Delete the check-hyperv program that we used to check for Hyper-V
in init scripts.
This commit is contained in:
Ben Hutchings 2018-10-17 01:48:57 +01:00
parent 85da926d38
commit bc118214a5
9 changed files with 8 additions and 117 deletions

1
debian/changelog vendored
View File

@ -10,6 +10,7 @@ linux (4.19~rc8-1~exp1) UNRELEASED; urgency=medium
* debian/rules: Checksum only the source name and version from
debian/changelog
* Move generation of CONFIG_BUILD_SALT to gencontrol.py
* [x86] hyperv-daemons: Make all services conditional on device existence
[ Karsten Merker ]
* [riscv64] Build a kernel image and udebs for riscv64 (Closes: #908161)

View File

@ -18,8 +18,7 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-fcopy-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V or the kernel device does not exist
/lib/hyperv-daemons/check-hyperv || exit 0
# Exit if the kernel device does not exist
[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
# Load the VERBOSE setting and other rcS variables

View File

@ -1,6 +1,5 @@
[Unit]
Description=Hyper-V file copy service (FCOPY) daemon
ConditionVirtualization=microsoft
ConditionPathExists=/dev/vmbus/hv_fcopy
[Service]

View File

@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-kvp-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V
/lib/hyperv-daemons/check-hyperv || exit 0
# Exit if the kernel device does not exist
[ -e "/dev/vmbus/hv_kvp" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

View File

@ -1,6 +1,6 @@
[Unit]
Description=Hyper-V key-value pair (KVP) daemon
ConditionVirtualization=microsoft
ConditionPathExists=/dev/vmbus/hv_kvp
[Service]
ExecStart=/usr/sbin/hv_kvp_daemon -n

View File

@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-vss-daemon
# Exit if the package is not installed
[ -x "$DAEMON" ] || exit 0
# Exit if we are not running under Hyper-V
/lib/hyperv-daemons/check-hyperv || exit 0
# Exit if the kernel device does not exist
[ -e "/dev/vmbus/hv_vss" ] || exit 0
# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

View File

@ -1,6 +1,6 @@
[Unit]
Description=Hyper-V volume shadow copy service (VSS) daemon
ConditionVirtualization=microsoft
ConditionPathExists=/dev/vmbus/hv_vss
[Service]
ExecStart=/usr/sbin/hv_vss_daemon -n

View File

@ -14,9 +14,4 @@ installdir = /usr/sbin
include $(top_rulesdir)/Makefile.inc
# Handle check-hyperv separately since it's installed in a different directory
all-local: check-hyperv
install-local:
install -D -m755 check-hyperv '$(DESTDIR)/lib/hyperv-daemons/check-hyperv'
endif

View File

@ -1,103 +0,0 @@
/*
* This program is derived from systemd.
*
* Copyright 2011 Lennart Poettering
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#define streq(a, b) (!strcmp(a, b))
#define ELEMENTSOF(a) (sizeof(a) / sizeof((a)[0]))
enum {
VIRTUALIZATION_NONE,
VIRTUALIZATION_VM_OTHER,
VIRTUALIZATION_MICROSOFT,
};
static int detect_vm_cpuid(void) {
static const struct {
const char *cpuid;
int id;
} cpuid_vendor_table[] = {
/* http://msdn.microsoft.com/en-us/library/ff542428.aspx */
{ "Microsoft Hv", VIRTUALIZATION_MICROSOFT },
};
uint32_t eax, ecx;
bool hypervisor;
/* http://lwn.net/Articles/301888/ */
#if defined (__i386__)
#define REG_a "eax"
#define REG_b "ebx"
#elif defined (__amd64__)
#define REG_a "rax"
#define REG_b "rbx"
#endif
/* First detect whether there is a hypervisor */
eax = 1;
__asm__ __volatile__ (
/* ebx/rbx is being used for PIC! */
" push %%"REG_b" \n\t"
" cpuid \n\t"
" pop %%"REG_b" \n\t"
: "=a" (eax), "=c" (ecx)
: "0" (eax)
);
hypervisor = !!(ecx & 0x80000000U);
if (hypervisor) {
union {
uint32_t sig32[3];
char text[13];
} sig = {};
unsigned j;
/* There is a hypervisor, see what it is */
eax = 0x40000000U;
__asm__ __volatile__ (
/* ebx/rbx is being used for PIC! */
" push %%"REG_b" \n\t"
" cpuid \n\t"
" mov %%ebx, %1 \n\t"
" pop %%"REG_b" \n\t"
: "=a" (eax), "=r" (sig.sig32[0]), "=c" (sig.sig32[1]), "=d" (sig.sig32[2])
: "0" (eax)
);
for (j = 0; j < ELEMENTSOF(cpuid_vendor_table); j ++)
if (streq(sig.text, cpuid_vendor_table[j].cpuid))
return cpuid_vendor_table[j].id;
return VIRTUALIZATION_VM_OTHER;
}
return VIRTUALIZATION_NONE;
}
int main(void)
{
return detect_vm_cpuid() != VIRTUALIZATION_MICROSOFT;
}