Commit d29384bf authored by Ben Walker's avatar Ben Walker
Browse files

iscsi: Add an iscsi library.



Change-Id: I28f3f4723a66f845eb478a6873d7aedb8f5409b8
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
parent d3090c84
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -37,13 +37,13 @@ To build SPDK, some dependencies must be installed.

Fedora/CentOS:

    sudo dnf install -y gcc libpciaccess-devel CUnit-devel libaio-devel
    sudo dnf install -y gcc libpciaccess-devel CUnit-devel libaio-devel openssl-devel
    # Additional dependencies for NVMf:
    sudo dnf install -y libibverbs-devel librdmacm-devel

Ubuntu/Debian:

    sudo apt-get install -y gcc libpciaccess-dev make libcunit1-dev libaio-dev
    sudo apt-get install -y gcc libpciaccess-dev make libcunit1-dev libaio-dev libssl-dev
    # Additional dependencies for NVMf:
    sudo apt-get install -y libibverbs-dev librdmacm-dev

@@ -53,6 +53,7 @@ FreeBSD:
- libpciaccess
- gmake
- cunit
- openssl

Additionally, [DPDK](http://dpdk.org/doc/quick-start) is required.

+6 −2
Original line number Diff line number Diff line
@@ -34,8 +34,12 @@
SPDK_ROOT_DIR := $(abspath $(CURDIR)/..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

DIRS-y += bdev conf copy cunit event json jsonrpc log memory \
          net rpc trace util nvme nvmf scsi ioat
DIRS-y += bdev conf copy cunit event json jsonrpc \
          log memory net rpc trace util nvme nvmf scsi ioat
ifeq ($(OS),Linux)
DIRS-y += iscsi
endif


.PHONY: all clean $(DIRS-y)

lib/iscsi/Makefile

0 → 100644
+44 −0
Original line number Diff line number Diff line
#
#  BSD LICENSE
#
#  Copyright (c) Intel Corporation.
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#
#    * Redistributions of source code must retain the above copyright
#      notice, this list of conditions and the following disclaimer.
#    * Redistributions in binary form must reproduce the above copyright
#      notice, this list of conditions and the following disclaimer in
#      the documentation and/or other materials provided with the
#      distribution.
#    * Neither the name of Intel Corporation nor the names of its
#      contributors may be used to endorse or promote products derived
#      from this software without specific prior written permission.
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
#  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
#  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
#  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
#  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
#  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
#  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

SPDK_ROOT_DIR := $(abspath $(CURDIR)/../..)
include $(SPDK_ROOT_DIR)/mk/spdk.common.mk

CFLAGS += $(DPDK_INC) -I$(SPDK_ROOT_DIR)/lib
C_SRCS = acceptor.c conn.c crc32c.c \
	 init_grp.c iscsi.c md5.c param.c portal_grp.c \
	 tgt_node.c iscsi_subsystem.c \
	 iscsi_rpc.c task.c
LIBNAME = iscsi

include $(SPDK_ROOT_DIR)/mk/spdk.lib.mk

lib/iscsi/acceptor.c

0 → 100644
+114 −0
Original line number Diff line number Diff line
/*-
 *   BSD LICENSE
 *
 *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
 *   Copyright (c) Intel Corporation.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <errno.h>
#include <string.h>
#include <unistd.h>

#include <sys/types.h>

#include <rte_config.h>
#include <rte_lcore.h>
#include <rte_cycles.h>
#include <rte_timer.h>

#include "spdk/log.h"
#include "spdk/net.h"
#include "iscsi/acceptor.h"
#include "iscsi/conn.h"
#include "iscsi/portal_grp.h"

#define ACCEPT_TIMEOUT (rte_get_timer_hz() >> 10) /* ~1ms */

static struct rte_timer g_acceptor_timer;

/*! \file

*/

static void
spdk_iscsi_portal_accept(struct spdk_iscsi_portal *portal)
{
	int				rc, sock;

	if (portal->sock < 0) {
		return;
	}

	while (1) {
		rc = spdk_sock_accept(portal->sock);
		if (rc >= 0) {
			sock = rc;
			rc = spdk_iscsi_conn_construct(portal, sock);
			if (rc < 0) {
				close(sock);
				SPDK_ERRLOG("spdk_iscsi_connection_construct() failed\n");
				break;
			}
		} else {
			if (errno != EAGAIN && errno != EWOULDBLOCK) {
				SPDK_ERRLOG("accept error(%d): %s\n", errno, strerror(errno));
			}
			break;
		}
	}
}

static void
spdk_acceptor(struct rte_timer *timer, void *arg)
{
	struct spdk_iscsi_globals		*iscsi = arg;
	struct spdk_iscsi_portal_grp	*portal_group;
	struct spdk_iscsi_portal	*portal;

	TAILQ_FOREACH(portal_group, &iscsi->pg_head, tailq) {
		TAILQ_FOREACH(portal, &portal_group->head, tailq) {
			spdk_iscsi_portal_accept(portal);
		}
	}
}

void
spdk_iscsi_acceptor_start(void)
{
	rte_timer_init(&g_acceptor_timer);
	rte_timer_reset(&g_acceptor_timer, ACCEPT_TIMEOUT, PERIODICAL,
			rte_lcore_id(), spdk_acceptor, &g_spdk_iscsi);
}

void
spdk_iscsi_acceptor_stop(void)
{
	rte_timer_stop_sync(&g_acceptor_timer);
}

lib/iscsi/acceptor.h

0 → 100644
+41 −0
Original line number Diff line number Diff line
/*-
 *   BSD LICENSE
 *
 *   Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>.
 *   Copyright (c) Intel Corporation.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Intel Corporation nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef SPDK_ACCEPTOR_H_
#define SPDK_ACCEPTOR_H_

void spdk_iscsi_acceptor_start(void);
void spdk_iscsi_acceptor_stop(void);

#endif /* SPDK_ACCEPTOR_H_ */
Loading