Add debugging framework
This patch adds a user configurable debug level. For testing it includes connection info and reporting errors.
This commit is contained in:
@@ -158,6 +158,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.
|
||||
@@ -213,6 +215,8 @@ try_again:
|
||||
iscsi->lun = old_iscsi->lun;
|
||||
|
||||
iscsi->portal = strdup(old_iscsi->portal);
|
||||
|
||||
iscsi->debug = old_iscsi->debug;
|
||||
|
||||
if (iscsi_full_connect_sync(iscsi, iscsi->portal, iscsi->lun) != 0) {
|
||||
iscsi_destroy_context(iscsi);
|
||||
|
||||
16
lib/init.c
16
lib/init.c
@@ -244,6 +244,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 +256,6 @@ iscsi_destroy_context(struct iscsi_context *iscsi)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
iscsi_set_error(struct iscsi_context *iscsi, const char *error_string, ...)
|
||||
{
|
||||
@@ -270,9 +273,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,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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -60,6 +60,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
|
||||
|
||||
@@ -68,6 +68,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.");
|
||||
@@ -170,6 +172,10 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
||||
}
|
||||
|
||||
freeaddrinfo(ai);
|
||||
|
||||
if (iscsi->connected_portal) free(iscsi->connected_portal);
|
||||
iscsi->connected_portal=strdup(portal);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -183,6 +189,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;
|
||||
|
||||
Reference in New Issue
Block a user