Skip to contentSkip to conversation

add container release logic - update fc transport to utilize it

PATCH In review James Smart 2 participants 4 messages Aug 14, 2007

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

PATCH 1/1 add container release logic - update fc transport to utilize it

Consistent with the code in the rest of the transports, when the driver module attached or detached to a transport, the transport ignored the statuses from transport_container_register() and transport_container_unregister(). This was particularly bad on the unregister path, because the transport would free the transport-internal structure that held all the attribute containers. Thus, if a driver was told to unload, and the unload path completed faster than the tear down of the scsi object tree (as a sysfs attribute was in use at the time, or whatever), you could get into ugly reuse of a freed internal structure.

Given that this is a module-global thing, there's no real relationship to the create/release (or refcounting) of the device objects that eventually bind to the structure.

I modified the container logic to potentially call back the container owner whenever all objects on the container were freed. This allowed the release to happen in the background to the LLDD removal.

Assuming this is how we want to handle this scenario, the other SCSI transports need to be updated accordingly.

-- james s

This patch was cut against 2.6.23-rc3

drivers/base/attribute_container.c +12 -0
diff -upNr a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
@@ -97,6 +97,8 @@ attribute_container_unregister(struct at
 	int retval = -EBUSY;
 	mutex_lock(&attribute_container_mutex);
 	spin_lock(&cont->containers.k_lock);
+	if (cont->release)
+		cont->flags |= ATTRIBUTE_CONTAINER_RELEASE_PENDING;
 	if (!list_empty(&cont->containers.k_list))
 		goto out;
 	retval = 0;
@@ -104,6 +106,8 @@ attribute_container_unregister(struct at
  out:
 	spin_unlock(&cont->containers.k_lock);
 	mutex_unlock(&attribute_container_mutex);
+	if ((retval == 0) && (cont->release))
+		cont->release(cont->release_arg, cont);
 	return retval;
 		
 }
@@ -212,6 +216,7 @@ attribute_container_remove_device(struct
 {
 	struct attribute_container *cont;
 
+rmv_restart:
 	mutex_lock(&attribute_container_mutex);
 	list_for_each_entry(cont, &attribute_container_list, node) {
 		struct internal_container *ic;
@@ -234,6 +239,13 @@ attribute_container_remove_device(struct
 				class_device_unregister(&ic->classdev);
 			}
 		}
+
+		if ((cont->flags & ATTRIBUTE_CONTAINER_RELEASE_PENDING)
+		    && list_empty(&cont->containers.k_list)) {
+			mutex_unlock(&attribute_container_mutex);
+			cont->release(cont->release_arg, cont);
+			goto rmv_restart;
+		}
 	}
 	mutex_unlock(&attribute_container_mutex);
 }
drivers/scsi/scsi_transport_fc.c +69 -6

118 lines not on this page · raw message

include/linux/attribute_container.h +3 -0
diff -upNr a/include/linux/attribute_container.h b/include/linux/attribute_container.h
@@ -19,7 +19,10 @@ struct attribute_container {
 	struct class		*class;
 	struct class_device_attribute **attrs;
 	int (*match)(struct attribute_container *, struct device *);
+	void (*release)(void *, struct attribute_container *);
+	void *release_arg;
 #define	ATTRIBUTE_CONTAINER_NO_CLASSDEVS	0x01
+#define	ATTRIBUTE_CONTAINER_RELEASE_PENDING	0x02
 	unsigned long		flags;
 };
 
#1 lore raw
Quoted 14 lines · James Smart

Consistent with the code in the rest of the transports, when the driver module attached or detached to a transport, the transport ignored the statuses from transport_container_register() and transport_container_unregister(). This was particularly bad on the unregister path, because the transport would free the transport-internal structure that held all the attribute containers. Thus, if a driver was told to unload, and the unload path completed faster than the tear down of the scsi object tree (as a sysfs attribute was in use at the time, or whatever), you could get into ugly reuse of a freed internal structure.

Given that this is a module-global thing, there's no real relationship to the create/release (or refcounting) of the device objects that eventually bind to the structure.

Quoted 6 lines

I modified the container logic to potentially call back the container owner whenever all objects on the container were freed. This allowed the release to happen in the background to the LLDD removal.

Assuming this is how we want to handle this scenario, the other SCSI transports need to be updated accordingly.

I'm afraid if you look at your solution, you'll see it still doesn't quite work: If the next thing the user does after unloading lpfc is to unload the transport class, the module is blown away with potentially a live release callback to now freed code.

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.

James

#2 lore raw
Quoted 4 lines · James Bottomley

I'm afraid if you look at your solution, you'll see it still doesn't quite work: If the next thing the user does after unloading lpfc is to unload the transport class, the module is blown away with potentially a live release callback to now freed code.

You're right... Although, most don't as the transports are dependencies for the LLDD's, and it's only the LLDDs they care about. But, point taken.

Quoted 5 lines

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 hoping you'd give some guidance. This area is black voodoo... :)

Sure - so are you suggesting that transport_container_unregister() continually loop until successful ? If not, what other kind of semantic can we give it that we don't have to muck with the transport classes ?

-- james s

#3 lore raw
Quoted 11 lines · James Smart
Quoted 5 lines

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 hoping you'd give some guidance. This area is black voodoo... :)

Sure - so are you suggesting that transport_container_unregister() continually loop until successful ? If not, what other kind of semantic can we give it that we don't have to muck with the transport classes ?

Not looping no, but otherwise that's basically correct.

I was thinking of a wait_event driven system checking for list_empty(cont->containers.k_list)

I'll cook up a patch.

James