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>
16 struct target_type tt
;
18 struct list_head list
;
22 static LIST_HEAD(_targets
);
23 static DECLARE_RWSEM(_lock
);
25 #define DM_MOD_NAME_SIZE 32
27 static inline struct tt_internal
*__find_target_type(const char *name
)
29 struct tt_internal
*ti
;
31 list_for_each_entry (ti
, &_targets
, list
)
32 if (!strcmp(name
, ti
->tt
.name
))
38 static struct tt_internal
*get_target_type(const char *name
)
40 struct tt_internal
*ti
;
44 ti
= __find_target_type(name
);
46 if ((ti
->use
== 0) && !try_module_get(ti
->tt
.module
))
56 static void load_module(const char *name
)
58 request_module("dm-%s", name
);
61 struct target_type
*dm_get_target_type(const char *name
)
63 struct tt_internal
*ti
= get_target_type(name
);
67 ti
= get_target_type(name
);
70 return ti
? &ti
->tt
: NULL
;
73 void dm_put_target_type(struct target_type
*t
)
75 struct tt_internal
*ti
= (struct tt_internal
*) t
;
79 module_put(ti
->tt
.module
);
88 static struct tt_internal
*alloc_target(struct target_type
*t
)
90 struct tt_internal
*ti
= kmalloc(sizeof(*ti
), GFP_KERNEL
);
93 memset(ti
, 0, sizeof(*ti
));
101 int dm_target_iterate(void (*iter_func
)(struct target_type
*tt
,
102 void *param
), void *param
)
104 struct tt_internal
*ti
;
107 list_for_each_entry (ti
, &_targets
, list
)
108 iter_func(&ti
->tt
, param
);
114 int dm_register_target(struct target_type
*t
)
117 struct tt_internal
*ti
= alloc_target(t
);
123 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 __init
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
);