]> git.proxmox.com Git - ceph.git/blame - ceph/src/spdk/lib/iscsi/task.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / spdk / lib / iscsi / task.h
CommitLineData
7c673cae
FG
1/*-
2 * BSD LICENSE
3 *
4 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
5 * Copyright (c) Intel Corporation.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 * * Neither the name of Intel Corporation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#ifndef SPDK_ISCSI_TASK_H
36#define SPDK_ISCSI_TASK_H
37
38#include "iscsi/iscsi.h"
39#include "spdk/scsi.h"
11fdf7f2 40#include "spdk/util.h"
7c673cae
FG
41
42struct spdk_iscsi_task {
43 struct spdk_scsi_task scsi;
44
11fdf7f2
TL
45 struct spdk_iscsi_task *parent;
46
47 struct spdk_iscsi_conn *conn;
7c673cae
FG
48 struct spdk_iscsi_pdu *pdu;
49 uint32_t outstanding_r2t;
50
11fdf7f2
TL
51 uint32_t desired_data_transfer_length;
52
53 /* Only valid for Read/Write */
54 uint32_t bytes_completed;
55
56 uint32_t data_out_cnt;
57
7c673cae
FG
58 /*
59 * Tracks the current offset of large read io.
60 */
61 uint32_t current_datain_offset;
62
63 /*
64 * next_expected_r2t_offset is used when we receive
65 * the DataOUT PDU.
66 */
67 uint32_t next_expected_r2t_offset;
68
69 /*
70 * Tracks the length of the R2T that is in progress.
71 * Used to check that an R2T burst does not exceed
72 * MaxBurstLength.
73 */
74 uint32_t current_r2t_length;
75
76 /*
77 * next_r2t_offset is used when we are sending the
78 * R2T packet to keep track of next offset of r2t.
79 */
80 uint32_t next_r2t_offset;
81 uint32_t R2TSN;
11fdf7f2 82 uint32_t r2t_datasn; /* record next datasn for a r2tsn */
7c673cae
FG
83 uint32_t acked_r2tsn; /* next r2tsn to be acked */
84 uint32_t datain_datasn;
85 uint32_t acked_data_sn; /* next expected datain datasn */
86 uint32_t ttt;
87
11fdf7f2
TL
88 uint32_t tag;
89
90 /**
91 * Record the lun id just in case the lun is invalid,
92 * which will happen when hot removing the lun.
93 */
94 int lun_id;
95
7c673cae 96 TAILQ_ENTRY(spdk_iscsi_task) link;
11fdf7f2
TL
97
98 TAILQ_HEAD(subtask_list, spdk_iscsi_task) subtask_list;
99 TAILQ_ENTRY(spdk_iscsi_task) subtask_link;
100 bool is_queued; /* is queued in scsi layer for handling */
7c673cae
FG
101};
102
103static inline void
104spdk_iscsi_task_put(struct spdk_iscsi_task *task)
105{
106 spdk_scsi_task_put(&task->scsi);
107}
108
109static inline struct spdk_iscsi_pdu *
110spdk_iscsi_task_get_pdu(struct spdk_iscsi_task *task)
111{
112 return task->pdu;
113}
114
115static inline void
116spdk_iscsi_task_set_pdu(struct spdk_iscsi_task *task, struct spdk_iscsi_pdu *pdu)
117{
118 task->pdu = pdu;
119}
120
121static inline struct iscsi_bhs *
122spdk_iscsi_task_get_bhs(struct spdk_iscsi_task *task)
123{
124 return &spdk_iscsi_task_get_pdu(task)->bhs;
125}
126
127static inline void
128spdk_iscsi_task_associate_pdu(struct spdk_iscsi_task *task, struct spdk_iscsi_pdu *pdu)
129{
130 spdk_iscsi_task_set_pdu(task, pdu);
131 pdu->ref++;
132}
133
134static inline void
135spdk_iscsi_task_disassociate_pdu(struct spdk_iscsi_task *task)
136{
137 if (spdk_iscsi_task_get_pdu(task)) {
138 spdk_put_pdu(spdk_iscsi_task_get_pdu(task));
139 spdk_iscsi_task_set_pdu(task, NULL);
140 }
141}
142
143static inline int
144spdk_iscsi_task_is_immediate(struct spdk_iscsi_task *task)
145{
146 struct iscsi_bhs_scsi_req *scsi_req;
147
148 scsi_req = (struct iscsi_bhs_scsi_req *)spdk_iscsi_task_get_bhs(task);
149 return (scsi_req->immediate == 1);
150}
151
152static inline int
153spdk_iscsi_task_is_read(struct spdk_iscsi_task *task)
154{
155 struct iscsi_bhs_scsi_req *scsi_req;
156
157 scsi_req = (struct iscsi_bhs_scsi_req *)spdk_iscsi_task_get_bhs(task);
11fdf7f2 158 return (scsi_req->read_bit == 1);
7c673cae
FG
159}
160
161static inline uint32_t
162spdk_iscsi_task_get_cmdsn(struct spdk_iscsi_task *task)
163{
164 return spdk_iscsi_task_get_pdu(task)->cmd_sn;
165}
166
11fdf7f2
TL
167struct spdk_iscsi_task *spdk_iscsi_task_get(struct spdk_iscsi_conn *conn,
168 struct spdk_iscsi_task *parent,
169 spdk_scsi_task_cpl cpl_fn);
7c673cae
FG
170
171static inline struct spdk_iscsi_task *
11fdf7f2 172spdk_iscsi_task_from_scsi_task(struct spdk_scsi_task *task)
7c673cae 173{
11fdf7f2
TL
174 return SPDK_CONTAINEROF(task, struct spdk_iscsi_task, scsi);
175}
7c673cae 176
11fdf7f2
TL
177static inline struct spdk_iscsi_task *
178spdk_iscsi_task_get_primary(struct spdk_iscsi_task *task)
179{
180 if (task->parent) {
181 return task->parent;
182 } else {
183 return task;
184 }
7c673cae
FG
185}
186
187#endif /* SPDK_ISCSI_TASK_H */