2008-02-20 15:49:25 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_iscsi.c: storage backend for iSCSI handling
|
|
|
|
*
|
2016-05-28 12:15:23 +00:00
|
|
|
* Copyright (C) 2007-2016 Red Hat, Inc.
|
2008-02-20 15:49:25 +00:00
|
|
|
* Copyright (C) 2007-2008 Daniel P. Berrange
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-02-20 15:49:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2013-03-25 16:43:38 +00:00
|
|
|
#include <dirent.h>
|
2008-02-20 15:49:25 +00:00
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
2010-01-21 11:50:52 +00:00
|
|
|
#include <sys/stat.h>
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2013-07-15 17:23:45 +00:00
|
|
|
#include "datatypes.h"
|
|
|
|
#include "driver.h"
|
2008-02-20 15:49:25 +00:00
|
|
|
#include "storage_backend_iscsi.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2012-12-12 16:27:01 +00:00
|
|
|
#include "vircommand.h"
|
2014-03-18 15:20:01 +00:00
|
|
|
#include "virerror.h"
|
|
|
|
#include "virfile.h"
|
2014-03-19 15:03:11 +00:00
|
|
|
#include "viriscsi.h"
|
2014-03-18 15:20:01 +00:00
|
|
|
#include "virlog.h"
|
2013-07-15 17:23:45 +00:00
|
|
|
#include "virobject.h"
|
2013-04-03 10:36:23 +00:00
|
|
|
#include "virstring.h"
|
2013-10-15 08:29:18 +00:00
|
|
|
#include "viruuid.h"
|
2016-05-28 12:15:23 +00:00
|
|
|
#include "secret_util.h"
|
2017-01-11 17:04:15 +00:00
|
|
|
#include "storage_util.h"
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2014-02-28 12:16:17 +00:00
|
|
|
VIR_LOG_INIT("storage.storage_backend_iscsi");
|
|
|
|
|
2013-07-18 16:30:29 +00:00
|
|
|
#define ISCSI_DEFAULT_TARGET_PORT 3260
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
static char *
|
|
|
|
virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
|
|
|
|
{
|
2013-06-06 12:00:13 +00:00
|
|
|
char *portal = NULL;
|
2010-11-02 11:40:46 +00:00
|
|
|
|
2012-04-25 10:43:09 +00:00
|
|
|
if (source->nhost != 1) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Expected exactly 1 host for the storage pool"));
|
2012-04-25 10:43:09 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-07-18 16:30:29 +00:00
|
|
|
if (source->hosts[0].port == 0)
|
|
|
|
source->hosts[0].port = ISCSI_DEFAULT_TARGET_PORT;
|
2010-11-02 11:40:46 +00:00
|
|
|
|
2013-07-18 16:30:29 +00:00
|
|
|
if (strchr(source->hosts[0].name, ':')) {
|
|
|
|
ignore_value(virAsprintf(&portal, "[%s]:%d,1",
|
|
|
|
source->hosts[0].name,
|
|
|
|
source->hosts[0].port));
|
2013-06-06 12:00:13 +00:00
|
|
|
} else {
|
2013-07-18 16:30:29 +00:00
|
|
|
ignore_value(virAsprintf(&portal, "%s:%d,1",
|
|
|
|
source->hosts[0].name,
|
|
|
|
source->hosts[0].port));
|
2010-11-02 11:40:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return portal;
|
|
|
|
}
|
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2014-03-19 14:54:08 +00:00
|
|
|
static char *
|
|
|
|
virStorageBackendISCSISession(virStoragePoolObjPtr pool,
|
|
|
|
bool probe)
|
|
|
|
{
|
2017-07-26 18:26:27 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
|
|
|
return virISCSIGetSession(def->source.devices[0].path, probe);
|
2014-03-19 14:52:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-25 16:43:38 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendISCSIGetHostNumber(const char *sysfs_path,
|
|
|
|
uint32_t *host)
|
|
|
|
{
|
2016-06-21 13:13:41 +00:00
|
|
|
int ret = -1;
|
2013-03-25 16:43:38 +00:00
|
|
|
DIR *sysdir = NULL;
|
|
|
|
struct dirent *dirent = NULL;
|
2014-04-24 21:48:55 +00:00
|
|
|
int direrr;
|
2013-03-25 16:43:38 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Finding host number from '%s'", sysfs_path);
|
|
|
|
|
2017-02-20 12:00:51 +00:00
|
|
|
virWaitForDevices();
|
2013-03-25 16:43:38 +00:00
|
|
|
|
2016-06-21 13:13:41 +00:00
|
|
|
if (virDirOpen(&sysdir, sysfs_path) < 0)
|
|
|
|
goto cleanup;
|
2013-03-25 16:43:38 +00:00
|
|
|
|
2014-04-24 21:48:55 +00:00
|
|
|
while ((direrr = virDirRead(sysdir, &dirent, sysfs_path)) > 0) {
|
2016-06-24 08:37:04 +00:00
|
|
|
if (STRPREFIX(dirent->d_name, "target")) {
|
2016-06-21 13:13:41 +00:00
|
|
|
if (sscanf(dirent->d_name, "target%u:", host) == 1) {
|
|
|
|
ret = 0;
|
|
|
|
goto cleanup;
|
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to parse target '%s'"), dirent->d_name);
|
|
|
|
goto cleanup;
|
2013-03-25 16:43:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 13:13:41 +00:00
|
|
|
if (direrr == 0) {
|
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Failed to get host number for iSCSI session "
|
|
|
|
"with path '%s'"), sysfs_path);
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
2016-06-21 10:40:29 +00:00
|
|
|
VIR_DIR_CLOSE(sysdir);
|
2016-06-21 13:13:41 +00:00
|
|
|
return ret;
|
2013-03-25 16:43:38 +00:00
|
|
|
}
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIFindLUs(virStoragePoolObjPtr pool,
|
2009-04-01 16:03:22 +00:00
|
|
|
const char *session)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
2011-04-03 09:21:30 +00:00
|
|
|
char *sysfs_path;
|
2015-04-01 10:46:25 +00:00
|
|
|
int retval = -1;
|
2009-04-01 16:03:22 +00:00
|
|
|
uint32_t host;
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2011-04-03 09:21:30 +00:00
|
|
|
if (virAsprintf(&sysfs_path,
|
2013-07-04 10:16:29 +00:00
|
|
|
"/sys/class/iscsi_session/session%s/device", session) < 0)
|
2015-04-01 10:46:25 +00:00
|
|
|
goto cleanup;
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2016-06-21 13:13:41 +00:00
|
|
|
if (virStorageBackendISCSIGetHostNumber(sysfs_path, &host) < 0)
|
2015-04-01 10:46:25 +00:00
|
|
|
goto cleanup;
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2015-03-30 22:49:36 +00:00
|
|
|
if (virStorageBackendSCSIFindLUs(pool, host) < 0)
|
2015-04-01 10:46:25 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
retval = 0;
|
|
|
|
|
|
|
|
cleanup:
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2011-04-03 09:21:30 +00:00
|
|
|
VIR_FREE(sysfs_path);
|
|
|
|
|
2008-06-17 12:49:37 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2008-02-20 15:49:25 +00:00
|
|
|
|
|
|
|
|
2010-11-12 15:41:16 +00:00
|
|
|
static char *
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendISCSIFindPoolSources(const char *srcSpec,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
2010-11-12 15:41:16 +00:00
|
|
|
{
|
|
|
|
size_t ntargets = 0;
|
|
|
|
char **targets = NULL;
|
|
|
|
char *ret = NULL;
|
Convert 'int i' to 'size_t i' in src/storage/ files
Convert the type of loop iterators named 'i', 'j', k',
'ii', 'jj', 'kk', to be 'size_t' instead of 'int' or
'unsigned int', also santizing 'ii', 'jj', 'kk' to use
the normal 'i', 'j', 'k' naming
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
2013-07-08 14:09:33 +00:00
|
|
|
size_t i;
|
2010-11-12 15:41:16 +00:00
|
|
|
virStoragePoolSourceList list = {
|
|
|
|
.type = VIR_STORAGE_POOL_ISCSI,
|
|
|
|
.nsources = 0,
|
|
|
|
.sources = NULL
|
|
|
|
};
|
|
|
|
char *portal = NULL;
|
2019-01-31 13:48:11 +00:00
|
|
|
VIR_AUTOPTR(virStoragePoolSource) source = NULL;
|
2010-11-12 15:41:16 +00:00
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2012-07-31 08:56:41 +00:00
|
|
|
if (!srcSpec) {
|
2015-02-25 22:31:55 +00:00
|
|
|
virReportError(VIR_ERR_INVALID_ARG, "%s",
|
|
|
|
_("hostname must be specified for iscsi sources"));
|
2012-07-31 08:56:41 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-11-12 15:41:16 +00:00
|
|
|
if (!(source = virStoragePoolDefParseSourceString(srcSpec,
|
|
|
|
list.type)))
|
|
|
|
return NULL;
|
|
|
|
|
2012-04-25 10:43:09 +00:00
|
|
|
if (source->nhost != 1) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Expected exactly 1 host for the storage pool"));
|
2012-04-25 10:43:09 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2010-11-12 15:41:16 +00:00
|
|
|
if (!(portal = virStorageBackendISCSIPortal(source)))
|
|
|
|
goto cleanup;
|
|
|
|
|
2018-06-29 14:05:50 +00:00
|
|
|
if (virISCSIScanTargets(portal,
|
|
|
|
source->initiator.iqn,
|
2018-06-29 14:18:23 +00:00
|
|
|
false,
|
2018-06-29 14:05:50 +00:00
|
|
|
&ntargets, &targets) < 0)
|
2010-11-12 15:41:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (VIR_ALLOC_N(list.sources, ntargets) < 0)
|
2010-11-12 15:41:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < ntargets; i++) {
|
2012-04-30 16:36:44 +00:00
|
|
|
if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0 ||
|
2013-07-04 10:16:29 +00:00
|
|
|
VIR_ALLOC_N(list.sources[i].hosts, 1) < 0)
|
2010-11-12 15:41:16 +00:00
|
|
|
goto cleanup;
|
2012-04-30 16:36:44 +00:00
|
|
|
list.sources[i].nhost = 1;
|
|
|
|
list.sources[i].hosts[0] = source->hosts[0];
|
2010-11-12 15:41:16 +00:00
|
|
|
list.sources[i].initiator = source->initiator;
|
|
|
|
list.sources[i].ndevice = 1;
|
|
|
|
list.sources[i].devices[0].path = targets[i];
|
|
|
|
list.nsources++;
|
|
|
|
}
|
|
|
|
|
2013-07-04 10:16:29 +00:00
|
|
|
if (!(ret = virStoragePoolSourceListFormat(&list)))
|
2010-11-12 15:41:16 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2010-11-12 15:41:16 +00:00
|
|
|
if (list.sources) {
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < ntargets; i++) {
|
2012-04-30 16:36:44 +00:00
|
|
|
VIR_FREE(list.sources[i].hosts);
|
2010-11-12 15:41:16 +00:00
|
|
|
VIR_FREE(list.sources[i].devices);
|
2012-04-30 16:36:44 +00:00
|
|
|
}
|
2010-11-12 15:41:16 +00:00
|
|
|
VIR_FREE(list.sources);
|
|
|
|
}
|
2013-05-21 07:21:21 +00:00
|
|
|
for (i = 0; i < ntargets; i++)
|
2010-11-12 15:41:16 +00:00
|
|
|
VIR_FREE(targets[i]);
|
|
|
|
VIR_FREE(targets);
|
|
|
|
VIR_FREE(portal);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
static int
|
2015-03-09 14:34:35 +00:00
|
|
|
virStorageBackendISCSICheckPool(virStoragePoolObjPtr pool,
|
2010-11-11 20:09:20 +00:00
|
|
|
bool *isActive)
|
|
|
|
{
|
2017-07-26 18:26:27 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2010-11-11 20:09:20 +00:00
|
|
|
char *session = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
*isActive = false;
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.nhost != 1) {
|
2014-03-20 12:23:42 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Expected exactly 1 host for the storage pool"));
|
2012-04-25 10:43:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.hosts[0].name == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source host"));
|
2010-11-11 20:09:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.ndevice != 1 ||
|
|
|
|
def->source.devices[0].path == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source device"));
|
2010-11-11 20:09:20 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-11 11:58:35 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, true)) != NULL) {
|
2010-11-11 20:09:20 +00:00
|
|
|
*isActive = true;
|
|
|
|
VIR_FREE(session);
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
static int
|
2013-07-15 17:23:45 +00:00
|
|
|
virStorageBackendISCSISetAuth(const char *portal,
|
2014-06-26 12:18:09 +00:00
|
|
|
virStoragePoolSourcePtr source)
|
2013-07-15 17:23:45 +00:00
|
|
|
{
|
|
|
|
unsigned char *secret_value = NULL;
|
2016-05-28 12:15:23 +00:00
|
|
|
size_t secret_size;
|
2014-06-26 12:18:09 +00:00
|
|
|
virStorageAuthDefPtr authdef = source->auth;
|
2013-07-15 17:23:45 +00:00
|
|
|
int ret = -1;
|
2018-01-26 13:15:33 +00:00
|
|
|
virConnectPtr conn = NULL;
|
2013-07-15 17:23:45 +00:00
|
|
|
|
2014-06-26 12:18:09 +00:00
|
|
|
if (!authdef || authdef->authType == VIR_STORAGE_AUTH_TYPE_NONE)
|
2013-07-15 17:23:45 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-05-28 12:43:23 +00:00
|
|
|
VIR_DEBUG("username='%s' authType=%d seclookupdef.type=%d",
|
|
|
|
authdef->username, authdef->authType, authdef->seclookupdef.type);
|
2014-06-26 12:18:09 +00:00
|
|
|
if (authdef->authType != VIR_STORAGE_AUTH_TYPE_CHAP) {
|
2013-07-15 17:23:45 +00:00
|
|
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
|
|
|
_("iscsi pool only supports 'chap' auth type"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-01-26 13:15:33 +00:00
|
|
|
conn = virGetConnectSecret();
|
|
|
|
if (!conn)
|
2013-07-15 17:23:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2016-05-28 12:43:23 +00:00
|
|
|
if (virSecretGetSecretString(conn, &authdef->seclookupdef,
|
|
|
|
VIR_SECRET_USAGE_TYPE_ISCSI,
|
2016-05-28 12:15:23 +00:00
|
|
|
&secret_value, &secret_size) < 0)
|
2013-07-15 17:23:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2018-08-13 08:35:37 +00:00
|
|
|
if (VIR_REALLOC_N(secret_value, secret_size + 1) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
secret_value[secret_size] = '\0';
|
|
|
|
|
2014-03-19 15:03:11 +00:00
|
|
|
if (virISCSINodeUpdate(portal,
|
2014-06-26 12:18:09 +00:00
|
|
|
source->devices[0].path,
|
2014-03-19 15:03:11 +00:00
|
|
|
"node.session.auth.authmethod",
|
|
|
|
"CHAP") < 0 ||
|
|
|
|
virISCSINodeUpdate(portal,
|
2014-06-26 12:18:09 +00:00
|
|
|
source->devices[0].path,
|
2014-03-19 15:03:11 +00:00
|
|
|
"node.session.auth.username",
|
2014-06-26 12:18:09 +00:00
|
|
|
authdef->username) < 0 ||
|
2014-03-19 15:03:11 +00:00
|
|
|
virISCSINodeUpdate(portal,
|
2014-06-26 12:18:09 +00:00
|
|
|
source->devices[0].path,
|
2014-03-19 15:03:11 +00:00
|
|
|
"node.session.auth.password",
|
|
|
|
(const char *)secret_value) < 0)
|
2013-07-15 17:23:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2016-05-28 12:15:23 +00:00
|
|
|
VIR_DISPOSE_N(secret_value, secret_size);
|
2018-01-26 13:15:33 +00:00
|
|
|
virObjectUnref(conn);
|
2013-07-15 17:23:45 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendISCSIStartPool(virStoragePoolObjPtr pool)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
2017-07-26 18:26:27 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2008-02-20 15:49:25 +00:00
|
|
|
char *portal = NULL;
|
2010-11-02 11:40:46 +00:00
|
|
|
char *session = NULL;
|
|
|
|
int ret = -1;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.nhost != 1) {
|
2014-03-20 12:23:42 +00:00
|
|
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
|
|
_("Expected exactly 1 host for the storage pool"));
|
2012-04-25 10:43:09 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.hosts[0].name == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source host"));
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if (def->source.ndevice != 1 ||
|
|
|
|
def->source.devices[0].path == NULL) {
|
2012-07-18 11:38:29 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source device"));
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2014-03-11 11:58:35 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, true)) == NULL) {
|
2017-07-26 18:26:27 +00:00
|
|
|
if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
2016-07-16 12:15:03 +00:00
|
|
|
|
|
|
|
/* Create a static node record for the IQN target. Must be done
|
|
|
|
* in order for login to the target */
|
2017-07-26 18:26:27 +00:00
|
|
|
if (virISCSINodeNew(portal, def->source.devices[0].path) < 0)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2018-01-26 13:15:33 +00:00
|
|
|
if (virStorageBackendISCSISetAuth(portal, &def->source) < 0)
|
2013-07-15 17:23:45 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
2014-03-19 15:03:11 +00:00
|
|
|
if (virISCSIConnectionLogin(portal,
|
2017-07-26 18:26:27 +00:00
|
|
|
def->source.initiator.iqn,
|
|
|
|
def->source.devices[0].path) < 0)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
2010-11-02 11:40:46 +00:00
|
|
|
ret = 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2013-05-06 12:36:23 +00:00
|
|
|
VIR_FREE(portal);
|
2010-11-02 11:40:46 +00:00
|
|
|
VIR_FREE(session);
|
|
|
|
return ret;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendISCSIRefreshPool(virStoragePoolObjPtr pool)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
2017-07-26 18:26:27 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2008-02-20 15:49:25 +00:00
|
|
|
char *session = NULL;
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
def->allocation = def->capacity = def->available = 0;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2014-03-11 11:58:35 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, false)) == NULL)
|
2008-02-20 15:49:25 +00:00
|
|
|
goto cleanup;
|
2014-03-19 15:03:11 +00:00
|
|
|
if (virISCSIRescanLUNs(session) < 0)
|
2008-02-20 15:49:25 +00:00
|
|
|
goto cleanup;
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendISCSIFindLUs(pool, session) < 0)
|
2008-02-20 15:49:25 +00:00
|
|
|
goto cleanup;
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(session);
|
2008-02-20 15:49:25 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(session);
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2018-01-26 13:31:58 +00:00
|
|
|
virStorageBackendISCSIStopPool(virStoragePoolObjPtr pool)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
2017-07-26 18:26:27 +00:00
|
|
|
virStoragePoolDefPtr def = virStoragePoolObjGetDef(pool);
|
2008-02-20 15:49:25 +00:00
|
|
|
char *portal;
|
2015-04-29 12:59:08 +00:00
|
|
|
char *session;
|
2010-11-02 11:40:46 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2015-04-29 12:59:08 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, true)) == NULL)
|
|
|
|
return 0;
|
|
|
|
VIR_FREE(session);
|
|
|
|
|
2017-07-26 18:26:27 +00:00
|
|
|
if ((portal = virStorageBackendISCSIPortal(&def->source)) == NULL)
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
|
2014-03-19 15:03:11 +00:00
|
|
|
if (virISCSIConnectionLogout(portal,
|
2017-07-26 18:26:27 +00:00
|
|
|
def->source.initiator.iqn,
|
|
|
|
def->source.devices[0].path) < 0)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2014-03-25 06:52:40 +00:00
|
|
|
cleanup:
|
2010-11-02 11:40:46 +00:00
|
|
|
VIR_FREE(portal);
|
|
|
|
return ret;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virStorageBackend virStorageBackendISCSI = {
|
2008-10-16 15:06:03 +00:00
|
|
|
.type = VIR_STORAGE_POOL_ISCSI,
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
.checkPool = virStorageBackendISCSICheckPool,
|
2008-10-16 15:06:03 +00:00
|
|
|
.startPool = virStorageBackendISCSIStartPool,
|
|
|
|
.refreshPool = virStorageBackendISCSIRefreshPool,
|
|
|
|
.stopPool = virStorageBackendISCSIStopPool,
|
2010-11-12 15:41:16 +00:00
|
|
|
.findPoolSources = virStorageBackendISCSIFindPoolSources,
|
2014-07-07 14:50:11 +00:00
|
|
|
.uploadVol = virStorageBackendVolUploadLocal,
|
|
|
|
.downloadVol = virStorageBackendVolDownloadLocal,
|
2014-07-07 14:50:11 +00:00
|
|
|
.wipeVol = virStorageBackendVolWipeLocal,
|
2008-02-20 15:49:25 +00:00
|
|
|
};
|
2017-01-13 15:50:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
virStorageBackendISCSIRegister(void)
|
|
|
|
{
|
|
|
|
return virStorageBackendRegister(&virStorageBackendISCSI);
|
|
|
|
}
|