A request failed under the enospc or stop policy cannot stay held
across a suspend: the suspend waits for it to complete. So presuspend
retries the held requests once, and a request that fails again is
completed with its error. A table reload or a snapshot taken while the
VM is paused on a held request then delivers the error that the policy
was meant to keep from the guest.

On a noflush suspend, requeue such a request to the dm queue instead.
It is dispatched through the new table on resume and is held again if
the error persists. This follows dm-mpath, which requeues on a noflush
suspend and fails the I/O queued for no paths on a flush suspend.

The noflush mode is recorded in presuspend rather than read with
dm_noflush_suspending(): an interrupted suspend clears
DMF_NOFLUSH_SUSPENDING and restarts the queue before presuspend_undo
runs, and a request failing in between would get its error although
the suspend was cancelled.

The request is requeued with a delay, as dm-mpath does for the no-path
case: until the queue is stopped, or after an interrupted suspend
restarts it, a request that keeps failing would otherwise be dispatched
and requeued in a loop. dm_requeue_original_rq() gets a delay argument
for that.

Requeued requests keep the device open: their submitter cannot drop
its last reference until they complete, so a remove fails with EBUSY
until the device is resumed with a working table or with an error
table, as dmsetup remove --force does. dm-mpath with queue_if_no_path
behaves the same way.

fail_held fails with EBUSY during a noflush suspend: the requeued
requests are out of the target's reach, and the flag would not
survive a table reload. Userspace sends it again after resume.

https://virtuozzo.atlassian.net/browse/VSTOR-152175
Feature: dm-qcow2: block device over QCOW2 files driver
Signed-off-by: Alexander Ivanov <[email protected]>
---
 drivers/md/dm-push-backup.c  |  2 +-
 drivers/md/dm-qcow2-cmd.c    |  6 +++---
 drivers/md/dm-qcow2-map.c    | 22 +++++++++++++++++++---
 drivers/md/dm-qcow2-target.c |  2 ++
 drivers/md/dm-qcow2.h        |  3 ++-
 drivers/md/dm-rq.c           |  4 ++--
 drivers/md/dm-rq.h           |  2 +-
 7 files changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/md/dm-push-backup.c b/drivers/md/dm-push-backup.c
index 4f6dc1f3c130..ca1f623f56a7 100644
--- a/drivers/md/dm-push-backup.c
+++ b/drivers/md/dm-push-backup.c
@@ -218,7 +218,7 @@ static void resubmit_pbios(struct push_backup *pb, struct 
list_head *list)
 
                list_del_init(&pbio->list);
                mempool_free(pbio, pb->pbio_pool);
-               dm_requeue_original_rq(rq);
+               dm_requeue_original_rq(rq, false);
        }
 }
 
diff --git a/drivers/md/dm-qcow2-cmd.c b/drivers/md/dm-qcow2-cmd.c
index 6a56919bec73..9106ce65d355 100644
--- a/drivers/md/dm-qcow2-cmd.c
+++ b/drivers/md/dm-qcow2-cmd.c
@@ -660,9 +660,9 @@ int qcow2_message(struct dm_target *ti, unsigned int argc, 
char **argv,
                        ret = -EINVAL;
                        goto out;
                }
-               timer_delete(&tgt->held_timer);
-               qcow2_fail_held_qios(tgt);
-               ret = 0;
+               ret = qcow2_fail_held_qios(tgt);
+               if (!ret)
+                       timer_delete(&tgt->held_timer);
                goto out;
        } else if (!strcmp(argv[0], "merge_backward")) {
                if (argc < 2) {
diff --git a/drivers/md/dm-qcow2-map.c b/drivers/md/dm-qcow2-map.c
index adbebe728f99..830e3af28730 100644
--- a/drivers/md/dm-qcow2-map.c
+++ b/drivers/md/dm-qcow2-map.c
@@ -4570,7 +4570,8 @@ static bool qcow2_try_hold_error(struct qcow2_target 
*tgt, struct qcow2_rq *qrq,
                                 struct qio *qio, blk_status_t bi_status)
 {
        bool write = op_is_write(qio->bi_op) || qio->bi_op == REQ_OP_FLUSH;
-       bool held = true, first = false;
+       bool held = true, first = false, requeue = false;
+       struct request *rq = qrq->rq;
        unsigned long flags;
        u8 policy;
 
@@ -4584,7 +4585,10 @@ static bool qcow2_try_hold_error(struct qcow2_target 
*tgt, struct qcow2_rq *qrq,
 
        spin_lock_irqsave(&tgt->event_lock, flags);
        if (unlikely(tgt->wants_suspend || tgt->fail_held)) {
-               held = false;
+               if (!tgt->fail_held && tgt->noflush_suspend)
+                       requeue = true;
+               else
+                       held = false;
                goto unlock;
        }
 
@@ -4613,6 +4617,12 @@ static bool qcow2_try_hold_error(struct qcow2_target 
*tgt, struct qcow2_rq *qrq,
 unlock:
        spin_unlock_irqrestore(&tgt->event_lock, flags);
 
+       if (requeue) {
+               mempool_free(qrq, tgt->qrq_pool);
+               dm_requeue_original_rq(rq, true);
+               return true;
+       }
+
        if (first)
                mod_timer(&tgt->held_timer, jiffies + HOLD_TIMEOUT_JI);
        schedule_work(&tgt->event_work);
@@ -4717,7 +4727,7 @@ void qcow2_resubmit_held_qios(struct qcow2_target *tgt)
        qcow2_submit_embedded_qios(tgt, &list);
 }
 
-void qcow2_fail_held_qios(struct qcow2_target *tgt)
+int qcow2_fail_held_qios(struct qcow2_target *tgt)
 {
        struct qcow2_rq *qrq;
        struct request *rq;
@@ -4725,6 +4735,10 @@ void qcow2_fail_held_qios(struct qcow2_target *tgt)
        LIST_HEAD(list);
 
        spin_lock_irq(&tgt->event_lock);
+       if (tgt->noflush_suspend) {
+               spin_unlock_irq(&tgt->event_lock);
+               return -EBUSY;
+       }
        tgt->fail_held = true;
        list_splice_init(&tgt->held_qios, &list);
        spin_unlock_irq(&tgt->event_lock);
@@ -4735,6 +4749,8 @@ void qcow2_fail_held_qios(struct qcow2_target *tgt)
                dm_complete_request(rq, qrq->held_status);
                mempool_free(qrq, tgt->qrq_pool);
        }
+
+       return 0;
 }
 
 int qcow2_clone_and_map(struct dm_target *ti, struct request *rq,
diff --git a/drivers/md/dm-qcow2-target.c b/drivers/md/dm-qcow2-target.c
index b3365f92c7dd..dd74e7c84b75 100644
--- a/drivers/md/dm-qcow2-target.c
+++ b/drivers/md/dm-qcow2-target.c
@@ -36,6 +36,7 @@ static void qcow2_set_wants_suspend(struct dm_target *ti, 
bool wants)
 
        spin_lock_irq(&tgt->event_lock);
        tgt->wants_suspend = wants;
+       tgt->noflush_suspend = wants && dm_noflush_suspending(ti);
        spin_unlock_irq(&tgt->event_lock);
 }
 
@@ -1289,6 +1290,7 @@ static int qcow2_preresume(struct dm_target *ti)
                spin_lock_irq(&tgt->event_lock);
                tgt->fail_held = false;
                tgt->wants_suspend = false;
+               tgt->noflush_suspend = false;
                spin_unlock_irq(&tgt->event_lock);
        }
 
diff --git a/drivers/md/dm-qcow2.h b/drivers/md/dm-qcow2.h
index cd73314ee28c..6b719113aeb6 100644
--- a/drivers/md/dm-qcow2.h
+++ b/drivers/md/dm-qcow2.h
@@ -212,6 +212,7 @@ struct qcow2_target {
 
        bool service_operations_allowed;
        bool wants_suspend;
+       bool noflush_suspend;
        bool fail_held;
        bool md_writeback_error;
        bool truncate_error;
@@ -439,7 +440,7 @@ void qcow2_dispatch_qios(struct qcow2 *qcow2, struct qio 
*qio,
                   struct list_head *qio_list);
 void qcow2_submit_embedded_qios(struct qcow2_target *tgt, struct list_head 
*list);
 void qcow2_resubmit_held_qios(struct qcow2_target *tgt);
-void qcow2_fail_held_qios(struct qcow2_target *tgt);
+int qcow2_fail_held_qios(struct qcow2_target *tgt);
 struct qcow2 *qcow2_ref_inc(struct qcow2_target *tgt, u8 *ref_index);
 void qcow2_ref_dec(struct qcow2_target *tgt, u8 ref_index);
 int qcow2_inflight_ref_switch(struct qcow2_target *tgt);
diff --git a/drivers/md/dm-rq.c b/drivers/md/dm-rq.c
index 5a8cd59ec257..b2fb6f853a41 100644
--- a/drivers/md/dm-rq.c
+++ b/drivers/md/dm-rq.c
@@ -204,11 +204,11 @@ static void dm_requeue_original_request(struct 
dm_rq_target_io *tio, bool delay_
        rq_completed(md);
 }
 
-void dm_requeue_original_rq(struct request *rq)
+void dm_requeue_original_rq(struct request *rq, bool delay)
 {
        struct dm_rq_target_io *tio = tio_from_request(rq);
 
-       dm_requeue_original_request(tio, false);
+       dm_requeue_original_request(tio, delay);
 }
 EXPORT_SYMBOL(dm_requeue_original_rq);
 
diff --git a/drivers/md/dm-rq.h b/drivers/md/dm-rq.h
index 53abc3cf9aee..d04cdb8adda2 100644
--- a/drivers/md/dm-rq.h
+++ b/drivers/md/dm-rq.h
@@ -46,6 +46,6 @@ ssize_t dm_attr_rq_based_seq_io_merge_deadline_store(struct 
mapped_device *md,
                                                     const char *buf, size_t 
count);
 
 void dm_complete_request(struct request *rq, blk_status_t error);
-void dm_requeue_original_rq(struct request *rq);
+void dm_requeue_original_rq(struct request *rq, bool delay);
 
 #endif
-- 
2.53.0

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to