2008-02-20 15:49:25 +00:00
|
|
|
/*
|
|
|
|
* storage_backend_iscsi.c: storage backend for iSCSI handling
|
|
|
|
*
|
build: detect potentential uninitialized variables
Even with -Wuninitialized (which is part of autobuild.sh
--enable-compile-warnings=error), gcc does NOT catch this
use of an uninitialized variable:
{
if (cond)
goto error;
int a = 1;
error:
printf("%d", a);
}
which prints 0 (supposing the stack started life wiped) if
cond was true. Clang will catch it, but we don't use clang
as often. Using gcc -Wjump-misses-init catches it, but also
gives false positives:
{
if (cond)
goto error;
int a = 1;
return a;
error:
return 0;
}
Here, a was never used in the scope of the error block, so
declaring it after goto is technically fine (and clang agrees).
However, given that our HACKING already documents a preference
to C89 decl-before-statement, the false positive warning is
enough of a prod to comply with HACKING.
[Personally, I'd _really_ rather use C99 decl-after-statement
to minimize scope, but until gcc can efficiently and reliably
catch scoping and uninitialized usage bugs, I'll settle with
the compromise of enforcing a coding standard that happens to
reject false positives if it can also detect real bugs.]
* acinclude.m4 (LIBVIRT_COMPILE_WARNINGS): Add -Wjump-misses-init.
* src/util/util.c (__virExec): Adjust offenders.
* src/conf/domain_conf.c (virDomainTimerDefParseXML): Likewise.
* src/remote/remote_driver.c (doRemoteOpen): Likewise.
* src/phyp/phyp_driver.c (phypGetLparNAME, phypGetLparProfile)
(phypGetVIOSFreeSCSIAdapter, phypVolumeGetKey)
(phypGetStoragePoolDevice)
(phypVolumeGetPhysicalVolumeByStoragePool)
(phypVolumeGetPath): Likewise.
* src/vbox/vbox_tmpl.c (vboxNetworkUndefineDestroy)
(vboxNetworkCreate, vboxNetworkDumpXML)
(vboxNetworkDefineCreateXML): Likewise.
* src/xenapi/xenapi_driver.c (getCapsObject)
(xenapiDomainDumpXML): Likewise.
* src/xenapi/xenapi_utils.c (createVMRecordFromXml): Likewise.
* src/security/security_selinux.c (SELinuxGenNewContext):
Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetPtyPaths):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainShutdown)
(qemudDomainBlockStats, qemudDomainMemoryPeek): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendCreateIfaceIQN): Likewise.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
2011-04-01 15:41:45 +00:00
|
|
|
* Copyright (C) 2007-2008, 2010-2011 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
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
* Author: Daniel P. Berrange <berrange@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <regex.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <dirent.h>
|
2010-01-21 11:50:52 +00:00
|
|
|
#include <sys/stat.h>
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2008-11-04 22:30:33 +00:00
|
|
|
#include "virterror_internal.h"
|
2009-04-01 16:03:22 +00:00
|
|
|
#include "storage_backend_scsi.h"
|
2008-02-20 15:49:25 +00:00
|
|
|
#include "storage_backend_iscsi.h"
|
|
|
|
#include "util.h"
|
2008-06-06 11:09:57 +00:00
|
|
|
#include "memory.h"
|
2010-01-21 11:50:52 +00:00
|
|
|
#include "logging.h"
|
2010-11-09 20:48:48 +00:00
|
|
|
#include "files.h"
|
2011-05-03 22:14:00 +00:00
|
|
|
#include "command.h"
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2009-01-20 17:13:33 +00:00
|
|
|
#define VIR_FROM_THIS VIR_FROM_STORAGE
|
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSITargetIP(const char *hostname,
|
2008-02-20 15:49:25 +00:00
|
|
|
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) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-20 15:49:25 +00:00
|
|
|
_("host lookup failed %s"),
|
|
|
|
gai_strerror(ret));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (result == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-20 15:49:25 +00:00
|
|
|
_("no IP address for target %s"),
|
|
|
|
hostname);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getnameinfo(result->ai_addr, result->ai_addrlen,
|
|
|
|
ipaddr, ipaddrlen, NULL, 0,
|
|
|
|
NI_NUMERICHOST) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-20 15:49:25 +00:00
|
|
|
_("cannot format ip addr for %s"),
|
|
|
|
hostname);
|
|
|
|
freeaddrinfo(result);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo(result);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
static char *
|
|
|
|
virStorageBackendISCSIPortal(virStoragePoolSourcePtr source)
|
|
|
|
{
|
|
|
|
char ipaddr[NI_MAXHOST];
|
|
|
|
char *portal;
|
|
|
|
|
|
|
|
if (virStorageBackendISCSITargetIP(source->host.name,
|
|
|
|
ipaddr, sizeof(ipaddr)) < 0)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (virAsprintf(&portal, "%s:%d,1", ipaddr,
|
|
|
|
source->host.port ?
|
|
|
|
source->host.port : 3260) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return portal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIExtractSession(virStoragePoolObjPtr pool,
|
2008-02-20 15:49:25 +00:00
|
|
|
char **const groups,
|
|
|
|
void *data)
|
|
|
|
{
|
|
|
|
char **session = data;
|
|
|
|
|
|
|
|
if (STREQ(groups[1], pool->def->source.devices[0].path)) {
|
|
|
|
if ((*session = strdup(groups[0])) == NULL) {
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSISession(virStoragePoolObjPtr pool,
|
2009-01-20 22:43:07 +00:00
|
|
|
int probe)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
|
|
|
/*
|
2008-06-17 12:46:38 +00:00
|
|
|
* # iscsiadm --mode session
|
2008-02-20 15:49:25 +00:00
|
|
|
* tcp: [1] 192.168.122.170:3260,1 demo-tgt-b
|
|
|
|
* tcp: [2] 192.168.122.170:3260,1 demo-tgt-a
|
|
|
|
*
|
|
|
|
* Pull out 2nd and 4th fields
|
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
|
|
|
"^tcp:\\s+\\[(\\S+)\\]\\s+\\S+\\s+(\\S+)\\s*$"
|
|
|
|
};
|
|
|
|
int vars[] = {
|
|
|
|
2,
|
|
|
|
};
|
2008-06-17 12:49:37 +00:00
|
|
|
const char *const prog[] = {
|
2008-06-17 12:46:38 +00:00
|
|
|
ISCSIADM, "--mode", "session", NULL
|
2008-02-20 15:49:25 +00:00
|
|
|
};
|
|
|
|
char *session = NULL;
|
|
|
|
|
2008-06-17 12:45:24 +00:00
|
|
|
/* Note that we ignore the exitstatus. Older versions of iscsiadm tools
|
|
|
|
* returned an exit status of > 0, even if they succeeded. We will just
|
|
|
|
* rely on whether session got filled in properly.
|
|
|
|
*/
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendRunProgRegex(pool,
|
2008-02-20 15:49:25 +00:00
|
|
|
prog,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendISCSIExtractSession,
|
2011-05-10 19:36:50 +00:00
|
|
|
&session) < 0)
|
2008-02-20 15:49:25 +00:00
|
|
|
return NULL;
|
|
|
|
|
2009-01-20 22:43:07 +00:00
|
|
|
if (session == NULL &&
|
|
|
|
!probe) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("cannot find session"));
|
2008-02-20 15:49:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return session;
|
|
|
|
}
|
|
|
|
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
#define LINE_SIZE 4096
|
|
|
|
|
|
|
|
static int
|
2010-11-02 11:40:46 +00:00
|
|
|
virStorageBackendIQNFound(const char *initiatoriqn,
|
2010-01-21 11:50:52 +00:00
|
|
|
char **ifacename)
|
|
|
|
{
|
|
|
|
int ret = IQN_MISSING, fd = -1;
|
|
|
|
char ebuf[64];
|
|
|
|
FILE *fp = NULL;
|
2011-07-04 02:41:38 +00:00
|
|
|
char *line = NULL, *newline = NULL, *iqn = NULL, *token = NULL;
|
2011-05-06 20:00:23 +00:00
|
|
|
virCommandPtr cmd = virCommandNewArgList(ISCSIADM,
|
|
|
|
"--mode", "iface", NULL);
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
if (VIR_ALLOC_N(line, LINE_SIZE) != 0) {
|
|
|
|
ret = IQN_ERROR;
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Could not allocate memory for output of '%s'"),
|
2011-05-06 20:00:23 +00:00
|
|
|
ISCSIADM);
|
2010-01-21 11:50:52 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(line, 0, LINE_SIZE);
|
|
|
|
|
2011-05-06 20:00:23 +00:00
|
|
|
virCommandSetOutputFD(cmd, &fd);
|
|
|
|
if (virCommandRunAsync(cmd, NULL) < 0) {
|
2010-01-21 11:50:52 +00:00
|
|
|
ret = IQN_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2010-11-17 02:13:29 +00:00
|
|
|
if ((fp = VIR_FDOPEN(fd, "r")) == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Failed to open stream for file descriptor "
|
|
|
|
"when reading output from '%s': '%s'"),
|
2011-05-06 20:00:23 +00:00
|
|
|
ISCSIADM, virStrerror(errno, ebuf, sizeof ebuf));
|
2010-01-21 11:50:52 +00:00
|
|
|
ret = IQN_ERROR;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (fgets(line, LINE_SIZE, fp) != NULL) {
|
|
|
|
newline = strrchr(line, '\n');
|
|
|
|
if (newline == NULL) {
|
|
|
|
ret = IQN_ERROR;
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Unexpected line > %d characters "
|
|
|
|
"when parsing output of '%s'"),
|
2011-05-06 20:00:23 +00:00
|
|
|
LINE_SIZE, ISCSIADM);
|
2010-01-21 11:50:52 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*newline = '\0';
|
|
|
|
|
|
|
|
iqn = strrchr(line, ',');
|
|
|
|
if (iqn == NULL) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
iqn++;
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
if (STREQ(iqn, initiatoriqn)) {
|
2011-07-04 02:41:38 +00:00
|
|
|
token = strchr(line, ' ');
|
|
|
|
if (!token) {
|
|
|
|
ret = IQN_ERROR;
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
_("Missing space when parsing output "
|
|
|
|
"of '%s'"), ISCSIADM);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
*ifacename = strndup(line, token - line);
|
2010-01-21 11:50:52 +00:00
|
|
|
if (*ifacename == NULL) {
|
|
|
|
ret = IQN_ERROR;
|
2010-02-04 18:19:08 +00:00
|
|
|
virReportOOMError();
|
2010-01-21 11:50:52 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
VIR_DEBUG("Found interface '%s' with IQN '%s'", *ifacename, iqn);
|
|
|
|
ret = IQN_FOUND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 20:00:23 +00:00
|
|
|
if (virCommandWait(cmd, NULL) < 0)
|
|
|
|
ret = IQN_ERROR;
|
|
|
|
|
2010-01-21 11:50:52 +00:00
|
|
|
out:
|
|
|
|
if (ret == IQN_MISSING) {
|
2010-08-02 19:52:02 +00:00
|
|
|
VIR_DEBUG("Could not find interface with IQN '%s'", iqn);
|
2010-01-21 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VIR_FREE(line);
|
2010-11-17 02:13:29 +00:00
|
|
|
VIR_FORCE_FCLOSE(fp);
|
|
|
|
VIR_FORCE_CLOSE(fd);
|
2011-05-06 20:00:23 +00:00
|
|
|
virCommandFree(cmd);
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-11-02 11:40:46 +00:00
|
|
|
virStorageBackendCreateIfaceIQN(const char *initiatoriqn,
|
2010-02-10 11:42:56 +00:00
|
|
|
char **ifacename)
|
2010-01-21 11:50:52 +00:00
|
|
|
{
|
|
|
|
int ret = -1, exitstatus = -1;
|
|
|
|
char temp_ifacename[32];
|
build: detect potentential uninitialized variables
Even with -Wuninitialized (which is part of autobuild.sh
--enable-compile-warnings=error), gcc does NOT catch this
use of an uninitialized variable:
{
if (cond)
goto error;
int a = 1;
error:
printf("%d", a);
}
which prints 0 (supposing the stack started life wiped) if
cond was true. Clang will catch it, but we don't use clang
as often. Using gcc -Wjump-misses-init catches it, but also
gives false positives:
{
if (cond)
goto error;
int a = 1;
return a;
error:
return 0;
}
Here, a was never used in the scope of the error block, so
declaring it after goto is technically fine (and clang agrees).
However, given that our HACKING already documents a preference
to C89 decl-before-statement, the false positive warning is
enough of a prod to comply with HACKING.
[Personally, I'd _really_ rather use C99 decl-after-statement
to minimize scope, but until gcc can efficiently and reliably
catch scoping and uninitialized usage bugs, I'll settle with
the compromise of enforcing a coding standard that happens to
reject false positives if it can also detect real bugs.]
* acinclude.m4 (LIBVIRT_COMPILE_WARNINGS): Add -Wjump-misses-init.
* src/util/util.c (__virExec): Adjust offenders.
* src/conf/domain_conf.c (virDomainTimerDefParseXML): Likewise.
* src/remote/remote_driver.c (doRemoteOpen): Likewise.
* src/phyp/phyp_driver.c (phypGetLparNAME, phypGetLparProfile)
(phypGetVIOSFreeSCSIAdapter, phypVolumeGetKey)
(phypGetStoragePoolDevice)
(phypVolumeGetPhysicalVolumeByStoragePool)
(phypVolumeGetPath): Likewise.
* src/vbox/vbox_tmpl.c (vboxNetworkUndefineDestroy)
(vboxNetworkCreate, vboxNetworkDumpXML)
(vboxNetworkDefineCreateXML): Likewise.
* src/xenapi/xenapi_driver.c (getCapsObject)
(xenapiDomainDumpXML): Likewise.
* src/xenapi/xenapi_utils.c (createVMRecordFromXml): Likewise.
* src/security/security_selinux.c (SELinuxGenNewContext):
Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetPtyPaths):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainShutdown)
(qemudDomainBlockStats, qemudDomainMemoryPeek): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendCreateIfaceIQN): Likewise.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
2011-04-01 15:41:45 +00:00
|
|
|
const char *const cmdargv1[] = {
|
|
|
|
ISCSIADM, "--mode", "iface", "--interface",
|
|
|
|
temp_ifacename, "--op", "new", NULL
|
|
|
|
};
|
|
|
|
const char *const cmdargv2[] = {
|
|
|
|
ISCSIADM, "--mode", "iface", "--interface", temp_ifacename,
|
|
|
|
"--op", "update", "--name", "iface.initiatorname", "--value",
|
|
|
|
initiatoriqn, NULL
|
|
|
|
};
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
if (virRandomInitialize(time(NULL) ^ getpid()) == -1) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Failed to initialize random generator "
|
|
|
|
"when creating iscsi interface"));
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
build: detect potentential uninitialized variables
Even with -Wuninitialized (which is part of autobuild.sh
--enable-compile-warnings=error), gcc does NOT catch this
use of an uninitialized variable:
{
if (cond)
goto error;
int a = 1;
error:
printf("%d", a);
}
which prints 0 (supposing the stack started life wiped) if
cond was true. Clang will catch it, but we don't use clang
as often. Using gcc -Wjump-misses-init catches it, but also
gives false positives:
{
if (cond)
goto error;
int a = 1;
return a;
error:
return 0;
}
Here, a was never used in the scope of the error block, so
declaring it after goto is technically fine (and clang agrees).
However, given that our HACKING already documents a preference
to C89 decl-before-statement, the false positive warning is
enough of a prod to comply with HACKING.
[Personally, I'd _really_ rather use C99 decl-after-statement
to minimize scope, but until gcc can efficiently and reliably
catch scoping and uninitialized usage bugs, I'll settle with
the compromise of enforcing a coding standard that happens to
reject false positives if it can also detect real bugs.]
* acinclude.m4 (LIBVIRT_COMPILE_WARNINGS): Add -Wjump-misses-init.
* src/util/util.c (__virExec): Adjust offenders.
* src/conf/domain_conf.c (virDomainTimerDefParseXML): Likewise.
* src/remote/remote_driver.c (doRemoteOpen): Likewise.
* src/phyp/phyp_driver.c (phypGetLparNAME, phypGetLparProfile)
(phypGetVIOSFreeSCSIAdapter, phypVolumeGetKey)
(phypGetStoragePoolDevice)
(phypVolumeGetPhysicalVolumeByStoragePool)
(phypVolumeGetPath): Likewise.
* src/vbox/vbox_tmpl.c (vboxNetworkUndefineDestroy)
(vboxNetworkCreate, vboxNetworkDumpXML)
(vboxNetworkDefineCreateXML): Likewise.
* src/xenapi/xenapi_driver.c (getCapsObject)
(xenapiDomainDumpXML): Likewise.
* src/xenapi/xenapi_utils.c (createVMRecordFromXml): Likewise.
* src/security/security_selinux.c (SELinuxGenNewContext):
Likewise.
* src/qemu/qemu_command.c (qemuBuildCommandLine): Likewise.
* src/qemu/qemu_hotplug.c (qemuDomainChangeEjectableMedia):
Likewise.
* src/qemu/qemu_process.c (qemuProcessWaitForMonitor): Likewise.
* src/qemu/qemu_monitor_text.c (qemuMonitorTextGetPtyPaths):
Likewise.
* src/qemu/qemu_driver.c (qemudDomainShutdown)
(qemudDomainBlockStats, qemudDomainMemoryPeek): Likewise.
* src/storage/storage_backend_iscsi.c
(virStorageBackendCreateIfaceIQN): Likewise.
* src/node_device/node_device_udev.c (udevProcessPCI): Likewise.
2011-04-01 15:41:45 +00:00
|
|
|
snprintf(temp_ifacename, sizeof(temp_ifacename), "libvirt-iface-%08x",
|
|
|
|
virRandom(1024 * 1024 * 1024));
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
VIR_DEBUG("Attempting to create interface '%s' with IQN '%s'",
|
2010-11-02 11:40:46 +00:00
|
|
|
&temp_ifacename[0], initiatoriqn);
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
/* Note that we ignore the exitstatus. Older versions of iscsiadm
|
|
|
|
* tools returned an exit status of > 0, even if they succeeded.
|
|
|
|
* We will just rely on whether the interface got created
|
|
|
|
* properly. */
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(cmdargv1, &exitstatus) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Failed to run command '%s' to create new iscsi interface"),
|
|
|
|
cmdargv1[0]);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Note that we ignore the exitstatus. Older versions of iscsiadm tools
|
|
|
|
* returned an exit status of > 0, even if they succeeded. We will just
|
|
|
|
* rely on whether iface file got updated properly. */
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(cmdargv2, &exitstatus) < 0) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2010-01-21 11:50:52 +00:00
|
|
|
_("Failed to run command '%s' to update iscsi interface with IQN '%s'"),
|
2010-11-02 11:40:46 +00:00
|
|
|
cmdargv2[0], initiatoriqn);
|
2010-01-21 11:50:52 +00:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check again to make sure the interface was created. */
|
2010-11-02 11:40:46 +00:00
|
|
|
if (virStorageBackendIQNFound(initiatoriqn, ifacename) != IQN_FOUND) {
|
2010-01-21 11:50:52 +00:00
|
|
|
VIR_DEBUG("Failed to find interface '%s' with IQN '%s' "
|
|
|
|
"after attempting to create it",
|
2010-11-02 11:40:46 +00:00
|
|
|
&temp_ifacename[0], initiatoriqn);
|
2010-01-21 11:50:52 +00:00
|
|
|
goto out;
|
|
|
|
} else {
|
|
|
|
VIR_DEBUG("Interface '%s' with IQN '%s' was created successfully",
|
2010-11-02 11:40:46 +00:00
|
|
|
*ifacename, initiatoriqn);
|
2010-01-21 11:50:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (ret != 0)
|
|
|
|
VIR_FREE(*ifacename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
|
2010-01-21 11:50:52 +00:00
|
|
|
static int
|
2010-11-02 11:40:46 +00:00
|
|
|
virStorageBackendISCSIConnection(const char *portal,
|
|
|
|
const char *initiatoriqn,
|
|
|
|
const char *target,
|
|
|
|
const char **extraargv)
|
2010-01-21 11:50:52 +00:00
|
|
|
{
|
|
|
|
int ret = -1;
|
2010-11-02 11:40:46 +00:00
|
|
|
const char *const baseargv[] = {
|
|
|
|
ISCSIADM,
|
|
|
|
"--mode", "node",
|
|
|
|
"--portal", portal,
|
|
|
|
"--targetname", target,
|
|
|
|
NULL
|
|
|
|
};
|
2011-05-03 22:14:00 +00:00
|
|
|
virCommandPtr cmd;
|
2010-01-21 11:50:52 +00:00
|
|
|
char *ifacename = NULL;
|
|
|
|
|
2011-05-03 22:14:00 +00:00
|
|
|
cmd = virCommandNewArgs(baseargv);
|
|
|
|
virCommandAddArgSet(cmd, extraargv);
|
2010-01-21 11:50:52 +00:00
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
if (initiatoriqn) {
|
|
|
|
switch (virStorageBackendIQNFound(initiatoriqn, &ifacename)) {
|
|
|
|
case IQN_FOUND:
|
|
|
|
VIR_DEBUG("ifacename: '%s'", ifacename);
|
|
|
|
break;
|
|
|
|
case IQN_MISSING:
|
2011-05-03 22:14:00 +00:00
|
|
|
if (virStorageBackendCreateIfaceIQN(initiatoriqn,
|
|
|
|
&ifacename) != 0) {
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case IQN_ERROR:
|
|
|
|
default:
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2011-05-03 22:14:00 +00:00
|
|
|
virCommandAddArgList(cmd, "--interface", ifacename, NULL);
|
2010-01-21 11:50:52 +00:00
|
|
|
}
|
2010-11-02 11:40:46 +00:00
|
|
|
|
2011-05-03 22:14:00 +00:00
|
|
|
if (virCommandRun(cmd, NULL) < 0)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
2010-01-21 11:50:52 +00:00
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
cleanup:
|
2011-05-03 22:14:00 +00:00
|
|
|
virCommandFree(cmd);
|
2010-01-21 11:50:52 +00:00
|
|
|
VIR_FREE(ifacename);
|
|
|
|
|
|
|
|
return ret;
|
2008-02-20 15:49:25 +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;
|
2009-04-01 16:03:22 +00:00
|
|
|
int retval = 0;
|
|
|
|
uint32_t host;
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2011-04-03 09:21:30 +00:00
|
|
|
if (virAsprintf(&sysfs_path,
|
|
|
|
"/sys/class/iscsi_session/session%s/device", session) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
2008-06-17 12:49:37 +00:00
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virStorageBackendSCSIGetHostNumber(sysfs_path, &host) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-04-01 16:03:22 +00:00
|
|
|
_("Failed to get host number for iSCSI session "
|
|
|
|
"with path '%s'"),
|
2009-01-20 17:13:33 +00:00
|
|
|
sysfs_path);
|
2009-04-01 16:03:22 +00:00
|
|
|
retval = -1;
|
2008-06-17 12:49:37 +00:00
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendSCSIFindLUs(pool, host) < 0) {
|
2010-02-04 20:02:58 +00:00
|
|
|
virReportSystemError(errno,
|
2009-04-01 16:03:22 +00:00
|
|
|
_("Failed to find LUs on host %u"), host);
|
|
|
|
retval = -1;
|
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
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIRescanLUNs(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
2008-02-20 15:49:25 +00:00
|
|
|
const char *session)
|
|
|
|
{
|
2008-06-17 12:49:37 +00:00
|
|
|
const char *const cmdargv[] = {
|
2008-02-20 15:49:25 +00:00
|
|
|
ISCSIADM, "--mode", "session", "-r", session, "-R", NULL,
|
|
|
|
};
|
|
|
|
|
2010-02-04 22:41:52 +00:00
|
|
|
if (virRun(cmdargv, NULL) < 0)
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-12 15:21:48 +00:00
|
|
|
struct virStorageBackendISCSITargetList {
|
|
|
|
size_t ntargets;
|
|
|
|
char **targets;
|
|
|
|
};
|
2008-02-20 15:49:25 +00:00
|
|
|
|
|
|
|
static int
|
2010-11-12 15:21:48 +00:00
|
|
|
virStorageBackendISCSIGetTargets(virStoragePoolObjPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
char **const groups,
|
|
|
|
void *data)
|
2008-02-20 15:49:25 +00:00
|
|
|
{
|
2010-11-12 15:21:48 +00:00
|
|
|
struct virStorageBackendISCSITargetList *list = data;
|
|
|
|
char *target;
|
|
|
|
|
|
|
|
if (!(target = strdup(groups[1]))) {
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (VIR_REALLOC_N(list->targets, list->ntargets + 1) < 0) {
|
|
|
|
VIR_FREE(target);
|
|
|
|
virReportOOMError();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
list->targets[list->ntargets] = target;
|
|
|
|
list->ntargets++;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendISCSITargetAutologin(const char *portal,
|
|
|
|
const char *initiatoriqn,
|
|
|
|
const char *target,
|
|
|
|
bool enable)
|
|
|
|
{
|
|
|
|
const char *extraargv[] = { "--op", "update",
|
|
|
|
"--name", "node.startup",
|
|
|
|
"--value", enable ? "automatic" : "manual",
|
|
|
|
NULL };
|
|
|
|
|
|
|
|
return virStorageBackendISCSIConnection(portal, initiatoriqn, target, extraargv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
virStorageBackendISCSIScanTargets(const char *portal,
|
|
|
|
const char *initiatoriqn,
|
|
|
|
size_t *ntargetsret,
|
|
|
|
char ***targetsret)
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* The output of sendtargets is very simple, just two columns,
|
|
|
|
* portal then target name
|
|
|
|
*
|
|
|
|
* 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo0.bf6d84
|
|
|
|
* 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo1.bf6d84
|
|
|
|
* 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo2.bf6d84
|
|
|
|
* 192.168.122.185:3260,1 iqn.2004-04.com:fedora14:iscsi.demo3.bf6d84
|
|
|
|
*/
|
|
|
|
const char *regexes[] = {
|
|
|
|
"^\\s*(\\S+)\\s+(\\S+)\\s*$"
|
2008-06-17 12:47:10 +00:00
|
|
|
};
|
2010-11-12 15:21:48 +00:00
|
|
|
int vars[] = { 2 };
|
|
|
|
const char *const cmdsendtarget[] = {
|
|
|
|
ISCSIADM, "--mode", "discovery", "--type", "sendtargets",
|
|
|
|
"--portal", portal, NULL
|
|
|
|
};
|
|
|
|
struct virStorageBackendISCSITargetList list;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
memset(&list, 0, sizeof(list));
|
|
|
|
|
|
|
|
if (virStorageBackendRunProgRegex(NULL, /* No pool for callback */
|
|
|
|
cmdsendtarget,
|
|
|
|
1,
|
|
|
|
regexes,
|
|
|
|
vars,
|
|
|
|
virStorageBackendISCSIGetTargets,
|
2011-05-10 19:36:50 +00:00
|
|
|
&list) < 0) {
|
2008-06-17 12:47:10 +00:00
|
|
|
return -1;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
2010-11-12 15:21:48 +00:00
|
|
|
|
|
|
|
for (i = 0 ; i < list.ntargets ; i++) {
|
|
|
|
/* We have to ignore failure, because we can't undo
|
|
|
|
* the results of 'sendtargets', unless we go scrubbing
|
|
|
|
* around in the dirt in /var/lib/iscsi.
|
|
|
|
*/
|
|
|
|
if (virStorageBackendISCSITargetAutologin(portal,
|
|
|
|
initiatoriqn,
|
|
|
|
list.targets[i], false) < 0)
|
|
|
|
VIR_WARN("Unable to disable auto-login on iSCSI target %s: %s",
|
|
|
|
portal, list.targets[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ntargetsret && targetsret) {
|
|
|
|
*ntargetsret = list.ntargets;
|
|
|
|
*targetsret = list.targets;
|
|
|
|
} else {
|
|
|
|
for (i = 0 ; i < list.ntargets ; i++) {
|
|
|
|
VIR_FREE(list.targets[i]);
|
|
|
|
}
|
|
|
|
VIR_FREE(list.targets);
|
|
|
|
}
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
return 0;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-12 15:41:16 +00:00
|
|
|
static char *
|
|
|
|
virStorageBackendISCSIFindPoolSources(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
const char *srcSpec,
|
2011-07-06 22:51:23 +00:00
|
|
|
unsigned int flags)
|
2010-11-12 15:41:16 +00:00
|
|
|
{
|
|
|
|
virStoragePoolSourcePtr source = NULL;
|
|
|
|
size_t ntargets = 0;
|
|
|
|
char **targets = NULL;
|
|
|
|
char *ret = NULL;
|
|
|
|
int i;
|
|
|
|
virStoragePoolSourceList list = {
|
|
|
|
.type = VIR_STORAGE_POOL_ISCSI,
|
|
|
|
.nsources = 0,
|
|
|
|
.sources = NULL
|
|
|
|
};
|
|
|
|
char *portal = NULL;
|
|
|
|
|
2011-07-06 22:51:23 +00:00
|
|
|
virCheckFlags(0, NULL);
|
|
|
|
|
2010-11-12 15:41:16 +00:00
|
|
|
if (!(source = virStoragePoolDefParseSourceString(srcSpec,
|
|
|
|
list.type)))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!(portal = virStorageBackendISCSIPortal(source)))
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageBackendISCSIScanTargets(portal,
|
|
|
|
source->initiator.iqn,
|
|
|
|
&ntargets, &targets) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (VIR_ALLOC_N(list.sources, ntargets) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0 ; i < ntargets ; i++) {
|
|
|
|
if (VIR_ALLOC_N(list.sources[i].devices, 1) < 0) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
list.sources[i].host = source->host;
|
|
|
|
list.sources[i].initiator = source->initiator;
|
|
|
|
list.sources[i].ndevice = 1;
|
|
|
|
list.sources[i].devices[0].path = targets[i];
|
|
|
|
list.nsources++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ret = virStoragePoolSourceListFormat(&list))) {
|
|
|
|
virReportOOMError();
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
if (list.sources) {
|
|
|
|
for (i = 0 ; i < ntargets ; i++)
|
|
|
|
VIR_FREE(list.sources[i].devices);
|
|
|
|
VIR_FREE(list.sources);
|
|
|
|
}
|
|
|
|
for (i = 0 ; i < ntargets ; i++)
|
|
|
|
VIR_FREE(targets[i]);
|
|
|
|
VIR_FREE(targets);
|
|
|
|
VIR_FREE(portal);
|
|
|
|
virStoragePoolSourceFree(source);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:09:20 +00:00
|
|
|
static int
|
|
|
|
virStorageBackendISCSICheckPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
virStoragePoolObjPtr pool,
|
|
|
|
bool *isActive)
|
|
|
|
{
|
|
|
|
char *session = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
|
|
|
|
*isActive = false;
|
|
|
|
|
|
|
|
if (pool->def->source.host.name == NULL) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source host"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->def->source.ndevice != 1 ||
|
|
|
|
pool->def->source.devices[0].path == NULL) {
|
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
|
|
|
"%s", _("missing source device"));
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((session = virStorageBackendISCSISession(pool, 1)) != NULL) {
|
|
|
|
*isActive = true;
|
|
|
|
VIR_FREE(session);
|
|
|
|
}
|
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-20 15:49:25 +00:00
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:49:25 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
char *portal = NULL;
|
2010-11-02 11:40:46 +00:00
|
|
|
char *session = NULL;
|
|
|
|
int ret = -1;
|
|
|
|
const char *loginargv[] = { "--login", NULL };
|
2008-02-20 15:49:25 +00:00
|
|
|
|
|
|
|
if (pool->def->source.host.name == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("missing source host"));
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pool->def->source.ndevice != 1 ||
|
|
|
|
pool->def->source.devices[0].path == NULL) {
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageReportError(VIR_ERR_INTERNAL_ERROR,
|
2008-02-22 16:26:13 +00:00
|
|
|
"%s", _("missing source device"));
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, 1)) == NULL) {
|
2010-11-02 11:40:46 +00:00
|
|
|
if ((portal = virStorageBackendISCSIPortal(&pool->def->source)) == NULL)
|
|
|
|
goto cleanup;
|
|
|
|
/*
|
|
|
|
* iscsiadm doesn't let you login to a target, unless you've
|
|
|
|
* first issued a 'sendtargets' command to the portal :-(
|
|
|
|
*/
|
2010-11-12 15:21:48 +00:00
|
|
|
if (virStorageBackendISCSIScanTargets(portal,
|
|
|
|
pool->def->source.initiator.iqn,
|
|
|
|
NULL, NULL) < 0)
|
2010-11-02 11:40:46 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
if (virStorageBackendISCSIConnection(portal,
|
|
|
|
pool->def->source.initiator.iqn,
|
|
|
|
pool->def->source.devices[0].path,
|
|
|
|
loginargv) < 0)
|
|
|
|
goto cleanup;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
2010-11-02 11:40:46 +00:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
cleanup:
|
|
|
|
VIR_FREE(session);
|
|
|
|
return ret;
|
2008-02-20 15:49:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIRefreshPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:49:25 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
|
|
|
char *session = NULL;
|
|
|
|
|
|
|
|
pool->def->allocation = pool->def->capacity = pool->def->available = 0;
|
|
|
|
|
2010-02-10 11:42:56 +00:00
|
|
|
if ((session = virStorageBackendISCSISession(pool, 0)) == NULL)
|
2008-02-20 15:49:25 +00:00
|
|
|
goto cleanup;
|
2010-02-10 11:42:56 +00:00
|
|
|
if (virStorageBackendISCSIRescanLUNs(pool, 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;
|
|
|
|
|
|
|
|
cleanup:
|
2008-06-06 11:09:57 +00:00
|
|
|
VIR_FREE(session);
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2010-02-10 11:42:56 +00:00
|
|
|
virStorageBackendISCSIStopPool(virConnectPtr conn ATTRIBUTE_UNUSED,
|
2008-02-20 15:49:25 +00:00
|
|
|
virStoragePoolObjPtr pool)
|
|
|
|
{
|
2010-11-02 11:40:46 +00:00
|
|
|
const char *logoutargv[] = { "--logout", NULL };
|
2008-02-20 15:49:25 +00:00
|
|
|
char *portal;
|
2010-11-02 11:40:46 +00:00
|
|
|
int ret = -1;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
if ((portal = virStorageBackendISCSIPortal(&pool->def->source)) == NULL)
|
2008-02-20 15:49:25 +00:00
|
|
|
return -1;
|
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
if (virStorageBackendISCSIConnection(portal,
|
|
|
|
pool->def->source.initiator.iqn,
|
|
|
|
pool->def->source.devices[0].path,
|
|
|
|
logoutargv) < 0)
|
|
|
|
goto cleanup;
|
|
|
|
ret = 0;
|
2008-02-20 15:49:25 +00:00
|
|
|
|
2010-11-02 11:40:46 +00:00
|
|
|
cleanup:
|
|
|
|
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,
|
2008-02-20 15:49:25 +00:00
|
|
|
};
|