Merge branch 'drm-nouveau-fixes-3.8' of git://anongit.freedesktop.org/git/nouveau...
[deliverable/linux.git] / drivers / block / drbd / drbd_req.h
CommitLineData
b411b363
PR
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
b411b363
PR
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,
3ad2f3fb 60 * either successfully or with io-error.
b411b363
PR
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
79enum drbd_req_event {
8554df1c
AG
80 CREATED,
81 TO_BE_SENT,
82 TO_BE_SUBMITTED,
b411b363
PR
83
84 /* XXX yes, now I am inconsistent...
73a01a18 85 * these are not "events" but "actions"
b411b363 86 * oh, well... */
8554df1c
AG
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 */
d4dabbe2 100 CONFLICT_RESOLVED,
7be8da07 101 POSTPONE_WRITE,
8554df1c
AG
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,
cdfda633 109 ABORT_DISK_IO,
8554df1c
AG
110 COMPLETED_OK,
111 RESEND,
112 FAIL_FROZEN_DISK_IO,
113 RESTART_FROZEN_DISK_IO,
114 NOTHING,
b411b363
PR
115};
116
117/* encoding of request states for now. we don't actually need that many bits.
118 * we don't need to do atomic bit operations either, since most of the time we
119 * need to look at the connection state and/or manipulate some lists at the
120 * same time, so we should hold the request lock anyways.
121 */
122enum drbd_req_state_bits {
cdfda633
PR
123 /* 3210
124 * 0000: no local possible
125 * 0001: to be submitted
b411b363 126 * UNUSED, we could map: 011: submitted, completion still pending
cdfda633
PR
127 * 0110: completed ok
128 * 0010: completed with error
129 * 1001: Aborted (before completion)
130 * 1x10: Aborted and completed -> free
b411b363
PR
131 */
132 __RQ_LOCAL_PENDING,
133 __RQ_LOCAL_COMPLETED,
134 __RQ_LOCAL_OK,
cdfda633 135 __RQ_LOCAL_ABORTED,
b411b363 136
cdfda633 137 /* 87654
b411b363
PR
138 * 00000: no network possible
139 * 00001: to be send
140 * 00011: to be send, on worker queue
141 * 00101: sent, expecting recv_ack (B) or write_ack (C)
142 * 11101: sent,
143 * recv_ack (B) or implicit "ack" (A),
144 * still waiting for the barrier ack.
145 * master_bio may already be completed and invalidated.
8554df1c
AG
146 * 11100: write acked (C),
147 * data received (for remote read, any protocol)
b411b363
PR
148 * or finally the barrier ack has arrived (B,A)...
149 * request can be freed
150 * 01100: neg-acked (write, protocol C)
151 * or neg-d-acked (read, any protocol)
152 * or killed from the transfer log
153 * during cleanup after connection loss
154 * request can be freed
155 * 01000: canceled or send failed...
156 * request can be freed
157 */
158
159 /* if "SENT" is not set, yet, this can still fail or be canceled.
160 * if "SENT" is set already, we still wait for an Ack packet.
161 * when cleared, the master_bio may be completed.
162 * in (B,A) the request object may still linger on the transaction log
163 * until the corresponding barrier ack comes in */
164 __RQ_NET_PENDING,
165
166 /* If it is QUEUED, and it is a WRITE, it is also registered in the
167 * transfer log. Currently we need this flag to avoid conflicts between
168 * worker canceling the request and tl_clear_barrier killing it from
169 * transfer log. We should restructure the code so this conflict does
170 * no longer occur. */
171 __RQ_NET_QUEUED,
172
173 /* well, actually only "handed over to the network stack".
174 *
175 * TODO can potentially be dropped because of the similar meaning
176 * of RQ_NET_SENT and ~RQ_NET_QUEUED.
177 * however it is not exactly the same. before we drop it
178 * we must ensure that we can tell a request with network part
179 * from a request without, regardless of what happens to it. */
180 __RQ_NET_SENT,
181
182 /* when set, the request may be freed (if RQ_NET_QUEUED is clear).
183 * basically this means the corresponding P_BARRIER_ACK was received */
184 __RQ_NET_DONE,
185
186 /* whether or not we know (C) or pretend (B,A) that the write
187 * was successfully written on the peer.
188 */
189 __RQ_NET_OK,
190
191 /* peer called drbd_set_in_sync() for this write */
192 __RQ_NET_SIS,
193
194 /* keep this last, its for the RQ_NET_MASK */
195 __RQ_NET_MAX,
288f422e
PR
196
197 /* Set when this is a write, clear for a read */
198 __RQ_WRITE,
0778286a
PR
199
200 /* Should call drbd_al_complete_io() for this request... */
201 __RQ_IN_ACT_LOG,
7be8da07
AG
202
203 /* The peer has sent a retry ACK */
204 __RQ_POSTPONED,
303d1448 205
a0d856df
LE
206 /* would have been completed,
207 * but was not, because of drbd_suspended() */
208 __RQ_COMPLETION_SUSP,
209
303d1448
PR
210 /* We expect a receive ACK (wire proto B) */
211 __RQ_EXP_RECEIVE_ACK,
212
213 /* We expect a write ACK (wite proto C) */
214 __RQ_EXP_WRITE_ACK,
a0d856df
LE
215
216 /* waiting for a barrier ack, did an extra kref_get */
217 __RQ_EXP_BARR_ACK,
b411b363
PR
218};
219
220#define RQ_LOCAL_PENDING (1UL << __RQ_LOCAL_PENDING)
221#define RQ_LOCAL_COMPLETED (1UL << __RQ_LOCAL_COMPLETED)
222#define RQ_LOCAL_OK (1UL << __RQ_LOCAL_OK)
cdfda633 223#define RQ_LOCAL_ABORTED (1UL << __RQ_LOCAL_ABORTED)
b411b363 224
cdfda633 225#define RQ_LOCAL_MASK ((RQ_LOCAL_ABORTED << 1)-1)
b411b363
PR
226
227#define RQ_NET_PENDING (1UL << __RQ_NET_PENDING)
228#define RQ_NET_QUEUED (1UL << __RQ_NET_QUEUED)
229#define RQ_NET_SENT (1UL << __RQ_NET_SENT)
230#define RQ_NET_DONE (1UL << __RQ_NET_DONE)
231#define RQ_NET_OK (1UL << __RQ_NET_OK)
232#define RQ_NET_SIS (1UL << __RQ_NET_SIS)
233
234/* 0x1f8 */
235#define RQ_NET_MASK (((1UL << __RQ_NET_MAX)-1) & ~RQ_LOCAL_MASK)
236
288f422e 237#define RQ_WRITE (1UL << __RQ_WRITE)
0778286a 238#define RQ_IN_ACT_LOG (1UL << __RQ_IN_ACT_LOG)
7be8da07 239#define RQ_POSTPONED (1UL << __RQ_POSTPONED)
a0d856df 240#define RQ_COMPLETION_SUSP (1UL << __RQ_COMPLETION_SUSP)
303d1448
PR
241#define RQ_EXP_RECEIVE_ACK (1UL << __RQ_EXP_RECEIVE_ACK)
242#define RQ_EXP_WRITE_ACK (1UL << __RQ_EXP_WRITE_ACK)
a0d856df 243#define RQ_EXP_BARR_ACK (1UL << __RQ_EXP_BARR_ACK)
288f422e 244
11b58e73
PR
245/* For waking up the frozen transfer log mod_req() has to return if the request
246 should be counted in the epoch object*/
f497609e
AG
247#define MR_WRITE 1
248#define MR_READ 2
11b58e73 249
5ba82308
PR
250static inline void drbd_req_make_private_bio(struct drbd_request *req, struct bio *bio_src)
251{
252 struct bio *bio;
253 bio = bio_clone(bio_src, GFP_NOIO); /* XXX cannot fail?? */
254
255 req->private_bio = bio;
256
257 bio->bi_private = req;
fcefa62e 258 bio->bi_end_io = drbd_request_endio;
5ba82308
PR
259 bio->bi_next = NULL;
260}
261
b411b363
PR
262/* Short lived temporary struct on the stack.
263 * We could squirrel the error to be returned into
264 * bio->bi_size, or similar. But that would be too ugly. */
265struct bio_and_error {
266 struct bio *bio;
267 int error;
268};
269
2681f7f6 270extern void start_new_tl_epoch(struct drbd_tconn *tconn);
9a278a79 271extern void drbd_req_destroy(struct kref *kref);
b411b363
PR
272extern void _req_may_be_done(struct drbd_request *req,
273 struct bio_and_error *m);
2a80699f 274extern int __req_mod(struct drbd_request *req, enum drbd_req_event what,
b411b363
PR
275 struct bio_and_error *m);
276extern void complete_master_bio(struct drbd_conf *mdev,
277 struct bio_and_error *m);
7fde2be9 278extern void request_timer_fn(unsigned long data);
2f5cdd0b
PR
279extern void tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what);
280extern void _tl_restart(struct drbd_tconn *tconn, enum drbd_req_event what);
b411b363 281
2312f0b3 282/* this is in drbd_main.c */
9d05e7c4 283extern void drbd_restart_request(struct drbd_request *req);
2312f0b3 284
b411b363
PR
285/* use this if you don't want to deal with calling complete_master_bio()
286 * outside the spinlock, e.g. when walking some list on cleanup. */
2a80699f 287static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what)
b411b363 288{
a21e9298 289 struct drbd_conf *mdev = req->w.mdev;
b411b363 290 struct bio_and_error m;
2a80699f 291 int rv;
b411b363
PR
292
293 /* __req_mod possibly frees req, do not touch req after that! */
2a80699f 294 rv = __req_mod(req, what, &m);
b411b363
PR
295 if (m.bio)
296 complete_master_bio(mdev, &m);
2a80699f
PR
297
298 return rv;
b411b363
PR
299}
300
759fbdfb
PR
301/* completion of master bio is outside of our spinlock.
302 * We still may or may not be inside some irqs disabled section
303 * of the lower level driver completion callback, so we need to
304 * spin_lock_irqsave here. */
2a80699f 305static inline int req_mod(struct drbd_request *req,
b411b363
PR
306 enum drbd_req_event what)
307{
759fbdfb 308 unsigned long flags;
a21e9298 309 struct drbd_conf *mdev = req->w.mdev;
b411b363 310 struct bio_and_error m;
2a80699f
PR
311 int rv;
312
87eeee41 313 spin_lock_irqsave(&mdev->tconn->req_lock, flags);
2a80699f 314 rv = __req_mod(req, what, &m);
87eeee41 315 spin_unlock_irqrestore(&mdev->tconn->req_lock, flags);
b411b363
PR
316
317 if (m.bio)
318 complete_master_bio(mdev, &m);
2a80699f
PR
319
320 return rv;
b411b363 321}
6a35c45f 322
da9fbc27 323static inline bool drbd_should_do_remote(union drbd_dev_state s)
6a35c45f
PR
324{
325 return s.pdsk == D_UP_TO_DATE ||
326 (s.pdsk >= D_INCONSISTENT &&
327 s.conn >= C_WF_BITMAP_T &&
328 s.conn < C_AHEAD);
329 /* Before proto 96 that was >= CONNECTED instead of >= C_WF_BITMAP_T.
330 That is equivalent since before 96 IO was frozen in the C_WF_BITMAP*
331 states. */
332}
da9fbc27 333static inline bool drbd_should_send_out_of_sync(union drbd_dev_state s)
6a35c45f
PR
334{
335 return s.conn == C_AHEAD || s.conn == C_WF_BITMAP_S;
336 /* pdsk = D_INCONSISTENT as a consequence. Protocol 96 check not necessary
337 since we enter state C_AHEAD only if proto >= 96 */
338}
339
b411b363 340#endif
This page took 0.123664 seconds and 5 git commands to generate.