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/slab.h>
15 #define DM_MSG_PREFIX "target"
17 static LIST_HEAD(_targets);
18 static DECLARE_RWSEM(_lock);
20 #define DM_MOD_NAME_SIZE 32
22 static inline struct target_type *__find_target_type(const char *name)
24 struct target_type *tt;
26 list_for_each_entry(tt, &_targets, list)
27 if (!strcmp(name, tt->name))
33 static struct target_type *get_target_type(const char *name)
35 struct target_type *tt;
39 tt = __find_target_type(name);
40 if (tt && !try_module_get(tt->module))
47 static void load_module(const char *name)
49 request_module("dm-%s", name);
52 struct target_type *dm_get_target_type(const char *name)
54 struct target_type *tt = get_target_type(name);
58 tt = get_target_type(name);
64 void dm_put_target_type(struct target_type *tt)
67 module_put(tt->module);
71 int dm_target_iterate(void (*iter_func)(struct target_type *tt,
72 void *param), void *param)
74 struct target_type *tt;
77 list_for_each_entry(tt, &_targets, list)
84 int dm_register_target(struct target_type *tt)
89 if (__find_target_type(tt->name))
92 list_add(&tt->list, &_targets);
98 void dm_unregister_target(struct target_type *tt)
101 if (!__find_target_type(tt->name)) {
102 DMCRIT("Unregistering unrecognised target: %s", tt->name);
112 * io-err: always fails an io, useful for bringing
113 * up LVs that have holes in them.
115 static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
120 static void io_err_dtr(struct dm_target *tt)
125 static int io_err_map(struct dm_target *tt, struct bio *bio,
126 union map_info *map_context)
131 static struct target_type error_target = {
133 .version = {1, 0, 1},
139 int __init dm_target_init(void)
141 return dm_register_target(&error_target);
144 void dm_target_exit(void)
146 dm_unregister_target(&error_target);
149 EXPORT_SYMBOL(dm_register_target);
150 EXPORT_SYMBOL(dm_unregister_target);