[rh8,4/7] ploop: Care about timeout on discard

Submitted by Kirill Tkhai on March 10, 2020, 12:16 p.m.

Details

Message ID 158384258895.212417.10405276231158675754.stgit@localhost.localdomain
State New
Series "ploop: Make service operations care about timeout"
Headers show

Commit Message

Kirill Tkhai March 10, 2020, 12:16 p.m.
Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/md/dm-ploop-map.c    |   11 ++++++++++-
 drivers/md/dm-ploop-target.c |    1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/drivers/md/dm-ploop-map.c b/drivers/md/dm-ploop-map.c
index d7cc5f078e14..07659fdf88f5 100644
--- a/drivers/md/dm-ploop-map.c
+++ b/drivers/md/dm-ploop-map.c
@@ -418,8 +418,10 @@  static void handle_discard_bio(struct ploop *ploop, struct bio *bio,
 	struct dm_ploop_endio_hook *h = bio_to_endio_hook(bio);
 	struct dm_ploop_endio_hook *inflight_h;
 	unsigned long flags;
+	int ret;
 
 	if (!cluster_is_in_top_delta(ploop, cluster) || ploop->nr_deltas) {
+enotsupp:
 		bio->bi_status = BLK_STS_NOTSUPP;
 		bio_endio(bio);
 		return;
@@ -437,7 +439,14 @@  static void handle_discard_bio(struct ploop *ploop, struct bio *bio,
 		 */
 		ploop->force_link_inflight_bios = true;
 		force_defer_bio_count_inc(ploop);
-		ploop_inflight_bios_ref_switch(ploop, false);
+		ret = ploop_inflight_bios_ref_switch(ploop, true);
+		if (ret) {
+			pr_err_ratelimited("ploop: discard ignored by err=%d\n",
+					ret);
+			ploop->force_link_inflight_bios = false;
+			force_defer_bio_count_dec(ploop);
+			goto enotsupp;
+		}
 	}
 
 	spin_lock_irqsave(&ploop->deferred_lock, flags);
diff --git a/drivers/md/dm-ploop-target.c b/drivers/md/dm-ploop-target.c
index bdeee2334499..546056e7e6d6 100644
--- a/drivers/md/dm-ploop-target.c
+++ b/drivers/md/dm-ploop-target.c
@@ -126,6 +126,7 @@  static int ploop_ctr(struct dm_target *ti, unsigned int argc, char **argv)
 	atomic_set(&ploop->nr_discard_bios, 0);
 
 	INIT_WORK(&ploop->worker, do_ploop_work);
+	init_completion(&ploop->inflight_bios_ref_comp);
 
 	for (i = 0; i < 2; i++) {
 		release = i ? inflight_bios_ref_exit1 : inflight_bios_ref_exit0;