Subject: Re: [RFC] add rtnl semaphore to linux-atm

From: Mitchell Blank Jr <[email-masked]>
Date: Fri, 3 Oct 2003 23:56:29 -0700

Mitchell Blank Jr wrote:
> I'm just trying to make the point that the spinlock (or rwlock, whatever)
> can't be held when we call atm_dev->{open,close}() since they can sleep.
> Which is why we need to do the three-step process I described in the
> earlier email.

Actually I guess there's two ways of doing it... so instead of

Method 1:
  1. Take rwlock for writing
  2. Search for {dev,vpi,vci} tuple.  If found, fail - otherwise add it
     as "inactive"
  3. Drop rwlock
  4. Take semaphore
  5. Call atm_dev->open()
  6. Drop semaphore
  7. Take rwlock for writing
  8. If open succeeded clear "inactive" flag.  If failed remove entry
  9. Drop rwlock

Method 2:
  1. Take semaphore
  2. Take rwlock for reading
  3. Search for tuple, if found fail
  4. Drop rwlock
  5. Call atm_dev->open
  6. Take rwlock for writing
  7. Add tuple to list
  8. Drop rwlock
  9. Drop semaphore

The second method has the advantage that you don't need the "inactive"
flag.  On the other hand, you have to wait for the semaphore before
you can return EADDRINUSE.

-Mitch