Garrett D'Amore wrote:
> On Fri, 2007-09-07 at 16:49 +0100, Paul Durrant wrote:
>> On 07/09/2007, Garrett D'Amore <[EMAIL PROTECTED]> wrote:
>>>> You mean upstream callers that have done mac_open()? That should take
>>>> a ref. on the mac_impl_t.
>>> Yes, but since that reference count would not be covered by a lock that
>>> the driver currently knows about or could safely acquire, the driver
>>> clould not rely upon it to tell it anything meaningful.
>>>
>> ? Surely mac_unregister() *must* take the same lock as mac_open() to
>> check the ref. count? It should do, if it doesn't today.
> 
> Yes, but you're *missing* the point.
> 
> The point is that without calling mac_unregister(), the driver doesn't
> know if there are any active upstream callers.
> 
> So the only easy solution I can come up with without major contortions
> on the part of drivers, is to create a new function, that separates
> *unregistration* (which honors such a reference count) from actually
> freeing the memory associated with the mac_impl_t.

For the Clearview iptun work, I created a mac_condemn() function which is 
basically:

int
mac_condemn(mac_handle_t mh)
{
         mac_impl_t      *mip = (mac_impl_t *)mh;

         rw_enter(&i_mac_impl_lock, RW_WRITER);
         if (mip->mi_ref > 0) {
                 ASSERT(!mip->mi_disabled);
                 rw_exit(&i_mac_impl_lock);
                 return (EBUSY);
         }
         mip->mi_disabled = B_TRUE;
         rw_exit(&i_mac_impl_lock);
         return (0);
}

This allows me (the driver) to call mac_condemn(), then disable things 
safely until I'm ready to call mac_unregister(), which safely frees the 
mac_impl_t.

-Seb
_______________________________________________
networking-discuss mailing list
[email protected]

Reply via email to