ploop: Skip repeated discard

Submitted by Kirill Tkhai on March 14, 2019, 11:30 a.m.

Details

Message ID 155256300036.18691.17884368763973251054.stgit@localhost.localdomain
State New
Series "ploop: Skip repeated discard"
Headers show

Commit Message

Kirill Tkhai March 14, 2019, 11:30 a.m.
We can't issue repeated discard in the same place,
so this patch prohibits it.

Otherwise there will be an allocation with
zero size page:

ploop_request::req_rw = REQ_WRITE|REQ_DISCARD

struct bio_vec {
  bv_page = 0x0,
  bv_len = 0,
  bv_offset = 0
}

This hunk strangly went in the second part of patches unsent.

https://jira.sw.ru/browse/PSBM-92656

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

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 518b52e8f0d0..6349f0d556be 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -2173,6 +2173,14 @@  void ploop_add_req_to_fsync_queue(struct ploop_request * preq)
 	spin_unlock_irq(&plo->lock);
 }
 
+static void
+complete_unsupported_discard_req(struct ploop_request * preq)
+{
+	preq->eng_state = PLOOP_E_COMPLETE;
+	preq->error = -EOPNOTSUPP;
+	ploop_complete_io_state(preq);
+}
+
 static void
 ploop_entry_request(struct ploop_request * preq)
 {
@@ -2482,6 +2490,12 @@  ploop_entry_request(struct ploop_request * preq)
 						      &sbl, iblk, cluster_size_in_sec(plo));
 			}
 		} else {
+			if (unlikely(preq->req_rw & REQ_DISCARD)) {
+				/* Skip repeated discard */
+				complete_unsupported_discard_req(preq);
+				return;
+			}
+
 			if (!whole_block(plo, preq) && map_index_fault(preq) == 0) {
 					__TRACE("f %p %u\n", preq, preq->req_cluster);
 					return;
@@ -2617,9 +2631,7 @@  static void ploop_req_state_process(struct ploop_request * preq)
 
 		if ((preq->req_rw & REQ_DISCARD) &&
 		    !ploop_can_issue_discard(plo, preq)) {
-			preq->eng_state = PLOOP_E_COMPLETE;
-			preq->error = -EOPNOTSUPP;
-			ploop_complete_io_state(preq);
+			complete_unsupported_discard_req(preq);
 #ifdef CONFIG_BEANCOUNTERS
 			if (saved_ub) {
 				saved_ub = set_exec_ub(saved_ub);