mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
Add rw_tryupgrade()
This implementation of rw_tryupgrade() behaves slightly differently from its counterparts on other platforms. It drops the RW_READER lock and then acquires the RW_WRITER lock leaving a small window where no lock is held. On other platforms the lock is never released during the upgrade process. This is necessary under Linux because the kernel does not provide an upgrade function. There are currently no callers in the ZFS code where this change in behavior is a problem. In fact, in most cases the code is already written such that if the upgrade fails the RW_READER lock is dropped and the caller blocks waiting to acquire the lock as RW_WRITER. Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Tim Chase <tim@chase2k.com> Signed-off-by: Matthew Thode <prometheanfire@gentoo.org> Closes zfsonlinux/zfs#4388 Closes #534
This commit is contained in:
@@ -32,65 +32,5 @@
|
||||
|
||||
#define DEBUG_SUBSYSTEM S_RWLOCK
|
||||
|
||||
#ifdef CONFIG_RWSEM_GENERIC_SPINLOCK
|
||||
|
||||
/*
|
||||
* From lib/rwsem-spinlock.c but modified such that the caller is
|
||||
* responsible for acquiring and dropping the sem->wait_lock.
|
||||
*/
|
||||
struct rwsem_waiter {
|
||||
struct list_head list;
|
||||
struct task_struct *task;
|
||||
unsigned int flags;
|
||||
#define RWSEM_WAITING_FOR_READ 0x00000001
|
||||
#define RWSEM_WAITING_FOR_WRITE 0x00000002
|
||||
};
|
||||
|
||||
/* wake a single writer */
|
||||
static struct rw_semaphore *
|
||||
__rwsem_wake_one_writer_locked(struct rw_semaphore *sem)
|
||||
{
|
||||
struct rwsem_waiter *waiter;
|
||||
struct task_struct *tsk;
|
||||
|
||||
sem->activity = -1;
|
||||
|
||||
waiter = list_entry(sem->wait_list.next, struct rwsem_waiter, list);
|
||||
list_del(&waiter->list);
|
||||
|
||||
tsk = waiter->task;
|
||||
smp_mb();
|
||||
waiter->task = NULL;
|
||||
wake_up_process(tsk);
|
||||
put_task_struct(tsk);
|
||||
return sem;
|
||||
}
|
||||
|
||||
/* release a read lock on the semaphore */
|
||||
void
|
||||
__up_read_locked(struct rw_semaphore *sem)
|
||||
{
|
||||
if (--sem->activity == 0 && !list_empty(&sem->wait_list))
|
||||
(void)__rwsem_wake_one_writer_locked(sem);
|
||||
}
|
||||
EXPORT_SYMBOL(__up_read_locked);
|
||||
|
||||
/* trylock for writing -- returns 1 if successful, 0 if contention */
|
||||
int
|
||||
__down_write_trylock_locked(struct rw_semaphore *sem)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (sem->activity == 0 && list_empty(&sem->wait_list)) {
|
||||
sem->activity = -1;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL(__down_write_trylock_locked);
|
||||
|
||||
#endif
|
||||
|
||||
int spl_rw_init(void) { return 0; }
|
||||
void spl_rw_fini(void) { }
|
||||
|
||||
Reference in New Issue
Block a user