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 list_head
*tih
;
29 struct tt_internal
*ti
;
31 list_for_each(tih
, &_targets
) {
32 ti
= list_entry(tih
, struct tt_internal
, list
);
34 if (!strcmp(name
, ti
->tt
.name
))
41 static struct tt_internal
*get_target_type(const char *name
)
43 struct tt_internal
*ti
;
47 ti
= __find_target_type(name
);
49 if ((ti
->use
== 0) && !try_module_get(ti
->tt
.module
))
59 static void load_module(const char *name
)
61 request_module("dm-%s", name
);
64 struct target_type
*dm_get_target_type(const char *name
)
66 struct tt_internal
*ti
= get_target_type(name
);
70 ti
= get_target_type(name
);
73 return ti
? &ti
->tt
: NULL
;
76 void dm_put_target_type(struct target_type
*t
)
78 struct tt_internal
*ti
= (struct tt_internal
*) t
;
82 module_put(ti
->tt
.module
);
91 static struct tt_internal
*alloc_target(struct target_type
*t
)
93 struct tt_internal
*ti
= kmalloc(sizeof(*ti
), GFP_KERNEL
);
96 memset(ti
, 0, sizeof(*ti
));
103 int dm_register_target(struct target_type
*t
)
106 struct tt_internal
*ti
= alloc_target(t
);
112 if (__find_target_type(t
->name
))
115 list_add(&ti
->list
, &_targets
);
123 int dm_unregister_target(struct target_type
*t
)
125 struct tt_internal
*ti
;
128 if (!(ti
= __find_target_type(t
->name
))) {
146 * io-err: always fails an io, useful for bringing
147 * up LVs that have holes in them.
149 static int io_err_ctr(struct dm_target
*ti
, int argc
, char **args
)
154 static void io_err_dtr(struct dm_target
*ti
)
159 static int io_err_map(struct dm_target
*ti
, struct bio
*bio
)
164 static struct target_type error_target
= {
171 int dm_target_init(void)
173 return dm_register_target(&error_target
);
176 void dm_target_exit(void)
178 if (dm_unregister_target(&error_target
))
179 DMWARN("error target unregistration failed");
182 EXPORT_SYMBOL(dm_register_target
);
183 EXPORT_SYMBOL(dm_unregister_target
);