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>
14 #define DM_MSG_PREFIX "target"
16 static LIST_HEAD(_targets
);
17 static DECLARE_RWSEM(_lock
);
19 static inline struct target_type
*__find_target_type(const char *name
)
21 struct target_type
*tt
;
23 list_for_each_entry(tt
, &_targets
, list
)
24 if (!strcmp(name
, tt
->name
))
30 static struct target_type
*get_target_type(const char *name
)
32 struct target_type
*tt
;
36 tt
= __find_target_type(name
);
37 if (tt
&& !try_module_get(tt
->module
))
44 static void load_module(const char *name
)
46 request_module("dm-%s", name
);
49 struct target_type
*dm_get_target_type(const char *name
)
51 struct target_type
*tt
= get_target_type(name
);
55 tt
= get_target_type(name
);
61 void dm_put_target_type(struct target_type
*tt
)
64 module_put(tt
->module
);
68 int dm_target_iterate(void (*iter_func
)(struct target_type
*tt
,
69 void *param
), void *param
)
71 struct target_type
*tt
;
74 list_for_each_entry(tt
, &_targets
, list
)
81 int dm_register_target(struct target_type
*tt
)
86 if (__find_target_type(tt
->name
))
89 list_add(&tt
->list
, &_targets
);
95 void dm_unregister_target(struct target_type
*tt
)
98 if (!__find_target_type(tt
->name
)) {
99 DMCRIT("Unregistering unrecognised target: %s", tt
->name
);
109 * io-err: always fails an io, useful for bringing
110 * up LVs that have holes in them.
112 static int io_err_ctr(struct dm_target
*tt
, unsigned int argc
, char **args
)
115 * Return error for discards instead of -EOPNOTSUPP
117 tt
->num_discard_bios
= 1;
122 static void io_err_dtr(struct dm_target
*tt
)
127 static int io_err_map(struct dm_target
*tt
, struct bio
*bio
)
129 return DM_MAPIO_KILL
;
132 static int io_err_clone_and_map_rq(struct dm_target
*ti
, struct request
*rq
,
133 union map_info
*map_context
,
134 struct request
**clone
)
136 return DM_MAPIO_KILL
;
139 static void io_err_release_clone_rq(struct request
*clone
,
140 union map_info
*map_context
)
144 static long io_err_dax_direct_access(struct dm_target
*ti
, pgoff_t pgoff
,
145 long nr_pages
, void **kaddr
, pfn_t
*pfn
)
150 static struct target_type error_target
= {
152 .version
= {1, 5, 0},
153 .features
= DM_TARGET_WILDCARD
,
157 .clone_and_map_rq
= io_err_clone_and_map_rq
,
158 .release_clone_rq
= io_err_release_clone_rq
,
159 .direct_access
= io_err_dax_direct_access
,
162 int __init
dm_target_init(void)
164 return dm_register_target(&error_target
);
167 void dm_target_exit(void)
169 dm_unregister_target(&error_target
);
172 EXPORT_SYMBOL(dm_register_target
);
173 EXPORT_SYMBOL(dm_unregister_target
);