tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Pseudo disk driver vs. mutex



Folks,

while trying to update the fss pseudo disk driver from simple_lock to
mutex I'm not sure what to do. Does this fragment look ok?

- IPL_NONE or IPL_SOFTBIO?
- Any need for splbio() / slpx()?
- biodone() inside the mutex or outside?

void
fssattach(int num)
{
        struct fss_softc *sc;

        mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&sc->sc_work, "fss");
        bufq_alloc(&sc->sc_bufq, "fcfs", 0);
}

void
fss_strategy(struct buf *bp)
{
        struct fss_softc *sc;

        mutex_enter(&sc->sc_lock);
        if (<bad request>) {
                mutex_exit(&sc->sc_lock);
                <adjust bp>
                biodone(bp);
                return;
        }
        bp->b_rawblkno = bp->b_blkno;
        BUFQ_PUT(sc->sc_bufq, bp);
        cv_signal(&sc->sc_work);
        mutex_exit(&sc->sc_lock);
}

static void
fss_bs_thread(void *arg)
{
        int work;
        struct fss_softc *sc;

        mutex_enter(&sc->sc_lock);
        work = 1;
        for (;;) {
                if (work == 0)
                        cv_wait(&sc->sc_work, &sc->sc_lock);
                work = 0;
                if ((bp = BUFQ_GET(sc->sc_bufq)) == NULL)
                        continue;
                work++;
                mutex_exit(&sc->sc_lock);
                <fulfill request>
                biodone(bp);
                mutex_enter(&sc->sc_lock);
                continue;
        }
}

-- 
Juergen Hannken-Illjes - hannken%eis.cs.tu-bs.de@localhost - TU Braunschweig 
(Germany)


Home | Main Index | Thread Index | Old Index