The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: James Smart <James.Smart@Emulex.Com>
To: james.bottomely@steeleye.com, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] make attribute_container_unregister() unconditionally wait for list empty
Date: Wed, 15 Aug 2007 11:40:00 -0400	[thread overview]
Message-ID: <1187192400.3142.6.camel@localhost.localdomain> (raw)

James,

>> > > Isn't a better way to handle it simply to give
>> > > transport_container_unregister() the semantics everyone is expecting
>> > > (i.e. to wait for everything to be tidied up and gone)?  That way none
>> > > of the transport classes needs updating, and we don't have to handle the
>> > > rather nasty release and unload races.
> 
> I was thinking of a wait_event driven system checking for 
> list_empty(cont->containers.k_list)

I hope this is more in line with what you were thinking.....

-- james s


Signed-off-by: James Smart <James.Smart@emulex.com>


diff -upNr a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
--- a/drivers/base/attribute_container.c	2007-08-16 02:59:50.000000000 -0400
+++ b/drivers/base/attribute_container.c	2007-08-17 05:02:03.000000000 -0400
@@ -19,6 +19,7 @@
 #include <linux/list.h>
 #include <linux/module.h>
 #include <linux/mutex.h>
+#include <linux/sched.h>
 
 #include "base.h"
 
@@ -75,6 +76,8 @@ int
 attribute_container_register(struct attribute_container *cont)
 {
 	INIT_LIST_HEAD(&cont->node);
+	init_waitqueue_head(&cont->cont_wait);
+	cont->flags &= ~ATTRIBUTE_CONTAINER_EVENT_PENDING;
 	klist_init(&cont->containers,internal_container_klist_get,
 		   internal_container_klist_put);
 		
@@ -89,23 +92,26 @@ EXPORT_SYMBOL_GPL(attribute_container_re
 /**
  * attribute_container_unregister - remove a container registration
  *
+ * Semantics have now changed - we never return until the list goes empty
+ * 
  * @cont: previously registered container to remove
  */
 int
 attribute_container_unregister(struct attribute_container *cont)
 {
-	int retval = -EBUSY;
 	mutex_lock(&attribute_container_mutex);
 	spin_lock(&cont->containers.k_lock);
-	if (!list_empty(&cont->containers.k_list))
-		goto out;
-	retval = 0;
-	list_del(&cont->node);
- out:
+	if (!list_empty(&cont->containers.k_list)) 
+		cont->flags |= ATTRIBUTE_CONTAINER_EVENT_PENDING;
 	spin_unlock(&cont->containers.k_lock);
 	mutex_unlock(&attribute_container_mutex);
-	return retval;
-		
+	wait_event(cont->cont_wait,
+			 !(cont->flags & ATTRIBUTE_CONTAINER_EVENT_PENDING));
+	mutex_lock(&attribute_container_mutex);
+	list_del(&cont->node);
+	mutex_unlock(&attribute_container_mutex);
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(attribute_container_unregister);
 
@@ -234,6 +240,15 @@ attribute_container_remove_device(struct
 				class_device_unregister(&ic->classdev);
 			}
 		}
+
+		if (cont->flags & ATTRIBUTE_CONTAINER_EVENT_PENDING) {
+			spin_lock(&cont->containers.k_lock);
+			if (list_empty(&cont->containers.k_list)) 
+				cont->flags &= 
+					~ATTRIBUTE_CONTAINER_EVENT_PENDING;
+			spin_unlock(&cont->containers.k_lock);
+			wake_up(&cont->cont_wait);
+		}
 	}
 	mutex_unlock(&attribute_container_mutex);
 }
diff -upNr a/include/linux/attribute_container.h b/include/linux/attribute_container.h
--- a/include/linux/attribute_container.h	2007-08-16 03:00:10.000000000 -0400
+++ b/include/linux/attribute_container.h	2007-08-17 03:46:01.000000000 -0400
@@ -20,7 +20,9 @@ struct attribute_container {
 	struct class_device_attribute **attrs;
 	int (*match)(struct attribute_container *, struct device *);
 #define	ATTRIBUTE_CONTAINER_NO_CLASSDEVS	0x01
+#define	ATTRIBUTE_CONTAINER_EVENT_PENDING	0x02
 	unsigned long		flags;
+	wait_queue_head_t       cont_wait;
 };
 
 static inline int




             reply	other threads:[~2007-08-15 15:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-15 15:40 James Smart [this message]
2007-08-15 15:54 ` [PATCH] make attribute_container_unregister() unconditionally wait for list empty James Bottomley
2007-08-16 14:49   ` James Bottomley

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1187192400.3142.6.camel@localhost.localdomain \
    --to=james.smart@emulex.com \
    --cc=james.bottomely@steeleye.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox