[dm-devel] [PATCH] 2.4: dm-zero
Kevin Corry
kevcorry at us.ibm.com
Wed Dec 3 11:36:01 UTC 2003
dm-zero target. Provides a block-device version of /dev/zero. This target was
originally written by Christophe Saout (http://www.saout.de/misc/) for 2.6.
I've backported it to 2.4. This patch is against device-mapper-1.00.07.
diff -Naur linux-2.4.22-dm-1.00.07/drivers/md/Makefile linux/drivers/md/Makefile
--- linux-2.4.22-dm-1.00.07/drivers/md/Makefile 2003-12-03 11:06:25.000000000 -0600
+++ linux/drivers/md/Makefile 2003-12-03 10:56:22.000000000 -0600
@@ -11,7 +11,7 @@
lvm-mod-objs := lvm.o lvm-snap.o lvm-fs.o
dm-mod-objs := dm.o dm-table.o dm-target.o dm-ioctl.o \
dm-linear.o dm-stripe.o dm-snapshot.o dm-exception-store.o \
- kcopyd.o dm-daemon.o dm-io.o
+ kcopyd.o dm-daemon.o dm-io.o dm-zero.o
dm-mirror-mod-objs := dm-raid1.o dm-log.o
# Note: link order is important. All raid personalities
diff -Naur linux-2.4.22-dm-1.00.07/drivers/md/dm-zero.c linux/drivers/md/dm-zero.c
--- linux-2.4.22-dm-1.00.07/drivers/md/dm-zero.c 1969-12-31 18:00:00.000000000 -0600
+++ linux/drivers/md/dm-zero.c 2003-12-03 11:05:49.000000000 -0600
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) Christophe Saout <christophe at saout.de>, 2003
+ *
+ * This file is released under the GPL.
+ */
+
+#include "dm.h"
+
+#include <linux/module.h>
+#include <linux/init.h>
+
+/*
+ * 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 = "dm-zero: No arguments required";
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+/*
+ * Return zeros only on reads
+ */
+static int zero_map(struct dm_target *ti, struct buffer_head *bh, int rw,
+ union map_info *map_context)
+{
+ switch(rw) {
+ case READ:
+ memset(bh->b_data, 0, bh->b_size);
+ break;
+ case READA:
+ /* readahead of null bytes only wastes buffer cache */
+ return -EIO;
+ case WRITE:
+ /* writes get silently dropped */
+ break;
+ }
+
+ if (bh->b_end_io)
+ bh->b_end_io(bh, 1);
+
+ /* accepted bh, don't make new request */
+ return 0;
+}
+
+static struct target_type zero_target = {
+ .name = "zero",
+ .module = THIS_MODULE,
+ .ctr = zero_ctr,
+ .map = zero_map,
+};
+
+int dm_zero_init(void)
+{
+ int r = dm_register_target(&zero_target);
+
+ if (r < 0)
+ DMERR("zero: register failed %d", r);
+
+ return r;
+}
+
+void dm_zero_exit(void)
+{
+ int r = dm_unregister_target(&zero_target);
+
+ if (r < 0)
+ DMERR("zero: unregister failed %d", r);
+}
+
diff -Naur linux-2.4.22-dm-1.00.07/drivers/md/dm.c linux/drivers/md/dm.c
--- linux-2.4.22-dm-1.00.07/drivers/md/dm.c 2003-12-03 11:06:25.000000000 -0600
+++ linux/drivers/md/dm.c 2003-12-03 10:56:48.000000000 -0600
@@ -370,6 +370,7 @@
xx(dm_stripe)
xx(dm_snapshot)
xx(dm_interface)
+ xx(dm_zero)
#undef xx
};
diff -Naur linux-2.4.22-dm-1.00.07/drivers/md/dm.h linux/drivers/md/dm.h
--- linux-2.4.22-dm-1.00.07/drivers/md/dm.h 2003-12-03 11:06:25.000000000 -0600
+++ linux/drivers/md/dm.h 2003-12-03 10:59:33.000000000 -0600
@@ -172,4 +172,7 @@
int dm_snapshot_init(void);
void dm_snapshot_exit(void);
+int dm_zero_init(void);
+void dm_zero_exit(void);
+
#endif
More information about the dm-devel
mailing list