s390/numa: always use logical cpu and core ids
[linux-2.6/btrfs-unstable.git] / drivers / md / dm-target.c
blob710ae28fd618256ea0b1da6fc34c40ae6e473066
1 /*
2 * Copyright (C) 2001 Sistina Software (UK) Limited
4 * This file is released under the GPL.
5 */
7 #include "dm-core.h"
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 #define DM_MOD_NAME_SIZE 32
21 static inline struct target_type *__find_target_type(const char *name)
23 struct target_type *tt;
25 list_for_each_entry(tt, &_targets, list)
26 if (!strcmp(name, tt->name))
27 return tt;
29 return NULL;
32 static struct target_type *get_target_type(const char *name)
34 struct target_type *tt;
36 down_read(&_lock);
38 tt = __find_target_type(name);
39 if (tt && !try_module_get(tt->module))
40 tt = NULL;
42 up_read(&_lock);
43 return tt;
46 static void load_module(const char *name)
48 request_module("dm-%s", name);
51 struct target_type *dm_get_target_type(const char *name)
53 struct target_type *tt = get_target_type(name);
55 if (!tt) {
56 load_module(name);
57 tt = get_target_type(name);
60 return tt;
63 void dm_put_target_type(struct target_type *tt)
65 down_read(&_lock);
66 module_put(tt->module);
67 up_read(&_lock);
70 int dm_target_iterate(void (*iter_func)(struct target_type *tt,
71 void *param), void *param)
73 struct target_type *tt;
75 down_read(&_lock);
76 list_for_each_entry(tt, &_targets, list)
77 iter_func(tt, param);
78 up_read(&_lock);
80 return 0;
83 int dm_register_target(struct target_type *tt)
85 int rv = 0;
87 down_write(&_lock);
88 if (__find_target_type(tt->name))
89 rv = -EEXIST;
90 else
91 list_add(&tt->list, &_targets);
93 up_write(&_lock);
94 return rv;
97 void dm_unregister_target(struct target_type *tt)
99 down_write(&_lock);
100 if (!__find_target_type(tt->name)) {
101 DMCRIT("Unregistering unrecognised target: %s", tt->name);
102 BUG();
105 list_del(&tt->list);
107 up_write(&_lock);
111 * io-err: always fails an io, useful for bringing
112 * up LVs that have holes in them.
114 static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
117 * Return error for discards instead of -EOPNOTSUPP
119 tt->num_discard_bios = 1;
121 return 0;
124 static void io_err_dtr(struct dm_target *tt)
126 /* empty */
129 static int io_err_map(struct dm_target *tt, struct bio *bio)
131 return -EIO;
134 static int io_err_map_rq(struct dm_target *ti, struct request *clone,
135 union map_info *map_context)
137 return -EIO;
140 static int io_err_clone_and_map_rq(struct dm_target *ti, struct request *rq,
141 union map_info *map_context,
142 struct request **clone)
144 return -EIO;
147 static void io_err_release_clone_rq(struct request *clone)
151 static long io_err_direct_access(struct dm_target *ti, sector_t sector,
152 void **kaddr, pfn_t *pfn, long size)
154 return -EIO;
157 static struct target_type error_target = {
158 .name = "error",
159 .version = {1, 5, 0},
160 .features = DM_TARGET_WILDCARD,
161 .ctr = io_err_ctr,
162 .dtr = io_err_dtr,
163 .map = io_err_map,
164 .map_rq = io_err_map_rq,
165 .clone_and_map_rq = io_err_clone_and_map_rq,
166 .release_clone_rq = io_err_release_clone_rq,
167 .direct_access = io_err_direct_access,
170 int __init dm_target_init(void)
172 return dm_register_target(&error_target);
175 void dm_target_exit(void)
177 dm_unregister_target(&error_target);
180 EXPORT_SYMBOL(dm_register_target);
181 EXPORT_SYMBOL(dm_unregister_target);