Lines 4-9
Link Here
|
4 |
* Released under the terms of the GNU GPL v2.0. |
4 |
* Released under the terms of the GNU GPL v2.0. |
5 |
*/ |
5 |
*/ |
6 |
|
6 |
|
|
|
7 |
#include <linux/mutex.h> |
8 |
|
7 |
#include "iscsi.h" |
9 |
#include "iscsi.h" |
8 |
#include "digest.h" |
10 |
#include "digest.h" |
9 |
#include "iscsi_dbg.h" |
11 |
#include "iscsi_dbg.h" |
Lines 11-17
Link Here
|
11 |
#define MAX_NR_TARGETS (1UL << 30) |
13 |
#define MAX_NR_TARGETS (1UL << 30) |
12 |
|
14 |
|
13 |
static LIST_HEAD(target_list); |
15 |
static LIST_HEAD(target_list); |
14 |
static DECLARE_MUTEX(target_list_sem); |
16 |
static DEFINE_MUTEX(target_list_mutex); |
15 |
static u32 next_target_id; |
17 |
static u32 next_target_id; |
16 |
static u32 nr_targets; |
18 |
static u32 nr_targets; |
17 |
|
19 |
|
Lines 48-63
Link Here
|
48 |
int err = 0; |
50 |
int err = 0; |
49 |
|
51 |
|
50 |
if (interruptible) |
52 |
if (interruptible) |
51 |
err = down_interruptible(&target->target_sem); |
53 |
err = mutex_lock_interruptible(&target->target_mutex); |
52 |
else |
54 |
else |
53 |
down(&target->target_sem); |
55 |
mutex_lock(&target->target_mutex); |
54 |
|
56 |
|
55 |
return err; |
57 |
return err; |
56 |
} |
58 |
} |
57 |
|
59 |
|
58 |
inline void target_unlock(struct iscsi_target *target) |
60 |
inline void target_unlock(struct iscsi_target *target) |
59 |
{ |
61 |
{ |
60 |
up(&target->target_sem); |
62 |
mutex_unlock(&target->target_mutex); |
61 |
} |
63 |
} |
62 |
|
64 |
|
63 |
static struct iscsi_target *__target_lookup_by_id(u32 id) |
65 |
static struct iscsi_target *__target_lookup_by_id(u32 id) |
Lines 86-94
Link Here
|
86 |
{ |
88 |
{ |
87 |
struct iscsi_target *target; |
89 |
struct iscsi_target *target; |
88 |
|
90 |
|
89 |
down(&target_list_sem); |
91 |
mutex_lock(&target_list_mutex); |
90 |
target = __target_lookup_by_id(id); |
92 |
target = __target_lookup_by_id(id); |
91 |
up(&target_list_sem); |
93 |
mutex_unlock(&target_list_mutex); |
92 |
|
94 |
|
93 |
return target; |
95 |
return target; |
94 |
} |
96 |
} |
Lines 157-163
Link Here
|
157 |
|
159 |
|
158 |
strncpy(target->name, name, sizeof(target->name) - 1); |
160 |
strncpy(target->name, name, sizeof(target->name) - 1); |
159 |
|
161 |
|
160 |
init_MUTEX(&target->target_sem); |
162 |
mutex_init(&target->target_mutex); |
161 |
spin_lock_init(&target->session_list_lock); |
163 |
spin_lock_init(&target->session_list_lock); |
162 |
|
164 |
|
163 |
INIT_LIST_HEAD(&target->session_list); |
165 |
INIT_LIST_HEAD(&target->session_list); |
Lines 195-201
Link Here
|
195 |
u32 tid = info->tid; |
197 |
u32 tid = info->tid; |
196 |
int err; |
198 |
int err; |
197 |
|
199 |
|
198 |
err = down_interruptible(&target_list_sem); |
200 |
err = mutex_lock_interruptible(&target_list_mutex); |
199 |
if (err < 0) |
201 |
if (err < 0) |
200 |
return err; |
202 |
return err; |
201 |
|
203 |
|
Lines 204-210
Link Here
|
204 |
goto out; |
206 |
goto out; |
205 |
} |
207 |
} |
206 |
|
208 |
|
207 |
if (__target_lookup_by_name(info->name) || |
209 |
if (__target_lookup_by_name(info->name) || |
208 |
(tid && __target_lookup_by_id(tid))) { |
210 |
(tid && __target_lookup_by_id(tid))) { |
209 |
err = -EEXIST; |
211 |
err = -EEXIST; |
210 |
goto out; |
212 |
goto out; |
Lines 223-229
Link Here
|
223 |
if (!err) |
225 |
if (!err) |
224 |
nr_targets++; |
226 |
nr_targets++; |
225 |
out: |
227 |
out: |
226 |
up(&target_list_sem); |
228 |
mutex_unlock(&target_list_mutex); |
227 |
|
229 |
|
228 |
return err; |
230 |
return err; |
229 |
} |
231 |
} |
Lines 248-254
Link Here
|
248 |
module_put(THIS_MODULE); |
250 |
module_put(THIS_MODULE); |
249 |
} |
251 |
} |
250 |
|
252 |
|
251 |
/* @locking: target_list_sem must be locked */ |
253 |
/* @locking: target_list_mutex must be locked */ |
252 |
static int __target_del(struct iscsi_target *target) |
254 |
static int __target_del(struct iscsi_target *target) |
253 |
{ |
255 |
{ |
254 |
int err; |
256 |
int err; |
Lines 283-289
Link Here
|
283 |
struct iscsi_target *target; |
285 |
struct iscsi_target *target; |
284 |
int err; |
286 |
int err; |
285 |
|
287 |
|
286 |
err = down_interruptible(&target_list_sem); |
288 |
err = mutex_lock_interruptible(&target_list_mutex); |
287 |
if (err < 0) |
289 |
if (err < 0) |
288 |
return err; |
290 |
return err; |
289 |
|
291 |
|
Lines 295-301
Link Here
|
295 |
|
297 |
|
296 |
err = __target_del(target); |
298 |
err = __target_del(target); |
297 |
out: |
299 |
out: |
298 |
up(&target_list_sem); |
300 |
mutex_unlock(&target_list_mutex); |
299 |
|
301 |
|
300 |
return err; |
302 |
return err; |
301 |
} |
303 |
} |
Lines 305-311
Link Here
|
305 |
struct iscsi_target *target, *tmp; |
307 |
struct iscsi_target *target, *tmp; |
306 |
int err; |
308 |
int err; |
307 |
|
309 |
|
308 |
down(&target_list_sem); |
310 |
mutex_lock(&target_list_mutex); |
309 |
|
311 |
|
310 |
if (!list_empty(&target_list)) |
312 |
if (!list_empty(&target_list)) |
311 |
iprintk("Removing all connections, sessions and targets\n"); |
313 |
iprintk("Removing all connections, sessions and targets\n"); |
Lines 319-325
Link Here
|
319 |
|
321 |
|
320 |
next_target_id = 0; |
322 |
next_target_id = 0; |
321 |
|
323 |
|
322 |
up(&target_list_sem); |
324 |
mutex_unlock(&target_list_mutex); |
323 |
} |
325 |
} |
324 |
|
326 |
|
325 |
static void *iet_seq_start(struct seq_file *m, loff_t *pos) |
327 |
static void *iet_seq_start(struct seq_file *m, loff_t *pos) |
Lines 327-333
Link Here
|
327 |
int err; |
329 |
int err; |
328 |
|
330 |
|
329 |
/* are you sure this is to be interruptible? */ |
331 |
/* are you sure this is to be interruptible? */ |
330 |
err = down_interruptible(&target_list_sem); |
332 |
err = mutex_lock_interruptible(&target_list_mutex); |
331 |
if (err < 0) |
333 |
if (err < 0) |
332 |
return ERR_PTR(err); |
334 |
return ERR_PTR(err); |
333 |
|
335 |
|
Lines 341-347
Link Here
|
341 |
|
343 |
|
342 |
static void iet_seq_stop(struct seq_file *m, void *v) |
344 |
static void iet_seq_stop(struct seq_file *m, void *v) |
343 |
{ |
345 |
{ |
344 |
up(&target_list_sem); |
346 |
mutex_unlock(&target_list_mutex); |
345 |
} |
347 |
} |
346 |
|
348 |
|
347 |
static int iet_seq_show(struct seq_file *m, void *p) |
349 |
static int iet_seq_show(struct seq_file *m, void *p) |