Merge with IET r170-191:

- Update MaxConnections documentation
 - Remove isns config description from man page
 - Check return values of chdir(), ftruncate() and write(), because recent versions of the glibc insist on the return value being checked by
introducing __attribute__((warn_unused_result)) to these functions.
 - Fix snprintf use in isns.c
 - Take \0-termination into account when passing strings to isns_tlv_set() to solve incompatibility with MS iSNS 3.0 as IQN length is multiple of 4
 - Fix list corruption if SCST target registration fails
 - Register the target port actually used instead of the default iSCSI port.
 - Remove unused connection->pad
 - Refactor cmnd_execute()
 - Version changed



git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@649 d57e44dd-8a1f-0410-8b47-8ef2f437770f
This commit is contained in:
Vladislav Bolkhovitin
2009-01-29 19:10:10 +00:00
parent ba698dbdd5
commit 684719c66e
8 changed files with 51 additions and 47 deletions
-5
View File
@@ -18,8 +18,6 @@ iscsi-scstd \- iSCSI SCST Target Daemon
.IR address \|]
.RB [\| \-p
.IR port \|]
.RB [\| \-s
.IR IP \|]
.RB [\| \-u
.IR UID \|]
.SH DESCRIPTION
@@ -53,9 +51,6 @@ Specify on which port the server should listen, default is 3260.
.BI \-h,\ \-\-help
Display help message on command line options.
.TP
.BI \-s\ IP ,\ \-\-isns= IP
isns server's IP address
.TP
.BI \-u\ UID ,\ \-\-uid= UID
Specify running user id, default is current uid.
.SH FILES
+1 -1
View File
@@ -134,7 +134,7 @@ Optional. If set to "CRC32C" and the initiator is configured accordingly, the in
Optional. If set to "CRC32C" and the initiator is configured accordingly, the integrity of an iSCSI PDU's data segment will be protected by a CRC32C checksum. The default is "None". Note that data digests are not supported during discovery sessions.
.TP
.B [MaxConnections <value>]
Optional. Has to be set to "1" (in words: one), which is also the default.
Optional. The number of connections within a session. Has to be set to "1" (in words: one), which is also the default since MC/S is not supported.
.TP
.B [InitialR2T <Yes|No>]
Optional. If set to "Yes", the initiator has to wait for the target to solicit SCSI data before sending it. Setting it to "No" (default) allows the initiator to send a burst of
+1 -1
View File
@@ -13,4 +13,4 @@
* GNU General Public License for more details.
*/
#define ISCSI_VERSION_STRING "1.0.1/0.4.16r155"
#define ISCSI_VERSION_STRING "1.0.1/0.4.17r191"
+2 -2
View File
@@ -116,8 +116,6 @@ static int iscsi_target_create(struct target_info *info, u32 tid)
mutex_init(&target->target_mutex);
INIT_LIST_HEAD(&target->session_list);
list_add(&target->target_list_entry, &target_list);
target->scst_tgt = scst_register(&iscsi_template, target->name);
if (!target->scst_tgt) {
PRINT_ERROR("%s", "scst_register() failed");
@@ -125,6 +123,8 @@ static int iscsi_target_create(struct target_info *info, u32 tid)
goto out_free;
}
list_add(&target->target_list_entry, &target_list);
return 0;
out_free:
+14 -3
View File
@@ -656,14 +656,25 @@ int main(int argc, char **argv)
exit(res);
}
chdir("/");
if (chdir("/") < 0) {
log_error("failed to set working dir to /: %m");
exit(1);
}
if (lockf(fd, F_TLOCK, 0) < 0) {
log_error("unable to lock pid file");
exit(1);
}
ftruncate(fd, 0);
if (ftruncate(fd, 0) < 0) {
log_error("failed to ftruncate the PID file: %m");
exit(1);
}
sprintf(buf, "%d\n", getpid());
write(fd, buf, strlen(buf));
if (write(fd, buf, strlen(buf)) < strlen(buf)) {
log_error("failed to write PID to PID file: %m");
exit(1);
}
close(0);
open("/dev/null", O_RDWR);
+8 -16
View File
@@ -727,36 +727,28 @@ int cmnd_execute(struct connection *conn)
case ISCSI_OP_LOGIN_CMD:
//if conn->state == STATE_FULL -> reject
cmnd_exec_login(conn);
conn->rsp.bhs.ahslength = conn->rsp.ahssize / 4;
conn->rsp.bhs.datalength[0] = conn->rsp.datasize >> 16;
conn->rsp.bhs.datalength[1] = conn->rsp.datasize >> 8;
conn->rsp.bhs.datalength[2] = conn->rsp.datasize;
log_pdu(2, &conn->rsp);
break;
case ISCSI_OP_TEXT_CMD:
//if conn->state != STATE_FULL -> reject
cmnd_exec_text(conn);
conn->rsp.bhs.ahslength = conn->rsp.ahssize / 4;
conn->rsp.bhs.datalength[0] = conn->rsp.datasize >> 16;
conn->rsp.bhs.datalength[1] = conn->rsp.datasize >> 8;
conn->rsp.bhs.datalength[2] = conn->rsp.datasize;
log_pdu(2, &conn->rsp);
break;
case ISCSI_OP_LOGOUT_CMD:
//if conn->state != STATE_FULL -> reject
cmnd_exec_logout(conn);
conn->rsp.bhs.ahslength = conn->rsp.ahssize / 4;
conn->rsp.bhs.datalength[0] = conn->rsp.datasize >> 16;
conn->rsp.bhs.datalength[1] = conn->rsp.datasize >> 8;
conn->rsp.bhs.datalength[2] = conn->rsp.datasize;
log_pdu(2, &conn->rsp);
break;
default:
//reject
res = 0;
break;
goto out;
}
conn->rsp.bhs.ahslength = conn->rsp.ahssize / 4;
conn->rsp.bhs.datalength[0] = conn->rsp.datasize >> 16;
conn->rsp.bhs.datalength[1] = conn->rsp.datasize >> 8;
conn->rsp.bhs.datalength[2] = conn->rsp.datasize;
log_pdu(2, &conn->rsp);
out:
return res;
}
-1
View File
@@ -65,7 +65,6 @@ struct connection {
char *user;
union iscsi_sid sid;
u16 cid;
u16 pad;
int session_type;
int auth_method;
+25 -18
View File
@@ -201,8 +201,10 @@ static int isns_scn_deregister(char *name)
memset(buf, 0, sizeof(buf));
tlv = (struct isns_tlv *) hdr->pdu;
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU;
isns_hdr_init(hdr, ISNS_FUNC_SCN_DEREG, length, flags,
@@ -251,9 +253,9 @@ static int isns_scn_register(void)
target = list_entry(targets_list.q_forw, struct target, tlist);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME,
strlen(target->name), target->name);
strlen(target->name) + 1, target->name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME,
strlen(target->name), target->name);
strlen(target->name) + 1, target->name);
length += isns_tlv_set(&tlv, 0, 0, 0);
scn_flags = ISNS_SCN_FLAG_INITIATOR | ISNS_SCN_FLAG_OBJECT_REMOVE |
@@ -301,14 +303,15 @@ static int isns_attr_query(char *name)
tlv = (struct isns_tlv *) hdr->pdu;
if (name)
snprintf(mgmt->name, sizeof(mgmt->name), name);
snprintf(mgmt->name, sizeof(mgmt->name), "%s", name);
else {
mgmt->name[0] = '\0';
target = list_entry(targets_list.q_forw, struct target, tlist);
name = target->name;
}
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NODE_TYPE,
sizeof(node), &node);
length += isns_tlv_set(&tlv, 0, 0, 0);
@@ -350,10 +353,10 @@ static int isns_deregister(void)
target = list_entry(targets_list.q_forw, struct target, tlist);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME,
strlen(target->name), target->name);
strlen(target->name) + 1, target->name);
length += isns_tlv_set(&tlv, 0, 0, 0);
length += isns_tlv_set(&tlv, ISNS_ATTR_ENTITY_IDENTIFIER,
strlen(eid), eid);
strlen(eid) + 1, eid);
flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU;
isns_hdr_init(hdr, ISNS_FUNC_DEV_DEREG, length, flags,
@@ -371,7 +374,7 @@ int isns_target_register(char *name)
uint16_t flags = 0, length = 0;
struct isns_hdr *hdr = (struct isns_hdr *) buf;
struct isns_tlv *tlv;
uint32_t port = htonl(ISCSI_LISTEN_PORT);
uint32_t port = htonl(server_port);
uint32_t node = htonl(ISNS_NODE_TARGET);
uint32_t type = htonl(2);
struct target *target;
@@ -389,14 +392,14 @@ int isns_target_register(char *name)
target = list_entry(targets_list.q_back, struct target, tlist);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME,
strlen(target->name), target->name);
strlen(target->name) + 1, target->name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ENTITY_IDENTIFIER,
strlen(eid), eid);
strlen(eid) + 1, eid);
length += isns_tlv_set(&tlv, 0, 0, 0);
length += isns_tlv_set(&tlv, ISNS_ATTR_ENTITY_IDENTIFIER,
strlen(eid), eid);
strlen(eid) + 1, eid);
if (initial) {
length += isns_tlv_set(&tlv, ISNS_ATTR_ENTITY_PROTOCOL,
sizeof(type), &type);
@@ -413,7 +416,8 @@ int isns_target_register(char *name)
}
}
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NODE_TYPE,
sizeof(node), &node);
@@ -478,14 +482,15 @@ int isns_target_deregister(char *name)
memset(buf, 0, sizeof(buf));
tlv = (struct isns_tlv *) hdr->pdu;
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
length += isns_tlv_set(&tlv, 0, 0, 0);
if (last)
length += isns_tlv_set(&tlv, ISNS_ATTR_ENTITY_IDENTIFIER,
strlen(eid), eid);
strlen(eid) + 1, eid);
else
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME,
strlen(name), name);
strlen(name) + 1, name);
flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU;
isns_hdr_init(hdr, ISNS_FUNC_DEV_DEREG, length, flags,
@@ -689,7 +694,8 @@ found:
ini = malloc(sizeof(*ini));
if (!ini)
goto free_qry_mgmt;
snprintf(ini->name, sizeof(ini->name), name);
snprintf(ini->name, sizeof(ini->name), "%s",
name);
insque(&ini->ilist, &target->isns_head);
} else
name = NULL;
@@ -797,7 +803,8 @@ static void send_scn_rsp(char *name, uint16_t transaction)
tlv = (struct isns_tlv *) ((char *) hdr->pdu + 4);
length +=4;
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name), name);
length += isns_tlv_set(&tlv, ISNS_ATTR_ISCSI_NAME, strlen(name) + 1,
name);
flags = ISNS_FLAG_CLIENT | ISNS_FLAG_LAST_PDU | ISNS_FLAG_FIRST_PDU;
isns_hdr_init(hdr, ISNS_FUNC_SCN_RSP, length, flags, transaction, 0);