dm-region-hash.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. /*
  2. * Copyright (C) 2003 Sistina Software Limited.
  3. * Copyright (C) 2004-2008 Red Hat, Inc. All rights reserved.
  4. *
  5. * This file is released under the GPL.
  6. */
  7. #include <linux/dm-dirty-log.h>
  8. #include <linux/dm-region-hash.h>
  9. #include <linux/ctype.h>
  10. #include <linux/init.h>
  11. #include <linux/module.h>
  12. #include <linux/vmalloc.h>
  13. #include "dm.h"
  14. #include "dm-bio-list.h"
  15. #define DM_MSG_PREFIX "region hash"
  16. /*-----------------------------------------------------------------
  17. * Region hash
  18. *
  19. * The mirror splits itself up into discrete regions. Each
  20. * region can be in one of three states: clean, dirty,
  21. * nosync. There is no need to put clean regions in the hash.
  22. *
  23. * In addition to being present in the hash table a region _may_
  24. * be present on one of three lists.
  25. *
  26. * clean_regions: Regions on this list have no io pending to
  27. * them, they are in sync, we are no longer interested in them,
  28. * they are dull. dm_rh_update_states() will remove them from the
  29. * hash table.
  30. *
  31. * quiesced_regions: These regions have been spun down, ready
  32. * for recovery. rh_recovery_start() will remove regions from
  33. * this list and hand them to kmirrord, which will schedule the
  34. * recovery io with kcopyd.
  35. *
  36. * recovered_regions: Regions that kcopyd has successfully
  37. * recovered. dm_rh_update_states() will now schedule any delayed
  38. * io, up the recovery_count, and remove the region from the
  39. * hash.
  40. *
  41. * There are 2 locks:
  42. * A rw spin lock 'hash_lock' protects just the hash table,
  43. * this is never held in write mode from interrupt context,
  44. * which I believe means that we only have to disable irqs when
  45. * doing a write lock.
  46. *
  47. * An ordinary spin lock 'region_lock' that protects the three
  48. * lists in the region_hash, with the 'state', 'list' and
  49. * 'delayed_bios' fields of the regions. This is used from irq
  50. * context, so all other uses will have to suspend local irqs.
  51. *---------------------------------------------------------------*/
  52. struct dm_region_hash {
  53. uint32_t region_size;
  54. unsigned region_shift;
  55. /* holds persistent region state */
  56. struct dm_dirty_log *log;
  57. /* hash table */
  58. rwlock_t hash_lock;
  59. mempool_t *region_pool;
  60. unsigned mask;
  61. unsigned nr_buckets;
  62. unsigned prime;
  63. unsigned shift;
  64. struct list_head *buckets;
  65. unsigned max_recovery; /* Max # of regions to recover in parallel */
  66. spinlock_t region_lock;
  67. atomic_t recovery_in_flight;
  68. struct semaphore recovery_count;
  69. struct list_head clean_regions;
  70. struct list_head quiesced_regions;
  71. struct list_head recovered_regions;
  72. struct list_head failed_recovered_regions;
  73. void *context;
  74. sector_t target_begin;
  75. /* Callback function to schedule bios writes */
  76. void (*dispatch_bios)(void *context, struct bio_list *bios);
  77. /* Callback function to wakeup callers worker thread. */
  78. void (*wakeup_workers)(void *context);
  79. /* Callback function to wakeup callers recovery waiters. */
  80. void (*wakeup_all_recovery_waiters)(void *context);
  81. };
  82. struct dm_region {
  83. struct dm_region_hash *rh; /* FIXME: can we get rid of this ? */
  84. region_t key;
  85. int state;
  86. struct list_head hash_list;
  87. struct list_head list;
  88. atomic_t pending;
  89. struct bio_list delayed_bios;
  90. };
  91. /*
  92. * Conversion fns
  93. */
  94. static region_t dm_rh_sector_to_region(struct dm_region_hash *rh, sector_t sector)
  95. {
  96. return sector >> rh->region_shift;
  97. }
  98. sector_t dm_rh_region_to_sector(struct dm_region_hash *rh, region_t region)
  99. {
  100. return region << rh->region_shift;
  101. }
  102. EXPORT_SYMBOL_GPL(dm_rh_region_to_sector);
  103. region_t dm_rh_bio_to_region(struct dm_region_hash *rh, struct bio *bio)
  104. {
  105. return dm_rh_sector_to_region(rh, bio->bi_sector - rh->target_begin);
  106. }
  107. EXPORT_SYMBOL_GPL(dm_rh_bio_to_region);
  108. void *dm_rh_region_context(struct dm_region *reg)
  109. {
  110. return reg->rh->context;
  111. }
  112. EXPORT_SYMBOL_GPL(dm_rh_region_context);
  113. region_t dm_rh_get_region_key(struct dm_region *reg)
  114. {
  115. return reg->key;
  116. }
  117. EXPORT_SYMBOL_GPL(dm_rh_get_region_key);
  118. sector_t dm_rh_get_region_size(struct dm_region_hash *rh)
  119. {
  120. return rh->region_size;
  121. }
  122. EXPORT_SYMBOL_GPL(dm_rh_get_region_size);
  123. /*
  124. * FIXME: shall we pass in a structure instead of all these args to
  125. * dm_region_hash_create()????
  126. */
  127. #define RH_HASH_MULT 2654435387U
  128. #define RH_HASH_SHIFT 12
  129. #define MIN_REGIONS 64
  130. struct dm_region_hash *dm_region_hash_create(
  131. void *context, void (*dispatch_bios)(void *context,
  132. struct bio_list *bios),
  133. void (*wakeup_workers)(void *context),
  134. void (*wakeup_all_recovery_waiters)(void *context),
  135. sector_t target_begin, unsigned max_recovery,
  136. struct dm_dirty_log *log, uint32_t region_size,
  137. region_t nr_regions)
  138. {
  139. struct dm_region_hash *rh;
  140. unsigned nr_buckets, max_buckets;
  141. size_t i;
  142. /*
  143. * Calculate a suitable number of buckets for our hash
  144. * table.
  145. */
  146. max_buckets = nr_regions >> 6;
  147. for (nr_buckets = 128u; nr_buckets < max_buckets; nr_buckets <<= 1)
  148. ;
  149. nr_buckets >>= 1;
  150. rh = kmalloc(sizeof(*rh), GFP_KERNEL);
  151. if (!rh) {
  152. DMERR("unable to allocate region hash memory");
  153. return ERR_PTR(-ENOMEM);
  154. }
  155. rh->context = context;
  156. rh->dispatch_bios = dispatch_bios;
  157. rh->wakeup_workers = wakeup_workers;
  158. rh->wakeup_all_recovery_waiters = wakeup_all_recovery_waiters;
  159. rh->target_begin = target_begin;
  160. rh->max_recovery = max_recovery;
  161. rh->log = log;
  162. rh->region_size = region_size;
  163. rh->region_shift = ffs(region_size) - 1;
  164. rwlock_init(&rh->hash_lock);
  165. rh->mask = nr_buckets - 1;
  166. rh->nr_buckets = nr_buckets;
  167. rh->shift = RH_HASH_SHIFT;
  168. rh->prime = RH_HASH_MULT;
  169. rh->buckets = vmalloc(nr_buckets * sizeof(*rh->buckets));
  170. if (!rh->buckets) {
  171. DMERR("unable to allocate region hash bucket memory");
  172. kfree(rh);
  173. return ERR_PTR(-ENOMEM);
  174. }
  175. for (i = 0; i < nr_buckets; i++)
  176. INIT_LIST_HEAD(rh->buckets + i);
  177. spin_lock_init(&rh->region_lock);
  178. sema_init(&rh->recovery_count, 0);
  179. atomic_set(&rh->recovery_in_flight, 0);
  180. INIT_LIST_HEAD(&rh->clean_regions);
  181. INIT_LIST_HEAD(&rh->quiesced_regions);
  182. INIT_LIST_HEAD(&rh->recovered_regions);
  183. INIT_LIST_HEAD(&rh->failed_recovered_regions);
  184. rh->region_pool = mempool_create_kmalloc_pool(MIN_REGIONS,
  185. sizeof(struct dm_region));
  186. if (!rh->region_pool) {
  187. vfree(rh->buckets);
  188. kfree(rh);
  189. rh = ERR_PTR(-ENOMEM);
  190. }
  191. return rh;
  192. }
  193. EXPORT_SYMBOL_GPL(dm_region_hash_create);
  194. void dm_region_hash_destroy(struct dm_region_hash *rh)
  195. {
  196. unsigned h;
  197. struct dm_region *reg, *nreg;
  198. BUG_ON(!list_empty(&rh->quiesced_regions));
  199. for (h = 0; h < rh->nr_buckets; h++) {
  200. list_for_each_entry_safe(reg, nreg, rh->buckets + h,
  201. hash_list) {
  202. BUG_ON(atomic_read(&reg->pending));
  203. mempool_free(reg, rh->region_pool);
  204. }
  205. }
  206. if (rh->log)
  207. dm_dirty_log_destroy(rh->log);
  208. if (rh->region_pool)
  209. mempool_destroy(rh->region_pool);
  210. vfree(rh->buckets);
  211. kfree(rh);
  212. }
  213. EXPORT_SYMBOL_GPL(dm_region_hash_destroy);
  214. struct dm_dirty_log *dm_rh_dirty_log(struct dm_region_hash *rh)
  215. {
  216. return rh->log;
  217. }
  218. EXPORT_SYMBOL_GPL(dm_rh_dirty_log);
  219. static unsigned rh_hash(struct dm_region_hash *rh, region_t region)
  220. {
  221. return (unsigned) ((region * rh->prime) >> rh->shift) & rh->mask;
  222. }
  223. static struct dm_region *__rh_lookup(struct dm_region_hash *rh, region_t region)
  224. {
  225. struct dm_region *reg;
  226. struct list_head *bucket = rh->buckets + rh_hash(rh, region);
  227. list_for_each_entry(reg, bucket, hash_list)
  228. if (reg->key == region)
  229. return reg;
  230. return NULL;
  231. }
  232. static void __rh_insert(struct dm_region_hash *rh, struct dm_region *reg)
  233. {
  234. list_add(&reg->hash_list, rh->buckets + rh_hash(rh, reg->key));
  235. }
  236. static struct dm_region *__rh_alloc(struct dm_region_hash *rh, region_t region)
  237. {
  238. struct dm_region *reg, *nreg;
  239. nreg = mempool_alloc(rh->region_pool, GFP_ATOMIC);
  240. if (unlikely(!nreg))
  241. nreg = kmalloc(sizeof(*nreg), GFP_NOIO);
  242. nreg->state = rh->log->type->in_sync(rh->log, region, 1) ?
  243. DM_RH_CLEAN : DM_RH_NOSYNC;
  244. nreg->rh = rh;
  245. nreg->key = region;
  246. INIT_LIST_HEAD(&nreg->list);
  247. atomic_set(&nreg->pending, 0);
  248. bio_list_init(&nreg->delayed_bios);
  249. write_lock_irq(&rh->hash_lock);
  250. reg = __rh_lookup(rh, region);
  251. if (reg)
  252. /* We lost the race. */
  253. mempool_free(nreg, rh->region_pool);
  254. else {
  255. __rh_insert(rh, nreg);
  256. if (nreg->state == DM_RH_CLEAN) {
  257. spin_lock(&rh->region_lock);
  258. list_add(&nreg->list, &rh->clean_regions);
  259. spin_unlock(&rh->region_lock);
  260. }
  261. reg = nreg;
  262. }
  263. write_unlock_irq(&rh->hash_lock);
  264. return reg;
  265. }
  266. static struct dm_region *__rh_find(struct dm_region_hash *rh, region_t region)
  267. {
  268. struct dm_region *reg;
  269. reg = __rh_lookup(rh, region);
  270. if (!reg) {
  271. read_unlock(&rh->hash_lock);
  272. reg = __rh_alloc(rh, region);
  273. read_lock(&rh->hash_lock);
  274. }
  275. return reg;
  276. }
  277. int dm_rh_get_state(struct dm_region_hash *rh, region_t region, int may_block)
  278. {
  279. int r;
  280. struct dm_region *reg;
  281. read_lock(&rh->hash_lock);
  282. reg = __rh_lookup(rh, region);
  283. read_unlock(&rh->hash_lock);
  284. if (reg)
  285. return reg->state;
  286. /*
  287. * The region wasn't in the hash, so we fall back to the
  288. * dirty log.
  289. */
  290. r = rh->log->type->in_sync(rh->log, region, may_block);
  291. /*
  292. * Any error from the dirty log (eg. -EWOULDBLOCK) gets
  293. * taken as a DM_RH_NOSYNC
  294. */
  295. return r == 1 ? DM_RH_CLEAN : DM_RH_NOSYNC;
  296. }
  297. EXPORT_SYMBOL_GPL(dm_rh_get_state);
  298. static void complete_resync_work(struct dm_region *reg, int success)
  299. {
  300. struct dm_region_hash *rh = reg->rh;
  301. rh->log->type->set_region_sync(rh->log, reg->key, success);
  302. /*
  303. * Dispatch the bios before we call 'wake_up_all'.
  304. * This is important because if we are suspending,
  305. * we want to know that recovery is complete and
  306. * the work queue is flushed. If we wake_up_all
  307. * before we dispatch_bios (queue bios and call wake()),
  308. * then we risk suspending before the work queue
  309. * has been properly flushed.
  310. */
  311. rh->dispatch_bios(rh->context, &reg->delayed_bios);
  312. if (atomic_dec_and_test(&rh->recovery_in_flight))
  313. rh->wakeup_all_recovery_waiters(rh->context);
  314. up(&rh->recovery_count);
  315. }
  316. /* dm_rh_mark_nosync
  317. * @ms
  318. * @bio
  319. * @done
  320. * @error
  321. *
  322. * The bio was written on some mirror(s) but failed on other mirror(s).
  323. * We can successfully endio the bio but should avoid the region being
  324. * marked clean by setting the state DM_RH_NOSYNC.
  325. *
  326. * This function is _not_ safe in interrupt context!
  327. */
  328. void dm_rh_mark_nosync(struct dm_region_hash *rh,
  329. struct bio *bio, unsigned done, int error)
  330. {
  331. unsigned long flags;
  332. struct dm_dirty_log *log = rh->log;
  333. struct dm_region *reg;
  334. region_t region = dm_rh_bio_to_region(rh, bio);
  335. int recovering = 0;
  336. /* We must inform the log that the sync count has changed. */
  337. log->type->set_region_sync(log, region, 0);
  338. read_lock(&rh->hash_lock);
  339. reg = __rh_find(rh, region);
  340. read_unlock(&rh->hash_lock);
  341. /* region hash entry should exist because write was in-flight */
  342. BUG_ON(!reg);
  343. BUG_ON(!list_empty(&reg->list));
  344. spin_lock_irqsave(&rh->region_lock, flags);
  345. /*
  346. * Possible cases:
  347. * 1) DM_RH_DIRTY
  348. * 2) DM_RH_NOSYNC: was dirty, other preceeding writes failed
  349. * 3) DM_RH_RECOVERING: flushing pending writes
  350. * Either case, the region should have not been connected to list.
  351. */
  352. recovering = (reg->state == DM_RH_RECOVERING);
  353. reg->state = DM_RH_NOSYNC;
  354. BUG_ON(!list_empty(&reg->list));
  355. spin_unlock_irqrestore(&rh->region_lock, flags);
  356. bio_endio(bio, error);
  357. if (recovering)
  358. complete_resync_work(reg, 0);
  359. }
  360. EXPORT_SYMBOL_GPL(dm_rh_mark_nosync);
  361. void dm_rh_update_states(struct dm_region_hash *rh, int errors_handled)
  362. {
  363. struct dm_region *reg, *next;
  364. LIST_HEAD(clean);
  365. LIST_HEAD(recovered);
  366. LIST_HEAD(failed_recovered);
  367. /*
  368. * Quickly grab the lists.
  369. */
  370. write_lock_irq(&rh->hash_lock);
  371. spin_lock(&rh->region_lock);
  372. if (!list_empty(&rh->clean_regions)) {
  373. list_splice_init(&rh->clean_regions, &clean);
  374. list_for_each_entry(reg, &clean, list)
  375. list_del(&reg->hash_list);
  376. }
  377. if (!list_empty(&rh->recovered_regions)) {
  378. list_splice_init(&rh->recovered_regions, &recovered);
  379. list_for_each_entry(reg, &recovered, list)
  380. list_del(&reg->hash_list);
  381. }
  382. if (!list_empty(&rh->failed_recovered_regions)) {
  383. list_splice_init(&rh->failed_recovered_regions,
  384. &failed_recovered);
  385. list_for_each_entry(reg, &failed_recovered, list)
  386. list_del(&reg->hash_list);
  387. }
  388. spin_unlock(&rh->region_lock);
  389. write_unlock_irq(&rh->hash_lock);
  390. /*
  391. * All the regions on the recovered and clean lists have
  392. * now been pulled out of the system, so no need to do
  393. * any more locking.
  394. */
  395. list_for_each_entry_safe(reg, next, &recovered, list) {
  396. rh->log->type->clear_region(rh->log, reg->key);
  397. complete_resync_work(reg, 1);
  398. mempool_free(reg, rh->region_pool);
  399. }
  400. list_for_each_entry_safe(reg, next, &failed_recovered, list) {
  401. complete_resync_work(reg, errors_handled ? 0 : 1);
  402. mempool_free(reg, rh->region_pool);
  403. }
  404. list_for_each_entry_safe(reg, next, &clean, list) {
  405. rh->log->type->clear_region(rh->log, reg->key);
  406. mempool_free(reg, rh->region_pool);
  407. }
  408. rh->log->type->flush(rh->log);
  409. }
  410. EXPORT_SYMBOL_GPL(dm_rh_update_states);
  411. static void rh_inc(struct dm_region_hash *rh, region_t region)
  412. {
  413. struct dm_region *reg;
  414. read_lock(&rh->hash_lock);
  415. reg = __rh_find(rh, region);
  416. spin_lock_irq(&rh->region_lock);
  417. atomic_inc(&reg->pending);
  418. if (reg->state == DM_RH_CLEAN) {
  419. reg->state = DM_RH_DIRTY;
  420. list_del_init(&reg->list); /* take off the clean list */
  421. spin_unlock_irq(&rh->region_lock);
  422. rh->log->type->mark_region(rh->log, reg->key);
  423. } else
  424. spin_unlock_irq(&rh->region_lock);
  425. read_unlock(&rh->hash_lock);
  426. }
  427. void dm_rh_inc_pending(struct dm_region_hash *rh, struct bio_list *bios)
  428. {
  429. struct bio *bio;
  430. for (bio = bios->head; bio; bio = bio->bi_next)
  431. rh_inc(rh, dm_rh_bio_to_region(rh, bio));
  432. }
  433. EXPORT_SYMBOL_GPL(dm_rh_inc_pending);
  434. void dm_rh_dec(struct dm_region_hash *rh, region_t region)
  435. {
  436. unsigned long flags;
  437. struct dm_region *reg;
  438. int should_wake = 0;
  439. read_lock(&rh->hash_lock);
  440. reg = __rh_lookup(rh, region);
  441. read_unlock(&rh->hash_lock);
  442. spin_lock_irqsave(&rh->region_lock, flags);
  443. if (atomic_dec_and_test(&reg->pending)) {
  444. /*
  445. * There is no pending I/O for this region.
  446. * We can move the region to corresponding list for next action.
  447. * At this point, the region is not yet connected to any list.
  448. *
  449. * If the state is DM_RH_NOSYNC, the region should be kept off
  450. * from clean list.
  451. * The hash entry for DM_RH_NOSYNC will remain in memory
  452. * until the region is recovered or the map is reloaded.
  453. */
  454. /* do nothing for DM_RH_NOSYNC */
  455. if (reg->state == DM_RH_RECOVERING) {
  456. list_add_tail(&reg->list, &rh->quiesced_regions);
  457. } else if (reg->state == DM_RH_DIRTY) {
  458. reg->state = DM_RH_CLEAN;
  459. list_add(&reg->list, &rh->clean_regions);
  460. }
  461. should_wake = 1;
  462. }
  463. spin_unlock_irqrestore(&rh->region_lock, flags);
  464. if (should_wake)
  465. rh->wakeup_workers(rh->context);
  466. }
  467. EXPORT_SYMBOL_GPL(dm_rh_dec);
  468. /*
  469. * Starts quiescing a region in preparation for recovery.
  470. */
  471. static int __rh_recovery_prepare(struct dm_region_hash *rh)
  472. {
  473. int r;
  474. region_t region;
  475. struct dm_region *reg;
  476. /*
  477. * Ask the dirty log what's next.
  478. */
  479. r = rh->log->type->get_resync_work(rh->log, &region);
  480. if (r <= 0)
  481. return r;
  482. /*
  483. * Get this region, and start it quiescing by setting the
  484. * recovering flag.
  485. */
  486. read_lock(&rh->hash_lock);
  487. reg = __rh_find(rh, region);
  488. read_unlock(&rh->hash_lock);
  489. spin_lock_irq(&rh->region_lock);
  490. reg->state = DM_RH_RECOVERING;
  491. /* Already quiesced ? */
  492. if (atomic_read(&reg->pending))
  493. list_del_init(&reg->list);
  494. else
  495. list_move(&reg->list, &rh->quiesced_regions);
  496. spin_unlock_irq(&rh->region_lock);
  497. return 1;
  498. }
  499. void dm_rh_recovery_prepare(struct dm_region_hash *rh)
  500. {
  501. /* Extra reference to avoid race with dm_rh_stop_recovery */
  502. atomic_inc(&rh->recovery_in_flight);
  503. while (!down_trylock(&rh->recovery_count)) {
  504. atomic_inc(&rh->recovery_in_flight);
  505. if (__rh_recovery_prepare(rh) <= 0) {
  506. atomic_dec(&rh->recovery_in_flight);
  507. up(&rh->recovery_count);
  508. break;
  509. }
  510. }
  511. /* Drop the extra reference */
  512. if (atomic_dec_and_test(&rh->recovery_in_flight))
  513. rh->wakeup_all_recovery_waiters(rh->context);
  514. }
  515. EXPORT_SYMBOL_GPL(dm_rh_recovery_prepare);
  516. /*
  517. * Returns any quiesced regions.
  518. */
  519. struct dm_region *dm_rh_recovery_start(struct dm_region_hash *rh)
  520. {
  521. struct dm_region *reg = NULL;
  522. spin_lock_irq(&rh->region_lock);
  523. if (!list_empty(&rh->quiesced_regions)) {
  524. reg = list_entry(rh->quiesced_regions.next,
  525. struct dm_region, list);
  526. list_del_init(&reg->list); /* remove from the quiesced list */
  527. }
  528. spin_unlock_irq(&rh->region_lock);
  529. return reg;
  530. }
  531. EXPORT_SYMBOL_GPL(dm_rh_recovery_start);
  532. void dm_rh_recovery_end(struct dm_region *reg, int success)
  533. {
  534. struct dm_region_hash *rh = reg->rh;
  535. spin_lock_irq(&rh->region_lock);
  536. if (success)
  537. list_add(&reg->list, &reg->rh->recovered_regions);
  538. else {
  539. reg->state = DM_RH_NOSYNC;
  540. list_add(&reg->list, &reg->rh->failed_recovered_regions);
  541. }
  542. spin_unlock_irq(&rh->region_lock);
  543. rh->wakeup_workers(rh->context);
  544. }
  545. EXPORT_SYMBOL_GPL(dm_rh_recovery_end);
  546. /* Return recovery in flight count. */
  547. int dm_rh_recovery_in_flight(struct dm_region_hash *rh)
  548. {
  549. return atomic_read(&rh->recovery_in_flight);
  550. }
  551. EXPORT_SYMBOL_GPL(dm_rh_recovery_in_flight);
  552. int dm_rh_flush(struct dm_region_hash *rh)
  553. {
  554. return rh->log->type->flush(rh->log);
  555. }
  556. EXPORT_SYMBOL_GPL(dm_rh_flush);
  557. void dm_rh_delay(struct dm_region_hash *rh, struct bio *bio)
  558. {
  559. struct dm_region *reg;
  560. read_lock(&rh->hash_lock);
  561. reg = __rh_find(rh, dm_rh_bio_to_region(rh, bio));
  562. bio_list_add(&reg->delayed_bios, bio);
  563. read_unlock(&rh->hash_lock);
  564. }
  565. EXPORT_SYMBOL_GPL(dm_rh_delay);
  566. void dm_rh_stop_recovery(struct dm_region_hash *rh)
  567. {
  568. int i;
  569. /* wait for any recovering regions */
  570. for (i = 0; i < rh->max_recovery; i++)
  571. down(&rh->recovery_count);
  572. }
  573. EXPORT_SYMBOL_GPL(dm_rh_stop_recovery);
  574. void dm_rh_start_recovery(struct dm_region_hash *rh)
  575. {
  576. int i;
  577. for (i = 0; i < rh->max_recovery; i++)
  578. up(&rh->recovery_count);
  579. rh->wakeup_workers(rh->context);
  580. }
  581. EXPORT_SYMBOL_GPL(dm_rh_start_recovery);
  582. MODULE_DESCRIPTION(DM_NAME " region hash");
  583. MODULE_AUTHOR("Joe Thornber/Heinz Mauelshagen <dm-devel@redhat.com>");
  584. MODULE_LICENSE("GPL");