summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreyk <reyk@openbsd.org>2017-01-10 17:16:39 +0000
committerreyk <reyk@openbsd.org>2017-01-10 17:16:39 +0000
commit0f265ed38c421156a6317ea5c28b91625d1e17d5 (patch)
tree3d0b2063f43f41ade9cdf8cdec3bd2e04309eda7
parentsimplify; NODE_ENDED does no harm in man(7) (diff)
downloadwireguard-openbsd-0f265ed38c421156a6317ea5c28b91625d1e17d5.tar.xz
wireguard-openbsd-0f265ed38c421156a6317ea5c28b91625d1e17d5.zip
Introduce pvbus_reboot() and pvbus_shutdown() to move the repeated
tasks from the PV drivers into a central place. While here, we figured out that it is not needed to check for allowpowerdown on the hypervisor-initiated shutdown requests. OK mikeb@
-rw-r--r--sys/dev/pv/hypervic.c12
-rw-r--r--sys/dev/pv/pvbus.c22
-rw-r--r--sys/dev/pv/pvvar.h4
-rw-r--r--sys/dev/pv/vmt.c16
-rw-r--r--sys/dev/pv/xen.c24
5 files changed, 32 insertions, 46 deletions
diff --git a/sys/dev/pv/hypervic.c b/sys/dev/pv/hypervic.c
index 079a8d27983..d5d233b700b 100644
--- a/sys/dev/pv/hypervic.c
+++ b/sys/dev/pv/hypervic.c
@@ -343,16 +343,8 @@ hv_heartbeat(void *arg)
static void
hv_shutdown_task(void *arg)
{
- extern int allowpowerdown;
-
- if (allowpowerdown == 0)
- return;
-
- suspend_randomness();
-
- log(LOG_KERN | LOG_NOTICE, "Shutting down in response to "
- "request from Hyper-V host\n");
- prsignal(initprocess, SIGUSR2);
+ struct hv_softc *sc = arg;
+ pvbus_shutdown(&sc->sc_dev);
}
int
diff --git a/sys/dev/pv/pvbus.c b/sys/dev/pv/pvbus.c
index 594ca5e222c..ecc60b3c6b3 100644
--- a/sys/dev/pv/pvbus.c
+++ b/sys/dev/pv/pvbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pvbus.c,v 1.15 2016/12/06 10:38:08 reyk Exp $ */
+/* $OpenBSD: pvbus.c,v 1.16 2017/01/10 17:16:39 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -260,6 +260,26 @@ pvbus_print(void *aux, const char *pnp)
}
void
+pvbus_shutdown(struct device *dev)
+{
+ suspend_randomness();
+
+ log(LOG_KERN | LOG_NOTICE, "Shutting down in response to request"
+ " from %s host\n", dev->dv_xname);
+ prsignal(initprocess, SIGUSR2);
+}
+
+void
+pvbus_reboot(struct device *dev)
+{
+ suspend_randomness();
+
+ log(LOG_KERN | LOG_NOTICE, "Rebooting in response to request"
+ " from %s host\n", dev->dv_xname);
+ prsignal(initprocess, SIGINT);
+}
+
+void
pvbus_kvm(struct pvbus_hv *hv)
{
uint32_t regs[4];
diff --git a/sys/dev/pv/pvvar.h b/sys/dev/pv/pvvar.h
index 4bb30318c28..b4dbf32929a 100644
--- a/sys/dev/pv/pvvar.h
+++ b/sys/dev/pv/pvvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pvvar.h,v 1.8 2016/06/06 17:17:54 mikeb Exp $ */
+/* $OpenBSD: pvvar.h,v 1.9 2017/01/10 17:16:39 reyk Exp $ */
/*
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -77,6 +77,8 @@ struct pv_attach_args {
void pvbus_identify(void);
int pvbus_probe(void);
+void pvbus_reboot(struct device *);
+void pvbus_shutdown(struct device *);
#endif /* _KERNEL */
#endif /* _DEV_PV_PVBUS_H_ */
diff --git a/sys/dev/pv/vmt.c b/sys/dev/pv/vmt.c
index fdd8bce8f38..9ddc31bad65 100644
--- a/sys/dev/pv/vmt.c
+++ b/sys/dev/pv/vmt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vmt.c,v 1.10 2016/10/04 09:59:44 kettenis Exp $ */
+/* $OpenBSD: vmt.c,v 1.11 2017/01/10 17:16:39 reyk Exp $ */
/*
* Copyright (c) 2007 David Crawshaw <david@zentus.com>
@@ -595,12 +595,7 @@ vmt_do_shutdown(struct vmt_softc *sc)
{
vmt_tclo_state_change_success(sc, 1, VM_STATE_CHANGE_HALT);
vm_rpc_send_str(&sc->sc_tclo_rpc, VM_RPC_REPLY_OK);
-
- suspend_randomness();
-
- log(LOG_KERN | LOG_NOTICE,
- "Shutting down in response to request from VMware host\n");
- prsignal(initprocess, SIGUSR2);
+ pvbus_reboot(&sc->sc_dev);
}
void
@@ -608,12 +603,7 @@ vmt_do_reboot(struct vmt_softc *sc)
{
vmt_tclo_state_change_success(sc, 1, VM_STATE_CHANGE_REBOOT);
vm_rpc_send_str(&sc->sc_tclo_rpc, VM_RPC_REPLY_OK);
-
- suspend_randomness();
-
- log(LOG_KERN | LOG_NOTICE,
- "Rebooting in response to request from VMware host\n");
- prsignal(initprocess, SIGINT);
+ pvbus_reboot(&sc->sc_dev);
}
void
diff --git a/sys/dev/pv/xen.c b/sys/dev/pv/xen.c
index c1a05e32816..dbc1d670a17 100644
--- a/sys/dev/pv/xen.c
+++ b/sys/dev/pv/xen.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xen.c,v 1.70 2016/12/21 12:17:15 mikeb Exp $ */
+/* $OpenBSD: xen.c,v 1.71 2017/01/10 17:16:39 reyk Exp $ */
/*
* Copyright (c) 2015 Mike Belopuhov
@@ -223,27 +223,9 @@ xen_control(void *arg)
xs_setprop(sc, "control", "shutdown", "", 0);
if (strcmp(action, "halt") == 0 || strcmp(action, "poweroff") == 0) {
- extern int allowpowerdown;
-
- if (allowpowerdown == 0)
- return;
-
- suspend_randomness();
-
- log(LOG_KERN | LOG_NOTICE, "Shutting down in response to "
- "request from Xen host\n");
- prsignal(initprocess, SIGUSR2);
+ pvbus_shutdown(&sc->sc_dev);
} else if (strcmp(action, "reboot") == 0) {
- extern int allowpowerdown;
-
- if (allowpowerdown == 0)
- return;
-
- suspend_randomness();
-
- log(LOG_KERN | LOG_NOTICE, "Rebooting in response to request "
- "from Xen host\n");
- prsignal(initprocess, SIGINT);
+ pvbus_reboot(&sc->sc_dev);
} else if (strcmp(action, "crash") == 0) {
panic("xen told us to do this");
} else if (strcmp(action, "suspend") == 0) {