ploop: Enable native discard support for kaio engine

Submitted by Kirill Tkhai on April 26, 2019, 1:46 p.m.

Details

Message ID 155628640341.24333.8063753950956062906.stgit@localhost.localdomain
State New
Series "ploop: Enable native discard support for kaio engine"
Headers show

Commit Message

Kirill Tkhai April 26, 2019, 1:46 p.m.
This enabled native discard support for kaio engine
in the way we have for direct engine.
Since io->prealloced_size is never initialized,
here small workaround to handle this case.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/fmt_ploop1.c |    3 ---
 drivers/block/ploop/io_kaio.c    |   17 +++++++++++++++--
 include/linux/ploop/ploop.h      |    2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 32437175dadb..2ae22179c9c5 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -271,9 +271,6 @@  ploop1_open(struct ploop_delta * delta)
 	    ((u64)ph->bd_size + ph->l1_off) << 9)
 		delta->flags |= PLOOP_FMT_PREALLOCATED;
 
-	if (delta->io.ops->id != PLOOP_IO_DIRECT)
-		set_bit(PLOOP_S_NO_FALLOC_DISCARD, &delta->plo->state);
-
 	return 0;
 
 out_err:
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index 5b97ed73611e..2bd5b6e176f5 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -552,7 +552,8 @@  kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
 {
 	int log = preq->plo->cluster_log + 9;
 	loff_t clu_siz = 1 << log;
-	loff_t end_pos = (loff_t)io->alloc_head << log;
+	loff_t end_pos = (loff_t)(iblk + 1) << log;
+	loff_t isize;
 
 	if (unlikely(preq->req_rw & REQ_FLUSH)) {
 		spin_lock_irq(&io->plo->lock);
@@ -565,6 +566,18 @@  kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
 	BUG_ON(preq->prealloc_size);
 
 	if (unlikely(io->prealloced_size < end_pos + clu_siz)) {
+		isize = i_size_read(io->files.inode);
+		/*
+		 * FIXME: We never initialize io->prealloced_size,
+		 * and it can be 0 here. The below actualizes it.
+		 * This should be reworked in more natural way.
+		 */
+		if (unlikely(io->prealloced_size < isize)) {
+			io->prealloced_size = isize;
+			if (io->prealloced_size >= end_pos + clu_siz)
+				goto submit;
+		}
+
 		if (!io->prealloc_preq) {
 			loff_t pos = (((loff_t)(iblk + 1)  << log) |
 				      (KAIO_PREALLOC - 1)) + 1;
@@ -584,7 +597,7 @@  kaio_submit_alloc(struct ploop_io *io, struct ploop_request * preq,
 			return 0;
 		}
 	}
-
+submit:
 	preq->iblock = iblk;
 	preq->eng_state = PLOOP_E_DATA_WBI;
 
diff --git a/include/linux/ploop/ploop.h b/include/linux/ploop/ploop.h
index 230c51ecba87..ea6df68634a5 100644
--- a/include/linux/ploop/ploop.h
+++ b/include/linux/ploop/ploop.h
@@ -52,7 +52,7 @@  enum {
 	PLOOP_S_ENOSPC_EVENT,	/* ENOSPC event happened but but was not
 				 * consumed by userspace yet */
 	PLOOP_S_CONGESTED,	/* Too many bios submitted to us */
-	PLOOP_S_NO_FALLOC_DISCARD, /* Unable to handle discard requests by fallocate */
+	PLOOP_S_NO_FALLOC_DISCARD, /* FIXME: Remove this: Unable to handle discard requests by fallocate */
 	PLOOP_S_DISCARD,	/* ploop is ready to handle discard request */
 	PLOOP_S_DISCARD_LOADED,	/* A discard request was handled and
 				   free blocks loaded */