Skip to content

Commit 9659f81

Browse files
committed
dm mpath: push path selector locking down to path selectors
Proper locking of the lists used by the path selectors should be handled within the selectors (relying on dm-mpath.c code's use of the m->lock spinlock was reckless). Signed-off-by: Mike Snitzer <snitzer@redhat.com>
1 parent 21136f8 commit 9659f81

3 files changed

Lines changed: 59 additions & 11 deletions

File tree

‎drivers/md/dm-queue-length.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
struct selector {
3030
struct list_head valid_paths;
3131
struct list_head failed_paths;
32+
spinlock_t lock;
3233
};
3334

3435
struct path_info {
@@ -45,6 +46,7 @@ static struct selector *alloc_selector(void)
4546
if (s) {
4647
INIT_LIST_HEAD(&s->valid_paths);
4748
INIT_LIST_HEAD(&s->failed_paths);
49+
spin_lock_init(&s->lock);
4850
}
4951

5052
return s;
@@ -113,6 +115,7 @@ static int ql_add_path(struct path_selector *ps, struct dm_path *path,
113115
struct path_info *pi;
114116
unsigned repeat_count = QL_MIN_IO;
115117
char dummy;
118+
unsigned long flags;
116119

117120
/*
118121
* Arguments: [<repeat_count>]
@@ -147,7 +150,9 @@ static int ql_add_path(struct path_selector *ps, struct dm_path *path,
147150

148151
path->pscontext = pi;
149152

153+
spin_lock_irqsave(&s->lock, flags);
150154
list_add_tail(&pi->list, &s->valid_paths);
155+
spin_unlock_irqrestore(&s->lock, flags);
151156

152157
return 0;
153158
}
@@ -156,16 +161,22 @@ static void ql_fail_path(struct path_selector *ps, struct dm_path *path)
156161
{
157162
struct selector *s = ps->context;
158163
struct path_info *pi = path->pscontext;
164+
unsigned long flags;
159165

166+
spin_lock_irqsave(&s->lock, flags);
160167
list_move(&pi->list, &s->failed_paths);
168+
spin_unlock_irqrestore(&s->lock, flags);
161169
}
162170

163171
static int ql_reinstate_path(struct path_selector *ps, struct dm_path *path)
164172
{
165173
struct selector *s = ps->context;
166174
struct path_info *pi = path->pscontext;
175+
unsigned long flags;
167176

177+
spin_lock_irqsave(&s->lock, flags);
168178
list_move_tail(&pi->list, &s->valid_paths);
179+
spin_unlock_irqrestore(&s->lock, flags);
169180

170181
return 0;
171182
}
@@ -178,9 +189,12 @@ static struct dm_path *ql_select_path(struct path_selector *ps,
178189
{
179190
struct selector *s = ps->context;
180191
struct path_info *pi = NULL, *best = NULL;
192+
struct dm_path *ret = NULL;
193+
unsigned long flags;
181194

195+
spin_lock_irqsave(&s->lock, flags);
182196
if (list_empty(&s->valid_paths))
183-
return NULL;
197+
goto out;
184198

185199
/* Change preferred (first in list) path to evenly balance. */
186200
list_move_tail(s->valid_paths.next, &s->valid_paths);
@@ -195,11 +209,14 @@ static struct dm_path *ql_select_path(struct path_selector *ps,
195209
}
196210

197211
if (!best)
198-
return NULL;
212+
goto out;
199213

200214
*repeat_count = best->repeat_count;
201215

202-
return best->path;
216+
ret = best->path;
217+
out:
218+
spin_unlock_irqrestore(&s->lock, flags);
219+
return ret;
203220
}
204221

205222
static int ql_start_io(struct path_selector *ps, struct dm_path *path,

‎drivers/md/dm-round-robin.c‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ static void free_paths(struct list_head *paths)
4646
struct selector {
4747
struct list_head valid_paths;
4848
struct list_head invalid_paths;
49+
spinlock_t lock;
4950
};
5051

5152
static struct selector *alloc_selector(void)
@@ -55,6 +56,7 @@ static struct selector *alloc_selector(void)
5556
if (s) {
5657
INIT_LIST_HEAD(&s->valid_paths);
5758
INIT_LIST_HEAD(&s->invalid_paths);
59+
spin_lock_init(&s->lock);
5860
}
5961

6062
return s;
@@ -74,7 +76,7 @@ static int rr_create(struct path_selector *ps, unsigned argc, char **argv)
7476

7577
static void rr_destroy(struct path_selector *ps)
7678
{
77-
struct selector *s = (struct selector *) ps->context;
79+
struct selector *s = ps->context;
7880

7981
free_paths(&s->valid_paths);
8082
free_paths(&s->invalid_paths);
@@ -111,10 +113,11 @@ static int rr_status(struct path_selector *ps, struct dm_path *path,
111113
static int rr_add_path(struct path_selector *ps, struct dm_path *path,
112114
int argc, char **argv, char **error)
113115
{
114-
struct selector *s = (struct selector *) ps->context;
116+
struct selector *s = ps->context;
115117
struct path_info *pi;
116118
unsigned repeat_count = RR_MIN_IO;
117119
char dummy;
120+
unsigned long flags;
118121

119122
if (argc > 1) {
120123
*error = "round-robin ps: incorrect number of arguments";
@@ -144,40 +147,51 @@ static int rr_add_path(struct path_selector *ps, struct dm_path *path,
144147

145148
path->pscontext = pi;
146149

150+
spin_lock_irqsave(&s->lock, flags);
147151
list_add_tail(&pi->list, &s->valid_paths);
152+
spin_unlock_irqrestore(&s->lock, flags);
148153

149154
return 0;
150155
}
151156

152157
static void rr_fail_path(struct path_selector *ps, struct dm_path *p)
153158
{
154-
struct selector *s = (struct selector *) ps->context;
159+
unsigned long flags;
160+
struct selector *s = ps->context;
155161
struct path_info *pi = p->pscontext;
156162

163+
spin_lock_irqsave(&s->lock, flags);
157164
list_move(&pi->list, &s->invalid_paths);
165+
spin_unlock_irqrestore(&s->lock, flags);
158166
}
159167

160168
static int rr_reinstate_path(struct path_selector *ps, struct dm_path *p)
161169
{
162-
struct selector *s = (struct selector *) ps->context;
170+
unsigned long flags;
171+
struct selector *s = ps->context;
163172
struct path_info *pi = p->pscontext;
164173

174+
spin_lock_irqsave(&s->lock, flags);
165175
list_move(&pi->list, &s->valid_paths);
176+
spin_unlock_irqrestore(&s->lock, flags);
166177

167178
return 0;
168179
}
169180

170181
static struct dm_path *rr_select_path(struct path_selector *ps,
171182
unsigned *repeat_count, size_t nr_bytes)
172183
{
173-
struct selector *s = (struct selector *) ps->context;
184+
unsigned long flags;
185+
struct selector *s = ps->context;
174186
struct path_info *pi = NULL;
175187

188+
spin_lock_irqsave(&s->lock, flags);
176189
if (!list_empty(&s->valid_paths)) {
177190
pi = list_entry(s->valid_paths.next, struct path_info, list);
178191
list_move_tail(&pi->list, &s->valid_paths);
179192
*repeat_count = pi->repeat_count;
180193
}
194+
spin_unlock_irqrestore(&s->lock, flags);
181195

182196
return pi ? pi->path : NULL;
183197
}

‎drivers/md/dm-service-time.c‎

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
struct selector {
2525
struct list_head valid_paths;
2626
struct list_head failed_paths;
27+
spinlock_t lock;
2728
};
2829

2930
struct path_info {
@@ -41,6 +42,7 @@ static struct selector *alloc_selector(void)
4142
if (s) {
4243
INIT_LIST_HEAD(&s->valid_paths);
4344
INIT_LIST_HEAD(&s->failed_paths);
45+
spin_lock_init(&s->lock);
4446
}
4547

4648
return s;
@@ -111,6 +113,7 @@ static int st_add_path(struct path_selector *ps, struct dm_path *path,
111113
unsigned repeat_count = ST_MIN_IO;
112114
unsigned relative_throughput = 1;
113115
char dummy;
116+
unsigned long flags;
114117

115118
/*
116119
* Arguments: [<repeat_count> [<relative_throughput>]]
@@ -160,7 +163,9 @@ static int st_add_path(struct path_selector *ps, struct dm_path *path,
160163

161164
path->pscontext = pi;
162165

166+
spin_lock_irqsave(&s->lock, flags);
163167
list_add_tail(&pi->list, &s->valid_paths);
168+
spin_unlock_irqrestore(&s->lock, flags);
164169

165170
return 0;
166171
}
@@ -169,16 +174,22 @@ static void st_fail_path(struct path_selector *ps, struct dm_path *path)
169174
{
170175
struct selector *s = ps->context;
171176
struct path_info *pi = path->pscontext;
177+
unsigned long flags;
172178

179+
spin_lock_irqsave(&s->lock, flags);
173180
list_move(&pi->list, &s->failed_paths);
181+
spin_unlock_irqrestore(&s->lock, flags);
174182
}
175183

176184
static int st_reinstate_path(struct path_selector *ps, struct dm_path *path)
177185
{
178186
struct selector *s = ps->context;
179187
struct path_info *pi = path->pscontext;
188+
unsigned long flags;
180189

190+
spin_lock_irqsave(&s->lock, flags);
181191
list_move_tail(&pi->list, &s->valid_paths);
192+
spin_unlock_irqrestore(&s->lock, flags);
182193

183194
return 0;
184195
}
@@ -265,9 +276,12 @@ static struct dm_path *st_select_path(struct path_selector *ps,
265276
{
266277
struct selector *s = ps->context;
267278
struct path_info *pi = NULL, *best = NULL;
279+
struct dm_path *ret = NULL;
280+
unsigned long flags;
268281

282+
spin_lock_irqsave(&s->lock, flags);
269283
if (list_empty(&s->valid_paths))
270-
return NULL;
284+
goto out;
271285

272286
/* Change preferred (first in list) path to evenly balance. */
273287
list_move_tail(s->valid_paths.next, &s->valid_paths);
@@ -277,11 +291,14 @@ static struct dm_path *st_select_path(struct path_selector *ps,
277291
best = pi;
278292

279293
if (!best)
280-
return NULL;
294+
goto out;
281295

282296
*repeat_count = best->repeat_count;
283297

284-
return best->path;
298+
ret = best->path;
299+
out:
300+
spin_unlock_irqrestore(&s->lock, flags);
301+
return ret;
285302
}
286303

287304
static int st_start_io(struct path_selector *ps, struct dm_path *path,

0 commit comments

Comments
 (0)