Skip to content

Commit d67ee21

Browse files
committed
dm: add presuspend_undo hook to target_type
The DM thin-pool target now must undo the changes performed during pool_presuspend() so introduce presuspend_undo hook in target_type. Signed-off-by: Mike Snitzer <[email protected]> Acked-by: Joe Thornber <[email protected]>
1 parent 4d341d8 commit d67ee21

File tree

5 files changed

+42
-11
lines changed

5 files changed

+42
-11
lines changed

drivers/md/dm-table.c

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,18 +1521,32 @@ fmode_t dm_table_get_mode(struct dm_table *t)
15211521
}
15221522
EXPORT_SYMBOL(dm_table_get_mode);
15231523

1524-
static void suspend_targets(struct dm_table *t, unsigned postsuspend)
1524+
enum suspend_mode {
1525+
PRESUSPEND,
1526+
PRESUSPEND_UNDO,
1527+
POSTSUSPEND,
1528+
};
1529+
1530+
static void suspend_targets(struct dm_table *t, enum suspend_mode mode)
15251531
{
15261532
int i = t->num_targets;
15271533
struct dm_target *ti = t->targets;
15281534

15291535
while (i--) {
1530-
if (postsuspend) {
1536+
switch (mode) {
1537+
case PRESUSPEND:
1538+
if (ti->type->presuspend)
1539+
ti->type->presuspend(ti);
1540+
break;
1541+
case PRESUSPEND_UNDO:
1542+
if (ti->type->presuspend_undo)
1543+
ti->type->presuspend_undo(ti);
1544+
break;
1545+
case POSTSUSPEND:
15311546
if (ti->type->postsuspend)
15321547
ti->type->postsuspend(ti);
1533-
} else if (ti->type->presuspend)
1534-
ti->type->presuspend(ti);
1535-
1548+
break;
1549+
}
15361550
ti++;
15371551
}
15381552
}
@@ -1542,15 +1556,23 @@ void dm_table_presuspend_targets(struct dm_table *t)
15421556
if (!t)
15431557
return;
15441558

1545-
suspend_targets(t, 0);
1559+
suspend_targets(t, PRESUSPEND);
1560+
}
1561+
1562+
void dm_table_presuspend_undo_targets(struct dm_table *t)
1563+
{
1564+
if (!t)
1565+
return;
1566+
1567+
suspend_targets(t, PRESUSPEND_UNDO);
15461568
}
15471569

15481570
void dm_table_postsuspend_targets(struct dm_table *t)
15491571
{
15501572
if (!t)
15511573
return;
15521574

1553-
suspend_targets(t, 1);
1575+
suspend_targets(t, POSTSUSPEND);
15541576
}
15551577

15561578
int dm_table_resume_targets(struct dm_table *t)

drivers/md/dm.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2756,7 +2756,10 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
27562756
if (noflush)
27572757
set_bit(DMF_NOFLUSH_SUSPENDING, &md->flags);
27582758

2759-
/* This does not get reverted if there's an error later. */
2759+
/*
2760+
* This gets reverted if there's an error later and the targets
2761+
* provide the .presuspend_undo hook.
2762+
*/
27602763
dm_table_presuspend_targets(map);
27612764

27622765
/*
@@ -2767,8 +2770,10 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
27672770
*/
27682771
if (!noflush && do_lockfs) {
27692772
r = lock_fs(md);
2770-
if (r)
2773+
if (r) {
2774+
dm_table_presuspend_undo_targets(map);
27712775
goto out_unlock;
2776+
}
27722777
}
27732778

27742779
/*
@@ -2816,6 +2821,7 @@ int dm_suspend(struct mapped_device *md, unsigned suspend_flags)
28162821
start_queue(md->queue);
28172822

28182823
unlock_fs(md);
2824+
dm_table_presuspend_undo_targets(map);
28192825
goto out_unlock; /* pushback list is already flushed, so skip flush */
28202826
}
28212827

drivers/md/dm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
6565
struct queue_limits *limits);
6666
struct list_head *dm_table_get_devices(struct dm_table *t);
6767
void dm_table_presuspend_targets(struct dm_table *t);
68+
void dm_table_presuspend_undo_targets(struct dm_table *t);
6869
void dm_table_postsuspend_targets(struct dm_table *t);
6970
int dm_table_resume_targets(struct dm_table *t);
7071
int dm_table_any_congested(struct dm_table *t, int bdi_bits);

include/linux/device-mapper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ typedef int (*dm_request_endio_fn) (struct dm_target *ti,
6464
union map_info *map_context);
6565

6666
typedef void (*dm_presuspend_fn) (struct dm_target *ti);
67+
typedef void (*dm_presuspend_undo_fn) (struct dm_target *ti);
6768
typedef void (*dm_postsuspend_fn) (struct dm_target *ti);
6869
typedef int (*dm_preresume_fn) (struct dm_target *ti);
6970
typedef void (*dm_resume_fn) (struct dm_target *ti);
@@ -145,6 +146,7 @@ struct target_type {
145146
dm_endio_fn end_io;
146147
dm_request_endio_fn rq_end_io;
147148
dm_presuspend_fn presuspend;
149+
dm_presuspend_undo_fn presuspend_undo;
148150
dm_postsuspend_fn postsuspend;
149151
dm_preresume_fn preresume;
150152
dm_resume_fn resume;

include/uapi/linux/dm-ioctl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,9 @@ enum {
267267
#define DM_DEV_SET_GEOMETRY _IOWR(DM_IOCTL, DM_DEV_SET_GEOMETRY_CMD, struct dm_ioctl)
268268

269269
#define DM_VERSION_MAJOR 4
270-
#define DM_VERSION_MINOR 28
270+
#define DM_VERSION_MINOR 29
271271
#define DM_VERSION_PATCHLEVEL 0
272-
#define DM_VERSION_EXTRA "-ioctl (2014-09-17)"
272+
#define DM_VERSION_EXTRA "-ioctl (2014-10-28)"
273273

274274
/* Status bits */
275275
#define DM_READONLY_FLAG (1 << 0) /* In/Out */

0 commit comments

Comments
 (0)