#define DMF_DELETING 4
#define DMF_NOFLUSH_SUSPENDING 5
+/*
+ * Work processed by per-device workqueue.
+ */
+struct dm_wq_req {
+ enum {
+ DM_WQ_FLUSH_ALL,
+ DM_WQ_FLUSH_DEFERRED,
+ } type;
+ struct work_struct work;
+ struct mapped_device *md;
+ void *context;
+};
+
struct mapped_device {
struct rw_semaphore io_lock;
struct mutex suspend_lock;
struct bio_list deferred;
struct bio_list pushback;
+ /*
+ * Processing queue (flush/barriers)
+ */
+ struct workqueue_struct *wq;
+
/*
* The current mapping.
*/
dm_target_init,
dm_linear_init,
dm_stripe_init,
+ dm_kcopyd_init,
dm_interface_init,
};
dm_target_exit,
dm_linear_exit,
dm_stripe_exit,
+ dm_kcopyd_exit,
dm_interface_exit,
};
/*
* See if the device with a specific minor # is free.
*/
-static int specific_minor(struct mapped_device *md, int minor)
+static int specific_minor(int minor)
{
int r, m;
return r;
}
-static int next_free_minor(struct mapped_device *md, int *minor)
+static int next_free_minor(int *minor)
{
int r, m;
spin_lock(&_minor_lock);
r = idr_get_new(&_minor_idr, MINOR_ALLOCED, &m);
- if (r) {
+ if (r)
goto out;
- }
if (m >= (1 << MINORBITS)) {
idr_remove(&_minor_idr, m);
static struct mapped_device *alloc_dev(int minor)
{
int r;
- struct mapped_device *md = kmalloc(sizeof(*md), GFP_KERNEL);
+ struct mapped_device *md = kzalloc(sizeof(*md), GFP_KERNEL);
void *old_md;
if (!md) {
/* get a minor number for the dev */
if (minor == DM_ANY_MINOR)
- r = next_free_minor(md, &minor);
+ r = next_free_minor(&minor);
else
- r = specific_minor(md, minor);
+ r = specific_minor(minor);
if (r < 0)
goto bad_minor;
- memset(md, 0, sizeof(*md));
init_rwsem(&md->io_lock);
mutex_init(&md->suspend_lock);
spin_lock_init(&md->pushback_lock);
add_disk(md->disk);
format_dev_t(md->name, MKDEV(_major, minor));
+ md->wq = create_singlethread_workqueue("kdmflush");
+ if (!md->wq)
+ goto bad_thread;
+
/* Populate the mapping, nobody knows we exist yet */
spin_lock(&_minor_lock);
old_md = idr_replace(&_minor_idr, md, minor);
return md;
+bad_thread:
+ put_disk(md->disk);
bad_disk:
bioset_free(md->bs);
bad_no_bioset:
unlock_fs(md);
bdput(md->suspended_bdev);
}
+ destroy_workqueue(md->wq);
mempool_destroy(md->tio_pool);
mempool_destroy(md->io_pool);
bioset_free(md->bs);
spin_unlock_irqrestore(&md->pushback_lock, flags);
}
+static void dm_wq_work(struct work_struct *work)
+{
+ struct dm_wq_req *req = container_of(work, struct dm_wq_req, work);
+ struct mapped_device *md = req->md;
+
+ down_write(&md->io_lock);
+ switch (req->type) {
+ case DM_WQ_FLUSH_ALL:
+ __merge_pushback_list(md);
+ /* pass through */
+ case DM_WQ_FLUSH_DEFERRED:
+ __flush_deferred_io(md);
+ break;
+ default:
+ DMERR("dm_wq_work: unrecognised work type %d", req->type);
+ BUG();
+ }
+ up_write(&md->io_lock);
+}
+
+static void dm_wq_queue(struct mapped_device *md, int type, void *context,
+ struct dm_wq_req *req)
+{
+ req->type = type;
+ req->md = md;
+ req->context = context;
+ INIT_WORK(&req->work, dm_wq_work);
+ queue_work(md->wq, &req->work);
+}
+
+static void dm_queue_flush(struct mapped_device *md, int type, void *context)
+{
+ struct dm_wq_req req;
+
+ dm_wq_queue(md, type, context, &req);
+ flush_workqueue(md->wq);
+}
+
/*
* Swap in a new table (destroying old one).
*/
/* were we interrupted ? */
if (r < 0) {
- down_write(&md->io_lock);
- __flush_deferred_io(md);
- up_write(&md->io_lock);
+ dm_queue_flush(md, DM_WQ_FLUSH_DEFERRED, NULL);
unlock_fs(md);
goto out; /* pushback list is already flushed, so skip flush */
set_bit(DMF_SUSPENDED, &md->flags);
flush_and_out:
- if (r && noflush) {
+ if (r && noflush)
/*
* Because there may be already I/Os in the pushback list,
* flush them before return.
*/
- down_write(&md->io_lock);
- __merge_pushback_list(md);
- __flush_deferred_io(md);
- up_write(&md->io_lock);
- }
+ dm_queue_flush(md, DM_WQ_FLUSH_ALL, NULL);
out:
if (r && md->suspended_bdev) {
if (r)
goto out;
- down_write(&md->io_lock);
- __flush_deferred_io(md);
- up_write(&md->io_lock);
+ dm_queue_flush(md, DM_WQ_FLUSH_DEFERRED, NULL);
unlock_fs(md);