[Devel] [PATCH RHEL9 COMMIT] dm-zero-req: Introduce zero request based target

Konstantin Khorenko khorenko at virtuozzo.com
Wed Apr 13 19:06:11 MSK 2022


The commit is pushed to "branch-rh9-5.14.0-42.vz9.14.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-42.vz9.14.7
------>
commit a1bfd9a511eab6407b07547ba2d0eca8f4e032ba
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Thu Mar 31 20:28:15 2022 +0300

    dm-zero-req: Introduce zero request based target
    
    This driver is like "dm-zero", but request based rather than bio based
    like original "dm-zero".
    
    This driver will be used on a block device for Container configuration
    stage: we need to construct a block device which honors CBT mask (stored
    in ploop image), for that first we need to create a dummy block device
    (pure technical issue, otherwise CBT mask is dropped).
    
    dm-ploop/dm-qcow2 are request based, thus we need zero target
    also to be request based.
    
    https://jira.sw.ru/browse/PSBM-134130
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    Feature: cbt: changed block tracking (for backup)
---
 drivers/md/Makefile      |  1 +
 drivers/md/dm-zero-req.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 92 insertions(+)

diff --git a/drivers/md/Makefile b/drivers/md/Makefile
index 94134440cf70..3197d24c0e75 100644
--- a/drivers/md/Makefile
+++ b/drivers/md/Makefile
@@ -76,6 +76,7 @@ obj-$(CONFIG_DM_PERSISTENT_DATA) += persistent-data/
 obj-$(CONFIG_DM_MIRROR)		+= dm-mirror.o dm-log.o dm-region-hash.o
 obj-$(CONFIG_DM_LOG_USERSPACE)	+= dm-log-userspace.o
 obj-$(CONFIG_DM_ZERO)		+= dm-zero.o
+obj-$(CONFIG_DM_ZERO)		+= dm-zero-req.o
 obj-$(CONFIG_DM_RAID)		+= dm-raid.o
 obj-$(CONFIG_DM_THIN_PROVISIONING) += dm-thin-pool.o
 obj-$(CONFIG_DM_VERITY)		+= dm-verity.o
diff --git a/drivers/md/dm-zero-req.c b/drivers/md/dm-zero-req.c
new file mode 100644
index 000000000000..9e44de15dcd6
--- /dev/null
+++ b/drivers/md/dm-zero-req.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (C) 2003 Jana Saout <jana at saout.de>
+ *
+ * This file is released under the GPL.
+ */
+
+#include <linux/device-mapper.h>
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/bio.h>
+#include <linux/blk-mq.h>
+#include "dm-rq.h"
+
+#define DM_MSG_PREFIX "zero"
+
+/*
+ * Construct a dummy mapping that only returns zeros
+ */
+static int zero_ctr(struct dm_target *ti, unsigned int argc, char **argv)
+{
+	if (argc != 0) {
+		ti->error = "No arguments required";
+		return -EINVAL;
+	}
+
+	/*
+	 * Silently drop discards, avoiding -EOPNOTSUPP.
+	 */
+	ti->num_discard_bios = 1;
+
+	return 0;
+}
+
+static int zero_clone_and_map_rq(struct dm_target *ti, struct request *rq,
+				 union map_info *map_context,
+				 struct request **clone)
+{
+	struct bio *bio = rq->bio;
+
+	switch (bio_op(bio)) {
+	case REQ_OP_READ:
+		while (bio) {
+			zero_fill_bio(bio);
+			bio = bio->bi_next;
+		}
+
+		break;
+	case REQ_OP_WRITE:
+		/* writes get silently dropped */
+		break;
+	default:
+		return DM_MAPIO_KILL;
+	}
+
+	dm_complete_request(rq, BLK_STS_OK);
+
+	/* accepted rq, don't make new request */
+	return DM_MAPIO_SUBMITTED;
+}
+
+static struct target_type zero_target = {
+	.name   = "zero-rq",
+	.version = {1, 1, 0},
+	.features = DM_TARGET_NOWAIT,
+	.module = THIS_MODULE,
+	.ctr    = zero_ctr,
+	.clone_and_map_rq = zero_clone_and_map_rq,
+};
+
+static int __init dm_zero_init(void)
+{
+	int r = dm_register_target(&zero_target);
+
+	if (r < 0)
+		DMERR("register failed %d", r);
+
+	return r;
+}
+
+static void __exit dm_zero_exit(void)
+{
+	dm_unregister_target(&zero_target);
+}
+
+module_init(dm_zero_init)
+module_exit(dm_zero_exit)
+
+MODULE_AUTHOR("Jana Saout <jana at saout.de>");
+MODULE_DESCRIPTION(DM_NAME " dummy request based target returning zeros");
+MODULE_LICENSE("GPL");


More information about the Devel mailing list