[Devel] [RFC PATCH vz7] Only perform standby check when enabled on the target.

Alexander Atanasov alexander.atanasov at virtuozzo.com
Thu Oct 20 13:51:41 MSK 2022


Add static key enabled via module parameter when running on
mixed mode systems and standby enable flag on the request queue.
Using the flags perform the check only if required by
the target device. Avoid unwanted side effects and performance impact.

Signed-off-by: Alexander Atanasov <alexander.atanasov at virtuozzo.com>
---
 drivers/block/ploop/dev.c     | 19 ++++++++++++++++---
 drivers/block/ploop/io_kaio.c | 11 ++++++++---
 include/linux/blkdev.h        |  2 ++
 3 files changed, 26 insertions(+), 6 deletions(-)

Cc: Kui Liu <Kui.Liu at acronis.com>
Cc: Alexey Kuznetsov <kuznet at acronis.com>

diff --git a/drivers/block/ploop/dev.c b/drivers/block/ploop/dev.c
index 06b72542633b..bdf0642d2773 100644
--- a/drivers/block/ploop/dev.c
+++ b/drivers/block/ploop/dev.c
@@ -70,6 +70,9 @@ static int native_discard_support __read_mostly = 1;
 int kaio_backed_ext4 __read_mostly = 0;
 EXPORT_SYMBOL(kaio_backed_ext4);
 
+static bool ploop_enable_standby; /* Used when running on specific targets  */
+struct static_key ploop_standby_check = STATIC_KEY_INIT_FALSE;
+
 static struct rb_root ploop_devices_tree = RB_ROOT;
 static DEFINE_MUTEX(ploop_devices_mutex);
 
@@ -985,9 +988,11 @@ static void ploop_make_request(struct request_queue *q, struct bio *bio)
 	hd_struct_put(part);
 	part_stat_unlock();
 
-	if (blk_queue_standby(plo->queue)) {
-		BIO_ENDIO(q, bio, -EIO);
-		return;
+	if (static_key_false(&ploop_standby_check)) {
+		if (blk_queue_standby(plo->queue)) {
+			BIO_ENDIO(q, bio, -EIO);
+			return;
+		}
 	}
 
 	if (unlikely(bio->bi_size == 0)) {
@@ -6043,6 +6048,9 @@ module_param(native_discard_support, int, 0644);
 MODULE_PARM_DESC(native_discard_support, "Native discard support");
 module_param(kaio_backed_ext4, int, 0644);
 MODULE_PARM_DESC(kaio_backed_ext4, "kaio-backed ext4");
+module_param(ploop_enable_standby, bool, 0444);
+MODULE_PARM_DESC(ploop_enable_standby, "Enable blk queue standby mode checks");
+
 
 static int __init ploop_mod_init(void)
 {
@@ -6066,6 +6074,11 @@ static int __init ploop_mod_init(void)
 			 proc_vz_dir, &proc_ploop_minor))
 		goto out_err2;
 
+	if (ploop_enable_standby) {
+		static_key_slow_inc(&ploop_standby_check);
+		pr_info("ploop: standby mode check enabled\n");
+	}
+
 	printk(KERN_INFO "ploop_dev: module loaded\n");
 	return 0;
 
diff --git a/drivers/block/ploop/io_kaio.c b/drivers/block/ploop/io_kaio.c
index e24952703549..a0c28379eb7d 100644
--- a/drivers/block/ploop/io_kaio.c
+++ b/drivers/block/ploop/io_kaio.c
@@ -23,6 +23,7 @@
 
 #define KAIO_MAX_PAGES_PER_REQ 32	  /* 128 KB */
 
+extern struct static_key ploop_standby_check;
 /* This will be used as flag "ploop_kaio_open() succeeded" */
 static struct extent_map_tree
 {
@@ -116,6 +117,9 @@ static void check_standby_mode(long res, struct ploop_device *plo) {
 	struct request_queue *q = plo->queue;
 	int prev;
 
+	if (!blk_queue_standby_en(q))
+		return;
+
 	/* move to standby if delta lease was stolen or mount is gone */
 	if (res != -EBUSY && res != -ENOTCONN && res != -EIO) {
 		return;
@@ -146,8 +150,8 @@ static void kaio_rw_aio_complete(u64 data, long res)
 		bio_list_for_each(b, &preq->bl)
 			printk(" bio=%p: bi_sector=%ld bi_size=%d\n",
 			       b, b->bi_sector, b->bi_size);
-
-		check_standby_mode(res, preq->plo);
+		if (static_key_false(&ploop_standby_check))
+			check_standby_mode(res, preq->plo);
 		PLOOP_REQ_SET_ERROR(preq, res);
 	}
 
@@ -560,7 +564,8 @@ static int kaio_fsync_thread(void * data)
 				       "on ploop%d)\n",
 				       err, io->files.inode->i_ino,
 				       io2level(io), plo->index);
-				check_standby_mode(err, plo);
+				if (static_key_false(&ploop_standby_check))
+					check_standby_mode(err, plo);
 				PLOOP_REQ_SET_ERROR(preq, -EIO);
 			} else if (preq->req_rw & REQ_FLUSH) {
 				BUG_ON(!preq->req_size);
diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
index 4e2970ff97b2..fb6daf0eef7a 100644
--- a/include/linux/blkdev.h
+++ b/include/linux/blkdev.h
@@ -643,6 +643,7 @@ struct request_queue {
 #define QUEUE_FLAG_SCSI_PASSTHROUGH 30	/* queue supports SCSI commands */
 
 #define QUEUE_FLAG_STANDBY     31	/* unable to handle read/write requests */
+#define QUEUE_FLAG_STANDBY_EN  32	/* enable standby queue flag */
 
 #define QUEUE_FLAG_DEFAULT	((1 << QUEUE_FLAG_IO_STAT) |		\
 				 (1 << QUEUE_FLAG_STACKABLE)	|	\
@@ -739,6 +740,7 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
 #define blk_queue_scsi_passthrough(q)	\
 	test_bit(QUEUE_FLAG_SCSI_PASSTHROUGH, &(q)->queue_flags)
 #define blk_queue_standby(q)	test_bit(QUEUE_FLAG_STANDBY, &(q)->queue_flags)
+#define blk_queue_standby_en(q)	test_bit(QUEUE_FLAG_STANDBY_EN, &(q)->queue_flags)
 
 extern int blk_set_preempt_only(struct request_queue *q);
 extern void blk_clear_preempt_only(struct request_queue *q);

base-commit: 726ab1f1d5f51619964a0626187f8aee970d6920
-- 
2.31.1



More information about the Devel mailing list