===================================================================
@@ -81,7 +81,7 @@
* context.
*/
struct dm_bufio_client {
- struct mutex lock;
+ struct rw_semaphore lock;
spinlock_t spinlock;
bool no_sleep;
@@ -174,7 +174,7 @@ static void dm_bufio_lock(struct dm_bufi
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
spin_lock_bh(&c->spinlock);
else
- mutex_lock_nested(&c->lock, dm_bufio_in_request());
+ down_write_nested(&c->lock, dm_bufio_in_request());
}
static int dm_bufio_trylock(struct dm_bufio_client *c)
@@ -182,7 +182,7 @@ static int dm_bufio_trylock(struct dm_bu
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
return spin_trylock_bh(&c->spinlock);
else
- return mutex_trylock(&c->lock);
+ return down_write_trylock(&c->lock);
}
static void dm_bufio_unlock(struct dm_bufio_client *c)
@@ -190,18 +190,18 @@ static void dm_bufio_unlock(struct dm_bu
if (static_branch_unlikely(&no_sleep_enabled) && c->no_sleep)
spin_unlock_bh(&c->spinlock);
else
- mutex_unlock(&c->lock);
+ up_write(&c->lock);
}
void dm_bufio_lock_read(struct dm_bufio_client *c)
{
- mutex_lock(&c->lock);
+ down_read(&c->lock);
}
EXPORT_SYMBOL_GPL(dm_bufio_lock_read);
void dm_bufio_unlock_read(struct dm_bufio_client *c)
{
- mutex_unlock(&c->lock);
+ up_read(&c->lock);
}
EXPORT_SYMBOL_GPL(dm_bufio_unlock_read);
@@ -1808,7 +1808,7 @@ struct dm_bufio_client *dm_bufio_client_
c->n_buffers[i] = 0;
}
- mutex_init(&c->lock);
+ init_rwsem(&c->lock);
spin_lock_init(&c->spinlock);
INIT_LIST_HEAD(&c->reserved_buffers);
c->need_reserved_buffers = reserved_buffers;
@@ -1887,7 +1887,6 @@ bad:
kmem_cache_destroy(c->slab_buffer);
dm_io_client_destroy(c->dm_io);
bad_dm_io:
- mutex_destroy(&c->lock);
kfree(c);
bad_client:
return ERR_PTR(r);
@@ -1935,7 +1934,6 @@ void dm_bufio_client_destroy(struct dm_b
kmem_cache_destroy(c->slab_cache);
kmem_cache_destroy(c->slab_buffer);
dm_io_client_destroy(c->dm_io);
- mutex_destroy(&c->lock);
if (c->no_sleep)
static_branch_dec(&no_sleep_enabled);
kfree(c);
Change mutex to rw_semaphore, so that there could be multiple processes inside dm_bufio_lock_read/dm_bufio_unlock_read concurrently. Signed-off-by: Mikulas Patocka <mpatocka@redhat.com> --- drivers/md/dm-bufio.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel