[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:
parent
85da926d38
commit
bc118214a5
|
@ -10,6 +10,7 @@ linux (4.19~rc8-1~exp1) UNRELEASED; urgency=medium
|
||||||
* debian/rules: Checksum only the source name and version from
|
* debian/rules: Checksum only the source name and version from
|
||||||
debian/changelog
|
debian/changelog
|
||||||
* Move generation of CONFIG_BUILD_SALT to gencontrol.py
|
* Move generation of CONFIG_BUILD_SALT to gencontrol.py
|
||||||
|
* [x86] hyperv-daemons: Make all services conditional on device existence
|
||||||
|
|
||||||
[ Karsten Merker ]
|
[ Karsten Merker ]
|
||||||
* [riscv64] Build a kernel image and udebs for riscv64 (Closes: #908161)
|
* [riscv64] Build a kernel image and udebs for riscv64 (Closes: #908161)
|
||||||
|
|
|
@ -18,8 +18,7 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-fcopy-daemon
|
||||||
# Exit if the package is not installed
|
# Exit if the package is not installed
|
||||||
[ -x "$DAEMON" ] || exit 0
|
[ -x "$DAEMON" ] || exit 0
|
||||||
|
|
||||||
# Exit if we are not running under Hyper-V or the kernel device does not exist
|
# Exit if the kernel device does not exist
|
||||||
/lib/hyperv-daemons/check-hyperv || exit 0
|
|
||||||
[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
|
[ -e "/dev/vmbus/hv_fcopy" ] || exit 0
|
||||||
|
|
||||||
# Load the VERBOSE setting and other rcS variables
|
# Load the VERBOSE setting and other rcS variables
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Hyper-V file copy service (FCOPY) daemon
|
Description=Hyper-V file copy service (FCOPY) daemon
|
||||||
ConditionVirtualization=microsoft
|
|
||||||
ConditionPathExists=/dev/vmbus/hv_fcopy
|
ConditionPathExists=/dev/vmbus/hv_fcopy
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
|
|
|
@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-kvp-daemon
|
||||||
# Exit if the package is not installed
|
# Exit if the package is not installed
|
||||||
[ -x "$DAEMON" ] || exit 0
|
[ -x "$DAEMON" ] || exit 0
|
||||||
|
|
||||||
# Exit if we are not running under Hyper-V
|
# Exit if the kernel device does not exist
|
||||||
/lib/hyperv-daemons/check-hyperv || exit 0
|
[ -e "/dev/vmbus/hv_kvp" ] || exit 0
|
||||||
|
|
||||||
# Load the VERBOSE setting and other rcS variables
|
# Load the VERBOSE setting and other rcS variables
|
||||||
. /lib/init/vars.sh
|
. /lib/init/vars.sh
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Hyper-V key-value pair (KVP) daemon
|
Description=Hyper-V key-value pair (KVP) daemon
|
||||||
ConditionVirtualization=microsoft
|
ConditionPathExists=/dev/vmbus/hv_kvp
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/sbin/hv_kvp_daemon -n
|
ExecStart=/usr/sbin/hv_kvp_daemon -n
|
||||||
|
|
|
@ -18,8 +18,8 @@ SCRIPTNAME=/etc/init.d/hyperv-daemons.hv-vss-daemon
|
||||||
# Exit if the package is not installed
|
# Exit if the package is not installed
|
||||||
[ -x "$DAEMON" ] || exit 0
|
[ -x "$DAEMON" ] || exit 0
|
||||||
|
|
||||||
# Exit if we are not running under Hyper-V
|
# Exit if the kernel device does not exist
|
||||||
/lib/hyperv-daemons/check-hyperv || exit 0
|
[ -e "/dev/vmbus/hv_vss" ] || exit 0
|
||||||
|
|
||||||
# Load the VERBOSE setting and other rcS variables
|
# Load the VERBOSE setting and other rcS variables
|
||||||
. /lib/init/vars.sh
|
. /lib/init/vars.sh
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Hyper-V volume shadow copy service (VSS) daemon
|
Description=Hyper-V volume shadow copy service (VSS) daemon
|
||||||
ConditionVirtualization=microsoft
|
ConditionPathExists=/dev/vmbus/hv_vss
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecStart=/usr/sbin/hv_vss_daemon -n
|
ExecStart=/usr/sbin/hv_vss_daemon -n
|
||||||
|
|
|
@ -14,9 +14,4 @@ installdir = /usr/sbin
|
||||||
|
|
||||||
include $(top_rulesdir)/Makefile.inc
|
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
|
endif
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue