dm-kcopyd.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /*
  2. * Copyright (C) 2002 Sistina Software (UK) Limited.
  3. * Copyright (C) 2006 Red Hat GmbH
  4. *
  5. * This file is released under the GPL.
  6. *
  7. * Kcopyd provides a simple interface for copying an area of one
  8. * block-device to one or more other block-devices, with an asynchronous
  9. * completion notification.
  10. */
  11. #include <linux/types.h>
  12. #include <linux/atomic.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/fs.h>
  15. #include <linux/init.h>
  16. #include <linux/list.h>
  17. #include <linux/mempool.h>
  18. #include <linux/module.h>
  19. #include <linux/pagemap.h>
  20. #include <linux/slab.h>
  21. #include <linux/vmalloc.h>
  22. #include <linux/workqueue.h>
  23. #include <linux/mutex.h>
  24. #include <linux/device-mapper.h>
  25. #include <linux/dm-kcopyd.h>
  26. #include "dm.h"
  27. #define SUB_JOB_SIZE 128
  28. #define SPLIT_COUNT 8
  29. #define MIN_JOBS 8
  30. #define RESERVE_PAGES (DIV_ROUND_UP(SUB_JOB_SIZE << SECTOR_SHIFT, PAGE_SIZE))
  31. /*-----------------------------------------------------------------
  32. * Each kcopyd client has its own little pool of preallocated
  33. * pages for kcopyd io.
  34. *---------------------------------------------------------------*/
  35. struct dm_kcopyd_client {
  36. struct page_list *pages;
  37. unsigned nr_reserved_pages;
  38. unsigned nr_free_pages;
  39. struct dm_io_client *io_client;
  40. wait_queue_head_t destroyq;
  41. atomic_t nr_jobs;
  42. mempool_t *job_pool;
  43. struct workqueue_struct *kcopyd_wq;
  44. struct work_struct kcopyd_work;
  45. /*
  46. * We maintain three lists of jobs:
  47. *
  48. * i) jobs waiting for pages
  49. * ii) jobs that have pages, and are waiting for the io to be issued.
  50. * iii) jobs that have completed.
  51. *
  52. * All three of these are protected by job_lock.
  53. */
  54. spinlock_t job_lock;
  55. struct list_head complete_jobs;
  56. struct list_head io_jobs;
  57. struct list_head pages_jobs;
  58. };
  59. static struct page_list zero_page_list;
  60. static void wake(struct dm_kcopyd_client *kc)
  61. {
  62. queue_work(kc->kcopyd_wq, &kc->kcopyd_work);
  63. }
  64. /*
  65. * Obtain one page for the use of kcopyd.
  66. */
  67. static struct page_list *alloc_pl(gfp_t gfp)
  68. {
  69. struct page_list *pl;
  70. pl = kmalloc(sizeof(*pl), gfp);
  71. if (!pl)
  72. return NULL;
  73. pl->page = alloc_page(gfp);
  74. if (!pl->page) {
  75. kfree(pl);
  76. return NULL;
  77. }
  78. return pl;
  79. }
  80. static void free_pl(struct page_list *pl)
  81. {
  82. __free_page(pl->page);
  83. kfree(pl);
  84. }
  85. /*
  86. * Add the provided pages to a client's free page list, releasing
  87. * back to the system any beyond the reserved_pages limit.
  88. */
  89. static void kcopyd_put_pages(struct dm_kcopyd_client *kc, struct page_list *pl)
  90. {
  91. struct page_list *next;
  92. do {
  93. next = pl->next;
  94. if (kc->nr_free_pages >= kc->nr_reserved_pages)
  95. free_pl(pl);
  96. else {
  97. pl->next = kc->pages;
  98. kc->pages = pl;
  99. kc->nr_free_pages++;
  100. }
  101. pl = next;
  102. } while (pl);
  103. }
  104. static int kcopyd_get_pages(struct dm_kcopyd_client *kc,
  105. unsigned int nr, struct page_list **pages)
  106. {
  107. struct page_list *pl;
  108. *pages = NULL;
  109. do {
  110. pl = alloc_pl(__GFP_NOWARN | __GFP_NORETRY);
  111. if (unlikely(!pl)) {
  112. /* Use reserved pages */
  113. pl = kc->pages;
  114. if (unlikely(!pl))
  115. goto out_of_memory;
  116. kc->pages = pl->next;
  117. kc->nr_free_pages--;
  118. }
  119. pl->next = *pages;
  120. *pages = pl;
  121. } while (--nr);
  122. return 0;
  123. out_of_memory:
  124. if (*pages)
  125. kcopyd_put_pages(kc, *pages);
  126. return -ENOMEM;
  127. }
  128. /*
  129. * These three functions resize the page pool.
  130. */
  131. static void drop_pages(struct page_list *pl)
  132. {
  133. struct page_list *next;
  134. while (pl) {
  135. next = pl->next;
  136. free_pl(pl);
  137. pl = next;
  138. }
  139. }
  140. /*
  141. * Allocate and reserve nr_pages for the use of a specific client.
  142. */
  143. static int client_reserve_pages(struct dm_kcopyd_client *kc, unsigned nr_pages)
  144. {
  145. unsigned i;
  146. struct page_list *pl = NULL, *next;
  147. for (i = 0; i < nr_pages; i++) {
  148. next = alloc_pl(GFP_KERNEL);
  149. if (!next) {
  150. if (pl)
  151. drop_pages(pl);
  152. return -ENOMEM;
  153. }
  154. next->next = pl;
  155. pl = next;
  156. }
  157. kc->nr_reserved_pages += nr_pages;
  158. kcopyd_put_pages(kc, pl);
  159. return 0;
  160. }
  161. static void client_free_pages(struct dm_kcopyd_client *kc)
  162. {
  163. BUG_ON(kc->nr_free_pages != kc->nr_reserved_pages);
  164. drop_pages(kc->pages);
  165. kc->pages = NULL;
  166. kc->nr_free_pages = kc->nr_reserved_pages = 0;
  167. }
  168. /*-----------------------------------------------------------------
  169. * kcopyd_jobs need to be allocated by the *clients* of kcopyd,
  170. * for this reason we use a mempool to prevent the client from
  171. * ever having to do io (which could cause a deadlock).
  172. *---------------------------------------------------------------*/
  173. struct kcopyd_job {
  174. struct dm_kcopyd_client *kc;
  175. struct list_head list;
  176. unsigned long flags;
  177. /*
  178. * Error state of the job.
  179. */
  180. int read_err;
  181. unsigned long write_err;
  182. /*
  183. * Either READ or WRITE
  184. */
  185. int rw;
  186. struct dm_io_region source;
  187. /*
  188. * The destinations for the transfer.
  189. */
  190. unsigned int num_dests;
  191. struct dm_io_region dests[DM_KCOPYD_MAX_REGIONS];
  192. struct page_list *pages;
  193. /*
  194. * Set this to ensure you are notified when the job has
  195. * completed. 'context' is for callback to use.
  196. */
  197. dm_kcopyd_notify_fn fn;
  198. void *context;
  199. /*
  200. * These fields are only used if the job has been split
  201. * into more manageable parts.
  202. */
  203. struct mutex lock;
  204. atomic_t sub_jobs;
  205. sector_t progress;
  206. struct kcopyd_job *master_job;
  207. };
  208. static struct kmem_cache *_job_cache;
  209. int __init dm_kcopyd_init(void)
  210. {
  211. _job_cache = kmem_cache_create("kcopyd_job",
  212. sizeof(struct kcopyd_job) * (SPLIT_COUNT + 1),
  213. __alignof__(struct kcopyd_job), 0, NULL);
  214. if (!_job_cache)
  215. return -ENOMEM;
  216. zero_page_list.next = &zero_page_list;
  217. zero_page_list.page = ZERO_PAGE(0);
  218. return 0;
  219. }
  220. void dm_kcopyd_exit(void)
  221. {
  222. kmem_cache_destroy(_job_cache);
  223. _job_cache = NULL;
  224. }
  225. /*
  226. * Functions to push and pop a job onto the head of a given job
  227. * list.
  228. */
  229. static struct kcopyd_job *pop(struct list_head *jobs,
  230. struct dm_kcopyd_client *kc)
  231. {
  232. struct kcopyd_job *job = NULL;
  233. unsigned long flags;
  234. spin_lock_irqsave(&kc->job_lock, flags);
  235. if (!list_empty(jobs)) {
  236. job = list_entry(jobs->next, struct kcopyd_job, list);
  237. list_del(&job->list);
  238. }
  239. spin_unlock_irqrestore(&kc->job_lock, flags);
  240. return job;
  241. }
  242. static void push(struct list_head *jobs, struct kcopyd_job *job)
  243. {
  244. unsigned long flags;
  245. struct dm_kcopyd_client *kc = job->kc;
  246. spin_lock_irqsave(&kc->job_lock, flags);
  247. list_add_tail(&job->list, jobs);
  248. spin_unlock_irqrestore(&kc->job_lock, flags);
  249. }
  250. static void push_head(struct list_head *jobs, struct kcopyd_job *job)
  251. {
  252. unsigned long flags;
  253. struct dm_kcopyd_client *kc = job->kc;
  254. spin_lock_irqsave(&kc->job_lock, flags);
  255. list_add(&job->list, jobs);
  256. spin_unlock_irqrestore(&kc->job_lock, flags);
  257. }
  258. /*
  259. * These three functions process 1 item from the corresponding
  260. * job list.
  261. *
  262. * They return:
  263. * < 0: error
  264. * 0: success
  265. * > 0: can't process yet.
  266. */
  267. static int run_complete_job(struct kcopyd_job *job)
  268. {
  269. void *context = job->context;
  270. int read_err = job->read_err;
  271. unsigned long write_err = job->write_err;
  272. dm_kcopyd_notify_fn fn = job->fn;
  273. struct dm_kcopyd_client *kc = job->kc;
  274. if (job->pages && job->pages != &zero_page_list)
  275. kcopyd_put_pages(kc, job->pages);
  276. /*
  277. * If this is the master job, the sub jobs have already
  278. * completed so we can free everything.
  279. */
  280. if (job->master_job == job)
  281. mempool_free(job, kc->job_pool);
  282. fn(read_err, write_err, context);
  283. if (atomic_dec_and_test(&kc->nr_jobs))
  284. wake_up(&kc->destroyq);
  285. return 0;
  286. }
  287. static void complete_io(unsigned long error, void *context)
  288. {
  289. struct kcopyd_job *job = (struct kcopyd_job *) context;
  290. struct dm_kcopyd_client *kc = job->kc;
  291. if (error) {
  292. if (job->rw == WRITE)
  293. job->write_err |= error;
  294. else
  295. job->read_err = 1;
  296. if (!test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
  297. push(&kc->complete_jobs, job);
  298. wake(kc);
  299. return;
  300. }
  301. }
  302. if (job->rw == WRITE)
  303. push(&kc->complete_jobs, job);
  304. else {
  305. job->rw = WRITE;
  306. push(&kc->io_jobs, job);
  307. }
  308. wake(kc);
  309. }
  310. /*
  311. * Request io on as many buffer heads as we can currently get for
  312. * a particular job.
  313. */
  314. static int run_io_job(struct kcopyd_job *job)
  315. {
  316. int r;
  317. struct dm_io_request io_req = {
  318. .bi_rw = job->rw,
  319. .mem.type = DM_IO_PAGE_LIST,
  320. .mem.ptr.pl = job->pages,
  321. .mem.offset = 0,
  322. .notify.fn = complete_io,
  323. .notify.context = job,
  324. .client = job->kc->io_client,
  325. };
  326. if (job->rw == READ)
  327. r = dm_io(&io_req, 1, &job->source, NULL);
  328. else
  329. r = dm_io(&io_req, job->num_dests, job->dests, NULL);
  330. return r;
  331. }
  332. static int run_pages_job(struct kcopyd_job *job)
  333. {
  334. int r;
  335. unsigned nr_pages = dm_div_up(job->dests[0].count, PAGE_SIZE >> 9);
  336. r = kcopyd_get_pages(job->kc, nr_pages, &job->pages);
  337. if (!r) {
  338. /* this job is ready for io */
  339. push(&job->kc->io_jobs, job);
  340. return 0;
  341. }
  342. if (r == -ENOMEM)
  343. /* can't complete now */
  344. return 1;
  345. return r;
  346. }
  347. /*
  348. * Run through a list for as long as possible. Returns the count
  349. * of successful jobs.
  350. */
  351. static int process_jobs(struct list_head *jobs, struct dm_kcopyd_client *kc,
  352. int (*fn) (struct kcopyd_job *))
  353. {
  354. struct kcopyd_job *job;
  355. int r, count = 0;
  356. while ((job = pop(jobs, kc))) {
  357. r = fn(job);
  358. if (r < 0) {
  359. /* error this rogue job */
  360. if (job->rw == WRITE)
  361. job->write_err = (unsigned long) -1L;
  362. else
  363. job->read_err = 1;
  364. push(&kc->complete_jobs, job);
  365. break;
  366. }
  367. if (r > 0) {
  368. /*
  369. * We couldn't service this job ATM, so
  370. * push this job back onto the list.
  371. */
  372. push_head(jobs, job);
  373. break;
  374. }
  375. count++;
  376. }
  377. return count;
  378. }
  379. /*
  380. * kcopyd does this every time it's woken up.
  381. */
  382. static void do_work(struct work_struct *work)
  383. {
  384. struct dm_kcopyd_client *kc = container_of(work,
  385. struct dm_kcopyd_client, kcopyd_work);
  386. struct blk_plug plug;
  387. /*
  388. * The order that these are called is *very* important.
  389. * complete jobs can free some pages for pages jobs.
  390. * Pages jobs when successful will jump onto the io jobs
  391. * list. io jobs call wake when they complete and it all
  392. * starts again.
  393. */
  394. blk_start_plug(&plug);
  395. process_jobs(&kc->complete_jobs, kc, run_complete_job);
  396. process_jobs(&kc->pages_jobs, kc, run_pages_job);
  397. process_jobs(&kc->io_jobs, kc, run_io_job);
  398. blk_finish_plug(&plug);
  399. }
  400. /*
  401. * If we are copying a small region we just dispatch a single job
  402. * to do the copy, otherwise the io has to be split up into many
  403. * jobs.
  404. */
  405. static void dispatch_job(struct kcopyd_job *job)
  406. {
  407. struct dm_kcopyd_client *kc = job->kc;
  408. atomic_inc(&kc->nr_jobs);
  409. if (unlikely(!job->source.count))
  410. push(&kc->complete_jobs, job);
  411. else if (job->pages == &zero_page_list)
  412. push(&kc->io_jobs, job);
  413. else
  414. push(&kc->pages_jobs, job);
  415. wake(kc);
  416. }
  417. static void segment_complete(int read_err, unsigned long write_err,
  418. void *context)
  419. {
  420. /* FIXME: tidy this function */
  421. sector_t progress = 0;
  422. sector_t count = 0;
  423. struct kcopyd_job *sub_job = (struct kcopyd_job *) context;
  424. struct kcopyd_job *job = sub_job->master_job;
  425. struct dm_kcopyd_client *kc = job->kc;
  426. mutex_lock(&job->lock);
  427. /* update the error */
  428. if (read_err)
  429. job->read_err = 1;
  430. if (write_err)
  431. job->write_err |= write_err;
  432. /*
  433. * Only dispatch more work if there hasn't been an error.
  434. */
  435. if ((!job->read_err && !job->write_err) ||
  436. test_bit(DM_KCOPYD_IGNORE_ERROR, &job->flags)) {
  437. /* get the next chunk of work */
  438. progress = job->progress;
  439. count = job->source.count - progress;
  440. if (count) {
  441. if (count > SUB_JOB_SIZE)
  442. count = SUB_JOB_SIZE;
  443. job->progress += count;
  444. }
  445. }
  446. mutex_unlock(&job->lock);
  447. if (count) {
  448. int i;
  449. *sub_job = *job;
  450. sub_job->source.sector += progress;
  451. sub_job->source.count = count;
  452. for (i = 0; i < job->num_dests; i++) {
  453. sub_job->dests[i].sector += progress;
  454. sub_job->dests[i].count = count;
  455. }
  456. sub_job->fn = segment_complete;
  457. sub_job->context = sub_job;
  458. dispatch_job(sub_job);
  459. } else if (atomic_dec_and_test(&job->sub_jobs)) {
  460. /*
  461. * Queue the completion callback to the kcopyd thread.
  462. *
  463. * Some callers assume that all the completions are called
  464. * from a single thread and don't race with each other.
  465. *
  466. * We must not call the callback directly here because this
  467. * code may not be executing in the thread.
  468. */
  469. push(&kc->complete_jobs, job);
  470. wake(kc);
  471. }
  472. }
  473. /*
  474. * Create some sub jobs to share the work between them.
  475. */
  476. static void split_job(struct kcopyd_job *master_job)
  477. {
  478. int i;
  479. atomic_inc(&master_job->kc->nr_jobs);
  480. atomic_set(&master_job->sub_jobs, SPLIT_COUNT);
  481. for (i = 0; i < SPLIT_COUNT; i++) {
  482. master_job[i + 1].master_job = master_job;
  483. segment_complete(0, 0u, &master_job[i + 1]);
  484. }
  485. }
  486. int dm_kcopyd_copy(struct dm_kcopyd_client *kc, struct dm_io_region *from,
  487. unsigned int num_dests, struct dm_io_region *dests,
  488. unsigned int flags, dm_kcopyd_notify_fn fn, void *context)
  489. {
  490. struct kcopyd_job *job;
  491. /*
  492. * Allocate an array of jobs consisting of one master job
  493. * followed by SPLIT_COUNT sub jobs.
  494. */
  495. job = mempool_alloc(kc->job_pool, GFP_NOIO);
  496. /*
  497. * set up for the read.
  498. */
  499. job->kc = kc;
  500. job->flags = flags;
  501. job->read_err = 0;
  502. job->write_err = 0;
  503. job->num_dests = num_dests;
  504. memcpy(&job->dests, dests, sizeof(*dests) * num_dests);
  505. if (from) {
  506. job->source = *from;
  507. job->pages = NULL;
  508. job->rw = READ;
  509. } else {
  510. memset(&job->source, 0, sizeof job->source);
  511. job->source.count = job->dests[0].count;
  512. job->pages = &zero_page_list;
  513. job->rw = WRITE;
  514. }
  515. job->fn = fn;
  516. job->context = context;
  517. job->master_job = job;
  518. if (job->source.count <= SUB_JOB_SIZE)
  519. dispatch_job(job);
  520. else {
  521. mutex_init(&job->lock);
  522. job->progress = 0;
  523. split_job(job);
  524. }
  525. return 0;
  526. }
  527. EXPORT_SYMBOL(dm_kcopyd_copy);
  528. int dm_kcopyd_zero(struct dm_kcopyd_client *kc,
  529. unsigned num_dests, struct dm_io_region *dests,
  530. unsigned flags, dm_kcopyd_notify_fn fn, void *context)
  531. {
  532. return dm_kcopyd_copy(kc, NULL, num_dests, dests, flags, fn, context);
  533. }
  534. EXPORT_SYMBOL(dm_kcopyd_zero);
  535. void *dm_kcopyd_prepare_callback(struct dm_kcopyd_client *kc,
  536. dm_kcopyd_notify_fn fn, void *context)
  537. {
  538. struct kcopyd_job *job;
  539. job = mempool_alloc(kc->job_pool, GFP_NOIO);
  540. memset(job, 0, sizeof(struct kcopyd_job));
  541. job->kc = kc;
  542. job->fn = fn;
  543. job->context = context;
  544. job->master_job = job;
  545. atomic_inc(&kc->nr_jobs);
  546. return job;
  547. }
  548. EXPORT_SYMBOL(dm_kcopyd_prepare_callback);
  549. void dm_kcopyd_do_callback(void *j, int read_err, unsigned long write_err)
  550. {
  551. struct kcopyd_job *job = j;
  552. struct dm_kcopyd_client *kc = job->kc;
  553. job->read_err = read_err;
  554. job->write_err = write_err;
  555. push(&kc->complete_jobs, job);
  556. wake(kc);
  557. }
  558. EXPORT_SYMBOL(dm_kcopyd_do_callback);
  559. /*
  560. * Cancels a kcopyd job, eg. someone might be deactivating a
  561. * mirror.
  562. */
  563. #if 0
  564. int kcopyd_cancel(struct kcopyd_job *job, int block)
  565. {
  566. /* FIXME: finish */
  567. return -1;
  568. }
  569. #endif /* 0 */
  570. /*-----------------------------------------------------------------
  571. * Client setup
  572. *---------------------------------------------------------------*/
  573. struct dm_kcopyd_client *dm_kcopyd_client_create(void)
  574. {
  575. int r = -ENOMEM;
  576. struct dm_kcopyd_client *kc;
  577. kc = kmalloc(sizeof(*kc), GFP_KERNEL);
  578. if (!kc)
  579. return ERR_PTR(-ENOMEM);
  580. spin_lock_init(&kc->job_lock);
  581. INIT_LIST_HEAD(&kc->complete_jobs);
  582. INIT_LIST_HEAD(&kc->io_jobs);
  583. INIT_LIST_HEAD(&kc->pages_jobs);
  584. kc->job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
  585. if (!kc->job_pool)
  586. goto bad_slab;
  587. INIT_WORK(&kc->kcopyd_work, do_work);
  588. kc->kcopyd_wq = alloc_workqueue("kcopyd",
  589. WQ_NON_REENTRANT | WQ_MEM_RECLAIM, 0);
  590. if (!kc->kcopyd_wq)
  591. goto bad_workqueue;
  592. kc->pages = NULL;
  593. kc->nr_reserved_pages = kc->nr_free_pages = 0;
  594. r = client_reserve_pages(kc, RESERVE_PAGES);
  595. if (r)
  596. goto bad_client_pages;
  597. kc->io_client = dm_io_client_create();
  598. if (IS_ERR(kc->io_client)) {
  599. r = PTR_ERR(kc->io_client);
  600. goto bad_io_client;
  601. }
  602. init_waitqueue_head(&kc->destroyq);
  603. atomic_set(&kc->nr_jobs, 0);
  604. return kc;
  605. bad_io_client:
  606. client_free_pages(kc);
  607. bad_client_pages:
  608. destroy_workqueue(kc->kcopyd_wq);
  609. bad_workqueue:
  610. mempool_destroy(kc->job_pool);
  611. bad_slab:
  612. kfree(kc);
  613. return ERR_PTR(r);
  614. }
  615. EXPORT_SYMBOL(dm_kcopyd_client_create);
  616. void dm_kcopyd_client_destroy(struct dm_kcopyd_client *kc)
  617. {
  618. /* Wait for completion of all jobs submitted by this client. */
  619. wait_event(kc->destroyq, !atomic_read(&kc->nr_jobs));
  620. BUG_ON(!list_empty(&kc->complete_jobs));
  621. BUG_ON(!list_empty(&kc->io_jobs));
  622. BUG_ON(!list_empty(&kc->pages_jobs));
  623. destroy_workqueue(kc->kcopyd_wq);
  624. dm_io_client_destroy(kc->io_client);
  625. client_free_pages(kc);
  626. mempool_destroy(kc->job_pool);
  627. kfree(kc);
  628. }
  629. EXPORT_SYMBOL(dm_kcopyd_client_destroy);