[rh7,11/12] ploop: Introduce ploop_can_issue_discard() helper

Submitted by Kirill Tkhai on March 1, 2019, 3:14 p.m.

Details

Message ID 155145326097.8852.8700777704435923179.stgit@localhost.localdomain
State New
Series "ploop: Add online discard support for dio engine"
Headers show

Commit Message

Kirill Tkhai March 1, 2019, 3:14 p.m.
Logical neighbouring blocks usually are not physically
neighbours, so we can issue discard only for a single
block.

This is the basis. Later we may introduce some performance
improvements for corner cases on top of this.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/dev.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index bf508a9b1bc8..518b52e8f0d0 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -2525,6 +2525,18 @@  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;
+
+	return whole_block(plo, preq);
+}
+
 static void ploop_req_state_process(struct ploop_request * preq)
 {
 	struct ploop_device * plo = preq->plo;
@@ -2604,8 +2616,7 @@  static void ploop_req_state_process(struct ploop_request * preq)
 		}
 
 		if ((preq->req_rw & REQ_DISCARD) &&
-		    !test_bit(PLOOP_REQ_DISCARD, &preq->state) &&
-		    test_bit(PLOOP_S_NO_FALLOC_DISCARD, &plo->state)) {
+		    !ploop_can_issue_discard(plo, preq)) {
 			preq->eng_state = PLOOP_E_COMPLETE;
 			preq->error = -EOPNOTSUPP;
 			ploop_complete_io_state(preq);