From: "Jan Beulich" Subject: [PATCH] Xen watchdog driver Date: Thu, 30 Sep 2010 15:01:06 +0100 Message-ID: <4CA4B4420200007800019CAB@vpn.id2.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part2A07CF32.1__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Jeremy Fitzhardinge Cc: "xen-devel@lists.xensource.com" List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part2A07CF32.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline While the hypervisor change adding SCHEDOP_watchdog support included a daemon to make use of the new functionality, having a kernel driver for /dev/watchdog so that user space code doesn't need to distinguish non-Xen and Xen seems to be preferable. Signed-off-by: Jan Beulich --- drivers/watchdog/Kconfig | 10 + drivers/watchdog/Makefile | 3=20 drivers/watchdog/xen_wdt.c | 359 +++++++++++++++++++++++++++++++++++++= +++++ include/xen/interface/sched.h | 34 +++ 4 files changed, 406 insertions(+) --- linux-2.6.36-rc6/drivers/watchdog/Kconfig +++ 2.6.36-rc6-xen-watchdog/drivers/watchdog/Kconfig @@ -1043,6 +1043,16 @@ config WATCHDOG_RIO =20 # XTENSA Architecture =20 +# Xen Architecture + +config XEN_WDT + tristate "Xen Watchdog support" + depends on XEN + help + Say Y here to support the hypervisor watchdog capability = provided + by Xen 4.0 and newer. The watchdog timeout period is normally = one + minute but can be changed with a boot-time parameter. + # # ISA-based Watchdog Cards # --- linux-2.6.36-rc6/drivers/watchdog/Makefile +++ 2.6.36-rc6-xen-watchdog/drivers/watchdog/Makefile @@ -145,6 +145,9 @@ obj-$(CONFIG_WATCHDOG_CP1XXX) +=3D = cpwd.o =20 # XTENSA Architecture =20 +# Xen +obj-$(CONFIG_XEN_WDT) +=3D xen_wdt.o + # Architecture Independant obj-$(CONFIG_WM831X_WATCHDOG) +=3D wm831x_wdt.o obj-$(CONFIG_WM8350_WATCHDOG) +=3D wm8350_wdt.o --- linux-2.6.36-rc6/drivers/watchdog/xen_wdt.c +++ 2.6.36-rc6-xen-watchdog/drivers/watchdog/xen_wdt.c @@ -0,0 +1,359 @@ +/* + * Xen Watchdog Driver + * + * (c) Copyright 2010 Novell, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#define DRV_NAME "wdt" +#define DRV_VERSION "0.01" +#define PFX DRV_NAME ": " + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct platform_device *platform_device; +static DEFINE_SPINLOCK(wdt_lock); +static struct sched_watchdog wdt; +static __kernel_time_t wdt_expires; +static bool is_active, expect_release; + +#define WATCHDOG_TIMEOUT 60 /* in seconds */ +static unsigned int timeout =3D WATCHDOG_TIMEOUT; +module_param(timeout, uint, S_IRUGO); +MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds " + "(default=3D" __MODULE_STRING(WATCHDOG_TIMEOUT) ")"); + +static bool nowayout =3D WATCHDOG_NOWAYOUT; +module_param(nowayout, bool, S_IRUGO); +MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " + "(default=3D" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); + +static inline __kernel_time_t set_timeout(void) +{ + wdt.timeout =3D timeout; + return ktime_to_timespec(ktime_get()).tv_sec + timeout; +} + +static int xen_wdt_start(void) +{ + __kernel_time_t expires; + int err; + + spin_lock(&wdt_lock); + + expires =3D set_timeout(); + if (!wdt.id) + err =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); + else + err =3D -EBUSY; + if (err > 0) { + wdt.id =3D err; + wdt_expires =3D expires; + err =3D 0; + } else + BUG_ON(!err); + + spin_unlock(&wdt_lock); + + return err; +} + +static int xen_wdt_stop(void) +{ + int err =3D 0; + + spin_lock(&wdt_lock); + + wdt.timeout =3D 0; + if (wdt.id) + err =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); + if (!err) + wdt.id =3D 0; + + spin_unlock(&wdt_lock); + + return err; +} + +static int xen_wdt_kick(void) +{ + __kernel_time_t expires; + int err; + + spin_lock(&wdt_lock); + + expires =3D set_timeout(); + if (wdt.id) + err =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt); + else + err =3D -ENXIO; + if (!err) + wdt_expires =3D expires; + + spin_unlock(&wdt_lock); + + return err; +} + +static int xen_wdt_open(struct inode *inode, struct file *file) +{ + int err; + + /* /dev/watchdog can only be opened once */ + if (xchg(&is_active, true)) + return -EBUSY; + + err =3D xen_wdt_start(); + if (err =3D=3D -EBUSY) + err =3D xen_wdt_kick(); + return err ?: nonseekable_open(inode, file); +} + +static int xen_wdt_release(struct inode *inode, struct file *file) +{ + if (expect_release) + xen_wdt_stop(); + else { + printk(KERN_CRIT PFX + "unexpected close, not stopping watchdog!\n"); + xen_wdt_kick(); + } + is_active =3D false; + expect_release =3D false; + return 0; +} + +static ssize_t xen_wdt_write(struct file *file, const char __user *data, + size_t len, loff_t *ppos) +{ + /* See if we got the magic character 'V' and reload the timer */ + if (len) { + if (!nowayout) { + size_t i; + + /* in case it was set long ago */ + expect_release =3D false; + + /* scan to see whether or not we got the magic + character */ + for (i =3D 0; i !=3D len; i++) { + char c; + if (get_user(c, data + i)) + return -EFAULT; + if (c =3D=3D 'V') + expect_release =3D true; + } + } + + /* someone wrote to us, we should reload the timer */ + xen_wdt_kick(); + } + return len; +} + +static long xen_wdt_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + int new_options, retval =3D -EINVAL; + int new_timeout; + int __user *argp =3D (void __user *)arg; + static const struct watchdog_info ident =3D { + .options =3D WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE= , + .firmware_version =3D 0, + .identity =3D DRV_NAME, + }; + + switch (cmd) { + case WDIOC_GETSUPPORT: + return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT = : 0; + + case WDIOC_GETSTATUS: + case WDIOC_GETBOOTSTATUS: + return put_user(0, argp); + + case WDIOC_SETOPTIONS: + if (get_user(new_options, argp)) + return -EFAULT; + + if (new_options & WDIOS_DISABLECARD) + retval =3D xen_wdt_stop(); + if (new_options & WDIOS_ENABLECARD) { + retval =3D xen_wdt_start(); + if (retval =3D=3D -EBUSY) + retval =3D xen_wdt_kick(); + } + return retval; + + case WDIOC_KEEPALIVE: + xen_wdt_kick(); + return 0; + + case WDIOC_SETTIMEOUT: + if (get_user(new_timeout, argp)) + return -EFAULT; + if (!new_timeout) + return -EINVAL; + timeout =3D new_timeout; + xen_wdt_kick(); + /* fall through */ + case WDIOC_GETTIMEOUT: + return put_user(timeout, argp); + + case WDIOC_GETTIMELEFT: + retval =3D wdt_expires - ktime_to_timespec(ktime_get()).tv_= sec; + return put_user(retval, argp); + } + + return -ENOTTY; +} + +static const struct file_operations xen_wdt_fops =3D { + .owner =3D THIS_MODULE, + .llseek =3D no_llseek, + .write =3D xen_wdt_write, + .unlocked_ioctl =3D xen_wdt_ioctl, + .open =3D xen_wdt_open, + .release =3D xen_wdt_release, +}; + +static struct miscdevice xen_wdt_miscdev =3D { + .minor =3D WATCHDOG_MINOR, + .name =3D "watchdog", + .fops =3D &xen_wdt_fops, +}; + +static int __devinit xen_wdt_probe(struct platform_device *dev) +{ + struct sched_watchdog wd =3D { .id =3D ~0 }; + int ret =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, &wd); + + switch (ret) { + case -EINVAL: + if (!timeout) { + timeout =3D WATCHDOG_TIMEOUT; + printk(KERN_INFO PFX + "timeout value invalid, using %d\n", = timeout); + } + + ret =3D misc_register(&xen_wdt_miscdev); + if (ret) { + printk(KERN_ERR PFX + "cannot register miscdev on minor=3D%d = (%d)\n", + WATCHDOG_MINOR, ret); + break; + } + + printk(KERN_INFO PFX + "initialized (timeout=3D%ds, nowayout=3D%d)\n", + timeout, nowayout); + break; + + case -ENOSYS: + printk(KERN_INFO PFX "not supported\n"); + ret =3D -ENODEV; + break; + + default: + printk(KERN_INFO PFX "bogus return value %d\n", ret); + break; + } + + return ret; +} + +static int __devexit xen_wdt_remove(struct platform_device *dev) +{ + /* Stop the timer before we leave */ + if (!nowayout) + xen_wdt_stop(); + + misc_deregister(&xen_wdt_miscdev); + + return 0; +} + +static void xen_wdt_shutdown(struct platform_device *dev) +{ + xen_wdt_stop(); +} + +static int xen_wdt_suspend(struct platform_device *dev, pm_message_t = state) +{ + return xen_wdt_stop(); +} + +static int xen_wdt_resume(struct platform_device *dev) +{ + return xen_wdt_start(); +} + +static struct platform_driver xen_wdt_driver =3D { + .probe =3D xen_wdt_probe, + .remove =3D __devexit_p(xen_wdt_remove), + .shutdown =3D xen_wdt_shutdown, + .suspend =3D xen_wdt_suspend, + .resume =3D xen_wdt_resume, + .driver =3D { + .owner =3D THIS_MODULE, + .name =3D DRV_NAME, + }, +}; + +static int __init xen_wdt_init_module(void) +{ + int err; + + if (!xen_domain()) + return -ENODEV; + + printk(KERN_INFO PFX "Xen WatchDog Timer Driver v%s\n", DRV_VERSION= ); + + err =3D platform_driver_register(&xen_wdt_driver); + if (err) + return err; + + platform_device =3D platform_device_register_simple(DRV_NAME, + -1, = NULL, 0); + if (IS_ERR(platform_device)) { + err =3D PTR_ERR(platform_device); + platform_driver_unregister(&xen_wdt_driver); + } + + return err; +} + +static void __exit xen_wdt_cleanup_module(void) +{ + platform_device_unregister(platform_device); + platform_driver_unregister(&xen_wdt_driver); + printk(KERN_INFO PFX "module unloaded\n"); +} + +module_init(xen_wdt_init_module); +module_exit(xen_wdt_cleanup_module); + +MODULE_AUTHOR("Jen Beulich "); +MODULE_DESCRIPTION("Xen WatchDog Timer Driver"); +MODULE_VERSION(DRV_VERSION); +MODULE_LICENSE("GPL"); +MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR); --- linux-2.6.36-rc6/include/xen/interface/sched.h +++ 2.6.36-rc6-xen-watchdog/include/xen/interface/sched.h @@ -65,6 +65,39 @@ struct sched_poll { DEFINE_GUEST_HANDLE_STRUCT(sched_poll); =20 /* + * Declare a shutdown for another domain. The main use of this function = is + * in interpreting shutdown requests and reasons for fully-virtualized + * domains. A para-virtualized domain may use SCHEDOP_shutdown directly. + * @arg =3D=3D pointer to sched_remote_shutdown structure. + */ +#define SCHEDOP_remote_shutdown 4 +struct sched_remote_shutdown { + domid_t domain_id; /* Remote domain ID */ + unsigned int reason; /* SHUTDOWN_xxx reason */ +}; + +/* + * Latch a shutdown code, so that when the domain later shuts down it + * reports this code to the control tools. + * @arg =3D=3D as for SCHEDOP_shutdown. + */ +#define SCHEDOP_shutdown_code 5 + +/* + * Setup, poke and destroy a domain watchdog timer. + * @arg =3D=3D pointer to sched_watchdog structure. + * With id =3D=3D 0, setup a domain watchdog timer to cause domain = shutdown + * after timeout, returns watchdog id. + * With id !=3D 0 and timeout =3D=3D 0, destroy domain watchdog timer. + * With id !=3D 0 and timeout !=3D 0, poke watchdog timer and set new = timeout. + */ +#define SCHEDOP_watchdog 6 +struct sched_watchdog { + uint32_t id; /* watchdog ID */ + uint32_t timeout; /* timeout */ +}; + +/* * Reason codes for SCHEDOP_shutdown. These may be interpreted by control * software to determine the appropriate action. For the most part, Xen = does * not care about the shutdown code. @@ -73,5 +106,6 @@ DEFINE_GUEST_HANDLE_STRUCT(sched_poll); #define SHUTDOWN_reboot 1 /* Clean up, kill, and then restart. = */ #define SHUTDOWN_suspend 2 /* Clean up, save suspend info, kill. = */ #define SHUTDOWN_crash 3 /* Tell controller we've crashed. = */ +#define SHUTDOWN_watchdog 4 /* Restart because watchdog time expired. = */ =20 #endif /* __XEN_PUBLIC_SCHED_H__ */ --=__Part2A07CF32.1__= Content-Type: text/plain; name="linux-2.6.36-rc6-xen-watchdog.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="linux-2.6.36-rc6-xen-watchdog.patch" While the hypervisor change adding SCHEDOP_watchdog support included = a=0Adaemon to make use of the new functionality, having a kernel driver=0Af= or /dev/watchdog so that user space code doesn't need to distinguish=0Anon-= Xen and Xen seems to be preferable.=0A=0ASigned-off-by: Jan Beulich = =0A=0A---=0A drivers/watchdog/Kconfig | 10 = +=0A drivers/watchdog/Makefile | 3 =0A drivers/watchdog/xen_wdt.c = | 359 ++++++++++++++++++++++++++++++++++++++++++=0A include/xen/interface= /sched.h | 34 +++=0A 4 files changed, 406 insertions(+)=0A=0A--- = linux-2.6.36-rc6/drivers/watchdog/Kconfig=0A+++ 2.6.36-rc6-xen-watchdog/dri= vers/watchdog/Kconfig=0A@@ -1043,6 +1043,16 @@ config WATCHDOG_RIO=0A =0A = # XTENSA Architecture=0A =0A+# Xen Architecture=0A+=0A+config XEN_WDT=0A+ = tristate "Xen Watchdog support"=0A+ depends on XEN=0A+ help=0A+ = Say Y here to support the hypervisor watchdog capability provided=0A+ = by Xen 4.0 and newer. The watchdog timeout period is normally one=0A+ = minute but can be changed with a boot-time parameter.=0A+=0A #=0A # = ISA-based Watchdog Cards=0A #=0A--- linux-2.6.36-rc6/drivers/watchdog/Makef= ile=0A+++ 2.6.36-rc6-xen-watchdog/drivers/watchdog/Makefile=0A@@ -145,6 = +145,9 @@ obj-$(CONFIG_WATCHDOG_CP1XXX) +=3D cpwd.o=0A =0A # = XTENSA Architecture=0A =0A+# Xen=0A+obj-$(CONFIG_XEN_WDT) +=3D xen_wdt.o=0A= +=0A # Architecture Independant=0A obj-$(CONFIG_WM831X_WATCHDOG) +=3D = wm831x_wdt.o=0A obj-$(CONFIG_WM8350_WATCHDOG) +=3D wm8350_wdt.o=0A--- = linux-2.6.36-rc6/drivers/watchdog/xen_wdt.c=0A+++ 2.6.36-rc6-xen-watchdog/d= rivers/watchdog/xen_wdt.c=0A@@ -0,0 +1,359 @@=0A+/*=0A+ * Xen = Watchdog Driver=0A+ *=0A+ * (c) Copyright 2010 Novell, Inc.=0A+ *=0A+ = * This program is free software; you can redistribute it and/or=0A+ = * modify it under the terms of the GNU General Public License=0A+ * = as published by the Free Software Foundation; either version=0A+ * 2 = of the License, or (at your option) any later version.=0A+ */=0A+=0A+#defin= e DRV_NAME "wdt"=0A+#define DRV_VERSION "0.01"=0A+#define PFX = DRV_NAME ": "=0A+=0A+#include =0A+#include =0A+= #include =0A+#include =0A+#include =0A+#include =0A+#include =0A+#include = =0A+#include =0A+#include =0A+#include =0A+#include =0A+#include =0A+#include =0A+#include= =0A+#include =0A+#include =0A+=0A+static struct platform_device *platform_device;=0A+static = DEFINE_SPINLOCK(wdt_lock);=0A+static struct sched_watchdog wdt;=0A+static = __kernel_time_t wdt_expires;=0A+static bool is_active, expect_release;=0A+= =0A+#define WATCHDOG_TIMEOUT 60 /* in seconds */=0A+static unsigned int = timeout =3D WATCHDOG_TIMEOUT;=0A+module_param(timeout, uint, S_IRUGO);=0A+M= ODULE_PARM_DESC(timeout, "Watchdog timeout in seconds "=0A+ = "(default=3D" __MODULE_STRING(WATCHDOG_TIMEOUT) ")");=0A+=0A+static bool = nowayout =3D WATCHDOG_NOWAYOUT;=0A+module_param(nowayout, bool, = S_IRUGO);=0A+MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once = started "=0A+ "(default=3D" __MODULE_STRING(WATCHDOG_NOWAYOUT) = ")");=0A+=0A+static inline __kernel_time_t set_timeout(void)=0A+{=0A+ = wdt.timeout =3D timeout;=0A+ return ktime_to_timespec(ktime_get()).tv_se= c + timeout;=0A+}=0A+=0A+static int xen_wdt_start(void)=0A+{=0A+ = __kernel_time_t expires;=0A+ int err;=0A+=0A+ spin_lock(&wdt_lock= );=0A+=0A+ expires =3D set_timeout();=0A+ if (!wdt.id)=0A+ = err =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, &wdt);=0A+ else=0A+ = err =3D -EBUSY;=0A+ if (err > 0) {=0A+ wdt.id =3D = err;=0A+ wdt_expires =3D expires;=0A+ err =3D = 0;=0A+ } else=0A+ BUG_ON(!err);=0A+=0A+ spin_unlock(&wdt_lo= ck);=0A+=0A+ return err;=0A+}=0A+=0A+static int xen_wdt_stop(void)=0A+{= =0A+ int err =3D 0;=0A+=0A+ spin_lock(&wdt_lock);=0A+=0A+ wdt.timeout= =3D 0;=0A+ if (wdt.id)=0A+ err =3D HYPERVISOR_sched_op(SCHEDOP= _watchdog, &wdt);=0A+ if (!err)=0A+ wdt.id =3D 0;=0A+=0A+ = spin_unlock(&wdt_lock);=0A+=0A+ return err;=0A+}=0A+=0A+static int = xen_wdt_kick(void)=0A+{=0A+ __kernel_time_t expires;=0A+ int = err;=0A+=0A+ spin_lock(&wdt_lock);=0A+=0A+ expires =3D set_timeout();= =0A+ if (wdt.id)=0A+ err =3D HYPERVISOR_sched_op(SCHEDOP_watchdo= g, &wdt);=0A+ else=0A+ err =3D -ENXIO;=0A+ if = (!err)=0A+ wdt_expires =3D expires;=0A+=0A+ spin_unlock= (&wdt_lock);=0A+=0A+ return err;=0A+}=0A+=0A+static int xen_wdt_open(str= uct inode *inode, struct file *file)=0A+{=0A+ int err;=0A+=0A+ /* = /dev/watchdog can only be opened once */=0A+ if (xchg(&is_active, = true))=0A+ return -EBUSY;=0A+=0A+ err =3D xen_wdt_start();=0A= + if (err =3D=3D -EBUSY)=0A+ err =3D xen_wdt_kick();=0A+= return err ?: nonseekable_open(inode, file);=0A+}=0A+=0A+static = int xen_wdt_release(struct inode *inode, struct file *file)=0A+{=0A+ if = (expect_release)=0A+ xen_wdt_stop();=0A+ else {=0A+ = printk(KERN_CRIT PFX=0A+ "unexpected close, not = stopping watchdog!\n");=0A+ xen_wdt_kick();=0A+ }=0A+ = is_active =3D false;=0A+ expect_release =3D false;=0A+ return = 0;=0A+}=0A+=0A+static ssize_t xen_wdt_write(struct file *file, const char = __user *data,=0A+ size_t len, loff_t *ppos)=0A+{= =0A+ /* See if we got the magic character 'V' and reload the timer = */=0A+ if (len) {=0A+ if (!nowayout) {=0A+ = size_t i;=0A+=0A+ /* in case it was set long ago = */=0A+ expect_release =3D false;=0A+=0A+ = /* scan to see whether or not we got the magic=0A+ = character */=0A+ for (i =3D 0; i !=3D len; i++) = {=0A+ char c;=0A+ if = (get_user(c, data + i))=0A+ return = -EFAULT;=0A+ if (c =3D=3D 'V')=0A+ = expect_release =3D true;=0A+ }=0A+ = }=0A+=0A+ /* someone wrote to us, we should reload the timer = */=0A+ xen_wdt_kick();=0A+ }=0A+ return len;=0A+}=0A+=0A+sta= tic long xen_wdt_ioctl(struct file *file, unsigned int cmd,=0A+ = unsigned long arg)=0A+{=0A+ int new_options, retval =3D -EINVAL;=0A+ = int new_timeout;=0A+ int __user *argp =3D (void __user *)arg;=0A+ = static const struct watchdog_info ident =3D {=0A+ .options = =3D WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE,=0A+ = .firmware_version =3D 0,=0A+ .identity =3D = DRV_NAME,=0A+ };=0A+=0A+ switch (cmd) {=0A+ case WDIOC_GETSUPPO= RT:=0A+ return copy_to_user(argp, &ident, sizeof(ident)) ? -EFAULT = : 0;=0A+=0A+ case WDIOC_GETSTATUS:=0A+ case WDIOC_GETBOOTSTATUS:= =0A+ return put_user(0, argp);=0A+=0A+ case WDIOC_SETOPTIO= NS:=0A+ if (get_user(new_options, argp))=0A+ = return -EFAULT;=0A+=0A+ if (new_options & WDIOS_DISABLECARD)=0A+ = retval =3D xen_wdt_stop();=0A+ if (new_options & = WDIOS_ENABLECARD) {=0A+ retval =3D xen_wdt_start();=0A+ = if (retval =3D=3D -EBUSY)=0A+ retval =3D = xen_wdt_kick();=0A+ }=0A+ return retval;=0A+=0A+ = case WDIOC_KEEPALIVE:=0A+ xen_wdt_kick();=0A+ = return 0;=0A+=0A+ case WDIOC_SETTIMEOUT:=0A+ if = (get_user(new_timeout, argp))=0A+ return -EFAULT;=0A+= if (!new_timeout)=0A+ return -EINVAL;=0A+= timeout =3D new_timeout;=0A+ xen_wdt_kick();=0A+= /* fall through */=0A+ case WDIOC_GETTIMEOUT:=0A+ = return put_user(timeout, argp);=0A+=0A+ case WDIOC_GETTIMELEFT:=0A+ = retval =3D wdt_expires - ktime_to_timespec(ktime_get()).tv_sec;=0A+ = return put_user(retval, argp);=0A+ }=0A+=0A+ return -ENOTTY;=0A+= }=0A+=0A+static const struct file_operations xen_wdt_fops =3D {=0A+ = .owner =3D THIS_MODULE,=0A+ .llseek =3D = no_llseek,=0A+ .write =3D xen_wdt_write,=0A+ .unlocked_i= octl =3D xen_wdt_ioctl,=0A+ .open =3D = xen_wdt_open,=0A+ .release =3D xen_wdt_release,=0A+};=0A+= =0A+static struct miscdevice xen_wdt_miscdev =3D {=0A+ .minor =3D = WATCHDOG_MINOR,=0A+ .name =3D "watchdog",=0A+ .fops =3D = &xen_wdt_fops,=0A+};=0A+=0A+static int __devinit xen_wdt_probe(stru= ct platform_device *dev)=0A+{=0A+ struct sched_watchdog wd =3D { .id = =3D ~0 };=0A+ int ret =3D HYPERVISOR_sched_op(SCHEDOP_watchdog, = &wd);=0A+=0A+ switch (ret) {=0A+ case -EINVAL:=0A+ if = (!timeout) {=0A+ timeout =3D WATCHDOG_TIMEOUT;=0A+ = printk(KERN_INFO PFX=0A+ = "timeout value invalid, using %d\n", timeout);=0A+ }=0A+=0A+ = ret =3D misc_register(&xen_wdt_miscdev);=0A+ if (ret) = {=0A+ printk(KERN_ERR PFX=0A+ = "cannot register miscdev on minor=3D%d (%d)\n",=0A+ = WATCHDOG_MINOR, ret);=0A+ break;=0A+ = }=0A+=0A+ printk(KERN_INFO PFX=0A+ = "initialized (timeout=3D%ds, nowayout=3D%d)\n",=0A+ = timeout, nowayout);=0A+ break;=0A+=0A+ case -ENOSYS:=0A+ = printk(KERN_INFO PFX "not supported\n");=0A+ ret =3D -ENODEV;=0A= + break;=0A+=0A+ default:=0A+ printk(KERN_INFO = PFX "bogus return value %d\n", ret);=0A+ break;=0A+ = }=0A+=0A+ return ret;=0A+}=0A+=0A+static int __devexit xen_wdt_remove= (struct platform_device *dev)=0A+{=0A+ /* Stop the timer before we leave = */=0A+ if (!nowayout)=0A+ xen_wdt_stop();=0A+=0A+ misc_deregi= ster(&xen_wdt_miscdev);=0A+=0A+ return 0;=0A+}=0A+=0A+static void = xen_wdt_shutdown(struct platform_device *dev)=0A+{=0A+ xen_wdt_stop();=0A+= }=0A+=0A+static int xen_wdt_suspend(struct platform_device *dev, pm_message= _t state)=0A+{=0A+ return xen_wdt_stop();=0A+}=0A+=0A+static int = xen_wdt_resume(struct platform_device *dev)=0A+{=0A+ return xen_wdt_star= t();=0A+}=0A+=0A+static struct platform_driver xen_wdt_driver =3D {=0A+ = .probe =3D xen_wdt_probe,=0A+ .remove =3D __devexit_p(xen= _wdt_remove),=0A+ .shutdown =3D xen_wdt_shutdown,=0A+ = .suspend =3D xen_wdt_suspend,=0A+ .resume =3D = xen_wdt_resume,=0A+ .driver =3D {=0A+ .owner = =3D THIS_MODULE,=0A+ .name =3D DRV_NAME,=0A+ },=0A+};=0A= +=0A+static int __init xen_wdt_init_module(void)=0A+{=0A+ int = err;=0A+=0A+ if (!xen_domain())=0A+ return -ENODEV;=0A+=0A+ = printk(KERN_INFO PFX "Xen WatchDog Timer Driver v%s\n", DRV_VERSION);=0A+= =0A+ err =3D platform_driver_register(&xen_wdt_driver);=0A+ if = (err)=0A+ return err;=0A+=0A+ platform_device =3D = platform_device_register_simple(DRV_NAME,=0A+ = -1, NULL, 0);=0A+ if (IS_ERR(platform_device)= ) {=0A+ err =3D PTR_ERR(platform_device);=0A+ platform_dr= iver_unregister(&xen_wdt_driver);=0A+ }=0A+=0A+ return err;=0A+}=0A= +=0A+static void __exit xen_wdt_cleanup_module(void)=0A+{=0A+ platform_de= vice_unregister(platform_device);=0A+ platform_driver_unregister(&xen_wdt= _driver);=0A+ printk(KERN_INFO PFX "module unloaded\n");=0A+}=0A+=0A+modu= le_init(xen_wdt_init_module);=0A+module_exit(xen_wdt_cleanup_module);=0A+= =0A+MODULE_AUTHOR("Jen Beulich ");=0A+MODULE_DESCRIPTI= ON("Xen WatchDog Timer Driver");=0A+MODULE_VERSION(DRV_VERSION);=0A+MODULE_= LICENSE("GPL");=0A+MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);=0A--- linux-2.6.36= -rc6/include/xen/interface/sched.h=0A+++ 2.6.36-rc6-xen-watchdog/include/xe= n/interface/sched.h=0A@@ -65,6 +65,39 @@ struct sched_poll {=0A DEFINE_GUES= T_HANDLE_STRUCT(sched_poll);=0A =0A /*=0A+ * Declare a shutdown for = another domain. The main use of this function is=0A+ * in interpreting = shutdown requests and reasons for fully-virtualized=0A+ * domains. A = para-virtualized domain may use SCHEDOP_shutdown directly.=0A+ * @arg = =3D=3D pointer to sched_remote_shutdown structure.=0A+ */=0A+#define = SCHEDOP_remote_shutdown 4=0A+struct sched_remote_shutdown {=0A+ = domid_t domain_id; /* Remote domain ID */=0A+ unsigned int = reason; /* SHUTDOWN_xxx reason */=0A+};=0A+=0A+/*=0A+ * Latch a = shutdown code, so that when the domain later shuts down it=0A+ * reports = this code to the control tools.=0A+ * @arg =3D=3D as for SCHEDOP_shutdown.= =0A+ */=0A+#define SCHEDOP_shutdown_code 5=0A+=0A+/*=0A+ * Setup, poke and = destroy a domain watchdog timer.=0A+ * @arg =3D=3D pointer to sched_watchdo= g structure.=0A+ * With id =3D=3D 0, setup a domain watchdog timer to = cause domain shutdown=0A+ * after timeout, returns watchdog = id.=0A+ * With id !=3D 0 and timeout =3D=3D 0, destroy domain watchdog = timer.=0A+ * With id !=3D 0 and timeout !=3D 0, poke watchdog timer and = set new timeout.=0A+ */=0A+#define SCHEDOP_watchdog 6=0A+struct = sched_watchdog {=0A+ uint32_t id; /* watchdog ID */=0A+ = uint32_t timeout; /* timeout */=0A+};=0A+=0A+/*=0A * Reason = codes for SCHEDOP_shutdown. These may be interpreted by control=0A * = software to determine the appropriate action. For the most part, Xen = does=0A * not care about the shutdown code.=0A@@ -73,5 +106,6 @@ = DEFINE_GUEST_HANDLE_STRUCT(sched_poll);=0A #define SHUTDOWN_reboot 1 = /* Clean up, kill, and then restart. */=0A #define SHUTDOWN_suspen= d 2 /* Clean up, save suspend info, kill. */=0A #define = SHUTDOWN_crash 3 /* Tell controller we've crashed. = */=0A+#define SHUTDOWN_watchdog 4 /* Restart because watchdog time = expired. */=0A =0A #endif /* __XEN_PUBLIC_SCHED_H__ */=0A --=__Part2A07CF32.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --=__Part2A07CF32.1__=--