2010-01-15 15:01:02 +00:00
|
|
|
/*
|
2010-03-02 21:19:24 +00:00
|
|
|
* esx_storage_driver.c: storage driver functions for managing VMware ESX
|
2010-01-15 15:01:02 +00:00
|
|
|
* host storage
|
|
|
|
*
|
2011-07-06 20:40:19 +00:00
|
|
|
* Copyright (C) 2010-2011 Red Hat, Inc.
|
2012-11-10 07:18:07 +00:00
|
|
|
* Copyright (C) 2010-2012 Matthias Bolte <matthias.bolte@googlemail.com>
|
|
|
|
* Copyright (C) 2012 Ata E Husain Bohra <ata.husain@hotmail.com>
|
2010-01-15 15:01:02 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
2010-01-15 15:01:02 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2012-12-13 18:01:25 +00:00
|
|
|
#include "viruuid.h"
|
2012-12-12 18:06:53 +00:00
|
|
|
#include "viralloc.h"
|
2010-05-18 16:11:59 +00:00
|
|
|
#include "storage_conf.h"
|
2010-01-15 15:01:02 +00:00
|
|
|
#include "esx_private.h"
|
|
|
|
#include "esx_storage_driver.h"
|
2012-11-10 07:18:07 +00:00
|
|
|
#include "esx_storage_backend_vmfs.h"
|
2012-11-10 07:18:08 +00:00
|
|
|
#include "esx_storage_backend_iscsi.h"
|
2010-01-15 15:01:02 +00:00
|
|
|
|
|
|
|
#define VIR_FROM_THIS VIR_FROM_ESX
|
|
|
|
|
2010-08-08 18:45:12 +00:00
|
|
|
/*
|
2012-11-10 07:18:07 +00:00
|
|
|
* ESX storage driver implements a facade pattern;
|
|
|
|
* the driver exposes the routines supported by libvirt
|
|
|
|
* public interface to manage ESX storage devices. Internally
|
|
|
|
* it uses backend drivers to perform the required task.
|
2010-08-08 18:45:12 +00:00
|
|
|
*/
|
2012-11-10 07:18:07 +00:00
|
|
|
enum {
|
|
|
|
VMFS = 0,
|
2012-11-10 07:18:08 +00:00
|
|
|
ISCSI,
|
2012-11-10 07:18:07 +00:00
|
|
|
LAST_BACKEND
|
|
|
|
};
|
2010-12-06 19:40:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
static virStorageDriverPtr backends[] = {
|
2012-11-10 07:18:08 +00:00
|
|
|
&esxStorageBackendVMFS,
|
|
|
|
&esxStorageBackendISCSI
|
2012-11-10 07:18:07 +00:00
|
|
|
};
|
2010-12-06 19:40:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-15 15:01:02 +00:00
|
|
|
static virDrvOpenStatus
|
|
|
|
esxStorageOpen(virConnectPtr conn,
|
|
|
|
virConnectAuthPtr auth ATTRIBUTE_UNUSED,
|
2011-07-06 22:14:33 +00:00
|
|
|
unsigned int flags)
|
2010-01-15 15:01:02 +00:00
|
|
|
{
|
2011-07-06 22:14:33 +00:00
|
|
|
virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (conn->driver->no != VIR_DRV_ESX)
|
2010-01-15 15:01:02 +00:00
|
|
|
return VIR_DRV_OPEN_DECLINED;
|
|
|
|
|
|
|
|
return VIR_DRV_OPEN_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2014-10-23 13:33:11 +00:00
|
|
|
esxStorageClose(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2010-01-15 15:01:02 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectNumOfStoragePools(virConnectPtr conn)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
int count = 0;
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} 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;
|
2012-11-10 07:18:07 +00:00
|
|
|
int tmp;
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
for (i = 0; i < LAST_BACKEND; ++i) {
|
2013-04-22 17:26:01 +00:00
|
|
|
tmp = backends[i]->connectNumOfStoragePools(conn);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (tmp < 0)
|
2012-11-10 07:18:07 +00:00
|
|
|
return -1;
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
count += tmp;
|
|
|
|
}
|
2010-05-18 16:11:59 +00:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectListStoragePools(virConnectPtr conn, char **const names, int maxnames)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
bool success = false;
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-05-18 16:11:59 +00:00
|
|
|
int count = 0;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} 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;
|
2012-11-10 07:18:07 +00:00
|
|
|
int tmp;
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (maxnames == 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return 0;
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
for (i = 0; i < LAST_BACKEND; ++i) {
|
2013-04-22 17:26:01 +00:00
|
|
|
tmp = backends[i]->connectListStoragePools(conn, &names[count], maxnames - count);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (tmp < 0)
|
2012-11-10 07:18:07 +00:00
|
|
|
goto cleanup;
|
|
|
|
|
|
|
|
count += tmp;
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
success = true;
|
|
|
|
|
2014-03-25 06:48:48 +00:00
|
|
|
cleanup:
|
2010-05-18 16:11:59 +00:00
|
|
|
if (! success) {
|
2014-11-13 14:22:20 +00:00
|
|
|
for (i = 0; i < count; ++i)
|
2010-05-18 16:11:59 +00:00
|
|
|
VIR_FREE(names[i]);
|
|
|
|
|
|
|
|
count = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectNumOfDefinedStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
/* ESX storage pools are always active */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxConnectListDefinedStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
|
|
|
|
char **const names ATTRIBUTE_UNUSED,
|
|
|
|
int maxnames ATTRIBUTE_UNUSED)
|
2010-05-18 16:11:59 +00:00
|
|
|
{
|
|
|
|
/* ESX storage pools are always active */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
esxStoragePoolLookupByName(virConnectPtr conn, const char *name)
|
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} 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;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStoragePoolPtr pool;
|
|
|
|
|
|
|
|
virCheckNonNullArgReturn(name, NULL);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
for (i = 0; i < LAST_BACKEND; ++i) {
|
2013-04-22 17:26:01 +00:00
|
|
|
pool = backends[i]->storagePoolLookupByName(conn, name);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (pool)
|
2012-11-10 07:18:07 +00:00
|
|
|
return pool;
|
2010-08-01 17:53:00 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("Could not find storage pool with name '%s'"), name);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
return NULL;
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStoragePoolPtr
|
|
|
|
esxStoragePoolLookupByUUID(virConnectPtr conn, const unsigned char *uuid)
|
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} 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;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStoragePoolPtr pool;
|
2010-05-18 16:11:59 +00:00
|
|
|
char uuid_string[VIR_UUID_STRING_BUFLEN] = "";
|
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
/* invoke backend drive method to search all known pools */
|
|
|
|
for (i = 0; i < LAST_BACKEND; ++i) {
|
2013-04-22 17:26:01 +00:00
|
|
|
pool = backends[i]->storagePoolLookupByUUID(conn, uuid);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (pool)
|
2012-11-10 07:18:07 +00:00
|
|
|
return pool;
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virUUIDFormat(uuid, uuid_string);
|
|
|
|
virReportError(VIR_ERR_NO_STORAGE_POOL,
|
|
|
|
_("Could not find storage pool with uuid '%s'"),
|
|
|
|
uuid_string);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
return NULL;
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
static virStoragePoolPtr
|
|
|
|
esxStoragePoolLookupByVolume(virStorageVolPtr volume)
|
|
|
|
{
|
|
|
|
return esxStoragePoolLookupByName(volume->conn, volume->pool);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
static int
|
|
|
|
esxStoragePoolRefresh(virStoragePoolPtr pool, unsigned int flags)
|
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(pool->privateData, -1);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storagePoolRefresh(pool, flags);
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxStoragePoolGetInfo(virStoragePoolPtr pool, virStoragePoolInfoPtr info)
|
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
|
|
|
|
|
|
|
virCheckNonNullArgReturn(pool->privateData, -1);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-03-29 09:52:04 +00:00
|
|
|
memset(info, 0, sizeof(*info));
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storagePoolGetInfo(pool, info);
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
esxStoragePoolGetXMLDesc(virStoragePoolPtr pool, unsigned int flags)
|
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(pool->privateData, NULL);
|
2010-05-18 16:11:59 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-05-18 16:11:59 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storagePoolGetXMLDesc(pool, flags);
|
2010-05-18 16:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxStoragePoolGetAutostart(virStoragePoolPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
int *autostart)
|
|
|
|
{
|
|
|
|
/* ESX storage pools are always active */
|
|
|
|
*autostart = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxStoragePoolSetAutostart(virStoragePoolPtr pool ATTRIBUTE_UNUSED,
|
|
|
|
int autostart)
|
|
|
|
{
|
|
|
|
/* Just accept autostart activation, but fail on autostart deactivation */
|
|
|
|
autostart = (autostart != 0);
|
|
|
|
|
|
|
|
if (! autostart) {
|
2012-07-18 14:25:50 +00:00
|
|
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
|
|
_("Cannot deactivate storage pool autostart"));
|
2010-05-18 16:11:59 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
|
|
|
|
|
|
|
virCheckNonNullArgReturn(pool->privateData, -1);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storagePoolNumOfVolumes(pool);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names,
|
|
|
|
int maxnames)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(pool->privateData, -1);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storagePoolListVolumes(pool, names, maxnames);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolLookupByName(virStoragePoolPtr pool, const char *name)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
|
|
|
|
|
|
|
virCheckNonNullArgReturn(pool->privateData, NULL);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolLookupByName(pool, name);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolLookupByPath(virConnectPtr conn, const char *path)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
/*
|
|
|
|
* FIXME: calling backends blindly may set unwanted error codes
|
|
|
|
*
|
2014-04-20 20:07:46 +00:00
|
|
|
* VMFS Datastore path follows canonical format i.e.:
|
2012-11-10 07:18:07 +00:00
|
|
|
* [<datastore_name>] <file_path>
|
2012-11-10 07:18:08 +00:00
|
|
|
* WHEREAS
|
|
|
|
* iSCSI LUNs device path follows normal linux path convention
|
2012-11-10 07:18:07 +00:00
|
|
|
*/
|
|
|
|
if (STRPREFIX(path, "[")) {
|
2013-04-22 17:26:01 +00:00
|
|
|
return backends[VMFS]->storageVolLookupByPath(conn, path);
|
2012-11-10 07:18:08 +00:00
|
|
|
} else if (STRPREFIX(path, "/")) {
|
2013-04-22 17:26:01 +00:00
|
|
|
return backends[ISCSI]->storageVolLookupByPath(conn, path);
|
2012-11-10 07:18:07 +00:00
|
|
|
} else {
|
|
|
|
virReportError(VIR_ERR_INVALID_ARG,
|
|
|
|
_("Unexpected volume path format: %s"), path);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
return NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
2010-08-29 17:33:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolLookupByKey(virConnectPtr conn, const char *key)
|
2010-08-29 17:33:49 +00:00
|
|
|
{
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageVolPtr volume;
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = conn->privateData;
|
Convert 'int i' to 'size_t i' in src/{esx,vmx,vmware} 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-09-03 23:30:04 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-29 17:33:49 +00:00
|
|
|
return NULL;
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
for (i = 0; i < LAST_BACKEND; ++i) {
|
2013-04-22 17:26:01 +00:00
|
|
|
volume = backends[i]->storageVolLookupByKey(conn, key);
|
2010-08-29 17:33:49 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (volume)
|
2012-11-10 07:18:07 +00:00
|
|
|
return volume;
|
2010-08-29 17:33:49 +00:00
|
|
|
}
|
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virReportError(VIR_ERR_NO_STORAGE_VOL,
|
|
|
|
_("Could not find storage volume with key '%s'"),
|
|
|
|
key);
|
|
|
|
|
|
|
|
return NULL;
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-28 19:49:07 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolCreateXML(virStoragePoolPtr pool, const char *xmldesc,
|
|
|
|
unsigned int flags)
|
2010-08-28 19:49:07 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
2010-08-28 19:49:07 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(pool->privateData, NULL);
|
2010-08-28 19:49:07 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-06 19:40:59 +00:00
|
|
|
return NULL;
|
2010-08-28 19:49:07 +00:00
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolCreateXML(pool, xmldesc, flags);
|
2010-08-28 19:49:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-06 20:07:35 +00:00
|
|
|
static virStorageVolPtr
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolCreateXMLFrom(virStoragePoolPtr pool, const char *xmldesc,
|
|
|
|
virStorageVolPtr sourceVolume, unsigned int flags)
|
2010-12-06 20:07:35 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = pool->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = pool->privateData;
|
2010-12-06 20:07:35 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(pool->privateData, NULL);
|
2010-12-06 20:07:35 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-06 20:07:35 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolCreateXMLFrom(pool, xmldesc, sourceVolume, flags);
|
2010-12-06 20:07:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-22 15:45:50 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolDelete(virStorageVolPtr volume, unsigned int flags)
|
2010-12-22 15:45:50 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = volume->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = volume->privateData;
|
2010-12-22 15:45:50 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(volume->privateData, -1);
|
2010-12-22 15:45:50 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-22 15:45:50 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolDelete(volume, flags);
|
2010-12-22 15:45:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-12-22 16:24:45 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolWipe(virStorageVolPtr volume, unsigned int flags)
|
2010-12-22 16:24:45 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = volume->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = volume->privateData;
|
2010-12-22 16:24:45 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(volume->privateData, -1);
|
2010-12-22 16:24:45 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-12-22 16:24:45 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolWipe(volume, flags);
|
2010-12-22 16:24:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
static int
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolGetInfo(virStorageVolPtr volume, virStorageVolInfoPtr info)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = volume->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = volume->privateData;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(volume->privateData, -1);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return -1;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolGetInfo(volume, info);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolGetXMLDesc(virStorageVolPtr volume, unsigned int flags)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = volume->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = volume->privateData;
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2012-11-10 07:18:07 +00:00
|
|
|
virCheckNonNullArgReturn(volume->privateData, NULL);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolGetXMLDesc(volume, flags);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char *
|
2013-04-23 12:50:18 +00:00
|
|
|
esxStorageVolGetPath(virStorageVolPtr volume)
|
2010-08-07 22:24:29 +00:00
|
|
|
{
|
2014-10-23 13:33:11 +00:00
|
|
|
esxPrivate *priv = volume->conn->privateData;
|
2012-11-10 07:18:07 +00:00
|
|
|
virStorageDriverPtr backend = volume->privateData;
|
|
|
|
|
|
|
|
virCheckNonNullArgReturn(volume->privateData, NULL);
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2014-11-13 14:22:20 +00:00
|
|
|
if (esxVI_EnsureSession(priv->primary) < 0)
|
2010-08-07 22:24:29 +00:00
|
|
|
return NULL;
|
|
|
|
|
2013-04-22 17:26:01 +00:00
|
|
|
return backend->storageVolGetPath(volume);
|
2010-08-07 22:24:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-05-18 16:11:59 +00:00
|
|
|
static int
|
|
|
|
esxStoragePoolIsActive(virStoragePoolPtr pool ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* ESX storage pools are always active */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
esxStoragePoolIsPersistent(virStoragePoolPtr pool ATTRIBUTE_UNUSED)
|
|
|
|
{
|
|
|
|
/* ESX has no concept of transient pools, so all of them are persistent */
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-07 22:24:29 +00:00
|
|
|
|
2010-01-15 15:01:02 +00:00
|
|
|
static virStorageDriver esxStorageDriver = {
|
2011-06-06 03:08:06 +00:00
|
|
|
.name = "ESX",
|
2013-04-23 12:49:21 +00:00
|
|
|
.storageOpen = esxStorageOpen, /* 0.7.6 */
|
|
|
|
.storageClose = esxStorageClose, /* 0.7.6 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.connectNumOfStoragePools = esxConnectNumOfStoragePools, /* 0.8.2 */
|
|
|
|
.connectListStoragePools = esxConnectListStoragePools, /* 0.8.2 */
|
|
|
|
.connectNumOfDefinedStoragePools = esxConnectNumOfDefinedStoragePools, /* 0.8.2 */
|
|
|
|
.connectListDefinedStoragePools = esxConnectListDefinedStoragePools, /* 0.8.2 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolLookupByName = esxStoragePoolLookupByName, /* 0.8.2 */
|
|
|
|
.storagePoolLookupByUUID = esxStoragePoolLookupByUUID, /* 0.8.2 */
|
|
|
|
.storagePoolLookupByVolume = esxStoragePoolLookupByVolume, /* 0.8.4 */
|
|
|
|
.storagePoolRefresh = esxStoragePoolRefresh, /* 0.8.2 */
|
|
|
|
.storagePoolGetInfo = esxStoragePoolGetInfo, /* 0.8.2 */
|
|
|
|
.storagePoolGetXMLDesc = esxStoragePoolGetXMLDesc, /* 0.8.2 */
|
|
|
|
.storagePoolGetAutostart = esxStoragePoolGetAutostart, /* 0.8.2 */
|
|
|
|
.storagePoolSetAutostart = esxStoragePoolSetAutostart, /* 0.8.2 */
|
2013-04-23 12:50:18 +00:00
|
|
|
.storagePoolNumOfVolumes = esxStoragePoolNumOfVolumes, /* 0.8.4 */
|
|
|
|
.storagePoolListVolumes = esxStoragePoolListVolumes, /* 0.8.4 */
|
|
|
|
.storageVolLookupByName = esxStorageVolLookupByName, /* 0.8.4 */
|
|
|
|
.storageVolLookupByPath = esxStorageVolLookupByPath, /* 0.8.4 */
|
|
|
|
.storageVolLookupByKey = esxStorageVolLookupByKey, /* 0.8.4 */
|
|
|
|
.storageVolCreateXML = esxStorageVolCreateXML, /* 0.8.4 */
|
|
|
|
.storageVolCreateXMLFrom = esxStorageVolCreateXMLFrom, /* 0.8.7 */
|
|
|
|
.storageVolDelete = esxStorageVolDelete, /* 0.8.7 */
|
|
|
|
.storageVolWipe = esxStorageVolWipe, /* 0.8.7 */
|
|
|
|
.storageVolGetInfo = esxStorageVolGetInfo, /* 0.8.4 */
|
|
|
|
.storageVolGetXMLDesc = esxStorageVolGetXMLDesc, /* 0.8.4 */
|
|
|
|
.storageVolGetPath = esxStorageVolGetPath, /* 0.8.4 */
|
2013-04-22 17:26:01 +00:00
|
|
|
.storagePoolIsActive = esxStoragePoolIsActive, /* 0.8.2 */
|
|
|
|
.storagePoolIsPersistent = esxStoragePoolIsPersistent, /* 0.8.2 */
|
2010-01-15 15:01:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
esxStorageRegister(void)
|
|
|
|
{
|
|
|
|
return virRegisterStorageDriver(&esxStorageDriver);
|
|
|
|
}
|