drbd: Rename various functions from *_oos_* to *_out_of_sync_* for clarity
[deliverable/linux.git] / drivers / block / drbd / drbd_req.h
1 /*
2 drbd_req.h
3
4 This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
5
6 Copyright (C) 2006-2008, LINBIT Information Technologies GmbH.
7 Copyright (C) 2006-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
8 Copyright (C) 2006-2008, Philipp Reisner <philipp.reisner@linbit.com>.
9
10 DRBD is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 DRBD is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with drbd; see the file COPYING. If not, write to
22 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
24
25 #ifndef _DRBD_REQ_H
26 #define _DRBD_REQ_H
27
28 #include <linux/module.h>
29
30 #include <linux/slab.h>
31 #include <linux/drbd.h>
32 #include "drbd_int.h"
33 #include "drbd_wrappers.h"
34
35 /* The request callbacks will be called in irq context by the IDE drivers,
36 and in Softirqs/Tasklets/BH context by the SCSI drivers,
37 and by the receiver and worker in kernel-thread context.
38 Try to get the locking right :) */
39
40 /*
41 * Objects of type struct drbd_request do only exist on a R_PRIMARY node, and are
42 * associated with IO requests originating from the block layer above us.
43 *
44 * There are quite a few things that may happen to a drbd request
45 * during its lifetime.
46 *
47 * It will be created.
48 * It will be marked with the intention to be
49 * submitted to local disk and/or
50 * send via the network.
51 *
52 * It has to be placed on the transfer log and other housekeeping lists,
53 * In case we have a network connection.
54 *
55 * It may be identified as a concurrent (write) request
56 * and be handled accordingly.
57 *
58 * It may me handed over to the local disk subsystem.
59 * It may be completed by the local disk subsystem,
60 * either successfully or with io-error.
61 * In case it is a READ request, and it failed locally,
62 * it may be retried remotely.
63 *
64 * It may be queued for sending.
65 * It may be handed over to the network stack,
66 * which may fail.
67 * It may be acknowledged by the "peer" according to the wire_protocol in use.
68 * this may be a negative ack.
69 * It may receive a faked ack when the network connection is lost and the
70 * transfer log is cleaned up.
71 * Sending may be canceled due to network connection loss.
72 * When it finally has outlived its time,
73 * corresponding dirty bits in the resync-bitmap may be cleared or set,
74 * it will be destroyed,
75 * and completion will be signalled to the originator,
76 * with or without "success".
77 */
78
79 enum drbd_req_event {
80 CREATED,
81 TO_BE_SENT,
82 TO_BE_SUBMITTED,
83
84 /* XXX yes, now I am inconsistent...
85 * these are not "events" but "actions"
86 * oh, well... */
87 QUEUE_FOR_NET_WRITE,
88 QUEUE_FOR_NET_READ,
89 QUEUE_FOR_SEND_OOS,
90
91 SEND_CANCELED,
92 SEND_FAILED,
93 HANDED_OVER_TO_NETWORK,
94 OOS_HANDED_TO_NETWORK,
95 CONNECTION_LOST_WHILE_PENDING,
96 READ_RETRY_REMOTE_CANCELED,
97 RECV_ACKED_BY_PEER,
98 WRITE_ACKED_BY_PEER,
99 WRITE_ACKED_BY_PEER_AND_SIS, /* and set_in_sync */
100 DISCARD_WRITE,
101 POSTPONE_WRITE,
102 NEG_ACKED,
103 BARRIER_ACKED, /* in protocol A and B */
104 DATA_RECEIVED, /* (remote read) */
105
106 READ_COMPLETED_WITH_ERROR,
107 READ_AHEAD_COMPLETED_WITH_ERROR,
108 WRITE_COMPLETED_WITH_ERROR,
109 COMPLETED_OK,
110 RESEND,
111 FAIL_FROZEN_DISK_IO,
112 RESTART_FROZEN_DISK_IO,
113 NOTHING,
114 };
115
116 /* encoding of request states for now. we don't actually need that many bits.
117 * we don't need to do atomic bit operations either, since most of the time we
118 * need to look at the connection state and/or manipulate some lists at the
119 * same time, so we should hold the request lock anyways.
120 */
121 enum drbd_req_state_bits {
122 /* 210
123 * 000: no local possible
124 * 001: to be submitted
125 * UNUSED, we could map: 011: submitted, completion still pending
126 * 110: completed ok
127 * 010: completed with error
128 */
129 __RQ_LOCAL_PENDING,
130 __RQ_LOCAL_COMPLETED,
131 __RQ_LOCAL_OK,
132
133 /* 76543
134 * 00000: no network possible
135 * 00001: to be send
136 * 00011: to be send, on worker queue
137 * 00101: sent, expecting recv_ack (B) or write_ack (C)
138 * 11101: sent,
139 * recv_ack (B) or implicit "ack" (A),
140 * still waiting for the barrier ack.
141 * master_bio may already be completed and invalidated.
142 * 11100: write acked (C),
143 * data received (for remote read, any protocol)
144 * or finally the barrier ack has arrived (B,A)...
145 * request can be freed
146 * 01100: neg-acked (write, protocol C)
147 * or neg-d-acked (read, any protocol)
148 * or killed from the transfer log
149 * during cleanup after connection loss
150 * request can be freed
151 * 01000: canceled or send failed...
152 * request can be freed
153 */
154
155 /* if "SENT" is not set, yet, this can still fail or be canceled.
156 * if "SENT" is set already, we still wait for an Ack packet.
157 * when cleared, the master_bio may be completed.
158 * in (B,A) the request object may still linger on the transaction log
159 * until the corresponding barrier ack comes in */
160 __RQ_NET_PENDING,
161
162 /* If it is QUEUED, and it is a WRITE, it is also registered in the
163 * transfer log. Currently we need this flag to avoid conflicts between
164 * worker canceling the request and tl_clear_barrier killing it from
165 * transfer log. We should restructure the code so this conflict does
166 * no longer occur. */
167 __RQ_NET_QUEUED,
168
169 /* well, actually only "handed over to the network stack".
170 *
171 * TODO can potentially be dropped because of the similar meaning
172 * of RQ_NET_SENT and ~RQ_NET_QUEUED.
173 * however it is not exactly the same. before we drop it
174 * we must ensure that we can tell a request with network part
175 * from a request without, regardless of what happens to it. */
176 __RQ_NET_SENT,
177
178 /* when set, the request may be freed (if RQ_NET_QUEUED is clear).
179 * basically this means the corresponding P_BARRIER_ACK was received */
180 __RQ_NET_DONE,
181
182 /* whether or not we know (C) or pretend (B,A) that the write
183 * was successfully written on the peer.
184 */
185 __RQ_NET_OK,
186
187 /* peer called drbd_set_in_sync() for this write */
188 __RQ_NET_SIS,
189
190 /* keep this last, its for the RQ_NET_MASK */
191 __RQ_NET_MAX,
192
193 /* Set when this is a write, clear for a read */
194 __RQ_WRITE,
195
196 /* Should call drbd_al_complete_io() for this request... */
197 __RQ_IN_ACT_LOG,
198
199 /* The peer has sent a retry ACK */
200 __RQ_POSTPONED,
201 };
202
203 #define RQ_LOCAL_PENDING (1UL << __RQ_LOCAL_PENDING)
204 #define RQ_LOCAL_COMPLETED (1UL << __RQ_LOCAL_COMPLETED)
205 #define RQ_LOCAL_OK (1UL << __RQ_LOCAL_OK)
206
207 #define RQ_LOCAL_MASK ((RQ_LOCAL_OK << 1)-1) /* 0x07 */
208
209 #define RQ_NET_PENDING (1UL << __RQ_NET_PENDING)
210 #define RQ_NET_QUEUED (1UL << __RQ_NET_QUEUED)
211 #define RQ_NET_SENT (1UL << __RQ_NET_SENT)
212 #define RQ_NET_DONE (1UL << __RQ_NET_DONE)
213 #define RQ_NET_OK (1UL << __RQ_NET_OK)
214 #define RQ_NET_SIS (1UL << __RQ_NET_SIS)
215
216 /* 0x1f8 */
217 #define RQ_NET_MASK (((1UL << __RQ_NET_MAX)-1) & ~RQ_LOCAL_MASK)
218
219 #define RQ_WRITE (1UL << __RQ_WRITE)
220 #define RQ_IN_ACT_LOG (1UL << __RQ_IN_ACT_LOG)
221 #define RQ_POSTPONED (1UL << __RQ_POSTPONED)
222
223 /* For waking up the frozen transfer log mod_req() has to return if the request
224 should be counted in the epoch object*/
225 #define MR_WRITE_SHIFT 0
226 #define MR_WRITE (1 << MR_WRITE_SHIFT)
227 #define MR_READ_SHIFT 1
228 #define MR_READ (1 << MR_READ_SHIFT)
229
230 static inline void drbd_req_make_private_bio(struct drbd_request *req, struct bio *bio_src)
231 {
232 struct bio *bio;
233 bio = bio_clone(bio_src, GFP_NOIO); /* XXX cannot fail?? */
234
235 req->private_bio = bio;
236
237 bio->bi_private = req;
238 bio->bi_end_io = drbd_request_endio;
239 bio->bi_next = NULL;
240 }
241
242 /* Short lived temporary struct on the stack.
243 * We could squirrel the error to be returned into
244 * bio->bi_size, or similar. But that would be too ugly. */
245 struct bio_and_error {
246 struct bio *bio;
247 int error;
248 };
249
250 extern void _req_may_be_done(struct drbd_request *req,
251 struct bio_and_error *m);
252 extern int __req_mod(struct drbd_request *req, enum drbd_req_event what,
253 struct bio_and_error *m);
254 extern void complete_master_bio(struct drbd_conf *mdev,
255 struct bio_and_error *m);
256 extern void request_timer_fn(unsigned long data);
257 extern void tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what);
258 extern void _tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what);
259
260 /* use this if you don't want to deal with calling complete_master_bio()
261 * outside the spinlock, e.g. when walking some list on cleanup. */
262 static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what)
263 {
264 struct drbd_conf *mdev = req->w.mdev;
265 struct bio_and_error m;
266 int rv;
267
268 /* __req_mod possibly frees req, do not touch req after that! */
269 rv = __req_mod(req, what, &m);
270 if (m.bio)
271 complete_master_bio(mdev, &m);
272
273 return rv;
274 }
275
276 /* completion of master bio is outside of our spinlock.
277 * We still may or may not be inside some irqs disabled section
278 * of the lower level driver completion callback, so we need to
279 * spin_lock_irqsave here. */
280 static inline int req_mod(struct drbd_request *req,
281 enum drbd_req_event what)
282 {
283 unsigned long flags;
284 struct drbd_conf *mdev = req->w.mdev;
285 struct bio_and_error m;
286 int rv;
287
288 spin_lock_irqsave(&mdev->tconn->req_lock, flags);
289 rv = __req_mod(req, what, &m);
290 spin_unlock_irqrestore(&mdev->tconn->req_lock, flags);
291
292 if (m.bio)
293 complete_master_bio(mdev, &m);
294
295 return rv;
296 }
297
298 static inline bool drbd_should_do_remote(union drbd_state s)
299 {
300 return s.pdsk == D_UP_TO_DATE ||
301 (s.pdsk >= D_INCONSISTENT &&
302 s.conn >= C_WF_BITMAP_T &&
303 s.conn < C_AHEAD);
304 /* Before proto 96 that was >= CONNECTED instead of >= C_WF_BITMAP_T.
305 That is equivalent since before 96 IO was frozen in the C_WF_BITMAP*
306 states. */
307 }
308 static inline bool drbd_should_send_out_of_sync(union drbd_state s)
309 {
310 return s.conn == C_AHEAD || s.conn == C_WF_BITMAP_S;
311 /* pdsk = D_INCONSISTENT as a consequence. Protocol 96 check not necessary
312 since we enter state C_AHEAD only if proto >= 96 */
313 }
314
315 #endif
This page took 0.037342 seconds and 5 git commands to generate.