0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef ZFCP_REQLIST_H
0012 #define ZFCP_REQLIST_H
0013
0014
0015 #define ZFCP_REQ_LIST_BUCKETS 128
0016
0017
0018
0019
0020
0021
0022 struct zfcp_reqlist {
0023 spinlock_t lock;
0024 struct list_head buckets[ZFCP_REQ_LIST_BUCKETS];
0025 };
0026
0027 static inline int zfcp_reqlist_hash(unsigned long req_id)
0028 {
0029 return req_id % ZFCP_REQ_LIST_BUCKETS;
0030 }
0031
0032
0033
0034
0035
0036
0037
0038 static inline struct zfcp_reqlist *zfcp_reqlist_alloc(void)
0039 {
0040 unsigned int i;
0041 struct zfcp_reqlist *rl;
0042
0043 rl = kzalloc(sizeof(struct zfcp_reqlist), GFP_KERNEL);
0044 if (!rl)
0045 return NULL;
0046
0047 spin_lock_init(&rl->lock);
0048
0049 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
0050 INIT_LIST_HEAD(&rl->buckets[i]);
0051
0052 return rl;
0053 }
0054
0055
0056
0057
0058
0059
0060
0061 static inline int zfcp_reqlist_isempty(struct zfcp_reqlist *rl)
0062 {
0063 unsigned int i;
0064
0065 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
0066 if (!list_empty(&rl->buckets[i]))
0067 return 0;
0068 return 1;
0069 }
0070
0071
0072
0073
0074
0075 static inline void zfcp_reqlist_free(struct zfcp_reqlist *rl)
0076 {
0077
0078 BUG_ON(!zfcp_reqlist_isempty(rl));
0079
0080 kfree(rl);
0081 }
0082
0083 static inline struct zfcp_fsf_req *
0084 _zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
0085 {
0086 struct zfcp_fsf_req *req;
0087 unsigned int i;
0088
0089 i = zfcp_reqlist_hash(req_id);
0090 list_for_each_entry(req, &rl->buckets[i], list)
0091 if (req->req_id == req_id)
0092 return req;
0093 return NULL;
0094 }
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104 static inline struct zfcp_fsf_req *
0105 zfcp_reqlist_find(struct zfcp_reqlist *rl, unsigned long req_id)
0106 {
0107 unsigned long flags;
0108 struct zfcp_fsf_req *req;
0109
0110 spin_lock_irqsave(&rl->lock, flags);
0111 req = _zfcp_reqlist_find(rl, req_id);
0112 spin_unlock_irqrestore(&rl->lock, flags);
0113
0114 return req;
0115 }
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 static inline struct zfcp_fsf_req *
0130 zfcp_reqlist_find_rm(struct zfcp_reqlist *rl, unsigned long req_id)
0131 {
0132 unsigned long flags;
0133 struct zfcp_fsf_req *req;
0134
0135 spin_lock_irqsave(&rl->lock, flags);
0136 req = _zfcp_reqlist_find(rl, req_id);
0137 if (req)
0138 list_del(&req->list);
0139 spin_unlock_irqrestore(&rl->lock, flags);
0140
0141 return req;
0142 }
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154 static inline void zfcp_reqlist_add(struct zfcp_reqlist *rl,
0155 struct zfcp_fsf_req *req)
0156 {
0157 unsigned int i;
0158 unsigned long flags;
0159
0160 i = zfcp_reqlist_hash(req->req_id);
0161
0162 spin_lock_irqsave(&rl->lock, flags);
0163 list_add_tail(&req->list, &rl->buckets[i]);
0164 spin_unlock_irqrestore(&rl->lock, flags);
0165 }
0166
0167
0168
0169
0170
0171
0172 static inline void zfcp_reqlist_move(struct zfcp_reqlist *rl,
0173 struct list_head *list)
0174 {
0175 unsigned int i;
0176 unsigned long flags;
0177
0178 spin_lock_irqsave(&rl->lock, flags);
0179 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
0180 list_splice_init(&rl->buckets[i], list);
0181 spin_unlock_irqrestore(&rl->lock, flags);
0182 }
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197 static inline void
0198 zfcp_reqlist_apply_for_all(struct zfcp_reqlist *rl,
0199 void (*f)(struct zfcp_fsf_req *, void *), void *data)
0200 {
0201 struct zfcp_fsf_req *req;
0202 unsigned long flags;
0203 unsigned int i;
0204
0205 spin_lock_irqsave(&rl->lock, flags);
0206 for (i = 0; i < ZFCP_REQ_LIST_BUCKETS; i++)
0207 list_for_each_entry(req, &rl->buckets[i], list)
0208 f(req, data);
0209 spin_unlock_irqrestore(&rl->lock, flags);
0210 }
0211
0212 #endif