^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) drbd_req.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) This file is part of DRBD by Philipp Reisner and Lars Ellenberg.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) Copyright (C) 2006-2008, LINBIT Information Technologies GmbH.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) Copyright (C) 2006-2008, Lars Ellenberg <lars.ellenberg@linbit.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) Copyright (C) 2006-2008, Philipp Reisner <philipp.reisner@linbit.com>.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #ifndef _DRBD_REQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #define _DRBD_REQ_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/drbd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include "drbd_int.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) /* The request callbacks will be called in irq context by the IDE drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) and in Softirqs/Tasklets/BH context by the SCSI drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) and by the receiver and worker in kernel-thread context.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) Try to get the locking right :) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * Objects of type struct drbd_request do only exist on a R_PRIMARY node, and are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * associated with IO requests originating from the block layer above us.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * There are quite a few things that may happen to a drbd request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * during its lifetime.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * It will be created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * It will be marked with the intention to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * submitted to local disk and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * send via the network.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * It has to be placed on the transfer log and other housekeeping lists,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * In case we have a network connection.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) * It may be identified as a concurrent (write) request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * and be handled accordingly.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * It may me handed over to the local disk subsystem.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * It may be completed by the local disk subsystem,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * either successfully or with io-error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) * In case it is a READ request, and it failed locally,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * it may be retried remotely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * It may be queued for sending.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * It may be handed over to the network stack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * which may fail.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * It may be acknowledged by the "peer" according to the wire_protocol in use.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * this may be a negative ack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * It may receive a faked ack when the network connection is lost and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * transfer log is cleaned up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * Sending may be canceled due to network connection loss.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * When it finally has outlived its time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * corresponding dirty bits in the resync-bitmap may be cleared or set,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * it will be destroyed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * and completion will be signalled to the originator,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) * with or without "success".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) enum drbd_req_event {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) CREATED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) TO_BE_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) TO_BE_SUBMITTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) /* XXX yes, now I am inconsistent...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) * these are not "events" but "actions"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * oh, well... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) QUEUE_FOR_NET_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) QUEUE_FOR_NET_READ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) QUEUE_FOR_SEND_OOS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) /* An empty flush is queued as P_BARRIER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * which will cause it to complete "successfully",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * even if the local disk flush failed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * Just like "real" requests, empty flushes (blkdev_issue_flush()) will
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * only see an error if neither local nor remote data is reachable. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) QUEUE_AS_DRBD_BARRIER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) SEND_CANCELED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) SEND_FAILED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) HANDED_OVER_TO_NETWORK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) OOS_HANDED_TO_NETWORK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) CONNECTION_LOST_WHILE_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) READ_RETRY_REMOTE_CANCELED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) RECV_ACKED_BY_PEER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) WRITE_ACKED_BY_PEER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) WRITE_ACKED_BY_PEER_AND_SIS, /* and set_in_sync */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) CONFLICT_RESOLVED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) POSTPONE_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) NEG_ACKED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) BARRIER_ACKED, /* in protocol A and B */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) DATA_RECEIVED, /* (remote read) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) COMPLETED_OK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) READ_COMPLETED_WITH_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) READ_AHEAD_COMPLETED_WITH_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) WRITE_COMPLETED_WITH_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) DISCARD_COMPLETED_NOTSUPP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) DISCARD_COMPLETED_WITH_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ABORT_DISK_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) RESEND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) FAIL_FROZEN_DISK_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) RESTART_FROZEN_DISK_IO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) NOTHING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) /* encoding of request states for now. we don't actually need that many bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) * we don't need to do atomic bit operations either, since most of the time we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) * need to look at the connection state and/or manipulate some lists at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) * same time, so we should hold the request lock anyways.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) enum drbd_req_state_bits {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) /* 3210
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) * 0000: no local possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) * 0001: to be submitted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) * UNUSED, we could map: 011: submitted, completion still pending
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * 0110: completed ok
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * 0010: completed with error
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * 1001: Aborted (before completion)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * 1x10: Aborted and completed -> free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) __RQ_LOCAL_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) __RQ_LOCAL_COMPLETED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) __RQ_LOCAL_OK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) __RQ_LOCAL_ABORTED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) /* 87654
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * 00000: no network possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * 00001: to be send
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * 00011: to be send, on worker queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * 00101: sent, expecting recv_ack (B) or write_ack (C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * 11101: sent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * recv_ack (B) or implicit "ack" (A),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * still waiting for the barrier ack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * master_bio may already be completed and invalidated.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * 11100: write acked (C),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * data received (for remote read, any protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * or finally the barrier ack has arrived (B,A)...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * request can be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * 01100: neg-acked (write, protocol C)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * or neg-d-acked (read, any protocol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * or killed from the transfer log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * during cleanup after connection loss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * request can be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * 01000: canceled or send failed...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * request can be freed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) /* if "SENT" is not set, yet, this can still fail or be canceled.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * if "SENT" is set already, we still wait for an Ack packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * when cleared, the master_bio may be completed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * in (B,A) the request object may still linger on the transaction log
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * until the corresponding barrier ack comes in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) __RQ_NET_PENDING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) /* If it is QUEUED, and it is a WRITE, it is also registered in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * transfer log. Currently we need this flag to avoid conflicts between
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) * worker canceling the request and tl_clear_barrier killing it from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) * transfer log. We should restructure the code so this conflict does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) * no longer occur. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) __RQ_NET_QUEUED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* well, actually only "handed over to the network stack".
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * TODO can potentially be dropped because of the similar meaning
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * of RQ_NET_SENT and ~RQ_NET_QUEUED.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * however it is not exactly the same. before we drop it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * we must ensure that we can tell a request with network part
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * from a request without, regardless of what happens to it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) __RQ_NET_SENT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /* when set, the request may be freed (if RQ_NET_QUEUED is clear).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * basically this means the corresponding P_BARRIER_ACK was received */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) __RQ_NET_DONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) /* whether or not we know (C) or pretend (B,A) that the write
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) * was successfully written on the peer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) __RQ_NET_OK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* peer called drbd_set_in_sync() for this write */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) __RQ_NET_SIS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* keep this last, its for the RQ_NET_MASK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) __RQ_NET_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) /* Set when this is a write, clear for a read */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) __RQ_WRITE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) __RQ_WSAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) __RQ_UNMAP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) __RQ_ZEROES,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) /* Should call drbd_al_complete_io() for this request... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) __RQ_IN_ACT_LOG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) /* This was the most recent request during some blk_finish_plug()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * or its implicit from-schedule equivalent.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) * We may use it as hint to send a P_UNPLUG_REMOTE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) __RQ_UNPLUG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) /* The peer has sent a retry ACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) __RQ_POSTPONED,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /* would have been completed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * but was not, because of drbd_suspended() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) __RQ_COMPLETION_SUSP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* We expect a receive ACK (wire proto B) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) __RQ_EXP_RECEIVE_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* We expect a write ACK (wite proto C) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) __RQ_EXP_WRITE_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* waiting for a barrier ack, did an extra kref_get */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) __RQ_EXP_BARR_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #define RQ_LOCAL_PENDING (1UL << __RQ_LOCAL_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) #define RQ_LOCAL_COMPLETED (1UL << __RQ_LOCAL_COMPLETED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) #define RQ_LOCAL_OK (1UL << __RQ_LOCAL_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) #define RQ_LOCAL_ABORTED (1UL << __RQ_LOCAL_ABORTED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) #define RQ_LOCAL_MASK ((RQ_LOCAL_ABORTED << 1)-1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) #define RQ_NET_PENDING (1UL << __RQ_NET_PENDING)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #define RQ_NET_QUEUED (1UL << __RQ_NET_QUEUED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) #define RQ_NET_SENT (1UL << __RQ_NET_SENT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) #define RQ_NET_DONE (1UL << __RQ_NET_DONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define RQ_NET_OK (1UL << __RQ_NET_OK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define RQ_NET_SIS (1UL << __RQ_NET_SIS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define RQ_NET_MASK (((1UL << __RQ_NET_MAX)-1) & ~RQ_LOCAL_MASK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) #define RQ_WRITE (1UL << __RQ_WRITE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) #define RQ_WSAME (1UL << __RQ_WSAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) #define RQ_UNMAP (1UL << __RQ_UNMAP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #define RQ_ZEROES (1UL << __RQ_ZEROES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define RQ_IN_ACT_LOG (1UL << __RQ_IN_ACT_LOG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #define RQ_UNPLUG (1UL << __RQ_UNPLUG)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) #define RQ_POSTPONED (1UL << __RQ_POSTPONED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) #define RQ_COMPLETION_SUSP (1UL << __RQ_COMPLETION_SUSP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) #define RQ_EXP_RECEIVE_ACK (1UL << __RQ_EXP_RECEIVE_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) #define RQ_EXP_WRITE_ACK (1UL << __RQ_EXP_WRITE_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) #define RQ_EXP_BARR_ACK (1UL << __RQ_EXP_BARR_ACK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) /* For waking up the frozen transfer log mod_req() has to return if the request
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) should be counted in the epoch object*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) #define MR_WRITE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #define MR_READ 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static inline void drbd_req_make_private_bio(struct drbd_request *req, struct bio *bio_src)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) bio = bio_clone_fast(bio_src, GFP_NOIO, &drbd_io_bio_set);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) req->private_bio = bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) bio->bi_private = req;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) bio->bi_end_io = drbd_request_endio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) bio->bi_next = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Short lived temporary struct on the stack.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * We could squirrel the error to be returned into
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * bio->bi_iter.bi_size, or similar. But that would be too ugly. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct bio_and_error {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct bio *bio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) extern void start_new_tl_epoch(struct drbd_connection *connection);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) extern void drbd_req_destroy(struct kref *kref);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) extern void _req_may_be_done(struct drbd_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct bio_and_error *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) extern int __req_mod(struct drbd_request *req, enum drbd_req_event what,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) struct bio_and_error *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) extern void complete_master_bio(struct drbd_device *device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct bio_and_error *m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) extern void request_timer_fn(struct timer_list *t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) extern void tl_restart(struct drbd_connection *connection, enum drbd_req_event what);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) extern void _tl_restart(struct drbd_connection *connection, enum drbd_req_event what);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) extern void tl_abort_disk_io(struct drbd_device *device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) /* this is in drbd_main.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) extern void drbd_restart_request(struct drbd_request *req);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) /* use this if you don't want to deal with calling complete_master_bio()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) * outside the spinlock, e.g. when walking some list on cleanup. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static inline int _req_mod(struct drbd_request *req, enum drbd_req_event what)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct drbd_device *device = req->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct bio_and_error m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) /* __req_mod possibly frees req, do not touch req after that! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) rv = __req_mod(req, what, &m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) if (m.bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) complete_master_bio(device, &m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) /* completion of master bio is outside of our spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * We still may or may not be inside some irqs disabled section
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * of the lower level driver completion callback, so we need to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * spin_lock_irqsave here. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) static inline int req_mod(struct drbd_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) enum drbd_req_event what)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct drbd_device *device = req->device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) struct bio_and_error m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) spin_lock_irqsave(&device->resource->req_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) rv = __req_mod(req, what, &m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) spin_unlock_irqrestore(&device->resource->req_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (m.bio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) complete_master_bio(device, &m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) return rv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) extern bool drbd_should_do_remote(union drbd_dev_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) #endif