aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/md/bcache/super.c
diff options
context:
space:
mode:
authorKent Overstreet <kmo@daterainc.com>2013-12-16 18:27:25 -0500
committerKent Overstreet <kmo@daterainc.com>2014-01-08 16:05:08 -0500
commitcb7a583e6a6ace661a5890803e115d2292a293df (patch)
treebe695468938237320560fc75b0f4b64cbe60117a /drivers/md/bcache/super.c
parenta5ae4300c15c778722c139953c825cd24d6ff517 (diff)
bcache: kill closure locking usage
Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Diffstat (limited to 'drivers/md/bcache/super.c')
-rw-r--r--drivers/md/bcache/super.c54
1 files changed, 39 insertions, 15 deletions
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 93d593f957f6..b057676fc67d 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -225,7 +225,7 @@ static void write_bdev_super_endio(struct bio *bio, int error)
225 struct cached_dev *dc = bio->bi_private; 225 struct cached_dev *dc = bio->bi_private;
226 /* XXX: error checking */ 226 /* XXX: error checking */
227 227
228 closure_put(&dc->sb_write.cl); 228 closure_put(&dc->sb_write);
229} 229}
230 230
231static void __write_super(struct cache_sb *sb, struct bio *bio) 231static void __write_super(struct cache_sb *sb, struct bio *bio)
@@ -263,12 +263,20 @@ static void __write_super(struct cache_sb *sb, struct bio *bio)
263 submit_bio(REQ_WRITE, bio); 263 submit_bio(REQ_WRITE, bio);
264} 264}
265 265
266static void bch_write_bdev_super_unlock(struct closure *cl)
267{
268 struct cached_dev *dc = container_of(cl, struct cached_dev, sb_write);
269
270 up(&dc->sb_write_mutex);
271}
272
266void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent) 273void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
267{ 274{
268 struct closure *cl = &dc->sb_write.cl; 275 struct closure *cl = &dc->sb_write;
269 struct bio *bio = &dc->sb_bio; 276 struct bio *bio = &dc->sb_bio;
270 277
271 closure_lock(&dc->sb_write, parent); 278 down(&dc->sb_write_mutex);
279 closure_init(cl, parent);
272 280
273 bio_reset(bio); 281 bio_reset(bio);
274 bio->bi_bdev = dc->bdev; 282 bio->bi_bdev = dc->bdev;
@@ -278,7 +286,7 @@ void bch_write_bdev_super(struct cached_dev *dc, struct closure *parent)
278 closure_get(cl); 286 closure_get(cl);
279 __write_super(&dc->sb, bio); 287 __write_super(&dc->sb, bio);
280 288
281 closure_return(cl); 289 closure_return_with_destructor(cl, bch_write_bdev_super_unlock);
282} 290}
283 291
284static void write_super_endio(struct bio *bio, int error) 292static void write_super_endio(struct bio *bio, int error)
@@ -286,16 +294,24 @@ static void write_super_endio(struct bio *bio, int error)
286 struct cache *ca = bio->bi_private; 294 struct cache *ca = bio->bi_private;
287 295
288 bch_count_io_errors(ca, error, "writing superblock"); 296 bch_count_io_errors(ca, error, "writing superblock");
289 closure_put(&ca->set->sb_write.cl); 297 closure_put(&ca->set->sb_write);
298}
299
300static void bcache_write_super_unlock(struct closure *cl)
301{
302 struct cache_set *c = container_of(cl, struct cache_set, sb_write);
303
304 up(&c->sb_write_mutex);
290} 305}
291 306
292void bcache_write_super(struct cache_set *c) 307void bcache_write_super(struct cache_set *c)
293{ 308{
294 struct closure *cl = &c->sb_write.cl; 309 struct closure *cl = &c->sb_write;
295 struct cache *ca; 310 struct cache *ca;
296 unsigned i; 311 unsigned i;
297 312
298 closure_lock(&c->sb_write, &c->cl); 313 down(&c->sb_write_mutex);
314 closure_init(cl, &c->cl);
299 315
300 c->sb.seq++; 316 c->sb.seq++;
301 317
@@ -317,7 +333,7 @@ void bcache_write_super(struct cache_set *c)
317 __write_super(&ca->sb, bio); 333 __write_super(&ca->sb, bio);
318 } 334 }
319 335
320 closure_return(cl); 336 closure_return_with_destructor(cl, bcache_write_super_unlock);
321} 337}
322 338
323/* UUID io */ 339/* UUID io */
@@ -325,23 +341,31 @@ void bcache_write_super(struct cache_set *c)
325static void uuid_endio(struct bio *bio, int error) 341static void uuid_endio(struct bio *bio, int error)
326{ 342{
327 struct closure *cl = bio->bi_private; 343 struct closure *cl = bio->bi_private;
328 struct cache_set *c = container_of(cl, struct cache_set, uuid_write.cl); 344 struct cache_set *c = container_of(cl, struct cache_set, uuid_write);
329 345
330 cache_set_err_on(error, c, "accessing uuids"); 346 cache_set_err_on(error, c, "accessing uuids");
331 bch_bbio_free(bio, c); 347 bch_bbio_free(bio, c);
332 closure_put(cl); 348 closure_put(cl);
333} 349}
334 350
351static void uuid_io_unlock(struct closure *cl)
352{
353 struct cache_set *c = container_of(cl, struct cache_set, uuid_write);
354
355 up(&c->uuid_write_mutex);
356}
357
335static void uuid_io(struct cache_set *c, unsigned long rw, 358static void uuid_io(struct cache_set *c, unsigned long rw,
336 struct bkey *k, struct closure *parent) 359 struct bkey *k, struct closure *parent)
337{ 360{
338 struct closure *cl = &c->uuid_write.cl; 361 struct closure *cl = &c->uuid_write;
339 struct uuid_entry *u; 362 struct uuid_entry *u;
340 unsigned i; 363 unsigned i;
341 char buf[80]; 364 char buf[80];
342 365
343 BUG_ON(!parent); 366 BUG_ON(!parent);
344 closure_lock(&c->uuid_write, parent); 367 down(&c->uuid_write_mutex);
368 closure_init(cl, parent);
345 369
346 for (i = 0; i < KEY_PTRS(k); i++) { 370 for (i = 0; i < KEY_PTRS(k); i++) {
347 struct bio *bio = bch_bbio_alloc(c); 371 struct bio *bio = bch_bbio_alloc(c);
@@ -368,7 +392,7 @@ static void uuid_io(struct cache_set *c, unsigned long rw,
368 u - c->uuids, u->uuid, u->label, 392 u - c->uuids, u->uuid, u->label,
369 u->first_reg, u->last_reg, u->invalidated); 393 u->first_reg, u->last_reg, u->invalidated);
370 394
371 closure_return(cl); 395 closure_return_with_destructor(cl, uuid_io_unlock);
372} 396}
373 397
374static char *uuid_read(struct cache_set *c, struct jset *j, struct closure *cl) 398static char *uuid_read(struct cache_set *c, struct jset *j, struct closure *cl)
@@ -1098,7 +1122,7 @@ static int cached_dev_init(struct cached_dev *dc, unsigned block_size)
1098 set_closure_fn(&dc->disk.cl, cached_dev_flush, system_wq); 1122 set_closure_fn(&dc->disk.cl, cached_dev_flush, system_wq);
1099 kobject_init(&dc->disk.kobj, &bch_cached_dev_ktype); 1123 kobject_init(&dc->disk.kobj, &bch_cached_dev_ktype);
1100 INIT_WORK(&dc->detach, cached_dev_detach_finish); 1124 INIT_WORK(&dc->detach, cached_dev_detach_finish);
1101 closure_init_unlocked(&dc->sb_write); 1125 sema_init(&dc->sb_write_mutex, 1);
1102 INIT_LIST_HEAD(&dc->io_lru); 1126 INIT_LIST_HEAD(&dc->io_lru);
1103 spin_lock_init(&dc->io_lock); 1127 spin_lock_init(&dc->io_lock);
1104 bch_cache_accounting_init(&dc->accounting, &dc->disk.cl); 1128 bch_cache_accounting_init(&dc->accounting, &dc->disk.cl);
@@ -1454,11 +1478,11 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
1454 1478
1455 c->sort_crit_factor = int_sqrt(c->btree_pages); 1479 c->sort_crit_factor = int_sqrt(c->btree_pages);
1456 1480
1457 closure_init_unlocked(&c->sb_write); 1481 sema_init(&c->sb_write_mutex, 1);
1458 mutex_init(&c->bucket_lock); 1482 mutex_init(&c->bucket_lock);
1459 init_waitqueue_head(&c->try_wait); 1483 init_waitqueue_head(&c->try_wait);
1460 init_waitqueue_head(&c->bucket_wait); 1484 init_waitqueue_head(&c->bucket_wait);
1461 closure_init_unlocked(&c->uuid_write); 1485 sema_init(&c->uuid_write_mutex, 1);
1462 mutex_init(&c->sort_lock); 1486 mutex_init(&c->sort_lock);
1463 1487
1464 spin_lock_init(&c->sort_time.lock); 1488 spin_lock_init(&c->sort_time.lock);