提交 42d36115 编写于 作者: J Jeff Dike 提交者: Linus Torvalds

[PATCH] uml: watchdog driver locking

Replace BKL use with a spinlock.

Also fix the control so that open doesn't return holding a lock.
Signed-off-by: NJeff Dike <jdike@addtoit.com>
Cc: Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 4ea21cd9
...@@ -44,12 +44,13 @@ ...@@ -44,12 +44,13 @@
#include <linux/reboot.h> #include <linux/reboot.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/spinlock.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include "mconsole.h" #include "mconsole.h"
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
/* Locked by the BKL in harddog_open and harddog_release */ static DEFINE_SPINLOCK(lock);
static int timer_alive; static int timer_alive;
static int harddog_in_fd = -1; static int harddog_in_fd = -1;
static int harddog_out_fd = -1; static int harddog_out_fd = -1;
...@@ -62,12 +63,12 @@ extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock); ...@@ -62,12 +63,12 @@ extern int start_watchdog(int *in_fd_ret, int *out_fd_ret, char *sock);
static int harddog_open(struct inode *inode, struct file *file) static int harddog_open(struct inode *inode, struct file *file)
{ {
int err; int err = -EBUSY;
char *sock = NULL; char *sock = NULL;
lock_kernel(); spin_lock(&lock);
if(timer_alive) if(timer_alive)
return -EBUSY; goto err;
#ifdef CONFIG_HARDDOG_NOWAYOUT #ifdef CONFIG_HARDDOG_NOWAYOUT
__module_get(THIS_MODULE); __module_get(THIS_MODULE);
#endif #endif
...@@ -76,11 +77,15 @@ static int harddog_open(struct inode *inode, struct file *file) ...@@ -76,11 +77,15 @@ static int harddog_open(struct inode *inode, struct file *file)
sock = mconsole_notify_socket(); sock = mconsole_notify_socket();
#endif #endif
err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock); err = start_watchdog(&harddog_in_fd, &harddog_out_fd, sock);
if(err) return(err); if(err)
goto err;
timer_alive = 1; timer_alive = 1;
unlock_kernel(); spin_unlock(&lock);
return nonseekable_open(inode, file); return nonseekable_open(inode, file);
err:
spin_unlock(&lock);
return err;
} }
extern void stop_watchdog(int in_fd, int out_fd); extern void stop_watchdog(int in_fd, int out_fd);
...@@ -90,14 +95,16 @@ static int harddog_release(struct inode *inode, struct file *file) ...@@ -90,14 +95,16 @@ static int harddog_release(struct inode *inode, struct file *file)
/* /*
* Shut off the timer. * Shut off the timer.
*/ */
lock_kernel();
spin_lock(&lock);
stop_watchdog(harddog_in_fd, harddog_out_fd); stop_watchdog(harddog_in_fd, harddog_out_fd);
harddog_in_fd = -1; harddog_in_fd = -1;
harddog_out_fd = -1; harddog_out_fd = -1;
timer_alive=0; timer_alive=0;
unlock_kernel(); spin_unlock(&lock);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册