Skip to content

Commit 45194e4

Browse files
crquankergon
authored andcommitted
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>
1 parent 570b9d9 commit 45194e4

3 files changed

Lines changed: 34 additions & 61 deletions

File tree

‎drivers/md/dm-target.c‎

Lines changed: 30 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,34 @@
1414

1515
#define DM_MSG_PREFIX "target"
1616

17-
struct tt_internal {
18-
struct target_type tt;
19-
20-
struct list_head list;
21-
};
22-
2317
static LIST_HEAD(_targets);
2418
static DECLARE_RWSEM(_lock);
2519

2620
#define DM_MOD_NAME_SIZE 32
2721

28-
static inline struct tt_internal *__find_target_type(const char *name)
22+
static inline struct target_type *__find_target_type(const char *name)
2923
{
30-
struct tt_internal *ti;
24+
struct target_type *tt;
3125

32-
list_for_each_entry (ti, &_targets, list)
33-
if (!strcmp(name, ti->tt.name))
34-
return ti;
26+
list_for_each_entry(tt, &_targets, list)
27+
if (!strcmp(name, tt->name))
28+
return tt;
3529

3630
return NULL;
3731
}
3832

39-
static struct tt_internal *get_target_type(const char *name)
33+
static struct target_type *get_target_type(const char *name)
4034
{
41-
struct tt_internal *ti;
35+
struct target_type *tt;
4236

4337
down_read(&_lock);
4438

45-
ti = __find_target_type(name);
46-
if (ti && !try_module_get(ti->tt.module))
47-
ti = NULL;
39+
tt = __find_target_type(name);
40+
if (tt && !try_module_get(tt->module))
41+
tt = NULL;
4842

4943
up_read(&_lock);
50-
return ti;
44+
return tt;
5145
}
5246

5347
static void load_module(const char *name)
@@ -57,83 +51,59 @@ static void load_module(const char *name)
5751

5852
struct target_type *dm_get_target_type(const char *name)
5953
{
60-
struct tt_internal *ti = get_target_type(name);
54+
struct target_type *tt = get_target_type(name);
6155

62-
if (!ti) {
56+
if (!tt) {
6357
load_module(name);
64-
ti = get_target_type(name);
58+
tt = get_target_type(name);
6559
}
6660

67-
return ti ? &ti->tt : NULL;
61+
return tt;
6862
}
6963

70-
void dm_put_target_type(struct target_type *t)
64+
void dm_put_target_type(struct target_type *tt)
7165
{
72-
struct tt_internal *ti = (struct tt_internal *) t;
73-
7466
down_read(&_lock);
75-
module_put(ti->tt.module);
67+
module_put(tt->module);
7668
up_read(&_lock);
77-
78-
return;
7969
}
8070

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-
9271
int dm_target_iterate(void (*iter_func)(struct target_type *tt,
9372
void *param), void *param)
9473
{
95-
struct tt_internal *ti;
74+
struct target_type *tt;
9675

9776
down_read(&_lock);
98-
list_for_each_entry (ti, &_targets, list)
99-
iter_func(&ti->tt, param);
77+
list_for_each_entry(tt, &_targets, list)
78+
iter_func(tt, param);
10079
up_read(&_lock);
10180

10281
return 0;
10382
}
10483

105-
int dm_register_target(struct target_type *t)
84+
int dm_register_target(struct target_type *tt)
10685
{
10786
int rv = 0;
108-
struct tt_internal *ti = alloc_target(t);
109-
110-
if (!ti)
111-
return -ENOMEM;
11287

11388
down_write(&_lock);
114-
if (__find_target_type(t->name))
89+
if (__find_target_type(tt->name))
11590
rv = -EEXIST;
11691
else
117-
list_add(&ti->list, &_targets);
92+
list_add(&tt->list, &_targets);
11893

11994
up_write(&_lock);
120-
if (rv)
121-
kfree(ti);
12295
return rv;
12396
}
12497

125-
void dm_unregister_target(struct target_type *t)
98+
void dm_unregister_target(struct target_type *tt)
12699
{
127-
struct tt_internal *ti;
128-
129100
down_write(&_lock);
130-
if (!(ti = __find_target_type(t->name))) {
131-
DMCRIT("Unregistering unrecognised target: %s", t->name);
101+
if (!__find_target_type(tt->name)) {
102+
DMCRIT("Unregistering unrecognised target: %s", tt->name);
132103
BUG();
133104
}
134105

135-
list_del(&ti->list);
136-
kfree(ti);
106+
list_del(&tt->list);
137107

138108
up_write(&_lock);
139109
}
@@ -142,17 +112,17 @@ void dm_unregister_target(struct target_type *t)
142112
* io-err: always fails an io, useful for bringing
143113
* up LVs that have holes in them.
144114
*/
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)
146116
{
147117
return 0;
148118
}
149119

150-
static void io_err_dtr(struct dm_target *ti)
120+
static void io_err_dtr(struct dm_target *tt)
151121
{
152122
/* empty */
153123
}
154124

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,
156126
union map_info *map_context)
157127
{
158128
return -EIO;

‎drivers/md/dm.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int dm_table_barrier_ok(struct dm_table *t);
6060
int dm_target_init(void);
6161
void dm_target_exit(void);
6262
struct target_type *dm_get_target_type(const char *name);
63-
void dm_put_target_type(struct target_type *t);
63+
void dm_put_target_type(struct target_type *tt);
6464
int dm_target_iterate(void (*iter_func)(struct target_type *tt,
6565
void *param), void *param);
6666

‎include/linux/device-mapper.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ struct target_type {
139139
dm_ioctl_fn ioctl;
140140
dm_merge_fn merge;
141141
dm_busy_fn busy;
142+
143+
/* For internal device-mapper use. */
144+
struct list_head list;
142145
};
143146

144147
struct io_restrictions {

0 commit comments

Comments
 (0)