2 * Copyright (C) 2001 Sistina Software (UK) Limited
4 * This file is released under the GPL.
9 #include <linux/module.h>
10 #include <linux/kmod.h>
11 #include <linux/bio.h>
12 #include <linux/slab.h>
15 struct target_type tt;
17 struct list_head list;
21 static LIST_HEAD(_targets);
22 static DECLARE_RWSEM(_lock);
24 #define DM_MOD_NAME_SIZE 32
26 static inline struct tt_internal *__find_target_type(const char *name)
28 struct tt_internal *ti;
30 list_for_each_entry (ti, &_targets, list)
31 if (!strcmp(name, ti->tt.name))
37 static struct tt_internal *get_target_type(const char *name)
39 struct tt_internal *ti;
43 ti = __find_target_type(name);
45 if ((ti->use == 0) && !try_module_get(ti->tt.module))
55 static void load_module(const char *name)
57 request_module("dm-%s", name);
60 struct target_type *dm_get_target_type(const char *name)
62 struct tt_internal *ti = get_target_type(name);
66 ti = get_target_type(name);
69 return ti ? &ti->tt : NULL;
72 void dm_put_target_type(struct target_type *t)
74 struct tt_internal *ti = (struct tt_internal *) t;
78 module_put(ti->tt.module);
87 static struct tt_internal *alloc_target(struct target_type *t)
89 struct tt_internal *ti = kmalloc(sizeof(*ti), GFP_KERNEL);
92 memset(ti, 0, sizeof(*ti));
100 int dm_target_iterate(void (*iter_func)(struct target_type *tt,
101 void *param), void *param)
103 struct tt_internal *ti;
106 list_for_each_entry (ti, &_targets, list)
107 iter_func(&ti->tt, param);
113 int dm_register_target(struct target_type *t)
116 struct tt_internal *ti = alloc_target(t);
122 if (__find_target_type(t->name)) {
126 list_add(&ti->list, &_targets);
134 int dm_unregister_target(struct target_type *t)
136 struct tt_internal *ti;
139 if (!(ti = __find_target_type(t->name))) {
157 * io-err: always fails an io, useful for bringing
158 * up LVs that have holes in them.
160 static int io_err_ctr(struct dm_target *ti, unsigned int argc, char **args)
165 static void io_err_dtr(struct dm_target *ti)
170 static int io_err_map(struct dm_target *ti, struct bio *bio,
171 union map_info *map_context)
176 static struct target_type error_target = {
178 .version = {1, 0, 1},
184 int dm_target_init(void)
186 return dm_register_target(&error_target);
189 void dm_target_exit(void)
191 if (dm_unregister_target(&error_target))
192 DMWARN("error target unregistration failed");
195 EXPORT_SYMBOL(dm_register_target);
196 EXPORT_SYMBOL(dm_unregister_target);