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"
18 struct target_type tt
;
20 struct list_head list
;
24 static LIST_HEAD(_targets
);
25 static DECLARE_RWSEM(_lock
);
27 #define DM_MOD_NAME_SIZE 32
29 static inline struct tt_internal
*__find_target_type(const char *name
)
31 struct tt_internal
*ti
;
33 list_for_each_entry (ti
, &_targets
, list
)
34 if (!strcmp(name
, ti
->tt
.name
))
40 static struct tt_internal
*get_target_type(const char *name
)
42 struct tt_internal
*ti
;
46 ti
= __find_target_type(name
);
48 if ((ti
->use
== 0) && !try_module_get(ti
->tt
.module
))
58 static void load_module(const char *name
)
60 request_module("dm-%s", name
);
63 struct target_type
*dm_get_target_type(const char *name
)
65 struct tt_internal
*ti
= get_target_type(name
);
69 ti
= get_target_type(name
);
72 return ti
? &ti
->tt
: NULL
;
75 void dm_put_target_type(struct target_type
*t
)
77 struct tt_internal
*ti
= (struct tt_internal
*) t
;
81 module_put(ti
->tt
.module
);
89 static struct tt_internal
*alloc_target(struct target_type
*t
)
91 struct tt_internal
*ti
= kmalloc(sizeof(*ti
), GFP_KERNEL
);
94 memset(ti
, 0, sizeof(*ti
));
102 int dm_target_iterate(void (*iter_func
)(struct target_type
*tt
,
103 void *param
), void *param
)
105 struct tt_internal
*ti
;
108 list_for_each_entry (ti
, &_targets
, list
)
109 iter_func(&ti
->tt
, param
);
115 int dm_register_target(struct target_type
*t
)
118 struct tt_internal
*ti
= alloc_target(t
);
124 if (__find_target_type(t
->name
))
127 list_add(&ti
->list
, &_targets
);
135 int dm_unregister_target(struct target_type
*t
)
137 struct tt_internal
*ti
;
140 if (!(ti
= __find_target_type(t
->name
))) {
158 * io-err: always fails an io, useful for bringing
159 * up LVs that have holes in them.
161 static int io_err_ctr(struct dm_target
*ti
, unsigned int argc
, char **args
)
166 static void io_err_dtr(struct dm_target
*ti
)
171 static int io_err_map(struct dm_target
*ti
, struct bio
*bio
,
172 union map_info
*map_context
)
177 static struct target_type error_target
= {
179 .version
= {1, 0, 1},
185 int __init
dm_target_init(void)
187 return dm_register_target(&error_target
);
190 void dm_target_exit(void)
192 if (dm_unregister_target(&error_target
))
193 DMWARN("error target unregistration failed");
196 EXPORT_SYMBOL(dm_register_target
);
197 EXPORT_SYMBOL(dm_unregister_target
);