Merge with upstream
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
#include "slist.h"
|
||||
#include "iscsi.h"
|
||||
#include "iscsi-private.h"
|
||||
@@ -35,6 +36,10 @@ struct connect_task {
|
||||
int lun;
|
||||
};
|
||||
|
||||
static void
|
||||
iscsi_connect_cb(struct iscsi_context *iscsi, int status, void *command_data _U_,
|
||||
void *private_data);
|
||||
|
||||
static void
|
||||
iscsi_testunitready_cb(struct iscsi_context *iscsi, int status,
|
||||
void *command_data, void *private_data)
|
||||
@@ -82,6 +87,14 @@ iscsi_login_cb(struct iscsi_context *iscsi, int status, void *command_data _U_,
|
||||
{
|
||||
struct connect_task *ct = private_data;
|
||||
|
||||
if (status == SCSI_STATUS_REDIRECT && iscsi->target_address) {
|
||||
iscsi_disconnect(iscsi);
|
||||
if (iscsi_connect_async(iscsi, iscsi->target_address, iscsi_connect_cb, iscsi->connect_data) != 0) {
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
ct->cb(iscsi, SCSI_STATUS_ERROR, NULL, ct->private_data);
|
||||
return;
|
||||
@@ -158,6 +171,8 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi)
|
||||
{
|
||||
struct iscsi_context *iscsi = old_iscsi;
|
||||
|
||||
DPRINTF(iscsi,2,"reconnect initiated");
|
||||
|
||||
/* This is mainly for tests, where we do not want to automatically
|
||||
reconnect but rather want the commands to fail with an error
|
||||
if the target drops the session.
|
||||
@@ -195,6 +210,9 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int retry = 0;
|
||||
srand (time(NULL)^getpid());
|
||||
|
||||
try_again:
|
||||
|
||||
iscsi = iscsi_create_context(old_iscsi->initiator_name);
|
||||
@@ -213,10 +231,28 @@ try_again:
|
||||
iscsi->lun = old_iscsi->lun;
|
||||
|
||||
iscsi->portal = strdup(old_iscsi->portal);
|
||||
|
||||
iscsi->debug = old_iscsi->debug;
|
||||
|
||||
iscsi->tcp_user_timeout = old_iscsi->tcp_user_timeout;
|
||||
iscsi->tcp_keepidle = old_iscsi->tcp_keepidle;
|
||||
iscsi->tcp_keepcnt = old_iscsi->tcp_keepcnt;
|
||||
iscsi->tcp_keepintvl = old_iscsi->tcp_keepintvl;
|
||||
iscsi->tcp_syncnt = old_iscsi->tcp_syncnt;
|
||||
|
||||
if (iscsi_full_connect_sync(iscsi, iscsi->portal, iscsi->lun) != 0) {
|
||||
int backoff=retry;
|
||||
if (backoff > 10) {
|
||||
backoff+=rand()%10;
|
||||
backoff-=5;
|
||||
}
|
||||
if (backoff > 30) {
|
||||
backoff=30;
|
||||
}
|
||||
DPRINTF(iscsi,1,"reconnect try %d failed, waiting %d seconds",retry,backoff);
|
||||
iscsi_destroy_context(iscsi);
|
||||
sleep(1);
|
||||
sleep(backoff);
|
||||
retry++;
|
||||
goto try_again;
|
||||
}
|
||||
|
||||
@@ -249,6 +285,15 @@ try_again:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pdu->flags & ISCSI_PDU_DELETE_WHEN_SENT) {
|
||||
/* We dont want to requeue things like DATA-OUT since these guys
|
||||
* will be reissued automatically anyway once the corresponding
|
||||
* write command is replayed.
|
||||
*/
|
||||
iscsi_free_pdu(old_iscsi, pdu);
|
||||
continue;
|
||||
}
|
||||
|
||||
pdu->itt = iscsi->itt++;
|
||||
iscsi_pdu_set_itt(pdu, pdu->itt);
|
||||
|
||||
|
||||
47
lib/init.c
47
lib/init.c
@@ -71,6 +71,34 @@ iscsi_create_context(const char *initiator_name)
|
||||
iscsi->use_immediate_data = ISCSI_IMMEDIATE_DATA_YES;
|
||||
iscsi->want_header_digest = ISCSI_HEADER_DIGEST_NONE_CRC32C;
|
||||
|
||||
iscsi->tcp_keepcnt=3;
|
||||
iscsi->tcp_keepintvl=30;
|
||||
iscsi->tcp_keepidle=30;
|
||||
|
||||
if (getenv("LIBISCSI_DEBUG") != NULL) {
|
||||
iscsi_set_debug(iscsi,atoi(getenv("LIBISCSI_DEBUG")));
|
||||
}
|
||||
|
||||
if (getenv("LIBISCSI_TCP_USER_TIMEOUT") != NULL) {
|
||||
iscsi_set_tcp_user_timeout(iscsi,atoi(getenv("LIBISCSI_TCP_USER_TIMEOUT")));
|
||||
}
|
||||
|
||||
if (getenv("LIBISCSI_TCP_KEEPCNT") != NULL) {
|
||||
iscsi_set_tcp_keepcnt(iscsi,atoi(getenv("LIBISCSI_TCP_KEEPCNT")));
|
||||
}
|
||||
|
||||
if (getenv("LIBISCSI_TCP_KEEPINTVL") != NULL) {
|
||||
iscsi_set_tcp_keepintvl(iscsi,atoi(getenv("LIBISCSI_TCP_KEEPINTVL")));
|
||||
}
|
||||
|
||||
if (getenv("LIBISCSI_TCP_KEEPIDLE") != NULL) {
|
||||
iscsi_set_tcp_keepidle(iscsi,atoi(getenv("LIBISCSI_TCP_KEEPIDLE")));
|
||||
}
|
||||
|
||||
if (getenv("LIBISCSI_TCP_SYNCNT") != NULL) {
|
||||
iscsi_set_tcp_syncnt(iscsi,atoi(getenv("LIBISCSI_TCP_SYNCNT")));
|
||||
}
|
||||
|
||||
return iscsi;
|
||||
}
|
||||
|
||||
@@ -244,6 +272,11 @@ iscsi_destroy_context(struct iscsi_context *iscsi)
|
||||
free(discard_const(iscsi->chap_c));
|
||||
iscsi->chap_c = NULL;
|
||||
|
||||
if (iscsi->connected_portal != NULL) {
|
||||
free(discard_const(iscsi->connected_portal));
|
||||
iscsi->connected_portal = NULL;
|
||||
}
|
||||
|
||||
iscsi->connect_data = NULL;
|
||||
|
||||
free(iscsi);
|
||||
@@ -251,8 +284,6 @@ iscsi_destroy_context(struct iscsi_context *iscsi)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...)
|
||||
{
|
||||
@@ -270,9 +301,18 @@ iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...)
|
||||
free(iscsi->error_string);
|
||||
|
||||
iscsi->error_string = str;
|
||||
|
||||
va_end(ap);
|
||||
|
||||
DPRINTF(iscsi,1,"%s",str);
|
||||
}
|
||||
|
||||
void
|
||||
iscsi_set_debug(struct iscsi_context *iscsi, int level)
|
||||
{
|
||||
iscsi->debug = level;
|
||||
DPRINTF(iscsi,2,"set debug level to %d",level);
|
||||
}
|
||||
|
||||
const char *
|
||||
iscsi_get_error(struct iscsi_context *iscsi)
|
||||
@@ -547,8 +587,7 @@ iscsi_destroy_url(struct iscsi_url *iscsi_url)
|
||||
|
||||
int
|
||||
iscsi_set_initiator_username_pwd(struct iscsi_context *iscsi,
|
||||
const char *user,
|
||||
const char *passwd)
|
||||
const char *user, const char *passwd)
|
||||
{
|
||||
free(discard_const(iscsi->user));
|
||||
iscsi->user = strdup(user);
|
||||
|
||||
@@ -64,6 +64,7 @@ iscsi_scsi_command_sync
|
||||
iscsi_scsi_task_cancel
|
||||
iscsi_service
|
||||
iscsi_set_alias
|
||||
iscsi_set_debug
|
||||
iscsi_set_header_digest
|
||||
iscsi_set_initiator_username_pwd
|
||||
iscsi_set_isid_en
|
||||
@@ -73,6 +74,11 @@ iscsi_set_isid_reserved
|
||||
iscsi_set_session_type
|
||||
iscsi_set_targetname
|
||||
iscsi_set_tcp_keepalive
|
||||
iscsi_set_tcp_user_timeout
|
||||
iscsi_set_tcp_keepidle
|
||||
iscsi_set_tcp_keepcnt
|
||||
iscsi_set_tcp_keepintvl
|
||||
iscsi_set_tcp_syncnt
|
||||
iscsi_startstopunit_sync
|
||||
iscsi_startstopunit_task
|
||||
iscsi_synchronizecache10_sync
|
||||
|
||||
@@ -62,6 +62,7 @@ iscsi_scsi_command_sync
|
||||
iscsi_scsi_task_cancel
|
||||
iscsi_service
|
||||
iscsi_set_alias
|
||||
iscsi_set_debug
|
||||
iscsi_set_header_digest
|
||||
iscsi_set_initiator_username_pwd
|
||||
iscsi_set_isid_en
|
||||
@@ -71,6 +72,11 @@ iscsi_set_isid_reserved
|
||||
iscsi_set_session_type
|
||||
iscsi_set_targetname
|
||||
iscsi_set_tcp_keepalive
|
||||
iscsi_set_tcp_user_timeout
|
||||
iscsi_set_tcp_keepidle
|
||||
iscsi_set_tcp_keepcnt
|
||||
iscsi_set_tcp_keepintvl
|
||||
iscsi_set_tcp_syncnt
|
||||
iscsi_startstopunit_sync
|
||||
iscsi_startstopunit_task
|
||||
iscsi_synchronizecache10_sync
|
||||
|
||||
@@ -1088,6 +1088,13 @@ iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
|
||||
size -= len + 1;
|
||||
}
|
||||
|
||||
if (status == SCSI_STATUS_REDIRECT && iscsi->target_address) {
|
||||
DPRINTF(iscsi,2,"target requests redirect to %s",iscsi->target_address);
|
||||
pdu->callback(iscsi, SCSI_STATUS_REDIRECT, NULL,
|
||||
pdu->private_data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (status != 0) {
|
||||
iscsi_set_error(iscsi, "Failed to log in to target. Status: %s(%d)",
|
||||
login_error_str(status), status);
|
||||
|
||||
@@ -242,8 +242,8 @@ iscsi_scsi_command_async(struct iscsi_context *iscsi, int lun,
|
||||
if (iscsi->use_immediate_data == ISCSI_IMMEDIATE_DATA_YES) {
|
||||
uint32_t len = data.size;
|
||||
|
||||
if (len > iscsi->target_max_recv_data_segment_length) {
|
||||
len = iscsi->target_max_recv_data_segment_length;
|
||||
if (len > iscsi->first_burst_length) {
|
||||
len = iscsi->first_burst_length;
|
||||
}
|
||||
|
||||
if (iscsi_pdu_add_data(iscsi, pdu, data.data, len)
|
||||
@@ -302,7 +302,7 @@ iscsi_scsi_command_async(struct iscsi_context *iscsi, int lun,
|
||||
}
|
||||
|
||||
/* Can we send some unsolicited data ? */
|
||||
if (pdu->nidata.size != 0 && iscsi->use_initial_r2t == ISCSI_INITIAL_R2T_NO) {
|
||||
if (pdu->nidata.size != 0 && iscsi->use_initial_r2t == ISCSI_INITIAL_R2T_NO && iscsi->use_immediate_data == ISCSI_IMMEDIATE_DATA_NO) {
|
||||
uint32_t len = pdu->nidata.size - offset;
|
||||
|
||||
if (len > iscsi->first_burst_length) {
|
||||
|
||||
@@ -76,8 +76,8 @@ scsi_malloc(struct scsi_task *task, size_t size)
|
||||
}
|
||||
|
||||
struct value_string {
|
||||
int value;
|
||||
const char *string;
|
||||
int value;
|
||||
const char *string;
|
||||
};
|
||||
|
||||
static const char *
|
||||
@@ -1399,7 +1399,7 @@ scsi_cdb_compareandwrite(uint64_t lba, uint32_t xferlen, int blocksize, int wrpr
|
||||
task->xfer_dir = SCSI_XFER_WRITE;
|
||||
} else {
|
||||
task->xfer_dir = SCSI_XFER_NONE;
|
||||
}
|
||||
}
|
||||
task->expxferlen = xferlen;
|
||||
|
||||
task->params.compareandwrite.lba = lba;
|
||||
@@ -2508,9 +2508,9 @@ scsi_get_task_private_ptr(struct scsi_task *task)
|
||||
|
||||
|
||||
struct scsi_data_buffer {
|
||||
struct scsi_data_buffer *next;
|
||||
uint32_t len;
|
||||
unsigned char *data;
|
||||
struct scsi_data_buffer *next;
|
||||
uint32_t len;
|
||||
unsigned char *data;
|
||||
};
|
||||
|
||||
int
|
||||
|
||||
174
lib/socket.c
174
lib/socket.c
@@ -58,6 +58,52 @@ static void set_nonblocking(int fd)
|
||||
#endif
|
||||
}
|
||||
|
||||
int set_tcp_sockopt(int sockfd, int optname, int value)
|
||||
{
|
||||
int level;
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__sun)
|
||||
struct protoent *buf;
|
||||
|
||||
if ((buf = getprotobyname("tcp")) != NULL)
|
||||
level = buf->p_proto;
|
||||
else
|
||||
return -1;
|
||||
#else
|
||||
level = SOL_TCP;
|
||||
#endif
|
||||
|
||||
return setsockopt(sockfd, level, optname, &value, sizeof(value));
|
||||
}
|
||||
|
||||
#ifndef TCP_USER_TIMEOUT
|
||||
#define TCP_USER_TIMEOUT 18
|
||||
#endif
|
||||
|
||||
int set_tcp_user_timeout(struct iscsi_context *iscsi)
|
||||
{
|
||||
if (set_tcp_sockopt(iscsi->fd, TCP_USER_TIMEOUT, iscsi->tcp_user_timeout) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set tcp user timeout. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DPRINTF(iscsi,3,"TCP_USER_TIMEOUT set to %d",iscsi->tcp_user_timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifndef TCP_SYNCNT
|
||||
#define TCP_SYNCNT 7
|
||||
#endif
|
||||
|
||||
int set_tcp_syncnt(struct iscsi_context *iscsi)
|
||||
{
|
||||
if (set_tcp_sockopt(iscsi->fd, TCP_SYNCNT, iscsi->tcp_syncnt) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set tcp syn retries. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DPRINTF(iscsi,3,"TCP_SYNCNT set to %d",iscsi->tcp_syncnt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
@@ -68,6 +114,8 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||
struct addrinfo *ai = NULL;
|
||||
int socksize;
|
||||
|
||||
DPRINTF(iscsi,2,"connecting to portal %s",portal);
|
||||
|
||||
if (iscsi->fd != -1) {
|
||||
iscsi_set_error(iscsi,
|
||||
"Trying to connect but already connected.");
|
||||
@@ -157,6 +205,16 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||
iscsi->connect_data = private_data;
|
||||
|
||||
set_nonblocking(iscsi->fd);
|
||||
|
||||
iscsi_set_tcp_keepalive(iscsi, iscsi->tcp_keepidle, iscsi->tcp_keepcnt, iscsi->tcp_keepintvl);
|
||||
|
||||
if (iscsi->tcp_user_timeout > 0) {
|
||||
set_tcp_user_timeout(iscsi);
|
||||
}
|
||||
|
||||
if (iscsi->tcp_syncnt > 0) {
|
||||
set_tcp_syncnt(iscsi);
|
||||
}
|
||||
|
||||
if (connect(iscsi->fd, ai->ai_addr, socksize) != 0
|
||||
&& errno != EINPROGRESS) {
|
||||
@@ -169,6 +227,10 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (iscsi->connected_portal) free(discard_const(iscsi->connected_portal));
|
||||
iscsi->connected_portal=strdup(portal);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -182,6 +244,9 @@ iscsi_disconnect(struct iscsi_context *iscsi)
|
||||
}
|
||||
|
||||
close(iscsi->fd);
|
||||
|
||||
if (iscsi->connected_portal)
|
||||
DPRINTF(iscsi,2,"disconnected from portal %s",iscsi->connected_portal);
|
||||
|
||||
iscsi->fd = -1;
|
||||
iscsi->is_connected = 0;
|
||||
@@ -374,6 +439,17 @@ iscsi_write_to_socket(struct iscsi_context *iscsi)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int inline
|
||||
iscsi_service_reconnect_if_loggedin(struct iscsi_context *iscsi)
|
||||
{
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
iscsi_service(struct iscsi_context *iscsi, int revents)
|
||||
{
|
||||
@@ -395,30 +471,19 @@ iscsi_service(struct iscsi_context *iscsi, int revents)
|
||||
}
|
||||
iscsi->socket_status_cb(iscsi, SCSI_STATUS_ERROR, NULL,
|
||||
iscsi->connect_data);
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
if (revents & POLLHUP) {
|
||||
iscsi_set_error(iscsi, "iscsi_service: POLLHUP, "
|
||||
"socket error.");
|
||||
iscsi->socket_status_cb(iscsi, SCSI_STATUS_ERROR, NULL,
|
||||
iscsi->connect_data);
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
|
||||
if (iscsi->is_connected == 0 && iscsi->fd != -1 && revents&POLLOUT) {
|
||||
int err = 0;
|
||||
socklen_t err_size = sizeof(err);
|
||||
|
||||
if (getsockopt(iscsi->fd, SOL_SOCKET, SO_ERROR,
|
||||
&err, &err_size) != 0 || err != 0) {
|
||||
if (err == 0) {
|
||||
@@ -429,15 +494,11 @@ iscsi_service(struct iscsi_context *iscsi, int revents)
|
||||
strerror(err), err);
|
||||
iscsi->socket_status_cb(iscsi, SCSI_STATUS_ERROR,
|
||||
NULL, iscsi->connect_data);
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
|
||||
iscsi_set_tcp_keepalive(iscsi, 30, 3, 30);
|
||||
DPRINTF(iscsi,2,"connection to %s established",iscsi->connected_portal);
|
||||
|
||||
iscsi->is_connected = 1;
|
||||
iscsi->socket_status_cb(iscsi, SCSI_STATUS_GOOD, NULL,
|
||||
iscsi->connect_data);
|
||||
@@ -446,22 +507,12 @@ iscsi_service(struct iscsi_context *iscsi, int revents)
|
||||
|
||||
if (revents & POLLOUT && iscsi->outqueue != NULL) {
|
||||
if (iscsi_write_to_socket(iscsi) != 0) {
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
}
|
||||
if (revents & POLLIN) {
|
||||
if (iscsi_read_from_socket(iscsi) != 0) {
|
||||
if (iscsi->is_loggedin) {
|
||||
if (iscsi_reconnect(iscsi) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return iscsi_service_reconnect_if_loggedin(iscsi);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,47 +566,66 @@ iscsi_free_iscsi_inqueue(struct iscsi_in_pdu *inqueue)
|
||||
}
|
||||
}
|
||||
|
||||
void iscsi_set_tcp_syncnt(struct iscsi_context *iscsi, int value)
|
||||
{
|
||||
iscsi->tcp_syncnt=value;
|
||||
DPRINTF(iscsi,2,"TCP_SYNCNT will be set to %d on next socket creation",value);
|
||||
}
|
||||
|
||||
void iscsi_set_tcp_user_timeout(struct iscsi_context *iscsi, int value)
|
||||
{
|
||||
iscsi->tcp_user_timeout=value;
|
||||
DPRINTF(iscsi,2,"TCP_USER_TIMEOUT will be set to %dms on next socket creation",value);
|
||||
}
|
||||
|
||||
void iscsi_set_tcp_keepidle(struct iscsi_context *iscsi, int value)
|
||||
{
|
||||
iscsi->tcp_keepidle=value;
|
||||
DPRINTF(iscsi,2,"TCP_KEEPIDLE will be set to %d on next socket creation",value);
|
||||
}
|
||||
|
||||
void iscsi_set_tcp_keepcnt(struct iscsi_context *iscsi, int value)
|
||||
{
|
||||
iscsi->tcp_keepcnt=value;
|
||||
DPRINTF(iscsi,2,"TCP_KEEPCNT will be set to %d on next socket creation",value);
|
||||
}
|
||||
|
||||
void iscsi_set_tcp_keepintvl(struct iscsi_context *iscsi, int value)
|
||||
{
|
||||
iscsi->tcp_keepintvl=value;
|
||||
DPRINTF(iscsi,2,"TCP_KEEPINTVL will be set to %d on next socket creation",value);
|
||||
}
|
||||
|
||||
int iscsi_set_tcp_keepalive(struct iscsi_context *iscsi, int idle, int count, int interval)
|
||||
{
|
||||
int level, value;
|
||||
#if defined(__FreeBSD__) || defined(__sun)
|
||||
struct protoent *buf;
|
||||
|
||||
if ((buf = getprotobyname("tcp")) != NULL)
|
||||
level = buf->p_proto;
|
||||
else
|
||||
return -1;
|
||||
#else
|
||||
level = SOL_TCP;
|
||||
#endif
|
||||
|
||||
#ifdef SO_KEEPALIVE
|
||||
value =1;
|
||||
int value = 1;
|
||||
if (setsockopt(iscsi->fd, SOL_SOCKET, SO_KEEPALIVE, &value, sizeof(value)) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set socket option SO_KEEPALIVE. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
DPRINTF(iscsi,3,"SO_KEEPALIVE set to %d",value);
|
||||
#ifdef TCP_KEEPCNT
|
||||
value = count;
|
||||
if (setsockopt(iscsi->fd, level, TCP_KEEPCNT, &value, sizeof(value)) != 0) {
|
||||
if (set_tcp_sockopt(iscsi->fd, TCP_KEEPCNT, count) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set tcp keepalive count. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DPRINTF(iscsi,3,"TCP_KEEPCNT set to %d",count);
|
||||
#endif
|
||||
#ifdef TCP_KEEPINTVL
|
||||
value = interval;
|
||||
if (setsockopt(iscsi->fd, level, TCP_KEEPINTVL, &value, sizeof(value)) != 0) {
|
||||
if (set_tcp_sockopt(iscsi->fd, TCP_KEEPINTVL, interval) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set tcp keepalive interval. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DPRINTF(iscsi,3,"TCP_KEEPINTVL set to %d",interval);
|
||||
#endif
|
||||
#ifdef TCP_KEEPIDLE
|
||||
value = idle;
|
||||
if (setsockopt(iscsi->fd, level, TCP_KEEPIDLE, &value, sizeof(value)) != 0) {
|
||||
if (set_tcp_sockopt(iscsi->fd, TCP_KEEPIDLE, idle) != 0) {
|
||||
iscsi_set_error(iscsi, "TCP: Failed to set tcp keepalive idle. Error %s(%d)", strerror(errno), errno);
|
||||
return -1;
|
||||
}
|
||||
DPRINTF(iscsi,3,"TCP_KEEPIDLE set to %d",idle);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -30,9 +30,9 @@
|
||||
#include "scsi-lowlevel.h"
|
||||
|
||||
struct iscsi_sync_state {
|
||||
int finished;
|
||||
int status;
|
||||
struct scsi_task *task;
|
||||
int finished;
|
||||
int status;
|
||||
struct scsi_task *task;
|
||||
};
|
||||
|
||||
static void
|
||||
|
||||
Reference in New Issue
Block a user