2 * Copyright (C) 2001 Sistina Software (UK) Limited
4 * This file is released under the GPL.
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/kmod.h>
12 #include <linux/bio.h>
13 #include <linux/dax.h>
15 #define DM_MSG_PREFIX "target"
17 static LIST_HEAD(_targets);
18 static DECLARE_RWSEM(_lock);
20 static inline struct target_type *__find_target_type(const char *name)
22 struct target_type *tt;
24 list_for_each_entry(tt, &_targets, list)
25 if (!strcmp(name, tt->name))
31 static struct target_type *get_target_type(const char *name)
33 struct target_type *tt;
37 tt = __find_target_type(name);
38 if (tt && !try_module_get(tt->module))
45 static void load_module(const char *name)
47 request_module("dm-%s", name);
50 struct target_type *dm_get_target_type(const char *name)
52 struct target_type *tt = get_target_type(name);
56 tt = get_target_type(name);
62 void dm_put_target_type(struct target_type *tt)
65 module_put(tt->module);
69 int dm_target_iterate(void (*iter_func)(struct target_type *tt,
70 void *param), void *param)
72 struct target_type *tt;
75 list_for_each_entry(tt, &_targets, list)
82 int dm_register_target(struct target_type *tt)
87 if (__find_target_type(tt->name))
90 list_add(&tt->list, &_targets);
96 void dm_unregister_target(struct target_type *tt)
99 if (!__find_target_type(tt->name)) {
100 DMCRIT("Unregistering unrecognised target: %s", tt->name);
110 * io-err: always fails an io, useful for bringing
111 * up LVs that have holes in them.
113 static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
116 * Return error for discards instead of -EOPNOTSUPP
118 tt->num_discard_bios = 1;
123 static void io_err_dtr(struct dm_target *tt)
128 static int io_err_map(struct dm_target *tt, struct bio *bio)
130 return DM_MAPIO_KILL;
133 static int io_err_clone_and_map_rq(struct dm_target *ti, struct request *rq,
134 union map_info *map_context,
135 struct request **clone)
137 return DM_MAPIO_KILL;
140 static void io_err_release_clone_rq(struct request *clone,
141 union map_info *map_context)
145 static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
146 long nr_pages, enum dax_access_mode mode, void **kaddr,
152 static struct target_type error_target = {
154 .version = {1, 5, 0},
155 .features = DM_TARGET_WILDCARD,
159 .clone_and_map_rq = io_err_clone_and_map_rq,
160 .release_clone_rq = io_err_release_clone_rq,
161 .direct_access = io_err_dax_direct_access,
164 int __init dm_target_init(void)
166 return dm_register_target(&error_target);
169 void dm_target_exit(void)
171 dm_unregister_target(&error_target);
174 EXPORT_SYMBOL(dm_register_target);
175 EXPORT_SYMBOL(dm_unregister_target);