1
2
3
4
5
6
7
8
9
10
11#ifndef ZFCP_REQLIST_H
12#define ZFCP_REQLIST_H
13
14
15#define ZFCP_REQ_LIST_BUCKETS 128
16
17
18
19
20
21
22struct zfcp_reqlist {
23 spinlock_t lock;
24 struct list_head buckets[ZFCP_REQ_LIST_BUCKETS];
25};
26
27static inline int zfcp_reqlist_hash(unsigned long req_id)
28{
29 return req_id % ZFCP_REQ_LIST_BUCKETS;
30}
31
32
33
34
35
36
37
38static inline struct zfcp_reqlist *zfcp_reqlist_alloc(void)
39{
40 unsigned int i;
41 struct zfcp_reqlist *rl;
42
43 rl = kzalloc(sizeof(struct zfcp_reqlist), GFP_KERNEL);
44 if (!rl)
45 return NULL;
46
47 spin_lock_init(&rl->lock);
48
49 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
50 INIT_LIST_HEAD(&rl->buckets[i]);
51
52 return rl;
53}
54
55
56
57
58
59
60
61static inline int zfcp_reqlist_isempty(struct zfcp_reqlist *rl)
62{
63 unsigned int i;
64
65 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
66 if (!list_empty(&rl->buckets[i]))
67 return 0;
68 return 1;
69}
70
71
72
73
74
75static inline void zfcp_reqlist_free(struct zfcp_reqlist *rl)
76{
77
78 BUG_ON(!zfcp_reqlist_isempty(rl));
79
80 kfree(rl);
81}
82
83static inline struct zfcp_fsf_req *
84_zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
85{
86 struct zfcp_fsf_req *req;
87 unsigned int i;
88
89 i = zfcp_reqlist_hash(req_id);
90 list_for_each_entry(req, &rl->buckets[i], list)
91 if (req->req_id == req_id)
92 return req;
93 return NULL;
94}
95
96
97
98
99
100
101
102
103
104static inline struct zfcp_fsf_req *
105zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
106{
107 unsigned long flags;
108 struct zfcp_fsf_req *req;
109
110 spin_lock_irqsave(&rl->lock, flags);
111 req = _zfcp_reqlist_find(rl, req_id);
112 spin_unlock_irqrestore(&rl->lock, flags);
113
114 return req;
115}
116
117
118
119
120
121
122
123
124
125
126
127
128
129static inline struct zfcp_fsf_req *
130zfcp_reqlist_find_rm(struct zfcp_reqlist *rl, unsigned long req_id)
131{
132 unsigned long flags;
133 struct zfcp_fsf_req *req;
134
135 spin_lock_irqsave(&rl->lock, flags);
136 req = _zfcp_reqlist_find(rl, req_id);
137 if (req)
138 list_del(&req->list);
139 spin_unlock_irqrestore(&rl->lock, flags);
140
141 return req;
142}
143
144
145
146
147
148
149
150
151
152
153
154static inline void zfcp_reqlist_add(struct zfcp_reqlist *rl,
155 struct zfcp_fsf_req *req)
156{
157 unsigned int i;
158 unsigned long flags;
159
160 i = zfcp_reqlist_hash(req->req_id);
161
162 spin_lock_irqsave(&rl->lock, flags);
163 list_add_tail(&req->list, &rl->buckets[i]);
164 spin_unlock_irqrestore(&rl->lock, flags);
165}
166
167
168
169
170
171
172static inline void zfcp_reqlist_move(struct zfcp_reqlist *rl,
173 struct list_head *list)
174{
175 unsigned int i;
176 unsigned long flags;
177
178 spin_lock_irqsave(&rl->lock, flags);
179 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
180 list_splice_init(&rl->buckets[i], list);
181 spin_unlock_irqrestore(&rl->lock, flags);
182}
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197static inline void
198zfcp_reqlist_apply_for_all(struct zfcp_reqlist *rl,
199 void (*f)(struct zfcp_fsf_req *, void *), void *data)
200{
201 struct zfcp_fsf_req *req;
202 unsigned long flags;
203 unsigned int i;
204
205 spin_lock_irqsave(&rl->lock, flags);
206 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
207 list_for_each_entry(req, &rl->buckets[i], list)
208 f(req, data);
209 spin_unlock_irqrestore(&rl->lock, flags);
210}
211
212#endif
213