mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-23 04:55:18 +00:00
iscsi: pass hostnames to iscsiadm instead of resolving them
iscsiadm now supports specifying hostnames in the portal argument [1] Instead of resolving the hostname to a single IPv4 address, pass the hostname to isciadm, allowing IPv6 targets to work. [1] https://bugzilla.redhat.com/show_bug.cgi?id=624437 (cherry picked from commit cbdb3c7326f7298d57233d835a5966df2e359d99)
This commit is contained in:
parent
818a933141
commit
3b6bc5eda6
@ -24,9 +24,6 @@
|
|||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/socket.h>
|
|
||||||
#include <netdb.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -47,55 +44,12 @@
|
|||||||
|
|
||||||
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
||||||
|
|
||||||
static int
|
|
||||||
virStorageBackendISCSITargetIP(const char *hostname,
|
|
||||||
char *ipaddr,
|
|
||||||
size_t ipaddrlen)
|
|
||||||
{
|
|
||||||
struct addrinfo hints;
|
|
||||||
struct addrinfo *result = NULL;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
memset(&hints, 0, sizeof(hints));
|
|
||||||
hints.ai_flags = AI_ADDRCONFIG;
|
|
||||||
hints.ai_family = AF_INET;
|
|
||||||
hints.ai_socktype = SOCK_STREAM;
|
|
||||||
hints.ai_protocol = 0;
|
|
||||||
|
|
||||||
ret = getaddrinfo(hostname, NULL, &hints, &result);
|
|
||||||
if (ret != 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("host lookup failed %s"),
|
|
||||||
gai_strerror(ret));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == NULL) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("no IP address for target %s"),
|
|
||||||
hostname);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getnameinfo(result->ai_addr, result->ai_addrlen,
|
|
||||||
ipaddr, ipaddrlen, NULL, 0,
|
|
||||||
NI_NUMERICHOST) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
||||||
_("cannot format ip addr for %s"),
|
|
||||||
hostname);
|
|
||||||
freeaddrinfo(result);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
freeaddrinfo(result);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
|
virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
|
||||||
{
|
{
|
||||||
char ipaddr[NI_MAXHOST];
|
char *portal = NULL;
|
||||||
char *portal;
|
const char *host;
|
||||||
|
int port = 3260;
|
||||||
|
|
||||||
if (source->nhost != 1) {
|
if (source->nhost != 1) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -103,15 +57,16 @@ virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virStorageBackendISCSITargetIP(source->hosts[0].name,
|
host = source->hosts[0].name;
|
||||||
ipaddr, sizeof(ipaddr)) < 0)
|
if (source->hosts[0].port != 0)
|
||||||
return NULL;
|
port = source->hosts[0].port;
|
||||||
|
|
||||||
if (virAsprintf(&portal, "%s:%d,1", ipaddr,
|
if (strchr(host, ':')) {
|
||||||
source->hosts[0].port ?
|
if (virAsprintf(&portal, "[%s]:%d,1", host, port) < 0)
|
||||||
source->hosts[0].port : 3260) < 0) {
|
virReportOOMError();
|
||||||
|
} else {
|
||||||
|
if (virAsprintf(&portal, "%s:%d,1", host, port) < 0)
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return portal;
|
return portal;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user