Skip to contentSkip to conversation

ATA over Ethernet: Convert emsgs_sema in a completion

PATCH In review Matthias Kaehlcke 3 participants 4 messages May 16, 2008 – May 21, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ATA over Ethernet: Convert emsgs_sema in a completion

ATA over Ethernet: The semaphore emsgs_sema is used for signaling an event, convert it in a completion.

--

drivers/block/aoe/aoechr.c +5 -4
index e8e60e7..d0ffe63 100644
@@ -6,6 +6,7 @@
 
 #include <linux/hdreg.h>
 #include <linux/blkdev.h>
+#include <linux/completion.h>
 #include <linux/delay.h>
 #include "aoe.h"
 
@@ -35,7 +36,7 @@ struct ErrMsg {
 
 static struct ErrMsg emsgs[NMSG];
 static int emsgs_head_idx, emsgs_tail_idx;
-static struct semaphore emsgs_sema;
+static struct completion emsgs_comp;
 static spinlock_t emsgs_lock;
 static int nblocked_emsgs_readers;
 static struct class *aoe_class;
@@ -140,7 +141,7 @@ bail:		spin_unlock_irqrestore(&emsgs_lock, flags);
 	spin_unlock_irqrestore(&emsgs_lock, flags);
 
 	if (nblocked_emsgs_readers)
-		up(&emsgs_sema);
+		complete(&emsgs_comp);
 }
 
 static ssize_t
@@ -216,7 +217,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 
 		spin_unlock_irqrestore(&emsgs_lock, flags);
 
-		n = down_interruptible(&emsgs_sema);
+		n = wait_for_completion_interruptible(&emsgs_comp);
 
 		spin_lock_irqsave(&emsgs_lock, flags);
 
@@ -264,7 +265,7 @@ aoechr_init(void)
 		printk(KERN_ERR "aoe: can't register char device\n");
 		return n;
 	}
-	sema_init(&emsgs_sema, 0);
+	init_completion(&emsgs_comp);
 	spin_lock_init(&emsgs_lock);
 	aoe_class = class_create(THIS_MODULE, "aoe");
 	if (IS_ERR(aoe_class)) {
Signature · 10 lines
Matthias Kaehlcke
Embedded Linux Engineer
Barcelona

             You must have a plan. If you don't have a plan,
               you'll become part of somebody else's plan
                                                                 .''`.
    using free software / Debian GNU/Linux | http://debian.org  : :'  :
                                                                `. `'`
gpg --keyserver pgp.mit.edu --recv-keys 47D8E5D4                  `-
#1 lore raw

drivers/block/aoe/aoechr.c aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off) · line 220

Quoted 6 lines · On Fri, 16 May 2008 21:11:33 +0200 Matthias Kaehlcke <[email protected]>…
drivers/block/aoe/aoechr.c +1 -1
@@ -216,7 +217,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 
 		spin_unlock_irqrestore(&emsgs_lock, flags);
 
-		n = down_interruptible(&emsgs_sema);
+		n = wait_for_completion_interruptible(&emsgs_comp);

Patch looks OK, but I worry about this code. Suppose a signal is sent and we return to userspace with the complete() still outstanding. Then someone removes the module.

Perhaps there is synchronisation code which prevents that crash?

#2 lore raw
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Fri, 16 May 2008 21:11:33 +0200 Matthias Kaehlcke <[email protected]>…
drivers/block/aoe/aoechr.c +0 -0
@@ -216,7 +217,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 
 		spin_unlock_irqrestore(&emsgs_lock, flags);
 
Quoted 8 lines

drivers/block/aoe/aoechr.c aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off) · line 220

Quoted 2 lines
drivers/block/aoe/aoechr.c +1 -1
-		n = down_interruptible(&emsgs_sema);
+		n = wait_for_completion_interruptible(&emsgs_comp);

Patch looks OK, but I worry about this code. Suppose a signal is sent and we return to userspace with the complete() still outstanding. Then someone removes the module.

Perhaps there is synchronisation code which prevents that crash?

I plan to answer this question soon. Right now I am quite busy.

This emsgs_sema part of the aoe driver has never caused any problems for users but has caused many problems for me, because it is tricky to think about, to talk about, and for others to patch.

I hope that there is a more straightforward way to get the current read-from-the-file-forever behavior using an existing kernel facility. A user currently can do,

cat /dev/etherd/err

... and have it block, waiting until there is an error to report, printing it, and then blocking again, like reading from a pipe.

Signature · 1 line
  Ed L Cashin <[email protected]>
#3 lore raw
Quoted 23 lines · On Wed, 21 May 2008 10:49:24 -0400 "Ed L. Cashin" <[email protected]> wrote:
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Fri, 16 May 2008 21:11:33 +0200 Matthias Kaehlcke <[email protected]>…
drivers/block/aoe/aoechr.c +0 -0
@@ -216,7 +217,7 @@ aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off)
 
 		spin_unlock_irqrestore(&emsgs_lock, flags);
 
Quoted 8 lines

drivers/block/aoe/aoechr.c aoechr_read(struct file *filp, char __user *buf, size_t cnt, loff_t *off) · line 220

Quoted 2 lines
drivers/block/aoe/aoechr.c +1 -1
-		n = down_interruptible(&emsgs_sema);
+		n = wait_for_completion_interruptible(&emsgs_comp);

Patch looks OK, but I worry about this code. Suppose a signal is sent and we return to userspace with the complete() still outstanding. Then someone removes the module.

Perhaps there is synchronisation code which prevents that crash?

I plan to answer this question soon. Right now I am quite busy.

This emsgs_sema part of the aoe driver has never caused any problems for users but has caused many problems for me, because it is tricky to think about, to talk about, and for others to patch.

Quoted 8 lines

I hope that there is a more straightforward way to get the current read-from-the-file-forever behavior using an existing kernel facility. A user currently can do,

cat /dev/etherd/err

... and have it block, waiting until there is an error to report, printing it, and then blocking again, like reading from a pipe.

That's fine - the normal way of handling that is for the user's fd to hold a reference against the module itself.