[RHEL7,COMMIT] ploop: Move queue autoconfiguration into add delta stage

Submitted by Vasily Averin on Sept. 4, 2020, 7:30 a.m.

Details

Message ID 202009040730.0847Uqpv024739@vz7build.vvs.sw.ru
State New
Series "ploop: Rework queue_settings autoconfig and allow fuse 4K discard"
Headers show

Commit Message

Vasily Averin Sept. 4, 2020, 7:30 a.m.
The commit is pushed to "branch-rh7-3.10.0-1127.18.2.vz7.163.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.18.2.vz7.163.16
------>
commit bab720d334c786d4e813ae4a14c7d8641204784b
Author: Kirill Tkhai <ktkhai@virtuozzo.com>
Date:   Fri Sep 4 10:30:52 2020 +0300

    ploop: Move queue autoconfiguration into add delta stage
    
    The period after addition of last delta and start of device
    will be the time to configure and to configure and to overwrite
    discard defaults from userspace.
    
    So, we move queue autoconfiguration (default settings assignment)
    to add delta stage.
    
    https://jira.sw.ru/browse/PSBM-107598
    Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 drivers/block/ploop/dev.c   | 32 ++++++++++++++++++++++++++------
 drivers/block/ploop/sysfs.c |  5 +++++
 2 files changed, 31 insertions(+), 6 deletions(-)

Patch hide | download patch | download mbox

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 07226e7..86689f29 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -3386,6 +3386,21 @@  static int ploop_set_max_delta_size(struct ploop_device *plo, unsigned long arg)
 	return 0;
 }
 
+static void autoconfigure_queue_settings(struct ploop_device *plo)
+{
+	struct ploop_delta *top_delta = ploop_top_delta(plo);
+	struct request_queue *q = plo->queue;
+
+	if (test_bit(PLOOP_S_RUNNING, &plo->state))
+		return;
+
+	plo->force_split_discard_reqs = false;
+	blk_set_default_limits(&q->limits);
+	top_delta->io.ops->queue_settings(&top_delta->io, q);
+	/* REQ_WRITE_SAME is not supported */
+	blk_queue_max_write_same_sectors(q, 0);
+}
+
 static int ploop_add_delta(struct ploop_device * plo, unsigned long arg)
 {
 	int err;
@@ -3451,6 +3466,17 @@  static int ploop_add_delta(struct ploop_device * plo, unsigned long arg)
 	mutex_unlock(&plo->sysfs_mutex);
 	set_bit(PLOOP_S_CHANGED, &plo->state);
 
+	/*
+	 * Inherit queue settings from top_delta. This is called every time
+	 * a new delta is added. We do not call this once in ploop_start(),
+	 * because of period between last delta addition and ploop start
+	 * is time to overwrite autoconfigured deraults from userspace
+	 * (e.g., to disable maintaince mode based discard).
+	 * We can't allow to overwrite after start, since we populate
+	 * holes_bitmap in ploop1 on start, and it depends on selected
+	 * discard mode.
+	 */
+	autoconfigure_queue_settings(plo);
 	return 0;
 
 out_close:
@@ -4215,12 +4241,6 @@  static int ploop_start(struct ploop_device * plo, struct block_device *bdev)
 	blk_queue_merge_bvec(q, ploop_merge_bvec);
 	blk_queue_flush(q, REQ_FLUSH);
 
-	plo->force_split_discard_reqs = false;
-	blk_set_default_limits(&q->limits);
-	top_delta->io.ops->queue_settings(&top_delta->io, q);
-	/* REQ_WRITE_SAME is not supported */
-	blk_queue_max_write_same_sectors(q, 0);
-
 	queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
 	queue_flag_clear_unlocked(QUEUE_FLAG_STANDBY, q);
 
diff --git a/drivers/block/ploop/sysfs.c b/drivers/block/ploop/sysfs.c
index 9a1c01d..ccf8ecc 100644
--- a/drivers/block/ploop/sysfs.c
+++ b/drivers/block/ploop/sysfs.c
@@ -381,6 +381,11 @@  static int store_discard_granularity(struct ploop_device *plo, u32 val)
 	int ret = 0;
 
 	mutex_lock(&plo->ctl_mutex);
+	if (test_bit(PLOOP_S_RUNNING, &plo->state)) {
+		ret = -EBUSY;
+		goto unlock;
+	}
+
 	q = plo->queue;
 	if (val == q->limits.discard_granularity)
 		goto unlock;