diff options
author | Cheng Renquan <crquan@gmail.com> | 2009-04-02 14:55:28 -0400 |
---|---|---|
committer | Alasdair G Kergon <agk@redhat.com> | 2009-04-02 14:55:28 -0400 |
commit | 45194e4f89fbdd97a2b7d2698c05f0b00c19e820 (patch) | |
tree | 70d35747228b84c1d7b7d76c5e18f72b16f412a3 /drivers/md/dm-target.c | |
parent | 570b9d968bf9b16974252ef7cbce73fa6dac34f3 (diff) |
dm target: remove struct tt_internal
The tt_internal is really just a list_head to manage registered target_type
in a double linked list,
Here embed the list_head into target_type directly,
1. to avoid kmalloc/kfree;
2. then tt_internal is really unneeded;
Cc: stable@kernel.org
Signed-off-by: Cheng Renquan <crquan@gmail.com>
Signed-off-by: Alasdair G Kergon <agk@redhat.com>
Reviewed-by: Alasdair G Kergon <agk@redhat.com>
Diffstat (limited to 'drivers/md/dm-target.c')
-rw-r--r-- | drivers/md/dm-target.c | 90 |
1 files changed, 30 insertions, 60 deletions
diff --git a/drivers/md/dm-target.c b/drivers/md/dm-target.c index db72c9497bb4..04feccf2a997 100644 --- a/drivers/md/dm-target.c +++ b/drivers/md/dm-target.c | |||
@@ -14,40 +14,34 @@ | |||
14 | 14 | ||
15 | #define DM_MSG_PREFIX "target" | 15 | #define DM_MSG_PREFIX "target" |
16 | 16 | ||
17 | struct tt_internal { | ||
18 | struct target_type tt; | ||
19 | |||
20 | struct list_head list; | ||
21 | }; | ||
22 | |||
23 | static LIST_HEAD(_targets); | 17 | static LIST_HEAD(_targets); |
24 | static DECLARE_RWSEM(_lock); | 18 | static DECLARE_RWSEM(_lock); |
25 | 19 | ||
26 | #define DM_MOD_NAME_SIZE 32 | 20 | #define DM_MOD_NAME_SIZE 32 |
27 | 21 | ||
28 | static inline struct tt_internal *__find_target_type(const char *name) | 22 | static inline struct target_type *__find_target_type(const char *name) |
29 | { | 23 | { |
30 | struct tt_internal *ti; | 24 | struct target_type *tt; |
31 | 25 | ||
32 | list_for_each_entry (ti, &_targets, list) | 26 | list_for_each_entry(tt, &_targets, list) |
33 | if (!strcmp(name, ti->tt.name)) | 27 | if (!strcmp(name, tt->name)) |
34 | return ti; | 28 | return tt; |
35 | 29 | ||
36 | return NULL; | 30 | return NULL; |
37 | } | 31 | } |
38 | 32 | ||
39 | static struct tt_internal *get_target_type(const char *name) | 33 | static struct target_type *get_target_type(const char *name) |
40 | { | 34 | { |
41 | struct tt_internal *ti; | 35 | struct target_type *tt; |
42 | 36 | ||
43 | down_read(&_lock); | 37 | down_read(&_lock); |
44 | 38 | ||
45 | ti = __find_target_type(name); | 39 | tt = __find_target_type(name); |
46 | if (ti && !try_module_get(ti->tt.module)) | 40 | if (tt && !try_module_get(tt->module)) |
47 | ti = NULL; | 41 | tt = NULL; |
48 | 42 | ||
49 | up_read(&_lock); | 43 | up_read(&_lock); |
50 | return ti; | 44 | return tt; |
51 | } | 45 | } |
52 | 46 | ||
53 | static void load_module(const char *name) | 47 | static void load_module(const char *name) |
@@ -57,83 +51,59 @@ static void load_module(const char *name) | |||
57 | 51 | ||
58 | struct target_type *dm_get_target_type(const char *name) | 52 | struct target_type *dm_get_target_type(const char *name) |
59 | { | 53 | { |
60 | struct tt_internal *ti = get_target_type(name); | 54 | struct target_type *tt = get_target_type(name); |
61 | 55 | ||
62 | if (!ti) { | 56 | if (!tt) { |
63 | load_module(name); | 57 | load_module(name); |
64 | ti = get_target_type(name); | 58 | tt = get_target_type(name); |
65 | } | 59 | } |
66 | 60 | ||
67 | return ti ? &ti->tt : NULL; | 61 | return tt; |
68 | } | 62 | } |
69 | 63 | ||
70 | void dm_put_target_type(struct target_type *t) | 64 | void dm_put_target_type(struct target_type *tt) |
71 | { | 65 | { |
72 | struct tt_internal *ti = (struct tt_internal *) t; | ||
73 | |||
74 | down_read(&_lock); | 66 | down_read(&_lock); |
75 | module_put(ti->tt.module); | 67 | module_put(tt->module); |
76 | up_read(&_lock); | 68 | up_read(&_lock); |
77 | |||
78 | return; | ||
79 | } | 69 | } |
80 | 70 | ||
81 | static struct tt_internal *alloc_target(struct target_type *t) | ||
82 | { | ||
83 | struct tt_internal *ti = kzalloc(sizeof(*ti), GFP_KERNEL); | ||
84 | |||
85 | if (ti) | ||
86 | ti->tt = *t; | ||
87 | |||
88 | return ti; | ||
89 | } | ||
90 | |||
91 | |||
92 | int dm_target_iterate(void (*iter_func)(struct target_type *tt, | 71 | int dm_target_iterate(void (*iter_func)(struct target_type *tt, |
93 | void *param), void *param) | 72 | void *param), void *param) |
94 | { | 73 | { |
95 | struct tt_internal *ti; | 74 | struct target_type *tt; |
96 | 75 | ||
97 | down_read(&_lock); | 76 | down_read(&_lock); |
98 | list_for_each_entry (ti, &_targets, list) | 77 | list_for_each_entry(tt, &_targets, list) |
99 | iter_func(&ti->tt, param); | 78 | iter_func(tt, param); |
100 | up_read(&_lock); | 79 | up_read(&_lock); |
101 | 80 | ||
102 | return 0; | 81 | return 0; |
103 | } | 82 | } |
104 | 83 | ||
105 | int dm_register_target(struct target_type *t) | 84 | int dm_register_target(struct target_type *tt) |
106 | { | 85 | { |
107 | int rv = 0; | 86 | int rv = 0; |
108 | struct tt_internal *ti = alloc_target(t); | ||
109 | |||
110 | if (!ti) | ||
111 | return -ENOMEM; | ||
112 | 87 | ||
113 | down_write(&_lock); | 88 | down_write(&_lock); |
114 | if (__find_target_type(t->name)) | 89 | if (__find_target_type(tt->name)) |
115 | rv = -EEXIST; | 90 | rv = -EEXIST; |
116 | else | 91 | else |
117 | list_add(&ti->list, &_targets); | 92 | list_add(&tt->list, &_targets); |
118 | 93 | ||
119 | up_write(&_lock); | 94 | up_write(&_lock); |
120 | if (rv) | ||
121 | kfree(ti); | ||
122 | return rv; | 95 | return rv; |
123 | } | 96 | } |
124 | 97 | ||
125 | void dm_unregister_target(struct target_type *t) | 98 | void dm_unregister_target(struct target_type *tt) |
126 | { | 99 | { |
127 | struct tt_internal *ti; | ||
128 | |||
129 | down_write(&_lock); | 100 | down_write(&_lock); |
130 | if (!(ti = __find_target_type(t->name))) { | 101 | if (!__find_target_type(tt->name)) { |
131 | DMCRIT("Unregistering unrecognised target: %s", t->name); | 102 | DMCRIT("Unregistering unrecognised target: %s", tt->name); |
132 | BUG(); | 103 | BUG(); |
133 | } | 104 | } |
134 | 105 | ||
135 | list_del(&ti->list); | 106 | list_del(&tt->list); |
136 | kfree(ti); | ||
137 | 107 | ||
138 | up_write(&_lock); | 108 | up_write(&_lock); |
139 | } | 109 | } |
@@ -142,17 +112,17 @@ void dm_unregister_target(struct target_type *t) | |||
142 | * io-err: always fails an io, useful for bringing | 112 | * io-err: always fails an io, useful for bringing |
143 | * up LVs that have holes in them. | 113 | * up LVs that have holes in them. |
144 | */ | 114 | */ |
145 | static int io_err_ctr(struct dm_target *ti, unsigned int argc, char **args) | 115 | static int io_err_ctr(struct dm_target *tt, unsigned int argc, char **args) |
146 | { | 116 | { |
147 | return 0; | 117 | return 0; |
148 | } | 118 | } |
149 | 119 | ||
150 | static void io_err_dtr(struct dm_target *ti) | 120 | static void io_err_dtr(struct dm_target *tt) |
151 | { | 121 | { |
152 | /* empty */ | 122 | /* empty */ |
153 | } | 123 | } |
154 | 124 | ||
155 | static int io_err_map(struct dm_target *ti, struct bio *bio, | 125 | static int io_err_map(struct dm_target *tt, struct bio *bio, |
156 | union map_info *map_context) | 126 | union map_info *map_context) |
157 | { | 127 | { |
158 | return -EIO; | 128 | return -EIO; |