Merge pull request #30 from plieven/master

debug level explaination, small improvement to iscsi-readcapacity16 and bounds check for data_size in socket_receive
This commit is contained in:
Ronnie Sahlberg
2012-10-26 18:32:12 -07:00
5 changed files with 46 additions and 13 deletions

View File

@@ -979,7 +979,14 @@ iscsi_scsi_cancel_all_tasks(struct iscsi_context *iscsi);
} while (0);
/*
* This function is to set the debugging level (0=disabled).
* This function is to set the debugging level where level is
*
* 0 = disabled (default)
* 1 = errors only
* 2 = connection related info
* 3 = user set variables
* 4 = function calls
* 5 = ...
*/
EXTERN void
iscsi_set_debug(struct iscsi_context *iscsi, int level);

View File

@@ -49,4 +49,15 @@
(*list) = head; \
}
#define SLIST_LENGTH(list,length) \
do { \
(length) = 0; \
void *head = (*list); \
while ((*list)) { \
(*list) = (*list)->next; \
(length)++; \
} \
(*list) = head; \
} while (0);
#endif /* __iscsi_slist_h__ */

View File

@@ -211,7 +211,6 @@ int iscsi_reconnect(struct iscsi_context *old_iscsi)
}
int retry = 0;
srand (time(NULL)^getpid());
try_again:
@@ -329,6 +328,10 @@ try_again:
free(discard_const(old_iscsi->passwd));
free(discard_const(old_iscsi->chap_c));
if (old_iscsi->connected_portal != NULL) {
free(discard_const(old_iscsi->connected_portal));
}
close(iscsi->fd);
iscsi->fd = old_iscsi->fd;
memcpy(old_iscsi, iscsi, sizeof(struct iscsi_context));

View File

@@ -333,6 +333,10 @@ iscsi_read_from_socket(struct iscsi_context *iscsi)
}
data_size = iscsi_get_pdu_data_size(&in->hdr[0]);
if (data_size < 0 || data_size > iscsi->initiator_max_recv_data_segment_length) {
iscsi_set_error(iscsi, "Invalid data size received from target (%d)", (int)data_size);
return -1;
}
if (data_size != 0) {
unsigned char *buf = NULL;

View File

@@ -30,13 +30,14 @@ const char *initiator = "iqn.2007-10.com.github:sahlberg:libiscsi:iscsi-readcapa
void print_usage(void)
{
fprintf(stderr, "Usage: iscsi-readcapacity16 [-?] [-?|--help] [--usage] [-i|--initiator-name=iqn-name] <iscsi-url>\n");
fprintf(stderr, "Usage: iscsi-readcapacity16 [-?] [-?|--help] [--usage] [-i|--initiator-name=iqn-name] [-s] <iscsi-url>\n");
}
void print_help(void)
{
fprintf(stderr, "Usage: iscsi_readcapacity16 [OPTION...] <iscsi-url>\n");
fprintf(stderr, " -i, --initiator-name=iqn-name Initiatorname to use\n");
fprintf(stderr, " -s, --size print target size only\n");
fprintf(stderr, " -d, --debug=integer debug level (0=disabled)\n");
fprintf(stderr, "\n");
fprintf(stderr, "Help options:\n");
@@ -59,7 +60,7 @@ int main(int argc, const char *argv[])
int extra_argc = 0;
const char *url = NULL;
struct iscsi_url *iscsi_url = NULL;
int show_help = 0, show_usage = 0, debug = 0;
int show_help = 0, show_usage = 0, debug = 0, size_only=0;
int res;
struct scsi_task *task;
struct scsi_readcapacity16 *rc16;
@@ -68,6 +69,7 @@ int main(int argc, const char *argv[])
{ "help", '?', POPT_ARG_NONE, &show_help, 0, "Show this help message", NULL },
{ "usage", 0, POPT_ARG_NONE, &show_usage, 0, "Display brief usage message", NULL },
{ "initiator-name", 'i', POPT_ARG_STRING, &initiator, 0, "Initiatorname to use", "iqn-name" },
{ "size", 's', POPT_ARG_NONE, &size_only, 0, "Print target size only", NULL },
{ "debug", 'd', POPT_ARG_INT, &debug, 0, "Debugging level", "integer" },
POPT_TABLEEND
};
@@ -155,16 +157,22 @@ int main(int argc, const char *argv[])
iscsi_destroy_context(iscsi);
exit(10);
}
if (!size_only) {
printf("RETURNED LOGICAL BLOCK ADDRESS:%" PRIu64 "\n", rc16->returned_lba);
printf("LOGICAL BLOCK LENGTH IN BYTES:%u\n", rc16->block_length);
printf("P_TYPE:%d PROT_EN:%d\n", rc16->p_type, rc16->prot_en);
printf("P_I_EXPONENT:%d LOGICAL BLOCKS PER PHYSICAL BLOCK EXPONENT:%d\n", rc16->p_i_exp, rc16->lbppbe);
printf("LBPME:%d LBPRZ:%d\n", rc16->lbpme, rc16->lbprz);
printf("LOWEST ALIGNED LOGICAL BLOCK ADDRESS:%d\n", rc16->lalba);
printf("RETURNED LOGICAL BLOCK ADDRESS:%" PRIu64 "\n", rc16->returned_lba);
printf("LOGICAL BLOCK LENGTH IN BYTES:%u\n", rc16->block_length);
printf("P_TYPE:%d PROT_EN:%d\n", rc16->p_type, rc16->prot_en);
printf("P_I_EXPONENT:%d LOGICAL BLOCKS PER PHYSICAL BLOCK EXPONENT:%d\n", rc16->p_i_exp, rc16->lbppbe);
printf("LBPME:%d LBPRZ:%d\n", rc16->lbpme, rc16->lbprz);
printf("LOWEST ALIGNED LOGICAL BLOCK ADDRESS:%d\n", rc16->lalba);
printf("Total size:%" PRIu64 "\n", rc16->block_length * (rc16->returned_lba + 1));
printf("Total size:%" PRIu64 "\n", rc16->block_length * (rc16->returned_lba + 1));
}
else
{
printf("%" PRIu64 "\n", rc16->block_length * (rc16->returned_lba + 1));
}
iscsi_destroy_url(iscsi_url);
iscsi_logout_sync(iscsi);