ploop: Add check that ploop don't grow endlessly

Submitted by Kirill Tkhai on April 12, 2019, 10:17 a.m.

Details

Message ID 155506423127.3292.3518806026921592999.stgit@localhost.localdomain
State New
Series "ploop: Add check that ploop don't grow endlessly"
Headers show

Commit Message

Kirill Tkhai April 12, 2019, 10:17 a.m.
Even during resize, ploop can must follow limitations.
Add a sanity check for that.

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

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/fmt_ploop1.c b/drivers/block/ploop/fmt_ploop1.c
index 738b96cb48f1..32c9a08e0e84 100644
--- a/drivers/block/ploop/fmt_ploop1.c
+++ b/drivers/block/ploop/fmt_ploop1.c
@@ -315,8 +315,10 @@  ploop1_allocate(struct ploop_delta * delta, struct ploop_request * preq,
 		struct bio_list * sbl, unsigned int size)
 {
 	struct ploop1_private * ph = delta->priv;
-	unsigned int max_size;
+	unsigned int log = delta->cluster_log;
+	struct ploop_device *plo = delta->plo;
 	cluster_t cluster = 0;
+	u64 max_size;
 	int ret;
 
 	if (delta->holes_bitmap) {
@@ -327,7 +329,13 @@  ploop1_allocate(struct ploop_delta * delta, struct ploop_request * preq,
 			cluster = 0; /* grow in process? */
 	}
 
-	max_size = (delta->max_delta_size >> delta->cluster_log);
+	max_size = delta->max_delta_size;
+	if (plo->maintenance_type == PLOOP_MNTN_GROW) {
+		/* Even in case of resize, alloc_head can't grow endlessly */
+		max_size = min(plo->grow_new_size >> 9, max_size);
+	}
+	max_size = max_size >> log;
+
 	if (!cluster && delta->io.alloc_head >= max_size) {
 		PLOOP_FAIL_REQUEST(preq, -E2BIG);
 		return;