/*
* iSCSI lib functions
*
* Copyright (C) 2006 Red Hat, Inc. All rights reserved.
* Copyright (C) 2004 - 2006 Mike Christie
* Copyright (C) 2004 - 2005 Dmitry Yusupov
* Copyright (C) 2004 - 2005 Alex Aizman
* maintained by open-iscsi@googlegroups.com
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <linux/types.h>
#include <linux/kfifo.h>
#include <linux/delay.h>
#include <linux/log2.h>
#include <asm/unaligned.h>
#include <net/tcp.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_eh.h>
#include <scsi/scsi_tcq.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi.h>
#include <scsi/scsi_transport.h>
#include "iscsi_proto.h"
#include "scsi_transport_iscsi.h"
#include "libiscsi.h"
static int iscsi_dbg_lib_conn;
module_param_named(debug_libiscsi_conn, iscsi_dbg_lib_conn, int,
S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug_libiscsi_conn,
"Turn on debugging for connections in libiscsi module. "
"Set to 1 to turn on, and zero to turn off. Default is off.");
static int iscsi_dbg_lib_session;
module_param_named(debug_libiscsi_session, iscsi_dbg_lib_session, int,
S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug_libiscsi_session,
"Turn on debugging for sessions in libiscsi module. "
"Set to 1 to turn on, and zero to turn off. Default is off.");
static int iscsi_dbg_lib_eh;
module_param_named(debug_libiscsi_eh, iscsi_dbg_lib_eh, int,
S_IRUGO | S_IWUSR);
MODULE_PARM_DESC(debug_libiscsi_eh,
"Turn on debugging for error handling in libiscsi module. "
"Set to 1 to turn on, and zero to turn off. Default is off.");
#define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...) \
do { \
if (iscsi_dbg_lib_conn) \
iscsi_conn_printk(KERN_INFO, _conn, \
"%s " dbg_fmt, \
__func__, ##arg); \
} while (0);
#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...) \
do { \
if (iscsi_dbg_lib_session) \
iscsi_session_printk(KERN_INFO, _session, \
"%s " dbg_fmt, \
__func__, ##arg); \
} while (0);
#define ISCSI_DBG_EH(_session, dbg_fmt, arg...) \
do { \
if (iscsi_dbg_lib_eh) \
iscsi_session_printk(KERN_INFO, _session, \
"%s " dbg_fmt, \
__func__, ##arg); \
} while (0);
/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
#define SNA32_CHECK 2147483648UL
static int iscsi_sna_lt(u32 n1, u32 n2)
{
return n1 != n2 && ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
(n1 > n2 && (n2 - n1 < SNA32_CHECK)));
}
/* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
static int iscsi_sna_lte(u32 n1, u32 n2)
{
return n1 == n2 || ((n1 < n2 && (n2 - n1 < SNA32_CHECK)) ||
(n1 > n2 && (n2 - n1 < SNA32_CHECK)));
}
inline void iscsi_conn_queue_work(struct iscsi_conn *conn)
{
struct Scsi_Host *shost = conn->session->host;
struct iscsi_host *ihost = shost_priv(shost);
if (ihost->workq)
queue_work(ihost->workq, &conn->xmitwork);
}
EXPORT_SYMBOL_GPL(iscsi_conn_queue_work);
void
iscsi_update_cmdsn(struct iscsi_session *session, struct iscsi_nopin *hdr)
{
uint32_t max_cmdsn = be32_to_cpu(hdr->max_cmdsn);
uint32_t exp_cmdsn = be32_to_cpu(hdr->exp_cmdsn);
/*
* standard specifies this check for when to update expected and
* max sequence numbers
*/
if (iscsi_sna_lt(max_cmdsn, exp_cmdsn - 1))
return;
if (exp_cmdsn != session->exp_cmdsn &&
!iscsi_sna_lt(exp_cmdsn, session->exp_cmdsn))
session->exp_cmdsn = exp_cmdsn;
if (max_cmdsn != session->max_cmdsn &&
!iscsi_sna_lt(max_cmdsn, session->max_cmdsn)) {
session->max_cmdsn = max_cmdsn;
/*
* if the window closed with IO queued, then kick the
* xmit thread
*/
if (!list_empty(&session->leadconn->cmdqueue) ||
!list_empty(&session->leadconn->mgmtqueue))
iscsi_conn_queue_work(session->leadconn);
}
}
EXPORT_SYMBOL_GPL(iscsi_update_cmdsn);
/**
* iscsi_prep_data_out_pdu - initialize Data-Out
* @task: scsi command task
* @r2t: R2T info
* @hdr: iscsi data in pdu
*
* Notes:
* Initialize Data-Out within this R2T sequence and finds
* proper data_offset within this SCSI command.
*
* This function is called with connection lock taken.
**/
void iscsi_prep_data_out_pdu(struct iscsi_task *task, struct iscsi_r2t_info *r2t,
struct iscsi_data *hdr)
{
struct iscsi_conn *conn = task->conn;
unsigned int left = r2t->data_length - r2t->sent;
task->hdr_len = sizeof(struct iscsi_data);
memset(hdr, 0, sizeof(struct iscsi_data));
hdr->ttt = r2t->ttt;
hdr->datasn = cpu_to_be32(r2t->datasn);
r2t->datasn++;
hdr->opcode = ISCSI_OP_SCSI_DATA_OUT;
memcpy(hdr->lun, task->lun, sizeof(hdr->lun));
hdr->itt = task->hdr_itt;
hdr->exp_statsn = r2t->exp_statsn;
hdr->offset = cpu_to_be32(r2t->data_offset + r2t->sent);
if (left > conn->max_xmit_dlength) {
hton24(hdr->dlength, conn->max_xmit_dlength);
r2t->data_count = conn->max_xmit_dlength;
hdr->flags = 0;
} else {
hton24(hdr->dlength, left);
r2t->data_count = left;
hdr->flags = ISCSI_FLAG_CMD_FINAL;
}
conn->dataout_pdus_cnt++;
}
EXPORT_SYMBOL_GPL(iscsi_prep_data_out_pdu);
static int iscsi_add_hdr(struct iscsi_task *task, unsigned len)
{
unsigned exp_len = task->hdr_len + len;
if (exp_len > task->hdr_max) {
WARN_ON(1);
return -EINVAL;
}
WARN_ON(len & (ISCSI_PAD_LEN - 1)); /* caller must pad the AHS */
task->hdr_len = exp_len;
return 0;
}
/*
* make an extended cdb AHS
*/
static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
{
struct scsi_cmnd *cmd = task->sc;
unsigned rlen, pad_len;
unsigned short ahslength;
struct iscsi_ecdb_ahdr *ecdb_ahdr;
int rc;
ecdb_ahdr = iscsi_next_hdr(task);
rlen = cmd->cmd_len - ISCSI_CDB_SIZE;
BUG_ON(rlen > sizeof(ecdb_ahdr->ecdb));
ahslength = rlen + sizeof(ecdb_ahdr->reserved);
pad_len = iscsi_padding(rlen);
rc = iscsi_add_hdr(task, sizeof(ecdb_ahdr->ahslength) +
sizeof(ecdb_ahdr->ahstype) + ahslength + pad_len);
if (rc)
return rc;
if (pad_len)
memset(&ecdb_ahdr->ecdb[rlen], 0, pad_len);
ecdb_ahdr->ahslength = cpu_to_be16(ahslength);
ecdb_ahdr->ahstype = ISCSI_AHSTYPE_CDB;
ecdb_ahdr->reserved = 0;
memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen);
ISCSI_DBG_SESSION(task->conn->session,
"iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
"rlen %d pad_len %d ahs_length %d iscsi_headers_size "
"%u\n", cmd->cmd_len, rlen, pad_len, ahslength,
task->hdr_len);
return 0;
}
static int iscsi_prep_bidi_ahs(struct iscsi_task *task)
{
struct scsi_cmnd *sc = task->sc;
struct iscsi_rlength_ahdr *rlen_ahdr;
int rc;
rlen_ahdr = iscsi_next_hdr(task);
rc = iscsi_add_hdr(task, sizeof(*rlen_ahdr));
if (rc)
return rc;
rlen_ahdr->ahslength =
cpu_to_be16(sizeof(rlen_ahdr->read_length) +
sizeof(rlen_ahdr->reserved));
rlen_ahdr->ahstype = ISCSI_AHSTYPE_RLENGTH;
rlen_ahdr->reserved = 0;
rlen_ahdr->read_length = cpu_to_be32(scsi_in(sc)->length);
ISCSI_DBG_SESSION(task->conn->session,
"bidi-in rlen_ahdr->read_length(%d) "
"rlen_ahdr->ahslength(%d)\n",
be32_to_cpu(rlen_ahdr->read_length),
be16_to_cpu(rlen_ahdr->ahslength));
return 0;
}
/**
* iscsi_prep_scsi_cmd_pdu - prep iscsi scsi cmd pdu
* @task: iscsi task
*
* Prep basic iSCSI PDU fields for a scsi cmd pdu. The LLD should set
* fields like dlength or final based on h
没有合适的资源?快使用搜索试试~ 我知道了~
open-iscsi 源码包
共403个文件
c:138个
h:135个
o:28个
5星 · 超过95%的资源 需积分: 41 29 下载量 145 浏览量
2011-05-13
15:16:07
上传
评论
收藏 3.31MB RAR 举报
温馨提示
open-iscsi最新源码包(2011年12月最新) 下载后解压直接make make install就可以了 可以通过KSRC制定内核
资源推荐
资源详情
资源评论
收起资源包目录
open-iscsi 源码包 (403个子文件)
iscsiadm.8 12KB
iscsiadm.8 12KB
iscsid.8 2KB
iscsid.8 2KB
iscsi_discovery.8 1KB
iscsi_discovery.8 1KB
libiscsi.c 79KB
prom_lex.c 71KB
prom_lex.c 71KB
libiscsi.c 71KB
initiator.c 66KB
initiator.c 66KB
initiator.c 63KB
initiator.c 59KB
iscsiadm.c 57KB
prom_parse.tab.c 57KB
prom_parse.tab.c 57KB
idbm.c 56KB
idbm.c 55KB
idbm.c 55KB
scsi_transport_iscsi.c 54KB
scsi_transport_iscsi.c 54KB
idbm.c 54KB
iscsi_tcp.c 52KB
iscsiadm.c 52KB
iscsiadm.c 52KB
auth.c 52KB
auth.c 52KB
复件 iscsiadm.c 52KB
auth.c 50KB
auth.c 50KB
iscsiadm.c 50KB
复件 iscsiadm.c 50KB
login.c 44KB
login.c 44KB
login.c 43KB
login.c 43KB
discovery.c 33KB
discovery.c 33KB
libiscsi_tcp.c 32KB
discovery.c 32KB
iscsi_sysfs.c 31KB
iscsi_sysfs.c 31KB
iscsi_sysfs.c 31KB
discovery.c 30KB
iscsi_sysfs.c 30KB
netlink.c 27KB
netlink.c 27KB
iscsi_tcp.c 26KB
netlink.c 26KB
netlink.c 26KB
io.c 23KB
io.c 23KB
io.c 22KB
io.c 22KB
sysfs.c 19KB
sysfs.c 19KB
sysfs.c 18KB
iface.c 18KB
iface.c 18KB
isns.c 18KB
isns.c 18KB
isns.c 17KB
iface.c 17KB
isns.c 17KB
iface.c 16KB
sysfs.c 15KB
mgmt_ipc.c 14KB
fwparam_ppc.c 14KB
iscsid.c 14KB
iscsid.c 14KB
iscsid.c 14KB
mgmt_ipc.c 13KB
mgmt_ipc.c 13KB
iscsid.c 13KB
mgmt_ipc.c 13KB
fwparam_ibft.c 13KB
fwparam_ibft.c 13KB
fwparam_ppc.c 12KB
iscsistart.c 12KB
iscsistart.c 12KB
iscsistart.c 12KB
ioctl.c 11KB
ioctl.c 11KB
iscsistart.c 11KB
ioctl.c 10KB
ioctl.c 10KB
session_info.c 10KB
session_info.c 10KB
util.c 10KB
session_info.c 10KB
util.c 9KB
util.c 9KB
log.c 9KB
log.c 9KB
util.c 9KB
fwparam_ibft_sysfs.c 9KB
log.c 9KB
log.c 9KB
actor.c 8KB
共 403 条
- 1
- 2
- 3
- 4
- 5
资源评论
- thinkpad_x312011-09-12源码很全,很好
- paterhai2012-08-30我开始下了一个open iscsi 1.0的版本,这个才是我想要的。
- mxltxt2020-02-18这个源码可以用 还不错 谢谢分享
liuyang1943
- 粉丝: 57
- 资源: 33
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 珍藏多年的基于matlab实现潮流计算程序源代码集合,包含多个潮流计算程序.rar
- 使用FPGA实现串-并型乘法器
- 基于matlab实现针对基于双曲线定位的DV-Hop算法中误差误差出一种基于加权双曲线定位的DV-Hop改进算法.rar
- 基于matlab实现由遗传算法开发的整数规划,车辆调度问题.rar
- 电视家7.0(对电视配置要求高).apk
- 免费计算机毕业设计-基于JavaEE的医院病历管理系统设计与实现(包含论文+源码)
- 手机端 我的世界融合植物大战僵尸版.apk
- 植物大战僵尸 · 戴夫的老年生活 手机版.apk
- Runcraft · 我的世界跑酷游戏 手机端.apk
- pta题库答案c语言.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功