[Devel] [PATCH 1/2] ploop: Do not forget to put io context

Kirill Tkhai ktkhai at virtuozzo.com
Thu Mar 21 13:14:46 MSK 2019


We have to put saved_ioc before we return from
this ploop_req_state_process(). Otherwise, it
becomes leaked.

So, move discard check into ploop_entry_request(),
and then just go by generic way to bottom of
ploop_req_state_process().

This is not connected with recent discard changes,
and it should go to RK too (small adoptation is
required).

Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
 drivers/block/ploop/dev.c |   48 ++++++++++++++++++++-------------------------
 1 file changed, 21 insertions(+), 27 deletions(-)

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 26745d9fc81f..f8b9b0bcba78 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -2181,6 +2181,21 @@ complete_unsupported_discard_req(struct ploop_request * preq)
 	ploop_complete_io_state(preq);
 }
 
+static bool ploop_can_issue_discard(struct ploop_device *plo,
+				    struct ploop_request *preq)
+{
+	if (test_bit(PLOOP_REQ_DISCARD, &preq->state))
+		return true;
+
+	if (test_bit(PLOOP_S_NO_FALLOC_DISCARD, &plo->state))
+		return false;
+
+	if (!list_is_singular(&plo->map.delta_list))
+		return false;
+
+	return whole_block(plo, preq);
+}
+
 static void
 ploop_entry_request(struct ploop_request * preq)
 {
@@ -2192,6 +2207,12 @@ ploop_entry_request(struct ploop_request * preq)
 	int err;
 	iblock_t iblk;
 
+	if ((preq->req_rw & REQ_DISCARD) &&
+	    !ploop_can_issue_discard(plo, preq)) {
+		complete_unsupported_discard_req(preq);
+		return;
+	}
+
 	if (!preq_is_special(preq)) {
 		/* Control request */
 		if (unlikely(preq->bl.head == NULL)) {
@@ -2539,21 +2560,6 @@ ploop_entry_request(struct ploop_request * preq)
 	PLOOP_REQ_FAIL_IMMEDIATE(preq, err);
 }
 
-static bool ploop_can_issue_discard(struct ploop_device *plo,
-				    struct ploop_request *preq)
-{
-	if (test_bit(PLOOP_REQ_DISCARD, &preq->state))
-		return true;
-
-	if (test_bit(PLOOP_S_NO_FALLOC_DISCARD, &plo->state))
-		return false;
-
-	if (!list_is_singular(&plo->map.delta_list))
-		return false;
-
-	return whole_block(plo, preq);
-}
-
 static void ploop_req_state_process(struct ploop_request * preq)
 {
 	struct ploop_device * plo = preq->plo;
@@ -2632,18 +2638,6 @@ static void ploop_req_state_process(struct ploop_request * preq)
 			break;
 		}
 
-		if ((preq->req_rw & REQ_DISCARD) &&
-		    !ploop_can_issue_discard(plo, preq)) {
-			complete_unsupported_discard_req(preq);
-#ifdef CONFIG_BEANCOUNTERS
-			if (saved_ub) {
-				saved_ub = set_exec_ub(saved_ub);
-				put_beancounter(saved_ub);
-			}
-#endif
-			return;
-		}
-
 		ploop_entry_request(preq);
 		break;
 



More information about the Devel mailing list