From: Mark Williamson Subject: [RFC] Xen paravirtual watchdog device [2/4] Date: Fri, 1 Jun 2007 04:48:13 +0100 Message-ID: <200706010448.13778.mark.williamson@cl.cam.ac.uk> References: <200706010444.29583.mark.williamson@cl.cam.ac.uk> Mime-Version: 1.0 Content-Type: Multipart/Mixed; boundary="Boundary-00=_9b5XGpIsf5ssFX7" Return-path: In-Reply-To: <200706010444.29583.mark.williamson@cl.cam.ac.uk> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org --Boundary-00=_9b5XGpIsf5ssFX7 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline XenLinux driver for Xen virtual watchdog device. This is based on the Linux softdog driver, but features slightly more functionality and omits all the internal timer logic since it has moved to Xen. Cheers, Mark -- Dave: Just a question. What use is a unicyle with no seat? And no pedals! Mark: To answer a question with a question: What use is a skateboard? Dave: Skateboards have wheels. Mark: My wheel has a wheel! --Boundary-00=_9b5XGpIsf5ssFX7 Content-Type: all/allfiles; name="watchdog2-linux.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="watchdog2-linux.patch" --- xen-incoming.hg/linux-2.6-xen-sparse/drivers/xen/Makefile 2007-03-31 23:00:06.000000000 +0100 +++ xen-watchdog-ref.hg/linux-2.6-xen-sparse/drivers/xen/Makefile 2007-06-01 04:23:01.000000000 +0100 @@ -18,3 +18,4 @@ obj-$(CONFIG_XEN_PCIDEV_BACKEND) += pcib obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += pcifront/ obj-$(CONFIG_XEN_FRAMEBUFFER) += fbfront/ obj-$(CONFIG_XEN_KEYBOARD) += fbfront/ +obj-$(CONFIG_XEN_WATCHDOG) += watchdog/ diff --exclude=.hg -rupN xen-incoming.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/Makefile xen-watchdog-ref.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/Makefile --- xen-incoming.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/Makefile 1970-01-01 01:00:00.000000000 +0100 +++ xen-watchdog-ref.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/Makefile 2007-06-01 04:23:01.000000000 +0100 @@ -0,0 +1 @@ +obj-$(CONFIG_XEN_WATCHDOG) := xen_watchdog.o diff --exclude=.hg -rupN xen-incoming.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/xen_watchdog.c xen-watchdog-ref.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/xen_watchdog.c --- xen-incoming.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/xen_watchdog.c 1970-01-01 01:00:00.000000000 +0100 +++ xen-watchdog-ref.hg/linux-2.6-xen-sparse/drivers/xen/watchdog/xen_watchdog.c 2007-06-01 04:23:01.000000000 +0100 @@ -0,0 +1,409 @@ +/* Xen watchdog. Mercilessly bodged from the Linux Softdog device by Mark + * Williamson . Original notices displayed + * below. Enjoy.*/ + +/* + * SoftDog 0.07: A Software Watchdog Device + * + * (c) Copyright 1996 Alan Cox , All Rights Reserved. + * http://www.redhat.com + * + * 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. + * + * Neither Alan Cox nor CymruNet Ltd. admit liability nor provide + * warranty for any of this software. This material is provided + * "AS-IS" and at no charge. + * + * (c) Copyright 1995 Alan Cox + * + * Software only watchdog driver. Unlike its big brother the WDT501P + * driver this won't always recover a failed machine. + * + * 03/96: Angelo Haritsis : + * Modularised. + * Added soft_margin; use upon insmod to change the timer delay. + * NB: uses same minor as wdt (WATCHDOG_MINOR); we could use separate + * minors. + * + * 19980911 Alan Cox + * Made SMP safe for 2.3.x + * + * 20011127 Joel Becker (jlbec@evilplan.org> + * Added soft_noboot; Allows testing the softdog trigger without + * requiring a recompile. + * Added WDIOC_GETTIMEOUT and WDIOC_SETTIMOUT. + * + * 20020530 Joel Becker + * Added Matt Domsch's nowayout module option. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#define PFX "Xen Watchdog: " + +#define TIMER_MARGIN 60 /* Default is 60 seconds */ +static int soft_margin = TIMER_MARGIN; /* in seconds */ +module_param(soft_margin, int, 0); +MODULE_PARM_DESC(soft_margin, "Watchdog soft_margin in seconds. (0options = ( WDIOF_SETTIMEOUT | + WDIOF_KEEPALIVEPING | + WDIOF_MAGICCLOSE ); + + op.domid = DOMID_SELF; + + ret = HYPERVISOR_watchdog_op(XEN_WATCHDOG_CMD_QUERY, &op); + + if (ret < 0) + return ret; + + if (op.features & XEN_WATCHDOG_LASTBOOT) + i->options |= WDIOF_CARDRESET; + + return 0; + +} + +static int setoptions(int __user *uopt) +{ + int ret; + int opt; + + ret = get_user(opt, uopt); + + if (ret != 0) + return ret; + + if ((opt & WDIOS_DISABLECARD) && (opt & WDIOS_ENABLECARD)) + return -EINVAL; + + ret = -EINVAL; /* Return this if we understand none of the options. */ + + if (opt & WDIOS_DISABLECARD) { + softdog_stop(); + ret = 0; + } + if (opt & WDIOS_ENABLECARD) { + softdog_keepalive(); + ret = 0; + } + + return ret; +} + +static int softdog_ioctl(struct inode *inode, struct file *file, + unsigned int cmd, unsigned long arg) +{ + void __user *argp = (void __user *)arg; + int __user *p = argp; + int new_margin; + + switch (cmd) { + default: + return -ENOIOCTLCMD; + case WDIOC_GETSUPPORT: + return copy_to_user(argp, &ident, + sizeof(ident)) ? -EFAULT : 0; + case WDIOC_GETSTATUS: + return put_user(0, p); + case WDIOC_GETBOOTSTATUS: + return getbootstatus(p); + case WDIOC_KEEPALIVE: + softdog_keepalive(); + return 0; + case WDIOC_SETOPTIONS: + return setoptions(p); + case WDIOC_SETTIMEOUT: + printk("Trying to set new timeout\n"); + if (get_user(new_margin, p)) { + printk("failed to get a new timeout!\n"); + return -EFAULT; + } + if (softdog_set_heartbeat(new_margin)) { + printk("failed to activate new timeout!\n"); + return -EINVAL; + } + /* Fall */ + case WDIOC_GETTIMEOUT: + return put_user(soft_margin, p); + } +} + +/* + * Notifier for system down + */ + +static int softdog_notify_sys(struct notifier_block *this, unsigned long code, + void *unused) +{ + if(code==SYS_DOWN || code==SYS_HALT) { + /* Turn the WDT off */ + softdog_stop(); + } + return NOTIFY_DONE; +} + +/* + * Kernel Interfaces + */ + +static struct file_operations softdog_fops = { + .owner = THIS_MODULE, + .llseek = no_llseek, + .write = softdog_write, + .ioctl = softdog_ioctl, + .open = softdog_open, + .release = softdog_release, +}; + +static struct miscdevice softdog_miscdev = { + .minor = WATCHDOG_MINOR, + .name = "watchdog", + .fops = &softdog_fops, +}; + +static struct notifier_block softdog_notifier = { + .notifier_call = softdog_notify_sys, +}; + +static char banner[] __initdata = KERN_INFO "Xen Watchdog Timer: initialized. soft_margin=%d sec (nowayout= %d)\n"; + +static int __init watchdog_init(void) +{ + int ret; + + /* Check that the soft_margin value is within it's range ; if not reset to the default */ + if (softdog_set_heartbeat(soft_margin)) { + softdog_set_heartbeat(TIMER_MARGIN); + printk(KERN_INFO PFX "soft_margin value must be 0 #include #include +#include #include #include #if defined(__i386__) --Boundary-00=_9b5XGpIsf5ssFX7 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 --Boundary-00=_9b5XGpIsf5ssFX7--