Merge pull request #439 from plieven/feat/improve_logging
Add some logging improvements
This commit is contained in:
@@ -72,9 +72,9 @@ iscsi_log_message(struct iscsi_context *iscsi, int level, const char *format, ..
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (iscsi->target_name[0]) {
|
if (iscsi->target_name[0]) {
|
||||||
static char message2[1282];
|
static char message2[1294];
|
||||||
|
|
||||||
snprintf(message2, 1282, "%s [%s]", message, iscsi->target_name);
|
snprintf(message2, sizeof(message2), "%s [%s/%d]", message, iscsi->target_name, iscsi->lun);
|
||||||
iscsi->log_fn(level, message2);
|
iscsi->log_fn(level, message2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
20
lib/socket.c
20
lib/socket.c
@@ -306,6 +306,7 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
struct addrinfo *ai = NULL;
|
struct addrinfo *ai = NULL;
|
||||||
union socket_address sa;
|
union socket_address sa;
|
||||||
int socksize;
|
int socksize;
|
||||||
|
bool portal_is_ip;
|
||||||
|
|
||||||
ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal);
|
ISCSI_LOG(iscsi, 2, "connecting to portal %s",portal);
|
||||||
|
|
||||||
@@ -352,6 +353,10 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
*str = 0;
|
*str = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check if we got an ip address or hostname for portal */
|
||||||
|
portal_is_ip = inet_pton(AF_INET, host, &sa) == 1 ||
|
||||||
|
inet_pton(AF_INET6, host, &sa) == 1;
|
||||||
|
|
||||||
/* is it a hostname ? */
|
/* is it a hostname ? */
|
||||||
if (getaddrinfo(host, NULL, NULL, &ai) != 0) {
|
if (getaddrinfo(host, NULL, NULL, &ai) != 0) {
|
||||||
iscsi_free(iscsi, addr);
|
iscsi_free(iscsi, addr);
|
||||||
@@ -371,6 +376,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
#ifdef HAVE_SOCK_SIN_LEN
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
sa.sin.sin_len = socksize;
|
sa.sin.sin_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
|
if (!portal_is_ip) {
|
||||||
|
char ip[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &sa.sin.sin_addr, ip, sizeof(ip));
|
||||||
|
ISCSI_LOG(iscsi, 2, "portal resolved to ipv4 address %s", ip);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef HAVE_SOCKADDR_IN6
|
#ifdef HAVE_SOCKADDR_IN6
|
||||||
case AF_INET6:
|
case AF_INET6:
|
||||||
@@ -381,6 +391,11 @@ iscsi_connect_async(struct iscsi_context *iscsi, const char *portal,
|
|||||||
#ifdef HAVE_SOCK_SIN_LEN
|
#ifdef HAVE_SOCK_SIN_LEN
|
||||||
sa.sin6.sin6_len = socksize;
|
sa.sin6.sin6_len = socksize;
|
||||||
#endif
|
#endif
|
||||||
|
if (!portal_is_ip) {
|
||||||
|
char ip[INET6_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET6, &sa.sin6.sin6_addr, ip, sizeof(ip));
|
||||||
|
ISCSI_LOG(iscsi, 2, "portal resolved to ipv6 address %s", ip);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
default:
|
default:
|
||||||
@@ -1073,7 +1088,10 @@ iscsi_tcp_service(struct iscsi_context *iscsi, int revents)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (getsockname(iscsi->fd, (struct sockaddr *) &local, &local_l) == 0) {
|
if (getsockname(iscsi->fd, (struct sockaddr *) &local, &local_l) == 0) {
|
||||||
ISCSI_LOG(iscsi, 2, "connection established to %s", iscsi->connected_portal);
|
char ip[INET_ADDRSTRLEN];
|
||||||
|
inet_ntop(AF_INET, &local.sin_addr, ip, sizeof(ip));
|
||||||
|
ISCSI_LOG(iscsi, 2, "connection established (%s:%u -> %s)", ip,
|
||||||
|
(unsigned)ntohs(local.sin_port), iscsi->connected_portal);
|
||||||
}
|
}
|
||||||
|
|
||||||
iscsi->is_connected = 1;
|
iscsi->is_connected = 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user