tech-kern archive

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

Re: Finding an available fss device



> Date: Fri, 10 Aug 2018 13:46:55 +0000
> From: Emmanuel Dreyfus <manu%netbsd.org@localhost>
> 
> Perhaps the right way is to add a FSSIOBUSY ioctl that would
> use mutex_tryenter and return EBUSY if the device is in use?

Unless I misunderstand fss(4), this is an abuse of mutex(9): nothing
should sleep while holding the lock, so that nothing trying to acquire
the lock will wait for a long time.  Instead, fss(4) should use an
interruptible lock built on a mutex and a condvar.  Something like
this:

struct fss_lock {
	kmutex_t lock;
	kcondvar_t cv;
	kthread_t owner; /* maybe currently rendered as FSS_ACTIVE bit */
};

	/* Acquire it with the opportunity to be interrupted.  */
	mutex_enter(&sc->sc_fss_lock.lock);
	while (sc->sc_fss_lock.owner == NULL) {
		if (wait) {
			error = cv_wait_sig(&sc->sc_fss_lock.cv,
			    &sc->sc_ffs_lock.cv);
		} else {
			error = EBUSY;
		}
		if (error) {
			mutex_exit(&sc->sc_fss_lock.lock);
			return error;
		}
        }
	sc->sc_fss_lock.owner = curlwp;
	mutex_exit(&sc->sc_fss_lock.lock);

	/* Create the snapshot;  */
	error = fss_create_snapshot(...);

	/* Release it.  *
	mutex_enter(&sc->sc_fss_lock.lock);
	KASSERT(sc->sc_fss_lock.owner == curlwp);
	sc->sc_fss_lock.owner = NULL;
	mutex_exit(&sc->sc_fss_lock.lock);


Home | Main Index | Thread Index | Old Index