storage: gluster: Support multiple hosts in backend functions

As gluster natively supports multiple hosts for failover reasons we can
easily add the support to the storage driver code in libvirt.

Extract the code setting an individual host into a separate function and
call them in a loop. The new code also tries to keep the debug log
entries sane.
This commit is contained in:
Peter Krempa 2016-07-22 09:48:51 +02:00
parent 1575f3e8d3
commit f1bbc7df4a

View File

@ -570,25 +570,55 @@ virStorageFileBackendGlusterDeinit(virStorageSourcePtr src)
} }
static int static int
virStorageFileBackendGlusterInit(virStorageSourcePtr src) virStorageFileBackendGlusterInitServer(virStorageFileBackendGlusterPrivPtr priv,
virStorageNetHostDefPtr host)
{ {
virStorageFileBackendGlusterPrivPtr priv = NULL; const char *transport = virStorageNetHostTransportTypeToString(host->transport);
virStorageNetHostDefPtr host = &(src->hosts[0]); const char *hoststr = NULL;
const char *hostname;
int port = 0; int port = 0;
if (src->nhosts != 1) { switch ((virStorageNetHostTransport) host->transport) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", case VIR_STORAGE_NET_HOST_TRANS_RDMA:
_("Expected exactly 1 host for the gluster volume")); case VIR_STORAGE_NET_HOST_TRANS_TCP:
hoststr = host->name;
if (host->port &&
virStrToLong_i(host->port, NULL, 10, &port) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("failed to parse port number '%s'"),
host->port);
return -1;
}
break;
case VIR_STORAGE_NET_HOST_TRANS_UNIX:
hoststr = host->socket;
break;
case VIR_STORAGE_NET_HOST_TRANS_LAST:
break;
}
VIR_DEBUG("adding gluster host for %p: transport=%s host=%s port=%d",
priv, transport, hoststr, port);
if (glfs_set_volfile_server(priv->vol, transport, hoststr, port) < 0) {
virReportSystemError(errno,
_("failed to set gluster volfile server '%s'"),
hoststr);
return -1; return -1;
} }
hostname = host->name; return 0;
}
VIR_DEBUG("initializing gluster storage file %p (gluster://%s:%s/%s%s)[%u:%u]",
src, hostname, host->port ? host->port : "0", static int
NULLSTR(src->volume), src->path, virStorageFileBackendGlusterInit(virStorageSourcePtr src)
(unsigned int)src->drv->uid, (unsigned int)src->drv->gid); {
virStorageFileBackendGlusterPrivPtr priv = NULL;
size_t i;
if (!src->volume) { if (!src->volume) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
@ -600,35 +630,25 @@ virStorageFileBackendGlusterInit(virStorageSourcePtr src)
if (VIR_ALLOC(priv) < 0) if (VIR_ALLOC(priv) < 0)
return -1; return -1;
if (host->port && VIR_DEBUG("initializing gluster storage file %p "
virStrToLong_i(host->port, NULL, 10, &port) < 0) { "(priv='%p' volume='%s' path='%s') as [%u:%u]",
virReportError(VIR_ERR_INTERNAL_ERROR, src, priv, src->volume, src->path,
_("failed to parse port number '%s'"), (unsigned int)src->drv->uid, (unsigned int)src->drv->gid);
host->port);
goto error;
}
if (host->transport == VIR_STORAGE_NET_HOST_TRANS_UNIX)
hostname = host->socket;
if (!(priv->vol = glfs_new(src->volume))) { if (!(priv->vol = glfs_new(src->volume))) {
virReportOOMError(); virReportOOMError();
goto error; goto error;
} }
if (glfs_set_volfile_server(priv->vol, for (i = 0; i < src->nhosts; i++) {
virStorageNetHostTransportTypeToString(host->transport), if (virStorageFileBackendGlusterInitServer(priv, src->hosts + i) < 0)
hostname, port) < 0) { goto error;
virReportSystemError(errno,
_("failed to set gluster volfile server '%s'"),
hostname);
goto error;
} }
if (glfs_init(priv->vol) < 0) { if (glfs_init(priv->vol) < 0) {
virReportSystemError(errno, virReportSystemError(errno,
_("failed to initialize gluster connection to " _("failed to initialize gluster connection "
"server: '%s'"), hostname); "(src=%p priv=%p)"), src, priv);
goto error; goto error;
} }