Libiscsi: iSER implementation

This commit includes all iSER implementation in libscsi
library and utilities.

Also, adding iser option in url.

Change-Id: I55ca8a9d4db802e72eb991061260dbb0bd0ef9ba
Signed-off-by: Roy Shterman <roysh@mellanox.com>
This commit is contained in:
Roy Shterman
2016-05-27 18:47:25 +03:00
committed by Ronnie Sahlberg
parent 0a1b96c383
commit a628264ef0
11 changed files with 1718 additions and 6 deletions

2
README
View File

@@ -39,6 +39,8 @@ Arguments:
Username and password for bidirectional CHAP authentication:
target_user=<account>
target_password=<password>
Transport:
iser
Example:

View File

@@ -1,6 +1,6 @@
AM_CPPFLAGS=-I. -I${srcdir}/../include "-D_U_=__attribute__((unused))" \
"-D_R_(A,B)=__attribute__((format(printf,A,B)))"
AM_CFLAGS=$(WARN_CFLAGS)
AM_CFLAGS=$(WARN_CFLAGS) -I/usr/include
LDADD = ../lib/libiscsi.la
noinst_PROGRAMS = iscsiclient iscsi-dd

View File

@@ -389,6 +389,8 @@ void iscsi_init_tcp_transport(struct iscsi_context *iscsi);
void iscsi_tcp_free_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
int iscsi_service_reconnect_if_loggedin(struct iscsi_context *iscsi);
struct iscsi_transport {
int (*connect)(struct iscsi_context *iscsi, union socket_address *sa, int ai_family);
int (*queue_pdu)(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);

View File

@@ -53,7 +53,8 @@ struct scsi_iovec;
"<host>[:<port>]\""
enum iscsi_transport_type {
TCP_TRANSPORT = 0
TCP_TRANSPORT = 0,
ISER_TRANSPORT = 1
};
EXTERN void iscsi_set_cache_allocations(struct iscsi_context *iscsi, int ca);
@@ -150,6 +151,7 @@ struct iscsi_url {
char target_passwd[MAX_STRING_SIZE + 1];
int lun;
struct iscsi_context *iscsi;
enum iscsi_transport_type transport;
};
/*
@@ -270,6 +272,7 @@ EXTERN int iscsi_init_transport(struct iscsi_context *iscsi,
*/
EXTERN int iscsi_set_alias(struct iscsi_context *iscsi, const char *alias);
/*
* Set the iqn name of the taqget to login to.
* The target name must be set before a normal-login can be initiated.

216
include/iser-private.h Normal file
View File

@@ -0,0 +1,216 @@
/*
Copyright (c) 2014-2016, Mellanox Technologies, Ltd. All rights reserved.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __iser_private_h__
#define __iser_private_h__
#include <stdint.h>
#include <time.h>
#include "iscsi-private.h"
#include "scsi-lowlevel.h"
#include <strings.h>
#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <pthread.h>
#include <semaphore.h>
#ifdef __linux
#include <infiniband/verbs.h>
#include <rdma/rdma_cma.h>
#include <rdma/rdma_verbs.h>
#define unlikely(x) __builtin_expect (!!(x), 0)
#define ISER_VER 0x10
#define ISER_WSV 0x08
#define ISER_RSV 0x04
#define NUM_MRS 0x100
#define DATA_BUFFER_SIZE 0x40000
#define ISER_HEADERS_LEN (sizeof(struct iser_hdr) + ISCSI_RAW_HEADER_SIZE)
#define ISER_RECV_DATA_SEG_LEN 128
#define ISER_RX_PAYLOAD_SIZE (ISER_HEADERS_LEN + ISER_RECV_DATA_SEG_LEN)
#define ISER_RX_LOGIN_SIZE (ISER_HEADERS_LEN + ISCSI_DEF_MAX_RECV_SEG_LEN)
#define ISCSI_DEF_MAX_RECV_SEG_LEN 8192
#define BHSSC_FLAGS_R 0x40
#define BHSSC_FLAGS_W 0x20
#define ISER_MAX_CQ_LEN 1024
#define ISER_ZBVA_NOT_SUPPORTED 0x80
#define ISER_SEND_W_INV_NOT_SUPPORTED 0x40
enum desc_type {
ISCSI_CONTROL = 0,
ISCSI_COMMAND};
enum conn_state{
CONN_ERROR = 0,
CONN_DISCONNECTED,
CONN_ESTABLISHED};
enum data_dir{
DATA_WRITE = 0,
DATA_READ};
#define SHIFT_4K 12
#define SIZE_4K (1ULL << SHIFT_4K)
#define MASK_4K (~(SIZE_4K-1))
#define ISER_DEF_XMIT_CMDS_MAX 512
#define ISER_QP_MAX_RECV_DTOS (ISER_DEF_XMIT_CMDS_MAX)
#define ISER_MIN_POSTED_RX (ISER_DEF_XMIT_CMDS_MAX >> 2)
#define ISER_RX_PAD_SIZE (256 - (ISER_RX_PAYLOAD_SIZE + \
sizeof(struct ibv_mr*) + sizeof(struct ibv_sge)))
/**
* struct iser_hdr - iSER header
*
* @flags: flags support (zbva, remote_inv)
* @rsvd: reserved
* @write_stag: write rkey
* @write_va: write virtual address
* @reaf_stag: read rkey
* @read_va: read virtual address
*/
struct iser_hdr {
uint8_t flags;
uint8_t rsvd[3];
uint32_t write_stag;
uint64_t write_va;
uint32_t read_stag;
uint64_t read_va;
} __attribute__((packed));
/**
* struct iser_rx_desc - iSER RX descriptor (for recv wr_id)
*
* @isr_hdr: iser header
* @iscsi_data: iscsi header
* @data: received data segment
* @rx_sg: ibv_sge of receive buffer
* @pad: padding
*/
struct iser_rx_desc {
struct iser_hdr iser_header;
char iscsi_header[ISCSI_RAW_HEADER_SIZE];
char data[ISER_RECV_DATA_SEG_LEN];
struct ibv_sge rx_sg;
struct ibv_mr *hdr_mr;
char pad[ISER_RX_PAD_SIZE];
} __attribute__((packed));
/**
* struct iser_tx_desc - iSER TX descriptor (for send wr_id)
*
* @iser_hdr: iser header
* @iscsi_header: iscsi header (bhs)
* @tx_sg: sg[0] points to iser/iscsi headers
* sg[1] optionally points to either of immediate data
* unsolicited data-out or control
* @num_sge: number sges used on this TX task
* @mr: iser/iscsi headers mr
* @data_mr: mr for case we need to allocate mr for read
* @next: next descriptor on the list
*/
struct iser_tx_desc {
struct iser_hdr iser_header;
unsigned char iscsi_header[ISCSI_RAW_HEADER_SIZE];
struct ibv_sge tx_sg[2];
int num_sge;
struct ibv_mr *hdr_mr;
char *data_buff;
struct ibv_mr *data_mr;
enum desc_type type;
enum data_dir data_dir;
struct iser_tx_desc *next;
};
struct iser_cm_hdr {
uint8_t flags;
uint8_t rsvd[3];
} __packed;
struct iser_pdu {
struct iscsi_pdu iscsi_pdu;
struct iser_tx_desc *desc;
};
struct iser_conn {
struct rdma_cm_id *cma_id;
struct rdma_event_channel *cma_channel;
struct rdma_cm_event *cma_event;
struct ibv_pd *pd;
struct ibv_cq *cq;
struct ibv_qp *qp;
struct ibv_comp_channel *comp_channel;
struct ibv_recv_wr rx_wr[ISER_MIN_POSTED_RX];
sem_t sem_connect;
struct ibv_mr *login_resp_mr;
struct ibv_mr *login_req_mr;
unsigned char *login_buf;
unsigned char *login_req_buf;
unsigned char *login_resp_buf;
pthread_t cmthread;
struct iser_rx_desc *rx_descs;
uint32_t num_rx_descs;
unsigned int rx_desc_head;
int post_recv_buf_count;
int qp_max_recv_dtos;
int min_posted_rx;
uint16_t max_cmds;
enum conn_state conn_state;
struct iser_tx_desc *tx_desc;
};
struct iser_transport { /* struct iser_conn */
struct iscsi_transport t;
struct iser_conn iser_conn;
};
void iscsi_init_iser_transport(struct iscsi_context *iscsi);
#endif /* __linux */
#endif /* __iser_private_h__ */

View File

@@ -10,6 +10,10 @@ if !HAVE_LIBGCRYPT
libiscsi_la_SOURCES += md5.c
endif
if HAVE_LINUX_ISER
libiscsi_la_SOURCES += iser.c
endif
SOCURRENT=7
SOREVISON=2
SOAGE=0
@@ -17,11 +21,15 @@ libiscsi_la_LDFLAGS = \
-version-info $(SOCURRENT):$(SOREVISON):$(SOAGE) -bindir $(bindir) \
-no-undefined -export-symbols ${srcdir}/libiscsi.syms
if HAVE_LINUX_ISER
libiscsi_la_LDFLAGS += -libverbs -lrdmacm
endif
libiscsi_la_CPPFLAGS = -I${srcdir}/../include -I$(srcdir)/include \
"-D_U_=__attribute__((unused))" \
"-D_R_(A,B)=__attribute__((format(printf,A,B)))"
AM_CFLAGS=$(WARN_CFLAGS)
AM_CFLAGS=$(WARN_CFLAGS) -I/usr/include
dist_noinst_DATA = libiscsi.syms libiscsi.def

View File

@@ -15,6 +15,10 @@
You should have received a copy of the GNU Lesser General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _GNU_SOURCE
#if defined(WIN32)
@@ -32,6 +36,9 @@
#include <time.h>
#include "iscsi.h"
#include "iscsi-private.h"
#ifdef HAVE_LINUX_ISER
#include "iser-private.h"
#endif
#include "slist.h"
@@ -42,6 +49,9 @@
int iscsi_init_transport(struct iscsi_context *iscsi,
enum iscsi_transport_type transport) {
struct tcp_transport *tcp_transport;
#ifdef HAVE_LINUX_ISER
struct iser_transport *iser_transport;
#endif
if (iscsi->t) {
iscsi_free(iscsi, iscsi->t);
@@ -59,6 +69,17 @@ int iscsi_init_transport(struct iscsi_context *iscsi,
iscsi->t = &tcp_transport->t;
iscsi_init_tcp_transport(iscsi);
break;
#ifdef HAVE_LINUX_ISER
case ISER_TRANSPORT:
iser_transport = iscsi_malloc(iscsi, sizeof(struct iser_transport));
if (iser_transport == NULL) {
iscsi_set_error(iscsi, "Couldn't allocate memory for transport\n");
return -1;
}
iscsi->t = &iser_transport->t;
iscsi_init_iser_transport(iscsi);
break;
#endif
default:
iscsi_set_error(iscsi, "Unfamiliar transport type");
return -1;
@@ -514,6 +535,9 @@ iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full)
char *lun;
char *tmp;
int l = 0;
#ifdef HAVE_LINUX_ISER
int is_iser = 0;
#endif
if (strncmp(url, "iscsi://", 8)) {
if (full) {
@@ -554,6 +578,10 @@ iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full)
target_user = value;
} else if (!strcmp(key, "target_password")) {
target_passwd = value;
#ifdef HAVE_LINUX_ISER
} else if (!strcmp(key, "iser")) {
is_iser = 1;
#endif
}
tmp = next;
}
@@ -647,6 +675,16 @@ iscsi_parse_url(struct iscsi_context *iscsi, const char *url, int full)
}
}
#ifdef HAVE_LINUX_ISER
if (iscsi) {
if (is_iser) {
if (iscsi_init_transport(iscsi, ISER_TRANSPORT))
iscsi_set_error(iscsi, "Cannot set transport to iSER");
}
}
iscsi_url->transport = is_iser;
#endif
if (full) {
strncpy(iscsi_url->target, target, MAX_STRING_SIZE);
iscsi_url->lun = l;

1443
lib/iser.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -816,7 +816,7 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
return 0;
}
static int
int
iscsi_service_reconnect_if_loggedin(struct iscsi_context *iscsi)
{
if (iscsi->is_loggedin) {

View File

@@ -1,6 +1,6 @@
AM_CPPFLAGS = -I../include "-D_U_=__attribute__((unused))" \
"-D_R_(A,B)=__attribute__((format(printf,A,B)))"
AM_CFLAGS = $(WARN_CFLAGS)
AM_CFLAGS = $(WARN_CFLAGS) -I/usr/include
LDADD = ../lib/libiscsi.la
noinst_PROGRAMS = prog_reconnect prog_reconnect_timeout prog_noop_reply \

View File

@@ -1,6 +1,6 @@
AM_CPPFLAGS = -I${srcdir}/../include "-D_U_=__attribute__((unused))" \
"-D_R_(A,B)=__attribute__((format(printf,A,B)))"
AM_CFLAGS = $(WARN_CFLAGS)
AM_CFLAGS = $(WARN_CFLAGS) -I/usr/include
LDADD = ../lib/libiscsi.la
bin_PROGRAMS = iscsi-inq iscsi-ls iscsi-perf iscsi-readcapacity16 \