mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 6/10 v2] Generic Watchdog Timer Driver
@ 2011-06-18 17:24 Wim Van Sebroeck
  2011-06-18 19:05 ` Arnd Bergmann
  0 siblings, 1 reply; 2+ messages in thread
From: Wim Van Sebroeck @ 2011-06-18 17:24 UTC (permalink / raw)
  To: LKML, Linux Watchdog Mailing List; +Cc: Alan Cox

watchdog: WatchDog Timer Driver Core - Part 6

Add support for the Magic Close feature to the
WatchDog Timer Driver Core framework.

Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

diff -urN linux-2.6.38-generic-part5/Documentation/watchdog/src/watchdog-with-timer-example.c linux-2.6.38-generic-part6/Documentation/watchdog/src/watchdog-with-timer-example.c
--- linux-2.6.38-generic-part5/Documentation/watchdog/src/watchdog-with-timer-example.c	2011-06-16 20:13:58.331178125 +0200
+++ linux-2.6.38-generic-part6/Documentation/watchdog/src/watchdog-with-timer-example.c	2011-06-16 21:04:06.283940741 +0200
@@ -123,6 +123,7 @@
 static const struct watchdog_info wdt_info = {
 	.identity =	DRV_NAME,
 	.options =	WDIOF_SETTIMEOUT |
+			WDIOF_MAGICCLOSE |
 			WDIOF_KEEPALIVEPING,
 };
 
diff -urN linux-2.6.38-generic-part5/Documentation/watchdog/watchdog-kernel-api.txt linux-2.6.38-generic-part6/Documentation/watchdog/watchdog-kernel-api.txt
--- linux-2.6.38-generic-part5/Documentation/watchdog/watchdog-kernel-api.txt	2011-06-16 20:09:01.759178229 +0200
+++ linux-2.6.38-generic-part6/Documentation/watchdog/watchdog-kernel-api.txt	2011-06-16 21:04:06.287940722 +0200
@@ -126,3 +126,10 @@
 * WDOG_DEV_OPEN: this status bit shows whether or not the watchdog device
   was opened via /dev/watchdog.
   (This bit should only be used by the WatchDog Timer Driver Core).
+* WDOG_EXPECT_RELEASE: this bit stores whether or not the magic close character
+  has been sent (so that we can support the magic close feature).
+  (This bit should only be used by the WatchDog Timer Driver Core).
+
+Note: The WatchDog Timer Driver Core supports the magic close feature. To use
+the magic close feature you must set the WDIOF_MAGICCLOSE bit in the options
+field of the watchdog's info structure.
diff -urN linux-2.6.38-generic-part5/drivers/watchdog/core/watchdog_dev.c linux-2.6.38-generic-part6/drivers/watchdog/core/watchdog_dev.c
--- linux-2.6.38-generic-part5/drivers/watchdog/core/watchdog_dev.c	2011-06-16 20:09:01.759178229 +0200
+++ linux-2.6.38-generic-part6/drivers/watchdog/core/watchdog_dev.c	2011-06-16 22:52:56.763937624 +0200
@@ -150,6 +150,8 @@
  *	@ppos: pointer to the file offset
  *
  *	A write to a watchdog device is defined as a keepalive ping.
+ *	Writing the magic 'V' sequence allows the next close to turn
+ *	off the watchdog.
  */
 
 static ssize_t watchdog_write(struct file *file, const char __user *data,
@@ -163,9 +165,18 @@
 	if (len == 0)	/* Can we see this even ? */
 		return 0;
 
+	/* note: just in case someone wrote the magic character
+	 * five months ago... */
+	clear_bit(WDOG_EXPECT_RELEASE, &wdd->status);
+
+	/* scan to see whether or not we got the magic character */
 	for (i = 0; i != len; i++) {
 		if (get_user(c, data + i))
 			return -EFAULT;
+		if (c == 'V') {
+			set_bit(WDOG_EXPECT_RELEASE, &wdd->status);
+			dbg("received the magic character");
+		}
 	}
 
 	/* someone wrote to us, so we sent the watchdog a keepalive ping */
@@ -294,7 +305,9 @@
  *      @inode: inode of device
  *      @file: file handle to device
  *
- *	This is the code for when /dev/watchdog get's closed.
+ *	This is the code for when /dev/watchdog get's closed. We will only
+ *	stop the watchdog when we have received the magic char, else the
+ *	watchdog will keep running.
  */
 
 static int watchdog_release(struct inode *inode, struct file *file)
@@ -302,9 +315,15 @@
 	int err = -1;
 
 	trace("%p, %p", inode, file);
+	dbg("expect_release=%d", test_bit(WDOG_EXPECT_RELEASE, &wdd->status));
+
+	/* We only stop the watchdog if we received the magic character
+	 * or if WDIOF_MAGICCLOSE is not set */
+	if (test_and_clear_bit(WDOG_EXPECT_RELEASE, &wdd->status) ||
+	    !(wdd->info->options & WDIOF_MAGICCLOSE))
+		err = watchdog_stop(wdd);
 
-	/* stop the watchdog */
-	err = watchdog_stop(wdd);
+	/* If the watchdog was not stopped, sent a keepalive ping */
 	if (err < 0) {
 		pr_crit("%s: not stopping watchdog!\n", wdd->name);
 		watchdog_ping(wdd);
diff -urN linux-2.6.38-generic-part5/include/linux/watchdog.h linux-2.6.38-generic-part6/include/linux/watchdog.h
--- linux-2.6.38-generic-part5/include/linux/watchdog.h	2011-06-16 20:09:01.759178229 +0200
+++ linux-2.6.38-generic-part6/include/linux/watchdog.h	2011-06-17 12:17:15.285063678 +0200
@@ -85,6 +85,7 @@
 #define WDOG_ACTIVE		0	/* is the watchdog running/active */
 #define WDOG_DEV_OPEN		1	/* is the watchdog opened via
 					 * /dev/watchdog */
+#define WDOG_EXPECT_RELEASE	2	/* did we receive the magic char ? */
 };
 
 /* drivers/watchdog/core/watchdog_core.c */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 6/10 v2] Generic Watchdog Timer Driver
  2011-06-18 17:24 [PATCH 6/10 v2] Generic Watchdog Timer Driver Wim Van Sebroeck
@ 2011-06-18 19:05 ` Arnd Bergmann
  0 siblings, 0 replies; 2+ messages in thread
From: Arnd Bergmann @ 2011-06-18 19:05 UTC (permalink / raw)
  To: Wim Van Sebroeck; +Cc: LKML, Linux Watchdog Mailing List, Alan Cox

On Saturday 18 June 2011 19:24:47 Wim Van Sebroeck wrote:
> watchdog: WatchDog Timer Driver Core - Part 6
> 
> Add support for the Magic Close feature to the
> WatchDog Timer Driver Core framework.
> 
> Signed-off-by: Alan Cox <alan@lxorguk.ukuu.org.uk>
> Signed-off-by: Wim Van Sebroeck <wim@iguana.be>

Acked-by: Arnd Bergmann <arnd@arndb.de>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-06-18 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-18 17:24 [PATCH 6/10 v2] Generic Watchdog Timer Driver Wim Van Sebroeck
2011-06-18 19:05 ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome