wait_queue_head_t destroyq;
atomic_t nr_jobs;
+ mempool_t *job_pool;
+
struct workqueue_struct *kcopyd_wq;
struct work_struct kcopyd_work;
#define MIN_JOBS 512
static struct kmem_cache *_job_cache;
-static mempool_t *_job_pool;
static int jobs_init(void)
{
if (!_job_cache)
return -ENOMEM;
- _job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
- if (!_job_pool) {
- kmem_cache_destroy(_job_cache);
- return -ENOMEM;
- }
-
return 0;
}
static void jobs_exit(void)
{
- mempool_destroy(_job_pool);
kmem_cache_destroy(_job_cache);
- _job_pool = NULL;
_job_cache = NULL;
}
struct dm_kcopyd_client *kc = job->kc;
kcopyd_put_pages(kc, job->pages);
- mempool_free(job, _job_pool);
+ mempool_free(job, kc->job_pool);
fn(read_err, write_err, context);
if (atomic_dec_and_test(&kc->nr_jobs))
if (count) {
int i;
- struct kcopyd_job *sub_job = mempool_alloc(_job_pool, GFP_NOIO);
+ struct kcopyd_job *sub_job = mempool_alloc(job->kc->job_pool,
+ GFP_NOIO);
*sub_job = *job;
sub_job->source.sector += progress;
* after we've completed.
*/
job->fn(read_err, write_err, job->context);
- mempool_free(job, _job_pool);
+ mempool_free(job, job->kc->job_pool);
}
}
/*
* Allocate a new job.
*/
- job = mempool_alloc(_job_pool, GFP_NOIO);
+ job = mempool_alloc(kc->job_pool, GFP_NOIO);
/*
* set up for the read.
INIT_LIST_HEAD(&kc->io_jobs);
INIT_LIST_HEAD(&kc->pages_jobs);
+ kc->job_pool = mempool_create_slab_pool(MIN_JOBS, _job_cache);
+ if (!kc->job_pool) {
+ r = -ENOMEM;
+ kfree(kc);
+ kcopyd_exit();
+ return r;
+ }
+
INIT_WORK(&kc->kcopyd_work, do_work);
kc->kcopyd_wq = create_singlethread_workqueue("kcopyd");
if (!kc->kcopyd_wq) {
r = -ENOMEM;
+ mempool_destroy(kc->job_pool);
kfree(kc);
kcopyd_exit();
return r;
r = client_alloc_pages(kc, nr_pages);
if (r) {
destroy_workqueue(kc->kcopyd_wq);
+ mempool_destroy(kc->job_pool);
kfree(kc);
kcopyd_exit();
return r;
r = PTR_ERR(kc->io_client);
client_free_pages(kc);
destroy_workqueue(kc->kcopyd_wq);
+ mempool_destroy(kc->job_pool);
kfree(kc);
kcopyd_exit();
return r;
dm_io_client_destroy(kc->io_client);
client_free_pages(kc);
client_del(kc);
+ mempool_destroy(kc->job_pool);
kfree(kc);
kcopyd_exit();
}