Commit e7a3e871d8954c636b6cd2db7c7ece7ffe405986

Authored by Joe Thornber
Committed by Mike Snitzer
1 parent 298eaa89b0

dm thin: cleanup noflush_work to use a proper completion

Factor out a pool_work interface that noflush_work makes use of to wait
for and complete work items (in terms of a proper completion struct).
Allows discontinuing the use of a custom completion in terms of atomic_t
and wait_event.

Signed-off-by: Joe Thornber <ejt@redhat.com>
Signed-off-by: Mike Snitzer <snitzer@redhat.com>

Showing 1 changed file with 34 additions and 18 deletions Side-by-side Diff

drivers/md/dm-thin.c
... ... @@ -1610,47 +1610,63 @@
1610 1610  
1611 1611 /*----------------------------------------------------------------*/
1612 1612  
1613   -struct noflush_work {
  1613 +struct pool_work {
1614 1614 struct work_struct worker;
1615   - struct thin_c *tc;
  1615 + struct completion complete;
  1616 +};
1616 1617  
1617   - atomic_t complete;
1618   - wait_queue_head_t wait;
  1618 +static struct pool_work *to_pool_work(struct work_struct *ws)
  1619 +{
  1620 + return container_of(ws, struct pool_work, worker);
  1621 +}
  1622 +
  1623 +static void pool_work_complete(struct pool_work *pw)
  1624 +{
  1625 + complete(&pw->complete);
  1626 +}
  1627 +
  1628 +static void pool_work_wait(struct pool_work *pw, struct pool *pool,
  1629 + void (*fn)(struct work_struct *))
  1630 +{
  1631 + INIT_WORK_ONSTACK(&pw->worker, fn);
  1632 + init_completion(&pw->complete);
  1633 + queue_work(pool->wq, &pw->worker);
  1634 + wait_for_completion(&pw->complete);
  1635 +}
  1636 +
  1637 +/*----------------------------------------------------------------*/
  1638 +
  1639 +struct noflush_work {
  1640 + struct pool_work pw;
  1641 + struct thin_c *tc;
1619 1642 };
1620 1643  
1621   -static void complete_noflush_work(struct noflush_work *w)
  1644 +static struct noflush_work *to_noflush(struct work_struct *ws)
1622 1645 {
1623   - atomic_set(&w->complete, 1);
1624   - wake_up(&w->wait);
  1646 + return container_of(to_pool_work(ws), struct noflush_work, pw);
1625 1647 }
1626 1648  
1627 1649 static void do_noflush_start(struct work_struct *ws)
1628 1650 {
1629   - struct noflush_work *w = container_of(ws, struct noflush_work, worker);
  1651 + struct noflush_work *w = to_noflush(ws);
1630 1652 w->tc->requeue_mode = true;
1631 1653 requeue_io(w->tc);
1632   - complete_noflush_work(w);
  1654 + pool_work_complete(&w->pw);
1633 1655 }
1634 1656  
1635 1657 static void do_noflush_stop(struct work_struct *ws)
1636 1658 {
1637   - struct noflush_work *w = container_of(ws, struct noflush_work, worker);
  1659 + struct noflush_work *w = to_noflush(ws);
1638 1660 w->tc->requeue_mode = false;
1639   - complete_noflush_work(w);
  1661 + pool_work_complete(&w->pw);
1640 1662 }
1641 1663  
1642 1664 static void noflush_work(struct thin_c *tc, void (*fn)(struct work_struct *))
1643 1665 {
1644 1666 struct noflush_work w;
1645 1667  
1646   - INIT_WORK_ONSTACK(&w.worker, fn);
1647 1668 w.tc = tc;
1648   - atomic_set(&w.complete, 0);
1649   - init_waitqueue_head(&w.wait);
1650   -
1651   - queue_work(tc->pool->wq, &w.worker);
1652   -
1653   - wait_event(w.wait, atomic_read(&w.complete));
  1669 + pool_work_wait(&w.pw, tc->pool, fn);
1654 1670 }
1655 1671  
1656 1672 /*----------------------------------------------------------------*/