]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/md/dm-target.c
dm mpath: fix missing call of path selector type->end_io
[mirror_ubuntu-bionic-kernel.git] / drivers / md / dm-target.c
CommitLineData
1da177e4
LT
1/*
2 * Copyright (C) 2001 Sistina Software (UK) Limited
3 *
4 * This file is released under the GPL.
5 */
6
4cc96131 7#include "dm-core.h"
1da177e4
LT
8
9#include <linux/module.h>
10#include <linux/init.h>
11#include <linux/kmod.h>
12#include <linux/bio.h>
1da177e4 13
72d94861
AK
14#define DM_MSG_PREFIX "target"
15
1da177e4
LT
16static LIST_HEAD(_targets);
17static DECLARE_RWSEM(_lock);
18
19#define DM_MOD_NAME_SIZE 32
20
45194e4f 21static inline struct target_type *__find_target_type(const char *name)
1da177e4 22{
45194e4f 23 struct target_type *tt;
1da177e4 24
45194e4f
CR
25 list_for_each_entry(tt, &_targets, list)
26 if (!strcmp(name, tt->name))
27 return tt;
1da177e4
LT
28
29 return NULL;
30}
31
45194e4f 32static struct target_type *get_target_type(const char *name)
1da177e4 33{
45194e4f 34 struct target_type *tt;
1da177e4
LT
35
36 down_read(&_lock);
37
45194e4f
CR
38 tt = __find_target_type(name);
39 if (tt && !try_module_get(tt->module))
40 tt = NULL;
1da177e4
LT
41
42 up_read(&_lock);
45194e4f 43 return tt;
1da177e4
LT
44}
45
46static void load_module(const char *name)
47{
48 request_module("dm-%s", name);
49}
50
51struct target_type *dm_get_target_type(const char *name)
52{
45194e4f 53 struct target_type *tt = get_target_type(name);
1da177e4 54
45194e4f 55 if (!tt) {
1da177e4 56 load_module(name);
45194e4f 57 tt = get_target_type(name);
1da177e4
LT
58 }
59
45194e4f 60 return tt;
1da177e4
LT
61}
62
45194e4f 63void dm_put_target_type(struct target_type *tt)
1da177e4 64{
1da177e4 65 down_read(&_lock);
45194e4f 66 module_put(tt->module);
1da177e4 67 up_read(&_lock);
1da177e4
LT
68}
69
1da177e4
LT
70int dm_target_iterate(void (*iter_func)(struct target_type *tt,
71 void *param), void *param)
72{
45194e4f 73 struct target_type *tt;
1da177e4
LT
74
75 down_read(&_lock);
45194e4f
CR
76 list_for_each_entry(tt, &_targets, list)
77 iter_func(tt, param);
1da177e4
LT
78 up_read(&_lock);
79
80 return 0;
81}
82
45194e4f 83int dm_register_target(struct target_type *tt)
1da177e4
LT
84{
85 int rv = 0;
1da177e4
LT
86
87 down_write(&_lock);
45194e4f 88 if (__find_target_type(tt->name))
1da177e4
LT
89 rv = -EEXIST;
90 else
45194e4f 91 list_add(&tt->list, &_targets);
1da177e4
LT
92
93 up_write(&_lock);
1da177e4
LT
94 return rv;
95}
96
45194e4f 97void dm_unregister_target(struct target_type *tt)
1da177e4 98{
1da177e4 99 down_write(&_lock);
45194e4f
CR
100 if (!__find_target_type(tt->name)) {
101 DMCRIT("Unregistering unrecognised target: %s", tt->name);
10d3bd09 102 BUG();
1da177e4
LT
103 }
104
45194e4f 105 list_del(&tt->list);
1da177e4
LT
106
107 up_write(&_lock);
1da177e4
LT
108}
109
110/*
111 * io-err: always fails an io, useful for bringing
112 * up LVs that have holes in them.
113 */
45194e4f 114static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args)
1da177e4 115{
38e1b257
MS
116 /*
117 * Return error for discards instead of -EOPNOTSUPP
118 */
55a62eef 119 tt->num_discard_bios = 1;
38e1b257 120
1da177e4
LT
121 return 0;
122}
123
45194e4f 124static void io_err_dtr(struct dm_target *tt)
1da177e4
LT
125{
126 /* empty */
127}
128
7de3ee57 129static int io_err_map(struct dm_target *tt, struct bio *bio)
1da177e4 130{
846785e6 131 return DM_MAPIO_KILL;
1da177e4
LT
132}
133
e5863d9a
MS
134static int io_err_clone_and_map_rq(struct dm_target *ti, struct request *rq,
135 union map_info *map_context,
136 struct request **clone)
137{
412445ac 138 return DM_MAPIO_KILL;
e5863d9a
MS
139}
140
17ee3fa8
YY
141static void io_err_release_clone_rq(struct request *clone,
142 union map_info *map_context)
e5863d9a
MS
143{
144}
145
817bf402
DW
146static long io_err_dax_direct_access(struct dm_target *ti, pgoff_t pgoff,
147 long nr_pages, void **kaddr, pfn_t *pfn)
f8df1fdf
MS
148{
149 return -EIO;
150}
151
1da177e4
LT
152static struct target_type error_target = {
153 .name = "error",
f8df1fdf 154 .version = {1, 5, 0},
f083b09b 155 .features = DM_TARGET_WILDCARD,
1da177e4
LT
156 .ctr = io_err_ctr,
157 .dtr = io_err_dtr,
158 .map = io_err_map,
e5863d9a
MS
159 .clone_and_map_rq = io_err_clone_and_map_rq,
160 .release_clone_rq = io_err_release_clone_rq,
817bf402 161 .direct_access = io_err_dax_direct_access,
1da177e4
LT
162};
163
164int __init dm_target_init(void)
165{
166 return dm_register_target(&error_target);
167}
168
169void dm_target_exit(void)
170{
10d3bd09 171 dm_unregister_target(&error_target);
1da177e4
LT
172}
173
174EXPORT_SYMBOL(dm_register_target);
175EXPORT_SYMBOL(dm_unregister_target);