[Devel] [PATCH RH8 4/5] ploop: Close race in ploop_flip_upper_deltas()
Kirill Tkhai
ktkhai at virtuozzo.com
Thu Jun 17 18:08:44 MSK 2021
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
drivers/md/dm-ploop-cmd.c | 3 +--
drivers/md/dm-ploop-target.c | 34 ++++++++++++++++++++++++++++++++++
drivers/md/dm-ploop.h | 2 ++
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/drivers/md/dm-ploop-cmd.c b/drivers/md/dm-ploop-cmd.c
index 38b0ad40815e..2afe909171d8 100644
--- a/drivers/md/dm-ploop-cmd.c
+++ b/drivers/md/dm-ploop-cmd.c
@@ -1153,10 +1153,9 @@ static int ploop_set_noresume(struct ploop *ploop, char *mode)
static int ploop_flip_upper_deltas(struct ploop *ploop)
{
- struct dm_target *ti = ploop->ti;
struct file *file;
- if (!dm_suspended(ti) || !ploop->noresume || ploop->maintaince)
+ if (!ploop->suspended || !ploop->noresume || ploop->maintaince)
return -EBUSY;
if (ploop_is_ro(ploop))
return -EROFS;
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index 848e099d03a7..da241509af3b 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -411,6 +411,25 @@ static void ploop_status(struct dm_target *ti, status_type_t type,
read_unlock_irq(&ploop->bat_rwlock);
}
+static void ploop_set_suspended(struct dm_target *ti, bool suspended)
+{
+ struct ploop *ploop = ti->private;
+
+ down_read(&ploop->ctl_rwsem);
+ ploop->suspended = suspended;
+ up_read(&ploop->ctl_rwsem);
+}
+
+static void ploop_presuspend(struct dm_target *ti)
+{
+}
+static void ploop_presuspend_undo(struct dm_target *ti)
+{
+}
+static void ploop_postsuspend(struct dm_target *ti)
+{
+ ploop_set_suspended(ti, true);
+}
static int ploop_preresume(struct dm_target *ti)
{
struct ploop *ploop = ti->private;
@@ -420,8 +439,19 @@ static int ploop_preresume(struct dm_target *ti)
if (ploop->noresume)
ret = -EAGAIN;
up_read(&ploop->ctl_rwsem);
+
+ if (ret == 0) {
+ /*
+ * We are singleton target. There will be
+ * no more reasons to break resume.
+ */
+ ploop_set_suspended(ti, false);
+ }
return ret;
}
+static void ploop_resume(struct dm_target *ti)
+{
+}
/*----------------------------------------------------------------*/
@@ -434,7 +464,11 @@ static struct target_type ploop_target = {
.dtr = ploop_dtr,
.message = ploop_message,
.io_hints = ploop_io_hints,
+ .presuspend = ploop_presuspend,
+ .presuspend_undo = ploop_presuspend_undo,
+ .postsuspend = ploop_postsuspend,
.preresume = ploop_preresume,
+ .resume = ploop_resume,
.clone_and_map_rq = ploop_clone_and_map,
.status = ploop_status,
};
diff --git a/drivers/md/dm-ploop.h b/drivers/md/dm-ploop.h
index d0f1493e12e6..143060d6cadf 100644
--- a/drivers/md/dm-ploop.h
+++ b/drivers/md/dm-ploop.h
@@ -185,6 +185,8 @@ struct ploop {
/* Resume is prohibited */
bool noresume;
+ /* Device is suspended */
+ bool suspended;
/* Maintaince in process */
bool maintaince;
More information about the Devel
mailing list