diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2017-01-10 18:30:54 -0900 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2017-01-18 21:41:34 -0900 |
commit | abf8953366dcbd8ab7a61873b25494d31ee721c2 (patch) | |
tree | 306ae3dfe9ee4cbf23c512bc7dbdaaf645243a49 | |
parent | 0fd192fcc98fadd65df6cc2f1b2922bb265a2069 (diff) |
lglock: add a proper lg_lock_init()
-rw-r--r-- | drivers/md/bcache/super.c | 5 | ||||
-rw-r--r-- | include/linux/lglock.h | 25 |
2 files changed, 20 insertions, 10 deletions
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index cf27f0c18d16..71ab21ad876f 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -910,7 +910,7 @@ static void cache_set_free(struct cache_set *c) bch_io_clock_exit(&c->io_clock[READ]); bch_compress_free(c); bdi_destroy(&c->bdi); - free_percpu(c->bucket_stats_lock.lock); + lg_lock_free(&c->bucket_stats_lock); free_percpu(c->bucket_stats_percpu); mempool_exit(&c->btree_bounce_pool); mempool_exit(&c->bio_bounce_pages); @@ -1081,7 +1081,6 @@ static struct cache_set *bch_cache_set_alloc(struct cache_sb *sb, sema_init(&c->sb_write_mutex, 1); INIT_RADIX_TREE(&c->devices, GFP_KERNEL); mutex_init(&c->btree_cache_lock); - lg_lock_init(&c->bucket_stats_lock); mutex_init(&c->bucket_lock); mutex_init(&c->btree_root_lock); INIT_WORK(&c->read_only_work, bch_cache_set_read_only_work); @@ -1181,7 +1180,7 @@ static struct cache_set *bch_cache_set_alloc(struct cache_sb *sb, CRC32_EXTENT_SIZE_MAX) / PAGE_SECTORS, 0) || !(c->bucket_stats_percpu = alloc_percpu(struct bucket_stats_cache_set)) || - !(c->bucket_stats_lock.lock = alloc_percpu(*c->bucket_stats_lock.lock)) || + lg_lock_init(&c->bucket_stats_lock) || mempool_init_page_pool(&c->btree_bounce_pool, 1, ilog2(btree_pages(c))) || bdi_setup_and_register(&c->bdi, "bcache") || diff --git a/include/linux/lglock.h b/include/linux/lglock.h index d0f59aeca769..b934e366113f 100644 --- a/include/linux/lglock.h +++ b/include/linux/lglock.h @@ -27,12 +27,6 @@ #ifdef CONFIG_SMP -#ifdef CONFIG_DEBUG_LOCK_ALLOC -#define LOCKDEP_INIT_MAP lockdep_init_map -#else -#define LOCKDEP_INIT_MAP(a, b, c, d) -#endif - struct lglock { arch_spinlock_t __percpu *lock; #ifdef CONFIG_DEBUG_LOCK_ALLOC @@ -50,13 +44,30 @@ struct lglock { = __ARCH_SPIN_LOCK_UNLOCKED; \ static struct lglock name = { .lock = &name ## _lock } -#define lg_lock_init(lock) \ +static inline void lg_lock_free(struct lglock *lg) +{ + free_percpu(lg->lock); +} + +#define lg_lock_lockdep_init(lock) \ do { \ static struct lock_class_key __key; \ \ lockdep_init_map(&(lock)->lock_dep_map, #lock, &__key, 0); \ } while (0) +static inline int __lg_lock_init(struct lglock *lg) +{ + lg->lock = alloc_percpu(*lg->lock); + return lg->lock ? 0 : -ENOMEM; +} + +#define lg_lock_init(lock) \ +({ \ + lg_lock_lockdep_init(lock); \ + __lg_lock_init(lock); \ +}) + void lg_local_lock(struct lglock *lg); void lg_local_unlock(struct lglock *lg); void lg_local_lock_cpu(struct lglock *lg, int cpu); |